blob: 5ad214dccfd74d7ac838191f81d81e33fb45a89b [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)
38# * arm-gcc and mingw-gcc
39# * ArmCC 5 and ArmCC 6, unless invoked with --no-armcc
40# * Yotta build dependencies, unless invoked with --no-yotta
41# * 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 Peskine2906a0a2019-01-09 22:29:17 +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.
62# * 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.
65# * support_XXX: if support_XXX exists and returns false then
66# component_XXX is not run by default.
67# * post_XXX: things to do after running the tests.
68# * other: miscellaneous support functions.
69#
70# 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 Peskine57db6ff2019-01-08 22:04:31 +0100108pre_check_environment () {
Gilles Peskine770ad7e2019-01-08 23:19:08 +0100109 if [ -d library -a -d include -a -d tests ]; then :; else
Gilles Peskine57db6ff2019-01-08 22:04:31 +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
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100115pre_initialize_variables () {
116 CONFIG_H='include/mbedtls/config.h'
117 CONFIG_BAK="$CONFIG_H.bak"
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200118
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100119 MEMORY=0
120 FORCE=0
121 KEEP_GOING=0
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100122 YOTTA=1
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100123
Antonin Décimo8fd91562019-01-23 15:24:37 +0100124 # Default commands, can be overridden by the environment
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100125 : ${OPENSSL:="openssl"}
126 : ${OPENSSL_LEGACY:="$OPENSSL"}
127 : ${GNUTLS_CLI:="gnutls-cli"}
128 : ${GNUTLS_SERV:="gnutls-serv"}
129 : ${GNUTLS_LEGACY_CLI:="$GNUTLS_CLI"}
130 : ${GNUTLS_LEGACY_SERV:="$GNUTLS_SERV"}
131 : ${OUT_OF_SOURCE_DIR:=./mbedtls_out_of_source_build}
132 : ${ARMC5_BIN_DIR:=/usr/bin}
133 : ${ARMC6_BIN_DIR:=/usr/bin}
Andres AGdc192212016-08-31 17:33:13 +0100134
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100135 # if MAKEFLAGS is not set add the -j option to speed up invocations of make
Gilles Peskine7120f772019-01-06 20:15:26 +0000136 if [ -z "${MAKEFLAGS+set}" ]; then
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100137 export MAKEFLAGS="-j"
138 fi
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100139
140 # Gather the list of available components. These are the functions
141 # defined in this script whose name starts with "component_".
142 # Parse the script with sed, because in sh there is no way to list
143 # defined functions.
144 ALL_COMPONENTS=$(sed -n 's/^ *component_\([0-9A-Z_a-z]*\) *().*/\1/p' <"$0")
Gilles Peskine3fbdd212019-01-08 23:33:45 +0100145
146 # Exclude components that are not supported on this platform.
147 SUPPORTED_COMPONENTS=
148 for component in $ALL_COMPONENTS; do
149 case $(type "support_$component" 2>&1) in
150 *' function'*)
151 if ! support_$component; then continue; fi;;
152 esac
153 SUPPORTED_COMPONENTS="$SUPPORTED_COMPONENTS $component"
154 done
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100155}
Andres AG38495a32016-07-12 16:54:33 +0100156
Gilles Peskineff7238f2019-01-10 00:05:18 +0100157# Test whether the component $1 is included in the command line patterns.
158is_component_included()
Gilles Peskine6e984232018-11-27 21:37:53 +0100159{
160 set -f
Gilles Peskineeb39b9b2019-01-08 23:41:00 +0100161 for pattern in $COMMAND_LINE_COMPONENTS; do
Gilles Peskine6e984232018-11-27 21:37:53 +0100162 set +f
163 case ${1#component_} in $pattern) return 0;; esac
164 done
165 set +f
166 return 1
167}
168
Simon Butcher41eeccf2016-09-07 00:07:09 +0100169usage()
SimonB2e23c822016-04-16 21:54:39 +0100170{
Gilles Peskine709346a2017-12-10 23:43:39 +0100171 cat <<EOF
Gilles Peskine91bd8b72019-01-08 23:01:34 +0100172Usage: $0 [OPTION]... [COMPONENT]...
173Run mbedtls release validation tests.
174By default, run all tests. With one or more COMPONENT, run only those.
Gilles Peskineff7238f2019-01-10 00:05:18 +0100175COMPONENT can be the name of a component or a shell wildcard pattern.
176
177Examples:
178 $0 "check_*"
179 Run all sanity checks.
180 $0 --no-armcc --except test_memsan
181 Run everything except builds that require armcc and MemSan.
Gilles Peskine91bd8b72019-01-08 23:01:34 +0100182
183Special options:
184 -h|--help Print this help and exit.
Gilles Peskineb3241cb2019-01-08 23:44:07 +0100185 --list-all-components List all available test components and exit.
186 --list-components List components supported on this platform and exit.
Gilles Peskine709346a2017-12-10 23:43:39 +0100187
188General options:
189 -f|--force Force the tests to overwrite any modified files.
Gilles Peskine7c652162017-12-11 00:01:40 +0100190 -k|--keep-going Run all tests and report errors at the end.
Gilles Peskine709346a2017-12-10 23:43:39 +0100191 -m|--memory Additional optional memory tests.
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100192 --armcc Run ARM Compiler builds (on by default).
Gilles Peskineff7238f2019-01-10 00:05:18 +0100193 --except Exclude the COMPONENTs listed on the command line,
194 instead of running only those.
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100195 --no-armcc Skip ARM Compiler builds.
Gilles Peskine19ceb712018-03-21 08:40:26 +0100196 --no-force Refuse to overwrite modified files (default).
197 --no-keep-going Stop at the first error (default).
198 --no-memory No additional memory tests (default).
Gilles Peskine2a22a802017-12-21 15:19:00 +0100199 --no-yotta Skip yotta module build.
Gilles Peskine709346a2017-12-10 23:43:39 +0100200 --out-of-source-dir=<path> Directory used for CMake out-of-source build tests.
Gilles Peskine19ceb712018-03-21 08:40:26 +0100201 --random-seed Use a random seed value for randomized tests (default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100202 -r|--release-test Run this script in release mode. This fixes the seed value to 1.
203 -s|--seed Integer seed value to use for this test run.
Gilles Peskine2a22a802017-12-21 15:19:00 +0100204 --yotta Build yotta module (on by default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100205
206Tool path options:
207 --armc5-bin-dir=<ARMC5_bin_dir_path> ARM Compiler 5 bin directory.
208 --armc6-bin-dir=<ARMC6_bin_dir_path> ARM Compiler 6 bin directory.
209 --gnutls-cli=<GnuTLS_cli_path> GnuTLS client executable to use for most tests.
210 --gnutls-serv=<GnuTLS_serv_path> GnuTLS server executable to use for most tests.
211 --gnutls-legacy-cli=<GnuTLS_cli_path> GnuTLS client executable to use for legacy tests.
212 --gnutls-legacy-serv=<GnuTLS_serv_path> GnuTLS server executable to use for legacy tests.
213 --openssl=<OpenSSL_path> OpenSSL executable to use for most tests.
214 --openssl-legacy=<OpenSSL_path> OpenSSL executable to use for legacy tests e.g. SSLv3.
215EOF
SimonB2e23c822016-04-16 21:54:39 +0100216}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100217
218# remove built files as well as the cmake cache/config
219cleanup()
220{
Gilles Peskinea71d64c2018-03-21 12:16:57 +0100221 if [ -n "${MBEDTLS_ROOT_DIR+set}" ]; then
222 cd "$MBEDTLS_ROOT_DIR"
223 fi
224
Gilles Peskine7c652162017-12-11 00:01:40 +0100225 command make clean
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200226
Gilles Peskine31b07e22018-03-21 12:15:06 +0100227 # Remove CMake artefacts
228 find . -name .git -prune -o -name yotta -prune -o \
229 -iname CMakeFiles -exec rm -rf {} \+ -o \
230 \( -iname cmake_install.cmake -o \
231 -iname CTestTestfile.cmake -o \
232 -iname CMakeCache.txt \) -exec rm {} \+
233 # Recover files overwritten by in-tree CMake builds
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000234 rm -f include/Makefile include/mbedtls/Makefile programs/*/Makefile
Paul Bakkerfe0984d2014-06-13 00:13:45 +0200235 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile
236 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200237
238 if [ -f "$CONFIG_BAK" ]; then
239 mv "$CONFIG_BAK" "$CONFIG_H"
240 fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100241}
242
Gilles Peskine7c652162017-12-11 00:01:40 +0100243# Executed on exit. May be redefined depending on command line options.
244final_report () {
245 :
246}
247
248fatal_signal () {
249 cleanup
250 final_report $1
251 trap - $1
252 kill -$1 $$
253}
254
255trap 'fatal_signal HUP' HUP
256trap 'fatal_signal INT' INT
257trap 'fatal_signal TERM' TERM
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200258
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100259msg()
260{
Gilles Peskine11ddca62018-12-04 12:49:28 +0100261 if [ -n "${current_component:-}" ]; then
262 current_section="${current_component#component_}: $1"
263 else
264 current_section="$1"
265 fi
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100266 echo ""
267 echo "******************************************************************"
Gilles Peskine11ddca62018-12-04 12:49:28 +0100268 echo "* $current_section "
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000269 printf "* "; date
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100270 echo "******************************************************************"
271}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100272
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100273armc6_build_test()
274{
275 FLAGS="$1"
Andres AGa5cd9732016-10-17 15:23:10 +0100276
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100277 msg "build: ARM Compiler 6 ($FLAGS), make"
278 ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \
279 WARNING_CFLAGS='-xc -std=c99' make lib
280 make clean
281}
Andres AGa5cd9732016-10-17 15:23:10 +0100282
Andres AGd9eba4b2016-08-26 14:42:14 +0100283err_msg()
284{
285 echo "$1" >&2
286}
287
288check_tools()
289{
290 for TOOL in "$@"; do
Andres AG98393602017-01-31 17:04:45 +0000291 if ! `type "$TOOL" >/dev/null 2>&1`; then
Andres AGd9eba4b2016-08-26 14:42:14 +0100292 err_msg "$TOOL not found!"
293 exit 1
294 fi
295 done
296}
297
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100298pre_parse_command_line () {
Gilles Peskineeb39b9b2019-01-08 23:41:00 +0100299 COMMAND_LINE_COMPONENTS=
Gilles Peskineff7238f2019-01-10 00:05:18 +0100300 all_except=0
Gilles Peskine53084872019-01-09 23:13:54 +0100301 no_armcc=
Gilles Peskine6e984232018-11-27 21:37:53 +0100302
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100303 while [ $# -gt 0 ]; do
304 case "$1" in
Gilles Peskine53084872019-01-09 23:13:54 +0100305 --armcc) no_armcc=;;
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100306 --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
307 --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
Gilles Peskineeb39b9b2019-01-08 23:41:00 +0100308 --except) all_except=1;;
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100309 --force|-f) FORCE=1;;
310 --gnutls-cli) shift; GNUTLS_CLI="$1";;
311 --gnutls-legacy-cli) shift; GNUTLS_LEGACY_CLI="$1";;
312 --gnutls-legacy-serv) shift; GNUTLS_LEGACY_SERV="$1";;
313 --gnutls-serv) shift; GNUTLS_SERV="$1";;
314 --help|-h) usage; exit;;
315 --keep-going|-k) KEEP_GOING=1;;
Gilles Peskineb3241cb2019-01-08 23:44:07 +0100316 --list-all-components) printf '%s\n' $ALL_COMPONENTS; exit;;
317 --list-components) printf '%s\n' $SUPPORTED_COMPONENTS; exit;;
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100318 --memory|-m) MEMORY=1;;
Gilles Peskine53084872019-01-09 23:13:54 +0100319 --no-armcc) no_armcc=1;;
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100320 --no-force) FORCE=0;;
321 --no-keep-going) KEEP_GOING=0;;
322 --no-memory) MEMORY=0;;
323 --no-yotta) YOTTA=0;;
324 --openssl) shift; OPENSSL="$1";;
325 --openssl-legacy) shift; OPENSSL_LEGACY="$1";;
326 --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
327 --random-seed) unset SEED;;
328 --release-test|-r) SEED=1;;
329 --seed|-s) shift; SEED="$1";;
330 --yotta) YOTTA=1;;
Gilles Peskine91bd8b72019-01-08 23:01:34 +0100331 -*)
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100332 echo >&2 "Unknown option: $1"
333 echo >&2 "Run $0 --help for usage."
334 exit 120
335 ;;
Gilles Peskineeb39b9b2019-01-08 23:41:00 +0100336 *) COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS $1";;
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100337 esac
338 shift
339 done
Gilles Peskine91bd8b72019-01-08 23:01:34 +0100340
Gilles Peskineff7238f2019-01-10 00:05:18 +0100341 # With no list of components, run everything.
Gilles Peskineeb39b9b2019-01-08 23:41:00 +0100342 if [ -z "$COMMAND_LINE_COMPONENTS" ]; then
343 all_except=1
344 fi
345
Gilles Peskine53084872019-01-09 23:13:54 +0100346 # --no-armcc is a legacy option. The modern way is --except '*_armcc*'.
347 # Ignore it if components are listed explicitly on the command line.
Gilles Peskineff7238f2019-01-10 00:05:18 +0100348 if [ -n "$no_armcc" ] && [ $all_except -eq 1 ]; then
Gilles Peskine53084872019-01-09 23:13:54 +0100349 COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS *_armcc*"
350 # --no-armcc also disables yotta.
351 COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS *_yotta*"
352 fi
353
Gilles Peskineeb39b9b2019-01-08 23:41:00 +0100354 # Build the list of components to run.
Gilles Peskineff7238f2019-01-10 00:05:18 +0100355 RUN_COMPONENTS=
356 for component in $SUPPORTED_COMPONENTS; do
357 if is_component_included "$component"; [ $? -eq $all_except ]; then
358 RUN_COMPONENTS="$RUN_COMPONENTS $component"
359 fi
360 done
Gilles Peskineeb39b9b2019-01-08 23:41:00 +0100361
362 unset all_except
Gilles Peskine53084872019-01-09 23:13:54 +0100363 unset no_armcc
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100364}
SimonB2e23c822016-04-16 21:54:39 +0100365
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100366pre_check_git () {
367 if [ $FORCE -eq 1 ]; then
Gilles Peskinec7800952019-01-09 23:14:09 +0100368 rm -rf "$OUT_OF_SOURCE_DIR"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100369 if [ $YOTTA -eq 1 ]; then
Gilles Peskinec7800952019-01-09 23:14:09 +0100370 rm -rf yotta/module
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100371 fi
372 git checkout-index -f -q $CONFIG_H
373 cleanup
374 else
375
376 if [ $YOTTA -ne 0 ] && [ -d yotta/module ]; then
377 err_msg "Warning - there is an existing yotta module in the directory 'yotta/module'"
378 echo "You can either delete your work and retry, or force the test to overwrite the"
379 echo "test by rerunning the script as: $0 --force"
380 exit 1
381 fi
382
383 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
384 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
385 echo "You can either delete this directory manually, or force the test by rerunning"
386 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
387 exit 1
388 fi
389
Gilles Peskinec9663b12019-01-09 22:30:01 +0100390 if ! git diff --quiet include/mbedtls/config.h; then
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100391 err_msg "Warning - the configuration file 'include/mbedtls/config.h' has been edited. "
392 echo "You can either delete or preserve your work, or force the test by rerunning the"
393 echo "script as: $0 --force"
394 exit 1
395 fi
Gilles Peskineda519252017-11-30 13:22:04 +0100396 fi
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100397}
SimonB2e23c822016-04-16 21:54:39 +0100398
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100399pre_setup_keep_going () {
Gilles Peskine7c652162017-12-11 00:01:40 +0100400 failure_summary=
401 failure_count=0
402 start_red=
403 end_color=
404 if [ -t 1 ]; then
Gilles Peskine9736b9d2018-01-02 21:54:17 +0100405 case "${TERM:-}" in
Gilles Peskine7c652162017-12-11 00:01:40 +0100406 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
407 start_red=$(printf '\033[31m')
408 end_color=$(printf '\033[0m')
409 ;;
410 esac
411 fi
412 record_status () {
413 if "$@"; then
414 last_status=0
415 else
416 last_status=$?
417 text="$current_section: $* -> $last_status"
418 failure_summary="$failure_summary
419$text"
420 failure_count=$((failure_count + 1))
421 echo "${start_red}^^^^$text^^^^${end_color}"
422 fi
423 }
424 make () {
425 case "$*" in
426 *test|*check)
427 if [ $build_status -eq 0 ]; then
428 record_status command make "$@"
429 else
430 echo "(skipped because the build failed)"
431 fi
432 ;;
433 *)
434 record_status command make "$@"
435 build_status=$last_status
436 ;;
437 esac
438 }
439 final_report () {
440 if [ $failure_count -gt 0 ]; then
441 echo
442 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
443 echo "${start_red}FAILED: $failure_count${end_color}$failure_summary"
444 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Jaeden Amero5113bde2018-07-20 16:42:14 +0100445 exit 1
Gilles Peskine7c652162017-12-11 00:01:40 +0100446 elif [ -z "${1-}" ]; then
447 echo "SUCCESS :)"
448 fi
449 if [ -n "${1-}" ]; then
450 echo "Killed by SIG$1."
451 fi
452 }
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100453}
454
Gilles Peskine7c652162017-12-11 00:01:40 +0100455if_build_succeeded () {
456 if [ $build_status -eq 0 ]; then
457 record_status "$@"
458 fi
459}
460
Gilles Peskine30bc3852019-01-09 23:25:25 +0100461# to be used instead of ! for commands run with
462# record_status or if_build_succeeded
463not() {
464 ! "$@"
465}
466
467
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100468pre_print_configuration () {
469 msg "info: $0 configuration"
470 echo "MEMORY: $MEMORY"
471 echo "FORCE: $FORCE"
472 echo "SEED: ${SEED-"UNSET"}"
473 echo "OPENSSL: $OPENSSL"
474 echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
475 echo "GNUTLS_CLI: $GNUTLS_CLI"
476 echo "GNUTLS_SERV: $GNUTLS_SERV"
477 echo "GNUTLS_LEGACY_CLI: $GNUTLS_LEGACY_CLI"
478 echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV"
479 echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
480 echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
481}
Andres AG7770ea82016-10-10 15:46:20 +0100482
Andres AGd9eba4b2016-08-26 14:42:14 +0100483# Make sure the tools we need are available.
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100484pre_check_tools () {
Gilles Peskine541fb1e2019-01-06 22:40:00 +0000485 # Build the list of variables to pass to output_env.sh.
486 set env
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100487
Gilles Peskine541fb1e2019-01-06 22:40:00 +0000488 case " $RUN_COMPONENTS " in
489 # Require OpenSSL and GnuTLS if running any tests (as opposed to
490 # only doing builds). Not all tests run OpenSSL and GnuTLS, but this
491 # is a good enough approximation in practice.
492 *" test_"*)
493 # To avoid setting OpenSSL and GnuTLS for each call to compat.sh
494 # and ssl-opt.sh, we just export the variables they require.
495 export OPENSSL_CMD="$OPENSSL"
496 export GNUTLS_CLI="$GNUTLS_CLI"
497 export GNUTLS_SERV="$GNUTLS_SERV"
498 # Avoid passing --seed flag in every call to ssl-opt.sh
499 if [ -n "${SEED-}" ]; then
500 export SEED
501 fi
502 set "$@" OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY"
503 set "$@" GNUTLS_CLI="$GNUTLS_CLI" GNUTLS_SERV="$GNUTLS_SERV"
504 set "$@" GNUTLS_LEGACY_CLI="$GNUTLS_LEGACY_CLI"
505 set "$@" GNUTLS_LEGACY_SERV="$GNUTLS_LEGACY_SERV"
506 check_tools "$OPENSSL" "$OPENSSL_LEGACY" \
507 "$GNUTLS_CLI" "$GNUTLS_SERV" \
508 "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV"
509 ;;
510 esac
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100511
Gilles Peskine541fb1e2019-01-06 22:40:00 +0000512 case " $RUN_COMPONENTS " in
513 *_doxygen[_\ ]*) check_tools "doxygen" "dot";;
514 esac
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100515
Gilles Peskine541fb1e2019-01-06 22:40:00 +0000516 case " $RUN_COMPONENTS " in
517 *_arm_none_eabi_gcc[_\ ]*) check_tools "arm-none-eabi-gcc";;
518 esac
519
520 case " $RUN_COMPONENTS " in
521 *_mingw[_\ ]*) check_tools "i686-w64-mingw32-gcc";;
522 esac
523
524 case " $RUN_COMPONENTS " in
Gilles Peskine53084872019-01-09 23:13:54 +0100525 *_armcc*|*_yotta*)
Gilles Peskine541fb1e2019-01-06 22:40:00 +0000526 ARMC5_CC="$ARMC5_BIN_DIR/armcc"
527 ARMC5_AR="$ARMC5_BIN_DIR/armar"
528 ARMC6_CC="$ARMC6_BIN_DIR/armclang"
529 ARMC6_AR="$ARMC6_BIN_DIR/armar"
Gilles Peskine53084872019-01-09 23:13:54 +0100530 check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC6_CC" "$ARMC6_AR";;
531 esac
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100532
533 msg "info: output_env.sh"
Gilles Peskine53084872019-01-09 23:13:54 +0100534 case $RUN_COMPONENTS in
535 *_armcc*|*_yotta*)
536 set "$@" ARMC5_CC="$ARMC5_CC" ARMC6_CC="$ARMC6_CC" RUN_ARMCC=1;;
537 *) set "$@" RUN_ARMCC=0;;
538 esac
539 "$@" scripts/output_env.sh
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100540}
Andres AGd9eba4b2016-08-26 14:42:14 +0100541
Gilles Peskine192c72f2017-12-21 15:59:21 +0100542
543
544################################################################
545#### Basic checks
546################################################################
SimonB2e23c822016-04-16 21:54:39 +0100547
548#
549# Test Suites to be executed
550#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200551# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100552# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard61bc57a2014-08-14 11:29:06 +0200553# and/or are more likely to fail than others (eg I use Clang most of the
554# time, so start with a GCC build).
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200555# 2. Minimize total running time, by avoiding useless rebuilds
556#
557# Indicative running times are given for reference.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100558
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100559component_check_recursion () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100560 msg "test: recursion.pl" # < 1s
561 record_status tests/scripts/recursion.pl library/*.c
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100562}
Manuel Pégourié-Gonnardea29d152014-11-20 17:32:33 +0100563
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100564component_check_generated_files () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100565 msg "test: freshness of generated source files" # < 1s
566 record_status tests/scripts/check-generated-files.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100567}
Manuel Pégourié-Gonnardb3b8e432015-02-13 14:52:19 +0000568
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100569component_check_doxy_blocks () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100570 msg "test: doxygen markup outside doxygen blocks" # < 1s
571 record_status tests/scripts/check-doxy-blocks.pl
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100572}
Manuel Pégourié-Gonnardd09a6b52015-04-09 17:19:23 +0200573
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100574component_check_files () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100575 msg "test: check-files.py" # < 1s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100576 record_status tests/scripts/check-files.py
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100577}
Manuel Pégourié-Gonnard77d56bb2015-07-28 15:00:37 +0200578
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100579component_check_names () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100580 msg "test/build: declared and exported names" # < 3s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100581 record_status tests/scripts/check-names.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100582}
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +0200583
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100584component_check_doxygen_warnings () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100585 msg "test: doxygen warnings" # ~ 3s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100586 record_status tests/scripts/doxygen.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100587}
Andres Amaya Garciadd29c2f2017-05-04 11:35:51 +0100588
Simon Butcher948f2642018-07-20 21:27:33 +0100589
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100590################################################################
591#### Build and test many configurations and targets
592################################################################
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100593
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100594component_build_yotta () {
Gilles Peskine53084872019-01-09 23:13:54 +0100595 # Note - use of yotta is deprecated, and yotta also requires armcc to be on the
596 # path, and uses whatever version of armcc it finds there.
597 msg "build: create and build yotta module" # ~ 30s
598 record_status tests/scripts/yotta-build.sh
599}
600support_build_yotta () {
601 [ $YOTTA -ne 0 ]
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100602}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100603
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100604component_test_default_cmake_gcc_asan () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100605 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100606 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100607 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +0200608
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100609 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100610 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100611
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100612 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
Gilles Peskine7c652162017-12-11 00:01:40 +0100613 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100614
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100615 msg "test: compat.sh (ASan build)" # ~ 6 min
616 if_build_succeeded tests/compat.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100617}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000618
Gilles Peskine3484ed82019-01-08 22:51:19 +0100619component_test_ref_configs () {
620 msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
621 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
622 record_status tests/scripts/test-ref-configs.pl
623}
624
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100625component_test_sslv3 () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100626 msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100627 scripts/config.pl set MBEDTLS_SSL_PROTO_SSL3
628 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
629 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000630
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100631 msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
632 make test
633
634 msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
635 if_build_succeeded tests/compat.sh -m 'tls1 tls1_1 tls1_2 dtls1 dtls1_2'
636 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
637
638 msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
639 if_build_succeeded tests/ssl-opt.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100640}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100641
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100642component_test_no_renegotiation () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100643 msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100644 scripts/config.pl unset MBEDTLS_SSL_RENEGOTIATION
645 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
646 make
647
648 msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
649 make test
650
651 msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
652 if_build_succeeded tests/ssl-opt.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100653}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100654
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100655component_test_rsa_no_crt () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100656 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100657 scripts/config.pl set MBEDTLS_RSA_NO_CRT
658 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
659 make
660
661 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
662 make test
663
664 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
665 if_build_succeeded tests/ssl-opt.sh -f RSA
666
667 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
668 if_build_succeeded tests/compat.sh -t RSA
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100669}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100670
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100671component_test_full_cmake_clang () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100672 msg "build: cmake, full config, clang" # ~ 50s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100673 scripts/config.pl full
674 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
675 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check -D ENABLE_TESTING=On .
676 make
677
678 msg "test: main suites (full config)" # ~ 5s
679 make test
680
681 msg "test: ssl-opt.sh default (full config)" # ~ 1s
682 if_build_succeeded tests/ssl-opt.sh -f Default
683
684 msg "test: compat.sh RC4, DES & NULL (full config)" # ~ 2 min
685 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'
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100686}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100687
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100688component_build_deprecated () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100689 msg "build: make, full config + DEPRECATED_WARNING, gcc -O" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100690 scripts/config.pl full
691 scripts/config.pl set MBEDTLS_DEPRECATED_WARNING
692 # Build with -O -Wextra to catch a maximum of issues.
693 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra' lib programs
694 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
695
696 msg "build: make, full config + DEPRECATED_REMOVED, clang -O" # ~ 30s
697 # No cleanup, just tweak the configuration and rebuild
698 make clean
699 scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
700 scripts/config.pl set MBEDTLS_DEPRECATED_REMOVED
701 # Build with -O -Wextra to catch a maximum of issues.
702 make CC=clang CFLAGS='-O -Werror -Wall -Wextra' lib programs
703 make CC=clang CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100704}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100705
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100706component_test_depends_curves () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100707 msg "test/build: curves.pl (gcc)" # ~ 4 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100708 record_status tests/scripts/curves.pl
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100709}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100710
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100711component_test_depends_hashes () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100712 msg "test/build: depends-hashes.pl (gcc)" # ~ 2 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100713 record_status tests/scripts/depends-hashes.pl
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100714}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100715
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100716component_test_depends_pkalgs () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100717 msg "test/build: depends-pkalgs.pl (gcc)" # ~ 2 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100718 record_status tests/scripts/depends-pkalgs.pl
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100719}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100720
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100721component_build_key_exchanges () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100722 msg "test/build: key-exchanges (gcc)" # ~ 1 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100723 record_status tests/scripts/key-exchanges.pl
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100724}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100725
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100726component_build_default_make_gcc () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100727 msg "build: Unix make, -Os (gcc)" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100728 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100729}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100730
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100731component_test_no_platform () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100732 # Full configuration build, without platform support, file IO and net sockets.
733 # This should catch missing mbedtls_printf definitions, and by disabling file
734 # IO, it should catch missing '#include <stdio.h>'
735 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100736 scripts/config.pl full
737 scripts/config.pl unset MBEDTLS_PLATFORM_C
738 scripts/config.pl unset MBEDTLS_NET_C
739 scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
740 scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
741 scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
742 scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
743 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
744 scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
745 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
746 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
747 scripts/config.pl unset MBEDTLS_FS_IO
748 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
749 # to re-enable platform integration features otherwise disabled in C99 builds
750 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -O0 -D_DEFAULT_SOURCE' lib programs
751 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0' test
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100752}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100753
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100754component_build_no_std_function () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100755 # catch compile bugs in _uninit functions
756 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100757 scripts/config.pl full
758 scripts/config.pl set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
759 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
760 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100761}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100762
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100763component_build_no_ssl_srv () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100764 msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100765 scripts/config.pl full
766 scripts/config.pl unset MBEDTLS_SSL_SRV_C
767 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100768}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100769
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100770component_build_no_ssl_cli () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100771 msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100772 scripts/config.pl full
773 scripts/config.pl unset MBEDTLS_SSL_CLI_C
774 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100775}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100776
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100777component_build_no_sockets () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100778 # Note, C99 compliance can also be tested with the sockets support disabled,
779 # as that requires a POSIX platform (which isn't the same as C99).
780 msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100781 scripts/config.pl full
782 scripts/config.pl unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
783 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
784 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0 -std=c99 -pedantic' lib
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100785}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100786
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100787component_test_no_max_fragment_length () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100788 msg "build: default config except MFL extension (ASan build)" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100789 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
790 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
791 make
792
793 msg "test: ssl-opt.sh, MFL-related tests"
794 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length"
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100795}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100796
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100797component_test_null_entropy () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100798 msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100799 scripts/config.pl set MBEDTLS_TEST_NULL_ENTROPY
800 scripts/config.pl set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
801 scripts/config.pl set MBEDTLS_ENTROPY_C
802 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
803 scripts/config.pl unset MBEDTLS_ENTROPY_HARDWARE_ALT
804 scripts/config.pl unset MBEDTLS_HAVEGE_C
Gilles Peskine4e7b3232019-01-06 19:48:30 +0000805 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan -D UNSAFE_BUILD=ON .
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100806 make
807
808 msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)"
809 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100810}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100811
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100812component_test_platform_calloc_macro () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100813 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100814 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
815 scripts/config.pl set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
816 scripts/config.pl set MBEDTLS_PLATFORM_FREE_MACRO free
817 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
818 make
819
820 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
821 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100822}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100823
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100824component_test_make_shared () {
Gilles Peskine770ad7e2019-01-08 23:19:08 +0100825 msg "build/test: make shared" # ~ 40s
826 make SHARED=1 all check
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100827}
828
Gilles Peskine3fbdd212019-01-08 23:33:45 +0100829component_test_m32_o0 () {
830 # Build once with -O0, to compile out the i386 specific inline assembly
831 msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
832 scripts/config.pl full
833 make CC=gcc CFLAGS='-O0 -Werror -Wall -Wextra -m32 -fsanitize=address'
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100834
Gilles Peskine3fbdd212019-01-08 23:33:45 +0100835 msg "test: i386, make, gcc -O0 (ASan build)"
836 make test
837}
838support_test_m32_o0 () {
839 case $(uname -m) in
840 *64*) true;;
841 *) false;;
842 esac
843}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100844
Gilles Peskine3fbdd212019-01-08 23:33:45 +0100845component_test_m32_o1 () {
846 # Build again with -O1, to compile in the i386 specific inline assembly
847 msg "build: i386, make, gcc -O1 (ASan build)" # ~ 30s
848 scripts/config.pl full
849 make CC=gcc CFLAGS='-O1 -Werror -Wall -Wextra -m32 -fsanitize=address'
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100850
Gilles Peskine3fbdd212019-01-08 23:33:45 +0100851 msg "test: i386, make, gcc -O1 (ASan build)"
852 make test
853}
854support_test_m32_o1 () {
855 support_test_m32_o0 "$@"
856}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100857
Gilles Peskine3fbdd212019-01-08 23:33:45 +0100858component_test_mx32 () {
859 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
860 scripts/config.pl full
861 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32'
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100862
Gilles Peskine3fbdd212019-01-08 23:33:45 +0100863 msg "test: 64-bit ILP32, make, gcc"
864 make test
865}
866support_test_mx32 () {
867 case $(uname -m) in
868 amd64|x86_64) true;;
869 *) false;;
870 esac
871}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100872
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100873component_test_have_int32 () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100874 msg "build: gcc, force 32-bit bignum limbs"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100875 scripts/config.pl unset MBEDTLS_HAVE_ASM
876 scripts/config.pl unset MBEDTLS_AESNI_C
877 scripts/config.pl unset MBEDTLS_PADLOCK_C
878 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
879
880 msg "test: gcc, force 32-bit bignum limbs"
881 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100882}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100883
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100884component_test_have_int64 () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100885 msg "build: gcc, force 64-bit bignum limbs"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100886 scripts/config.pl unset MBEDTLS_HAVE_ASM
887 scripts/config.pl unset MBEDTLS_AESNI_C
888 scripts/config.pl unset MBEDTLS_PADLOCK_C
889 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
890
891 msg "test: gcc, force 64-bit bignum limbs"
892 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100893}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100894
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100895component_build_arm_none_eabi_gcc () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100896 msg "build: arm-none-eabi-gcc, make" # ~ 10s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100897 scripts/config.pl full
898 scripts/config.pl unset MBEDTLS_NET_C
899 scripts/config.pl unset MBEDTLS_TIMING_C
900 scripts/config.pl unset MBEDTLS_FS_IO
901 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
902 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
903 # following things are not in the default config
904 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
905 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
906 scripts/config.pl unset MBEDTLS_THREADING_C
907 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
908 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
909 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100910}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100911
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100912component_build_arm_none_eabi_gcc_no_udbl_division () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100913 msg "build: arm-none-eabi-gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100914 scripts/config.pl full
915 scripts/config.pl unset MBEDTLS_NET_C
916 scripts/config.pl unset MBEDTLS_TIMING_C
917 scripts/config.pl unset MBEDTLS_FS_IO
918 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
919 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
920 # following things are not in the default config
921 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
922 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
923 scripts/config.pl unset MBEDTLS_THREADING_C
924 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
925 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
926 scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
927 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
928 echo "Checking that software 64-bit division is not required"
Gilles Peskine30bc3852019-01-09 23:25:25 +0100929 if_build_succeeded not grep __aeabi_uldiv library/*.o
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100930}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100931
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100932component_build_armcc () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100933 msg "build: ARM Compiler 5, make"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100934 scripts/config.pl full
935 scripts/config.pl unset MBEDTLS_NET_C
936 scripts/config.pl unset MBEDTLS_TIMING_C
937 scripts/config.pl unset MBEDTLS_FS_IO
938 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
939 scripts/config.pl unset MBEDTLS_HAVE_TIME
940 scripts/config.pl unset MBEDTLS_HAVE_TIME_DATE
941 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
942 # following things are not in the default config
943 scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
944 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
945 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
946 scripts/config.pl unset MBEDTLS_THREADING_C
947 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
948 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
949 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT # depends on MBEDTLS_HAVE_TIME
950
Gilles Peskine53084872019-01-09 23:13:54 +0100951 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
952 make clean
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100953
Gilles Peskine53084872019-01-09 23:13:54 +0100954 # ARM Compiler 6 - Target ARMv7-A
955 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-a"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100956
Gilles Peskine53084872019-01-09 23:13:54 +0100957 # ARM Compiler 6 - Target ARMv7-M
958 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100959
Gilles Peskine53084872019-01-09 23:13:54 +0100960 # ARM Compiler 6 - Target ARMv8-A - AArch32
961 armc6_build_test "--target=arm-arm-none-eabi -march=armv8.2-a"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100962
Gilles Peskine53084872019-01-09 23:13:54 +0100963 # ARM Compiler 6 - Target ARMv8-M
964 armc6_build_test "--target=arm-arm-none-eabi -march=armv8-m.main"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100965
Gilles Peskine53084872019-01-09 23:13:54 +0100966 # ARM Compiler 6 - Target ARMv8-A - AArch64
967 armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a"
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100968}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000969
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100970component_test_allow_sha1 () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100971 msg "build: allow SHA1 in certificates by default"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100972 scripts/config.pl set MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
973 make CFLAGS='-Werror -Wall -Wextra'
974 msg "test: allow SHA1 in certificates by default"
975 make test
976 if_build_succeeded tests/ssl-opt.sh -f SHA-1
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100977}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000978
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100979component_build_mingw () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100980 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100981 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
982
983 # note Make tests only builds the tests, but doesn't run them
984 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror' WINDOWS_BUILD=1 tests
985 make WINDOWS_BUILD=1 clean
986
987 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
988 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
989 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
990 make WINDOWS_BUILD=1 clean
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100991}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100992
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100993component_test_memsan () {
Gilles Peskine770ad7e2019-01-08 23:19:08 +0100994 msg "build: MSan (clang)" # ~ 1 min 20s
995 scripts/config.pl unset MBEDTLS_AESNI_C # memsan doesn't grok asm
996 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
997 make
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100998
Gilles Peskine770ad7e2019-01-08 23:19:08 +0100999 msg "test: main suites (MSan)" # ~ 10s
1000 make test
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001001
Gilles Peskine770ad7e2019-01-08 23:19:08 +01001002 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
1003 if_build_succeeded tests/ssl-opt.sh
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001004
Gilles Peskine770ad7e2019-01-08 23:19:08 +01001005 # Optional part(s)
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001006
Gilles Peskine770ad7e2019-01-08 23:19:08 +01001007 if [ "$MEMORY" -gt 0 ]; then
1008 msg "test: compat.sh (MSan)" # ~ 6 min 20s
1009 if_build_succeeded tests/compat.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001010 fi
1011}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001012
Gilles Peskine9f553642019-01-10 00:11:42 +01001013component_test_valgrind () {
Gilles Peskine770ad7e2019-01-08 23:19:08 +01001014 msg "build: Release (clang)"
1015 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
1016 make
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001017
Gilles Peskine770ad7e2019-01-08 23:19:08 +01001018 msg "test: main suites valgrind (Release)"
1019 make memcheck
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001020
Gilles Peskine770ad7e2019-01-08 23:19:08 +01001021 # Optional part(s)
1022 # Currently broken, programs don't seem to receive signals
1023 # under valgrind on OS X
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001024
Gilles Peskine770ad7e2019-01-08 23:19:08 +01001025 if [ "$MEMORY" -gt 0 ]; then
1026 msg "test: ssl-opt.sh --memcheck (Release)"
1027 if_build_succeeded tests/ssl-opt.sh --memcheck
1028 fi
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001029
Gilles Peskine770ad7e2019-01-08 23:19:08 +01001030 if [ "$MEMORY" -gt 1 ]; then
1031 msg "test: compat.sh --memcheck (Release)"
1032 if_build_succeeded tests/compat.sh --memcheck
1033 fi
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001034}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001035
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001036component_test_cmake_out_of_source () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001037 msg "build: cmake 'out-of-source' build"
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001038 MBEDTLS_ROOT_DIR="$PWD"
1039 mkdir "$OUT_OF_SOURCE_DIR"
1040 cd "$OUT_OF_SOURCE_DIR"
1041 cmake "$MBEDTLS_ROOT_DIR"
1042 make
1043
1044 msg "test: cmake 'out-of-source' build"
1045 make test
1046 # Test an SSL option that requires an auxiliary script in test/scripts/.
1047 # Also ensure that there are no error messages such as
1048 # "No such file or directory", which would indicate that some required
1049 # file is missing (ssl-opt.sh tolerates the absence of some files so
1050 # may exit with status 0 but emit errors).
1051 if_build_succeeded ./tests/ssl-opt.sh -f 'Fallback SCSV: beginning of list' 2>ssl-opt.err
1052 if [ -s ssl-opt.err ]; then
1053 cat ssl-opt.err >&2
1054 record_status [ ! -s ssl-opt.err ]
1055 rm ssl-opt.err
1056 fi
1057 cd "$MBEDTLS_ROOT_DIR"
1058 rm -rf "$OUT_OF_SOURCE_DIR"
1059 unset MBEDTLS_ROOT_DIR
1060}
Andres AGdc192212016-08-31 17:33:13 +01001061
Gilles Peskine192c72f2017-12-21 15:59:21 +01001062
1063
1064################################################################
1065#### Termination
1066################################################################
1067
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001068post_report () {
1069 msg "Done, cleaning up"
1070 cleanup
1071
1072 final_report
1073}
1074
1075
1076
1077################################################################
1078#### Run all the things
1079################################################################
1080
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001081# Run one component and clean up afterwards.
1082run_component () {
Gilles Peskine72adb432019-01-02 18:57:02 +01001083 # Back up the configuration in case the component modifies it.
1084 # The cleanup function will restore it.
1085 cp -p "$CONFIG_H" "$CONFIG_BAK"
Gilles Peskine11ddca62018-12-04 12:49:28 +01001086 current_component="$1"
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001087 "$@"
1088 cleanup
1089}
1090
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001091# Preliminary setup
1092pre_check_environment
1093pre_initialize_variables
1094pre_parse_command_line "$@"
1095
1096pre_check_git
1097build_status=0
1098if [ $KEEP_GOING -eq 1 ]; then
1099 pre_setup_keep_going
1100else
1101 record_status () {
1102 "$@"
1103 }
1104fi
1105pre_print_configuration
1106pre_check_tools
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001107cleanup
Gilles Peskine7c652162017-12-11 00:01:40 +01001108
Gilles Peskineeb39b9b2019-01-08 23:41:00 +01001109# Run the requested tests.
Gilles Peskine6e984232018-11-27 21:37:53 +01001110for component in $RUN_COMPONENTS; do
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001111 run_component "component_$component"
1112done
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001113
1114# We're done.
1115post_report