blob: 421adc3444544a534e03c7686fe09bc92094df38 [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é-Gonnard7f809972015-03-09 17:05:11 +000020CONFIG_H='include/mbedtls/config.h'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +020021CONFIG_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é-Gonnard77d56bb2015-07-28 15:00:37 +020044 find . -name yotta -prune -o -iname '*cmake*' -not -name CMakeLists.txt -exec rm -rf {} \+
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000045 rm -f include/Makefile include/mbedtls/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
Manuel Pégourié-Gonnardd09a6b52015-04-09 17:19:23 +020074tests/scripts/recursion.pl library/*.c
Manuel Pégourié-Gonnardea29d152014-11-20 17:32:33 +010075
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é-Gonnardd09a6b52015-04-09 17:19:23 +020079msg "test: doxygen markup outside doxygen blocks" # < 1s
80tests/scripts/check-doxy-blocks.pl
81
Manuel Pégourié-Gonnarda687baf2015-04-09 11:09:03 +020082msg "test/build: declared and exported names" # < 3s
83cleanup
84tests/scripts/check-names.sh
85
Manuel Pégourié-Gonnard1d552e72016-01-04 16:49:09 +010086if which doxygen >/dev/null; then
87 msg "test: doxygen warnings" # ~ 3s
88 cleanup
89 tests/scripts/doxygen.sh
90fi
91
Manuel Pégourié-Gonnard77d56bb2015-07-28 15:00:37 +020092msg "build: create and build yotta module" # ~ 30s
93cleanup
94tests/scripts/yotta-build.sh
95
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +010096msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +010097cleanup
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +010098CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +010099make
100
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100101msg "test: main suites and selftest (ASan build)" # ~ 50s
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100102make test
103programs/test/selftest
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200104
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100105msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
Manuel Pégourié-Gonnard3d404b42015-07-08 21:59:16 +0100106tests/ssl-opt.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200107
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100108msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200109tests/scripts/test-ref-configs.pl
110
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100111# Most frequent issues are likely to be caught at this point
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200112
113msg "build: with ASan (rebuild after ref-configs)" # ~ 1 min
114make
115
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100116msg "test: compat.sh (ASan build)" # ~ 6 min
Manuel Pégourié-Gonnard3d404b42015-07-08 21:59:16 +0100117tests/compat.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200118
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100119msg "build: cmake, full config, clang" # ~ 50s
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100120cleanup
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200121cp "$CONFIG_H" "$CONFIG_BAK"
122scripts/config.pl full
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200123scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100124CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check .
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100125make
126
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100127msg "test: main suites (full config)" # ~ 5s
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200128make test
129
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100130msg "test: ssl-opt.sh default (full config)" # ~ 1s
Manuel Pégourié-Gonnard3d404b42015-07-08 21:59:16 +0100131tests/ssl-opt.sh -f Default
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200132
Manuel Pégourié-Gonnardea0920f2015-03-24 09:50:15 +0100133msg "test: compat.sh RC4, DES & NULL (full config)" # ~ 2 min
Manuel Pégourié-Gonnard3d404b42015-07-08 21:59:16 +0100134tests/compat.sh -e '3DES\|DES-CBC3' -f 'NULL\|DES\|RC4\|ARCFOUR'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200135
Manuel Pégourié-Gonnard503a5ef2015-10-23 09:04:45 +0200136msg "test/build: curves.pl (gcc)" # ~ 4 min
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +0100137cleanup
138cmake -D CMAKE_BUILD_TYPE:String=Debug .
139tests/scripts/curves.pl
140
Manuel Pégourié-Gonnard503a5ef2015-10-23 09:04:45 +0200141msg "test/build: key-exchanges (gcc)" # ~ 1 min
142cleanup
143cmake -D CMAKE_BUILD_TYPE:String=Check .
144tests/scripts/key-exchanges.pl
145
Manuel Pégourié-Gonnard61fe8b02015-03-13 14:33:16 +0000146msg "build: Unix make, -Os (gcc)" # ~ 30s
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100147cleanup
Manuel Pégourié-Gonnard61fe8b02015-03-13 14:33:16 +0000148CC=gcc CFLAGS='-Werror -Os' make
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100149
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200150# this is meant to cath missing #define mbedtls_printf etc
Manuel Pégourié-Gonnard981732b2015-02-17 15:46:45 +0000151# disable fsio to catch some more missing #include <stdio.h>
Manuel Pégourié-Gonnard757ca002015-03-23 15:24:07 +0100152msg "build: full config except platform/fsio, make, gcc" # ~ 30s
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +0000153cleanup
154cp "$CONFIG_H" "$CONFIG_BAK"
155scripts/config.pl full
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200156scripts/config.pl unset MBEDTLS_PLATFORM_C
157scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
Manuel Pégourié-Gonnard3d4755b2015-06-03 14:03:17 +0100158scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
159scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
160scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
161scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200162scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
163scripts/config.pl unset MBEDTLS_FS_IO
Manuel Pégourié-Gonnard61fe8b02015-03-13 14:33:16 +0000164CC=gcc CFLAGS='-Werror -O0' make
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +0000165
Manuel Pégourié-Gonnarddccb80b2015-06-03 10:20:33 +0100166# catch compile bugs in _uninit functions
167msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
168cleanup
169cp "$CONFIG_H" "$CONFIG_BAK"
170scripts/config.pl full
Manuel Pégourié-Gonnard7ee5ddd2015-06-03 10:33:55 +0100171scripts/config.pl set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
Manuel Pégourié-Gonnarddccb80b2015-06-03 10:20:33 +0100172CC=gcc CFLAGS='-Werror -O0' make
173
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200174msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
175cleanup
176cp "$CONFIG_H" "$CONFIG_BAK"
177scripts/config.pl full
178scripts/config.pl unset MBEDTLS_SSL_SRV_C
179CC=gcc CFLAGS='-Werror -O0' make
180
181msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
182cleanup
183cp "$CONFIG_H" "$CONFIG_BAK"
184scripts/config.pl full
185scripts/config.pl unset MBEDTLS_SSL_CLI_C
186CC=gcc CFLAGS='-Werror -O0' make
187
Manuel Pégourié-Gonnardf78e4de2015-05-29 10:52:14 +0200188msg "build: full config except net.c, make, gcc -std=c99 -pedantic" # ~ 30s
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +0200189cleanup
190cp "$CONFIG_H" "$CONFIG_BAK"
191scripts/config.pl full
Manuel Pégourié-Gonnardf78e4de2015-05-29 10:52:14 +0200192scripts/config.pl unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
193scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
Manuel Pégourié-Gonnard71859362015-06-02 16:39:22 +0100194CC=gcc CFLAGS='-Werror -O0 -std=c99 -pedantic' make lib
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +0200195
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +0200196if uname -a | grep -F Linux >/dev/null; then
197msg "build/test: make shared" # ~ 40s
198cleanup
199make SHARED=1 all check
200fi
201
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000202if uname -a | grep -F x86_64 >/dev/null; then
203msg "build: i386, make, gcc" # ~ 30s
204cleanup
205CC=gcc CFLAGS='-Werror -m32' make
206fi # x86_64
207
208if which arm-none-eabi-gcc >/dev/null; then
209msg "build: arm-none-eabi-gcc, make" # ~ 10s
210cleanup
211cp "$CONFIG_H" "$CONFIG_BAK"
212scripts/config.pl full
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200213scripts/config.pl unset MBEDTLS_NET_C
214scripts/config.pl unset MBEDTLS_TIMING_C
215scripts/config.pl unset MBEDTLS_FS_IO
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000216# following things are not in the default config
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200217scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
218scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
219scripts/config.pl unset MBEDTLS_THREADING_C
220scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
221scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
Manuel Pégourié-Gonnarde058ea22015-06-25 09:04:13 +0200222CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS=-Werror make lib
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000223fi # arm-gcc
224
Manuel Pégourié-Gonnard6dc26512015-06-25 10:48:24 +0200225if which armcc >/dev/null && armcc --help >/dev/null 2>&1; then
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +0100226msg "build: armcc, make"
227cleanup
228cp "$CONFIG_H" "$CONFIG_BAK"
229scripts/config.pl full
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200230scripts/config.pl unset MBEDTLS_NET_C
231scripts/config.pl unset MBEDTLS_TIMING_C
232scripts/config.pl unset MBEDTLS_FS_IO
233scripts/config.pl unset MBEDTLS_HAVE_TIME
Manuel Pégourié-Gonnardbbc60db2015-06-22 14:31:50 +0200234scripts/config.pl unset MBEDTLS_HAVE_TIME_DATE
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +0100235# following things are not in the default config
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200236scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
237scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
238scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
239scripts/config.pl unset MBEDTLS_THREADING_C
240scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
241scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
Manuel Pégourié-Gonnard129e4132015-03-13 17:29:18 +0100242CC=armcc WARNING_CFLAGS= make lib 2> armcc.stderr
243if [ -s armcc.stderr ]; then
244 cat armcc.stderr
245 exit 1;
246fi
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +0100247rm armcc.stderr
248fi # armcc
249
Manuel Pégourié-Gonnard6448bce2015-02-16 17:18:36 +0100250if which i686-w64-mingw32-gcc >/dev/null; then
251msg "build: cross-mingw64, make" # ~ 30s
252cleanup
Manuel Pégourié-Gonnarde058ea22015-06-25 09:04:13 +0200253CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS=-Werror WINDOWS_BUILD=1 make
Manuel Pégourié-Gonnard52fa38a2015-06-23 14:29:58 +0200254WINDOWS_BUILD=1 make clean
Manuel Pégourié-Gonnarde33316c2015-08-07 13:17:23 +0200255CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS=-Werror WINDOWS_BUILD=1 SHARED=1 make
256WINDOWS_BUILD=1 make clean
Manuel Pégourié-Gonnard6448bce2015-02-16 17:18:36 +0100257fi
258
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000259# MemSan currently only available on Linux 64 bits
260if uname -a | grep 'Linux.*x86_64' >/dev/null; then
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000261
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100262msg "build: MSan (clang)" # ~ 1 min 20s
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100263cleanup
264cp "$CONFIG_H" "$CONFIG_BAK"
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200265scripts/config.pl unset MBEDTLS_AESNI_C # memsan doesn't grok asm
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100266CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
267make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +0200268
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100269msg "test: main suites (MSan)" # ~ 10s
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100270make test
271
272msg "test: ssl-opt.sh (MSan)" # ~ 1 min
Manuel Pégourié-Gonnard3d404b42015-07-08 21:59:16 +0100273tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100274
275# Optional part(s)
276
277if [ "$MEMORY" -gt 0 ]; then
278 msg "test: compat.sh (MSan)" # ~ 6 min 20s
Manuel Pégourié-Gonnard3d404b42015-07-08 21:59:16 +0100279 tests/compat.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200280fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100281
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000282else # no MemSan
283
284msg "build: Release (clang)"
285cleanup
286CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
287make
288
289msg "test: main suites valgrind (Release)"
Manuel Pégourié-Gonnard9afdc832015-08-04 17:15:13 +0200290make memcheck
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000291
292# Optional part(s)
293# Currently broken, programs don't seem to receive signals
294# under valgrind on OS X
295
296if [ "$MEMORY" -gt 0 ]; then
297 msg "test: ssl-opt.sh --memcheck (Release)"
Manuel Pégourié-Gonnard3d404b42015-07-08 21:59:16 +0100298 tests/ssl-opt.sh --memcheck
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000299fi
300
301if [ "$MEMORY" -gt 1 ]; then
302 msg "test: compat.sh --memcheck (Release)"
Manuel Pégourié-Gonnard3d404b42015-07-08 21:59:16 +0100303 tests/compat.sh --memcheck
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000304fi
305
306fi # MemSan
307
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100308msg "Done, cleaning up"
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100309cleanup
310