blob: 34c03c3fa8dc470792a3459c3e3d0b20ad31b775 [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
Gilles Peskine636c26a2020-03-04 20:46:15 +010027# * Makefile, library/Makefile, programs/Makefile, tests/Makefile,
28# programs/fuzz/Makefile
Gilles Peskine192c72f2017-12-21 15:59:21 +010029# After running this script, the CMake cache will be lost and CMake
30# will no longer be initialised.
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +010031#
Gilles Peskine192c72f2017-12-21 15:59:21 +010032# The script assumes the presence of a number of tools:
33# * Basic Unix tools (Windows users note: a Unix-style find must be before
34# the Windows find in the PATH)
35# * Perl
36# * GNU Make
37# * CMake
38# * GCC and Clang (recent enough for using ASan with gcc and MemSan with clang, or valgrind)
Andrzej Kurek05be06c2018-06-28 04:41:50 -040039# * G++
Gilles Peskine192c72f2017-12-21 15:59:21 +010040# * arm-gcc and mingw-gcc
41# * ArmCC 5 and ArmCC 6, unless invoked with --no-armcc
Gilles Peskine192c72f2017-12-21 15:59:21 +010042# * OpenSSL and GnuTLS command line tools, recent enough for the
43# interoperability tests. If they don't support SSLv3 then a legacy
44# version of these tools must be present as well (search for LEGACY
45# below).
46# See the invocation of check_tools below for details.
47#
48# This script must be invoked from the toplevel directory of a git
49# working copy of Mbed TLS.
50#
51# Note that the output is not saved. You may want to run
52# script -c tests/scripts/all.sh
53# or
54# tests/scripts/all.sh >all.log 2>&1
55#
56# Notes for maintainers
57# ---------------------
58#
Gilles Peskine8f073122018-11-27 15:58:47 +010059# The bulk of the code is organized into functions that follow one of the
60# following naming conventions:
61# * pre_XXX: things to do before running the tests, in order.
62# * component_XXX: independent components. They can be run in any order.
Gilles Peskinec70637a2019-01-09 22:29:17 +010063# * component_check_XXX: quick tests that aren't worth parallelizing.
64# * component_build_XXX: build things but don't run them.
65# * component_test_XXX: build and test.
Gilles Peskine878cf602019-01-06 20:50:38 +000066# * support_XXX: if support_XXX exists and returns false then
67# component_XXX is not run by default.
Gilles Peskine8f073122018-11-27 15:58:47 +010068# * post_XXX: things to do after running the tests.
69# * other: miscellaneous support functions.
70#
Gilles Peskinec70637a2019-01-09 22:29:17 +010071# Each component must start by invoking `msg` with a short informative message.
72#
73# The framework performs some cleanup tasks after each component. This
74# means that components can assume that the working directory is in a
75# cleaned-up state, and don't need to perform the cleanup themselves.
76# * Run `make clean`.
77# * Restore `include/mbedtks/config.h` from a backup made before running
78# the component.
Gilles Peskine636c26a2020-03-04 20:46:15 +010079# * Check out `Makefile`, `library/Makefile`, `programs/Makefile`,
80# `tests/Makefile` and `programs/fuzz/Makefile` from git.
81# This cleans up after an in-tree use of CMake.
Gilles Peskinec70637a2019-01-09 22:29:17 +010082#
83# Any command that is expected to fail must be protected so that the
84# script keeps running in --keep-going mode despite `set -e`. In keep-going
85# mode, if a protected command fails, this is logged as a failure and the
86# script will exit with a failure status once it has run all components.
87# Commands can be protected in any of the following ways:
88# * `make` is a function which runs the `make` command with protection.
89# Note that you must write `make VAR=value`, not `VAR=value make`,
90# because the `VAR=value make` syntax doesn't work with functions.
91# * Put `report_status` before the command to protect it.
92# * Put `if_build_successful` before a command. This protects it, and
93# additionally skips it if a prior invocation of `make` in the same
94# component failed.
95#
Gilles Peskine192c72f2017-12-21 15:59:21 +010096# The tests are roughly in order from fastest to slowest. This doesn't
97# have to be exact, but in general you should add slower tests towards
98# the end and fast checks near the beginning.
Gilles Peskine192c72f2017-12-21 15:59:21 +010099
100
101
102################################################################
103#### Initialization and command line parsing
104################################################################
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100105
SimonB2e23c822016-04-16 21:54:39 +0100106# Abort on errors (and uninitialised variables)
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100107set -eu
108
Gilles Peskine8f073122018-11-27 15:58:47 +0100109pre_check_environment () {
Gilles Peskinea16c2b12019-01-06 19:58:02 +0000110 if [ -d library -a -d include -a -d tests ]; then :; else
Gilles Peskine8f073122018-11-27 15:58:47 +0100111 echo "Must be run from mbed TLS root" >&2
112 exit 1
113 fi
114}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100115
Gilles Peskine8f073122018-11-27 15:58:47 +0100116pre_initialize_variables () {
117 CONFIG_H='include/mbedtls/config.h'
118 CONFIG_BAK="$CONFIG_H.bak"
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200119
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200120 append_outcome=0
Gilles Peskine8f073122018-11-27 15:58:47 +0100121 MEMORY=0
122 FORCE=0
123 KEEP_GOING=0
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100124
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200125 : ${MBEDTLS_TEST_OUTCOME_FILE=}
Gilles Peskine9004a172019-09-16 15:20:36 +0200126 : ${MBEDTLS_TEST_PLATFORM="$(uname -s | tr -c \\n0-9A-Za-z _)-$(uname -m | tr -c \\n0-9A-Za-z _)"}
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200127 export MBEDTLS_TEST_OUTCOME_FILE
Gilles Peskine9004a172019-09-16 15:20:36 +0200128 export MBEDTLS_TEST_PLATFORM
129
Jaeden Ameroc4cc2512019-01-30 15:35:44 +0000130 # Default commands, can be overridden by the environment
Gilles Peskine8f073122018-11-27 15:58:47 +0100131 : ${OPENSSL:="openssl"}
132 : ${OPENSSL_LEGACY:="$OPENSSL"}
133 : ${OPENSSL_NEXT:="$OPENSSL"}
134 : ${GNUTLS_CLI:="gnutls-cli"}
135 : ${GNUTLS_SERV:="gnutls-serv"}
136 : ${GNUTLS_LEGACY_CLI:="$GNUTLS_CLI"}
137 : ${GNUTLS_LEGACY_SERV:="$GNUTLS_SERV"}
138 : ${OUT_OF_SOURCE_DIR:=./mbedtls_out_of_source_build}
139 : ${ARMC5_BIN_DIR:=/usr/bin}
140 : ${ARMC6_BIN_DIR:=/usr/bin}
Gilles Peskine6d061342020-04-30 18:19:32 +0200141 : ${ARM_NONE_EABI_GCC_PREFIX:=arm-none-eabi-}
Andres AGdc192212016-08-31 17:33:13 +0100142
Gilles Peskine8f073122018-11-27 15:58:47 +0100143 # if MAKEFLAGS is not set add the -j option to speed up invocations of make
Gilles Peskinea1fc4b52019-01-06 20:15:26 +0000144 if [ -z "${MAKEFLAGS+set}" ]; then
Gilles Peskine8f073122018-11-27 15:58:47 +0100145 export MAKEFLAGS="-j"
146 fi
Gilles Peskine878cf602019-01-06 20:50:38 +0000147
Jaeden Amerod48e9c72019-02-07 17:43:39 +0000148 # Include more verbose output for failing tests run by CMake
149 export CTEST_OUTPUT_ON_FAILURE=1
150
Gilles Peskine8fd59422019-10-21 17:11:33 +0200151 # CFLAGS and LDFLAGS for Asan builds that don't use CMake
Gilles Peskine5ca393f2019-10-21 19:06:33 +0200152 ASAN_CFLAGS='-Werror -Wall -Wextra -fsanitize=address,undefined -fno-sanitize-recover=all'
Gilles Peskine8fd59422019-10-21 17:11:33 +0200153
Gilles Peskine878cf602019-01-06 20:50:38 +0000154 # Gather the list of available components. These are the functions
155 # defined in this script whose name starts with "component_".
156 # Parse the script with sed, because in sh there is no way to list
157 # defined functions.
158 ALL_COMPONENTS=$(sed -n 's/^ *component_\([0-9A-Z_a-z]*\) *().*/\1/p' <"$0")
159
160 # Exclude components that are not supported on this platform.
161 SUPPORTED_COMPONENTS=
162 for component in $ALL_COMPONENTS; do
163 case $(type "support_$component" 2>&1) in
164 *' function'*)
165 if ! support_$component; then continue; fi;;
166 esac
167 SUPPORTED_COMPONENTS="$SUPPORTED_COMPONENTS $component"
168 done
Gilles Peskine8f073122018-11-27 15:58:47 +0100169}
Andres AG38495a32016-07-12 16:54:33 +0100170
Gilles Peskinea28db922019-01-10 00:05:18 +0100171# Test whether the component $1 is included in the command line patterns.
172is_component_included()
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100173{
174 set -f
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000175 for pattern in $COMMAND_LINE_COMPONENTS; do
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100176 set +f
177 case ${1#component_} in $pattern) return 0;; esac
178 done
179 set +f
180 return 1
181}
Andres AG7770ea82016-10-10 15:46:20 +0100182
Simon Butcher41eeccf2016-09-07 00:07:09 +0100183usage()
Andres AGd9eba4b2016-08-26 14:42:14 +0100184{
Gilles Peskine709346a2017-12-10 23:43:39 +0100185 cat <<EOF
Gilles Peskine92525112018-11-27 18:15:35 +0100186Usage: $0 [OPTION]... [COMPONENT]...
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100187Run mbedtls release validation tests.
Gilles Peskine92525112018-11-27 18:15:35 +0100188By default, run all tests. With one or more COMPONENT, run only those.
Gilles Peskinea28db922019-01-10 00:05:18 +0100189COMPONENT can be the name of a component or a shell wildcard pattern.
190
191Examples:
192 $0 "check_*"
193 Run all sanity checks.
194 $0 --no-armcc --except test_memsan
195 Run everything except builds that require armcc and MemSan.
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100196
197Special options:
198 -h|--help Print this help and exit.
Gilles Peskine878cf602019-01-06 20:50:38 +0000199 --list-all-components List all available test components and exit.
200 --list-components List components supported on this platform and exit.
Gilles Peskine709346a2017-12-10 23:43:39 +0100201
202General options:
203 -f|--force Force the tests to overwrite any modified files.
Gilles Peskine7c652162017-12-11 00:01:40 +0100204 -k|--keep-going Run all tests and report errors at the end.
Gilles Peskine709346a2017-12-10 23:43:39 +0100205 -m|--memory Additional optional memory tests.
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200206 --append-outcome Append to the outcome file (if used).
Gilles Peskine6d061342020-04-30 18:19:32 +0200207 --arm-none-eabi-gcc-prefix=<string>
208 Prefix for a cross-compiler for arm-none-eabi
209 (default: "${ARM_NONE_EABI_GCC_PREFIX}")
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100210 --armcc Run ARM Compiler builds (on by default).
Gilles Peskinea28db922019-01-10 00:05:18 +0100211 --except Exclude the COMPONENTs listed on the command line,
212 instead of running only those.
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200213 --no-append-outcome Write a new outcome file and analyze it (default).
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100214 --no-armcc Skip ARM Compiler builds.
Gilles Peskine38d81652018-03-21 08:40:26 +0100215 --no-force Refuse to overwrite modified files (default).
216 --no-keep-going Stop at the first error (default).
217 --no-memory No additional memory tests (default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100218 --out-of-source-dir=<path> Directory used for CMake out-of-source build tests.
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200219 --outcome-file=<path> File where test outcomes are written (not done if
220 empty; default: \$MBEDTLS_TEST_OUTCOME_FILE).
Gilles Peskine38d81652018-03-21 08:40:26 +0100221 --random-seed Use a random seed value for randomized tests (default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100222 -r|--release-test Run this script in release mode. This fixes the seed value to 1.
223 -s|--seed Integer seed value to use for this test run.
224
225Tool path options:
226 --armc5-bin-dir=<ARMC5_bin_dir_path> ARM Compiler 5 bin directory.
227 --armc6-bin-dir=<ARMC6_bin_dir_path> ARM Compiler 6 bin directory.
228 --gnutls-cli=<GnuTLS_cli_path> GnuTLS client executable to use for most tests.
229 --gnutls-serv=<GnuTLS_serv_path> GnuTLS server executable to use for most tests.
230 --gnutls-legacy-cli=<GnuTLS_cli_path> GnuTLS client executable to use for legacy tests.
231 --gnutls-legacy-serv=<GnuTLS_serv_path> GnuTLS server executable to use for legacy tests.
232 --openssl=<OpenSSL_path> OpenSSL executable to use for most tests.
233 --openssl-legacy=<OpenSSL_path> OpenSSL executable to use for legacy tests e.g. SSLv3.
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100234 --openssl-next=<OpenSSL_path> OpenSSL executable to use for recent things like ARIA
Gilles Peskine709346a2017-12-10 23:43:39 +0100235EOF
SimonB2e23c822016-04-16 21:54:39 +0100236}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100237
238# remove built files as well as the cmake cache/config
239cleanup()
240{
Gilles Peskinea71d64c2018-03-21 12:16:57 +0100241 if [ -n "${MBEDTLS_ROOT_DIR+set}" ]; then
242 cd "$MBEDTLS_ROOT_DIR"
243 fi
244
Gilles Peskine7c652162017-12-11 00:01:40 +0100245 command make clean
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200246
Gilles Peskine31b07e22018-03-21 12:15:06 +0100247 # Remove CMake artefacts
Jaeden Amero2d0e00f2018-11-07 18:46:41 +0000248 find . -name .git -prune -o \
Gilles Peskine31b07e22018-03-21 12:15:06 +0100249 -iname CMakeFiles -exec rm -rf {} \+ -o \
250 \( -iname cmake_install.cmake -o \
251 -iname CTestTestfile.cmake -o \
252 -iname CMakeCache.txt \) -exec rm {} \+
253 # Recover files overwritten by in-tree CMake builds
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000254 rm -f include/Makefile include/mbedtls/Makefile programs/*/Makefile
Gilles Peskine636c26a2020-03-04 20:46:15 +0100255 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile
256 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200257
Jaeden Ameroab83fdf2019-06-20 17:38:22 +0100258 # Remove any artifacts from the component_test_cmake_as_subdirectory test.
259 rm -rf programs/test/cmake_subproject/build
260 rm -f programs/test/cmake_subproject/Makefile
261 rm -f programs/test/cmake_subproject/cmake_subproject
262
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200263 if [ -f "$CONFIG_BAK" ]; then
264 mv "$CONFIG_BAK" "$CONFIG_H"
265 fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100266}
267
Gilles Peskine7c652162017-12-11 00:01:40 +0100268# Executed on exit. May be redefined depending on command line options.
269final_report () {
270 :
271}
272
273fatal_signal () {
274 cleanup
275 final_report $1
276 trap - $1
277 kill -$1 $$
278}
279
280trap 'fatal_signal HUP' HUP
281trap 'fatal_signal INT' INT
282trap 'fatal_signal TERM' TERM
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200283
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100284msg()
285{
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100286 if [ -n "${current_component:-}" ]; then
287 current_section="${current_component#component_}: $1"
288 else
289 current_section="$1"
290 fi
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100291 echo ""
292 echo "******************************************************************"
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100293 echo "* $current_section "
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000294 printf "* "; date
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100295 echo "******************************************************************"
296}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100297
Gilles Peskine8f073122018-11-27 15:58:47 +0100298armc6_build_test()
299{
300 FLAGS="$1"
Andres AGa5cd9732016-10-17 15:23:10 +0100301
Gilles Peskine18487f62020-04-30 23:11:54 +0200302 msg "build: ARM Compiler 6 ($FLAGS)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100303 ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \
304 WARNING_CFLAGS='-xc -std=c99' make lib
Gilles Peskine18487f62020-04-30 23:11:54 +0200305
306 msg "size: ARM Compiler 6 ($FLAGS)"
307 "$ARMC6_FROMELF" -z library/*.o
308
Gilles Peskine8f073122018-11-27 15:58:47 +0100309 make clean
310}
Andres AGa5cd9732016-10-17 15:23:10 +0100311
Andres AGd9eba4b2016-08-26 14:42:14 +0100312err_msg()
313{
314 echo "$1" >&2
315}
316
317check_tools()
318{
319 for TOOL in "$@"; do
Andres AG98393602017-01-31 17:04:45 +0000320 if ! `type "$TOOL" >/dev/null 2>&1`; then
Andres AGd9eba4b2016-08-26 14:42:14 +0100321 err_msg "$TOOL not found!"
322 exit 1
323 fi
324 done
325}
326
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400327check_headers_in_cpp () {
Peter Kolbus1bc1a4c2019-02-01 17:19:08 -0600328 ls include/mbedtls | grep "\.h$" >headers.txt
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400329 <programs/test/cpp_dummy_build.cpp sed -n 's/"$//; s!^#include "mbedtls/!!p' |
330 sort |
331 diff headers.txt -
332 rm headers.txt
333}
334
Gilles Peskine8f073122018-11-27 15:58:47 +0100335pre_parse_command_line () {
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000336 COMMAND_LINE_COMPONENTS=
Gilles Peskinea28db922019-01-10 00:05:18 +0100337 all_except=0
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000338 no_armcc=
SimonB2e23c822016-04-16 21:54:39 +0100339
Jaeden Amero9b90f2e2018-11-02 18:34:17 +0000340 # Note that legacy options are ignored instead of being omitted from this
341 # list of options, so invocations that worked with previous version of
342 # all.sh will still run and work properly.
Gilles Peskine8f073122018-11-27 15:58:47 +0100343 while [ $# -gt 0 ]; do
Gilles Peskine55f7c942019-01-09 22:28:21 +0100344 case "$1" in
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200345 --append-outcome) append_outcome=1;;
Gilles Peskine6d061342020-04-30 18:19:32 +0200346 --arm-none-eabi-gcc-prefix) shift; ARM_NONE_EABI_GCC_PREFIX="$1";;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000347 --armcc) no_armcc=;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100348 --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
349 --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000350 --except) all_except=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100351 --force|-f) FORCE=1;;
352 --gnutls-cli) shift; GNUTLS_CLI="$1";;
353 --gnutls-legacy-cli) shift; GNUTLS_LEGACY_CLI="$1";;
354 --gnutls-legacy-serv) shift; GNUTLS_LEGACY_SERV="$1";;
355 --gnutls-serv) shift; GNUTLS_SERV="$1";;
356 --help|-h) usage; exit;;
357 --keep-going|-k) KEEP_GOING=1;;
Gilles Peskine878cf602019-01-06 20:50:38 +0000358 --list-all-components) printf '%s\n' $ALL_COMPONENTS; exit;;
359 --list-components) printf '%s\n' $SUPPORTED_COMPONENTS; exit;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100360 --memory|-m) MEMORY=1;;
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200361 --no-append-outcome) append_outcome=0;;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000362 --no-armcc) no_armcc=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100363 --no-force) FORCE=0;;
364 --no-keep-going) KEEP_GOING=0;;
365 --no-memory) MEMORY=0;;
366 --openssl) shift; OPENSSL="$1";;
367 --openssl-legacy) shift; OPENSSL_LEGACY="$1";;
368 --openssl-next) shift; OPENSSL_NEXT="$1";;
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200369 --outcome-file) shift; MBEDTLS_TEST_OUTCOME_FILE="$1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100370 --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
371 --random-seed) unset SEED;;
372 --release-test|-r) SEED=1;;
373 --seed|-s) shift; SEED="$1";;
374 -*)
375 echo >&2 "Unknown option: $1"
376 echo >&2 "Run $0 --help for usage."
377 exit 120
378 ;;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000379 *) COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS $1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100380 esac
381 shift
Gilles Peskine8f073122018-11-27 15:58:47 +0100382 done
SimonB2e23c822016-04-16 21:54:39 +0100383
Gilles Peskinea28db922019-01-10 00:05:18 +0100384 # With no list of components, run everything.
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000385 if [ -z "$COMMAND_LINE_COMPONENTS" ]; then
386 all_except=1
Andres AGdc192212016-08-31 17:33:13 +0100387 fi
388
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000389 # --no-armcc is a legacy option. The modern way is --except '*_armcc*'.
390 # Ignore it if components are listed explicitly on the command line.
Gilles Peskinea28db922019-01-10 00:05:18 +0100391 if [ -n "$no_armcc" ] && [ $all_except -eq 1 ]; then
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000392 COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS *_armcc*"
SimonB2e23c822016-04-16 21:54:39 +0100393 fi
SimonB2e23c822016-04-16 21:54:39 +0100394
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000395 # Build the list of components to run.
Gilles Peskinea28db922019-01-10 00:05:18 +0100396 RUN_COMPONENTS=
397 for component in $SUPPORTED_COMPONENTS; do
398 if is_component_included "$component"; [ $? -eq $all_except ]; then
399 RUN_COMPONENTS="$RUN_COMPONENTS $component"
400 fi
401 done
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000402
403 unset all_except
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000404 unset no_armcc
Gilles Peskine8f073122018-11-27 15:58:47 +0100405}
SimonB2e23c822016-04-16 21:54:39 +0100406
Gilles Peskine8f073122018-11-27 15:58:47 +0100407pre_check_git () {
408 if [ $FORCE -eq 1 ]; then
Gilles Peskine53190e62019-01-09 23:17:35 +0100409 rm -rf "$OUT_OF_SOURCE_DIR"
Gilles Peskine8f073122018-11-27 15:58:47 +0100410 git checkout-index -f -q $CONFIG_H
411 cleanup
412 else
SimonB2e23c822016-04-16 21:54:39 +0100413
Gilles Peskine8f073122018-11-27 15:58:47 +0100414 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
415 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
416 echo "You can either delete this directory manually, or force the test by rerunning"
417 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
418 exit 1
419 fi
420
Gilles Peskined1174cf2019-01-09 22:30:01 +0100421 if ! git diff --quiet include/mbedtls/config.h; then
Gilles Peskine8f073122018-11-27 15:58:47 +0100422 err_msg "Warning - the configuration file 'include/mbedtls/config.h' has been edited. "
423 echo "You can either delete or preserve your work, or force the test by rerunning the"
424 echo "script as: $0 --force"
425 exit 1
426 fi
SimonB2e23c822016-04-16 21:54:39 +0100427 fi
Andrzej Kurekeb508712019-02-14 07:18:59 -0500428}
429
Gilles Peskine8f073122018-11-27 15:58:47 +0100430pre_setup_keep_going () {
Gilles Peskine7c652162017-12-11 00:01:40 +0100431 failure_summary=
432 failure_count=0
433 start_red=
434 end_color=
435 if [ -t 1 ]; then
Gilles Peskine9736b9d2018-01-02 21:54:17 +0100436 case "${TERM:-}" in
Gilles Peskine7c652162017-12-11 00:01:40 +0100437 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
438 start_red=$(printf '\033[31m')
439 end_color=$(printf '\033[0m')
440 ;;
441 esac
442 fi
443 record_status () {
444 if "$@"; then
445 last_status=0
446 else
447 last_status=$?
448 text="$current_section: $* -> $last_status"
449 failure_summary="$failure_summary
450$text"
451 failure_count=$((failure_count + 1))
452 echo "${start_red}^^^^$text^^^^${end_color}"
453 fi
454 }
455 make () {
456 case "$*" in
457 *test|*check)
458 if [ $build_status -eq 0 ]; then
459 record_status command make "$@"
460 else
461 echo "(skipped because the build failed)"
462 fi
463 ;;
464 *)
465 record_status command make "$@"
466 build_status=$last_status
467 ;;
468 esac
469 }
470 final_report () {
471 if [ $failure_count -gt 0 ]; then
472 echo
473 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
474 echo "${start_red}FAILED: $failure_count${end_color}$failure_summary"
475 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Jaeden Amero7c1258d2018-07-20 16:42:14 +0100476 exit 1
Gilles Peskine7c652162017-12-11 00:01:40 +0100477 elif [ -z "${1-}" ]; then
478 echo "SUCCESS :)"
479 fi
480 if [ -n "${1-}" ]; then
481 echo "Killed by SIG$1."
482 fi
483 }
Gilles Peskine8f073122018-11-27 15:58:47 +0100484}
485
Gilles Peskine7c652162017-12-11 00:01:40 +0100486if_build_succeeded () {
487 if [ $build_status -eq 0 ]; then
488 record_status "$@"
489 fi
490}
491
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200492# to be used instead of ! for commands run with
493# record_status or if_build_succeeded
494not() {
495 ! "$@"
496}
497
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200498pre_prepare_outcome_file () {
499 case "$MBEDTLS_TEST_OUTCOME_FILE" in
500 [!/]*) MBEDTLS_TEST_OUTCOME_FILE="$PWD/$MBEDTLS_TEST_OUTCOME_FILE";;
501 esac
502 if [ -n "$MBEDTLS_TEST_OUTCOME_FILE" ] && [ "$append_outcome" -eq 0 ]; then
503 rm -f "$MBEDTLS_TEST_OUTCOME_FILE"
504 fi
505}
506
Gilles Peskine8f073122018-11-27 15:58:47 +0100507pre_print_configuration () {
508 msg "info: $0 configuration"
509 echo "MEMORY: $MEMORY"
510 echo "FORCE: $FORCE"
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200511 echo "MBEDTLS_TEST_OUTCOME_FILE: ${MBEDTLS_TEST_OUTCOME_FILE:-(none)}"
Gilles Peskine8f073122018-11-27 15:58:47 +0100512 echo "SEED: ${SEED-"UNSET"}"
Gilles Peskine636c26a2020-03-04 20:46:15 +0100513 echo
Gilles Peskine8f073122018-11-27 15:58:47 +0100514 echo "OPENSSL: $OPENSSL"
515 echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
516 echo "OPENSSL_NEXT: $OPENSSL_NEXT"
517 echo "GNUTLS_CLI: $GNUTLS_CLI"
518 echo "GNUTLS_SERV: $GNUTLS_SERV"
519 echo "GNUTLS_LEGACY_CLI: $GNUTLS_LEGACY_CLI"
520 echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV"
521 echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
522 echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
523}
Andres AG7770ea82016-10-10 15:46:20 +0100524
Andres AGd9eba4b2016-08-26 14:42:14 +0100525# Make sure the tools we need are available.
Gilles Peskine8f073122018-11-27 15:58:47 +0100526pre_check_tools () {
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000527 # Build the list of variables to pass to output_env.sh.
528 set env
SimonB2e23c822016-04-16 21:54:39 +0100529
Gilles Peskine87964262019-01-06 22:40:00 +0000530 case " $RUN_COMPONENTS " in
531 # Require OpenSSL and GnuTLS if running any tests (as opposed to
532 # only doing builds). Not all tests run OpenSSL and GnuTLS, but this
533 # is a good enough approximation in practice.
534 *" test_"*)
535 # To avoid setting OpenSSL and GnuTLS for each call to compat.sh
536 # and ssl-opt.sh, we just export the variables they require.
537 export OPENSSL_CMD="$OPENSSL"
538 export GNUTLS_CLI="$GNUTLS_CLI"
539 export GNUTLS_SERV="$GNUTLS_SERV"
540 # Avoid passing --seed flag in every call to ssl-opt.sh
541 if [ -n "${SEED-}" ]; then
542 export SEED
543 fi
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000544 set "$@" OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY"
545 set "$@" GNUTLS_CLI="$GNUTLS_CLI" GNUTLS_SERV="$GNUTLS_SERV"
546 set "$@" GNUTLS_LEGACY_CLI="$GNUTLS_LEGACY_CLI"
547 set "$@" GNUTLS_LEGACY_SERV="$GNUTLS_LEGACY_SERV"
Gilles Peskine87964262019-01-06 22:40:00 +0000548 check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$OPENSSL_NEXT" \
549 "$GNUTLS_CLI" "$GNUTLS_SERV" \
550 "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV"
551 ;;
552 esac
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200553
Gilles Peskine87964262019-01-06 22:40:00 +0000554 case " $RUN_COMPONENTS " in
555 *_doxygen[_\ ]*) check_tools "doxygen" "dot";;
556 esac
Andres AGd9eba4b2016-08-26 14:42:14 +0100557
Gilles Peskine87964262019-01-06 22:40:00 +0000558 case " $RUN_COMPONENTS " in
Gilles Peskine6d061342020-04-30 18:19:32 +0200559 *_arm_none_eabi_gcc[_\ ]*) check_tools "${ARM_NONE_EABI_GCC_PREFIX}gcc";;
Gilles Peskine87964262019-01-06 22:40:00 +0000560 esac
Andres AGd9eba4b2016-08-26 14:42:14 +0100561
Gilles Peskine87964262019-01-06 22:40:00 +0000562 case " $RUN_COMPONENTS " in
563 *_mingw[_\ ]*) check_tools "i686-w64-mingw32-gcc";;
564 esac
565
566 case " $RUN_COMPONENTS " in
567 *" test_zeroize "*) check_tools "gdb";;
568 esac
569
570 case " $RUN_COMPONENTS " in
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000571 *_armcc*)
Gilles Peskine87964262019-01-06 22:40:00 +0000572 ARMC5_CC="$ARMC5_BIN_DIR/armcc"
573 ARMC5_AR="$ARMC5_BIN_DIR/armar"
Gilles Peskine18487f62020-04-30 23:11:54 +0200574 ARMC5_FROMELF="$ARMC5_BIN_DIR/fromelf"
Gilles Peskine87964262019-01-06 22:40:00 +0000575 ARMC6_CC="$ARMC6_BIN_DIR/armclang"
576 ARMC6_AR="$ARMC6_BIN_DIR/armar"
Gilles Peskine18487f62020-04-30 23:11:54 +0200577 ARMC6_FROMELF="$ARMC6_BIN_DIR/fromelf"
578 check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC5_FROMELF" \
579 "$ARMC6_CC" "$ARMC6_AR" "$ARMC6_FROMELF";;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000580 esac
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000581
582 msg "info: output_env.sh"
583 case $RUN_COMPONENTS in
584 *_armcc*)
585 set "$@" ARMC5_CC="$ARMC5_CC" ARMC6_CC="$ARMC6_CC" RUN_ARMCC=1;;
586 *) set "$@" RUN_ARMCC=0;;
587 esac
588 "$@" scripts/output_env.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100589}
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100590
Gilles Peskine192c72f2017-12-21 15:59:21 +0100591
592
593################################################################
594#### Basic checks
595################################################################
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100596
597#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200598# Test Suites to be executed
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100599#
Manuel Pégourié-Gonnard3d404b42015-07-08 21:59:16 +0100600# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200601# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100602# 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 +0200603# time, so start with a GCC build).
604# 2. Minimize total running time, by avoiding useless rebuilds
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100605#
Manuel Pégourié-Gonnard259b08a2016-01-08 16:27:41 +0100606# Indicative running times are given for reference.
607
Gilles Peskine8f073122018-11-27 15:58:47 +0100608component_check_recursion () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200609 msg "Check: recursion.pl" # < 1s
Gilles Peskine8f073122018-11-27 15:58:47 +0100610 record_status tests/scripts/recursion.pl library/*.c
611}
Janos Follathb72c6782016-07-19 14:54:17 +0100612
Gilles Peskine8f073122018-11-27 15:58:47 +0100613component_check_generated_files () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200614 msg "Check: freshness of generated source files" # < 1s
Gilles Peskine8f073122018-11-27 15:58:47 +0100615 record_status tests/scripts/check-generated-files.sh
616}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200617
Gilles Peskine8f073122018-11-27 15:58:47 +0100618component_check_doxy_blocks () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200619 msg "Check: doxygen markup outside doxygen blocks" # < 1s
Gilles Peskine8f073122018-11-27 15:58:47 +0100620 record_status tests/scripts/check-doxy-blocks.pl
621}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200622
Gilles Peskine8f073122018-11-27 15:58:47 +0100623component_check_files () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200624 msg "Check: file sanity checks (permissions, encodings)" # < 1s
Gilles Peskine8f073122018-11-27 15:58:47 +0100625 record_status tests/scripts/check-files.py
626}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200627
Gilles Peskine30e0bb42020-05-10 17:40:49 +0200628component_check_changelog () {
629 msg "Check: changelog entries" # < 1s
630 rm -f ChangeLog.new
631 record_status scripts/assemble_changelog.py -o ChangeLog.new
632 if [ -e ChangeLog.new ]; then
633 # Show the diff for information. It isn't an error if the diff is
634 # non-empty.
635 diff -u ChangeLog ChangeLog.new || true
636 rm ChangeLog.new
637 fi
638}
639
Gilles Peskine8f073122018-11-27 15:58:47 +0100640component_check_names () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200641 msg "Check: declared and exported names (builds the library)" # < 3s
Gilles Peskine13f97dc2019-05-15 17:52:22 +0200642 record_status tests/scripts/check-names.sh -v
Gilles Peskine8f073122018-11-27 15:58:47 +0100643}
Darryl Greena07039c2018-03-13 16:48:16 +0000644
Gilles Peskine895868b2019-09-19 21:30:05 +0200645component_check_test_cases () {
646 msg "Check: test case descriptions" # < 1s
647 record_status tests/scripts/check-test-cases.py
648}
649
Gilles Peskine8f073122018-11-27 15:58:47 +0100650component_check_doxygen_warnings () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200651 msg "Check: doxygen warnings (builds the documentation)" # ~ 3s
Gilles Peskine8f073122018-11-27 15:58:47 +0100652 record_status tests/scripts/doxygen.sh
653}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200654
Gilles Peskine192c72f2017-12-21 15:59:21 +0100655
Gilles Peskine636c26a2020-03-04 20:46:15 +0100656
Gilles Peskine192c72f2017-12-21 15:59:21 +0100657################################################################
658#### Build and test many configurations and targets
659################################################################
660
Gilles Peskine7832c9f2019-04-08 17:00:15 +0200661component_test_default_out_of_box () {
662 msg "build: make, default config (out-of-box)" # ~1min
663 make
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200664 # Disable fancy stuff
Gilles Peskine717cd762019-09-27 20:21:11 +0200665 SAVE_MBEDTLS_TEST_OUTCOME_FILE="$MBEDTLS_TEST_OUTCOME_FILE"
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200666 unset MBEDTLS_TEST_OUTCOME_FILE
Gilles Peskine7832c9f2019-04-08 17:00:15 +0200667
668 msg "test: main suites make, default config (out-of-box)" # ~10s
669 make test
670
671 msg "selftest: make, default config (out-of-box)" # ~10s
Gilles Peskine97bea012020-04-23 23:37:45 +0200672 if_build_succeeded programs/test/selftest
Gilles Peskine717cd762019-09-27 20:21:11 +0200673
674 export MBEDTLS_TEST_OUTCOME_FILE="$SAVE_MBEDTLS_TEST_OUTCOME_FILE"
675 unset SAVE_MBEDTLS_TEST_OUTCOME_FILE
Gilles Peskine7832c9f2019-04-08 17:00:15 +0200676}
677
Gilles Peskine8f073122018-11-27 15:58:47 +0100678component_test_default_cmake_gcc_asan () {
679 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100680 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
681 make
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200682
Gilles Peskine8f073122018-11-27 15:58:47 +0100683 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
684 make test
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200685
Gilles Peskine97bea012020-04-23 23:37:45 +0200686 msg "test: selftest (ASan build)" # ~ 10s
687 if_build_succeeded programs/test/selftest
688
Gilles Peskine8f073122018-11-27 15:58:47 +0100689 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
690 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200691
Gilles Peskine8f073122018-11-27 15:58:47 +0100692 msg "test: compat.sh (ASan build)" # ~ 6 min
693 if_build_succeeded tests/compat.sh
Piotr Nowicki9978e6e2020-04-07 16:07:05 +0200694
695 msg "test: context-info.sh (ASan build)" # ~ 15 sec
696 if_build_succeeded tests/context-info.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100697}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200698
Hanno Becker01635512019-02-26 14:27:09 +0000699component_test_full_cmake_gcc_asan () {
700 msg "build: full config, cmake, gcc, ASan"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200701 scripts/config.py full
Hanno Becker01635512019-02-26 14:27:09 +0000702 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
703 make
704
705 msg "test: main suites (inc. selftests) (full config, ASan build)"
706 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +0100707
Gilles Peskine97bea012020-04-23 23:37:45 +0200708 msg "test: selftest (ASan build)" # ~ 10s
709 if_build_succeeded programs/test/selftest
710
Gilles Peskine636c26a2020-03-04 20:46:15 +0100711 msg "test: ssl-opt.sh (full config, ASan build)"
712 if_build_succeeded tests/ssl-opt.sh
713
714 msg "test: compat.sh (full config, ASan build)"
715 if_build_succeeded tests/compat.sh
Piotr Nowicki9978e6e2020-04-07 16:07:05 +0200716
717 msg "test: context-info.sh (full config, ASan build)" # ~ 15 sec
718 if_build_succeeded tests/context-info.sh
Gilles Peskine636c26a2020-03-04 20:46:15 +0100719}
720
721component_test_zlib_make() {
722 msg "build: zlib enabled, make"
723 scripts/config.py set MBEDTLS_ZLIB_SUPPORT
724 make ZLIB=1 CFLAGS='-Werror -O1'
725
726 msg "test: main suites (zlib, make)"
727 make test
728
729 msg "test: ssl-opt.sh (zlib, make)"
730 if_build_succeeded tests/ssl-opt.sh
731}
732support_test_zlib_make () {
733 base=support_test_zlib_$$
734 cat <<'EOF' > ${base}.c
735#include "zlib.h"
736int main(void) { return 0; }
737EOF
738 gcc -o ${base}.exe ${base}.c -lz 2>/dev/null
739 ret=$?
740 rm -f ${base}.*
741 return $ret
742}
743
744component_test_zlib_cmake() {
745 msg "build: zlib enabled, cmake"
746 scripts/config.py set MBEDTLS_ZLIB_SUPPORT
747 cmake -D ENABLE_ZLIB_SUPPORT=On -D CMAKE_BUILD_TYPE:String=Check .
748 make
749
750 msg "test: main suites (zlib, cmake)"
751 make test
752
753 msg "test: ssl-opt.sh (zlib, cmake)"
754 if_build_succeeded tests/ssl-opt.sh
755}
756support_test_zlib_cmake () {
757 support_test_zlib_make "$@"
Manuel Pégourié-Gonnardf2e29022020-01-24 10:17:20 +0100758}
Manuel Pégourié-Gonnard95e04492020-01-02 11:45:12 +0100759
Gilles Peskine782f4112018-11-27 16:11:09 +0100760component_test_ref_configs () {
761 msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
762 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
763 record_status tests/scripts/test-ref-configs.pl
764}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200765
Gilles Peskine8f073122018-11-27 15:58:47 +0100766component_test_sslv3 () {
767 msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200768 scripts/config.py set MBEDTLS_SSL_PROTO_SSL3
Gilles Peskine8f073122018-11-27 15:58:47 +0100769 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
770 make
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200771
Gilles Peskine8f073122018-11-27 15:58:47 +0100772 msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
773 make test
Simon Butcher3ea7f522016-03-07 23:22:10 +0000774
Gilles Peskine8f073122018-11-27 15:58:47 +0100775 msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
776 if_build_succeeded tests/compat.sh -m 'tls1 tls1_1 tls1_2 dtls1 dtls1_2'
777 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
Simon Butcher3ea7f522016-03-07 23:22:10 +0000778
Gilles Peskine8f073122018-11-27 15:58:47 +0100779 msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
780 if_build_succeeded tests/ssl-opt.sh
Piotr Nowicki9978e6e2020-04-07 16:07:05 +0200781
782 msg "build: SSLv3 - context-info.sh (ASan build)" # ~ 15 sec
783 if_build_succeeded tests/context-info.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100784}
Simon Butcher3ea7f522016-03-07 23:22:10 +0000785
Gilles Peskine8f073122018-11-27 15:58:47 +0100786component_test_no_renegotiation () {
787 msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200788 scripts/config.py unset MBEDTLS_SSL_RENEGOTIATION
Gilles Peskine8f073122018-11-27 15:58:47 +0100789 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
790 make
Simon Butcher3ea7f522016-03-07 23:22:10 +0000791
Gilles Peskine8f073122018-11-27 15:58:47 +0100792 msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
793 make test
Hanno Becker134c2ab2017-10-12 15:29:50 +0100794
Gilles Peskine8f073122018-11-27 15:58:47 +0100795 msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
796 if_build_succeeded tests/ssl-opt.sh
797}
Hanno Becker134c2ab2017-10-12 15:29:50 +0100798
Gilles Peskine636c26a2020-03-04 20:46:15 +0100799component_test_no_pem_no_fs () {
800 msg "build: Default + !MBEDTLS_PEM_PARSE_C + !MBEDTLS_FS_IO (ASan build)"
801 scripts/config.py unset MBEDTLS_PEM_PARSE_C
802 scripts/config.py unset MBEDTLS_FS_IO
803 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C # requires a filesystem
804 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA ITS
805 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
806 make
807
808 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - main suites (inc. selftests) (ASan build)" # ~ 50s
809 make test
810
811 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - ssl-opt.sh (ASan build)" # ~ 6 min
812 if_build_succeeded tests/ssl-opt.sh
813}
814
Gilles Peskine8f073122018-11-27 15:58:47 +0100815component_test_rsa_no_crt () {
816 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200817 scripts/config.py set MBEDTLS_RSA_NO_CRT
Gilles Peskine8f073122018-11-27 15:58:47 +0100818 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
819 make
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +0100820
Gilles Peskine8f073122018-11-27 15:58:47 +0100821 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
822 make test
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100823
Gilles Peskine8f073122018-11-27 15:58:47 +0100824 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
825 if_build_succeeded tests/ssl-opt.sh -f RSA
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100826
Gilles Peskine8f073122018-11-27 15:58:47 +0100827 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
828 if_build_succeeded tests/compat.sh -t RSA
Piotr Nowicki9978e6e2020-04-07 16:07:05 +0200829
830 msg "test: RSA_NO_CRT - RSA-related part of context-info.sh (ASan build)" # ~ 15 sec
831 if_build_succeeded tests/context-info.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100832}
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100833
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +0200834component_test_no_ctr_drbg () {
835 msg "build: Full minus CTR_DRBG"
836 scripts/config.py full
837 scripts/config.py unset MBEDTLS_CTR_DRBG_C
838 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C # requires CTR_DRBG
839 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA Crypto
840 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C # requires PSA Crypto
841 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO # requires PSA Crypto
842
843 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
844 make
845
846 msg "test: no CTR_DRBG"
847 make test
848
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +0200849 # no ssl-opt.sh/compat.sh as they all depend on CTR_DRBG so far
850}
851
852component_test_no_hmac_drbg () {
853 msg "build: Full minus HMAC_DRBG"
854 scripts/config.py full
855 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
856 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
857
858 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
859 make
860
861 msg "test: no HMAC_DRBG"
862 make test
863
864 # No ssl-opt.sh/compat.sh as they never use HMAC_DRBG so far,
865 # so there's little value in running those lengthy tests here.
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +0200866}
867
Manuel Pégourié-Gonnard1a3f9ed2020-05-19 12:38:31 +0200868component_test_ecp_no_internal_rng () {
869 msg "build: Default plus ECP_NO_INTERNAL_RNG minus DRBG modules"
870 scripts/config.py set MBEDTLS_ECP_NO_INTERNAL_RNG
871 scripts/config.py unset MBEDTLS_CTR_DRBG_C
872 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
873 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
874 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C # requires a DRBG
875 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA Crypto
876
877 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
878 make
879
880 msg "test: ECP_NO_INTERNAL_RNG, no DRBG module"
881 make test
882
883 # no SSL tests as they all depend on having a DRBG
884}
885
Manuel Pégourié-Gonnard53fb66d2020-06-04 09:43:14 +0200886component_test_ecp_restartable_no_internal_rng () {
887 msg "build: Default plus ECP_RESTARTABLE and ECP_NO_INTERNAL_RNG, no DRBG"
888 scripts/config.py set MBEDTLS_ECP_NO_INTERNAL_RNG
889 scripts/config.py set MBEDTLS_ECP_RESTARTABLE
890 scripts/config.py unset MBEDTLS_CTR_DRBG_C
891 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
892 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
893 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C # requires CTR_DRBG
894 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA Crypto
895
896 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
897 make
898
899 msg "test: ECP_RESTARTABLE and ECP_NO_INTERNAL_RNG, no DRBG module"
900 make test
901
902 # no SSL tests as they all depend on having a DRBG
903}
904
Gilles Peskine636c26a2020-03-04 20:46:15 +0100905component_test_new_ecdh_context () {
906 msg "build: new ECDH context (ASan build)" # ~ 6 min
907 scripts/config.py unset MBEDTLS_ECDH_LEGACY_CONTEXT
908 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
909 make
910
911 msg "test: new ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
912 make test
913
914 msg "test: new ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
915 if_build_succeeded tests/ssl-opt.sh -f ECDH
916
917 msg "test: new ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
918 # Exclude some symmetric ciphers that are redundant here to gain time.
919 if_build_succeeded tests/compat.sh -f ECDH -V NO -e 'ARCFOUR\|ARIA\|CAMELLIA\|CHACHA\|DES\|RC4'
920}
921
922component_test_everest () {
923 msg "build: Everest ECDH context (ASan build)" # ~ 6 min
924 scripts/config.py unset MBEDTLS_ECDH_LEGACY_CONTEXT
925 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
926 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Asan .
927 make
928
929 msg "test: Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
930 make test
931
932 msg "test: Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
933 if_build_succeeded tests/ssl-opt.sh -f ECDH
934
935 msg "test: Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
936 # Exclude some symmetric ciphers that are redundant here to gain time.
937 if_build_succeeded tests/compat.sh -f ECDH -V NO -e 'ARCFOUR\|ARIA\|CAMELLIA\|CHACHA\|DES\|RC4'
938}
939
Gilles Peskine8f073122018-11-27 15:58:47 +0100940component_test_small_ssl_out_content_len () {
941 msg "build: small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200942 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 16384
943 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
Gilles Peskine8f073122018-11-27 15:58:47 +0100944 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
945 make
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100946
Gilles Peskine8f073122018-11-27 15:58:47 +0100947 msg "test: small SSL_OUT_CONTENT_LEN - ssl-opt.sh MFL and large packet tests"
948 if_build_succeeded tests/ssl-opt.sh -f "Max fragment\|Large packet"
949}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000950
Gilles Peskine8f073122018-11-27 15:58:47 +0100951component_test_small_ssl_in_content_len () {
952 msg "build: small SSL_IN_CONTENT_LEN (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200953 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 4096
954 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 16384
Gilles Peskine8f073122018-11-27 15:58:47 +0100955 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
956 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000957
Gilles Peskine8f073122018-11-27 15:58:47 +0100958 msg "test: small SSL_IN_CONTENT_LEN - ssl-opt.sh MFL tests"
959 if_build_succeeded tests/ssl-opt.sh -f "Max fragment"
960}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000961
Gilles Peskine8f073122018-11-27 15:58:47 +0100962component_test_small_ssl_dtls_max_buffering () {
963 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200964 scripts/config.py set MBEDTLS_SSL_DTLS_MAX_BUFFERING 1000
Gilles Peskine8f073122018-11-27 15:58:47 +0100965 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
966 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000967
Gilles Peskine8f073122018-11-27 15:58:47 +0100968 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0 - ssl-opt.sh specific reordering test"
969 if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer out-of-order hs msg before reassembling next, free buffered msg"
970}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100971
Gilles Peskine8f073122018-11-27 15:58:47 +0100972component_test_small_mbedtls_ssl_dtls_max_buffering () {
973 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1"
Gilles Peskine636c26a2020-03-04 20:46:15 +0100974 scripts/config.py set MBEDTLS_SSL_DTLS_MAX_BUFFERING 190
Gilles Peskine8f073122018-11-27 15:58:47 +0100975 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
976 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100977
Gilles Peskine8f073122018-11-27 15:58:47 +0100978 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1 - ssl-opt.sh specific reordering test"
979 if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer encrypted Finished message, drop for fragmented NewSessionTicket"
980}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100981
Gilles Peskine75cc7712019-09-06 19:47:17 +0200982component_test_psa_collect_statuses () {
983 msg "build+test: psa_collect_statuses" # ~30s
Gilles Peskine3bdd4122019-07-27 23:52:53 +0200984 scripts/config.py full
Gilles Peskine75cc7712019-09-06 19:47:17 +0200985 record_status tests/scripts/psa_collect_statuses.py
986 # Check that psa_crypto_init() succeeded at least once
987 record_status grep -q '^0:psa_crypto_init:' tests/statuses.log
988 rm -f tests/statuses.log
989}
990
Gilles Peskine8f073122018-11-27 15:58:47 +0100991component_test_full_cmake_clang () {
992 msg "build: cmake, full config, clang" # ~ 50s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200993 scripts/config.py full
Gilles Peskine8f073122018-11-27 15:58:47 +0100994 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check -D ENABLE_TESTING=On .
995 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100996
k-stachowiak0291cb72019-06-26 15:52:12 +0200997 msg "test: main suites (full config, clang)" # ~ 5s
Gilles Peskine8f073122018-11-27 15:58:47 +0100998 make test
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100999
k-stachowiak0291cb72019-06-26 15:52:12 +02001000 msg "test: psa_constant_names (full config, clang)" # ~ 1s
Darryl Green45010a32019-02-06 13:43:58 +00001001 record_status tests/scripts/test_psa_constant_names.py
Gilles Peskine69e8f7f2020-02-26 19:51:43 +01001002
Gilles Peskine8f073122018-11-27 15:58:47 +01001003 msg "test: ssl-opt.sh default, ECJPAKE, SSL async (full config)" # ~ 1s
1004 if_build_succeeded tests/ssl-opt.sh -f 'Default\|ECJPAKE\|SSL async private'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +02001005
Andres Amaya Garcia2dadab72019-01-08 21:42:27 +00001006 msg "test: compat.sh RC4, DES, 3DES & NULL (full config)" # ~ 2 min
Andres Amaya Garcia419bd002019-02-19 20:20:57 +00001007 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" GNUTLS_CLI="$GNUTLS_LEGACY_CLI" GNUTLS_SERV="$GNUTLS_LEGACY_SERV" tests/compat.sh -e '^$' -f 'NULL\|DES\|RC4\|ARCFOUR'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +02001008
Gilles Peskine8f073122018-11-27 15:58:47 +01001009 msg "test: compat.sh ARIA + ChachaPoly"
1010 if_build_succeeded env OPENSSL_CMD="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
1011}
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +02001012
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001013component_test_default_no_deprecated () {
Gilles Peskine8386ea22020-04-30 09:07:29 +02001014 # Test that removing the deprecated features from the default
1015 # configuration leaves something consistent.
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001016 msg "build: make, default + MBEDTLS_DEPRECATED_REMOVED" # ~ 30s
1017 scripts/config.py set MBEDTLS_DEPRECATED_REMOVED
1018 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra'
1019
1020 msg "test: make, default + MBEDTLS_DEPRECATED_REMOVED" # ~ 5s
1021 make test
1022}
1023
1024component_test_full_no_deprecated () {
Gilles Peskine30de2e82020-04-20 21:39:22 +02001025 msg "build: make, full_no_deprecated config" # ~ 30s
1026 scripts/config.py full_no_deprecated
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001027 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra'
1028
Gilles Peskine30de2e82020-04-20 21:39:22 +02001029 msg "test: make, full_no_deprecated config" # ~ 5s
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001030 make test
1031}
1032
Gilles Peskine8386ea22020-04-30 09:07:29 +02001033component_test_full_no_deprecated_deprecated_warning () {
1034 # Test that there is nothing deprecated in "full_no_deprecated".
1035 # A deprecated feature would trigger a warning (made fatal) from
1036 # MBEDTLS_DEPRECATED_WARNING.
Gilles Peskine30de2e82020-04-20 21:39:22 +02001037 msg "build: make, full_no_deprecated config, MBEDTLS_DEPRECATED_WARNING" # ~ 30s
1038 scripts/config.py full_no_deprecated
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001039 scripts/config.py unset MBEDTLS_DEPRECATED_REMOVED
1040 scripts/config.py set MBEDTLS_DEPRECATED_WARNING
1041 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra'
1042
Gilles Peskine30de2e82020-04-20 21:39:22 +02001043 msg "test: make, full_no_deprecated config, MBEDTLS_DEPRECATED_WARNING" # ~ 5s
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001044 make test
1045}
1046
Gilles Peskine8386ea22020-04-30 09:07:29 +02001047component_test_full_deprecated_warning () {
1048 # Test that when MBEDTLS_DEPRECATED_WARNING is enabled, the build passes
1049 # with only certain whitelisted types of warnings.
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001050 msg "build: make, full config + MBEDTLS_DEPRECATED_WARNING, expect warnings" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001051 scripts/config.py full
1052 scripts/config.py set MBEDTLS_DEPRECATED_WARNING
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001053 # Expect warnings from '#warning' directives in check_config.h.
1054 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-error=cpp' lib programs
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +01001055
Gilles Peskine8386ea22020-04-30 09:07:29 +02001056 msg "build: make tests, full config + MBEDTLS_DEPRECATED_WARNING, expect warnings" # ~ 30s
1057 # Set MBEDTLS_TEST_DEPRECATED to enable tests for deprecated features.
1058 # By default those are disabled when MBEDTLS_DEPRECATED_WARNING is set.
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001059 # Expect warnings from '#warning' directives in check_config.h and
1060 # from the use of deprecated functions in test suites.
1061 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-error=deprecated-declarations -Wno-error=cpp -DMBEDTLS_TEST_DEPRECATED' tests
Gilles Peskine841b14b2019-11-26 17:37:37 +01001062
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001063 msg "test: full config + MBEDTLS_TEST_DEPRECATED" # ~ 30s
1064 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01001065}
Jaeden Ameroed93bdc2018-11-02 16:57:24 +00001066
Gilles Peskineec541fe2020-01-31 14:24:14 +01001067# Check that the specified libraries exist and are empty.
1068are_empty_libraries () {
1069 nm "$@" >/dev/null 2>/dev/null
1070 ! nm "$@" 2>/dev/null | grep -v ':$' | grep .
1071}
1072
1073component_build_crypto_default () {
1074 msg "build: make, crypto only"
1075 scripts/config.py crypto
Gilles Peskine6bb39152020-02-03 11:59:20 +01001076 make CFLAGS='-O1 -Werror'
Gilles Peskineec541fe2020-01-31 14:24:14 +01001077 if_build_succeeded are_empty_libraries library/libmbedx509.* library/libmbedtls.*
1078}
1079
1080component_build_crypto_full () {
1081 msg "build: make, crypto only, full config"
1082 scripts/config.py crypto_full
Gilles Peskine6bb39152020-02-03 11:59:20 +01001083 make CFLAGS='-O1 -Werror'
Gilles Peskineec541fe2020-01-31 14:24:14 +01001084 if_build_succeeded are_empty_libraries library/libmbedx509.* library/libmbedtls.*
1085}
1086
1087component_build_crypto_baremetal () {
1088 msg "build: make, crypto only, baremetal config"
1089 scripts/config.py crypto_baremetal
Gilles Peskine6bb39152020-02-03 11:59:20 +01001090 make CFLAGS='-O1 -Werror'
Gilles Peskineec541fe2020-01-31 14:24:14 +01001091 if_build_succeeded are_empty_libraries library/libmbedx509.* library/libmbedtls.*
1092}
1093
Gilles Peskine8f073122018-11-27 15:58:47 +01001094component_test_depends_curves () {
1095 msg "test/build: curves.pl (gcc)" # ~ 4 min
Gilles Peskine8f073122018-11-27 15:58:47 +01001096 record_status tests/scripts/curves.pl
1097}
Jaeden Ameroacaabe72018-11-07 11:52:52 +00001098
Gilles Peskine8f073122018-11-27 15:58:47 +01001099component_test_depends_hashes () {
1100 msg "test/build: depends-hashes.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +01001101 record_status tests/scripts/depends-hashes.pl
1102}
Jaeden Ameroacaabe72018-11-07 11:52:52 +00001103
Gilles Peskine8f073122018-11-27 15:58:47 +01001104component_test_depends_pkalgs () {
1105 msg "test/build: depends-pkalgs.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +01001106 record_status tests/scripts/depends-pkalgs.pl
1107}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01001108
Gilles Peskine8f073122018-11-27 15:58:47 +01001109component_build_key_exchanges () {
1110 msg "test/build: key-exchanges (gcc)" # ~ 1 min
Gilles Peskine8f073122018-11-27 15:58:47 +01001111 record_status tests/scripts/key-exchanges.pl
1112}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01001113
Gilles Peskine8f073122018-11-27 15:58:47 +01001114component_build_default_make_gcc_and_cxx () {
1115 msg "build: Unix make, -Os (gcc)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +01001116 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01001117
Gilles Peskine8f073122018-11-27 15:58:47 +01001118 msg "test: verify header list in cpp_dummy_build.cpp"
1119 record_status check_headers_in_cpp
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01001120
Gilles Peskine8f073122018-11-27 15:58:47 +01001121 msg "build: Unix make, incremental g++"
1122 make TEST_CPP=1
1123}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01001124
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001125component_test_no_use_psa_crypto_full_cmake_asan() {
1126 # full minus MBEDTLS_USE_PSA_CRYPTO: run the same set of tests as basic-build-test.sh
Gilles Peskinedc3a1792019-09-03 11:42:04 +02001127 msg "build: cmake, full config minus MBEDTLS_USE_PSA_CRYPTO, ASan"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001128 scripts/config.py full
1129 scripts/config.py set MBEDTLS_ECP_RESTARTABLE # not using PSA, so enable restartable ECC
1130 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C
1131 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1132 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C
Gilles Peskinedc6d8382020-04-12 14:21:55 +02001133 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001134 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
Manuel Pégourié-Gonnardd8167e82019-02-01 11:12:52 +01001135 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Andrzej Kurekde5a0072019-02-01 07:03:03 -05001136 make
Manuel Pégourié-Gonnard43be6cd2017-06-20 09:53:42 +02001137
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001138 msg "test: main suites (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -05001139 make test
Manuel Pégourié-Gonnard503a5ef2015-10-23 09:04:45 +02001140
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001141 msg "test: ssl-opt.sh (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -05001142 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001143
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001144 msg "test: compat.sh default (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -05001145 if_build_succeeded tests/compat.sh
Andrzej Kurek991f9fe2018-07-02 09:08:21 -04001146
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001147 msg "test: compat.sh RC4, DES & NULL (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -05001148 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 -05001149
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001150 msg "test: compat.sh ARIA + ChachaPoly (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -05001151 if_build_succeeded env OPENSSL_CMD="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
1152}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -05001153
Gilles Peskineadcde5e2019-06-12 16:05:50 +02001154component_test_check_params_functionality () {
1155 msg "build+test: MBEDTLS_CHECK_PARAMS functionality"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001156 scripts/config.py full # includes CHECK_PARAMS
Gilles Peskineadcde5e2019-06-12 16:05:50 +02001157 # Make MBEDTLS_PARAM_FAILED call mbedtls_param_failed().
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001158 scripts/config.py unset MBEDTLS_CHECK_PARAMS_ASSERT
Gilles Peskineadcde5e2019-06-12 16:05:50 +02001159 # Only build and run tests. Do not build sample programs, because
1160 # they don't have a mbedtls_param_failed() function.
1161 make CC=gcc CFLAGS='-Werror -O1' lib test
1162}
1163
Gilles Peskineb28636b2019-01-02 19:06:24 +01001164component_test_check_params_without_platform () {
1165 msg "build+test: MBEDTLS_CHECK_PARAMS without MBEDTLS_PLATFORM_C"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001166 scripts/config.py full # includes CHECK_PARAMS
Gilles Peskineadcde5e2019-06-12 16:05:50 +02001167 # Keep MBEDTLS_PARAM_FAILED as assert.
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001168 scripts/config.py unset MBEDTLS_PLATFORM_EXIT_ALT
1169 scripts/config.py unset MBEDTLS_PLATFORM_TIME_ALT
1170 scripts/config.py unset MBEDTLS_PLATFORM_FPRINTF_ALT
1171 scripts/config.py unset MBEDTLS_PLATFORM_MEMORY
Gilles Peskine32e889d2020-04-12 23:43:28 +02001172 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001173 scripts/config.py unset MBEDTLS_PLATFORM_PRINTF_ALT
1174 scripts/config.py unset MBEDTLS_PLATFORM_SNPRINTF_ALT
1175 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
1176 scripts/config.py unset MBEDTLS_PLATFORM_C
Gilles Peskineb28636b2019-01-02 19:06:24 +01001177 make CC=gcc CFLAGS='-Werror -O1' all test
1178}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -05001179
Gilles Peskineb28636b2019-01-02 19:06:24 +01001180component_test_check_params_silent () {
1181 msg "build+test: MBEDTLS_CHECK_PARAMS with alternative MBEDTLS_PARAM_FAILED()"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001182 scripts/config.py full # includes CHECK_PARAMS
Gilles Peskineadcde5e2019-06-12 16:05:50 +02001183 # Set MBEDTLS_PARAM_FAILED to nothing.
Gilles Peskineb28636b2019-01-02 19:06:24 +01001184 sed -i 's/.*\(#define MBEDTLS_PARAM_FAILED( cond )\).*/\1/' "$CONFIG_H"
1185 make CC=gcc CFLAGS='-Werror -O1' all test
1186}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -05001187
Gilles Peskine8f073122018-11-27 15:58:47 +01001188component_test_no_platform () {
1189 # Full configuration build, without platform support, file IO and net sockets.
1190 # This should catch missing mbedtls_printf definitions, and by disabling file
1191 # IO, it should catch missing '#include <stdio.h>'
1192 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001193 scripts/config.py full
1194 scripts/config.py unset MBEDTLS_PLATFORM_C
1195 scripts/config.py unset MBEDTLS_NET_C
1196 scripts/config.py unset MBEDTLS_PLATFORM_MEMORY
1197 scripts/config.py unset MBEDTLS_PLATFORM_PRINTF_ALT
1198 scripts/config.py unset MBEDTLS_PLATFORM_FPRINTF_ALT
1199 scripts/config.py unset MBEDTLS_PLATFORM_SNPRINTF_ALT
1200 scripts/config.py unset MBEDTLS_PLATFORM_TIME_ALT
1201 scripts/config.py unset MBEDTLS_PLATFORM_EXIT_ALT
Gilles Peskine32e889d2020-04-12 23:43:28 +02001202 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001203 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
1204 scripts/config.py unset MBEDTLS_FS_IO
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001205 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001206 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
1207 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C
Gilles Peskine8f073122018-11-27 15:58:47 +01001208 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
1209 # to re-enable platform integration features otherwise disabled in C99 builds
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02001210 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -Os -D_DEFAULT_SOURCE' lib programs
1211 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os' test
Gilles Peskine8f073122018-11-27 15:58:47 +01001212}
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +00001213
Gilles Peskine8f073122018-11-27 15:58:47 +01001214component_build_no_std_function () {
1215 # catch compile bugs in _uninit functions
1216 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001217 scripts/config.py full
1218 scripts/config.py set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
1219 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskine32e889d2020-04-12 23:43:28 +02001220 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02001221 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Gilles Peskine8f073122018-11-27 15:58:47 +01001222}
Manuel Pégourié-Gonnarddccb80b2015-06-03 10:20:33 +01001223
Gilles Peskine8f073122018-11-27 15:58:47 +01001224component_build_no_ssl_srv () {
1225 msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001226 scripts/config.py full
1227 scripts/config.py unset MBEDTLS_SSL_SRV_C
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02001228 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
Gilles Peskine8f073122018-11-27 15:58:47 +01001229}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +02001230
Gilles Peskine8f073122018-11-27 15:58:47 +01001231component_build_no_ssl_cli () {
1232 msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001233 scripts/config.py full
1234 scripts/config.py unset MBEDTLS_SSL_CLI_C
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02001235 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
Gilles Peskine8f073122018-11-27 15:58:47 +01001236}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +02001237
Gilles Peskine8f073122018-11-27 15:58:47 +01001238component_build_no_sockets () {
1239 # Note, C99 compliance can also be tested with the sockets support disabled,
1240 # as that requires a POSIX platform (which isn't the same as C99).
1241 msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001242 scripts/config.py full
1243 scripts/config.py unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
1244 scripts/config.py set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02001245 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1 -std=c99 -pedantic' lib
Gilles Peskine8f073122018-11-27 15:58:47 +01001246}
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +02001247
Andrzej Kurek69f20aa2019-09-05 09:27:47 -04001248component_test_memory_buffer_allocator_backtrace () {
1249 msg "build: default config with memory buffer allocator and backtrace enabled"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001250 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
1251 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
1252 scripts/config.py set MBEDTLS_MEMORY_BACKTRACE
1253 scripts/config.py set MBEDTLS_MEMORY_DEBUG
Andrzej Kurek69f20aa2019-09-05 09:27:47 -04001254 CC=gcc cmake .
1255 make
1256
1257 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C and MBEDTLS_MEMORY_BACKTRACE"
1258 make test
1259}
1260
1261component_test_memory_buffer_allocator () {
1262 msg "build: default config with memory buffer allocator"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001263 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
1264 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
Hanno Becker0fb9ba22019-02-26 14:34:13 +00001265 CC=gcc cmake .
1266 make
1267
1268 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C"
1269 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +01001270
1271 msg "test: ssl-opt.sh, MBEDTLS_MEMORY_BUFFER_ALLOC_C"
1272 # MBEDTLS_MEMORY_BUFFER_ALLOC is slow. Skip tests that tend to time out.
1273 if_build_succeeded tests/ssl-opt.sh -e '^DTLS proxy'
Hanno Becker0fb9ba22019-02-26 14:34:13 +00001274}
1275
Gilles Peskine8f073122018-11-27 15:58:47 +01001276component_test_no_max_fragment_length () {
1277 # Run max fragment length tests with MFL disabled
1278 msg "build: default config except MFL extension (ASan build)" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001279 scripts/config.py unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
Gilles Peskine8f073122018-11-27 15:58:47 +01001280 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1281 make
Hanno Becker5175ac62017-09-18 15:36:25 +01001282
Gilles Peskine8f073122018-11-27 15:58:47 +01001283 msg "test: ssl-opt.sh, MFL-related tests"
1284 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length"
1285}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001286
Hanno Becker545ced42019-02-19 11:10:48 +00001287component_test_asan_remove_peer_certificate () {
1288 msg "build: default config with MBEDTLS_SSL_KEEP_PEER_CERTIFICATE disabled (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001289 scripts/config.py unset MBEDTLS_SSL_KEEP_PEER_CERTIFICATE
Hanno Becker545ced42019-02-19 11:10:48 +00001290 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1291 make
1292
1293 msg "test: !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
1294 make test
1295
1296 msg "test: ssl-opt.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
1297 if_build_succeeded tests/ssl-opt.sh
1298
1299 msg "test: compat.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
1300 if_build_succeeded tests/compat.sh
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02001301
1302 msg "test: context-info.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
1303 if_build_succeeded tests/context-info.sh
Hanno Becker545ced42019-02-19 11:10:48 +00001304}
1305
Gilles Peskine8f073122018-11-27 15:58:47 +01001306component_test_no_max_fragment_length_small_ssl_out_content_len () {
1307 msg "build: no MFL extension, small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001308 scripts/config.py unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
1309 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 16384
1310 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
Gilles Peskine8f073122018-11-27 15:58:47 +01001311 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1312 make
Angus Grattonc4dd0732018-04-11 16:28:39 +10001313
Gilles Peskine8f073122018-11-27 15:58:47 +01001314 msg "test: MFL tests (disabled MFL extension case) & large packet tests"
1315 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length\|Large buffer"
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02001316
1317 msg "test: context-info.sh (disabled MFL extension case)"
1318 if_build_succeeded tests/context-info.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01001319}
Angus Grattonc4dd0732018-04-11 16:28:39 +10001320
Darryl Greenaad82f92019-12-02 10:53:11 +00001321component_test_variable_ssl_in_out_buffer_len () {
1322 msg "build: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled (ASan build)"
1323 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
1324 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1325 make
1326
1327 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
1328 make test
1329
1330 msg "test: ssl-opt.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
1331 if_build_succeeded tests/ssl-opt.sh
1332
1333 msg "test: compat.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
1334 if_build_succeeded tests/compat.sh
1335}
1336
1337component_test_variable_ssl_in_out_buffer_len_CID () {
1338 msg "build: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_DTLS_CONNECTION_ID enabled (ASan build)"
1339 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
1340 scripts/config.py set MBEDTLS_SSL_DTLS_CONNECTION_ID
1341
1342 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1343 make
1344
1345 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_DTLS_CONNECTION_ID"
1346 make test
1347
1348 msg "test: ssl-opt.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_DTLS_CONNECTION_ID enabled"
1349 if_build_succeeded tests/ssl-opt.sh
1350
1351 msg "test: compat.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_DTLS_CONNECTION_ID enabled"
1352 if_build_succeeded tests/compat.sh
1353}
1354
1355component_test_variable_ssl_in_out_buffer_len_record_splitting () {
1356 msg "build: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_CBC_RECORD_SPLITTING enabled (ASan build)"
1357 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
1358 scripts/config.py set MBEDTLS_SSL_CBC_RECORD_SPLITTING
1359
1360 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1361 make
1362
1363 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_CBC_RECORD_SPLITTING"
1364 make test
1365
1366 msg "test: ssl-opt.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_CBC_RECORD_SPLITTING enabled"
1367 if_build_succeeded tests/ssl-opt.sh
1368
1369 msg "test: compat.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_CBC_RECORD_SPLITTING enabled"
1370 if_build_succeeded tests/compat.sh
1371}
1372
Piotr Nowicki0937ed22019-11-26 16:32:40 +01001373component_test_ssl_alloc_buffer_and_mfl () {
1374 msg "build: default config with memory buffer allocator and MFL extension"
1375 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
1376 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
1377 scripts/config.py set MBEDTLS_MEMORY_DEBUG
1378 scripts/config.py set MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
1379 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
1380 CC=gcc cmake .
1381 make
1382
1383 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH, MBEDTLS_MEMORY_BUFFER_ALLOC_C, MBEDTLS_MEMORY_DEBUG and MBEDTLS_SSL_MAX_FRAGMENT_LENGTH"
1384 make test
1385
1386 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH, MBEDTLS_MEMORY_BUFFER_ALLOC_C, MBEDTLS_MEMORY_DEBUG and MBEDTLS_SSL_MAX_FRAGMENT_LENGTH"
1387 if_build_succeeded tests/ssl-opt.sh -f "Handshake memory usage"
1388}
1389
Gilles Peskine636c26a2020-03-04 20:46:15 +01001390component_test_when_no_ciphersuites_have_mac () {
1391 msg "build: when no ciphersuites have MAC"
1392 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
1393 scripts/config.py unset MBEDTLS_ARC4_C
1394 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
1395 make
1396
1397 msg "test: !MBEDTLS_SSL_SOME_MODES_USE_MAC"
1398 make test
1399
1400 msg "test ssl-opt.sh: !MBEDTLS_SSL_SOME_MODES_USE_MAC"
1401 if_build_succeeded tests/ssl-opt.sh -f 'Default\|EtM' -e 'without EtM'
1402}
1403
Gilles Peskine8f073122018-11-27 15:58:47 +01001404component_test_null_entropy () {
1405 msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001406 scripts/config.py set MBEDTLS_TEST_NULL_ENTROPY
1407 scripts/config.py set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
1408 scripts/config.py set MBEDTLS_ENTROPY_C
1409 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskine32e889d2020-04-12 23:43:28 +02001410 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001411 scripts/config.py unset MBEDTLS_ENTROPY_HARDWARE_ALT
1412 scripts/config.py unset MBEDTLS_HAVEGE_C
Gilles Peskine5fa32a72019-01-06 19:48:30 +00001413 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan -D UNSAFE_BUILD=ON .
Gilles Peskine8f073122018-11-27 15:58:47 +01001414 make
Janos Follath06c54002016-06-09 13:57:40 +01001415
Gilles Peskine8f073122018-11-27 15:58:47 +01001416 msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)"
1417 make test
1418}
Janos Follath06c54002016-06-09 13:57:40 +01001419
Gilles Peskine8f073122018-11-27 15:58:47 +01001420component_test_platform_calloc_macro () {
1421 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001422 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
1423 scripts/config.py set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
1424 scripts/config.py set MBEDTLS_PLATFORM_FREE_MACRO free
Gilles Peskine8f073122018-11-27 15:58:47 +01001425 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1426 make
Hanno Beckere5fecec2018-10-11 11:02:52 +01001427
Gilles Peskine8f073122018-11-27 15:58:47 +01001428 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
1429 make test
1430}
Hanno Beckere5fecec2018-10-11 11:02:52 +01001431
Gilles Peskinec4ef7a92019-09-17 19:04:38 +02001432component_test_malloc_0_null () {
1433 msg "build: malloc(0) returns NULL (ASan+UBSan build)"
Manuel Pégourié-Gonnard68192fc2020-03-04 10:34:47 +01001434 scripts/config.py full
Gilles Peskine004206c2019-10-21 17:11:33 +02001435 make CC=gcc CFLAGS="'-DMBEDTLS_CONFIG_FILE=\"$PWD/tests/configs/config-wrapper-malloc-0-null.h\"' $ASAN_CFLAGS -O" LDFLAGS="$ASAN_CFLAGS"
Gilles Peskinec4ef7a92019-09-17 19:04:38 +02001436
1437 msg "test: malloc(0) returns NULL (ASan+UBSan build)"
1438 make test
1439
1440 msg "selftest: malloc(0) returns NULL (ASan+UBSan build)"
1441 # Just the calloc selftest. "make test" ran the others as part of the
1442 # test suites.
1443 if_build_succeeded programs/test/selftest calloc
Gilles Peskine765d2402020-02-11 18:26:34 +01001444
1445 msg "test ssl-opt.sh: malloc(0) returns NULL (ASan+UBSan build)"
1446 # Run a subset of the tests. The choice is a balance between coverage
1447 # and time (including time indirectly wasted due to flaky tests).
1448 # The current choice is to skip tests whose description includes
1449 # "proxy", which is an approximation of skipping tests that use the
1450 # UDP proxy, which tend to be slower and flakier.
1451 if_build_succeeded tests/ssl-opt.sh -e 'proxy'
Gilles Peskinec4ef7a92019-09-17 19:04:38 +02001452}
1453
Gilles Peskine8f073122018-11-27 15:58:47 +01001454component_test_aes_fewer_tables () {
1455 msg "build: default config with AES_FEWER_TABLES enabled"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001456 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
Gilles Peskine8f073122018-11-27 15:58:47 +01001457 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01001458
Gilles Peskine8f073122018-11-27 15:58:47 +01001459 msg "test: AES_FEWER_TABLES"
1460 make test
1461}
Hanno Becker83ebf782017-07-07 12:29:15 +01001462
Gilles Peskine8f073122018-11-27 15:58:47 +01001463component_test_aes_rom_tables () {
1464 msg "build: default config with AES_ROM_TABLES enabled"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001465 scripts/config.py set MBEDTLS_AES_ROM_TABLES
Gilles Peskine8f073122018-11-27 15:58:47 +01001466 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01001467
Gilles Peskine8f073122018-11-27 15:58:47 +01001468 msg "test: AES_ROM_TABLES"
1469 make test
1470}
Hanno Becker83ebf782017-07-07 12:29:15 +01001471
Gilles Peskine8f073122018-11-27 15:58:47 +01001472component_test_aes_fewer_tables_and_rom_tables () {
1473 msg "build: default config with AES_ROM_TABLES and AES_FEWER_TABLES enabled"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001474 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
1475 scripts/config.py set MBEDTLS_AES_ROM_TABLES
Gilles Peskine8f073122018-11-27 15:58:47 +01001476 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01001477
Gilles Peskine8f073122018-11-27 15:58:47 +01001478 msg "test: AES_FEWER_TABLES + AES_ROM_TABLES"
1479 make test
1480}
1481
Gilles Peskine592f5912019-10-07 18:49:32 +02001482component_test_ctr_drbg_aes_256_sha_256 () {
1483 msg "build: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
Gilles Peskine3b46cd32020-02-18 17:56:33 +01001484 scripts/config.py full
1485 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
1486 scripts/config.py set MBEDTLS_ENTROPY_FORCE_SHA256
Gilles Peskine592f5912019-10-07 18:49:32 +02001487 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1488 make
1489
1490 msg "test: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
1491 make test
1492}
1493
1494component_test_ctr_drbg_aes_128_sha_512 () {
1495 msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)"
Gilles Peskine3b46cd32020-02-18 17:56:33 +01001496 scripts/config.py full
1497 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
1498 scripts/config.py set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
Gilles Peskine592f5912019-10-07 18:49:32 +02001499 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1500 make
1501
1502 msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)"
1503 make test
1504}
1505
1506component_test_ctr_drbg_aes_128_sha_256 () {
1507 msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
Gilles Peskine3b46cd32020-02-18 17:56:33 +01001508 scripts/config.py full
1509 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
1510 scripts/config.py set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
1511 scripts/config.py set MBEDTLS_ENTROPY_FORCE_SHA256
Gilles Peskine592f5912019-10-07 18:49:32 +02001512 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1513 make
1514
1515 msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
1516 make test
1517}
1518
Gilles Peskinef96aefe2019-07-24 14:58:38 +02001519component_test_se_default () {
1520 msg "build: default config + MBEDTLS_PSA_CRYPTO_SE_C"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001521 scripts/config.py set MBEDTLS_PSA_CRYPTO_SE_C
Gilles Peskine004206c2019-10-21 17:11:33 +02001522 make CC=clang CFLAGS="$ASAN_CFLAGS -Os" LDFLAGS="$ASAN_CFLAGS"
Gilles Peskinef96aefe2019-07-24 14:58:38 +02001523
1524 msg "test: default config + MBEDTLS_PSA_CRYPTO_SE_C"
1525 make test
1526}
1527
Gilles Peskine8f073122018-11-27 15:58:47 +01001528component_test_make_shared () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001529 msg "build/test: make shared" # ~ 40s
Andrzej Kurek232e8f92019-10-03 03:18:01 -04001530 make SHARED=1 all check
Gilles Peskine56c01612019-07-03 20:43:32 +02001531 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskine8f073122018-11-27 15:58:47 +01001532}
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +02001533
Gilles Peskinecf740502019-07-03 20:43:05 +02001534component_test_cmake_shared () {
1535 msg "build/test: cmake shared" # ~ 2min
1536 cmake -DUSE_SHARED_MBEDTLS_LIBRARY=On .
1537 make
Gilles Peskine56c01612019-07-03 20:43:32 +02001538 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskinecf740502019-07-03 20:43:05 +02001539 make test
1540}
1541
Gilles Peskineec10bf12019-09-20 19:56:06 +02001542test_build_opt () {
1543 info=$1 cc=$2; shift 2
1544 for opt in "$@"; do
1545 msg "build/test: $cc $opt, $info" # ~ 30s
Gilles Peskinee094a182020-04-14 20:08:41 +02001546 make CC="$cc" CFLAGS="$opt -std=c99 -pedantic -Wall -Wextra -Werror"
Gilles Peskineec10bf12019-09-20 19:56:06 +02001547 # We're confident enough in compilers to not run _all_ the tests,
1548 # but at least run the unit tests. In particular, runs with
1549 # optimizations use inline assembly whereas runs with -O0
1550 # skip inline assembly.
1551 make test # ~30s
1552 make clean
1553 done
1554}
1555
1556component_test_clang_opt () {
Manuel Pégourié-Gonnard68192fc2020-03-04 10:34:47 +01001557 scripts/config.py full
Gilles Peskineec10bf12019-09-20 19:56:06 +02001558 test_build_opt 'full config' clang -O0 -Os -O2
1559}
1560
1561component_test_gcc_opt () {
Manuel Pégourié-Gonnard68192fc2020-03-04 10:34:47 +01001562 scripts/config.py full
Gilles Peskineec10bf12019-09-20 19:56:06 +02001563 test_build_opt 'full config' gcc -O0 -Os -O2
1564}
1565
Gilles Peskineabf9b4d2019-07-03 20:42:16 +02001566component_build_mbedtls_config_file () {
1567 msg "build: make with MBEDTLS_CONFIG_FILE" # ~40s
1568 # Use the full config so as to catch a maximum of places where
1569 # the check of MBEDTLS_CONFIG_FILE might be missing.
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001570 scripts/config.py full
Gilles Peskineabf9b4d2019-07-03 20:42:16 +02001571 sed 's!"check_config.h"!"mbedtls/check_config.h"!' <"$CONFIG_H" >full_config.h
1572 echo '#error "MBEDTLS_CONFIG_FILE is not working"' >"$CONFIG_H"
1573 make CFLAGS="-I '$PWD' -DMBEDTLS_CONFIG_FILE='\"full_config.h\"'"
1574 rm -f full_config.h
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001575}
1576
Gilles Peskine8f073122018-11-27 15:58:47 +01001577component_test_m32_o0 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001578 # Build once with -O0, to compile out the i386 specific inline assembly
1579 msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001580 scripts/config.py full
Gilles Peskine8fd59422019-10-21 17:11:33 +02001581 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O0" LDFLAGS="-m32 $ASAN_CFLAGS"
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01001582
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001583 msg "test: i386, make, gcc -O0 (ASan build)"
1584 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01001585}
Gilles Peskine878cf602019-01-06 20:50:38 +00001586support_test_m32_o0 () {
1587 case $(uname -m) in
1588 *64*) true;;
1589 *) false;;
1590 esac
1591}
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001592
Gilles Peskine8f073122018-11-27 15:58:47 +01001593component_test_m32_o1 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001594 # Build again with -O1, to compile in the i386 specific inline assembly
1595 msg "build: i386, make, gcc -O1 (ASan build)" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001596 scripts/config.py full
Gilles Peskine8fd59422019-10-21 17:11:33 +02001597 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O1" LDFLAGS="-m32 $ASAN_CFLAGS"
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001598
1599 msg "test: i386, make, gcc -O1 (ASan build)"
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001600 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +01001601
1602 msg "test ssl-opt.sh, i386, make, gcc-O1"
1603 if_build_succeeded tests/ssl-opt.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01001604}
Gilles Peskine878cf602019-01-06 20:50:38 +00001605support_test_m32_o1 () {
1606 support_test_m32_o0 "$@"
1607}
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001608
Gilles Peskine0c6b7992019-04-12 20:29:48 +02001609component_test_m32_everest () {
1610 msg "build: i386, Everest ECDH context (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001611 scripts/config.py unset MBEDTLS_ECDH_LEGACY_CONTEXT
1612 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
Gilles Peskine8fd59422019-10-21 17:11:33 +02001613 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O2" LDFLAGS="-m32 $ASAN_CFLAGS"
Gilles Peskine0c6b7992019-04-12 20:29:48 +02001614
1615 msg "test: i386, Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
1616 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +01001617
1618 msg "test: i386, Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
1619 if_build_succeeded tests/ssl-opt.sh -f ECDH
1620
1621 msg "test: i386, Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
1622 # Exclude some symmetric ciphers that are redundant here to gain time.
1623 if_build_succeeded tests/compat.sh -f ECDH -V NO -e 'ARCFOUR\|ARIA\|CAMELLIA\|CHACHA\|DES\|RC4'
Gilles Peskine0c6b7992019-04-12 20:29:48 +02001624}
1625support_test_m32_everest () {
1626 support_test_m32_o0 "$@"
1627}
1628
Gilles Peskine8f073122018-11-27 15:58:47 +01001629component_test_mx32 () {
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001630 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001631 scripts/config.py full
Gilles Peskine5d26e7c2019-06-07 14:50:09 +02001632 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32' LDFLAGS='-mx32'
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001633
1634 msg "test: 64-bit ILP32, make, gcc"
1635 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01001636}
Gilles Peskine878cf602019-01-06 20:50:38 +00001637support_test_mx32 () {
1638 case $(uname -m) in
1639 amd64|x86_64) true;;
1640 *) false;;
1641 esac
1642}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001643
Peter Kolbus60c6da22018-12-27 06:59:04 -06001644component_test_min_mpi_window_size () {
1645 msg "build: Default + MBEDTLS_MPI_WINDOW_SIZE=1 (ASan build)" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001646 scripts/config.py set MBEDTLS_MPI_WINDOW_SIZE 1
Peter Kolbus60c6da22018-12-27 06:59:04 -06001647 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1648 make
1649
1650 msg "test: MBEDTLS_MPI_WINDOW_SIZE=1 - main suites (inc. selftests) (ASan build)" # ~ 10s
1651 make test
1652}
1653
Gilles Peskine8f073122018-11-27 15:58:47 +01001654component_test_have_int32 () {
1655 msg "build: gcc, force 32-bit bignum limbs"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001656 scripts/config.py unset MBEDTLS_HAVE_ASM
1657 scripts/config.py unset MBEDTLS_AESNI_C
1658 scripts/config.py unset MBEDTLS_PADLOCK_C
Gilles Peskine8f073122018-11-27 15:58:47 +01001659 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01001660
Gilles Peskine8f073122018-11-27 15:58:47 +01001661 msg "test: gcc, force 32-bit bignum limbs"
1662 make test
1663}
Andres Amaya Garciafe843a32017-07-20 13:21:34 +01001664
Gilles Peskine8f073122018-11-27 15:58:47 +01001665component_test_have_int64 () {
1666 msg "build: gcc, force 64-bit bignum limbs"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001667 scripts/config.py unset MBEDTLS_HAVE_ASM
1668 scripts/config.py unset MBEDTLS_AESNI_C
1669 scripts/config.py unset MBEDTLS_PADLOCK_C
Gilles Peskine8f073122018-11-27 15:58:47 +01001670 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
Gilles Peskine14c3c062018-01-29 21:25:12 +01001671
Gilles Peskine8f073122018-11-27 15:58:47 +01001672 msg "test: gcc, force 64-bit bignum limbs"
1673 make test
1674}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001675
Gilles Peskine8f073122018-11-27 15:58:47 +01001676component_test_no_udbl_division () {
1677 msg "build: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001678 scripts/config.py full
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001679 scripts/config.py set MBEDTLS_NO_UDBL_DIVISION
Gilles Peskine8f073122018-11-27 15:58:47 +01001680 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001681
Gilles Peskine8f073122018-11-27 15:58:47 +01001682 msg "test: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
1683 make test
1684}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001685
Gilles Peskine8f073122018-11-27 15:58:47 +01001686component_test_no_64bit_multiplication () {
1687 msg "build: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001688 scripts/config.py full
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001689 scripts/config.py set MBEDTLS_NO_64BIT_MULTIPLICATION
Gilles Peskine8f073122018-11-27 15:58:47 +01001690 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001691
Gilles Peskine8f073122018-11-27 15:58:47 +01001692 msg "test: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
1693 make test
1694}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001695
Gilles Peskine8f073122018-11-27 15:58:47 +01001696component_build_arm_none_eabi_gcc () {
Gilles Peskine18487f62020-04-30 23:11:54 +02001697 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001698 scripts/config.py baremetal
Gilles Peskine65375882020-04-30 22:54:00 +02001699 make CC="${ARM_NONE_EABI_GCC_PREFIX}gcc" AR="${ARM_NONE_EABI_GCC_PREFIX}ar" LD="${ARM_NONE_EABI_GCC_PREFIX}ld" CFLAGS='-Werror -Wall -Wextra -O1' lib
Gilles Peskine18487f62020-04-30 23:11:54 +02001700
1701 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1"
1702 ${ARM_NONE_EABI_GCC_PREFIX}size library/*.o
Gilles Peskine8f073122018-11-27 15:58:47 +01001703}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001704
Gilles Peskine2c897d72019-08-09 16:05:05 +02001705component_build_arm_none_eabi_gcc_arm5vte () {
Gilles Peskine18487f62020-04-30 23:11:54 +02001706 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=arm5vte" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001707 scripts/config.py baremetal
Gilles Peskine2c897d72019-08-09 16:05:05 +02001708 # Build for a target platform that's close to what Debian uses
1709 # for its "armel" distribution (https://wiki.debian.org/ArmEabiPort).
1710 # See https://github.com/ARMmbed/mbedtls/pull/2169 and comments.
1711 # It would be better to build with arm-linux-gnueabi-gcc but
1712 # we don't have that on our CI at this time.
Gilles Peskine6d061342020-04-30 18:19:32 +02001713 make CC="${ARM_NONE_EABI_GCC_PREFIX}gcc" AR="${ARM_NONE_EABI_GCC_PREFIX}ar" CFLAGS='-Werror -Wall -Wextra -march=armv5te -O1' LDFLAGS='-march=armv5te' SHELL='sh -x' lib
Gilles Peskine18487f62020-04-30 23:11:54 +02001714
1715 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=armv5te -O1"
1716 ${ARM_NONE_EABI_GCC_PREFIX}size library/*.o
Gilles Peskine93e4e032019-08-05 11:34:25 +02001717}
1718
Gilles Peskine6e2fb862020-04-30 23:00:53 +02001719component_build_arm_none_eabi_gcc_m0plus () {
1720 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus" # ~ 10s
1721 scripts/config.py baremetal
1722 make CC="${ARM_NONE_EABI_GCC_PREFIX}gcc" AR="${ARM_NONE_EABI_GCC_PREFIX}ar" LD="${ARM_NONE_EABI_GCC_PREFIX}ld" CFLAGS='-Werror -Wall -Wextra -mthumb -mcpu=cortex-m0plus -Os' lib
Gilles Peskine18487f62020-04-30 23:11:54 +02001723
1724 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus -Os"
1725 ${ARM_NONE_EABI_GCC_PREFIX}size library/*.o
Gilles Peskine6e2fb862020-04-30 23:00:53 +02001726}
1727
Gilles Peskine8f073122018-11-27 15:58:47 +01001728component_build_arm_none_eabi_gcc_no_udbl_division () {
Gilles Peskine6d061342020-04-30 18:19:32 +02001729 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001730 scripts/config.py baremetal
1731 scripts/config.py set MBEDTLS_NO_UDBL_DIVISION
Gilles Peskine6d061342020-04-30 18:19:32 +02001732 make CC="${ARM_NONE_EABI_GCC_PREFIX}gcc" AR="${ARM_NONE_EABI_GCC_PREFIX}ar" LD="${ARM_NONE_EABI_GCC_PREFIX}ld" CFLAGS='-Werror -Wall -Wextra' lib
Gilles Peskine8f073122018-11-27 15:58:47 +01001733 echo "Checking that software 64-bit division is not required"
1734 if_build_succeeded not grep __aeabi_uldiv library/*.o
1735}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001736
Gilles Peskine8f073122018-11-27 15:58:47 +01001737component_build_arm_none_eabi_gcc_no_64bit_multiplication () {
Gilles Peskine6d061342020-04-30 18:19:32 +02001738 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc MBEDTLS_NO_64BIT_MULTIPLICATION, make" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001739 scripts/config.py baremetal
1740 scripts/config.py set MBEDTLS_NO_64BIT_MULTIPLICATION
Gilles Peskine6d061342020-04-30 18:19:32 +02001741 make CC="${ARM_NONE_EABI_GCC_PREFIX}gcc" AR="${ARM_NONE_EABI_GCC_PREFIX}ar" LD="${ARM_NONE_EABI_GCC_PREFIX}ld" CFLAGS='-Werror -O1 -march=armv6-m -mthumb' lib
Gilles Peskine8f073122018-11-27 15:58:47 +01001742 echo "Checking that software 64-bit multiplication is not required"
1743 if_build_succeeded not grep __aeabi_lmul library/*.o
1744}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001745
Gilles Peskine8f073122018-11-27 15:58:47 +01001746component_build_armcc () {
Gilles Peskine18487f62020-04-30 23:11:54 +02001747 msg "build: ARM Compiler 5"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001748 scripts/config.py baremetal
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001749 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
Gilles Peskine18487f62020-04-30 23:11:54 +02001750
1751 msg "size: ARM Compiler 5"
1752 "$ARMC5_FROMELF" -z library/*.o
1753
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001754 make clean
Andres AG87bb5772016-09-27 15:05:15 +01001755
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001756 # ARM Compiler 6 - Target ARMv7-A
1757 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-a"
Simon Butcher940737f2017-07-23 13:42:36 +02001758
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001759 # ARM Compiler 6 - Target ARMv7-M
1760 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m"
Simon Butcher940737f2017-07-23 13:42:36 +02001761
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001762 # ARM Compiler 6 - Target ARMv8-A - AArch32
1763 armc6_build_test "--target=arm-arm-none-eabi -march=armv8.2-a"
Simon Butcher940737f2017-07-23 13:42:36 +02001764
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001765 # ARM Compiler 6 - Target ARMv8-M
1766 armc6_build_test "--target=arm-arm-none-eabi -march=armv8-m.main"
Simon Butcher940737f2017-07-23 13:42:36 +02001767
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001768 # ARM Compiler 6 - Target ARMv8-A - AArch64
1769 armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a"
Gilles Peskine8f073122018-11-27 15:58:47 +01001770}
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +01001771
Manuel Pégourié-Gonnarddd8807f2020-02-26 09:56:27 +01001772component_build_ssl_hw_record_accel() {
1773 msg "build: default config with MBEDTLS_SSL_HW_RECORD_ACCEL enabled"
1774 scripts/config.pl set MBEDTLS_SSL_HW_RECORD_ACCEL
1775 make CFLAGS='-Werror -O1'
1776}
1777
Gilles Peskine8f073122018-11-27 15:58:47 +01001778component_test_allow_sha1 () {
1779 msg "build: allow SHA1 in certificates by default"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001780 scripts/config.py set MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
Gilles Peskine8f073122018-11-27 15:58:47 +01001781 make CFLAGS='-Werror -Wall -Wextra'
1782 msg "test: allow SHA1 in certificates by default"
1783 make test
1784 if_build_succeeded tests/ssl-opt.sh -f SHA-1
1785}
Gilles Peskine2a458da2017-05-12 15:26:58 +02001786
Hanno Beckera711f6e2020-05-04 12:03:51 +01001787component_test_tls13_experimental () {
1788 msg "build: default config with MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL enabled"
1789 scripts/config.pl set MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL
1790 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1791 make
1792 msg "test: default config with MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL enabled"
1793 make test
1794}
1795
Gilles Peskine8f073122018-11-27 15:58:47 +01001796component_build_mingw () {
1797 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
Andrzej Kurek232e8f92019-10-03 03:18:01 -04001798 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 +00001799
Gilles Peskine8f073122018-11-27 15:58:47 +01001800 # note Make tests only builds the tests, but doesn't run them
Andrzej Kurek232e8f92019-10-03 03:18:01 -04001801 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror' WINDOWS_BUILD=1 tests
Gilles Peskine8f073122018-11-27 15:58:47 +01001802 make WINDOWS_BUILD=1 clean
Simon Butcher002bc622016-11-17 09:27:45 +00001803
Gilles Peskine8f073122018-11-27 15:58:47 +01001804 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
Andrzej Kurek232e8f92019-10-03 03:18:01 -04001805 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
1806 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
Gilles Peskine8f073122018-11-27 15:58:47 +01001807 make WINDOWS_BUILD=1 clean
1808}
Jaeden Amero117b8a42019-04-17 15:19:26 +01001809support_build_mingw() {
1810 case $(i686-w64-mingw32-gcc -dumpversion) in
1811 [0-5]*) false;;
1812 *) true;;
1813 esac
1814}
Manuel Pégourié-Gonnard6448bce2015-02-16 17:18:36 +01001815
Gilles Peskine8f073122018-11-27 15:58:47 +01001816component_test_memsan () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001817 msg "build: MSan (clang)" # ~ 1 min 20s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001818 scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001819 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
1820 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +02001821
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001822 msg "test: main suites (MSan)" # ~ 10s
1823 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001824
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001825 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
Gilles Peskine7c652162017-12-11 00:01:40 +01001826 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001827
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001828 # Optional part(s)
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001829
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001830 if [ "$MEMORY" -gt 0 ]; then
1831 msg "test: compat.sh (MSan)" # ~ 6 min 20s
Gilles Peskine7c652162017-12-11 00:01:40 +01001832 if_build_succeeded tests/compat.sh
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001833 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001834}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001835
Gilles Peskine69f190e2019-01-10 00:11:42 +01001836component_test_valgrind () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001837 msg "build: Release (clang)"
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001838 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
1839 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001840
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001841 msg "test: main suites valgrind (Release)"
1842 make memcheck
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001843
Gilles Peskine636c26a2020-03-04 20:46:15 +01001844 # Optional parts (slow; currently broken on OS X because programs don't
1845 # seem to receive signals under valgrind on OS X).
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001846 if [ "$MEMORY" -gt 0 ]; then
1847 msg "test: ssl-opt.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +01001848 if_build_succeeded tests/ssl-opt.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001849 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001850
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001851 if [ "$MEMORY" -gt 1 ]; then
1852 msg "test: compat.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +01001853 if_build_succeeded tests/compat.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001854 fi
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02001855
1856 if [ "$MEMORY" -gt 0 ]; then
1857 msg "test: context-info.sh --memcheck (Release)"
1858 if_build_succeeded tests/context-info.sh --memcheck
1859 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001860}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001861
Gilles Peskine8f073122018-11-27 15:58:47 +01001862component_test_cmake_out_of_source () {
1863 msg "build: cmake 'out-of-source' build"
Gilles Peskine8f073122018-11-27 15:58:47 +01001864 MBEDTLS_ROOT_DIR="$PWD"
1865 mkdir "$OUT_OF_SOURCE_DIR"
1866 cd "$OUT_OF_SOURCE_DIR"
1867 cmake "$MBEDTLS_ROOT_DIR"
1868 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001869
Gilles Peskine8f073122018-11-27 15:58:47 +01001870 msg "test: cmake 'out-of-source' build"
1871 make test
1872 # Test an SSL option that requires an auxiliary script in test/scripts/.
1873 # Also ensure that there are no error messages such as
1874 # "No such file or directory", which would indicate that some required
1875 # file is missing (ssl-opt.sh tolerates the absence of some files so
1876 # may exit with status 0 but emit errors).
1877 if_build_succeeded ./tests/ssl-opt.sh -f 'Fallback SCSV: beginning of list' 2>ssl-opt.err
1878 if [ -s ssl-opt.err ]; then
1879 cat ssl-opt.err >&2
1880 record_status [ ! -s ssl-opt.err ]
1881 rm ssl-opt.err
1882 fi
1883 cd "$MBEDTLS_ROOT_DIR"
1884 rm -rf "$OUT_OF_SOURCE_DIR"
1885 unset MBEDTLS_ROOT_DIR
1886}
Andres AGdc192212016-08-31 17:33:13 +01001887
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01001888component_test_cmake_as_subdirectory () {
1889 msg "build: cmake 'as-subdirectory' build"
1890 MBEDTLS_ROOT_DIR="$PWD"
1891
1892 cd programs/test/cmake_subproject
1893 cmake .
1894 make
1895 if_build_succeeded ./cmake_subproject
1896
1897 cd "$MBEDTLS_ROOT_DIR"
1898 unset MBEDTLS_ROOT_DIR
1899}
1900
Gilles Peskine8f073122018-11-27 15:58:47 +01001901component_test_zeroize () {
1902 # Test that the function mbedtls_platform_zeroize() is not optimized away by
1903 # different combinations of compilers and optimization flags by using an
1904 # auxiliary GDB script. Unfortunately, GDB does not return error values to the
1905 # system in all cases that the script fails, so we must manually search the
1906 # output to check whether the pass string is present and no failure strings
1907 # were printed.
Andres AGdc192212016-08-31 17:33:13 +01001908
Gilles Peskine4976e822019-01-06 19:52:22 +00001909 # Don't try to disable ASLR. We don't care about ASLR here. We do care
1910 # about a spurious message if Gdb tries and fails, so suppress that.
1911 gdb_disable_aslr=
1912 if [ -z "$(gdb -batch -nw -ex 'set disable-randomization off' 2>&1)" ]; then
1913 gdb_disable_aslr='set disable-randomization off'
1914 fi
1915
Gilles Peskine8f073122018-11-27 15:58:47 +01001916 for optimization_flag in -O2 -O3 -Ofast -Os; do
Gilles Peskine55f7c942019-01-09 22:28:21 +01001917 for compiler in clang gcc; do
1918 msg "test: $compiler $optimization_flag, mbedtls_platform_zeroize()"
1919 make programs CC="$compiler" DEBUG=1 CFLAGS="$optimization_flag"
Gilles Peskine4976e822019-01-06 19:52:22 +00001920 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 +01001921 if_build_succeeded grep "The buffer was correctly zeroized" test_zeroize.log
1922 if_build_succeeded not grep -i "error" test_zeroize.log
1923 rm -f test_zeroize.log
1924 make clean
1925 done
Andres Amaya Garcia29673812017-10-25 10:35:51 +01001926 done
Andres Amaya Garciad0d7bf62017-10-25 09:01:31 +01001927
Gilles Peskine4976e822019-01-06 19:52:22 +00001928 unset gdb_disable_aslr
Gilles Peskine8f073122018-11-27 15:58:47 +01001929}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001930
Gilles Peskine8f073122018-11-27 15:58:47 +01001931component_check_python_files () {
1932 msg "Lint: Python scripts"
1933 record_status tests/scripts/check-python-files.sh
1934}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001935
Gilles Peskine8f073122018-11-27 15:58:47 +01001936component_check_generate_test_code () {
1937 msg "uint test: generate_test_code.py"
1938 record_status ./tests/scripts/test_generate_test_code.py
1939}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001940
1941################################################################
1942#### Termination
1943################################################################
1944
Gilles Peskine8f073122018-11-27 15:58:47 +01001945post_report () {
1946 msg "Done, cleaning up"
1947 cleanup
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001948
Gilles Peskine8f073122018-11-27 15:58:47 +01001949 final_report
1950}
1951
1952
1953
1954################################################################
1955#### Run all the things
1956################################################################
1957
Gilles Peskinee48351a2018-11-27 16:06:30 +01001958# Run one component and clean up afterwards.
Gilles Peskine8f073122018-11-27 15:58:47 +01001959run_component () {
Gilles Peskine608953e2019-01-02 18:57:02 +01001960 # Back up the configuration in case the component modifies it.
1961 # The cleanup function will restore it.
1962 cp -p "$CONFIG_H" "$CONFIG_BAK"
Gilles Peskineffcdeff2018-12-04 12:49:28 +01001963 current_component="$1"
Gilles Peskine9004a172019-09-16 15:20:36 +02001964 export MBEDTLS_TEST_CONFIGURATION="$current_component"
Gilles Peskine2ef377d2019-10-07 18:44:21 +02001965
1966 # Unconditionally create a seedfile that's sufficiently long.
1967 # Do this before each component, because a previous component may
1968 # have messed it up or shortened it.
1969 dd if=/dev/urandom of=./tests/seedfile bs=64 count=1
1970
1971 # Run the component code.
Gilles Peskine8f073122018-11-27 15:58:47 +01001972 "$@"
Gilles Peskine2ef377d2019-10-07 18:44:21 +02001973
1974 # Restore the build tree to a clean state.
Gilles Peskinee48351a2018-11-27 16:06:30 +01001975 cleanup
Gilles Peskine8f073122018-11-27 15:58:47 +01001976}
1977
1978# Preliminary setup
1979pre_check_environment
1980pre_initialize_variables
1981pre_parse_command_line "$@"
Gilles Peskine348fb9a2018-11-27 17:04:29 +01001982
Gilles Peskine878cf602019-01-06 20:50:38 +00001983pre_check_git
Andrzej Kurekeb508712019-02-14 07:18:59 -05001984
Gilles Peskine878cf602019-01-06 20:50:38 +00001985build_status=0
1986if [ $KEEP_GOING -eq 1 ]; then
1987 pre_setup_keep_going
Gilles Peskine92525112018-11-27 18:15:35 +01001988else
Gilles Peskine878cf602019-01-06 20:50:38 +00001989 record_status () {
1990 "$@"
1991 }
Gilles Peskine8f073122018-11-27 15:58:47 +01001992fi
Gilles Peskine67ffdaf2019-09-16 15:55:46 +02001993pre_prepare_outcome_file
Gilles Peskine878cf602019-01-06 20:50:38 +00001994pre_print_configuration
1995pre_check_tools
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001996cleanup
1997
Gilles Peskinebeb3a812019-01-06 22:11:25 +00001998# Run the requested tests.
1999for component in $RUN_COMPONENTS; do
2000 run_component "component_$component"
2001done
Gilles Peskine8f073122018-11-27 15:58:47 +01002002
2003# We're done.
Gilles Peskine878cf602019-01-06 20:50:38 +00002004post_report