blob: 252fa7da3e0d64c2eccfcd9cc5213a0e3ef75acc [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 Peskine57db6ff2019-01-08 22:04:31 +0100284 msg "build: ARM Compiler 6 ($FLAGS), make"
285 ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \
286 WARNING_CFLAGS='-xc -std=c99' make lib
287 make clean
288}
Andres AGa5cd9732016-10-17 15:23:10 +0100289
Andres AGd9eba4b2016-08-26 14:42:14 +0100290err_msg()
291{
292 echo "$1" >&2
293}
294
295check_tools()
296{
297 for TOOL in "$@"; do
Andres AG98393602017-01-31 17:04:45 +0000298 if ! `type "$TOOL" >/dev/null 2>&1`; then
Andres AGd9eba4b2016-08-26 14:42:14 +0100299 err_msg "$TOOL not found!"
300 exit 1
301 fi
302 done
303}
304
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100305pre_parse_command_line () {
Gilles Peskineeb39b9b2019-01-08 23:41:00 +0100306 COMMAND_LINE_COMPONENTS=
Gilles Peskineff7238f2019-01-10 00:05:18 +0100307 all_except=0
Gilles Peskine53084872019-01-09 23:13:54 +0100308 no_armcc=
Gilles Peskine6e984232018-11-27 21:37:53 +0100309
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100310 while [ $# -gt 0 ]; do
311 case "$1" in
Gilles Peskinef1709bb2020-04-30 18:19:32 +0200312 --arm-none-eabi-gcc-prefix) shift; ARM_NONE_EABI_GCC_PREFIX="$1";;
Gilles Peskine53084872019-01-09 23:13:54 +0100313 --armcc) no_armcc=;;
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100314 --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
315 --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
Gilles Peskineeb39b9b2019-01-08 23:41:00 +0100316 --except) all_except=1;;
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100317 --force|-f) FORCE=1;;
318 --gnutls-cli) shift; GNUTLS_CLI="$1";;
319 --gnutls-legacy-cli) shift; GNUTLS_LEGACY_CLI="$1";;
320 --gnutls-legacy-serv) shift; GNUTLS_LEGACY_SERV="$1";;
321 --gnutls-serv) shift; GNUTLS_SERV="$1";;
322 --help|-h) usage; exit;;
323 --keep-going|-k) KEEP_GOING=1;;
Gilles Peskineb3241cb2019-01-08 23:44:07 +0100324 --list-all-components) printf '%s\n' $ALL_COMPONENTS; exit;;
325 --list-components) printf '%s\n' $SUPPORTED_COMPONENTS; exit;;
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100326 --memory|-m) MEMORY=1;;
Gilles Peskine53084872019-01-09 23:13:54 +0100327 --no-armcc) no_armcc=1;;
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100328 --no-force) FORCE=0;;
329 --no-keep-going) KEEP_GOING=0;;
330 --no-memory) MEMORY=0;;
331 --no-yotta) YOTTA=0;;
332 --openssl) shift; OPENSSL="$1";;
333 --openssl-legacy) shift; OPENSSL_LEGACY="$1";;
334 --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
335 --random-seed) unset SEED;;
336 --release-test|-r) SEED=1;;
337 --seed|-s) shift; SEED="$1";;
338 --yotta) YOTTA=1;;
Gilles Peskine91bd8b72019-01-08 23:01:34 +0100339 -*)
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100340 echo >&2 "Unknown option: $1"
341 echo >&2 "Run $0 --help for usage."
342 exit 120
343 ;;
Gilles Peskineeb39b9b2019-01-08 23:41:00 +0100344 *) COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS $1";;
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100345 esac
346 shift
347 done
Gilles Peskine91bd8b72019-01-08 23:01:34 +0100348
Gilles Peskineff7238f2019-01-10 00:05:18 +0100349 # With no list of components, run everything.
Gilles Peskineeb39b9b2019-01-08 23:41:00 +0100350 if [ -z "$COMMAND_LINE_COMPONENTS" ]; then
351 all_except=1
352 fi
353
Gilles Peskine53084872019-01-09 23:13:54 +0100354 # --no-armcc is a legacy option. The modern way is --except '*_armcc*'.
355 # Ignore it if components are listed explicitly on the command line.
Gilles Peskineff7238f2019-01-10 00:05:18 +0100356 if [ -n "$no_armcc" ] && [ $all_except -eq 1 ]; then
Gilles Peskine53084872019-01-09 23:13:54 +0100357 COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS *_armcc*"
358 # --no-armcc also disables yotta.
359 COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS *_yotta*"
360 fi
361
Gilles Peskineeb39b9b2019-01-08 23:41:00 +0100362 # Build the list of components to run.
Gilles Peskineff7238f2019-01-10 00:05:18 +0100363 RUN_COMPONENTS=
364 for component in $SUPPORTED_COMPONENTS; do
365 if is_component_included "$component"; [ $? -eq $all_except ]; then
366 RUN_COMPONENTS="$RUN_COMPONENTS $component"
367 fi
368 done
Gilles Peskineeb39b9b2019-01-08 23:41:00 +0100369
370 unset all_except
Gilles Peskine53084872019-01-09 23:13:54 +0100371 unset no_armcc
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100372}
SimonB2e23c822016-04-16 21:54:39 +0100373
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100374pre_check_git () {
375 if [ $FORCE -eq 1 ]; then
Gilles Peskinec7800952019-01-09 23:14:09 +0100376 rm -rf "$OUT_OF_SOURCE_DIR"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100377 if [ $YOTTA -eq 1 ]; then
Gilles Peskinec7800952019-01-09 23:14:09 +0100378 rm -rf yotta/module
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100379 fi
380 git checkout-index -f -q $CONFIG_H
381 cleanup
382 else
383
384 if [ $YOTTA -ne 0 ] && [ -d yotta/module ]; then
385 err_msg "Warning - there is an existing yotta module in the directory 'yotta/module'"
386 echo "You can either delete your work and retry, or force the test to overwrite the"
387 echo "test by rerunning the script as: $0 --force"
388 exit 1
389 fi
390
391 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
392 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
393 echo "You can either delete this directory manually, or force the test by rerunning"
394 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
395 exit 1
396 fi
397
Gilles Peskinec9663b12019-01-09 22:30:01 +0100398 if ! git diff --quiet include/mbedtls/config.h; then
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100399 err_msg "Warning - the configuration file 'include/mbedtls/config.h' has been edited. "
400 echo "You can either delete or preserve your work, or force the test by rerunning the"
401 echo "script as: $0 --force"
402 exit 1
403 fi
Gilles Peskineda519252017-11-30 13:22:04 +0100404 fi
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100405}
SimonB2e23c822016-04-16 21:54:39 +0100406
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100407pre_setup_keep_going () {
Gilles Peskine7c652162017-12-11 00:01:40 +0100408 failure_summary=
409 failure_count=0
410 start_red=
411 end_color=
412 if [ -t 1 ]; then
Gilles Peskine9736b9d2018-01-02 21:54:17 +0100413 case "${TERM:-}" in
Gilles Peskine7c652162017-12-11 00:01:40 +0100414 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
415 start_red=$(printf '\033[31m')
416 end_color=$(printf '\033[0m')
417 ;;
418 esac
419 fi
420 record_status () {
421 if "$@"; then
422 last_status=0
423 else
424 last_status=$?
425 text="$current_section: $* -> $last_status"
426 failure_summary="$failure_summary
427$text"
428 failure_count=$((failure_count + 1))
429 echo "${start_red}^^^^$text^^^^${end_color}"
430 fi
431 }
432 make () {
433 case "$*" in
434 *test|*check)
435 if [ $build_status -eq 0 ]; then
436 record_status command make "$@"
437 else
438 echo "(skipped because the build failed)"
439 fi
440 ;;
441 *)
442 record_status command make "$@"
443 build_status=$last_status
444 ;;
445 esac
446 }
447 final_report () {
448 if [ $failure_count -gt 0 ]; then
449 echo
450 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
451 echo "${start_red}FAILED: $failure_count${end_color}$failure_summary"
452 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Jaeden Amero5113bde2018-07-20 16:42:14 +0100453 exit 1
Gilles Peskine7c652162017-12-11 00:01:40 +0100454 elif [ -z "${1-}" ]; then
455 echo "SUCCESS :)"
456 fi
457 if [ -n "${1-}" ]; then
458 echo "Killed by SIG$1."
459 fi
460 }
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100461}
462
Gilles Peskine7c652162017-12-11 00:01:40 +0100463if_build_succeeded () {
464 if [ $build_status -eq 0 ]; then
465 record_status "$@"
466 fi
467}
468
Gilles Peskine30bc3852019-01-09 23:25:25 +0100469# to be used instead of ! for commands run with
470# record_status or if_build_succeeded
471not() {
472 ! "$@"
473}
474
475
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100476pre_print_configuration () {
477 msg "info: $0 configuration"
478 echo "MEMORY: $MEMORY"
479 echo "FORCE: $FORCE"
480 echo "SEED: ${SEED-"UNSET"}"
481 echo "OPENSSL: $OPENSSL"
482 echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
483 echo "GNUTLS_CLI: $GNUTLS_CLI"
484 echo "GNUTLS_SERV: $GNUTLS_SERV"
485 echo "GNUTLS_LEGACY_CLI: $GNUTLS_LEGACY_CLI"
486 echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV"
487 echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
488 echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
489}
Andres AG7770ea82016-10-10 15:46:20 +0100490
Andres AGd9eba4b2016-08-26 14:42:14 +0100491# Make sure the tools we need are available.
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100492pre_check_tools () {
Gilles Peskine541fb1e2019-01-06 22:40:00 +0000493 # Build the list of variables to pass to output_env.sh.
494 set env
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100495
Gilles Peskine541fb1e2019-01-06 22:40:00 +0000496 case " $RUN_COMPONENTS " in
497 # Require OpenSSL and GnuTLS if running any tests (as opposed to
498 # only doing builds). Not all tests run OpenSSL and GnuTLS, but this
499 # is a good enough approximation in practice.
500 *" test_"*)
501 # To avoid setting OpenSSL and GnuTLS for each call to compat.sh
502 # and ssl-opt.sh, we just export the variables they require.
503 export OPENSSL_CMD="$OPENSSL"
504 export GNUTLS_CLI="$GNUTLS_CLI"
505 export GNUTLS_SERV="$GNUTLS_SERV"
506 # Avoid passing --seed flag in every call to ssl-opt.sh
507 if [ -n "${SEED-}" ]; then
508 export SEED
509 fi
510 set "$@" OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY"
511 set "$@" GNUTLS_CLI="$GNUTLS_CLI" GNUTLS_SERV="$GNUTLS_SERV"
512 set "$@" GNUTLS_LEGACY_CLI="$GNUTLS_LEGACY_CLI"
513 set "$@" GNUTLS_LEGACY_SERV="$GNUTLS_LEGACY_SERV"
514 check_tools "$OPENSSL" "$OPENSSL_LEGACY" \
515 "$GNUTLS_CLI" "$GNUTLS_SERV" \
516 "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV"
517 ;;
518 esac
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100519
Gilles Peskine541fb1e2019-01-06 22:40:00 +0000520 case " $RUN_COMPONENTS " in
521 *_doxygen[_\ ]*) check_tools "doxygen" "dot";;
522 esac
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100523
Gilles Peskine541fb1e2019-01-06 22:40:00 +0000524 case " $RUN_COMPONENTS " in
Gilles Peskinef1709bb2020-04-30 18:19:32 +0200525 *_arm_none_eabi_gcc[_\ ]*) check_tools "${ARM_NONE_EABI_GCC_PREFIX}gcc";;
Gilles Peskine541fb1e2019-01-06 22:40:00 +0000526 esac
527
528 case " $RUN_COMPONENTS " in
529 *_mingw[_\ ]*) check_tools "i686-w64-mingw32-gcc";;
530 esac
531
532 case " $RUN_COMPONENTS " in
Gilles Peskine53084872019-01-09 23:13:54 +0100533 *_armcc*|*_yotta*)
Gilles Peskine541fb1e2019-01-06 22:40:00 +0000534 ARMC5_CC="$ARMC5_BIN_DIR/armcc"
535 ARMC5_AR="$ARMC5_BIN_DIR/armar"
536 ARMC6_CC="$ARMC6_BIN_DIR/armclang"
537 ARMC6_AR="$ARMC6_BIN_DIR/armar"
Gilles Peskine53084872019-01-09 23:13:54 +0100538 check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC6_CC" "$ARMC6_AR";;
539 esac
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100540
541 msg "info: output_env.sh"
Gilles Peskine53084872019-01-09 23:13:54 +0100542 case $RUN_COMPONENTS in
543 *_armcc*|*_yotta*)
544 set "$@" ARMC5_CC="$ARMC5_CC" ARMC6_CC="$ARMC6_CC" RUN_ARMCC=1;;
545 *) set "$@" RUN_ARMCC=0;;
546 esac
547 "$@" scripts/output_env.sh
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100548}
Andres AGd9eba4b2016-08-26 14:42:14 +0100549
Gilles Peskine192c72f2017-12-21 15:59:21 +0100550
551
552################################################################
553#### Basic checks
554################################################################
SimonB2e23c822016-04-16 21:54:39 +0100555
556#
557# Test Suites to be executed
558#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200559# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100560# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard61bc57a2014-08-14 11:29:06 +0200561# and/or are more likely to fail than others (eg I use Clang most of the
562# time, so start with a GCC build).
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200563# 2. Minimize total running time, by avoiding useless rebuilds
564#
565# Indicative running times are given for reference.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100566
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100567component_check_recursion () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100568 msg "test: recursion.pl" # < 1s
569 record_status tests/scripts/recursion.pl library/*.c
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100570}
Manuel Pégourié-Gonnardea29d152014-11-20 17:32:33 +0100571
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100572component_check_generated_files () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100573 msg "test: freshness of generated source files" # < 1s
574 record_status tests/scripts/check-generated-files.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100575}
Manuel Pégourié-Gonnardb3b8e432015-02-13 14:52:19 +0000576
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100577component_check_doxy_blocks () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100578 msg "test: doxygen markup outside doxygen blocks" # < 1s
579 record_status tests/scripts/check-doxy-blocks.pl
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100580}
Manuel Pégourié-Gonnardd09a6b52015-04-09 17:19:23 +0200581
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100582component_check_files () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100583 msg "test: check-files.py" # < 1s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100584 record_status tests/scripts/check-files.py
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100585}
Manuel Pégourié-Gonnard77d56bb2015-07-28 15:00:37 +0200586
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100587component_check_names () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100588 msg "test/build: declared and exported names" # < 3s
Gilles Peskinee952fdf2019-05-15 17:52:22 +0200589 record_status tests/scripts/check-names.sh -v
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100590}
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +0200591
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100592component_check_doxygen_warnings () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100593 msg "test: doxygen warnings" # ~ 3s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100594 record_status tests/scripts/doxygen.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100595}
Andres Amaya Garciadd29c2f2017-05-04 11:35:51 +0100596
Simon Butcher948f2642018-07-20 21:27:33 +0100597
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100598################################################################
599#### Build and test many configurations and targets
600################################################################
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100601
k-stachowiak45d0ba12019-06-04 13:14:58 +0200602component_test_large_ecdsa_key_signature () {
603
604 SMALL_MPI_MAX_SIZE=136 # Small enough to interfere with the EC signatures
605
606 msg "build: cmake + MBEDTLS_MPI_MAX_SIZE=${SMALL_MPI_MAX_SIZE}, gcc, ASan" # ~ 1 min 50s
607 scripts/config.pl set MBEDTLS_MPI_MAX_SIZE $SMALL_MPI_MAX_SIZE
608 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
609 make
610
611 INEVITABLY_PRESENT_FILE=Makefile
612 SIGNATURE_FILE="${INEVITABLY_PRESENT_FILE}.sig" # Warning, this is rm -f'ed below
613
614 msg "test: pk_sign secp521r1_prv.der for MBEDTLS_MPI_MAX_SIZE=${SMALL_MPI_MAX_SIZE} (ASan build)" # ~ 5s
615 if_build_succeeded programs/pkey/pk_sign tests/data_files/secp521r1_prv.der $INEVITABLY_PRESENT_FILE
616 rm -f $SIGNATURE_FILE
617}
618
Gilles Peskine1270d322019-04-08 17:00:15 +0200619component_test_default_out_of_box () {
620 msg "build: make, default config (out-of-box)" # ~1min
621 make
622
623 msg "test: main suites make, default config (out-of-box)" # ~10s
624 make test
625
626 msg "selftest: make, default config (out-of-box)" # ~10s
Gilles Peskinebfda0332020-04-23 23:37:45 +0200627 if_build_succeeded programs/test/selftest
Gilles Peskine1270d322019-04-08 17:00:15 +0200628}
629
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100630component_build_yotta () {
Gilles Peskine53084872019-01-09 23:13:54 +0100631 # Note - use of yotta is deprecated, and yotta also requires armcc to be on the
632 # path, and uses whatever version of armcc it finds there.
633 msg "build: create and build yotta module" # ~ 30s
634 record_status tests/scripts/yotta-build.sh
635}
636support_build_yotta () {
637 [ $YOTTA -ne 0 ]
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100638}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100639
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100640component_test_default_cmake_gcc_asan () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100641 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100642 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100643 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +0200644
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100645 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100646 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100647
Gilles Peskinebfda0332020-04-23 23:37:45 +0200648 msg "test: selftest (ASan build)" # ~ 10s
649 if_build_succeeded programs/test/selftest
650
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100651 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
Gilles Peskine7c652162017-12-11 00:01:40 +0100652 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100653
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100654 msg "test: compat.sh (ASan build)" # ~ 6 min
655 if_build_succeeded tests/compat.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100656}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000657
Hanno Becker167ae432019-02-26 14:27:09 +0000658component_test_full_cmake_gcc_asan () {
659 msg "build: full config, cmake, gcc, ASan"
660 scripts/config.pl full
661 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
662 make
663
664 msg "test: main suites (inc. selftests) (full config, ASan build)"
665 make test
666
Gilles Peskinebfda0332020-04-23 23:37:45 +0200667 msg "test: selftest (ASan build)" # ~ 10s
668 if_build_succeeded programs/test/selftest
669
Hanno Becker167ae432019-02-26 14:27:09 +0000670 msg "test: ssl-opt.sh (full config, ASan build)"
671 if_build_succeeded tests/ssl-opt.sh
672
673 msg "test: compat.sh (full config, ASan build)"
674 if_build_succeeded tests/compat.sh
675}
676
Manuel Pégourié-Gonnard51e24942020-01-02 11:45:12 +0100677component_test_zlib_make() {
678 msg "build: zlib enabled, make"
679 scripts/config.pl set MBEDTLS_ZLIB_SUPPORT
680 make ZLIB=1 CFLAGS='-Werror -O1'
681
682 msg "test: main suites (zlib, make)"
683 make test
684
685 msg "test: ssl-opt.sh (zlib, make)"
686 if_build_succeeded tests/ssl-opt.sh
687}
Manuel Pégourié-Gonnard2150fb22020-01-24 10:17:20 +0100688support_test_zlib_make () {
689 base=support_test_zlib_$$
690 cat <<'EOF' > ${base}.c
691#include "zlib.h"
692int main(void) { return 0; }
693EOF
694 gcc -o ${base}.exe ${base}.c -lz 2>/dev/null
695 ret=$?
696 rm -f ${base}.*
697 return $ret
698}
Manuel Pégourié-Gonnard51e24942020-01-02 11:45:12 +0100699
700component_test_zlib_cmake() {
701 msg "build: zlib enabled, cmake"
702 scripts/config.pl set MBEDTLS_ZLIB_SUPPORT
703 cmake -D ENABLE_ZLIB_SUPPORT=On -D CMAKE_BUILD_TYPE:String=Check .
704 make
705
706 msg "test: main suites (zlib, cmake)"
707 make test
708
709 msg "test: ssl-opt.sh (zlib, cmake)"
710 if_build_succeeded tests/ssl-opt.sh
711}
Manuel Pégourié-Gonnard2150fb22020-01-24 10:17:20 +0100712support_test_zlib_cmake () {
713 support_test_zlib_make "$@"
714}
Manuel Pégourié-Gonnard51e24942020-01-02 11:45:12 +0100715
Gilles Peskine3484ed82019-01-08 22:51:19 +0100716component_test_ref_configs () {
717 msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
718 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
719 record_status tests/scripts/test-ref-configs.pl
720}
721
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100722component_test_sslv3 () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100723 msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100724 scripts/config.pl set MBEDTLS_SSL_PROTO_SSL3
725 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
726 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000727
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100728 msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
729 make test
730
731 msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
732 if_build_succeeded tests/compat.sh -m 'tls1 tls1_1 tls1_2 dtls1 dtls1_2'
733 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
734
735 msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
736 if_build_succeeded tests/ssl-opt.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100737}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100738
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100739component_test_no_renegotiation () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100740 msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100741 scripts/config.pl unset MBEDTLS_SSL_RENEGOTIATION
742 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
743 make
744
745 msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
746 make test
747
748 msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
749 if_build_succeeded tests/ssl-opt.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100750}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100751
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100752component_test_rsa_no_crt () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100753 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100754 scripts/config.pl set MBEDTLS_RSA_NO_CRT
755 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
756 make
757
758 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
759 make test
760
761 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
762 if_build_succeeded tests/ssl-opt.sh -f RSA
763
764 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
765 if_build_succeeded tests/compat.sh -t RSA
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100766}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100767
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100768component_test_full_cmake_clang () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100769 msg "build: cmake, full config, clang" # ~ 50s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100770 scripts/config.pl full
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100771 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check -D ENABLE_TESTING=On .
772 make
773
774 msg "test: main suites (full config)" # ~ 5s
775 make test
776
777 msg "test: ssl-opt.sh default (full config)" # ~ 1s
778 if_build_succeeded tests/ssl-opt.sh -f Default
779
Andres Amaya Garcia0a0e5b12019-01-08 21:42:27 +0000780 msg "test: compat.sh RC4, DES, 3DES & NULL (full config)" # ~ 2 min
Andres Amaya Garciafea3d0a2019-02-19 20:20:57 +0000781 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 +0100782}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100783
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100784component_build_deprecated () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100785 msg "build: make, full config + DEPRECATED_WARNING, gcc -O" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100786 scripts/config.pl full
787 scripts/config.pl set MBEDTLS_DEPRECATED_WARNING
788 # Build with -O -Wextra to catch a maximum of issues.
789 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra' lib programs
790 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
791
792 msg "build: make, full config + DEPRECATED_REMOVED, clang -O" # ~ 30s
793 # No cleanup, just tweak the configuration and rebuild
794 make clean
795 scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
796 scripts/config.pl set MBEDTLS_DEPRECATED_REMOVED
797 # Build with -O -Wextra to catch a maximum of issues.
798 make CC=clang CFLAGS='-O -Werror -Wall -Wextra' lib programs
799 make CC=clang CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100800}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100801
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100802component_test_depends_curves () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100803 msg "test/build: curves.pl (gcc)" # ~ 4 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100804 record_status tests/scripts/curves.pl
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100805}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100806
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100807component_test_depends_hashes () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100808 msg "test/build: depends-hashes.pl (gcc)" # ~ 2 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100809 record_status tests/scripts/depends-hashes.pl
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100810}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100811
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100812component_test_depends_pkalgs () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100813 msg "test/build: depends-pkalgs.pl (gcc)" # ~ 2 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100814 record_status tests/scripts/depends-pkalgs.pl
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100815}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100816
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100817component_build_key_exchanges () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100818 msg "test/build: key-exchanges (gcc)" # ~ 1 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100819 record_status tests/scripts/key-exchanges.pl
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100820}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100821
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100822component_build_default_make_gcc () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100823 msg "build: Unix make, -Os (gcc)" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100824 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100825}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100826
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100827component_test_no_platform () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100828 # Full configuration build, without platform support, file IO and net sockets.
829 # This should catch missing mbedtls_printf definitions, and by disabling file
830 # IO, it should catch missing '#include <stdio.h>'
831 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100832 scripts/config.pl full
833 scripts/config.pl unset MBEDTLS_PLATFORM_C
834 scripts/config.pl unset MBEDTLS_NET_C
835 scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
836 scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
837 scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
838 scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
839 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
840 scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
841 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100842 scripts/config.pl unset MBEDTLS_FS_IO
843 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
844 # to re-enable platform integration features otherwise disabled in C99 builds
Gilles Peskinec9247122019-09-20 19:23:10 +0200845 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -Os -D_DEFAULT_SOURCE' lib programs
846 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os' test
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100847}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100848
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100849component_build_no_std_function () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100850 # catch compile bugs in _uninit functions
851 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100852 scripts/config.pl full
853 scripts/config.pl set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
854 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskinec9247122019-09-20 19:23:10 +0200855 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100856}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100857
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100858component_build_no_ssl_srv () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100859 msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100860 scripts/config.pl full
861 scripts/config.pl unset MBEDTLS_SSL_SRV_C
Gilles Peskinec9247122019-09-20 19:23:10 +0200862 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100863}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100864
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100865component_build_no_ssl_cli () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100866 msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100867 scripts/config.pl full
868 scripts/config.pl unset MBEDTLS_SSL_CLI_C
Gilles Peskinec9247122019-09-20 19:23:10 +0200869 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100870}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100871
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100872component_build_no_sockets () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100873 # Note, C99 compliance can also be tested with the sockets support disabled,
874 # as that requires a POSIX platform (which isn't the same as C99).
875 msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100876 scripts/config.pl full
877 scripts/config.pl unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
878 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
Gilles Peskinec9247122019-09-20 19:23:10 +0200879 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1 -std=c99 -pedantic' lib
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100880}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100881
Andrzej Kurek9a461a12019-09-05 09:27:47 -0400882component_test_memory_buffer_allocator_backtrace () {
883 msg "build: default config with memory buffer allocator and backtrace enabled"
Hanno Beckerf5baaaa2019-02-26 14:34:13 +0000884 scripts/config.pl set MBEDTLS_MEMORY_BUFFER_ALLOC_C
Andrzej Kurek9a461a12019-09-05 09:27:47 -0400885 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
Hanno Beckerf5baaaa2019-02-26 14:34:13 +0000886 scripts/config.pl set MBEDTLS_MEMORY_BACKTRACE
Andrzej Kurek9b1c2482019-09-10 02:58:34 -0400887 scripts/config.pl set MBEDTLS_MEMORY_DEBUG
Andrzej Kurek9a461a12019-09-05 09:27:47 -0400888 CC=gcc cmake .
889 make
890
891 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C and MBEDTLS_MEMORY_BACKTRACE"
892 make test
893}
894
895component_test_memory_buffer_allocator () {
896 msg "build: default config with memory buffer allocator"
897 scripts/config.pl set MBEDTLS_MEMORY_BUFFER_ALLOC_C
Hanno Becker7aad93c2019-06-03 16:35:02 +0100898 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
Hanno Beckerf5baaaa2019-02-26 14:34:13 +0000899 CC=gcc cmake .
900 make
901
902 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C"
903 make test
904
905 msg "test: ssl-opt.sh, MBEDTLS_MEMORY_BUFFER_ALLOC_C"
Andrzej Kurek6addfdd2019-09-05 10:09:37 -0400906 # MBEDTLS_MEMORY_BUFFER_ALLOC is slow. Skip tests that tend to time out.
907 if_build_succeeded tests/ssl-opt.sh -e '^DTLS proxy'
Hanno Beckerf5baaaa2019-02-26 14:34:13 +0000908}
909
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100910component_test_no_max_fragment_length () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100911 msg "build: default config except MFL extension (ASan build)" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100912 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
913 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
914 make
915
916 msg "test: ssl-opt.sh, MFL-related tests"
917 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length"
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100918}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100919
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100920component_test_null_entropy () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100921 msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100922 scripts/config.pl set MBEDTLS_TEST_NULL_ENTROPY
923 scripts/config.pl set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
924 scripts/config.pl set MBEDTLS_ENTROPY_C
925 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
926 scripts/config.pl unset MBEDTLS_ENTROPY_HARDWARE_ALT
927 scripts/config.pl unset MBEDTLS_HAVEGE_C
Gilles Peskine4e7b3232019-01-06 19:48:30 +0000928 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan -D UNSAFE_BUILD=ON .
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100929 make
930
931 msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)"
932 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100933}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100934
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100935component_test_platform_calloc_macro () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100936 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100937 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
938 scripts/config.pl set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
939 scripts/config.pl set MBEDTLS_PLATFORM_FREE_MACRO free
940 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
941 make
942
943 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
944 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100945}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100946
Gilles Peskine0981a5d2019-09-17 19:04:38 +0200947component_test_malloc_0_null () {
948 msg "build: malloc(0) returns NULL (ASan+UBSan build)"
949 scripts/config.pl full
950 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
951 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'
952
953 msg "test: malloc(0) returns NULL (ASan+UBSan build)"
954 make test
955
956 msg "selftest: malloc(0) returns NULL (ASan+UBSan build)"
957 # Just the calloc selftest. "make test" ran the others as part of the
958 # test suites.
959 if_build_succeeded programs/test/selftest calloc
960}
961
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100962component_test_make_shared () {
Gilles Peskine770ad7e2019-01-08 23:19:08 +0100963 msg "build/test: make shared" # ~ 40s
964 make SHARED=1 all check
Gilles Peskine950de1e2019-07-03 20:43:32 +0200965 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100966}
967
Gilles Peskine17ecb242019-07-03 20:43:05 +0200968component_test_cmake_shared () {
969 msg "build/test: cmake shared" # ~ 2min
970 cmake -DUSE_SHARED_MBEDTLS_LIBRARY=On .
971 make
Gilles Peskine950de1e2019-07-03 20:43:32 +0200972 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskine17ecb242019-07-03 20:43:05 +0200973 make test
974}
975
Gilles Peskinefa0e8b52019-09-20 19:56:06 +0200976test_build_opt () {
977 info=$1 cc=$2; shift 2
978 for opt in "$@"; do
979 msg "build/test: $cc $opt, $info" # ~ 30s
980 make CC="$cc" CFLAGS="$opt -Wall -Wextra -Werror"
981 # We're confident enough in compilers to not run _all_ the tests,
982 # but at least run the unit tests. In particular, runs with
983 # optimizations use inline assembly whereas runs with -O0
984 # skip inline assembly.
985 make test # ~30s
986 make clean
987 done
988}
989
990component_test_clang_opt () {
991 scripts/config.pl full
992 test_build_opt 'full config' clang -O0 -Os -O2
993}
994
995component_test_gcc_opt () {
996 scripts/config.pl full
997 test_build_opt 'full config' gcc -O0 -Os -O2
998}
999
Gilles Peskinef852f5f2019-07-03 20:42:16 +02001000component_build_mbedtls_config_file () {
1001 msg "build: make with MBEDTLS_CONFIG_FILE" # ~40s
1002 # Use the full config so as to catch a maximum of places where
1003 # the check of MBEDTLS_CONFIG_FILE might be missing.
1004 scripts/config.pl full
1005 sed 's!"check_config.h"!"mbedtls/check_config.h"!' <"$CONFIG_H" >full_config.h
1006 echo '#error "MBEDTLS_CONFIG_FILE is not working"' >"$CONFIG_H"
1007 make CFLAGS="-I '$PWD' -DMBEDTLS_CONFIG_FILE='\"full_config.h\"'"
1008 rm -f full_config.h
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001009}
1010
Gilles Peskine3fbdd212019-01-08 23:33:45 +01001011component_test_m32_o0 () {
1012 # Build once with -O0, to compile out the i386 specific inline assembly
1013 msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
1014 scripts/config.pl full
Gilles Peskinec20a4052019-10-21 17:11:33 +02001015 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O0" LDFLAGS="-m32 $ASAN_CFLAGS"
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001016
Gilles Peskine3fbdd212019-01-08 23:33:45 +01001017 msg "test: i386, make, gcc -O0 (ASan build)"
1018 make test
1019}
1020support_test_m32_o0 () {
1021 case $(uname -m) in
1022 *64*) true;;
1023 *) false;;
1024 esac
1025}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001026
Gilles Peskine3fbdd212019-01-08 23:33:45 +01001027component_test_m32_o1 () {
1028 # Build again with -O1, to compile in the i386 specific inline assembly
1029 msg "build: i386, make, gcc -O1 (ASan build)" # ~ 30s
1030 scripts/config.pl full
Gilles Peskinec20a4052019-10-21 17:11:33 +02001031 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O1" LDFLAGS="-m32 $ASAN_CFLAGS"
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001032
Gilles Peskine3fbdd212019-01-08 23:33:45 +01001033 msg "test: i386, make, gcc -O1 (ASan build)"
1034 make test
Gilles Peskine11064292019-04-08 16:58:02 +02001035
1036 msg "test ssl-opt.sh, i386, make, gcc-O1"
1037 if_build_succeeded tests/ssl-opt.sh
Gilles Peskine3fbdd212019-01-08 23:33:45 +01001038}
1039support_test_m32_o1 () {
1040 support_test_m32_o0 "$@"
1041}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001042
Gilles Peskine3fbdd212019-01-08 23:33:45 +01001043component_test_mx32 () {
1044 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
1045 scripts/config.pl full
Gilles Peskined535f4d2019-06-07 14:50:09 +02001046 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32' LDFLAGS='-mx32'
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001047
Gilles Peskine3fbdd212019-01-08 23:33:45 +01001048 msg "test: 64-bit ILP32, make, gcc"
1049 make test
1050}
1051support_test_mx32 () {
1052 case $(uname -m) in
1053 amd64|x86_64) true;;
1054 *) false;;
1055 esac
1056}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001057
Peter Kolbus16015dd2018-12-27 06:59:04 -06001058component_test_min_mpi_window_size () {
1059 msg "build: Default + MBEDTLS_MPI_WINDOW_SIZE=1 (ASan build)" # ~ 10s
1060 scripts/config.pl set MBEDTLS_MPI_WINDOW_SIZE 1
1061 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1062 make
1063
1064 msg "test: MBEDTLS_MPI_WINDOW_SIZE=1 - main suites (inc. selftests) (ASan build)" # ~ 10s
1065 make test
1066}
1067
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001068component_test_have_int32 () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001069 msg "build: gcc, force 32-bit bignum limbs"
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001070 scripts/config.pl unset MBEDTLS_HAVE_ASM
1071 scripts/config.pl unset MBEDTLS_AESNI_C
1072 scripts/config.pl unset MBEDTLS_PADLOCK_C
1073 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
1074
1075 msg "test: gcc, force 32-bit bignum limbs"
1076 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001077}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001078
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001079component_test_have_int64 () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001080 msg "build: gcc, force 64-bit bignum limbs"
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001081 scripts/config.pl unset MBEDTLS_HAVE_ASM
1082 scripts/config.pl unset MBEDTLS_AESNI_C
1083 scripts/config.pl unset MBEDTLS_PADLOCK_C
1084 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
1085
1086 msg "test: gcc, force 64-bit bignum limbs"
1087 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001088}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001089
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001090component_build_arm_none_eabi_gcc () {
Gilles Peskinef1709bb2020-04-30 18:19:32 +02001091 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}, make" # ~ 10s
Manuel Pégourié-Gonnard59bc9a12019-04-29 12:44:12 +02001092 scripts/config.pl baremetal
Gilles Peskinef1709bb2020-04-30 18:19:32 +02001093 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 Peskine1a2ca722019-01-08 22:35:16 +01001094}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001095
Gilles Peskinea27af6f2020-04-30 23:22:55 +02001096component_build_arm_none_eabi_gcc_arm5vte () {
1097 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=arm5vte, make" # ~ 10s
1098 scripts/config.pl baremetal
1099 # Build for a target platform that's close to what Debian uses
1100 # for its "armel" distribution (https://wiki.debian.org/ArmEabiPort).
1101 # See https://github.com/ARMmbed/mbedtls/pull/2169 and comments.
1102 # It would be better to build with arm-linux-gnueabi-gcc but
1103 # we don't have that on our CI at this time.
1104 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
1105}
1106
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001107component_build_arm_none_eabi_gcc_no_udbl_division () {
Gilles Peskinef1709bb2020-04-30 18:19:32 +02001108 msg "build: ${ARM_NONE_EABI_GCC_PREFIX} -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
Manuel Pégourié-Gonnard59bc9a12019-04-29 12:44:12 +02001109 scripts/config.pl baremetal
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001110 scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
Gilles Peskinef1709bb2020-04-30 18:19:32 +02001111 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 +01001112 echo "Checking that software 64-bit division is not required"
Gilles Peskine30bc3852019-01-09 23:25:25 +01001113 if_build_succeeded not grep __aeabi_uldiv library/*.o
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001114}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001115
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001116component_build_armcc () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001117 msg "build: ARM Compiler 5, make"
Manuel Pégourié-Gonnard59bc9a12019-04-29 12:44:12 +02001118 scripts/config.pl baremetal
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001119
Gilles Peskine53084872019-01-09 23:13:54 +01001120 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
1121 make clean
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001122
Gilles Peskine53084872019-01-09 23:13:54 +01001123 # ARM Compiler 6 - Target ARMv7-A
1124 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-a"
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001125
Gilles Peskine53084872019-01-09 23:13:54 +01001126 # ARM Compiler 6 - Target ARMv7-M
1127 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m"
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001128
Gilles Peskine53084872019-01-09 23:13:54 +01001129 # ARM Compiler 6 - Target ARMv8-A - AArch32
1130 armc6_build_test "--target=arm-arm-none-eabi -march=armv8.2-a"
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001131
Gilles Peskine53084872019-01-09 23:13:54 +01001132 # ARM Compiler 6 - Target ARMv8-M
1133 armc6_build_test "--target=arm-arm-none-eabi -march=armv8-m.main"
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001134
Gilles Peskine53084872019-01-09 23:13:54 +01001135 # ARM Compiler 6 - Target ARMv8-A - AArch64
1136 armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a"
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001137}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001138
Andres Amaya Garciabb13e3b2018-12-05 22:03:56 +00001139component_build_ssl_hw_record_accel() {
1140 msg "build: default config with MBEDTLS_SSL_HW_RECORD_ACCEL enabled"
1141 scripts/config.pl set MBEDTLS_SSL_HW_RECORD_ACCEL
1142 make CFLAGS='-Werror -O1'
1143}
1144
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001145component_test_allow_sha1 () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001146 msg "build: allow SHA1 in certificates by default"
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001147 scripts/config.pl set MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
1148 make CFLAGS='-Werror -Wall -Wextra'
1149 msg "test: allow SHA1 in certificates by default"
1150 make test
1151 if_build_succeeded tests/ssl-opt.sh -f SHA-1
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001152}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001153
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001154component_build_mingw () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001155 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001156 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
1157
1158 # note Make tests only builds the tests, but doesn't run them
1159 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror' WINDOWS_BUILD=1 tests
1160 make WINDOWS_BUILD=1 clean
1161
1162 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
1163 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
1164 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
1165 make WINDOWS_BUILD=1 clean
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001166}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001167
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001168component_test_memsan () {
Gilles Peskine770ad7e2019-01-08 23:19:08 +01001169 msg "build: MSan (clang)" # ~ 1 min 20s
1170 scripts/config.pl unset MBEDTLS_AESNI_C # memsan doesn't grok asm
1171 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
1172 make
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001173
Gilles Peskine770ad7e2019-01-08 23:19:08 +01001174 msg "test: main suites (MSan)" # ~ 10s
1175 make test
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001176
Gilles Peskine770ad7e2019-01-08 23:19:08 +01001177 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
1178 if_build_succeeded tests/ssl-opt.sh
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001179
Gilles Peskine770ad7e2019-01-08 23:19:08 +01001180 # Optional part(s)
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001181
Gilles Peskine770ad7e2019-01-08 23:19:08 +01001182 if [ "$MEMORY" -gt 0 ]; then
1183 msg "test: compat.sh (MSan)" # ~ 6 min 20s
1184 if_build_succeeded tests/compat.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001185 fi
1186}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001187
Gilles Peskine9f553642019-01-10 00:11:42 +01001188component_test_valgrind () {
Gilles Peskine770ad7e2019-01-08 23:19:08 +01001189 msg "build: Release (clang)"
1190 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
1191 make
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001192
Gilles Peskine770ad7e2019-01-08 23:19:08 +01001193 msg "test: main suites valgrind (Release)"
1194 make memcheck
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001195
Gilles Peskine26cae712019-04-08 17:00:56 +02001196 # Optional parts (slow; currently broken on OS X because programs don't
1197 # seem to receive signals under valgrind on OS X).
Gilles Peskine770ad7e2019-01-08 23:19:08 +01001198 if [ "$MEMORY" -gt 0 ]; then
1199 msg "test: ssl-opt.sh --memcheck (Release)"
1200 if_build_succeeded tests/ssl-opt.sh --memcheck
1201 fi
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001202
Gilles Peskine770ad7e2019-01-08 23:19:08 +01001203 if [ "$MEMORY" -gt 1 ]; then
1204 msg "test: compat.sh --memcheck (Release)"
1205 if_build_succeeded tests/compat.sh --memcheck
1206 fi
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001207}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001208
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001209component_test_cmake_out_of_source () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001210 msg "build: cmake 'out-of-source' build"
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001211 MBEDTLS_ROOT_DIR="$PWD"
1212 mkdir "$OUT_OF_SOURCE_DIR"
1213 cd "$OUT_OF_SOURCE_DIR"
1214 cmake "$MBEDTLS_ROOT_DIR"
1215 make
1216
1217 msg "test: cmake 'out-of-source' build"
1218 make test
1219 # Test an SSL option that requires an auxiliary script in test/scripts/.
1220 # Also ensure that there are no error messages such as
1221 # "No such file or directory", which would indicate that some required
1222 # file is missing (ssl-opt.sh tolerates the absence of some files so
1223 # may exit with status 0 but emit errors).
1224 if_build_succeeded ./tests/ssl-opt.sh -f 'Fallback SCSV: beginning of list' 2>ssl-opt.err
1225 if [ -s ssl-opt.err ]; then
1226 cat ssl-opt.err >&2
1227 record_status [ ! -s ssl-opt.err ]
1228 rm ssl-opt.err
1229 fi
1230 cd "$MBEDTLS_ROOT_DIR"
1231 rm -rf "$OUT_OF_SOURCE_DIR"
1232 unset MBEDTLS_ROOT_DIR
1233}
Andres AGdc192212016-08-31 17:33:13 +01001234
Gilles Peskine192c72f2017-12-21 15:59:21 +01001235
1236
1237################################################################
1238#### Termination
1239################################################################
1240
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001241post_report () {
1242 msg "Done, cleaning up"
1243 cleanup
1244
1245 final_report
1246}
1247
1248
1249
1250################################################################
1251#### Run all the things
1252################################################################
1253
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001254# Run one component and clean up afterwards.
1255run_component () {
Gilles Peskine72adb432019-01-02 18:57:02 +01001256 # Back up the configuration in case the component modifies it.
1257 # The cleanup function will restore it.
1258 cp -p "$CONFIG_H" "$CONFIG_BAK"
Gilles Peskine11ddca62018-12-04 12:49:28 +01001259 current_component="$1"
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001260 "$@"
1261 cleanup
1262}
1263
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001264# Preliminary setup
1265pre_check_environment
1266pre_initialize_variables
1267pre_parse_command_line "$@"
1268
1269pre_check_git
1270build_status=0
1271if [ $KEEP_GOING -eq 1 ]; then
1272 pre_setup_keep_going
1273else
1274 record_status () {
1275 "$@"
1276 }
1277fi
1278pre_print_configuration
1279pre_check_tools
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001280cleanup
Gilles Peskine7c652162017-12-11 00:01:40 +01001281
Gilles Peskineeb39b9b2019-01-08 23:41:00 +01001282# Run the requested tests.
Gilles Peskine6e984232018-11-27 21:37:53 +01001283for component in $RUN_COMPONENTS; do
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001284 run_component "component_$component"
1285done
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001286
1287# We're done.
1288post_report