blob: dfc0061ca98bba6c4385ddfbae48f78df9e169ec [file] [log] [blame]
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001#!/bin/sh
2
3# Run all available tests (mostly).
4#
5# Warning: includes various build modes, so it will mess with the current
6# CMake configuration. After this script is run, the CMake cache is lost and
7# CMake is not initialised any more!
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +01008#
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00009# Assumes gcc and clang (recent enough for using ASan with gcc and MemSan with
10# clang, or valgrind) are available, as well as cmake and a "good" find.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010011
12# Abort on errors (and uninitiliased variables)
13set -eu
14
15if [ -d library -a -d include -a -d tests ]; then :; else
Manuel Pégourié-Gonnarde4f6edc2015-01-22 16:43:54 +000016 echo "Must be run from mbed TLS root" >&2
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010017 exit 1
18fi
19
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +020020CONFIG_H='include/polarssl/config.h'
21CONFIG_BAK="$CONFIG_H.bak"
22
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010023MEMORY=0
24
25while [ $# -gt 0 ]; do
26 case "$1" in
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +010027 -m*)
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +000028 MEMORY=${1#-m}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010029 ;;
30 *)
31 echo "Unknown argument: '$1'" >&2
32 echo "Use the source, Luke!" >&2
33 exit 1
34 ;;
35 esac
36 shift
37done
38
39# remove built files as well as the cmake cache/config
40cleanup()
41{
42 make clean
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +020043
Manuel Pégourié-Gonnard76c99a02014-12-11 10:33:43 +010044 find . -iname '*cmake*' -not -name CMakeLists.txt -exec rm -rf {} \+
Manuel Pégourié-Gonnard897a5952014-03-25 13:23:04 +010045 rm -f include/Makefile include/polarssl/Makefile programs/*/Makefile
Paul Bakkerfe0984d2014-06-13 00:13:45 +020046 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile
47 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +020048
49 if [ -f "$CONFIG_BAK" ]; then
50 mv "$CONFIG_BAK" "$CONFIG_H"
51 fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010052}
53
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +020054trap cleanup INT TERM HUP
55
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +010056msg()
57{
58 echo ""
59 echo "******************************************************************"
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +010060 echo "* $1 "
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +000061 printf "* "; date
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +010062 echo "******************************************************************"
63}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010064
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +020065# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +010066# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard61bc57a2014-08-14 11:29:06 +020067# and/or are more likely to fail than others (eg I use Clang most of the
68# time, so start with a GCC build).
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +020069# 2. Minimize total running time, by avoiding useless rebuilds
70#
71# Indicative running times are given for reference.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010072
Manuel Pégourié-Gonnardea29d152014-11-20 17:32:33 +010073msg "test: recursion.pl" # < 1s
74scripts/recursion.pl library/*.c
75
Manuel Pégourié-Gonnardb3b8e432015-02-13 14:52:19 +000076msg "test: freshness of generated source files" # < 1s
77tests/scripts/check-generated-files.sh
78
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +010079msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +010080cleanup
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +010081CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +010082make
83
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +010084msg "test: main suites and selftest (ASan build)" # ~ 50s
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +010085make test
86programs/test/selftest
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +020087
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +010088msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +020089cd tests
90./ssl-opt.sh
91cd ..
92
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +010093msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +020094tests/scripts/test-ref-configs.pl
95
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +010096# Most frequent issues are likely to be caught at this point
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +020097
98msg "build: with ASan (rebuild after ref-configs)" # ~ 1 min
99make
100
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100101msg "test: compat.sh (ASan build)" # ~ 6 min
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200102cd tests
103./compat.sh
104cd ..
105
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100106msg "build: cmake, full config, clang" # ~ 50s
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100107cleanup
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200108cp "$CONFIG_H" "$CONFIG_BAK"
109scripts/config.pl full
110scripts/config.pl unset POLARSSL_MEMORY_BACKTRACE # too slow for tests
Manuel Pégourié-Gonnard4d9e36a2015-09-02 10:10:32 +0200111scripts/config.pl unset POLARSSL_ERROR_STRERROR_BC # deprecated
112scripts/config.pl unset POLARSSL_PBKDF2_C # deprecated
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100113CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check .
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100114make
115
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100116msg "test: main suites (full config)" # ~ 5s
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200117make test
118
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100119msg "test: ssl-opt.sh default (full config)" # ~ 1s
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200120cd tests
121./ssl-opt.sh -f Default
122cd ..
123
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100124msg "test: compat.sh DES & NULL (full config)" # ~ 2 min
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200125cd tests
126./compat.sh -e '^$' -f 'NULL\|3DES-EDE-CBC\|DES-CBC3'
127cd ..
128
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +0100129msg "test/build: curves.pl (gcc)" # ~ 5 min (?)
130cleanup
131cmake -D CMAKE_BUILD_TYPE:String=Debug .
132tests/scripts/curves.pl
133
Manuel Pégourié-Gonnard61fe8b02015-03-13 14:33:16 +0000134msg "build: Unix make, -Os (gcc)" # ~ 30s
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100135cleanup
Manuel Pégourié-Gonnard61fe8b02015-03-13 14:33:16 +0000136CC=gcc CFLAGS='-Werror -Os' make
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100137
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +0000138# this is meant to cath missing #define polarssl_printf etc
Manuel Pégourié-Gonnard981732b2015-02-17 15:46:45 +0000139# disable fsio to catch some more missing #include <stdio.h>
Manuel Pégourié-Gonnard757ca002015-03-23 15:24:07 +0100140msg "build: full config except platform/fsio, make, gcc" # ~ 30s
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +0000141cleanup
142cp "$CONFIG_H" "$CONFIG_BAK"
143scripts/config.pl full
144scripts/config.pl unset POLARSSL_PLATFORM_C
Manuel Pégourié-Gonnard6ca40762015-02-13 15:57:35 +0000145scripts/config.pl unset POLARSSL_PLATFORM_MEMORY
Manuel Pégourié-Gonnard721e6bb2015-06-03 13:38:20 +0100146scripts/config.pl unset POLARSSL_PLATFORM_PRINTF_ALT
147scripts/config.pl unset POLARSSL_PLATFORM_FPRINTF_ALT
148scripts/config.pl unset POLARSSL_PLATFORM_SNPRINTF_ALT
149scripts/config.pl unset POLARSSL_PLATFORM_EXIT_ALT
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +0000150scripts/config.pl unset POLARSSL_MEMORY_C
151scripts/config.pl unset POLARSSL_MEMORY_BUFFER_ALLOC_C
Manuel Pégourié-Gonnard981732b2015-02-17 15:46:45 +0000152scripts/config.pl unset POLARSSL_FS_IO
Manuel Pégourié-Gonnardb0282ea2015-09-02 12:12:44 +0200153scripts/config.pl unset POLARSSL_ERROR_STRERROR_BC # deprecated
154scripts/config.pl unset POLARSSL_PBKDF2_C # deprecated
Manuel Pégourié-Gonnard61fe8b02015-03-13 14:33:16 +0000155CC=gcc CFLAGS='-Werror -O0' make
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +0000156
Manuel Pégourié-Gonnarddccb80b2015-06-03 10:20:33 +0100157# catch compile bugs in _uninit functions
158msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
159cleanup
160cp "$CONFIG_H" "$CONFIG_BAK"
161scripts/config.pl full
162scripts/config.pl set POLARSSL_PLATFORM_NO_STD_FUNCTIONS
Manuel Pégourié-Gonnardb0282ea2015-09-02 12:12:44 +0200163scripts/config.pl unset POLARSSL_ERROR_STRERROR_BC # deprecated
164scripts/config.pl unset POLARSSL_PBKDF2_C # deprecated
Manuel Pégourié-Gonnarddccb80b2015-06-03 10:20:33 +0100165CC=gcc CFLAGS='-Werror -O0' make
166
Manuel Pégourié-Gonnard1b1254f2015-08-10 11:56:06 +0200167if uname -a | grep -F Linux >/dev/null; then
168msg "build/test: make shared" # ~ 40s
169cleanup
170make SHARED=1 all check
171fi
172
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000173if uname -a | grep -F x86_64 >/dev/null; then
174msg "build: i386, make, gcc" # ~ 30s
175cleanup
176CC=gcc CFLAGS='-Werror -m32' make
177fi # x86_64
178
179if which arm-none-eabi-gcc >/dev/null; then
180msg "build: arm-none-eabi-gcc, make" # ~ 10s
181cleanup
182cp "$CONFIG_H" "$CONFIG_BAK"
183scripts/config.pl full
184scripts/config.pl unset POLARSSL_NET_C
185scripts/config.pl unset POLARSSL_TIMING_C
186scripts/config.pl unset POLARSSL_FS_IO
Manuel Pégourié-Gonnardb0282ea2015-09-02 12:12:44 +0200187scripts/config.pl unset POLARSSL_ERROR_STRERROR_BC # deprecated
188scripts/config.pl unset POLARSSL_PBKDF2_C # deprecated
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000189# following things are not in the default config
190scripts/config.pl unset POLARSSL_HAVEGE_C # depends on timing.c
191scripts/config.pl unset POLARSSL_THREADING_PTHREAD
192scripts/config.pl unset POLARSSL_THREADING_C
193scripts/config.pl unset POLARSSL_MEMORY_BACKTRACE # execinfo.h
194scripts/config.pl unset POLARSSL_MEMORY_BUFFER_ALLOC_C # calls exit
195CC=arm-none-eabi-gcc CFLAGS=-Werror make lib
196fi # arm-gcc
197
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +0100198if which armcc >/dev/null; then
199msg "build: armcc, make"
200cleanup
201cp "$CONFIG_H" "$CONFIG_BAK"
202scripts/config.pl full
203scripts/config.pl unset POLARSSL_NET_C
204scripts/config.pl unset POLARSSL_TIMING_C
205scripts/config.pl unset POLARSSL_FS_IO
206scripts/config.pl unset POLARSSL_HAVE_TIME
Manuel Pégourié-Gonnardb0282ea2015-09-02 12:12:44 +0200207scripts/config.pl unset POLARSSL_ERROR_STRERROR_BC # deprecated
208scripts/config.pl unset POLARSSL_PBKDF2_C # deprecated
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +0100209# following things are not in the default config
Manuel Pégourié-Gonnardf1002f82015-03-25 16:44:26 +0100210scripts/config.pl unset POLARSSL_DEPRECATED_WARNING
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +0100211scripts/config.pl unset POLARSSL_HAVEGE_C # depends on timing.c
212scripts/config.pl unset POLARSSL_THREADING_PTHREAD
213scripts/config.pl unset POLARSSL_THREADING_C
214scripts/config.pl unset POLARSSL_MEMORY_BACKTRACE # execinfo.h
215scripts/config.pl unset POLARSSL_MEMORY_BUFFER_ALLOC_C # calls exit
Manuel Pégourié-Gonnard20715dc2016-01-07 13:06:51 +0100216CC=armcc AR=armar WARNING_CFLAGS= make lib 2> armcc.stderr
Manuel Pégourié-Gonnard129e4132015-03-13 17:29:18 +0100217if [ -s armcc.stderr ]; then
218 cat armcc.stderr
219 exit 1;
220fi
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +0100221rm armcc.stderr
222fi # armcc
223
Manuel Pégourié-Gonnard6448bce2015-02-16 17:18:36 +0100224if which i686-w64-mingw32-gcc >/dev/null; then
225msg "build: cross-mingw64, make" # ~ 30s
226cleanup
Manuel Pégourié-Gonnard1b1254f2015-08-10 11:56:06 +0200227CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS=-Werror WINDOWS_BUILD=1 make
228WINDOWS_BUILD=1 make clean
229CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS=-Werror WINDOWS_BUILD=1 SHARED=1 make
230WINDOWS_BUILD=1 make clean
Manuel Pégourié-Gonnard6448bce2015-02-16 17:18:36 +0100231fi
232
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000233# MemSan currently only available on Linux 64 bits
234if uname -a | grep 'Linux.*x86_64' >/dev/null; then
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000235
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100236msg "build: MSan (clang)" # ~ 1 min 20s
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100237cleanup
238cp "$CONFIG_H" "$CONFIG_BAK"
239scripts/config.pl unset POLARSSL_AESNI_C # memsan doesn't grok asm
Manuel Pégourié-Gonnard1e77a962015-01-26 14:11:51 +0100240scripts/config.pl set POLARSSL_NO_PLATFORM_ENTROPY # memsan vs getrandom()
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100241CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
242make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +0200243
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100244msg "test: main suites (MSan)" # ~ 10s
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100245make test
246
247msg "test: ssl-opt.sh (MSan)" # ~ 1 min
248cd tests
249./ssl-opt.sh
250cd ..
251
252# Optional part(s)
253
254if [ "$MEMORY" -gt 0 ]; then
255 msg "test: compat.sh (MSan)" # ~ 6 min 20s
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100256 cd tests
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100257 ./compat.sh
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100258 cd ..
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200259fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100260
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000261else # no MemSan
262
263msg "build: Release (clang)"
264cleanup
265CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
266make
267
268msg "test: main suites valgrind (Release)"
269make test
270
271# Optional part(s)
272# Currently broken, programs don't seem to receive signals
273# under valgrind on OS X
274
275if [ "$MEMORY" -gt 0 ]; then
276 msg "test: ssl-opt.sh --memcheck (Release)"
277 cd tests
278 ./ssl-opt.sh --memcheck
279 cd ..
280fi
281
282if [ "$MEMORY" -gt 1 ]; then
283 msg "test: compat.sh --memcheck (Release)"
284 cd tests
285 ./compat.sh --memcheck
286 cd ..
287fi
288
289fi # MemSan
290
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100291msg "Done, cleaning up"
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100292cleanup
293