blob: fad039c10bb88079cdc8363f6a76a72a3a673744 [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é-Gonnard57255b12014-06-09 11:21:49 +02009# Assumes gcc and clang (recent enough for using ASan) are available,
10# as well as cmake and valgrind.
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é-Gonnard4a9dc2a2014-05-09 13:46:59 +020027 -m1)
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010028 MEMORY=1
29 ;;
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +020030 -m2)
31 MEMORY=2
32 ;;
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010033 *)
34 echo "Unknown argument: '$1'" >&2
35 echo "Use the source, Luke!" >&2
36 exit 1
37 ;;
38 esac
39 shift
40done
41
42# remove built files as well as the cmake cache/config
43cleanup()
44{
45 make clean
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +020046
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010047 find -iname '*cmake*' -not -name CMakeLists.txt -exec rm -rf {} \+
Manuel Pégourié-Gonnard897a5952014-03-25 13:23:04 +010048 rm -f include/Makefile include/polarssl/Makefile programs/*/Makefile
Paul Bakkerfe0984d2014-06-13 00:13:45 +020049 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile
50 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +020051
52 if [ -f "$CONFIG_BAK" ]; then
53 mv "$CONFIG_BAK" "$CONFIG_H"
54 fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010055}
56
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +020057trap cleanup INT TERM HUP
58
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +010059msg()
60{
61 echo ""
62 echo "******************************************************************"
63 echo "* $1"
64 echo "******************************************************************"
65}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010066
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +020067# The test ordering tries to optimize for the following criteria:
68# 1. Catch possible problems early, by running first test that run quickly
69# and/or are more likely to fail than others.
70# 2. Minimize total running time, by avoiding useless rebuilds
71#
72# Indicative running times are given for reference.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010073
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +020074msg "build: cmake, gcc with lots of warnings" # ~ 1 min
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +010075cleanup
76CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Check .
77make
78
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +020079msg "test: main suites with valgrind" # ~ 2 min 10s
80make memcheck
81
82msg "build: with ASan" # ~ 1 min
83cleanup
84cmake -D CMAKE_BUILD_TYPE:String=ASan .
85make
86
87msg "test: ssl-opt.sh (ASan build)" # ~ 1 min 10s
88cd tests
89./ssl-opt.sh
90cd ..
91
92msg "test: main suites and selftest (ASan build)" # ~ 10s + 30s
93make test
94programs/test/selftest
95
96msg "test: ref-configs (ASan build)" # ~ 4 min 45 s
97tests/scripts/test-ref-configs.pl
98
99# Most issues are likely to be caught at this point
100
101msg "build: with ASan (rebuild after ref-configs)" # ~ 1 min
102make
103
104msg "test: compat.sh (ASan build)" # ~ 7 min 30s
105cd tests
106./compat.sh
107cd ..
108
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200109msg "build: cmake, full config, clang with lots of warnings" # ~ 40s
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100110cleanup
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200111cp "$CONFIG_H" "$CONFIG_BAK"
112scripts/config.pl full
113scripts/config.pl unset POLARSSL_MEMORY_BACKTRACE # too slow for tests
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100114CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check .
115make
116
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200117msg "test: main suites (full config)"
118make test
119
120msg "test: ssl-opt.sh default (full config)"
121cd tests
122./ssl-opt.sh -f Default
123cd ..
124
125msg "test: compat.sh 3DES & NULL (full config)"
126cd tests
127./compat.sh -e '^$' -f 'NULL\|3DES-EDE-CBC\|DES-CBC3'
128cd ..
129
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200130msg "build: Unix make, -O2" # ~ 30s
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100131cleanup
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100132make
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100133
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200134# Optional parts that take a long time to run
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +0200135
136if [ "$MEMORY" -gt 0 ]; then
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200137 msg "test: ssl-opt --memcheck (-02 build)" # ~ 8 min
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100138 cd tests
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100139 ./ssl-opt.sh --memcheck
140 cd ..
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100141
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200142 if [ "$MEMORY" -gt 1 ]; then
143 msg "test: compat --memcheck (-02 build)" # ~ 42 min
144 cd tests
145 ./compat.sh --memcheck
146 cd ..
147 fi
148fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100149
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100150echo "Done."
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100151cleanup
152