blob: 7430b3888f43fe6832ccb4e6f320a72f4dbbf639 [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é-Gonnard89d69b32014-11-20 13:48:53 +010076msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +010077cleanup
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +010078CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +010079make
80
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +010081msg "test: main suites and selftest (ASan build)" # ~ 50s
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +010082make test
83programs/test/selftest
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +020084
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +010085msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +020086cd tests
87./ssl-opt.sh
88cd ..
89
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +010090msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +020091tests/scripts/test-ref-configs.pl
92
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +010093# Most frequent issues are likely to be caught at this point
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +020094
95msg "build: with ASan (rebuild after ref-configs)" # ~ 1 min
96make
97
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +010098msg "test: compat.sh (ASan build)" # ~ 6 min
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +020099cd tests
100./compat.sh
101cd ..
102
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100103msg "build: cmake, full config, clang" # ~ 50s
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100104cleanup
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200105cp "$CONFIG_H" "$CONFIG_BAK"
106scripts/config.pl full
107scripts/config.pl unset POLARSSL_MEMORY_BACKTRACE # too slow for tests
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100108CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check .
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100109make
110
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100111msg "test: main suites (full config)" # ~ 5s
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200112make test
113
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100114msg "test: ssl-opt.sh default (full config)" # ~ 1s
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200115cd tests
116./ssl-opt.sh -f Default
117cd ..
118
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100119msg "test: compat.sh DES & NULL (full config)" # ~ 2 min
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200120cd tests
121./compat.sh -e '^$' -f 'NULL\|3DES-EDE-CBC\|DES-CBC3'
122cd ..
123
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +0100124msg "test/build: curves.pl (gcc)" # ~ 5 min (?)
125cleanup
126cmake -D CMAKE_BUILD_TYPE:String=Debug .
127tests/scripts/curves.pl
128
Manuel Pégourié-Gonnard61bc57a2014-08-14 11:29:06 +0200129msg "build: Unix make, -O2 (gcc)" # ~ 30s
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100130cleanup
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000131CC=gcc CFLAGS=-Werror make
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100132
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000133if uname -a | grep -F x86_64 >/dev/null; then
134msg "build: i386, make, gcc" # ~ 30s
135cleanup
136CC=gcc CFLAGS='-Werror -m32' make
137fi # x86_64
138
139if which arm-none-eabi-gcc >/dev/null; then
140msg "build: arm-none-eabi-gcc, make" # ~ 10s
141cleanup
142cp "$CONFIG_H" "$CONFIG_BAK"
143scripts/config.pl full
144scripts/config.pl unset POLARSSL_NET_C
145scripts/config.pl unset POLARSSL_TIMING_C
146scripts/config.pl unset POLARSSL_FS_IO
147# following things are not in the default config
148scripts/config.pl unset POLARSSL_HAVEGE_C # depends on timing.c
149scripts/config.pl unset POLARSSL_THREADING_PTHREAD
150scripts/config.pl unset POLARSSL_THREADING_C
151scripts/config.pl unset POLARSSL_MEMORY_BACKTRACE # execinfo.h
152scripts/config.pl unset POLARSSL_MEMORY_BUFFER_ALLOC_C # calls exit
153CC=arm-none-eabi-gcc CFLAGS=-Werror make lib
154fi # arm-gcc
155
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +0100156if which armcc >/dev/null; then
157msg "build: armcc, make"
158cleanup
159cp "$CONFIG_H" "$CONFIG_BAK"
160scripts/config.pl full
161scripts/config.pl unset POLARSSL_NET_C
162scripts/config.pl unset POLARSSL_TIMING_C
163scripts/config.pl unset POLARSSL_FS_IO
164scripts/config.pl unset POLARSSL_HAVE_TIME
165# following things are not in the default config
166scripts/config.pl unset POLARSSL_HAVEGE_C # depends on timing.c
167scripts/config.pl unset POLARSSL_THREADING_PTHREAD
168scripts/config.pl unset POLARSSL_THREADING_C
169scripts/config.pl unset POLARSSL_MEMORY_BACKTRACE # execinfo.h
170scripts/config.pl unset POLARSSL_MEMORY_BUFFER_ALLOC_C # calls exit
171CC=arm-none-eabi-gcc CFLAGS=-Werror make lib 2> armcc.stderr
172grep -v '^ar: creating' armcc.stderr || exit 1
173rm armcc.stderr
174fi # armcc
175
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000176# MemSan currently only available on Linux 64 bits
177if uname -a | grep 'Linux.*x86_64' >/dev/null; then
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000178
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100179msg "build: MSan (clang)" # ~ 1 min 20s
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100180cleanup
181cp "$CONFIG_H" "$CONFIG_BAK"
182scripts/config.pl unset POLARSSL_AESNI_C # memsan doesn't grok asm
Manuel Pégourié-Gonnard1e77a962015-01-26 14:11:51 +0100183scripts/config.pl set POLARSSL_NO_PLATFORM_ENTROPY # memsan vs getrandom()
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100184CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
185make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +0200186
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100187msg "test: main suites (MSan)" # ~ 10s
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100188make test
189
190msg "test: ssl-opt.sh (MSan)" # ~ 1 min
191cd tests
192./ssl-opt.sh
193cd ..
194
195# Optional part(s)
196
197if [ "$MEMORY" -gt 0 ]; then
198 msg "test: compat.sh (MSan)" # ~ 6 min 20s
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100199 cd tests
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100200 ./compat.sh
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100201 cd ..
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200202fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100203
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000204else # no MemSan
205
206msg "build: Release (clang)"
207cleanup
208CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
209make
210
211msg "test: main suites valgrind (Release)"
212make test
213
214# Optional part(s)
215# Currently broken, programs don't seem to receive signals
216# under valgrind on OS X
217
218if [ "$MEMORY" -gt 0 ]; then
219 msg "test: ssl-opt.sh --memcheck (Release)"
220 cd tests
221 ./ssl-opt.sh --memcheck
222 cd ..
223fi
224
225if [ "$MEMORY" -gt 1 ]; then
226 msg "test: compat.sh --memcheck (Release)"
227 cd tests
228 ./compat.sh --memcheck
229 cd ..
230fi
231
232fi # MemSan
233
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100234msg "Done, cleaning up"
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100235cleanup
236