blob: e7b84f08fad742de5486d3fbe4a0b8c8a4269f59 [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)
38# * arm-gcc and mingw-gcc
39# * ArmCC 5 and ArmCC 6, unless invoked with --no-armcc
40# * Yotta build dependencies, unless invoked with --no-yotta
41# * 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 Peskine2906a0a2019-01-09 22:29:17 +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.
62# * 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.
65# * support_XXX: if support_XXX exists and returns false then
66# component_XXX is not run by default.
67# * post_XXX: things to do after running the tests.
68# * other: miscellaneous support functions.
69#
70# 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 Peskine57db6ff2019-01-08 22:04:31 +0100108pre_check_environment () {
Gilles Peskine770ad7e2019-01-08 23:19:08 +0100109 if [ -d library -a -d include -a -d tests ]; then :; else
Gilles Peskine57db6ff2019-01-08 22:04:31 +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 Peskine57db6ff2019-01-08 22:04:31 +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 Peskine57db6ff2019-01-08 22:04:31 +0100119 MEMORY=0
120 FORCE=0
121 KEEP_GOING=0
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100122 YOTTA=1
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100123
Antonin Décimo8fd91562019-01-23 15:24:37 +0100124 # Default commands, can be overridden by the environment
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100125 : ${OPENSSL:="openssl"}
126 : ${OPENSSL_LEGACY:="$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}
Gilles Peskinef1709bb2020-04-30 18:19:32 +0200134 : ${ARM_NONE_EABI_GCC_PREFIX:=arm-none-eabi-}
Andres AGdc192212016-08-31 17:33:13 +0100135
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100136 # if MAKEFLAGS is not set add the -j option to speed up invocations of make
Gilles Peskine7120f772019-01-06 20:15:26 +0000137 if [ -z "${MAKEFLAGS+set}" ]; then
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100138 export MAKEFLAGS="-j"
139 fi
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100140
Gilles Peskinec20a4052019-10-21 17:11:33 +0200141 # CFLAGS and LDFLAGS for Asan builds that don't use CMake
Gilles Peskine4c2697f2019-10-21 19:06:33 +0200142 ASAN_CFLAGS='-Werror -Wall -Wextra -fsanitize=address,undefined -fno-sanitize-recover=all'
Gilles Peskinec20a4052019-10-21 17:11:33 +0200143
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100144 # Gather the list of available components. These are the functions
145 # defined in this script whose name starts with "component_".
146 # Parse the script with sed, because in sh there is no way to list
147 # defined functions.
148 ALL_COMPONENTS=$(sed -n 's/^ *component_\([0-9A-Z_a-z]*\) *().*/\1/p' <"$0")
Gilles Peskine3fbdd212019-01-08 23:33:45 +0100149
150 # Exclude components that are not supported on this platform.
151 SUPPORTED_COMPONENTS=
152 for component in $ALL_COMPONENTS; do
153 case $(type "support_$component" 2>&1) in
154 *' function'*)
155 if ! support_$component; then continue; fi;;
156 esac
157 SUPPORTED_COMPONENTS="$SUPPORTED_COMPONENTS $component"
158 done
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100159}
Andres AG38495a32016-07-12 16:54:33 +0100160
Gilles Peskineff7238f2019-01-10 00:05:18 +0100161# Test whether the component $1 is included in the command line patterns.
162is_component_included()
Gilles Peskine6e984232018-11-27 21:37:53 +0100163{
164 set -f
Gilles Peskineeb39b9b2019-01-08 23:41:00 +0100165 for pattern in $COMMAND_LINE_COMPONENTS; do
Gilles Peskine6e984232018-11-27 21:37:53 +0100166 set +f
167 case ${1#component_} in $pattern) return 0;; esac
168 done
169 set +f
170 return 1
171}
172
Simon Butcher41eeccf2016-09-07 00:07:09 +0100173usage()
SimonB2e23c822016-04-16 21:54:39 +0100174{
Gilles Peskine709346a2017-12-10 23:43:39 +0100175 cat <<EOF
Gilles Peskine91bd8b72019-01-08 23:01:34 +0100176Usage: $0 [OPTION]... [COMPONENT]...
177Run mbedtls release validation tests.
178By default, run all tests. With one or more COMPONENT, run only those.
Gilles Peskineff7238f2019-01-10 00:05:18 +0100179COMPONENT can be the name of a component or a shell wildcard pattern.
180
181Examples:
182 $0 "check_*"
183 Run all sanity checks.
184 $0 --no-armcc --except test_memsan
185 Run everything except builds that require armcc and MemSan.
Gilles Peskine91bd8b72019-01-08 23:01:34 +0100186
187Special options:
188 -h|--help Print this help and exit.
Gilles Peskineb3241cb2019-01-08 23:44:07 +0100189 --list-all-components List all available test components and exit.
190 --list-components List components supported on this platform and exit.
Gilles Peskine709346a2017-12-10 23:43:39 +0100191
192General options:
193 -f|--force Force the tests to overwrite any modified files.
Gilles Peskine7c652162017-12-11 00:01:40 +0100194 -k|--keep-going Run all tests and report errors at the end.
Gilles Peskine709346a2017-12-10 23:43:39 +0100195 -m|--memory Additional optional memory tests.
Gilles Peskinef1709bb2020-04-30 18:19:32 +0200196 --arm-none-eabi-gcc-prefix=<string>
197 Prefix for a cross-compiler for arm-none-eabi
198 (default: "${ARM_NONE_EABI_GCC_PREFIX}")
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100199 --armcc Run ARM Compiler builds (on by default).
Gilles Peskineff7238f2019-01-10 00:05:18 +0100200 --except Exclude the COMPONENTs listed on the command line,
201 instead of running only those.
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100202 --no-armcc Skip ARM Compiler builds.
Gilles Peskine19ceb712018-03-21 08:40:26 +0100203 --no-force Refuse to overwrite modified files (default).
204 --no-keep-going Stop at the first error (default).
205 --no-memory No additional memory tests (default).
Gilles Peskine2a22a802017-12-21 15:19:00 +0100206 --no-yotta Skip yotta module build.
Gilles Peskine709346a2017-12-10 23:43:39 +0100207 --out-of-source-dir=<path> Directory used for CMake out-of-source build tests.
Gilles Peskine19ceb712018-03-21 08:40:26 +0100208 --random-seed Use a random seed value for randomized tests (default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100209 -r|--release-test Run this script in release mode. This fixes the seed value to 1.
210 -s|--seed Integer seed value to use for this test run.
Gilles Peskine2a22a802017-12-21 15:19:00 +0100211 --yotta Build yotta module (on by default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100212
213Tool path options:
214 --armc5-bin-dir=<ARMC5_bin_dir_path> ARM Compiler 5 bin directory.
215 --armc6-bin-dir=<ARMC6_bin_dir_path> ARM Compiler 6 bin directory.
216 --gnutls-cli=<GnuTLS_cli_path> GnuTLS client executable to use for most tests.
217 --gnutls-serv=<GnuTLS_serv_path> GnuTLS server executable to use for most tests.
218 --gnutls-legacy-cli=<GnuTLS_cli_path> GnuTLS client executable to use for legacy tests.
219 --gnutls-legacy-serv=<GnuTLS_serv_path> GnuTLS server executable to use for legacy tests.
220 --openssl=<OpenSSL_path> OpenSSL executable to use for most tests.
221 --openssl-legacy=<OpenSSL_path> OpenSSL executable to use for legacy tests e.g. SSLv3.
222EOF
SimonB2e23c822016-04-16 21:54:39 +0100223}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100224
225# remove built files as well as the cmake cache/config
226cleanup()
227{
Gilles Peskinea71d64c2018-03-21 12:16:57 +0100228 if [ -n "${MBEDTLS_ROOT_DIR+set}" ]; then
229 cd "$MBEDTLS_ROOT_DIR"
230 fi
231
Gilles Peskine7c652162017-12-11 00:01:40 +0100232 command make clean
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200233
Gilles Peskine31b07e22018-03-21 12:15:06 +0100234 # Remove CMake artefacts
235 find . -name .git -prune -o -name yotta -prune -o \
236 -iname CMakeFiles -exec rm -rf {} \+ -o \
237 \( -iname cmake_install.cmake -o \
238 -iname CTestTestfile.cmake -o \
239 -iname CMakeCache.txt \) -exec rm {} \+
240 # Recover files overwritten by in-tree CMake builds
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000241 rm -f include/Makefile include/mbedtls/Makefile programs/*/Makefile
Paul Bakkerfe0984d2014-06-13 00:13:45 +0200242 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile
243 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200244
245 if [ -f "$CONFIG_BAK" ]; then
246 mv "$CONFIG_BAK" "$CONFIG_H"
247 fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100248}
249
Gilles Peskine7c652162017-12-11 00:01:40 +0100250# Executed on exit. May be redefined depending on command line options.
251final_report () {
252 :
253}
254
255fatal_signal () {
256 cleanup
257 final_report $1
258 trap - $1
259 kill -$1 $$
260}
261
262trap 'fatal_signal HUP' HUP
263trap 'fatal_signal INT' INT
264trap 'fatal_signal TERM' TERM
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200265
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100266msg()
267{
Gilles Peskine11ddca62018-12-04 12:49:28 +0100268 if [ -n "${current_component:-}" ]; then
269 current_section="${current_component#component_}: $1"
270 else
271 current_section="$1"
272 fi
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100273 echo ""
274 echo "******************************************************************"
Gilles Peskine11ddca62018-12-04 12:49:28 +0100275 echo "* $current_section "
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000276 printf "* "; date
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100277 echo "******************************************************************"
278}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100279
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100280armc6_build_test()
281{
282 FLAGS="$1"
Andres AGa5cd9732016-10-17 15:23:10 +0100283
Gilles Peskine81b60fb2020-04-30 23:11:54 +0200284 msg "build: ARM Compiler 6 ($FLAGS)"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100285 ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \
286 WARNING_CFLAGS='-xc -std=c99' make lib
Gilles Peskine81b60fb2020-04-30 23:11:54 +0200287
288 msg "size: ARM Compiler 6 ($FLAGS)"
289 "$ARMC6_FROMELF" -z library/*.o
290
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100291 make clean
292}
Andres AGa5cd9732016-10-17 15:23:10 +0100293
Andres AGd9eba4b2016-08-26 14:42:14 +0100294err_msg()
295{
296 echo "$1" >&2
297}
298
299check_tools()
300{
301 for TOOL in "$@"; do
Andres AG98393602017-01-31 17:04:45 +0000302 if ! `type "$TOOL" >/dev/null 2>&1`; then
Andres AGd9eba4b2016-08-26 14:42:14 +0100303 err_msg "$TOOL not found!"
304 exit 1
305 fi
306 done
307}
308
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100309pre_parse_command_line () {
Gilles Peskineeb39b9b2019-01-08 23:41:00 +0100310 COMMAND_LINE_COMPONENTS=
Gilles Peskineff7238f2019-01-10 00:05:18 +0100311 all_except=0
Gilles Peskine53084872019-01-09 23:13:54 +0100312 no_armcc=
Gilles Peskine6e984232018-11-27 21:37:53 +0100313
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100314 while [ $# -gt 0 ]; do
315 case "$1" in
Gilles Peskinef1709bb2020-04-30 18:19:32 +0200316 --arm-none-eabi-gcc-prefix) shift; ARM_NONE_EABI_GCC_PREFIX="$1";;
Gilles Peskine53084872019-01-09 23:13:54 +0100317 --armcc) no_armcc=;;
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100318 --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
319 --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
Gilles Peskineeb39b9b2019-01-08 23:41:00 +0100320 --except) all_except=1;;
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100321 --force|-f) FORCE=1;;
322 --gnutls-cli) shift; GNUTLS_CLI="$1";;
323 --gnutls-legacy-cli) shift; GNUTLS_LEGACY_CLI="$1";;
324 --gnutls-legacy-serv) shift; GNUTLS_LEGACY_SERV="$1";;
325 --gnutls-serv) shift; GNUTLS_SERV="$1";;
326 --help|-h) usage; exit;;
327 --keep-going|-k) KEEP_GOING=1;;
Gilles Peskineb3241cb2019-01-08 23:44:07 +0100328 --list-all-components) printf '%s\n' $ALL_COMPONENTS; exit;;
329 --list-components) printf '%s\n' $SUPPORTED_COMPONENTS; exit;;
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100330 --memory|-m) MEMORY=1;;
Gilles Peskine53084872019-01-09 23:13:54 +0100331 --no-armcc) no_armcc=1;;
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100332 --no-force) FORCE=0;;
333 --no-keep-going) KEEP_GOING=0;;
334 --no-memory) MEMORY=0;;
335 --no-yotta) YOTTA=0;;
336 --openssl) shift; OPENSSL="$1";;
337 --openssl-legacy) shift; OPENSSL_LEGACY="$1";;
338 --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
339 --random-seed) unset SEED;;
340 --release-test|-r) SEED=1;;
341 --seed|-s) shift; SEED="$1";;
342 --yotta) YOTTA=1;;
Gilles Peskine91bd8b72019-01-08 23:01:34 +0100343 -*)
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100344 echo >&2 "Unknown option: $1"
345 echo >&2 "Run $0 --help for usage."
346 exit 120
347 ;;
Gilles Peskineeb39b9b2019-01-08 23:41:00 +0100348 *) COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS $1";;
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100349 esac
350 shift
351 done
Gilles Peskine91bd8b72019-01-08 23:01:34 +0100352
Gilles Peskineff7238f2019-01-10 00:05:18 +0100353 # With no list of components, run everything.
Gilles Peskineeb39b9b2019-01-08 23:41:00 +0100354 if [ -z "$COMMAND_LINE_COMPONENTS" ]; then
355 all_except=1
356 fi
357
Gilles Peskine53084872019-01-09 23:13:54 +0100358 # --no-armcc is a legacy option. The modern way is --except '*_armcc*'.
359 # Ignore it if components are listed explicitly on the command line.
Gilles Peskineff7238f2019-01-10 00:05:18 +0100360 if [ -n "$no_armcc" ] && [ $all_except -eq 1 ]; then
Gilles Peskine53084872019-01-09 23:13:54 +0100361 COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS *_armcc*"
362 # --no-armcc also disables yotta.
363 COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS *_yotta*"
364 fi
365
Gilles Peskineeb39b9b2019-01-08 23:41:00 +0100366 # Build the list of components to run.
Gilles Peskineff7238f2019-01-10 00:05:18 +0100367 RUN_COMPONENTS=
368 for component in $SUPPORTED_COMPONENTS; do
369 if is_component_included "$component"; [ $? -eq $all_except ]; then
370 RUN_COMPONENTS="$RUN_COMPONENTS $component"
371 fi
372 done
Gilles Peskineeb39b9b2019-01-08 23:41:00 +0100373
374 unset all_except
Gilles Peskine53084872019-01-09 23:13:54 +0100375 unset no_armcc
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100376}
SimonB2e23c822016-04-16 21:54:39 +0100377
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100378pre_check_git () {
379 if [ $FORCE -eq 1 ]; then
Gilles Peskinec7800952019-01-09 23:14:09 +0100380 rm -rf "$OUT_OF_SOURCE_DIR"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100381 if [ $YOTTA -eq 1 ]; then
Gilles Peskinec7800952019-01-09 23:14:09 +0100382 rm -rf yotta/module
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100383 fi
384 git checkout-index -f -q $CONFIG_H
385 cleanup
386 else
387
388 if [ $YOTTA -ne 0 ] && [ -d yotta/module ]; then
389 err_msg "Warning - there is an existing yotta module in the directory 'yotta/module'"
390 echo "You can either delete your work and retry, or force the test to overwrite the"
391 echo "test by rerunning the script as: $0 --force"
392 exit 1
393 fi
394
395 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
396 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
397 echo "You can either delete this directory manually, or force the test by rerunning"
398 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
399 exit 1
400 fi
401
Gilles Peskinec9663b12019-01-09 22:30:01 +0100402 if ! git diff --quiet include/mbedtls/config.h; then
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100403 err_msg "Warning - the configuration file 'include/mbedtls/config.h' has been edited. "
404 echo "You can either delete or preserve your work, or force the test by rerunning the"
405 echo "script as: $0 --force"
406 exit 1
407 fi
Gilles Peskineda519252017-11-30 13:22:04 +0100408 fi
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100409}
SimonB2e23c822016-04-16 21:54:39 +0100410
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100411pre_setup_keep_going () {
Gilles Peskine7c652162017-12-11 00:01:40 +0100412 failure_summary=
413 failure_count=0
414 start_red=
415 end_color=
416 if [ -t 1 ]; then
Gilles Peskine9736b9d2018-01-02 21:54:17 +0100417 case "${TERM:-}" in
Gilles Peskine7c652162017-12-11 00:01:40 +0100418 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
419 start_red=$(printf '\033[31m')
420 end_color=$(printf '\033[0m')
421 ;;
422 esac
423 fi
424 record_status () {
425 if "$@"; then
426 last_status=0
427 else
428 last_status=$?
429 text="$current_section: $* -> $last_status"
430 failure_summary="$failure_summary
431$text"
432 failure_count=$((failure_count + 1))
433 echo "${start_red}^^^^$text^^^^${end_color}"
434 fi
435 }
436 make () {
437 case "$*" in
438 *test|*check)
439 if [ $build_status -eq 0 ]; then
440 record_status command make "$@"
441 else
442 echo "(skipped because the build failed)"
443 fi
444 ;;
445 *)
446 record_status command make "$@"
447 build_status=$last_status
448 ;;
449 esac
450 }
451 final_report () {
452 if [ $failure_count -gt 0 ]; then
453 echo
454 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
455 echo "${start_red}FAILED: $failure_count${end_color}$failure_summary"
456 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Jaeden Amero5113bde2018-07-20 16:42:14 +0100457 exit 1
Gilles Peskine7c652162017-12-11 00:01:40 +0100458 elif [ -z "${1-}" ]; then
459 echo "SUCCESS :)"
460 fi
461 if [ -n "${1-}" ]; then
462 echo "Killed by SIG$1."
463 fi
464 }
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100465}
466
Gilles Peskine7c652162017-12-11 00:01:40 +0100467if_build_succeeded () {
468 if [ $build_status -eq 0 ]; then
469 record_status "$@"
470 fi
471}
472
Gilles Peskine30bc3852019-01-09 23:25:25 +0100473# to be used instead of ! for commands run with
474# record_status or if_build_succeeded
475not() {
476 ! "$@"
477}
478
479
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100480pre_print_configuration () {
481 msg "info: $0 configuration"
482 echo "MEMORY: $MEMORY"
483 echo "FORCE: $FORCE"
484 echo "SEED: ${SEED-"UNSET"}"
485 echo "OPENSSL: $OPENSSL"
486 echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
487 echo "GNUTLS_CLI: $GNUTLS_CLI"
488 echo "GNUTLS_SERV: $GNUTLS_SERV"
489 echo "GNUTLS_LEGACY_CLI: $GNUTLS_LEGACY_CLI"
490 echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV"
491 echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
492 echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
493}
Andres AG7770ea82016-10-10 15:46:20 +0100494
Andres AGd9eba4b2016-08-26 14:42:14 +0100495# Make sure the tools we need are available.
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100496pre_check_tools () {
Gilles Peskine541fb1e2019-01-06 22:40:00 +0000497 # Build the list of variables to pass to output_env.sh.
498 set env
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100499
Gilles Peskine541fb1e2019-01-06 22:40:00 +0000500 case " $RUN_COMPONENTS " in
501 # Require OpenSSL and GnuTLS if running any tests (as opposed to
502 # only doing builds). Not all tests run OpenSSL and GnuTLS, but this
503 # is a good enough approximation in practice.
504 *" test_"*)
505 # To avoid setting OpenSSL and GnuTLS for each call to compat.sh
506 # and ssl-opt.sh, we just export the variables they require.
507 export OPENSSL_CMD="$OPENSSL"
508 export GNUTLS_CLI="$GNUTLS_CLI"
509 export GNUTLS_SERV="$GNUTLS_SERV"
510 # Avoid passing --seed flag in every call to ssl-opt.sh
511 if [ -n "${SEED-}" ]; then
512 export SEED
513 fi
514 set "$@" OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY"
515 set "$@" GNUTLS_CLI="$GNUTLS_CLI" GNUTLS_SERV="$GNUTLS_SERV"
516 set "$@" GNUTLS_LEGACY_CLI="$GNUTLS_LEGACY_CLI"
517 set "$@" GNUTLS_LEGACY_SERV="$GNUTLS_LEGACY_SERV"
518 check_tools "$OPENSSL" "$OPENSSL_LEGACY" \
519 "$GNUTLS_CLI" "$GNUTLS_SERV" \
520 "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV"
521 ;;
522 esac
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100523
Gilles Peskine541fb1e2019-01-06 22:40:00 +0000524 case " $RUN_COMPONENTS " in
525 *_doxygen[_\ ]*) check_tools "doxygen" "dot";;
526 esac
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100527
Gilles Peskine541fb1e2019-01-06 22:40:00 +0000528 case " $RUN_COMPONENTS " in
Gilles Peskinef1709bb2020-04-30 18:19:32 +0200529 *_arm_none_eabi_gcc[_\ ]*) check_tools "${ARM_NONE_EABI_GCC_PREFIX}gcc";;
Gilles Peskine541fb1e2019-01-06 22:40:00 +0000530 esac
531
532 case " $RUN_COMPONENTS " in
533 *_mingw[_\ ]*) check_tools "i686-w64-mingw32-gcc";;
534 esac
535
536 case " $RUN_COMPONENTS " in
Gilles Peskine53084872019-01-09 23:13:54 +0100537 *_armcc*|*_yotta*)
Gilles Peskine541fb1e2019-01-06 22:40:00 +0000538 ARMC5_CC="$ARMC5_BIN_DIR/armcc"
539 ARMC5_AR="$ARMC5_BIN_DIR/armar"
Gilles Peskine81b60fb2020-04-30 23:11:54 +0200540 ARMC5_FROMELF="$ARMC5_BIN_DIR/fromelf"
Gilles Peskine541fb1e2019-01-06 22:40:00 +0000541 ARMC6_CC="$ARMC6_BIN_DIR/armclang"
542 ARMC6_AR="$ARMC6_BIN_DIR/armar"
Gilles Peskine81b60fb2020-04-30 23:11:54 +0200543 ARMC6_FROMELF="$ARMC6_BIN_DIR/fromelf"
544 check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC5_FROMELF" \
545 "$ARMC6_CC" "$ARMC6_AR" "$ARMC6_FROMELF";;
Gilles Peskine53084872019-01-09 23:13:54 +0100546 esac
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100547
548 msg "info: output_env.sh"
Gilles Peskine53084872019-01-09 23:13:54 +0100549 case $RUN_COMPONENTS in
550 *_armcc*|*_yotta*)
551 set "$@" ARMC5_CC="$ARMC5_CC" ARMC6_CC="$ARMC6_CC" RUN_ARMCC=1;;
552 *) set "$@" RUN_ARMCC=0;;
553 esac
554 "$@" scripts/output_env.sh
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100555}
Andres AGd9eba4b2016-08-26 14:42:14 +0100556
Gilles Peskine192c72f2017-12-21 15:59:21 +0100557
558
559################################################################
560#### Basic checks
561################################################################
SimonB2e23c822016-04-16 21:54:39 +0100562
563#
564# Test Suites to be executed
565#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200566# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100567# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard61bc57a2014-08-14 11:29:06 +0200568# and/or are more likely to fail than others (eg I use Clang most of the
569# time, so start with a GCC build).
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200570# 2. Minimize total running time, by avoiding useless rebuilds
571#
572# Indicative running times are given for reference.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100573
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100574component_check_recursion () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100575 msg "test: recursion.pl" # < 1s
576 record_status tests/scripts/recursion.pl library/*.c
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100577}
Manuel Pégourié-Gonnardea29d152014-11-20 17:32:33 +0100578
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100579component_check_generated_files () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100580 msg "test: freshness of generated source files" # < 1s
581 record_status tests/scripts/check-generated-files.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100582}
Manuel Pégourié-Gonnardb3b8e432015-02-13 14:52:19 +0000583
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100584component_check_doxy_blocks () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100585 msg "test: doxygen markup outside doxygen blocks" # < 1s
586 record_status tests/scripts/check-doxy-blocks.pl
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100587}
Manuel Pégourié-Gonnardd09a6b52015-04-09 17:19:23 +0200588
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100589component_check_files () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100590 msg "test: check-files.py" # < 1s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100591 record_status tests/scripts/check-files.py
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100592}
Manuel Pégourié-Gonnard77d56bb2015-07-28 15:00:37 +0200593
Gilles Peskinec3189252020-05-10 17:40:49 +0200594component_check_changelog () {
595 msg "Check: changelog entries" # < 1s
596 rm -f ChangeLog.new
597 record_status scripts/assemble_changelog.py -o ChangeLog.new
598 if [ -e ChangeLog.new ]; then
599 # Show the diff for information. It isn't an error if the diff is
600 # non-empty.
601 diff -u ChangeLog ChangeLog.new || true
602 rm ChangeLog.new
603 fi
604}
605
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100606component_check_names () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100607 msg "test/build: declared and exported names" # < 3s
Gilles Peskinee952fdf2019-05-15 17:52:22 +0200608 record_status tests/scripts/check-names.sh -v
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100609}
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +0200610
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100611component_check_doxygen_warnings () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100612 msg "test: doxygen warnings" # ~ 3s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100613 record_status tests/scripts/doxygen.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100614}
Andres Amaya Garciadd29c2f2017-05-04 11:35:51 +0100615
Simon Butcher948f2642018-07-20 21:27:33 +0100616
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100617################################################################
618#### Build and test many configurations and targets
619################################################################
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100620
k-stachowiak45d0ba12019-06-04 13:14:58 +0200621component_test_large_ecdsa_key_signature () {
622
623 SMALL_MPI_MAX_SIZE=136 # Small enough to interfere with the EC signatures
624
625 msg "build: cmake + MBEDTLS_MPI_MAX_SIZE=${SMALL_MPI_MAX_SIZE}, gcc, ASan" # ~ 1 min 50s
626 scripts/config.pl set MBEDTLS_MPI_MAX_SIZE $SMALL_MPI_MAX_SIZE
627 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
628 make
629
630 INEVITABLY_PRESENT_FILE=Makefile
631 SIGNATURE_FILE="${INEVITABLY_PRESENT_FILE}.sig" # Warning, this is rm -f'ed below
632
633 msg "test: pk_sign secp521r1_prv.der for MBEDTLS_MPI_MAX_SIZE=${SMALL_MPI_MAX_SIZE} (ASan build)" # ~ 5s
634 if_build_succeeded programs/pkey/pk_sign tests/data_files/secp521r1_prv.der $INEVITABLY_PRESENT_FILE
635 rm -f $SIGNATURE_FILE
636}
637
Gilles Peskine1270d322019-04-08 17:00:15 +0200638component_test_default_out_of_box () {
639 msg "build: make, default config (out-of-box)" # ~1min
640 make
641
642 msg "test: main suites make, default config (out-of-box)" # ~10s
643 make test
644
645 msg "selftest: make, default config (out-of-box)" # ~10s
Gilles Peskinebfda0332020-04-23 23:37:45 +0200646 if_build_succeeded programs/test/selftest
Gilles Peskine1270d322019-04-08 17:00:15 +0200647}
648
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100649component_build_yotta () {
Gilles Peskine53084872019-01-09 23:13:54 +0100650 # Note - use of yotta is deprecated, and yotta also requires armcc to be on the
651 # path, and uses whatever version of armcc it finds there.
652 msg "build: create and build yotta module" # ~ 30s
653 record_status tests/scripts/yotta-build.sh
654}
655support_build_yotta () {
656 [ $YOTTA -ne 0 ]
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100657}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100658
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100659component_test_default_cmake_gcc_asan () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100660 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100661 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100662 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +0200663
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100664 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100665 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100666
Gilles Peskinebfda0332020-04-23 23:37:45 +0200667 msg "test: selftest (ASan build)" # ~ 10s
668 if_build_succeeded programs/test/selftest
669
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100670 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
Gilles Peskine7c652162017-12-11 00:01:40 +0100671 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100672
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100673 msg "test: compat.sh (ASan build)" # ~ 6 min
674 if_build_succeeded tests/compat.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100675}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000676
Hanno Becker167ae432019-02-26 14:27:09 +0000677component_test_full_cmake_gcc_asan () {
678 msg "build: full config, cmake, gcc, ASan"
679 scripts/config.pl full
680 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
681 make
682
683 msg "test: main suites (inc. selftests) (full config, ASan build)"
684 make test
685
Gilles Peskinebfda0332020-04-23 23:37:45 +0200686 msg "test: selftest (ASan build)" # ~ 10s
687 if_build_succeeded programs/test/selftest
688
Hanno Becker167ae432019-02-26 14:27:09 +0000689 msg "test: ssl-opt.sh (full config, ASan build)"
690 if_build_succeeded tests/ssl-opt.sh
691
692 msg "test: compat.sh (full config, ASan build)"
693 if_build_succeeded tests/compat.sh
694}
695
Manuel Pégourié-Gonnard51e24942020-01-02 11:45:12 +0100696component_test_zlib_make() {
697 msg "build: zlib enabled, make"
698 scripts/config.pl set MBEDTLS_ZLIB_SUPPORT
699 make ZLIB=1 CFLAGS='-Werror -O1'
700
701 msg "test: main suites (zlib, make)"
702 make test
703
704 msg "test: ssl-opt.sh (zlib, make)"
705 if_build_succeeded tests/ssl-opt.sh
706}
Manuel Pégourié-Gonnard2150fb22020-01-24 10:17:20 +0100707support_test_zlib_make () {
708 base=support_test_zlib_$$
709 cat <<'EOF' > ${base}.c
710#include "zlib.h"
711int main(void) { return 0; }
712EOF
713 gcc -o ${base}.exe ${base}.c -lz 2>/dev/null
714 ret=$?
715 rm -f ${base}.*
716 return $ret
717}
Manuel Pégourié-Gonnard51e24942020-01-02 11:45:12 +0100718
719component_test_zlib_cmake() {
720 msg "build: zlib enabled, cmake"
721 scripts/config.pl set MBEDTLS_ZLIB_SUPPORT
722 cmake -D ENABLE_ZLIB_SUPPORT=On -D CMAKE_BUILD_TYPE:String=Check .
723 make
724
725 msg "test: main suites (zlib, cmake)"
726 make test
727
728 msg "test: ssl-opt.sh (zlib, cmake)"
729 if_build_succeeded tests/ssl-opt.sh
730}
Manuel Pégourié-Gonnard2150fb22020-01-24 10:17:20 +0100731support_test_zlib_cmake () {
732 support_test_zlib_make "$@"
733}
Manuel Pégourié-Gonnard51e24942020-01-02 11:45:12 +0100734
Gilles Peskine3484ed82019-01-08 22:51:19 +0100735component_test_ref_configs () {
736 msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
737 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
738 record_status tests/scripts/test-ref-configs.pl
739}
740
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100741component_test_sslv3 () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100742 msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100743 scripts/config.pl set MBEDTLS_SSL_PROTO_SSL3
744 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
745 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000746
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100747 msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
748 make test
749
750 msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
751 if_build_succeeded tests/compat.sh -m 'tls1 tls1_1 tls1_2 dtls1 dtls1_2'
752 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
753
754 msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
755 if_build_succeeded tests/ssl-opt.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100756}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100757
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100758component_test_no_renegotiation () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100759 msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100760 scripts/config.pl unset MBEDTLS_SSL_RENEGOTIATION
761 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
762 make
763
764 msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
765 make test
766
767 msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
768 if_build_succeeded tests/ssl-opt.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100769}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100770
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100771component_test_rsa_no_crt () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100772 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100773 scripts/config.pl set MBEDTLS_RSA_NO_CRT
774 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
775 make
776
777 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
778 make test
779
780 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
781 if_build_succeeded tests/ssl-opt.sh -f RSA
782
783 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
784 if_build_succeeded tests/compat.sh -t RSA
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100785}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100786
Manuel Pégourié-Gonnardc98fde52020-05-28 12:55:10 +0200787component_test_no_ctr_drbg () {
788 msg "build: Full minus CTR_DRBG"
789 scripts/config.pl full
790 scripts/config.pl unset MBEDTLS_CTR_DRBG_C
791
792 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
793 make
794
795 msg "test: no CTR_DRBG"
796 make test
797
Manuel Pégourié-Gonnardcdfa2f92020-06-05 09:29:51 +0200798 # no ssl-opt.sh/compat.sh as they all depend on CTR_DRBG so far
799}
800
801component_test_no_hmac_drbg () {
802 msg "build: Full minus HMAC_DRBG"
803 scripts/config.pl full
804 scripts/config.pl unset MBEDTLS_HMAC_DRBG_C
805 scripts/config.pl unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
806
807 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
808 make
809
810 msg "test: no HMAC_DRBG"
811 make test
812
813 # No ssl-opt.sh/compat.sh as they never use HMAC_DRBG so far,
814 # so there's little value in running those lengthy tests here.
Manuel Pégourié-Gonnardc98fde52020-05-28 12:55:10 +0200815}
816
Manuel Pégourié-Gonnard6d614982020-06-16 12:51:42 +0200817component_test_no_drbg_all_hashes () {
818 # this tests the internal ECP DRBG using a KDF based on SHA-512
819 msg "build: Default minus DRBGs"
820 scripts/config.pl unset MBEDTLS_CTR_DRBG_C
821 scripts/config.pl unset MBEDTLS_HMAC_DRBG_C
822 scripts/config.pl unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
823 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_C # requires a DRBG
824 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA Crypto
825
826 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
827 make
828
829 msg "test: Default minus DRBGs"
830 make test
831
832 # no SSL tests as they all depend on having a DRBG
833}
834
835component_test_no_drbg_no_sha512 () {
836 # this tests the internal ECP DRBG using a KDF based on SHA-256
837 msg "build: Default minus DRBGs minus SHA-512"
838 scripts/config.pl unset MBEDTLS_CTR_DRBG_C
839 scripts/config.pl unset MBEDTLS_HMAC_DRBG_C
840 scripts/config.pl unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
841 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_C # requires a DRBG
842 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA Crypto
843 scripts/config.pl unset MBEDTLS_SHA512_C
844
845 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
846 make
847
848 msg "test: Default minus DRBGs minus SHA-512"
849 make test
850
851 # no SSL tests as they all depend on having a DRBG
852}
853
854component_test_no_drbg_no_sha2 () {
855 # this tests the internal ECP DRBG using a KDF based on SHA-1
856 msg "build: Default minus DRBGs minus SHA-2"
857 scripts/config.pl unset MBEDTLS_CTR_DRBG_C
858 scripts/config.pl unset MBEDTLS_HMAC_DRBG_C
859 scripts/config.pl unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
860 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_C # requires a DRBG
861 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA Crypto
862 scripts/config.pl unset MBEDTLS_SHA512_C
863 scripts/config.pl unset MBEDTLS_SHA256_C
864 scripts/config.pl unset MBEDTLS_ENTROPY_C # requires SHA-2
865 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_C # requires Entropy
866 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA Crypto
867 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_SE_C # requires PSA Crypto
868 scripts/config.pl unset MBEDTLS_USE_PSA_CRYPTO # requires PSA Crypto
869 scripts/config.pl unset MBEDTLS_SSL_PROTO_TLS1_2 # requires SHA-2
870
871 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
872 make
873
874 msg "test: Default minus DRBGs minus SHA-2"
875 make test
876
877 # no SSL tests as they all depend on having a DRBG
878}
879
Manuel Pégourié-Gonnardd90faf92020-05-19 12:38:31 +0200880component_test_ecp_no_internal_rng () {
881 msg "build: Default plus ECP_NO_INTERNAL_RNG minus DRBG modules"
882 scripts/config.pl set MBEDTLS_ECP_NO_INTERNAL_RNG
883 scripts/config.pl unset MBEDTLS_CTR_DRBG_C
884 scripts/config.pl unset MBEDTLS_HMAC_DRBG_C
885 scripts/config.pl unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
886 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_C # requires a DRBG
887 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA Crypto
888
889 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
890 make
891
892 msg "test: ECP_NO_INTERNAL_RNG, no DRBG module"
893 make test
894
895 # no SSL tests as they all depend on having a DRBG
896}
897
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100898component_test_full_cmake_clang () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100899 msg "build: cmake, full config, clang" # ~ 50s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100900 scripts/config.pl full
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100901 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check -D ENABLE_TESTING=On .
902 make
903
904 msg "test: main suites (full config)" # ~ 5s
905 make test
906
907 msg "test: ssl-opt.sh default (full config)" # ~ 1s
908 if_build_succeeded tests/ssl-opt.sh -f Default
909
Andres Amaya Garcia0a0e5b12019-01-08 21:42:27 +0000910 msg "test: compat.sh RC4, DES, 3DES & NULL (full config)" # ~ 2 min
Andres Amaya Garciafea3d0a2019-02-19 20:20:57 +0000911 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'
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100912}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100913
Gilles Peskineadaaddb2020-04-28 14:04:28 +0200914component_test_default_no_deprecated () {
915 # Test that removing the deprecated features from the default
916 # configuration leaves something consistent.
917 msg "build: make, default + MBEDTLS_DEPRECATED_REMOVED" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100918 scripts/config.pl set MBEDTLS_DEPRECATED_REMOVED
Gilles Peskineadaaddb2020-04-28 14:04:28 +0200919 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra'
920
921 msg "test: make, default + MBEDTLS_DEPRECATED_REMOVED" # ~ 5s
922 make test
923}
924
925component_test_full_deprecated_warning () {
926 # Test that there is nothing deprecated in the full configuraration.
927 # A deprecated feature would trigger a warning (made fatal) from
928 # MBEDTLS_DEPRECATED_WARNING.
929 msg "build: make, full + MBEDTLS_DEPRECATED_WARNING" # ~ 30s
930 scripts/config.pl full
931 scripts/config.pl unset MBEDTLS_DEPRECATED_REMOVED
932 scripts/config.pl set MBEDTLS_DEPRECATED_WARNING
933 # There are currently no tests for any deprecated feature.
934 # If some are added, 'make test' would trigger warnings here.
935 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra'
936
937 msg "test: make, full + MBEDTLS_DEPRECATED_WARNING" # ~ 5s
938 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100939}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100940
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100941component_test_depends_curves () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100942 msg "test/build: curves.pl (gcc)" # ~ 4 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100943 record_status tests/scripts/curves.pl
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100944}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100945
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100946component_test_depends_hashes () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100947 msg "test/build: depends-hashes.pl (gcc)" # ~ 2 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100948 record_status tests/scripts/depends-hashes.pl
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100949}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100950
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100951component_test_depends_pkalgs () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100952 msg "test/build: depends-pkalgs.pl (gcc)" # ~ 2 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100953 record_status tests/scripts/depends-pkalgs.pl
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100954}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100955
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100956component_build_key_exchanges () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100957 msg "test/build: key-exchanges (gcc)" # ~ 1 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100958 record_status tests/scripts/key-exchanges.pl
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100959}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100960
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100961component_build_default_make_gcc () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100962 msg "build: Unix make, -Os (gcc)" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100963 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100964}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100965
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100966component_test_no_platform () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100967 # Full configuration build, without platform support, file IO and net sockets.
968 # This should catch missing mbedtls_printf definitions, and by disabling file
969 # IO, it should catch missing '#include <stdio.h>'
970 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100971 scripts/config.pl full
972 scripts/config.pl unset MBEDTLS_PLATFORM_C
973 scripts/config.pl unset MBEDTLS_NET_C
974 scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
975 scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
976 scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
977 scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
978 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
979 scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
Gilles Peskinea21c5e92020-04-28 10:41:20 +0200980 scripts/config.pl unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100981 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100982 scripts/config.pl unset MBEDTLS_FS_IO
983 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
984 # to re-enable platform integration features otherwise disabled in C99 builds
Gilles Peskinec9247122019-09-20 19:23:10 +0200985 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -Os -D_DEFAULT_SOURCE' lib programs
986 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os' test
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100987}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100988
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100989component_build_no_std_function () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100990 # catch compile bugs in _uninit functions
991 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100992 scripts/config.pl full
993 scripts/config.pl set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
994 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskinea21c5e92020-04-28 10:41:20 +0200995 scripts/config.pl unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskinec9247122019-09-20 19:23:10 +0200996 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100997}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100998
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100999component_build_no_ssl_srv () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001000 msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001001 scripts/config.pl full
1002 scripts/config.pl unset MBEDTLS_SSL_SRV_C
Gilles Peskinec9247122019-09-20 19:23:10 +02001003 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001004}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001005
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001006component_build_no_ssl_cli () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001007 msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001008 scripts/config.pl full
1009 scripts/config.pl unset MBEDTLS_SSL_CLI_C
Gilles Peskinec9247122019-09-20 19:23:10 +02001010 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001011}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001012
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001013component_build_no_sockets () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001014 # Note, C99 compliance can also be tested with the sockets support disabled,
1015 # as that requires a POSIX platform (which isn't the same as C99).
1016 msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001017 scripts/config.pl full
1018 scripts/config.pl unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
1019 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
Gilles Peskinec9247122019-09-20 19:23:10 +02001020 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1 -std=c99 -pedantic' lib
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001021}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001022
Andrzej Kurek9a461a12019-09-05 09:27:47 -04001023component_test_memory_buffer_allocator_backtrace () {
1024 msg "build: default config with memory buffer allocator and backtrace enabled"
Hanno Beckerf5baaaa2019-02-26 14:34:13 +00001025 scripts/config.pl set MBEDTLS_MEMORY_BUFFER_ALLOC_C
Andrzej Kurek9a461a12019-09-05 09:27:47 -04001026 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
Hanno Beckerf5baaaa2019-02-26 14:34:13 +00001027 scripts/config.pl set MBEDTLS_MEMORY_BACKTRACE
Andrzej Kurek9b1c2482019-09-10 02:58:34 -04001028 scripts/config.pl set MBEDTLS_MEMORY_DEBUG
Andrzej Kurek9a461a12019-09-05 09:27:47 -04001029 CC=gcc cmake .
1030 make
1031
1032 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C and MBEDTLS_MEMORY_BACKTRACE"
1033 make test
1034}
1035
1036component_test_memory_buffer_allocator () {
1037 msg "build: default config with memory buffer allocator"
1038 scripts/config.pl set MBEDTLS_MEMORY_BUFFER_ALLOC_C
Hanno Becker7aad93c2019-06-03 16:35:02 +01001039 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
Hanno Beckerf5baaaa2019-02-26 14:34:13 +00001040 CC=gcc cmake .
1041 make
1042
1043 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C"
1044 make test
1045
1046 msg "test: ssl-opt.sh, MBEDTLS_MEMORY_BUFFER_ALLOC_C"
Andrzej Kurek6addfdd2019-09-05 10:09:37 -04001047 # MBEDTLS_MEMORY_BUFFER_ALLOC is slow. Skip tests that tend to time out.
1048 if_build_succeeded tests/ssl-opt.sh -e '^DTLS proxy'
Hanno Beckerf5baaaa2019-02-26 14:34:13 +00001049}
1050
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001051component_test_no_max_fragment_length () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001052 msg "build: default config except MFL extension (ASan build)" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001053 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
1054 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1055 make
1056
1057 msg "test: ssl-opt.sh, MFL-related tests"
1058 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length"
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001059}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001060
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001061component_test_null_entropy () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001062 msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)"
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001063 scripts/config.pl set MBEDTLS_TEST_NULL_ENTROPY
1064 scripts/config.pl set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
1065 scripts/config.pl set MBEDTLS_ENTROPY_C
1066 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskinea21c5e92020-04-28 10:41:20 +02001067 scripts/config.pl unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001068 scripts/config.pl unset MBEDTLS_ENTROPY_HARDWARE_ALT
1069 scripts/config.pl unset MBEDTLS_HAVEGE_C
Gilles Peskine4e7b3232019-01-06 19:48:30 +00001070 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan -D UNSAFE_BUILD=ON .
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001071 make
1072
1073 msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)"
1074 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001075}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001076
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001077component_test_platform_calloc_macro () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001078 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001079 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
1080 scripts/config.pl set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
1081 scripts/config.pl set MBEDTLS_PLATFORM_FREE_MACRO free
1082 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1083 make
1084
1085 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
1086 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001087}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001088
Gilles Peskine0981a5d2019-09-17 19:04:38 +02001089component_test_malloc_0_null () {
1090 msg "build: malloc(0) returns NULL (ASan+UBSan build)"
1091 scripts/config.pl full
1092 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
1093 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'
1094
1095 msg "test: malloc(0) returns NULL (ASan+UBSan build)"
1096 make test
1097
1098 msg "selftest: malloc(0) returns NULL (ASan+UBSan build)"
1099 # Just the calloc selftest. "make test" ran the others as part of the
1100 # test suites.
1101 if_build_succeeded programs/test/selftest calloc
1102}
1103
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001104component_test_make_shared () {
Gilles Peskine770ad7e2019-01-08 23:19:08 +01001105 msg "build/test: make shared" # ~ 40s
1106 make SHARED=1 all check
Gilles Peskine950de1e2019-07-03 20:43:32 +02001107 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001108}
1109
Gilles Peskine17ecb242019-07-03 20:43:05 +02001110component_test_cmake_shared () {
1111 msg "build/test: cmake shared" # ~ 2min
1112 cmake -DUSE_SHARED_MBEDTLS_LIBRARY=On .
1113 make
Gilles Peskine950de1e2019-07-03 20:43:32 +02001114 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskine17ecb242019-07-03 20:43:05 +02001115 make test
1116}
1117
Gilles Peskinefa0e8b52019-09-20 19:56:06 +02001118test_build_opt () {
1119 info=$1 cc=$2; shift 2
1120 for opt in "$@"; do
1121 msg "build/test: $cc $opt, $info" # ~ 30s
1122 make CC="$cc" CFLAGS="$opt -Wall -Wextra -Werror"
1123 # We're confident enough in compilers to not run _all_ the tests,
1124 # but at least run the unit tests. In particular, runs with
1125 # optimizations use inline assembly whereas runs with -O0
1126 # skip inline assembly.
1127 make test # ~30s
1128 make clean
1129 done
1130}
1131
1132component_test_clang_opt () {
1133 scripts/config.pl full
1134 test_build_opt 'full config' clang -O0 -Os -O2
1135}
1136
1137component_test_gcc_opt () {
1138 scripts/config.pl full
1139 test_build_opt 'full config' gcc -O0 -Os -O2
1140}
1141
Gilles Peskinef852f5f2019-07-03 20:42:16 +02001142component_build_mbedtls_config_file () {
1143 msg "build: make with MBEDTLS_CONFIG_FILE" # ~40s
1144 # Use the full config so as to catch a maximum of places where
1145 # the check of MBEDTLS_CONFIG_FILE might be missing.
1146 scripts/config.pl full
1147 sed 's!"check_config.h"!"mbedtls/check_config.h"!' <"$CONFIG_H" >full_config.h
1148 echo '#error "MBEDTLS_CONFIG_FILE is not working"' >"$CONFIG_H"
1149 make CFLAGS="-I '$PWD' -DMBEDTLS_CONFIG_FILE='\"full_config.h\"'"
1150 rm -f full_config.h
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001151}
1152
Gilles Peskine3fbdd212019-01-08 23:33:45 +01001153component_test_m32_o0 () {
1154 # Build once with -O0, to compile out the i386 specific inline assembly
1155 msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
1156 scripts/config.pl full
Gilles Peskinec20a4052019-10-21 17:11:33 +02001157 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O0" LDFLAGS="-m32 $ASAN_CFLAGS"
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001158
Gilles Peskine3fbdd212019-01-08 23:33:45 +01001159 msg "test: i386, make, gcc -O0 (ASan build)"
1160 make test
1161}
1162support_test_m32_o0 () {
1163 case $(uname -m) in
1164 *64*) true;;
1165 *) false;;
1166 esac
1167}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001168
Gilles Peskine3fbdd212019-01-08 23:33:45 +01001169component_test_m32_o1 () {
1170 # Build again with -O1, to compile in the i386 specific inline assembly
1171 msg "build: i386, make, gcc -O1 (ASan build)" # ~ 30s
1172 scripts/config.pl full
Gilles Peskinec20a4052019-10-21 17:11:33 +02001173 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O1" LDFLAGS="-m32 $ASAN_CFLAGS"
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001174
Gilles Peskine3fbdd212019-01-08 23:33:45 +01001175 msg "test: i386, make, gcc -O1 (ASan build)"
1176 make test
Gilles Peskine11064292019-04-08 16:58:02 +02001177
1178 msg "test ssl-opt.sh, i386, make, gcc-O1"
1179 if_build_succeeded tests/ssl-opt.sh
Gilles Peskine3fbdd212019-01-08 23:33:45 +01001180}
1181support_test_m32_o1 () {
1182 support_test_m32_o0 "$@"
1183}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001184
Gilles Peskine3fbdd212019-01-08 23:33:45 +01001185component_test_mx32 () {
1186 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
1187 scripts/config.pl full
Gilles Peskined535f4d2019-06-07 14:50:09 +02001188 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32' LDFLAGS='-mx32'
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001189
Gilles Peskine3fbdd212019-01-08 23:33:45 +01001190 msg "test: 64-bit ILP32, make, gcc"
1191 make test
1192}
1193support_test_mx32 () {
1194 case $(uname -m) in
1195 amd64|x86_64) true;;
1196 *) false;;
1197 esac
1198}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001199
Peter Kolbus16015dd2018-12-27 06:59:04 -06001200component_test_min_mpi_window_size () {
1201 msg "build: Default + MBEDTLS_MPI_WINDOW_SIZE=1 (ASan build)" # ~ 10s
1202 scripts/config.pl set MBEDTLS_MPI_WINDOW_SIZE 1
1203 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1204 make
1205
1206 msg "test: MBEDTLS_MPI_WINDOW_SIZE=1 - main suites (inc. selftests) (ASan build)" # ~ 10s
1207 make test
1208}
1209
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001210component_test_have_int32 () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001211 msg "build: gcc, force 32-bit bignum limbs"
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001212 scripts/config.pl unset MBEDTLS_HAVE_ASM
1213 scripts/config.pl unset MBEDTLS_AESNI_C
1214 scripts/config.pl unset MBEDTLS_PADLOCK_C
1215 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
1216
1217 msg "test: gcc, force 32-bit bignum limbs"
1218 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001219}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001220
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001221component_test_have_int64 () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001222 msg "build: gcc, force 64-bit bignum limbs"
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001223 scripts/config.pl unset MBEDTLS_HAVE_ASM
1224 scripts/config.pl unset MBEDTLS_AESNI_C
1225 scripts/config.pl unset MBEDTLS_PADLOCK_C
1226 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
1227
1228 msg "test: gcc, force 64-bit bignum limbs"
1229 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001230}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001231
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001232component_build_arm_none_eabi_gcc () {
Gilles Peskine81b60fb2020-04-30 23:11:54 +02001233 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1" # ~ 10s
Manuel Pégourié-Gonnard59bc9a12019-04-29 12:44:12 +02001234 scripts/config.pl baremetal
Gilles Peskine009908b2020-04-30 22:54:00 +02001235 make CC="${ARM_NONE_EABI_GCC_PREFIX}gcc" AR="${ARM_NONE_EABI_GCC_PREFIX}ar" LD="${ARM_NONE_EABI_GCC_PREFIX}ld" CFLAGS='-Werror -Wall -Wextra -O1' lib
Gilles Peskine81b60fb2020-04-30 23:11:54 +02001236
1237 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1"
1238 ${ARM_NONE_EABI_GCC_PREFIX}size library/*.o
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001239}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001240
Gilles Peskinea27af6f2020-04-30 23:22:55 +02001241component_build_arm_none_eabi_gcc_arm5vte () {
Gilles Peskine81b60fb2020-04-30 23:11:54 +02001242 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=arm5vte" # ~ 10s
Gilles Peskinea27af6f2020-04-30 23:22:55 +02001243 scripts/config.pl baremetal
1244 # Build for a target platform that's close to what Debian uses
1245 # for its "armel" distribution (https://wiki.debian.org/ArmEabiPort).
1246 # See https://github.com/ARMmbed/mbedtls/pull/2169 and comments.
1247 # It would be better to build with arm-linux-gnueabi-gcc but
1248 # we don't have that on our CI at this time.
1249 make CC="${ARM_NONE_EABI_GCC_PREFIX}gcc" AR="${ARM_NONE_EABI_GCC_PREFIX}ar" CFLAGS='-Werror -Wall -Wextra -march=armv5te -O1' LDFLAGS='-march=armv5te' SHELL='sh -x' lib
Gilles Peskine81b60fb2020-04-30 23:11:54 +02001250
1251 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=armv5te -O1"
1252 ${ARM_NONE_EABI_GCC_PREFIX}size library/*.o
Gilles Peskinea27af6f2020-04-30 23:22:55 +02001253}
1254
Gilles Peskine4fb7a2f2020-04-30 23:00:53 +02001255component_build_arm_none_eabi_gcc_m0plus () {
1256 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus" # ~ 10s
1257 scripts/config.pl baremetal
1258 make CC="${ARM_NONE_EABI_GCC_PREFIX}gcc" AR="${ARM_NONE_EABI_GCC_PREFIX}ar" LD="${ARM_NONE_EABI_GCC_PREFIX}ld" CFLAGS='-Werror -Wall -Wextra -mthumb -mcpu=cortex-m0plus -Os' lib
Gilles Peskine81b60fb2020-04-30 23:11:54 +02001259
1260 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus -Os"
1261 ${ARM_NONE_EABI_GCC_PREFIX}size library/*.o
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001262}
1263
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001264component_build_arm_none_eabi_gcc_no_udbl_division () {
Gilles Peskinef1709bb2020-04-30 18:19:32 +02001265 msg "build: ${ARM_NONE_EABI_GCC_PREFIX} -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
Manuel Pégourié-Gonnard59bc9a12019-04-29 12:44:12 +02001266 scripts/config.pl baremetal
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001267 scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
Gilles Peskinef1709bb2020-04-30 18:19:32 +02001268 make CC="${ARM_NONE_EABI_GCC_PREFIX}gcc" AR="${ARM_NONE_EABI_GCC_PREFIX}ar" LD="${ARM_NONE_EABI_GCC_PREFIX}ld" CFLAGS='-Werror -Wall -Wextra' lib
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001269 echo "Checking that software 64-bit division is not required"
Gilles Peskine30bc3852019-01-09 23:25:25 +01001270 if_build_succeeded not grep __aeabi_uldiv library/*.o
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001271}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001272
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001273component_build_armcc () {
Gilles Peskine81b60fb2020-04-30 23:11:54 +02001274 msg "build: ARM Compiler 5"
Manuel Pégourié-Gonnard59bc9a12019-04-29 12:44:12 +02001275 scripts/config.pl baremetal
Gilles Peskine53084872019-01-09 23:13:54 +01001276 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
Gilles Peskine81b60fb2020-04-30 23:11:54 +02001277
1278 msg "size: ARM Compiler 5"
1279 "$ARMC5_FROMELF" -z library/*.o
1280
Gilles Peskine53084872019-01-09 23:13:54 +01001281 make clean
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001282
Gilles Peskine53084872019-01-09 23:13:54 +01001283 # ARM Compiler 6 - Target ARMv7-A
1284 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-a"
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001285
Gilles Peskine53084872019-01-09 23:13:54 +01001286 # ARM Compiler 6 - Target ARMv7-M
1287 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m"
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001288
Gilles Peskine53084872019-01-09 23:13:54 +01001289 # ARM Compiler 6 - Target ARMv8-A - AArch32
1290 armc6_build_test "--target=arm-arm-none-eabi -march=armv8.2-a"
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001291
Gilles Peskine53084872019-01-09 23:13:54 +01001292 # ARM Compiler 6 - Target ARMv8-M
1293 armc6_build_test "--target=arm-arm-none-eabi -march=armv8-m.main"
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001294
Gilles Peskine53084872019-01-09 23:13:54 +01001295 # ARM Compiler 6 - Target ARMv8-A - AArch64
1296 armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a"
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001297}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001298
Andres Amaya Garciabb13e3b2018-12-05 22:03:56 +00001299component_build_ssl_hw_record_accel() {
1300 msg "build: default config with MBEDTLS_SSL_HW_RECORD_ACCEL enabled"
1301 scripts/config.pl set MBEDTLS_SSL_HW_RECORD_ACCEL
1302 make CFLAGS='-Werror -O1'
1303}
1304
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001305component_test_allow_sha1 () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001306 msg "build: allow SHA1 in certificates by default"
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001307 scripts/config.pl set MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
1308 make CFLAGS='-Werror -Wall -Wextra'
1309 msg "test: allow SHA1 in certificates by default"
1310 make test
1311 if_build_succeeded tests/ssl-opt.sh -f SHA-1
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001312}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001313
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001314component_build_mingw () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001315 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001316 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
1317
1318 # note Make tests only builds the tests, but doesn't run them
1319 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror' WINDOWS_BUILD=1 tests
1320 make WINDOWS_BUILD=1 clean
1321
1322 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
1323 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
1324 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
1325 make WINDOWS_BUILD=1 clean
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001326}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001327
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001328component_test_memsan () {
Gilles Peskine770ad7e2019-01-08 23:19:08 +01001329 msg "build: MSan (clang)" # ~ 1 min 20s
1330 scripts/config.pl unset MBEDTLS_AESNI_C # memsan doesn't grok asm
1331 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
1332 make
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001333
Gilles Peskine770ad7e2019-01-08 23:19:08 +01001334 msg "test: main suites (MSan)" # ~ 10s
1335 make test
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001336
Gilles Peskine770ad7e2019-01-08 23:19:08 +01001337 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
1338 if_build_succeeded tests/ssl-opt.sh
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001339
Gilles Peskine770ad7e2019-01-08 23:19:08 +01001340 # Optional part(s)
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001341
Gilles Peskine770ad7e2019-01-08 23:19:08 +01001342 if [ "$MEMORY" -gt 0 ]; then
1343 msg "test: compat.sh (MSan)" # ~ 6 min 20s
1344 if_build_succeeded tests/compat.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001345 fi
1346}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001347
Gilles Peskine9f553642019-01-10 00:11:42 +01001348component_test_valgrind () {
Gilles Peskine770ad7e2019-01-08 23:19:08 +01001349 msg "build: Release (clang)"
1350 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
1351 make
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001352
Gilles Peskine770ad7e2019-01-08 23:19:08 +01001353 msg "test: main suites valgrind (Release)"
1354 make memcheck
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001355
Gilles Peskine26cae712019-04-08 17:00:56 +02001356 # Optional parts (slow; currently broken on OS X because programs don't
1357 # seem to receive signals under valgrind on OS X).
Gilles Peskine770ad7e2019-01-08 23:19:08 +01001358 if [ "$MEMORY" -gt 0 ]; then
1359 msg "test: ssl-opt.sh --memcheck (Release)"
1360 if_build_succeeded tests/ssl-opt.sh --memcheck
1361 fi
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001362
Gilles Peskine770ad7e2019-01-08 23:19:08 +01001363 if [ "$MEMORY" -gt 1 ]; then
1364 msg "test: compat.sh --memcheck (Release)"
1365 if_build_succeeded tests/compat.sh --memcheck
1366 fi
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001367}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001368
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001369component_test_cmake_out_of_source () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001370 msg "build: cmake 'out-of-source' build"
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001371 MBEDTLS_ROOT_DIR="$PWD"
1372 mkdir "$OUT_OF_SOURCE_DIR"
1373 cd "$OUT_OF_SOURCE_DIR"
1374 cmake "$MBEDTLS_ROOT_DIR"
1375 make
1376
1377 msg "test: cmake 'out-of-source' build"
1378 make test
1379 # Test an SSL option that requires an auxiliary script in test/scripts/.
1380 # Also ensure that there are no error messages such as
1381 # "No such file or directory", which would indicate that some required
1382 # file is missing (ssl-opt.sh tolerates the absence of some files so
1383 # may exit with status 0 but emit errors).
1384 if_build_succeeded ./tests/ssl-opt.sh -f 'Fallback SCSV: beginning of list' 2>ssl-opt.err
1385 if [ -s ssl-opt.err ]; then
1386 cat ssl-opt.err >&2
1387 record_status [ ! -s ssl-opt.err ]
1388 rm ssl-opt.err
1389 fi
1390 cd "$MBEDTLS_ROOT_DIR"
1391 rm -rf "$OUT_OF_SOURCE_DIR"
1392 unset MBEDTLS_ROOT_DIR
1393}
Andres AGdc192212016-08-31 17:33:13 +01001394
Gilles Peskine192c72f2017-12-21 15:59:21 +01001395
1396
1397################################################################
1398#### Termination
1399################################################################
1400
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001401post_report () {
1402 msg "Done, cleaning up"
1403 cleanup
1404
1405 final_report
1406}
1407
1408
1409
1410################################################################
1411#### Run all the things
1412################################################################
1413
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001414# Run one component and clean up afterwards.
1415run_component () {
Gilles Peskine72adb432019-01-02 18:57:02 +01001416 # Back up the configuration in case the component modifies it.
1417 # The cleanup function will restore it.
1418 cp -p "$CONFIG_H" "$CONFIG_BAK"
Gilles Peskine11ddca62018-12-04 12:49:28 +01001419 current_component="$1"
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001420 "$@"
1421 cleanup
1422}
1423
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001424# Preliminary setup
1425pre_check_environment
1426pre_initialize_variables
1427pre_parse_command_line "$@"
1428
1429pre_check_git
1430build_status=0
1431if [ $KEEP_GOING -eq 1 ]; then
1432 pre_setup_keep_going
1433else
1434 record_status () {
1435 "$@"
1436 }
1437fi
1438pre_print_configuration
1439pre_check_tools
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001440cleanup
Gilles Peskine7c652162017-12-11 00:01:40 +01001441
Gilles Peskineeb39b9b2019-01-08 23:41:00 +01001442# Run the requested tests.
Gilles Peskine6e984232018-11-27 21:37:53 +01001443for component in $RUN_COMPONENTS; do
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001444 run_component "component_$component"
1445done
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001446
1447# We're done.
1448post_report