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 ' |
SimonB | 098a3b5 | 2016-04-16 21:56:59 +0100 | [diff] [blame] | 67 | make clean |
Janos Follath | 7ccac85 | 2016-06-06 13:18:39 +0100 | [diff] [blame] | 68 | cp "$CONFIG_H" "$CONFIG_BAK" |
SimonB | 098a3b5 | 2016-04-16 21:56:59 +0100 | [diff] [blame] | 69 | scripts/config.pl full |
Simon Butcher | ae79124 | 2016-05-10 21:16:54 +0100 | [diff] [blame] | 70 | scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE |
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 |
| 77 | |
Paul Bakker | 4b8bc52 | 2016-07-20 09:52:01 +0100 | [diff] [blame] | 78 | # Step 2a - Unit Tests |
Jaeden Amero | 60ca6e5 | 2018-12-07 13:06:24 +0000 | [diff] [blame^] | 79 | perl scripts/run-test-suites.pl -v 2 |tee unit-test-$TEST_OUTPUT |
SimonB | 21ab9d7 | 2016-03-12 20:37:32 +0000 | [diff] [blame] | 80 | echo |
| 81 | |
Paul Bakker | 4b8bc52 | 2016-07-20 09:52:01 +0100 | [diff] [blame] | 82 | # Step 2b - System Tests |
SimonB | 21ab9d7 | 2016-03-12 20:37:32 +0000 | [diff] [blame] | 83 | sh ssl-opt.sh |tee sys-test-$TEST_OUTPUT |
| 84 | echo |
| 85 | |
Paul Bakker | 4b8bc52 | 2016-07-20 09:52:01 +0100 | [diff] [blame] | 86 | # Step 2c - Compatibility tests |
Andres AG | b2fdd04 | 2016-09-22 14:17:46 +0100 | [diff] [blame] | 87 | sh compat.sh -m 'tls1 tls1_1 tls1_2 dtls1 dtls1_2' | \ |
| 88 | tee compat-test-$TEST_OUTPUT |
| 89 | OPENSSL_CMD="$OPENSSL_LEGACY" \ |
| 90 | sh compat.sh -m 'ssl3' |tee -a compat-test-$TEST_OUTPUT |
| 91 | OPENSSL_CMD="$OPENSSL_LEGACY" \ |
| 92 | GNUTLS_CLI="$GNUTLS_LEGACY_CLI" \ |
| 93 | GNUTLS_SERV="$GNUTLS_LEGACY_SERV" \ |
| 94 | sh compat.sh -e '3DES\|DES-CBC3' -f 'NULL\|DES\|RC4\|ARCFOUR' | \ |
| 95 | tee -a compat-test-$TEST_OUTPUT |
SimonB | 21ab9d7 | 2016-03-12 20:37:32 +0000 | [diff] [blame] | 96 | echo |
| 97 | |
| 98 | # Step 3 - Process the coverage report |
| 99 | cd .. |
| 100 | make lcov |tee tests/cov-$TEST_OUTPUT |
| 101 | |
| 102 | |
| 103 | # Step 4 - Summarise the test report |
| 104 | echo |
| 105 | echo "=========================================================================" |
| 106 | echo "Test Report Summary" |
| 107 | echo |
| 108 | |
| 109 | cd tests |
| 110 | |
Paul Bakker | 4b8bc52 | 2016-07-20 09:52:01 +0100 | [diff] [blame] | 111 | # Step 4a - Unit tests |
SimonB | 21ab9d7 | 2016-03-12 20:37:32 +0000 | [diff] [blame] | 112 | echo "Unit tests - tests/scripts/run-test-suites.pl" |
| 113 | |
| 114 | PASSED_TESTS=$(tail -n6 unit-test-$TEST_OUTPUT|sed -n -e 's/test cases passed :[\t]*\([0-9]*\)/\1/p'| tr -d ' ') |
| 115 | SKIPPED_TESTS=$(tail -n6 unit-test-$TEST_OUTPUT|sed -n -e 's/skipped :[ \t]*\([0-9]*\)/\1/p'| tr -d ' ') |
| 116 | TOTAL_SUITES=$(tail -n6 unit-test-$TEST_OUTPUT|sed -n -e 's/.* (\([0-9]*\) .*, [0-9]* tests run)/\1/p'| tr -d ' ') |
| 117 | FAILED_TESTS=$(tail -n6 unit-test-$TEST_OUTPUT|sed -n -e 's/failed :[\t]*\([0-9]*\)/\1/p' |tr -d ' ') |
| 118 | |
| 119 | echo "No test suites : $TOTAL_SUITES" |
| 120 | echo "Passed : $PASSED_TESTS" |
| 121 | echo "Failed : $FAILED_TESTS" |
| 122 | echo "Skipped : $SKIPPED_TESTS" |
| 123 | echo "Total exec'd tests : $(($PASSED_TESTS + $FAILED_TESTS))" |
| 124 | echo "Total avail tests : $(($PASSED_TESTS + $FAILED_TESTS + $SKIPPED_TESTS))" |
| 125 | echo |
| 126 | |
Paul Bakker | 4b8bc52 | 2016-07-20 09:52:01 +0100 | [diff] [blame] | 127 | TOTAL_PASS=$PASSED_TESTS |
| 128 | TOTAL_FAIL=$FAILED_TESTS |
| 129 | TOTAL_SKIP=$SKIPPED_TESTS |
| 130 | TOTAL_AVAIL=$(($PASSED_TESTS + $FAILED_TESTS + $SKIPPED_TESTS)) |
| 131 | TOTAL_EXED=$(($PASSED_TESTS + $FAILED_TESTS)) |
SimonB | 21ab9d7 | 2016-03-12 20:37:32 +0000 | [diff] [blame] | 132 | |
Paul Bakker | 4b8bc52 | 2016-07-20 09:52:01 +0100 | [diff] [blame] | 133 | # Step 4b - TLS Options tests |
Simon Butcher | ab0c51d | 2016-03-13 01:23:34 +0000 | [diff] [blame] | 134 | echo "TLS Options tests - tests/ssl-opt.sh" |
SimonB | 21ab9d7 | 2016-03-12 20:37:32 +0000 | [diff] [blame] | 135 | |
| 136 | PASSED_TESTS=$(tail -n5 sys-test-$TEST_OUTPUT|sed -n -e 's/.* (\([0-9]*\) \/ [0-9]* tests ([0-9]* skipped))$/\1/p') |
| 137 | SKIPPED_TESTS=$(tail -n5 sys-test-$TEST_OUTPUT|sed -n -e 's/.* ([0-9]* \/ [0-9]* tests (\([0-9]*\) skipped))$/\1/p') |
| 138 | TOTAL_TESTS=$(tail -n5 sys-test-$TEST_OUTPUT|sed -n -e 's/.* ([0-9]* \/ \([0-9]*\) tests ([0-9]* skipped))$/\1/p') |
| 139 | FAILED_TESTS=$(($TOTAL_TESTS - $PASSED_TESTS)) |
| 140 | |
| 141 | echo "Passed : $PASSED_TESTS" |
| 142 | echo "Failed : $FAILED_TESTS" |
| 143 | echo "Skipped : $SKIPPED_TESTS" |
| 144 | echo "Total exec'd tests : $TOTAL_TESTS" |
| 145 | echo "Total avail tests : $(($TOTAL_TESTS + $SKIPPED_TESTS))" |
| 146 | echo |
| 147 | |
| 148 | TOTAL_PASS=$(($TOTAL_PASS+$PASSED_TESTS)) |
| 149 | TOTAL_FAIL=$(($TOTAL_FAIL+$FAILED_TESTS)) |
| 150 | TOTAL_SKIP=$(($TOTAL_SKIP+$SKIPPED_TESTS)) |
| 151 | TOTAL_AVAIL=$(($TOTAL_AVAIL + $TOTAL_TESTS + $SKIPPED_TESTS)) |
| 152 | TOTAL_EXED=$(($TOTAL_EXED + $TOTAL_TESTS)) |
| 153 | |
| 154 | |
Paul Bakker | 4b8bc52 | 2016-07-20 09:52:01 +0100 | [diff] [blame] | 155 | # Step 4c - System Compatibility tests |
Simon Butcher | ab0c51d | 2016-03-13 01:23:34 +0000 | [diff] [blame] | 156 | echo "System/Compatibility tests - tests/compat.sh" |
SimonB | 21ab9d7 | 2016-03-12 20:37:32 +0000 | [diff] [blame] | 157 | |
Andres AG | b2fdd04 | 2016-09-22 14:17:46 +0100 | [diff] [blame] | 158 | 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 }') |
| 159 | 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 }') |
| 160 | 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] | 161 | FAILED_TESTS=$(($EXED_TESTS - $PASSED_TESTS)) |
| 162 | |
| 163 | echo "Passed : $PASSED_TESTS" |
| 164 | echo "Failed : $FAILED_TESTS" |
| 165 | echo "Skipped : $SKIPPED_TESTS" |
| 166 | echo "Total exec'd tests : $EXED_TESTS" |
| 167 | echo "Total avail tests : $(($EXED_TESTS + $SKIPPED_TESTS))" |
| 168 | echo |
| 169 | |
| 170 | TOTAL_PASS=$(($TOTAL_PASS+$PASSED_TESTS)) |
| 171 | TOTAL_FAIL=$(($TOTAL_FAIL+$FAILED_TESTS)) |
| 172 | TOTAL_SKIP=$(($TOTAL_SKIP+$SKIPPED_TESTS)) |
| 173 | TOTAL_AVAIL=$(($TOTAL_AVAIL + $EXED_TESTS + $SKIPPED_TESTS)) |
| 174 | TOTAL_EXED=$(($TOTAL_EXED + $EXED_TESTS)) |
| 175 | |
| 176 | |
Paul Bakker | 4b8bc52 | 2016-07-20 09:52:01 +0100 | [diff] [blame] | 177 | # Step 4d - Grand totals |
SimonB | 21ab9d7 | 2016-03-12 20:37:32 +0000 | [diff] [blame] | 178 | echo "-------------------------------------------------------------------------" |
| 179 | echo "Total tests" |
| 180 | |
| 181 | echo "Total Passed : $TOTAL_PASS" |
| 182 | echo "Total Failed : $TOTAL_FAIL" |
| 183 | echo "Total Skipped : $TOTAL_SKIP" |
| 184 | echo "Total exec'd tests : $TOTAL_EXED" |
| 185 | echo "Total avail tests : $TOTAL_AVAIL" |
| 186 | echo |
| 187 | |
| 188 | |
Paul Bakker | 4b8bc52 | 2016-07-20 09:52:01 +0100 | [diff] [blame] | 189 | # Step 4e - Coverage |
SimonB | 21ab9d7 | 2016-03-12 20:37:32 +0000 | [diff] [blame] | 190 | echo "Coverage" |
| 191 | |
| 192 | LINES_TESTED=$(tail -n3 cov-$TEST_OUTPUT|sed -n -e 's/ lines......: [0-9]*.[0-9]% (\([0-9]*\) of [0-9]* lines)/\1/p') |
| 193 | LINES_TOTAL=$(tail -n3 cov-$TEST_OUTPUT|sed -n -e 's/ lines......: [0-9]*.[0-9]% ([0-9]* of \([0-9]*\) lines)/\1/p') |
| 194 | FUNCS_TESTED=$(tail -n3 cov-$TEST_OUTPUT|sed -n -e 's/ functions..: [0-9]*.[0-9]% (\([0-9]*\) of [0-9]* functions)$/\1/p') |
Simon Butcher | ab0c51d | 2016-03-13 01:23:34 +0000 | [diff] [blame] | 195 | FUNCS_TOTAL=$(tail -n3 cov-$TEST_OUTPUT|sed -n -e 's/ functions..: [0-9]*.[0-9]% ([0-9]* of \([0-9]*\) functions)$/\1/p') |
SimonB | 21ab9d7 | 2016-03-12 20:37:32 +0000 | [diff] [blame] | 196 | |
| 197 | LINES_PERCENT=$((1000*$LINES_TESTED/$LINES_TOTAL)) |
| 198 | LINES_PERCENT="$(($LINES_PERCENT/10)).$(($LINES_PERCENT-($LINES_PERCENT/10)*10))" |
| 199 | |
| 200 | FUNCS_PERCENT=$((1000*$FUNCS_TESTED/$FUNCS_TOTAL)) |
| 201 | FUNCS_PERCENT="$(($FUNCS_PERCENT/10)).$(($FUNCS_PERCENT-($FUNCS_PERCENT/10)*10))" |
| 202 | |
| 203 | echo "Lines Tested : $LINES_TESTED of $LINES_TOTAL $LINES_PERCENT%" |
| 204 | echo "Functions Tested : $FUNCS_TESTED of $FUNCS_TOTAL $FUNCS_PERCENT%" |
| 205 | echo |
| 206 | |
| 207 | |
SimonB | 21ab9d7 | 2016-03-12 20:37:32 +0000 | [diff] [blame] | 208 | rm unit-test-$TEST_OUTPUT |
| 209 | rm sys-test-$TEST_OUTPUT |
| 210 | rm compat-test-$TEST_OUTPUT |
| 211 | rm cov-$TEST_OUTPUT |
| 212 | |
| 213 | cd .. |
Janos Follath | 7ccac85 | 2016-06-06 13:18:39 +0100 | [diff] [blame] | 214 | |
| 215 | make clean |
| 216 | |
| 217 | if [ -f "$CONFIG_BAK" ]; then |
| 218 | mv "$CONFIG_BAK" "$CONFIG_H" |
| 219 | fi |