blob: d995ba50ce3607718b289331c1d5cb5872159802 [file] [log] [blame]
Andres AG31f9b5b2016-10-04 17:14:38 +01001#! /usr/bin/env sh
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01002
Simon Butcher3ea7f522016-03-07 23:22:10 +00003# all.sh
4#
SimonB2e23c822016-04-16 21:54:39 +01005# This file is part of mbed TLS (https://tls.mbed.org)
6#
Gilles Peskine192c72f2017-12-21 15:59:21 +01007# Copyright (c) 2014-2017, ARM Limited, All Rights Reserved
8
9
10
11################################################################
12#### Documentation
13################################################################
14
Simon Butcher3ea7f522016-03-07 23:22:10 +000015# Purpose
Gilles Peskine192c72f2017-12-21 15:59:21 +010016# -------
Simon Butcher3ea7f522016-03-07 23:22:10 +000017#
SimonB2e23c822016-04-16 21:54:39 +010018# To run all tests possible or available on the platform.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010019#
Gilles Peskine192c72f2017-12-21 15:59:21 +010020# Notes for users
21# ---------------
22#
SimonB2e23c822016-04-16 21:54:39 +010023# Warning: the test is destructive. It includes various build modes and
24# configurations, and can and will arbitrarily change the current CMake
Gilles Peskine192c72f2017-12-21 15:59:21 +010025# configuration. The following files must be committed into git:
26# * include/mbedtls/config.h
27# * Makefile, library/Makefile, programs/Makefile, tests/Makefile
28# After running this script, the CMake cache will be lost and CMake
29# will no longer be initialised.
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +010030#
Gilles Peskine192c72f2017-12-21 15:59:21 +010031# The script assumes the presence of a number of tools:
32# * Basic Unix tools (Windows users note: a Unix-style find must be before
33# the Windows find in the PATH)
34# * Perl
35# * GNU Make
36# * CMake
37# * GCC and Clang (recent enough for using ASan with gcc and MemSan with clang, or valgrind)
Andrzej Kurek05be06c2018-06-28 04:41:50 -040038# * G++
Gilles Peskine192c72f2017-12-21 15:59:21 +010039# * arm-gcc and mingw-gcc
40# * ArmCC 5 and ArmCC 6, unless invoked with --no-armcc
Gilles Peskine192c72f2017-12-21 15:59:21 +010041# See the invocation of check_tools below for details.
42#
43# This script must be invoked from the toplevel directory of a git
44# working copy of Mbed TLS.
45#
46# Note that the output is not saved. You may want to run
47# script -c tests/scripts/all.sh
48# or
49# tests/scripts/all.sh >all.log 2>&1
50#
51# Notes for maintainers
52# ---------------------
53#
Gilles Peskine8f073122018-11-27 15:58:47 +010054# The bulk of the code is organized into functions that follow one of the
55# following naming conventions:
56# * pre_XXX: things to do before running the tests, in order.
57# * component_XXX: independent components. They can be run in any order.
Gilles Peskine92bff7f2019-01-09 22:29:17 +010058# * component_check_XXX: quick tests that aren't worth parallelizing.
59# * component_build_XXX: build things but don't run them.
60# * component_test_XXX: build and test.
Gilles Peskine10726102019-01-06 20:50:38 +000061# * support_XXX: if support_XXX exists and returns false then
62# component_XXX is not run by default.
Gilles Peskine8f073122018-11-27 15:58:47 +010063# * post_XXX: things to do after running the tests.
64# * other: miscellaneous support functions.
65#
Gilles Peskine92bff7f2019-01-09 22:29:17 +010066# Each component must start by invoking `msg` with a short informative message.
67#
68# The framework performs some cleanup tasks after each component. This
69# means that components can assume that the working directory is in a
70# cleaned-up state, and don't need to perform the cleanup themselves.
71# * Run `make clean`.
72# * Restore `include/mbedtks/config.h` from a backup made before running
73# the component.
74# * Check out `Makefile`, `library/Makefile`, `programs/Makefile` and
75# `tests/Makefile` from git. This cleans up after an in-tree use of
76# CMake.
77#
78# Any command that is expected to fail must be protected so that the
79# script keeps running in --keep-going mode despite `set -e`. In keep-going
80# mode, if a protected command fails, this is logged as a failure and the
81# script will exit with a failure status once it has run all components.
82# Commands can be protected in any of the following ways:
83# * `make` is a function which runs the `make` command with protection.
84# Note that you must write `make VAR=value`, not `VAR=value make`,
85# because the `VAR=value make` syntax doesn't work with functions.
86# * Put `report_status` before the command to protect it.
87# * Put `if_build_successful` before a command. This protects it, and
88# additionally skips it if a prior invocation of `make` in the same
89# component failed.
90#
Gilles Peskine192c72f2017-12-21 15:59:21 +010091# The tests are roughly in order from fastest to slowest. This doesn't
92# have to be exact, but in general you should add slower tests towards
93# the end and fast checks near the beginning.
Gilles Peskine192c72f2017-12-21 15:59:21 +010094
95
96
97################################################################
98#### Initialization and command line parsing
99################################################################
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100100
SimonB2e23c822016-04-16 21:54:39 +0100101# Abort on errors (and uninitialised variables)
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100102set -eu
103
Gilles Peskine8f073122018-11-27 15:58:47 +0100104pre_check_environment () {
Gilles Peskinebdf3f522019-01-06 19:58:02 +0000105 if [ -d library -a -d include -a -d tests ]; then :; else
Gilles Peskine8f073122018-11-27 15:58:47 +0100106 echo "Must be run from mbed TLS root" >&2
107 exit 1
108 fi
109}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100110
Gilles Peskine8f073122018-11-27 15:58:47 +0100111pre_initialize_variables () {
112 CONFIG_H='include/mbedtls/config.h'
113 CONFIG_BAK="$CONFIG_H.bak"
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200114
Gilles Peskine8f073122018-11-27 15:58:47 +0100115 FORCE=0
116 KEEP_GOING=0
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100117
Jaeden Ameroc4cc2512019-01-30 15:35:44 +0000118 # Default commands, can be overridden by the environment
Gilles Peskine8f073122018-11-27 15:58:47 +0100119 : ${OUT_OF_SOURCE_DIR:=./mbedtls_out_of_source_build}
120 : ${ARMC5_BIN_DIR:=/usr/bin}
121 : ${ARMC6_BIN_DIR:=/usr/bin}
Andres AGdc192212016-08-31 17:33:13 +0100122
Gilles Peskine8f073122018-11-27 15:58:47 +0100123 # if MAKEFLAGS is not set add the -j option to speed up invocations of make
Gilles Peskine55ae1622019-01-06 20:15:26 +0000124 if [ -z "${MAKEFLAGS+set}" ]; then
Gilles Peskine8f073122018-11-27 15:58:47 +0100125 export MAKEFLAGS="-j"
126 fi
Gilles Peskine10726102019-01-06 20:50:38 +0000127
Jaeden Amerod48e9c72019-02-07 17:43:39 +0000128 # Include more verbose output for failing tests run by CMake
129 export CTEST_OUTPUT_ON_FAILURE=1
130
Gilles Peskine10726102019-01-06 20:50:38 +0000131 # Gather the list of available components. These are the functions
132 # defined in this script whose name starts with "component_".
133 # Parse the script with sed, because in sh there is no way to list
134 # defined functions.
135 ALL_COMPONENTS=$(sed -n 's/^ *component_\([0-9A-Z_a-z]*\) *().*/\1/p' <"$0")
136
137 # Exclude components that are not supported on this platform.
138 SUPPORTED_COMPONENTS=
139 for component in $ALL_COMPONENTS; do
140 case $(type "support_$component" 2>&1) in
141 *' function'*)
142 if ! support_$component; then continue; fi;;
143 esac
144 SUPPORTED_COMPONENTS="$SUPPORTED_COMPONENTS $component"
145 done
Gilles Peskine8f073122018-11-27 15:58:47 +0100146}
Andres AG38495a32016-07-12 16:54:33 +0100147
Gilles Peskinea49b00f2019-01-10 00:05:18 +0100148# Test whether the component $1 is included in the command line patterns.
149is_component_included()
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100150{
151 set -f
Gilles Peskine1bcb1c82019-01-06 22:11:25 +0000152 for pattern in $COMMAND_LINE_COMPONENTS; do
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100153 set +f
154 case ${1#component_} in $pattern) return 0;; esac
155 done
156 set +f
157 return 1
158}
159
Simon Butcher41eeccf2016-09-07 00:07:09 +0100160usage()
SimonB2e23c822016-04-16 21:54:39 +0100161{
Gilles Peskine709346a2017-12-10 23:43:39 +0100162 cat <<EOF
Gilles Peskine92525112018-11-27 18:15:35 +0100163Usage: $0 [OPTION]... [COMPONENT]...
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100164Run mbedtls release validation tests.
Gilles Peskine92525112018-11-27 18:15:35 +0100165By default, run all tests. With one or more COMPONENT, run only those.
Gilles Peskinea49b00f2019-01-10 00:05:18 +0100166COMPONENT can be the name of a component or a shell wildcard pattern.
167
168Examples:
169 $0 "check_*"
170 Run all sanity checks.
171 $0 --no-armcc --except test_memsan
172 Run everything except builds that require armcc and MemSan.
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100173
174Special options:
175 -h|--help Print this help and exit.
Gilles Peskine10726102019-01-06 20:50:38 +0000176 --list-all-components List all available test components and exit.
177 --list-components List components supported on this platform and exit.
Gilles Peskine709346a2017-12-10 23:43:39 +0100178
179General options:
180 -f|--force Force the tests to overwrite any modified files.
Gilles Peskine7c652162017-12-11 00:01:40 +0100181 -k|--keep-going Run all tests and report errors at the end.
Gilles Peskine709346a2017-12-10 23:43:39 +0100182 -m|--memory Additional optional memory tests.
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100183 --armcc Run ARM Compiler builds (on by default).
Gilles Peskinea49b00f2019-01-10 00:05:18 +0100184 --except Exclude the COMPONENTs listed on the command line,
185 instead of running only those.
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100186 --no-armcc Skip ARM Compiler builds.
Gilles Peskine38d81652018-03-21 08:40:26 +0100187 --no-force Refuse to overwrite modified files (default).
188 --no-keep-going Stop at the first error (default).
189 --no-memory No additional memory tests (default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100190 --out-of-source-dir=<path> Directory used for CMake out-of-source build tests.
Gilles Peskine38d81652018-03-21 08:40:26 +0100191 --random-seed Use a random seed value for randomized tests (default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100192 -r|--release-test Run this script in release mode. This fixes the seed value to 1.
193 -s|--seed Integer seed value to use for this test run.
194
195Tool path options:
196 --armc5-bin-dir=<ARMC5_bin_dir_path> ARM Compiler 5 bin directory.
197 --armc6-bin-dir=<ARMC6_bin_dir_path> ARM Compiler 6 bin directory.
Gilles Peskine709346a2017-12-10 23:43:39 +0100198EOF
SimonB2e23c822016-04-16 21:54:39 +0100199}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100200
201# remove built files as well as the cmake cache/config
202cleanup()
203{
Gilles Peskinea71d64c2018-03-21 12:16:57 +0100204 if [ -n "${MBEDTLS_ROOT_DIR+set}" ]; then
205 cd "$MBEDTLS_ROOT_DIR"
206 fi
207
Gilles Peskine7c652162017-12-11 00:01:40 +0100208 command make clean
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200209
Gilles Peskine31b07e22018-03-21 12:15:06 +0100210 # Remove CMake artefacts
Jaeden Amero2d0e00f2018-11-07 18:46:41 +0000211 find . -name .git -prune -o \
Gilles Peskine31b07e22018-03-21 12:15:06 +0100212 -iname CMakeFiles -exec rm -rf {} \+ -o \
213 \( -iname cmake_install.cmake -o \
214 -iname CTestTestfile.cmake -o \
215 -iname CMakeCache.txt \) -exec rm {} \+
216 # Recover files overwritten by in-tree CMake builds
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000217 rm -f include/Makefile include/mbedtls/Makefile programs/*/Makefile
Paul Bakkerfe0984d2014-06-13 00:13:45 +0200218 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile
219 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200220
221 if [ -f "$CONFIG_BAK" ]; then
222 mv "$CONFIG_BAK" "$CONFIG_H"
223 fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100224}
225
Gilles Peskine7c652162017-12-11 00:01:40 +0100226# Executed on exit. May be redefined depending on command line options.
227final_report () {
228 :
229}
230
231fatal_signal () {
232 cleanup
233 final_report $1
234 trap - $1
235 kill -$1 $$
236}
237
238trap 'fatal_signal HUP' HUP
239trap 'fatal_signal INT' INT
240trap 'fatal_signal TERM' TERM
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200241
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100242msg()
243{
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100244 if [ -n "${current_component:-}" ]; then
245 current_section="${current_component#component_}: $1"
246 else
247 current_section="$1"
248 fi
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100249 echo ""
250 echo "******************************************************************"
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100251 echo "* $current_section "
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000252 printf "* "; date
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100253 echo "******************************************************************"
254}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100255
Gilles Peskine8f073122018-11-27 15:58:47 +0100256armc6_build_test()
257{
258 FLAGS="$1"
Andres AGa5cd9732016-10-17 15:23:10 +0100259
Gilles Peskine8f073122018-11-27 15:58:47 +0100260 msg "build: ARM Compiler 6 ($FLAGS), make"
261 ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \
262 WARNING_CFLAGS='-xc -std=c99' make lib
263 make clean
264}
Andres AGa5cd9732016-10-17 15:23:10 +0100265
Andres AGd9eba4b2016-08-26 14:42:14 +0100266err_msg()
267{
268 echo "$1" >&2
269}
270
271check_tools()
272{
273 for TOOL in "$@"; do
Andres AG98393602017-01-31 17:04:45 +0000274 if ! `type "$TOOL" >/dev/null 2>&1`; then
Andres AGd9eba4b2016-08-26 14:42:14 +0100275 err_msg "$TOOL not found!"
276 exit 1
277 fi
278 done
279}
280
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400281check_headers_in_cpp () {
Peter Kolbus1bc1a4c2019-02-01 17:19:08 -0600282 ls include/mbedtls | grep "\.h$" >headers.txt
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400283 <programs/test/cpp_dummy_build.cpp sed -n 's/"$//; s!^#include "mbedtls/!!p' |
284 sort |
285 diff headers.txt -
286 rm headers.txt
287}
288
Gilles Peskine8f073122018-11-27 15:58:47 +0100289pre_parse_command_line () {
Gilles Peskine1bcb1c82019-01-06 22:11:25 +0000290 COMMAND_LINE_COMPONENTS=
Gilles Peskinea49b00f2019-01-10 00:05:18 +0100291 all_except=0
Gilles Peskinee26ab182019-01-06 22:23:42 +0000292 no_armcc=
Gilles Peskine1bcb1c82019-01-06 22:11:25 +0000293
Jaeden Amero9b90f2e2018-11-02 18:34:17 +0000294 # Note that legacy options are ignored instead of being omitted from this
295 # list of options, so invocations that worked with previous version of
296 # all.sh will still run and work properly.
Gilles Peskine8f073122018-11-27 15:58:47 +0100297 while [ $# -gt 0 ]; do
Gilles Peskine06b385f2019-01-09 22:28:21 +0100298 case "$1" in
Gilles Peskinee26ab182019-01-06 22:23:42 +0000299 --armcc) no_armcc=;;
Gilles Peskine06b385f2019-01-09 22:28:21 +0100300 --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
301 --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
Gilles Peskine1bcb1c82019-01-06 22:11:25 +0000302 --except) all_except=1;;
Gilles Peskine06b385f2019-01-09 22:28:21 +0100303 --force|-f) FORCE=1;;
Jaeden Amero9b90f2e2018-11-02 18:34:17 +0000304 --gnutls-cli) shift;;
305 --gnutls-legacy-cli) shift;;
306 --gnutls-legacy-serv) shift;;
307 --gnutls-serv) shift;;
Gilles Peskine06b385f2019-01-09 22:28:21 +0100308 --help|-h) usage; exit;;
309 --keep-going|-k) KEEP_GOING=1;;
Gilles Peskine10726102019-01-06 20:50:38 +0000310 --list-all-components) printf '%s\n' $ALL_COMPONENTS; exit;;
311 --list-components) printf '%s\n' $SUPPORTED_COMPONENTS; exit;;
Jaeden Amero9b90f2e2018-11-02 18:34:17 +0000312 --memory|-m) ;;
Gilles Peskinee26ab182019-01-06 22:23:42 +0000313 --no-armcc) no_armcc=1;;
Gilles Peskine06b385f2019-01-09 22:28:21 +0100314 --no-force) FORCE=0;;
315 --no-keep-going) KEEP_GOING=0;;
Jaeden Amero9b90f2e2018-11-02 18:34:17 +0000316 --no-memory) ;;
317 --openssl) shift;;
318 --openssl-legacy) shift;;
319 --openssl-next) shift;;
Gilles Peskine06b385f2019-01-09 22:28:21 +0100320 --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
Jaeden Amero9b90f2e2018-11-02 18:34:17 +0000321 --random-seed) ;;
322 --release-test|-r) ;;
323 --seed|-s) shift;;
Gilles Peskine06b385f2019-01-09 22:28:21 +0100324 -*)
325 echo >&2 "Unknown option: $1"
326 echo >&2 "Run $0 --help for usage."
327 exit 120
328 ;;
Gilles Peskine1bcb1c82019-01-06 22:11:25 +0000329 *) COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS $1";;
Gilles Peskine06b385f2019-01-09 22:28:21 +0100330 esac
331 shift
Gilles Peskine8f073122018-11-27 15:58:47 +0100332 done
Gilles Peskine1bcb1c82019-01-06 22:11:25 +0000333
Gilles Peskinea49b00f2019-01-10 00:05:18 +0100334 # With no list of components, run everything.
Gilles Peskine1bcb1c82019-01-06 22:11:25 +0000335 if [ -z "$COMMAND_LINE_COMPONENTS" ]; then
336 all_except=1
337 fi
338
Gilles Peskinee26ab182019-01-06 22:23:42 +0000339 # --no-armcc is a legacy option. The modern way is --except '*_armcc*'.
340 # Ignore it if components are listed explicitly on the command line.
Gilles Peskinea49b00f2019-01-10 00:05:18 +0100341 if [ -n "$no_armcc" ] && [ $all_except -eq 1 ]; then
Gilles Peskinee26ab182019-01-06 22:23:42 +0000342 COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS *_armcc*"
343 fi
344
Gilles Peskine1bcb1c82019-01-06 22:11:25 +0000345 # Build the list of components to run.
Gilles Peskinea49b00f2019-01-10 00:05:18 +0100346 RUN_COMPONENTS=
347 for component in $SUPPORTED_COMPONENTS; do
348 if is_component_included "$component"; [ $? -eq $all_except ]; then
349 RUN_COMPONENTS="$RUN_COMPONENTS $component"
350 fi
351 done
Gilles Peskine1bcb1c82019-01-06 22:11:25 +0000352
353 unset all_except
Gilles Peskinee26ab182019-01-06 22:23:42 +0000354 unset no_armcc
Gilles Peskine8f073122018-11-27 15:58:47 +0100355}
SimonB2e23c822016-04-16 21:54:39 +0100356
Gilles Peskine8f073122018-11-27 15:58:47 +0100357pre_check_git () {
358 if [ $FORCE -eq 1 ]; then
Gilles Peskined692e112019-01-09 23:17:35 +0100359 rm -rf "$OUT_OF_SOURCE_DIR"
Gilles Peskine8f073122018-11-27 15:58:47 +0100360 git checkout-index -f -q $CONFIG_H
361 cleanup
362 else
SimonB2e23c822016-04-16 21:54:39 +0100363
Gilles Peskine8f073122018-11-27 15:58:47 +0100364 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
365 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
366 echo "You can either delete this directory manually, or force the test by rerunning"
367 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
368 exit 1
369 fi
370
Gilles Peskineadd1d232019-01-09 22:30:01 +0100371 if ! git diff --quiet include/mbedtls/config.h; then
Gilles Peskine8f073122018-11-27 15:58:47 +0100372 err_msg "Warning - the configuration file 'include/mbedtls/config.h' has been edited. "
373 echo "You can either delete or preserve your work, or force the test by rerunning the"
374 echo "script as: $0 --force"
375 exit 1
376 fi
Andres AGdc192212016-08-31 17:33:13 +0100377 fi
Gilles Peskine8f073122018-11-27 15:58:47 +0100378}
Andres AGdc192212016-08-31 17:33:13 +0100379
Andrzej Kurekeb508712019-02-14 07:18:59 -0500380pre_check_seedfile () {
381 if [ ! -f "./tests/seedfile" ]; then
382 dd if=/dev/urandom of=./tests/seedfile bs=32 count=1
383 fi
384}
385
Gilles Peskine8f073122018-11-27 15:58:47 +0100386pre_setup_keep_going () {
Gilles Peskine7c652162017-12-11 00:01:40 +0100387 failure_summary=
388 failure_count=0
389 start_red=
390 end_color=
391 if [ -t 1 ]; then
Gilles Peskine9736b9d2018-01-02 21:54:17 +0100392 case "${TERM:-}" in
Gilles Peskine7c652162017-12-11 00:01:40 +0100393 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
394 start_red=$(printf '\033[31m')
395 end_color=$(printf '\033[0m')
396 ;;
397 esac
398 fi
399 record_status () {
400 if "$@"; then
401 last_status=0
402 else
403 last_status=$?
404 text="$current_section: $* -> $last_status"
405 failure_summary="$failure_summary
406$text"
407 failure_count=$((failure_count + 1))
408 echo "${start_red}^^^^$text^^^^${end_color}"
409 fi
410 }
411 make () {
412 case "$*" in
413 *test|*check)
414 if [ $build_status -eq 0 ]; then
415 record_status command make "$@"
416 else
417 echo "(skipped because the build failed)"
418 fi
419 ;;
420 *)
421 record_status command make "$@"
422 build_status=$last_status
423 ;;
424 esac
425 }
426 final_report () {
427 if [ $failure_count -gt 0 ]; then
428 echo
429 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
430 echo "${start_red}FAILED: $failure_count${end_color}$failure_summary"
431 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Jaeden Amero7c1258d2018-07-20 16:42:14 +0100432 exit 1
Gilles Peskine7c652162017-12-11 00:01:40 +0100433 elif [ -z "${1-}" ]; then
434 echo "SUCCESS :)"
435 fi
436 if [ -n "${1-}" ]; then
437 echo "Killed by SIG$1."
438 fi
439 }
Gilles Peskine8f073122018-11-27 15:58:47 +0100440}
441
Gilles Peskine7c652162017-12-11 00:01:40 +0100442if_build_succeeded () {
443 if [ $build_status -eq 0 ]; then
444 record_status "$@"
445 fi
446}
447
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200448# to be used instead of ! for commands run with
449# record_status or if_build_succeeded
450not() {
451 ! "$@"
452}
453
Gilles Peskine8f073122018-11-27 15:58:47 +0100454pre_print_configuration () {
455 msg "info: $0 configuration"
Gilles Peskine8f073122018-11-27 15:58:47 +0100456 echo "FORCE: $FORCE"
Gilles Peskine8f073122018-11-27 15:58:47 +0100457 echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
458 echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
459}
Andres AG87bb5772016-09-27 15:05:15 +0100460
Gilles Peskine657f59a2019-01-06 22:40:00 +0000461# Make sure the tools we need are available.
Gilles Peskine8f073122018-11-27 15:58:47 +0100462pre_check_tools () {
Gilles Peskine2edf47c2019-01-06 22:46:21 +0000463 # Build the list of variables to pass to output_env.sh.
464 set env
465
Gilles Peskine657f59a2019-01-06 22:40:00 +0000466 case " $RUN_COMPONENTS " in
Gilles Peskine657f59a2019-01-06 22:40:00 +0000467 *_doxygen[_\ ]*) check_tools "doxygen" "dot";;
468 esac
Andres AGb2fdd042016-09-22 14:17:46 +0100469
Gilles Peskine657f59a2019-01-06 22:40:00 +0000470 case " $RUN_COMPONENTS " in
471 *_arm_none_eabi_gcc[_\ ]*) check_tools "arm-none-eabi-gcc";;
472 esac
Andres AG7770ea82016-10-10 15:46:20 +0100473
Gilles Peskine657f59a2019-01-06 22:40:00 +0000474 case " $RUN_COMPONENTS " in
475 *_mingw[_\ ]*) check_tools "i686-w64-mingw32-gcc";;
476 esac
477
478 case " $RUN_COMPONENTS " in
479 *" test_zeroize "*) check_tools "gdb";;
480 esac
481
482 case " $RUN_COMPONENTS " in
Gilles Peskinee26ab182019-01-06 22:23:42 +0000483 *_armcc*)
Gilles Peskine657f59a2019-01-06 22:40:00 +0000484 ARMC5_CC="$ARMC5_BIN_DIR/armcc"
485 ARMC5_AR="$ARMC5_BIN_DIR/armar"
486 ARMC6_CC="$ARMC6_BIN_DIR/armclang"
487 ARMC6_AR="$ARMC6_BIN_DIR/armar"
Gilles Peskinee26ab182019-01-06 22:23:42 +0000488 check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC6_CC" "$ARMC6_AR";;
489 esac
Gilles Peskine2edf47c2019-01-06 22:46:21 +0000490
491 msg "info: output_env.sh"
492 case $RUN_COMPONENTS in
493 *_armcc*)
494 set "$@" ARMC5_CC="$ARMC5_CC" ARMC6_CC="$ARMC6_CC" RUN_ARMCC=1;;
495 *) set "$@" RUN_ARMCC=0;;
496 esac
497 "$@" scripts/output_env.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100498}
Gilles Peskine192c72f2017-12-21 15:59:21 +0100499
500
Gilles Peskine2edf47c2019-01-06 22:46:21 +0000501
Gilles Peskine192c72f2017-12-21 15:59:21 +0100502################################################################
503#### Basic checks
504################################################################
Andres AGd9eba4b2016-08-26 14:42:14 +0100505
SimonB2e23c822016-04-16 21:54:39 +0100506#
507# Test Suites to be executed
508#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200509# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100510# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard61bc57a2014-08-14 11:29:06 +0200511# and/or are more likely to fail than others (eg I use Clang most of the
512# time, so start with a GCC build).
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200513# 2. Minimize total running time, by avoiding useless rebuilds
514#
515# Indicative running times are given for reference.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100516
Gilles Peskine8f073122018-11-27 15:58:47 +0100517component_check_recursion () {
518 msg "test: recursion.pl" # < 1s
519 record_status tests/scripts/recursion.pl library/*.c
520}
Manuel Pégourié-Gonnardea29d152014-11-20 17:32:33 +0100521
Gilles Peskine8f073122018-11-27 15:58:47 +0100522component_check_generated_files () {
523 msg "test: freshness of generated source files" # < 1s
524 record_status tests/scripts/check-generated-files.sh
525}
Manuel Pégourié-Gonnardb3b8e432015-02-13 14:52:19 +0000526
Gilles Peskine8f073122018-11-27 15:58:47 +0100527component_check_doxy_blocks () {
528 msg "test: doxygen markup outside doxygen blocks" # < 1s
529 record_status tests/scripts/check-doxy-blocks.pl
530}
Manuel Pégourié-Gonnardd09a6b52015-04-09 17:19:23 +0200531
Gilles Peskine8f073122018-11-27 15:58:47 +0100532component_check_files () {
533 msg "test: check-files.py" # < 1s
Gilles Peskine8f073122018-11-27 15:58:47 +0100534 record_status tests/scripts/check-files.py
535}
Darryl Greena07039c2018-03-13 16:48:16 +0000536
Gilles Peskine8f073122018-11-27 15:58:47 +0100537component_check_names () {
538 msg "test/build: declared and exported names" # < 3s
Gilles Peskine8f073122018-11-27 15:58:47 +0100539 record_status tests/scripts/check-names.sh
540}
Manuel Pégourié-Gonnarda687baf2015-04-09 11:09:03 +0200541
Gilles Peskine8f073122018-11-27 15:58:47 +0100542component_check_doxygen_warnings () {
543 msg "test: doxygen warnings" # ~ 3s
Gilles Peskine8f073122018-11-27 15:58:47 +0100544 record_status tests/scripts/doxygen.sh
545}
Manuel Pégourié-Gonnard1d552e72016-01-04 16:49:09 +0100546
Gilles Peskine192c72f2017-12-21 15:59:21 +0100547
Gilles Peskine192c72f2017-12-21 15:59:21 +0100548################################################################
549#### Build and test many configurations and targets
550################################################################
551
Gilles Peskine8f073122018-11-27 15:58:47 +0100552component_test_default_cmake_gcc_asan () {
553 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100554 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
555 make
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100556
Gilles Peskine8f073122018-11-27 15:58:47 +0100557 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
558 make test
Gilles Peskine8f073122018-11-27 15:58:47 +0100559}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200560
Gilles Peskine782f4112018-11-27 16:11:09 +0100561component_test_ref_configs () {
562 msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
563 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
564 record_status tests/scripts/test-ref-configs.pl
565}
566
Gilles Peskine8f073122018-11-27 15:58:47 +0100567component_test_rsa_no_crt () {
568 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100569 scripts/config.pl set MBEDTLS_RSA_NO_CRT
570 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
571 make
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100572
Gilles Peskine8f073122018-11-27 15:58:47 +0100573 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
574 make test
Gilles Peskine8f073122018-11-27 15:58:47 +0100575}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100576
Gilles Peskine8f073122018-11-27 15:58:47 +0100577component_test_full_cmake_clang () {
578 msg "build: cmake, full config, clang" # ~ 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100579 scripts/config.pl full
580 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
581 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check -D ENABLE_TESTING=On .
582 make
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100583
Gilles Peskine8f073122018-11-27 15:58:47 +0100584 msg "test: main suites (full config)" # ~ 5s
585 make test
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200586
Darryl Green45010a32019-02-06 13:43:58 +0000587 msg "test: psa_constant_names (full config)" # ~ 1s
588 record_status tests/scripts/test_psa_constant_names.py
Gilles Peskine8f073122018-11-27 15:58:47 +0100589}
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100590
Gilles Peskine8f073122018-11-27 15:58:47 +0100591component_build_deprecated () {
592 msg "build: make, full config + DEPRECATED_WARNING, gcc -O" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100593 scripts/config.pl full
594 scripts/config.pl set MBEDTLS_DEPRECATED_WARNING
595 # Build with -O -Wextra to catch a maximum of issues.
596 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra' lib programs
597 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
Gilles Peskineb4ef45b2018-03-01 22:23:50 +0100598
Gilles Peskine8f073122018-11-27 15:58:47 +0100599 msg "build: make, full config + DEPRECATED_REMOVED, clang -O" # ~ 30s
600 # No cleanup, just tweak the configuration and rebuild
601 make clean
602 scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
603 scripts/config.pl set MBEDTLS_DEPRECATED_REMOVED
604 # Build with -O -Wextra to catch a maximum of issues.
605 make CC=clang CFLAGS='-O -Werror -Wall -Wextra' lib programs
606 make CC=clang CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
607}
Gilles Peskine0afe6242018-02-21 19:28:12 +0100608
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +0100609
Gilles Peskine8f073122018-11-27 15:58:47 +0100610component_test_depends_curves () {
611 msg "test/build: curves.pl (gcc)" # ~ 4 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100612 record_status tests/scripts/curves.pl
613}
Manuel Pégourié-Gonnard1fe6bb92017-06-06 11:36:16 +0200614
Gilles Peskine8f073122018-11-27 15:58:47 +0100615component_test_depends_hashes () {
616 msg "test/build: depends-hashes.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100617 record_status tests/scripts/depends-hashes.pl
618}
Manuel Pégourié-Gonnard43be6cd2017-06-20 09:53:42 +0200619
Gilles Peskine8f073122018-11-27 15:58:47 +0100620component_test_depends_pkalgs () {
621 msg "test/build: depends-pkalgs.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100622 record_status tests/scripts/depends-pkalgs.pl
623}
Manuel Pégourié-Gonnard503a5ef2015-10-23 09:04:45 +0200624
Gilles Peskine8f073122018-11-27 15:58:47 +0100625component_build_default_make_gcc_and_cxx () {
626 msg "build: Unix make, -Os (gcc)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100627 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400628
Gilles Peskine8f073122018-11-27 15:58:47 +0100629 msg "test: verify header list in cpp_dummy_build.cpp"
630 record_status check_headers_in_cpp
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400631
Gilles Peskine8f073122018-11-27 15:58:47 +0100632 msg "build: Unix make, incremental g++"
633 make TEST_CPP=1
634}
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +0000635
Andrzej Kurekfd0381a2019-02-05 05:00:02 -0500636component_test_use_psa_crypto_full_cmake_asan() {
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500637 # MBEDTLS_USE_PSA_CRYPTO: run the same set of tests as basic-build-test.sh
638 msg "build: cmake, full config + MBEDTLS_USE_PSA_CRYPTO, ASan"
639 scripts/config.pl full
640 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
Hanno Becker241b5242019-02-22 10:26:18 +0000641 scripts/config.pl unset MBEDTLS_ECP_RESTARTABLE # restartable ECC not supported through PSA
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500642 scripts/config.pl set MBEDTLS_PSA_CRYPTO_C
643 scripts/config.pl set MBEDTLS_USE_PSA_CRYPTO
Jaeden Amero67ea2c52019-02-11 12:05:54 +0000644 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500645 make
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100646
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500647 msg "test: main suites (MBEDTLS_USE_PSA_CRYPTO)"
648 make test
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500649}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500650
Gilles Peskineb28636b2019-01-02 19:06:24 +0100651component_test_check_params_without_platform () {
652 msg "build+test: MBEDTLS_CHECK_PARAMS without MBEDTLS_PLATFORM_C"
653 scripts/config.pl full # includes CHECK_PARAMS
654 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
655 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
656 scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
657 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
658 scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
659 scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
660 scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
661 scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
662 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
663 scripts/config.pl unset MBEDTLS_PLATFORM_C
664 make CC=gcc CFLAGS='-Werror -O1' all test
665}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500666
Gilles Peskineb28636b2019-01-02 19:06:24 +0100667component_test_check_params_silent () {
668 msg "build+test: MBEDTLS_CHECK_PARAMS with alternative MBEDTLS_PARAM_FAILED()"
669 scripts/config.pl full # includes CHECK_PARAMS
670 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
671 sed -i 's/.*\(#define MBEDTLS_PARAM_FAILED( cond )\).*/\1/' "$CONFIG_H"
672 make CC=gcc CFLAGS='-Werror -O1' all test
673}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500674
Gilles Peskine8f073122018-11-27 15:58:47 +0100675component_test_no_platform () {
676 # Full configuration build, without platform support, file IO and net sockets.
677 # This should catch missing mbedtls_printf definitions, and by disabling file
678 # IO, it should catch missing '#include <stdio.h>'
679 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100680 scripts/config.pl full
681 scripts/config.pl unset MBEDTLS_PLATFORM_C
682 scripts/config.pl unset MBEDTLS_NET_C
683 scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
684 scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
685 scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
686 scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
687 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
688 scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
689 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
690 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
691 scripts/config.pl unset MBEDTLS_FS_IO
Gilles Peskine51585382019-01-05 10:27:47 +0100692 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_C
Gilles Peskinee435f232019-02-24 14:03:29 +0100693 scripts/config.pl unset MBEDTLS_PSA_ITS_FILE_C
694 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_ITS_C
Gilles Peskine8f073122018-11-27 15:58:47 +0100695 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
696 # to re-enable platform integration features otherwise disabled in C99 builds
697 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -O0 -D_DEFAULT_SOURCE' lib programs
698 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0' test
699}
Manuel Pégourié-Gonnarddccb80b2015-06-03 10:20:33 +0100700
Gilles Peskine8f073122018-11-27 15:58:47 +0100701component_build_no_std_function () {
702 # catch compile bugs in _uninit functions
703 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100704 scripts/config.pl full
705 scripts/config.pl set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
706 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
707 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
708}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200709
Gilles Peskine8f073122018-11-27 15:58:47 +0100710component_test_null_entropy () {
711 msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100712 scripts/config.pl set MBEDTLS_TEST_NULL_ENTROPY
713 scripts/config.pl set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
714 scripts/config.pl set MBEDTLS_ENTROPY_C
715 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
716 scripts/config.pl unset MBEDTLS_ENTROPY_HARDWARE_ALT
717 scripts/config.pl unset MBEDTLS_HAVEGE_C
Gilles Peskine19275652019-01-06 19:48:30 +0000718 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan -D UNSAFE_BUILD=ON .
Gilles Peskine8f073122018-11-27 15:58:47 +0100719 make
Janos Follath06c54002016-06-09 13:57:40 +0100720
Gilles Peskine8f073122018-11-27 15:58:47 +0100721 msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)"
722 make test
723}
Hanno Beckere5fecec2018-10-11 11:02:52 +0100724
Gilles Peskine8f073122018-11-27 15:58:47 +0100725component_test_platform_calloc_macro () {
726 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100727 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
728 scripts/config.pl set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
729 scripts/config.pl set MBEDTLS_PLATFORM_FREE_MACRO free
730 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
731 make
Hanno Beckere5fecec2018-10-11 11:02:52 +0100732
Gilles Peskine8f073122018-11-27 15:58:47 +0100733 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
734 make test
735}
Hanno Becker83ebf782017-07-07 12:29:15 +0100736
Gilles Peskine8f073122018-11-27 15:58:47 +0100737component_test_aes_fewer_tables () {
738 msg "build: default config with AES_FEWER_TABLES enabled"
Gilles Peskine8f073122018-11-27 15:58:47 +0100739 scripts/config.pl set MBEDTLS_AES_FEWER_TABLES
740 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +0100741
Gilles Peskine8f073122018-11-27 15:58:47 +0100742 msg "test: AES_FEWER_TABLES"
743 make test
744}
Hanno Becker83ebf782017-07-07 12:29:15 +0100745
Gilles Peskine8f073122018-11-27 15:58:47 +0100746component_test_aes_rom_tables () {
747 msg "build: default config with AES_ROM_TABLES enabled"
Gilles Peskine8f073122018-11-27 15:58:47 +0100748 scripts/config.pl set MBEDTLS_AES_ROM_TABLES
749 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +0100750
Gilles Peskine8f073122018-11-27 15:58:47 +0100751 msg "test: AES_ROM_TABLES"
752 make test
753}
Hanno Becker83ebf782017-07-07 12:29:15 +0100754
Gilles Peskine8f073122018-11-27 15:58:47 +0100755component_test_aes_fewer_tables_and_rom_tables () {
756 msg "build: default config with AES_ROM_TABLES and AES_FEWER_TABLES enabled"
Gilles Peskine8f073122018-11-27 15:58:47 +0100757 scripts/config.pl set MBEDTLS_AES_FEWER_TABLES
758 scripts/config.pl set MBEDTLS_AES_ROM_TABLES
759 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +0100760
Gilles Peskine8f073122018-11-27 15:58:47 +0100761 msg "test: AES_FEWER_TABLES + AES_ROM_TABLES"
762 make test
763}
764
765component_test_make_shared () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100766 msg "build/test: make shared" # ~ 40s
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100767 make SHARED=1 all check
Gilles Peskine8f073122018-11-27 15:58:47 +0100768}
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +0200769
Gilles Peskine8f073122018-11-27 15:58:47 +0100770component_test_m32_o0 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100771 # Build once with -O0, to compile out the i386 specific inline assembly
772 msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
Simon Butcher7a6da6e2018-06-27 21:52:54 +0100773 scripts/config.pl full
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100774 make CC=gcc CFLAGS='-O0 -Werror -Wall -Wextra -m32 -fsanitize=address'
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +0100775
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100776 msg "test: i386, make, gcc -O0 (ASan build)"
777 make test
Gilles Peskine8f073122018-11-27 15:58:47 +0100778}
Gilles Peskine10726102019-01-06 20:50:38 +0000779support_test_m32_o0 () {
780 case $(uname -m) in
781 *64*) true;;
782 *) false;;
783 esac
784}
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100785
Gilles Peskine8f073122018-11-27 15:58:47 +0100786component_test_m32_o1 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100787 # Build again with -O1, to compile in the i386 specific inline assembly
788 msg "build: i386, make, gcc -O1 (ASan build)" # ~ 30s
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100789 scripts/config.pl full
790 make CC=gcc CFLAGS='-O1 -Werror -Wall -Wextra -m32 -fsanitize=address'
791
792 msg "test: i386, make, gcc -O1 (ASan build)"
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +0100793 make test
Gilles Peskine8f073122018-11-27 15:58:47 +0100794}
Gilles Peskine10726102019-01-06 20:50:38 +0000795support_test_m32_o1 () {
796 support_test_m32_o0 "$@"
797}
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +0100798
Gilles Peskine8f073122018-11-27 15:58:47 +0100799component_test_mx32 () {
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +0100800 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
Simon Butcher7a6da6e2018-06-27 21:52:54 +0100801 scripts/config.pl full
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +0100802 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32'
803
804 msg "test: 64-bit ILP32, make, gcc"
805 make test
Gilles Peskine8f073122018-11-27 15:58:47 +0100806}
Gilles Peskine10726102019-01-06 20:50:38 +0000807support_test_mx32 () {
808 case $(uname -m) in
809 amd64|x86_64) true;;
810 *) false;;
811 esac
812}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000813
Peter Kolbus60c6da22018-12-27 06:59:04 -0600814component_test_min_mpi_window_size () {
815 msg "build: Default + MBEDTLS_MPI_WINDOW_SIZE=1 (ASan build)" # ~ 10s
816 scripts/config.pl set MBEDTLS_MPI_WINDOW_SIZE 1
817 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
818 make
819
820 msg "test: MBEDTLS_MPI_WINDOW_SIZE=1 - main suites (inc. selftests) (ASan build)" # ~ 10s
821 make test
822}
823
Gilles Peskine8f073122018-11-27 15:58:47 +0100824component_test_have_int32 () {
825 msg "build: gcc, force 32-bit bignum limbs"
Gilles Peskine8f073122018-11-27 15:58:47 +0100826 scripts/config.pl unset MBEDTLS_HAVE_ASM
827 scripts/config.pl unset MBEDTLS_AESNI_C
828 scripts/config.pl unset MBEDTLS_PADLOCK_C
829 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +0100830
Gilles Peskine8f073122018-11-27 15:58:47 +0100831 msg "test: gcc, force 32-bit bignum limbs"
832 make test
833}
Andres Amaya Garciafe843a32017-07-20 13:21:34 +0100834
Gilles Peskine8f073122018-11-27 15:58:47 +0100835component_test_have_int64 () {
836 msg "build: gcc, force 64-bit bignum limbs"
Gilles Peskine8f073122018-11-27 15:58:47 +0100837 scripts/config.pl unset MBEDTLS_HAVE_ASM
838 scripts/config.pl unset MBEDTLS_AESNI_C
839 scripts/config.pl unset MBEDTLS_PADLOCK_C
840 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
Gilles Peskine14c3c062018-01-29 21:25:12 +0100841
Gilles Peskine8f073122018-11-27 15:58:47 +0100842 msg "test: gcc, force 64-bit bignum limbs"
843 make test
844}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000845
Gilles Peskine8f073122018-11-27 15:58:47 +0100846component_test_no_udbl_division () {
847 msg "build: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +0100848 scripts/config.pl full
849 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
850 scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
851 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200852
Gilles Peskine8f073122018-11-27 15:58:47 +0100853 msg "test: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
854 make test
855}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200856
Gilles Peskine8f073122018-11-27 15:58:47 +0100857component_test_no_64bit_multiplication () {
858 msg "build: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +0100859 scripts/config.pl full
860 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
861 scripts/config.pl set MBEDTLS_NO_64BIT_MULTIPLICATION
862 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200863
Gilles Peskine8f073122018-11-27 15:58:47 +0100864 msg "test: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
865 make test
866}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200867
Gilles Peskine8f073122018-11-27 15:58:47 +0100868component_build_arm_none_eabi_gcc () {
869 msg "build: arm-none-eabi-gcc, make" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +0100870 scripts/config.pl full
871 scripts/config.pl unset MBEDTLS_NET_C
872 scripts/config.pl unset MBEDTLS_TIMING_C
873 scripts/config.pl unset MBEDTLS_FS_IO
Gilles Peskinee435f232019-02-24 14:03:29 +0100874 scripts/config.pl unset MBEDTLS_PSA_ITS_FILE_C
875 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_ITS_C
Gilles Peskine51585382019-01-05 10:27:47 +0100876 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_C
Gilles Peskine8f073122018-11-27 15:58:47 +0100877 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
878 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
879 # following things are not in the default config
880 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
881 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
882 scripts/config.pl unset MBEDTLS_THREADING_C
883 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
884 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
885 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
886}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200887
Gilles Peskine8f073122018-11-27 15:58:47 +0100888component_build_arm_none_eabi_gcc_no_udbl_division () {
889 msg "build: arm-none-eabi-gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +0100890 scripts/config.pl full
891 scripts/config.pl unset MBEDTLS_NET_C
892 scripts/config.pl unset MBEDTLS_TIMING_C
893 scripts/config.pl unset MBEDTLS_FS_IO
Gilles Peskinee435f232019-02-24 14:03:29 +0100894 scripts/config.pl unset MBEDTLS_PSA_ITS_FILE_C
895 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_ITS_C
Gilles Peskine51585382019-01-05 10:27:47 +0100896 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_C
Gilles Peskine8f073122018-11-27 15:58:47 +0100897 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
898 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
899 # following things are not in the default config
900 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
901 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
902 scripts/config.pl unset MBEDTLS_THREADING_C
903 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
904 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
905 scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
906 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
907 echo "Checking that software 64-bit division is not required"
908 if_build_succeeded not grep __aeabi_uldiv library/*.o
909}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200910
Gilles Peskine8f073122018-11-27 15:58:47 +0100911component_build_arm_none_eabi_gcc_no_64bit_multiplication () {
912 msg "build: arm-none-eabi-gcc MBEDTLS_NO_64BIT_MULTIPLICATION, make" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +0100913 scripts/config.pl full
914 scripts/config.pl unset MBEDTLS_NET_C
915 scripts/config.pl unset MBEDTLS_TIMING_C
916 scripts/config.pl unset MBEDTLS_FS_IO
Gilles Peskinee435f232019-02-24 14:03:29 +0100917 scripts/config.pl unset MBEDTLS_PSA_ITS_FILE_C
918 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_ITS_C
Gilles Peskine51585382019-01-05 10:27:47 +0100919 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_C
Gilles Peskine8f073122018-11-27 15:58:47 +0100920 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
921 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
922 # following things are not in the default config
923 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
924 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
925 scripts/config.pl unset MBEDTLS_THREADING_C
926 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
927 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
928 scripts/config.pl set MBEDTLS_NO_64BIT_MULTIPLICATION
929 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -O1 -march=armv6-m -mthumb' lib
930 echo "Checking that software 64-bit multiplication is not required"
931 if_build_succeeded not grep __aeabi_lmul library/*.o
932}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200933
Gilles Peskine8f073122018-11-27 15:58:47 +0100934component_build_armcc () {
935 msg "build: ARM Compiler 5, make"
Gilles Peskine8f073122018-11-27 15:58:47 +0100936 scripts/config.pl full
937 scripts/config.pl unset MBEDTLS_NET_C
938 scripts/config.pl unset MBEDTLS_TIMING_C
939 scripts/config.pl unset MBEDTLS_FS_IO
Gilles Peskinee435f232019-02-24 14:03:29 +0100940 scripts/config.pl unset MBEDTLS_PSA_ITS_FILE_C
941 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_ITS_C
Gilles Peskine51585382019-01-05 10:27:47 +0100942 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_C
Gilles Peskine8f073122018-11-27 15:58:47 +0100943 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
944 scripts/config.pl unset MBEDTLS_HAVE_TIME
945 scripts/config.pl unset MBEDTLS_HAVE_TIME_DATE
946 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
947 # following things are not in the default config
948 scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
949 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
950 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
951 scripts/config.pl unset MBEDTLS_THREADING_C
952 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
953 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
954 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT # depends on MBEDTLS_HAVE_TIME
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000955
Gilles Peskinee26ab182019-01-06 22:23:42 +0000956 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
957 make clean
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200958
Gilles Peskinee26ab182019-01-06 22:23:42 +0000959 # ARM Compiler 6 - Target ARMv7-A
960 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-a"
Gilles Peskineed942f82017-06-08 15:19:20 +0200961
Gilles Peskinee26ab182019-01-06 22:23:42 +0000962 # ARM Compiler 6 - Target ARMv7-M
963 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m"
Andres AG87bb5772016-09-27 15:05:15 +0100964
Gilles Peskinee26ab182019-01-06 22:23:42 +0000965 # ARM Compiler 6 - Target ARMv8-A - AArch32
966 armc6_build_test "--target=arm-arm-none-eabi -march=armv8.2-a"
Andres AG87bb5772016-09-27 15:05:15 +0100967
Gilles Peskinee26ab182019-01-06 22:23:42 +0000968 # ARM Compiler 6 - Target ARMv8-M
969 armc6_build_test "--target=arm-arm-none-eabi -march=armv8-m.main"
Simon Butcher940737f2017-07-23 13:42:36 +0200970
Gilles Peskinee26ab182019-01-06 22:23:42 +0000971 # ARM Compiler 6 - Target ARMv8-A - AArch64
972 armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a"
Gilles Peskine8f073122018-11-27 15:58:47 +0100973}
Simon Butcher940737f2017-07-23 13:42:36 +0200974
Gilles Peskine8f073122018-11-27 15:58:47 +0100975component_build_mingw () {
976 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100977 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
Gilles Peskine2a458da2017-05-12 15:26:58 +0200978
Gilles Peskine8f073122018-11-27 15:58:47 +0100979 # note Make tests only builds the tests, but doesn't run them
980 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror' WINDOWS_BUILD=1 tests
981 make WINDOWS_BUILD=1 clean
Hanno Beckere963efa2018-01-03 10:03:43 +0000982
Gilles Peskine8f073122018-11-27 15:58:47 +0100983 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
984 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
985 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
986 make WINDOWS_BUILD=1 clean
987}
Simon Butcher002bc622016-11-17 09:27:45 +0000988
Gilles Peskine8f073122018-11-27 15:58:47 +0100989component_test_memsan () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100990 msg "build: MSan (clang)" # ~ 1 min 20s
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100991 scripts/config.pl unset MBEDTLS_AESNI_C # memsan doesn't grok asm
992 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
993 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +0200994
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100995 msg "test: main suites (MSan)" # ~ 10s
996 make test
Gilles Peskine8f073122018-11-27 15:58:47 +0100997}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100998
Gilles Peskinee8789872019-01-10 00:11:42 +0100999component_test_valgrind () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001000 msg "build: Release (clang)"
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001001 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
1002 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001003
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001004 msg "test: main suites valgrind (Release)"
1005 make memcheck
Gilles Peskine8f073122018-11-27 15:58:47 +01001006}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001007
Gilles Peskine8f073122018-11-27 15:58:47 +01001008component_test_cmake_out_of_source () {
1009 msg "build: cmake 'out-of-source' build"
Gilles Peskine8f073122018-11-27 15:58:47 +01001010 MBEDTLS_ROOT_DIR="$PWD"
1011 mkdir "$OUT_OF_SOURCE_DIR"
1012 cd "$OUT_OF_SOURCE_DIR"
1013 cmake "$MBEDTLS_ROOT_DIR"
1014 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001015
Gilles Peskine8f073122018-11-27 15:58:47 +01001016 msg "test: cmake 'out-of-source' build"
1017 make test
Jaeden Amero9b90f2e2018-11-02 18:34:17 +00001018
Gilles Peskine8f073122018-11-27 15:58:47 +01001019 cd "$MBEDTLS_ROOT_DIR"
1020 rm -rf "$OUT_OF_SOURCE_DIR"
1021 unset MBEDTLS_ROOT_DIR
1022}
Andres AGdc192212016-08-31 17:33:13 +01001023
Gilles Peskine8f073122018-11-27 15:58:47 +01001024component_test_zeroize () {
1025 # Test that the function mbedtls_platform_zeroize() is not optimized away by
1026 # different combinations of compilers and optimization flags by using an
1027 # auxiliary GDB script. Unfortunately, GDB does not return error values to the
1028 # system in all cases that the script fails, so we must manually search the
1029 # output to check whether the pass string is present and no failure strings
1030 # were printed.
Gilles Peskine74851d82019-01-06 19:52:22 +00001031
1032 # Don't try to disable ASLR. We don't care about ASLR here. We do care
1033 # about a spurious message if Gdb tries and fails, so suppress that.
1034 gdb_disable_aslr=
1035 if [ -z "$(gdb -batch -nw -ex 'set disable-randomization off' 2>&1)" ]; then
1036 gdb_disable_aslr='set disable-randomization off'
1037 fi
1038
Gilles Peskine8f073122018-11-27 15:58:47 +01001039 for optimization_flag in -O2 -O3 -Ofast -Os; do
Gilles Peskine06b385f2019-01-09 22:28:21 +01001040 for compiler in clang gcc; do
1041 msg "test: $compiler $optimization_flag, mbedtls_platform_zeroize()"
1042 make programs CC="$compiler" DEBUG=1 CFLAGS="$optimization_flag"
Gilles Peskine74851d82019-01-06 19:52:22 +00001043 if_build_succeeded gdb -ex "$gdb_disable_aslr" -x tests/scripts/test_zeroize.gdb -nw -batch -nx 2>&1 | tee test_zeroize.log
Gilles Peskine06b385f2019-01-09 22:28:21 +01001044 if_build_succeeded grep "The buffer was correctly zeroized" test_zeroize.log
1045 if_build_succeeded not grep -i "error" test_zeroize.log
1046 rm -f test_zeroize.log
1047 make clean
1048 done
Andres Amaya Garcia29673812017-10-25 10:35:51 +01001049 done
Gilles Peskine74851d82019-01-06 19:52:22 +00001050
1051 unset gdb_disable_aslr
Gilles Peskine8f073122018-11-27 15:58:47 +01001052}
Andres Amaya Garciad0d7bf62017-10-25 09:01:31 +01001053
Gilles Peskine8f073122018-11-27 15:58:47 +01001054component_check_python_files () {
1055 msg "Lint: Python scripts"
1056 record_status tests/scripts/check-python-files.sh
1057}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001058
Gilles Peskine8f073122018-11-27 15:58:47 +01001059component_check_generate_test_code () {
1060 msg "uint test: generate_test_code.py"
1061 record_status ./tests/scripts/test_generate_test_code.py
1062}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001063
1064################################################################
1065#### Termination
1066################################################################
1067
Gilles Peskine8f073122018-11-27 15:58:47 +01001068post_report () {
1069 msg "Done, cleaning up"
1070 cleanup
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001071
Gilles Peskine8f073122018-11-27 15:58:47 +01001072 final_report
1073}
1074
1075
1076
1077################################################################
1078#### Run all the things
1079################################################################
1080
Gilles Peskinee48351a2018-11-27 16:06:30 +01001081# Run one component and clean up afterwards.
Gilles Peskine8f073122018-11-27 15:58:47 +01001082run_component () {
Gilles Peskine8ae15dd2019-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 Peskineffcdeff2018-12-04 12:49:28 +01001086 current_component="$1"
Gilles Peskine8f073122018-11-27 15:58:47 +01001087 "$@"
Gilles Peskinee48351a2018-11-27 16:06:30 +01001088 cleanup
Gilles Peskine8f073122018-11-27 15:58:47 +01001089}
1090
1091# Preliminary setup
1092pre_check_environment
1093pre_initialize_variables
1094pre_parse_command_line "$@"
Gilles Peskine348fb9a2018-11-27 17:04:29 +01001095
Gilles Peskine10726102019-01-06 20:50:38 +00001096pre_check_git
Andrzej Kurekeb508712019-02-14 07:18:59 -05001097pre_check_seedfile
1098
Gilles Peskine10726102019-01-06 20:50:38 +00001099build_status=0
1100if [ $KEEP_GOING -eq 1 ]; then
1101 pre_setup_keep_going
1102else
1103 record_status () {
1104 "$@"
1105 }
1106fi
1107pre_print_configuration
1108pre_check_tools
Gilles Peskine10726102019-01-06 20:50:38 +00001109cleanup
Gilles Peskine8f073122018-11-27 15:58:47 +01001110
Gilles Peskine1bcb1c82019-01-06 22:11:25 +00001111# Run the requested tests.
1112for component in $RUN_COMPONENTS; do
1113 run_component "component_$component"
1114done
Gilles Peskine8f073122018-11-27 15:58:47 +01001115
1116# We're done.
Gilles Peskine10726102019-01-06 20:50:38 +00001117post_report