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 | 09b4f19 | 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 ' |
SimonB | 098a3b5 | 2016-04-16 21:56:59 +0100 | [diff] [blame] | 80 | make clean |
Janos Follath | 7ccac85 | 2016-06-06 13:18:39 +0100 | [diff] [blame] | 81 | cp "$CONFIG_H" "$CONFIG_BAK" |
SimonB | 098a3b5 | 2016-04-16 21:56:59 +0100 | [diff] [blame] | 82 | scripts/config.pl full |
Simon Butcher | cbb9075 | 2016-05-19 22:15:34 +0100 | [diff] [blame] | 83 | make -j |
SimonB | 21ab9d7 | 2016-03-12 20:37:32 +0000 | [diff] [blame] | 84 | |
| 85 | |
| 86 | # Step 2 - Execute the tests |
| 87 | TEST_OUTPUT=out_${PPID} |
| 88 | cd tests |
| 89 | |
Gilles Peskine | 9cc203a | 2020-04-09 18:33:34 +0200 | [diff] [blame] | 90 | if [ ! -f "seedfile" ]; then |
| 91 | dd if=/dev/urandom of="seedfile" bs=64 count=1 |
| 92 | fi |
| 93 | |
Gilles Peskine | 27c36f0 | 2020-04-09 18:29:42 +0200 | [diff] [blame] | 94 | # Step 2a - Unit Tests (keep going even if some tests fail) |
Jaeden Amero | 3ee5579 | 2018-12-07 13:06:24 +0000 | [diff] [blame] | 95 | perl scripts/run-test-suites.pl -v 2 |tee unit-test-$TEST_OUTPUT |
SimonB | 21ab9d7 | 2016-03-12 20:37:32 +0000 | [diff] [blame] | 96 | echo |
| 97 | |
Gilles Peskine | 27c36f0 | 2020-04-09 18:29:42 +0200 | [diff] [blame] | 98 | # Step 2b - System Tests (keep going even if some tests fail) |
SimonB | 21ab9d7 | 2016-03-12 20:37:32 +0000 | [diff] [blame] | 99 | sh ssl-opt.sh |tee sys-test-$TEST_OUTPUT |
| 100 | echo |
| 101 | |
Gilles Peskine | 27c36f0 | 2020-04-09 18:29:42 +0200 | [diff] [blame] | 102 | # Step 2c - Compatibility tests (keep going even if some tests fail) |
Andres AG | b2fdd04 | 2016-09-22 14:17:46 +0100 | [diff] [blame] | 103 | sh compat.sh -m 'tls1 tls1_1 tls1_2 dtls1 dtls1_2' | \ |
| 104 | tee compat-test-$TEST_OUTPUT |
| 105 | OPENSSL_CMD="$OPENSSL_LEGACY" \ |
| 106 | sh compat.sh -m 'ssl3' |tee -a compat-test-$TEST_OUTPUT |
| 107 | OPENSSL_CMD="$OPENSSL_LEGACY" \ |
| 108 | GNUTLS_CLI="$GNUTLS_LEGACY_CLI" \ |
| 109 | GNUTLS_SERV="$GNUTLS_LEGACY_SERV" \ |
Andres Amaya Garcia | fea3d0a | 2019-02-19 20:20:57 +0000 | [diff] [blame] | 110 | sh compat.sh -e '^$' -f 'NULL\|DES\|RC4\|ARCFOUR' | \ |
Andres AG | b2fdd04 | 2016-09-22 14:17:46 +0100 | [diff] [blame] | 111 | tee -a compat-test-$TEST_OUTPUT |
SimonB | 21ab9d7 | 2016-03-12 20:37:32 +0000 | [diff] [blame] | 112 | echo |
| 113 | |
| 114 | # Step 3 - Process the coverage report |
| 115 | cd .. |
Gilles Peskine | b07541d | 2020-04-09 18:32:48 +0200 | [diff] [blame] | 116 | { |
| 117 | make lcov |
| 118 | echo SUCCESS |
| 119 | } | tee tests/cov-$TEST_OUTPUT |
| 120 | |
| 121 | if [ "$(tail -n1 tests/cov-$TEST_OUTPUT)" != "SUCCESS" ]; then |
| 122 | echo >&2 "Fatal: 'make lcov' failed" |
| 123 | exit 2 |
| 124 | fi |
SimonB | 21ab9d7 | 2016-03-12 20:37:32 +0000 | [diff] [blame] | 125 | |
| 126 | |
| 127 | # Step 4 - Summarise the test report |
| 128 | echo |
| 129 | echo "=========================================================================" |
| 130 | echo "Test Report Summary" |
| 131 | echo |
| 132 | |
| 133 | cd tests |
| 134 | |
Paul Bakker | 4b8bc52 | 2016-07-20 09:52:01 +0100 | [diff] [blame] | 135 | # Step 4a - Unit tests |
SimonB | 21ab9d7 | 2016-03-12 20:37:32 +0000 | [diff] [blame] | 136 | echo "Unit tests - tests/scripts/run-test-suites.pl" |
| 137 | |
| 138 | PASSED_TESTS=$(tail -n6 unit-test-$TEST_OUTPUT|sed -n -e 's/test cases passed :[\t]*\([0-9]*\)/\1/p'| tr -d ' ') |
| 139 | SKIPPED_TESTS=$(tail -n6 unit-test-$TEST_OUTPUT|sed -n -e 's/skipped :[ \t]*\([0-9]*\)/\1/p'| tr -d ' ') |
| 140 | TOTAL_SUITES=$(tail -n6 unit-test-$TEST_OUTPUT|sed -n -e 's/.* (\([0-9]*\) .*, [0-9]* tests run)/\1/p'| tr -d ' ') |
| 141 | FAILED_TESTS=$(tail -n6 unit-test-$TEST_OUTPUT|sed -n -e 's/failed :[\t]*\([0-9]*\)/\1/p' |tr -d ' ') |
| 142 | |
| 143 | echo "No test suites : $TOTAL_SUITES" |
| 144 | echo "Passed : $PASSED_TESTS" |
| 145 | echo "Failed : $FAILED_TESTS" |
| 146 | echo "Skipped : $SKIPPED_TESTS" |
| 147 | echo "Total exec'd tests : $(($PASSED_TESTS + $FAILED_TESTS))" |
| 148 | echo "Total avail tests : $(($PASSED_TESTS + $FAILED_TESTS + $SKIPPED_TESTS))" |
| 149 | echo |
| 150 | |
Paul Bakker | 4b8bc52 | 2016-07-20 09:52:01 +0100 | [diff] [blame] | 151 | TOTAL_PASS=$PASSED_TESTS |
| 152 | TOTAL_FAIL=$FAILED_TESTS |
| 153 | TOTAL_SKIP=$SKIPPED_TESTS |
| 154 | TOTAL_AVAIL=$(($PASSED_TESTS + $FAILED_TESTS + $SKIPPED_TESTS)) |
| 155 | TOTAL_EXED=$(($PASSED_TESTS + $FAILED_TESTS)) |
SimonB | 21ab9d7 | 2016-03-12 20:37:32 +0000 | [diff] [blame] | 156 | |
Paul Bakker | 4b8bc52 | 2016-07-20 09:52:01 +0100 | [diff] [blame] | 157 | # Step 4b - TLS Options tests |
Simon Butcher | ab0c51d | 2016-03-13 01:23:34 +0000 | [diff] [blame] | 158 | echo "TLS Options tests - tests/ssl-opt.sh" |
SimonB | 21ab9d7 | 2016-03-12 20:37:32 +0000 | [diff] [blame] | 159 | |
| 160 | PASSED_TESTS=$(tail -n5 sys-test-$TEST_OUTPUT|sed -n -e 's/.* (\([0-9]*\) \/ [0-9]* tests ([0-9]* skipped))$/\1/p') |
| 161 | SKIPPED_TESTS=$(tail -n5 sys-test-$TEST_OUTPUT|sed -n -e 's/.* ([0-9]* \/ [0-9]* tests (\([0-9]*\) skipped))$/\1/p') |
| 162 | TOTAL_TESTS=$(tail -n5 sys-test-$TEST_OUTPUT|sed -n -e 's/.* ([0-9]* \/ \([0-9]*\) tests ([0-9]* skipped))$/\1/p') |
| 163 | FAILED_TESTS=$(($TOTAL_TESTS - $PASSED_TESTS)) |
| 164 | |
| 165 | echo "Passed : $PASSED_TESTS" |
| 166 | echo "Failed : $FAILED_TESTS" |
| 167 | echo "Skipped : $SKIPPED_TESTS" |
| 168 | echo "Total exec'd tests : $TOTAL_TESTS" |
| 169 | echo "Total avail tests : $(($TOTAL_TESTS + $SKIPPED_TESTS))" |
| 170 | echo |
| 171 | |
| 172 | TOTAL_PASS=$(($TOTAL_PASS+$PASSED_TESTS)) |
| 173 | TOTAL_FAIL=$(($TOTAL_FAIL+$FAILED_TESTS)) |
| 174 | TOTAL_SKIP=$(($TOTAL_SKIP+$SKIPPED_TESTS)) |
| 175 | TOTAL_AVAIL=$(($TOTAL_AVAIL + $TOTAL_TESTS + $SKIPPED_TESTS)) |
| 176 | TOTAL_EXED=$(($TOTAL_EXED + $TOTAL_TESTS)) |
| 177 | |
| 178 | |
Paul Bakker | 4b8bc52 | 2016-07-20 09:52:01 +0100 | [diff] [blame] | 179 | # Step 4c - System Compatibility tests |
Simon Butcher | ab0c51d | 2016-03-13 01:23:34 +0000 | [diff] [blame] | 180 | echo "System/Compatibility tests - tests/compat.sh" |
SimonB | 21ab9d7 | 2016-03-12 20:37:32 +0000 | [diff] [blame] | 181 | |
Andres AG | b2fdd04 | 2016-09-22 14:17:46 +0100 | [diff] [blame] | 182 | 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 }') |
| 183 | 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 }') |
| 184 | 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] | 185 | FAILED_TESTS=$(($EXED_TESTS - $PASSED_TESTS)) |
| 186 | |
| 187 | echo "Passed : $PASSED_TESTS" |
| 188 | echo "Failed : $FAILED_TESTS" |
| 189 | echo "Skipped : $SKIPPED_TESTS" |
| 190 | echo "Total exec'd tests : $EXED_TESTS" |
| 191 | echo "Total avail tests : $(($EXED_TESTS + $SKIPPED_TESTS))" |
| 192 | echo |
| 193 | |
| 194 | TOTAL_PASS=$(($TOTAL_PASS+$PASSED_TESTS)) |
| 195 | TOTAL_FAIL=$(($TOTAL_FAIL+$FAILED_TESTS)) |
| 196 | TOTAL_SKIP=$(($TOTAL_SKIP+$SKIPPED_TESTS)) |
| 197 | TOTAL_AVAIL=$(($TOTAL_AVAIL + $EXED_TESTS + $SKIPPED_TESTS)) |
| 198 | TOTAL_EXED=$(($TOTAL_EXED + $EXED_TESTS)) |
| 199 | |
| 200 | |
Paul Bakker | 4b8bc52 | 2016-07-20 09:52:01 +0100 | [diff] [blame] | 201 | # Step 4d - Grand totals |
SimonB | 21ab9d7 | 2016-03-12 20:37:32 +0000 | [diff] [blame] | 202 | echo "-------------------------------------------------------------------------" |
| 203 | echo "Total tests" |
| 204 | |
| 205 | echo "Total Passed : $TOTAL_PASS" |
| 206 | echo "Total Failed : $TOTAL_FAIL" |
| 207 | echo "Total Skipped : $TOTAL_SKIP" |
| 208 | echo "Total exec'd tests : $TOTAL_EXED" |
| 209 | echo "Total avail tests : $TOTAL_AVAIL" |
| 210 | echo |
| 211 | |
| 212 | |
Paul Bakker | 4b8bc52 | 2016-07-20 09:52:01 +0100 | [diff] [blame] | 213 | # Step 4e - Coverage |
SimonB | 21ab9d7 | 2016-03-12 20:37:32 +0000 | [diff] [blame] | 214 | echo "Coverage" |
| 215 | |
Dan Handley | aba9e22 | 2020-05-28 16:20:31 +0100 | [diff] [blame] | 216 | LINES_TESTED=$(tail -n4 cov-$TEST_OUTPUT|sed -n -e 's/ lines......: [0-9]*.[0-9]% (\([0-9]*\) of [0-9]* lines)/\1/p') |
| 217 | LINES_TOTAL=$(tail -n4 cov-$TEST_OUTPUT|sed -n -e 's/ lines......: [0-9]*.[0-9]% ([0-9]* of \([0-9]*\) lines)/\1/p') |
| 218 | FUNCS_TESTED=$(tail -n4 cov-$TEST_OUTPUT|sed -n -e 's/ functions..: [0-9]*.[0-9]% (\([0-9]*\) of [0-9]* functions)$/\1/p') |
| 219 | FUNCS_TOTAL=$(tail -n4 cov-$TEST_OUTPUT|sed -n -e 's/ functions..: [0-9]*.[0-9]% ([0-9]* of \([0-9]*\) functions)$/\1/p') |
| 220 | BRANCHES_TESTED=$(tail -n4 cov-$TEST_OUTPUT|sed -n -e 's/ branches...: [0-9]*.[0-9]% (\([0-9]*\) of [0-9]* branches)$/\1/p') |
| 221 | 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] | 222 | |
| 223 | LINES_PERCENT=$((1000*$LINES_TESTED/$LINES_TOTAL)) |
| 224 | LINES_PERCENT="$(($LINES_PERCENT/10)).$(($LINES_PERCENT-($LINES_PERCENT/10)*10))" |
| 225 | |
| 226 | FUNCS_PERCENT=$((1000*$FUNCS_TESTED/$FUNCS_TOTAL)) |
| 227 | FUNCS_PERCENT="$(($FUNCS_PERCENT/10)).$(($FUNCS_PERCENT-($FUNCS_PERCENT/10)*10))" |
| 228 | |
Dan Handley | aba9e22 | 2020-05-28 16:20:31 +0100 | [diff] [blame] | 229 | BRANCHES_PERCENT=$((1000*$BRANCHES_TESTED/$BRANCHES_TOTAL)) |
| 230 | BRANCHES_PERCENT="$(($BRANCHES_PERCENT/10)).$(($BRANCHES_PERCENT-($BRANCHES_PERCENT/10)*10))" |
| 231 | |
SimonB | 21ab9d7 | 2016-03-12 20:37:32 +0000 | [diff] [blame] | 232 | echo "Lines Tested : $LINES_TESTED of $LINES_TOTAL $LINES_PERCENT%" |
| 233 | echo "Functions Tested : $FUNCS_TESTED of $FUNCS_TOTAL $FUNCS_PERCENT%" |
Dan Handley | aba9e22 | 2020-05-28 16:20:31 +0100 | [diff] [blame] | 234 | echo "Branches Tested : $BRANCHES_TESTED of $BRANCHES_TOTAL $BRANCHES_PERCENT%" |
SimonB | 21ab9d7 | 2016-03-12 20:37:32 +0000 | [diff] [blame] | 235 | echo |
| 236 | |
SimonB | 21ab9d7 | 2016-03-12 20:37:32 +0000 | [diff] [blame] | 237 | rm unit-test-$TEST_OUTPUT |
| 238 | rm sys-test-$TEST_OUTPUT |
| 239 | rm compat-test-$TEST_OUTPUT |
| 240 | rm cov-$TEST_OUTPUT |
| 241 | |
| 242 | cd .. |
Janos Follath | 7ccac85 | 2016-06-06 13:18:39 +0100 | [diff] [blame] | 243 | |
| 244 | make clean |
| 245 | |
| 246 | if [ -f "$CONFIG_BAK" ]; then |
| 247 | mv "$CONFIG_BAK" "$CONFIG_H" |
| 248 | fi |
Gilles Peskine | dd7ea38 | 2020-04-09 18:28:14 +0200 | [diff] [blame] | 249 | |
| 250 | if [ $TOTAL_FAIL -ne 0 ]; then |
| 251 | exit 1 |
| 252 | fi |