blob: 1e11d78c8f18a027c7e6a0d0080fc2c1cc7f1063 [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#
9# Assumes gcc, clang (recent enough for using ASan) are available, as weel as
10# cmake. Also assumes valgrind is available if --memcheck is used.
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
20MEMORY=0
21
22while [ $# -gt 0 ]; do
23 case "$1" in
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +020024 -m1)
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010025 MEMORY=1
26 ;;
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +020027 -m2)
28 MEMORY=2
29 ;;
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010030 *)
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
43 find -iname '*cmake*' -not -name CMakeLists.txt -exec rm -rf {} \+
Manuel Pégourié-Gonnard897a5952014-03-25 13:23:04 +010044 rm -f include/Makefile include/polarssl/Makefile programs/*/Makefile
45 git update-index --no-skip-worktree {.,library,programs,tests}/Makefile
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010046 git checkout -- {.,library,programs,tests}/Makefile
47}
48
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +010049msg()
50{
51 echo ""
52 echo "******************************************************************"
53 echo "* $1"
54 echo "******************************************************************"
55}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010056
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +010057# Step 1: various build types
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010058
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +010059msg "Unix make, default compiler and flags"
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010060cleanup
61make
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +010062
63msg "cmake, gcc with lots of warnings"
64cleanup
65CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Check .
66make
67
68msg "cmake, clang with lots of warnings"
69cleanup
70CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check .
71make
72
73# Step 2: Full tests, with ASan
74
75msg "ASan build and full tests"
76cleanup
77cmake -D CMAKE_BUILD_TYPE:String=ASan .
78make
79make test
Manuel Pégourié-Gonnard2be0b522014-03-27 20:16:07 +010080programs/test/selftest
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010081cd tests
82./compat.sh
83./ssl-opt.sh
84cd ..
85tests/scripts/test-ref-configs.pl
86
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010087# Step 3: using valgrind's memcheck
88
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +020089msg "Release build, test suites with valgrind's memcheck"
90cleanup
91# optimized build to compensate a bit for valgrind slowdown
92cmake -D CMAKE_BUILD_TYPE:String=Release .
93make
94make memcheck
95
96if [ "$MEMORY" -gt 0 ]; then
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010097 cd tests
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010098 ./ssl-opt.sh --memcheck
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +020099 [ "$MEMORY" -gt 1 ] && ./compat.sh --memcheck
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100100 cd ..
101 # no test-ref-configs: doesn't have a memcheck option (yet?)
102fi
103
104# Done
105
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100106echo "Done."
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100107cleanup
108