blob: b29e07a1377bde0eb31710780a21a180537633a7 [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é-Gonnard76c99a02014-12-11 10:33:43 +010044 find . -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é-Gonnard89d69b32014-11-20 13:48:53 +010086msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +010087cleanup
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +010088CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +010089make
90
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +010091msg "test: main suites and selftest (ASan build)" # ~ 50s
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +010092make test
93programs/test/selftest
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +020094
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +010095msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +020096cd tests
97./ssl-opt.sh
98cd ..
99
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100100msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200101tests/scripts/test-ref-configs.pl
102
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100103# Most frequent issues are likely to be caught at this point
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200104
105msg "build: with ASan (rebuild after ref-configs)" # ~ 1 min
106make
107
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100108msg "test: compat.sh (ASan build)" # ~ 6 min
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200109cd tests
110./compat.sh
111cd ..
112
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100113msg "build: cmake, full config, clang" # ~ 50s
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100114cleanup
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200115cp "$CONFIG_H" "$CONFIG_BAK"
116scripts/config.pl full
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200117scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100118CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check .
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100119make
120
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100121msg "test: main suites (full config)" # ~ 5s
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200122make test
123
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100124msg "test: ssl-opt.sh default (full config)" # ~ 1s
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200125cd tests
126./ssl-opt.sh -f Default
127cd ..
128
Manuel Pégourié-Gonnardea0920f2015-03-24 09:50:15 +0100129msg "test: compat.sh RC4, DES & NULL (full config)" # ~ 2 min
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200130cd tests
Manuel Pégourié-Gonnardea0920f2015-03-24 09:50:15 +0100131./compat.sh -e '3DES\|DES-CBC3' -f 'NULL\|DES\|RC4\|ARCFOUR'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200132cd ..
133
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +0100134msg "test/build: curves.pl (gcc)" # ~ 5 min (?)
135cleanup
136cmake -D CMAKE_BUILD_TYPE:String=Debug .
137tests/scripts/curves.pl
138
Manuel Pégourié-Gonnard61fe8b02015-03-13 14:33:16 +0000139msg "build: Unix make, -Os (gcc)" # ~ 30s
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100140cleanup
Manuel Pégourié-Gonnard61fe8b02015-03-13 14:33:16 +0000141CC=gcc CFLAGS='-Werror -Os' make
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100142
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200143# this is meant to cath missing #define mbedtls_printf etc
Manuel Pégourié-Gonnard981732b2015-02-17 15:46:45 +0000144# disable fsio to catch some more missing #include <stdio.h>
Manuel Pégourié-Gonnard757ca002015-03-23 15:24:07 +0100145msg "build: full config except platform/fsio, make, gcc" # ~ 30s
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +0000146cleanup
147cp "$CONFIG_H" "$CONFIG_BAK"
148scripts/config.pl full
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200149scripts/config.pl unset MBEDTLS_PLATFORM_C
150scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
151scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
152scripts/config.pl unset MBEDTLS_FS_IO
Manuel Pégourié-Gonnard61fe8b02015-03-13 14:33:16 +0000153CC=gcc CFLAGS='-Werror -O0' make
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +0000154
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000155if uname -a | grep -F x86_64 >/dev/null; then
156msg "build: i386, make, gcc" # ~ 30s
157cleanup
158CC=gcc CFLAGS='-Werror -m32' make
159fi # x86_64
160
161if which arm-none-eabi-gcc >/dev/null; then
162msg "build: arm-none-eabi-gcc, make" # ~ 10s
163cleanup
164cp "$CONFIG_H" "$CONFIG_BAK"
165scripts/config.pl full
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200166scripts/config.pl unset MBEDTLS_NET_C
167scripts/config.pl unset MBEDTLS_TIMING_C
168scripts/config.pl unset MBEDTLS_FS_IO
169scripts/config.pl unset MBEDTLS_SSL_PROTO_DTLS # timing.c
170scripts/config.pl unset MBEDTLS_SSL_DTLS_ANTI_REPLAY
171scripts/config.pl unset MBEDTLS_SSL_DTLS_HELLO_VERIFY
172scripts/config.pl unset MBEDTLS_SSL_DTLS_BADMAC_LIMIT
173scripts/config.pl unset MBEDTLS_SSL_COOKIE_C
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000174# following things are not in the default config
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200175scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
176scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
177scripts/config.pl unset MBEDTLS_THREADING_C
178scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
179scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000180CC=arm-none-eabi-gcc CFLAGS=-Werror make lib
181fi # arm-gcc
182
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +0100183if which armcc >/dev/null; then
184msg "build: armcc, make"
185cleanup
186cp "$CONFIG_H" "$CONFIG_BAK"
187scripts/config.pl full
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200188scripts/config.pl unset MBEDTLS_NET_C
189scripts/config.pl unset MBEDTLS_TIMING_C
190scripts/config.pl unset MBEDTLS_FS_IO
191scripts/config.pl unset MBEDTLS_HAVE_TIME
192scripts/config.pl unset MBEDTLS_SSL_PROTO_DTLS # timing.c
193scripts/config.pl unset MBEDTLS_SSL_DTLS_ANTI_REPLAY
194scripts/config.pl unset MBEDTLS_SSL_DTLS_HELLO_VERIFY
195scripts/config.pl unset MBEDTLS_SSL_DTLS_BADMAC_LIMIT
196scripts/config.pl unset MBEDTLS_SSL_COOKIE_C
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +0100197# following things are not in the default config
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200198scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
199scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
200scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
201scripts/config.pl unset MBEDTLS_THREADING_C
202scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
203scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
Manuel Pégourié-Gonnard129e4132015-03-13 17:29:18 +0100204CC=armcc WARNING_CFLAGS= make lib 2> armcc.stderr
205if [ -s armcc.stderr ]; then
206 cat armcc.stderr
207 exit 1;
208fi
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +0100209rm armcc.stderr
210fi # armcc
211
Manuel Pégourié-Gonnard6448bce2015-02-16 17:18:36 +0100212if which i686-w64-mingw32-gcc >/dev/null; then
213msg "build: cross-mingw64, make" # ~ 30s
214cleanup
215CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar CFLAGS=-Werror WINDOWS_BUILD=1 make
216fi
217
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000218# MemSan currently only available on Linux 64 bits
219if uname -a | grep 'Linux.*x86_64' >/dev/null; then
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000220
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100221msg "build: MSan (clang)" # ~ 1 min 20s
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100222cleanup
223cp "$CONFIG_H" "$CONFIG_BAK"
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200224scripts/config.pl unset MBEDTLS_AESNI_C # memsan doesn't grok asm
225scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY # memsan vs getrandom()
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100226CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
227make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +0200228
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100229msg "test: main suites (MSan)" # ~ 10s
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100230make test
231
232msg "test: ssl-opt.sh (MSan)" # ~ 1 min
233cd tests
234./ssl-opt.sh
235cd ..
236
237# Optional part(s)
238
239if [ "$MEMORY" -gt 0 ]; then
240 msg "test: compat.sh (MSan)" # ~ 6 min 20s
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100241 cd tests
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100242 ./compat.sh
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100243 cd ..
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200244fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100245
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000246else # no MemSan
247
248msg "build: Release (clang)"
249cleanup
250CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
251make
252
253msg "test: main suites valgrind (Release)"
254make test
255
256# Optional part(s)
257# Currently broken, programs don't seem to receive signals
258# under valgrind on OS X
259
260if [ "$MEMORY" -gt 0 ]; then
261 msg "test: ssl-opt.sh --memcheck (Release)"
262 cd tests
263 ./ssl-opt.sh --memcheck
264 cd ..
265fi
266
267if [ "$MEMORY" -gt 1 ]; then
268 msg "test: compat.sh --memcheck (Release)"
269 cd tests
270 ./compat.sh --memcheck
271 cd ..
272fi
273
274fi # MemSan
275
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100276msg "Done, cleaning up"
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100277cleanup
278