blob: bbbaf748a33dc562e93ce26d4e2fb2aa286df395 [file] [log] [blame]
Andres AG31f9b5b2016-10-04 17:14:38 +01001#! /usr/bin/env sh
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01002
Simon Butcher3ea7f522016-03-07 23:22:10 +00003# all.sh
4#
SimonB2e23c822016-04-16 21:54:39 +01005# This file is part of mbed TLS (https://tls.mbed.org)
6#
Gilles Peskine192c72f2017-12-21 15:59:21 +01007# Copyright (c) 2014-2017, ARM Limited, All Rights Reserved
8
9
10
11################################################################
12#### Documentation
13################################################################
14
Simon Butcher3ea7f522016-03-07 23:22:10 +000015# Purpose
Gilles Peskine192c72f2017-12-21 15:59:21 +010016# -------
Simon Butcher3ea7f522016-03-07 23:22:10 +000017#
SimonB2e23c822016-04-16 21:54:39 +010018# To run all tests possible or available on the platform.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010019#
Gilles Peskine192c72f2017-12-21 15:59:21 +010020# Notes for users
21# ---------------
22#
SimonB2e23c822016-04-16 21:54:39 +010023# Warning: the test is destructive. It includes various build modes and
24# configurations, and can and will arbitrarily change the current CMake
Gilles Peskine192c72f2017-12-21 15:59:21 +010025# configuration. The following files must be committed into git:
26# * include/mbedtls/config.h
27# * Makefile, library/Makefile, programs/Makefile, tests/Makefile
28# After running this script, the CMake cache will be lost and CMake
29# will no longer be initialised.
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +010030#
Gilles Peskine192c72f2017-12-21 15:59:21 +010031# The script assumes the presence of a number of tools:
32# * Basic Unix tools (Windows users note: a Unix-style find must be before
33# the Windows find in the PATH)
34# * Perl
35# * GNU Make
36# * CMake
37# * GCC and Clang (recent enough for using ASan with gcc and MemSan with clang, or valgrind)
Andrzej Kurek05be06c2018-06-28 04:41:50 -040038# * G++
Gilles Peskine192c72f2017-12-21 15:59:21 +010039# * arm-gcc and mingw-gcc
40# * ArmCC 5 and ArmCC 6, unless invoked with --no-armcc
Gilles Peskine192c72f2017-12-21 15:59:21 +010041# * OpenSSL and GnuTLS command line tools, recent enough for the
42# interoperability tests. If they don't support SSLv3 then a legacy
43# version of these tools must be present as well (search for LEGACY
44# below).
45# See the invocation of check_tools below for details.
46#
47# This script must be invoked from the toplevel directory of a git
48# working copy of Mbed TLS.
49#
50# Note that the output is not saved. You may want to run
51# script -c tests/scripts/all.sh
52# or
53# tests/scripts/all.sh >all.log 2>&1
54#
55# Notes for maintainers
56# ---------------------
57#
Gilles Peskine8f073122018-11-27 15:58:47 +010058# The bulk of the code is organized into functions that follow one of the
59# following naming conventions:
60# * pre_XXX: things to do before running the tests, in order.
61# * component_XXX: independent components. They can be run in any order.
Gilles Peskinec70637a2019-01-09 22:29:17 +010062# * component_check_XXX: quick tests that aren't worth parallelizing.
63# * component_build_XXX: build things but don't run them.
64# * component_test_XXX: build and test.
Gilles Peskine878cf602019-01-06 20:50:38 +000065# * support_XXX: if support_XXX exists and returns false then
66# component_XXX is not run by default.
Gilles Peskine8f073122018-11-27 15:58:47 +010067# * post_XXX: things to do after running the tests.
68# * other: miscellaneous support functions.
69#
Gilles Peskinec70637a2019-01-09 22:29:17 +010070# Each component must start by invoking `msg` with a short informative message.
71#
72# The framework performs some cleanup tasks after each component. This
73# means that components can assume that the working directory is in a
74# cleaned-up state, and don't need to perform the cleanup themselves.
75# * Run `make clean`.
76# * Restore `include/mbedtks/config.h` from a backup made before running
77# the component.
Gilles Peskine92bff7f2019-01-09 22:29:17 +010078# * Check out `Makefile`, `library/Makefile`, `programs/Makefile` and
79# `tests/Makefile` from git. This cleans up after an in-tree use of
80# CMake.
Gilles Peskinec70637a2019-01-09 22:29:17 +010081#
82# Any command that is expected to fail must be protected so that the
83# script keeps running in --keep-going mode despite `set -e`. In keep-going
84# mode, if a protected command fails, this is logged as a failure and the
85# script will exit with a failure status once it has run all components.
86# Commands can be protected in any of the following ways:
87# * `make` is a function which runs the `make` command with protection.
88# Note that you must write `make VAR=value`, not `VAR=value make`,
89# because the `VAR=value make` syntax doesn't work with functions.
90# * Put `report_status` before the command to protect it.
91# * Put `if_build_successful` before a command. This protects it, and
92# additionally skips it if a prior invocation of `make` in the same
93# component failed.
94#
Gilles Peskine192c72f2017-12-21 15:59:21 +010095# The tests are roughly in order from fastest to slowest. This doesn't
96# have to be exact, but in general you should add slower tests towards
97# the end and fast checks near the beginning.
Gilles Peskine192c72f2017-12-21 15:59:21 +010098
99
100
101################################################################
102#### Initialization and command line parsing
103################################################################
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100104
SimonB2e23c822016-04-16 21:54:39 +0100105# Abort on errors (and uninitialised variables)
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100106set -eu
107
Gilles Peskine8f073122018-11-27 15:58:47 +0100108pre_check_environment () {
Gilles Peskinea16c2b12019-01-06 19:58:02 +0000109 if [ -d library -a -d include -a -d tests ]; then :; else
Gilles Peskine8f073122018-11-27 15:58:47 +0100110 echo "Must be run from mbed TLS root" >&2
111 exit 1
112 fi
113}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100114
Gilles Peskine8f073122018-11-27 15:58:47 +0100115pre_initialize_variables () {
116 CONFIG_H='include/mbedtls/config.h'
117 CONFIG_BAK="$CONFIG_H.bak"
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200118
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200119 append_outcome=0
Gilles Peskine8f073122018-11-27 15:58:47 +0100120 MEMORY=0
121 FORCE=0
122 KEEP_GOING=0
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100123
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200124 : ${MBEDTLS_TEST_OUTCOME_FILE=}
Gilles Peskine9004a172019-09-16 15:20:36 +0200125 : ${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 +0200126 export MBEDTLS_TEST_OUTCOME_FILE
Gilles Peskine9004a172019-09-16 15:20:36 +0200127 export MBEDTLS_TEST_PLATFORM
128
Jaeden Ameroc4cc2512019-01-30 15:35:44 +0000129 # Default commands, can be overridden by the environment
Gilles Peskine8f073122018-11-27 15:58:47 +0100130 : ${OPENSSL:="openssl"}
131 : ${OPENSSL_LEGACY:="$OPENSSL"}
132 : ${OPENSSL_NEXT:="$OPENSSL"}
133 : ${GNUTLS_CLI:="gnutls-cli"}
134 : ${GNUTLS_SERV:="gnutls-serv"}
135 : ${GNUTLS_LEGACY_CLI:="$GNUTLS_CLI"}
136 : ${GNUTLS_LEGACY_SERV:="$GNUTLS_SERV"}
137 : ${OUT_OF_SOURCE_DIR:=./mbedtls_out_of_source_build}
138 : ${ARMC5_BIN_DIR:=/usr/bin}
139 : ${ARMC6_BIN_DIR:=/usr/bin}
Andres AGdc192212016-08-31 17:33:13 +0100140
Gilles Peskine8f073122018-11-27 15:58:47 +0100141 # if MAKEFLAGS is not set add the -j option to speed up invocations of make
Gilles Peskinea1fc4b52019-01-06 20:15:26 +0000142 if [ -z "${MAKEFLAGS+set}" ]; then
Gilles Peskine8f073122018-11-27 15:58:47 +0100143 export MAKEFLAGS="-j"
144 fi
Gilles Peskine878cf602019-01-06 20:50:38 +0000145
Jaeden Amerod48e9c72019-02-07 17:43:39 +0000146 # Include more verbose output for failing tests run by CMake
147 export CTEST_OUTPUT_ON_FAILURE=1
148
Gilles Peskine8fd59422019-10-21 17:11:33 +0200149 # CFLAGS and LDFLAGS for Asan builds that don't use CMake
Gilles Peskine5ca393f2019-10-21 19:06:33 +0200150 ASAN_CFLAGS='-Werror -Wall -Wextra -fsanitize=address,undefined -fno-sanitize-recover=all'
Gilles Peskine8fd59422019-10-21 17:11:33 +0200151
Gilles Peskine878cf602019-01-06 20:50:38 +0000152 # Gather the list of available components. These are the functions
153 # defined in this script whose name starts with "component_".
154 # Parse the script with sed, because in sh there is no way to list
155 # defined functions.
156 ALL_COMPONENTS=$(sed -n 's/^ *component_\([0-9A-Z_a-z]*\) *().*/\1/p' <"$0")
157
158 # Exclude components that are not supported on this platform.
159 SUPPORTED_COMPONENTS=
160 for component in $ALL_COMPONENTS; do
161 case $(type "support_$component" 2>&1) in
162 *' function'*)
163 if ! support_$component; then continue; fi;;
164 esac
165 SUPPORTED_COMPONENTS="$SUPPORTED_COMPONENTS $component"
166 done
Gilles Peskine8f073122018-11-27 15:58:47 +0100167}
Andres AG38495a32016-07-12 16:54:33 +0100168
Gilles Peskinea28db922019-01-10 00:05:18 +0100169# Test whether the component $1 is included in the command line patterns.
170is_component_included()
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100171{
172 set -f
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000173 for pattern in $COMMAND_LINE_COMPONENTS; do
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100174 set +f
175 case ${1#component_} in $pattern) return 0;; esac
176 done
177 set +f
178 return 1
179}
Andres AG7770ea82016-10-10 15:46:20 +0100180
Simon Butcher41eeccf2016-09-07 00:07:09 +0100181usage()
Andres AGd9eba4b2016-08-26 14:42:14 +0100182{
Gilles Peskine709346a2017-12-10 23:43:39 +0100183 cat <<EOF
Gilles Peskine92525112018-11-27 18:15:35 +0100184Usage: $0 [OPTION]... [COMPONENT]...
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100185Run mbedtls release validation tests.
Gilles Peskine92525112018-11-27 18:15:35 +0100186By default, run all tests. With one or more COMPONENT, run only those.
Gilles Peskinea28db922019-01-10 00:05:18 +0100187COMPONENT can be the name of a component or a shell wildcard pattern.
188
189Examples:
190 $0 "check_*"
191 Run all sanity checks.
192 $0 --no-armcc --except test_memsan
193 Run everything except builds that require armcc and MemSan.
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100194
195Special options:
196 -h|--help Print this help and exit.
Gilles Peskine878cf602019-01-06 20:50:38 +0000197 --list-all-components List all available test components and exit.
198 --list-components List components supported on this platform and exit.
Gilles Peskine709346a2017-12-10 23:43:39 +0100199
200General options:
201 -f|--force Force the tests to overwrite any modified files.
Gilles Peskine7c652162017-12-11 00:01:40 +0100202 -k|--keep-going Run all tests and report errors at the end.
Gilles Peskine709346a2017-12-10 23:43:39 +0100203 -m|--memory Additional optional memory tests.
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200204 --append-outcome Append to the outcome file (if used).
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100205 --armcc Run ARM Compiler builds (on by default).
Gilles Peskinea28db922019-01-10 00:05:18 +0100206 --except Exclude the COMPONENTs listed on the command line,
207 instead of running only those.
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200208 --no-append-outcome Write a new outcome file and analyze it (default).
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100209 --no-armcc Skip ARM Compiler builds.
Gilles Peskine38d81652018-03-21 08:40:26 +0100210 --no-force Refuse to overwrite modified files (default).
211 --no-keep-going Stop at the first error (default).
212 --no-memory No additional memory tests (default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100213 --out-of-source-dir=<path> Directory used for CMake out-of-source build tests.
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200214 --outcome-file=<path> File where test outcomes are written (not done if
215 empty; default: \$MBEDTLS_TEST_OUTCOME_FILE).
Gilles Peskine38d81652018-03-21 08:40:26 +0100216 --random-seed Use a random seed value for randomized tests (default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100217 -r|--release-test Run this script in release mode. This fixes the seed value to 1.
218 -s|--seed Integer seed value to use for this test run.
219
220Tool path options:
221 --armc5-bin-dir=<ARMC5_bin_dir_path> ARM Compiler 5 bin directory.
222 --armc6-bin-dir=<ARMC6_bin_dir_path> ARM Compiler 6 bin directory.
223 --gnutls-cli=<GnuTLS_cli_path> GnuTLS client executable to use for most tests.
224 --gnutls-serv=<GnuTLS_serv_path> GnuTLS server executable to use for most tests.
225 --gnutls-legacy-cli=<GnuTLS_cli_path> GnuTLS client executable to use for legacy tests.
226 --gnutls-legacy-serv=<GnuTLS_serv_path> GnuTLS server executable to use for legacy tests.
227 --openssl=<OpenSSL_path> OpenSSL executable to use for most tests.
228 --openssl-legacy=<OpenSSL_path> OpenSSL executable to use for legacy tests e.g. SSLv3.
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100229 --openssl-next=<OpenSSL_path> OpenSSL executable to use for recent things like ARIA
Gilles Peskine709346a2017-12-10 23:43:39 +0100230EOF
SimonB2e23c822016-04-16 21:54:39 +0100231}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100232
233# remove built files as well as the cmake cache/config
234cleanup()
235{
Gilles Peskinea71d64c2018-03-21 12:16:57 +0100236 if [ -n "${MBEDTLS_ROOT_DIR+set}" ]; then
237 cd "$MBEDTLS_ROOT_DIR"
238 fi
239
Gilles Peskine7c652162017-12-11 00:01:40 +0100240 command make clean
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200241
Gilles Peskine31b07e22018-03-21 12:15:06 +0100242 # Remove CMake artefacts
Jaeden Amero2d0e00f2018-11-07 18:46:41 +0000243 find . -name .git -prune -o \
Gilles Peskine31b07e22018-03-21 12:15:06 +0100244 -iname CMakeFiles -exec rm -rf {} \+ -o \
245 \( -iname cmake_install.cmake -o \
246 -iname CTestTestfile.cmake -o \
247 -iname CMakeCache.txt \) -exec rm {} \+
248 # Recover files overwritten by in-tree CMake builds
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000249 rm -f include/Makefile include/mbedtls/Makefile programs/*/Makefile
Jaeden Ameroed93bdc2018-11-02 16:57:24 +0000250 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile
251 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200252
Jaeden Ameroe8451f22019-06-20 17:38:22 +0100253 # Remove any artifacts from the component_test_cmake_as_subdirectory test.
254 rm -rf programs/test/cmake_subproject/build
255 rm -f programs/test/cmake_subproject/Makefile
256 rm -f programs/test/cmake_subproject/cmake_subproject
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 Peskine8f073122018-11-27 15:58:47 +0100302 msg "build: ARM Compiler 6 ($FLAGS), make"
303 ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \
304 WARNING_CFLAGS='-xc -std=c99' make lib
305 make clean
306}
Andres AGa5cd9732016-10-17 15:23:10 +0100307
Andres AGd9eba4b2016-08-26 14:42:14 +0100308err_msg()
309{
310 echo "$1" >&2
311}
312
313check_tools()
314{
315 for TOOL in "$@"; do
Andres AG98393602017-01-31 17:04:45 +0000316 if ! `type "$TOOL" >/dev/null 2>&1`; then
Andres AGd9eba4b2016-08-26 14:42:14 +0100317 err_msg "$TOOL not found!"
318 exit 1
319 fi
320 done
321}
322
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400323check_headers_in_cpp () {
Peter Kolbus1bc1a4c2019-02-01 17:19:08 -0600324 ls include/mbedtls | grep "\.h$" >headers.txt
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400325 <programs/test/cpp_dummy_build.cpp sed -n 's/"$//; s!^#include "mbedtls/!!p' |
326 sort |
327 diff headers.txt -
328 rm headers.txt
329}
330
Gilles Peskine8f073122018-11-27 15:58:47 +0100331pre_parse_command_line () {
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000332 COMMAND_LINE_COMPONENTS=
Gilles Peskinea28db922019-01-10 00:05:18 +0100333 all_except=0
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000334 no_armcc=
SimonB2e23c822016-04-16 21:54:39 +0100335
Jaeden Amero9b90f2e2018-11-02 18:34:17 +0000336 # Note that legacy options are ignored instead of being omitted from this
337 # list of options, so invocations that worked with previous version of
338 # all.sh will still run and work properly.
Gilles Peskine8f073122018-11-27 15:58:47 +0100339 while [ $# -gt 0 ]; do
Gilles Peskine55f7c942019-01-09 22:28:21 +0100340 case "$1" in
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200341 --append-outcome) append_outcome=1;;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000342 --armcc) no_armcc=;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100343 --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
344 --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000345 --except) all_except=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100346 --force|-f) FORCE=1;;
347 --gnutls-cli) shift; GNUTLS_CLI="$1";;
348 --gnutls-legacy-cli) shift; GNUTLS_LEGACY_CLI="$1";;
349 --gnutls-legacy-serv) shift; GNUTLS_LEGACY_SERV="$1";;
350 --gnutls-serv) shift; GNUTLS_SERV="$1";;
351 --help|-h) usage; exit;;
352 --keep-going|-k) KEEP_GOING=1;;
Gilles Peskine878cf602019-01-06 20:50:38 +0000353 --list-all-components) printf '%s\n' $ALL_COMPONENTS; exit;;
354 --list-components) printf '%s\n' $SUPPORTED_COMPONENTS; exit;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100355 --memory|-m) MEMORY=1;;
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200356 --no-append-outcome) append_outcome=0;;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000357 --no-armcc) no_armcc=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100358 --no-force) FORCE=0;;
359 --no-keep-going) KEEP_GOING=0;;
360 --no-memory) MEMORY=0;;
361 --openssl) shift; OPENSSL="$1";;
362 --openssl-legacy) shift; OPENSSL_LEGACY="$1";;
363 --openssl-next) shift; OPENSSL_NEXT="$1";;
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200364 --outcome-file) shift; MBEDTLS_TEST_OUTCOME_FILE="$1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100365 --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
366 --random-seed) unset SEED;;
367 --release-test|-r) SEED=1;;
368 --seed|-s) shift; SEED="$1";;
369 -*)
370 echo >&2 "Unknown option: $1"
371 echo >&2 "Run $0 --help for usage."
372 exit 120
373 ;;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000374 *) COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS $1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100375 esac
376 shift
Gilles Peskine8f073122018-11-27 15:58:47 +0100377 done
SimonB2e23c822016-04-16 21:54:39 +0100378
Gilles Peskinea28db922019-01-10 00:05:18 +0100379 # With no list of components, run everything.
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000380 if [ -z "$COMMAND_LINE_COMPONENTS" ]; then
381 all_except=1
Andres AGdc192212016-08-31 17:33:13 +0100382 fi
383
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000384 # --no-armcc is a legacy option. The modern way is --except '*_armcc*'.
385 # Ignore it if components are listed explicitly on the command line.
Gilles Peskinea28db922019-01-10 00:05:18 +0100386 if [ -n "$no_armcc" ] && [ $all_except -eq 1 ]; then
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000387 COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS *_armcc*"
SimonB2e23c822016-04-16 21:54:39 +0100388 fi
SimonB2e23c822016-04-16 21:54:39 +0100389
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000390 # Build the list of components to run.
Gilles Peskinea28db922019-01-10 00:05:18 +0100391 RUN_COMPONENTS=
392 for component in $SUPPORTED_COMPONENTS; do
393 if is_component_included "$component"; [ $? -eq $all_except ]; then
394 RUN_COMPONENTS="$RUN_COMPONENTS $component"
395 fi
396 done
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000397
398 unset all_except
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000399 unset no_armcc
Gilles Peskine8f073122018-11-27 15:58:47 +0100400}
SimonB2e23c822016-04-16 21:54:39 +0100401
Gilles Peskine8f073122018-11-27 15:58:47 +0100402pre_check_git () {
403 if [ $FORCE -eq 1 ]; then
Gilles Peskine53190e62019-01-09 23:17:35 +0100404 rm -rf "$OUT_OF_SOURCE_DIR"
Gilles Peskine8f073122018-11-27 15:58:47 +0100405 git checkout-index -f -q $CONFIG_H
406 cleanup
407 else
SimonB2e23c822016-04-16 21:54:39 +0100408
Gilles Peskine8f073122018-11-27 15:58:47 +0100409 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
410 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
411 echo "You can either delete this directory manually, or force the test by rerunning"
412 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
413 exit 1
414 fi
415
Gilles Peskined1174cf2019-01-09 22:30:01 +0100416 if ! git diff --quiet include/mbedtls/config.h; then
Gilles Peskine8f073122018-11-27 15:58:47 +0100417 err_msg "Warning - the configuration file 'include/mbedtls/config.h' has been edited. "
418 echo "You can either delete or preserve your work, or force the test by rerunning the"
419 echo "script as: $0 --force"
420 exit 1
421 fi
SimonB2e23c822016-04-16 21:54:39 +0100422 fi
Andrzej Kurekeb508712019-02-14 07:18:59 -0500423}
424
Gilles Peskine8f073122018-11-27 15:58:47 +0100425pre_setup_keep_going () {
Gilles Peskine7c652162017-12-11 00:01:40 +0100426 failure_summary=
427 failure_count=0
428 start_red=
429 end_color=
430 if [ -t 1 ]; then
Gilles Peskine9736b9d2018-01-02 21:54:17 +0100431 case "${TERM:-}" in
Gilles Peskine7c652162017-12-11 00:01:40 +0100432 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
433 start_red=$(printf '\033[31m')
434 end_color=$(printf '\033[0m')
435 ;;
436 esac
437 fi
438 record_status () {
439 if "$@"; then
440 last_status=0
441 else
442 last_status=$?
443 text="$current_section: $* -> $last_status"
444 failure_summary="$failure_summary
445$text"
446 failure_count=$((failure_count + 1))
447 echo "${start_red}^^^^$text^^^^${end_color}"
448 fi
449 }
450 make () {
451 case "$*" in
452 *test|*check)
453 if [ $build_status -eq 0 ]; then
454 record_status command make "$@"
455 else
456 echo "(skipped because the build failed)"
457 fi
458 ;;
459 *)
460 record_status command make "$@"
461 build_status=$last_status
462 ;;
463 esac
464 }
465 final_report () {
466 if [ $failure_count -gt 0 ]; then
467 echo
468 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
469 echo "${start_red}FAILED: $failure_count${end_color}$failure_summary"
470 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Jaeden Amero7c1258d2018-07-20 16:42:14 +0100471 exit 1
Gilles Peskine7c652162017-12-11 00:01:40 +0100472 elif [ -z "${1-}" ]; then
473 echo "SUCCESS :)"
474 fi
475 if [ -n "${1-}" ]; then
476 echo "Killed by SIG$1."
477 fi
478 }
Gilles Peskine8f073122018-11-27 15:58:47 +0100479}
480
Gilles Peskine7c652162017-12-11 00:01:40 +0100481if_build_succeeded () {
482 if [ $build_status -eq 0 ]; then
483 record_status "$@"
484 fi
485}
486
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200487# to be used instead of ! for commands run with
488# record_status or if_build_succeeded
489not() {
490 ! "$@"
491}
492
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200493pre_prepare_outcome_file () {
494 case "$MBEDTLS_TEST_OUTCOME_FILE" in
495 [!/]*) MBEDTLS_TEST_OUTCOME_FILE="$PWD/$MBEDTLS_TEST_OUTCOME_FILE";;
496 esac
497 if [ -n "$MBEDTLS_TEST_OUTCOME_FILE" ] && [ "$append_outcome" -eq 0 ]; then
498 rm -f "$MBEDTLS_TEST_OUTCOME_FILE"
499 fi
500}
501
Gilles Peskine8f073122018-11-27 15:58:47 +0100502pre_print_configuration () {
503 msg "info: $0 configuration"
504 echo "MEMORY: $MEMORY"
505 echo "FORCE: $FORCE"
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200506 echo "MBEDTLS_TEST_OUTCOME_FILE: ${MBEDTLS_TEST_OUTCOME_FILE:-(none)}"
Gilles Peskine8f073122018-11-27 15:58:47 +0100507 echo "SEED: ${SEED-"UNSET"}"
508 echo "OPENSSL: $OPENSSL"
509 echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
510 echo "OPENSSL_NEXT: $OPENSSL_NEXT"
511 echo "GNUTLS_CLI: $GNUTLS_CLI"
512 echo "GNUTLS_SERV: $GNUTLS_SERV"
513 echo "GNUTLS_LEGACY_CLI: $GNUTLS_LEGACY_CLI"
514 echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV"
515 echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
516 echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
517}
Andres AG7770ea82016-10-10 15:46:20 +0100518
Andres AGd9eba4b2016-08-26 14:42:14 +0100519# Make sure the tools we need are available.
Gilles Peskine8f073122018-11-27 15:58:47 +0100520pre_check_tools () {
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000521 # Build the list of variables to pass to output_env.sh.
522 set env
SimonB2e23c822016-04-16 21:54:39 +0100523
Gilles Peskine87964262019-01-06 22:40:00 +0000524 case " $RUN_COMPONENTS " in
525 # Require OpenSSL and GnuTLS if running any tests (as opposed to
526 # only doing builds). Not all tests run OpenSSL and GnuTLS, but this
527 # is a good enough approximation in practice.
528 *" test_"*)
529 # To avoid setting OpenSSL and GnuTLS for each call to compat.sh
530 # and ssl-opt.sh, we just export the variables they require.
531 export OPENSSL_CMD="$OPENSSL"
532 export GNUTLS_CLI="$GNUTLS_CLI"
533 export GNUTLS_SERV="$GNUTLS_SERV"
534 # Avoid passing --seed flag in every call to ssl-opt.sh
535 if [ -n "${SEED-}" ]; then
536 export SEED
537 fi
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000538 set "$@" OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY"
539 set "$@" GNUTLS_CLI="$GNUTLS_CLI" GNUTLS_SERV="$GNUTLS_SERV"
540 set "$@" GNUTLS_LEGACY_CLI="$GNUTLS_LEGACY_CLI"
541 set "$@" GNUTLS_LEGACY_SERV="$GNUTLS_LEGACY_SERV"
Gilles Peskine87964262019-01-06 22:40:00 +0000542 check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$OPENSSL_NEXT" \
543 "$GNUTLS_CLI" "$GNUTLS_SERV" \
544 "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV"
545 ;;
546 esac
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200547
Gilles Peskine87964262019-01-06 22:40:00 +0000548 case " $RUN_COMPONENTS " in
549 *_doxygen[_\ ]*) check_tools "doxygen" "dot";;
550 esac
Andres AGd9eba4b2016-08-26 14:42:14 +0100551
Gilles Peskine87964262019-01-06 22:40:00 +0000552 case " $RUN_COMPONENTS " in
553 *_arm_none_eabi_gcc[_\ ]*) check_tools "arm-none-eabi-gcc";;
554 esac
Andres AGd9eba4b2016-08-26 14:42:14 +0100555
Gilles Peskine87964262019-01-06 22:40:00 +0000556 case " $RUN_COMPONENTS " in
557 *_mingw[_\ ]*) check_tools "i686-w64-mingw32-gcc";;
558 esac
559
560 case " $RUN_COMPONENTS " in
561 *" test_zeroize "*) check_tools "gdb";;
562 esac
563
564 case " $RUN_COMPONENTS " in
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000565 *_armcc*)
Gilles Peskine87964262019-01-06 22:40:00 +0000566 ARMC5_CC="$ARMC5_BIN_DIR/armcc"
567 ARMC5_AR="$ARMC5_BIN_DIR/armar"
568 ARMC6_CC="$ARMC6_BIN_DIR/armclang"
569 ARMC6_AR="$ARMC6_BIN_DIR/armar"
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000570 check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC6_CC" "$ARMC6_AR";;
571 esac
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000572
573 msg "info: output_env.sh"
574 case $RUN_COMPONENTS in
575 *_armcc*)
576 set "$@" ARMC5_CC="$ARMC5_CC" ARMC6_CC="$ARMC6_CC" RUN_ARMCC=1;;
577 *) set "$@" RUN_ARMCC=0;;
578 esac
579 "$@" scripts/output_env.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100580}
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100581
Gilles Peskine192c72f2017-12-21 15:59:21 +0100582
583
584################################################################
585#### Basic checks
586################################################################
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100587
588#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200589# Test Suites to be executed
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100590#
Manuel Pégourié-Gonnard3d404b42015-07-08 21:59:16 +0100591# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200592# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100593# 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 +0200594# time, so start with a GCC build).
595# 2. Minimize total running time, by avoiding useless rebuilds
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100596#
Manuel Pégourié-Gonnard259b08a2016-01-08 16:27:41 +0100597# Indicative running times are given for reference.
598
Gilles Peskine8f073122018-11-27 15:58:47 +0100599component_check_recursion () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200600 msg "Check: recursion.pl" # < 1s
Gilles Peskine8f073122018-11-27 15:58:47 +0100601 record_status tests/scripts/recursion.pl library/*.c
602}
Janos Follathb72c6782016-07-19 14:54:17 +0100603
Gilles Peskine8f073122018-11-27 15:58:47 +0100604component_check_generated_files () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200605 msg "Check: freshness of generated source files" # < 1s
Gilles Peskine8f073122018-11-27 15:58:47 +0100606 record_status tests/scripts/check-generated-files.sh
607}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200608
Gilles Peskine8f073122018-11-27 15:58:47 +0100609component_check_doxy_blocks () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200610 msg "Check: doxygen markup outside doxygen blocks" # < 1s
Gilles Peskine8f073122018-11-27 15:58:47 +0100611 record_status tests/scripts/check-doxy-blocks.pl
612}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200613
Gilles Peskine8f073122018-11-27 15:58:47 +0100614component_check_files () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200615 msg "Check: file sanity checks (permissions, encodings)" # < 1s
Gilles Peskine8f073122018-11-27 15:58:47 +0100616 record_status tests/scripts/check-files.py
617}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200618
Gilles Peskine8f073122018-11-27 15:58:47 +0100619component_check_names () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200620 msg "Check: declared and exported names (builds the library)" # < 3s
Gilles Peskine13f97dc2019-05-15 17:52:22 +0200621 record_status tests/scripts/check-names.sh -v
Gilles Peskine8f073122018-11-27 15:58:47 +0100622}
Darryl Greena07039c2018-03-13 16:48:16 +0000623
Gilles Peskine895868b2019-09-19 21:30:05 +0200624component_check_test_cases () {
625 msg "Check: test case descriptions" # < 1s
626 record_status tests/scripts/check-test-cases.py
627}
628
Gilles Peskine8f073122018-11-27 15:58:47 +0100629component_check_doxygen_warnings () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200630 msg "Check: doxygen warnings (builds the documentation)" # ~ 3s
Gilles Peskine8f073122018-11-27 15:58:47 +0100631 record_status tests/scripts/doxygen.sh
632}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200633
Gilles Peskine192c72f2017-12-21 15:59:21 +0100634
Gilles Peskine192c72f2017-12-21 15:59:21 +0100635################################################################
636#### Build and test many configurations and targets
637################################################################
638
Gilles Peskine7832c9f2019-04-08 17:00:15 +0200639component_test_default_out_of_box () {
640 msg "build: make, default config (out-of-box)" # ~1min
641 make
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200642 # Disable fancy stuff
Gilles Peskine717cd762019-09-27 20:21:11 +0200643 SAVE_MBEDTLS_TEST_OUTCOME_FILE="$MBEDTLS_TEST_OUTCOME_FILE"
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200644 unset MBEDTLS_TEST_OUTCOME_FILE
Gilles Peskine7832c9f2019-04-08 17:00:15 +0200645
646 msg "test: main suites make, default config (out-of-box)" # ~10s
647 make test
648
649 msg "selftest: make, default config (out-of-box)" # ~10s
650 programs/test/selftest
Gilles Peskine717cd762019-09-27 20:21:11 +0200651
652 export MBEDTLS_TEST_OUTCOME_FILE="$SAVE_MBEDTLS_TEST_OUTCOME_FILE"
653 unset SAVE_MBEDTLS_TEST_OUTCOME_FILE
Gilles Peskine7832c9f2019-04-08 17:00:15 +0200654}
655
Gilles Peskine8f073122018-11-27 15:58:47 +0100656component_test_default_cmake_gcc_asan () {
657 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100658 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
659 make
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200660
Gilles Peskine8f073122018-11-27 15:58:47 +0100661 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
662 make test
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200663
Gilles Peskine8f073122018-11-27 15:58:47 +0100664 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
665 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200666
Gilles Peskine8f073122018-11-27 15:58:47 +0100667 msg "test: compat.sh (ASan build)" # ~ 6 min
668 if_build_succeeded tests/compat.sh
669}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200670
Hanno Becker01635512019-02-26 14:27:09 +0000671component_test_full_cmake_gcc_asan () {
672 msg "build: full config, cmake, gcc, ASan"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200673 scripts/config.py full
Hanno Becker01635512019-02-26 14:27:09 +0000674 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
675 make
676
677 msg "test: main suites (inc. selftests) (full config, ASan build)"
678 make test
Manuel Pégourié-Gonnardf2e29022020-01-24 10:17:20 +0100679}
Manuel Pégourié-Gonnard95e04492020-01-02 11:45:12 +0100680
Gilles Peskine782f4112018-11-27 16:11:09 +0100681component_test_ref_configs () {
682 msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
683 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
684 record_status tests/scripts/test-ref-configs.pl
685}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200686
Hanno Beckera545be22019-05-10 14:45:37 +0100687component_test_no_pem_no_fs () {
688 msg "build: Default + !MBEDTLS_PEM_PARSE_C + !MBEDTLS_FS_IO (ASan build)"
Gilles Peskine3bdd4122019-07-27 23:52:53 +0200689 scripts/config.py unset MBEDTLS_PEM_PARSE_C
690 scripts/config.py unset MBEDTLS_FS_IO
691 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C # requires a filesystem
692 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA ITS
Hanno Beckera545be22019-05-10 14:45:37 +0100693 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
694 make
695
696 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - main suites (inc. selftests) (ASan build)" # ~ 50s
697 make test
Hanno Beckera545be22019-05-10 14:45:37 +0100698}
699
Gilles Peskine8f073122018-11-27 15:58:47 +0100700component_test_sslv3 () {
701 msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200702 scripts/config.py set MBEDTLS_SSL_PROTO_SSL3
Gilles Peskine8f073122018-11-27 15:58:47 +0100703 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
704 make
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200705
Gilles Peskine8f073122018-11-27 15:58:47 +0100706 msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
707 make test
Simon Butcher3ea7f522016-03-07 23:22:10 +0000708
Gilles Peskine8f073122018-11-27 15:58:47 +0100709 msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
710 if_build_succeeded tests/compat.sh -m 'tls1 tls1_1 tls1_2 dtls1 dtls1_2'
711 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
Simon Butcher3ea7f522016-03-07 23:22:10 +0000712
Gilles Peskine8f073122018-11-27 15:58:47 +0100713 msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
714 if_build_succeeded tests/ssl-opt.sh
715}
Simon Butcher3ea7f522016-03-07 23:22:10 +0000716
Gilles Peskine8f073122018-11-27 15:58:47 +0100717component_test_no_renegotiation () {
718 msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200719 scripts/config.py unset MBEDTLS_SSL_RENEGOTIATION
Gilles Peskine8f073122018-11-27 15:58:47 +0100720 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
721 make
Simon Butcher3ea7f522016-03-07 23:22:10 +0000722
Gilles Peskine8f073122018-11-27 15:58:47 +0100723 msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
724 make test
Hanno Becker134c2ab2017-10-12 15:29:50 +0100725
Gilles Peskine8f073122018-11-27 15:58:47 +0100726 msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
727 if_build_succeeded tests/ssl-opt.sh
728}
Hanno Becker134c2ab2017-10-12 15:29:50 +0100729
Gilles Peskine8f073122018-11-27 15:58:47 +0100730component_test_rsa_no_crt () {
731 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200732 scripts/config.py set MBEDTLS_RSA_NO_CRT
Gilles Peskine8f073122018-11-27 15:58:47 +0100733 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
734 make
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +0100735
Gilles Peskine8f073122018-11-27 15:58:47 +0100736 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
737 make test
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100738
Gilles Peskine8f073122018-11-27 15:58:47 +0100739 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
740 if_build_succeeded tests/ssl-opt.sh -f RSA
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100741
Gilles Peskine8f073122018-11-27 15:58:47 +0100742 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
743 if_build_succeeded tests/compat.sh -t RSA
744}
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100745
Gilles Peskine8f073122018-11-27 15:58:47 +0100746component_test_small_ssl_out_content_len () {
747 msg "build: small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200748 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 16384
749 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
Gilles Peskine8f073122018-11-27 15:58:47 +0100750 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
751 make
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100752
Gilles Peskine8f073122018-11-27 15:58:47 +0100753 msg "test: small SSL_OUT_CONTENT_LEN - ssl-opt.sh MFL and large packet tests"
754 if_build_succeeded tests/ssl-opt.sh -f "Max fragment\|Large packet"
755}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000756
Gilles Peskine8f073122018-11-27 15:58:47 +0100757component_test_small_ssl_in_content_len () {
758 msg "build: small SSL_IN_CONTENT_LEN (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200759 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 4096
760 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 16384
Gilles Peskine8f073122018-11-27 15:58:47 +0100761 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
762 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000763
Gilles Peskine8f073122018-11-27 15:58:47 +0100764 msg "test: small SSL_IN_CONTENT_LEN - ssl-opt.sh MFL tests"
765 if_build_succeeded tests/ssl-opt.sh -f "Max fragment"
766}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000767
Gilles Peskine8f073122018-11-27 15:58:47 +0100768component_test_small_ssl_dtls_max_buffering () {
769 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200770 scripts/config.py set MBEDTLS_SSL_DTLS_MAX_BUFFERING 1000
Gilles Peskine8f073122018-11-27 15:58:47 +0100771 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
772 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000773
Gilles Peskine8f073122018-11-27 15:58:47 +0100774 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0 - ssl-opt.sh specific reordering test"
775 if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer out-of-order hs msg before reassembling next, free buffered msg"
776}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100777
Gilles Peskine8f073122018-11-27 15:58:47 +0100778component_test_small_mbedtls_ssl_dtls_max_buffering () {
779 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1"
Gilles Peskine3b46cd32020-02-18 17:56:33 +0100780 scripts/config.py set MBEDTLS_SSL_DTLS_MAX_BUFFERING 240
Gilles Peskine8f073122018-11-27 15:58:47 +0100781 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
782 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100783
Gilles Peskine8f073122018-11-27 15:58:47 +0100784 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1 - ssl-opt.sh specific reordering test"
785 if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer encrypted Finished message, drop for fragmented NewSessionTicket"
786}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100787
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200788component_test_new_ecdh_context () {
789 msg "build: new ECDH context (ASan build)" # ~ 6 min
Gilles Peskine3bdd4122019-07-27 23:52:53 +0200790 scripts/config.py unset MBEDTLS_ECDH_LEGACY_CONTEXT
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200791 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
792 make
793
794 msg "test: new ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
795 make test
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100796}
797
Gilles Peskine09a24b32019-04-12 20:29:48 +0200798component_test_everest () {
799 msg "build: Everest ECDH context (ASan build)" # ~ 6 min
Gilles Peskine3bdd4122019-07-27 23:52:53 +0200800 scripts/config.py unset MBEDTLS_ECDH_LEGACY_CONTEXT
801 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
Gilles Peskine09a24b32019-04-12 20:29:48 +0200802 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Asan .
803 make
804
805 msg "test: Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
806 make test
807}
808
Gilles Peskine75cc7712019-09-06 19:47:17 +0200809component_test_psa_collect_statuses () {
810 msg "build+test: psa_collect_statuses" # ~30s
Gilles Peskine3bdd4122019-07-27 23:52:53 +0200811 scripts/config.py full
Gilles Peskine75cc7712019-09-06 19:47:17 +0200812 record_status tests/scripts/psa_collect_statuses.py
813 # Check that psa_crypto_init() succeeded at least once
814 record_status grep -q '^0:psa_crypto_init:' tests/statuses.log
815 rm -f tests/statuses.log
816}
817
Gilles Peskine8f073122018-11-27 15:58:47 +0100818component_test_full_cmake_clang () {
819 msg "build: cmake, full config, clang" # ~ 50s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200820 scripts/config.py full
Gilles Peskine8f073122018-11-27 15:58:47 +0100821 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check -D ENABLE_TESTING=On .
822 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100823
k-stachowiak0291cb72019-06-26 15:52:12 +0200824 msg "test: main suites (full config, clang)" # ~ 5s
Gilles Peskine8f073122018-11-27 15:58:47 +0100825 make test
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100826
k-stachowiak0291cb72019-06-26 15:52:12 +0200827 msg "test: psa_constant_names (full config, clang)" # ~ 1s
Darryl Green45010a32019-02-06 13:43:58 +0000828 record_status tests/scripts/test_psa_constant_names.py
Gilles Peskine69e8f7f2020-02-26 19:51:43 +0100829
Gilles Peskine8f073122018-11-27 15:58:47 +0100830 msg "test: ssl-opt.sh default, ECJPAKE, SSL async (full config)" # ~ 1s
831 if_build_succeeded tests/ssl-opt.sh -f 'Default\|ECJPAKE\|SSL async private'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200832
Andres Amaya Garcia2dadab72019-01-08 21:42:27 +0000833 msg "test: compat.sh RC4, DES, 3DES & NULL (full config)" # ~ 2 min
Andres Amaya Garcia419bd002019-02-19 20:20:57 +0000834 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 +0200835
Gilles Peskine8f073122018-11-27 15:58:47 +0100836 msg "test: compat.sh ARIA + ChachaPoly"
837 if_build_succeeded env OPENSSL_CMD="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
838}
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200839
k-stachowiak5559b312019-06-27 11:28:11 +0200840component_test_full_make_gcc_o0 () {
841 msg "build: make, full config, gcc -O0" # ~ 50s
Gilles Peskine3bdd4122019-07-27 23:52:53 +0200842 scripts/config.py full
k-stachowiak5559b312019-06-27 11:28:11 +0200843 make CC=gcc CFLAGS='-O0'
k-stachowiak0291cb72019-06-26 15:52:12 +0200844
k-stachowiak5559b312019-06-27 11:28:11 +0200845 msg "test: main suites (full config, gcc -O0)" # ~ 5s
k-stachowiak0291cb72019-06-26 15:52:12 +0200846 make test
847}
848
Gilles Peskine8f073122018-11-27 15:58:47 +0100849component_build_deprecated () {
850 msg "build: make, full config + DEPRECATED_WARNING, gcc -O" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200851 scripts/config.py full
852 scripts/config.py set MBEDTLS_DEPRECATED_WARNING
Gilles Peskine8f073122018-11-27 15:58:47 +0100853 # Build with -O -Wextra to catch a maximum of issues.
854 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra' lib programs
855 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100856
Gilles Peskine841b14b2019-11-26 17:37:37 +0100857 msg "test: make, full config + DEPRECATED_WARNING, expect warnings" # ~ 30s
858 make -C tests clean
859 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-error=deprecated-declarations -DMBEDTLS_TEST_DEPRECATED' tests
860
Gilles Peskine8f073122018-11-27 15:58:47 +0100861 msg "build: make, full config + DEPRECATED_REMOVED, clang -O" # ~ 30s
862 # No cleanup, just tweak the configuration and rebuild
863 make clean
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200864 scripts/config.py unset MBEDTLS_DEPRECATED_WARNING
865 scripts/config.py set MBEDTLS_DEPRECATED_REMOVED
Gilles Peskine8f073122018-11-27 15:58:47 +0100866 # Build with -O -Wextra to catch a maximum of issues.
867 make CC=clang CFLAGS='-O -Werror -Wall -Wextra' lib programs
868 make CC=clang CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
869}
Jaeden Ameroed93bdc2018-11-02 16:57:24 +0000870
Gilles Peskineec541fe2020-01-31 14:24:14 +0100871# Check that the specified libraries exist and are empty.
872are_empty_libraries () {
873 nm "$@" >/dev/null 2>/dev/null
874 ! nm "$@" 2>/dev/null | grep -v ':$' | grep .
875}
876
877component_build_crypto_default () {
878 msg "build: make, crypto only"
879 scripts/config.py crypto
Gilles Peskine6bb39152020-02-03 11:59:20 +0100880 make CFLAGS='-O1 -Werror'
Gilles Peskineec541fe2020-01-31 14:24:14 +0100881 if_build_succeeded are_empty_libraries library/libmbedx509.* library/libmbedtls.*
882}
883
884component_build_crypto_full () {
885 msg "build: make, crypto only, full config"
886 scripts/config.py crypto_full
Gilles Peskine6bb39152020-02-03 11:59:20 +0100887 make CFLAGS='-O1 -Werror'
Gilles Peskineec541fe2020-01-31 14:24:14 +0100888 if_build_succeeded are_empty_libraries library/libmbedx509.* library/libmbedtls.*
889}
890
891component_build_crypto_baremetal () {
892 msg "build: make, crypto only, baremetal config"
893 scripts/config.py crypto_baremetal
Gilles Peskine6bb39152020-02-03 11:59:20 +0100894 make CFLAGS='-O1 -Werror'
Gilles Peskineec541fe2020-01-31 14:24:14 +0100895 if_build_succeeded are_empty_libraries library/libmbedx509.* library/libmbedtls.*
896}
897
Gilles Peskine8f073122018-11-27 15:58:47 +0100898component_test_depends_curves () {
899 msg "test/build: curves.pl (gcc)" # ~ 4 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100900 record_status tests/scripts/curves.pl
901}
Jaeden Ameroacaabe72018-11-07 11:52:52 +0000902
Gilles Peskine8f073122018-11-27 15:58:47 +0100903component_test_depends_hashes () {
904 msg "test/build: depends-hashes.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100905 record_status tests/scripts/depends-hashes.pl
906}
Jaeden Ameroacaabe72018-11-07 11:52:52 +0000907
Gilles Peskine8f073122018-11-27 15:58:47 +0100908component_test_depends_pkalgs () {
909 msg "test/build: depends-pkalgs.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100910 record_status tests/scripts/depends-pkalgs.pl
911}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100912
Gilles Peskine8f073122018-11-27 15:58:47 +0100913component_build_key_exchanges () {
914 msg "test/build: key-exchanges (gcc)" # ~ 1 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100915 record_status tests/scripts/key-exchanges.pl
916}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100917
Gilles Peskine8f073122018-11-27 15:58:47 +0100918component_build_default_make_gcc_and_cxx () {
919 msg "build: Unix make, -Os (gcc)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100920 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100921
Gilles Peskine8f073122018-11-27 15:58:47 +0100922 msg "test: verify header list in cpp_dummy_build.cpp"
923 record_status check_headers_in_cpp
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100924
Gilles Peskine8f073122018-11-27 15:58:47 +0100925 msg "build: Unix make, incremental g++"
926 make TEST_CPP=1
927}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100928
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100929component_test_no_use_psa_crypto_full_cmake_asan() {
930 # full minus MBEDTLS_USE_PSA_CRYPTO: run the same set of tests as basic-build-test.sh
Gilles Peskinedc3a1792019-09-03 11:42:04 +0200931 msg "build: cmake, full config minus MBEDTLS_USE_PSA_CRYPTO, ASan"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200932 scripts/config.py full
933 scripts/config.py set MBEDTLS_ECP_RESTARTABLE # not using PSA, so enable restartable ECC
934 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C
935 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
936 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C
937 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
Manuel Pégourié-Gonnardd8167e82019-02-01 11:12:52 +0100938 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500939 make
Manuel Pégourié-Gonnard43be6cd2017-06-20 09:53:42 +0200940
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100941 msg "test: main suites (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500942 make test
Manuel Pégourié-Gonnard503a5ef2015-10-23 09:04:45 +0200943
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100944 msg "test: ssl-opt.sh (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500945 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100946
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100947 msg "test: compat.sh default (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500948 if_build_succeeded tests/compat.sh
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400949
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100950 msg "test: compat.sh RC4, DES & NULL (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500951 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 -0500952
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100953 msg "test: compat.sh ARIA + ChachaPoly (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500954 if_build_succeeded env OPENSSL_CMD="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
955}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500956
Gilles Peskineadcde5e2019-06-12 16:05:50 +0200957component_test_check_params_functionality () {
958 msg "build+test: MBEDTLS_CHECK_PARAMS functionality"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200959 scripts/config.py full # includes CHECK_PARAMS
Gilles Peskineadcde5e2019-06-12 16:05:50 +0200960 # Make MBEDTLS_PARAM_FAILED call mbedtls_param_failed().
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200961 scripts/config.py unset MBEDTLS_CHECK_PARAMS_ASSERT
Gilles Peskineadcde5e2019-06-12 16:05:50 +0200962 # Only build and run tests. Do not build sample programs, because
963 # they don't have a mbedtls_param_failed() function.
964 make CC=gcc CFLAGS='-Werror -O1' lib test
965}
966
Gilles Peskineb28636b2019-01-02 19:06:24 +0100967component_test_check_params_without_platform () {
968 msg "build+test: MBEDTLS_CHECK_PARAMS without MBEDTLS_PLATFORM_C"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200969 scripts/config.py full # includes CHECK_PARAMS
Gilles Peskineadcde5e2019-06-12 16:05:50 +0200970 # Keep MBEDTLS_PARAM_FAILED as assert.
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200971 scripts/config.py unset MBEDTLS_PLATFORM_EXIT_ALT
972 scripts/config.py unset MBEDTLS_PLATFORM_TIME_ALT
973 scripts/config.py unset MBEDTLS_PLATFORM_FPRINTF_ALT
974 scripts/config.py unset MBEDTLS_PLATFORM_MEMORY
975 scripts/config.py unset MBEDTLS_PLATFORM_PRINTF_ALT
976 scripts/config.py unset MBEDTLS_PLATFORM_SNPRINTF_ALT
977 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
978 scripts/config.py unset MBEDTLS_PLATFORM_C
Gilles Peskineb28636b2019-01-02 19:06:24 +0100979 make CC=gcc CFLAGS='-Werror -O1' all test
980}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500981
Gilles Peskineb28636b2019-01-02 19:06:24 +0100982component_test_check_params_silent () {
983 msg "build+test: MBEDTLS_CHECK_PARAMS with alternative MBEDTLS_PARAM_FAILED()"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200984 scripts/config.py full # includes CHECK_PARAMS
Gilles Peskineadcde5e2019-06-12 16:05:50 +0200985 # Set MBEDTLS_PARAM_FAILED to nothing.
Gilles Peskineb28636b2019-01-02 19:06:24 +0100986 sed -i 's/.*\(#define MBEDTLS_PARAM_FAILED( cond )\).*/\1/' "$CONFIG_H"
987 make CC=gcc CFLAGS='-Werror -O1' all test
988}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500989
Gilles Peskine8f073122018-11-27 15:58:47 +0100990component_test_no_platform () {
991 # Full configuration build, without platform support, file IO and net sockets.
992 # This should catch missing mbedtls_printf definitions, and by disabling file
993 # IO, it should catch missing '#include <stdio.h>'
994 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200995 scripts/config.py full
996 scripts/config.py unset MBEDTLS_PLATFORM_C
997 scripts/config.py unset MBEDTLS_NET_C
998 scripts/config.py unset MBEDTLS_PLATFORM_MEMORY
999 scripts/config.py unset MBEDTLS_PLATFORM_PRINTF_ALT
1000 scripts/config.py unset MBEDTLS_PLATFORM_FPRINTF_ALT
1001 scripts/config.py unset MBEDTLS_PLATFORM_SNPRINTF_ALT
1002 scripts/config.py unset MBEDTLS_PLATFORM_TIME_ALT
1003 scripts/config.py unset MBEDTLS_PLATFORM_EXIT_ALT
1004 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
1005 scripts/config.py unset MBEDTLS_FS_IO
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001006 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001007 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
1008 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C
Gilles Peskine8f073122018-11-27 15:58:47 +01001009 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
1010 # to re-enable platform integration features otherwise disabled in C99 builds
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02001011 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -Os -D_DEFAULT_SOURCE' lib programs
1012 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os' test
Gilles Peskine8f073122018-11-27 15:58:47 +01001013}
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +00001014
Gilles Peskine8f073122018-11-27 15:58:47 +01001015component_build_no_std_function () {
1016 # catch compile bugs in _uninit functions
1017 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001018 scripts/config.py full
1019 scripts/config.py set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
1020 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02001021 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Gilles Peskine8f073122018-11-27 15:58:47 +01001022}
Manuel Pégourié-Gonnarddccb80b2015-06-03 10:20:33 +01001023
Gilles Peskine8f073122018-11-27 15:58:47 +01001024component_build_no_ssl_srv () {
1025 msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001026 scripts/config.py full
1027 scripts/config.py unset MBEDTLS_SSL_SRV_C
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02001028 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
Gilles Peskine8f073122018-11-27 15:58:47 +01001029}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +02001030
Gilles Peskine8f073122018-11-27 15:58:47 +01001031component_build_no_ssl_cli () {
1032 msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001033 scripts/config.py full
1034 scripts/config.py unset MBEDTLS_SSL_CLI_C
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02001035 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
Gilles Peskine8f073122018-11-27 15:58:47 +01001036}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +02001037
Gilles Peskine8f073122018-11-27 15:58:47 +01001038component_build_no_sockets () {
1039 # Note, C99 compliance can also be tested with the sockets support disabled,
1040 # as that requires a POSIX platform (which isn't the same as C99).
1041 msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001042 scripts/config.py full
1043 scripts/config.py unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
1044 scripts/config.py set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02001045 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1 -std=c99 -pedantic' lib
Gilles Peskine8f073122018-11-27 15:58:47 +01001046}
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +02001047
Andrzej Kurek69f20aa2019-09-05 09:27:47 -04001048component_test_memory_buffer_allocator_backtrace () {
1049 msg "build: default config with memory buffer allocator and backtrace enabled"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001050 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
1051 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
1052 scripts/config.py set MBEDTLS_MEMORY_BACKTRACE
1053 scripts/config.py set MBEDTLS_MEMORY_DEBUG
Andrzej Kurek69f20aa2019-09-05 09:27:47 -04001054 CC=gcc cmake .
1055 make
1056
1057 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C and MBEDTLS_MEMORY_BACKTRACE"
1058 make test
1059}
1060
1061component_test_memory_buffer_allocator () {
1062 msg "build: default config with memory buffer allocator"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001063 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
1064 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
Hanno Becker0fb9ba22019-02-26 14:34:13 +00001065 CC=gcc cmake .
1066 make
1067
1068 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C"
1069 make test
Hanno Becker0fb9ba22019-02-26 14:34:13 +00001070}
1071
Gilles Peskine8f073122018-11-27 15:58:47 +01001072component_test_no_max_fragment_length () {
1073 # Run max fragment length tests with MFL disabled
1074 msg "build: default config except MFL extension (ASan build)" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001075 scripts/config.py unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
Gilles Peskine8f073122018-11-27 15:58:47 +01001076 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1077 make
Hanno Becker5175ac62017-09-18 15:36:25 +01001078
Gilles Peskine8f073122018-11-27 15:58:47 +01001079 msg "test: ssl-opt.sh, MFL-related tests"
1080 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length"
1081}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001082
Hanno Becker545ced42019-02-19 11:10:48 +00001083component_test_asan_remove_peer_certificate () {
1084 msg "build: default config with MBEDTLS_SSL_KEEP_PEER_CERTIFICATE disabled (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001085 scripts/config.py unset MBEDTLS_SSL_KEEP_PEER_CERTIFICATE
Hanno Becker545ced42019-02-19 11:10:48 +00001086 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1087 make
1088
1089 msg "test: !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
1090 make test
1091
1092 msg "test: ssl-opt.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
1093 if_build_succeeded tests/ssl-opt.sh
1094
1095 msg "test: compat.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
1096 if_build_succeeded tests/compat.sh
1097}
1098
Gilles Peskine8f073122018-11-27 15:58:47 +01001099component_test_no_max_fragment_length_small_ssl_out_content_len () {
1100 msg "build: no MFL extension, small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001101 scripts/config.py unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
1102 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 16384
1103 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
Gilles Peskine8f073122018-11-27 15:58:47 +01001104 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1105 make
Angus Grattonc4dd0732018-04-11 16:28:39 +10001106
Gilles Peskine8f073122018-11-27 15:58:47 +01001107 msg "test: MFL tests (disabled MFL extension case) & large packet tests"
1108 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length\|Large buffer"
1109}
Angus Grattonc4dd0732018-04-11 16:28:39 +10001110
Gilles Peskine8f073122018-11-27 15:58:47 +01001111component_test_null_entropy () {
1112 msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001113 scripts/config.py set MBEDTLS_TEST_NULL_ENTROPY
1114 scripts/config.py set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
1115 scripts/config.py set MBEDTLS_ENTROPY_C
1116 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
1117 scripts/config.py unset MBEDTLS_ENTROPY_HARDWARE_ALT
1118 scripts/config.py unset MBEDTLS_HAVEGE_C
Gilles Peskine5fa32a72019-01-06 19:48:30 +00001119 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan -D UNSAFE_BUILD=ON .
Gilles Peskine8f073122018-11-27 15:58:47 +01001120 make
Janos Follath06c54002016-06-09 13:57:40 +01001121
Gilles Peskine8f073122018-11-27 15:58:47 +01001122 msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)"
1123 make test
1124}
Janos Follath06c54002016-06-09 13:57:40 +01001125
Gilles Peskine8f073122018-11-27 15:58:47 +01001126component_test_platform_calloc_macro () {
1127 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001128 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
1129 scripts/config.py set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
1130 scripts/config.py set MBEDTLS_PLATFORM_FREE_MACRO free
Gilles Peskine8f073122018-11-27 15:58:47 +01001131 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1132 make
Hanno Beckere5fecec2018-10-11 11:02:52 +01001133
Gilles Peskine8f073122018-11-27 15:58:47 +01001134 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
1135 make test
1136}
Hanno Beckere5fecec2018-10-11 11:02:52 +01001137
Gilles Peskinec4ef7a92019-09-17 19:04:38 +02001138component_test_malloc_0_null () {
1139 msg "build: malloc(0) returns NULL (ASan+UBSan build)"
Manuel Pégourié-Gonnard68192fc2020-03-04 10:34:47 +01001140 scripts/config.py full
Gilles Peskine004206c2019-10-21 17:11:33 +02001141 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 +02001142
1143 msg "test: malloc(0) returns NULL (ASan+UBSan build)"
1144 make test
1145
1146 msg "selftest: malloc(0) returns NULL (ASan+UBSan build)"
1147 # Just the calloc selftest. "make test" ran the others as part of the
1148 # test suites.
1149 if_build_succeeded programs/test/selftest calloc
Gilles Peskine765d2402020-02-11 18:26:34 +01001150
1151 msg "test ssl-opt.sh: malloc(0) returns NULL (ASan+UBSan build)"
1152 # Run a subset of the tests. The choice is a balance between coverage
1153 # and time (including time indirectly wasted due to flaky tests).
1154 # The current choice is to skip tests whose description includes
1155 # "proxy", which is an approximation of skipping tests that use the
1156 # UDP proxy, which tend to be slower and flakier.
1157 if_build_succeeded tests/ssl-opt.sh -e 'proxy'
Gilles Peskinec4ef7a92019-09-17 19:04:38 +02001158}
1159
Gilles Peskine8f073122018-11-27 15:58:47 +01001160component_test_aes_fewer_tables () {
1161 msg "build: default config with AES_FEWER_TABLES enabled"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001162 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
Gilles Peskine8f073122018-11-27 15:58:47 +01001163 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01001164
Gilles Peskine8f073122018-11-27 15:58:47 +01001165 msg "test: AES_FEWER_TABLES"
1166 make test
1167}
Hanno Becker83ebf782017-07-07 12:29:15 +01001168
Gilles Peskine8f073122018-11-27 15:58:47 +01001169component_test_aes_rom_tables () {
1170 msg "build: default config with AES_ROM_TABLES enabled"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001171 scripts/config.py set MBEDTLS_AES_ROM_TABLES
Gilles Peskine8f073122018-11-27 15:58:47 +01001172 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01001173
Gilles Peskine8f073122018-11-27 15:58:47 +01001174 msg "test: AES_ROM_TABLES"
1175 make test
1176}
Hanno Becker83ebf782017-07-07 12:29:15 +01001177
Gilles Peskine8f073122018-11-27 15:58:47 +01001178component_test_aes_fewer_tables_and_rom_tables () {
1179 msg "build: default config with AES_ROM_TABLES and AES_FEWER_TABLES enabled"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001180 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
1181 scripts/config.py set MBEDTLS_AES_ROM_TABLES
Gilles Peskine8f073122018-11-27 15:58:47 +01001182 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01001183
Gilles Peskine8f073122018-11-27 15:58:47 +01001184 msg "test: AES_FEWER_TABLES + AES_ROM_TABLES"
1185 make test
1186}
1187
Gilles Peskine592f5912019-10-07 18:49:32 +02001188component_test_ctr_drbg_aes_256_sha_256 () {
1189 msg "build: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
Gilles Peskine3b46cd32020-02-18 17:56:33 +01001190 scripts/config.py full
1191 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
1192 scripts/config.py set MBEDTLS_ENTROPY_FORCE_SHA256
Gilles Peskine592f5912019-10-07 18:49:32 +02001193 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1194 make
1195
1196 msg "test: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
1197 make test
1198}
1199
1200component_test_ctr_drbg_aes_128_sha_512 () {
1201 msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)"
Gilles Peskine3b46cd32020-02-18 17:56:33 +01001202 scripts/config.py full
1203 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
1204 scripts/config.py set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
Gilles Peskine592f5912019-10-07 18:49:32 +02001205 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1206 make
1207
1208 msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)"
1209 make test
1210}
1211
1212component_test_ctr_drbg_aes_128_sha_256 () {
1213 msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
Gilles Peskine3b46cd32020-02-18 17:56:33 +01001214 scripts/config.py full
1215 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
1216 scripts/config.py set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
1217 scripts/config.py set MBEDTLS_ENTROPY_FORCE_SHA256
Gilles Peskine592f5912019-10-07 18:49:32 +02001218 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1219 make
1220
1221 msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
1222 make test
1223}
1224
Gilles Peskinef96aefe2019-07-24 14:58:38 +02001225component_test_se_default () {
1226 msg "build: default config + MBEDTLS_PSA_CRYPTO_SE_C"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001227 scripts/config.py set MBEDTLS_PSA_CRYPTO_SE_C
Gilles Peskine004206c2019-10-21 17:11:33 +02001228 make CC=clang CFLAGS="$ASAN_CFLAGS -Os" LDFLAGS="$ASAN_CFLAGS"
Gilles Peskinef96aefe2019-07-24 14:58:38 +02001229
1230 msg "test: default config + MBEDTLS_PSA_CRYPTO_SE_C"
1231 make test
1232}
1233
1234component_test_se_full () {
1235 msg "build: full config + MBEDTLS_PSA_CRYPTO_SE_C"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001236 scripts/config.py full
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001237 scripts/config.py set MBEDTLS_PSA_CRYPTO_SE_C
Gilles Peskine004206c2019-10-21 17:11:33 +02001238 make CC=gcc CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
Gilles Peskinef96aefe2019-07-24 14:58:38 +02001239
1240 msg "test: full config + MBEDTLS_PSA_CRYPTO_SE_C"
1241 make test
1242}
1243
Gilles Peskine8f073122018-11-27 15:58:47 +01001244component_test_make_shared () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001245 msg "build/test: make shared" # ~ 40s
Andrzej Kurek232e8f92019-10-03 03:18:01 -04001246 make SHARED=1 all check
Gilles Peskine56c01612019-07-03 20:43:32 +02001247 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskine8f073122018-11-27 15:58:47 +01001248}
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +02001249
Gilles Peskinecf740502019-07-03 20:43:05 +02001250component_test_cmake_shared () {
1251 msg "build/test: cmake shared" # ~ 2min
1252 cmake -DUSE_SHARED_MBEDTLS_LIBRARY=On .
1253 make
Gilles Peskine56c01612019-07-03 20:43:32 +02001254 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskinecf740502019-07-03 20:43:05 +02001255 make test
1256}
1257
Gilles Peskineec10bf12019-09-20 19:56:06 +02001258test_build_opt () {
1259 info=$1 cc=$2; shift 2
1260 for opt in "$@"; do
1261 msg "build/test: $cc $opt, $info" # ~ 30s
1262 make CC="$cc" CFLAGS="$opt -Wall -Wextra -Werror"
1263 # We're confident enough in compilers to not run _all_ the tests,
1264 # but at least run the unit tests. In particular, runs with
1265 # optimizations use inline assembly whereas runs with -O0
1266 # skip inline assembly.
1267 make test # ~30s
1268 make clean
1269 done
1270}
1271
1272component_test_clang_opt () {
Manuel Pégourié-Gonnard68192fc2020-03-04 10:34:47 +01001273 scripts/config.py full
Gilles Peskineec10bf12019-09-20 19:56:06 +02001274 test_build_opt 'full config' clang -O0 -Os -O2
1275}
1276
1277component_test_gcc_opt () {
Manuel Pégourié-Gonnard68192fc2020-03-04 10:34:47 +01001278 scripts/config.py full
Gilles Peskineec10bf12019-09-20 19:56:06 +02001279 test_build_opt 'full config' gcc -O0 -Os -O2
1280}
1281
Gilles Peskineabf9b4d2019-07-03 20:42:16 +02001282component_build_mbedtls_config_file () {
1283 msg "build: make with MBEDTLS_CONFIG_FILE" # ~40s
1284 # Use the full config so as to catch a maximum of places where
1285 # the check of MBEDTLS_CONFIG_FILE might be missing.
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001286 scripts/config.py full
Gilles Peskineabf9b4d2019-07-03 20:42:16 +02001287 sed 's!"check_config.h"!"mbedtls/check_config.h"!' <"$CONFIG_H" >full_config.h
1288 echo '#error "MBEDTLS_CONFIG_FILE is not working"' >"$CONFIG_H"
1289 make CFLAGS="-I '$PWD' -DMBEDTLS_CONFIG_FILE='\"full_config.h\"'"
1290 rm -f full_config.h
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001291}
1292
Gilles Peskine8f073122018-11-27 15:58:47 +01001293component_test_m32_o0 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001294 # Build once with -O0, to compile out the i386 specific inline assembly
1295 msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001296 scripts/config.py full
Gilles Peskine8fd59422019-10-21 17:11:33 +02001297 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O0" LDFLAGS="-m32 $ASAN_CFLAGS"
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01001298
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001299 msg "test: i386, make, gcc -O0 (ASan build)"
1300 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01001301}
Gilles Peskine878cf602019-01-06 20:50:38 +00001302support_test_m32_o0 () {
1303 case $(uname -m) in
1304 *64*) true;;
1305 *) false;;
1306 esac
1307}
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001308
Gilles Peskine8f073122018-11-27 15:58:47 +01001309component_test_m32_o1 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001310 # Build again with -O1, to compile in the i386 specific inline assembly
1311 msg "build: i386, make, gcc -O1 (ASan build)" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001312 scripts/config.py full
Gilles Peskine8fd59422019-10-21 17:11:33 +02001313 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O1" LDFLAGS="-m32 $ASAN_CFLAGS"
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001314
1315 msg "test: i386, make, gcc -O1 (ASan build)"
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001316 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01001317}
Gilles Peskine878cf602019-01-06 20:50:38 +00001318support_test_m32_o1 () {
1319 support_test_m32_o0 "$@"
1320}
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001321
Gilles Peskine0c6b7992019-04-12 20:29:48 +02001322component_test_m32_everest () {
1323 msg "build: i386, Everest ECDH context (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001324 scripts/config.py unset MBEDTLS_ECDH_LEGACY_CONTEXT
1325 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
Gilles Peskine8fd59422019-10-21 17:11:33 +02001326 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O2" LDFLAGS="-m32 $ASAN_CFLAGS"
Gilles Peskine0c6b7992019-04-12 20:29:48 +02001327
1328 msg "test: i386, Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
1329 make test
Gilles Peskine0c6b7992019-04-12 20:29:48 +02001330}
1331support_test_m32_everest () {
1332 support_test_m32_o0 "$@"
1333}
1334
Gilles Peskine8f073122018-11-27 15:58:47 +01001335component_test_mx32 () {
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001336 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001337 scripts/config.py full
Gilles Peskine5d26e7c2019-06-07 14:50:09 +02001338 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32' LDFLAGS='-mx32'
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001339
1340 msg "test: 64-bit ILP32, make, gcc"
1341 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01001342}
Gilles Peskine878cf602019-01-06 20:50:38 +00001343support_test_mx32 () {
1344 case $(uname -m) in
1345 amd64|x86_64) true;;
1346 *) false;;
1347 esac
1348}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001349
Peter Kolbus60c6da22018-12-27 06:59:04 -06001350component_test_min_mpi_window_size () {
1351 msg "build: Default + MBEDTLS_MPI_WINDOW_SIZE=1 (ASan build)" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001352 scripts/config.py set MBEDTLS_MPI_WINDOW_SIZE 1
Peter Kolbus60c6da22018-12-27 06:59:04 -06001353 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1354 make
1355
1356 msg "test: MBEDTLS_MPI_WINDOW_SIZE=1 - main suites (inc. selftests) (ASan build)" # ~ 10s
1357 make test
1358}
1359
Gilles Peskine8f073122018-11-27 15:58:47 +01001360component_test_have_int32 () {
1361 msg "build: gcc, force 32-bit bignum limbs"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001362 scripts/config.py unset MBEDTLS_HAVE_ASM
1363 scripts/config.py unset MBEDTLS_AESNI_C
1364 scripts/config.py unset MBEDTLS_PADLOCK_C
Gilles Peskine8f073122018-11-27 15:58:47 +01001365 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01001366
Gilles Peskine8f073122018-11-27 15:58:47 +01001367 msg "test: gcc, force 32-bit bignum limbs"
1368 make test
1369}
Andres Amaya Garciafe843a32017-07-20 13:21:34 +01001370
Gilles Peskine8f073122018-11-27 15:58:47 +01001371component_test_have_int64 () {
1372 msg "build: gcc, force 64-bit bignum limbs"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001373 scripts/config.py unset MBEDTLS_HAVE_ASM
1374 scripts/config.py unset MBEDTLS_AESNI_C
1375 scripts/config.py unset MBEDTLS_PADLOCK_C
Gilles Peskine8f073122018-11-27 15:58:47 +01001376 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
Gilles Peskine14c3c062018-01-29 21:25:12 +01001377
Gilles Peskine8f073122018-11-27 15:58:47 +01001378 msg "test: gcc, force 64-bit bignum limbs"
1379 make test
1380}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001381
Gilles Peskine8f073122018-11-27 15:58:47 +01001382component_test_no_udbl_division () {
1383 msg "build: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001384 scripts/config.py full
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001385 scripts/config.py set MBEDTLS_NO_UDBL_DIVISION
Gilles Peskine8f073122018-11-27 15:58:47 +01001386 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001387
Gilles Peskine8f073122018-11-27 15:58:47 +01001388 msg "test: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
1389 make test
1390}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001391
Gilles Peskine8f073122018-11-27 15:58:47 +01001392component_test_no_64bit_multiplication () {
1393 msg "build: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001394 scripts/config.py full
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001395 scripts/config.py set MBEDTLS_NO_64BIT_MULTIPLICATION
Gilles Peskine8f073122018-11-27 15:58:47 +01001396 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001397
Gilles Peskine8f073122018-11-27 15:58:47 +01001398 msg "test: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
1399 make test
1400}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001401
Gilles Peskine8f073122018-11-27 15:58:47 +01001402component_build_arm_none_eabi_gcc () {
1403 msg "build: arm-none-eabi-gcc, make" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001404 scripts/config.py baremetal
Gilles Peskine8f073122018-11-27 15:58:47 +01001405 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
1406}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001407
Gilles Peskine2c897d72019-08-09 16:05:05 +02001408component_build_arm_none_eabi_gcc_arm5vte () {
Gilles Peskine8a52af92019-08-08 16:09:02 +02001409 msg "build: arm-none-eabi-gcc -march=arm5vte, make" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001410 scripts/config.py baremetal
Gilles Peskine2c897d72019-08-09 16:05:05 +02001411 # Build for a target platform that's close to what Debian uses
1412 # for its "armel" distribution (https://wiki.debian.org/ArmEabiPort).
1413 # See https://github.com/ARMmbed/mbedtls/pull/2169 and comments.
1414 # It would be better to build with arm-linux-gnueabi-gcc but
1415 # we don't have that on our CI at this time.
Gilles Peskine8a52af92019-08-08 16:09:02 +02001416 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar CFLAGS='-Werror -Wall -Wextra -march=armv5te -O1' LDFLAGS='-march=armv5te' SHELL='sh -x' lib
Gilles Peskine93e4e032019-08-05 11:34:25 +02001417}
1418
Gilles Peskine8f073122018-11-27 15:58:47 +01001419component_build_arm_none_eabi_gcc_no_udbl_division () {
1420 msg "build: arm-none-eabi-gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001421 scripts/config.py baremetal
1422 scripts/config.py set MBEDTLS_NO_UDBL_DIVISION
Gilles Peskine8f073122018-11-27 15:58:47 +01001423 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
1424 echo "Checking that software 64-bit division is not required"
1425 if_build_succeeded not grep __aeabi_uldiv library/*.o
1426}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001427
Gilles Peskine8f073122018-11-27 15:58:47 +01001428component_build_arm_none_eabi_gcc_no_64bit_multiplication () {
1429 msg "build: arm-none-eabi-gcc MBEDTLS_NO_64BIT_MULTIPLICATION, make" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001430 scripts/config.py baremetal
1431 scripts/config.py set MBEDTLS_NO_64BIT_MULTIPLICATION
Gilles Peskine8f073122018-11-27 15:58:47 +01001432 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -O1 -march=armv6-m -mthumb' lib
1433 echo "Checking that software 64-bit multiplication is not required"
1434 if_build_succeeded not grep __aeabi_lmul library/*.o
1435}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001436
Gilles Peskine8f073122018-11-27 15:58:47 +01001437component_build_armcc () {
1438 msg "build: ARM Compiler 5, make"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001439 scripts/config.py baremetal
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001440
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001441 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
1442 make clean
Andres AG87bb5772016-09-27 15:05:15 +01001443
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001444 # ARM Compiler 6 - Target ARMv7-A
1445 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-a"
Simon Butcher940737f2017-07-23 13:42:36 +02001446
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001447 # ARM Compiler 6 - Target ARMv7-M
1448 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m"
Simon Butcher940737f2017-07-23 13:42:36 +02001449
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001450 # ARM Compiler 6 - Target ARMv8-A - AArch32
1451 armc6_build_test "--target=arm-arm-none-eabi -march=armv8.2-a"
Simon Butcher940737f2017-07-23 13:42:36 +02001452
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001453 # ARM Compiler 6 - Target ARMv8-M
1454 armc6_build_test "--target=arm-arm-none-eabi -march=armv8-m.main"
Simon Butcher940737f2017-07-23 13:42:36 +02001455
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001456 # ARM Compiler 6 - Target ARMv8-A - AArch64
1457 armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a"
Gilles Peskine8f073122018-11-27 15:58:47 +01001458}
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +01001459
Gilles Peskine8f073122018-11-27 15:58:47 +01001460component_test_allow_sha1 () {
1461 msg "build: allow SHA1 in certificates by default"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001462 scripts/config.py set MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
Gilles Peskine8f073122018-11-27 15:58:47 +01001463 make CFLAGS='-Werror -Wall -Wextra'
1464 msg "test: allow SHA1 in certificates by default"
1465 make test
1466 if_build_succeeded tests/ssl-opt.sh -f SHA-1
1467}
Gilles Peskine2a458da2017-05-12 15:26:58 +02001468
Gilles Peskine8f073122018-11-27 15:58:47 +01001469component_build_mingw () {
1470 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
Andrzej Kurek232e8f92019-10-03 03:18:01 -04001471 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 +00001472
Gilles Peskine8f073122018-11-27 15:58:47 +01001473 # note Make tests only builds the tests, but doesn't run them
Andrzej Kurek232e8f92019-10-03 03:18:01 -04001474 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 +01001475 make WINDOWS_BUILD=1 clean
Simon Butcher002bc622016-11-17 09:27:45 +00001476
Gilles Peskine8f073122018-11-27 15:58:47 +01001477 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
Andrzej Kurek232e8f92019-10-03 03:18:01 -04001478 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
1479 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 +01001480 make WINDOWS_BUILD=1 clean
1481}
Jaeden Amero117b8a42019-04-17 15:19:26 +01001482support_build_mingw() {
1483 case $(i686-w64-mingw32-gcc -dumpversion) in
1484 [0-5]*) false;;
1485 *) true;;
1486 esac
1487}
Manuel Pégourié-Gonnard6448bce2015-02-16 17:18:36 +01001488
Gilles Peskine8f073122018-11-27 15:58:47 +01001489component_test_memsan () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001490 msg "build: MSan (clang)" # ~ 1 min 20s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001491 scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001492 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
1493 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +02001494
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001495 msg "test: main suites (MSan)" # ~ 10s
1496 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001497
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001498 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
Gilles Peskine7c652162017-12-11 00:01:40 +01001499 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001500
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001501 # Optional part(s)
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001502
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001503 if [ "$MEMORY" -gt 0 ]; then
1504 msg "test: compat.sh (MSan)" # ~ 6 min 20s
Gilles Peskine7c652162017-12-11 00:01:40 +01001505 if_build_succeeded tests/compat.sh
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001506 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001507}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001508
Gilles Peskine69f190e2019-01-10 00:11:42 +01001509component_test_valgrind () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001510 msg "build: Release (clang)"
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001511 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
1512 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001513
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001514 msg "test: main suites valgrind (Release)"
1515 make memcheck
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001516
Gilles Peskine69e8f7f2020-02-26 19:51:43 +01001517 # Optional part(s)
1518 # Currently broken, programs don't seem to receive signals
1519 # under valgrind on OS X
1520
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001521 if [ "$MEMORY" -gt 0 ]; then
1522 msg "test: ssl-opt.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +01001523 if_build_succeeded tests/ssl-opt.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001524 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001525
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001526 if [ "$MEMORY" -gt 1 ]; then
1527 msg "test: compat.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +01001528 if_build_succeeded tests/compat.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001529 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001530}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001531
Gilles Peskine8f073122018-11-27 15:58:47 +01001532component_test_cmake_out_of_source () {
1533 msg "build: cmake 'out-of-source' build"
Gilles Peskine8f073122018-11-27 15:58:47 +01001534 MBEDTLS_ROOT_DIR="$PWD"
1535 mkdir "$OUT_OF_SOURCE_DIR"
1536 cd "$OUT_OF_SOURCE_DIR"
1537 cmake "$MBEDTLS_ROOT_DIR"
1538 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001539
Gilles Peskine8f073122018-11-27 15:58:47 +01001540 msg "test: cmake 'out-of-source' build"
1541 make test
1542 # Test an SSL option that requires an auxiliary script in test/scripts/.
1543 # Also ensure that there are no error messages such as
1544 # "No such file or directory", which would indicate that some required
1545 # file is missing (ssl-opt.sh tolerates the absence of some files so
1546 # may exit with status 0 but emit errors).
1547 if_build_succeeded ./tests/ssl-opt.sh -f 'Fallback SCSV: beginning of list' 2>ssl-opt.err
1548 if [ -s ssl-opt.err ]; then
1549 cat ssl-opt.err >&2
1550 record_status [ ! -s ssl-opt.err ]
1551 rm ssl-opt.err
1552 fi
1553 cd "$MBEDTLS_ROOT_DIR"
1554 rm -rf "$OUT_OF_SOURCE_DIR"
1555 unset MBEDTLS_ROOT_DIR
1556}
Andres AGdc192212016-08-31 17:33:13 +01001557
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01001558component_test_cmake_as_subdirectory () {
1559 msg "build: cmake 'as-subdirectory' build"
1560 MBEDTLS_ROOT_DIR="$PWD"
1561
1562 cd programs/test/cmake_subproject
1563 cmake .
1564 make
1565 if_build_succeeded ./cmake_subproject
1566
1567 cd "$MBEDTLS_ROOT_DIR"
1568 unset MBEDTLS_ROOT_DIR
1569}
1570
Gilles Peskine8f073122018-11-27 15:58:47 +01001571component_test_zeroize () {
1572 # Test that the function mbedtls_platform_zeroize() is not optimized away by
1573 # different combinations of compilers and optimization flags by using an
1574 # auxiliary GDB script. Unfortunately, GDB does not return error values to the
1575 # system in all cases that the script fails, so we must manually search the
1576 # output to check whether the pass string is present and no failure strings
1577 # were printed.
Andres AGdc192212016-08-31 17:33:13 +01001578
Gilles Peskine4976e822019-01-06 19:52:22 +00001579 # Don't try to disable ASLR. We don't care about ASLR here. We do care
1580 # about a spurious message if Gdb tries and fails, so suppress that.
1581 gdb_disable_aslr=
1582 if [ -z "$(gdb -batch -nw -ex 'set disable-randomization off' 2>&1)" ]; then
1583 gdb_disable_aslr='set disable-randomization off'
1584 fi
1585
Gilles Peskine8f073122018-11-27 15:58:47 +01001586 for optimization_flag in -O2 -O3 -Ofast -Os; do
Gilles Peskine55f7c942019-01-09 22:28:21 +01001587 for compiler in clang gcc; do
1588 msg "test: $compiler $optimization_flag, mbedtls_platform_zeroize()"
1589 make programs CC="$compiler" DEBUG=1 CFLAGS="$optimization_flag"
Gilles Peskine4976e822019-01-06 19:52:22 +00001590 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 +01001591 if_build_succeeded grep "The buffer was correctly zeroized" test_zeroize.log
1592 if_build_succeeded not grep -i "error" test_zeroize.log
1593 rm -f test_zeroize.log
1594 make clean
1595 done
Andres Amaya Garcia29673812017-10-25 10:35:51 +01001596 done
Andres Amaya Garciad0d7bf62017-10-25 09:01:31 +01001597
Gilles Peskine4976e822019-01-06 19:52:22 +00001598 unset gdb_disable_aslr
Gilles Peskine8f073122018-11-27 15:58:47 +01001599}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001600
Gilles Peskineaad2ebd2019-02-25 20:26:06 +01001601support_check_python_files () {
1602 type pylint3 >/dev/null 2>/dev/null
1603}
Gilles Peskine8f073122018-11-27 15:58:47 +01001604component_check_python_files () {
1605 msg "Lint: Python scripts"
1606 record_status tests/scripts/check-python-files.sh
1607}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001608
Gilles Peskine8f073122018-11-27 15:58:47 +01001609component_check_generate_test_code () {
1610 msg "uint test: generate_test_code.py"
1611 record_status ./tests/scripts/test_generate_test_code.py
1612}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001613
1614################################################################
1615#### Termination
1616################################################################
1617
Gilles Peskine8f073122018-11-27 15:58:47 +01001618post_report () {
1619 msg "Done, cleaning up"
1620 cleanup
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001621
Gilles Peskine8f073122018-11-27 15:58:47 +01001622 final_report
1623}
1624
1625
1626
1627################################################################
1628#### Run all the things
1629################################################################
1630
Gilles Peskinee48351a2018-11-27 16:06:30 +01001631# Run one component and clean up afterwards.
Gilles Peskine8f073122018-11-27 15:58:47 +01001632run_component () {
Gilles Peskine608953e2019-01-02 18:57:02 +01001633 # Back up the configuration in case the component modifies it.
1634 # The cleanup function will restore it.
1635 cp -p "$CONFIG_H" "$CONFIG_BAK"
Gilles Peskineffcdeff2018-12-04 12:49:28 +01001636 current_component="$1"
Gilles Peskine9004a172019-09-16 15:20:36 +02001637 export MBEDTLS_TEST_CONFIGURATION="$current_component"
Gilles Peskine2ef377d2019-10-07 18:44:21 +02001638
1639 # Unconditionally create a seedfile that's sufficiently long.
1640 # Do this before each component, because a previous component may
1641 # have messed it up or shortened it.
1642 dd if=/dev/urandom of=./tests/seedfile bs=64 count=1
1643
1644 # Run the component code.
Gilles Peskine8f073122018-11-27 15:58:47 +01001645 "$@"
Gilles Peskine2ef377d2019-10-07 18:44:21 +02001646
1647 # Restore the build tree to a clean state.
Gilles Peskinee48351a2018-11-27 16:06:30 +01001648 cleanup
Gilles Peskine8f073122018-11-27 15:58:47 +01001649}
1650
1651# Preliminary setup
1652pre_check_environment
1653pre_initialize_variables
1654pre_parse_command_line "$@"
Gilles Peskine348fb9a2018-11-27 17:04:29 +01001655
Gilles Peskine878cf602019-01-06 20:50:38 +00001656pre_check_git
Andrzej Kurekeb508712019-02-14 07:18:59 -05001657
Gilles Peskine878cf602019-01-06 20:50:38 +00001658build_status=0
1659if [ $KEEP_GOING -eq 1 ]; then
1660 pre_setup_keep_going
Gilles Peskine92525112018-11-27 18:15:35 +01001661else
Gilles Peskine878cf602019-01-06 20:50:38 +00001662 record_status () {
1663 "$@"
1664 }
Gilles Peskine8f073122018-11-27 15:58:47 +01001665fi
Gilles Peskine67ffdaf2019-09-16 15:55:46 +02001666pre_prepare_outcome_file
Gilles Peskine878cf602019-01-06 20:50:38 +00001667pre_print_configuration
1668pre_check_tools
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001669cleanup
1670
Gilles Peskinebeb3a812019-01-06 22:11:25 +00001671# Run the requested tests.
1672for component in $RUN_COMPONENTS; do
1673 run_component "component_$component"
1674done
Gilles Peskine8f073122018-11-27 15:58:47 +01001675
1676# We're done.
Gilles Peskine878cf602019-01-06 20:50:38 +00001677post_report