blob: ae2e11283b121ed01fef1f876ede2a7424da39de [file] [log] [blame]
Andres AG31f9b5b2016-10-04 17:14:38 +01001#! /usr/bin/env sh
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01002
Simon Butcher3ea7f522016-03-07 23:22:10 +00003# all.sh
4#
SimonB2e23c822016-04-16 21:54:39 +01005# This file is part of mbed TLS (https://tls.mbed.org)
6#
Gilles Peskine192c72f2017-12-21 15:59:21 +01007# Copyright (c) 2014-2017, ARM Limited, All Rights Reserved
8
9
10
11################################################################
12#### Documentation
13################################################################
14
Simon Butcher3ea7f522016-03-07 23:22:10 +000015# Purpose
Gilles Peskine192c72f2017-12-21 15:59:21 +010016# -------
Simon Butcher3ea7f522016-03-07 23:22:10 +000017#
SimonB2e23c822016-04-16 21:54:39 +010018# To run all tests possible or available on the platform.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010019#
Gilles Peskine192c72f2017-12-21 15:59:21 +010020# Notes for users
21# ---------------
22#
SimonB2e23c822016-04-16 21:54:39 +010023# Warning: the test is destructive. It includes various build modes and
24# configurations, and can and will arbitrarily change the current CMake
Gilles Peskine192c72f2017-12-21 15:59:21 +010025# configuration. The following files must be committed into git:
26# * include/mbedtls/config.h
27# * Makefile, library/Makefile, programs/Makefile, tests/Makefile
28# After running this script, the CMake cache will be lost and CMake
29# will no longer be initialised.
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +010030#
Gilles Peskine192c72f2017-12-21 15:59:21 +010031# The script assumes the presence of a number of tools:
32# * Basic Unix tools (Windows users note: a Unix-style find must be before
33# the Windows find in the PATH)
34# * Perl
35# * GNU Make
36# * CMake
37# * GCC and Clang (recent enough for using ASan with gcc and MemSan with clang, or valgrind)
Andrzej Kurek05be06c2018-06-28 04:41:50 -040038# * G++
Gilles Peskine192c72f2017-12-21 15:59:21 +010039# * arm-gcc and mingw-gcc
40# * ArmCC 5 and ArmCC 6, unless invoked with --no-armcc
Gilles Peskine192c72f2017-12-21 15:59:21 +010041# * OpenSSL and GnuTLS command line tools, recent enough for the
42# interoperability tests. If they don't support SSLv3 then a legacy
43# version of these tools must be present as well (search for LEGACY
44# below).
45# See the invocation of check_tools below for details.
46#
47# This script must be invoked from the toplevel directory of a git
48# working copy of Mbed TLS.
49#
50# Note that the output is not saved. You may want to run
51# script -c tests/scripts/all.sh
52# or
53# tests/scripts/all.sh >all.log 2>&1
54#
55# Notes for maintainers
56# ---------------------
57#
Gilles Peskine8f073122018-11-27 15:58:47 +010058# The bulk of the code is organized into functions that follow one of the
59# following naming conventions:
60# * pre_XXX: things to do before running the tests, in order.
61# * component_XXX: independent components. They can be run in any order.
Gilles Peskinec70637a2019-01-09 22:29:17 +010062# * component_check_XXX: quick tests that aren't worth parallelizing.
63# * component_build_XXX: build things but don't run them.
64# * component_test_XXX: build and test.
Gilles Peskine878cf602019-01-06 20:50:38 +000065# * support_XXX: if support_XXX exists and returns false then
66# component_XXX is not run by default.
Gilles Peskine8f073122018-11-27 15:58:47 +010067# * post_XXX: things to do after running the tests.
68# * other: miscellaneous support functions.
69#
Gilles Peskinec70637a2019-01-09 22:29:17 +010070# Each component must start by invoking `msg` with a short informative message.
71#
72# The framework performs some cleanup tasks after each component. This
73# means that components can assume that the working directory is in a
74# cleaned-up state, and don't need to perform the cleanup themselves.
75# * Run `make clean`.
76# * Restore `include/mbedtks/config.h` from a backup made before running
77# the component.
78# * Check out `Makefile`, `library/Makefile`, `programs/Makefile` and
79# `tests/Makefile` from git. This cleans up after an in-tree use of
80# CMake.
81#
82# Any command that is expected to fail must be protected so that the
83# script keeps running in --keep-going mode despite `set -e`. In keep-going
84# mode, if a protected command fails, this is logged as a failure and the
85# script will exit with a failure status once it has run all components.
86# Commands can be protected in any of the following ways:
87# * `make` is a function which runs the `make` command with protection.
88# Note that you must write `make VAR=value`, not `VAR=value make`,
89# because the `VAR=value make` syntax doesn't work with functions.
90# * Put `report_status` before the command to protect it.
91# * Put `if_build_successful` before a command. This protects it, and
92# additionally skips it if a prior invocation of `make` in the same
93# component failed.
94#
Gilles Peskine192c72f2017-12-21 15:59:21 +010095# The tests are roughly in order from fastest to slowest. This doesn't
96# have to be exact, but in general you should add slower tests towards
97# the end and fast checks near the beginning.
Gilles Peskine192c72f2017-12-21 15:59:21 +010098
99
100
101################################################################
102#### Initialization and command line parsing
103################################################################
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100104
SimonB2e23c822016-04-16 21:54:39 +0100105# Abort on errors (and uninitialised variables)
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100106set -eu
107
Gilles Peskine8f073122018-11-27 15:58:47 +0100108pre_check_environment () {
Gilles Peskinea16c2b12019-01-06 19:58:02 +0000109 if [ -d library -a -d include -a -d tests ]; then :; else
Gilles Peskine8f073122018-11-27 15:58:47 +0100110 echo "Must be run from mbed TLS root" >&2
111 exit 1
112 fi
113}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100114
Gilles Peskine8f073122018-11-27 15:58:47 +0100115pre_initialize_variables () {
116 CONFIG_H='include/mbedtls/config.h'
117 CONFIG_BAK="$CONFIG_H.bak"
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200118
Gilles Peskine8f073122018-11-27 15:58:47 +0100119 MEMORY=0
120 FORCE=0
121 KEEP_GOING=0
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100122
Antonin Décimod5f47592019-01-23 15:24:37 +0100123 # Default commands, can be overridden by the environment
Gilles Peskine8f073122018-11-27 15:58:47 +0100124 : ${OPENSSL:="openssl"}
125 : ${OPENSSL_LEGACY:="$OPENSSL"}
126 : ${OPENSSL_NEXT:="$OPENSSL"}
127 : ${GNUTLS_CLI:="gnutls-cli"}
128 : ${GNUTLS_SERV:="gnutls-serv"}
129 : ${GNUTLS_LEGACY_CLI:="$GNUTLS_CLI"}
130 : ${GNUTLS_LEGACY_SERV:="$GNUTLS_SERV"}
131 : ${OUT_OF_SOURCE_DIR:=./mbedtls_out_of_source_build}
132 : ${ARMC5_BIN_DIR:=/usr/bin}
133 : ${ARMC6_BIN_DIR:=/usr/bin}
Andres AGdc192212016-08-31 17:33:13 +0100134
Gilles Peskine8f073122018-11-27 15:58:47 +0100135 # if MAKEFLAGS is not set add the -j option to speed up invocations of make
Gilles Peskinea1fc4b52019-01-06 20:15:26 +0000136 if [ -z "${MAKEFLAGS+set}" ]; then
Gilles Peskine8f073122018-11-27 15:58:47 +0100137 export MAKEFLAGS="-j"
138 fi
Gilles Peskine878cf602019-01-06 20:50:38 +0000139
Gilles Peskine3ccb7f12019-10-21 17:11:33 +0200140 # CFLAGS and LDFLAGS for Asan builds that don't use CMake
Gilles Peskine6eec4ab2019-10-21 19:06:33 +0200141 ASAN_CFLAGS='-Werror -Wall -Wextra -fsanitize=address,undefined -fno-sanitize-recover=all'
Gilles Peskine3ccb7f12019-10-21 17:11:33 +0200142
Gilles Peskine878cf602019-01-06 20:50:38 +0000143 # Gather the list of available components. These are the functions
144 # defined in this script whose name starts with "component_".
145 # Parse the script with sed, because in sh there is no way to list
146 # defined functions.
147 ALL_COMPONENTS=$(sed -n 's/^ *component_\([0-9A-Z_a-z]*\) *().*/\1/p' <"$0")
148
149 # Exclude components that are not supported on this platform.
150 SUPPORTED_COMPONENTS=
151 for component in $ALL_COMPONENTS; do
152 case $(type "support_$component" 2>&1) in
153 *' function'*)
154 if ! support_$component; then continue; fi;;
155 esac
156 SUPPORTED_COMPONENTS="$SUPPORTED_COMPONENTS $component"
157 done
Gilles Peskine8f073122018-11-27 15:58:47 +0100158}
Andres AG38495a32016-07-12 16:54:33 +0100159
Gilles Peskinea28db922019-01-10 00:05:18 +0100160# Test whether the component $1 is included in the command line patterns.
161is_component_included()
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100162{
163 set -f
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000164 for pattern in $COMMAND_LINE_COMPONENTS; do
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100165 set +f
166 case ${1#component_} in $pattern) return 0;; esac
167 done
168 set +f
169 return 1
170}
171
Simon Butcher41eeccf2016-09-07 00:07:09 +0100172usage()
SimonB2e23c822016-04-16 21:54:39 +0100173{
Gilles Peskine709346a2017-12-10 23:43:39 +0100174 cat <<EOF
Gilles Peskine92525112018-11-27 18:15:35 +0100175Usage: $0 [OPTION]... [COMPONENT]...
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100176Run mbedtls release validation tests.
Gilles Peskine92525112018-11-27 18:15:35 +0100177By default, run all tests. With one or more COMPONENT, run only those.
Gilles Peskinea28db922019-01-10 00:05:18 +0100178COMPONENT can be the name of a component or a shell wildcard pattern.
179
180Examples:
181 $0 "check_*"
182 Run all sanity checks.
183 $0 --no-armcc --except test_memsan
184 Run everything except builds that require armcc and MemSan.
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100185
186Special options:
187 -h|--help Print this help and exit.
Gilles Peskine878cf602019-01-06 20:50:38 +0000188 --list-all-components List all available test components and exit.
189 --list-components List components supported on this platform and exit.
Gilles Peskine709346a2017-12-10 23:43:39 +0100190
191General options:
192 -f|--force Force the tests to overwrite any modified files.
Gilles Peskine7c652162017-12-11 00:01:40 +0100193 -k|--keep-going Run all tests and report errors at the end.
Gilles Peskine709346a2017-12-10 23:43:39 +0100194 -m|--memory Additional optional memory tests.
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100195 --armcc Run ARM Compiler builds (on by default).
Gilles Peskinea28db922019-01-10 00:05:18 +0100196 --except Exclude the COMPONENTs listed on the command line,
197 instead of running only those.
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100198 --no-armcc Skip ARM Compiler builds.
Gilles Peskine38d81652018-03-21 08:40:26 +0100199 --no-force Refuse to overwrite modified files (default).
200 --no-keep-going Stop at the first error (default).
201 --no-memory No additional memory tests (default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100202 --out-of-source-dir=<path> Directory used for CMake out-of-source build tests.
Gilles Peskine38d81652018-03-21 08:40:26 +0100203 --random-seed Use a random seed value for randomized tests (default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100204 -r|--release-test Run this script in release mode. This fixes the seed value to 1.
205 -s|--seed Integer seed value to use for this test run.
206
207Tool path options:
208 --armc5-bin-dir=<ARMC5_bin_dir_path> ARM Compiler 5 bin directory.
209 --armc6-bin-dir=<ARMC6_bin_dir_path> ARM Compiler 6 bin directory.
210 --gnutls-cli=<GnuTLS_cli_path> GnuTLS client executable to use for most tests.
211 --gnutls-serv=<GnuTLS_serv_path> GnuTLS server executable to use for most tests.
212 --gnutls-legacy-cli=<GnuTLS_cli_path> GnuTLS client executable to use for legacy tests.
213 --gnutls-legacy-serv=<GnuTLS_serv_path> GnuTLS server executable to use for legacy tests.
214 --openssl=<OpenSSL_path> OpenSSL executable to use for most tests.
215 --openssl-legacy=<OpenSSL_path> OpenSSL executable to use for legacy tests e.g. SSLv3.
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100216 --openssl-next=<OpenSSL_path> OpenSSL executable to use for recent things like ARIA
Gilles Peskine709346a2017-12-10 23:43:39 +0100217EOF
SimonB2e23c822016-04-16 21:54:39 +0100218}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100219
220# remove built files as well as the cmake cache/config
221cleanup()
222{
Gilles Peskinea71d64c2018-03-21 12:16:57 +0100223 if [ -n "${MBEDTLS_ROOT_DIR+set}" ]; then
224 cd "$MBEDTLS_ROOT_DIR"
225 fi
226
Gilles Peskine7c652162017-12-11 00:01:40 +0100227 command make clean
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200228
Gilles Peskine31b07e22018-03-21 12:15:06 +0100229 # Remove CMake artefacts
Simon Butcher3ad2efd2018-05-02 14:49:38 +0100230 find . -name .git -prune \
Gilles Peskine31b07e22018-03-21 12:15:06 +0100231 -iname CMakeFiles -exec rm -rf {} \+ -o \
232 \( -iname cmake_install.cmake -o \
233 -iname CTestTestfile.cmake -o \
234 -iname CMakeCache.txt \) -exec rm {} \+
235 # Recover files overwritten by in-tree CMake builds
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000236 rm -f include/Makefile include/mbedtls/Makefile programs/*/Makefile
Paul Bakkerfe0984d2014-06-13 00:13:45 +0200237 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile
238 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200239
240 if [ -f "$CONFIG_BAK" ]; then
241 mv "$CONFIG_BAK" "$CONFIG_H"
242 fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100243}
244
Gilles Peskine7c652162017-12-11 00:01:40 +0100245# Executed on exit. May be redefined depending on command line options.
246final_report () {
247 :
248}
249
250fatal_signal () {
251 cleanup
252 final_report $1
253 trap - $1
254 kill -$1 $$
255}
256
257trap 'fatal_signal HUP' HUP
258trap 'fatal_signal INT' INT
259trap 'fatal_signal TERM' TERM
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200260
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100261msg()
262{
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100263 if [ -n "${current_component:-}" ]; then
264 current_section="${current_component#component_}: $1"
265 else
266 current_section="$1"
267 fi
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100268 echo ""
269 echo "******************************************************************"
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100270 echo "* $current_section "
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000271 printf "* "; date
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100272 echo "******************************************************************"
273}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100274
Gilles Peskine8f073122018-11-27 15:58:47 +0100275armc6_build_test()
276{
277 FLAGS="$1"
Andres AGa5cd9732016-10-17 15:23:10 +0100278
Gilles Peskine8f073122018-11-27 15:58:47 +0100279 msg "build: ARM Compiler 6 ($FLAGS), make"
280 ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \
281 WARNING_CFLAGS='-xc -std=c99' make lib
282 make clean
283}
Andres AGa5cd9732016-10-17 15:23:10 +0100284
Andres AGd9eba4b2016-08-26 14:42:14 +0100285err_msg()
286{
287 echo "$1" >&2
288}
289
290check_tools()
291{
292 for TOOL in "$@"; do
Andres AG98393602017-01-31 17:04:45 +0000293 if ! `type "$TOOL" >/dev/null 2>&1`; then
Andres AGd9eba4b2016-08-26 14:42:14 +0100294 err_msg "$TOOL not found!"
295 exit 1
296 fi
297 done
298}
299
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400300check_headers_in_cpp () {
Peter Kolbus30987072019-02-01 17:19:08 -0600301 ls include/mbedtls | grep "\.h$" >headers.txt
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400302 <programs/test/cpp_dummy_build.cpp sed -n 's/"$//; s!^#include "mbedtls/!!p' |
303 sort |
304 diff headers.txt -
305 rm headers.txt
306}
307
Gilles Peskine8f073122018-11-27 15:58:47 +0100308pre_parse_command_line () {
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000309 COMMAND_LINE_COMPONENTS=
Gilles Peskinea28db922019-01-10 00:05:18 +0100310 all_except=0
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000311 no_armcc=
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000312
Gilles Peskine8f073122018-11-27 15:58:47 +0100313 while [ $# -gt 0 ]; do
Gilles Peskine55f7c942019-01-09 22:28:21 +0100314 case "$1" in
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000315 --armcc) no_armcc=;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100316 --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
317 --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000318 --except) all_except=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100319 --force|-f) FORCE=1;;
320 --gnutls-cli) shift; GNUTLS_CLI="$1";;
321 --gnutls-legacy-cli) shift; GNUTLS_LEGACY_CLI="$1";;
322 --gnutls-legacy-serv) shift; GNUTLS_LEGACY_SERV="$1";;
323 --gnutls-serv) shift; GNUTLS_SERV="$1";;
324 --help|-h) usage; exit;;
325 --keep-going|-k) KEEP_GOING=1;;
Gilles Peskine878cf602019-01-06 20:50:38 +0000326 --list-all-components) printf '%s\n' $ALL_COMPONENTS; exit;;
327 --list-components) printf '%s\n' $SUPPORTED_COMPONENTS; exit;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100328 --memory|-m) MEMORY=1;;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000329 --no-armcc) no_armcc=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100330 --no-force) FORCE=0;;
331 --no-keep-going) KEEP_GOING=0;;
332 --no-memory) MEMORY=0;;
333 --openssl) shift; OPENSSL="$1";;
334 --openssl-legacy) shift; OPENSSL_LEGACY="$1";;
335 --openssl-next) shift; OPENSSL_NEXT="$1";;
336 --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
337 --random-seed) unset SEED;;
338 --release-test|-r) SEED=1;;
339 --seed|-s) shift; SEED="$1";;
340 -*)
341 echo >&2 "Unknown option: $1"
342 echo >&2 "Run $0 --help for usage."
343 exit 120
344 ;;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000345 *) COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS $1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100346 esac
347 shift
Gilles Peskine8f073122018-11-27 15:58:47 +0100348 done
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000349
Gilles Peskinea28db922019-01-10 00:05:18 +0100350 # With no list of components, run everything.
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000351 if [ -z "$COMMAND_LINE_COMPONENTS" ]; then
352 all_except=1
353 fi
354
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000355 # --no-armcc is a legacy option. The modern way is --except '*_armcc*'.
356 # Ignore it if components are listed explicitly on the command line.
Gilles Peskinea28db922019-01-10 00:05:18 +0100357 if [ -n "$no_armcc" ] && [ $all_except -eq 1 ]; then
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000358 COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS *_armcc*"
359 fi
360
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000361 # Build the list of components to run.
Gilles Peskinea28db922019-01-10 00:05:18 +0100362 RUN_COMPONENTS=
363 for component in $SUPPORTED_COMPONENTS; do
364 if is_component_included "$component"; [ $? -eq $all_except ]; then
365 RUN_COMPONENTS="$RUN_COMPONENTS $component"
366 fi
367 done
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000368
369 unset all_except
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000370 unset no_armcc
Gilles Peskine8f073122018-11-27 15:58:47 +0100371}
SimonB2e23c822016-04-16 21:54:39 +0100372
Gilles Peskine8f073122018-11-27 15:58:47 +0100373pre_check_git () {
374 if [ $FORCE -eq 1 ]; then
Gilles Peskine53190e62019-01-09 23:17:35 +0100375 rm -rf "$OUT_OF_SOURCE_DIR"
Gilles Peskine8f073122018-11-27 15:58:47 +0100376 git checkout-index -f -q $CONFIG_H
377 cleanup
378 else
SimonB2e23c822016-04-16 21:54:39 +0100379
Gilles Peskine8f073122018-11-27 15:58:47 +0100380 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
381 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
382 echo "You can either delete this directory manually, or force the test by rerunning"
383 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
384 exit 1
385 fi
386
Gilles Peskined1174cf2019-01-09 22:30:01 +0100387 if ! git diff --quiet include/mbedtls/config.h; then
Gilles Peskine8f073122018-11-27 15:58:47 +0100388 err_msg "Warning - the configuration file 'include/mbedtls/config.h' has been edited. "
389 echo "You can either delete or preserve your work, or force the test by rerunning the"
390 echo "script as: $0 --force"
391 exit 1
392 fi
Andres AGdc192212016-08-31 17:33:13 +0100393 fi
Gilles Peskine8f073122018-11-27 15:58:47 +0100394}
Andres AGdc192212016-08-31 17:33:13 +0100395
Gilles Peskine8f073122018-11-27 15:58:47 +0100396pre_setup_keep_going () {
Gilles Peskine7c652162017-12-11 00:01:40 +0100397 failure_summary=
398 failure_count=0
399 start_red=
400 end_color=
401 if [ -t 1 ]; then
Gilles Peskine9736b9d2018-01-02 21:54:17 +0100402 case "${TERM:-}" in
Gilles Peskine7c652162017-12-11 00:01:40 +0100403 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
404 start_red=$(printf '\033[31m')
405 end_color=$(printf '\033[0m')
406 ;;
407 esac
408 fi
409 record_status () {
410 if "$@"; then
411 last_status=0
412 else
413 last_status=$?
414 text="$current_section: $* -> $last_status"
415 failure_summary="$failure_summary
416$text"
417 failure_count=$((failure_count + 1))
418 echo "${start_red}^^^^$text^^^^${end_color}"
419 fi
420 }
421 make () {
422 case "$*" in
423 *test|*check)
424 if [ $build_status -eq 0 ]; then
425 record_status command make "$@"
426 else
427 echo "(skipped because the build failed)"
428 fi
429 ;;
430 *)
431 record_status command make "$@"
Manuel Pégourié-Gonnard66491e12019-10-22 12:50:13 +0200432 if [ $build_status -eq 0 ]; then
433 build_status=$last_status
434 fi
Gilles Peskine7c652162017-12-11 00:01:40 +0100435 ;;
436 esac
437 }
438 final_report () {
439 if [ $failure_count -gt 0 ]; then
440 echo
441 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
442 echo "${start_red}FAILED: $failure_count${end_color}$failure_summary"
443 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Jaeden Amero7c1258d2018-07-20 16:42:14 +0100444 exit 1
Gilles Peskine7c652162017-12-11 00:01:40 +0100445 elif [ -z "${1-}" ]; then
446 echo "SUCCESS :)"
447 fi
448 if [ -n "${1-}" ]; then
449 echo "Killed by SIG$1."
450 fi
451 }
Gilles Peskine8f073122018-11-27 15:58:47 +0100452}
453
Gilles Peskine7c652162017-12-11 00:01:40 +0100454if_build_succeeded () {
455 if [ $build_status -eq 0 ]; then
456 record_status "$@"
457 fi
458}
459
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200460# to be used instead of ! for commands run with
461# record_status or if_build_succeeded
462not() {
463 ! "$@"
464}
465
Gilles Peskine8f073122018-11-27 15:58:47 +0100466pre_print_configuration () {
467 msg "info: $0 configuration"
468 echo "MEMORY: $MEMORY"
469 echo "FORCE: $FORCE"
470 echo "SEED: ${SEED-"UNSET"}"
471 echo "OPENSSL: $OPENSSL"
472 echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
473 echo "OPENSSL_NEXT: $OPENSSL_NEXT"
474 echo "GNUTLS_CLI: $GNUTLS_CLI"
475 echo "GNUTLS_SERV: $GNUTLS_SERV"
476 echo "GNUTLS_LEGACY_CLI: $GNUTLS_LEGACY_CLI"
477 echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV"
478 echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
479 echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
480}
Andres AG87bb5772016-09-27 15:05:15 +0100481
Gilles Peskine87964262019-01-06 22:40:00 +0000482# Make sure the tools we need are available.
Gilles Peskine8f073122018-11-27 15:58:47 +0100483pre_check_tools () {
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000484 # Build the list of variables to pass to output_env.sh.
485 set env
486
Gilles Peskine87964262019-01-06 22:40:00 +0000487 case " $RUN_COMPONENTS " in
488 # Require OpenSSL and GnuTLS if running any tests (as opposed to
489 # only doing builds). Not all tests run OpenSSL and GnuTLS, but this
490 # is a good enough approximation in practice.
491 *" test_"*)
492 # To avoid setting OpenSSL and GnuTLS for each call to compat.sh
493 # and ssl-opt.sh, we just export the variables they require.
494 export OPENSSL_CMD="$OPENSSL"
495 export GNUTLS_CLI="$GNUTLS_CLI"
496 export GNUTLS_SERV="$GNUTLS_SERV"
497 # Avoid passing --seed flag in every call to ssl-opt.sh
498 if [ -n "${SEED-}" ]; then
499 export SEED
500 fi
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000501 set "$@" OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY"
502 set "$@" GNUTLS_CLI="$GNUTLS_CLI" GNUTLS_SERV="$GNUTLS_SERV"
503 set "$@" GNUTLS_LEGACY_CLI="$GNUTLS_LEGACY_CLI"
504 set "$@" GNUTLS_LEGACY_SERV="$GNUTLS_LEGACY_SERV"
Gilles Peskine87964262019-01-06 22:40:00 +0000505 check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$OPENSSL_NEXT" \
506 "$GNUTLS_CLI" "$GNUTLS_SERV" \
507 "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV"
508 ;;
509 esac
Andres AGd9eba4b2016-08-26 14:42:14 +0100510
Gilles Peskine87964262019-01-06 22:40:00 +0000511 case " $RUN_COMPONENTS " in
512 *_doxygen[_\ ]*) check_tools "doxygen" "dot";;
513 esac
Andres AGb2fdd042016-09-22 14:17:46 +0100514
Gilles Peskine87964262019-01-06 22:40:00 +0000515 case " $RUN_COMPONENTS " in
516 *_arm_none_eabi_gcc[_\ ]*) check_tools "arm-none-eabi-gcc";;
517 esac
Andres AG7770ea82016-10-10 15:46:20 +0100518
Gilles Peskine87964262019-01-06 22:40:00 +0000519 case " $RUN_COMPONENTS " in
520 *_mingw[_\ ]*) check_tools "i686-w64-mingw32-gcc";;
521 esac
522
523 case " $RUN_COMPONENTS " in
524 *" test_zeroize "*) check_tools "gdb";;
525 esac
526
527 case " $RUN_COMPONENTS " in
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000528 *_armcc*)
Gilles Peskine87964262019-01-06 22:40:00 +0000529 ARMC5_CC="$ARMC5_BIN_DIR/armcc"
530 ARMC5_AR="$ARMC5_BIN_DIR/armar"
531 ARMC6_CC="$ARMC6_BIN_DIR/armclang"
532 ARMC6_AR="$ARMC6_BIN_DIR/armar"
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000533 check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC6_CC" "$ARMC6_AR";;
534 esac
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000535
536 msg "info: output_env.sh"
537 case $RUN_COMPONENTS in
538 *_armcc*)
539 set "$@" ARMC5_CC="$ARMC5_CC" ARMC6_CC="$ARMC6_CC" RUN_ARMCC=1;;
540 *) set "$@" RUN_ARMCC=0;;
541 esac
542 "$@" scripts/output_env.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100543}
Gilles Peskine192c72f2017-12-21 15:59:21 +0100544
545
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000546
Gilles Peskine192c72f2017-12-21 15:59:21 +0100547################################################################
548#### Basic checks
549################################################################
Andres AGd9eba4b2016-08-26 14:42:14 +0100550
SimonB2e23c822016-04-16 21:54:39 +0100551#
552# Test Suites to be executed
553#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200554# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100555# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard61bc57a2014-08-14 11:29:06 +0200556# and/or are more likely to fail than others (eg I use Clang most of the
557# time, so start with a GCC build).
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200558# 2. Minimize total running time, by avoiding useless rebuilds
559#
560# Indicative running times are given for reference.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100561
Gilles Peskine8f073122018-11-27 15:58:47 +0100562component_check_recursion () {
563 msg "test: recursion.pl" # < 1s
564 record_status tests/scripts/recursion.pl library/*.c
565}
Manuel Pégourié-Gonnardea29d152014-11-20 17:32:33 +0100566
Gilles Peskine8f073122018-11-27 15:58:47 +0100567component_check_generated_files () {
568 msg "test: freshness of generated source files" # < 1s
569 record_status tests/scripts/check-generated-files.sh
570}
Manuel Pégourié-Gonnardb3b8e432015-02-13 14:52:19 +0000571
Gilles Peskine8f073122018-11-27 15:58:47 +0100572component_check_doxy_blocks () {
573 msg "test: doxygen markup outside doxygen blocks" # < 1s
574 record_status tests/scripts/check-doxy-blocks.pl
575}
Manuel Pégourié-Gonnardd09a6b52015-04-09 17:19:23 +0200576
Gilles Peskine8f073122018-11-27 15:58:47 +0100577component_check_files () {
578 msg "test: check-files.py" # < 1s
Gilles Peskine8f073122018-11-27 15:58:47 +0100579 record_status tests/scripts/check-files.py
580}
Darryl Greena07039c2018-03-13 16:48:16 +0000581
Gilles Peskine8f073122018-11-27 15:58:47 +0100582component_check_names () {
583 msg "test/build: declared and exported names" # < 3s
Gilles Peskine473f2d42019-05-15 17:52:22 +0200584 record_status tests/scripts/check-names.sh -v
Gilles Peskine8f073122018-11-27 15:58:47 +0100585}
Manuel Pégourié-Gonnarda687baf2015-04-09 11:09:03 +0200586
Gilles Peskine8f073122018-11-27 15:58:47 +0100587component_check_doxygen_warnings () {
588 msg "test: doxygen warnings" # ~ 3s
Gilles Peskine8f073122018-11-27 15:58:47 +0100589 record_status tests/scripts/doxygen.sh
590}
Manuel Pégourié-Gonnard1d552e72016-01-04 16:49:09 +0100591
Gilles Peskine192c72f2017-12-21 15:59:21 +0100592
593
594################################################################
595#### Build and test many configurations and targets
596################################################################
597
k-stachowiak11f38e22019-06-04 13:14:58 +0200598component_test_large_ecdsa_key_signature () {
599
600 SMALL_MPI_MAX_SIZE=136 # Small enough to interfere with the EC signatures
601
602 msg "build: cmake + MBEDTLS_MPI_MAX_SIZE=${SMALL_MPI_MAX_SIZE}, gcc, ASan" # ~ 1 min 50s
603 scripts/config.pl set MBEDTLS_MPI_MAX_SIZE $SMALL_MPI_MAX_SIZE
604 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
605 make
606
607 INEVITABLY_PRESENT_FILE=Makefile
608 SIGNATURE_FILE="${INEVITABLY_PRESENT_FILE}.sig" # Warning, this is rm -f'ed below
609
610 msg "test: pk_sign secp521r1_prv.der for MBEDTLS_MPI_MAX_SIZE=${SMALL_MPI_MAX_SIZE} (ASan build)" # ~ 5s
611 if_build_succeeded programs/pkey/pk_sign tests/data_files/secp521r1_prv.der $INEVITABLY_PRESENT_FILE
612 rm -f $SIGNATURE_FILE
613}
614
Gilles Peskine99a33102019-04-08 17:00:15 +0200615component_test_default_out_of_box () {
616 msg "build: make, default config (out-of-box)" # ~1min
617 make
618
619 msg "test: main suites make, default config (out-of-box)" # ~10s
620 make test
621
622 msg "selftest: make, default config (out-of-box)" # ~10s
623 programs/test/selftest
624}
625
Gilles Peskine8f073122018-11-27 15:58:47 +0100626component_test_default_cmake_gcc_asan () {
627 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100628 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
629 make
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100630
Gilles Peskine8f073122018-11-27 15:58:47 +0100631 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
632 make test
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200633
Gilles Peskine8f073122018-11-27 15:58:47 +0100634 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
635 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200636
Gilles Peskine8f073122018-11-27 15:58:47 +0100637 msg "test: compat.sh (ASan build)" # ~ 6 min
638 if_build_succeeded tests/compat.sh
639}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200640
Hanno Beckerf8799e82019-02-26 14:27:09 +0000641component_test_full_cmake_gcc_asan () {
642 msg "build: full config, cmake, gcc, ASan"
643 scripts/config.pl full
644 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
645 make
646
647 msg "test: main suites (inc. selftests) (full config, ASan build)"
648 make test
649
650 msg "test: ssl-opt.sh (full config, ASan build)"
651 if_build_succeeded tests/ssl-opt.sh
652
653 msg "test: compat.sh (full config, ASan build)"
654 if_build_succeeded tests/compat.sh
655}
656
Manuel Pégourié-Gonnarddf59bfc2020-01-02 11:45:12 +0100657component_test_zlib_make() {
658 msg "build: zlib enabled, make"
659 scripts/config.pl set MBEDTLS_ZLIB_SUPPORT
660 make ZLIB=1 CFLAGS='-Werror -O1'
661
662 msg "test: main suites (zlib, make)"
663 make test
664
665 msg "test: ssl-opt.sh (zlib, make)"
666 if_build_succeeded tests/ssl-opt.sh
667}
Manuel Pégourié-Gonnardf0658b12020-01-24 10:17:20 +0100668support_test_zlib_make () {
669 base=support_test_zlib_$$
670 cat <<'EOF' > ${base}.c
671#include "zlib.h"
672int main(void) { return 0; }
673EOF
674 gcc -o ${base}.exe ${base}.c -lz 2>/dev/null
675 ret=$?
676 rm -f ${base}.*
677 return $ret
678}
Manuel Pégourié-Gonnarddf59bfc2020-01-02 11:45:12 +0100679
680component_test_zlib_cmake() {
681 msg "build: zlib enabled, cmake"
682 scripts/config.pl set MBEDTLS_ZLIB_SUPPORT
683 cmake -D ENABLE_ZLIB_SUPPORT=On -D CMAKE_BUILD_TYPE:String=Check .
684 make
685
686 msg "test: main suites (zlib, cmake)"
687 make test
688
689 msg "test: ssl-opt.sh (zlib, cmake)"
690 if_build_succeeded tests/ssl-opt.sh
691}
Manuel Pégourié-Gonnardf0658b12020-01-24 10:17:20 +0100692support_test_zlib_cmake () {
693 support_test_zlib_make "$@"
694}
Manuel Pégourié-Gonnarddf59bfc2020-01-02 11:45:12 +0100695
Gilles Peskine782f4112018-11-27 16:11:09 +0100696component_test_ref_configs () {
697 msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
698 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
699 record_status tests/scripts/test-ref-configs.pl
700}
701
Gilles Peskine8f073122018-11-27 15:58:47 +0100702component_test_sslv3 () {
703 msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100704 scripts/config.pl set MBEDTLS_SSL_PROTO_SSL3
705 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
706 make
Simon Butcher3ea7f522016-03-07 23:22:10 +0000707
Gilles Peskine8f073122018-11-27 15:58:47 +0100708 msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
709 make test
Simon Butcher3ea7f522016-03-07 23:22:10 +0000710
Gilles Peskine8f073122018-11-27 15:58:47 +0100711 msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
712 if_build_succeeded tests/compat.sh -m 'tls1 tls1_1 tls1_2 dtls1 dtls1_2'
713 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
Simon Butcher3ea7f522016-03-07 23:22:10 +0000714
Gilles Peskine8f073122018-11-27 15:58:47 +0100715 msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
716 if_build_succeeded tests/ssl-opt.sh
717}
Simon Butcher3ea7f522016-03-07 23:22:10 +0000718
Hanno Beckerbaac25d2019-07-26 12:22:50 +0100719component_test_dtls_only () {
720 msg "build: Default + DTLS only (ASan build)" # ~ 6 min
721 scripts/config.pl set MBEDTLS_SSL_PROTO_NO_TLS
722 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
723 make
724
725 msg "test: DTLS only - main suites (inc. selftests) (ASan build)" # ~ 50s
726 make test
727
Hanno Beckerfcda6dd2019-09-05 14:49:53 +0100728 msg "test: DTLS only - ssl-opt.sh (ASan build)" # ~ 6 min
Hanno Beckerbaac25d2019-07-26 12:22:50 +0100729 if_build_succeeded tests/ssl-opt.sh
730}
731
Gilles Peskine8f073122018-11-27 15:58:47 +0100732component_test_no_renegotiation () {
733 msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100734 scripts/config.pl unset MBEDTLS_SSL_RENEGOTIATION
735 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
736 make
Hanno Becker134c2ab2017-10-12 15:29:50 +0100737
Gilles Peskine8f073122018-11-27 15:58:47 +0100738 msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
739 make test
Hanno Becker134c2ab2017-10-12 15:29:50 +0100740
Gilles Peskine8f073122018-11-27 15:58:47 +0100741 msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
742 if_build_succeeded tests/ssl-opt.sh
743}
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +0100744
Hanno Beckere562e7d2019-05-10 14:45:37 +0100745component_test_no_pem_no_fs () {
746 msg "build: Default + !MBEDTLS_PEM_PARSE_C + !MBEDTLS_FS_IO (ASan build)"
747 scripts/config.pl unset MBEDTLS_PEM_PARSE_C
748 scripts/config.pl unset MBEDTLS_FS_IO
749 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
750 make
751
752 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - main suites (inc. selftests) (ASan build)" # ~ 50s
753 make test
754
755 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - ssl-opt.sh (ASan build)" # ~ 6 min
756 if_build_succeeded tests/ssl-opt.sh
757}
758
Gilles Peskine8f073122018-11-27 15:58:47 +0100759component_test_rsa_no_crt () {
760 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100761 scripts/config.pl set MBEDTLS_RSA_NO_CRT
762 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
763 make
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100764
Gilles Peskine8f073122018-11-27 15:58:47 +0100765 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
766 make test
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100767
Gilles Peskine8f073122018-11-27 15:58:47 +0100768 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
769 if_build_succeeded tests/ssl-opt.sh -f RSA
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100770
Gilles Peskine8f073122018-11-27 15:58:47 +0100771 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
772 if_build_succeeded tests/compat.sh -t RSA
773}
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100774
Hanno Beckerc973fde2019-08-26 13:35:56 +0100775component_test_no_ctr_drbg () {
776 msg "build: Default + !MBEDTLS_CTR_DRBG_C"
777 scripts/config.pl unset MBEDTLS_CTR_DRBG_C
778 CC=gcc cmake .
779 make
780
781 msg "test: !MBEDTLS_CTR_DRBG_C - ssl-opt.sh" # ~ 5s
782 if_build_succeeded tests/ssl-opt.sh --filter "Default"
783}
784
785component_test_no_ctr_drbg_no_sha512 () {
786 msg "build: Default + !MBEDTLS_CTR_DRBG_C + !MBEDTLS_SHA512_C"
787 scripts/config.pl unset MBEDTLS_CTR_DRBG_C
788 scripts/config.pl unset MBEDTLS_SHA512_C
789 CC=gcc cmake .
790 make
791
792 msg "test: !MBEDTLS_CTR_DRBG_C + !MBEDTLS_SHA512_C - ssl-opt.sh" # ~ 5s
793 if_build_succeeded tests/ssl-opt.sh --filter "Default"
794}
795
Jarno Lamsa0905c3d2019-06-19 14:04:31 +0300796component_test_no_resumption () {
Jarno Lamsa29f2dd02019-06-20 15:31:52 +0300797 msg "build: Default + MBEDTLS_SSL_NO_SESSION_RESUMPTION (ASan build)" # ~ 6 min
Jarno Lamsa0905c3d2019-06-19 14:04:31 +0300798 scripts/config.pl unset MBEDTLS_SSL_SESSION_TICKETS
Jarno Lamsa29f2dd02019-06-20 15:31:52 +0300799 scripts/config.pl set MBEDTLS_SSL_NO_SESSION_CACHE
800 scripts/config.pl set MBEDTLS_SSL_NO_SESSION_RESUMPTION
Jarno Lamsa0905c3d2019-06-19 14:04:31 +0300801 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
802 make
803
Jarno Lamsa29f2dd02019-06-20 15:31:52 +0300804 msg "test: MBEDTLS_SSL_NO_SESSION_RESUMPTION - main suites (inc. selftests) (ASan build)" # ~ 50s
Jarno Lamsa0905c3d2019-06-19 14:04:31 +0300805 make test
806
Jarno Lamsa29f2dd02019-06-20 15:31:52 +0300807 msg "test: MBEDTLS_SSL_NO_SESSION_RESUMPTION - ssl-opt.sh (ASan build)" # ~ 6 min
Jarno Lamsa0905c3d2019-06-19 14:04:31 +0300808 if_build_succeeded tests/ssl-opt.sh
809}
810
Gilles Peskine8f073122018-11-27 15:58:47 +0100811component_test_small_ssl_out_content_len () {
812 msg "build: small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100813 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 16384
814 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
815 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
816 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000817
Gilles Peskine8f073122018-11-27 15:58:47 +0100818 msg "test: small SSL_OUT_CONTENT_LEN - ssl-opt.sh MFL and large packet tests"
819 if_build_succeeded tests/ssl-opt.sh -f "Max fragment\|Large packet"
820}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000821
Gilles Peskine8f073122018-11-27 15:58:47 +0100822component_test_small_ssl_in_content_len () {
823 msg "build: small SSL_IN_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100824 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 4096
825 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 16384
826 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
827 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000828
Gilles Peskine8f073122018-11-27 15:58:47 +0100829 msg "test: small SSL_IN_CONTENT_LEN - ssl-opt.sh MFL tests"
830 if_build_succeeded tests/ssl-opt.sh -f "Max fragment"
831}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000832
Gilles Peskine8f073122018-11-27 15:58:47 +0100833component_test_small_ssl_dtls_max_buffering () {
834 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0"
Gilles Peskine8f073122018-11-27 15:58:47 +0100835 scripts/config.pl set MBEDTLS_SSL_DTLS_MAX_BUFFERING 1000
836 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
837 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100838
Gilles Peskine8f073122018-11-27 15:58:47 +0100839 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0 - ssl-opt.sh specific reordering test"
840 if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer out-of-order hs msg before reassembling next, free buffered msg"
841}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100842
Gilles Peskine8f073122018-11-27 15:58:47 +0100843component_test_small_mbedtls_ssl_dtls_max_buffering () {
844 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1"
Manuel Pégourié-Gonnardf8c355a2019-05-28 10:21:30 +0200845 scripts/config.pl set MBEDTLS_SSL_DTLS_MAX_BUFFERING 190
Gilles Peskine8f073122018-11-27 15:58:47 +0100846 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
847 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100848
Gilles Peskine8f073122018-11-27 15:58:47 +0100849 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1 - ssl-opt.sh specific reordering test"
850 if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer encrypted Finished message, drop for fragmented NewSessionTicket"
851}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100852
Gilles Peskine8f073122018-11-27 15:58:47 +0100853component_test_full_cmake_clang () {
854 msg "build: cmake, full config, clang" # ~ 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100855 scripts/config.pl full
Hanno Becker22cf2552019-05-28 16:45:21 +0100856 CC=clang cmake -D LINK_WITH_PTHREAD=1 -D CMAKE_BUILD_TYPE:String=Check -D ENABLE_TESTING=On .
Gilles Peskine8f073122018-11-27 15:58:47 +0100857 make
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100858
Gilles Peskine8f073122018-11-27 15:58:47 +0100859 msg "test: main suites (full config)" # ~ 5s
860 make test
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200861
Gilles Peskine8f073122018-11-27 15:58:47 +0100862 msg "test: ssl-opt.sh default, ECJPAKE, SSL async (full config)" # ~ 1s
863 if_build_succeeded tests/ssl-opt.sh -f 'Default\|ECJPAKE\|SSL async private'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200864
Andres Amaya Garciaac9c5222019-01-08 21:42:27 +0000865 msg "test: compat.sh RC4, DES, 3DES & NULL (full config)" # ~ 2 min
Andres Amaya Garcia37e0a8c2019-02-19 20:20:57 +0000866 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 +0200867
Gilles Peskine8f073122018-11-27 15:58:47 +0100868 msg "test: compat.sh ARIA + ChachaPoly"
869 if_build_succeeded env OPENSSL_CMD="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
870}
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100871
Hanno Beckerefe13272019-07-03 13:32:01 +0100872component_test_hardcoded_ciphersuite_cmake_clang() {
873 msg "build: cmake, full config + MBEDTLS_SSL_CONF_SINGLE_CIPHERSUITE, clang" # ~ 50s
874 scripts/config.pl full
Hanno Beckerffb45b92019-07-19 15:07:03 +0100875 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE
876 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
Hanno Beckerefe13272019-07-03 13:32:01 +0100877 scripts/config.pl set MBEDTLS_SSL_CONF_SINGLE_CIPHERSUITE MBEDTLS_SUITE_TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8
Hanno Beckerffb45b92019-07-19 15:07:03 +0100878 CC=clang cmake -D LINK_WITH_PTHREAD=1 -D CMAKE_BUILD_TYPE:String=ASanDbg -D ENABLE_TESTING=On .
879 make
880
881 msg "test: main suites (full config + MBEDTLS_SSL_CONF_SINGLE_CIPHERSUITE)" # ~ 5s
882 make test
883
884 msg "test: ssl-opt.sh default (full config + MBEDTLS_SSL_CONF_SINGLE_CIPHERSUITE)" # ~ 5s
885 if_build_succeeded tests/ssl-opt.sh -f '^Default$\|^Default, DTLS$'
886}
887
888component_test_hardcoded_timer_callback_cmake_clang() {
889 msg "build: cmake, full config + MBEDTLS_SSL_CONF_SINGLE_CIPHERSUITE, clang" # ~ 50s
890 scripts/config.pl full
891 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE
892 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
893 scripts/config.pl set MBEDTLS_SSL_CONF_GET_TIMER mbedtls_timing_get_delay
894 scripts/config.pl set MBEDTLS_SSL_CONF_SET_TIMER mbedtls_timing_set_delay
895 CC=clang cmake -D LINK_WITH_PTHREAD=1 -D CMAKE_BUILD_TYPE:String=ASanDbg -D ENABLE_TESTING=On .
Hanno Beckerefe13272019-07-03 13:32:01 +0100896 make
897
898 msg "test: main suites (full config + MBEDTLS_SSL_CONF_SINGLE_CIPHERSUITE)" # ~ 5s
899 make test
900
901 msg "test: ssl-opt.sh default (full config + MBEDTLS_SSL_CONF_SINGLE_CIPHERSUITE)" # ~ 5s
902 if_build_succeeded tests/ssl-opt.sh -f '^Default$\|^Default, DTLS$'
903}
904
Hanno Becker9fb3f1e2019-07-19 16:55:35 +0100905component_test_hardcoded_version_cmake_clang() {
906 msg "build: cmake, full config + hardcoded version, clang" # ~ 50s
907 scripts/config.pl full
908 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE
909 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
910 scripts/config.pl set MBEDTLS_SSL_CONF_MIN_MINOR_VER MBEDTLS_SSL_MINOR_VERSION_3
911 scripts/config.pl set MBEDTLS_SSL_CONF_MAX_MINOR_VER MBEDTLS_SSL_MINOR_VERSION_3
912 scripts/config.pl set MBEDTLS_SSL_CONF_MIN_MAJOR_VER MBEDTLS_SSL_MAJOR_VERSION_3
913 scripts/config.pl set MBEDTLS_SSL_CONF_MAX_MAJOR_VER MBEDTLS_SSL_MAJOR_VERSION_3
914 CC=clang cmake -D LINK_WITH_PTHREAD=1 -D CMAKE_BUILD_TYPE:String=ASanDbg -D ENABLE_TESTING=On .
915 make
916
917 msg "test: main suites (full config + hardcoded version)" # ~ 5s
918 make test
919
920 msg "test: ssl-opt.sh default (full config + hardcoded version)" # ~ 5s
921 if_build_succeeded tests/ssl-opt.sh -f '^Default$\|^Default, DTLS$'
922}
923
Hanno Becker2a0cd5a2019-07-19 17:07:20 +0100924component_test_hardcoded_io_callbacks_cmake_clang() {
925 msg "build: cmake, full config + hardcoded IO callbacks, clang" # ~ 50s
926 scripts/config.pl full
927 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE
928 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
929 scripts/config.pl set MBEDTLS_SSL_CONF_RECV mbedtls_net_recv
930 scripts/config.pl set MBEDTLS_SSL_CONF_SEND mbedtls_net_send
931 scripts/config.pl set MBEDTLS_SSL_CONF_RECV_TIMEOUT mbedtls_net_recv_timeout
932 CC=clang cmake -D LINK_WITH_PTHREAD=1 -D CMAKE_BUILD_TYPE:String=ASanDbg -D ENABLE_TESTING=On .
933 make
934
935 msg "test: main suites (full config + hardcoded IO callbacks)" # ~ 5s
936 make test
937
938 msg "test: ssl-opt.sh default (full config + hardcoded IO callbacks)" # ~ 5s
939 if_build_succeeded tests/ssl-opt.sh -f '^Default$\|^Default, DTLS$'
940}
941
Hanno Becker6dd8e1c2019-07-22 11:04:12 +0100942component_test_hardcoded_misc_options_cmake_clang() {
943 msg "build: cmake, full config + hardcode various SSL config options, clang" # ~ 50s
944 scripts/config.pl full
945 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE
946 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
947 scripts/config.pl set MBEDTLS_SSL_CONF_READ_TIMEOUT 0
948 scripts/config.pl set MBEDTLS_SSL_CONF_HS_TIMEOUT_MIN MBEDTLS_SSL_DTLS_TIMEOUT_DFL_MIN
949 scripts/config.pl set MBEDTLS_SSL_CONF_HS_TIMEOUT_MAX MBEDTLS_SSL_DTLS_TIMEOUT_DFL_MAX
950 scripts/config.pl set MBEDTLS_SSL_CONF_CERT_REQ_CA_LIST MBEDTLS_SSL_CERT_REQ_CA_LIST_ENABLED
951 scripts/config.pl set MBEDTLS_SSL_CONF_ANTI_REPLAY MBEDTLS_SSL_ANTI_REPLAY_ENABLED
952 scripts/config.pl set MBEDTLS_SSL_CONF_BADMAC_LIMIT 0
953 scripts/config.pl set MBEDTLS_SSL_CONF_AUTHMODE MBEDTLS_SSL_VERIFY_REQUIRED
954 scripts/config.pl set MBEDTLS_SSL_CONF_ALLOW_LEGACY_RENEGOTIATION MBEDTLS_SSL_LEGACY_NO_RENEGOTIATION
955 CC=clang cmake -D LINK_WITH_PTHREAD=1 -D CMAKE_BUILD_TYPE:String=ASanDbg -D ENABLE_TESTING=On .
956 make
957
958 msg "test: main suites (full config + hardcode various SSL config options)" # ~ 5s
959 make test
960
961 msg "test: ssl-opt.sh default (full config + hardcode various SSL config options)" # ~ 5s
962 if_build_succeeded tests/ssl-opt.sh -f '^Default$\|^Default, DTLS$'
963}
964
Hanno Beckerfe1bd782019-07-19 17:32:14 +0100965component_test_hardcoded_elliptic_curve_cmake_clang() {
966 msg "build: cmake, full config + hardcode elliptic curve, clang" # ~ 50s
967 scripts/config.pl full
968 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE
969 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
970 scripts/config.pl set MBEDTLS_SSL_CONF_SINGLE_EC
971 scripts/config.pl set MBEDTLS_SSL_CONF_SINGLE_EC_GRP_ID MBEDTLS_ECP_DP_SECP256R1
972 scripts/config.pl set MBEDTLS_SSL_CONF_SINGLE_EC_TLS_ID 23
973 CC=clang cmake -D LINK_WITH_PTHREAD=1 -D CMAKE_BUILD_TYPE:String=ASanDbg -D ENABLE_TESTING=On .
974 make
975
976 msg "test: main suites (full config + hardcode elliptic curve)" # ~ 5s
977 make test
978
979 msg "test: ssl-opt.sh default (full config + hardcode elliptic curve)" # ~ 5s
980 if_build_succeeded tests/ssl-opt.sh -f '^Default$\|^Default, DTLS$'
981}
982
Hanno Beckerc763e9d2019-09-03 12:46:51 +0100983component_test_hardcoded_hash_cmake_clang() {
984 msg "build: cmake, full config + MBEDTLS_MD_SINGLE_HASH, clang" # ~ 50s
985 scripts/config.pl full
986 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
987 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
988 scripts/config.pl unset MBEDTLS_SHA1_C
989 scripts/config.pl unset MBEDTLS_SHA512_C
990 scripts/config.pl set MBEDTLS_SHA256_NO_SHA224
991 scripts/config.pl unset MBEDTLS_MD2_C
992 scripts/config.pl unset MBEDTLS_MD4_C
993 scripts/config.pl unset MBEDTLS_MD5_C
994 scripts/config.pl unset MBEDTLS_RIPEMD160_C
995 scripts/config.pl unset MBEDTLS_SSL_PROTO_SSL3
996 scripts/config.pl unset MBEDTLS_SSL_PROTO_TLS1
997 scripts/config.pl unset MBEDTLS_SSL_PROTO_TLS1_1
998 scripts/config.pl unset MBEDTLS_SSL_CBC_RECORD_SPLITTING
999 scripts/config.pl set MBEDTLS_MD_SINGLE_HASH MBEDTLS_MD_INFO_SHA256
1000
1001 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check -D ENABLE_TESTING=On .
1002 make
1003
1004 msg "test: main suites (full config + MBEDTLS_MD_SINGLE_HASH)" # ~ 5s
1005 make test
1006
Hanno Beckerf2075622019-09-06 11:58:41 +01001007 msg "test: ssl-opt.sh default (full config + MBEDTLS_MD_SINGLE_HASH)" # ~ 5s
Hanno Beckerc763e9d2019-09-03 12:46:51 +01001008 if_build_succeeded tests/ssl-opt.sh -f '^Default$\|^Default, DTLS$'
1009}
1010
Gilles Peskine8f073122018-11-27 15:58:47 +01001011component_build_deprecated () {
1012 msg "build: make, full config + DEPRECATED_WARNING, gcc -O" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +01001013 scripts/config.pl full
1014 scripts/config.pl set MBEDTLS_DEPRECATED_WARNING
1015 # Build with -O -Wextra to catch a maximum of issues.
1016 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra' lib programs
Hanno Becker22cf2552019-05-28 16:45:21 +01001017 make PTHREAD=1 CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
Gilles Peskineb4ef45b2018-03-01 22:23:50 +01001018
Gilles Peskine8f073122018-11-27 15:58:47 +01001019 msg "build: make, full config + DEPRECATED_REMOVED, clang -O" # ~ 30s
1020 # No cleanup, just tweak the configuration and rebuild
1021 make clean
1022 scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
1023 scripts/config.pl set MBEDTLS_DEPRECATED_REMOVED
1024 # Build with -O -Wextra to catch a maximum of issues.
1025 make CC=clang CFLAGS='-O -Werror -Wall -Wextra' lib programs
Hanno Becker22cf2552019-05-28 16:45:21 +01001026 make PTHREAD=1 CC=clang CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
Gilles Peskine8f073122018-11-27 15:58:47 +01001027}
Gilles Peskine0afe6242018-02-21 19:28:12 +01001028
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +02001029
Gilles Peskine8f073122018-11-27 15:58:47 +01001030component_test_depends_curves () {
1031 msg "test/build: curves.pl (gcc)" # ~ 4 min
Gilles Peskine8f073122018-11-27 15:58:47 +01001032 record_status tests/scripts/curves.pl
1033}
Manuel Pégourié-Gonnard1fe6bb92017-06-06 11:36:16 +02001034
Gilles Peskine8f073122018-11-27 15:58:47 +01001035component_test_depends_hashes () {
1036 msg "test/build: depends-hashes.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +01001037 record_status tests/scripts/depends-hashes.pl
1038}
Manuel Pégourié-Gonnard43be6cd2017-06-20 09:53:42 +02001039
Gilles Peskine8f073122018-11-27 15:58:47 +01001040component_test_depends_pkalgs () {
1041 msg "test/build: depends-pkalgs.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +01001042 record_status tests/scripts/depends-pkalgs.pl
1043}
Manuel Pégourié-Gonnard503a5ef2015-10-23 09:04:45 +02001044
Gilles Peskine8f073122018-11-27 15:58:47 +01001045component_build_key_exchanges () {
1046 msg "test/build: key-exchanges (gcc)" # ~ 1 min
Gilles Peskine8f073122018-11-27 15:58:47 +01001047 record_status tests/scripts/key-exchanges.pl
1048}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001049
Gilles Peskine8f073122018-11-27 15:58:47 +01001050component_build_default_make_gcc_and_cxx () {
1051 msg "build: Unix make, -Os (gcc)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +01001052 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Andrzej Kurek991f9fe2018-07-02 09:08:21 -04001053
Gilles Peskine8f073122018-11-27 15:58:47 +01001054 msg "test: verify header list in cpp_dummy_build.cpp"
1055 record_status check_headers_in_cpp
Andrzej Kurek991f9fe2018-07-02 09:08:21 -04001056
Gilles Peskine8f073122018-11-27 15:58:47 +01001057 msg "build: Unix make, incremental g++"
1058 make TEST_CPP=1
1059}
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +00001060
Gilles Peskinedcab2022019-06-12 16:05:50 +02001061component_test_check_params_functionality () {
1062 msg "build+test: MBEDTLS_CHECK_PARAMS functionality"
1063 scripts/config.pl full # includes CHECK_PARAMS
1064 # Make MBEDTLS_PARAM_FAILED call mbedtls_param_failed().
1065 scripts/config.pl unset MBEDTLS_CHECK_PARAMS_ASSERT
Gilles Peskinedcab2022019-06-12 16:05:50 +02001066 # Only build and run tests. Do not build sample programs, because
1067 # they don't have a mbedtls_param_failed() function.
1068 make CC=gcc CFLAGS='-Werror -O1' lib test
1069}
1070
Gilles Peskineb28636b2019-01-02 19:06:24 +01001071component_test_check_params_without_platform () {
1072 msg "build+test: MBEDTLS_CHECK_PARAMS without MBEDTLS_PLATFORM_C"
1073 scripts/config.pl full # includes CHECK_PARAMS
Gilles Peskinedcab2022019-06-12 16:05:50 +02001074 # Keep MBEDTLS_PARAM_FAILED as assert.
Gilles Peskineb28636b2019-01-02 19:06:24 +01001075 scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
1076 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
1077 scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
1078 scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
1079 scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
1080 scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
1081 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
1082 scripts/config.pl unset MBEDTLS_PLATFORM_C
Hanno Becker22cf2552019-05-28 16:45:21 +01001083 make CC=gcc PTHREAD=1 CFLAGS='-Werror -O1' all test
Gilles Peskineb28636b2019-01-02 19:06:24 +01001084}
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +02001085
Gilles Peskineb28636b2019-01-02 19:06:24 +01001086component_test_check_params_silent () {
1087 msg "build+test: MBEDTLS_CHECK_PARAMS with alternative MBEDTLS_PARAM_FAILED()"
1088 scripts/config.pl full # includes CHECK_PARAMS
Gilles Peskinedcab2022019-06-12 16:05:50 +02001089 # Set MBEDTLS_PARAM_FAILED to nothing.
Gilles Peskineb28636b2019-01-02 19:06:24 +01001090 sed -i 's/.*\(#define MBEDTLS_PARAM_FAILED( cond )\).*/\1/' "$CONFIG_H"
Hanno Becker22cf2552019-05-28 16:45:21 +01001091 make CC=gcc PTHREAD=1 CFLAGS='-Werror -O1' all test
Gilles Peskineb28636b2019-01-02 19:06:24 +01001092}
Hanno Becker5175ac62017-09-18 15:36:25 +01001093
Gilles Peskine8f073122018-11-27 15:58:47 +01001094component_test_no_platform () {
1095 # Full configuration build, without platform support, file IO and net sockets.
1096 # This should catch missing mbedtls_printf definitions, and by disabling file
1097 # IO, it should catch missing '#include <stdio.h>'
1098 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +01001099 scripts/config.pl full
1100 scripts/config.pl unset MBEDTLS_PLATFORM_C
1101 scripts/config.pl unset MBEDTLS_NET_C
1102 scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
1103 scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
1104 scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
1105 scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
1106 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
1107 scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
1108 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskine8f073122018-11-27 15:58:47 +01001109 scripts/config.pl unset MBEDTLS_FS_IO
1110 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
1111 # to re-enable platform integration features otherwise disabled in C99 builds
Gilles Peskine06c1e232019-09-20 19:23:10 +02001112 make CC=gcc PTHREAD=1 CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -Os -D_DEFAULT_SOURCE' lib programs
1113 make CC=gcc PTHREAD=1 CFLAGS='-Werror -Wall -Wextra -Os' test
Gilles Peskine8f073122018-11-27 15:58:47 +01001114}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +02001115
Gilles Peskine8f073122018-11-27 15:58:47 +01001116component_build_no_std_function () {
1117 # catch compile bugs in _uninit functions
1118 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +01001119 scripts/config.pl full
1120 scripts/config.pl set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
1121 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskine06c1e232019-09-20 19:23:10 +02001122 make CC=gcc PTHREAD=1 CFLAGS='-Werror -Wall -Wextra -Os'
Gilles Peskine8f073122018-11-27 15:58:47 +01001123}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +02001124
Gilles Peskine8f073122018-11-27 15:58:47 +01001125component_build_no_ssl_srv () {
1126 msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +01001127 scripts/config.pl full
1128 scripts/config.pl unset MBEDTLS_SSL_SRV_C
Gilles Peskine06c1e232019-09-20 19:23:10 +02001129 make CC=gcc PTHREAD=1 CFLAGS='-Werror -Wall -Wextra -O1'
Gilles Peskine8f073122018-11-27 15:58:47 +01001130}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +02001131
Gilles Peskine8f073122018-11-27 15:58:47 +01001132component_build_no_ssl_cli () {
1133 msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +01001134 scripts/config.pl full
1135 scripts/config.pl unset MBEDTLS_SSL_CLI_C
Gilles Peskine06c1e232019-09-20 19:23:10 +02001136 make CC=gcc PTHREAD=1 CFLAGS='-Werror -Wall -Wextra -O1'
Gilles Peskine8f073122018-11-27 15:58:47 +01001137}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001138
Gilles Peskine8f073122018-11-27 15:58:47 +01001139component_build_no_sockets () {
1140 # Note, C99 compliance can also be tested with the sockets support disabled,
1141 # as that requires a POSIX platform (which isn't the same as C99).
1142 msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +01001143 scripts/config.pl full
1144 scripts/config.pl unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
1145 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
Gilles Peskine06c1e232019-09-20 19:23:10 +02001146 make CC=gcc PTHREAD=1 CFLAGS='-Werror -Wall -Wextra -O1 -std=c99 -pedantic' lib
Gilles Peskine8f073122018-11-27 15:58:47 +01001147}
Hanno Becker5175ac62017-09-18 15:36:25 +01001148
Andrzej Kurek1d070822019-09-05 09:27:47 -04001149component_test_memory_buffer_allocator_backtrace () {
1150 msg "build: default config with memory buffer allocator and backtrace enabled"
Hanno Becker74b5e342019-02-26 14:34:13 +00001151 scripts/config.pl set MBEDTLS_MEMORY_BUFFER_ALLOC_C
Andrzej Kurek1d070822019-09-05 09:27:47 -04001152 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
Hanno Becker74b5e342019-02-26 14:34:13 +00001153 scripts/config.pl set MBEDTLS_MEMORY_BACKTRACE
Andrzej Kurek60ebd982019-09-10 02:58:34 -04001154 scripts/config.pl set MBEDTLS_MEMORY_DEBUG
Andrzej Kurek1d070822019-09-05 09:27:47 -04001155 CC=gcc cmake .
1156 make
1157
1158 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C and MBEDTLS_MEMORY_BACKTRACE"
1159 make test
1160}
1161
1162component_test_memory_buffer_allocator () {
1163 msg "build: default config with memory buffer allocator"
1164 scripts/config.pl set MBEDTLS_MEMORY_BUFFER_ALLOC_C
Hanno Beckerd130b982019-06-03 16:35:02 +01001165 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
Hanno Becker74b5e342019-02-26 14:34:13 +00001166 CC=gcc cmake .
1167 make
1168
1169 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C"
1170 make test
1171
1172 msg "test: ssl-opt.sh, MBEDTLS_MEMORY_BUFFER_ALLOC_C"
Andrzej Kurek1f5a5962019-09-05 10:09:37 -04001173 # MBEDTLS_MEMORY_BUFFER_ALLOC is slow. Skip tests that tend to time out.
1174 if_build_succeeded tests/ssl-opt.sh -e '^DTLS proxy'
Hanno Becker74b5e342019-02-26 14:34:13 +00001175}
1176
Gilles Peskine8f073122018-11-27 15:58:47 +01001177component_test_no_max_fragment_length () {
1178 # Run max fragment length tests with MFL disabled
1179 msg "build: default config except MFL extension (ASan build)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +01001180 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
1181 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1182 make
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001183
Gilles Peskine8f073122018-11-27 15:58:47 +01001184 msg "test: ssl-opt.sh, MFL-related tests"
1185 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length"
1186}
Angus Grattonc4dd0732018-04-11 16:28:39 +10001187
Hanno Becker92820a12019-02-19 11:10:48 +00001188component_test_asan_remove_peer_certificate () {
1189 msg "build: default config with MBEDTLS_SSL_KEEP_PEER_CERTIFICATE disabled (ASan build)"
1190 scripts/config.pl unset MBEDTLS_SSL_KEEP_PEER_CERTIFICATE
1191 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1192 make
1193
1194 msg "test: !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
1195 make test
1196
1197 msg "test: ssl-opt.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
1198 if_build_succeeded tests/ssl-opt.sh
1199
1200 msg "test: compat.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
1201 if_build_succeeded tests/compat.sh
1202}
1203
Hanno Beckere256f7c2019-06-07 11:14:53 +01001204component_test_asan_remove_peer_certificate_no_renego () {
1205 msg "build: default config with MBEDTLS_SSL_KEEP_PEER_CERTIFICATE and MBEDTLS_SSL_RENEGOTIATION disabled (ASan build)"
1206 scripts/config.pl unset MBEDTLS_SSL_KEEP_PEER_CERTIFICATE
1207 scripts/config.pl unset MBEDTLS_SSL_RENEGOTIATION
1208 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1209 make
1210
1211 msg "test: !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
1212 make test
1213
1214 msg "test: ssl-opt.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE + !MBEDTLS_SSL_RENEGOTIATION"
1215 if_build_succeeded tests/ssl-opt.sh
1216
1217 msg "test: compat.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE + !MBEDTLS_SSL_RENEGOTIATION"
1218 if_build_succeeded tests/compat.sh
1219}
1220
Hanno Beckerbfabd1d2019-02-28 17:31:54 +00001221component_test_asan_on_demand_parsing_remove_peer_cert () {
1222 msg "build: default config, no peer CRT, on-demand CRT parsing (ASan build)"
1223 scripts/config.pl unset MBEDTLS_SSL_KEEP_PEER_CERTIFICATE
1224 scripts/config.pl set MBEDTLS_X509_ON_DEMAND_PARSING
Hanno Becker7dbf49a2019-03-04 16:30:14 +00001225 scripts/config.pl set MBEDTLS_THREADING_C
1226 scripts/config.pl set MBEDTLS_THREADING_PTHREAD
Hanno Becker22cf2552019-05-28 16:45:21 +01001227 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan -D LINK_WITH_PTHREAD=1 .
Hanno Beckerbfabd1d2019-02-28 17:31:54 +00001228 make
1229
1230 msg "test: !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE, MBEDTLS_X509_ON_DEMAND_PARSING"
1231 make test
1232
1233 msg "test: ssl-opt.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE, MBEDTLS_X509_ON_DEMAND_PARSING"
1234 if_build_succeeded tests/ssl-opt.sh
1235}
1236
Gilles Peskine8f073122018-11-27 15:58:47 +01001237component_test_no_max_fragment_length_small_ssl_out_content_len () {
1238 msg "build: no MFL extension, small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +01001239 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
1240 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 16384
1241 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
1242 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1243 make
Angus Grattonc4dd0732018-04-11 16:28:39 +10001244
Gilles Peskine8f073122018-11-27 15:58:47 +01001245 msg "test: MFL tests (disabled MFL extension case) & large packet tests"
1246 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length\|Large buffer"
1247}
Janos Follath06c54002016-06-09 13:57:40 +01001248
Jaeden Amero2eaf2c72019-06-05 13:32:08 +01001249component_test_when_no_ciphersuites_have_mac () {
1250 msg "build: when no ciphersuites have MAC"
1251 scripts/config.pl unset MBEDTLS_CIPHER_NULL_CIPHER
1252 scripts/config.pl unset MBEDTLS_ARC4_C
1253 scripts/config.pl unset MBEDTLS_CIPHER_MODE_CBC
1254 make
1255
1256 msg "test: !MBEDTLS_SSL_SOME_MODES_USE_MAC"
1257 make test
1258
1259 msg "test ssl-opt.sh: !MBEDTLS_SSL_SOME_MODES_USE_MAC"
Jaeden Amerofa8e6da2019-06-05 14:42:50 +01001260 if_build_succeeded tests/ssl-opt.sh -f 'Default\|EtM' -e 'without EtM'
Jaeden Amero2eaf2c72019-06-05 13:32:08 +01001261}
1262
Gilles Peskine8f073122018-11-27 15:58:47 +01001263component_test_null_entropy () {
1264 msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +01001265 scripts/config.pl set MBEDTLS_TEST_NULL_ENTROPY
1266 scripts/config.pl set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
1267 scripts/config.pl set MBEDTLS_ENTROPY_C
1268 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
1269 scripts/config.pl unset MBEDTLS_ENTROPY_HARDWARE_ALT
1270 scripts/config.pl unset MBEDTLS_HAVEGE_C
Gilles Peskine5fa32a72019-01-06 19:48:30 +00001271 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan -D UNSAFE_BUILD=ON .
Gilles Peskine8f073122018-11-27 15:58:47 +01001272 make
Janos Follath06c54002016-06-09 13:57:40 +01001273
Gilles Peskine8f073122018-11-27 15:58:47 +01001274 msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)"
1275 make test
1276}
Hanno Beckere5fecec2018-10-11 11:02:52 +01001277
Gilles Peskine8f073122018-11-27 15:58:47 +01001278component_test_platform_calloc_macro () {
1279 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +01001280 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
1281 scripts/config.pl set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
1282 scripts/config.pl set MBEDTLS_PLATFORM_FREE_MACRO free
1283 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1284 make
Hanno Beckere5fecec2018-10-11 11:02:52 +01001285
Gilles Peskine8f073122018-11-27 15:58:47 +01001286 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
1287 make test
1288}
Hanno Becker83ebf782017-07-07 12:29:15 +01001289
Gilles Peskine34693b52019-09-17 19:04:38 +02001290component_test_malloc_0_null () {
1291 msg "build: malloc(0) returns NULL (ASan+UBSan build)"
1292 scripts/config.pl full
1293 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
1294 make CC=gcc CFLAGS="'-DMBEDTLS_CONFIG_FILE=\"$PWD/tests/configs/config-wrapper-malloc-0-null.h\"' -O -Werror -Wall -Wextra -fsanitize=address,undefined" LDFLAGS='-fsanitize=address,undefined'
1295
1296 msg "test: malloc(0) returns NULL (ASan+UBSan build)"
1297 make test
1298
1299 msg "selftest: malloc(0) returns NULL (ASan+UBSan build)"
1300 # Just the calloc selftest. "make test" ran the others as part of the
1301 # test suites.
1302 if_build_succeeded programs/test/selftest calloc
1303}
1304
Gilles Peskine8f073122018-11-27 15:58:47 +01001305component_test_aes_fewer_tables () {
1306 msg "build: default config with AES_FEWER_TABLES enabled"
Gilles Peskine8f073122018-11-27 15:58:47 +01001307 scripts/config.pl set MBEDTLS_AES_FEWER_TABLES
1308 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01001309
Gilles Peskine8f073122018-11-27 15:58:47 +01001310 msg "test: AES_FEWER_TABLES"
1311 make test
1312}
Hanno Becker83ebf782017-07-07 12:29:15 +01001313
Gilles Peskine8f073122018-11-27 15:58:47 +01001314component_test_aes_rom_tables () {
1315 msg "build: default config with AES_ROM_TABLES enabled"
Gilles Peskine8f073122018-11-27 15:58:47 +01001316 scripts/config.pl set MBEDTLS_AES_ROM_TABLES
1317 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01001318
Gilles Peskine8f073122018-11-27 15:58:47 +01001319 msg "test: AES_ROM_TABLES"
1320 make test
1321}
Hanno Becker83ebf782017-07-07 12:29:15 +01001322
Arto Kinnunen4ab702b2019-08-30 16:03:15 +03001323component_test_aes_only_128_bit_keys () {
1324 msg "build: default config with AES_ONLY_128_BIT_KEY_LENGTH enabled"
1325 scripts/config.pl set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
1326 scripts/config.pl set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
Arto Kinnunen4c003ca2019-10-21 10:24:05 +03001327 scripts/config.pl unset MBEDTLS_PADLOCK_C
1328
1329 make CC=gcc CFLAGS='-Werror -O1'
Arto Kinnunen4ab702b2019-08-30 16:03:15 +03001330
1331 msg "test: AES_ONLY_128_BIT_KEY_LENGTH"
1332 make test
1333}
1334
Arto Kinnunenc0a8bd42019-10-16 14:23:14 +03001335component_test_aes_only_encrypt () {
1336 msg "build: default config with MBEDTLS_AES_ONLY_ENCRYPT enabled"
1337 scripts/config.pl set MBEDTLS_AES_ONLY_ENCRYPT
Arto Kinnunen0fa65aa2019-10-21 14:43:37 +03001338 make CC=gcc CFLAGS='-Werror -O1'
Arto Kinnunenc0a8bd42019-10-16 14:23:14 +03001339
Arto Kinnunen0fa65aa2019-10-21 14:43:37 +03001340 msg "test: AES_ONLY_ENCRYPT"
Arto Kinnunenc0a8bd42019-10-16 14:23:14 +03001341 make test
1342}
1343
Gilles Peskine8f073122018-11-27 15:58:47 +01001344component_test_aes_fewer_tables_and_rom_tables () {
1345 msg "build: default config with AES_ROM_TABLES and AES_FEWER_TABLES enabled"
Gilles Peskine8f073122018-11-27 15:58:47 +01001346 scripts/config.pl set MBEDTLS_AES_FEWER_TABLES
1347 scripts/config.pl set MBEDTLS_AES_ROM_TABLES
1348 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01001349
Gilles Peskine8f073122018-11-27 15:58:47 +01001350 msg "test: AES_FEWER_TABLES + AES_ROM_TABLES"
1351 make test
1352}
1353
Arto Kinnunen430ac132019-10-14 10:42:28 +03001354component_test_aes_sca_countermeasures () {
1355 msg "build: default config + MBEDTLS_AES_SCA_COUNTERMEASURES + MBEDTLS_ENTROPY_HARDWARE_ALT + !MBEDTLS_AESNI_C"
1356 scripts/config.pl set MBEDTLS_AES_SCA_COUNTERMEASURES
1357 scripts/config.pl set MBEDTLS_ENTROPY_HARDWARE_ALT
1358 scripts/config.pl unset MBEDTLS_AESNI_C
1359
1360 msg "test: AES SCA countermeasures"
1361 make test
1362}
1363
Gilles Peskine8f073122018-11-27 15:58:47 +01001364component_test_make_shared () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001365 msg "build/test: make shared" # ~ 40s
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001366 make SHARED=1 all check
Gilles Peskinedc25c322019-07-03 20:43:32 +02001367 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskine8f073122018-11-27 15:58:47 +01001368}
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +02001369
Gilles Peskine2c47ffc2019-07-03 20:43:05 +02001370component_test_cmake_shared () {
1371 msg "build/test: cmake shared" # ~ 2min
1372 cmake -DUSE_SHARED_MBEDTLS_LIBRARY=On .
1373 make
Gilles Peskinedc25c322019-07-03 20:43:32 +02001374 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskine2c47ffc2019-07-03 20:43:05 +02001375 make test
1376}
1377
Gilles Peskinea4c1c4b2019-09-20 19:56:06 +02001378test_build_opt () {
1379 info=$1 cc=$2; shift 2
1380 for opt in "$@"; do
1381 msg "build/test: $cc $opt, $info" # ~ 30s
1382 make CC="$cc" CFLAGS="$opt -Wall -Wextra -Werror"
1383 # We're confident enough in compilers to not run _all_ the tests,
1384 # but at least run the unit tests. In particular, runs with
1385 # optimizations use inline assembly whereas runs with -O0
1386 # skip inline assembly.
1387 make test # ~30s
1388 make clean
1389 done
1390}
1391
1392component_test_clang_opt () {
1393 scripts/config.pl full
1394 test_build_opt 'full config' clang -O0 -Os -O2
1395}
1396
1397component_test_gcc_opt () {
1398 scripts/config.pl full
1399 test_build_opt 'full config' gcc -O0 -Os -O2
1400}
1401
Gilles Peskine87bf1b52019-07-03 20:42:16 +02001402component_build_mbedtls_config_file () {
1403 msg "build: make with MBEDTLS_CONFIG_FILE" # ~40s
1404 # Use the full config so as to catch a maximum of places where
1405 # the check of MBEDTLS_CONFIG_FILE might be missing.
1406 scripts/config.pl full
1407 sed 's!"check_config.h"!"mbedtls/check_config.h"!' <"$CONFIG_H" >full_config.h
1408 echo '#error "MBEDTLS_CONFIG_FILE is not working"' >"$CONFIG_H"
1409 make CFLAGS="-I '$PWD' -DMBEDTLS_CONFIG_FILE='\"full_config.h\"'"
1410 rm -f full_config.h
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001411}
1412
Gilles Peskine8f073122018-11-27 15:58:47 +01001413component_test_m32_o0 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001414 # Build once with -O0, to compile out the i386 specific inline assembly
1415 msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
Simon Butcher7a6da6e2018-06-27 21:52:54 +01001416 scripts/config.pl full
Gilles Peskine3ccb7f12019-10-21 17:11:33 +02001417 make CC=gcc PTHREAD=1 CFLAGS="$ASAN_CFLAGS -m32 -O0" LDFLAGS="-m32 $ASAN_CFLAGS"
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01001418
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001419 msg "test: i386, make, gcc -O0 (ASan build)"
1420 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01001421}
Gilles Peskine878cf602019-01-06 20:50:38 +00001422support_test_m32_o0 () {
1423 case $(uname -m) in
1424 *64*) true;;
1425 *) false;;
1426 esac
1427}
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001428
Gilles Peskine8f073122018-11-27 15:58:47 +01001429component_test_m32_o1 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001430 # Build again with -O1, to compile in the i386 specific inline assembly
1431 msg "build: i386, make, gcc -O1 (ASan build)" # ~ 30s
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001432 scripts/config.pl full
Gilles Peskine3ccb7f12019-10-21 17:11:33 +02001433 make CC=gcc PTHREAD=1 CFLAGS="$ASAN_CFLAGS -m32 -O1" LDFLAGS="-m32 $ASAN_CFLAGS"
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001434
1435 msg "test: i386, make, gcc -O1 (ASan build)"
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001436 make test
Gilles Peskine7dd44b22019-04-08 16:58:02 +02001437
1438 msg "test ssl-opt.sh, i386, make, gcc-O1"
1439 if_build_succeeded tests/ssl-opt.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01001440}
Gilles Peskine878cf602019-01-06 20:50:38 +00001441support_test_m32_o1 () {
1442 support_test_m32_o0 "$@"
1443}
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001444
Gilles Peskine8f073122018-11-27 15:58:47 +01001445component_test_mx32 () {
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001446 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
Simon Butcher7a6da6e2018-06-27 21:52:54 +01001447 scripts/config.pl full
Manuel Pégourié-Gonnardde8869c2019-07-03 10:31:46 +02001448 make CC=gcc PTHREAD=1 CFLAGS='-Werror -Wall -Wextra -mx32' LDFLAGS='-mx32'
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001449
1450 msg "test: 64-bit ILP32, make, gcc"
1451 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01001452}
Gilles Peskine878cf602019-01-06 20:50:38 +00001453support_test_mx32 () {
1454 case $(uname -m) in
1455 amd64|x86_64) true;;
1456 *) false;;
1457 esac
1458}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001459
Peter Kolbus1e2aa722018-12-27 06:59:04 -06001460component_test_min_mpi_window_size () {
1461 msg "build: Default + MBEDTLS_MPI_WINDOW_SIZE=1 (ASan build)" # ~ 10s
1462 scripts/config.pl set MBEDTLS_MPI_WINDOW_SIZE 1
1463 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1464 make
1465
1466 msg "test: MBEDTLS_MPI_WINDOW_SIZE=1 - main suites (inc. selftests) (ASan build)" # ~ 10s
1467 make test
1468}
1469
Gilles Peskine8f073122018-11-27 15:58:47 +01001470component_test_have_int32 () {
1471 msg "build: gcc, force 32-bit bignum limbs"
Gilles Peskine8f073122018-11-27 15:58:47 +01001472 scripts/config.pl unset MBEDTLS_HAVE_ASM
1473 scripts/config.pl unset MBEDTLS_AESNI_C
1474 scripts/config.pl unset MBEDTLS_PADLOCK_C
1475 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01001476
Gilles Peskine8f073122018-11-27 15:58:47 +01001477 msg "test: gcc, force 32-bit bignum limbs"
1478 make test
1479}
Andres Amaya Garciafe843a32017-07-20 13:21:34 +01001480
Gilles Peskine8f073122018-11-27 15:58:47 +01001481component_test_have_int64 () {
1482 msg "build: gcc, force 64-bit bignum limbs"
Gilles Peskine8f073122018-11-27 15:58:47 +01001483 scripts/config.pl unset MBEDTLS_HAVE_ASM
1484 scripts/config.pl unset MBEDTLS_AESNI_C
1485 scripts/config.pl unset MBEDTLS_PADLOCK_C
1486 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
Gilles Peskine14c3c062018-01-29 21:25:12 +01001487
Gilles Peskine8f073122018-11-27 15:58:47 +01001488 msg "test: gcc, force 64-bit bignum limbs"
1489 make test
1490}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001491
Gilles Peskine8f073122018-11-27 15:58:47 +01001492component_test_no_udbl_division () {
1493 msg "build: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +01001494 scripts/config.pl full
Gilles Peskine8f073122018-11-27 15:58:47 +01001495 scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
1496 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001497
Gilles Peskine8f073122018-11-27 15:58:47 +01001498 msg "test: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
1499 make test
1500}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001501
Gilles Peskine8f073122018-11-27 15:58:47 +01001502component_test_no_64bit_multiplication () {
1503 msg "build: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +01001504 scripts/config.pl full
Gilles Peskine8f073122018-11-27 15:58:47 +01001505 scripts/config.pl set MBEDTLS_NO_64BIT_MULTIPLICATION
1506 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001507
Gilles Peskine8f073122018-11-27 15:58:47 +01001508 msg "test: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
1509 make test
1510}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001511
Peter Kolbusb1cb0bd2019-01-29 17:42:02 -06001512component_test_no_x509_info () {
1513 msg "build: full + MBEDTLS_X509_REMOVE_INFO" # ~ 10s
1514 scripts/config.pl full
1515 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
1516 scripts/config.pl set MBEDTLS_X509_REMOVE_INFO
1517 make CFLAGS='-Werror -O1'
1518
1519 msg "test: full + MBEDTLS_X509_REMOVE_INFO" # ~ 10s
1520 make test
1521
1522 msg "test: ssl-opt.sh, full + MBEDTLS_X509_REMOVE_INFO" # ~ 1 min
1523 if_build_succeeded tests/ssl-opt.sh
1524}
1525
Teppo Järvelin4009d8f2019-08-19 14:48:09 +03001526component_test_no_hostname_verification () {
1527 msg "build: full + MBEDTLS_X509_REMOVE_HOSTNAME_VERIFICATION" # ~ 10s
1528 scripts/config.pl full
1529 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
1530 scripts/config.pl set MBEDTLS_X509_REMOVE_HOSTNAME_VERIFICATION
1531 make CFLAGS='-Werror -O1'
1532
1533 msg "test: full + MBEDTLS_X509_REMOVE_HOSTNAME_VERIFICATION" # ~ 10s
1534 make test
1535
1536 msg "test: ssl-opt.sh, full + MBEDTLS_X509_REMOVE_HOSTNAME_VERIFICATION" # ~ 1 min
1537 if_build_succeeded tests/ssl-opt.sh
1538}
1539
Hanno Becker9ec3fe02019-07-01 17:36:12 +01001540component_test_no_x509_verify_callback () {
1541 msg "build: full + MBEDTLS_X509_REMOVE_VERIFY_CALLBACK" # ~ 10s
1542 scripts/config.pl full
1543 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
1544 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
1545 scripts/config.pl set MBEDTLS_X509_REMOVE_VERIFY_CALLBACK
1546 make CFLAGS='-Werror -O1'
1547
1548 msg "test: full + MBEDTLS_X509_REMOVE_VERIFY_CALLBACK" # ~ 10s
1549 make test
1550
1551 msg "test: ssl-opt.sh, full + MBEDTLS_X509_REMOVE_VERIFY_CALLBACK" # ~ 1 min
1552 if_build_succeeded tests/ssl-opt.sh
1553}
1554
Gilles Peskine8f073122018-11-27 15:58:47 +01001555component_build_arm_none_eabi_gcc () {
1556 msg "build: arm-none-eabi-gcc, make" # ~ 10s
Manuel Pégourié-Gonnard6e6ae9b2019-04-29 12:44:12 +02001557 scripts/config.pl baremetal
Gilles Peskine8f073122018-11-27 15:58:47 +01001558 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
1559}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001560
Gilles Peskine560f3322019-08-09 16:05:05 +02001561component_build_arm_none_eabi_gcc_arm5vte () {
Gilles Peskinee07b9ff2019-08-08 16:09:02 +02001562 msg "build: arm-none-eabi-gcc -march=arm5vte, make" # ~ 10s
Gilles Peskine0bd284d2019-08-05 11:34:25 +02001563 scripts/config.pl baremetal
Gilles Peskine560f3322019-08-09 16:05:05 +02001564 # Build for a target platform that's close to what Debian uses
1565 # for its "armel" distribution (https://wiki.debian.org/ArmEabiPort).
1566 # See https://github.com/ARMmbed/mbedtls/pull/2169 and comments.
1567 # It would be better to build with arm-linux-gnueabi-gcc but
1568 # we don't have that on our CI at this time.
Gilles Peskinee07b9ff2019-08-08 16:09:02 +02001569 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 Peskine0bd284d2019-08-05 11:34:25 +02001570}
1571
Gilles Peskine8f073122018-11-27 15:58:47 +01001572component_build_arm_none_eabi_gcc_no_udbl_division () {
1573 msg "build: arm-none-eabi-gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
Manuel Pégourié-Gonnard6e6ae9b2019-04-29 12:44:12 +02001574 scripts/config.pl baremetal
Gilles Peskine8f073122018-11-27 15:58:47 +01001575 scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
1576 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
1577 echo "Checking that software 64-bit division is not required"
1578 if_build_succeeded not grep __aeabi_uldiv library/*.o
1579}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001580
Gilles Peskine8f073122018-11-27 15:58:47 +01001581component_build_arm_none_eabi_gcc_no_64bit_multiplication () {
1582 msg "build: arm-none-eabi-gcc MBEDTLS_NO_64BIT_MULTIPLICATION, make" # ~ 10s
Manuel Pégourié-Gonnard6e6ae9b2019-04-29 12:44:12 +02001583 scripts/config.pl baremetal
Gilles Peskine8f073122018-11-27 15:58:47 +01001584 scripts/config.pl set MBEDTLS_NO_64BIT_MULTIPLICATION
Simon Butcher96998872019-11-22 15:09:39 +00001585 make TINYCRYPT_BUILD=0 CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -O1 -march=armv6-m -mthumb' lib
Gilles Peskine8f073122018-11-27 15:58:47 +01001586 echo "Checking that software 64-bit multiplication is not required"
1587 if_build_succeeded not grep __aeabi_lmul library/*.o
1588}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001589
Gilles Peskine8f073122018-11-27 15:58:47 +01001590component_build_armcc () {
1591 msg "build: ARM Compiler 5, make"
Manuel Pégourié-Gonnard6e6ae9b2019-04-29 12:44:12 +02001592 scripts/config.pl baremetal
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001593
Gilles Peskine5331c6e2019-01-06 22:23:42 +00001594 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
1595 make clean
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001596
Gilles Peskine5331c6e2019-01-06 22:23:42 +00001597 # ARM Compiler 6 - Target ARMv7-A
1598 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-a"
Gilles Peskineed942f82017-06-08 15:19:20 +02001599
Gilles Peskine5331c6e2019-01-06 22:23:42 +00001600 # ARM Compiler 6 - Target ARMv7-M
1601 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m"
Andres AG87bb5772016-09-27 15:05:15 +01001602
Gilles Peskine5331c6e2019-01-06 22:23:42 +00001603 # ARM Compiler 6 - Target ARMv8-A - AArch32
1604 armc6_build_test "--target=arm-arm-none-eabi -march=armv8.2-a"
Andres AG87bb5772016-09-27 15:05:15 +01001605
Gilles Peskine5331c6e2019-01-06 22:23:42 +00001606 # ARM Compiler 6 - Target ARMv8-M
1607 armc6_build_test "--target=arm-arm-none-eabi -march=armv8-m.main"
Simon Butcher940737f2017-07-23 13:42:36 +02001608
Gilles Peskine5331c6e2019-01-06 22:23:42 +00001609 # ARM Compiler 6 - Target ARMv8-A - AArch64
1610 armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a"
Gilles Peskine8f073122018-11-27 15:58:47 +01001611}
Simon Butcher940737f2017-07-23 13:42:36 +02001612
Manuel Pégourié-Gonnard31ae7fa2019-06-18 12:03:51 +02001613# need _armcc in the name for pre_check_tools()
Hanno Becker62daad32019-07-25 12:41:40 +01001614component_build_baremetal_raw_armcc () {
Manuel Pégourié-Gonnard31ae7fa2019-06-18 12:03:51 +02001615 msg "build: scripts/baremetal.sh gcc/armc5/armc6"
1616 scripts/baremetal.sh --rom --gcc --armc5 --armc6 --check
1617}
1618
Hanno Beckerb1074972019-09-02 12:27:03 +01001619component_test_default_tinycrypt_without_legacy_ecc () {
1620 msg "test default config with tinycrypt enabled and legacy ECC disabled"
Jarno Lamsa7ba62882019-08-02 11:45:44 +03001621
1622 scripts/config.pl set MBEDTLS_USE_TINYCRYPT
1623 scripts/config.pl set MBEDTLS_SSL_CONF_RNG rng_wrap
1624 scripts/config.pl set MBEDTLS_SSL_CONF_SINGLE_EC
1625 scripts/config.pl set MBEDTLS_SSL_CONF_SINGLE_EC_TLS_ID 23
Hanno Becker49ac40b2019-08-29 16:25:49 +01001626 scripts/config.pl set MBEDTLS_SSL_CONF_SINGLE_UECC_GRP_ID MBEDTLS_UECC_DP_SECP256R1
Hanno Beckerb1074972019-09-02 12:27:03 +01001627 scripts/config.pl unset MBEDTLS_ECP_C
Jarno Lamsa7ba62882019-08-02 11:45:44 +03001628 scripts/config.pl unset MBEDTLS_ECDH_C
Hanno Beckerb1074972019-09-02 12:27:03 +01001629 scripts/config.pl unset MBEDTLS_ECDSA_C
Jarno Lamsa7ba62882019-08-02 11:45:44 +03001630 scripts/config.pl unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
1631 scripts/config.pl unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
1632 scripts/config.pl unset MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
Hanno Becker325eb332019-09-02 13:47:19 +01001633 scripts/config.pl unset MBEDTLS_ECP_DP_SECP192R1_ENABLED
1634 scripts/config.pl unset MBEDTLS_ECP_DP_SECP224R1_ENABLED
1635 scripts/config.pl unset MBEDTLS_ECP_DP_SECP256R1_ENABLED
1636 scripts/config.pl unset MBEDTLS_ECP_DP_SECP384R1_ENABLED
1637 scripts/config.pl unset MBEDTLS_ECP_DP_SECP521R1_ENABLED
1638 scripts/config.pl unset MBEDTLS_ECP_DP_BP256R1_ENABLED
1639 scripts/config.pl unset MBEDTLS_ECP_DP_BP384R1_ENABLED
1640 scripts/config.pl unset MBEDTLS_ECP_DP_BP512R1_ENABLED
1641 scripts/config.pl unset MBEDTLS_ECP_DP_SECP192K1_ENABLED
1642 scripts/config.pl unset MBEDTLS_ECP_DP_SECP224K1_ENABLED
1643 scripts/config.pl unset MBEDTLS_ECP_DP_SECP256K1_ENABLED
Jarno Lamsa7ba62882019-08-02 11:45:44 +03001644 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
1645
Hanno Beckerb1074972019-09-02 12:27:03 +01001646 msg "test: default config with tinycrypt enabled and legacy ECC disabled"
Jarno Lamsa7ba62882019-08-02 11:45:44 +03001647 make test
Hanno Becker8b3408f2019-09-02 14:35:23 +01001648 if_build_succeeded tests/ssl-opt.sh
Hanno Becker7c2cd3e2019-09-02 09:15:23 +01001649
1650 export SRV_ECDSA_CRT=data_files/server11.crt.pem
1651 export SRV_ECDSA_KEY=data_files/server11.key.pem
1652 export CLI_ECDSA_CRT=data_files/cli3.crt.pem
1653 export CLI_ECDSA_KEY=data_files/cli3.key.pem
1654 export CA_FILE=data_files/test-ca3.crt.pem
Hanno Beckerfe088442019-09-02 13:07:20 +01001655 if_build_succeeded tests/compat.sh -f 'ECDHE-ECDSA\|ECDHE-PSK\|ECDH-ECDSA'
Jarno Lamsa7ba62882019-08-02 11:45:44 +03001656}
1657
Manuel Pégourié-Gonnard1c1cc0d2019-09-19 10:45:14 +02001658component_test_hardcoded_pk_type () {
1659 msg "build: default config + single PK type harcoded (tinycrypt)"
1660 # need to enable tinycrypt first - copied from tinycrypt component
1661 scripts/config.pl set MBEDTLS_USE_TINYCRYPT
1662 scripts/config.pl set MBEDTLS_SSL_CONF_RNG rng_wrap
1663 scripts/config.pl set MBEDTLS_SSL_CONF_SINGLE_EC
1664 scripts/config.pl set MBEDTLS_SSL_CONF_SINGLE_EC_TLS_ID 23
1665 scripts/config.pl set MBEDTLS_SSL_CONF_SINGLE_UECC_GRP_ID MBEDTLS_UECC_DP_SECP256R1
1666 scripts/config.pl unset MBEDTLS_ECP_C
1667 scripts/config.pl unset MBEDTLS_ECDH_C
1668 scripts/config.pl unset MBEDTLS_ECDSA_C
1669 scripts/config.pl unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
1670 scripts/config.pl unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
1671 scripts/config.pl unset MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
1672 scripts/config.pl unset MBEDTLS_ECP_DP_SECP192R1_ENABLED
1673 scripts/config.pl unset MBEDTLS_ECP_DP_SECP224R1_ENABLED
1674 scripts/config.pl unset MBEDTLS_ECP_DP_SECP256R1_ENABLED
1675 scripts/config.pl unset MBEDTLS_ECP_DP_SECP384R1_ENABLED
1676 scripts/config.pl unset MBEDTLS_ECP_DP_SECP521R1_ENABLED
1677 scripts/config.pl unset MBEDTLS_ECP_DP_BP256R1_ENABLED
1678 scripts/config.pl unset MBEDTLS_ECP_DP_BP384R1_ENABLED
1679 scripts/config.pl unset MBEDTLS_ECP_DP_BP512R1_ENABLED
1680 scripts/config.pl unset MBEDTLS_ECP_DP_SECP192K1_ENABLED
1681 scripts/config.pl unset MBEDTLS_ECP_DP_SECP224K1_ENABLED
1682 scripts/config.pl unset MBEDTLS_ECP_DP_SECP256K1_ENABLED
1683 # now single-PK specific configs
1684 scripts/config.pl set MBEDTLS_PK_SINGLE_TYPE MBEDTLS_PK_INFO_ECKEY
1685 scripts/config.pl unset MBEDTLS_PK_RSA_ALT_SUPPORT
1686 scripts/config.pl unset MBEDTLS_RSA_C
1687 scripts/config.pl unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
1688 scripts/config.pl unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
1689 scripts/config.pl unset MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
1690 scripts/config.pl unset MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
1691 scripts/config.pl unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
1692 make CFLAGS='-Werror -O1'
1693
1694 msg "test: default config + single PK type harcoded (tinycrypt)"
1695 make test
1696 if_build_succeeded tests/ssl-opt.sh -f '^Default, DTLS$'
1697}
1698
Hanno Becker62daad32019-07-25 12:41:40 +01001699component_test_baremetal () {
Hanno Beckere7895aa2019-07-22 12:47:20 +01001700 msg "build: lib+test+programs for baremetal.h + baremetal_test.h"
1701 record_status scripts/baremetal.sh --ram --build-only
1702
1703 msg "test: baremetal.h + baremetal_test.h"
1704 if_build_succeeded make test
Jarno Lamsa08d6cf22019-10-18 11:49:52 +03001705 if_build_succeeded tests/ssl-opt.sh
Hanno Beckere7895aa2019-07-22 12:47:20 +01001706}
1707
Jarno Lamsa990135e2019-10-04 13:09:10 +03001708component_test_hardware_entropy () {
1709 msg "build: default config + MBEDTLS_ENTROPY_HARDWARE_ALT"
1710 scripts/config.pl set MBEDTLS_ENTROPY_HARDWARE_ALT
Manuel Pégourié-Gonnard66491e12019-10-22 12:50:13 +02001711 make CFLAGS='-Werror -O1' lib tests
1712 make CFLAGS='-Werror -O1' -C programs ssl/ssl_server2 ssl/ssl_client2 test/udp_proxy
Jarno Lamsa990135e2019-10-04 13:09:10 +03001713
1714 msg "test: default config + MBEDTLS_ENTROPY_HARDWARE_ALT"
1715 if_build_succeeded make test
1716 if_build_succeeded tests/ssl-opt.sh --filter "^Default, DTLS$"
1717}
1718
Gilles Peskine8f073122018-11-27 15:58:47 +01001719component_test_allow_sha1 () {
1720 msg "build: allow SHA1 in certificates by default"
Gilles Peskine8f073122018-11-27 15:58:47 +01001721 scripts/config.pl set MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
1722 make CFLAGS='-Werror -Wall -Wextra'
1723 msg "test: allow SHA1 in certificates by default"
1724 make test
1725 if_build_succeeded tests/ssl-opt.sh -f SHA-1
1726}
Simon Butcher940737f2017-07-23 13:42:36 +02001727
Gilles Peskine8f073122018-11-27 15:58:47 +01001728component_build_mingw () {
1729 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +01001730 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -Wall -Wextra' WINDOWS_BUILD=1 lib programs
Gilles Peskine2a458da2017-05-12 15:26:58 +02001731
Gilles Peskine8f073122018-11-27 15:58:47 +01001732 # note Make tests only builds the tests, but doesn't run them
1733 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror' WINDOWS_BUILD=1 tests
1734 make WINDOWS_BUILD=1 clean
Hanno Beckere963efa2018-01-03 10:03:43 +00001735
Gilles Peskine8f073122018-11-27 15:58:47 +01001736 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
1737 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
1738 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
1739 make WINDOWS_BUILD=1 clean
1740}
Simon Butcher002bc622016-11-17 09:27:45 +00001741
Gilles Peskine8f073122018-11-27 15:58:47 +01001742component_test_memsan () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001743 msg "build: MSan (clang)" # ~ 1 min 20s
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001744 scripts/config.pl unset MBEDTLS_AESNI_C # memsan doesn't grok asm
1745 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
1746 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +02001747
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001748 msg "test: main suites (MSan)" # ~ 10s
1749 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001750
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001751 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
Gilles Peskine7c652162017-12-11 00:01:40 +01001752 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001753
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001754 # Optional part(s)
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001755
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001756 if [ "$MEMORY" -gt 0 ]; then
1757 msg "test: compat.sh (MSan)" # ~ 6 min 20s
Gilles Peskine7c652162017-12-11 00:01:40 +01001758 if_build_succeeded tests/compat.sh
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001759 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001760}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001761
Gilles Peskine69f190e2019-01-10 00:11:42 +01001762component_test_valgrind () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001763 msg "build: Release (clang)"
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001764 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
1765 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001766
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001767 msg "test: main suites valgrind (Release)"
1768 make memcheck
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001769
Gilles Peskine0a47c4f2019-04-08 17:00:56 +02001770 # Optional parts (slow; currently broken on OS X because programs don't
1771 # seem to receive signals under valgrind on OS X).
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001772 if [ "$MEMORY" -gt 0 ]; then
1773 msg "test: ssl-opt.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +01001774 if_build_succeeded tests/ssl-opt.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001775 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001776
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001777 if [ "$MEMORY" -gt 1 ]; then
1778 msg "test: compat.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +01001779 if_build_succeeded tests/compat.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001780 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001781}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001782
Gilles Peskine8f073122018-11-27 15:58:47 +01001783component_test_cmake_out_of_source () {
1784 msg "build: cmake 'out-of-source' build"
Gilles Peskine8f073122018-11-27 15:58:47 +01001785 MBEDTLS_ROOT_DIR="$PWD"
1786 mkdir "$OUT_OF_SOURCE_DIR"
1787 cd "$OUT_OF_SOURCE_DIR"
1788 cmake "$MBEDTLS_ROOT_DIR"
1789 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001790
Gilles Peskine8f073122018-11-27 15:58:47 +01001791 msg "test: cmake 'out-of-source' build"
1792 make test
1793 # Test an SSL option that requires an auxiliary script in test/scripts/.
1794 # Also ensure that there are no error messages such as
1795 # "No such file or directory", which would indicate that some required
1796 # file is missing (ssl-opt.sh tolerates the absence of some files so
1797 # may exit with status 0 but emit errors).
1798 if_build_succeeded ./tests/ssl-opt.sh -f 'Fallback SCSV: beginning of list' 2>ssl-opt.err
1799 if [ -s ssl-opt.err ]; then
1800 cat ssl-opt.err >&2
1801 record_status [ ! -s ssl-opt.err ]
1802 rm ssl-opt.err
1803 fi
1804 cd "$MBEDTLS_ROOT_DIR"
1805 rm -rf "$OUT_OF_SOURCE_DIR"
1806 unset MBEDTLS_ROOT_DIR
1807}
Andres AGdc192212016-08-31 17:33:13 +01001808
Gilles Peskine8f073122018-11-27 15:58:47 +01001809component_test_zeroize () {
1810 # Test that the function mbedtls_platform_zeroize() is not optimized away by
1811 # different combinations of compilers and optimization flags by using an
1812 # auxiliary GDB script. Unfortunately, GDB does not return error values to the
1813 # system in all cases that the script fails, so we must manually search the
1814 # output to check whether the pass string is present and no failure strings
1815 # were printed.
Gilles Peskine4976e822019-01-06 19:52:22 +00001816
1817 # Don't try to disable ASLR. We don't care about ASLR here. We do care
1818 # about a spurious message if Gdb tries and fails, so suppress that.
1819 gdb_disable_aslr=
1820 if [ -z "$(gdb -batch -nw -ex 'set disable-randomization off' 2>&1)" ]; then
1821 gdb_disable_aslr='set disable-randomization off'
1822 fi
1823
Gilles Peskine8f073122018-11-27 15:58:47 +01001824 for optimization_flag in -O2 -O3 -Ofast -Os; do
Gilles Peskine55f7c942019-01-09 22:28:21 +01001825 for compiler in clang gcc; do
1826 msg "test: $compiler $optimization_flag, mbedtls_platform_zeroize()"
1827 make programs CC="$compiler" DEBUG=1 CFLAGS="$optimization_flag"
Gilles Peskine4976e822019-01-06 19:52:22 +00001828 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 +01001829 if_build_succeeded grep "The buffer was correctly zeroized" test_zeroize.log
1830 if_build_succeeded not grep -i "error" test_zeroize.log
1831 rm -f test_zeroize.log
1832 make clean
1833 done
Andres Amaya Garcia29673812017-10-25 10:35:51 +01001834 done
Gilles Peskine4976e822019-01-06 19:52:22 +00001835
1836 unset gdb_disable_aslr
Gilles Peskine8f073122018-11-27 15:58:47 +01001837}
Andres Amaya Garciad0d7bf62017-10-25 09:01:31 +01001838
Gilles Peskine7b9fcdc2019-02-25 20:26:06 +01001839support_check_python_files () {
1840 type pylint3 >/dev/null 2>/dev/null
1841}
Gilles Peskine8f073122018-11-27 15:58:47 +01001842component_check_python_files () {
1843 msg "Lint: Python scripts"
1844 record_status tests/scripts/check-python-files.sh
1845}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001846
Gilles Peskine8f073122018-11-27 15:58:47 +01001847component_check_generate_test_code () {
1848 msg "uint test: generate_test_code.py"
1849 record_status ./tests/scripts/test_generate_test_code.py
1850}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001851
1852################################################################
1853#### Termination
1854################################################################
1855
Gilles Peskine8f073122018-11-27 15:58:47 +01001856post_report () {
1857 msg "Done, cleaning up"
1858 cleanup
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001859
Gilles Peskine8f073122018-11-27 15:58:47 +01001860 final_report
1861}
1862
1863
1864
1865################################################################
1866#### Run all the things
1867################################################################
1868
Gilles Peskinee48351a2018-11-27 16:06:30 +01001869# Run one component and clean up afterwards.
Gilles Peskine8f073122018-11-27 15:58:47 +01001870run_component () {
Gilles Peskine608953e2019-01-02 18:57:02 +01001871 # Back up the configuration in case the component modifies it.
1872 # The cleanup function will restore it.
1873 cp -p "$CONFIG_H" "$CONFIG_BAK"
Gilles Peskineffcdeff2018-12-04 12:49:28 +01001874 current_component="$1"
Gilles Peskine8f073122018-11-27 15:58:47 +01001875 "$@"
Gilles Peskinee48351a2018-11-27 16:06:30 +01001876 cleanup
Gilles Peskine8f073122018-11-27 15:58:47 +01001877}
1878
1879# Preliminary setup
1880pre_check_environment
1881pre_initialize_variables
1882pre_parse_command_line "$@"
Gilles Peskine348fb9a2018-11-27 17:04:29 +01001883
Gilles Peskine878cf602019-01-06 20:50:38 +00001884pre_check_git
1885build_status=0
1886if [ $KEEP_GOING -eq 1 ]; then
1887 pre_setup_keep_going
1888else
1889 record_status () {
1890 "$@"
1891 }
1892fi
1893pre_print_configuration
1894pre_check_tools
Gilles Peskine878cf602019-01-06 20:50:38 +00001895cleanup
Gilles Peskine8f073122018-11-27 15:58:47 +01001896
Gilles Peskinebeb3a812019-01-06 22:11:25 +00001897# Run the requested tests.
1898for component in $RUN_COMPONENTS; do
1899 run_component "component_$component"
1900done
Gilles Peskine8f073122018-11-27 15:58:47 +01001901
1902# We're done.
Gilles Peskine878cf602019-01-06 20:50:38 +00001903post_report