blob: 57a538b0ca78231a7b7898f6e39c74f8b7ef3005 [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 Peskinecd7b0422020-04-25 22:21:30 +0200134 : ${ARM_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 Peskinecd7b0422020-04-25 22:21:30 +0200196 --arm-gcc-prefix=<string> Prefix for gcc as a cross-compiler for arm
197 (default: "${ARM_GCC_PREFIX}")
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100198 --armcc Run ARM Compiler builds (on by default).
Gilles Peskineff7238f2019-01-10 00:05:18 +0100199 --except Exclude the COMPONENTs listed on the command line,
200 instead of running only those.
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100201 --no-armcc Skip ARM Compiler builds.
Gilles Peskine19ceb712018-03-21 08:40:26 +0100202 --no-force Refuse to overwrite modified files (default).
203 --no-keep-going Stop at the first error (default).
204 --no-memory No additional memory tests (default).
Gilles Peskine2a22a802017-12-21 15:19:00 +0100205 --no-yotta Skip yotta module build.
Gilles Peskine709346a2017-12-10 23:43:39 +0100206 --out-of-source-dir=<path> Directory used for CMake out-of-source build tests.
Gilles Peskine19ceb712018-03-21 08:40:26 +0100207 --random-seed Use a random seed value for randomized tests (default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100208 -r|--release-test Run this script in release mode. This fixes the seed value to 1.
209 -s|--seed Integer seed value to use for this test run.
Gilles Peskine2a22a802017-12-21 15:19:00 +0100210 --yotta Build yotta module (on by default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100211
212Tool path options:
213 --armc5-bin-dir=<ARMC5_bin_dir_path> ARM Compiler 5 bin directory.
214 --armc6-bin-dir=<ARMC6_bin_dir_path> ARM Compiler 6 bin directory.
215 --gnutls-cli=<GnuTLS_cli_path> GnuTLS client executable to use for most tests.
216 --gnutls-serv=<GnuTLS_serv_path> GnuTLS server executable to use for most tests.
217 --gnutls-legacy-cli=<GnuTLS_cli_path> GnuTLS client executable to use for legacy tests.
218 --gnutls-legacy-serv=<GnuTLS_serv_path> GnuTLS server executable to use for legacy tests.
219 --openssl=<OpenSSL_path> OpenSSL executable to use for most tests.
220 --openssl-legacy=<OpenSSL_path> OpenSSL executable to use for legacy tests e.g. SSLv3.
221EOF
SimonB2e23c822016-04-16 21:54:39 +0100222}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100223
224# remove built files as well as the cmake cache/config
225cleanup()
226{
Gilles Peskinea71d64c2018-03-21 12:16:57 +0100227 if [ -n "${MBEDTLS_ROOT_DIR+set}" ]; then
228 cd "$MBEDTLS_ROOT_DIR"
229 fi
230
Gilles Peskine7c652162017-12-11 00:01:40 +0100231 command make clean
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200232
Gilles Peskine31b07e22018-03-21 12:15:06 +0100233 # Remove CMake artefacts
234 find . -name .git -prune -o -name yotta -prune -o \
235 -iname CMakeFiles -exec rm -rf {} \+ -o \
236 \( -iname cmake_install.cmake -o \
237 -iname CTestTestfile.cmake -o \
238 -iname CMakeCache.txt \) -exec rm {} \+
239 # Recover files overwritten by in-tree CMake builds
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000240 rm -f include/Makefile include/mbedtls/Makefile programs/*/Makefile
Paul Bakkerfe0984d2014-06-13 00:13:45 +0200241 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile
242 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200243
244 if [ -f "$CONFIG_BAK" ]; then
245 mv "$CONFIG_BAK" "$CONFIG_H"
246 fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100247}
248
Gilles Peskine7c652162017-12-11 00:01:40 +0100249# Executed on exit. May be redefined depending on command line options.
250final_report () {
251 :
252}
253
254fatal_signal () {
255 cleanup
256 final_report $1
257 trap - $1
258 kill -$1 $$
259}
260
261trap 'fatal_signal HUP' HUP
262trap 'fatal_signal INT' INT
263trap 'fatal_signal TERM' TERM
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200264
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100265msg()
266{
Gilles Peskine11ddca62018-12-04 12:49:28 +0100267 if [ -n "${current_component:-}" ]; then
268 current_section="${current_component#component_}: $1"
269 else
270 current_section="$1"
271 fi
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100272 echo ""
273 echo "******************************************************************"
Gilles Peskine11ddca62018-12-04 12:49:28 +0100274 echo "* $current_section "
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000275 printf "* "; date
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100276 echo "******************************************************************"
277}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100278
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100279armc6_build_test()
280{
281 FLAGS="$1"
Andres AGa5cd9732016-10-17 15:23:10 +0100282
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100283 msg "build: ARM Compiler 6 ($FLAGS), make"
284 ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \
285 WARNING_CFLAGS='-xc -std=c99' make lib
286 make clean
287}
Andres AGa5cd9732016-10-17 15:23:10 +0100288
Andres AGd9eba4b2016-08-26 14:42:14 +0100289err_msg()
290{
291 echo "$1" >&2
292}
293
294check_tools()
295{
296 for TOOL in "$@"; do
Andres AG98393602017-01-31 17:04:45 +0000297 if ! `type "$TOOL" >/dev/null 2>&1`; then
Andres AGd9eba4b2016-08-26 14:42:14 +0100298 err_msg "$TOOL not found!"
299 exit 1
300 fi
301 done
302}
303
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100304pre_parse_command_line () {
Gilles Peskineeb39b9b2019-01-08 23:41:00 +0100305 COMMAND_LINE_COMPONENTS=
Gilles Peskineff7238f2019-01-10 00:05:18 +0100306 all_except=0
Gilles Peskine53084872019-01-09 23:13:54 +0100307 no_armcc=
Gilles Peskine6e984232018-11-27 21:37:53 +0100308
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100309 while [ $# -gt 0 ]; do
310 case "$1" in
Gilles Peskinecd7b0422020-04-25 22:21:30 +0200311 --arm-gcc-prefix) shift; ARM_GCC_PREFIX="$1";;
Gilles Peskine53084872019-01-09 23:13:54 +0100312 --armcc) no_armcc=;;
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100313 --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
314 --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
Gilles Peskineeb39b9b2019-01-08 23:41:00 +0100315 --except) all_except=1;;
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100316 --force|-f) FORCE=1;;
317 --gnutls-cli) shift; GNUTLS_CLI="$1";;
318 --gnutls-legacy-cli) shift; GNUTLS_LEGACY_CLI="$1";;
319 --gnutls-legacy-serv) shift; GNUTLS_LEGACY_SERV="$1";;
320 --gnutls-serv) shift; GNUTLS_SERV="$1";;
321 --help|-h) usage; exit;;
322 --keep-going|-k) KEEP_GOING=1;;
Gilles Peskineb3241cb2019-01-08 23:44:07 +0100323 --list-all-components) printf '%s\n' $ALL_COMPONENTS; exit;;
324 --list-components) printf '%s\n' $SUPPORTED_COMPONENTS; exit;;
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100325 --memory|-m) MEMORY=1;;
Gilles Peskine53084872019-01-09 23:13:54 +0100326 --no-armcc) no_armcc=1;;
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100327 --no-force) FORCE=0;;
328 --no-keep-going) KEEP_GOING=0;;
329 --no-memory) MEMORY=0;;
330 --no-yotta) YOTTA=0;;
331 --openssl) shift; OPENSSL="$1";;
332 --openssl-legacy) shift; OPENSSL_LEGACY="$1";;
333 --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
334 --random-seed) unset SEED;;
335 --release-test|-r) SEED=1;;
336 --seed|-s) shift; SEED="$1";;
337 --yotta) YOTTA=1;;
Gilles Peskine91bd8b72019-01-08 23:01:34 +0100338 -*)
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100339 echo >&2 "Unknown option: $1"
340 echo >&2 "Run $0 --help for usage."
341 exit 120
342 ;;
Gilles Peskineeb39b9b2019-01-08 23:41:00 +0100343 *) COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS $1";;
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100344 esac
345 shift
346 done
Gilles Peskine91bd8b72019-01-08 23:01:34 +0100347
Gilles Peskineff7238f2019-01-10 00:05:18 +0100348 # With no list of components, run everything.
Gilles Peskineeb39b9b2019-01-08 23:41:00 +0100349 if [ -z "$COMMAND_LINE_COMPONENTS" ]; then
350 all_except=1
351 fi
352
Gilles Peskine53084872019-01-09 23:13:54 +0100353 # --no-armcc is a legacy option. The modern way is --except '*_armcc*'.
354 # Ignore it if components are listed explicitly on the command line.
Gilles Peskineff7238f2019-01-10 00:05:18 +0100355 if [ -n "$no_armcc" ] && [ $all_except -eq 1 ]; then
Gilles Peskine53084872019-01-09 23:13:54 +0100356 COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS *_armcc*"
357 # --no-armcc also disables yotta.
358 COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS *_yotta*"
359 fi
360
Gilles Peskineeb39b9b2019-01-08 23:41:00 +0100361 # Build the list of components to run.
Gilles Peskineff7238f2019-01-10 00:05:18 +0100362 RUN_COMPONENTS=
363 for component in $SUPPORTED_COMPONENTS; do
364 if is_component_included "$component"; [ $? -eq $all_except ]; then
365 RUN_COMPONENTS="$RUN_COMPONENTS $component"
366 fi
367 done
Gilles Peskineeb39b9b2019-01-08 23:41:00 +0100368
369 unset all_except
Gilles Peskine53084872019-01-09 23:13:54 +0100370 unset no_armcc
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100371}
SimonB2e23c822016-04-16 21:54:39 +0100372
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100373pre_check_git () {
374 if [ $FORCE -eq 1 ]; then
Gilles Peskinec7800952019-01-09 23:14:09 +0100375 rm -rf "$OUT_OF_SOURCE_DIR"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100376 if [ $YOTTA -eq 1 ]; then
Gilles Peskinec7800952019-01-09 23:14:09 +0100377 rm -rf yotta/module
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100378 fi
379 git checkout-index -f -q $CONFIG_H
380 cleanup
381 else
382
383 if [ $YOTTA -ne 0 ] && [ -d yotta/module ]; then
384 err_msg "Warning - there is an existing yotta module in the directory 'yotta/module'"
385 echo "You can either delete your work and retry, or force the test to overwrite the"
386 echo "test by rerunning the script as: $0 --force"
387 exit 1
388 fi
389
390 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
391 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
392 echo "You can either delete this directory manually, or force the test by rerunning"
393 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
394 exit 1
395 fi
396
Gilles Peskinec9663b12019-01-09 22:30:01 +0100397 if ! git diff --quiet include/mbedtls/config.h; then
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100398 err_msg "Warning - the configuration file 'include/mbedtls/config.h' has been edited. "
399 echo "You can either delete or preserve your work, or force the test by rerunning the"
400 echo "script as: $0 --force"
401 exit 1
402 fi
Gilles Peskineda519252017-11-30 13:22:04 +0100403 fi
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100404}
SimonB2e23c822016-04-16 21:54:39 +0100405
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100406pre_setup_keep_going () {
Gilles Peskine7c652162017-12-11 00:01:40 +0100407 failure_summary=
408 failure_count=0
409 start_red=
410 end_color=
411 if [ -t 1 ]; then
Gilles Peskine9736b9d2018-01-02 21:54:17 +0100412 case "${TERM:-}" in
Gilles Peskine7c652162017-12-11 00:01:40 +0100413 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
414 start_red=$(printf '\033[31m')
415 end_color=$(printf '\033[0m')
416 ;;
417 esac
418 fi
419 record_status () {
420 if "$@"; then
421 last_status=0
422 else
423 last_status=$?
424 text="$current_section: $* -> $last_status"
425 failure_summary="$failure_summary
426$text"
427 failure_count=$((failure_count + 1))
428 echo "${start_red}^^^^$text^^^^${end_color}"
429 fi
430 }
431 make () {
432 case "$*" in
433 *test|*check)
434 if [ $build_status -eq 0 ]; then
435 record_status command make "$@"
436 else
437 echo "(skipped because the build failed)"
438 fi
439 ;;
440 *)
441 record_status command make "$@"
442 build_status=$last_status
443 ;;
444 esac
445 }
446 final_report () {
447 if [ $failure_count -gt 0 ]; then
448 echo
449 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
450 echo "${start_red}FAILED: $failure_count${end_color}$failure_summary"
451 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Jaeden Amero5113bde2018-07-20 16:42:14 +0100452 exit 1
Gilles Peskine7c652162017-12-11 00:01:40 +0100453 elif [ -z "${1-}" ]; then
454 echo "SUCCESS :)"
455 fi
456 if [ -n "${1-}" ]; then
457 echo "Killed by SIG$1."
458 fi
459 }
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100460}
461
Gilles Peskine7c652162017-12-11 00:01:40 +0100462if_build_succeeded () {
463 if [ $build_status -eq 0 ]; then
464 record_status "$@"
465 fi
466}
467
Gilles Peskine30bc3852019-01-09 23:25:25 +0100468# to be used instead of ! for commands run with
469# record_status or if_build_succeeded
470not() {
471 ! "$@"
472}
473
474
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100475pre_print_configuration () {
476 msg "info: $0 configuration"
477 echo "MEMORY: $MEMORY"
478 echo "FORCE: $FORCE"
479 echo "SEED: ${SEED-"UNSET"}"
480 echo "OPENSSL: $OPENSSL"
481 echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
482 echo "GNUTLS_CLI: $GNUTLS_CLI"
483 echo "GNUTLS_SERV: $GNUTLS_SERV"
484 echo "GNUTLS_LEGACY_CLI: $GNUTLS_LEGACY_CLI"
485 echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV"
486 echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
487 echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
488}
Andres AG7770ea82016-10-10 15:46:20 +0100489
Andres AGd9eba4b2016-08-26 14:42:14 +0100490# Make sure the tools we need are available.
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100491pre_check_tools () {
Gilles Peskine541fb1e2019-01-06 22:40:00 +0000492 # Build the list of variables to pass to output_env.sh.
493 set env
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100494
Gilles Peskine541fb1e2019-01-06 22:40:00 +0000495 case " $RUN_COMPONENTS " in
496 # Require OpenSSL and GnuTLS if running any tests (as opposed to
497 # only doing builds). Not all tests run OpenSSL and GnuTLS, but this
498 # is a good enough approximation in practice.
499 *" test_"*)
500 # To avoid setting OpenSSL and GnuTLS for each call to compat.sh
501 # and ssl-opt.sh, we just export the variables they require.
502 export OPENSSL_CMD="$OPENSSL"
503 export GNUTLS_CLI="$GNUTLS_CLI"
504 export GNUTLS_SERV="$GNUTLS_SERV"
505 # Avoid passing --seed flag in every call to ssl-opt.sh
506 if [ -n "${SEED-}" ]; then
507 export SEED
508 fi
509 set "$@" OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY"
510 set "$@" GNUTLS_CLI="$GNUTLS_CLI" GNUTLS_SERV="$GNUTLS_SERV"
511 set "$@" GNUTLS_LEGACY_CLI="$GNUTLS_LEGACY_CLI"
512 set "$@" GNUTLS_LEGACY_SERV="$GNUTLS_LEGACY_SERV"
513 check_tools "$OPENSSL" "$OPENSSL_LEGACY" \
514 "$GNUTLS_CLI" "$GNUTLS_SERV" \
515 "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV"
516 ;;
517 esac
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100518
Gilles Peskine541fb1e2019-01-06 22:40:00 +0000519 case " $RUN_COMPONENTS " in
520 *_doxygen[_\ ]*) check_tools "doxygen" "dot";;
521 esac
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100522
Gilles Peskine541fb1e2019-01-06 22:40:00 +0000523 case " $RUN_COMPONENTS " in
Gilles Peskinecd7b0422020-04-25 22:21:30 +0200524 *_arm_none_eabi_gcc[_\ ]*) check_tools "${ARM_GCC_PREFIX}gcc";;
Gilles Peskine541fb1e2019-01-06 22:40:00 +0000525 esac
526
527 case " $RUN_COMPONENTS " in
528 *_mingw[_\ ]*) check_tools "i686-w64-mingw32-gcc";;
529 esac
530
531 case " $RUN_COMPONENTS " in
Gilles Peskine53084872019-01-09 23:13:54 +0100532 *_armcc*|*_yotta*)
Gilles Peskine541fb1e2019-01-06 22:40:00 +0000533 ARMC5_CC="$ARMC5_BIN_DIR/armcc"
534 ARMC5_AR="$ARMC5_BIN_DIR/armar"
535 ARMC6_CC="$ARMC6_BIN_DIR/armclang"
536 ARMC6_AR="$ARMC6_BIN_DIR/armar"
Gilles Peskine53084872019-01-09 23:13:54 +0100537 check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC6_CC" "$ARMC6_AR";;
538 esac
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100539
540 msg "info: output_env.sh"
Gilles Peskine53084872019-01-09 23:13:54 +0100541 case $RUN_COMPONENTS in
542 *_armcc*|*_yotta*)
543 set "$@" ARMC5_CC="$ARMC5_CC" ARMC6_CC="$ARMC6_CC" RUN_ARMCC=1;;
544 *) set "$@" RUN_ARMCC=0;;
545 esac
546 "$@" scripts/output_env.sh
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100547}
Andres AGd9eba4b2016-08-26 14:42:14 +0100548
Gilles Peskine192c72f2017-12-21 15:59:21 +0100549
550
551################################################################
552#### Basic checks
553################################################################
SimonB2e23c822016-04-16 21:54:39 +0100554
555#
556# Test Suites to be executed
557#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200558# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100559# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard61bc57a2014-08-14 11:29:06 +0200560# and/or are more likely to fail than others (eg I use Clang most of the
561# time, so start with a GCC build).
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200562# 2. Minimize total running time, by avoiding useless rebuilds
563#
564# Indicative running times are given for reference.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100565
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100566component_check_recursion () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100567 msg "test: recursion.pl" # < 1s
568 record_status tests/scripts/recursion.pl library/*.c
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100569}
Manuel Pégourié-Gonnardea29d152014-11-20 17:32:33 +0100570
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100571component_check_generated_files () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100572 msg "test: freshness of generated source files" # < 1s
573 record_status tests/scripts/check-generated-files.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100574}
Manuel Pégourié-Gonnardb3b8e432015-02-13 14:52:19 +0000575
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100576component_check_doxy_blocks () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100577 msg "test: doxygen markup outside doxygen blocks" # < 1s
578 record_status tests/scripts/check-doxy-blocks.pl
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100579}
Manuel Pégourié-Gonnardd09a6b52015-04-09 17:19:23 +0200580
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100581component_check_files () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100582 msg "test: check-files.py" # < 1s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100583 record_status tests/scripts/check-files.py
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100584}
Manuel Pégourié-Gonnard77d56bb2015-07-28 15:00:37 +0200585
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100586component_check_names () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100587 msg "test/build: declared and exported names" # < 3s
Gilles Peskinee952fdf2019-05-15 17:52:22 +0200588 record_status tests/scripts/check-names.sh -v
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100589}
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +0200590
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100591component_check_doxygen_warnings () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100592 msg "test: doxygen warnings" # ~ 3s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100593 record_status tests/scripts/doxygen.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100594}
Andres Amaya Garciadd29c2f2017-05-04 11:35:51 +0100595
Simon Butcher948f2642018-07-20 21:27:33 +0100596
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100597################################################################
598#### Build and test many configurations and targets
599################################################################
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100600
k-stachowiak45d0ba12019-06-04 13:14:58 +0200601component_test_large_ecdsa_key_signature () {
602
603 SMALL_MPI_MAX_SIZE=136 # Small enough to interfere with the EC signatures
604
605 msg "build: cmake + MBEDTLS_MPI_MAX_SIZE=${SMALL_MPI_MAX_SIZE}, gcc, ASan" # ~ 1 min 50s
606 scripts/config.pl set MBEDTLS_MPI_MAX_SIZE $SMALL_MPI_MAX_SIZE
607 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
608 make
609
610 INEVITABLY_PRESENT_FILE=Makefile
611 SIGNATURE_FILE="${INEVITABLY_PRESENT_FILE}.sig" # Warning, this is rm -f'ed below
612
613 msg "test: pk_sign secp521r1_prv.der for MBEDTLS_MPI_MAX_SIZE=${SMALL_MPI_MAX_SIZE} (ASan build)" # ~ 5s
614 if_build_succeeded programs/pkey/pk_sign tests/data_files/secp521r1_prv.der $INEVITABLY_PRESENT_FILE
615 rm -f $SIGNATURE_FILE
616}
617
Gilles Peskine1270d322019-04-08 17:00:15 +0200618component_test_default_out_of_box () {
619 msg "build: make, default config (out-of-box)" # ~1min
620 make
621
622 msg "test: main suites make, default config (out-of-box)" # ~10s
623 make test
624
625 msg "selftest: make, default config (out-of-box)" # ~10s
Gilles Peskinebfda0332020-04-23 23:37:45 +0200626 if_build_succeeded programs/test/selftest
Gilles Peskine1270d322019-04-08 17:00:15 +0200627}
628
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100629component_build_yotta () {
Gilles Peskine53084872019-01-09 23:13:54 +0100630 # Note - use of yotta is deprecated, and yotta also requires armcc to be on the
631 # path, and uses whatever version of armcc it finds there.
632 msg "build: create and build yotta module" # ~ 30s
633 record_status tests/scripts/yotta-build.sh
634}
635support_build_yotta () {
636 [ $YOTTA -ne 0 ]
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100637}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100638
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100639component_test_default_cmake_gcc_asan () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100640 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100641 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100642 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +0200643
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100644 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100645 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100646
Gilles Peskinebfda0332020-04-23 23:37:45 +0200647 msg "test: selftest (ASan build)" # ~ 10s
648 if_build_succeeded programs/test/selftest
649
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100650 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
Gilles Peskine7c652162017-12-11 00:01:40 +0100651 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100652
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100653 msg "test: compat.sh (ASan build)" # ~ 6 min
654 if_build_succeeded tests/compat.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100655}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000656
Hanno Becker167ae432019-02-26 14:27:09 +0000657component_test_full_cmake_gcc_asan () {
658 msg "build: full config, cmake, gcc, ASan"
659 scripts/config.pl full
660 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
661 make
662
663 msg "test: main suites (inc. selftests) (full config, ASan build)"
664 make test
665
Gilles Peskinebfda0332020-04-23 23:37:45 +0200666 msg "test: selftest (ASan build)" # ~ 10s
667 if_build_succeeded programs/test/selftest
668
Hanno Becker167ae432019-02-26 14:27:09 +0000669 msg "test: ssl-opt.sh (full config, ASan build)"
670 if_build_succeeded tests/ssl-opt.sh
671
672 msg "test: compat.sh (full config, ASan build)"
673 if_build_succeeded tests/compat.sh
674}
675
Manuel Pégourié-Gonnard51e24942020-01-02 11:45:12 +0100676component_test_zlib_make() {
677 msg "build: zlib enabled, make"
678 scripts/config.pl set MBEDTLS_ZLIB_SUPPORT
679 make ZLIB=1 CFLAGS='-Werror -O1'
680
681 msg "test: main suites (zlib, make)"
682 make test
683
684 msg "test: ssl-opt.sh (zlib, make)"
685 if_build_succeeded tests/ssl-opt.sh
686}
Manuel Pégourié-Gonnard2150fb22020-01-24 10:17:20 +0100687support_test_zlib_make () {
688 base=support_test_zlib_$$
689 cat <<'EOF' > ${base}.c
690#include "zlib.h"
691int main(void) { return 0; }
692EOF
693 gcc -o ${base}.exe ${base}.c -lz 2>/dev/null
694 ret=$?
695 rm -f ${base}.*
696 return $ret
697}
Manuel Pégourié-Gonnard51e24942020-01-02 11:45:12 +0100698
699component_test_zlib_cmake() {
700 msg "build: zlib enabled, cmake"
701 scripts/config.pl set MBEDTLS_ZLIB_SUPPORT
702 cmake -D ENABLE_ZLIB_SUPPORT=On -D CMAKE_BUILD_TYPE:String=Check .
703 make
704
705 msg "test: main suites (zlib, cmake)"
706 make test
707
708 msg "test: ssl-opt.sh (zlib, cmake)"
709 if_build_succeeded tests/ssl-opt.sh
710}
Manuel Pégourié-Gonnard2150fb22020-01-24 10:17:20 +0100711support_test_zlib_cmake () {
712 support_test_zlib_make "$@"
713}
Manuel Pégourié-Gonnard51e24942020-01-02 11:45:12 +0100714
Gilles Peskine3484ed82019-01-08 22:51:19 +0100715component_test_ref_configs () {
716 msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
717 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
718 record_status tests/scripts/test-ref-configs.pl
719}
720
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100721component_test_sslv3 () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100722 msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100723 scripts/config.pl set MBEDTLS_SSL_PROTO_SSL3
724 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
725 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000726
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100727 msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
728 make test
729
730 msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
731 if_build_succeeded tests/compat.sh -m 'tls1 tls1_1 tls1_2 dtls1 dtls1_2'
732 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
733
734 msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
735 if_build_succeeded tests/ssl-opt.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100736}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100737
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100738component_test_no_renegotiation () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100739 msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100740 scripts/config.pl unset MBEDTLS_SSL_RENEGOTIATION
741 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
742 make
743
744 msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
745 make test
746
747 msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
748 if_build_succeeded tests/ssl-opt.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100749}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100750
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100751component_test_rsa_no_crt () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100752 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100753 scripts/config.pl set MBEDTLS_RSA_NO_CRT
754 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
755 make
756
757 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
758 make test
759
760 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
761 if_build_succeeded tests/ssl-opt.sh -f RSA
762
763 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
764 if_build_succeeded tests/compat.sh -t RSA
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100765}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100766
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100767component_test_full_cmake_clang () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100768 msg "build: cmake, full config, clang" # ~ 50s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100769 scripts/config.pl full
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100770 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check -D ENABLE_TESTING=On .
771 make
772
773 msg "test: main suites (full config)" # ~ 5s
774 make test
775
776 msg "test: ssl-opt.sh default (full config)" # ~ 1s
777 if_build_succeeded tests/ssl-opt.sh -f Default
778
Andres Amaya Garcia0a0e5b12019-01-08 21:42:27 +0000779 msg "test: compat.sh RC4, DES, 3DES & NULL (full config)" # ~ 2 min
Andres Amaya Garciafea3d0a2019-02-19 20:20:57 +0000780 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 +0100781}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100782
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100783component_build_deprecated () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100784 msg "build: make, full config + DEPRECATED_WARNING, gcc -O" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100785 scripts/config.pl full
786 scripts/config.pl set MBEDTLS_DEPRECATED_WARNING
787 # Build with -O -Wextra to catch a maximum of issues.
788 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra' lib programs
789 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
790
791 msg "build: make, full config + DEPRECATED_REMOVED, clang -O" # ~ 30s
792 # No cleanup, just tweak the configuration and rebuild
793 make clean
794 scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
795 scripts/config.pl set MBEDTLS_DEPRECATED_REMOVED
796 # Build with -O -Wextra to catch a maximum of issues.
797 make CC=clang CFLAGS='-O -Werror -Wall -Wextra' lib programs
798 make CC=clang CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100799}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100800
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100801component_test_depends_curves () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100802 msg "test/build: curves.pl (gcc)" # ~ 4 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100803 record_status tests/scripts/curves.pl
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100804}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100805
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100806component_test_depends_hashes () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100807 msg "test/build: depends-hashes.pl (gcc)" # ~ 2 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100808 record_status tests/scripts/depends-hashes.pl
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100809}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100810
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100811component_test_depends_pkalgs () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100812 msg "test/build: depends-pkalgs.pl (gcc)" # ~ 2 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100813 record_status tests/scripts/depends-pkalgs.pl
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100814}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100815
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100816component_build_key_exchanges () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100817 msg "test/build: key-exchanges (gcc)" # ~ 1 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100818 record_status tests/scripts/key-exchanges.pl
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100819}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100820
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100821component_build_default_make_gcc () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100822 msg "build: Unix make, -Os (gcc)" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100823 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100824}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100825
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100826component_test_no_platform () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100827 # Full configuration build, without platform support, file IO and net sockets.
828 # This should catch missing mbedtls_printf definitions, and by disabling file
829 # IO, it should catch missing '#include <stdio.h>'
830 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100831 scripts/config.pl full
832 scripts/config.pl unset MBEDTLS_PLATFORM_C
833 scripts/config.pl unset MBEDTLS_NET_C
834 scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
835 scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
836 scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
837 scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
838 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
839 scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
840 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100841 scripts/config.pl unset MBEDTLS_FS_IO
842 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
843 # to re-enable platform integration features otherwise disabled in C99 builds
Gilles Peskinec9247122019-09-20 19:23:10 +0200844 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -Os -D_DEFAULT_SOURCE' lib programs
845 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os' test
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100846}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100847
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100848component_build_no_std_function () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100849 # catch compile bugs in _uninit functions
850 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100851 scripts/config.pl full
852 scripts/config.pl set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
853 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskinec9247122019-09-20 19:23:10 +0200854 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100855}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100856
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100857component_build_no_ssl_srv () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100858 msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100859 scripts/config.pl full
860 scripts/config.pl unset MBEDTLS_SSL_SRV_C
Gilles Peskinec9247122019-09-20 19:23:10 +0200861 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100862}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100863
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100864component_build_no_ssl_cli () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100865 msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100866 scripts/config.pl full
867 scripts/config.pl unset MBEDTLS_SSL_CLI_C
Gilles Peskinec9247122019-09-20 19:23:10 +0200868 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100869}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100870
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100871component_build_no_sockets () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100872 # Note, C99 compliance can also be tested with the sockets support disabled,
873 # as that requires a POSIX platform (which isn't the same as C99).
874 msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100875 scripts/config.pl full
876 scripts/config.pl unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
877 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
Gilles Peskinec9247122019-09-20 19:23:10 +0200878 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1 -std=c99 -pedantic' lib
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100879}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100880
Andrzej Kurek9a461a12019-09-05 09:27:47 -0400881component_test_memory_buffer_allocator_backtrace () {
882 msg "build: default config with memory buffer allocator and backtrace enabled"
Hanno Beckerf5baaaa2019-02-26 14:34:13 +0000883 scripts/config.pl set MBEDTLS_MEMORY_BUFFER_ALLOC_C
Andrzej Kurek9a461a12019-09-05 09:27:47 -0400884 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
Hanno Beckerf5baaaa2019-02-26 14:34:13 +0000885 scripts/config.pl set MBEDTLS_MEMORY_BACKTRACE
Andrzej Kurek9b1c2482019-09-10 02:58:34 -0400886 scripts/config.pl set MBEDTLS_MEMORY_DEBUG
Andrzej Kurek9a461a12019-09-05 09:27:47 -0400887 CC=gcc cmake .
888 make
889
890 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C and MBEDTLS_MEMORY_BACKTRACE"
891 make test
892}
893
894component_test_memory_buffer_allocator () {
895 msg "build: default config with memory buffer allocator"
896 scripts/config.pl set MBEDTLS_MEMORY_BUFFER_ALLOC_C
Hanno Becker7aad93c2019-06-03 16:35:02 +0100897 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
Hanno Beckerf5baaaa2019-02-26 14:34:13 +0000898 CC=gcc cmake .
899 make
900
901 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C"
902 make test
903
904 msg "test: ssl-opt.sh, MBEDTLS_MEMORY_BUFFER_ALLOC_C"
Andrzej Kurek6addfdd2019-09-05 10:09:37 -0400905 # MBEDTLS_MEMORY_BUFFER_ALLOC is slow. Skip tests that tend to time out.
906 if_build_succeeded tests/ssl-opt.sh -e '^DTLS proxy'
Hanno Beckerf5baaaa2019-02-26 14:34:13 +0000907}
908
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100909component_test_no_max_fragment_length () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100910 msg "build: default config except MFL extension (ASan build)" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100911 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
912 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
913 make
914
915 msg "test: ssl-opt.sh, MFL-related tests"
916 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length"
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100917}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100918
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100919component_test_null_entropy () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100920 msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100921 scripts/config.pl set MBEDTLS_TEST_NULL_ENTROPY
922 scripts/config.pl set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
923 scripts/config.pl set MBEDTLS_ENTROPY_C
924 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
925 scripts/config.pl unset MBEDTLS_ENTROPY_HARDWARE_ALT
926 scripts/config.pl unset MBEDTLS_HAVEGE_C
Gilles Peskine4e7b3232019-01-06 19:48:30 +0000927 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan -D UNSAFE_BUILD=ON .
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100928 make
929
930 msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)"
931 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100932}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100933
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100934component_test_platform_calloc_macro () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100935 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100936 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
937 scripts/config.pl set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
938 scripts/config.pl set MBEDTLS_PLATFORM_FREE_MACRO free
939 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
940 make
941
942 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
943 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100944}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100945
Gilles Peskine0981a5d2019-09-17 19:04:38 +0200946component_test_malloc_0_null () {
947 msg "build: malloc(0) returns NULL (ASan+UBSan build)"
948 scripts/config.pl full
949 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
950 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'
951
952 msg "test: malloc(0) returns NULL (ASan+UBSan build)"
953 make test
954
955 msg "selftest: malloc(0) returns NULL (ASan+UBSan build)"
956 # Just the calloc selftest. "make test" ran the others as part of the
957 # test suites.
958 if_build_succeeded programs/test/selftest calloc
959}
960
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100961component_test_make_shared () {
Gilles Peskine770ad7e2019-01-08 23:19:08 +0100962 msg "build/test: make shared" # ~ 40s
963 make SHARED=1 all check
Gilles Peskine950de1e2019-07-03 20:43:32 +0200964 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100965}
966
Gilles Peskine17ecb242019-07-03 20:43:05 +0200967component_test_cmake_shared () {
968 msg "build/test: cmake shared" # ~ 2min
969 cmake -DUSE_SHARED_MBEDTLS_LIBRARY=On .
970 make
Gilles Peskine950de1e2019-07-03 20:43:32 +0200971 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskine17ecb242019-07-03 20:43:05 +0200972 make test
973}
974
Gilles Peskinefa0e8b52019-09-20 19:56:06 +0200975test_build_opt () {
976 info=$1 cc=$2; shift 2
977 for opt in "$@"; do
978 msg "build/test: $cc $opt, $info" # ~ 30s
979 make CC="$cc" CFLAGS="$opt -Wall -Wextra -Werror"
980 # We're confident enough in compilers to not run _all_ the tests,
981 # but at least run the unit tests. In particular, runs with
982 # optimizations use inline assembly whereas runs with -O0
983 # skip inline assembly.
984 make test # ~30s
985 make clean
986 done
987}
988
989component_test_clang_opt () {
990 scripts/config.pl full
991 test_build_opt 'full config' clang -O0 -Os -O2
992}
993
994component_test_gcc_opt () {
995 scripts/config.pl full
996 test_build_opt 'full config' gcc -O0 -Os -O2
997}
998
Gilles Peskinef852f5f2019-07-03 20:42:16 +0200999component_build_mbedtls_config_file () {
1000 msg "build: make with MBEDTLS_CONFIG_FILE" # ~40s
1001 # Use the full config so as to catch a maximum of places where
1002 # the check of MBEDTLS_CONFIG_FILE might be missing.
1003 scripts/config.pl full
1004 sed 's!"check_config.h"!"mbedtls/check_config.h"!' <"$CONFIG_H" >full_config.h
1005 echo '#error "MBEDTLS_CONFIG_FILE is not working"' >"$CONFIG_H"
1006 make CFLAGS="-I '$PWD' -DMBEDTLS_CONFIG_FILE='\"full_config.h\"'"
1007 rm -f full_config.h
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001008}
1009
Gilles Peskine3fbdd212019-01-08 23:33:45 +01001010component_test_m32_o0 () {
1011 # Build once with -O0, to compile out the i386 specific inline assembly
1012 msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
1013 scripts/config.pl full
Gilles Peskinec20a4052019-10-21 17:11:33 +02001014 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O0" LDFLAGS="-m32 $ASAN_CFLAGS"
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001015
Gilles Peskine3fbdd212019-01-08 23:33:45 +01001016 msg "test: i386, make, gcc -O0 (ASan build)"
1017 make test
1018}
1019support_test_m32_o0 () {
1020 case $(uname -m) in
1021 *64*) true;;
1022 *) false;;
1023 esac
1024}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001025
Gilles Peskine3fbdd212019-01-08 23:33:45 +01001026component_test_m32_o1 () {
1027 # Build again with -O1, to compile in the i386 specific inline assembly
1028 msg "build: i386, make, gcc -O1 (ASan build)" # ~ 30s
1029 scripts/config.pl full
Gilles Peskinec20a4052019-10-21 17:11:33 +02001030 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O1" LDFLAGS="-m32 $ASAN_CFLAGS"
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001031
Gilles Peskine3fbdd212019-01-08 23:33:45 +01001032 msg "test: i386, make, gcc -O1 (ASan build)"
1033 make test
Gilles Peskine11064292019-04-08 16:58:02 +02001034
1035 msg "test ssl-opt.sh, i386, make, gcc-O1"
1036 if_build_succeeded tests/ssl-opt.sh
Gilles Peskine3fbdd212019-01-08 23:33:45 +01001037}
1038support_test_m32_o1 () {
1039 support_test_m32_o0 "$@"
1040}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001041
Gilles Peskine3fbdd212019-01-08 23:33:45 +01001042component_test_mx32 () {
1043 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
1044 scripts/config.pl full
Gilles Peskined535f4d2019-06-07 14:50:09 +02001045 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32' LDFLAGS='-mx32'
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001046
Gilles Peskine3fbdd212019-01-08 23:33:45 +01001047 msg "test: 64-bit ILP32, make, gcc"
1048 make test
1049}
1050support_test_mx32 () {
1051 case $(uname -m) in
1052 amd64|x86_64) true;;
1053 *) false;;
1054 esac
1055}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001056
Peter Kolbus16015dd2018-12-27 06:59:04 -06001057component_test_min_mpi_window_size () {
1058 msg "build: Default + MBEDTLS_MPI_WINDOW_SIZE=1 (ASan build)" # ~ 10s
1059 scripts/config.pl set MBEDTLS_MPI_WINDOW_SIZE 1
1060 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1061 make
1062
1063 msg "test: MBEDTLS_MPI_WINDOW_SIZE=1 - main suites (inc. selftests) (ASan build)" # ~ 10s
1064 make test
1065}
1066
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001067component_test_have_int32 () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001068 msg "build: gcc, force 32-bit bignum limbs"
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001069 scripts/config.pl unset MBEDTLS_HAVE_ASM
1070 scripts/config.pl unset MBEDTLS_AESNI_C
1071 scripts/config.pl unset MBEDTLS_PADLOCK_C
1072 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
1073
1074 msg "test: gcc, force 32-bit bignum limbs"
1075 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001076}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001077
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001078component_test_have_int64 () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001079 msg "build: gcc, force 64-bit bignum limbs"
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001080 scripts/config.pl unset MBEDTLS_HAVE_ASM
1081 scripts/config.pl unset MBEDTLS_AESNI_C
1082 scripts/config.pl unset MBEDTLS_PADLOCK_C
1083 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
1084
1085 msg "test: gcc, force 64-bit bignum limbs"
1086 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001087}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001088
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001089component_build_arm_none_eabi_gcc () {
Gilles Peskinecd7b0422020-04-25 22:21:30 +02001090 msg "build: ${ARM_GCC_PREFIX}, make" # ~ 10s
Manuel Pégourié-Gonnard59bc9a12019-04-29 12:44:12 +02001091 scripts/config.pl baremetal
Gilles Peskinecd7b0422020-04-25 22:21:30 +02001092 make CC="${ARM_GCC_PREFIX}gcc" AR="${ARM_GCC_PREFIX}ar" LD="${ARM_GCC_PREFIX}ld" CFLAGS='-Werror -Wall -Wextra' lib
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001093}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001094
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001095component_build_arm_none_eabi_gcc_no_udbl_division () {
Gilles Peskinecd7b0422020-04-25 22:21:30 +02001096 msg "build: ${ARM_GCC_PREFIX} -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
Manuel Pégourié-Gonnard59bc9a12019-04-29 12:44:12 +02001097 scripts/config.pl baremetal
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001098 scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
Gilles Peskinecd7b0422020-04-25 22:21:30 +02001099 make CC="${ARM_GCC_PREFIX}gcc" AR="${ARM_GCC_PREFIX}ar" LD="${ARM_GCC_PREFIX}ld" CFLAGS='-Werror -Wall -Wextra' lib
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001100 echo "Checking that software 64-bit division is not required"
Gilles Peskine30bc3852019-01-09 23:25:25 +01001101 if_build_succeeded not grep __aeabi_uldiv library/*.o
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001102}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001103
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001104component_build_armcc () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001105 msg "build: ARM Compiler 5, make"
Manuel Pégourié-Gonnard59bc9a12019-04-29 12:44:12 +02001106 scripts/config.pl baremetal
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001107
Gilles Peskine53084872019-01-09 23:13:54 +01001108 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
1109 make clean
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001110
Gilles Peskine53084872019-01-09 23:13:54 +01001111 # ARM Compiler 6 - Target ARMv7-A
1112 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-a"
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001113
Gilles Peskine53084872019-01-09 23:13:54 +01001114 # ARM Compiler 6 - Target ARMv7-M
1115 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m"
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001116
Gilles Peskine53084872019-01-09 23:13:54 +01001117 # ARM Compiler 6 - Target ARMv8-A - AArch32
1118 armc6_build_test "--target=arm-arm-none-eabi -march=armv8.2-a"
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001119
Gilles Peskine53084872019-01-09 23:13:54 +01001120 # ARM Compiler 6 - Target ARMv8-M
1121 armc6_build_test "--target=arm-arm-none-eabi -march=armv8-m.main"
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001122
Gilles Peskine53084872019-01-09 23:13:54 +01001123 # ARM Compiler 6 - Target ARMv8-A - AArch64
1124 armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a"
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001125}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001126
Andres Amaya Garciabb13e3b2018-12-05 22:03:56 +00001127component_build_ssl_hw_record_accel() {
1128 msg "build: default config with MBEDTLS_SSL_HW_RECORD_ACCEL enabled"
1129 scripts/config.pl set MBEDTLS_SSL_HW_RECORD_ACCEL
1130 make CFLAGS='-Werror -O1'
1131}
1132
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001133component_test_allow_sha1 () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001134 msg "build: allow SHA1 in certificates by default"
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001135 scripts/config.pl set MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
1136 make CFLAGS='-Werror -Wall -Wextra'
1137 msg "test: allow SHA1 in certificates by default"
1138 make test
1139 if_build_succeeded tests/ssl-opt.sh -f SHA-1
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001140}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001141
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001142component_build_mingw () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001143 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001144 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
1145
1146 # note Make tests only builds the tests, but doesn't run them
1147 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror' WINDOWS_BUILD=1 tests
1148 make WINDOWS_BUILD=1 clean
1149
1150 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
1151 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
1152 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
1153 make WINDOWS_BUILD=1 clean
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001154}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001155
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001156component_test_memsan () {
Gilles Peskine770ad7e2019-01-08 23:19:08 +01001157 msg "build: MSan (clang)" # ~ 1 min 20s
1158 scripts/config.pl unset MBEDTLS_AESNI_C # memsan doesn't grok asm
1159 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
1160 make
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001161
Gilles Peskine770ad7e2019-01-08 23:19:08 +01001162 msg "test: main suites (MSan)" # ~ 10s
1163 make test
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001164
Gilles Peskine770ad7e2019-01-08 23:19:08 +01001165 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
1166 if_build_succeeded tests/ssl-opt.sh
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001167
Gilles Peskine770ad7e2019-01-08 23:19:08 +01001168 # Optional part(s)
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001169
Gilles Peskine770ad7e2019-01-08 23:19:08 +01001170 if [ "$MEMORY" -gt 0 ]; then
1171 msg "test: compat.sh (MSan)" # ~ 6 min 20s
1172 if_build_succeeded tests/compat.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001173 fi
1174}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001175
Gilles Peskine9f553642019-01-10 00:11:42 +01001176component_test_valgrind () {
Gilles Peskine770ad7e2019-01-08 23:19:08 +01001177 msg "build: Release (clang)"
1178 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
1179 make
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001180
Gilles Peskine770ad7e2019-01-08 23:19:08 +01001181 msg "test: main suites valgrind (Release)"
1182 make memcheck
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001183
Gilles Peskine26cae712019-04-08 17:00:56 +02001184 # Optional parts (slow; currently broken on OS X because programs don't
1185 # seem to receive signals under valgrind on OS X).
Gilles Peskine770ad7e2019-01-08 23:19:08 +01001186 if [ "$MEMORY" -gt 0 ]; then
1187 msg "test: ssl-opt.sh --memcheck (Release)"
1188 if_build_succeeded tests/ssl-opt.sh --memcheck
1189 fi
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001190
Gilles Peskine770ad7e2019-01-08 23:19:08 +01001191 if [ "$MEMORY" -gt 1 ]; then
1192 msg "test: compat.sh --memcheck (Release)"
1193 if_build_succeeded tests/compat.sh --memcheck
1194 fi
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001195}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001196
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001197component_test_cmake_out_of_source () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001198 msg "build: cmake 'out-of-source' build"
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001199 MBEDTLS_ROOT_DIR="$PWD"
1200 mkdir "$OUT_OF_SOURCE_DIR"
1201 cd "$OUT_OF_SOURCE_DIR"
1202 cmake "$MBEDTLS_ROOT_DIR"
1203 make
1204
1205 msg "test: cmake 'out-of-source' build"
1206 make test
1207 # Test an SSL option that requires an auxiliary script in test/scripts/.
1208 # Also ensure that there are no error messages such as
1209 # "No such file or directory", which would indicate that some required
1210 # file is missing (ssl-opt.sh tolerates the absence of some files so
1211 # may exit with status 0 but emit errors).
1212 if_build_succeeded ./tests/ssl-opt.sh -f 'Fallback SCSV: beginning of list' 2>ssl-opt.err
1213 if [ -s ssl-opt.err ]; then
1214 cat ssl-opt.err >&2
1215 record_status [ ! -s ssl-opt.err ]
1216 rm ssl-opt.err
1217 fi
1218 cd "$MBEDTLS_ROOT_DIR"
1219 rm -rf "$OUT_OF_SOURCE_DIR"
1220 unset MBEDTLS_ROOT_DIR
1221}
Andres AGdc192212016-08-31 17:33:13 +01001222
Gilles Peskine192c72f2017-12-21 15:59:21 +01001223
1224
1225################################################################
1226#### Termination
1227################################################################
1228
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001229post_report () {
1230 msg "Done, cleaning up"
1231 cleanup
1232
1233 final_report
1234}
1235
1236
1237
1238################################################################
1239#### Run all the things
1240################################################################
1241
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001242# Run one component and clean up afterwards.
1243run_component () {
Gilles Peskine72adb432019-01-02 18:57:02 +01001244 # Back up the configuration in case the component modifies it.
1245 # The cleanup function will restore it.
1246 cp -p "$CONFIG_H" "$CONFIG_BAK"
Gilles Peskine11ddca62018-12-04 12:49:28 +01001247 current_component="$1"
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001248 "$@"
1249 cleanup
1250}
1251
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001252# Preliminary setup
1253pre_check_environment
1254pre_initialize_variables
1255pre_parse_command_line "$@"
1256
1257pre_check_git
1258build_status=0
1259if [ $KEEP_GOING -eq 1 ]; then
1260 pre_setup_keep_going
1261else
1262 record_status () {
1263 "$@"
1264 }
1265fi
1266pre_print_configuration
1267pre_check_tools
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001268cleanup
Gilles Peskine7c652162017-12-11 00:01:40 +01001269
Gilles Peskineeb39b9b2019-01-08 23:41:00 +01001270# Run the requested tests.
Gilles Peskine6e984232018-11-27 21:37:53 +01001271for component in $RUN_COMPONENTS; do
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001272 run_component "component_$component"
1273done
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001274
1275# We're done.
1276post_report