Manuel Pégourié-Gonnard | 80955ee | 2014-03-19 18:29:01 +0100 | [diff] [blame] | 1 | #!/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é-Gonnard | 3895f5a | 2014-03-27 14:44:04 +0100 | [diff] [blame] | 8 | # |
Manuel Pégourié-Gonnard | 392d3dd | 2015-01-26 14:03:56 +0000 | [diff] [blame] | 9 | # Assumes gcc and clang (recent enough for using ASan with gcc and MemSan with |
| 10 | # clang, or valgrind) are available, as well as cmake and a "good" find. |
Manuel Pégourié-Gonnard | 80955ee | 2014-03-19 18:29:01 +0100 | [diff] [blame] | 11 | |
| 12 | # Abort on errors (and uninitiliased variables) |
| 13 | set -eu |
| 14 | |
| 15 | if [ -d library -a -d include -a -d tests ]; then :; else |
Manuel Pégourié-Gonnard | e4f6edc | 2015-01-22 16:43:54 +0000 | [diff] [blame] | 16 | echo "Must be run from mbed TLS root" >&2 |
Manuel Pégourié-Gonnard | 80955ee | 2014-03-19 18:29:01 +0100 | [diff] [blame] | 17 | exit 1 |
| 18 | fi |
| 19 | |
Manuel Pégourié-Gonnard | e73b263 | 2014-07-12 04:00:00 +0200 | [diff] [blame] | 20 | CONFIG_H='include/polarssl/config.h' |
| 21 | CONFIG_BAK="$CONFIG_H.bak" |
| 22 | |
Manuel Pégourié-Gonnard | 80955ee | 2014-03-19 18:29:01 +0100 | [diff] [blame] | 23 | MEMORY=0 |
| 24 | |
| 25 | while [ $# -gt 0 ]; do |
| 26 | case "$1" in |
Manuel Pégourié-Gonnard | 9bda9b3 | 2014-11-20 13:10:22 +0100 | [diff] [blame] | 27 | -m*) |
Manuel Pégourié-Gonnard | 392d3dd | 2015-01-26 14:03:56 +0000 | [diff] [blame] | 28 | MEMORY=${1#-m} |
Manuel Pégourié-Gonnard | 80955ee | 2014-03-19 18:29:01 +0100 | [diff] [blame] | 29 | ;; |
| 30 | *) |
| 31 | echo "Unknown argument: '$1'" >&2 |
| 32 | echo "Use the source, Luke!" >&2 |
| 33 | exit 1 |
| 34 | ;; |
| 35 | esac |
| 36 | shift |
| 37 | done |
| 38 | |
| 39 | # remove built files as well as the cmake cache/config |
| 40 | cleanup() |
| 41 | { |
| 42 | make clean |
Manuel Pégourié-Gonnard | e73b263 | 2014-07-12 04:00:00 +0200 | [diff] [blame] | 43 | |
Manuel Pégourié-Gonnard | 76c99a0 | 2014-12-11 10:33:43 +0100 | [diff] [blame] | 44 | find . -iname '*cmake*' -not -name CMakeLists.txt -exec rm -rf {} \+ |
Manuel Pégourié-Gonnard | 897a595 | 2014-03-25 13:23:04 +0100 | [diff] [blame] | 45 | rm -f include/Makefile include/polarssl/Makefile programs/*/Makefile |
Paul Bakker | fe0984d | 2014-06-13 00:13:45 +0200 | [diff] [blame] | 46 | 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é-Gonnard | e73b263 | 2014-07-12 04:00:00 +0200 | [diff] [blame] | 48 | |
| 49 | if [ -f "$CONFIG_BAK" ]; then |
| 50 | mv "$CONFIG_BAK" "$CONFIG_H" |
| 51 | fi |
Manuel Pégourié-Gonnard | 80955ee | 2014-03-19 18:29:01 +0100 | [diff] [blame] | 52 | } |
| 53 | |
Manuel Pégourié-Gonnard | e73b263 | 2014-07-12 04:00:00 +0200 | [diff] [blame] | 54 | trap cleanup INT TERM HUP |
| 55 | |
Manuel Pégourié-Gonnard | 3895f5a | 2014-03-27 14:44:04 +0100 | [diff] [blame] | 56 | msg() |
| 57 | { |
| 58 | echo "" |
| 59 | echo "******************************************************************" |
Manuel Pégourié-Gonnard | 9bda9b3 | 2014-11-20 13:10:22 +0100 | [diff] [blame] | 60 | echo "* $1 " |
Manuel Pégourié-Gonnard | 392d3dd | 2015-01-26 14:03:56 +0000 | [diff] [blame] | 61 | printf "* "; date |
Manuel Pégourié-Gonnard | 3895f5a | 2014-03-27 14:44:04 +0100 | [diff] [blame] | 62 | echo "******************************************************************" |
| 63 | } |
Manuel Pégourié-Gonnard | 80955ee | 2014-03-19 18:29:01 +0100 | [diff] [blame] | 64 | |
Manuel Pégourié-Gonnard | 57255b1 | 2014-06-09 11:21:49 +0200 | [diff] [blame] | 65 | # The test ordering tries to optimize for the following criteria: |
Manuel Pégourié-Gonnard | 89d69b3 | 2014-11-20 13:48:53 +0100 | [diff] [blame] | 66 | # 1. Catch possible problems early, by running first tests that run quickly |
Manuel Pégourié-Gonnard | 61bc57a | 2014-08-14 11:29:06 +0200 | [diff] [blame] | 67 | # 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é-Gonnard | 57255b1 | 2014-06-09 11:21:49 +0200 | [diff] [blame] | 69 | # 2. Minimize total running time, by avoiding useless rebuilds |
| 70 | # |
| 71 | # Indicative running times are given for reference. |
Manuel Pégourié-Gonnard | 80955ee | 2014-03-19 18:29:01 +0100 | [diff] [blame] | 72 | |
Manuel Pégourié-Gonnard | ea29d15 | 2014-11-20 17:32:33 +0100 | [diff] [blame] | 73 | msg "test: recursion.pl" # < 1s |
| 74 | scripts/recursion.pl library/*.c |
| 75 | |
Manuel Pégourié-Gonnard | 89d69b3 | 2014-11-20 13:48:53 +0100 | [diff] [blame] | 76 | msg "build: cmake, gcc, ASan" # ~ 1 min 50s |
Manuel Pégourié-Gonnard | 3895f5a | 2014-03-27 14:44:04 +0100 | [diff] [blame] | 77 | cleanup |
Manuel Pégourié-Gonnard | 9bda9b3 | 2014-11-20 13:10:22 +0100 | [diff] [blame] | 78 | CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan . |
Manuel Pégourié-Gonnard | 3895f5a | 2014-03-27 14:44:04 +0100 | [diff] [blame] | 79 | make |
| 80 | |
Manuel Pégourié-Gonnard | 89d69b3 | 2014-11-20 13:48:53 +0100 | [diff] [blame] | 81 | msg "test: main suites and selftest (ASan build)" # ~ 50s |
Manuel Pégourié-Gonnard | 9bda9b3 | 2014-11-20 13:10:22 +0100 | [diff] [blame] | 82 | make test |
| 83 | programs/test/selftest |
Manuel Pégourié-Gonnard | 57255b1 | 2014-06-09 11:21:49 +0200 | [diff] [blame] | 84 | |
Manuel Pégourié-Gonnard | 89d69b3 | 2014-11-20 13:48:53 +0100 | [diff] [blame] | 85 | msg "test: ssl-opt.sh (ASan build)" # ~ 1 min |
Manuel Pégourié-Gonnard | 57255b1 | 2014-06-09 11:21:49 +0200 | [diff] [blame] | 86 | cd tests |
| 87 | ./ssl-opt.sh |
| 88 | cd .. |
| 89 | |
Manuel Pégourié-Gonnard | 89d69b3 | 2014-11-20 13:48:53 +0100 | [diff] [blame] | 90 | msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s |
Manuel Pégourié-Gonnard | 57255b1 | 2014-06-09 11:21:49 +0200 | [diff] [blame] | 91 | tests/scripts/test-ref-configs.pl |
| 92 | |
Manuel Pégourié-Gonnard | 89d69b3 | 2014-11-20 13:48:53 +0100 | [diff] [blame] | 93 | # Most frequent issues are likely to be caught at this point |
Manuel Pégourié-Gonnard | 57255b1 | 2014-06-09 11:21:49 +0200 | [diff] [blame] | 94 | |
| 95 | msg "build: with ASan (rebuild after ref-configs)" # ~ 1 min |
| 96 | make |
| 97 | |
Manuel Pégourié-Gonnard | 89d69b3 | 2014-11-20 13:48:53 +0100 | [diff] [blame] | 98 | msg "test: compat.sh (ASan build)" # ~ 6 min |
Manuel Pégourié-Gonnard | 57255b1 | 2014-06-09 11:21:49 +0200 | [diff] [blame] | 99 | cd tests |
| 100 | ./compat.sh |
| 101 | cd .. |
| 102 | |
Manuel Pégourié-Gonnard | 89d69b3 | 2014-11-20 13:48:53 +0100 | [diff] [blame] | 103 | msg "build: cmake, full config, clang" # ~ 50s |
Manuel Pégourié-Gonnard | 3895f5a | 2014-03-27 14:44:04 +0100 | [diff] [blame] | 104 | cleanup |
Manuel Pégourié-Gonnard | e73b263 | 2014-07-12 04:00:00 +0200 | [diff] [blame] | 105 | cp "$CONFIG_H" "$CONFIG_BAK" |
| 106 | scripts/config.pl full |
| 107 | scripts/config.pl unset POLARSSL_MEMORY_BACKTRACE # too slow for tests |
Manuel Pégourié-Gonnard | 9bda9b3 | 2014-11-20 13:10:22 +0100 | [diff] [blame] | 108 | CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check . |
Manuel Pégourié-Gonnard | 3895f5a | 2014-03-27 14:44:04 +0100 | [diff] [blame] | 109 | make |
| 110 | |
Manuel Pégourié-Gonnard | 89d69b3 | 2014-11-20 13:48:53 +0100 | [diff] [blame] | 111 | msg "test: main suites (full config)" # ~ 5s |
Manuel Pégourié-Gonnard | e73b263 | 2014-07-12 04:00:00 +0200 | [diff] [blame] | 112 | make test |
| 113 | |
Manuel Pégourié-Gonnard | 89d69b3 | 2014-11-20 13:48:53 +0100 | [diff] [blame] | 114 | msg "test: ssl-opt.sh default (full config)" # ~ 1s |
Manuel Pégourié-Gonnard | e73b263 | 2014-07-12 04:00:00 +0200 | [diff] [blame] | 115 | cd tests |
| 116 | ./ssl-opt.sh -f Default |
| 117 | cd .. |
| 118 | |
Manuel Pégourié-Gonnard | 89d69b3 | 2014-11-20 13:48:53 +0100 | [diff] [blame] | 119 | msg "test: compat.sh DES & NULL (full config)" # ~ 2 min |
Manuel Pégourié-Gonnard | e73b263 | 2014-07-12 04:00:00 +0200 | [diff] [blame] | 120 | cd tests |
| 121 | ./compat.sh -e '^$' -f 'NULL\|3DES-EDE-CBC\|DES-CBC3' |
| 122 | cd .. |
| 123 | |
Manuel Pégourié-Gonnard | 246978d | 2014-11-20 13:29:53 +0100 | [diff] [blame] | 124 | msg "test/build: curves.pl (gcc)" # ~ 5 min (?) |
| 125 | cleanup |
| 126 | cmake -D CMAKE_BUILD_TYPE:String=Debug . |
| 127 | tests/scripts/curves.pl |
| 128 | |
Manuel Pégourié-Gonnard | 61bc57a | 2014-08-14 11:29:06 +0200 | [diff] [blame] | 129 | msg "build: Unix make, -O2 (gcc)" # ~ 30s |
Manuel Pégourié-Gonnard | 3895f5a | 2014-03-27 14:44:04 +0100 | [diff] [blame] | 130 | cleanup |
Manuel Pégourié-Gonnard | edb2dc9 | 2015-02-10 14:36:31 +0000 | [diff] [blame^] | 131 | CC=gcc CFLAGS=-Werror make |
Manuel Pégourié-Gonnard | 80955ee | 2014-03-19 18:29:01 +0100 | [diff] [blame] | 132 | |
Manuel Pégourié-Gonnard | edb2dc9 | 2015-02-10 14:36:31 +0000 | [diff] [blame^] | 133 | if uname -a | grep -F x86_64 >/dev/null; then |
| 134 | msg "build: i386, make, gcc" # ~ 30s |
| 135 | cleanup |
| 136 | CC=gcc CFLAGS='-Werror -m32' make |
| 137 | fi # x86_64 |
| 138 | |
| 139 | if which arm-none-eabi-gcc >/dev/null; then |
| 140 | msg "build: arm-none-eabi-gcc, make" # ~ 10s |
| 141 | cleanup |
| 142 | cp "$CONFIG_H" "$CONFIG_BAK" |
| 143 | scripts/config.pl full |
| 144 | scripts/config.pl unset POLARSSL_NET_C |
| 145 | scripts/config.pl unset POLARSSL_TIMING_C |
| 146 | scripts/config.pl unset POLARSSL_FS_IO |
| 147 | # following things are not in the default config |
| 148 | scripts/config.pl unset POLARSSL_HAVEGE_C # depends on timing.c |
| 149 | scripts/config.pl unset POLARSSL_THREADING_PTHREAD |
| 150 | scripts/config.pl unset POLARSSL_THREADING_C |
| 151 | scripts/config.pl unset POLARSSL_MEMORY_BACKTRACE # execinfo.h |
| 152 | scripts/config.pl unset POLARSSL_MEMORY_BUFFER_ALLOC_C # calls exit |
| 153 | CC=arm-none-eabi-gcc CFLAGS=-Werror make lib |
| 154 | fi # arm-gcc |
| 155 | |
| 156 | # MemSan currently only available on Linux 64 bits |
| 157 | if uname -a | grep 'Linux.*x86_64' >/dev/null; then |
Manuel Pégourié-Gonnard | 392d3dd | 2015-01-26 14:03:56 +0000 | [diff] [blame] | 158 | |
Manuel Pégourié-Gonnard | 89d69b3 | 2014-11-20 13:48:53 +0100 | [diff] [blame] | 159 | msg "build: MSan (clang)" # ~ 1 min 20s |
Manuel Pégourié-Gonnard | 9bda9b3 | 2014-11-20 13:10:22 +0100 | [diff] [blame] | 160 | cleanup |
| 161 | cp "$CONFIG_H" "$CONFIG_BAK" |
| 162 | scripts/config.pl unset POLARSSL_AESNI_C # memsan doesn't grok asm |
Manuel Pégourié-Gonnard | 1e77a96 | 2015-01-26 14:11:51 +0100 | [diff] [blame] | 163 | scripts/config.pl set POLARSSL_NO_PLATFORM_ENTROPY # memsan vs getrandom() |
Manuel Pégourié-Gonnard | 9bda9b3 | 2014-11-20 13:10:22 +0100 | [diff] [blame] | 164 | CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan . |
| 165 | make |
Manuel Pégourié-Gonnard | 4a9dc2a | 2014-05-09 13:46:59 +0200 | [diff] [blame] | 166 | |
Manuel Pégourié-Gonnard | 89d69b3 | 2014-11-20 13:48:53 +0100 | [diff] [blame] | 167 | msg "test: main suites (MSan)" # ~ 10s |
Manuel Pégourié-Gonnard | 9bda9b3 | 2014-11-20 13:10:22 +0100 | [diff] [blame] | 168 | make test |
| 169 | |
| 170 | msg "test: ssl-opt.sh (MSan)" # ~ 1 min |
| 171 | cd tests |
| 172 | ./ssl-opt.sh |
| 173 | cd .. |
| 174 | |
| 175 | # Optional part(s) |
| 176 | |
| 177 | if [ "$MEMORY" -gt 0 ]; then |
| 178 | msg "test: compat.sh (MSan)" # ~ 6 min 20s |
Manuel Pégourié-Gonnard | 80955ee | 2014-03-19 18:29:01 +0100 | [diff] [blame] | 179 | cd tests |
Manuel Pégourié-Gonnard | 9bda9b3 | 2014-11-20 13:10:22 +0100 | [diff] [blame] | 180 | ./compat.sh |
Manuel Pégourié-Gonnard | 80955ee | 2014-03-19 18:29:01 +0100 | [diff] [blame] | 181 | cd .. |
Manuel Pégourié-Gonnard | 57255b1 | 2014-06-09 11:21:49 +0200 | [diff] [blame] | 182 | fi |
Manuel Pégourié-Gonnard | 80955ee | 2014-03-19 18:29:01 +0100 | [diff] [blame] | 183 | |
Manuel Pégourié-Gonnard | 392d3dd | 2015-01-26 14:03:56 +0000 | [diff] [blame] | 184 | else # no MemSan |
| 185 | |
| 186 | msg "build: Release (clang)" |
| 187 | cleanup |
| 188 | CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release . |
| 189 | make |
| 190 | |
| 191 | msg "test: main suites valgrind (Release)" |
| 192 | make test |
| 193 | |
| 194 | # Optional part(s) |
| 195 | # Currently broken, programs don't seem to receive signals |
| 196 | # under valgrind on OS X |
| 197 | |
| 198 | if [ "$MEMORY" -gt 0 ]; then |
| 199 | msg "test: ssl-opt.sh --memcheck (Release)" |
| 200 | cd tests |
| 201 | ./ssl-opt.sh --memcheck |
| 202 | cd .. |
| 203 | fi |
| 204 | |
| 205 | if [ "$MEMORY" -gt 1 ]; then |
| 206 | msg "test: compat.sh --memcheck (Release)" |
| 207 | cd tests |
| 208 | ./compat.sh --memcheck |
| 209 | cd .. |
| 210 | fi |
| 211 | |
| 212 | fi # MemSan |
| 213 | |
Manuel Pégourié-Gonnard | 9bda9b3 | 2014-11-20 13:10:22 +0100 | [diff] [blame] | 214 | msg "Done, cleaning up" |
Manuel Pégourié-Gonnard | 80955ee | 2014-03-19 18:29:01 +0100 | [diff] [blame] | 215 | cleanup |
| 216 | |