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