blob: 481665a14cf700e368d7b0c2f383fda3ea2de06e [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 Peskine69e8f7f2020-02-26 19:51:43 +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).
Gilles Peskine192c72f2017-12-21 15:59:21 +010045# 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 Peskine92bff7f2019-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 Peskine10726102019-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 Peskine92bff7f2019-01-09 22:29:17 +010070# Each component must start by invoking `msg` with a short informative message.
71#
72# The framework performs some cleanup tasks after each component. This
73# means that components can assume that the working directory is in a
74# cleaned-up state, and don't need to perform the cleanup themselves.
75# * Run `make clean`.
76# * Restore `include/mbedtks/config.h` from a backup made before running
77# the component.
78# * Check out `Makefile`, `library/Makefile`, `programs/Makefile` and
79# `tests/Makefile` from git. This cleans up after an in-tree use of
80# CMake.
81#
82# Any command that is expected to fail must be protected so that the
83# script keeps running in --keep-going mode despite `set -e`. In keep-going
84# mode, if a protected command fails, this is logged as a failure and the
85# script will exit with a failure status once it has run all components.
86# Commands can be protected in any of the following ways:
87# * `make` is a function which runs the `make` command with protection.
88# Note that you must write `make VAR=value`, not `VAR=value make`,
89# because the `VAR=value make` syntax doesn't work with functions.
90# * Put `report_status` before the command to protect it.
91# * Put `if_build_successful` before a command. This protects it, and
92# additionally skips it if a prior invocation of `make` in the same
93# component failed.
94#
Gilles Peskine192c72f2017-12-21 15:59:21 +010095# The tests are roughly in order from fastest to slowest. This doesn't
96# have to be exact, but in general you should add slower tests towards
97# the end and fast checks near the beginning.
Gilles Peskine192c72f2017-12-21 15:59:21 +010098
99
100
101################################################################
102#### Initialization and command line parsing
103################################################################
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100104
SimonB2e23c822016-04-16 21:54:39 +0100105# Abort on errors (and uninitialised variables)
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100106set -eu
107
Gilles Peskine8f073122018-11-27 15:58:47 +0100108pre_check_environment () {
Gilles Peskinebdf3f522019-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 Peskine69e8f7f2020-02-26 19:51:43 +0100120 MEMORY=0
Gilles Peskine8f073122018-11-27 15:58:47 +0100121 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 Peskine69e8f7f2020-02-26 19:51:43 +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"}
Gilles Peskine8f073122018-11-27 15:58:47 +0100137 : ${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 Peskine55ae1622019-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 Peskine10726102019-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 Peskine004206c2019-10-21 17:11:33 +0200149 # CFLAGS and LDFLAGS for Asan builds that don't use CMake
Gilles Peskinebfeed662019-10-21 19:06:33 +0200150 ASAN_CFLAGS='-Werror -Wall -Wextra -fsanitize=address,undefined -fno-sanitize-recover=all'
Gilles Peskine004206c2019-10-21 17:11:33 +0200151
Gilles Peskine10726102019-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 Peskinea49b00f2019-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 Peskine1bcb1c82019-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}
180
Simon Butcher41eeccf2016-09-07 00:07:09 +0100181usage()
SimonB2e23c822016-04-16 21:54:39 +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 Peskinea49b00f2019-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 Peskine10726102019-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 Peskinea49b00f2019-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.
Gilles Peskine69e8f7f2020-02-26 19:51:43 +0100223 --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.
229 --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
Paul Bakkerfe0984d2014-06-13 00:13:45 +0200250 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
257
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 Peskine1bcb1c82019-01-06 22:11:25 +0000332 COMMAND_LINE_COMPONENTS=
Gilles Peskinea49b00f2019-01-10 00:05:18 +0100333 all_except=0
Gilles Peskinee26ab182019-01-06 22:23:42 +0000334 no_armcc=
Gilles Peskine1bcb1c82019-01-06 22:11:25 +0000335
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 Peskine06b385f2019-01-09 22:28:21 +0100340 case "$1" in
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200341 --append-outcome) append_outcome=1;;
Gilles Peskinee26ab182019-01-06 22:23:42 +0000342 --armcc) no_armcc=;;
Gilles Peskine06b385f2019-01-09 22:28:21 +0100343 --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
344 --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
Gilles Peskine1bcb1c82019-01-06 22:11:25 +0000345 --except) all_except=1;;
Gilles Peskine06b385f2019-01-09 22:28:21 +0100346 --force|-f) FORCE=1;;
Gilles Peskine69e8f7f2020-02-26 19:51:43 +0100347 --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";;
Gilles Peskine06b385f2019-01-09 22:28:21 +0100351 --help|-h) usage; exit;;
352 --keep-going|-k) KEEP_GOING=1;;
Gilles Peskine10726102019-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 Peskine69e8f7f2020-02-26 19:51:43 +0100355 --memory|-m) MEMORY=1;;
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200356 --no-append-outcome) append_outcome=0;;
Gilles Peskinee26ab182019-01-06 22:23:42 +0000357 --no-armcc) no_armcc=1;;
Gilles Peskine06b385f2019-01-09 22:28:21 +0100358 --no-force) FORCE=0;;
359 --no-keep-going) KEEP_GOING=0;;
Gilles Peskine69e8f7f2020-02-26 19:51:43 +0100360 --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 Peskine06b385f2019-01-09 22:28:21 +0100365 --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
Gilles Peskine69e8f7f2020-02-26 19:51:43 +0100366 --random-seed) unset SEED;;
367 --release-test|-r) SEED=1;;
368 --seed|-s) shift; SEED="$1";;
Gilles Peskine06b385f2019-01-09 22:28:21 +0100369 -*)
370 echo >&2 "Unknown option: $1"
371 echo >&2 "Run $0 --help for usage."
372 exit 120
373 ;;
Gilles Peskine1bcb1c82019-01-06 22:11:25 +0000374 *) COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS $1";;
Gilles Peskine06b385f2019-01-09 22:28:21 +0100375 esac
376 shift
Gilles Peskine8f073122018-11-27 15:58:47 +0100377 done
Gilles Peskine1bcb1c82019-01-06 22:11:25 +0000378
Gilles Peskinea49b00f2019-01-10 00:05:18 +0100379 # With no list of components, run everything.
Gilles Peskine1bcb1c82019-01-06 22:11:25 +0000380 if [ -z "$COMMAND_LINE_COMPONENTS" ]; then
381 all_except=1
382 fi
383
Gilles Peskinee26ab182019-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 Peskinea49b00f2019-01-10 00:05:18 +0100386 if [ -n "$no_armcc" ] && [ $all_except -eq 1 ]; then
Gilles Peskinee26ab182019-01-06 22:23:42 +0000387 COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS *_armcc*"
388 fi
389
Gilles Peskine1bcb1c82019-01-06 22:11:25 +0000390 # Build the list of components to run.
Gilles Peskinea49b00f2019-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 Peskine1bcb1c82019-01-06 22:11:25 +0000397
398 unset all_except
Gilles Peskinee26ab182019-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 Peskined692e112019-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 Peskineadd1d232019-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
Andres AGdc192212016-08-31 17:33:13 +0100422 fi
Gilles Peskine8f073122018-11-27 15:58:47 +0100423}
Andres AGdc192212016-08-31 17:33:13 +0100424
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"
Gilles Peskine69e8f7f2020-02-26 19:51:43 +0100504 echo "MEMORY: $MEMORY"
Gilles Peskine8f073122018-11-27 15:58:47 +0100505 echo "FORCE: $FORCE"
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200506 echo "MBEDTLS_TEST_OUTCOME_FILE: ${MBEDTLS_TEST_OUTCOME_FILE:-(none)}"
Gilles Peskine69e8f7f2020-02-26 19:51:43 +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"
Gilles Peskine8f073122018-11-27 15:58:47 +0100515 echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
516 echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
517}
Andres AG87bb5772016-09-27 15:05:15 +0100518
Gilles Peskine657f59a2019-01-06 22:40:00 +0000519# Make sure the tools we need are available.
Gilles Peskine8f073122018-11-27 15:58:47 +0100520pre_check_tools () {
Gilles Peskine2edf47c2019-01-06 22:46:21 +0000521 # Build the list of variables to pass to output_env.sh.
522 set env
523
Gilles Peskine657f59a2019-01-06 22:40:00 +0000524 case " $RUN_COMPONENTS " in
Gilles Peskine69e8f7f2020-02-26 19:51:43 +0100525 # 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
538 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"
542 check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$OPENSSL_NEXT" \
543 "$GNUTLS_CLI" "$GNUTLS_SERV" \
544 "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV"
545 ;;
546 esac
547
548 case " $RUN_COMPONENTS " in
Gilles Peskine657f59a2019-01-06 22:40:00 +0000549 *_doxygen[_\ ]*) check_tools "doxygen" "dot";;
550 esac
Andres AGb2fdd042016-09-22 14:17:46 +0100551
Gilles Peskine657f59a2019-01-06 22:40:00 +0000552 case " $RUN_COMPONENTS " in
553 *_arm_none_eabi_gcc[_\ ]*) check_tools "arm-none-eabi-gcc";;
554 esac
Andres AG7770ea82016-10-10 15:46:20 +0100555
Gilles Peskine657f59a2019-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 Peskinee26ab182019-01-06 22:23:42 +0000565 *_armcc*)
Gilles Peskine657f59a2019-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 Peskinee26ab182019-01-06 22:23:42 +0000570 check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC6_CC" "$ARMC6_AR";;
571 esac
Gilles Peskine2edf47c2019-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}
Gilles Peskine192c72f2017-12-21 15:59:21 +0100581
582
Gilles Peskine2edf47c2019-01-06 22:46:21 +0000583
Gilles Peskine192c72f2017-12-21 15:59:21 +0100584################################################################
585#### Basic checks
586################################################################
Andres AGd9eba4b2016-08-26 14:42:14 +0100587
SimonB2e23c822016-04-16 21:54:39 +0100588#
589# Test Suites to be executed
590#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200591# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100592# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard61bc57a2014-08-14 11:29:06 +0200593# and/or are more likely to fail than others (eg I use Clang most of the
594# time, so start with a GCC build).
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200595# 2. Minimize total running time, by avoiding useless rebuilds
596#
597# Indicative running times are given for reference.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100598
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}
Manuel Pégourié-Gonnardea29d152014-11-20 17:32:33 +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é-Gonnardb3b8e432015-02-13 14:52:19 +0000608
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é-Gonnardd09a6b52015-04-09 17:19:23 +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}
Darryl Greena07039c2018-03-13 16:48:16 +0000618
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}
Manuel Pégourié-Gonnarda687baf2015-04-09 11:09:03 +0200623
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é-Gonnard1d552e72016-01-04 16:49:09 +0100633
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é-Gonnard3895f5a2014-03-27 14:44:04 +0100660
Gilles Peskine8f073122018-11-27 15:58:47 +0100661 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
662 make test
Gilles Peskine69e8f7f2020-02-26 19:51:43 +0100663
664 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
665 if_build_succeeded tests/ssl-opt.sh
666
667 msg "test: compat.sh (ASan build)" # ~ 6 min
668 if_build_succeeded tests/compat.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100669}
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
Hanno Becker01635512019-02-26 14:27:09 +0000679}
680
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}
686
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 Peskine69e8f7f2020-02-26 19:51:43 +0100700component_test_sslv3 () {
701 msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
702 scripts/config.pl set MBEDTLS_SSL_PROTO_SSL3
703 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
704 make
705
706 msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
707 make test
708
709 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'
712
713 msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
714 if_build_succeeded tests/ssl-opt.sh
715}
716
717component_test_no_renegotiation () {
718 msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
719 scripts/config.pl unset MBEDTLS_SSL_RENEGOTIATION
720 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
721 make
722
723 msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
724 make test
725
726 msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
727 if_build_succeeded tests/ssl-opt.sh
728}
729
Gilles Peskine8f073122018-11-27 15:58:47 +0100730component_test_rsa_no_crt () {
731 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
Gilles Peskine3bdd4122019-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
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100735
Gilles Peskine8f073122018-11-27 15:58:47 +0100736 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
737 make test
Gilles Peskine69e8f7f2020-02-26 19:51:43 +0100738
739 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
741
742 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}
745
746component_test_small_ssl_out_content_len () {
747 msg "build: small SSL_OUT_CONTENT_LEN (ASan build)"
748 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 16384
749 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
750 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
751 make
752
753 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}
756
757component_test_small_ssl_in_content_len () {
758 msg "build: small SSL_IN_CONTENT_LEN (ASan build)"
759 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 4096
760 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 16384
761 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
762 make
763
764 msg "test: small SSL_IN_CONTENT_LEN - ssl-opt.sh MFL tests"
765 if_build_succeeded tests/ssl-opt.sh -f "Max fragment"
766}
767
768component_test_small_ssl_dtls_max_buffering () {
769 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0"
770 scripts/config.pl set MBEDTLS_SSL_DTLS_MAX_BUFFERING 1000
771 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
772 make
773
774 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}
777
778component_test_small_mbedtls_ssl_dtls_max_buffering () {
779 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1"
780 scripts/config.pl set MBEDTLS_SSL_DTLS_MAX_BUFFERING 240
781 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
782 make
783
784 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"
Gilles Peskine8f073122018-11-27 15:58:47 +0100786}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100787
Gilles Peskinee023c802019-02-22 12:31:02 +0100788component_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
Gilles Peskinee023c802019-02-22 12:31:02 +0100791 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
Manuel Pégourié-Gonnard9fece7e2018-06-18 11:38:22 +0200796}
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200797
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 Peskine3bdd4122019-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
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200823
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é-Gonnard80955ee2014-03-19 18:29:01 +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
830 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'
832
833 msg "test: compat.sh RC4, DES, 3DES & NULL (full config)" # ~ 2 min
834 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'
835
836 msg "test: compat.sh ARIA + ChachaPoly"
837 if_build_succeeded env OPENSSL_CMD="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
Gilles Peskine8f073122018-11-27 15:58:47 +0100838}
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100839
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 Peskine3bdd4122019-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
Gilles Peskineb4ef45b2018-03-01 22:23:50 +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 Peskine3bdd4122019-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}
Gilles Peskine0afe6242018-02-21 19:28:12 +0100870
Gilles Peskine8f073122018-11-27 15:58:47 +0100871component_test_depends_curves () {
872 msg "test/build: curves.pl (gcc)" # ~ 4 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100873 record_status tests/scripts/curves.pl
874}
Manuel Pégourié-Gonnard1fe6bb92017-06-06 11:36:16 +0200875
Gilles Peskine8f073122018-11-27 15:58:47 +0100876component_test_depends_hashes () {
877 msg "test/build: depends-hashes.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100878 record_status tests/scripts/depends-hashes.pl
879}
Manuel Pégourié-Gonnard43be6cd2017-06-20 09:53:42 +0200880
Gilles Peskine8f073122018-11-27 15:58:47 +0100881component_test_depends_pkalgs () {
882 msg "test/build: depends-pkalgs.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100883 record_status tests/scripts/depends-pkalgs.pl
884}
Manuel Pégourié-Gonnard503a5ef2015-10-23 09:04:45 +0200885
Gilles Peskine69e8f7f2020-02-26 19:51:43 +0100886component_build_key_exchanges () {
887 msg "test/build: key-exchanges (gcc)" # ~ 1 min
888 record_status tests/scripts/key-exchanges.pl
889}
890
Gilles Peskine8f073122018-11-27 15:58:47 +0100891component_build_default_make_gcc_and_cxx () {
892 msg "build: Unix make, -Os (gcc)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100893 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400894
Gilles Peskine8f073122018-11-27 15:58:47 +0100895 msg "test: verify header list in cpp_dummy_build.cpp"
896 record_status check_headers_in_cpp
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400897
Gilles Peskine8f073122018-11-27 15:58:47 +0100898 msg "build: Unix make, incremental g++"
899 make TEST_CPP=1
900}
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +0000901
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100902component_test_no_use_psa_crypto_full_cmake_asan() {
903 # full minus MBEDTLS_USE_PSA_CRYPTO: run the same set of tests as basic-build-test.sh
Gilles Peskinedc3a1792019-09-03 11:42:04 +0200904 msg "build: cmake, full config minus MBEDTLS_USE_PSA_CRYPTO, ASan"
Gilles Peskine3bdd4122019-07-27 23:52:53 +0200905 scripts/config.py full
Gilles Peskine3bdd4122019-07-27 23:52:53 +0200906 scripts/config.py set MBEDTLS_ECP_RESTARTABLE # not using PSA, so enable restartable ECC
907 scripts/config.py set MBEDTLS_PSA_CRYPTO_C
908 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
909 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C
910 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
Jaeden Amero67ea2c52019-02-11 12:05:54 +0000911 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500912 make
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100913
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100914 msg "test: main suites (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500915 make test
Gilles Peskine69e8f7f2020-02-26 19:51:43 +0100916
917 msg "test: ssl-opt.sh (MBEDTLS_USE_PSA_CRYPTO)"
918 if_build_succeeded tests/ssl-opt.sh
919
920 msg "test: compat.sh default (MBEDTLS_USE_PSA_CRYPTO)"
921 if_build_succeeded tests/compat.sh
922
923 msg "test: compat.sh ssl3 (MBEDTLS_USE_PSA_CRYPTO)"
924 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
925
926 msg "test: compat.sh RC4, DES & NULL (MBEDTLS_USE_PSA_CRYPTO)"
927 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'
928
929 msg "test: compat.sh ARIA + ChachaPoly (MBEDTLS_USE_PSA_CRYPTO)"
930 if_build_succeeded env OPENSSL_CMD="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500931}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500932
Gilles Peskineadcde5e2019-06-12 16:05:50 +0200933component_test_check_params_functionality () {
934 msg "build+test: MBEDTLS_CHECK_PARAMS functionality"
Gilles Peskine3bdd4122019-07-27 23:52:53 +0200935 scripts/config.py full # includes CHECK_PARAMS
Gilles Peskineadcde5e2019-06-12 16:05:50 +0200936 # Make MBEDTLS_PARAM_FAILED call mbedtls_param_failed().
Gilles Peskine3bdd4122019-07-27 23:52:53 +0200937 scripts/config.py unset MBEDTLS_CHECK_PARAMS_ASSERT
Gilles Peskineadcde5e2019-06-12 16:05:50 +0200938 # Only build and run tests. Do not build sample programs, because
939 # they don't have a mbedtls_param_failed() function.
940 make CC=gcc CFLAGS='-Werror -O1' lib test
941}
942
Gilles Peskineb28636b2019-01-02 19:06:24 +0100943component_test_check_params_without_platform () {
944 msg "build+test: MBEDTLS_CHECK_PARAMS without MBEDTLS_PLATFORM_C"
Gilles Peskine3bdd4122019-07-27 23:52:53 +0200945 scripts/config.py full # includes CHECK_PARAMS
Gilles Peskineadcde5e2019-06-12 16:05:50 +0200946 # Keep MBEDTLS_PARAM_FAILED as assert.
Gilles Peskine3bdd4122019-07-27 23:52:53 +0200947 scripts/config.py unset MBEDTLS_PLATFORM_EXIT_ALT
948 scripts/config.py unset MBEDTLS_PLATFORM_TIME_ALT
949 scripts/config.py unset MBEDTLS_PLATFORM_FPRINTF_ALT
950 scripts/config.py unset MBEDTLS_PLATFORM_MEMORY
951 scripts/config.py unset MBEDTLS_PLATFORM_PRINTF_ALT
952 scripts/config.py unset MBEDTLS_PLATFORM_SNPRINTF_ALT
953 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
954 scripts/config.py unset MBEDTLS_PLATFORM_C
Gilles Peskineb28636b2019-01-02 19:06:24 +0100955 make CC=gcc CFLAGS='-Werror -O1' all test
956}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500957
Gilles Peskineb28636b2019-01-02 19:06:24 +0100958component_test_check_params_silent () {
959 msg "build+test: MBEDTLS_CHECK_PARAMS with alternative MBEDTLS_PARAM_FAILED()"
Gilles Peskine3bdd4122019-07-27 23:52:53 +0200960 scripts/config.py full # includes CHECK_PARAMS
Gilles Peskineadcde5e2019-06-12 16:05:50 +0200961 # Set MBEDTLS_PARAM_FAILED to nothing.
Gilles Peskineb28636b2019-01-02 19:06:24 +0100962 sed -i 's/.*\(#define MBEDTLS_PARAM_FAILED( cond )\).*/\1/' "$CONFIG_H"
963 make CC=gcc CFLAGS='-Werror -O1' all test
964}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500965
Gilles Peskine8f073122018-11-27 15:58:47 +0100966component_test_no_platform () {
967 # Full configuration build, without platform support, file IO and net sockets.
968 # This should catch missing mbedtls_printf definitions, and by disabling file
969 # IO, it should catch missing '#include <stdio.h>'
970 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Gilles Peskine3bdd4122019-07-27 23:52:53 +0200971 scripts/config.py full
972 scripts/config.py unset MBEDTLS_PLATFORM_C
Gilles Peskine4e117492020-02-26 18:56:08 +0100973 scripts/config.py unset MBEDTLS_NET_C
Gilles Peskine3bdd4122019-07-27 23:52:53 +0200974 scripts/config.py unset MBEDTLS_PLATFORM_MEMORY
975 scripts/config.py unset MBEDTLS_PLATFORM_PRINTF_ALT
976 scripts/config.py unset MBEDTLS_PLATFORM_FPRINTF_ALT
977 scripts/config.py unset MBEDTLS_PLATFORM_SNPRINTF_ALT
978 scripts/config.py unset MBEDTLS_PLATFORM_TIME_ALT
979 scripts/config.py unset MBEDTLS_PLATFORM_EXIT_ALT
980 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskine3bdd4122019-07-27 23:52:53 +0200981 scripts/config.py unset MBEDTLS_FS_IO
982 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
983 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
984 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C
Gilles Peskine8f073122018-11-27 15:58:47 +0100985 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
986 # to re-enable platform integration features otherwise disabled in C99 builds
987 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -O0 -D_DEFAULT_SOURCE' lib programs
988 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0' test
989}
Manuel Pégourié-Gonnarddccb80b2015-06-03 10:20:33 +0100990
Gilles Peskine8f073122018-11-27 15:58:47 +0100991component_build_no_std_function () {
992 # catch compile bugs in _uninit functions
993 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
Gilles Peskine3bdd4122019-07-27 23:52:53 +0200994 scripts/config.py full
995 scripts/config.py set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
996 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskine8f073122018-11-27 15:58:47 +0100997 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
998}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200999
Gilles Peskine69e8f7f2020-02-26 19:51:43 +01001000component_build_no_ssl_srv () {
1001 msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
1002 scripts/config.pl full
1003 scripts/config.pl unset MBEDTLS_SSL_SRV_C
1004 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
1005}
1006
1007component_build_no_ssl_cli () {
1008 msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
1009 scripts/config.pl full
1010 scripts/config.pl unset MBEDTLS_SSL_CLI_C
1011 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
1012}
1013
1014component_build_no_sockets () {
1015 # Note, C99 compliance can also be tested with the sockets support disabled,
1016 # as that requires a POSIX platform (which isn't the same as C99).
1017 msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
1018 scripts/config.pl full
1019 scripts/config.pl unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
1020 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
1021 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0 -std=c99 -pedantic' lib
1022}
1023
Gilles Peskine26e4fdc2020-03-02 21:15:04 +01001024component_test_memory_buffer_allocator_backtrace () {
1025 msg "build: default config with memory buffer allocator and backtrace enabled"
1026 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
1027 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
1028 scripts/config.py set MBEDTLS_MEMORY_BACKTRACE
1029 scripts/config.py set MBEDTLS_MEMORY_DEBUG
1030 CC=gcc cmake .
1031 make
1032
1033 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C and MBEDTLS_MEMORY_BACKTRACE"
1034 make test
1035}
1036
1037component_test_memory_buffer_allocator () {
1038 msg "build: default config with memory buffer allocator"
1039 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
1040 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
1041 CC=gcc cmake .
1042 make
1043
1044 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C"
1045 make test
1046}
1047
Gilles Peskine69e8f7f2020-02-26 19:51:43 +01001048component_test_no_max_fragment_length () {
1049 # Run max fragment length tests with MFL disabled
1050 msg "build: default config except MFL extension (ASan build)" # ~ 30s
1051 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
1052 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1053 make
1054
1055 msg "test: ssl-opt.sh, MFL-related tests"
1056 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length"
1057}
1058
1059component_test_asan_remove_peer_certificate () {
1060 msg "build: default config with MBEDTLS_SSL_KEEP_PEER_CERTIFICATE disabled (ASan build)"
1061 scripts/config.pl unset MBEDTLS_SSL_KEEP_PEER_CERTIFICATE
1062 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1063 make
1064
1065 msg "test: !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
1066 make test
1067
1068 msg "test: ssl-opt.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
1069 if_build_succeeded tests/ssl-opt.sh
1070
1071 msg "test: compat.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
1072 if_build_succeeded tests/compat.sh
1073}
1074
1075component_test_no_max_fragment_length_small_ssl_out_content_len () {
1076 msg "build: no MFL extension, small SSL_OUT_CONTENT_LEN (ASan build)"
1077 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
1078 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 16384
1079 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
1080 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1081 make
1082
1083 msg "test: MFL tests (disabled MFL extension case) & large packet tests"
1084 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length\|Large buffer"
1085}
1086
Gilles Peskine8f073122018-11-27 15:58:47 +01001087component_test_null_entropy () {
1088 msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001089 scripts/config.py set MBEDTLS_TEST_NULL_ENTROPY
1090 scripts/config.py set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
1091 scripts/config.py set MBEDTLS_ENTROPY_C
1092 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
1093 scripts/config.py unset MBEDTLS_ENTROPY_HARDWARE_ALT
1094 scripts/config.py unset MBEDTLS_HAVEGE_C
Gilles Peskine19275652019-01-06 19:48:30 +00001095 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan -D UNSAFE_BUILD=ON .
Gilles Peskine8f073122018-11-27 15:58:47 +01001096 make
Janos Follath06c54002016-06-09 13:57:40 +01001097
Gilles Peskine8f073122018-11-27 15:58:47 +01001098 msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)"
1099 make test
1100}
Hanno Beckere5fecec2018-10-11 11:02:52 +01001101
Gilles Peskine8f073122018-11-27 15:58:47 +01001102component_test_platform_calloc_macro () {
1103 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001104 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
1105 scripts/config.py set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
1106 scripts/config.py set MBEDTLS_PLATFORM_FREE_MACRO free
Gilles Peskine8f073122018-11-27 15:58:47 +01001107 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1108 make
Hanno Beckere5fecec2018-10-11 11:02:52 +01001109
Gilles Peskine8f073122018-11-27 15:58:47 +01001110 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
1111 make test
1112}
Hanno Becker83ebf782017-07-07 12:29:15 +01001113
Gilles Peskine31b0a3c2019-09-17 19:04:38 +02001114component_test_malloc_0_null () {
1115 msg "build: malloc(0) returns NULL (ASan+UBSan build)"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001116 scripts/config.py full
Gilles Peskine004206c2019-10-21 17:11:33 +02001117 make CC=gcc CFLAGS="'-DMBEDTLS_CONFIG_FILE=\"$PWD/tests/configs/config-wrapper-malloc-0-null.h\"' $ASAN_CFLAGS -O" LDFLAGS="$ASAN_CFLAGS"
Gilles Peskine31b0a3c2019-09-17 19:04:38 +02001118
1119 msg "test: malloc(0) returns NULL (ASan+UBSan build)"
1120 make test
1121
1122 msg "selftest: malloc(0) returns NULL (ASan+UBSan build)"
1123 # Just the calloc selftest. "make test" ran the others as part of the
1124 # test suites.
1125 if_build_succeeded programs/test/selftest calloc
1126}
1127
Gilles Peskine8f073122018-11-27 15:58:47 +01001128component_test_aes_fewer_tables () {
1129 msg "build: default config with AES_FEWER_TABLES enabled"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001130 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
Gilles Peskine8f073122018-11-27 15:58:47 +01001131 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01001132
Gilles Peskine8f073122018-11-27 15:58:47 +01001133 msg "test: AES_FEWER_TABLES"
1134 make test
1135}
Hanno Becker83ebf782017-07-07 12:29:15 +01001136
Gilles Peskine8f073122018-11-27 15:58:47 +01001137component_test_aes_rom_tables () {
1138 msg "build: default config with AES_ROM_TABLES enabled"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001139 scripts/config.py set MBEDTLS_AES_ROM_TABLES
Gilles Peskine8f073122018-11-27 15:58:47 +01001140 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01001141
Gilles Peskine8f073122018-11-27 15:58:47 +01001142 msg "test: AES_ROM_TABLES"
1143 make test
1144}
Hanno Becker83ebf782017-07-07 12:29:15 +01001145
Gilles Peskine8f073122018-11-27 15:58:47 +01001146component_test_aes_fewer_tables_and_rom_tables () {
1147 msg "build: default config with AES_ROM_TABLES and AES_FEWER_TABLES enabled"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001148 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
1149 scripts/config.py set MBEDTLS_AES_ROM_TABLES
Gilles Peskine8f073122018-11-27 15:58:47 +01001150 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01001151
Gilles Peskine8f073122018-11-27 15:58:47 +01001152 msg "test: AES_FEWER_TABLES + AES_ROM_TABLES"
1153 make test
1154}
1155
Gilles Peskine592f5912019-10-07 18:49:32 +02001156component_test_ctr_drbg_aes_256_sha_256 () {
1157 msg "build: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
1158 scripts/config.pl full
1159 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
1160 scripts/config.pl set MBEDTLS_ENTROPY_FORCE_SHA256
1161 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1162 make
1163
1164 msg "test: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
1165 make test
1166}
1167
1168component_test_ctr_drbg_aes_128_sha_512 () {
1169 msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)"
1170 scripts/config.pl full
1171 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
1172 scripts/config.pl set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
1173 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1174 make
1175
1176 msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)"
1177 make test
1178}
1179
1180component_test_ctr_drbg_aes_128_sha_256 () {
1181 msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
1182 scripts/config.pl full
1183 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
1184 scripts/config.pl set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
1185 scripts/config.pl set MBEDTLS_ENTROPY_FORCE_SHA256
1186 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1187 make
1188
1189 msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
1190 make test
1191}
1192
Gilles Peskinef96aefe2019-07-24 14:58:38 +02001193component_test_se_default () {
1194 msg "build: default config + MBEDTLS_PSA_CRYPTO_SE_C"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001195 scripts/config.py set MBEDTLS_PSA_CRYPTO_SE_C
Gilles Peskine004206c2019-10-21 17:11:33 +02001196 make CC=clang CFLAGS="$ASAN_CFLAGS -Os" LDFLAGS="$ASAN_CFLAGS"
Gilles Peskinef96aefe2019-07-24 14:58:38 +02001197
1198 msg "test: default config + MBEDTLS_PSA_CRYPTO_SE_C"
1199 make test
1200}
1201
1202component_test_se_full () {
1203 msg "build: full config + MBEDTLS_PSA_CRYPTO_SE_C"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001204 scripts/config.py full
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001205 scripts/config.py set MBEDTLS_PSA_CRYPTO_SE_C
Gilles Peskine004206c2019-10-21 17:11:33 +02001206 make CC=gcc CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
Gilles Peskinef96aefe2019-07-24 14:58:38 +02001207
1208 msg "test: full config + MBEDTLS_PSA_CRYPTO_SE_C"
1209 make test
1210}
1211
Gilles Peskine8f073122018-11-27 15:58:47 +01001212component_test_make_shared () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001213 msg "build/test: make shared" # ~ 40s
Andrzej Kurek232e8f92019-10-03 03:18:01 -04001214 make SHARED=1 all check
Gilles Peskine56c01612019-07-03 20:43:32 +02001215 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskine8f073122018-11-27 15:58:47 +01001216}
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +02001217
Gilles Peskinecf740502019-07-03 20:43:05 +02001218component_test_cmake_shared () {
1219 msg "build/test: cmake shared" # ~ 2min
1220 cmake -DUSE_SHARED_MBEDTLS_LIBRARY=On .
1221 make
Gilles Peskine56c01612019-07-03 20:43:32 +02001222 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskinecf740502019-07-03 20:43:05 +02001223 make test
1224}
1225
Gilles Peskineabf9b4d2019-07-03 20:42:16 +02001226component_build_mbedtls_config_file () {
1227 msg "build: make with MBEDTLS_CONFIG_FILE" # ~40s
1228 # Use the full config so as to catch a maximum of places where
1229 # the check of MBEDTLS_CONFIG_FILE might be missing.
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001230 scripts/config.py full
Gilles Peskineabf9b4d2019-07-03 20:42:16 +02001231 sed 's!"check_config.h"!"mbedtls/check_config.h"!' <"$CONFIG_H" >full_config.h
1232 echo '#error "MBEDTLS_CONFIG_FILE is not working"' >"$CONFIG_H"
1233 make CFLAGS="-I '$PWD' -DMBEDTLS_CONFIG_FILE='\"full_config.h\"'"
1234 rm -f full_config.h
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001235}
1236
Gilles Peskine8f073122018-11-27 15:58:47 +01001237component_test_m32_o0 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001238 # Build once with -O0, to compile out the i386 specific inline assembly
1239 msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001240 scripts/config.py full
Gilles Peskine004206c2019-10-21 17:11:33 +02001241 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O0" LDFLAGS="-m32 $ASAN_CFLAGS"
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01001242
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001243 msg "test: i386, make, gcc -O0 (ASan build)"
1244 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01001245}
Gilles Peskine10726102019-01-06 20:50:38 +00001246support_test_m32_o0 () {
1247 case $(uname -m) in
1248 *64*) true;;
1249 *) false;;
1250 esac
1251}
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001252
Gilles Peskine8f073122018-11-27 15:58:47 +01001253component_test_m32_o1 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001254 # Build again with -O1, to compile in the i386 specific inline assembly
1255 msg "build: i386, make, gcc -O1 (ASan build)" # ~ 30s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001256 scripts/config.py full
Gilles Peskine004206c2019-10-21 17:11:33 +02001257 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O1" LDFLAGS="-m32 $ASAN_CFLAGS"
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001258
1259 msg "test: i386, make, gcc -O1 (ASan build)"
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001260 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01001261}
Gilles Peskine10726102019-01-06 20:50:38 +00001262support_test_m32_o1 () {
1263 support_test_m32_o0 "$@"
1264}
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001265
Gilles Peskine09a24b32019-04-12 20:29:48 +02001266component_test_m32_everest () {
1267 msg "build: i386, Everest ECDH context (ASan build)" # ~ 6 min
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001268 scripts/config.py unset MBEDTLS_ECDH_LEGACY_CONTEXT
1269 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
Gilles Peskine004206c2019-10-21 17:11:33 +02001270 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O2" LDFLAGS="-m32 $ASAN_CFLAGS"
Gilles Peskine09a24b32019-04-12 20:29:48 +02001271
1272 msg "test: i386, Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
1273 make test
1274}
1275support_test_m32_everest () {
1276 support_test_m32_o0 "$@"
1277}
1278
Gilles Peskine8f073122018-11-27 15:58:47 +01001279component_test_mx32 () {
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001280 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001281 scripts/config.py full
Gilles Peskine5d26e7c2019-06-07 14:50:09 +02001282 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32' LDFLAGS='-mx32'
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001283
1284 msg "test: 64-bit ILP32, make, gcc"
1285 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01001286}
Gilles Peskine10726102019-01-06 20:50:38 +00001287support_test_mx32 () {
1288 case $(uname -m) in
1289 amd64|x86_64) true;;
1290 *) false;;
1291 esac
1292}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001293
Peter Kolbus60c6da22018-12-27 06:59:04 -06001294component_test_min_mpi_window_size () {
1295 msg "build: Default + MBEDTLS_MPI_WINDOW_SIZE=1 (ASan build)" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001296 scripts/config.py set MBEDTLS_MPI_WINDOW_SIZE 1
Peter Kolbus60c6da22018-12-27 06:59:04 -06001297 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1298 make
1299
1300 msg "test: MBEDTLS_MPI_WINDOW_SIZE=1 - main suites (inc. selftests) (ASan build)" # ~ 10s
1301 make test
1302}
1303
Gilles Peskine8f073122018-11-27 15:58:47 +01001304component_test_have_int32 () {
1305 msg "build: gcc, force 32-bit bignum limbs"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001306 scripts/config.py unset MBEDTLS_HAVE_ASM
1307 scripts/config.py unset MBEDTLS_AESNI_C
1308 scripts/config.py unset MBEDTLS_PADLOCK_C
Gilles Peskine8f073122018-11-27 15:58:47 +01001309 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01001310
Gilles Peskine8f073122018-11-27 15:58:47 +01001311 msg "test: gcc, force 32-bit bignum limbs"
1312 make test
1313}
Andres Amaya Garciafe843a32017-07-20 13:21:34 +01001314
Gilles Peskine8f073122018-11-27 15:58:47 +01001315component_test_have_int64 () {
1316 msg "build: gcc, force 64-bit bignum limbs"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001317 scripts/config.py unset MBEDTLS_HAVE_ASM
1318 scripts/config.py unset MBEDTLS_AESNI_C
1319 scripts/config.py unset MBEDTLS_PADLOCK_C
Gilles Peskine8f073122018-11-27 15:58:47 +01001320 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
Gilles Peskine14c3c062018-01-29 21:25:12 +01001321
Gilles Peskine8f073122018-11-27 15:58:47 +01001322 msg "test: gcc, force 64-bit bignum limbs"
1323 make test
1324}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001325
Gilles Peskine8f073122018-11-27 15:58:47 +01001326component_test_no_udbl_division () {
1327 msg "build: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001328 scripts/config.py full
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001329 scripts/config.py set MBEDTLS_NO_UDBL_DIVISION
Gilles Peskine8f073122018-11-27 15:58:47 +01001330 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001331
Gilles Peskine8f073122018-11-27 15:58:47 +01001332 msg "test: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
1333 make test
1334}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001335
Gilles Peskine8f073122018-11-27 15:58:47 +01001336component_test_no_64bit_multiplication () {
1337 msg "build: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001338 scripts/config.py full
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001339 scripts/config.py set MBEDTLS_NO_64BIT_MULTIPLICATION
Gilles Peskine8f073122018-11-27 15:58:47 +01001340 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001341
Gilles Peskine8f073122018-11-27 15:58:47 +01001342 msg "test: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
1343 make test
1344}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001345
Gilles Peskine8f073122018-11-27 15:58:47 +01001346component_build_arm_none_eabi_gcc () {
1347 msg "build: arm-none-eabi-gcc, make" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001348 scripts/config.py baremetal
Gilles Peskine8f073122018-11-27 15:58:47 +01001349 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
1350}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001351
Gilles Peskine2c897d72019-08-09 16:05:05 +02001352component_build_arm_none_eabi_gcc_arm5vte () {
Gilles Peskine8a52af92019-08-08 16:09:02 +02001353 msg "build: arm-none-eabi-gcc -march=arm5vte, make" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001354 scripts/config.py baremetal
Gilles Peskine2c897d72019-08-09 16:05:05 +02001355 # Build for a target platform that's close to what Debian uses
1356 # for its "armel" distribution (https://wiki.debian.org/ArmEabiPort).
1357 # See https://github.com/ARMmbed/mbedtls/pull/2169 and comments.
1358 # It would be better to build with arm-linux-gnueabi-gcc but
1359 # we don't have that on our CI at this time.
Gilles Peskine8a52af92019-08-08 16:09:02 +02001360 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 +02001361}
1362
Gilles Peskine8f073122018-11-27 15:58:47 +01001363component_build_arm_none_eabi_gcc_no_udbl_division () {
1364 msg "build: arm-none-eabi-gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001365 scripts/config.py baremetal
1366 scripts/config.py set MBEDTLS_NO_UDBL_DIVISION
Gilles Peskine8f073122018-11-27 15:58:47 +01001367 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
1368 echo "Checking that software 64-bit division is not required"
1369 if_build_succeeded not grep __aeabi_uldiv library/*.o
1370}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001371
Gilles Peskine8f073122018-11-27 15:58:47 +01001372component_build_arm_none_eabi_gcc_no_64bit_multiplication () {
1373 msg "build: arm-none-eabi-gcc MBEDTLS_NO_64BIT_MULTIPLICATION, make" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001374 scripts/config.py baremetal
1375 scripts/config.py set MBEDTLS_NO_64BIT_MULTIPLICATION
Gilles Peskine8f073122018-11-27 15:58:47 +01001376 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -O1 -march=armv6-m -mthumb' lib
1377 echo "Checking that software 64-bit multiplication is not required"
1378 if_build_succeeded not grep __aeabi_lmul library/*.o
1379}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001380
Gilles Peskine8f073122018-11-27 15:58:47 +01001381component_build_armcc () {
1382 msg "build: ARM Compiler 5, make"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001383 scripts/config.py baremetal
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001384
Gilles Peskinee26ab182019-01-06 22:23:42 +00001385 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
1386 make clean
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001387
Gilles Peskinee26ab182019-01-06 22:23:42 +00001388 # ARM Compiler 6 - Target ARMv7-A
1389 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-a"
Gilles Peskineed942f82017-06-08 15:19:20 +02001390
Gilles Peskinee26ab182019-01-06 22:23:42 +00001391 # ARM Compiler 6 - Target ARMv7-M
1392 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m"
Andres AG87bb5772016-09-27 15:05:15 +01001393
Gilles Peskinee26ab182019-01-06 22:23:42 +00001394 # ARM Compiler 6 - Target ARMv8-A - AArch32
1395 armc6_build_test "--target=arm-arm-none-eabi -march=armv8.2-a"
Andres AG87bb5772016-09-27 15:05:15 +01001396
Gilles Peskinee26ab182019-01-06 22:23:42 +00001397 # ARM Compiler 6 - Target ARMv8-M
1398 armc6_build_test "--target=arm-arm-none-eabi -march=armv8-m.main"
Simon Butcher940737f2017-07-23 13:42:36 +02001399
Gilles Peskinee26ab182019-01-06 22:23:42 +00001400 # ARM Compiler 6 - Target ARMv8-A - AArch64
1401 armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a"
Gilles Peskine8f073122018-11-27 15:58:47 +01001402}
Simon Butcher940737f2017-07-23 13:42:36 +02001403
Gilles Peskine69e8f7f2020-02-26 19:51:43 +01001404component_test_allow_sha1 () {
1405 msg "build: allow SHA1 in certificates by default"
1406 scripts/config.pl set MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
1407 make CFLAGS='-Werror -Wall -Wextra'
1408 msg "test: allow SHA1 in certificates by default"
1409 make test
1410 if_build_succeeded tests/ssl-opt.sh -f SHA-1
1411}
1412
Gilles Peskine8f073122018-11-27 15:58:47 +01001413component_build_mingw () {
1414 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
Andrzej Kurek232e8f92019-10-03 03:18:01 -04001415 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -Wall -Wextra' WINDOWS_BUILD=1 lib programs
Gilles Peskine2a458da2017-05-12 15:26:58 +02001416
Gilles Peskine8f073122018-11-27 15:58:47 +01001417 # note Make tests only builds the tests, but doesn't run them
Andrzej Kurek232e8f92019-10-03 03:18:01 -04001418 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 +01001419 make WINDOWS_BUILD=1 clean
Hanno Beckere963efa2018-01-03 10:03:43 +00001420
Gilles Peskine8f073122018-11-27 15:58:47 +01001421 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
Andrzej Kurek232e8f92019-10-03 03:18:01 -04001422 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
1423 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 +01001424 make WINDOWS_BUILD=1 clean
1425}
Jaeden Amero117b8a42019-04-17 15:19:26 +01001426support_build_mingw() {
1427 case $(i686-w64-mingw32-gcc -dumpversion) in
1428 [0-5]*) false;;
1429 *) true;;
1430 esac
1431}
Simon Butcher002bc622016-11-17 09:27:45 +00001432
Gilles Peskine8f073122018-11-27 15:58:47 +01001433component_test_memsan () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001434 msg "build: MSan (clang)" # ~ 1 min 20s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001435 scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001436 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
1437 make
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001438
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001439 msg "test: main suites (MSan)" # ~ 10s
1440 make test
Gilles Peskine69e8f7f2020-02-26 19:51:43 +01001441
1442 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
1443 if_build_succeeded tests/ssl-opt.sh
1444
1445 # Optional part(s)
1446
1447 if [ "$MEMORY" -gt 0 ]; then
1448 msg "test: compat.sh (MSan)" # ~ 6 min 20s
1449 if_build_succeeded tests/compat.sh
1450 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001451}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001452
Gilles Peskinee8789872019-01-10 00:11:42 +01001453component_test_valgrind () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001454 msg "build: Release (clang)"
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001455 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
1456 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001457
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001458 msg "test: main suites valgrind (Release)"
1459 make memcheck
Gilles Peskine69e8f7f2020-02-26 19:51:43 +01001460
1461 # Optional part(s)
1462 # Currently broken, programs don't seem to receive signals
1463 # under valgrind on OS X
1464
1465 if [ "$MEMORY" -gt 0 ]; then
1466 msg "test: ssl-opt.sh --memcheck (Release)"
1467 if_build_succeeded tests/ssl-opt.sh --memcheck
1468 fi
1469
1470 if [ "$MEMORY" -gt 1 ]; then
1471 msg "test: compat.sh --memcheck (Release)"
1472 if_build_succeeded tests/compat.sh --memcheck
1473 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001474}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001475
Gilles Peskine8f073122018-11-27 15:58:47 +01001476component_test_cmake_out_of_source () {
1477 msg "build: cmake 'out-of-source' build"
Gilles Peskine8f073122018-11-27 15:58:47 +01001478 MBEDTLS_ROOT_DIR="$PWD"
1479 mkdir "$OUT_OF_SOURCE_DIR"
1480 cd "$OUT_OF_SOURCE_DIR"
1481 cmake "$MBEDTLS_ROOT_DIR"
1482 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001483
Gilles Peskine8f073122018-11-27 15:58:47 +01001484 msg "test: cmake 'out-of-source' build"
1485 make test
Gilles Peskine69e8f7f2020-02-26 19:51:43 +01001486 # Test an SSL option that requires an auxiliary script in test/scripts/.
1487 # Also ensure that there are no error messages such as
1488 # "No such file or directory", which would indicate that some required
1489 # file is missing (ssl-opt.sh tolerates the absence of some files so
1490 # may exit with status 0 but emit errors).
1491 if_build_succeeded ./tests/ssl-opt.sh -f 'Fallback SCSV: beginning of list' 2>ssl-opt.err
1492 if [ -s ssl-opt.err ]; then
1493 cat ssl-opt.err >&2
1494 record_status [ ! -s ssl-opt.err ]
1495 rm ssl-opt.err
1496 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001497 cd "$MBEDTLS_ROOT_DIR"
1498 rm -rf "$OUT_OF_SOURCE_DIR"
1499 unset MBEDTLS_ROOT_DIR
1500}
Andres AGdc192212016-08-31 17:33:13 +01001501
Jaeden Ameroe8451f22019-06-20 17:38:22 +01001502component_test_cmake_as_subdirectory () {
1503 msg "build: cmake 'as-subdirectory' build"
1504 MBEDTLS_ROOT_DIR="$PWD"
1505
1506 cd programs/test/cmake_subproject
1507 cmake .
1508 make
1509 if_build_succeeded ./cmake_subproject
1510
1511 cd "$MBEDTLS_ROOT_DIR"
1512 unset MBEDTLS_ROOT_DIR
1513}
1514
Gilles Peskine8f073122018-11-27 15:58:47 +01001515component_test_zeroize () {
1516 # Test that the function mbedtls_platform_zeroize() is not optimized away by
1517 # different combinations of compilers and optimization flags by using an
1518 # auxiliary GDB script. Unfortunately, GDB does not return error values to the
1519 # system in all cases that the script fails, so we must manually search the
1520 # output to check whether the pass string is present and no failure strings
1521 # were printed.
Gilles Peskine74851d82019-01-06 19:52:22 +00001522
1523 # Don't try to disable ASLR. We don't care about ASLR here. We do care
1524 # about a spurious message if Gdb tries and fails, so suppress that.
1525 gdb_disable_aslr=
1526 if [ -z "$(gdb -batch -nw -ex 'set disable-randomization off' 2>&1)" ]; then
1527 gdb_disable_aslr='set disable-randomization off'
1528 fi
1529
Gilles Peskine8f073122018-11-27 15:58:47 +01001530 for optimization_flag in -O2 -O3 -Ofast -Os; do
Gilles Peskine06b385f2019-01-09 22:28:21 +01001531 for compiler in clang gcc; do
1532 msg "test: $compiler $optimization_flag, mbedtls_platform_zeroize()"
1533 make programs CC="$compiler" DEBUG=1 CFLAGS="$optimization_flag"
Gilles Peskine74851d82019-01-06 19:52:22 +00001534 if_build_succeeded gdb -ex "$gdb_disable_aslr" -x tests/scripts/test_zeroize.gdb -nw -batch -nx 2>&1 | tee test_zeroize.log
Gilles Peskine06b385f2019-01-09 22:28:21 +01001535 if_build_succeeded grep "The buffer was correctly zeroized" test_zeroize.log
1536 if_build_succeeded not grep -i "error" test_zeroize.log
1537 rm -f test_zeroize.log
1538 make clean
1539 done
Andres Amaya Garcia29673812017-10-25 10:35:51 +01001540 done
Gilles Peskine74851d82019-01-06 19:52:22 +00001541
1542 unset gdb_disable_aslr
Gilles Peskine8f073122018-11-27 15:58:47 +01001543}
Andres Amaya Garciad0d7bf62017-10-25 09:01:31 +01001544
Gilles Peskineaad2ebd2019-02-25 20:26:06 +01001545support_check_python_files () {
1546 type pylint3 >/dev/null 2>/dev/null
1547}
Gilles Peskine8f073122018-11-27 15:58:47 +01001548component_check_python_files () {
1549 msg "Lint: Python scripts"
1550 record_status tests/scripts/check-python-files.sh
1551}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001552
Gilles Peskine8f073122018-11-27 15:58:47 +01001553component_check_generate_test_code () {
1554 msg "uint test: generate_test_code.py"
1555 record_status ./tests/scripts/test_generate_test_code.py
1556}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001557
1558################################################################
1559#### Termination
1560################################################################
1561
Gilles Peskine8f073122018-11-27 15:58:47 +01001562post_report () {
1563 msg "Done, cleaning up"
1564 cleanup
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001565
Gilles Peskine8f073122018-11-27 15:58:47 +01001566 final_report
1567}
1568
1569
1570
1571################################################################
1572#### Run all the things
1573################################################################
1574
Gilles Peskinee48351a2018-11-27 16:06:30 +01001575# Run one component and clean up afterwards.
Gilles Peskine8f073122018-11-27 15:58:47 +01001576run_component () {
Gilles Peskine8ae15dd2019-01-02 18:57:02 +01001577 # Back up the configuration in case the component modifies it.
1578 # The cleanup function will restore it.
1579 cp -p "$CONFIG_H" "$CONFIG_BAK"
Gilles Peskineffcdeff2018-12-04 12:49:28 +01001580 current_component="$1"
Gilles Peskine9004a172019-09-16 15:20:36 +02001581 export MBEDTLS_TEST_CONFIGURATION="$current_component"
Gilles Peskine2ef377d2019-10-07 18:44:21 +02001582
1583 # Unconditionally create a seedfile that's sufficiently long.
1584 # Do this before each component, because a previous component may
1585 # have messed it up or shortened it.
1586 dd if=/dev/urandom of=./tests/seedfile bs=64 count=1
1587
1588 # Run the component code.
Gilles Peskine8f073122018-11-27 15:58:47 +01001589 "$@"
Gilles Peskine2ef377d2019-10-07 18:44:21 +02001590
1591 # Restore the build tree to a clean state.
Gilles Peskinee48351a2018-11-27 16:06:30 +01001592 cleanup
Gilles Peskine8f073122018-11-27 15:58:47 +01001593}
1594
1595# Preliminary setup
1596pre_check_environment
1597pre_initialize_variables
1598pre_parse_command_line "$@"
Gilles Peskine348fb9a2018-11-27 17:04:29 +01001599
Gilles Peskine10726102019-01-06 20:50:38 +00001600pre_check_git
Andrzej Kurekeb508712019-02-14 07:18:59 -05001601
Gilles Peskine10726102019-01-06 20:50:38 +00001602build_status=0
1603if [ $KEEP_GOING -eq 1 ]; then
1604 pre_setup_keep_going
1605else
1606 record_status () {
1607 "$@"
1608 }
1609fi
Gilles Peskine67ffdaf2019-09-16 15:55:46 +02001610pre_prepare_outcome_file
Gilles Peskine10726102019-01-06 20:50:38 +00001611pre_print_configuration
1612pre_check_tools
Gilles Peskine10726102019-01-06 20:50:38 +00001613cleanup
Gilles Peskine8f073122018-11-27 15:58:47 +01001614
Gilles Peskine1bcb1c82019-01-06 22:11:25 +00001615# Run the requested tests.
1616for component in $RUN_COMPONENTS; do
1617 run_component "component_$component"
1618done
Gilles Peskine8f073122018-11-27 15:58:47 +01001619
1620# We're done.
Gilles Peskine10726102019-01-06 20:50:38 +00001621post_report