blob: 9202c252904aea1b71882536024a934de1de8aec [file] [log] [blame]
SimonB21ab9d72016-03-12 20:37:32 +00001#!/bin/sh
2
Tom Cosgrove5f49b3c2022-11-30 11:13:00 +00003# basic-build-test.sh
SimonB21ab9d72016-03-12 20:37:32 +00004#
Bence Szépkúti1e148272020-08-07 13:07:28 +02005# Copyright The Mbed TLS Contributors
Dave Rodgman7ff79652023-11-03 12:04:52 +00006# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
Bence Szépkútic7da1fe2020-05-26 01:54:15 +02007#
SimonB21ab9d72016-03-12 20:37:32 +00008# Purpose
9#
10# Executes the basic test suites, captures the results, and generates a simple
11# test report and code coverage report.
12#
13# The tests include:
SimonB21ab9d72016-03-12 20:37:32 +000014# * Unit tests - executed using tests/scripts/run-test-suite.pl
Paul Bakker4b8bc522016-07-20 09:52:01 +010015# * Self-tests - executed using the test suites above
SimonB21ab9d72016-03-12 20:37:32 +000016# * System tests - executed using tests/ssl-opt.sh
17# * Interoperability tests - executed using tests/compat.sh
18#
19# The tests focus on functionality and do not consider performance.
20#
21# Note the tests self-adapt due to configurations in include/mbedtls/config.h
22# which can lead to some tests being skipped, and can cause the number of
Paul Bakker4b8bc522016-07-20 09:52:01 +010023# available tests to fluctuate.
SimonB21ab9d72016-03-12 20:37:32 +000024#
25# This script has been written to be generic and should work on any shell.
26#
Tom Cosgrove5f49b3c2022-11-30 11:13:00 +000027# Usage: basic-build-test.sh
SimonB21ab9d72016-03-12 20:37:32 +000028#
29
30# Abort on errors (and uninitiliased variables)
31set -eu
32
33if [ -d library -a -d include -a -d tests ]; then :; else
Gilles Peskinef08ca832023-09-12 19:21:54 +020034 echo "Must be run from Mbed TLS root" >&2
SimonB21ab9d72016-03-12 20:37:32 +000035 exit 1
36fi
37
Andres AGb2fdd042016-09-22 14:17:46 +010038: ${OPENSSL:="openssl"}
39: ${OPENSSL_LEGACY:="$OPENSSL"}
40: ${GNUTLS_CLI:="gnutls-cli"}
41: ${GNUTLS_SERV:="gnutls-serv"}
Andres AGb2fdd042016-09-22 14:17:46 +010042
Manuel Pégourié-Gonnarde0501912020-06-08 12:59:27 +020043# Used to make ssl-opt.sh deterministic.
Manuel Pégourié-Gonnard54304472020-06-22 10:11:47 +020044#
45# See also RELEASE_SEED in all.sh. Debugging is easier if both values are kept
46# in sync. If you change the value here because it breaks some tests, you'll
47# definitely want to change it in all.sh as well.
Manuel Pégourié-Gonnarde0501912020-06-08 12:59:27 +020048: ${SEED:=1}
49export SEED
50
Gilles Peskine5a09a4a2021-07-13 23:23:23 +020051# if MAKEFLAGS is not set add the -j option to speed up invocations of make
52if [ -z "${MAKEFLAGS+set}" ]; then
53 export MAKEFLAGS="-j"
54fi
55
Andres AGb2fdd042016-09-22 14:17:46 +010056# To avoid setting OpenSSL and GnuTLS for each call to compat.sh and ssl-opt.sh
57# we just export the variables they require
Manuel Pégourié-Gonnard89d40272022-12-19 11:42:12 +010058export OPENSSL="$OPENSSL"
Andres AGb2fdd042016-09-22 14:17:46 +010059export GNUTLS_CLI="$GNUTLS_CLI"
60export GNUTLS_SERV="$GNUTLS_SERV"
61
Janos Follath7ccac852016-06-06 13:18:39 +010062CONFIG_H='include/mbedtls/config.h'
63CONFIG_BAK="$CONFIG_H.bak"
SimonB21ab9d72016-03-12 20:37:32 +000064
Janos Follathb72c6782016-07-19 14:54:17 +010065# Step 0 - print build environment info
Andres AGb2fdd042016-09-22 14:17:46 +010066OPENSSL="$OPENSSL" \
67 OPENSSL_LEGACY="$OPENSSL_LEGACY" \
68 GNUTLS_CLI="$GNUTLS_CLI" \
69 GNUTLS_SERV="$GNUTLS_SERV" \
Andres AGb2fdd042016-09-22 14:17:46 +010070 scripts/output_env.sh
Janos Follathb72c6782016-07-19 14:54:17 +010071echo
72
SimonB21ab9d72016-03-12 20:37:32 +000073# Step 1 - Make and instrumented build for code coverage
Simon Butcherc2b0efc2016-03-18 18:28:43 +000074export CFLAGS=' --coverage -g3 -O0 '
Philippe Antoine702c6592019-07-09 17:44:53 +020075export LDFLAGS=' --coverage'
SimonB098a3b52016-04-16 21:56:59 +010076make clean
Janos Follath7ccac852016-06-06 13:18:39 +010077cp "$CONFIG_H" "$CONFIG_BAK"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +020078scripts/config.py full
Gilles Peskine5a09a4a2021-07-13 23:23:23 +020079make
SimonB21ab9d72016-03-12 20:37:32 +000080
81
82# Step 2 - Execute the tests
83TEST_OUTPUT=out_${PPID}
84cd tests
Gilles Peskine3c8ccc02019-05-20 11:39:18 +020085if [ ! -f "seedfile" ]; then
Gilles Peskinebfcb6e12020-04-09 18:33:34 +020086 dd if=/dev/urandom of="seedfile" bs=64 count=1
Gilles Peskine3c8ccc02019-05-20 11:39:18 +020087fi
Gilles Peskine40be51f2020-04-09 18:50:08 +020088echo
SimonB21ab9d72016-03-12 20:37:32 +000089
Gilles Peskineca51b472020-04-09 18:29:42 +020090# Step 2a - Unit Tests (keep going even if some tests fail)
Gilles Peskine40be51f2020-04-09 18:50:08 +020091echo '################ Unit tests ################'
Jaeden Amero60ca6e52018-12-07 13:06:24 +000092perl scripts/run-test-suites.pl -v 2 |tee unit-test-$TEST_OUTPUT
Gilles Peskine40be51f2020-04-09 18:50:08 +020093echo '^^^^^^^^^^^^^^^^ Unit tests ^^^^^^^^^^^^^^^^'
SimonB21ab9d72016-03-12 20:37:32 +000094echo
95
Gilles Peskineca51b472020-04-09 18:29:42 +020096# Step 2b - System Tests (keep going even if some tests fail)
Gilles Peskine40be51f2020-04-09 18:50:08 +020097echo
98echo '################ ssl-opt.sh ################'
Gilles Peskine8e741412021-07-13 23:26:00 +020099echo "ssl-opt.sh will use SEED=$SEED for udp_proxy"
SimonB21ab9d72016-03-12 20:37:32 +0000100sh ssl-opt.sh |tee sys-test-$TEST_OUTPUT
Gilles Peskine40be51f2020-04-09 18:50:08 +0200101echo '^^^^^^^^^^^^^^^^ ssl-opt.sh ^^^^^^^^^^^^^^^^'
SimonB21ab9d72016-03-12 20:37:32 +0000102echo
103
Gilles Peskineca51b472020-04-09 18:29:42 +0200104# Step 2c - Compatibility tests (keep going even if some tests fail)
Gilles Peskine40be51f2020-04-09 18:50:08 +0200105echo '################ compat.sh ################'
106{
Gilles Peskinec67c3b32023-08-27 21:33:41 +0200107 echo '#### compat.sh: Default ciphers'
108 sh compat.sh -m 'ssl3 tls1 tls1_1 tls12 dtls1 dtls12'
Gilles Peskine40be51f2020-04-09 18:50:08 +0200109 echo
110
111 echo '#### compat.sh: legacy (null, DES, RC4)'
Manuel Pégourié-Gonnard89d40272022-12-19 11:42:12 +0100112 OPENSSL="$OPENSSL_LEGACY" \
Manuel Pégourié-Gonnard2cd43a72024-04-09 23:01:09 +0200113 sh compat.sh -e '^$' -f 'NULL\|DES\|RC4\|ARCFOUR' \
114 -m 'ssl3 tls1 tls1_1 tls12 dtls1 dtls12'
Gilles Peskine40be51f2020-04-09 18:50:08 +0200115 echo
116
117 echo '#### compat.sh: next (ARIA, ChaCha)'
Manuel Pégourié-Gonnard89d40272022-12-19 11:42:12 +0100118 OPENSSL="$OPENSSL_NEXT" sh compat.sh -e '^$' -f 'ARIA\|CHACHA'
Gilles Peskine40be51f2020-04-09 18:50:08 +0200119 echo
120} | tee compat-test-$TEST_OUTPUT
121echo '^^^^^^^^^^^^^^^^ compat.sh ^^^^^^^^^^^^^^^^'
SimonB21ab9d72016-03-12 20:37:32 +0000122echo
123
124# Step 3 - Process the coverage report
125cd ..
Gilles Peskine5757d542020-04-09 18:32:48 +0200126{
127 make lcov
128 echo SUCCESS
129} | tee tests/cov-$TEST_OUTPUT
130
131if [ "$(tail -n1 tests/cov-$TEST_OUTPUT)" != "SUCCESS" ]; then
132 echo >&2 "Fatal: 'make lcov' failed"
133 exit 2
134fi
SimonB21ab9d72016-03-12 20:37:32 +0000135
136
137# Step 4 - Summarise the test report
138echo
139echo "========================================================================="
140echo "Test Report Summary"
141echo
142
Gilles Peskine5cf753a2021-07-22 11:08:30 +0200143# A failure of the left-hand side of a pipe is ignored (this is a limitation
144# of sh). We'll use the presence of this file as a marker that the generation
145# of the report succeeded.
Gilles Peskineeadd8ee2021-07-22 12:29:27 +0200146rm -f "tests/basic-build-test-$$.ok"
Gilles Peskine5cf753a2021-07-22 11:08:30 +0200147
Gilles Peskine81786e42021-07-13 23:27:01 +0200148{
SimonB21ab9d72016-03-12 20:37:32 +0000149
Gilles Peskine81786e42021-07-13 23:27:01 +0200150 cd tests
SimonB21ab9d72016-03-12 20:37:32 +0000151
Gilles Peskine81786e42021-07-13 23:27:01 +0200152 # Step 4a - Unit tests
153 echo "Unit tests - tests/scripts/run-test-suites.pl"
SimonB21ab9d72016-03-12 20:37:32 +0000154
Gilles Peskine81786e42021-07-13 23:27:01 +0200155 PASSED_TESTS=$(tail -n6 unit-test-$TEST_OUTPUT|sed -n -e 's/test cases passed :[\t]*\([0-9]*\)/\1/p'| tr -d ' ')
156 SKIPPED_TESTS=$(tail -n6 unit-test-$TEST_OUTPUT|sed -n -e 's/skipped :[ \t]*\([0-9]*\)/\1/p'| tr -d ' ')
157 TOTAL_SUITES=$(tail -n6 unit-test-$TEST_OUTPUT|sed -n -e 's/.* (\([0-9]*\) .*, [0-9]* tests run)/\1/p'| tr -d ' ')
158 FAILED_TESTS=$(tail -n6 unit-test-$TEST_OUTPUT|sed -n -e 's/failed :[\t]*\([0-9]*\)/\1/p' |tr -d ' ')
SimonB21ab9d72016-03-12 20:37:32 +0000159
Gilles Peskine81786e42021-07-13 23:27:01 +0200160 echo "No test suites : $TOTAL_SUITES"
161 echo "Passed : $PASSED_TESTS"
162 echo "Failed : $FAILED_TESTS"
163 echo "Skipped : $SKIPPED_TESTS"
164 echo "Total exec'd tests : $(($PASSED_TESTS + $FAILED_TESTS))"
165 echo "Total avail tests : $(($PASSED_TESTS + $FAILED_TESTS + $SKIPPED_TESTS))"
166 echo
SimonB21ab9d72016-03-12 20:37:32 +0000167
Gilles Peskine81786e42021-07-13 23:27:01 +0200168 TOTAL_PASS=$PASSED_TESTS
169 TOTAL_FAIL=$FAILED_TESTS
170 TOTAL_SKIP=$SKIPPED_TESTS
171 TOTAL_AVAIL=$(($PASSED_TESTS + $FAILED_TESTS + $SKIPPED_TESTS))
172 TOTAL_EXED=$(($PASSED_TESTS + $FAILED_TESTS))
SimonB21ab9d72016-03-12 20:37:32 +0000173
Gilles Peskine81786e42021-07-13 23:27:01 +0200174 # Step 4b - TLS Options tests
175 echo "TLS Options tests - tests/ssl-opt.sh"
SimonB21ab9d72016-03-12 20:37:32 +0000176
Gilles Peskine81786e42021-07-13 23:27:01 +0200177 PASSED_TESTS=$(tail -n5 sys-test-$TEST_OUTPUT|sed -n -e 's/.* (\([0-9]*\) \/ [0-9]* tests ([0-9]* skipped))$/\1/p')
178 SKIPPED_TESTS=$(tail -n5 sys-test-$TEST_OUTPUT|sed -n -e 's/.* ([0-9]* \/ [0-9]* tests (\([0-9]*\) skipped))$/\1/p')
179 TOTAL_TESTS=$(tail -n5 sys-test-$TEST_OUTPUT|sed -n -e 's/.* ([0-9]* \/ \([0-9]*\) tests ([0-9]* skipped))$/\1/p')
180 FAILED_TESTS=$(($TOTAL_TESTS - $PASSED_TESTS))
SimonB21ab9d72016-03-12 20:37:32 +0000181
Gilles Peskine81786e42021-07-13 23:27:01 +0200182 echo "Passed : $PASSED_TESTS"
183 echo "Failed : $FAILED_TESTS"
184 echo "Skipped : $SKIPPED_TESTS"
185 echo "Total exec'd tests : $TOTAL_TESTS"
186 echo "Total avail tests : $(($TOTAL_TESTS + $SKIPPED_TESTS))"
187 echo
188
189 TOTAL_PASS=$(($TOTAL_PASS+$PASSED_TESTS))
190 TOTAL_FAIL=$(($TOTAL_FAIL+$FAILED_TESTS))
191 TOTAL_SKIP=$(($TOTAL_SKIP+$SKIPPED_TESTS))
192 TOTAL_AVAIL=$(($TOTAL_AVAIL + $TOTAL_TESTS + $SKIPPED_TESTS))
193 TOTAL_EXED=$(($TOTAL_EXED + $TOTAL_TESTS))
SimonB21ab9d72016-03-12 20:37:32 +0000194
195
Gilles Peskine81786e42021-07-13 23:27:01 +0200196 # Step 4c - System Compatibility tests
197 echo "System/Compatibility tests - tests/compat.sh"
SimonB21ab9d72016-03-12 20:37:32 +0000198
Gilles Peskine81786e42021-07-13 23:27:01 +0200199 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 }')
200 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 }')
201 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 }')
202 FAILED_TESTS=$(($EXED_TESTS - $PASSED_TESTS))
SimonB21ab9d72016-03-12 20:37:32 +0000203
Gilles Peskine81786e42021-07-13 23:27:01 +0200204 echo "Passed : $PASSED_TESTS"
205 echo "Failed : $FAILED_TESTS"
206 echo "Skipped : $SKIPPED_TESTS"
207 echo "Total exec'd tests : $EXED_TESTS"
208 echo "Total avail tests : $(($EXED_TESTS + $SKIPPED_TESTS))"
209 echo
SimonB21ab9d72016-03-12 20:37:32 +0000210
Gilles Peskine81786e42021-07-13 23:27:01 +0200211 TOTAL_PASS=$(($TOTAL_PASS+$PASSED_TESTS))
212 TOTAL_FAIL=$(($TOTAL_FAIL+$FAILED_TESTS))
213 TOTAL_SKIP=$(($TOTAL_SKIP+$SKIPPED_TESTS))
214 TOTAL_AVAIL=$(($TOTAL_AVAIL + $EXED_TESTS + $SKIPPED_TESTS))
215 TOTAL_EXED=$(($TOTAL_EXED + $EXED_TESTS))
SimonB21ab9d72016-03-12 20:37:32 +0000216
217
Gilles Peskine81786e42021-07-13 23:27:01 +0200218 # Step 4d - Grand totals
219 echo "-------------------------------------------------------------------------"
220 echo "Total tests"
SimonB21ab9d72016-03-12 20:37:32 +0000221
Gilles Peskine81786e42021-07-13 23:27:01 +0200222 echo "Total Passed : $TOTAL_PASS"
223 echo "Total Failed : $TOTAL_FAIL"
224 echo "Total Skipped : $TOTAL_SKIP"
225 echo "Total exec'd tests : $TOTAL_EXED"
226 echo "Total avail tests : $TOTAL_AVAIL"
227 echo
SimonB21ab9d72016-03-12 20:37:32 +0000228
229
Gilles Peskine38a49562022-12-16 12:03:39 +0100230 # Step 4e - Coverage report
231 echo "Coverage statistics:"
232 sed -n '1,/^Overall coverage/d; /%/p' cov-$TEST_OUTPUT
233 echo
Dan Handleya8b26c22020-05-28 16:20:31 +0100234
Gilles Peskine81786e42021-07-13 23:27:01 +0200235 rm unit-test-$TEST_OUTPUT
236 rm sys-test-$TEST_OUTPUT
237 rm compat-test-$TEST_OUTPUT
238 rm cov-$TEST_OUTPUT
SimonB21ab9d72016-03-12 20:37:32 +0000239
Gilles Peskineeadd8ee2021-07-22 12:29:27 +0200240 # Mark the report generation as having succeeded. This must be the
241 # last thing in the report generation.
Gilles Peskine5cf753a2021-07-22 11:08:30 +0200242 touch "basic-build-test-$$.ok"
Gilles Peskine81786e42021-07-13 23:27:01 +0200243} | tee coverage-summary.txt
Janos Follath7ccac852016-06-06 13:18:39 +0100244
245make clean
246
247if [ -f "$CONFIG_BAK" ]; then
248 mv "$CONFIG_BAK" "$CONFIG_H"
249fi
Gilles Peskine6d6ee982020-04-09 18:28:14 +0200250
Gilles Peskine5cf753a2021-07-22 11:08:30 +0200251# The file must exist, otherwise it means something went wrong while generating
252# the coverage report. If something did go wrong, rm will complain so this
253# script will exit with a failure status.
Gilles Peskineeadd8ee2021-07-22 12:29:27 +0200254rm "tests/basic-build-test-$$.ok"