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