blob: 38ea62870c4555eb2eb2c1afb5427a77ce9b0475 [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
Manuel Pégourié-Gonnard61bc57a2014-08-14 11:29:06 +020069# and/or are more likely to fail than others (eg I use Clang most of the
70# time, so start with a GCC build).
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +020071# 2. Minimize total running time, by avoiding useless rebuilds
72#
73# Indicative running times are given for reference.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010074
Manuel Pégourié-Gonnard61bc57a2014-08-14 11:29:06 +020075msg "build: cmake, -Werror (gcc)" # ~ 1 min
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +010076cleanup
77CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Check .
78make
79
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +020080msg "test: main suites with valgrind" # ~ 2 min 10s
81make memcheck
82
Manuel Pégourié-Gonnard61bc57a2014-08-14 11:29:06 +020083msg "build: with ASan (clang)" # ~ 1 min
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +020084cleanup
Manuel Pégourié-Gonnard61bc57a2014-08-14 11:29:06 +020085CC=clang cmake -D CMAKE_BUILD_TYPE:String=ASan .
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +020086make
87
88msg "test: ssl-opt.sh (ASan build)" # ~ 1 min 10s
89cd tests
90./ssl-opt.sh
91cd ..
92
93msg "test: main suites and selftest (ASan build)" # ~ 10s + 30s
94make test
95programs/test/selftest
96
97msg "test: ref-configs (ASan build)" # ~ 4 min 45 s
98tests/scripts/test-ref-configs.pl
99
100# Most issues are likely to be caught at this point
101
102msg "build: with ASan (rebuild after ref-configs)" # ~ 1 min
103make
104
105msg "test: compat.sh (ASan build)" # ~ 7 min 30s
106cd tests
107./compat.sh
108cd ..
109
Manuel Pégourié-Gonnard61bc57a2014-08-14 11:29:06 +0200110msg "build: cmake, full config" # ~ 40s
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100111cleanup
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200112cp "$CONFIG_H" "$CONFIG_BAK"
113scripts/config.pl full
114scripts/config.pl unset POLARSSL_MEMORY_BACKTRACE # too slow for tests
Manuel Pégourié-Gonnard61bc57a2014-08-14 11:29:06 +0200115cmake -D CMAKE_BUILD_TYPE:String=Check .
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100116make
117
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200118msg "test: main suites (full config)"
119make test
120
121msg "test: ssl-opt.sh default (full config)"
122cd tests
123./ssl-opt.sh -f Default
124cd ..
125
126msg "test: compat.sh 3DES & NULL (full config)"
127cd tests
128./compat.sh -e '^$' -f 'NULL\|3DES-EDE-CBC\|DES-CBC3'
129cd ..
130
Manuel Pégourié-Gonnard61bc57a2014-08-14 11:29:06 +0200131msg "build: Unix make, -O2 (gcc)" # ~ 30s
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100132cleanup
Manuel Pégourié-Gonnard61bc57a2014-08-14 11:29:06 +0200133CC=gcc make
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100134
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200135# Optional parts that take a long time to run
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +0200136
Manuel Pégourié-Gonnard61bc57a2014-08-14 11:29:06 +0200137if [ "$MEMORY" -ge 1 ]; then
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200138 msg "test: ssl-opt --memcheck (-02 build)" # ~ 8 min
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100139 cd tests
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100140 ./ssl-opt.sh --memcheck
141 cd ..
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100142
Manuel Pégourié-Gonnard61bc57a2014-08-14 11:29:06 +0200143 if [ "$MEMORY" -ge 2 ]; then
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200144 msg "test: compat --memcheck (-02 build)" # ~ 42 min
145 cd tests
146 ./compat.sh --memcheck
147 cd ..
148 fi
149fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100150
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100151echo "Done."
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100152cleanup
153