blob: 50b3750c52d1b21190e75ed9b30a5001ae958f6b [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
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100124 # Default commands, can be overriden by the environment
125 : ${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 Peskine3fbdd212019-01-08 23:33:45 +0100157# Test whether $1 is excluded via the command line.
Gilles Peskine6e984232018-11-27 21:37:53 +0100158is_component_excluded()
159{
Gilles Peskine3fbdd212019-01-08 23:33:45 +0100160 # Is $1 excluded via $COMPONENTS (a space-separated list of wildcard
161 # patterns)?
Gilles Peskine6e984232018-11-27 21:37:53 +0100162 set -f
Gilles Peskineeb39b9b2019-01-08 23:41:00 +0100163 for pattern in $COMMAND_LINE_COMPONENTS; do
Gilles Peskine6e984232018-11-27 21:37:53 +0100164 set +f
165 case ${1#component_} in $pattern) return 0;; esac
166 done
167 set +f
168 return 1
169}
170
Simon Butcher41eeccf2016-09-07 00:07:09 +0100171usage()
SimonB2e23c822016-04-16 21:54:39 +0100172{
Gilles Peskine709346a2017-12-10 23:43:39 +0100173 cat <<EOF
Gilles Peskine91bd8b72019-01-08 23:01:34 +0100174Usage: $0 [OPTION]... [COMPONENT]...
175Run mbedtls release validation tests.
176By default, run all tests. With one or more COMPONENT, run only those.
177
178Special options:
179 -h|--help Print this help and exit.
Gilles Peskineb3241cb2019-01-08 23:44:07 +0100180 --list-all-components List all available test components and exit.
181 --list-components List components supported on this platform and exit.
Gilles Peskine709346a2017-12-10 23:43:39 +0100182
183General options:
184 -f|--force Force the tests to overwrite any modified files.
Gilles Peskine7c652162017-12-11 00:01:40 +0100185 -k|--keep-going Run all tests and report errors at the end.
Gilles Peskine709346a2017-12-10 23:43:39 +0100186 -m|--memory Additional optional memory tests.
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100187 --armcc Run ARM Compiler builds (on by default).
Gilles Peskine6e984232018-11-27 21:37:53 +0100188 --except If some components are passed on the command line,
189 run all the tests except for these components. In
190 this mode, you can pass shell wildcard patterns as
191 component names, e.g. "$0 --except 'test_*'" to
192 exclude all components that run tests.
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100193 --no-armcc Skip ARM Compiler builds.
Gilles Peskine19ceb712018-03-21 08:40:26 +0100194 --no-force Refuse to overwrite modified files (default).
195 --no-keep-going Stop at the first error (default).
196 --no-memory No additional memory tests (default).
Gilles Peskine2a22a802017-12-21 15:19:00 +0100197 --no-yotta Skip yotta module build.
Gilles Peskine709346a2017-12-10 23:43:39 +0100198 --out-of-source-dir=<path> Directory used for CMake out-of-source build tests.
Gilles Peskine19ceb712018-03-21 08:40:26 +0100199 --random-seed Use a random seed value for randomized tests (default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100200 -r|--release-test Run this script in release mode. This fixes the seed value to 1.
201 -s|--seed Integer seed value to use for this test run.
Gilles Peskine2a22a802017-12-21 15:19:00 +0100202 --yotta Build yotta module (on by default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100203
204Tool path options:
205 --armc5-bin-dir=<ARMC5_bin_dir_path> ARM Compiler 5 bin directory.
206 --armc6-bin-dir=<ARMC6_bin_dir_path> ARM Compiler 6 bin directory.
207 --gnutls-cli=<GnuTLS_cli_path> GnuTLS client executable to use for most tests.
208 --gnutls-serv=<GnuTLS_serv_path> GnuTLS server executable to use for most tests.
209 --gnutls-legacy-cli=<GnuTLS_cli_path> GnuTLS client executable to use for legacy tests.
210 --gnutls-legacy-serv=<GnuTLS_serv_path> GnuTLS server executable to use for legacy tests.
211 --openssl=<OpenSSL_path> OpenSSL executable to use for most tests.
212 --openssl-legacy=<OpenSSL_path> OpenSSL executable to use for legacy tests e.g. SSLv3.
213EOF
SimonB2e23c822016-04-16 21:54:39 +0100214}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100215
216# remove built files as well as the cmake cache/config
217cleanup()
218{
Gilles Peskinea71d64c2018-03-21 12:16:57 +0100219 if [ -n "${MBEDTLS_ROOT_DIR+set}" ]; then
220 cd "$MBEDTLS_ROOT_DIR"
221 fi
222
Gilles Peskine7c652162017-12-11 00:01:40 +0100223 command make clean
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200224
Gilles Peskine31b07e22018-03-21 12:15:06 +0100225 # Remove CMake artefacts
226 find . -name .git -prune -o -name yotta -prune -o \
227 -iname CMakeFiles -exec rm -rf {} \+ -o \
228 \( -iname cmake_install.cmake -o \
229 -iname CTestTestfile.cmake -o \
230 -iname CMakeCache.txt \) -exec rm {} \+
231 # Recover files overwritten by in-tree CMake builds
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000232 rm -f include/Makefile include/mbedtls/Makefile programs/*/Makefile
Paul Bakkerfe0984d2014-06-13 00:13:45 +0200233 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile
234 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200235
236 if [ -f "$CONFIG_BAK" ]; then
237 mv "$CONFIG_BAK" "$CONFIG_H"
238 fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100239}
240
Gilles Peskine7c652162017-12-11 00:01:40 +0100241# Executed on exit. May be redefined depending on command line options.
242final_report () {
243 :
244}
245
246fatal_signal () {
247 cleanup
248 final_report $1
249 trap - $1
250 kill -$1 $$
251}
252
253trap 'fatal_signal HUP' HUP
254trap 'fatal_signal INT' INT
255trap 'fatal_signal TERM' TERM
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200256
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100257msg()
258{
Gilles Peskine11ddca62018-12-04 12:49:28 +0100259 if [ -n "${current_component:-}" ]; then
260 current_section="${current_component#component_}: $1"
261 else
262 current_section="$1"
263 fi
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100264 echo ""
265 echo "******************************************************************"
Gilles Peskine11ddca62018-12-04 12:49:28 +0100266 echo "* $current_section "
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000267 printf "* "; date
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100268 echo "******************************************************************"
269}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100270
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100271armc6_build_test()
272{
273 FLAGS="$1"
Andres AGa5cd9732016-10-17 15:23:10 +0100274
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100275 msg "build: ARM Compiler 6 ($FLAGS), make"
276 ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \
277 WARNING_CFLAGS='-xc -std=c99' make lib
278 make clean
279}
Andres AGa5cd9732016-10-17 15:23:10 +0100280
Andres AGd9eba4b2016-08-26 14:42:14 +0100281err_msg()
282{
283 echo "$1" >&2
284}
285
286check_tools()
287{
288 for TOOL in "$@"; do
Andres AG98393602017-01-31 17:04:45 +0000289 if ! `type "$TOOL" >/dev/null 2>&1`; then
Andres AGd9eba4b2016-08-26 14:42:14 +0100290 err_msg "$TOOL not found!"
291 exit 1
292 fi
293 done
294}
295
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100296pre_parse_command_line () {
Gilles Peskineeb39b9b2019-01-08 23:41:00 +0100297 COMMAND_LINE_COMPONENTS=
298 all_except=
Gilles Peskine53084872019-01-09 23:13:54 +0100299 no_armcc=
Gilles Peskine6e984232018-11-27 21:37:53 +0100300
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100301 while [ $# -gt 0 ]; do
302 case "$1" in
Gilles Peskine53084872019-01-09 23:13:54 +0100303 --armcc) no_armcc=;;
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100304 --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
305 --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
Gilles Peskineeb39b9b2019-01-08 23:41:00 +0100306 --except) all_except=1;;
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100307 --force|-f) FORCE=1;;
308 --gnutls-cli) shift; GNUTLS_CLI="$1";;
309 --gnutls-legacy-cli) shift; GNUTLS_LEGACY_CLI="$1";;
310 --gnutls-legacy-serv) shift; GNUTLS_LEGACY_SERV="$1";;
311 --gnutls-serv) shift; GNUTLS_SERV="$1";;
312 --help|-h) usage; exit;;
313 --keep-going|-k) KEEP_GOING=1;;
Gilles Peskineb3241cb2019-01-08 23:44:07 +0100314 --list-all-components) printf '%s\n' $ALL_COMPONENTS; exit;;
315 --list-components) printf '%s\n' $SUPPORTED_COMPONENTS; exit;;
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100316 --memory|-m) MEMORY=1;;
Gilles Peskine53084872019-01-09 23:13:54 +0100317 --no-armcc) no_armcc=1;;
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100318 --no-force) FORCE=0;;
319 --no-keep-going) KEEP_GOING=0;;
320 --no-memory) MEMORY=0;;
321 --no-yotta) YOTTA=0;;
322 --openssl) shift; OPENSSL="$1";;
323 --openssl-legacy) shift; OPENSSL_LEGACY="$1";;
324 --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
325 --random-seed) unset SEED;;
326 --release-test|-r) SEED=1;;
327 --seed|-s) shift; SEED="$1";;
328 --yotta) YOTTA=1;;
Gilles Peskine91bd8b72019-01-08 23:01:34 +0100329 -*)
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100330 echo >&2 "Unknown option: $1"
331 echo >&2 "Run $0 --help for usage."
332 exit 120
333 ;;
Gilles Peskineeb39b9b2019-01-08 23:41:00 +0100334 *) COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS $1";;
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100335 esac
336 shift
337 done
Gilles Peskine91bd8b72019-01-08 23:01:34 +0100338
Gilles Peskineeb39b9b2019-01-08 23:41:00 +0100339 if [ -z "$COMMAND_LINE_COMPONENTS" ]; then
340 all_except=1
341 fi
342
Gilles Peskine53084872019-01-09 23:13:54 +0100343 # --no-armcc is a legacy option. The modern way is --except '*_armcc*'.
344 # Ignore it if components are listed explicitly on the command line.
345 if [ -n "$no_armcc" ] && [ -n "$all_except" ]; then
346 COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS *_armcc*"
347 # --no-armcc also disables yotta.
348 COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS *_yotta*"
349 fi
350
Gilles Peskineeb39b9b2019-01-08 23:41:00 +0100351 # Build the list of components to run.
352 if [ -n "$all_except" ]; then
Gilles Peskine6e984232018-11-27 21:37:53 +0100353 RUN_COMPONENTS=
Gilles Peskine3fbdd212019-01-08 23:33:45 +0100354 for component in $SUPPORTED_COMPONENTS; do
Gilles Peskine6e984232018-11-27 21:37:53 +0100355 if ! is_component_excluded "$component"; then
356 RUN_COMPONENTS="$RUN_COMPONENTS $component"
357 fi
358 done
Gilles Peskine6e984232018-11-27 21:37:53 +0100359 else
Gilles Peskineeb39b9b2019-01-08 23:41:00 +0100360 RUN_COMPONENTS="$COMMAND_LINE_COMPONENTS"
Gilles Peskine91bd8b72019-01-08 23:01:34 +0100361 fi
Gilles Peskineeb39b9b2019-01-08 23:41:00 +0100362
363 unset all_except
Gilles Peskine53084872019-01-09 23:13:54 +0100364 unset no_armcc
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100365}
SimonB2e23c822016-04-16 21:54:39 +0100366
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100367pre_check_git () {
368 if [ $FORCE -eq 1 ]; then
Gilles Peskinec7800952019-01-09 23:14:09 +0100369 rm -rf "$OUT_OF_SOURCE_DIR"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100370 if [ $YOTTA -eq 1 ]; then
Gilles Peskinec7800952019-01-09 23:14:09 +0100371 rm -rf yotta/module
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100372 fi
373 git checkout-index -f -q $CONFIG_H
374 cleanup
375 else
376
377 if [ $YOTTA -ne 0 ] && [ -d yotta/module ]; then
378 err_msg "Warning - there is an existing yotta module in the directory 'yotta/module'"
379 echo "You can either delete your work and retry, or force the test to overwrite the"
380 echo "test by rerunning the script as: $0 --force"
381 exit 1
382 fi
383
384 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
385 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
386 echo "You can either delete this directory manually, or force the test by rerunning"
387 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
388 exit 1
389 fi
390
Gilles Peskinec9663b12019-01-09 22:30:01 +0100391 if ! git diff --quiet include/mbedtls/config.h; then
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100392 err_msg "Warning - the configuration file 'include/mbedtls/config.h' has been edited. "
393 echo "You can either delete or preserve your work, or force the test by rerunning the"
394 echo "script as: $0 --force"
395 exit 1
396 fi
Gilles Peskineda519252017-11-30 13:22:04 +0100397 fi
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100398}
SimonB2e23c822016-04-16 21:54:39 +0100399
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100400pre_setup_keep_going () {
Gilles Peskine7c652162017-12-11 00:01:40 +0100401 failure_summary=
402 failure_count=0
403 start_red=
404 end_color=
405 if [ -t 1 ]; then
Gilles Peskine9736b9d2018-01-02 21:54:17 +0100406 case "${TERM:-}" in
Gilles Peskine7c652162017-12-11 00:01:40 +0100407 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
408 start_red=$(printf '\033[31m')
409 end_color=$(printf '\033[0m')
410 ;;
411 esac
412 fi
413 record_status () {
414 if "$@"; then
415 last_status=0
416 else
417 last_status=$?
418 text="$current_section: $* -> $last_status"
419 failure_summary="$failure_summary
420$text"
421 failure_count=$((failure_count + 1))
422 echo "${start_red}^^^^$text^^^^${end_color}"
423 fi
424 }
425 make () {
426 case "$*" in
427 *test|*check)
428 if [ $build_status -eq 0 ]; then
429 record_status command make "$@"
430 else
431 echo "(skipped because the build failed)"
432 fi
433 ;;
434 *)
435 record_status command make "$@"
436 build_status=$last_status
437 ;;
438 esac
439 }
440 final_report () {
441 if [ $failure_count -gt 0 ]; then
442 echo
443 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
444 echo "${start_red}FAILED: $failure_count${end_color}$failure_summary"
445 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Jaeden Amero5113bde2018-07-20 16:42:14 +0100446 exit 1
Gilles Peskine7c652162017-12-11 00:01:40 +0100447 elif [ -z "${1-}" ]; then
448 echo "SUCCESS :)"
449 fi
450 if [ -n "${1-}" ]; then
451 echo "Killed by SIG$1."
452 fi
453 }
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100454}
455
Gilles Peskine7c652162017-12-11 00:01:40 +0100456if_build_succeeded () {
457 if [ $build_status -eq 0 ]; then
458 record_status "$@"
459 fi
460}
461
Gilles Peskine30bc3852019-01-09 23:25:25 +0100462# to be used instead of ! for commands run with
463# record_status or if_build_succeeded
464not() {
465 ! "$@"
466}
467
468
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100469pre_print_configuration () {
470 msg "info: $0 configuration"
471 echo "MEMORY: $MEMORY"
472 echo "FORCE: $FORCE"
473 echo "SEED: ${SEED-"UNSET"}"
474 echo "OPENSSL: $OPENSSL"
475 echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
476 echo "GNUTLS_CLI: $GNUTLS_CLI"
477 echo "GNUTLS_SERV: $GNUTLS_SERV"
478 echo "GNUTLS_LEGACY_CLI: $GNUTLS_LEGACY_CLI"
479 echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV"
480 echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
481 echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
482}
Andres AG7770ea82016-10-10 15:46:20 +0100483
Andres AGd9eba4b2016-08-26 14:42:14 +0100484# Make sure the tools we need are available.
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100485pre_check_tools () {
Gilles Peskine541fb1e2019-01-06 22:40:00 +0000486 # Build the list of variables to pass to output_env.sh.
487 set env
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100488
Gilles Peskine541fb1e2019-01-06 22:40:00 +0000489 case " $RUN_COMPONENTS " in
490 # Require OpenSSL and GnuTLS if running any tests (as opposed to
491 # only doing builds). Not all tests run OpenSSL and GnuTLS, but this
492 # is a good enough approximation in practice.
493 *" test_"*)
494 # To avoid setting OpenSSL and GnuTLS for each call to compat.sh
495 # and ssl-opt.sh, we just export the variables they require.
496 export OPENSSL_CMD="$OPENSSL"
497 export GNUTLS_CLI="$GNUTLS_CLI"
498 export GNUTLS_SERV="$GNUTLS_SERV"
499 # Avoid passing --seed flag in every call to ssl-opt.sh
500 if [ -n "${SEED-}" ]; then
501 export SEED
502 fi
503 set "$@" OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY"
504 set "$@" GNUTLS_CLI="$GNUTLS_CLI" GNUTLS_SERV="$GNUTLS_SERV"
505 set "$@" GNUTLS_LEGACY_CLI="$GNUTLS_LEGACY_CLI"
506 set "$@" GNUTLS_LEGACY_SERV="$GNUTLS_LEGACY_SERV"
507 check_tools "$OPENSSL" "$OPENSSL_LEGACY" \
508 "$GNUTLS_CLI" "$GNUTLS_SERV" \
509 "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV"
510 ;;
511 esac
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100512
Gilles Peskine541fb1e2019-01-06 22:40:00 +0000513 case " $RUN_COMPONENTS " in
514 *_doxygen[_\ ]*) check_tools "doxygen" "dot";;
515 esac
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100516
Gilles Peskine541fb1e2019-01-06 22:40:00 +0000517 case " $RUN_COMPONENTS " in
518 *_arm_none_eabi_gcc[_\ ]*) check_tools "arm-none-eabi-gcc";;
519 esac
520
521 case " $RUN_COMPONENTS " in
522 *_mingw[_\ ]*) check_tools "i686-w64-mingw32-gcc";;
523 esac
524
525 case " $RUN_COMPONENTS " in
Gilles Peskine53084872019-01-09 23:13:54 +0100526 *_armcc*|*_yotta*)
Gilles Peskine541fb1e2019-01-06 22:40:00 +0000527 ARMC5_CC="$ARMC5_BIN_DIR/armcc"
528 ARMC5_AR="$ARMC5_BIN_DIR/armar"
529 ARMC6_CC="$ARMC6_BIN_DIR/armclang"
530 ARMC6_AR="$ARMC6_BIN_DIR/armar"
Gilles Peskine53084872019-01-09 23:13:54 +0100531 check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC6_CC" "$ARMC6_AR";;
532 esac
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100533
534 msg "info: output_env.sh"
Gilles Peskine53084872019-01-09 23:13:54 +0100535 case $RUN_COMPONENTS in
536 *_armcc*|*_yotta*)
537 set "$@" ARMC5_CC="$ARMC5_CC" ARMC6_CC="$ARMC6_CC" RUN_ARMCC=1;;
538 *) set "$@" RUN_ARMCC=0;;
539 esac
540 "$@" scripts/output_env.sh
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100541}
Andres AGd9eba4b2016-08-26 14:42:14 +0100542
Gilles Peskine192c72f2017-12-21 15:59:21 +0100543
544
545################################################################
546#### Basic checks
547################################################################
SimonB2e23c822016-04-16 21:54:39 +0100548
549#
550# Test Suites to be executed
551#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200552# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100553# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard61bc57a2014-08-14 11:29:06 +0200554# and/or are more likely to fail than others (eg I use Clang most of the
555# time, so start with a GCC build).
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200556# 2. Minimize total running time, by avoiding useless rebuilds
557#
558# Indicative running times are given for reference.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100559
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100560component_check_recursion () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100561 msg "test: recursion.pl" # < 1s
562 record_status tests/scripts/recursion.pl library/*.c
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100563}
Manuel Pégourié-Gonnardea29d152014-11-20 17:32:33 +0100564
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100565component_check_generated_files () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100566 msg "test: freshness of generated source files" # < 1s
567 record_status tests/scripts/check-generated-files.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100568}
Manuel Pégourié-Gonnardb3b8e432015-02-13 14:52:19 +0000569
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100570component_check_doxy_blocks () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100571 msg "test: doxygen markup outside doxygen blocks" # < 1s
572 record_status tests/scripts/check-doxy-blocks.pl
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100573}
Manuel Pégourié-Gonnardd09a6b52015-04-09 17:19:23 +0200574
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100575component_check_files () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100576 msg "test: check-files.py" # < 1s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100577 record_status tests/scripts/check-files.py
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100578}
Manuel Pégourié-Gonnard77d56bb2015-07-28 15:00:37 +0200579
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100580component_check_names () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100581 msg "test/build: declared and exported names" # < 3s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100582 record_status tests/scripts/check-names.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100583}
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +0200584
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100585component_check_doxygen_warnings () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100586 msg "test: doxygen warnings" # ~ 3s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100587 record_status tests/scripts/doxygen.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100588}
Andres Amaya Garciadd29c2f2017-05-04 11:35:51 +0100589
Simon Butcher948f2642018-07-20 21:27:33 +0100590
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100591################################################################
592#### Build and test many configurations and targets
593################################################################
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100594
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100595component_build_yotta () {
Gilles Peskine53084872019-01-09 23:13:54 +0100596 # Note - use of yotta is deprecated, and yotta also requires armcc to be on the
597 # path, and uses whatever version of armcc it finds there.
598 msg "build: create and build yotta module" # ~ 30s
599 record_status tests/scripts/yotta-build.sh
600}
601support_build_yotta () {
602 [ $YOTTA -ne 0 ]
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100603}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100604
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100605component_test_default_cmake_gcc_asan () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100606 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100607 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100608 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +0200609
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100610 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100611 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100612
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100613 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
Gilles Peskine7c652162017-12-11 00:01:40 +0100614 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100615
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100616 msg "test: compat.sh (ASan build)" # ~ 6 min
617 if_build_succeeded tests/compat.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100618}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000619
Gilles Peskine3484ed82019-01-08 22:51:19 +0100620component_test_ref_configs () {
621 msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
622 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
623 record_status tests/scripts/test-ref-configs.pl
624}
625
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100626component_test_sslv3 () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100627 msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100628 scripts/config.pl set MBEDTLS_SSL_PROTO_SSL3
629 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
630 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000631
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100632 msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
633 make test
634
635 msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
636 if_build_succeeded tests/compat.sh -m 'tls1 tls1_1 tls1_2 dtls1 dtls1_2'
637 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
638
639 msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
640 if_build_succeeded tests/ssl-opt.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100641}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100642
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100643component_test_no_renegotiation () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100644 msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100645 scripts/config.pl unset MBEDTLS_SSL_RENEGOTIATION
646 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
647 make
648
649 msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
650 make test
651
652 msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
653 if_build_succeeded tests/ssl-opt.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100654}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100655
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100656component_test_rsa_no_crt () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100657 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100658 scripts/config.pl set MBEDTLS_RSA_NO_CRT
659 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
660 make
661
662 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
663 make test
664
665 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
666 if_build_succeeded tests/ssl-opt.sh -f RSA
667
668 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
669 if_build_succeeded tests/compat.sh -t RSA
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100670}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100671
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100672component_test_full_cmake_clang () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100673 msg "build: cmake, full config, clang" # ~ 50s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100674 scripts/config.pl full
675 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
676 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check -D ENABLE_TESTING=On .
677 make
678
679 msg "test: main suites (full config)" # ~ 5s
680 make test
681
682 msg "test: ssl-opt.sh default (full config)" # ~ 1s
683 if_build_succeeded tests/ssl-opt.sh -f Default
684
685 msg "test: compat.sh RC4, DES & NULL (full config)" # ~ 2 min
686 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 +0100687}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100688
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100689component_build_deprecated () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100690 msg "build: make, full config + DEPRECATED_WARNING, gcc -O" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100691 scripts/config.pl full
692 scripts/config.pl set MBEDTLS_DEPRECATED_WARNING
693 # Build with -O -Wextra to catch a maximum of issues.
694 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra' lib programs
695 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
696
697 msg "build: make, full config + DEPRECATED_REMOVED, clang -O" # ~ 30s
698 # No cleanup, just tweak the configuration and rebuild
699 make clean
700 scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
701 scripts/config.pl set MBEDTLS_DEPRECATED_REMOVED
702 # Build with -O -Wextra to catch a maximum of issues.
703 make CC=clang CFLAGS='-O -Werror -Wall -Wextra' lib programs
704 make CC=clang CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100705}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100706
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100707component_test_depends_curves () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100708 msg "test/build: curves.pl (gcc)" # ~ 4 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100709 record_status tests/scripts/curves.pl
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100710}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100711
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100712component_test_depends_hashes () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100713 msg "test/build: depends-hashes.pl (gcc)" # ~ 2 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100714 record_status tests/scripts/depends-hashes.pl
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100715}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100716
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100717component_test_depends_pkalgs () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100718 msg "test/build: depends-pkalgs.pl (gcc)" # ~ 2 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100719 record_status tests/scripts/depends-pkalgs.pl
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100720}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100721
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100722component_build_key_exchanges () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100723 msg "test/build: key-exchanges (gcc)" # ~ 1 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100724 record_status tests/scripts/key-exchanges.pl
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100725}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100726
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100727component_build_default_make_gcc () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100728 msg "build: Unix make, -Os (gcc)" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100729 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100730}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100731
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100732component_test_no_platform () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100733 # Full configuration build, without platform support, file IO and net sockets.
734 # This should catch missing mbedtls_printf definitions, and by disabling file
735 # IO, it should catch missing '#include <stdio.h>'
736 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100737 scripts/config.pl full
738 scripts/config.pl unset MBEDTLS_PLATFORM_C
739 scripts/config.pl unset MBEDTLS_NET_C
740 scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
741 scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
742 scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
743 scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
744 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
745 scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
746 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
747 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
748 scripts/config.pl unset MBEDTLS_FS_IO
749 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
750 # to re-enable platform integration features otherwise disabled in C99 builds
751 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -O0 -D_DEFAULT_SOURCE' lib programs
752 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0' test
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100753}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100754
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100755component_build_no_std_function () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100756 # catch compile bugs in _uninit functions
757 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100758 scripts/config.pl full
759 scripts/config.pl set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
760 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
761 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100762}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100763
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100764component_build_no_ssl_srv () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100765 msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100766 scripts/config.pl full
767 scripts/config.pl unset MBEDTLS_SSL_SRV_C
768 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100769}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100770
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100771component_build_no_ssl_cli () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100772 msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100773 scripts/config.pl full
774 scripts/config.pl unset MBEDTLS_SSL_CLI_C
775 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100776}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100777
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100778component_build_no_sockets () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100779 # Note, C99 compliance can also be tested with the sockets support disabled,
780 # as that requires a POSIX platform (which isn't the same as C99).
781 msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100782 scripts/config.pl full
783 scripts/config.pl unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
784 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
785 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0 -std=c99 -pedantic' lib
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100786}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100787
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100788component_test_no_max_fragment_length () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100789 msg "build: default config except MFL extension (ASan build)" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100790 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
791 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
792 make
793
794 msg "test: ssl-opt.sh, MFL-related tests"
795 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length"
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100796}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100797
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100798component_test_null_entropy () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100799 msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100800 scripts/config.pl set MBEDTLS_TEST_NULL_ENTROPY
801 scripts/config.pl set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
802 scripts/config.pl set MBEDTLS_ENTROPY_C
803 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
804 scripts/config.pl unset MBEDTLS_ENTROPY_HARDWARE_ALT
805 scripts/config.pl unset MBEDTLS_HAVEGE_C
Gilles Peskine4e7b3232019-01-06 19:48:30 +0000806 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan -D UNSAFE_BUILD=ON .
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100807 make
808
809 msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)"
810 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100811}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100812
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100813component_test_platform_calloc_macro () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100814 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100815 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
816 scripts/config.pl set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
817 scripts/config.pl set MBEDTLS_PLATFORM_FREE_MACRO free
818 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
819 make
820
821 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
822 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100823}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100824
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100825component_test_make_shared () {
Gilles Peskine770ad7e2019-01-08 23:19:08 +0100826 msg "build/test: make shared" # ~ 40s
827 make SHARED=1 all check
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100828}
829
Gilles Peskine3fbdd212019-01-08 23:33:45 +0100830component_test_m32_o0 () {
831 # Build once with -O0, to compile out the i386 specific inline assembly
832 msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
833 scripts/config.pl full
834 make CC=gcc CFLAGS='-O0 -Werror -Wall -Wextra -m32 -fsanitize=address'
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100835
Gilles Peskine3fbdd212019-01-08 23:33:45 +0100836 msg "test: i386, make, gcc -O0 (ASan build)"
837 make test
838}
839support_test_m32_o0 () {
840 case $(uname -m) in
841 *64*) true;;
842 *) false;;
843 esac
844}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100845
Gilles Peskine3fbdd212019-01-08 23:33:45 +0100846component_test_m32_o1 () {
847 # Build again with -O1, to compile in the i386 specific inline assembly
848 msg "build: i386, make, gcc -O1 (ASan build)" # ~ 30s
849 scripts/config.pl full
850 make CC=gcc CFLAGS='-O1 -Werror -Wall -Wextra -m32 -fsanitize=address'
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100851
Gilles Peskine3fbdd212019-01-08 23:33:45 +0100852 msg "test: i386, make, gcc -O1 (ASan build)"
853 make test
854}
855support_test_m32_o1 () {
856 support_test_m32_o0 "$@"
857}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100858
Gilles Peskine3fbdd212019-01-08 23:33:45 +0100859component_test_mx32 () {
860 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
861 scripts/config.pl full
862 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32'
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100863
Gilles Peskine3fbdd212019-01-08 23:33:45 +0100864 msg "test: 64-bit ILP32, make, gcc"
865 make test
866}
867support_test_mx32 () {
868 case $(uname -m) in
869 amd64|x86_64) true;;
870 *) false;;
871 esac
872}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100873
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100874component_test_have_int32 () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100875 msg "build: gcc, force 32-bit bignum limbs"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100876 scripts/config.pl unset MBEDTLS_HAVE_ASM
877 scripts/config.pl unset MBEDTLS_AESNI_C
878 scripts/config.pl unset MBEDTLS_PADLOCK_C
879 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
880
881 msg "test: gcc, force 32-bit bignum limbs"
882 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100883}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100884
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100885component_test_have_int64 () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100886 msg "build: gcc, force 64-bit bignum limbs"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100887 scripts/config.pl unset MBEDTLS_HAVE_ASM
888 scripts/config.pl unset MBEDTLS_AESNI_C
889 scripts/config.pl unset MBEDTLS_PADLOCK_C
890 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
891
892 msg "test: gcc, force 64-bit bignum limbs"
893 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100894}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100895
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100896component_build_arm_none_eabi_gcc () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100897 msg "build: arm-none-eabi-gcc, make" # ~ 10s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100898 scripts/config.pl full
899 scripts/config.pl unset MBEDTLS_NET_C
900 scripts/config.pl unset MBEDTLS_TIMING_C
901 scripts/config.pl unset MBEDTLS_FS_IO
902 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
903 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
904 # following things are not in the default config
905 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
906 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
907 scripts/config.pl unset MBEDTLS_THREADING_C
908 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
909 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
910 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 +0100911}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100912
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100913component_build_arm_none_eabi_gcc_no_udbl_division () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100914 msg "build: arm-none-eabi-gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100915 scripts/config.pl full
916 scripts/config.pl unset MBEDTLS_NET_C
917 scripts/config.pl unset MBEDTLS_TIMING_C
918 scripts/config.pl unset MBEDTLS_FS_IO
919 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
920 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
921 # following things are not in the default config
922 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
923 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
924 scripts/config.pl unset MBEDTLS_THREADING_C
925 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
926 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
927 scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
928 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
929 echo "Checking that software 64-bit division is not required"
Gilles Peskine30bc3852019-01-09 23:25:25 +0100930 if_build_succeeded not grep __aeabi_uldiv library/*.o
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100931}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100932
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100933component_build_armcc () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100934 msg "build: ARM Compiler 5, make"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100935 scripts/config.pl full
936 scripts/config.pl unset MBEDTLS_NET_C
937 scripts/config.pl unset MBEDTLS_TIMING_C
938 scripts/config.pl unset MBEDTLS_FS_IO
939 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
940 scripts/config.pl unset MBEDTLS_HAVE_TIME
941 scripts/config.pl unset MBEDTLS_HAVE_TIME_DATE
942 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
943 # following things are not in the default config
944 scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
945 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
946 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
947 scripts/config.pl unset MBEDTLS_THREADING_C
948 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
949 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
950 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT # depends on MBEDTLS_HAVE_TIME
951
Gilles Peskine53084872019-01-09 23:13:54 +0100952 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
953 make clean
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100954
Gilles Peskine53084872019-01-09 23:13:54 +0100955 # ARM Compiler 6 - Target ARMv7-A
956 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-a"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100957
Gilles Peskine53084872019-01-09 23:13:54 +0100958 # ARM Compiler 6 - Target ARMv7-M
959 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100960
Gilles Peskine53084872019-01-09 23:13:54 +0100961 # ARM Compiler 6 - Target ARMv8-A - AArch32
962 armc6_build_test "--target=arm-arm-none-eabi -march=armv8.2-a"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100963
Gilles Peskine53084872019-01-09 23:13:54 +0100964 # ARM Compiler 6 - Target ARMv8-M
965 armc6_build_test "--target=arm-arm-none-eabi -march=armv8-m.main"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100966
Gilles Peskine53084872019-01-09 23:13:54 +0100967 # ARM Compiler 6 - Target ARMv8-A - AArch64
968 armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a"
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100969}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000970
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100971component_test_allow_sha1 () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100972 msg "build: allow SHA1 in certificates by default"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100973 scripts/config.pl set MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
974 make CFLAGS='-Werror -Wall -Wextra'
975 msg "test: allow SHA1 in certificates by default"
976 make test
977 if_build_succeeded tests/ssl-opt.sh -f SHA-1
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100978}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000979
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100980component_build_mingw () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100981 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100982 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
983
984 # note Make tests only builds the tests, but doesn't run them
985 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror' WINDOWS_BUILD=1 tests
986 make WINDOWS_BUILD=1 clean
987
988 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
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 lib programs
990 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
991 make WINDOWS_BUILD=1 clean
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100992}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100993
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100994component_test_memsan () {
Gilles Peskine770ad7e2019-01-08 23:19:08 +0100995 msg "build: MSan (clang)" # ~ 1 min 20s
996 scripts/config.pl unset MBEDTLS_AESNI_C # memsan doesn't grok asm
997 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
998 make
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100999
Gilles Peskine770ad7e2019-01-08 23:19:08 +01001000 msg "test: main suites (MSan)" # ~ 10s
1001 make test
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001002
Gilles Peskine770ad7e2019-01-08 23:19:08 +01001003 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
1004 if_build_succeeded tests/ssl-opt.sh
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001005
Gilles Peskine770ad7e2019-01-08 23:19:08 +01001006 # Optional part(s)
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001007
Gilles Peskine770ad7e2019-01-08 23:19:08 +01001008 if [ "$MEMORY" -gt 0 ]; then
1009 msg "test: compat.sh (MSan)" # ~ 6 min 20s
1010 if_build_succeeded tests/compat.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001011 fi
1012}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001013
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001014component_test_memcheck () {
Gilles Peskine770ad7e2019-01-08 23:19:08 +01001015 msg "build: Release (clang)"
1016 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
1017 make
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001018
Gilles Peskine770ad7e2019-01-08 23:19:08 +01001019 msg "test: main suites valgrind (Release)"
1020 make memcheck
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001021
Gilles Peskine770ad7e2019-01-08 23:19:08 +01001022 # Optional part(s)
1023 # Currently broken, programs don't seem to receive signals
1024 # under valgrind on OS X
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001025
Gilles Peskine770ad7e2019-01-08 23:19:08 +01001026 if [ "$MEMORY" -gt 0 ]; then
1027 msg "test: ssl-opt.sh --memcheck (Release)"
1028 if_build_succeeded tests/ssl-opt.sh --memcheck
1029 fi
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001030
Gilles Peskine770ad7e2019-01-08 23:19:08 +01001031 if [ "$MEMORY" -gt 1 ]; then
1032 msg "test: compat.sh --memcheck (Release)"
1033 if_build_succeeded tests/compat.sh --memcheck
1034 fi
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001035}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001036
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001037component_test_cmake_out_of_source () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001038 msg "build: cmake 'out-of-source' build"
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001039 MBEDTLS_ROOT_DIR="$PWD"
1040 mkdir "$OUT_OF_SOURCE_DIR"
1041 cd "$OUT_OF_SOURCE_DIR"
1042 cmake "$MBEDTLS_ROOT_DIR"
1043 make
1044
1045 msg "test: cmake 'out-of-source' build"
1046 make test
1047 # Test an SSL option that requires an auxiliary script in test/scripts/.
1048 # Also ensure that there are no error messages such as
1049 # "No such file or directory", which would indicate that some required
1050 # file is missing (ssl-opt.sh tolerates the absence of some files so
1051 # may exit with status 0 but emit errors).
1052 if_build_succeeded ./tests/ssl-opt.sh -f 'Fallback SCSV: beginning of list' 2>ssl-opt.err
1053 if [ -s ssl-opt.err ]; then
1054 cat ssl-opt.err >&2
1055 record_status [ ! -s ssl-opt.err ]
1056 rm ssl-opt.err
1057 fi
1058 cd "$MBEDTLS_ROOT_DIR"
1059 rm -rf "$OUT_OF_SOURCE_DIR"
1060 unset MBEDTLS_ROOT_DIR
1061}
Andres AGdc192212016-08-31 17:33:13 +01001062
Gilles Peskine192c72f2017-12-21 15:59:21 +01001063
1064
1065################################################################
1066#### Termination
1067################################################################
1068
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001069post_report () {
1070 msg "Done, cleaning up"
1071 cleanup
1072
1073 final_report
1074}
1075
1076
1077
1078################################################################
1079#### Run all the things
1080################################################################
1081
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001082# Run one component and clean up afterwards.
1083run_component () {
Gilles Peskine72adb432019-01-02 18:57:02 +01001084 # Back up the configuration in case the component modifies it.
1085 # The cleanup function will restore it.
1086 cp -p "$CONFIG_H" "$CONFIG_BAK"
Gilles Peskine11ddca62018-12-04 12:49:28 +01001087 current_component="$1"
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001088 "$@"
1089 cleanup
1090}
1091
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001092# Preliminary setup
1093pre_check_environment
1094pre_initialize_variables
1095pre_parse_command_line "$@"
1096
1097pre_check_git
1098build_status=0
1099if [ $KEEP_GOING -eq 1 ]; then
1100 pre_setup_keep_going
1101else
1102 record_status () {
1103 "$@"
1104 }
1105fi
1106pre_print_configuration
1107pre_check_tools
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001108cleanup
Gilles Peskine7c652162017-12-11 00:01:40 +01001109
Gilles Peskineeb39b9b2019-01-08 23:41:00 +01001110# Run the requested tests.
Gilles Peskine6e984232018-11-27 21:37:53 +01001111for component in $RUN_COMPONENTS; do
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001112 run_component "component_$component"
1113done
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001114
1115# We're done.
1116post_report