blob: 22611b9019d1818e2b1b75f632fa358acd1c101b [file] [log] [blame]
Andres AG31f9b5b2016-10-04 17:14:38 +01001#! /usr/bin/env sh
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01002
Simon Butcher3ea7f522016-03-07 23:22:10 +00003# all.sh
4#
SimonB2e23c822016-04-16 21:54:39 +01005# This file is part of mbed TLS (https://tls.mbed.org)
6#
Gilles Peskine192c72f2017-12-21 15:59:21 +01007# Copyright (c) 2014-2017, ARM Limited, All Rights Reserved
8
9
10
11################################################################
12#### Documentation
13################################################################
14
Simon Butcher3ea7f522016-03-07 23:22:10 +000015# Purpose
Gilles Peskine192c72f2017-12-21 15:59:21 +010016# -------
Simon Butcher3ea7f522016-03-07 23:22:10 +000017#
SimonB2e23c822016-04-16 21:54:39 +010018# To run all tests possible or available on the platform.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010019#
Gilles Peskine192c72f2017-12-21 15:59:21 +010020# Notes for users
21# ---------------
22#
SimonB2e23c822016-04-16 21:54:39 +010023# Warning: the test is destructive. It includes various build modes and
24# configurations, and can and will arbitrarily change the current CMake
Gilles Peskine192c72f2017-12-21 15:59:21 +010025# configuration. The following files must be committed into git:
26# * include/mbedtls/config.h
27# * Makefile, library/Makefile, programs/Makefile, tests/Makefile
28# After running this script, the CMake cache will be lost and CMake
29# will no longer be initialised.
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +010030#
Gilles Peskine192c72f2017-12-21 15:59:21 +010031# The script assumes the presence of a number of tools:
32# * Basic Unix tools (Windows users note: a Unix-style find must be before
33# the Windows find in the PATH)
34# * Perl
35# * GNU Make
36# * CMake
37# * GCC and Clang (recent enough for using ASan with gcc and MemSan with clang, or valgrind)
Andrzej Kurek05be06c2018-06-28 04:41:50 -040038# * G++
Gilles Peskine192c72f2017-12-21 15:59:21 +010039# * arm-gcc and mingw-gcc
40# * ArmCC 5 and ArmCC 6, unless invoked with --no-armcc
Gilles Peskine192c72f2017-12-21 15:59:21 +010041# * OpenSSL and GnuTLS command line tools, recent enough for the
42# interoperability tests. If they don't support SSLv3 then a legacy
43# version of these tools must be present as well (search for LEGACY
44# below).
45# See the invocation of check_tools below for details.
46#
47# This script must be invoked from the toplevel directory of a git
48# working copy of Mbed TLS.
49#
50# Note that the output is not saved. You may want to run
51# script -c tests/scripts/all.sh
52# or
53# tests/scripts/all.sh >all.log 2>&1
54#
55# Notes for maintainers
56# ---------------------
57#
Gilles Peskine8f073122018-11-27 15:58:47 +010058# The bulk of the code is organized into functions that follow one of the
59# following naming conventions:
60# * pre_XXX: things to do before running the tests, in order.
61# * component_XXX: independent components. They can be run in any order.
Gilles Peskinec70637a2019-01-09 22:29:17 +010062# * component_check_XXX: quick tests that aren't worth parallelizing.
63# * component_build_XXX: build things but don't run them.
64# * component_test_XXX: build and test.
Gilles Peskine878cf602019-01-06 20:50:38 +000065# * support_XXX: if support_XXX exists and returns false then
66# component_XXX is not run by default.
Gilles Peskine8f073122018-11-27 15:58:47 +010067# * post_XXX: things to do after running the tests.
68# * other: miscellaneous support functions.
69#
Gilles Peskinec70637a2019-01-09 22:29:17 +010070# Each component must start by invoking `msg` with a short informative message.
71#
72# The framework performs some cleanup tasks after each component. This
73# means that components can assume that the working directory is in a
74# cleaned-up state, and don't need to perform the cleanup themselves.
75# * Run `make clean`.
76# * Restore `include/mbedtks/config.h` from a backup made before running
77# the component.
78# * Check out `Makefile`, `library/Makefile`, `programs/Makefile` and
79# `tests/Makefile` from git. This cleans up after an in-tree use of
80# CMake.
81#
82# Any command that is expected to fail must be protected so that the
83# script keeps running in --keep-going mode despite `set -e`. In keep-going
84# mode, if a protected command fails, this is logged as a failure and the
85# script will exit with a failure status once it has run all components.
86# Commands can be protected in any of the following ways:
87# * `make` is a function which runs the `make` command with protection.
88# Note that you must write `make VAR=value`, not `VAR=value make`,
89# because the `VAR=value make` syntax doesn't work with functions.
90# * Put `report_status` before the command to protect it.
91# * Put `if_build_successful` before a command. This protects it, and
92# additionally skips it if a prior invocation of `make` in the same
93# component failed.
94#
Gilles Peskine192c72f2017-12-21 15:59:21 +010095# The tests are roughly in order from fastest to slowest. This doesn't
96# have to be exact, but in general you should add slower tests towards
97# the end and fast checks near the beginning.
Gilles Peskine192c72f2017-12-21 15:59:21 +010098
99
100
101################################################################
102#### Initialization and command line parsing
103################################################################
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100104
SimonB2e23c822016-04-16 21:54:39 +0100105# Abort on errors (and uninitialised variables)
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100106set -eu
107
Gilles Peskine8f073122018-11-27 15:58:47 +0100108pre_check_environment () {
Gilles Peskinea16c2b12019-01-06 19:58:02 +0000109 if [ -d library -a -d include -a -d tests ]; then :; else
Gilles Peskine8f073122018-11-27 15:58:47 +0100110 echo "Must be run from mbed TLS root" >&2
111 exit 1
112 fi
113}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100114
Gilles Peskine8f073122018-11-27 15:58:47 +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 Peskine8f073122018-11-27 15:58:47 +0100119 MEMORY=0
120 FORCE=0
121 KEEP_GOING=0
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100122
Jaeden Ameroc4cc2512019-01-30 15:35:44 +0000123 # Default commands, can be overridden by the environment
Gilles Peskine8f073122018-11-27 15:58:47 +0100124 : ${OPENSSL:="openssl"}
125 : ${OPENSSL_LEGACY:="$OPENSSL"}
126 : ${OPENSSL_NEXT:="$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 Peskine8f073122018-11-27 15:58:47 +0100135 # if MAKEFLAGS is not set add the -j option to speed up invocations of make
Gilles Peskinea1fc4b52019-01-06 20:15:26 +0000136 if [ -z "${MAKEFLAGS+set}" ]; then
Gilles Peskine8f073122018-11-27 15:58:47 +0100137 export MAKEFLAGS="-j"
138 fi
Gilles Peskine878cf602019-01-06 20:50:38 +0000139
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")
145
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 Peskine8f073122018-11-27 15:58:47 +0100155}
Andres AG38495a32016-07-12 16:54:33 +0100156
Gilles Peskinea28db922019-01-10 00:05:18 +0100157# Test whether the component $1 is included in the command line patterns.
158is_component_included()
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100159{
160 set -f
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000161 for pattern in $COMMAND_LINE_COMPONENTS; do
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100162 set +f
163 case ${1#component_} in $pattern) return 0;; esac
164 done
165 set +f
166 return 1
167}
Andres AG7770ea82016-10-10 15:46:20 +0100168
Simon Butcher41eeccf2016-09-07 00:07:09 +0100169usage()
Andres AGd9eba4b2016-08-26 14:42:14 +0100170{
Gilles Peskine709346a2017-12-10 23:43:39 +0100171 cat <<EOF
Gilles Peskine92525112018-11-27 18:15:35 +0100172Usage: $0 [OPTION]... [COMPONENT]...
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100173Run mbedtls release validation tests.
Gilles Peskine92525112018-11-27 18:15:35 +0100174By default, run all tests. With one or more COMPONENT, run only those.
Gilles Peskinea28db922019-01-10 00:05:18 +0100175COMPONENT can be the name of a component or a shell wildcard pattern.
176
177Examples:
178 $0 "check_*"
179 Run all sanity checks.
180 $0 --no-armcc --except test_memsan
181 Run everything except builds that require armcc and MemSan.
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100182
183Special options:
184 -h|--help Print this help and exit.
Gilles Peskine878cf602019-01-06 20:50:38 +0000185 --list-all-components List all available test components and exit.
186 --list-components List components supported on this platform and exit.
Gilles Peskine709346a2017-12-10 23:43:39 +0100187
188General options:
189 -f|--force Force the tests to overwrite any modified files.
Gilles Peskine7c652162017-12-11 00:01:40 +0100190 -k|--keep-going Run all tests and report errors at the end.
Gilles Peskine709346a2017-12-10 23:43:39 +0100191 -m|--memory Additional optional memory tests.
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100192 --armcc Run ARM Compiler builds (on by default).
Gilles Peskinea28db922019-01-10 00:05:18 +0100193 --except Exclude the COMPONENTs listed on the command line,
194 instead of running only those.
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100195 --no-armcc Skip ARM Compiler builds.
Gilles Peskine38d81652018-03-21 08:40:26 +0100196 --no-force Refuse to overwrite modified files (default).
197 --no-keep-going Stop at the first error (default).
198 --no-memory No additional memory tests (default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100199 --out-of-source-dir=<path> Directory used for CMake out-of-source build tests.
Gilles Peskine38d81652018-03-21 08:40:26 +0100200 --random-seed Use a random seed value for randomized tests (default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100201 -r|--release-test Run this script in release mode. This fixes the seed value to 1.
202 -s|--seed Integer seed value to use for this test run.
203
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.
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100213 --openssl-next=<OpenSSL_path> OpenSSL executable to use for recent things like ARIA
Gilles Peskine709346a2017-12-10 23:43:39 +0100214EOF
SimonB2e23c822016-04-16 21:54:39 +0100215}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100216
217# remove built files as well as the cmake cache/config
218cleanup()
219{
Gilles Peskinea71d64c2018-03-21 12:16:57 +0100220 if [ -n "${MBEDTLS_ROOT_DIR+set}" ]; then
221 cd "$MBEDTLS_ROOT_DIR"
222 fi
223
Gilles Peskine7c652162017-12-11 00:01:40 +0100224 command make clean
Jaeden Ameroed93bdc2018-11-02 16:57:24 +0000225 cd crypto
226 command make clean
227 cd ..
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200228
Gilles Peskine31b07e22018-03-21 12:15:06 +0100229 # Remove CMake artefacts
Jaeden Amero2d0e00f2018-11-07 18:46:41 +0000230 find . -name .git -prune -o \
Gilles Peskine31b07e22018-03-21 12:15:06 +0100231 -iname CMakeFiles -exec rm -rf {} \+ -o \
232 \( -iname cmake_install.cmake -o \
233 -iname CTestTestfile.cmake -o \
234 -iname CMakeCache.txt \) -exec rm {} \+
235 # Recover files overwritten by in-tree CMake builds
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000236 rm -f include/Makefile include/mbedtls/Makefile programs/*/Makefile
Paul Bakkerfe0984d2014-06-13 00:13:45 +0200237 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile
238 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile
Jaeden Ameroed93bdc2018-11-02 16:57:24 +0000239 cd crypto
240 rm -f include/Makefile include/mbedtls/Makefile programs/*/Makefile
241 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile
242 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile
243 cd ..
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200244
245 if [ -f "$CONFIG_BAK" ]; then
246 mv "$CONFIG_BAK" "$CONFIG_H"
247 fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100248}
249
Gilles Peskine7c652162017-12-11 00:01:40 +0100250# Executed on exit. May be redefined depending on command line options.
251final_report () {
252 :
253}
254
255fatal_signal () {
256 cleanup
257 final_report $1
258 trap - $1
259 kill -$1 $$
260}
261
262trap 'fatal_signal HUP' HUP
263trap 'fatal_signal INT' INT
264trap 'fatal_signal TERM' TERM
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200265
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100266msg()
267{
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100268 if [ -n "${current_component:-}" ]; then
269 current_section="${current_component#component_}: $1"
270 else
271 current_section="$1"
272 fi
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100273 echo ""
274 echo "******************************************************************"
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100275 echo "* $current_section "
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000276 printf "* "; date
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100277 echo "******************************************************************"
278}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100279
Gilles Peskine8f073122018-11-27 15:58:47 +0100280armc6_build_test()
281{
282 FLAGS="$1"
Andres AGa5cd9732016-10-17 15:23:10 +0100283
Gilles Peskine8f073122018-11-27 15:58:47 +0100284 msg "build: ARM Compiler 6 ($FLAGS), make"
285 ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \
286 WARNING_CFLAGS='-xc -std=c99' make lib
287 make clean
288}
Andres AGa5cd9732016-10-17 15:23:10 +0100289
Andres AGd9eba4b2016-08-26 14:42:14 +0100290err_msg()
291{
292 echo "$1" >&2
293}
294
295check_tools()
296{
297 for TOOL in "$@"; do
Andres AG98393602017-01-31 17:04:45 +0000298 if ! `type "$TOOL" >/dev/null 2>&1`; then
Andres AGd9eba4b2016-08-26 14:42:14 +0100299 err_msg "$TOOL not found!"
300 exit 1
301 fi
302 done
303}
304
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400305check_headers_in_cpp () {
306 ls include/mbedtls >headers.txt
307 <programs/test/cpp_dummy_build.cpp sed -n 's/"$//; s!^#include "mbedtls/!!p' |
308 sort |
309 diff headers.txt -
310 rm headers.txt
311}
312
Gilles Peskine8f073122018-11-27 15:58:47 +0100313pre_parse_command_line () {
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000314 COMMAND_LINE_COMPONENTS=
Gilles Peskinea28db922019-01-10 00:05:18 +0100315 all_except=0
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000316 no_armcc=
SimonB2e23c822016-04-16 21:54:39 +0100317
Gilles Peskine8f073122018-11-27 15:58:47 +0100318 while [ $# -gt 0 ]; do
Gilles Peskine55f7c942019-01-09 22:28:21 +0100319 case "$1" in
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000320 --armcc) no_armcc=;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100321 --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
322 --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000323 --except) all_except=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100324 --force|-f) FORCE=1;;
325 --gnutls-cli) shift; GNUTLS_CLI="$1";;
326 --gnutls-legacy-cli) shift; GNUTLS_LEGACY_CLI="$1";;
327 --gnutls-legacy-serv) shift; GNUTLS_LEGACY_SERV="$1";;
328 --gnutls-serv) shift; GNUTLS_SERV="$1";;
329 --help|-h) usage; exit;;
330 --keep-going|-k) KEEP_GOING=1;;
Gilles Peskine878cf602019-01-06 20:50:38 +0000331 --list-all-components) printf '%s\n' $ALL_COMPONENTS; exit;;
332 --list-components) printf '%s\n' $SUPPORTED_COMPONENTS; exit;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100333 --memory|-m) MEMORY=1;;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000334 --no-armcc) no_armcc=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100335 --no-force) FORCE=0;;
336 --no-keep-going) KEEP_GOING=0;;
337 --no-memory) MEMORY=0;;
338 --openssl) shift; OPENSSL="$1";;
339 --openssl-legacy) shift; OPENSSL_LEGACY="$1";;
340 --openssl-next) shift; OPENSSL_NEXT="$1";;
341 --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
342 --random-seed) unset SEED;;
343 --release-test|-r) SEED=1;;
344 --seed|-s) shift; SEED="$1";;
345 -*)
346 echo >&2 "Unknown option: $1"
347 echo >&2 "Run $0 --help for usage."
348 exit 120
349 ;;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000350 *) COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS $1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100351 esac
352 shift
Gilles Peskine8f073122018-11-27 15:58:47 +0100353 done
SimonB2e23c822016-04-16 21:54:39 +0100354
Gilles Peskinea28db922019-01-10 00:05:18 +0100355 # With no list of components, run everything.
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000356 if [ -z "$COMMAND_LINE_COMPONENTS" ]; then
357 all_except=1
Andres AGdc192212016-08-31 17:33:13 +0100358 fi
359
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000360 # --no-armcc is a legacy option. The modern way is --except '*_armcc*'.
361 # Ignore it if components are listed explicitly on the command line.
Gilles Peskinea28db922019-01-10 00:05:18 +0100362 if [ -n "$no_armcc" ] && [ $all_except -eq 1 ]; then
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000363 COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS *_armcc*"
SimonB2e23c822016-04-16 21:54:39 +0100364 fi
SimonB2e23c822016-04-16 21:54:39 +0100365
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000366 # Build the list of components to run.
Gilles Peskinea28db922019-01-10 00:05:18 +0100367 RUN_COMPONENTS=
368 for component in $SUPPORTED_COMPONENTS; do
369 if is_component_included "$component"; [ $? -eq $all_except ]; then
370 RUN_COMPONENTS="$RUN_COMPONENTS $component"
371 fi
372 done
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000373
374 unset all_except
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000375 unset no_armcc
Gilles Peskine8f073122018-11-27 15:58:47 +0100376}
SimonB2e23c822016-04-16 21:54:39 +0100377
Gilles Peskine8f073122018-11-27 15:58:47 +0100378pre_check_git () {
379 if [ $FORCE -eq 1 ]; then
Gilles Peskine53190e62019-01-09 23:17:35 +0100380 rm -rf "$OUT_OF_SOURCE_DIR"
Gilles Peskine8f073122018-11-27 15:58:47 +0100381 git checkout-index -f -q $CONFIG_H
382 cleanup
383 else
SimonB2e23c822016-04-16 21:54:39 +0100384
Gilles Peskine8f073122018-11-27 15:58:47 +0100385 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
386 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
387 echo "You can either delete this directory manually, or force the test by rerunning"
388 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
389 exit 1
390 fi
391
Gilles Peskined1174cf2019-01-09 22:30:01 +0100392 if ! git diff --quiet include/mbedtls/config.h; then
Gilles Peskine8f073122018-11-27 15:58:47 +0100393 err_msg "Warning - the configuration file 'include/mbedtls/config.h' has been edited. "
394 echo "You can either delete or preserve your work, or force the test by rerunning the"
395 echo "script as: $0 --force"
396 exit 1
397 fi
SimonB2e23c822016-04-16 21:54:39 +0100398 fi
Andrzej Kureke9c3b812019-02-05 05:34:21 -0500399 if ! [ -f crypto/Makefile ]; then
400 echo "Please initialize the crypto submodule" >&2
401 exit 1
402 fi
Gilles Peskine8f073122018-11-27 15:58:47 +0100403}
SimonB2e23c822016-04-16 21:54:39 +0100404
Gilles Peskine8f073122018-11-27 15:58:47 +0100405pre_setup_keep_going () {
Gilles Peskine7c652162017-12-11 00:01:40 +0100406 failure_summary=
407 failure_count=0
408 start_red=
409 end_color=
410 if [ -t 1 ]; then
Gilles Peskine9736b9d2018-01-02 21:54:17 +0100411 case "${TERM:-}" in
Gilles Peskine7c652162017-12-11 00:01:40 +0100412 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
413 start_red=$(printf '\033[31m')
414 end_color=$(printf '\033[0m')
415 ;;
416 esac
417 fi
418 record_status () {
419 if "$@"; then
420 last_status=0
421 else
422 last_status=$?
423 text="$current_section: $* -> $last_status"
424 failure_summary="$failure_summary
425$text"
426 failure_count=$((failure_count + 1))
427 echo "${start_red}^^^^$text^^^^${end_color}"
428 fi
429 }
430 make () {
431 case "$*" in
432 *test|*check)
433 if [ $build_status -eq 0 ]; then
434 record_status command make "$@"
435 else
436 echo "(skipped because the build failed)"
437 fi
438 ;;
439 *)
440 record_status command make "$@"
441 build_status=$last_status
442 ;;
443 esac
444 }
445 final_report () {
446 if [ $failure_count -gt 0 ]; then
447 echo
448 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
449 echo "${start_red}FAILED: $failure_count${end_color}$failure_summary"
450 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Jaeden Amero7c1258d2018-07-20 16:42:14 +0100451 exit 1
Gilles Peskine7c652162017-12-11 00:01:40 +0100452 elif [ -z "${1-}" ]; then
453 echo "SUCCESS :)"
454 fi
455 if [ -n "${1-}" ]; then
456 echo "Killed by SIG$1."
457 fi
458 }
Gilles Peskine8f073122018-11-27 15:58:47 +0100459}
460
Gilles Peskine7c652162017-12-11 00:01:40 +0100461if_build_succeeded () {
462 if [ $build_status -eq 0 ]; then
463 record_status "$@"
464 fi
465}
466
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200467# to be used instead of ! for commands run with
468# record_status or if_build_succeeded
469not() {
470 ! "$@"
471}
472
Gilles Peskine8f073122018-11-27 15:58:47 +0100473pre_print_configuration () {
474 msg "info: $0 configuration"
475 echo "MEMORY: $MEMORY"
476 echo "FORCE: $FORCE"
477 echo "SEED: ${SEED-"UNSET"}"
478 echo "OPENSSL: $OPENSSL"
479 echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
480 echo "OPENSSL_NEXT: $OPENSSL_NEXT"
481 echo "GNUTLS_CLI: $GNUTLS_CLI"
482 echo "GNUTLS_SERV: $GNUTLS_SERV"
483 echo "GNUTLS_LEGACY_CLI: $GNUTLS_LEGACY_CLI"
484 echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV"
485 echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
486 echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
487}
Andres AG7770ea82016-10-10 15:46:20 +0100488
Andres AGd9eba4b2016-08-26 14:42:14 +0100489# Make sure the tools we need are available.
Gilles Peskine8f073122018-11-27 15:58:47 +0100490pre_check_tools () {
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000491 # Build the list of variables to pass to output_env.sh.
492 set env
SimonB2e23c822016-04-16 21:54:39 +0100493
Gilles Peskine87964262019-01-06 22:40:00 +0000494 case " $RUN_COMPONENTS " in
495 # Require OpenSSL and GnuTLS if running any tests (as opposed to
496 # only doing builds). Not all tests run OpenSSL and GnuTLS, but this
497 # is a good enough approximation in practice.
498 *" test_"*)
499 # To avoid setting OpenSSL and GnuTLS for each call to compat.sh
500 # and ssl-opt.sh, we just export the variables they require.
501 export OPENSSL_CMD="$OPENSSL"
502 export GNUTLS_CLI="$GNUTLS_CLI"
503 export GNUTLS_SERV="$GNUTLS_SERV"
504 # Avoid passing --seed flag in every call to ssl-opt.sh
505 if [ -n "${SEED-}" ]; then
506 export SEED
507 fi
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000508 set "$@" OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY"
509 set "$@" GNUTLS_CLI="$GNUTLS_CLI" GNUTLS_SERV="$GNUTLS_SERV"
510 set "$@" GNUTLS_LEGACY_CLI="$GNUTLS_LEGACY_CLI"
511 set "$@" GNUTLS_LEGACY_SERV="$GNUTLS_LEGACY_SERV"
Gilles Peskine87964262019-01-06 22:40:00 +0000512 check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$OPENSSL_NEXT" \
513 "$GNUTLS_CLI" "$GNUTLS_SERV" \
514 "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV"
515 ;;
516 esac
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200517
Gilles Peskine87964262019-01-06 22:40:00 +0000518 case " $RUN_COMPONENTS " in
519 *_doxygen[_\ ]*) check_tools "doxygen" "dot";;
520 esac
Andres AGd9eba4b2016-08-26 14:42:14 +0100521
Gilles Peskine87964262019-01-06 22:40:00 +0000522 case " $RUN_COMPONENTS " in
523 *_arm_none_eabi_gcc[_\ ]*) check_tools "arm-none-eabi-gcc";;
524 esac
Andres AGd9eba4b2016-08-26 14:42:14 +0100525
Gilles Peskine87964262019-01-06 22:40:00 +0000526 case " $RUN_COMPONENTS " in
527 *_mingw[_\ ]*) check_tools "i686-w64-mingw32-gcc";;
528 esac
529
530 case " $RUN_COMPONENTS " in
531 *" test_zeroize "*) check_tools "gdb";;
532 esac
533
534 case " $RUN_COMPONENTS " in
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000535 *_armcc*)
Gilles Peskine87964262019-01-06 22:40:00 +0000536 ARMC5_CC="$ARMC5_BIN_DIR/armcc"
537 ARMC5_AR="$ARMC5_BIN_DIR/armar"
538 ARMC6_CC="$ARMC6_BIN_DIR/armclang"
539 ARMC6_AR="$ARMC6_BIN_DIR/armar"
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000540 check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC6_CC" "$ARMC6_AR";;
541 esac
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000542
543 msg "info: output_env.sh"
544 case $RUN_COMPONENTS in
545 *_armcc*)
546 set "$@" ARMC5_CC="$ARMC5_CC" ARMC6_CC="$ARMC6_CC" RUN_ARMCC=1;;
547 *) set "$@" RUN_ARMCC=0;;
548 esac
549 "$@" scripts/output_env.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100550}
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100551
Gilles Peskine192c72f2017-12-21 15:59:21 +0100552
553
554################################################################
555#### Basic checks
556################################################################
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100557
558#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200559# Test Suites to be executed
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100560#
Manuel Pégourié-Gonnard3d404b42015-07-08 21:59:16 +0100561# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200562# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100563# and/or are more likely to fail than others (eg I use Clang most of the
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200564# time, so start with a GCC build).
565# 2. Minimize total running time, by avoiding useless rebuilds
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100566#
Manuel Pégourié-Gonnard259b08a2016-01-08 16:27:41 +0100567# Indicative running times are given for reference.
568
Gilles Peskine8f073122018-11-27 15:58:47 +0100569component_check_recursion () {
570 msg "test: recursion.pl" # < 1s
571 record_status tests/scripts/recursion.pl library/*.c
572}
Janos Follathb72c6782016-07-19 14:54:17 +0100573
Gilles Peskine8f073122018-11-27 15:58:47 +0100574component_check_generated_files () {
575 msg "test: freshness of generated source files" # < 1s
576 record_status tests/scripts/check-generated-files.sh
577}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200578
Gilles Peskine8f073122018-11-27 15:58:47 +0100579component_check_doxy_blocks () {
580 msg "test: doxygen markup outside doxygen blocks" # < 1s
581 record_status tests/scripts/check-doxy-blocks.pl
582}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200583
Gilles Peskine8f073122018-11-27 15:58:47 +0100584component_check_files () {
585 msg "test: check-files.py" # < 1s
Gilles Peskine8f073122018-11-27 15:58:47 +0100586 record_status tests/scripts/check-files.py
587}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200588
Gilles Peskine8f073122018-11-27 15:58:47 +0100589component_check_names () {
590 msg "test/build: declared and exported names" # < 3s
Gilles Peskine8f073122018-11-27 15:58:47 +0100591 record_status tests/scripts/check-names.sh
592}
Darryl Greena07039c2018-03-13 16:48:16 +0000593
Gilles Peskine8f073122018-11-27 15:58:47 +0100594component_check_doxygen_warnings () {
595 msg "test: doxygen warnings" # ~ 3s
Gilles Peskine8f073122018-11-27 15:58:47 +0100596 record_status tests/scripts/doxygen.sh
597}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200598
Gilles Peskine192c72f2017-12-21 15:59:21 +0100599
600
601################################################################
602#### Build and test many configurations and targets
603################################################################
604
Gilles Peskine8f073122018-11-27 15:58:47 +0100605component_test_default_cmake_gcc_asan () {
606 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100607 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
608 make
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200609
Gilles Peskine8f073122018-11-27 15:58:47 +0100610 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
611 make test
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200612
Gilles Peskine8f073122018-11-27 15:58:47 +0100613 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
614 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200615
Gilles Peskine8f073122018-11-27 15:58:47 +0100616 msg "test: compat.sh (ASan build)" # ~ 6 min
617 if_build_succeeded tests/compat.sh
618}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200619
Gilles Peskine782f4112018-11-27 16:11:09 +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}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200625
Gilles Peskine8f073122018-11-27 15:58:47 +0100626component_test_sslv3 () {
627 msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100628 scripts/config.pl set MBEDTLS_SSL_PROTO_SSL3
629 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
630 make
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200631
Gilles Peskine8f073122018-11-27 15:58:47 +0100632 msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
633 make test
Simon Butcher3ea7f522016-03-07 23:22:10 +0000634
Gilles Peskine8f073122018-11-27 15:58:47 +0100635 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'
Simon Butcher3ea7f522016-03-07 23:22:10 +0000638
Gilles Peskine8f073122018-11-27 15:58:47 +0100639 msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
640 if_build_succeeded tests/ssl-opt.sh
641}
Simon Butcher3ea7f522016-03-07 23:22:10 +0000642
Gilles Peskine8f073122018-11-27 15:58:47 +0100643component_test_no_renegotiation () {
644 msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100645 scripts/config.pl unset MBEDTLS_SSL_RENEGOTIATION
646 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
647 make
Simon Butcher3ea7f522016-03-07 23:22:10 +0000648
Gilles Peskine8f073122018-11-27 15:58:47 +0100649 msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
650 make test
Hanno Becker134c2ab2017-10-12 15:29:50 +0100651
Gilles Peskine8f073122018-11-27 15:58:47 +0100652 msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
653 if_build_succeeded tests/ssl-opt.sh
654}
Hanno Becker134c2ab2017-10-12 15:29:50 +0100655
Gilles Peskine8f073122018-11-27 15:58:47 +0100656component_test_rsa_no_crt () {
657 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100658 scripts/config.pl set MBEDTLS_RSA_NO_CRT
659 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
660 make
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +0100661
Gilles Peskine8f073122018-11-27 15:58:47 +0100662 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
663 make test
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100664
Gilles Peskine8f073122018-11-27 15:58:47 +0100665 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
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100667
Gilles Peskine8f073122018-11-27 15:58:47 +0100668 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
669 if_build_succeeded tests/compat.sh -t RSA
670}
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100671
Gilles Peskine8f073122018-11-27 15:58:47 +0100672component_test_small_ssl_out_content_len () {
673 msg "build: small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100674 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 16384
675 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
676 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
677 make
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100678
Gilles Peskine8f073122018-11-27 15:58:47 +0100679 msg "test: small SSL_OUT_CONTENT_LEN - ssl-opt.sh MFL and large packet tests"
680 if_build_succeeded tests/ssl-opt.sh -f "Max fragment\|Large packet"
681}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000682
Gilles Peskine8f073122018-11-27 15:58:47 +0100683component_test_small_ssl_in_content_len () {
684 msg "build: small SSL_IN_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100685 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 4096
686 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 16384
687 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
688 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000689
Gilles Peskine8f073122018-11-27 15:58:47 +0100690 msg "test: small SSL_IN_CONTENT_LEN - ssl-opt.sh MFL tests"
691 if_build_succeeded tests/ssl-opt.sh -f "Max fragment"
692}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000693
Gilles Peskine8f073122018-11-27 15:58:47 +0100694component_test_small_ssl_dtls_max_buffering () {
695 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0"
Gilles Peskine8f073122018-11-27 15:58:47 +0100696 scripts/config.pl set MBEDTLS_SSL_DTLS_MAX_BUFFERING 1000
697 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
698 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000699
Gilles Peskine8f073122018-11-27 15:58:47 +0100700 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0 - ssl-opt.sh specific reordering test"
701 if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer out-of-order hs msg before reassembling next, free buffered msg"
702}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100703
Gilles Peskine8f073122018-11-27 15:58:47 +0100704component_test_small_mbedtls_ssl_dtls_max_buffering () {
705 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1"
Gilles Peskine8f073122018-11-27 15:58:47 +0100706 scripts/config.pl set MBEDTLS_SSL_DTLS_MAX_BUFFERING 240
707 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
708 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100709
Gilles Peskine8f073122018-11-27 15:58:47 +0100710 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1 - ssl-opt.sh specific reordering test"
711 if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer encrypted Finished message, drop for fragmented NewSessionTicket"
712}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100713
Gilles Peskine8f073122018-11-27 15:58:47 +0100714component_test_full_cmake_clang () {
715 msg "build: cmake, full config, clang" # ~ 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100716 scripts/config.pl full
717 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
718 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check -D ENABLE_TESTING=On .
719 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100720
Gilles Peskine8f073122018-11-27 15:58:47 +0100721 msg "test: main suites (full config)" # ~ 5s
722 make test
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100723
Gilles Peskine8f073122018-11-27 15:58:47 +0100724 msg "test: ssl-opt.sh default, ECJPAKE, SSL async (full config)" # ~ 1s
725 if_build_succeeded tests/ssl-opt.sh -f 'Default\|ECJPAKE\|SSL async private'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200726
Gilles Peskine8f073122018-11-27 15:58:47 +0100727 msg "test: compat.sh RC4, DES & NULL (full config)" # ~ 2 min
728 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" GNUTLS_CLI="$GNUTLS_LEGACY_CLI" GNUTLS_SERV="$GNUTLS_LEGACY_SERV" tests/compat.sh -e '3DES\|DES-CBC3' -f 'NULL\|DES\|RC4\|ARCFOUR'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200729
Gilles Peskine8f073122018-11-27 15:58:47 +0100730 msg "test: compat.sh ARIA + ChachaPoly"
731 if_build_succeeded env OPENSSL_CMD="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
732}
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200733
Gilles Peskine8f073122018-11-27 15:58:47 +0100734component_build_deprecated () {
735 msg "build: make, full config + DEPRECATED_WARNING, gcc -O" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100736 scripts/config.pl full
737 scripts/config.pl set MBEDTLS_DEPRECATED_WARNING
738 # Build with -O -Wextra to catch a maximum of issues.
739 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra' lib programs
740 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100741
Gilles Peskine8f073122018-11-27 15:58:47 +0100742 msg "build: make, full config + DEPRECATED_REMOVED, clang -O" # ~ 30s
743 # No cleanup, just tweak the configuration and rebuild
744 make clean
745 scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
746 scripts/config.pl set MBEDTLS_DEPRECATED_REMOVED
747 # Build with -O -Wextra to catch a maximum of issues.
748 make CC=clang CFLAGS='-O -Werror -Wall -Wextra' lib programs
749 make CC=clang CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
750}
Jaeden Ameroed93bdc2018-11-02 16:57:24 +0000751
Jaeden Ameroed93bdc2018-11-02 16:57:24 +0000752
Gilles Peskine8f073122018-11-27 15:58:47 +0100753component_test_depends_curves () {
754 msg "test/build: curves.pl (gcc)" # ~ 4 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100755 record_status tests/scripts/curves.pl
756}
Jaeden Ameroacaabe72018-11-07 11:52:52 +0000757
Gilles Peskine8f073122018-11-27 15:58:47 +0100758component_test_depends_hashes () {
759 msg "test/build: depends-hashes.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100760 record_status tests/scripts/depends-hashes.pl
761}
Jaeden Ameroacaabe72018-11-07 11:52:52 +0000762
Gilles Peskine8f073122018-11-27 15:58:47 +0100763component_test_depends_pkalgs () {
764 msg "test/build: depends-pkalgs.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100765 record_status tests/scripts/depends-pkalgs.pl
766}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100767
Gilles Peskine8f073122018-11-27 15:58:47 +0100768component_build_key_exchanges () {
769 msg "test/build: key-exchanges (gcc)" # ~ 1 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100770 record_status tests/scripts/key-exchanges.pl
771}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100772
Gilles Peskine8f073122018-11-27 15:58:47 +0100773component_build_default_make_gcc_and_cxx () {
774 msg "build: Unix make, -Os (gcc)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100775 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100776
Gilles Peskine8f073122018-11-27 15:58:47 +0100777 msg "test: verify header list in cpp_dummy_build.cpp"
778 record_status check_headers_in_cpp
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100779
Gilles Peskine8f073122018-11-27 15:58:47 +0100780 msg "build: Unix make, incremental g++"
781 make TEST_CPP=1
782}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100783
Andrzej Kurek1767e402019-02-05 06:05:49 -0500784component_test_submodule_cmake () {
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500785 # USE_CRYPTO_SUBMODULE: check that the build works with CMake
786 msg "build: cmake, full config + USE_CRYPTO_SUBMODULE, gcc+debug"
787 scripts/config.pl full # enables md4 and submodule doesn't enable md4
788 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
789 CC=gcc cmake -D USE_CRYPTO_SUBMODULE=1 -D CMAKE_BUILD_TYPE=Debug .
790 make
791 msg "test: top-level libmbedcrypto wasn't built (USE_CRYPTO_SUBMODULE, cmake)"
792 if_build_succeeded not test -f library/libmbedcrypto.a
793 msg "test: libmbedcrypto symbols are from crypto files (USE_CRYPTO_SUBMODULE, cmake)"
794 if_build_succeeded objdump -g crypto/library/libmbedcrypto.a | grep -E 'crypto/library$' > /dev/null
795 msg "test: libmbedcrypto uses top-level config (USE_CRYPTO_SUBMODULE, cmake)"
796 if_build_succeeded objdump -g crypto/library/libmbedcrypto.a | grep 'md4.c' > /dev/null
797 msg "test: main suites (USE_CRYPTO_SUBMODULE, cmake)"
798 make test
799 msg "test: ssl-opt.sh (USE_CRYPTO_SUBMODULE, cmake)"
800 if_build_succeeded tests/ssl-opt.sh
801}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100802
Andrzej Kurek1767e402019-02-05 06:05:49 -0500803component_test_submodule_make () {
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500804 # USE_CRYPTO_SUBMODULE: check that the build works with make
805 msg "build: make, full config + USE_CRYPTO_SUBMODULE, gcc+debug"
806 scripts/config.pl full # enables md4 and submodule doesn't enable md4
807 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
808 make CC=gcc CFLAGS='-g' USE_CRYPTO_SUBMODULE=1
809 msg "test: top-level libmbedcrypto wasn't built (USE_CRYPTO_SUBMODULE, make)"
810 if_build_succeeded not test -f library/libmbedcrypto.a
811 msg "test: libmbedcrypto symbols are from crypto files (USE_CRYPTO_SUBMODULE, make)"
812 if_build_succeeded objdump -g crypto/library/libmbedcrypto.a | grep -E 'crypto/library$' > /dev/null
813 msg "test: libmbedcrypto uses top-level config (USE_CRYPTO_SUBMODULE, make)"
814 if_build_succeeded objdump -g crypto/library/libmbedcrypto.a | grep 'md4.c' > /dev/null
815 msg "test: main suites (USE_CRYPTO_SUBMODULE, make)"
816 make CC=gcc USE_CRYPTO_SUBMODULE=1 test
817 msg "test: ssl-opt.sh (USE_CRYPTO_SUBMODULE, make)"
818 if_build_succeeded tests/ssl-opt.sh
819}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100820
Andrzej Kurek1767e402019-02-05 06:05:49 -0500821component_test_not_submodule_make () {
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500822 # Don't USE_CRYPTO_SUBMODULE: check that the submodule is not used with make
823 msg "build: make, full config - USE_CRYPTO_SUBMODULE, gcc+debug"
824 scripts/config.pl full
825 make CC=gcc CFLAGS='-g'
826 msg "test: submodule libmbedcrypto wasn't built (USE_CRYPTO_SUBMODULE, make)"
827 if_build_succeeded not test -f crypto/library/libmbedcrypto.a
828 msg "test: libmbedcrypto symbols are from library files (USE_CRYPTO_SUBMODULE, make)"
829 if_build_succeeded objdump -g library/libmbedcrypto.a | grep -E 'library$' | not grep 'crypto' > /dev/null
830}
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200831
Andrzej Kurek1767e402019-02-05 06:05:49 -0500832component_test_not_submodule_cmake () {
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500833 # Don't USE_CRYPTO_SUBMODULE: check that the submodule is not used with CMake
834 msg "build: cmake, full config - USE_CRYPTO_SUBMODULE, gcc+debug"
835 scripts/config.pl full
836 CC=gcc cmake -D CMAKE_BUILD_TYPE=Debug .
837 make
838 msg "test: submodule libmbedcrypto wasn't built (USE_CRYPTO_SUBMODULE, cmake)"
839 if_build_succeeded not test -f crypto/library/libmbedcrypto.a
840 msg "test: libmbedcrypto symbols are from library files (USE_CRYPTO_SUBMODULE, cmake)"
841 if_build_succeeded objdump -g library/libmbedcrypto.a | grep -E 'library$' | not grep 'crypto' > /dev/null
842}
Manuel Pégourié-Gonnard1fe6bb92017-06-06 11:36:16 +0200843
Andrzej Kurekfd0381a2019-02-05 05:00:02 -0500844component_test_use_psa_crypto_full_cmake_asan() {
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500845 # MBEDTLS_USE_PSA_CRYPTO: run the same set of tests as basic-build-test.sh
846 msg "build: cmake, full config + MBEDTLS_USE_PSA_CRYPTO, ASan"
847 scripts/config.pl full
848 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
849 scripts/config.pl set MBEDTLS_PSA_CRYPTO_C
850 scripts/config.pl set MBEDTLS_USE_PSA_CRYPTO
851 CC=gcc cmake -D USE_CRYPTO_SUBMODULE=1 -D CMAKE_BUILD_TYPE:String=Asan .
852 make
Manuel Pégourié-Gonnard43be6cd2017-06-20 09:53:42 +0200853
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500854 msg "test: main suites (MBEDTLS_USE_PSA_CRYPTO)"
855 make test
Manuel Pégourié-Gonnard503a5ef2015-10-23 09:04:45 +0200856
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500857 msg "test: ssl-opt.sh (MBEDTLS_USE_PSA_CRYPTO)"
858 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100859
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500860 msg "test: compat.sh default (MBEDTLS_USE_PSA_CRYPTO)"
861 if_build_succeeded tests/compat.sh
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400862
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500863 msg "test: compat.sh ssl3 (MBEDTLS_USE_PSA_CRYPTO)"
864 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400865
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500866 msg "test: compat.sh RC4, DES & NULL (MBEDTLS_USE_PSA_CRYPTO)"
867 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" GNUTLS_CLI="$GNUTLS_LEGACY_CLI" GNUTLS_SERV="$GNUTLS_LEGACY_SERV" tests/compat.sh -e '3DES\|DES-CBC3' -f 'NULL\|DES\|RC4\|ARCFOUR'
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500868
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500869 msg "test: compat.sh ARIA + ChachaPoly (MBEDTLS_USE_PSA_CRYPTO)"
870 if_build_succeeded env OPENSSL_CMD="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
871}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500872
Gilles Peskineb28636b2019-01-02 19:06:24 +0100873component_test_check_params_without_platform () {
874 msg "build+test: MBEDTLS_CHECK_PARAMS without MBEDTLS_PLATFORM_C"
875 scripts/config.pl full # includes CHECK_PARAMS
876 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
877 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
878 scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
879 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
880 scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
881 scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
882 scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
883 scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
884 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
885 scripts/config.pl unset MBEDTLS_PLATFORM_C
886 make CC=gcc CFLAGS='-Werror -O1' all test
887}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500888
Gilles Peskineb28636b2019-01-02 19:06:24 +0100889component_test_check_params_silent () {
890 msg "build+test: MBEDTLS_CHECK_PARAMS with alternative MBEDTLS_PARAM_FAILED()"
891 scripts/config.pl full # includes CHECK_PARAMS
892 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
893 sed -i 's/.*\(#define MBEDTLS_PARAM_FAILED( cond )\).*/\1/' "$CONFIG_H"
894 make CC=gcc CFLAGS='-Werror -O1' all test
895}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500896
Gilles Peskine8f073122018-11-27 15:58:47 +0100897component_test_no_platform () {
898 # Full configuration build, without platform support, file IO and net sockets.
899 # This should catch missing mbedtls_printf definitions, and by disabling file
900 # IO, it should catch missing '#include <stdio.h>'
901 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100902 scripts/config.pl full
903 scripts/config.pl unset MBEDTLS_PLATFORM_C
904 scripts/config.pl unset MBEDTLS_NET_C
905 scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
906 scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
907 scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
908 scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
909 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
910 scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
911 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
912 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
913 scripts/config.pl unset MBEDTLS_FS_IO
914 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
915 # to re-enable platform integration features otherwise disabled in C99 builds
916 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -O0 -D_DEFAULT_SOURCE' lib programs
917 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0' test
918}
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +0000919
Gilles Peskine8f073122018-11-27 15:58:47 +0100920component_build_no_std_function () {
921 # catch compile bugs in _uninit functions
922 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100923 scripts/config.pl full
924 scripts/config.pl set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
925 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
926 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
927}
Manuel Pégourié-Gonnarddccb80b2015-06-03 10:20:33 +0100928
Gilles Peskine8f073122018-11-27 15:58:47 +0100929component_build_no_ssl_srv () {
930 msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100931 scripts/config.pl full
932 scripts/config.pl unset MBEDTLS_SSL_SRV_C
933 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
934}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200935
Gilles Peskine8f073122018-11-27 15:58:47 +0100936component_build_no_ssl_cli () {
937 msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100938 scripts/config.pl full
939 scripts/config.pl unset MBEDTLS_SSL_CLI_C
940 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
941}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200942
Gilles Peskine8f073122018-11-27 15:58:47 +0100943component_build_no_sockets () {
944 # Note, C99 compliance can also be tested with the sockets support disabled,
945 # as that requires a POSIX platform (which isn't the same as C99).
946 msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100947 scripts/config.pl full
948 scripts/config.pl unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
949 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
950 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0 -std=c99 -pedantic' lib
951}
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +0200952
Gilles Peskine8f073122018-11-27 15:58:47 +0100953component_test_no_max_fragment_length () {
954 # Run max fragment length tests with MFL disabled
955 msg "build: default config except MFL extension (ASan build)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100956 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
957 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
958 make
Hanno Becker5175ac62017-09-18 15:36:25 +0100959
Gilles Peskine8f073122018-11-27 15:58:47 +0100960 msg "test: ssl-opt.sh, MFL-related tests"
961 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length"
962}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000963
Gilles Peskine8f073122018-11-27 15:58:47 +0100964component_test_no_max_fragment_length_small_ssl_out_content_len () {
965 msg "build: no MFL extension, small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100966 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
967 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 16384
968 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
969 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
970 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000971
Gilles Peskine8f073122018-11-27 15:58:47 +0100972 msg "test: MFL tests (disabled MFL extension case) & large packet tests"
973 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length\|Large buffer"
974}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000975
Gilles Peskine8f073122018-11-27 15:58:47 +0100976component_test_null_entropy () {
977 msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100978 scripts/config.pl set MBEDTLS_TEST_NULL_ENTROPY
979 scripts/config.pl set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
980 scripts/config.pl set MBEDTLS_ENTROPY_C
981 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
982 scripts/config.pl unset MBEDTLS_ENTROPY_HARDWARE_ALT
983 scripts/config.pl unset MBEDTLS_HAVEGE_C
Gilles Peskine5fa32a72019-01-06 19:48:30 +0000984 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan -D UNSAFE_BUILD=ON .
Gilles Peskine8f073122018-11-27 15:58:47 +0100985 make
Janos Follath06c54002016-06-09 13:57:40 +0100986
Gilles Peskine8f073122018-11-27 15:58:47 +0100987 msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)"
988 make test
989}
Janos Follath06c54002016-06-09 13:57:40 +0100990
Gilles Peskine8f073122018-11-27 15:58:47 +0100991component_test_platform_calloc_macro () {
992 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100993 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
994 scripts/config.pl set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
995 scripts/config.pl set MBEDTLS_PLATFORM_FREE_MACRO free
996 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
997 make
Hanno Beckere5fecec2018-10-11 11:02:52 +0100998
Gilles Peskine8f073122018-11-27 15:58:47 +0100999 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
1000 make test
1001}
Hanno Beckere5fecec2018-10-11 11:02:52 +01001002
Gilles Peskine8f073122018-11-27 15:58:47 +01001003component_test_aes_fewer_tables () {
1004 msg "build: default config with AES_FEWER_TABLES enabled"
Gilles Peskine8f073122018-11-27 15:58:47 +01001005 scripts/config.pl set MBEDTLS_AES_FEWER_TABLES
1006 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01001007
Gilles Peskine8f073122018-11-27 15:58:47 +01001008 msg "test: AES_FEWER_TABLES"
1009 make test
1010}
Hanno Becker83ebf782017-07-07 12:29:15 +01001011
Gilles Peskine8f073122018-11-27 15:58:47 +01001012component_test_aes_rom_tables () {
1013 msg "build: default config with AES_ROM_TABLES enabled"
Gilles Peskine8f073122018-11-27 15:58:47 +01001014 scripts/config.pl set MBEDTLS_AES_ROM_TABLES
1015 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01001016
Gilles Peskine8f073122018-11-27 15:58:47 +01001017 msg "test: AES_ROM_TABLES"
1018 make test
1019}
Hanno Becker83ebf782017-07-07 12:29:15 +01001020
Gilles Peskine8f073122018-11-27 15:58:47 +01001021component_test_aes_fewer_tables_and_rom_tables () {
1022 msg "build: default config with AES_ROM_TABLES and AES_FEWER_TABLES enabled"
Gilles Peskine8f073122018-11-27 15:58:47 +01001023 scripts/config.pl set MBEDTLS_AES_FEWER_TABLES
1024 scripts/config.pl set MBEDTLS_AES_ROM_TABLES
1025 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01001026
Gilles Peskine8f073122018-11-27 15:58:47 +01001027 msg "test: AES_FEWER_TABLES + AES_ROM_TABLES"
1028 make test
1029}
Hanno Becker83ebf782017-07-07 12:29:15 +01001030
Gilles Peskine8f073122018-11-27 15:58:47 +01001031component_test_make_shared () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001032 msg "build/test: make shared" # ~ 40s
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001033 make SHARED=1 all check
Gilles Peskine8f073122018-11-27 15:58:47 +01001034}
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +02001035
Gilles Peskine8f073122018-11-27 15:58:47 +01001036component_test_m32_o0 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001037 # Build once with -O0, to compile out the i386 specific inline assembly
1038 msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
Simon Butcher7a6da6e2018-06-27 21:52:54 +01001039 scripts/config.pl full
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001040 make CC=gcc CFLAGS='-O0 -Werror -Wall -Wextra -m32 -fsanitize=address'
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01001041
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001042 msg "test: i386, make, gcc -O0 (ASan build)"
1043 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01001044}
Gilles Peskine878cf602019-01-06 20:50:38 +00001045support_test_m32_o0 () {
1046 case $(uname -m) in
1047 *64*) true;;
1048 *) false;;
1049 esac
1050}
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001051
Gilles Peskine8f073122018-11-27 15:58:47 +01001052component_test_m32_o1 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001053 # Build again with -O1, to compile in the i386 specific inline assembly
1054 msg "build: i386, make, gcc -O1 (ASan build)" # ~ 30s
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001055 scripts/config.pl full
1056 make CC=gcc CFLAGS='-O1 -Werror -Wall -Wextra -m32 -fsanitize=address'
1057
1058 msg "test: i386, make, gcc -O1 (ASan build)"
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001059 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01001060}
Gilles Peskine878cf602019-01-06 20:50:38 +00001061support_test_m32_o1 () {
1062 support_test_m32_o0 "$@"
1063}
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001064
Gilles Peskine8f073122018-11-27 15:58:47 +01001065component_test_mx32 () {
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001066 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
Simon Butcher7a6da6e2018-06-27 21:52:54 +01001067 scripts/config.pl full
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001068 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32'
1069
1070 msg "test: 64-bit ILP32, make, gcc"
1071 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01001072}
Gilles Peskine878cf602019-01-06 20:50:38 +00001073support_test_mx32 () {
1074 case $(uname -m) in
1075 amd64|x86_64) true;;
1076 *) false;;
1077 esac
1078}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001079
Gilles Peskine8f073122018-11-27 15:58:47 +01001080component_test_have_int32 () {
1081 msg "build: gcc, force 32-bit bignum limbs"
Gilles Peskine8f073122018-11-27 15:58:47 +01001082 scripts/config.pl unset MBEDTLS_HAVE_ASM
1083 scripts/config.pl unset MBEDTLS_AESNI_C
1084 scripts/config.pl unset MBEDTLS_PADLOCK_C
1085 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01001086
Gilles Peskine8f073122018-11-27 15:58:47 +01001087 msg "test: gcc, force 32-bit bignum limbs"
1088 make test
1089}
Andres Amaya Garciafe843a32017-07-20 13:21:34 +01001090
Gilles Peskine8f073122018-11-27 15:58:47 +01001091component_test_have_int64 () {
1092 msg "build: gcc, force 64-bit bignum limbs"
Gilles Peskine8f073122018-11-27 15:58:47 +01001093 scripts/config.pl unset MBEDTLS_HAVE_ASM
1094 scripts/config.pl unset MBEDTLS_AESNI_C
1095 scripts/config.pl unset MBEDTLS_PADLOCK_C
1096 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
Gilles Peskine14c3c062018-01-29 21:25:12 +01001097
Gilles Peskine8f073122018-11-27 15:58:47 +01001098 msg "test: gcc, force 64-bit bignum limbs"
1099 make test
1100}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001101
Gilles Peskine8f073122018-11-27 15:58:47 +01001102component_test_no_udbl_division () {
1103 msg "build: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +01001104 scripts/config.pl full
1105 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
1106 scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
1107 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001108
Gilles Peskine8f073122018-11-27 15:58:47 +01001109 msg "test: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
1110 make test
1111}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001112
Gilles Peskine8f073122018-11-27 15:58:47 +01001113component_test_no_64bit_multiplication () {
1114 msg "build: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +01001115 scripts/config.pl full
1116 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
1117 scripts/config.pl set MBEDTLS_NO_64BIT_MULTIPLICATION
1118 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001119
Gilles Peskine8f073122018-11-27 15:58:47 +01001120 msg "test: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
1121 make test
1122}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001123
Gilles Peskine8f073122018-11-27 15:58:47 +01001124component_build_arm_none_eabi_gcc () {
1125 msg "build: arm-none-eabi-gcc, make" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +01001126 scripts/config.pl full
1127 scripts/config.pl unset MBEDTLS_NET_C
1128 scripts/config.pl unset MBEDTLS_TIMING_C
1129 scripts/config.pl unset MBEDTLS_FS_IO
1130 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
1131 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
1132 # following things are not in the default config
1133 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
1134 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
1135 scripts/config.pl unset MBEDTLS_THREADING_C
1136 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
1137 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
1138 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
1139}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001140
Gilles Peskine8f073122018-11-27 15:58:47 +01001141component_build_arm_none_eabi_gcc_no_udbl_division () {
1142 msg "build: arm-none-eabi-gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +01001143 scripts/config.pl full
1144 scripts/config.pl unset MBEDTLS_NET_C
1145 scripts/config.pl unset MBEDTLS_TIMING_C
1146 scripts/config.pl unset MBEDTLS_FS_IO
1147 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
1148 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
1149 # following things are not in the default config
1150 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
1151 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
1152 scripts/config.pl unset MBEDTLS_THREADING_C
1153 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
1154 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
1155 scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
1156 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
1157 echo "Checking that software 64-bit division is not required"
1158 if_build_succeeded not grep __aeabi_uldiv library/*.o
1159}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001160
Gilles Peskine8f073122018-11-27 15:58:47 +01001161component_build_arm_none_eabi_gcc_no_64bit_multiplication () {
1162 msg "build: arm-none-eabi-gcc MBEDTLS_NO_64BIT_MULTIPLICATION, make" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +01001163 scripts/config.pl full
1164 scripts/config.pl unset MBEDTLS_NET_C
1165 scripts/config.pl unset MBEDTLS_TIMING_C
1166 scripts/config.pl unset MBEDTLS_FS_IO
1167 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
1168 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
1169 # following things are not in the default config
1170 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
1171 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
1172 scripts/config.pl unset MBEDTLS_THREADING_C
1173 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
1174 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
1175 scripts/config.pl set MBEDTLS_NO_64BIT_MULTIPLICATION
1176 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -O1 -march=armv6-m -mthumb' lib
1177 echo "Checking that software 64-bit multiplication is not required"
1178 if_build_succeeded not grep __aeabi_lmul library/*.o
1179}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001180
Gilles Peskine8f073122018-11-27 15:58:47 +01001181component_build_armcc () {
1182 msg "build: ARM Compiler 5, make"
Gilles Peskine8f073122018-11-27 15:58:47 +01001183 scripts/config.pl full
1184 scripts/config.pl unset MBEDTLS_NET_C
1185 scripts/config.pl unset MBEDTLS_TIMING_C
1186 scripts/config.pl unset MBEDTLS_FS_IO
1187 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
1188 scripts/config.pl unset MBEDTLS_HAVE_TIME
1189 scripts/config.pl unset MBEDTLS_HAVE_TIME_DATE
1190 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
1191 # following things are not in the default config
1192 scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
1193 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
1194 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
1195 scripts/config.pl unset MBEDTLS_THREADING_C
1196 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
1197 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
1198 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT # depends on MBEDTLS_HAVE_TIME
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001199
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001200 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
1201 make clean
Andres AG87bb5772016-09-27 15:05:15 +01001202
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001203 # ARM Compiler 6 - Target ARMv7-A
1204 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-a"
Simon Butcher940737f2017-07-23 13:42:36 +02001205
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001206 # ARM Compiler 6 - Target ARMv7-M
1207 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m"
Simon Butcher940737f2017-07-23 13:42:36 +02001208
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001209 # ARM Compiler 6 - Target ARMv8-A - AArch32
1210 armc6_build_test "--target=arm-arm-none-eabi -march=armv8.2-a"
Simon Butcher940737f2017-07-23 13:42:36 +02001211
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001212 # ARM Compiler 6 - Target ARMv8-M
1213 armc6_build_test "--target=arm-arm-none-eabi -march=armv8-m.main"
Simon Butcher940737f2017-07-23 13:42:36 +02001214
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001215 # ARM Compiler 6 - Target ARMv8-A - AArch64
1216 armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a"
Gilles Peskine8f073122018-11-27 15:58:47 +01001217}
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +01001218
Gilles Peskine8f073122018-11-27 15:58:47 +01001219component_test_allow_sha1 () {
1220 msg "build: allow SHA1 in certificates by default"
Gilles Peskine8f073122018-11-27 15:58:47 +01001221 scripts/config.pl set MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
1222 make CFLAGS='-Werror -Wall -Wextra'
1223 msg "test: allow SHA1 in certificates by default"
1224 make test
1225 if_build_succeeded tests/ssl-opt.sh -f SHA-1
1226}
Gilles Peskine2a458da2017-05-12 15:26:58 +02001227
Gilles Peskine8f073122018-11-27 15:58:47 +01001228component_build_mingw () {
1229 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +01001230 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -Wall -Wextra' WINDOWS_BUILD=1 lib programs
Hanno Beckere963efa2018-01-03 10:03:43 +00001231
Gilles Peskine8f073122018-11-27 15:58:47 +01001232 # note Make tests only builds the tests, but doesn't run them
1233 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror' WINDOWS_BUILD=1 tests
1234 make WINDOWS_BUILD=1 clean
Simon Butcher002bc622016-11-17 09:27:45 +00001235
Gilles Peskine8f073122018-11-27 15:58:47 +01001236 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
1237 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
1238 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -Wall -Wextra' WINDOWS_BUILD=1 SHARED=1 tests
1239 make WINDOWS_BUILD=1 clean
1240}
Manuel Pégourié-Gonnard6448bce2015-02-16 17:18:36 +01001241
Gilles Peskine8f073122018-11-27 15:58:47 +01001242component_test_memsan () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001243 msg "build: MSan (clang)" # ~ 1 min 20s
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001244 scripts/config.pl unset MBEDTLS_AESNI_C # memsan doesn't grok asm
1245 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
1246 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +02001247
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001248 msg "test: main suites (MSan)" # ~ 10s
1249 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001250
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001251 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
Gilles Peskine7c652162017-12-11 00:01:40 +01001252 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001253
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001254 # Optional part(s)
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001255
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001256 if [ "$MEMORY" -gt 0 ]; then
1257 msg "test: compat.sh (MSan)" # ~ 6 min 20s
Gilles Peskine7c652162017-12-11 00:01:40 +01001258 if_build_succeeded tests/compat.sh
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001259 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001260}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001261
Gilles Peskine69f190e2019-01-10 00:11:42 +01001262component_test_valgrind () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001263 msg "build: Release (clang)"
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001264 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
1265 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001266
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001267 msg "test: main suites valgrind (Release)"
1268 make memcheck
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001269
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001270 # Optional part(s)
1271 # Currently broken, programs don't seem to receive signals
1272 # under valgrind on OS X
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001273
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001274 if [ "$MEMORY" -gt 0 ]; then
1275 msg "test: ssl-opt.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +01001276 if_build_succeeded tests/ssl-opt.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001277 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001278
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001279 if [ "$MEMORY" -gt 1 ]; then
1280 msg "test: compat.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +01001281 if_build_succeeded tests/compat.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001282 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001283}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001284
Gilles Peskine8f073122018-11-27 15:58:47 +01001285component_test_cmake_out_of_source () {
1286 msg "build: cmake 'out-of-source' build"
Gilles Peskine8f073122018-11-27 15:58:47 +01001287 MBEDTLS_ROOT_DIR="$PWD"
1288 mkdir "$OUT_OF_SOURCE_DIR"
1289 cd "$OUT_OF_SOURCE_DIR"
1290 cmake "$MBEDTLS_ROOT_DIR"
1291 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001292
Gilles Peskine8f073122018-11-27 15:58:47 +01001293 msg "test: cmake 'out-of-source' build"
1294 make test
1295 # Test an SSL option that requires an auxiliary script in test/scripts/.
1296 # Also ensure that there are no error messages such as
1297 # "No such file or directory", which would indicate that some required
1298 # file is missing (ssl-opt.sh tolerates the absence of some files so
1299 # may exit with status 0 but emit errors).
1300 if_build_succeeded ./tests/ssl-opt.sh -f 'Fallback SCSV: beginning of list' 2>ssl-opt.err
1301 if [ -s ssl-opt.err ]; then
1302 cat ssl-opt.err >&2
1303 record_status [ ! -s ssl-opt.err ]
1304 rm ssl-opt.err
1305 fi
1306 cd "$MBEDTLS_ROOT_DIR"
1307 rm -rf "$OUT_OF_SOURCE_DIR"
1308 unset MBEDTLS_ROOT_DIR
1309}
Andres AGdc192212016-08-31 17:33:13 +01001310
Gilles Peskine8f073122018-11-27 15:58:47 +01001311component_test_zeroize () {
1312 # Test that the function mbedtls_platform_zeroize() is not optimized away by
1313 # different combinations of compilers and optimization flags by using an
1314 # auxiliary GDB script. Unfortunately, GDB does not return error values to the
1315 # system in all cases that the script fails, so we must manually search the
1316 # output to check whether the pass string is present and no failure strings
1317 # were printed.
Andres AGdc192212016-08-31 17:33:13 +01001318
Gilles Peskine4976e822019-01-06 19:52:22 +00001319 # Don't try to disable ASLR. We don't care about ASLR here. We do care
1320 # about a spurious message if Gdb tries and fails, so suppress that.
1321 gdb_disable_aslr=
1322 if [ -z "$(gdb -batch -nw -ex 'set disable-randomization off' 2>&1)" ]; then
1323 gdb_disable_aslr='set disable-randomization off'
1324 fi
1325
Gilles Peskine8f073122018-11-27 15:58:47 +01001326 for optimization_flag in -O2 -O3 -Ofast -Os; do
Gilles Peskine55f7c942019-01-09 22:28:21 +01001327 for compiler in clang gcc; do
1328 msg "test: $compiler $optimization_flag, mbedtls_platform_zeroize()"
1329 make programs CC="$compiler" DEBUG=1 CFLAGS="$optimization_flag"
Gilles Peskine4976e822019-01-06 19:52:22 +00001330 if_build_succeeded gdb -ex "$gdb_disable_aslr" -x tests/scripts/test_zeroize.gdb -nw -batch -nx 2>&1 | tee test_zeroize.log
Gilles Peskine55f7c942019-01-09 22:28:21 +01001331 if_build_succeeded grep "The buffer was correctly zeroized" test_zeroize.log
1332 if_build_succeeded not grep -i "error" test_zeroize.log
1333 rm -f test_zeroize.log
1334 make clean
1335 done
Andres Amaya Garcia29673812017-10-25 10:35:51 +01001336 done
Andres Amaya Garciad0d7bf62017-10-25 09:01:31 +01001337
Gilles Peskine4976e822019-01-06 19:52:22 +00001338 unset gdb_disable_aslr
Gilles Peskine8f073122018-11-27 15:58:47 +01001339}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001340
Gilles Peskine8f073122018-11-27 15:58:47 +01001341component_check_python_files () {
1342 msg "Lint: Python scripts"
1343 record_status tests/scripts/check-python-files.sh
1344}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001345
Gilles Peskine8f073122018-11-27 15:58:47 +01001346component_check_generate_test_code () {
1347 msg "uint test: generate_test_code.py"
1348 record_status ./tests/scripts/test_generate_test_code.py
1349}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001350
1351################################################################
1352#### Termination
1353################################################################
1354
Gilles Peskine8f073122018-11-27 15:58:47 +01001355post_report () {
1356 msg "Done, cleaning up"
1357 cleanup
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001358
Gilles Peskine8f073122018-11-27 15:58:47 +01001359 final_report
1360}
1361
1362
1363
1364################################################################
1365#### Run all the things
1366################################################################
1367
Gilles Peskinee48351a2018-11-27 16:06:30 +01001368# Run one component and clean up afterwards.
Gilles Peskine8f073122018-11-27 15:58:47 +01001369run_component () {
Gilles Peskine608953e2019-01-02 18:57:02 +01001370 # Back up the configuration in case the component modifies it.
1371 # The cleanup function will restore it.
1372 cp -p "$CONFIG_H" "$CONFIG_BAK"
Gilles Peskineffcdeff2018-12-04 12:49:28 +01001373 current_component="$1"
Gilles Peskine8f073122018-11-27 15:58:47 +01001374 "$@"
Gilles Peskinee48351a2018-11-27 16:06:30 +01001375 cleanup
Gilles Peskine8f073122018-11-27 15:58:47 +01001376}
1377
1378# Preliminary setup
1379pre_check_environment
1380pre_initialize_variables
1381pre_parse_command_line "$@"
Gilles Peskine348fb9a2018-11-27 17:04:29 +01001382
Gilles Peskine878cf602019-01-06 20:50:38 +00001383pre_check_git
1384build_status=0
1385if [ $KEEP_GOING -eq 1 ]; then
1386 pre_setup_keep_going
Gilles Peskine92525112018-11-27 18:15:35 +01001387else
Gilles Peskine878cf602019-01-06 20:50:38 +00001388 record_status () {
1389 "$@"
1390 }
Gilles Peskine8f073122018-11-27 15:58:47 +01001391fi
Gilles Peskine878cf602019-01-06 20:50:38 +00001392pre_print_configuration
1393pre_check_tools
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001394cleanup
1395
Gilles Peskinebeb3a812019-01-06 22:11:25 +00001396# Run the requested tests.
1397for component in $RUN_COMPONENTS; do
1398 run_component "component_$component"
1399done
Gilles Peskine8f073122018-11-27 15:58:47 +01001400
1401# We're done.
Gilles Peskine878cf602019-01-06 20:50:38 +00001402post_report