blob: eebcfeb2a21174a625a743838dc54bf0aefa71fb [file] [log] [blame]
Andres AG31f9b5b2016-10-04 17:14:38 +01001#! /usr/bin/env sh
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01002
Simon Butcher3ea7f522016-03-07 23:22:10 +00003# all.sh
4#
SimonB2e23c822016-04-16 21:54:39 +01005# This file is part of mbed TLS (https://tls.mbed.org)
6#
Gilles Peskine192c72f2017-12-21 15:59:21 +01007# Copyright (c) 2014-2017, ARM Limited, All Rights Reserved
8
9
10
11################################################################
12#### Documentation
13################################################################
14
Simon Butcher3ea7f522016-03-07 23:22:10 +000015# Purpose
Gilles Peskine192c72f2017-12-21 15:59:21 +010016# -------
Simon Butcher3ea7f522016-03-07 23:22:10 +000017#
SimonB2e23c822016-04-16 21:54:39 +010018# To run all tests possible or available on the platform.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010019#
Gilles Peskine192c72f2017-12-21 15:59:21 +010020# Notes for users
21# ---------------
22#
SimonB2e23c822016-04-16 21:54:39 +010023# Warning: the test is destructive. It includes various build modes and
24# configurations, and can and will arbitrarily change the current CMake
Gilles Peskine192c72f2017-12-21 15:59:21 +010025# configuration. The following files must be committed into git:
26# * include/mbedtls/config.h
27# * Makefile, library/Makefile, programs/Makefile, tests/Makefile
28# After running this script, the CMake cache will be lost and CMake
29# will no longer be initialised.
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +010030#
Gilles Peskine192c72f2017-12-21 15:59:21 +010031# The script assumes the presence of a number of tools:
32# * Basic Unix tools (Windows users note: a Unix-style find must be before
33# the Windows find in the PATH)
34# * Perl
35# * GNU Make
36# * CMake
37# * GCC and Clang (recent enough for using ASan with gcc and MemSan with clang, or valgrind)
Andrzej Kurek05be06c2018-06-28 04:41:50 -040038# * G++
Gilles Peskine192c72f2017-12-21 15:59:21 +010039# * arm-gcc and mingw-gcc
40# * ArmCC 5 and ArmCC 6, unless invoked with --no-armcc
Gilles Peskine192c72f2017-12-21 15:59:21 +010041# * OpenSSL and GnuTLS command line tools, recent enough for the
42# interoperability tests. If they don't support SSLv3 then a legacy
43# version of these tools must be present as well (search for LEGACY
44# below).
45# See the invocation of check_tools below for details.
46#
47# This script must be invoked from the toplevel directory of a git
48# working copy of Mbed TLS.
49#
50# Note that the output is not saved. You may want to run
51# script -c tests/scripts/all.sh
52# or
53# tests/scripts/all.sh >all.log 2>&1
54#
55# Notes for maintainers
56# ---------------------
57#
Gilles Peskine8f073122018-11-27 15:58:47 +010058# The bulk of the code is organized into functions that follow one of the
59# following naming conventions:
60# * pre_XXX: things to do before running the tests, in order.
61# * component_XXX: independent components. They can be run in any order.
Gilles Peskinec70637a2019-01-09 22:29:17 +010062# * component_check_XXX: quick tests that aren't worth parallelizing.
63# * component_build_XXX: build things but don't run them.
64# * component_test_XXX: build and test.
Gilles Peskine878cf602019-01-06 20:50:38 +000065# * support_XXX: if support_XXX exists and returns false then
66# component_XXX is not run by default.
Gilles Peskine8f073122018-11-27 15:58:47 +010067# * post_XXX: things to do after running the tests.
68# * other: miscellaneous support functions.
69#
Gilles Peskinec70637a2019-01-09 22:29:17 +010070# Each component must start by invoking `msg` with a short informative message.
71#
72# The framework performs some cleanup tasks after each component. This
73# means that components can assume that the working directory is in a
74# cleaned-up state, and don't need to perform the cleanup themselves.
75# * Run `make clean`.
76# * Restore `include/mbedtks/config.h` from a backup made before running
77# the component.
78# * Check out `Makefile`, `library/Makefile`, `programs/Makefile` and
79# `tests/Makefile` from git. This cleans up after an in-tree use of
80# CMake.
81#
82# Any command that is expected to fail must be protected so that the
83# script keeps running in --keep-going mode despite `set -e`. In keep-going
84# mode, if a protected command fails, this is logged as a failure and the
85# script will exit with a failure status once it has run all components.
86# Commands can be protected in any of the following ways:
87# * `make` is a function which runs the `make` command with protection.
88# Note that you must write `make VAR=value`, not `VAR=value make`,
89# because the `VAR=value make` syntax doesn't work with functions.
90# * Put `report_status` before the command to protect it.
91# * Put `if_build_successful` before a command. This protects it, and
92# additionally skips it if a prior invocation of `make` in the same
93# component failed.
94#
Gilles Peskine192c72f2017-12-21 15:59:21 +010095# The tests are roughly in order from fastest to slowest. This doesn't
96# have to be exact, but in general you should add slower tests towards
97# the end and fast checks near the beginning.
Gilles Peskine192c72f2017-12-21 15:59:21 +010098
99
100
101################################################################
102#### Initialization and command line parsing
103################################################################
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100104
SimonB2e23c822016-04-16 21:54:39 +0100105# Abort on errors (and uninitialised variables)
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100106set -eu
107
Gilles Peskine8f073122018-11-27 15:58:47 +0100108pre_check_environment () {
Gilles Peskinea16c2b12019-01-06 19:58:02 +0000109 if [ -d library -a -d include -a -d tests ]; then :; else
Gilles Peskine8f073122018-11-27 15:58:47 +0100110 echo "Must be run from mbed TLS root" >&2
111 exit 1
112 fi
113}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100114
Jaeden Ameroed93bdc2018-11-02 16:57:24 +0000115if ! [ -f crypto/Makefile ]; then
116 echo "Please initialize the crypto submodule" >&2
117 exit 1
118fi
119
Gilles Peskine8f073122018-11-27 15:58:47 +0100120pre_initialize_variables () {
121 CONFIG_H='include/mbedtls/config.h'
122 CONFIG_BAK="$CONFIG_H.bak"
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200123
Gilles Peskine8f073122018-11-27 15:58:47 +0100124 MEMORY=0
125 FORCE=0
126 KEEP_GOING=0
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100127
Jaeden Ameroc4cc2512019-01-30 15:35:44 +0000128 # Default commands, can be overridden by the environment
Gilles Peskine8f073122018-11-27 15:58:47 +0100129 : ${OPENSSL:="openssl"}
130 : ${OPENSSL_LEGACY:="$OPENSSL"}
131 : ${OPENSSL_NEXT:="$OPENSSL"}
132 : ${GNUTLS_CLI:="gnutls-cli"}
133 : ${GNUTLS_SERV:="gnutls-serv"}
134 : ${GNUTLS_LEGACY_CLI:="$GNUTLS_CLI"}
135 : ${GNUTLS_LEGACY_SERV:="$GNUTLS_SERV"}
136 : ${OUT_OF_SOURCE_DIR:=./mbedtls_out_of_source_build}
137 : ${ARMC5_BIN_DIR:=/usr/bin}
138 : ${ARMC6_BIN_DIR:=/usr/bin}
Andres AGdc192212016-08-31 17:33:13 +0100139
Gilles Peskine8f073122018-11-27 15:58:47 +0100140 # if MAKEFLAGS is not set add the -j option to speed up invocations of make
Gilles Peskinea1fc4b52019-01-06 20:15:26 +0000141 if [ -z "${MAKEFLAGS+set}" ]; then
Gilles Peskine8f073122018-11-27 15:58:47 +0100142 export MAKEFLAGS="-j"
143 fi
Gilles Peskine878cf602019-01-06 20:50:38 +0000144
145 # Gather the list of available components. These are the functions
146 # defined in this script whose name starts with "component_".
147 # Parse the script with sed, because in sh there is no way to list
148 # defined functions.
149 ALL_COMPONENTS=$(sed -n 's/^ *component_\([0-9A-Z_a-z]*\) *().*/\1/p' <"$0")
150
151 # Exclude components that are not supported on this platform.
152 SUPPORTED_COMPONENTS=
153 for component in $ALL_COMPONENTS; do
154 case $(type "support_$component" 2>&1) in
155 *' function'*)
156 if ! support_$component; then continue; fi;;
157 esac
158 SUPPORTED_COMPONENTS="$SUPPORTED_COMPONENTS $component"
159 done
Gilles Peskine8f073122018-11-27 15:58:47 +0100160}
Andres AG38495a32016-07-12 16:54:33 +0100161
Gilles Peskinea28db922019-01-10 00:05:18 +0100162# Test whether the component $1 is included in the command line patterns.
163is_component_included()
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100164{
165 set -f
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000166 for pattern in $COMMAND_LINE_COMPONENTS; do
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100167 set +f
168 case ${1#component_} in $pattern) return 0;; esac
169 done
170 set +f
171 return 1
172}
Andres AG7770ea82016-10-10 15:46:20 +0100173
Simon Butcher41eeccf2016-09-07 00:07:09 +0100174usage()
Andres AGd9eba4b2016-08-26 14:42:14 +0100175{
Gilles Peskine709346a2017-12-10 23:43:39 +0100176 cat <<EOF
Gilles Peskine92525112018-11-27 18:15:35 +0100177Usage: $0 [OPTION]... [COMPONENT]...
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100178Run mbedtls release validation tests.
Gilles Peskine92525112018-11-27 18:15:35 +0100179By default, run all tests. With one or more COMPONENT, run only those.
Gilles Peskinea28db922019-01-10 00:05:18 +0100180COMPONENT can be the name of a component or a shell wildcard pattern.
181
182Examples:
183 $0 "check_*"
184 Run all sanity checks.
185 $0 --no-armcc --except test_memsan
186 Run everything except builds that require armcc and MemSan.
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100187
188Special options:
189 -h|--help Print this help and exit.
Gilles Peskine878cf602019-01-06 20:50:38 +0000190 --list-all-components List all available test components and exit.
191 --list-components List components supported on this platform and exit.
Gilles Peskine709346a2017-12-10 23:43:39 +0100192
193General options:
194 -f|--force Force the tests to overwrite any modified files.
Gilles Peskine7c652162017-12-11 00:01:40 +0100195 -k|--keep-going Run all tests and report errors at the end.
Gilles Peskine709346a2017-12-10 23:43:39 +0100196 -m|--memory Additional optional memory tests.
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100197 --armcc Run ARM Compiler builds (on by default).
Gilles Peskinea28db922019-01-10 00:05:18 +0100198 --except Exclude the COMPONENTs listed on the command line,
199 instead of running only those.
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100200 --no-armcc Skip ARM Compiler builds.
Gilles Peskine38d81652018-03-21 08:40:26 +0100201 --no-force Refuse to overwrite modified files (default).
202 --no-keep-going Stop at the first error (default).
203 --no-memory No additional memory tests (default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100204 --out-of-source-dir=<path> Directory used for CMake out-of-source build tests.
Gilles Peskine38d81652018-03-21 08:40:26 +0100205 --random-seed Use a random seed value for randomized tests (default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100206 -r|--release-test Run this script in release mode. This fixes the seed value to 1.
207 -s|--seed Integer seed value to use for this test run.
208
209Tool path options:
210 --armc5-bin-dir=<ARMC5_bin_dir_path> ARM Compiler 5 bin directory.
211 --armc6-bin-dir=<ARMC6_bin_dir_path> ARM Compiler 6 bin directory.
212 --gnutls-cli=<GnuTLS_cli_path> GnuTLS client executable to use for most tests.
213 --gnutls-serv=<GnuTLS_serv_path> GnuTLS server executable to use for most tests.
214 --gnutls-legacy-cli=<GnuTLS_cli_path> GnuTLS client executable to use for legacy tests.
215 --gnutls-legacy-serv=<GnuTLS_serv_path> GnuTLS server executable to use for legacy tests.
216 --openssl=<OpenSSL_path> OpenSSL executable to use for most tests.
217 --openssl-legacy=<OpenSSL_path> OpenSSL executable to use for legacy tests e.g. SSLv3.
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100218 --openssl-next=<OpenSSL_path> OpenSSL executable to use for recent things like ARIA
Gilles Peskine709346a2017-12-10 23:43:39 +0100219EOF
SimonB2e23c822016-04-16 21:54:39 +0100220}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100221
222# remove built files as well as the cmake cache/config
223cleanup()
224{
Gilles Peskinea71d64c2018-03-21 12:16:57 +0100225 if [ -n "${MBEDTLS_ROOT_DIR+set}" ]; then
226 cd "$MBEDTLS_ROOT_DIR"
227 fi
228
Gilles Peskine7c652162017-12-11 00:01:40 +0100229 command make clean
Jaeden Ameroed93bdc2018-11-02 16:57:24 +0000230 cd crypto
231 command make clean
232 cd ..
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200233
Gilles Peskine31b07e22018-03-21 12:15:06 +0100234 # Remove CMake artefacts
Jaeden Amero2d0e00f2018-11-07 18:46:41 +0000235 find . -name .git -prune -o \
Gilles Peskine31b07e22018-03-21 12:15:06 +0100236 -iname CMakeFiles -exec rm -rf {} \+ -o \
237 \( -iname cmake_install.cmake -o \
238 -iname CTestTestfile.cmake -o \
239 -iname CMakeCache.txt \) -exec rm {} \+
240 # Recover files overwritten by in-tree CMake builds
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000241 rm -f include/Makefile include/mbedtls/Makefile programs/*/Makefile
Paul Bakkerfe0984d2014-06-13 00:13:45 +0200242 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile
243 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile
Jaeden Ameroed93bdc2018-11-02 16:57:24 +0000244 cd crypto
245 rm -f include/Makefile include/mbedtls/Makefile programs/*/Makefile
246 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile
247 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile
248 cd ..
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200249
250 if [ -f "$CONFIG_BAK" ]; then
251 mv "$CONFIG_BAK" "$CONFIG_H"
252 fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100253}
254
Gilles Peskine7c652162017-12-11 00:01:40 +0100255# Executed on exit. May be redefined depending on command line options.
256final_report () {
257 :
258}
259
260fatal_signal () {
261 cleanup
262 final_report $1
263 trap - $1
264 kill -$1 $$
265}
266
267trap 'fatal_signal HUP' HUP
268trap 'fatal_signal INT' INT
269trap 'fatal_signal TERM' TERM
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200270
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100271msg()
272{
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100273 if [ -n "${current_component:-}" ]; then
274 current_section="${current_component#component_}: $1"
275 else
276 current_section="$1"
277 fi
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100278 echo ""
279 echo "******************************************************************"
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100280 echo "* $current_section "
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000281 printf "* "; date
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100282 echo "******************************************************************"
283}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100284
Gilles Peskine8f073122018-11-27 15:58:47 +0100285armc6_build_test()
286{
287 FLAGS="$1"
Andres AGa5cd9732016-10-17 15:23:10 +0100288
Gilles Peskine8f073122018-11-27 15:58:47 +0100289 msg "build: ARM Compiler 6 ($FLAGS), make"
290 ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \
291 WARNING_CFLAGS='-xc -std=c99' make lib
292 make clean
293}
Andres AGa5cd9732016-10-17 15:23:10 +0100294
Andres AGd9eba4b2016-08-26 14:42:14 +0100295err_msg()
296{
297 echo "$1" >&2
298}
299
300check_tools()
301{
302 for TOOL in "$@"; do
Andres AG98393602017-01-31 17:04:45 +0000303 if ! `type "$TOOL" >/dev/null 2>&1`; then
Andres AGd9eba4b2016-08-26 14:42:14 +0100304 err_msg "$TOOL not found!"
305 exit 1
306 fi
307 done
308}
309
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400310check_headers_in_cpp () {
311 ls include/mbedtls >headers.txt
312 <programs/test/cpp_dummy_build.cpp sed -n 's/"$//; s!^#include "mbedtls/!!p' |
313 sort |
314 diff headers.txt -
315 rm headers.txt
316}
317
Gilles Peskine8f073122018-11-27 15:58:47 +0100318pre_parse_command_line () {
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000319 COMMAND_LINE_COMPONENTS=
Gilles Peskinea28db922019-01-10 00:05:18 +0100320 all_except=0
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000321 no_armcc=
SimonB2e23c822016-04-16 21:54:39 +0100322
Gilles Peskine8f073122018-11-27 15:58:47 +0100323 while [ $# -gt 0 ]; do
Gilles Peskine55f7c942019-01-09 22:28:21 +0100324 case "$1" in
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000325 --armcc) no_armcc=;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100326 --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
327 --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000328 --except) all_except=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100329 --force|-f) FORCE=1;;
330 --gnutls-cli) shift; GNUTLS_CLI="$1";;
331 --gnutls-legacy-cli) shift; GNUTLS_LEGACY_CLI="$1";;
332 --gnutls-legacy-serv) shift; GNUTLS_LEGACY_SERV="$1";;
333 --gnutls-serv) shift; GNUTLS_SERV="$1";;
334 --help|-h) usage; exit;;
335 --keep-going|-k) KEEP_GOING=1;;
Gilles Peskine878cf602019-01-06 20:50:38 +0000336 --list-all-components) printf '%s\n' $ALL_COMPONENTS; exit;;
337 --list-components) printf '%s\n' $SUPPORTED_COMPONENTS; exit;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100338 --memory|-m) MEMORY=1;;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000339 --no-armcc) no_armcc=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100340 --no-force) FORCE=0;;
341 --no-keep-going) KEEP_GOING=0;;
342 --no-memory) MEMORY=0;;
343 --openssl) shift; OPENSSL="$1";;
344 --openssl-legacy) shift; OPENSSL_LEGACY="$1";;
345 --openssl-next) shift; OPENSSL_NEXT="$1";;
346 --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
347 --random-seed) unset SEED;;
348 --release-test|-r) SEED=1;;
349 --seed|-s) shift; SEED="$1";;
350 -*)
351 echo >&2 "Unknown option: $1"
352 echo >&2 "Run $0 --help for usage."
353 exit 120
354 ;;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000355 *) COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS $1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100356 esac
357 shift
Gilles Peskine8f073122018-11-27 15:58:47 +0100358 done
SimonB2e23c822016-04-16 21:54:39 +0100359
Gilles Peskinea28db922019-01-10 00:05:18 +0100360 # With no list of components, run everything.
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000361 if [ -z "$COMMAND_LINE_COMPONENTS" ]; then
362 all_except=1
Andres AGdc192212016-08-31 17:33:13 +0100363 fi
364
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000365 # --no-armcc is a legacy option. The modern way is --except '*_armcc*'.
366 # Ignore it if components are listed explicitly on the command line.
Gilles Peskinea28db922019-01-10 00:05:18 +0100367 if [ -n "$no_armcc" ] && [ $all_except -eq 1 ]; then
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000368 COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS *_armcc*"
SimonB2e23c822016-04-16 21:54:39 +0100369 fi
SimonB2e23c822016-04-16 21:54:39 +0100370
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000371 # Build the list of components to run.
Gilles Peskinea28db922019-01-10 00:05:18 +0100372 RUN_COMPONENTS=
373 for component in $SUPPORTED_COMPONENTS; do
374 if is_component_included "$component"; [ $? -eq $all_except ]; then
375 RUN_COMPONENTS="$RUN_COMPONENTS $component"
376 fi
377 done
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000378
379 unset all_except
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000380 unset no_armcc
Gilles Peskine8f073122018-11-27 15:58:47 +0100381}
SimonB2e23c822016-04-16 21:54:39 +0100382
Gilles Peskine8f073122018-11-27 15:58:47 +0100383pre_check_git () {
384 if [ $FORCE -eq 1 ]; then
Gilles Peskine53190e62019-01-09 23:17:35 +0100385 rm -rf "$OUT_OF_SOURCE_DIR"
Gilles Peskine8f073122018-11-27 15:58:47 +0100386 git checkout-index -f -q $CONFIG_H
387 cleanup
388 else
SimonB2e23c822016-04-16 21:54:39 +0100389
Gilles Peskine8f073122018-11-27 15:58:47 +0100390 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
391 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
392 echo "You can either delete this directory manually, or force the test by rerunning"
393 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
394 exit 1
395 fi
396
Gilles Peskined1174cf2019-01-09 22:30:01 +0100397 if ! git diff --quiet include/mbedtls/config.h; then
Gilles Peskine8f073122018-11-27 15:58:47 +0100398 err_msg "Warning - the configuration file 'include/mbedtls/config.h' has been edited. "
399 echo "You can either delete or preserve your work, or force the test by rerunning the"
400 echo "script as: $0 --force"
401 exit 1
402 fi
SimonB2e23c822016-04-16 21:54:39 +0100403 fi
Gilles Peskine8f073122018-11-27 15:58:47 +0100404}
SimonB2e23c822016-04-16 21:54:39 +0100405
Gilles Peskine8f073122018-11-27 15:58:47 +0100406pre_setup_keep_going () {
Gilles Peskine7c652162017-12-11 00:01:40 +0100407 failure_summary=
408 failure_count=0
409 start_red=
410 end_color=
411 if [ -t 1 ]; then
Gilles Peskine9736b9d2018-01-02 21:54:17 +0100412 case "${TERM:-}" in
Gilles Peskine7c652162017-12-11 00:01:40 +0100413 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
414 start_red=$(printf '\033[31m')
415 end_color=$(printf '\033[0m')
416 ;;
417 esac
418 fi
419 record_status () {
420 if "$@"; then
421 last_status=0
422 else
423 last_status=$?
424 text="$current_section: $* -> $last_status"
425 failure_summary="$failure_summary
426$text"
427 failure_count=$((failure_count + 1))
428 echo "${start_red}^^^^$text^^^^${end_color}"
429 fi
430 }
431 make () {
432 case "$*" in
433 *test|*check)
434 if [ $build_status -eq 0 ]; then
435 record_status command make "$@"
436 else
437 echo "(skipped because the build failed)"
438 fi
439 ;;
440 *)
441 record_status command make "$@"
442 build_status=$last_status
443 ;;
444 esac
445 }
446 final_report () {
447 if [ $failure_count -gt 0 ]; then
448 echo
449 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
450 echo "${start_red}FAILED: $failure_count${end_color}$failure_summary"
451 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Jaeden Amero7c1258d2018-07-20 16:42:14 +0100452 exit 1
Gilles Peskine7c652162017-12-11 00:01:40 +0100453 elif [ -z "${1-}" ]; then
454 echo "SUCCESS :)"
455 fi
456 if [ -n "${1-}" ]; then
457 echo "Killed by SIG$1."
458 fi
459 }
Gilles Peskine8f073122018-11-27 15:58:47 +0100460}
461
Gilles Peskine7c652162017-12-11 00:01:40 +0100462if_build_succeeded () {
463 if [ $build_status -eq 0 ]; then
464 record_status "$@"
465 fi
466}
467
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200468# to be used instead of ! for commands run with
469# record_status or if_build_succeeded
470not() {
471 ! "$@"
472}
473
Gilles Peskine8f073122018-11-27 15:58:47 +0100474pre_print_configuration () {
475 msg "info: $0 configuration"
476 echo "MEMORY: $MEMORY"
477 echo "FORCE: $FORCE"
478 echo "SEED: ${SEED-"UNSET"}"
479 echo "OPENSSL: $OPENSSL"
480 echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
481 echo "OPENSSL_NEXT: $OPENSSL_NEXT"
482 echo "GNUTLS_CLI: $GNUTLS_CLI"
483 echo "GNUTLS_SERV: $GNUTLS_SERV"
484 echo "GNUTLS_LEGACY_CLI: $GNUTLS_LEGACY_CLI"
485 echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV"
486 echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
487 echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
488}
Andres AG7770ea82016-10-10 15:46:20 +0100489
Andres AGd9eba4b2016-08-26 14:42:14 +0100490# Make sure the tools we need are available.
Gilles Peskine8f073122018-11-27 15:58:47 +0100491pre_check_tools () {
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000492 # Build the list of variables to pass to output_env.sh.
493 set env
SimonB2e23c822016-04-16 21:54:39 +0100494
Gilles Peskine87964262019-01-06 22:40:00 +0000495 case " $RUN_COMPONENTS " in
496 # Require OpenSSL and GnuTLS if running any tests (as opposed to
497 # only doing builds). Not all tests run OpenSSL and GnuTLS, but this
498 # is a good enough approximation in practice.
499 *" test_"*)
500 # To avoid setting OpenSSL and GnuTLS for each call to compat.sh
501 # and ssl-opt.sh, we just export the variables they require.
502 export OPENSSL_CMD="$OPENSSL"
503 export GNUTLS_CLI="$GNUTLS_CLI"
504 export GNUTLS_SERV="$GNUTLS_SERV"
505 # Avoid passing --seed flag in every call to ssl-opt.sh
506 if [ -n "${SEED-}" ]; then
507 export SEED
508 fi
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000509 set "$@" OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY"
510 set "$@" GNUTLS_CLI="$GNUTLS_CLI" GNUTLS_SERV="$GNUTLS_SERV"
511 set "$@" GNUTLS_LEGACY_CLI="$GNUTLS_LEGACY_CLI"
512 set "$@" GNUTLS_LEGACY_SERV="$GNUTLS_LEGACY_SERV"
Gilles Peskine87964262019-01-06 22:40:00 +0000513 check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$OPENSSL_NEXT" \
514 "$GNUTLS_CLI" "$GNUTLS_SERV" \
515 "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV"
516 ;;
517 esac
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200518
Gilles Peskine87964262019-01-06 22:40:00 +0000519 case " $RUN_COMPONENTS " in
520 *_doxygen[_\ ]*) check_tools "doxygen" "dot";;
521 esac
Andres AGd9eba4b2016-08-26 14:42:14 +0100522
Gilles Peskine87964262019-01-06 22:40:00 +0000523 case " $RUN_COMPONENTS " in
524 *_arm_none_eabi_gcc[_\ ]*) check_tools "arm-none-eabi-gcc";;
525 esac
Andres AGd9eba4b2016-08-26 14:42:14 +0100526
Gilles Peskine87964262019-01-06 22:40:00 +0000527 case " $RUN_COMPONENTS " in
528 *_mingw[_\ ]*) check_tools "i686-w64-mingw32-gcc";;
529 esac
530
531 case " $RUN_COMPONENTS " in
532 *" test_zeroize "*) check_tools "gdb";;
533 esac
534
535 case " $RUN_COMPONENTS " in
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000536 *_armcc*)
Gilles Peskine87964262019-01-06 22:40:00 +0000537 ARMC5_CC="$ARMC5_BIN_DIR/armcc"
538 ARMC5_AR="$ARMC5_BIN_DIR/armar"
539 ARMC6_CC="$ARMC6_BIN_DIR/armclang"
540 ARMC6_AR="$ARMC6_BIN_DIR/armar"
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000541 check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC6_CC" "$ARMC6_AR";;
542 esac
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000543
544 msg "info: output_env.sh"
545 case $RUN_COMPONENTS in
546 *_armcc*)
547 set "$@" ARMC5_CC="$ARMC5_CC" ARMC6_CC="$ARMC6_CC" RUN_ARMCC=1;;
548 *) set "$@" RUN_ARMCC=0;;
549 esac
550 "$@" scripts/output_env.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100551}
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100552
Gilles Peskine192c72f2017-12-21 15:59:21 +0100553
554
555################################################################
556#### Basic checks
557################################################################
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100558
559#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200560# Test Suites to be executed
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100561#
Manuel Pégourié-Gonnard3d404b42015-07-08 21:59:16 +0100562# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200563# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100564# and/or are more likely to fail than others (eg I use Clang most of the
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200565# time, so start with a GCC build).
566# 2. Minimize total running time, by avoiding useless rebuilds
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100567#
Manuel Pégourié-Gonnard259b08a2016-01-08 16:27:41 +0100568# Indicative running times are given for reference.
569
Gilles Peskine8f073122018-11-27 15:58:47 +0100570component_check_recursion () {
571 msg "test: recursion.pl" # < 1s
572 record_status tests/scripts/recursion.pl library/*.c
573}
Janos Follathb72c6782016-07-19 14:54:17 +0100574
Gilles Peskine8f073122018-11-27 15:58:47 +0100575component_check_generated_files () {
576 msg "test: freshness of generated source files" # < 1s
577 record_status tests/scripts/check-generated-files.sh
578}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200579
Gilles Peskine8f073122018-11-27 15:58:47 +0100580component_check_doxy_blocks () {
581 msg "test: doxygen markup outside doxygen blocks" # < 1s
582 record_status tests/scripts/check-doxy-blocks.pl
583}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200584
Gilles Peskine8f073122018-11-27 15:58:47 +0100585component_check_files () {
586 msg "test: check-files.py" # < 1s
Gilles Peskine8f073122018-11-27 15:58:47 +0100587 record_status tests/scripts/check-files.py
588}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200589
Gilles Peskine8f073122018-11-27 15:58:47 +0100590component_check_names () {
591 msg "test/build: declared and exported names" # < 3s
Gilles Peskine8f073122018-11-27 15:58:47 +0100592 record_status tests/scripts/check-names.sh
593}
Darryl Greena07039c2018-03-13 16:48:16 +0000594
Gilles Peskine8f073122018-11-27 15:58:47 +0100595component_check_doxygen_warnings () {
596 msg "test: doxygen warnings" # ~ 3s
Gilles Peskine8f073122018-11-27 15:58:47 +0100597 record_status tests/scripts/doxygen.sh
598}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200599
Gilles Peskine192c72f2017-12-21 15:59:21 +0100600
601
602################################################################
603#### Build and test many configurations and targets
604################################################################
605
Gilles Peskine8f073122018-11-27 15:58:47 +0100606component_test_default_cmake_gcc_asan () {
607 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100608 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
609 make
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200610
Gilles Peskine8f073122018-11-27 15:58:47 +0100611 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
612 make test
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200613
Gilles Peskine8f073122018-11-27 15:58:47 +0100614 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
615 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200616
Gilles Peskine8f073122018-11-27 15:58:47 +0100617 msg "test: compat.sh (ASan build)" # ~ 6 min
618 if_build_succeeded tests/compat.sh
619}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200620
Gilles Peskine782f4112018-11-27 16:11:09 +0100621component_test_ref_configs () {
622 msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
623 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
624 record_status tests/scripts/test-ref-configs.pl
625}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200626
Gilles Peskine8f073122018-11-27 15:58:47 +0100627component_test_sslv3 () {
628 msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100629 scripts/config.pl set MBEDTLS_SSL_PROTO_SSL3
630 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
631 make
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200632
Gilles Peskine8f073122018-11-27 15:58:47 +0100633 msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
634 make test
Simon Butcher3ea7f522016-03-07 23:22:10 +0000635
Gilles Peskine8f073122018-11-27 15:58:47 +0100636 msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
637 if_build_succeeded tests/compat.sh -m 'tls1 tls1_1 tls1_2 dtls1 dtls1_2'
638 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
Simon Butcher3ea7f522016-03-07 23:22:10 +0000639
Gilles Peskine8f073122018-11-27 15:58:47 +0100640 msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
641 if_build_succeeded tests/ssl-opt.sh
642}
Simon Butcher3ea7f522016-03-07 23:22:10 +0000643
Gilles Peskine8f073122018-11-27 15:58:47 +0100644component_test_no_renegotiation () {
645 msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100646 scripts/config.pl unset MBEDTLS_SSL_RENEGOTIATION
647 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
648 make
Simon Butcher3ea7f522016-03-07 23:22:10 +0000649
Gilles Peskine8f073122018-11-27 15:58:47 +0100650 msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
651 make test
Hanno Becker134c2ab2017-10-12 15:29:50 +0100652
Gilles Peskine8f073122018-11-27 15:58:47 +0100653 msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
654 if_build_succeeded tests/ssl-opt.sh
655}
Hanno Becker134c2ab2017-10-12 15:29:50 +0100656
Gilles Peskine8f073122018-11-27 15:58:47 +0100657component_test_rsa_no_crt () {
658 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100659 scripts/config.pl set MBEDTLS_RSA_NO_CRT
660 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
661 make
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +0100662
Gilles Peskine8f073122018-11-27 15:58:47 +0100663 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
664 make test
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100665
Gilles Peskine8f073122018-11-27 15:58:47 +0100666 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
667 if_build_succeeded tests/ssl-opt.sh -f RSA
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100668
Gilles Peskine8f073122018-11-27 15:58:47 +0100669 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
670 if_build_succeeded tests/compat.sh -t RSA
671}
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100672
Gilles Peskine8f073122018-11-27 15:58:47 +0100673component_test_small_ssl_out_content_len () {
674 msg "build: small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100675 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 16384
676 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
677 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
678 make
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100679
Gilles Peskine8f073122018-11-27 15:58:47 +0100680 msg "test: small SSL_OUT_CONTENT_LEN - ssl-opt.sh MFL and large packet tests"
681 if_build_succeeded tests/ssl-opt.sh -f "Max fragment\|Large packet"
682}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000683
Gilles Peskine8f073122018-11-27 15:58:47 +0100684component_test_small_ssl_in_content_len () {
685 msg "build: small SSL_IN_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100686 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 4096
687 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 16384
688 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
689 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000690
Gilles Peskine8f073122018-11-27 15:58:47 +0100691 msg "test: small SSL_IN_CONTENT_LEN - ssl-opt.sh MFL tests"
692 if_build_succeeded tests/ssl-opt.sh -f "Max fragment"
693}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000694
Gilles Peskine8f073122018-11-27 15:58:47 +0100695component_test_small_ssl_dtls_max_buffering () {
696 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0"
Gilles Peskine8f073122018-11-27 15:58:47 +0100697 scripts/config.pl set MBEDTLS_SSL_DTLS_MAX_BUFFERING 1000
698 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
699 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000700
Gilles Peskine8f073122018-11-27 15:58:47 +0100701 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0 - ssl-opt.sh specific reordering test"
702 if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer out-of-order hs msg before reassembling next, free buffered msg"
703}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100704
Gilles Peskine8f073122018-11-27 15:58:47 +0100705component_test_small_mbedtls_ssl_dtls_max_buffering () {
706 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1"
Gilles Peskine8f073122018-11-27 15:58:47 +0100707 scripts/config.pl set MBEDTLS_SSL_DTLS_MAX_BUFFERING 240
708 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
709 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100710
Gilles Peskine8f073122018-11-27 15:58:47 +0100711 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1 - ssl-opt.sh specific reordering test"
712 if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer encrypted Finished message, drop for fragmented NewSessionTicket"
713}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100714
Gilles Peskine8f073122018-11-27 15:58:47 +0100715component_test_full_cmake_clang () {
716 msg "build: cmake, full config, clang" # ~ 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100717 scripts/config.pl full
718 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
719 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check -D ENABLE_TESTING=On .
720 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100721
Gilles Peskine8f073122018-11-27 15:58:47 +0100722 msg "test: main suites (full config)" # ~ 5s
723 make test
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100724
Gilles Peskine8f073122018-11-27 15:58:47 +0100725 msg "test: ssl-opt.sh default, ECJPAKE, SSL async (full config)" # ~ 1s
726 if_build_succeeded tests/ssl-opt.sh -f 'Default\|ECJPAKE\|SSL async private'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200727
Gilles Peskine8f073122018-11-27 15:58:47 +0100728 msg "test: compat.sh RC4, DES & NULL (full config)" # ~ 2 min
729 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" GNUTLS_CLI="$GNUTLS_LEGACY_CLI" GNUTLS_SERV="$GNUTLS_LEGACY_SERV" tests/compat.sh -e '3DES\|DES-CBC3' -f 'NULL\|DES\|RC4\|ARCFOUR'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200730
Gilles Peskine8f073122018-11-27 15:58:47 +0100731 msg "test: compat.sh ARIA + ChachaPoly"
732 if_build_succeeded env OPENSSL_CMD="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
733}
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200734
Gilles Peskine8f073122018-11-27 15:58:47 +0100735component_build_deprecated () {
736 msg "build: make, full config + DEPRECATED_WARNING, gcc -O" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100737 scripts/config.pl full
738 scripts/config.pl set MBEDTLS_DEPRECATED_WARNING
739 # Build with -O -Wextra to catch a maximum of issues.
740 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra' lib programs
741 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100742
Gilles Peskine8f073122018-11-27 15:58:47 +0100743 msg "build: make, full config + DEPRECATED_REMOVED, clang -O" # ~ 30s
744 # No cleanup, just tweak the configuration and rebuild
745 make clean
746 scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
747 scripts/config.pl set MBEDTLS_DEPRECATED_REMOVED
748 # Build with -O -Wextra to catch a maximum of issues.
749 make CC=clang CFLAGS='-O -Werror -Wall -Wextra' lib programs
750 make CC=clang CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
751}
Jaeden Ameroed93bdc2018-11-02 16:57:24 +0000752
Jaeden Ameroed93bdc2018-11-02 16:57:24 +0000753
Gilles Peskine8f073122018-11-27 15:58:47 +0100754component_test_depends_curves () {
755 msg "test/build: curves.pl (gcc)" # ~ 4 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100756 record_status tests/scripts/curves.pl
757}
Jaeden Ameroacaabe72018-11-07 11:52:52 +0000758
Gilles Peskine8f073122018-11-27 15:58:47 +0100759component_test_depends_hashes () {
760 msg "test/build: depends-hashes.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100761 record_status tests/scripts/depends-hashes.pl
762}
Jaeden Ameroacaabe72018-11-07 11:52:52 +0000763
Gilles Peskine8f073122018-11-27 15:58:47 +0100764component_test_depends_pkalgs () {
765 msg "test/build: depends-pkalgs.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100766 record_status tests/scripts/depends-pkalgs.pl
767}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100768
Gilles Peskine8f073122018-11-27 15:58:47 +0100769component_build_key_exchanges () {
770 msg "test/build: key-exchanges (gcc)" # ~ 1 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100771 record_status tests/scripts/key-exchanges.pl
772}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100773
Gilles Peskine8f073122018-11-27 15:58:47 +0100774component_build_default_make_gcc_and_cxx () {
775 msg "build: Unix make, -Os (gcc)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100776 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100777
Gilles Peskine8f073122018-11-27 15:58:47 +0100778 msg "test: verify header list in cpp_dummy_build.cpp"
779 record_status check_headers_in_cpp
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100780
Gilles Peskine8f073122018-11-27 15:58:47 +0100781 msg "build: Unix make, incremental g++"
782 make TEST_CPP=1
783}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100784
Andrzej Kurekfd0381a2019-02-05 05:00:02 -0500785component_test_use_psa_crypto_cmake () {
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500786 # USE_CRYPTO_SUBMODULE: check that the build works with CMake
787 msg "build: cmake, full config + USE_CRYPTO_SUBMODULE, gcc+debug"
788 scripts/config.pl full # enables md4 and submodule doesn't enable md4
789 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
790 CC=gcc cmake -D USE_CRYPTO_SUBMODULE=1 -D CMAKE_BUILD_TYPE=Debug .
791 make
792 msg "test: top-level libmbedcrypto wasn't built (USE_CRYPTO_SUBMODULE, cmake)"
793 if_build_succeeded not test -f library/libmbedcrypto.a
794 msg "test: libmbedcrypto symbols are from crypto files (USE_CRYPTO_SUBMODULE, cmake)"
795 if_build_succeeded objdump -g crypto/library/libmbedcrypto.a | grep -E 'crypto/library$' > /dev/null
796 msg "test: libmbedcrypto uses top-level config (USE_CRYPTO_SUBMODULE, cmake)"
797 if_build_succeeded objdump -g crypto/library/libmbedcrypto.a | grep 'md4.c' > /dev/null
798 msg "test: main suites (USE_CRYPTO_SUBMODULE, cmake)"
799 make test
800 msg "test: ssl-opt.sh (USE_CRYPTO_SUBMODULE, cmake)"
801 if_build_succeeded tests/ssl-opt.sh
802}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100803
Andrzej Kurekfd0381a2019-02-05 05:00:02 -0500804component_test_use_psa_crypto_make () {
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500805 # USE_CRYPTO_SUBMODULE: check that the build works with make
806 msg "build: make, full config + USE_CRYPTO_SUBMODULE, gcc+debug"
807 scripts/config.pl full # enables md4 and submodule doesn't enable md4
808 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
809 make CC=gcc CFLAGS='-g' USE_CRYPTO_SUBMODULE=1
810 msg "test: top-level libmbedcrypto wasn't built (USE_CRYPTO_SUBMODULE, make)"
811 if_build_succeeded not test -f library/libmbedcrypto.a
812 msg "test: libmbedcrypto symbols are from crypto files (USE_CRYPTO_SUBMODULE, make)"
813 if_build_succeeded objdump -g crypto/library/libmbedcrypto.a | grep -E 'crypto/library$' > /dev/null
814 msg "test: libmbedcrypto uses top-level config (USE_CRYPTO_SUBMODULE, make)"
815 if_build_succeeded objdump -g crypto/library/libmbedcrypto.a | grep 'md4.c' > /dev/null
816 msg "test: main suites (USE_CRYPTO_SUBMODULE, make)"
817 make CC=gcc USE_CRYPTO_SUBMODULE=1 test
818 msg "test: ssl-opt.sh (USE_CRYPTO_SUBMODULE, make)"
819 if_build_succeeded tests/ssl-opt.sh
820}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100821
Andrzej Kurekfd0381a2019-02-05 05:00:02 -0500822component_test_not_use_psa_crypto_make () {
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500823 # Don't USE_CRYPTO_SUBMODULE: check that the submodule is not used with make
824 msg "build: make, full config - USE_CRYPTO_SUBMODULE, gcc+debug"
825 scripts/config.pl full
826 make CC=gcc CFLAGS='-g'
827 msg "test: submodule libmbedcrypto wasn't built (USE_CRYPTO_SUBMODULE, make)"
828 if_build_succeeded not test -f crypto/library/libmbedcrypto.a
829 msg "test: libmbedcrypto symbols are from library files (USE_CRYPTO_SUBMODULE, make)"
830 if_build_succeeded objdump -g library/libmbedcrypto.a | grep -E 'library$' | not grep 'crypto' > /dev/null
831}
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200832
Andrzej Kurekfd0381a2019-02-05 05:00:02 -0500833component_test_not_use_psa_crypto_cmake () {
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500834 # Don't USE_CRYPTO_SUBMODULE: check that the submodule is not used with CMake
835 msg "build: cmake, full config - USE_CRYPTO_SUBMODULE, gcc+debug"
836 scripts/config.pl full
837 CC=gcc cmake -D CMAKE_BUILD_TYPE=Debug .
838 make
839 msg "test: submodule libmbedcrypto wasn't built (USE_CRYPTO_SUBMODULE, cmake)"
840 if_build_succeeded not test -f crypto/library/libmbedcrypto.a
841 msg "test: libmbedcrypto symbols are from library files (USE_CRYPTO_SUBMODULE, cmake)"
842 if_build_succeeded objdump -g library/libmbedcrypto.a | grep -E 'library$' | not grep 'crypto' > /dev/null
843}
Manuel Pégourié-Gonnard1fe6bb92017-06-06 11:36:16 +0200844
Andrzej Kurekfd0381a2019-02-05 05:00:02 -0500845component_test_use_psa_crypto_full_cmake_asan() {
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500846 # MBEDTLS_USE_PSA_CRYPTO: run the same set of tests as basic-build-test.sh
847 msg "build: cmake, full config + MBEDTLS_USE_PSA_CRYPTO, ASan"
848 scripts/config.pl full
849 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
850 scripts/config.pl set MBEDTLS_PSA_CRYPTO_C
851 scripts/config.pl set MBEDTLS_USE_PSA_CRYPTO
852 CC=gcc cmake -D USE_CRYPTO_SUBMODULE=1 -D CMAKE_BUILD_TYPE:String=Asan .
853 make
Manuel Pégourié-Gonnard43be6cd2017-06-20 09:53:42 +0200854
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500855 msg "test: main suites (MBEDTLS_USE_PSA_CRYPTO)"
856 make test
Manuel Pégourié-Gonnard503a5ef2015-10-23 09:04:45 +0200857
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500858 msg "test: ssl-opt.sh (MBEDTLS_USE_PSA_CRYPTO)"
859 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100860
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500861 msg "test: compat.sh default (MBEDTLS_USE_PSA_CRYPTO)"
862 if_build_succeeded tests/compat.sh
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400863
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500864 msg "test: compat.sh ssl3 (MBEDTLS_USE_PSA_CRYPTO)"
865 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400866
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500867 msg "test: compat.sh RC4, DES & NULL (MBEDTLS_USE_PSA_CRYPTO)"
868 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" GNUTLS_CLI="$GNUTLS_LEGACY_CLI" GNUTLS_SERV="$GNUTLS_LEGACY_SERV" tests/compat.sh -e '3DES\|DES-CBC3' -f 'NULL\|DES\|RC4\|ARCFOUR'
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500869
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500870 msg "test: compat.sh ARIA + ChachaPoly (MBEDTLS_USE_PSA_CRYPTO)"
871 if_build_succeeded env OPENSSL_CMD="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
872}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500873
Gilles Peskineb28636b2019-01-02 19:06:24 +0100874component_test_check_params_without_platform () {
875 msg "build+test: MBEDTLS_CHECK_PARAMS without MBEDTLS_PLATFORM_C"
876 scripts/config.pl full # includes CHECK_PARAMS
877 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
878 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
879 scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
880 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
881 scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
882 scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
883 scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
884 scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
885 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
886 scripts/config.pl unset MBEDTLS_PLATFORM_C
887 make CC=gcc CFLAGS='-Werror -O1' all test
888}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500889
Gilles Peskineb28636b2019-01-02 19:06:24 +0100890component_test_check_params_silent () {
891 msg "build+test: MBEDTLS_CHECK_PARAMS with alternative MBEDTLS_PARAM_FAILED()"
892 scripts/config.pl full # includes CHECK_PARAMS
893 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
894 sed -i 's/.*\(#define MBEDTLS_PARAM_FAILED( cond )\).*/\1/' "$CONFIG_H"
895 make CC=gcc CFLAGS='-Werror -O1' all test
896}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500897
Gilles Peskine8f073122018-11-27 15:58:47 +0100898component_test_no_platform () {
899 # Full configuration build, without platform support, file IO and net sockets.
900 # This should catch missing mbedtls_printf definitions, and by disabling file
901 # IO, it should catch missing '#include <stdio.h>'
902 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100903 scripts/config.pl full
904 scripts/config.pl unset MBEDTLS_PLATFORM_C
905 scripts/config.pl unset MBEDTLS_NET_C
906 scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
907 scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
908 scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
909 scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
910 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
911 scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
912 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
913 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
914 scripts/config.pl unset MBEDTLS_FS_IO
915 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
916 # to re-enable platform integration features otherwise disabled in C99 builds
917 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -O0 -D_DEFAULT_SOURCE' lib programs
918 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0' test
919}
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +0000920
Gilles Peskine8f073122018-11-27 15:58:47 +0100921component_build_no_std_function () {
922 # catch compile bugs in _uninit functions
923 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100924 scripts/config.pl full
925 scripts/config.pl set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
926 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
927 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
928}
Manuel Pégourié-Gonnarddccb80b2015-06-03 10:20:33 +0100929
Gilles Peskine8f073122018-11-27 15:58:47 +0100930component_build_no_ssl_srv () {
931 msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100932 scripts/config.pl full
933 scripts/config.pl unset MBEDTLS_SSL_SRV_C
934 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
935}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200936
Gilles Peskine8f073122018-11-27 15:58:47 +0100937component_build_no_ssl_cli () {
938 msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100939 scripts/config.pl full
940 scripts/config.pl unset MBEDTLS_SSL_CLI_C
941 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
942}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200943
Gilles Peskine8f073122018-11-27 15:58:47 +0100944component_build_no_sockets () {
945 # Note, C99 compliance can also be tested with the sockets support disabled,
946 # as that requires a POSIX platform (which isn't the same as C99).
947 msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100948 scripts/config.pl full
949 scripts/config.pl unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
950 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
951 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0 -std=c99 -pedantic' lib
952}
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +0200953
Gilles Peskine8f073122018-11-27 15:58:47 +0100954component_test_no_max_fragment_length () {
955 # Run max fragment length tests with MFL disabled
956 msg "build: default config except MFL extension (ASan build)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100957 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
958 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
959 make
Hanno Becker5175ac62017-09-18 15:36:25 +0100960
Gilles Peskine8f073122018-11-27 15:58:47 +0100961 msg "test: ssl-opt.sh, MFL-related tests"
962 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length"
963}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000964
Gilles Peskine8f073122018-11-27 15:58:47 +0100965component_test_no_max_fragment_length_small_ssl_out_content_len () {
966 msg "build: no MFL extension, small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100967 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
968 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 16384
969 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
970 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
971 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000972
Gilles Peskine8f073122018-11-27 15:58:47 +0100973 msg "test: MFL tests (disabled MFL extension case) & large packet tests"
974 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length\|Large buffer"
975}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000976
Gilles Peskine8f073122018-11-27 15:58:47 +0100977component_test_null_entropy () {
978 msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100979 scripts/config.pl set MBEDTLS_TEST_NULL_ENTROPY
980 scripts/config.pl set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
981 scripts/config.pl set MBEDTLS_ENTROPY_C
982 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
983 scripts/config.pl unset MBEDTLS_ENTROPY_HARDWARE_ALT
984 scripts/config.pl unset MBEDTLS_HAVEGE_C
Gilles Peskine5fa32a72019-01-06 19:48:30 +0000985 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan -D UNSAFE_BUILD=ON .
Gilles Peskine8f073122018-11-27 15:58:47 +0100986 make
Janos Follath06c54002016-06-09 13:57:40 +0100987
Gilles Peskine8f073122018-11-27 15:58:47 +0100988 msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)"
989 make test
990}
Janos Follath06c54002016-06-09 13:57:40 +0100991
Gilles Peskine8f073122018-11-27 15:58:47 +0100992component_test_platform_calloc_macro () {
993 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100994 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
995 scripts/config.pl set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
996 scripts/config.pl set MBEDTLS_PLATFORM_FREE_MACRO free
997 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
998 make
Hanno Beckere5fecec2018-10-11 11:02:52 +0100999
Gilles Peskine8f073122018-11-27 15:58:47 +01001000 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
1001 make test
1002}
Hanno Beckere5fecec2018-10-11 11:02:52 +01001003
Gilles Peskine8f073122018-11-27 15:58:47 +01001004component_test_aes_fewer_tables () {
1005 msg "build: default config with AES_FEWER_TABLES enabled"
Gilles Peskine8f073122018-11-27 15:58:47 +01001006 scripts/config.pl set MBEDTLS_AES_FEWER_TABLES
1007 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01001008
Gilles Peskine8f073122018-11-27 15:58:47 +01001009 msg "test: AES_FEWER_TABLES"
1010 make test
1011}
Hanno Becker83ebf782017-07-07 12:29:15 +01001012
Gilles Peskine8f073122018-11-27 15:58:47 +01001013component_test_aes_rom_tables () {
1014 msg "build: default config with AES_ROM_TABLES enabled"
Gilles Peskine8f073122018-11-27 15:58:47 +01001015 scripts/config.pl set MBEDTLS_AES_ROM_TABLES
1016 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01001017
Gilles Peskine8f073122018-11-27 15:58:47 +01001018 msg "test: AES_ROM_TABLES"
1019 make test
1020}
Hanno Becker83ebf782017-07-07 12:29:15 +01001021
Gilles Peskine8f073122018-11-27 15:58:47 +01001022component_test_aes_fewer_tables_and_rom_tables () {
1023 msg "build: default config with AES_ROM_TABLES and AES_FEWER_TABLES enabled"
Gilles Peskine8f073122018-11-27 15:58:47 +01001024 scripts/config.pl set MBEDTLS_AES_FEWER_TABLES
1025 scripts/config.pl set MBEDTLS_AES_ROM_TABLES
1026 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01001027
Gilles Peskine8f073122018-11-27 15:58:47 +01001028 msg "test: AES_FEWER_TABLES + AES_ROM_TABLES"
1029 make test
1030}
Hanno Becker83ebf782017-07-07 12:29:15 +01001031
Gilles Peskine8f073122018-11-27 15:58:47 +01001032component_test_make_shared () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001033 msg "build/test: make shared" # ~ 40s
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001034 make SHARED=1 all check
Gilles Peskine8f073122018-11-27 15:58:47 +01001035}
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +02001036
Gilles Peskine8f073122018-11-27 15:58:47 +01001037component_test_m32_o0 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001038 # Build once with -O0, to compile out the i386 specific inline assembly
1039 msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
Simon Butcher7a6da6e2018-06-27 21:52:54 +01001040 scripts/config.pl full
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001041 make CC=gcc CFLAGS='-O0 -Werror -Wall -Wextra -m32 -fsanitize=address'
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01001042
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001043 msg "test: i386, make, gcc -O0 (ASan build)"
1044 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01001045}
Gilles Peskine878cf602019-01-06 20:50:38 +00001046support_test_m32_o0 () {
1047 case $(uname -m) in
1048 *64*) true;;
1049 *) false;;
1050 esac
1051}
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001052
Gilles Peskine8f073122018-11-27 15:58:47 +01001053component_test_m32_o1 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001054 # Build again with -O1, to compile in the i386 specific inline assembly
1055 msg "build: i386, make, gcc -O1 (ASan build)" # ~ 30s
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001056 scripts/config.pl full
1057 make CC=gcc CFLAGS='-O1 -Werror -Wall -Wextra -m32 -fsanitize=address'
1058
1059 msg "test: i386, make, gcc -O1 (ASan build)"
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001060 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01001061}
Gilles Peskine878cf602019-01-06 20:50:38 +00001062support_test_m32_o1 () {
1063 support_test_m32_o0 "$@"
1064}
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001065
Gilles Peskine8f073122018-11-27 15:58:47 +01001066component_test_mx32 () {
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001067 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
Simon Butcher7a6da6e2018-06-27 21:52:54 +01001068 scripts/config.pl full
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001069 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32'
1070
1071 msg "test: 64-bit ILP32, make, gcc"
1072 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01001073}
Gilles Peskine878cf602019-01-06 20:50:38 +00001074support_test_mx32 () {
1075 case $(uname -m) in
1076 amd64|x86_64) true;;
1077 *) false;;
1078 esac
1079}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001080
Gilles Peskine8f073122018-11-27 15:58:47 +01001081component_test_have_int32 () {
1082 msg "build: gcc, force 32-bit bignum limbs"
Gilles Peskine8f073122018-11-27 15:58:47 +01001083 scripts/config.pl unset MBEDTLS_HAVE_ASM
1084 scripts/config.pl unset MBEDTLS_AESNI_C
1085 scripts/config.pl unset MBEDTLS_PADLOCK_C
1086 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01001087
Gilles Peskine8f073122018-11-27 15:58:47 +01001088 msg "test: gcc, force 32-bit bignum limbs"
1089 make test
1090}
Andres Amaya Garciafe843a32017-07-20 13:21:34 +01001091
Gilles Peskine8f073122018-11-27 15:58:47 +01001092component_test_have_int64 () {
1093 msg "build: gcc, force 64-bit bignum limbs"
Gilles Peskine8f073122018-11-27 15:58:47 +01001094 scripts/config.pl unset MBEDTLS_HAVE_ASM
1095 scripts/config.pl unset MBEDTLS_AESNI_C
1096 scripts/config.pl unset MBEDTLS_PADLOCK_C
1097 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
Gilles Peskine14c3c062018-01-29 21:25:12 +01001098
Gilles Peskine8f073122018-11-27 15:58:47 +01001099 msg "test: gcc, force 64-bit bignum limbs"
1100 make test
1101}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001102
Gilles Peskine8f073122018-11-27 15:58:47 +01001103component_test_no_udbl_division () {
1104 msg "build: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +01001105 scripts/config.pl full
1106 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
1107 scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
1108 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001109
Gilles Peskine8f073122018-11-27 15:58:47 +01001110 msg "test: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
1111 make test
1112}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001113
Gilles Peskine8f073122018-11-27 15:58:47 +01001114component_test_no_64bit_multiplication () {
1115 msg "build: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +01001116 scripts/config.pl full
1117 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
1118 scripts/config.pl set MBEDTLS_NO_64BIT_MULTIPLICATION
1119 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001120
Gilles Peskine8f073122018-11-27 15:58:47 +01001121 msg "test: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
1122 make test
1123}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001124
Gilles Peskine8f073122018-11-27 15:58:47 +01001125component_build_arm_none_eabi_gcc () {
1126 msg "build: arm-none-eabi-gcc, make" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +01001127 scripts/config.pl full
1128 scripts/config.pl unset MBEDTLS_NET_C
1129 scripts/config.pl unset MBEDTLS_TIMING_C
1130 scripts/config.pl unset MBEDTLS_FS_IO
1131 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
1132 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
1133 # following things are not in the default config
1134 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
1135 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
1136 scripts/config.pl unset MBEDTLS_THREADING_C
1137 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
1138 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
1139 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
1140}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001141
Gilles Peskine8f073122018-11-27 15:58:47 +01001142component_build_arm_none_eabi_gcc_no_udbl_division () {
1143 msg "build: arm-none-eabi-gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +01001144 scripts/config.pl full
1145 scripts/config.pl unset MBEDTLS_NET_C
1146 scripts/config.pl unset MBEDTLS_TIMING_C
1147 scripts/config.pl unset MBEDTLS_FS_IO
1148 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
1149 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
1150 # following things are not in the default config
1151 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
1152 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
1153 scripts/config.pl unset MBEDTLS_THREADING_C
1154 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
1155 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
1156 scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
1157 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
1158 echo "Checking that software 64-bit division is not required"
1159 if_build_succeeded not grep __aeabi_uldiv library/*.o
1160}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001161
Gilles Peskine8f073122018-11-27 15:58:47 +01001162component_build_arm_none_eabi_gcc_no_64bit_multiplication () {
1163 msg "build: arm-none-eabi-gcc MBEDTLS_NO_64BIT_MULTIPLICATION, make" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +01001164 scripts/config.pl full
1165 scripts/config.pl unset MBEDTLS_NET_C
1166 scripts/config.pl unset MBEDTLS_TIMING_C
1167 scripts/config.pl unset MBEDTLS_FS_IO
1168 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
1169 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
1170 # following things are not in the default config
1171 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
1172 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
1173 scripts/config.pl unset MBEDTLS_THREADING_C
1174 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
1175 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
1176 scripts/config.pl set MBEDTLS_NO_64BIT_MULTIPLICATION
1177 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -O1 -march=armv6-m -mthumb' lib
1178 echo "Checking that software 64-bit multiplication is not required"
1179 if_build_succeeded not grep __aeabi_lmul library/*.o
1180}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001181
Gilles Peskine8f073122018-11-27 15:58:47 +01001182component_build_armcc () {
1183 msg "build: ARM Compiler 5, make"
Gilles Peskine8f073122018-11-27 15:58:47 +01001184 scripts/config.pl full
1185 scripts/config.pl unset MBEDTLS_NET_C
1186 scripts/config.pl unset MBEDTLS_TIMING_C
1187 scripts/config.pl unset MBEDTLS_FS_IO
1188 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
1189 scripts/config.pl unset MBEDTLS_HAVE_TIME
1190 scripts/config.pl unset MBEDTLS_HAVE_TIME_DATE
1191 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
1192 # following things are not in the default config
1193 scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
1194 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
1195 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
1196 scripts/config.pl unset MBEDTLS_THREADING_C
1197 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
1198 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
1199 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT # depends on MBEDTLS_HAVE_TIME
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001200
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001201 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
1202 make clean
Andres AG87bb5772016-09-27 15:05:15 +01001203
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001204 # ARM Compiler 6 - Target ARMv7-A
1205 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-a"
Simon Butcher940737f2017-07-23 13:42:36 +02001206
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001207 # ARM Compiler 6 - Target ARMv7-M
1208 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m"
Simon Butcher940737f2017-07-23 13:42:36 +02001209
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001210 # ARM Compiler 6 - Target ARMv8-A - AArch32
1211 armc6_build_test "--target=arm-arm-none-eabi -march=armv8.2-a"
Simon Butcher940737f2017-07-23 13:42:36 +02001212
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001213 # ARM Compiler 6 - Target ARMv8-M
1214 armc6_build_test "--target=arm-arm-none-eabi -march=armv8-m.main"
Simon Butcher940737f2017-07-23 13:42:36 +02001215
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001216 # ARM Compiler 6 - Target ARMv8-A - AArch64
1217 armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a"
Gilles Peskine8f073122018-11-27 15:58:47 +01001218}
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +01001219
Gilles Peskine8f073122018-11-27 15:58:47 +01001220component_test_allow_sha1 () {
1221 msg "build: allow SHA1 in certificates by default"
Gilles Peskine8f073122018-11-27 15:58:47 +01001222 scripts/config.pl set MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
1223 make CFLAGS='-Werror -Wall -Wextra'
1224 msg "test: allow SHA1 in certificates by default"
1225 make test
1226 if_build_succeeded tests/ssl-opt.sh -f SHA-1
1227}
Gilles Peskine2a458da2017-05-12 15:26:58 +02001228
Gilles Peskine8f073122018-11-27 15:58:47 +01001229component_build_mingw () {
1230 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +01001231 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -Wall -Wextra' WINDOWS_BUILD=1 lib programs
Hanno Beckere963efa2018-01-03 10:03:43 +00001232
Gilles Peskine8f073122018-11-27 15:58:47 +01001233 # note Make tests only builds the tests, but doesn't run them
1234 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror' WINDOWS_BUILD=1 tests
1235 make WINDOWS_BUILD=1 clean
Simon Butcher002bc622016-11-17 09:27:45 +00001236
Gilles Peskine8f073122018-11-27 15:58:47 +01001237 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
1238 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -Wall -Wextra' WINDOWS_BUILD=1 SHARED=1 lib programs
1239 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -Wall -Wextra' WINDOWS_BUILD=1 SHARED=1 tests
1240 make WINDOWS_BUILD=1 clean
1241}
Manuel Pégourié-Gonnard6448bce2015-02-16 17:18:36 +01001242
Gilles Peskine8f073122018-11-27 15:58:47 +01001243component_test_memsan () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001244 msg "build: MSan (clang)" # ~ 1 min 20s
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001245 scripts/config.pl unset MBEDTLS_AESNI_C # memsan doesn't grok asm
1246 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
1247 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +02001248
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001249 msg "test: main suites (MSan)" # ~ 10s
1250 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001251
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001252 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
Gilles Peskine7c652162017-12-11 00:01:40 +01001253 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001254
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001255 # Optional part(s)
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001256
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001257 if [ "$MEMORY" -gt 0 ]; then
1258 msg "test: compat.sh (MSan)" # ~ 6 min 20s
Gilles Peskine7c652162017-12-11 00:01:40 +01001259 if_build_succeeded tests/compat.sh
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001260 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001261}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001262
Gilles Peskine69f190e2019-01-10 00:11:42 +01001263component_test_valgrind () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001264 msg "build: Release (clang)"
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001265 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
1266 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001267
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001268 msg "test: main suites valgrind (Release)"
1269 make memcheck
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001270
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001271 # Optional part(s)
1272 # Currently broken, programs don't seem to receive signals
1273 # under valgrind on OS X
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001274
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001275 if [ "$MEMORY" -gt 0 ]; then
1276 msg "test: ssl-opt.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +01001277 if_build_succeeded tests/ssl-opt.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001278 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001279
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001280 if [ "$MEMORY" -gt 1 ]; then
1281 msg "test: compat.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +01001282 if_build_succeeded tests/compat.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001283 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001284}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001285
Gilles Peskine8f073122018-11-27 15:58:47 +01001286component_test_cmake_out_of_source () {
1287 msg "build: cmake 'out-of-source' build"
Gilles Peskine8f073122018-11-27 15:58:47 +01001288 MBEDTLS_ROOT_DIR="$PWD"
1289 mkdir "$OUT_OF_SOURCE_DIR"
1290 cd "$OUT_OF_SOURCE_DIR"
1291 cmake "$MBEDTLS_ROOT_DIR"
1292 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001293
Gilles Peskine8f073122018-11-27 15:58:47 +01001294 msg "test: cmake 'out-of-source' build"
1295 make test
1296 # Test an SSL option that requires an auxiliary script in test/scripts/.
1297 # Also ensure that there are no error messages such as
1298 # "No such file or directory", which would indicate that some required
1299 # file is missing (ssl-opt.sh tolerates the absence of some files so
1300 # may exit with status 0 but emit errors).
1301 if_build_succeeded ./tests/ssl-opt.sh -f 'Fallback SCSV: beginning of list' 2>ssl-opt.err
1302 if [ -s ssl-opt.err ]; then
1303 cat ssl-opt.err >&2
1304 record_status [ ! -s ssl-opt.err ]
1305 rm ssl-opt.err
1306 fi
1307 cd "$MBEDTLS_ROOT_DIR"
1308 rm -rf "$OUT_OF_SOURCE_DIR"
1309 unset MBEDTLS_ROOT_DIR
1310}
Andres AGdc192212016-08-31 17:33:13 +01001311
Gilles Peskine8f073122018-11-27 15:58:47 +01001312component_test_zeroize () {
1313 # Test that the function mbedtls_platform_zeroize() is not optimized away by
1314 # different combinations of compilers and optimization flags by using an
1315 # auxiliary GDB script. Unfortunately, GDB does not return error values to the
1316 # system in all cases that the script fails, so we must manually search the
1317 # output to check whether the pass string is present and no failure strings
1318 # were printed.
Andres AGdc192212016-08-31 17:33:13 +01001319
Gilles Peskine4976e822019-01-06 19:52:22 +00001320 # Don't try to disable ASLR. We don't care about ASLR here. We do care
1321 # about a spurious message if Gdb tries and fails, so suppress that.
1322 gdb_disable_aslr=
1323 if [ -z "$(gdb -batch -nw -ex 'set disable-randomization off' 2>&1)" ]; then
1324 gdb_disable_aslr='set disable-randomization off'
1325 fi
1326
Gilles Peskine8f073122018-11-27 15:58:47 +01001327 for optimization_flag in -O2 -O3 -Ofast -Os; do
Gilles Peskine55f7c942019-01-09 22:28:21 +01001328 for compiler in clang gcc; do
1329 msg "test: $compiler $optimization_flag, mbedtls_platform_zeroize()"
1330 make programs CC="$compiler" DEBUG=1 CFLAGS="$optimization_flag"
Gilles Peskine4976e822019-01-06 19:52:22 +00001331 if_build_succeeded gdb -ex "$gdb_disable_aslr" -x tests/scripts/test_zeroize.gdb -nw -batch -nx 2>&1 | tee test_zeroize.log
Gilles Peskine55f7c942019-01-09 22:28:21 +01001332 if_build_succeeded grep "The buffer was correctly zeroized" test_zeroize.log
1333 if_build_succeeded not grep -i "error" test_zeroize.log
1334 rm -f test_zeroize.log
1335 make clean
1336 done
Andres Amaya Garcia29673812017-10-25 10:35:51 +01001337 done
Andres Amaya Garciad0d7bf62017-10-25 09:01:31 +01001338
Gilles Peskine4976e822019-01-06 19:52:22 +00001339 unset gdb_disable_aslr
Gilles Peskine8f073122018-11-27 15:58:47 +01001340}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001341
Gilles Peskine8f073122018-11-27 15:58:47 +01001342component_check_python_files () {
1343 msg "Lint: Python scripts"
1344 record_status tests/scripts/check-python-files.sh
1345}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001346
Gilles Peskine8f073122018-11-27 15:58:47 +01001347component_check_generate_test_code () {
1348 msg "uint test: generate_test_code.py"
1349 record_status ./tests/scripts/test_generate_test_code.py
1350}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001351
1352################################################################
1353#### Termination
1354################################################################
1355
Gilles Peskine8f073122018-11-27 15:58:47 +01001356post_report () {
1357 msg "Done, cleaning up"
1358 cleanup
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001359
Gilles Peskine8f073122018-11-27 15:58:47 +01001360 final_report
1361}
1362
1363
1364
1365################################################################
1366#### Run all the things
1367################################################################
1368
Gilles Peskinee48351a2018-11-27 16:06:30 +01001369# Run one component and clean up afterwards.
Gilles Peskine8f073122018-11-27 15:58:47 +01001370run_component () {
Gilles Peskine608953e2019-01-02 18:57:02 +01001371 # Back up the configuration in case the component modifies it.
1372 # The cleanup function will restore it.
1373 cp -p "$CONFIG_H" "$CONFIG_BAK"
Gilles Peskineffcdeff2018-12-04 12:49:28 +01001374 current_component="$1"
Gilles Peskine8f073122018-11-27 15:58:47 +01001375 "$@"
Gilles Peskinee48351a2018-11-27 16:06:30 +01001376 cleanup
Gilles Peskine8f073122018-11-27 15:58:47 +01001377}
1378
1379# Preliminary setup
1380pre_check_environment
1381pre_initialize_variables
1382pre_parse_command_line "$@"
Gilles Peskine348fb9a2018-11-27 17:04:29 +01001383
Gilles Peskine878cf602019-01-06 20:50:38 +00001384pre_check_git
1385build_status=0
1386if [ $KEEP_GOING -eq 1 ]; then
1387 pre_setup_keep_going
Gilles Peskine92525112018-11-27 18:15:35 +01001388else
Gilles Peskine878cf602019-01-06 20:50:38 +00001389 record_status () {
1390 "$@"
1391 }
Gilles Peskine8f073122018-11-27 15:58:47 +01001392fi
Gilles Peskine878cf602019-01-06 20:50:38 +00001393pre_print_configuration
1394pre_check_tools
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001395cleanup
1396
Gilles Peskinebeb3a812019-01-06 22:11:25 +00001397# Run the requested tests.
1398for component in $RUN_COMPONENTS; do
1399 run_component "component_$component"
1400done
Gilles Peskine8f073122018-11-27 15:58:47 +01001401
1402# We're done.
Gilles Peskine878cf602019-01-06 20:50:38 +00001403post_report