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