SimonB | 21ab9d7 | 2016-03-12 20:37:32 +0000 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | # basic-build-tests.sh |
| 4 | # |
Simon Butcher | cbb9075 | 2016-05-19 22:15:34 +0100 | [diff] [blame] | 5 | # This file is part of mbed TLS (https://tls.mbed.org) |
| 6 | # |
SimonB | 21ab9d7 | 2016-03-12 20:37:32 +0000 | [diff] [blame] | 7 | # Copyright (c) 2016, ARM Limited, All Rights Reserved |
| 8 | # |
| 9 | # Purpose |
| 10 | # |
| 11 | # Executes the basic test suites, captures the results, and generates a simple |
| 12 | # test report and code coverage report. |
| 13 | # |
| 14 | # The tests include: |
SimonB | 21ab9d7 | 2016-03-12 20:37:32 +0000 | [diff] [blame] | 15 | # * Unit tests - executed using tests/scripts/run-test-suite.pl |
Paul Bakker | 4b8bc52 | 2016-07-20 09:52:01 +0100 | [diff] [blame] | 16 | # * Self-tests - executed using the test suites above |
SimonB | 21ab9d7 | 2016-03-12 20:37:32 +0000 | [diff] [blame] | 17 | # * System tests - executed using tests/ssl-opt.sh |
| 18 | # * Interoperability tests - executed using tests/compat.sh |
| 19 | # |
| 20 | # The tests focus on functionality and do not consider performance. |
| 21 | # |
| 22 | # Note the tests self-adapt due to configurations in include/mbedtls/config.h |
| 23 | # which can lead to some tests being skipped, and can cause the number of |
Paul Bakker | 4b8bc52 | 2016-07-20 09:52:01 +0100 | [diff] [blame] | 24 | # available tests to fluctuate. |
SimonB | 21ab9d7 | 2016-03-12 20:37:32 +0000 | [diff] [blame] | 25 | # |
| 26 | # This script has been written to be generic and should work on any shell. |
| 27 | # |
| 28 | # Usage: basic-build-tests.sh |
| 29 | # |
| 30 | |
| 31 | # Abort on errors (and uninitiliased variables) |
| 32 | set -eu |
| 33 | |
| 34 | if [ -d library -a -d include -a -d tests ]; then :; else |
| 35 | echo "Must be run from mbed TLS root" >&2 |
| 36 | exit 1 |
| 37 | fi |
| 38 | |
Andres AG | b2fdd04 | 2016-09-22 14:17:46 +0100 | [diff] [blame] | 39 | : ${OPENSSL:="openssl"} |
| 40 | : ${OPENSSL_LEGACY:="$OPENSSL"} |
| 41 | : ${GNUTLS_CLI:="gnutls-cli"} |
| 42 | : ${GNUTLS_SERV:="gnutls-serv"} |
| 43 | : ${GNUTLS_LEGACY_CLI:="$GNUTLS_CLI"} |
| 44 | : ${GNUTLS_LEGACY_SERV:="$GNUTLS_SERV"} |
| 45 | |
Manuel Pégourié-Gonnard | e050191 | 2020-06-08 12:59:27 +0200 | [diff] [blame^] | 46 | # Used to make ssl-opt.sh deterministic. |
| 47 | # !!! Keep this in sync with RELEASE_SEED in all.sh !!! |
| 48 | : ${SEED:=1} |
| 49 | export SEED |
| 50 | |
Andres AG | b2fdd04 | 2016-09-22 14:17:46 +0100 | [diff] [blame] | 51 | # To avoid setting OpenSSL and GnuTLS for each call to compat.sh and ssl-opt.sh |
| 52 | # we just export the variables they require |
| 53 | export OPENSSL_CMD="$OPENSSL" |
| 54 | export GNUTLS_CLI="$GNUTLS_CLI" |
| 55 | export GNUTLS_SERV="$GNUTLS_SERV" |
| 56 | |
Janos Follath | 7ccac85 | 2016-06-06 13:18:39 +0100 | [diff] [blame] | 57 | CONFIG_H='include/mbedtls/config.h' |
| 58 | CONFIG_BAK="$CONFIG_H.bak" |
SimonB | 21ab9d7 | 2016-03-12 20:37:32 +0000 | [diff] [blame] | 59 | |
Janos Follath | b72c678 | 2016-07-19 14:54:17 +0100 | [diff] [blame] | 60 | # Step 0 - print build environment info |
Andres AG | b2fdd04 | 2016-09-22 14:17:46 +0100 | [diff] [blame] | 61 | OPENSSL="$OPENSSL" \ |
| 62 | OPENSSL_LEGACY="$OPENSSL_LEGACY" \ |
| 63 | GNUTLS_CLI="$GNUTLS_CLI" \ |
| 64 | GNUTLS_SERV="$GNUTLS_SERV" \ |
| 65 | GNUTLS_LEGACY_CLI="$GNUTLS_LEGACY_CLI" \ |
| 66 | GNUTLS_LEGACY_SERV="$GNUTLS_LEGACY_SERV" \ |
| 67 | scripts/output_env.sh |
Janos Follath | b72c678 | 2016-07-19 14:54:17 +0100 | [diff] [blame] | 68 | echo |
| 69 | |
SimonB | 21ab9d7 | 2016-03-12 20:37:32 +0000 | [diff] [blame] | 70 | # Step 1 - Make and instrumented build for code coverage |
Simon Butcher | c2b0efc | 2016-03-18 18:28:43 +0000 | [diff] [blame] | 71 | export CFLAGS=' --coverage -g3 -O0 ' |
Philippe Antoine | 702c659 | 2019-07-09 17:44:53 +0200 | [diff] [blame] | 72 | export LDFLAGS=' --coverage' |
SimonB | 098a3b5 | 2016-04-16 21:56:59 +0100 | [diff] [blame] | 73 | make clean |
Janos Follath | 7ccac85 | 2016-06-06 13:18:39 +0100 | [diff] [blame] | 74 | cp "$CONFIG_H" "$CONFIG_BAK" |
Gilles Peskine | 5d46f6a | 2019-07-27 23:52:53 +0200 | [diff] [blame] | 75 | scripts/config.py full |
Simon Butcher | cbb9075 | 2016-05-19 22:15:34 +0100 | [diff] [blame] | 76 | make -j |
SimonB | 21ab9d7 | 2016-03-12 20:37:32 +0000 | [diff] [blame] | 77 | |
| 78 | |
| 79 | # Step 2 - Execute the tests |
| 80 | TEST_OUTPUT=out_${PPID} |
| 81 | cd tests |
Gilles Peskine | 3c8ccc0 | 2019-05-20 11:39:18 +0200 | [diff] [blame] | 82 | if [ ! -f "seedfile" ]; then |
Gilles Peskine | bfcb6e1 | 2020-04-09 18:33:34 +0200 | [diff] [blame] | 83 | dd if=/dev/urandom of="seedfile" bs=64 count=1 |
Gilles Peskine | 3c8ccc0 | 2019-05-20 11:39:18 +0200 | [diff] [blame] | 84 | fi |
Gilles Peskine | 40be51f | 2020-04-09 18:50:08 +0200 | [diff] [blame] | 85 | echo |
SimonB | 21ab9d7 | 2016-03-12 20:37:32 +0000 | [diff] [blame] | 86 | |
Gilles Peskine | ca51b47 | 2020-04-09 18:29:42 +0200 | [diff] [blame] | 87 | # Step 2a - Unit Tests (keep going even if some tests fail) |
Gilles Peskine | 40be51f | 2020-04-09 18:50:08 +0200 | [diff] [blame] | 88 | echo '################ Unit tests ################' |
Jaeden Amero | 60ca6e5 | 2018-12-07 13:06:24 +0000 | [diff] [blame] | 89 | perl scripts/run-test-suites.pl -v 2 |tee unit-test-$TEST_OUTPUT |
Gilles Peskine | 40be51f | 2020-04-09 18:50:08 +0200 | [diff] [blame] | 90 | echo '^^^^^^^^^^^^^^^^ Unit tests ^^^^^^^^^^^^^^^^' |
SimonB | 21ab9d7 | 2016-03-12 20:37:32 +0000 | [diff] [blame] | 91 | echo |
| 92 | |
Gilles Peskine | ca51b47 | 2020-04-09 18:29:42 +0200 | [diff] [blame] | 93 | # Step 2b - System Tests (keep going even if some tests fail) |
Gilles Peskine | 40be51f | 2020-04-09 18:50:08 +0200 | [diff] [blame] | 94 | echo |
| 95 | echo '################ ssl-opt.sh ################' |
SimonB | 21ab9d7 | 2016-03-12 20:37:32 +0000 | [diff] [blame] | 96 | sh ssl-opt.sh |tee sys-test-$TEST_OUTPUT |
Gilles Peskine | 40be51f | 2020-04-09 18:50:08 +0200 | [diff] [blame] | 97 | echo '^^^^^^^^^^^^^^^^ ssl-opt.sh ^^^^^^^^^^^^^^^^' |
SimonB | 21ab9d7 | 2016-03-12 20:37:32 +0000 | [diff] [blame] | 98 | echo |
| 99 | |
Gilles Peskine | ca51b47 | 2020-04-09 18:29:42 +0200 | [diff] [blame] | 100 | # Step 2c - Compatibility tests (keep going even if some tests fail) |
Gilles Peskine | 40be51f | 2020-04-09 18:50:08 +0200 | [diff] [blame] | 101 | echo '################ compat.sh ################' |
| 102 | { |
| 103 | echo '#### compat.sh: Default versions' |
| 104 | sh compat.sh -m 'tls1 tls1_1 tls1_2 dtls1 dtls1_2' |
| 105 | echo |
| 106 | |
| 107 | echo '#### compat.sh: legacy (SSLv3)' |
| 108 | OPENSSL_CMD="$OPENSSL_LEGACY" sh compat.sh -m 'ssl3' |
| 109 | echo |
| 110 | |
| 111 | echo '#### compat.sh: legacy (null, DES, RC4)' |
| 112 | OPENSSL_CMD="$OPENSSL_LEGACY" \ |
| 113 | GNUTLS_CLI="$GNUTLS_LEGACY_CLI" GNUTLS_SERV="$GNUTLS_LEGACY_SERV" \ |
| 114 | sh compat.sh -e '^$' -f 'NULL\|DES\|RC4\|ARCFOUR' |
| 115 | echo |
| 116 | |
| 117 | echo '#### compat.sh: next (ARIA, ChaCha)' |
| 118 | OPENSSL_CMD="$OPENSSL_NEXT" sh compat.sh -e '^$' -f 'ARIA\|CHACHA' |
| 119 | echo |
| 120 | } | tee compat-test-$TEST_OUTPUT |
| 121 | echo '^^^^^^^^^^^^^^^^ compat.sh ^^^^^^^^^^^^^^^^' |
SimonB | 21ab9d7 | 2016-03-12 20:37:32 +0000 | [diff] [blame] | 122 | echo |
| 123 | |
| 124 | # Step 3 - Process the coverage report |
| 125 | cd .. |
Gilles Peskine | 5757d54 | 2020-04-09 18:32:48 +0200 | [diff] [blame] | 126 | { |
| 127 | make lcov |
| 128 | echo SUCCESS |
| 129 | } | tee tests/cov-$TEST_OUTPUT |
| 130 | |
| 131 | if [ "$(tail -n1 tests/cov-$TEST_OUTPUT)" != "SUCCESS" ]; then |
| 132 | echo >&2 "Fatal: 'make lcov' failed" |
| 133 | exit 2 |
| 134 | fi |
SimonB | 21ab9d7 | 2016-03-12 20:37:32 +0000 | [diff] [blame] | 135 | |
| 136 | |
| 137 | # Step 4 - Summarise the test report |
| 138 | echo |
| 139 | echo "=========================================================================" |
| 140 | echo "Test Report Summary" |
| 141 | echo |
| 142 | |
| 143 | cd tests |
| 144 | |
Paul Bakker | 4b8bc52 | 2016-07-20 09:52:01 +0100 | [diff] [blame] | 145 | # Step 4a - Unit tests |
SimonB | 21ab9d7 | 2016-03-12 20:37:32 +0000 | [diff] [blame] | 146 | echo "Unit tests - tests/scripts/run-test-suites.pl" |
| 147 | |
| 148 | PASSED_TESTS=$(tail -n6 unit-test-$TEST_OUTPUT|sed -n -e 's/test cases passed :[\t]*\([0-9]*\)/\1/p'| tr -d ' ') |
| 149 | SKIPPED_TESTS=$(tail -n6 unit-test-$TEST_OUTPUT|sed -n -e 's/skipped :[ \t]*\([0-9]*\)/\1/p'| tr -d ' ') |
| 150 | TOTAL_SUITES=$(tail -n6 unit-test-$TEST_OUTPUT|sed -n -e 's/.* (\([0-9]*\) .*, [0-9]* tests run)/\1/p'| tr -d ' ') |
| 151 | FAILED_TESTS=$(tail -n6 unit-test-$TEST_OUTPUT|sed -n -e 's/failed :[\t]*\([0-9]*\)/\1/p' |tr -d ' ') |
| 152 | |
| 153 | echo "No test suites : $TOTAL_SUITES" |
| 154 | echo "Passed : $PASSED_TESTS" |
| 155 | echo "Failed : $FAILED_TESTS" |
| 156 | echo "Skipped : $SKIPPED_TESTS" |
| 157 | echo "Total exec'd tests : $(($PASSED_TESTS + $FAILED_TESTS))" |
| 158 | echo "Total avail tests : $(($PASSED_TESTS + $FAILED_TESTS + $SKIPPED_TESTS))" |
| 159 | echo |
| 160 | |
Paul Bakker | 4b8bc52 | 2016-07-20 09:52:01 +0100 | [diff] [blame] | 161 | TOTAL_PASS=$PASSED_TESTS |
| 162 | TOTAL_FAIL=$FAILED_TESTS |
| 163 | TOTAL_SKIP=$SKIPPED_TESTS |
| 164 | TOTAL_AVAIL=$(($PASSED_TESTS + $FAILED_TESTS + $SKIPPED_TESTS)) |
| 165 | TOTAL_EXED=$(($PASSED_TESTS + $FAILED_TESTS)) |
SimonB | 21ab9d7 | 2016-03-12 20:37:32 +0000 | [diff] [blame] | 166 | |
Paul Bakker | 4b8bc52 | 2016-07-20 09:52:01 +0100 | [diff] [blame] | 167 | # Step 4b - TLS Options tests |
Simon Butcher | ab0c51d | 2016-03-13 01:23:34 +0000 | [diff] [blame] | 168 | echo "TLS Options tests - tests/ssl-opt.sh" |
SimonB | 21ab9d7 | 2016-03-12 20:37:32 +0000 | [diff] [blame] | 169 | |
| 170 | PASSED_TESTS=$(tail -n5 sys-test-$TEST_OUTPUT|sed -n -e 's/.* (\([0-9]*\) \/ [0-9]* tests ([0-9]* skipped))$/\1/p') |
| 171 | SKIPPED_TESTS=$(tail -n5 sys-test-$TEST_OUTPUT|sed -n -e 's/.* ([0-9]* \/ [0-9]* tests (\([0-9]*\) skipped))$/\1/p') |
| 172 | TOTAL_TESTS=$(tail -n5 sys-test-$TEST_OUTPUT|sed -n -e 's/.* ([0-9]* \/ \([0-9]*\) tests ([0-9]* skipped))$/\1/p') |
| 173 | FAILED_TESTS=$(($TOTAL_TESTS - $PASSED_TESTS)) |
| 174 | |
| 175 | echo "Passed : $PASSED_TESTS" |
| 176 | echo "Failed : $FAILED_TESTS" |
| 177 | echo "Skipped : $SKIPPED_TESTS" |
| 178 | echo "Total exec'd tests : $TOTAL_TESTS" |
| 179 | echo "Total avail tests : $(($TOTAL_TESTS + $SKIPPED_TESTS))" |
| 180 | echo |
| 181 | |
| 182 | TOTAL_PASS=$(($TOTAL_PASS+$PASSED_TESTS)) |
| 183 | TOTAL_FAIL=$(($TOTAL_FAIL+$FAILED_TESTS)) |
| 184 | TOTAL_SKIP=$(($TOTAL_SKIP+$SKIPPED_TESTS)) |
| 185 | TOTAL_AVAIL=$(($TOTAL_AVAIL + $TOTAL_TESTS + $SKIPPED_TESTS)) |
| 186 | TOTAL_EXED=$(($TOTAL_EXED + $TOTAL_TESTS)) |
| 187 | |
| 188 | |
Paul Bakker | 4b8bc52 | 2016-07-20 09:52:01 +0100 | [diff] [blame] | 189 | # Step 4c - System Compatibility tests |
Simon Butcher | ab0c51d | 2016-03-13 01:23:34 +0000 | [diff] [blame] | 190 | echo "System/Compatibility tests - tests/compat.sh" |
SimonB | 21ab9d7 | 2016-03-12 20:37:32 +0000 | [diff] [blame] | 191 | |
Andres AG | b2fdd04 | 2016-09-22 14:17:46 +0100 | [diff] [blame] | 192 | PASSED_TESTS=$(cat compat-test-$TEST_OUTPUT | sed -n -e 's/.* (\([0-9]*\) \/ [0-9]* tests ([0-9]* skipped))$/\1/p' | awk 'BEGIN{ s = 0 } { s += $1 } END{ print s }') |
| 193 | SKIPPED_TESTS=$(cat compat-test-$TEST_OUTPUT | sed -n -e 's/.* ([0-9]* \/ [0-9]* tests (\([0-9]*\) skipped))$/\1/p' | awk 'BEGIN{ s = 0 } { s += $1 } END{ print s }') |
| 194 | EXED_TESTS=$(cat compat-test-$TEST_OUTPUT | sed -n -e 's/.* ([0-9]* \/ \([0-9]*\) tests ([0-9]* skipped))$/\1/p' | awk 'BEGIN{ s = 0 } { s += $1 } END{ print s }') |
SimonB | 21ab9d7 | 2016-03-12 20:37:32 +0000 | [diff] [blame] | 195 | FAILED_TESTS=$(($EXED_TESTS - $PASSED_TESTS)) |
| 196 | |
| 197 | echo "Passed : $PASSED_TESTS" |
| 198 | echo "Failed : $FAILED_TESTS" |
| 199 | echo "Skipped : $SKIPPED_TESTS" |
| 200 | echo "Total exec'd tests : $EXED_TESTS" |
| 201 | echo "Total avail tests : $(($EXED_TESTS + $SKIPPED_TESTS))" |
| 202 | echo |
| 203 | |
| 204 | TOTAL_PASS=$(($TOTAL_PASS+$PASSED_TESTS)) |
| 205 | TOTAL_FAIL=$(($TOTAL_FAIL+$FAILED_TESTS)) |
| 206 | TOTAL_SKIP=$(($TOTAL_SKIP+$SKIPPED_TESTS)) |
| 207 | TOTAL_AVAIL=$(($TOTAL_AVAIL + $EXED_TESTS + $SKIPPED_TESTS)) |
| 208 | TOTAL_EXED=$(($TOTAL_EXED + $EXED_TESTS)) |
| 209 | |
| 210 | |
Paul Bakker | 4b8bc52 | 2016-07-20 09:52:01 +0100 | [diff] [blame] | 211 | # Step 4d - Grand totals |
SimonB | 21ab9d7 | 2016-03-12 20:37:32 +0000 | [diff] [blame] | 212 | echo "-------------------------------------------------------------------------" |
| 213 | echo "Total tests" |
| 214 | |
| 215 | echo "Total Passed : $TOTAL_PASS" |
| 216 | echo "Total Failed : $TOTAL_FAIL" |
| 217 | echo "Total Skipped : $TOTAL_SKIP" |
| 218 | echo "Total exec'd tests : $TOTAL_EXED" |
| 219 | echo "Total avail tests : $TOTAL_AVAIL" |
| 220 | echo |
| 221 | |
| 222 | |
Paul Bakker | 4b8bc52 | 2016-07-20 09:52:01 +0100 | [diff] [blame] | 223 | # Step 4e - Coverage |
SimonB | 21ab9d7 | 2016-03-12 20:37:32 +0000 | [diff] [blame] | 224 | echo "Coverage" |
| 225 | |
Dan Handley | a8b26c2 | 2020-05-28 16:20:31 +0100 | [diff] [blame] | 226 | LINES_TESTED=$(tail -n4 cov-$TEST_OUTPUT|sed -n -e 's/ lines......: [0-9]*.[0-9]% (\([0-9]*\) of [0-9]* lines)/\1/p') |
| 227 | LINES_TOTAL=$(tail -n4 cov-$TEST_OUTPUT|sed -n -e 's/ lines......: [0-9]*.[0-9]% ([0-9]* of \([0-9]*\) lines)/\1/p') |
| 228 | FUNCS_TESTED=$(tail -n4 cov-$TEST_OUTPUT|sed -n -e 's/ functions..: [0-9]*.[0-9]% (\([0-9]*\) of [0-9]* functions)$/\1/p') |
| 229 | FUNCS_TOTAL=$(tail -n4 cov-$TEST_OUTPUT|sed -n -e 's/ functions..: [0-9]*.[0-9]% ([0-9]* of \([0-9]*\) functions)$/\1/p') |
| 230 | BRANCHES_TESTED=$(tail -n4 cov-$TEST_OUTPUT|sed -n -e 's/ branches...: [0-9]*.[0-9]% (\([0-9]*\) of [0-9]* branches)$/\1/p') |
| 231 | BRANCHES_TOTAL=$(tail -n4 cov-$TEST_OUTPUT|sed -n -e 's/ branches...: [0-9]*.[0-9]% ([0-9]* of \([0-9]*\) branches)$/\1/p') |
SimonB | 21ab9d7 | 2016-03-12 20:37:32 +0000 | [diff] [blame] | 232 | |
| 233 | LINES_PERCENT=$((1000*$LINES_TESTED/$LINES_TOTAL)) |
| 234 | LINES_PERCENT="$(($LINES_PERCENT/10)).$(($LINES_PERCENT-($LINES_PERCENT/10)*10))" |
| 235 | |
| 236 | FUNCS_PERCENT=$((1000*$FUNCS_TESTED/$FUNCS_TOTAL)) |
| 237 | FUNCS_PERCENT="$(($FUNCS_PERCENT/10)).$(($FUNCS_PERCENT-($FUNCS_PERCENT/10)*10))" |
| 238 | |
Dan Handley | a8b26c2 | 2020-05-28 16:20:31 +0100 | [diff] [blame] | 239 | BRANCHES_PERCENT=$((1000*$BRANCHES_TESTED/$BRANCHES_TOTAL)) |
| 240 | BRANCHES_PERCENT="$(($BRANCHES_PERCENT/10)).$(($BRANCHES_PERCENT-($BRANCHES_PERCENT/10)*10))" |
| 241 | |
SimonB | 21ab9d7 | 2016-03-12 20:37:32 +0000 | [diff] [blame] | 242 | echo "Lines Tested : $LINES_TESTED of $LINES_TOTAL $LINES_PERCENT%" |
| 243 | echo "Functions Tested : $FUNCS_TESTED of $FUNCS_TOTAL $FUNCS_PERCENT%" |
Dan Handley | a8b26c2 | 2020-05-28 16:20:31 +0100 | [diff] [blame] | 244 | echo "Branches Tested : $BRANCHES_TESTED of $BRANCHES_TOTAL $BRANCHES_PERCENT%" |
SimonB | 21ab9d7 | 2016-03-12 20:37:32 +0000 | [diff] [blame] | 245 | echo |
| 246 | |
SimonB | 21ab9d7 | 2016-03-12 20:37:32 +0000 | [diff] [blame] | 247 | rm unit-test-$TEST_OUTPUT |
| 248 | rm sys-test-$TEST_OUTPUT |
| 249 | rm compat-test-$TEST_OUTPUT |
| 250 | rm cov-$TEST_OUTPUT |
| 251 | |
| 252 | cd .. |
Janos Follath | 7ccac85 | 2016-06-06 13:18:39 +0100 | [diff] [blame] | 253 | |
| 254 | make clean |
| 255 | |
| 256 | if [ -f "$CONFIG_BAK" ]; then |
| 257 | mv "$CONFIG_BAK" "$CONFIG_H" |
| 258 | fi |
Gilles Peskine | 6d6ee98 | 2020-04-09 18:28:14 +0200 | [diff] [blame] | 259 | |
| 260 | if [ $TOTAL_FAIL -ne 0 ]; then |
| 261 | exit 1 |
| 262 | fi |