blob: 28e13668560da6f4b78242191585bdc7c436fd3e [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:
66# 1. Catch possible problems early, by running first test 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é-Gonnard9bda9b32014-11-20 13:10:22 +010073msg "build: cmake, gcc, ASan" # ~ 1 min
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é-Gonnard9bda9b32014-11-20 13:10:22 +010078msg "test: main suites and selftest (ASan build)" # ~ 10s + 30s
79make test
80programs/test/selftest
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +020081
82msg "test: ssl-opt.sh (ASan build)" # ~ 1 min 10s
83cd tests
84./ssl-opt.sh
85cd ..
86
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +020087msg "test: ref-configs (ASan build)" # ~ 4 min 45 s
88tests/scripts/test-ref-configs.pl
89
90# Most issues are likely to be caught at this point
91
92msg "build: with ASan (rebuild after ref-configs)" # ~ 1 min
93make
94
95msg "test: compat.sh (ASan build)" # ~ 7 min 30s
96cd tests
97./compat.sh
98cd ..
99
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100100msg "build: cmake, full config, clang" # ~ 40s
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é-Gonnard9bda9b32014-11-20 13:10:22 +0100108msg "test: main suites (full config)" # ~ 30s (?)
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200109make test
110
111msg "test: ssl-opt.sh default (full config)"
112cd tests
113./ssl-opt.sh -f Default
114cd ..
115
116msg "test: compat.sh 3DES & NULL (full config)"
117cd tests
118./compat.sh -e '^$' -f 'NULL\|3DES-EDE-CBC\|DES-CBC3'
119cd ..
120
Manuel Pégourié-Gonnard61bc57a2014-08-14 11:29:06 +0200121msg "build: Unix make, -O2 (gcc)" # ~ 30s
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100122cleanup
Manuel Pégourié-Gonnard61bc57a2014-08-14 11:29:06 +0200123CC=gcc make
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100124
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100125msg "build: MSan (clang)" # ~ 1 min 30s
126cleanup
127cp "$CONFIG_H" "$CONFIG_BAK"
128scripts/config.pl unset POLARSSL_AESNI_C # memsan doesn't grok asm
129CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
130make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +0200131
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100132msg "test: main suites (MSan)" # ~ 15s
133make test
134
135msg "test: ssl-opt.sh (MSan)" # ~ 1 min
136cd tests
137./ssl-opt.sh
138cd ..
139
140# Optional part(s)
141
142if [ "$MEMORY" -gt 0 ]; then
143 msg "test: compat.sh (MSan)" # ~ 6 min 20s
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100144 cd tests
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100145 ./compat.sh
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100146 cd ..
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200147fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100148
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100149msg "Done, cleaning up"
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100150cleanup
151