blob: 0f5713d701fb49af4ad80ad11b3d10346ff70964 [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é-Gonnard9bda9b32014-11-20 13:10:22 +01009# Assumes gcc and clang (recent enough for using ASan with gcc and MemSen with
10# clang) are available, as well as cmake and GNU 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
16 echo "Must be run from PolarSSL root" >&2
17 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é-Gonnard80955ee2014-03-19 18:29:01 +010028 MEMORY=1
29 ;;
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é-Gonnard80955ee2014-03-19 18:29:01 +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 "
61 echo -n "* "; 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é-Gonnard89d69b32014-11-20 13:48:53 +010073msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +010074cleanup
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +010075CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +010076make
77
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +010078msg "test: main suites and selftest (ASan build)" # ~ 50s
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +010079make test
80programs/test/selftest
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +020081
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +010082msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +020083cd tests
84./ssl-opt.sh
85cd ..
86
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +010087msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +020088tests/scripts/test-ref-configs.pl
89
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +010090# Most frequent issues are likely to be caught at this point
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +020091
92msg "build: with ASan (rebuild after ref-configs)" # ~ 1 min
93make
94
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +010095msg "test: compat.sh (ASan build)" # ~ 6 min
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +020096cd tests
97./compat.sh
98cd ..
99
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100100msg "build: cmake, full config, clang" # ~ 50s
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100101cleanup
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200102cp "$CONFIG_H" "$CONFIG_BAK"
103scripts/config.pl full
104scripts/config.pl unset POLARSSL_MEMORY_BACKTRACE # too slow for tests
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100105CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check .
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100106make
107
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100108msg "test: main suites (full config)" # ~ 5s
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200109make test
110
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100111msg "test: ssl-opt.sh default (full config)" # ~ 1s
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200112cd tests
113./ssl-opt.sh -f Default
114cd ..
115
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100116msg "test: compat.sh DES & NULL (full config)" # ~ 2 min
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200117cd tests
118./compat.sh -e '^$' -f 'NULL\|3DES-EDE-CBC\|DES-CBC3'
119cd ..
120
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +0100121msg "test/build: curves.pl (gcc)" # ~ 5 min (?)
122cleanup
123cmake -D CMAKE_BUILD_TYPE:String=Debug .
124tests/scripts/curves.pl
125
Manuel Pégourié-Gonnard61bc57a2014-08-14 11:29:06 +0200126msg "build: Unix make, -O2 (gcc)" # ~ 30s
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100127cleanup
Manuel Pégourié-Gonnard61bc57a2014-08-14 11:29:06 +0200128CC=gcc make
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100129
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100130msg "build: MSan (clang)" # ~ 1 min 20s
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100131cleanup
132cp "$CONFIG_H" "$CONFIG_BAK"
133scripts/config.pl unset POLARSSL_AESNI_C # memsan doesn't grok asm
134CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
135make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +0200136
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100137msg "test: main suites (MSan)" # ~ 10s
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100138make test
139
140msg "test: ssl-opt.sh (MSan)" # ~ 1 min
141cd tests
142./ssl-opt.sh
143cd ..
144
145# Optional part(s)
146
147if [ "$MEMORY" -gt 0 ]; then
148 msg "test: compat.sh (MSan)" # ~ 6 min 20s
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100149 cd tests
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100150 ./compat.sh
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100151 cd ..
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200152fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100153
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100154msg "Done, cleaning up"
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100155cleanup
156