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 | 57255b1 | 2014-06-09 11:21:49 +0200 | [diff] [blame] | 9 | # Assumes gcc and clang (recent enough for using ASan) are available, |
| 10 | # as well as cmake and valgrind. |
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 |
| 16 | echo "Must be run from PolarSSL root" >&2 |
| 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 | 4a9dc2a | 2014-05-09 13:46:59 +0200 | [diff] [blame] | 27 | -m1) |
Manuel Pégourié-Gonnard | 80955ee | 2014-03-19 18:29:01 +0100 | [diff] [blame] | 28 | MEMORY=1 |
| 29 | ;; |
Manuel Pégourié-Gonnard | 4a9dc2a | 2014-05-09 13:46:59 +0200 | [diff] [blame] | 30 | -m2) |
| 31 | MEMORY=2 |
| 32 | ;; |
Manuel Pégourié-Gonnard | 80955ee | 2014-03-19 18:29:01 +0100 | [diff] [blame] | 33 | *) |
| 34 | echo "Unknown argument: '$1'" >&2 |
| 35 | echo "Use the source, Luke!" >&2 |
| 36 | exit 1 |
| 37 | ;; |
| 38 | esac |
| 39 | shift |
| 40 | done |
| 41 | |
| 42 | # remove built files as well as the cmake cache/config |
| 43 | cleanup() |
| 44 | { |
| 45 | make clean |
Manuel Pégourié-Gonnard | e73b263 | 2014-07-12 04:00:00 +0200 | [diff] [blame] | 46 | |
Manuel Pégourié-Gonnard | 80955ee | 2014-03-19 18:29:01 +0100 | [diff] [blame] | 47 | find -iname '*cmake*' -not -name CMakeLists.txt -exec rm -rf {} \+ |
Manuel Pégourié-Gonnard | 897a595 | 2014-03-25 13:23:04 +0100 | [diff] [blame] | 48 | rm -f include/Makefile include/polarssl/Makefile programs/*/Makefile |
Paul Bakker | fe0984d | 2014-06-13 00:13:45 +0200 | [diff] [blame] | 49 | 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é-Gonnard | e73b263 | 2014-07-12 04:00:00 +0200 | [diff] [blame] | 51 | |
| 52 | if [ -f "$CONFIG_BAK" ]; then |
| 53 | mv "$CONFIG_BAK" "$CONFIG_H" |
| 54 | fi |
Manuel Pégourié-Gonnard | 80955ee | 2014-03-19 18:29:01 +0100 | [diff] [blame] | 55 | } |
| 56 | |
Manuel Pégourié-Gonnard | e73b263 | 2014-07-12 04:00:00 +0200 | [diff] [blame] | 57 | trap cleanup INT TERM HUP |
| 58 | |
Manuel Pégourié-Gonnard | 3895f5a | 2014-03-27 14:44:04 +0100 | [diff] [blame] | 59 | msg() |
| 60 | { |
| 61 | echo "" |
| 62 | echo "******************************************************************" |
| 63 | echo "* $1" |
| 64 | echo "******************************************************************" |
| 65 | } |
Manuel Pégourié-Gonnard | 80955ee | 2014-03-19 18:29:01 +0100 | [diff] [blame] | 66 | |
Manuel Pégourié-Gonnard | 57255b1 | 2014-06-09 11:21:49 +0200 | [diff] [blame] | 67 | # 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é-Gonnard | 61bc57a | 2014-08-14 11:29:06 +0200 | [diff] [blame] | 69 | # 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é-Gonnard | 57255b1 | 2014-06-09 11:21:49 +0200 | [diff] [blame] | 71 | # 2. Minimize total running time, by avoiding useless rebuilds |
| 72 | # |
| 73 | # Indicative running times are given for reference. |
Manuel Pégourié-Gonnard | 80955ee | 2014-03-19 18:29:01 +0100 | [diff] [blame] | 74 | |
Manuel Pégourié-Gonnard | 61bc57a | 2014-08-14 11:29:06 +0200 | [diff] [blame] | 75 | msg "build: cmake, -Werror (gcc)" # ~ 1 min |
Manuel Pégourié-Gonnard | 3895f5a | 2014-03-27 14:44:04 +0100 | [diff] [blame] | 76 | cleanup |
| 77 | CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Check . |
| 78 | make |
| 79 | |
Manuel Pégourié-Gonnard | 57255b1 | 2014-06-09 11:21:49 +0200 | [diff] [blame] | 80 | msg "test: main suites with valgrind" # ~ 2 min 10s |
| 81 | make memcheck |
| 82 | |
Manuel Pégourié-Gonnard | 61bc57a | 2014-08-14 11:29:06 +0200 | [diff] [blame] | 83 | msg "build: with ASan (clang)" # ~ 1 min |
Manuel Pégourié-Gonnard | 57255b1 | 2014-06-09 11:21:49 +0200 | [diff] [blame] | 84 | cleanup |
Manuel Pégourié-Gonnard | 61bc57a | 2014-08-14 11:29:06 +0200 | [diff] [blame] | 85 | CC=clang cmake -D CMAKE_BUILD_TYPE:String=ASan . |
Manuel Pégourié-Gonnard | 57255b1 | 2014-06-09 11:21:49 +0200 | [diff] [blame] | 86 | make |
| 87 | |
| 88 | msg "test: ssl-opt.sh (ASan build)" # ~ 1 min 10s |
| 89 | cd tests |
| 90 | ./ssl-opt.sh |
| 91 | cd .. |
| 92 | |
| 93 | msg "test: main suites and selftest (ASan build)" # ~ 10s + 30s |
| 94 | make test |
| 95 | programs/test/selftest |
| 96 | |
| 97 | msg "test: ref-configs (ASan build)" # ~ 4 min 45 s |
| 98 | tests/scripts/test-ref-configs.pl |
| 99 | |
| 100 | # Most issues are likely to be caught at this point |
| 101 | |
| 102 | msg "build: with ASan (rebuild after ref-configs)" # ~ 1 min |
| 103 | make |
| 104 | |
| 105 | msg "test: compat.sh (ASan build)" # ~ 7 min 30s |
| 106 | cd tests |
| 107 | ./compat.sh |
| 108 | cd .. |
| 109 | |
Manuel Pégourié-Gonnard | 61bc57a | 2014-08-14 11:29:06 +0200 | [diff] [blame] | 110 | msg "build: cmake, full config" # ~ 40s |
Manuel Pégourié-Gonnard | 3895f5a | 2014-03-27 14:44:04 +0100 | [diff] [blame] | 111 | cleanup |
Manuel Pégourié-Gonnard | e73b263 | 2014-07-12 04:00:00 +0200 | [diff] [blame] | 112 | cp "$CONFIG_H" "$CONFIG_BAK" |
| 113 | scripts/config.pl full |
| 114 | scripts/config.pl unset POLARSSL_MEMORY_BACKTRACE # too slow for tests |
Manuel Pégourié-Gonnard | 61bc57a | 2014-08-14 11:29:06 +0200 | [diff] [blame] | 115 | cmake -D CMAKE_BUILD_TYPE:String=Check . |
Manuel Pégourié-Gonnard | 3895f5a | 2014-03-27 14:44:04 +0100 | [diff] [blame] | 116 | make |
| 117 | |
Manuel Pégourié-Gonnard | e73b263 | 2014-07-12 04:00:00 +0200 | [diff] [blame] | 118 | msg "test: main suites (full config)" |
| 119 | make test |
| 120 | |
| 121 | msg "test: ssl-opt.sh default (full config)" |
| 122 | cd tests |
| 123 | ./ssl-opt.sh -f Default |
| 124 | cd .. |
| 125 | |
| 126 | msg "test: compat.sh 3DES & NULL (full config)" |
| 127 | cd tests |
| 128 | ./compat.sh -e '^$' -f 'NULL\|3DES-EDE-CBC\|DES-CBC3' |
| 129 | cd .. |
| 130 | |
Manuel Pégourié-Gonnard | 61bc57a | 2014-08-14 11:29:06 +0200 | [diff] [blame] | 131 | msg "build: Unix make, -O2 (gcc)" # ~ 30s |
Manuel Pégourié-Gonnard | 3895f5a | 2014-03-27 14:44:04 +0100 | [diff] [blame] | 132 | cleanup |
Manuel Pégourié-Gonnard | 61bc57a | 2014-08-14 11:29:06 +0200 | [diff] [blame] | 133 | CC=gcc make |
Manuel Pégourié-Gonnard | 80955ee | 2014-03-19 18:29:01 +0100 | [diff] [blame] | 134 | |
Manuel Pégourié-Gonnard | 57255b1 | 2014-06-09 11:21:49 +0200 | [diff] [blame] | 135 | # Optional parts that take a long time to run |
Manuel Pégourié-Gonnard | 4a9dc2a | 2014-05-09 13:46:59 +0200 | [diff] [blame] | 136 | |
Manuel Pégourié-Gonnard | 61bc57a | 2014-08-14 11:29:06 +0200 | [diff] [blame] | 137 | if [ "$MEMORY" -ge 1 ]; then |
Manuel Pégourié-Gonnard | 57255b1 | 2014-06-09 11:21:49 +0200 | [diff] [blame] | 138 | msg "test: ssl-opt --memcheck (-02 build)" # ~ 8 min |
Manuel Pégourié-Gonnard | 80955ee | 2014-03-19 18:29:01 +0100 | [diff] [blame] | 139 | cd tests |
Manuel Pégourié-Gonnard | 80955ee | 2014-03-19 18:29:01 +0100 | [diff] [blame] | 140 | ./ssl-opt.sh --memcheck |
| 141 | cd .. |
Manuel Pégourié-Gonnard | 80955ee | 2014-03-19 18:29:01 +0100 | [diff] [blame] | 142 | |
Manuel Pégourié-Gonnard | 61bc57a | 2014-08-14 11:29:06 +0200 | [diff] [blame] | 143 | if [ "$MEMORY" -ge 2 ]; then |
Manuel Pégourié-Gonnard | 57255b1 | 2014-06-09 11:21:49 +0200 | [diff] [blame] | 144 | msg "test: compat --memcheck (-02 build)" # ~ 42 min |
| 145 | cd tests |
| 146 | ./compat.sh --memcheck |
| 147 | cd .. |
| 148 | fi |
| 149 | fi |
Manuel Pégourié-Gonnard | 80955ee | 2014-03-19 18:29:01 +0100 | [diff] [blame] | 150 | |
Manuel Pégourié-Gonnard | 3895f5a | 2014-03-27 14:44:04 +0100 | [diff] [blame] | 151 | echo "Done." |
Manuel Pégourié-Gonnard | 80955ee | 2014-03-19 18:29:01 +0100 | [diff] [blame] | 152 | cleanup |
| 153 | |