blob: 730c80755e4a916f71961d4ddfff7a972f167987 [file] [log] [blame]
Andres AG31f9b5b2016-10-04 17:14:38 +01001#! /usr/bin/env sh
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01002
Simon Butcher3ea7f522016-03-07 23:22:10 +00003# all.sh
4#
SimonB2e23c822016-04-16 21:54:39 +01005# This file is part of mbed TLS (https://tls.mbed.org)
6#
Gilles Peskine192c72f2017-12-21 15:59:21 +01007# Copyright (c) 2014-2017, ARM Limited, All Rights Reserved
8
9
10
11################################################################
12#### Documentation
13################################################################
14
Simon Butcher3ea7f522016-03-07 23:22:10 +000015# Purpose
Gilles Peskine192c72f2017-12-21 15:59:21 +010016# -------
Simon Butcher3ea7f522016-03-07 23:22:10 +000017#
SimonB2e23c822016-04-16 21:54:39 +010018# To run all tests possible or available on the platform.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010019#
Gilles Peskine192c72f2017-12-21 15:59:21 +010020# Notes for users
21# ---------------
22#
SimonB2e23c822016-04-16 21:54:39 +010023# Warning: the test is destructive. It includes various build modes and
24# configurations, and can and will arbitrarily change the current CMake
Gilles Peskine192c72f2017-12-21 15:59:21 +010025# configuration. The following files must be committed into git:
26# * include/mbedtls/config.h
Gilles Peskine636c26a2020-03-04 20:46:15 +010027# * Makefile, library/Makefile, programs/Makefile, tests/Makefile,
28# programs/fuzz/Makefile
Gilles Peskine192c72f2017-12-21 15:59:21 +010029# After running this script, the CMake cache will be lost and CMake
30# will no longer be initialised.
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +010031#
Gilles Peskine192c72f2017-12-21 15:59:21 +010032# The script assumes the presence of a number of tools:
33# * Basic Unix tools (Windows users note: a Unix-style find must be before
34# the Windows find in the PATH)
35# * Perl
36# * GNU Make
37# * CMake
38# * GCC and Clang (recent enough for using ASan with gcc and MemSan with clang, or valgrind)
Andrzej Kurek05be06c2018-06-28 04:41:50 -040039# * G++
Gilles Peskine192c72f2017-12-21 15:59:21 +010040# * arm-gcc and mingw-gcc
41# * ArmCC 5 and ArmCC 6, unless invoked with --no-armcc
Gilles Peskine192c72f2017-12-21 15:59:21 +010042# * OpenSSL and GnuTLS command line tools, recent enough for the
43# interoperability tests. If they don't support SSLv3 then a legacy
44# version of these tools must be present as well (search for LEGACY
45# below).
46# See the invocation of check_tools below for details.
47#
48# This script must be invoked from the toplevel directory of a git
49# working copy of Mbed TLS.
50#
51# Note that the output is not saved. You may want to run
52# script -c tests/scripts/all.sh
53# or
54# tests/scripts/all.sh >all.log 2>&1
55#
56# Notes for maintainers
57# ---------------------
58#
Gilles Peskine8f073122018-11-27 15:58:47 +010059# The bulk of the code is organized into functions that follow one of the
60# following naming conventions:
61# * pre_XXX: things to do before running the tests, in order.
62# * component_XXX: independent components. They can be run in any order.
Gilles Peskinec70637a2019-01-09 22:29:17 +010063# * component_check_XXX: quick tests that aren't worth parallelizing.
64# * component_build_XXX: build things but don't run them.
65# * component_test_XXX: build and test.
Gilles Peskine878cf602019-01-06 20:50:38 +000066# * support_XXX: if support_XXX exists and returns false then
67# component_XXX is not run by default.
Gilles Peskine8f073122018-11-27 15:58:47 +010068# * post_XXX: things to do after running the tests.
69# * other: miscellaneous support functions.
70#
Gilles Peskinec70637a2019-01-09 22:29:17 +010071# Each component must start by invoking `msg` with a short informative message.
72#
73# The framework performs some cleanup tasks after each component. This
74# means that components can assume that the working directory is in a
75# cleaned-up state, and don't need to perform the cleanup themselves.
76# * Run `make clean`.
77# * Restore `include/mbedtks/config.h` from a backup made before running
78# the component.
Gilles Peskine636c26a2020-03-04 20:46:15 +010079# * Check out `Makefile`, `library/Makefile`, `programs/Makefile`,
80# `tests/Makefile` and `programs/fuzz/Makefile` from git.
81# This cleans up after an in-tree use of CMake.
Gilles Peskinec70637a2019-01-09 22:29:17 +010082#
83# Any command that is expected to fail must be protected so that the
84# script keeps running in --keep-going mode despite `set -e`. In keep-going
85# mode, if a protected command fails, this is logged as a failure and the
86# script will exit with a failure status once it has run all components.
87# Commands can be protected in any of the following ways:
88# * `make` is a function which runs the `make` command with protection.
89# Note that you must write `make VAR=value`, not `VAR=value make`,
90# because the `VAR=value make` syntax doesn't work with functions.
91# * Put `report_status` before the command to protect it.
92# * Put `if_build_successful` before a command. This protects it, and
93# additionally skips it if a prior invocation of `make` in the same
94# component failed.
95#
Gilles Peskine192c72f2017-12-21 15:59:21 +010096# The tests are roughly in order from fastest to slowest. This doesn't
97# have to be exact, but in general you should add slower tests towards
98# the end and fast checks near the beginning.
Gilles Peskine192c72f2017-12-21 15:59:21 +010099
100
101
102################################################################
103#### Initialization and command line parsing
104################################################################
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100105
SimonB2e23c822016-04-16 21:54:39 +0100106# Abort on errors (and uninitialised variables)
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100107set -eu
108
Gilles Peskine8f073122018-11-27 15:58:47 +0100109pre_check_environment () {
Gilles Peskinea16c2b12019-01-06 19:58:02 +0000110 if [ -d library -a -d include -a -d tests ]; then :; else
Gilles Peskine8f073122018-11-27 15:58:47 +0100111 echo "Must be run from mbed TLS root" >&2
112 exit 1
113 fi
114}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100115
Gilles Peskine8f073122018-11-27 15:58:47 +0100116pre_initialize_variables () {
117 CONFIG_H='include/mbedtls/config.h'
118 CONFIG_BAK="$CONFIG_H.bak"
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200119
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200120 append_outcome=0
Gilles Peskine8f073122018-11-27 15:58:47 +0100121 MEMORY=0
122 FORCE=0
123 KEEP_GOING=0
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100124
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200125 : ${MBEDTLS_TEST_OUTCOME_FILE=}
Gilles Peskine9004a172019-09-16 15:20:36 +0200126 : ${MBEDTLS_TEST_PLATFORM="$(uname -s | tr -c \\n0-9A-Za-z _)-$(uname -m | tr -c \\n0-9A-Za-z _)"}
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200127 export MBEDTLS_TEST_OUTCOME_FILE
Gilles Peskine9004a172019-09-16 15:20:36 +0200128 export MBEDTLS_TEST_PLATFORM
129
Jaeden Ameroc4cc2512019-01-30 15:35:44 +0000130 # Default commands, can be overridden by the environment
Gilles Peskine8f073122018-11-27 15:58:47 +0100131 : ${OPENSSL:="openssl"}
132 : ${OPENSSL_LEGACY:="$OPENSSL"}
133 : ${OPENSSL_NEXT:="$OPENSSL"}
134 : ${GNUTLS_CLI:="gnutls-cli"}
135 : ${GNUTLS_SERV:="gnutls-serv"}
136 : ${GNUTLS_LEGACY_CLI:="$GNUTLS_CLI"}
137 : ${GNUTLS_LEGACY_SERV:="$GNUTLS_SERV"}
138 : ${OUT_OF_SOURCE_DIR:=./mbedtls_out_of_source_build}
139 : ${ARMC5_BIN_DIR:=/usr/bin}
140 : ${ARMC6_BIN_DIR:=/usr/bin}
Andres AGdc192212016-08-31 17:33:13 +0100141
Gilles Peskine8f073122018-11-27 15:58:47 +0100142 # if MAKEFLAGS is not set add the -j option to speed up invocations of make
Gilles Peskinea1fc4b52019-01-06 20:15:26 +0000143 if [ -z "${MAKEFLAGS+set}" ]; then
Gilles Peskine8f073122018-11-27 15:58:47 +0100144 export MAKEFLAGS="-j"
145 fi
Gilles Peskine878cf602019-01-06 20:50:38 +0000146
Jaeden Amerod48e9c72019-02-07 17:43:39 +0000147 # Include more verbose output for failing tests run by CMake
148 export CTEST_OUTPUT_ON_FAILURE=1
149
Gilles Peskine8fd59422019-10-21 17:11:33 +0200150 # CFLAGS and LDFLAGS for Asan builds that don't use CMake
Gilles Peskine5ca393f2019-10-21 19:06:33 +0200151 ASAN_CFLAGS='-Werror -Wall -Wextra -fsanitize=address,undefined -fno-sanitize-recover=all'
Gilles Peskine8fd59422019-10-21 17:11:33 +0200152
Gilles Peskine878cf602019-01-06 20:50:38 +0000153 # Gather the list of available components. These are the functions
154 # defined in this script whose name starts with "component_".
155 # Parse the script with sed, because in sh there is no way to list
156 # defined functions.
157 ALL_COMPONENTS=$(sed -n 's/^ *component_\([0-9A-Z_a-z]*\) *().*/\1/p' <"$0")
158
159 # Exclude components that are not supported on this platform.
160 SUPPORTED_COMPONENTS=
161 for component in $ALL_COMPONENTS; do
162 case $(type "support_$component" 2>&1) in
163 *' function'*)
164 if ! support_$component; then continue; fi;;
165 esac
166 SUPPORTED_COMPONENTS="$SUPPORTED_COMPONENTS $component"
167 done
Gilles Peskine8f073122018-11-27 15:58:47 +0100168}
Andres AG38495a32016-07-12 16:54:33 +0100169
Gilles Peskinea28db922019-01-10 00:05:18 +0100170# Test whether the component $1 is included in the command line patterns.
171is_component_included()
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100172{
173 set -f
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000174 for pattern in $COMMAND_LINE_COMPONENTS; do
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100175 set +f
176 case ${1#component_} in $pattern) return 0;; esac
177 done
178 set +f
179 return 1
180}
Andres AG7770ea82016-10-10 15:46:20 +0100181
Simon Butcher41eeccf2016-09-07 00:07:09 +0100182usage()
Andres AGd9eba4b2016-08-26 14:42:14 +0100183{
Gilles Peskine709346a2017-12-10 23:43:39 +0100184 cat <<EOF
Gilles Peskine92525112018-11-27 18:15:35 +0100185Usage: $0 [OPTION]... [COMPONENT]...
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100186Run mbedtls release validation tests.
Gilles Peskine92525112018-11-27 18:15:35 +0100187By default, run all tests. With one or more COMPONENT, run only those.
Gilles Peskinea28db922019-01-10 00:05:18 +0100188COMPONENT can be the name of a component or a shell wildcard pattern.
189
190Examples:
191 $0 "check_*"
192 Run all sanity checks.
193 $0 --no-armcc --except test_memsan
194 Run everything except builds that require armcc and MemSan.
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100195
196Special options:
197 -h|--help Print this help and exit.
Gilles Peskine878cf602019-01-06 20:50:38 +0000198 --list-all-components List all available test components and exit.
199 --list-components List components supported on this platform and exit.
Gilles Peskine709346a2017-12-10 23:43:39 +0100200
201General options:
202 -f|--force Force the tests to overwrite any modified files.
Gilles Peskine7c652162017-12-11 00:01:40 +0100203 -k|--keep-going Run all tests and report errors at the end.
Gilles Peskine709346a2017-12-10 23:43:39 +0100204 -m|--memory Additional optional memory tests.
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200205 --append-outcome Append to the outcome file (if used).
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100206 --armcc Run ARM Compiler builds (on by default).
Gilles Peskinea28db922019-01-10 00:05:18 +0100207 --except Exclude the COMPONENTs listed on the command line,
208 instead of running only those.
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200209 --no-append-outcome Write a new outcome file and analyze it (default).
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100210 --no-armcc Skip ARM Compiler builds.
Gilles Peskine38d81652018-03-21 08:40:26 +0100211 --no-force Refuse to overwrite modified files (default).
212 --no-keep-going Stop at the first error (default).
213 --no-memory No additional memory tests (default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100214 --out-of-source-dir=<path> Directory used for CMake out-of-source build tests.
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200215 --outcome-file=<path> File where test outcomes are written (not done if
216 empty; default: \$MBEDTLS_TEST_OUTCOME_FILE).
Gilles Peskine38d81652018-03-21 08:40:26 +0100217 --random-seed Use a random seed value for randomized tests (default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100218 -r|--release-test Run this script in release mode. This fixes the seed value to 1.
219 -s|--seed Integer seed value to use for this test run.
220
221Tool path options:
222 --armc5-bin-dir=<ARMC5_bin_dir_path> ARM Compiler 5 bin directory.
223 --armc6-bin-dir=<ARMC6_bin_dir_path> ARM Compiler 6 bin directory.
224 --gnutls-cli=<GnuTLS_cli_path> GnuTLS client executable to use for most tests.
225 --gnutls-serv=<GnuTLS_serv_path> GnuTLS server executable to use for most tests.
226 --gnutls-legacy-cli=<GnuTLS_cli_path> GnuTLS client executable to use for legacy tests.
227 --gnutls-legacy-serv=<GnuTLS_serv_path> GnuTLS server executable to use for legacy tests.
228 --openssl=<OpenSSL_path> OpenSSL executable to use for most tests.
229 --openssl-legacy=<OpenSSL_path> OpenSSL executable to use for legacy tests e.g. SSLv3.
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100230 --openssl-next=<OpenSSL_path> OpenSSL executable to use for recent things like ARIA
Gilles Peskine709346a2017-12-10 23:43:39 +0100231EOF
SimonB2e23c822016-04-16 21:54:39 +0100232}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100233
234# remove built files as well as the cmake cache/config
235cleanup()
236{
Gilles Peskinea71d64c2018-03-21 12:16:57 +0100237 if [ -n "${MBEDTLS_ROOT_DIR+set}" ]; then
238 cd "$MBEDTLS_ROOT_DIR"
239 fi
240
Gilles Peskine7c652162017-12-11 00:01:40 +0100241 command make clean
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200242
Gilles Peskine31b07e22018-03-21 12:15:06 +0100243 # Remove CMake artefacts
Jaeden Amero2d0e00f2018-11-07 18:46:41 +0000244 find . -name .git -prune -o \
Gilles Peskine31b07e22018-03-21 12:15:06 +0100245 -iname CMakeFiles -exec rm -rf {} \+ -o \
246 \( -iname cmake_install.cmake -o \
247 -iname CTestTestfile.cmake -o \
248 -iname CMakeCache.txt \) -exec rm {} \+
249 # Recover files overwritten by in-tree CMake builds
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000250 rm -f include/Makefile include/mbedtls/Makefile programs/*/Makefile
Gilles Peskine636c26a2020-03-04 20:46:15 +0100251 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile
252 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200253
Jaeden Ameroab83fdf2019-06-20 17:38:22 +0100254 # Remove any artifacts from the component_test_cmake_as_subdirectory test.
255 rm -rf programs/test/cmake_subproject/build
256 rm -f programs/test/cmake_subproject/Makefile
257 rm -f programs/test/cmake_subproject/cmake_subproject
258
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200259 if [ -f "$CONFIG_BAK" ]; then
260 mv "$CONFIG_BAK" "$CONFIG_H"
261 fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100262}
263
Gilles Peskine7c652162017-12-11 00:01:40 +0100264# Executed on exit. May be redefined depending on command line options.
265final_report () {
266 :
267}
268
269fatal_signal () {
270 cleanup
271 final_report $1
272 trap - $1
273 kill -$1 $$
274}
275
276trap 'fatal_signal HUP' HUP
277trap 'fatal_signal INT' INT
278trap 'fatal_signal TERM' TERM
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200279
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100280msg()
281{
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100282 if [ -n "${current_component:-}" ]; then
283 current_section="${current_component#component_}: $1"
284 else
285 current_section="$1"
286 fi
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100287 echo ""
288 echo "******************************************************************"
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100289 echo "* $current_section "
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000290 printf "* "; date
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100291 echo "******************************************************************"
292}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100293
Gilles Peskine8f073122018-11-27 15:58:47 +0100294armc6_build_test()
295{
296 FLAGS="$1"
Andres AGa5cd9732016-10-17 15:23:10 +0100297
Gilles Peskine8f073122018-11-27 15:58:47 +0100298 msg "build: ARM Compiler 6 ($FLAGS), make"
299 ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \
300 WARNING_CFLAGS='-xc -std=c99' make lib
301 make clean
302}
Andres AGa5cd9732016-10-17 15:23:10 +0100303
Andres AGd9eba4b2016-08-26 14:42:14 +0100304err_msg()
305{
306 echo "$1" >&2
307}
308
309check_tools()
310{
311 for TOOL in "$@"; do
Andres AG98393602017-01-31 17:04:45 +0000312 if ! `type "$TOOL" >/dev/null 2>&1`; then
Andres AGd9eba4b2016-08-26 14:42:14 +0100313 err_msg "$TOOL not found!"
314 exit 1
315 fi
316 done
317}
318
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400319check_headers_in_cpp () {
Peter Kolbus1bc1a4c2019-02-01 17:19:08 -0600320 ls include/mbedtls | grep "\.h$" >headers.txt
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400321 <programs/test/cpp_dummy_build.cpp sed -n 's/"$//; s!^#include "mbedtls/!!p' |
322 sort |
323 diff headers.txt -
324 rm headers.txt
325}
326
Gilles Peskine8f073122018-11-27 15:58:47 +0100327pre_parse_command_line () {
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000328 COMMAND_LINE_COMPONENTS=
Gilles Peskinea28db922019-01-10 00:05:18 +0100329 all_except=0
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000330 no_armcc=
SimonB2e23c822016-04-16 21:54:39 +0100331
Jaeden Amero9b90f2e2018-11-02 18:34:17 +0000332 # Note that legacy options are ignored instead of being omitted from this
333 # list of options, so invocations that worked with previous version of
334 # all.sh will still run and work properly.
Gilles Peskine8f073122018-11-27 15:58:47 +0100335 while [ $# -gt 0 ]; do
Gilles Peskine55f7c942019-01-09 22:28:21 +0100336 case "$1" in
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200337 --append-outcome) append_outcome=1;;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000338 --armcc) no_armcc=;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100339 --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
340 --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000341 --except) all_except=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100342 --force|-f) FORCE=1;;
343 --gnutls-cli) shift; GNUTLS_CLI="$1";;
344 --gnutls-legacy-cli) shift; GNUTLS_LEGACY_CLI="$1";;
345 --gnutls-legacy-serv) shift; GNUTLS_LEGACY_SERV="$1";;
346 --gnutls-serv) shift; GNUTLS_SERV="$1";;
347 --help|-h) usage; exit;;
348 --keep-going|-k) KEEP_GOING=1;;
Gilles Peskine878cf602019-01-06 20:50:38 +0000349 --list-all-components) printf '%s\n' $ALL_COMPONENTS; exit;;
350 --list-components) printf '%s\n' $SUPPORTED_COMPONENTS; exit;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100351 --memory|-m) MEMORY=1;;
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200352 --no-append-outcome) append_outcome=0;;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000353 --no-armcc) no_armcc=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100354 --no-force) FORCE=0;;
355 --no-keep-going) KEEP_GOING=0;;
356 --no-memory) MEMORY=0;;
357 --openssl) shift; OPENSSL="$1";;
358 --openssl-legacy) shift; OPENSSL_LEGACY="$1";;
359 --openssl-next) shift; OPENSSL_NEXT="$1";;
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200360 --outcome-file) shift; MBEDTLS_TEST_OUTCOME_FILE="$1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100361 --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
362 --random-seed) unset SEED;;
363 --release-test|-r) SEED=1;;
364 --seed|-s) shift; SEED="$1";;
365 -*)
366 echo >&2 "Unknown option: $1"
367 echo >&2 "Run $0 --help for usage."
368 exit 120
369 ;;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000370 *) COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS $1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100371 esac
372 shift
Gilles Peskine8f073122018-11-27 15:58:47 +0100373 done
SimonB2e23c822016-04-16 21:54:39 +0100374
Gilles Peskinea28db922019-01-10 00:05:18 +0100375 # With no list of components, run everything.
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000376 if [ -z "$COMMAND_LINE_COMPONENTS" ]; then
377 all_except=1
Andres AGdc192212016-08-31 17:33:13 +0100378 fi
379
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000380 # --no-armcc is a legacy option. The modern way is --except '*_armcc*'.
381 # Ignore it if components are listed explicitly on the command line.
Gilles Peskinea28db922019-01-10 00:05:18 +0100382 if [ -n "$no_armcc" ] && [ $all_except -eq 1 ]; then
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000383 COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS *_armcc*"
SimonB2e23c822016-04-16 21:54:39 +0100384 fi
SimonB2e23c822016-04-16 21:54:39 +0100385
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000386 # Build the list of components to run.
Gilles Peskinea28db922019-01-10 00:05:18 +0100387 RUN_COMPONENTS=
388 for component in $SUPPORTED_COMPONENTS; do
389 if is_component_included "$component"; [ $? -eq $all_except ]; then
390 RUN_COMPONENTS="$RUN_COMPONENTS $component"
391 fi
392 done
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000393
394 unset all_except
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000395 unset no_armcc
Gilles Peskine8f073122018-11-27 15:58:47 +0100396}
SimonB2e23c822016-04-16 21:54:39 +0100397
Gilles Peskine8f073122018-11-27 15:58:47 +0100398pre_check_git () {
399 if [ $FORCE -eq 1 ]; then
Gilles Peskine53190e62019-01-09 23:17:35 +0100400 rm -rf "$OUT_OF_SOURCE_DIR"
Gilles Peskine8f073122018-11-27 15:58:47 +0100401 git checkout-index -f -q $CONFIG_H
402 cleanup
403 else
SimonB2e23c822016-04-16 21:54:39 +0100404
Gilles Peskine8f073122018-11-27 15:58:47 +0100405 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
406 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
407 echo "You can either delete this directory manually, or force the test by rerunning"
408 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
409 exit 1
410 fi
411
Gilles Peskined1174cf2019-01-09 22:30:01 +0100412 if ! git diff --quiet include/mbedtls/config.h; then
Gilles Peskine8f073122018-11-27 15:58:47 +0100413 err_msg "Warning - the configuration file 'include/mbedtls/config.h' has been edited. "
414 echo "You can either delete or preserve your work, or force the test by rerunning the"
415 echo "script as: $0 --force"
416 exit 1
417 fi
SimonB2e23c822016-04-16 21:54:39 +0100418 fi
Andrzej Kurekeb508712019-02-14 07:18:59 -0500419}
420
Gilles Peskine8f073122018-11-27 15:58:47 +0100421pre_setup_keep_going () {
Gilles Peskine7c652162017-12-11 00:01:40 +0100422 failure_summary=
423 failure_count=0
424 start_red=
425 end_color=
426 if [ -t 1 ]; then
Gilles Peskine9736b9d2018-01-02 21:54:17 +0100427 case "${TERM:-}" in
Gilles Peskine7c652162017-12-11 00:01:40 +0100428 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
429 start_red=$(printf '\033[31m')
430 end_color=$(printf '\033[0m')
431 ;;
432 esac
433 fi
434 record_status () {
435 if "$@"; then
436 last_status=0
437 else
438 last_status=$?
439 text="$current_section: $* -> $last_status"
440 failure_summary="$failure_summary
441$text"
442 failure_count=$((failure_count + 1))
443 echo "${start_red}^^^^$text^^^^${end_color}"
444 fi
445 }
446 make () {
447 case "$*" in
448 *test|*check)
449 if [ $build_status -eq 0 ]; then
450 record_status command make "$@"
451 else
452 echo "(skipped because the build failed)"
453 fi
454 ;;
455 *)
456 record_status command make "$@"
457 build_status=$last_status
458 ;;
459 esac
460 }
461 final_report () {
462 if [ $failure_count -gt 0 ]; then
463 echo
464 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
465 echo "${start_red}FAILED: $failure_count${end_color}$failure_summary"
466 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Jaeden Amero7c1258d2018-07-20 16:42:14 +0100467 exit 1
Gilles Peskine7c652162017-12-11 00:01:40 +0100468 elif [ -z "${1-}" ]; then
469 echo "SUCCESS :)"
470 fi
471 if [ -n "${1-}" ]; then
472 echo "Killed by SIG$1."
473 fi
474 }
Gilles Peskine8f073122018-11-27 15:58:47 +0100475}
476
Gilles Peskine7c652162017-12-11 00:01:40 +0100477if_build_succeeded () {
478 if [ $build_status -eq 0 ]; then
479 record_status "$@"
480 fi
481}
482
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200483# to be used instead of ! for commands run with
484# record_status or if_build_succeeded
485not() {
486 ! "$@"
487}
488
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200489pre_prepare_outcome_file () {
490 case "$MBEDTLS_TEST_OUTCOME_FILE" in
491 [!/]*) MBEDTLS_TEST_OUTCOME_FILE="$PWD/$MBEDTLS_TEST_OUTCOME_FILE";;
492 esac
493 if [ -n "$MBEDTLS_TEST_OUTCOME_FILE" ] && [ "$append_outcome" -eq 0 ]; then
494 rm -f "$MBEDTLS_TEST_OUTCOME_FILE"
495 fi
496}
497
Gilles Peskine8f073122018-11-27 15:58:47 +0100498pre_print_configuration () {
499 msg "info: $0 configuration"
500 echo "MEMORY: $MEMORY"
501 echo "FORCE: $FORCE"
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200502 echo "MBEDTLS_TEST_OUTCOME_FILE: ${MBEDTLS_TEST_OUTCOME_FILE:-(none)}"
Gilles Peskine8f073122018-11-27 15:58:47 +0100503 echo "SEED: ${SEED-"UNSET"}"
Gilles Peskine636c26a2020-03-04 20:46:15 +0100504 echo
Gilles Peskine8f073122018-11-27 15:58:47 +0100505 echo "OPENSSL: $OPENSSL"
506 echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
507 echo "OPENSSL_NEXT: $OPENSSL_NEXT"
508 echo "GNUTLS_CLI: $GNUTLS_CLI"
509 echo "GNUTLS_SERV: $GNUTLS_SERV"
510 echo "GNUTLS_LEGACY_CLI: $GNUTLS_LEGACY_CLI"
511 echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV"
512 echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
513 echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
514}
Andres AG7770ea82016-10-10 15:46:20 +0100515
Andres AGd9eba4b2016-08-26 14:42:14 +0100516# Make sure the tools we need are available.
Gilles Peskine8f073122018-11-27 15:58:47 +0100517pre_check_tools () {
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000518 # Build the list of variables to pass to output_env.sh.
519 set env
SimonB2e23c822016-04-16 21:54:39 +0100520
Gilles Peskine87964262019-01-06 22:40:00 +0000521 case " $RUN_COMPONENTS " in
522 # Require OpenSSL and GnuTLS if running any tests (as opposed to
523 # only doing builds). Not all tests run OpenSSL and GnuTLS, but this
524 # is a good enough approximation in practice.
525 *" test_"*)
526 # To avoid setting OpenSSL and GnuTLS for each call to compat.sh
527 # and ssl-opt.sh, we just export the variables they require.
528 export OPENSSL_CMD="$OPENSSL"
529 export GNUTLS_CLI="$GNUTLS_CLI"
530 export GNUTLS_SERV="$GNUTLS_SERV"
531 # Avoid passing --seed flag in every call to ssl-opt.sh
532 if [ -n "${SEED-}" ]; then
533 export SEED
534 fi
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000535 set "$@" OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY"
536 set "$@" GNUTLS_CLI="$GNUTLS_CLI" GNUTLS_SERV="$GNUTLS_SERV"
537 set "$@" GNUTLS_LEGACY_CLI="$GNUTLS_LEGACY_CLI"
538 set "$@" GNUTLS_LEGACY_SERV="$GNUTLS_LEGACY_SERV"
Gilles Peskine87964262019-01-06 22:40:00 +0000539 check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$OPENSSL_NEXT" \
540 "$GNUTLS_CLI" "$GNUTLS_SERV" \
541 "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV"
542 ;;
543 esac
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200544
Gilles Peskine87964262019-01-06 22:40:00 +0000545 case " $RUN_COMPONENTS " in
546 *_doxygen[_\ ]*) check_tools "doxygen" "dot";;
547 esac
Andres AGd9eba4b2016-08-26 14:42:14 +0100548
Gilles Peskine87964262019-01-06 22:40:00 +0000549 case " $RUN_COMPONENTS " in
550 *_arm_none_eabi_gcc[_\ ]*) check_tools "arm-none-eabi-gcc";;
551 esac
Andres AGd9eba4b2016-08-26 14:42:14 +0100552
Gilles Peskine87964262019-01-06 22:40:00 +0000553 case " $RUN_COMPONENTS " in
554 *_mingw[_\ ]*) check_tools "i686-w64-mingw32-gcc";;
555 esac
556
557 case " $RUN_COMPONENTS " in
558 *" test_zeroize "*) check_tools "gdb";;
559 esac
560
561 case " $RUN_COMPONENTS " in
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000562 *_armcc*)
Gilles Peskine87964262019-01-06 22:40:00 +0000563 ARMC5_CC="$ARMC5_BIN_DIR/armcc"
564 ARMC5_AR="$ARMC5_BIN_DIR/armar"
565 ARMC6_CC="$ARMC6_BIN_DIR/armclang"
566 ARMC6_AR="$ARMC6_BIN_DIR/armar"
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000567 check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC6_CC" "$ARMC6_AR";;
568 esac
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000569
570 msg "info: output_env.sh"
571 case $RUN_COMPONENTS in
572 *_armcc*)
573 set "$@" ARMC5_CC="$ARMC5_CC" ARMC6_CC="$ARMC6_CC" RUN_ARMCC=1;;
574 *) set "$@" RUN_ARMCC=0;;
575 esac
576 "$@" scripts/output_env.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100577}
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100578
Gilles Peskine192c72f2017-12-21 15:59:21 +0100579
580
581################################################################
582#### Basic checks
583################################################################
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100584
585#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200586# Test Suites to be executed
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100587#
Manuel Pégourié-Gonnard3d404b42015-07-08 21:59:16 +0100588# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200589# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100590# 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 +0200591# time, so start with a GCC build).
592# 2. Minimize total running time, by avoiding useless rebuilds
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100593#
Manuel Pégourié-Gonnard259b08a2016-01-08 16:27:41 +0100594# Indicative running times are given for reference.
595
Gilles Peskine8f073122018-11-27 15:58:47 +0100596component_check_recursion () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200597 msg "Check: recursion.pl" # < 1s
Gilles Peskine8f073122018-11-27 15:58:47 +0100598 record_status tests/scripts/recursion.pl library/*.c
599}
Janos Follathb72c6782016-07-19 14:54:17 +0100600
Gilles Peskine8f073122018-11-27 15:58:47 +0100601component_check_generated_files () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200602 msg "Check: freshness of generated source files" # < 1s
Gilles Peskine8f073122018-11-27 15:58:47 +0100603 record_status tests/scripts/check-generated-files.sh
604}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200605
Gilles Peskine8f073122018-11-27 15:58:47 +0100606component_check_doxy_blocks () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200607 msg "Check: doxygen markup outside doxygen blocks" # < 1s
Gilles Peskine8f073122018-11-27 15:58:47 +0100608 record_status tests/scripts/check-doxy-blocks.pl
609}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200610
Gilles Peskine8f073122018-11-27 15:58:47 +0100611component_check_files () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200612 msg "Check: file sanity checks (permissions, encodings)" # < 1s
Gilles Peskine8f073122018-11-27 15:58:47 +0100613 record_status tests/scripts/check-files.py
614}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200615
Gilles Peskine8f073122018-11-27 15:58:47 +0100616component_check_names () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200617 msg "Check: declared and exported names (builds the library)" # < 3s
Gilles Peskine13f97dc2019-05-15 17:52:22 +0200618 record_status tests/scripts/check-names.sh -v
Gilles Peskine8f073122018-11-27 15:58:47 +0100619}
Darryl Greena07039c2018-03-13 16:48:16 +0000620
Gilles Peskine895868b2019-09-19 21:30:05 +0200621component_check_test_cases () {
622 msg "Check: test case descriptions" # < 1s
623 record_status tests/scripts/check-test-cases.py
624}
625
Gilles Peskine8f073122018-11-27 15:58:47 +0100626component_check_doxygen_warnings () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200627 msg "Check: doxygen warnings (builds the documentation)" # ~ 3s
Gilles Peskine8f073122018-11-27 15:58:47 +0100628 record_status tests/scripts/doxygen.sh
629}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200630
Gilles Peskine192c72f2017-12-21 15:59:21 +0100631
Gilles Peskine636c26a2020-03-04 20:46:15 +0100632
Gilles Peskine192c72f2017-12-21 15:59:21 +0100633################################################################
634#### Build and test many configurations and targets
635################################################################
636
Gilles Peskine7832c9f2019-04-08 17:00:15 +0200637component_test_default_out_of_box () {
638 msg "build: make, default config (out-of-box)" # ~1min
639 make
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200640 # Disable fancy stuff
Gilles Peskine717cd762019-09-27 20:21:11 +0200641 SAVE_MBEDTLS_TEST_OUTCOME_FILE="$MBEDTLS_TEST_OUTCOME_FILE"
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200642 unset MBEDTLS_TEST_OUTCOME_FILE
Gilles Peskine7832c9f2019-04-08 17:00:15 +0200643
644 msg "test: main suites make, default config (out-of-box)" # ~10s
645 make test
646
647 msg "selftest: make, default config (out-of-box)" # ~10s
Gilles Peskine97bea012020-04-23 23:37:45 +0200648 if_build_succeeded programs/test/selftest
Gilles Peskine717cd762019-09-27 20:21:11 +0200649
650 export MBEDTLS_TEST_OUTCOME_FILE="$SAVE_MBEDTLS_TEST_OUTCOME_FILE"
651 unset SAVE_MBEDTLS_TEST_OUTCOME_FILE
Gilles Peskine7832c9f2019-04-08 17:00:15 +0200652}
653
Gilles Peskine8f073122018-11-27 15:58:47 +0100654component_test_default_cmake_gcc_asan () {
655 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100656 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
657 make
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200658
Gilles Peskine8f073122018-11-27 15:58:47 +0100659 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
660 make test
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200661
Gilles Peskine97bea012020-04-23 23:37:45 +0200662 msg "test: selftest (ASan build)" # ~ 10s
663 if_build_succeeded programs/test/selftest
664
Gilles Peskine8f073122018-11-27 15:58:47 +0100665 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
666 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200667
Gilles Peskine8f073122018-11-27 15:58:47 +0100668 msg "test: compat.sh (ASan build)" # ~ 6 min
669 if_build_succeeded tests/compat.sh
Piotr Nowicki9978e6e2020-04-07 16:07:05 +0200670
671 msg "test: context-info.sh (ASan build)" # ~ 15 sec
672 if_build_succeeded tests/context-info.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100673}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200674
Hanno Becker01635512019-02-26 14:27:09 +0000675component_test_full_cmake_gcc_asan () {
676 msg "build: full config, cmake, gcc, ASan"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200677 scripts/config.py full
Hanno Becker01635512019-02-26 14:27:09 +0000678 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
679 make
680
681 msg "test: main suites (inc. selftests) (full config, ASan build)"
682 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +0100683
Gilles Peskine97bea012020-04-23 23:37:45 +0200684 msg "test: selftest (ASan build)" # ~ 10s
685 if_build_succeeded programs/test/selftest
686
Gilles Peskine636c26a2020-03-04 20:46:15 +0100687 msg "test: ssl-opt.sh (full config, ASan build)"
688 if_build_succeeded tests/ssl-opt.sh
689
690 msg "test: compat.sh (full config, ASan build)"
691 if_build_succeeded tests/compat.sh
Piotr Nowicki9978e6e2020-04-07 16:07:05 +0200692
693 msg "test: context-info.sh (full config, ASan build)" # ~ 15 sec
694 if_build_succeeded tests/context-info.sh
Gilles Peskine636c26a2020-03-04 20:46:15 +0100695}
696
697component_test_zlib_make() {
698 msg "build: zlib enabled, make"
699 scripts/config.py set MBEDTLS_ZLIB_SUPPORT
700 make ZLIB=1 CFLAGS='-Werror -O1'
701
702 msg "test: main suites (zlib, make)"
703 make test
704
705 msg "test: ssl-opt.sh (zlib, make)"
706 if_build_succeeded tests/ssl-opt.sh
707}
708support_test_zlib_make () {
709 base=support_test_zlib_$$
710 cat <<'EOF' > ${base}.c
711#include "zlib.h"
712int main(void) { return 0; }
713EOF
714 gcc -o ${base}.exe ${base}.c -lz 2>/dev/null
715 ret=$?
716 rm -f ${base}.*
717 return $ret
718}
719
720component_test_zlib_cmake() {
721 msg "build: zlib enabled, cmake"
722 scripts/config.py set MBEDTLS_ZLIB_SUPPORT
723 cmake -D ENABLE_ZLIB_SUPPORT=On -D CMAKE_BUILD_TYPE:String=Check .
724 make
725
726 msg "test: main suites (zlib, cmake)"
727 make test
728
729 msg "test: ssl-opt.sh (zlib, cmake)"
730 if_build_succeeded tests/ssl-opt.sh
731}
732support_test_zlib_cmake () {
733 support_test_zlib_make "$@"
Manuel Pégourié-Gonnardf2e29022020-01-24 10:17:20 +0100734}
Manuel Pégourié-Gonnard95e04492020-01-02 11:45:12 +0100735
Gilles Peskine782f4112018-11-27 16:11:09 +0100736component_test_ref_configs () {
737 msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
738 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
739 record_status tests/scripts/test-ref-configs.pl
740}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200741
Gilles Peskine8f073122018-11-27 15:58:47 +0100742component_test_sslv3 () {
743 msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200744 scripts/config.py set MBEDTLS_SSL_PROTO_SSL3
Gilles Peskine8f073122018-11-27 15:58:47 +0100745 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
746 make
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200747
Gilles Peskine8f073122018-11-27 15:58:47 +0100748 msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
749 make test
Simon Butcher3ea7f522016-03-07 23:22:10 +0000750
Gilles Peskine8f073122018-11-27 15:58:47 +0100751 msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
752 if_build_succeeded tests/compat.sh -m 'tls1 tls1_1 tls1_2 dtls1 dtls1_2'
753 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
Simon Butcher3ea7f522016-03-07 23:22:10 +0000754
Gilles Peskine8f073122018-11-27 15:58:47 +0100755 msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
756 if_build_succeeded tests/ssl-opt.sh
Piotr Nowicki9978e6e2020-04-07 16:07:05 +0200757
758 msg "build: SSLv3 - context-info.sh (ASan build)" # ~ 15 sec
759 if_build_succeeded tests/context-info.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100760}
Simon Butcher3ea7f522016-03-07 23:22:10 +0000761
Gilles Peskine8f073122018-11-27 15:58:47 +0100762component_test_no_renegotiation () {
763 msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200764 scripts/config.py unset MBEDTLS_SSL_RENEGOTIATION
Gilles Peskine8f073122018-11-27 15:58:47 +0100765 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
766 make
Simon Butcher3ea7f522016-03-07 23:22:10 +0000767
Gilles Peskine8f073122018-11-27 15:58:47 +0100768 msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
769 make test
Hanno Becker134c2ab2017-10-12 15:29:50 +0100770
Gilles Peskine8f073122018-11-27 15:58:47 +0100771 msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
772 if_build_succeeded tests/ssl-opt.sh
773}
Hanno Becker134c2ab2017-10-12 15:29:50 +0100774
Gilles Peskine636c26a2020-03-04 20:46:15 +0100775component_test_no_pem_no_fs () {
776 msg "build: Default + !MBEDTLS_PEM_PARSE_C + !MBEDTLS_FS_IO (ASan build)"
777 scripts/config.py unset MBEDTLS_PEM_PARSE_C
778 scripts/config.py unset MBEDTLS_FS_IO
779 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C # requires a filesystem
780 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA ITS
781 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
782 make
783
784 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - main suites (inc. selftests) (ASan build)" # ~ 50s
785 make test
786
787 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - ssl-opt.sh (ASan build)" # ~ 6 min
788 if_build_succeeded tests/ssl-opt.sh
789}
790
Gilles Peskine8f073122018-11-27 15:58:47 +0100791component_test_rsa_no_crt () {
792 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200793 scripts/config.py set MBEDTLS_RSA_NO_CRT
Gilles Peskine8f073122018-11-27 15:58:47 +0100794 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
795 make
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +0100796
Gilles Peskine8f073122018-11-27 15:58:47 +0100797 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
798 make test
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100799
Gilles Peskine8f073122018-11-27 15:58:47 +0100800 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
801 if_build_succeeded tests/ssl-opt.sh -f RSA
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100802
Gilles Peskine8f073122018-11-27 15:58:47 +0100803 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
804 if_build_succeeded tests/compat.sh -t RSA
Piotr Nowicki9978e6e2020-04-07 16:07:05 +0200805
806 msg "test: RSA_NO_CRT - RSA-related part of context-info.sh (ASan build)" # ~ 15 sec
807 if_build_succeeded tests/context-info.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100808}
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100809
Gilles Peskine636c26a2020-03-04 20:46:15 +0100810component_test_new_ecdh_context () {
811 msg "build: new ECDH context (ASan build)" # ~ 6 min
812 scripts/config.py unset MBEDTLS_ECDH_LEGACY_CONTEXT
813 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
814 make
815
816 msg "test: new ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
817 make test
818
819 msg "test: new ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
820 if_build_succeeded tests/ssl-opt.sh -f ECDH
821
822 msg "test: new ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
823 # Exclude some symmetric ciphers that are redundant here to gain time.
824 if_build_succeeded tests/compat.sh -f ECDH -V NO -e 'ARCFOUR\|ARIA\|CAMELLIA\|CHACHA\|DES\|RC4'
825}
826
827component_test_everest () {
828 msg "build: Everest ECDH context (ASan build)" # ~ 6 min
829 scripts/config.py unset MBEDTLS_ECDH_LEGACY_CONTEXT
830 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
831 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Asan .
832 make
833
834 msg "test: Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
835 make test
836
837 msg "test: Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
838 if_build_succeeded tests/ssl-opt.sh -f ECDH
839
840 msg "test: Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
841 # Exclude some symmetric ciphers that are redundant here to gain time.
842 if_build_succeeded tests/compat.sh -f ECDH -V NO -e 'ARCFOUR\|ARIA\|CAMELLIA\|CHACHA\|DES\|RC4'
843}
844
Gilles Peskine8f073122018-11-27 15:58:47 +0100845component_test_small_ssl_out_content_len () {
846 msg "build: small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200847 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 16384
848 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
Gilles Peskine8f073122018-11-27 15:58:47 +0100849 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
850 make
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100851
Gilles Peskine8f073122018-11-27 15:58:47 +0100852 msg "test: small SSL_OUT_CONTENT_LEN - ssl-opt.sh MFL and large packet tests"
853 if_build_succeeded tests/ssl-opt.sh -f "Max fragment\|Large packet"
854}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000855
Gilles Peskine8f073122018-11-27 15:58:47 +0100856component_test_small_ssl_in_content_len () {
857 msg "build: small SSL_IN_CONTENT_LEN (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200858 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 4096
859 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 16384
Gilles Peskine8f073122018-11-27 15:58:47 +0100860 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
861 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000862
Gilles Peskine8f073122018-11-27 15:58:47 +0100863 msg "test: small SSL_IN_CONTENT_LEN - ssl-opt.sh MFL tests"
864 if_build_succeeded tests/ssl-opt.sh -f "Max fragment"
865}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000866
Gilles Peskine8f073122018-11-27 15:58:47 +0100867component_test_small_ssl_dtls_max_buffering () {
868 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200869 scripts/config.py set MBEDTLS_SSL_DTLS_MAX_BUFFERING 1000
Gilles Peskine8f073122018-11-27 15:58:47 +0100870 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
871 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000872
Gilles Peskine8f073122018-11-27 15:58:47 +0100873 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0 - ssl-opt.sh specific reordering test"
874 if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer out-of-order hs msg before reassembling next, free buffered msg"
875}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100876
Gilles Peskine8f073122018-11-27 15:58:47 +0100877component_test_small_mbedtls_ssl_dtls_max_buffering () {
878 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1"
Gilles Peskine636c26a2020-03-04 20:46:15 +0100879 scripts/config.py set MBEDTLS_SSL_DTLS_MAX_BUFFERING 190
Gilles Peskine8f073122018-11-27 15:58:47 +0100880 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
881 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100882
Gilles Peskine8f073122018-11-27 15:58:47 +0100883 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1 - ssl-opt.sh specific reordering test"
884 if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer encrypted Finished message, drop for fragmented NewSessionTicket"
885}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100886
Gilles Peskine75cc7712019-09-06 19:47:17 +0200887component_test_psa_collect_statuses () {
888 msg "build+test: psa_collect_statuses" # ~30s
Gilles Peskine3bdd4122019-07-27 23:52:53 +0200889 scripts/config.py full
Gilles Peskine75cc7712019-09-06 19:47:17 +0200890 record_status tests/scripts/psa_collect_statuses.py
891 # Check that psa_crypto_init() succeeded at least once
892 record_status grep -q '^0:psa_crypto_init:' tests/statuses.log
893 rm -f tests/statuses.log
894}
895
Gilles Peskine8f073122018-11-27 15:58:47 +0100896component_test_full_cmake_clang () {
897 msg "build: cmake, full config, clang" # ~ 50s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200898 scripts/config.py full
Gilles Peskine8f073122018-11-27 15:58:47 +0100899 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check -D ENABLE_TESTING=On .
900 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100901
k-stachowiak0291cb72019-06-26 15:52:12 +0200902 msg "test: main suites (full config, clang)" # ~ 5s
Gilles Peskine8f073122018-11-27 15:58:47 +0100903 make test
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100904
k-stachowiak0291cb72019-06-26 15:52:12 +0200905 msg "test: psa_constant_names (full config, clang)" # ~ 1s
Darryl Green45010a32019-02-06 13:43:58 +0000906 record_status tests/scripts/test_psa_constant_names.py
Gilles Peskine69e8f7f2020-02-26 19:51:43 +0100907
Gilles Peskine8f073122018-11-27 15:58:47 +0100908 msg "test: ssl-opt.sh default, ECJPAKE, SSL async (full config)" # ~ 1s
909 if_build_succeeded tests/ssl-opt.sh -f 'Default\|ECJPAKE\|SSL async private'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200910
Andres Amaya Garcia2dadab72019-01-08 21:42:27 +0000911 msg "test: compat.sh RC4, DES, 3DES & NULL (full config)" # ~ 2 min
Andres Amaya Garcia419bd002019-02-19 20:20:57 +0000912 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 +0200913
Gilles Peskine8f073122018-11-27 15:58:47 +0100914 msg "test: compat.sh ARIA + ChachaPoly"
915 if_build_succeeded env OPENSSL_CMD="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
916}
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200917
Gilles Peskine8f073122018-11-27 15:58:47 +0100918component_build_deprecated () {
919 msg "build: make, full config + DEPRECATED_WARNING, gcc -O" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200920 scripts/config.py full
921 scripts/config.py set MBEDTLS_DEPRECATED_WARNING
Gilles Peskine8f073122018-11-27 15:58:47 +0100922 # Build with -O -Wextra to catch a maximum of issues.
923 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra' lib programs
924 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100925
Gilles Peskine841b14b2019-11-26 17:37:37 +0100926 msg "test: make, full config + DEPRECATED_WARNING, expect warnings" # ~ 30s
927 make -C tests clean
928 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-error=deprecated-declarations -DMBEDTLS_TEST_DEPRECATED' tests
929
Gilles Peskine8f073122018-11-27 15:58:47 +0100930 msg "build: make, full config + DEPRECATED_REMOVED, clang -O" # ~ 30s
931 # No cleanup, just tweak the configuration and rebuild
932 make clean
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200933 scripts/config.py unset MBEDTLS_DEPRECATED_WARNING
934 scripts/config.py set MBEDTLS_DEPRECATED_REMOVED
Gilles Peskine8f073122018-11-27 15:58:47 +0100935 # Build with -O -Wextra to catch a maximum of issues.
936 make CC=clang CFLAGS='-O -Werror -Wall -Wextra' lib programs
937 make CC=clang CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
938}
Jaeden Ameroed93bdc2018-11-02 16:57:24 +0000939
Gilles Peskineec541fe2020-01-31 14:24:14 +0100940# Check that the specified libraries exist and are empty.
941are_empty_libraries () {
942 nm "$@" >/dev/null 2>/dev/null
943 ! nm "$@" 2>/dev/null | grep -v ':$' | grep .
944}
945
946component_build_crypto_default () {
947 msg "build: make, crypto only"
948 scripts/config.py crypto
Gilles Peskine6bb39152020-02-03 11:59:20 +0100949 make CFLAGS='-O1 -Werror'
Gilles Peskineec541fe2020-01-31 14:24:14 +0100950 if_build_succeeded are_empty_libraries library/libmbedx509.* library/libmbedtls.*
951}
952
953component_build_crypto_full () {
954 msg "build: make, crypto only, full config"
955 scripts/config.py crypto_full
Gilles Peskine6bb39152020-02-03 11:59:20 +0100956 make CFLAGS='-O1 -Werror'
Gilles Peskineec541fe2020-01-31 14:24:14 +0100957 if_build_succeeded are_empty_libraries library/libmbedx509.* library/libmbedtls.*
958}
959
960component_build_crypto_baremetal () {
961 msg "build: make, crypto only, baremetal config"
962 scripts/config.py crypto_baremetal
Gilles Peskine6bb39152020-02-03 11:59:20 +0100963 make CFLAGS='-O1 -Werror'
Gilles Peskineec541fe2020-01-31 14:24:14 +0100964 if_build_succeeded are_empty_libraries library/libmbedx509.* library/libmbedtls.*
965}
966
Gilles Peskine8f073122018-11-27 15:58:47 +0100967component_test_depends_curves () {
968 msg "test/build: curves.pl (gcc)" # ~ 4 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100969 record_status tests/scripts/curves.pl
970}
Jaeden Ameroacaabe72018-11-07 11:52:52 +0000971
Gilles Peskine8f073122018-11-27 15:58:47 +0100972component_test_depends_hashes () {
973 msg "test/build: depends-hashes.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100974 record_status tests/scripts/depends-hashes.pl
975}
Jaeden Ameroacaabe72018-11-07 11:52:52 +0000976
Gilles Peskine8f073122018-11-27 15:58:47 +0100977component_test_depends_pkalgs () {
978 msg "test/build: depends-pkalgs.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100979 record_status tests/scripts/depends-pkalgs.pl
980}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100981
Gilles Peskine8f073122018-11-27 15:58:47 +0100982component_build_key_exchanges () {
983 msg "test/build: key-exchanges (gcc)" # ~ 1 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100984 record_status tests/scripts/key-exchanges.pl
985}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100986
Gilles Peskine8f073122018-11-27 15:58:47 +0100987component_build_default_make_gcc_and_cxx () {
988 msg "build: Unix make, -Os (gcc)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100989 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100990
Gilles Peskine8f073122018-11-27 15:58:47 +0100991 msg "test: verify header list in cpp_dummy_build.cpp"
992 record_status check_headers_in_cpp
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100993
Gilles Peskine8f073122018-11-27 15:58:47 +0100994 msg "build: Unix make, incremental g++"
995 make TEST_CPP=1
996}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100997
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100998component_test_no_use_psa_crypto_full_cmake_asan() {
999 # full minus MBEDTLS_USE_PSA_CRYPTO: run the same set of tests as basic-build-test.sh
Gilles Peskinedc3a1792019-09-03 11:42:04 +02001000 msg "build: cmake, full config minus MBEDTLS_USE_PSA_CRYPTO, ASan"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001001 scripts/config.py full
1002 scripts/config.py set MBEDTLS_ECP_RESTARTABLE # not using PSA, so enable restartable ECC
1003 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C
1004 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1005 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C
1006 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
Manuel Pégourié-Gonnardd8167e82019-02-01 11:12:52 +01001007 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Andrzej Kurekde5a0072019-02-01 07:03:03 -05001008 make
Manuel Pégourié-Gonnard43be6cd2017-06-20 09:53:42 +02001009
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001010 msg "test: main suites (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -05001011 make test
Manuel Pégourié-Gonnard503a5ef2015-10-23 09:04:45 +02001012
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001013 msg "test: ssl-opt.sh (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -05001014 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001015
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001016 msg "test: compat.sh default (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -05001017 if_build_succeeded tests/compat.sh
Andrzej Kurek991f9fe2018-07-02 09:08:21 -04001018
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001019 msg "test: compat.sh RC4, DES & NULL (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -05001020 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 -05001021
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001022 msg "test: compat.sh ARIA + ChachaPoly (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -05001023 if_build_succeeded env OPENSSL_CMD="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
1024}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -05001025
Gilles Peskineadcde5e2019-06-12 16:05:50 +02001026component_test_check_params_functionality () {
1027 msg "build+test: MBEDTLS_CHECK_PARAMS functionality"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001028 scripts/config.py full # includes CHECK_PARAMS
Gilles Peskineadcde5e2019-06-12 16:05:50 +02001029 # Make MBEDTLS_PARAM_FAILED call mbedtls_param_failed().
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001030 scripts/config.py unset MBEDTLS_CHECK_PARAMS_ASSERT
Gilles Peskineadcde5e2019-06-12 16:05:50 +02001031 # Only build and run tests. Do not build sample programs, because
1032 # they don't have a mbedtls_param_failed() function.
1033 make CC=gcc CFLAGS='-Werror -O1' lib test
1034}
1035
Gilles Peskineb28636b2019-01-02 19:06:24 +01001036component_test_check_params_without_platform () {
1037 msg "build+test: MBEDTLS_CHECK_PARAMS without MBEDTLS_PLATFORM_C"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001038 scripts/config.py full # includes CHECK_PARAMS
Gilles Peskineadcde5e2019-06-12 16:05:50 +02001039 # Keep MBEDTLS_PARAM_FAILED as assert.
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001040 scripts/config.py unset MBEDTLS_PLATFORM_EXIT_ALT
1041 scripts/config.py unset MBEDTLS_PLATFORM_TIME_ALT
1042 scripts/config.py unset MBEDTLS_PLATFORM_FPRINTF_ALT
1043 scripts/config.py unset MBEDTLS_PLATFORM_MEMORY
1044 scripts/config.py unset MBEDTLS_PLATFORM_PRINTF_ALT
1045 scripts/config.py unset MBEDTLS_PLATFORM_SNPRINTF_ALT
1046 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
1047 scripts/config.py unset MBEDTLS_PLATFORM_C
Gilles Peskineb28636b2019-01-02 19:06:24 +01001048 make CC=gcc CFLAGS='-Werror -O1' all test
1049}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -05001050
Gilles Peskineb28636b2019-01-02 19:06:24 +01001051component_test_check_params_silent () {
1052 msg "build+test: MBEDTLS_CHECK_PARAMS with alternative MBEDTLS_PARAM_FAILED()"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001053 scripts/config.py full # includes CHECK_PARAMS
Gilles Peskineadcde5e2019-06-12 16:05:50 +02001054 # Set MBEDTLS_PARAM_FAILED to nothing.
Gilles Peskineb28636b2019-01-02 19:06:24 +01001055 sed -i 's/.*\(#define MBEDTLS_PARAM_FAILED( cond )\).*/\1/' "$CONFIG_H"
1056 make CC=gcc CFLAGS='-Werror -O1' all test
1057}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -05001058
Gilles Peskine8f073122018-11-27 15:58:47 +01001059component_test_no_platform () {
1060 # Full configuration build, without platform support, file IO and net sockets.
1061 # This should catch missing mbedtls_printf definitions, and by disabling file
1062 # IO, it should catch missing '#include <stdio.h>'
1063 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001064 scripts/config.py full
1065 scripts/config.py unset MBEDTLS_PLATFORM_C
1066 scripts/config.py unset MBEDTLS_NET_C
1067 scripts/config.py unset MBEDTLS_PLATFORM_MEMORY
1068 scripts/config.py unset MBEDTLS_PLATFORM_PRINTF_ALT
1069 scripts/config.py unset MBEDTLS_PLATFORM_FPRINTF_ALT
1070 scripts/config.py unset MBEDTLS_PLATFORM_SNPRINTF_ALT
1071 scripts/config.py unset MBEDTLS_PLATFORM_TIME_ALT
1072 scripts/config.py unset MBEDTLS_PLATFORM_EXIT_ALT
1073 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
1074 scripts/config.py unset MBEDTLS_FS_IO
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001075 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001076 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
1077 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C
Gilles Peskine8f073122018-11-27 15:58:47 +01001078 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
1079 # to re-enable platform integration features otherwise disabled in C99 builds
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02001080 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -Os -D_DEFAULT_SOURCE' lib programs
1081 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os' test
Gilles Peskine8f073122018-11-27 15:58:47 +01001082}
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +00001083
Gilles Peskine8f073122018-11-27 15:58:47 +01001084component_build_no_std_function () {
1085 # catch compile bugs in _uninit functions
1086 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001087 scripts/config.py full
1088 scripts/config.py set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
1089 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02001090 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Gilles Peskine8f073122018-11-27 15:58:47 +01001091}
Manuel Pégourié-Gonnarddccb80b2015-06-03 10:20:33 +01001092
Gilles Peskine8f073122018-11-27 15:58:47 +01001093component_build_no_ssl_srv () {
1094 msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001095 scripts/config.py full
1096 scripts/config.py unset MBEDTLS_SSL_SRV_C
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02001097 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
Gilles Peskine8f073122018-11-27 15:58:47 +01001098}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +02001099
Gilles Peskine8f073122018-11-27 15:58:47 +01001100component_build_no_ssl_cli () {
1101 msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001102 scripts/config.py full
1103 scripts/config.py unset MBEDTLS_SSL_CLI_C
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02001104 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
Gilles Peskine8f073122018-11-27 15:58:47 +01001105}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +02001106
Gilles Peskine8f073122018-11-27 15:58:47 +01001107component_build_no_sockets () {
1108 # Note, C99 compliance can also be tested with the sockets support disabled,
1109 # as that requires a POSIX platform (which isn't the same as C99).
1110 msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001111 scripts/config.py full
1112 scripts/config.py unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
1113 scripts/config.py set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02001114 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1 -std=c99 -pedantic' lib
Gilles Peskine8f073122018-11-27 15:58:47 +01001115}
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +02001116
Andrzej Kurek69f20aa2019-09-05 09:27:47 -04001117component_test_memory_buffer_allocator_backtrace () {
1118 msg "build: default config with memory buffer allocator and backtrace enabled"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001119 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
1120 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
1121 scripts/config.py set MBEDTLS_MEMORY_BACKTRACE
1122 scripts/config.py set MBEDTLS_MEMORY_DEBUG
Andrzej Kurek69f20aa2019-09-05 09:27:47 -04001123 CC=gcc cmake .
1124 make
1125
1126 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C and MBEDTLS_MEMORY_BACKTRACE"
1127 make test
1128}
1129
1130component_test_memory_buffer_allocator () {
1131 msg "build: default config with memory buffer allocator"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001132 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
1133 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
Hanno Becker0fb9ba22019-02-26 14:34:13 +00001134 CC=gcc cmake .
1135 make
1136
1137 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C"
1138 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +01001139
1140 msg "test: ssl-opt.sh, MBEDTLS_MEMORY_BUFFER_ALLOC_C"
1141 # MBEDTLS_MEMORY_BUFFER_ALLOC is slow. Skip tests that tend to time out.
1142 if_build_succeeded tests/ssl-opt.sh -e '^DTLS proxy'
Hanno Becker0fb9ba22019-02-26 14:34:13 +00001143}
1144
Gilles Peskine8f073122018-11-27 15:58:47 +01001145component_test_no_max_fragment_length () {
1146 # Run max fragment length tests with MFL disabled
1147 msg "build: default config except MFL extension (ASan build)" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001148 scripts/config.py unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
Gilles Peskine8f073122018-11-27 15:58:47 +01001149 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1150 make
Hanno Becker5175ac62017-09-18 15:36:25 +01001151
Gilles Peskine8f073122018-11-27 15:58:47 +01001152 msg "test: ssl-opt.sh, MFL-related tests"
1153 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length"
1154}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001155
Hanno Becker545ced42019-02-19 11:10:48 +00001156component_test_asan_remove_peer_certificate () {
1157 msg "build: default config with MBEDTLS_SSL_KEEP_PEER_CERTIFICATE disabled (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001158 scripts/config.py unset MBEDTLS_SSL_KEEP_PEER_CERTIFICATE
Hanno Becker545ced42019-02-19 11:10:48 +00001159 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1160 make
1161
1162 msg "test: !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
1163 make test
1164
1165 msg "test: ssl-opt.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
1166 if_build_succeeded tests/ssl-opt.sh
1167
1168 msg "test: compat.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
1169 if_build_succeeded tests/compat.sh
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02001170
1171 msg "test: context-info.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
1172 if_build_succeeded tests/context-info.sh
Hanno Becker545ced42019-02-19 11:10:48 +00001173}
1174
Gilles Peskine8f073122018-11-27 15:58:47 +01001175component_test_no_max_fragment_length_small_ssl_out_content_len () {
1176 msg "build: no MFL extension, small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001177 scripts/config.py unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
1178 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 16384
1179 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
Gilles Peskine8f073122018-11-27 15:58:47 +01001180 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1181 make
Angus Grattonc4dd0732018-04-11 16:28:39 +10001182
Gilles Peskine8f073122018-11-27 15:58:47 +01001183 msg "test: MFL tests (disabled MFL extension case) & large packet tests"
1184 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length\|Large buffer"
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02001185
1186 msg "test: context-info.sh (disabled MFL extension case)"
1187 if_build_succeeded tests/context-info.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01001188}
Angus Grattonc4dd0732018-04-11 16:28:39 +10001189
Darryl Greenaad82f92019-12-02 10:53:11 +00001190component_test_variable_ssl_in_out_buffer_len () {
1191 msg "build: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled (ASan build)"
1192 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
1193 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1194 make
1195
1196 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
1197 make test
1198
1199 msg "test: ssl-opt.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
1200 if_build_succeeded tests/ssl-opt.sh
1201
1202 msg "test: compat.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
1203 if_build_succeeded tests/compat.sh
1204}
1205
1206component_test_variable_ssl_in_out_buffer_len_CID () {
1207 msg "build: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_DTLS_CONNECTION_ID enabled (ASan build)"
1208 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
1209 scripts/config.py set MBEDTLS_SSL_DTLS_CONNECTION_ID
1210
1211 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1212 make
1213
1214 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_DTLS_CONNECTION_ID"
1215 make test
1216
1217 msg "test: ssl-opt.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_DTLS_CONNECTION_ID enabled"
1218 if_build_succeeded tests/ssl-opt.sh
1219
1220 msg "test: compat.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_DTLS_CONNECTION_ID enabled"
1221 if_build_succeeded tests/compat.sh
1222}
1223
1224component_test_variable_ssl_in_out_buffer_len_record_splitting () {
1225 msg "build: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_CBC_RECORD_SPLITTING enabled (ASan build)"
1226 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
1227 scripts/config.py set MBEDTLS_SSL_CBC_RECORD_SPLITTING
1228
1229 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1230 make
1231
1232 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_CBC_RECORD_SPLITTING"
1233 make test
1234
1235 msg "test: ssl-opt.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_CBC_RECORD_SPLITTING enabled"
1236 if_build_succeeded tests/ssl-opt.sh
1237
1238 msg "test: compat.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_CBC_RECORD_SPLITTING enabled"
1239 if_build_succeeded tests/compat.sh
1240}
1241
Piotr Nowicki0937ed22019-11-26 16:32:40 +01001242component_test_ssl_alloc_buffer_and_mfl () {
1243 msg "build: default config with memory buffer allocator and MFL extension"
1244 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
1245 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
1246 scripts/config.py set MBEDTLS_MEMORY_DEBUG
1247 scripts/config.py set MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
1248 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
1249 CC=gcc cmake .
1250 make
1251
1252 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH, MBEDTLS_MEMORY_BUFFER_ALLOC_C, MBEDTLS_MEMORY_DEBUG and MBEDTLS_SSL_MAX_FRAGMENT_LENGTH"
1253 make test
1254
1255 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH, MBEDTLS_MEMORY_BUFFER_ALLOC_C, MBEDTLS_MEMORY_DEBUG and MBEDTLS_SSL_MAX_FRAGMENT_LENGTH"
1256 if_build_succeeded tests/ssl-opt.sh -f "Handshake memory usage"
1257}
1258
Gilles Peskine636c26a2020-03-04 20:46:15 +01001259component_test_when_no_ciphersuites_have_mac () {
1260 msg "build: when no ciphersuites have MAC"
1261 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
1262 scripts/config.py unset MBEDTLS_ARC4_C
1263 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
1264 make
1265
1266 msg "test: !MBEDTLS_SSL_SOME_MODES_USE_MAC"
1267 make test
1268
1269 msg "test ssl-opt.sh: !MBEDTLS_SSL_SOME_MODES_USE_MAC"
1270 if_build_succeeded tests/ssl-opt.sh -f 'Default\|EtM' -e 'without EtM'
1271}
1272
Gilles Peskine8f073122018-11-27 15:58:47 +01001273component_test_null_entropy () {
1274 msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001275 scripts/config.py set MBEDTLS_TEST_NULL_ENTROPY
1276 scripts/config.py set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
1277 scripts/config.py set MBEDTLS_ENTROPY_C
1278 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
1279 scripts/config.py unset MBEDTLS_ENTROPY_HARDWARE_ALT
1280 scripts/config.py unset MBEDTLS_HAVEGE_C
Gilles Peskine5fa32a72019-01-06 19:48:30 +00001281 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan -D UNSAFE_BUILD=ON .
Gilles Peskine8f073122018-11-27 15:58:47 +01001282 make
Janos Follath06c54002016-06-09 13:57:40 +01001283
Gilles Peskine8f073122018-11-27 15:58:47 +01001284 msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)"
1285 make test
1286}
Janos Follath06c54002016-06-09 13:57:40 +01001287
Gilles Peskine8f073122018-11-27 15:58:47 +01001288component_test_platform_calloc_macro () {
1289 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001290 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
1291 scripts/config.py set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
1292 scripts/config.py set MBEDTLS_PLATFORM_FREE_MACRO free
Gilles Peskine8f073122018-11-27 15:58:47 +01001293 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1294 make
Hanno Beckere5fecec2018-10-11 11:02:52 +01001295
Gilles Peskine8f073122018-11-27 15:58:47 +01001296 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
1297 make test
1298}
Hanno Beckere5fecec2018-10-11 11:02:52 +01001299
Gilles Peskinec4ef7a92019-09-17 19:04:38 +02001300component_test_malloc_0_null () {
1301 msg "build: malloc(0) returns NULL (ASan+UBSan build)"
Manuel Pégourié-Gonnard68192fc2020-03-04 10:34:47 +01001302 scripts/config.py full
Gilles Peskine004206c2019-10-21 17:11:33 +02001303 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 +02001304
1305 msg "test: malloc(0) returns NULL (ASan+UBSan build)"
1306 make test
1307
1308 msg "selftest: malloc(0) returns NULL (ASan+UBSan build)"
1309 # Just the calloc selftest. "make test" ran the others as part of the
1310 # test suites.
1311 if_build_succeeded programs/test/selftest calloc
Gilles Peskine765d2402020-02-11 18:26:34 +01001312
1313 msg "test ssl-opt.sh: malloc(0) returns NULL (ASan+UBSan build)"
1314 # Run a subset of the tests. The choice is a balance between coverage
1315 # and time (including time indirectly wasted due to flaky tests).
1316 # The current choice is to skip tests whose description includes
1317 # "proxy", which is an approximation of skipping tests that use the
1318 # UDP proxy, which tend to be slower and flakier.
1319 if_build_succeeded tests/ssl-opt.sh -e 'proxy'
Gilles Peskinec4ef7a92019-09-17 19:04:38 +02001320}
1321
Gilles Peskine8f073122018-11-27 15:58:47 +01001322component_test_aes_fewer_tables () {
1323 msg "build: default config with AES_FEWER_TABLES enabled"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001324 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
Gilles Peskine8f073122018-11-27 15:58:47 +01001325 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01001326
Gilles Peskine8f073122018-11-27 15:58:47 +01001327 msg "test: AES_FEWER_TABLES"
1328 make test
1329}
Hanno Becker83ebf782017-07-07 12:29:15 +01001330
Gilles Peskine8f073122018-11-27 15:58:47 +01001331component_test_aes_rom_tables () {
1332 msg "build: default config with AES_ROM_TABLES enabled"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001333 scripts/config.py set MBEDTLS_AES_ROM_TABLES
Gilles Peskine8f073122018-11-27 15:58:47 +01001334 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01001335
Gilles Peskine8f073122018-11-27 15:58:47 +01001336 msg "test: AES_ROM_TABLES"
1337 make test
1338}
Hanno Becker83ebf782017-07-07 12:29:15 +01001339
Gilles Peskine8f073122018-11-27 15:58:47 +01001340component_test_aes_fewer_tables_and_rom_tables () {
1341 msg "build: default config with AES_ROM_TABLES and AES_FEWER_TABLES enabled"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001342 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
1343 scripts/config.py set MBEDTLS_AES_ROM_TABLES
Gilles Peskine8f073122018-11-27 15:58:47 +01001344 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01001345
Gilles Peskine8f073122018-11-27 15:58:47 +01001346 msg "test: AES_FEWER_TABLES + AES_ROM_TABLES"
1347 make test
1348}
1349
Gilles Peskine592f5912019-10-07 18:49:32 +02001350component_test_ctr_drbg_aes_256_sha_256 () {
1351 msg "build: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
Gilles Peskine3b46cd32020-02-18 17:56:33 +01001352 scripts/config.py full
1353 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
1354 scripts/config.py set MBEDTLS_ENTROPY_FORCE_SHA256
Gilles Peskine592f5912019-10-07 18:49:32 +02001355 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1356 make
1357
1358 msg "test: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
1359 make test
1360}
1361
1362component_test_ctr_drbg_aes_128_sha_512 () {
1363 msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)"
Gilles Peskine3b46cd32020-02-18 17:56:33 +01001364 scripts/config.py full
1365 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
1366 scripts/config.py set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
Gilles Peskine592f5912019-10-07 18:49:32 +02001367 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1368 make
1369
1370 msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)"
1371 make test
1372}
1373
1374component_test_ctr_drbg_aes_128_sha_256 () {
1375 msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
Gilles Peskine3b46cd32020-02-18 17:56:33 +01001376 scripts/config.py full
1377 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
1378 scripts/config.py set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
1379 scripts/config.py set MBEDTLS_ENTROPY_FORCE_SHA256
Gilles Peskine592f5912019-10-07 18:49:32 +02001380 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1381 make
1382
1383 msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
1384 make test
1385}
1386
Gilles Peskinef96aefe2019-07-24 14:58:38 +02001387component_test_se_default () {
1388 msg "build: default config + MBEDTLS_PSA_CRYPTO_SE_C"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001389 scripts/config.py set MBEDTLS_PSA_CRYPTO_SE_C
Gilles Peskine004206c2019-10-21 17:11:33 +02001390 make CC=clang CFLAGS="$ASAN_CFLAGS -Os" LDFLAGS="$ASAN_CFLAGS"
Gilles Peskinef96aefe2019-07-24 14:58:38 +02001391
1392 msg "test: default config + MBEDTLS_PSA_CRYPTO_SE_C"
1393 make test
1394}
1395
1396component_test_se_full () {
1397 msg "build: full config + MBEDTLS_PSA_CRYPTO_SE_C"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001398 scripts/config.py full
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001399 scripts/config.py set MBEDTLS_PSA_CRYPTO_SE_C
Gilles Peskine004206c2019-10-21 17:11:33 +02001400 make CC=gcc CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
Gilles Peskinef96aefe2019-07-24 14:58:38 +02001401
1402 msg "test: full config + MBEDTLS_PSA_CRYPTO_SE_C"
1403 make test
1404}
1405
Gilles Peskine8f073122018-11-27 15:58:47 +01001406component_test_make_shared () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001407 msg "build/test: make shared" # ~ 40s
Andrzej Kurek232e8f92019-10-03 03:18:01 -04001408 make SHARED=1 all check
Gilles Peskine56c01612019-07-03 20:43:32 +02001409 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskine8f073122018-11-27 15:58:47 +01001410}
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +02001411
Gilles Peskinecf740502019-07-03 20:43:05 +02001412component_test_cmake_shared () {
1413 msg "build/test: cmake shared" # ~ 2min
1414 cmake -DUSE_SHARED_MBEDTLS_LIBRARY=On .
1415 make
Gilles Peskine56c01612019-07-03 20:43:32 +02001416 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskinecf740502019-07-03 20:43:05 +02001417 make test
1418}
1419
Gilles Peskineec10bf12019-09-20 19:56:06 +02001420test_build_opt () {
1421 info=$1 cc=$2; shift 2
1422 for opt in "$@"; do
1423 msg "build/test: $cc $opt, $info" # ~ 30s
1424 make CC="$cc" CFLAGS="$opt -Wall -Wextra -Werror"
1425 # We're confident enough in compilers to not run _all_ the tests,
1426 # but at least run the unit tests. In particular, runs with
1427 # optimizations use inline assembly whereas runs with -O0
1428 # skip inline assembly.
1429 make test # ~30s
1430 make clean
1431 done
1432}
1433
1434component_test_clang_opt () {
Manuel Pégourié-Gonnard68192fc2020-03-04 10:34:47 +01001435 scripts/config.py full
Gilles Peskineec10bf12019-09-20 19:56:06 +02001436 test_build_opt 'full config' clang -O0 -Os -O2
1437}
1438
1439component_test_gcc_opt () {
Manuel Pégourié-Gonnard68192fc2020-03-04 10:34:47 +01001440 scripts/config.py full
Gilles Peskineec10bf12019-09-20 19:56:06 +02001441 test_build_opt 'full config' gcc -O0 -Os -O2
1442}
1443
Gilles Peskineabf9b4d2019-07-03 20:42:16 +02001444component_build_mbedtls_config_file () {
1445 msg "build: make with MBEDTLS_CONFIG_FILE" # ~40s
1446 # Use the full config so as to catch a maximum of places where
1447 # the check of MBEDTLS_CONFIG_FILE might be missing.
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001448 scripts/config.py full
Gilles Peskineabf9b4d2019-07-03 20:42:16 +02001449 sed 's!"check_config.h"!"mbedtls/check_config.h"!' <"$CONFIG_H" >full_config.h
1450 echo '#error "MBEDTLS_CONFIG_FILE is not working"' >"$CONFIG_H"
1451 make CFLAGS="-I '$PWD' -DMBEDTLS_CONFIG_FILE='\"full_config.h\"'"
1452 rm -f full_config.h
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001453}
1454
Gilles Peskine8f073122018-11-27 15:58:47 +01001455component_test_m32_o0 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001456 # Build once with -O0, to compile out the i386 specific inline assembly
1457 msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001458 scripts/config.py full
Gilles Peskine8fd59422019-10-21 17:11:33 +02001459 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O0" LDFLAGS="-m32 $ASAN_CFLAGS"
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01001460
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001461 msg "test: i386, make, gcc -O0 (ASan build)"
1462 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01001463}
Gilles Peskine878cf602019-01-06 20:50:38 +00001464support_test_m32_o0 () {
1465 case $(uname -m) in
1466 *64*) true;;
1467 *) false;;
1468 esac
1469}
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001470
Gilles Peskine8f073122018-11-27 15:58:47 +01001471component_test_m32_o1 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001472 # Build again with -O1, to compile in the i386 specific inline assembly
1473 msg "build: i386, make, gcc -O1 (ASan build)" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001474 scripts/config.py full
Gilles Peskine8fd59422019-10-21 17:11:33 +02001475 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O1" LDFLAGS="-m32 $ASAN_CFLAGS"
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001476
1477 msg "test: i386, make, gcc -O1 (ASan build)"
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001478 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +01001479
1480 msg "test ssl-opt.sh, i386, make, gcc-O1"
1481 if_build_succeeded tests/ssl-opt.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01001482}
Gilles Peskine878cf602019-01-06 20:50:38 +00001483support_test_m32_o1 () {
1484 support_test_m32_o0 "$@"
1485}
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001486
Gilles Peskine0c6b7992019-04-12 20:29:48 +02001487component_test_m32_everest () {
1488 msg "build: i386, Everest ECDH context (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001489 scripts/config.py unset MBEDTLS_ECDH_LEGACY_CONTEXT
1490 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
Gilles Peskine8fd59422019-10-21 17:11:33 +02001491 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O2" LDFLAGS="-m32 $ASAN_CFLAGS"
Gilles Peskine0c6b7992019-04-12 20:29:48 +02001492
1493 msg "test: i386, Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
1494 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +01001495
1496 msg "test: i386, Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
1497 if_build_succeeded tests/ssl-opt.sh -f ECDH
1498
1499 msg "test: i386, Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
1500 # Exclude some symmetric ciphers that are redundant here to gain time.
1501 if_build_succeeded tests/compat.sh -f ECDH -V NO -e 'ARCFOUR\|ARIA\|CAMELLIA\|CHACHA\|DES\|RC4'
Gilles Peskine0c6b7992019-04-12 20:29:48 +02001502}
1503support_test_m32_everest () {
1504 support_test_m32_o0 "$@"
1505}
1506
Gilles Peskine8f073122018-11-27 15:58:47 +01001507component_test_mx32 () {
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001508 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001509 scripts/config.py full
Gilles Peskine5d26e7c2019-06-07 14:50:09 +02001510 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32' LDFLAGS='-mx32'
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001511
1512 msg "test: 64-bit ILP32, make, gcc"
1513 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01001514}
Gilles Peskine878cf602019-01-06 20:50:38 +00001515support_test_mx32 () {
1516 case $(uname -m) in
1517 amd64|x86_64) true;;
1518 *) false;;
1519 esac
1520}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001521
Peter Kolbus60c6da22018-12-27 06:59:04 -06001522component_test_min_mpi_window_size () {
1523 msg "build: Default + MBEDTLS_MPI_WINDOW_SIZE=1 (ASan build)" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001524 scripts/config.py set MBEDTLS_MPI_WINDOW_SIZE 1
Peter Kolbus60c6da22018-12-27 06:59:04 -06001525 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1526 make
1527
1528 msg "test: MBEDTLS_MPI_WINDOW_SIZE=1 - main suites (inc. selftests) (ASan build)" # ~ 10s
1529 make test
1530}
1531
Gilles Peskine8f073122018-11-27 15:58:47 +01001532component_test_have_int32 () {
1533 msg "build: gcc, force 32-bit bignum limbs"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001534 scripts/config.py unset MBEDTLS_HAVE_ASM
1535 scripts/config.py unset MBEDTLS_AESNI_C
1536 scripts/config.py unset MBEDTLS_PADLOCK_C
Gilles Peskine8f073122018-11-27 15:58:47 +01001537 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01001538
Gilles Peskine8f073122018-11-27 15:58:47 +01001539 msg "test: gcc, force 32-bit bignum limbs"
1540 make test
1541}
Andres Amaya Garciafe843a32017-07-20 13:21:34 +01001542
Gilles Peskine8f073122018-11-27 15:58:47 +01001543component_test_have_int64 () {
1544 msg "build: gcc, force 64-bit bignum limbs"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001545 scripts/config.py unset MBEDTLS_HAVE_ASM
1546 scripts/config.py unset MBEDTLS_AESNI_C
1547 scripts/config.py unset MBEDTLS_PADLOCK_C
Gilles Peskine8f073122018-11-27 15:58:47 +01001548 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
Gilles Peskine14c3c062018-01-29 21:25:12 +01001549
Gilles Peskine8f073122018-11-27 15:58:47 +01001550 msg "test: gcc, force 64-bit bignum limbs"
1551 make test
1552}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001553
Gilles Peskine8f073122018-11-27 15:58:47 +01001554component_test_no_udbl_division () {
1555 msg "build: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001556 scripts/config.py full
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001557 scripts/config.py set MBEDTLS_NO_UDBL_DIVISION
Gilles Peskine8f073122018-11-27 15:58:47 +01001558 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001559
Gilles Peskine8f073122018-11-27 15:58:47 +01001560 msg "test: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
1561 make test
1562}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001563
Gilles Peskine8f073122018-11-27 15:58:47 +01001564component_test_no_64bit_multiplication () {
1565 msg "build: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001566 scripts/config.py full
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001567 scripts/config.py set MBEDTLS_NO_64BIT_MULTIPLICATION
Gilles Peskine8f073122018-11-27 15:58:47 +01001568 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001569
Gilles Peskine8f073122018-11-27 15:58:47 +01001570 msg "test: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
1571 make test
1572}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001573
Gilles Peskine8f073122018-11-27 15:58:47 +01001574component_build_arm_none_eabi_gcc () {
1575 msg "build: arm-none-eabi-gcc, make" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001576 scripts/config.py baremetal
Gilles Peskine8f073122018-11-27 15:58:47 +01001577 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
1578}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001579
Gilles Peskine2c897d72019-08-09 16:05:05 +02001580component_build_arm_none_eabi_gcc_arm5vte () {
Gilles Peskine8a52af92019-08-08 16:09:02 +02001581 msg "build: arm-none-eabi-gcc -march=arm5vte, make" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001582 scripts/config.py baremetal
Gilles Peskine2c897d72019-08-09 16:05:05 +02001583 # Build for a target platform that's close to what Debian uses
1584 # for its "armel" distribution (https://wiki.debian.org/ArmEabiPort).
1585 # See https://github.com/ARMmbed/mbedtls/pull/2169 and comments.
1586 # It would be better to build with arm-linux-gnueabi-gcc but
1587 # we don't have that on our CI at this time.
Gilles Peskine8a52af92019-08-08 16:09:02 +02001588 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 +02001589}
1590
Gilles Peskine8f073122018-11-27 15:58:47 +01001591component_build_arm_none_eabi_gcc_no_udbl_division () {
1592 msg "build: arm-none-eabi-gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001593 scripts/config.py baremetal
1594 scripts/config.py set MBEDTLS_NO_UDBL_DIVISION
Gilles Peskine8f073122018-11-27 15:58:47 +01001595 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
1596 echo "Checking that software 64-bit division is not required"
1597 if_build_succeeded not grep __aeabi_uldiv library/*.o
1598}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001599
Gilles Peskine8f073122018-11-27 15:58:47 +01001600component_build_arm_none_eabi_gcc_no_64bit_multiplication () {
1601 msg "build: arm-none-eabi-gcc MBEDTLS_NO_64BIT_MULTIPLICATION, make" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001602 scripts/config.py baremetal
1603 scripts/config.py set MBEDTLS_NO_64BIT_MULTIPLICATION
Gilles Peskine8f073122018-11-27 15:58:47 +01001604 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -O1 -march=armv6-m -mthumb' lib
1605 echo "Checking that software 64-bit multiplication is not required"
1606 if_build_succeeded not grep __aeabi_lmul library/*.o
1607}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001608
Gilles Peskine8f073122018-11-27 15:58:47 +01001609component_build_armcc () {
1610 msg "build: ARM Compiler 5, make"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001611 scripts/config.py baremetal
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001612
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001613 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
1614 make clean
Andres AG87bb5772016-09-27 15:05:15 +01001615
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001616 # ARM Compiler 6 - Target ARMv7-A
1617 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-a"
Simon Butcher940737f2017-07-23 13:42:36 +02001618
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001619 # ARM Compiler 6 - Target ARMv7-M
1620 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m"
Simon Butcher940737f2017-07-23 13:42:36 +02001621
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001622 # ARM Compiler 6 - Target ARMv8-A - AArch32
1623 armc6_build_test "--target=arm-arm-none-eabi -march=armv8.2-a"
Simon Butcher940737f2017-07-23 13:42:36 +02001624
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001625 # ARM Compiler 6 - Target ARMv8-M
1626 armc6_build_test "--target=arm-arm-none-eabi -march=armv8-m.main"
Simon Butcher940737f2017-07-23 13:42:36 +02001627
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001628 # ARM Compiler 6 - Target ARMv8-A - AArch64
1629 armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a"
Gilles Peskine8f073122018-11-27 15:58:47 +01001630}
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +01001631
Manuel Pégourié-Gonnarddd8807f2020-02-26 09:56:27 +01001632component_build_ssl_hw_record_accel() {
1633 msg "build: default config with MBEDTLS_SSL_HW_RECORD_ACCEL enabled"
1634 scripts/config.pl set MBEDTLS_SSL_HW_RECORD_ACCEL
1635 make CFLAGS='-Werror -O1'
1636}
1637
Gilles Peskine8f073122018-11-27 15:58:47 +01001638component_test_allow_sha1 () {
1639 msg "build: allow SHA1 in certificates by default"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001640 scripts/config.py set MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
Gilles Peskine8f073122018-11-27 15:58:47 +01001641 make CFLAGS='-Werror -Wall -Wextra'
1642 msg "test: allow SHA1 in certificates by default"
1643 make test
1644 if_build_succeeded tests/ssl-opt.sh -f SHA-1
1645}
Gilles Peskine2a458da2017-05-12 15:26:58 +02001646
Gilles Peskine8f073122018-11-27 15:58:47 +01001647component_build_mingw () {
1648 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
Andrzej Kurek232e8f92019-10-03 03:18:01 -04001649 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 +00001650
Gilles Peskine8f073122018-11-27 15:58:47 +01001651 # note Make tests only builds the tests, but doesn't run them
Andrzej Kurek232e8f92019-10-03 03:18:01 -04001652 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 +01001653 make WINDOWS_BUILD=1 clean
Simon Butcher002bc622016-11-17 09:27:45 +00001654
Gilles Peskine8f073122018-11-27 15:58:47 +01001655 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
Andrzej Kurek232e8f92019-10-03 03:18:01 -04001656 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
1657 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 +01001658 make WINDOWS_BUILD=1 clean
1659}
Jaeden Amero117b8a42019-04-17 15:19:26 +01001660support_build_mingw() {
1661 case $(i686-w64-mingw32-gcc -dumpversion) in
1662 [0-5]*) false;;
1663 *) true;;
1664 esac
1665}
Manuel Pégourié-Gonnard6448bce2015-02-16 17:18:36 +01001666
Gilles Peskine8f073122018-11-27 15:58:47 +01001667component_test_memsan () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001668 msg "build: MSan (clang)" # ~ 1 min 20s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001669 scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001670 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
1671 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +02001672
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001673 msg "test: main suites (MSan)" # ~ 10s
1674 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001675
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001676 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
Gilles Peskine7c652162017-12-11 00:01:40 +01001677 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001678
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001679 # Optional part(s)
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001680
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001681 if [ "$MEMORY" -gt 0 ]; then
1682 msg "test: compat.sh (MSan)" # ~ 6 min 20s
Gilles Peskine7c652162017-12-11 00:01:40 +01001683 if_build_succeeded tests/compat.sh
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001684 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001685}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001686
Gilles Peskine69f190e2019-01-10 00:11:42 +01001687component_test_valgrind () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001688 msg "build: Release (clang)"
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001689 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
1690 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001691
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001692 msg "test: main suites valgrind (Release)"
1693 make memcheck
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001694
Gilles Peskine636c26a2020-03-04 20:46:15 +01001695 # Optional parts (slow; currently broken on OS X because programs don't
1696 # seem to receive signals under valgrind on OS X).
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001697 if [ "$MEMORY" -gt 0 ]; then
1698 msg "test: ssl-opt.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +01001699 if_build_succeeded tests/ssl-opt.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001700 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001701
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001702 if [ "$MEMORY" -gt 1 ]; then
1703 msg "test: compat.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +01001704 if_build_succeeded tests/compat.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001705 fi
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02001706
1707 if [ "$MEMORY" -gt 0 ]; then
1708 msg "test: context-info.sh --memcheck (Release)"
1709 if_build_succeeded tests/context-info.sh --memcheck
1710 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001711}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001712
Gilles Peskine8f073122018-11-27 15:58:47 +01001713component_test_cmake_out_of_source () {
1714 msg "build: cmake 'out-of-source' build"
Gilles Peskine8f073122018-11-27 15:58:47 +01001715 MBEDTLS_ROOT_DIR="$PWD"
1716 mkdir "$OUT_OF_SOURCE_DIR"
1717 cd "$OUT_OF_SOURCE_DIR"
1718 cmake "$MBEDTLS_ROOT_DIR"
1719 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001720
Gilles Peskine8f073122018-11-27 15:58:47 +01001721 msg "test: cmake 'out-of-source' build"
1722 make test
1723 # Test an SSL option that requires an auxiliary script in test/scripts/.
1724 # Also ensure that there are no error messages such as
1725 # "No such file or directory", which would indicate that some required
1726 # file is missing (ssl-opt.sh tolerates the absence of some files so
1727 # may exit with status 0 but emit errors).
1728 if_build_succeeded ./tests/ssl-opt.sh -f 'Fallback SCSV: beginning of list' 2>ssl-opt.err
1729 if [ -s ssl-opt.err ]; then
1730 cat ssl-opt.err >&2
1731 record_status [ ! -s ssl-opt.err ]
1732 rm ssl-opt.err
1733 fi
1734 cd "$MBEDTLS_ROOT_DIR"
1735 rm -rf "$OUT_OF_SOURCE_DIR"
1736 unset MBEDTLS_ROOT_DIR
1737}
Andres AGdc192212016-08-31 17:33:13 +01001738
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01001739component_test_cmake_as_subdirectory () {
1740 msg "build: cmake 'as-subdirectory' build"
1741 MBEDTLS_ROOT_DIR="$PWD"
1742
1743 cd programs/test/cmake_subproject
1744 cmake .
1745 make
1746 if_build_succeeded ./cmake_subproject
1747
1748 cd "$MBEDTLS_ROOT_DIR"
1749 unset MBEDTLS_ROOT_DIR
1750}
1751
Gilles Peskine8f073122018-11-27 15:58:47 +01001752component_test_zeroize () {
1753 # Test that the function mbedtls_platform_zeroize() is not optimized away by
1754 # different combinations of compilers and optimization flags by using an
1755 # auxiliary GDB script. Unfortunately, GDB does not return error values to the
1756 # system in all cases that the script fails, so we must manually search the
1757 # output to check whether the pass string is present and no failure strings
1758 # were printed.
Andres AGdc192212016-08-31 17:33:13 +01001759
Gilles Peskine4976e822019-01-06 19:52:22 +00001760 # Don't try to disable ASLR. We don't care about ASLR here. We do care
1761 # about a spurious message if Gdb tries and fails, so suppress that.
1762 gdb_disable_aslr=
1763 if [ -z "$(gdb -batch -nw -ex 'set disable-randomization off' 2>&1)" ]; then
1764 gdb_disable_aslr='set disable-randomization off'
1765 fi
1766
Gilles Peskine8f073122018-11-27 15:58:47 +01001767 for optimization_flag in -O2 -O3 -Ofast -Os; do
Gilles Peskine55f7c942019-01-09 22:28:21 +01001768 for compiler in clang gcc; do
1769 msg "test: $compiler $optimization_flag, mbedtls_platform_zeroize()"
1770 make programs CC="$compiler" DEBUG=1 CFLAGS="$optimization_flag"
Gilles Peskine4976e822019-01-06 19:52:22 +00001771 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 +01001772 if_build_succeeded grep "The buffer was correctly zeroized" test_zeroize.log
1773 if_build_succeeded not grep -i "error" test_zeroize.log
1774 rm -f test_zeroize.log
1775 make clean
1776 done
Andres Amaya Garcia29673812017-10-25 10:35:51 +01001777 done
Andres Amaya Garciad0d7bf62017-10-25 09:01:31 +01001778
Gilles Peskine4976e822019-01-06 19:52:22 +00001779 unset gdb_disable_aslr
Gilles Peskine8f073122018-11-27 15:58:47 +01001780}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001781
Gilles Peskine8f073122018-11-27 15:58:47 +01001782component_check_python_files () {
1783 msg "Lint: Python scripts"
1784 record_status tests/scripts/check-python-files.sh
1785}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001786
Gilles Peskine8f073122018-11-27 15:58:47 +01001787component_check_generate_test_code () {
1788 msg "uint test: generate_test_code.py"
1789 record_status ./tests/scripts/test_generate_test_code.py
1790}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001791
1792################################################################
1793#### Termination
1794################################################################
1795
Gilles Peskine8f073122018-11-27 15:58:47 +01001796post_report () {
1797 msg "Done, cleaning up"
1798 cleanup
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001799
Gilles Peskine8f073122018-11-27 15:58:47 +01001800 final_report
1801}
1802
1803
1804
1805################################################################
1806#### Run all the things
1807################################################################
1808
Gilles Peskinee48351a2018-11-27 16:06:30 +01001809# Run one component and clean up afterwards.
Gilles Peskine8f073122018-11-27 15:58:47 +01001810run_component () {
Gilles Peskine608953e2019-01-02 18:57:02 +01001811 # Back up the configuration in case the component modifies it.
1812 # The cleanup function will restore it.
1813 cp -p "$CONFIG_H" "$CONFIG_BAK"
Gilles Peskineffcdeff2018-12-04 12:49:28 +01001814 current_component="$1"
Gilles Peskine9004a172019-09-16 15:20:36 +02001815 export MBEDTLS_TEST_CONFIGURATION="$current_component"
Gilles Peskine2ef377d2019-10-07 18:44:21 +02001816
1817 # Unconditionally create a seedfile that's sufficiently long.
1818 # Do this before each component, because a previous component may
1819 # have messed it up or shortened it.
1820 dd if=/dev/urandom of=./tests/seedfile bs=64 count=1
1821
1822 # Run the component code.
Gilles Peskine8f073122018-11-27 15:58:47 +01001823 "$@"
Gilles Peskine2ef377d2019-10-07 18:44:21 +02001824
1825 # Restore the build tree to a clean state.
Gilles Peskinee48351a2018-11-27 16:06:30 +01001826 cleanup
Gilles Peskine8f073122018-11-27 15:58:47 +01001827}
1828
1829# Preliminary setup
1830pre_check_environment
1831pre_initialize_variables
1832pre_parse_command_line "$@"
Gilles Peskine348fb9a2018-11-27 17:04:29 +01001833
Gilles Peskine878cf602019-01-06 20:50:38 +00001834pre_check_git
Andrzej Kurekeb508712019-02-14 07:18:59 -05001835
Gilles Peskine878cf602019-01-06 20:50:38 +00001836build_status=0
1837if [ $KEEP_GOING -eq 1 ]; then
1838 pre_setup_keep_going
Gilles Peskine92525112018-11-27 18:15:35 +01001839else
Gilles Peskine878cf602019-01-06 20:50:38 +00001840 record_status () {
1841 "$@"
1842 }
Gilles Peskine8f073122018-11-27 15:58:47 +01001843fi
Gilles Peskine67ffdaf2019-09-16 15:55:46 +02001844pre_prepare_outcome_file
Gilles Peskine878cf602019-01-06 20:50:38 +00001845pre_print_configuration
1846pre_check_tools
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001847cleanup
1848
Gilles Peskinebeb3a812019-01-06 22:11:25 +00001849# Run the requested tests.
1850for component in $RUN_COMPONENTS; do
1851 run_component "component_$component"
1852done
Gilles Peskine8f073122018-11-27 15:58:47 +01001853
1854# We're done.
Gilles Peskine878cf602019-01-06 20:50:38 +00001855post_report