blob: 39fff1bee64d8170819006ce65f38370e9ade3b0 [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}
Andres AGdc192212016-08-31 17:33:13 +0100134
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100135 # if MAKEFLAGS is not set add the -j option to speed up invocations of make
Gilles Peskine7120f772019-01-06 20:15:26 +0000136 if [ -z "${MAKEFLAGS+set}" ]; then
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100137 export MAKEFLAGS="-j"
138 fi
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100139
Gilles Peskinec20a4052019-10-21 17:11:33 +0200140 # CFLAGS and LDFLAGS for Asan builds that don't use CMake
Gilles Peskine4c2697f2019-10-21 19:06:33 +0200141 ASAN_CFLAGS='-Werror -Wall -Wextra -fsanitize=address,undefined -fno-sanitize-recover=all'
Gilles Peskinec20a4052019-10-21 17:11:33 +0200142
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100143 # Gather the list of available components. These are the functions
144 # defined in this script whose name starts with "component_".
145 # Parse the script with sed, because in sh there is no way to list
146 # defined functions.
147 ALL_COMPONENTS=$(sed -n 's/^ *component_\([0-9A-Z_a-z]*\) *().*/\1/p' <"$0")
Gilles Peskine3fbdd212019-01-08 23:33:45 +0100148
149 # Exclude components that are not supported on this platform.
150 SUPPORTED_COMPONENTS=
151 for component in $ALL_COMPONENTS; do
152 case $(type "support_$component" 2>&1) in
153 *' function'*)
154 if ! support_$component; then continue; fi;;
155 esac
156 SUPPORTED_COMPONENTS="$SUPPORTED_COMPONENTS $component"
157 done
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100158}
Andres AG38495a32016-07-12 16:54:33 +0100159
Gilles Peskineff7238f2019-01-10 00:05:18 +0100160# Test whether the component $1 is included in the command line patterns.
161is_component_included()
Gilles Peskine6e984232018-11-27 21:37:53 +0100162{
163 set -f
Gilles Peskineeb39b9b2019-01-08 23:41:00 +0100164 for pattern in $COMMAND_LINE_COMPONENTS; do
Gilles Peskine6e984232018-11-27 21:37:53 +0100165 set +f
166 case ${1#component_} in $pattern) return 0;; esac
167 done
168 set +f
169 return 1
170}
171
Simon Butcher41eeccf2016-09-07 00:07:09 +0100172usage()
SimonB2e23c822016-04-16 21:54:39 +0100173{
Gilles Peskine709346a2017-12-10 23:43:39 +0100174 cat <<EOF
Gilles Peskine91bd8b72019-01-08 23:01:34 +0100175Usage: $0 [OPTION]... [COMPONENT]...
176Run mbedtls release validation tests.
177By default, run all tests. With one or more COMPONENT, run only those.
Gilles Peskineff7238f2019-01-10 00:05:18 +0100178COMPONENT can be the name of a component or a shell wildcard pattern.
179
180Examples:
181 $0 "check_*"
182 Run all sanity checks.
183 $0 --no-armcc --except test_memsan
184 Run everything except builds that require armcc and MemSan.
Gilles Peskine91bd8b72019-01-08 23:01:34 +0100185
186Special options:
187 -h|--help Print this help and exit.
Gilles Peskineb3241cb2019-01-08 23:44:07 +0100188 --list-all-components List all available test components and exit.
189 --list-components List components supported on this platform and exit.
Gilles Peskine709346a2017-12-10 23:43:39 +0100190
191General options:
192 -f|--force Force the tests to overwrite any modified files.
Gilles Peskine7c652162017-12-11 00:01:40 +0100193 -k|--keep-going Run all tests and report errors at the end.
Gilles Peskine709346a2017-12-10 23:43:39 +0100194 -m|--memory Additional optional memory tests.
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100195 --armcc Run ARM Compiler builds (on by default).
Gilles Peskineff7238f2019-01-10 00:05:18 +0100196 --except Exclude the COMPONENTs listed on the command line,
197 instead of running only those.
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100198 --no-armcc Skip ARM Compiler builds.
Gilles Peskine19ceb712018-03-21 08:40:26 +0100199 --no-force Refuse to overwrite modified files (default).
200 --no-keep-going Stop at the first error (default).
201 --no-memory No additional memory tests (default).
Gilles Peskine2a22a802017-12-21 15:19:00 +0100202 --no-yotta Skip yotta module build.
Gilles Peskine709346a2017-12-10 23:43:39 +0100203 --out-of-source-dir=<path> Directory used for CMake out-of-source build tests.
Gilles Peskine19ceb712018-03-21 08:40:26 +0100204 --random-seed Use a random seed value for randomized tests (default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100205 -r|--release-test Run this script in release mode. This fixes the seed value to 1.
206 -s|--seed Integer seed value to use for this test run.
Gilles Peskine2a22a802017-12-21 15:19:00 +0100207 --yotta Build yotta module (on by default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100208
209Tool path options:
210 --armc5-bin-dir=<ARMC5_bin_dir_path> ARM Compiler 5 bin directory.
211 --armc6-bin-dir=<ARMC6_bin_dir_path> ARM Compiler 6 bin directory.
212 --gnutls-cli=<GnuTLS_cli_path> GnuTLS client executable to use for most tests.
213 --gnutls-serv=<GnuTLS_serv_path> GnuTLS server executable to use for most tests.
214 --gnutls-legacy-cli=<GnuTLS_cli_path> GnuTLS client executable to use for legacy tests.
215 --gnutls-legacy-serv=<GnuTLS_serv_path> GnuTLS server executable to use for legacy tests.
216 --openssl=<OpenSSL_path> OpenSSL executable to use for most tests.
217 --openssl-legacy=<OpenSSL_path> OpenSSL executable to use for legacy tests e.g. SSLv3.
218EOF
SimonB2e23c822016-04-16 21:54:39 +0100219}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100220
221# remove built files as well as the cmake cache/config
222cleanup()
223{
Gilles Peskinea71d64c2018-03-21 12:16:57 +0100224 if [ -n "${MBEDTLS_ROOT_DIR+set}" ]; then
225 cd "$MBEDTLS_ROOT_DIR"
226 fi
227
Gilles Peskine7c652162017-12-11 00:01:40 +0100228 command make clean
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200229
Gilles Peskine31b07e22018-03-21 12:15:06 +0100230 # Remove CMake artefacts
231 find . -name .git -prune -o -name yotta -prune -o \
232 -iname CMakeFiles -exec rm -rf {} \+ -o \
233 \( -iname cmake_install.cmake -o \
234 -iname CTestTestfile.cmake -o \
235 -iname CMakeCache.txt \) -exec rm {} \+
236 # Recover files overwritten by in-tree CMake builds
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000237 rm -f include/Makefile include/mbedtls/Makefile programs/*/Makefile
Paul Bakkerfe0984d2014-06-13 00:13:45 +0200238 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile
239 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200240
241 if [ -f "$CONFIG_BAK" ]; then
242 mv "$CONFIG_BAK" "$CONFIG_H"
243 fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100244}
245
Gilles Peskine7c652162017-12-11 00:01:40 +0100246# Executed on exit. May be redefined depending on command line options.
247final_report () {
248 :
249}
250
251fatal_signal () {
252 cleanup
253 final_report $1
254 trap - $1
255 kill -$1 $$
256}
257
258trap 'fatal_signal HUP' HUP
259trap 'fatal_signal INT' INT
260trap 'fatal_signal TERM' TERM
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200261
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100262msg()
263{
Gilles Peskine11ddca62018-12-04 12:49:28 +0100264 if [ -n "${current_component:-}" ]; then
265 current_section="${current_component#component_}: $1"
266 else
267 current_section="$1"
268 fi
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100269 echo ""
270 echo "******************************************************************"
Gilles Peskine11ddca62018-12-04 12:49:28 +0100271 echo "* $current_section "
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000272 printf "* "; date
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100273 echo "******************************************************************"
274}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100275
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100276armc6_build_test()
277{
278 FLAGS="$1"
Andres AGa5cd9732016-10-17 15:23:10 +0100279
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100280 msg "build: ARM Compiler 6 ($FLAGS), make"
281 ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \
282 WARNING_CFLAGS='-xc -std=c99' make lib
283 make clean
284}
Andres AGa5cd9732016-10-17 15:23:10 +0100285
Andres AGd9eba4b2016-08-26 14:42:14 +0100286err_msg()
287{
288 echo "$1" >&2
289}
290
291check_tools()
292{
293 for TOOL in "$@"; do
Andres AG98393602017-01-31 17:04:45 +0000294 if ! `type "$TOOL" >/dev/null 2>&1`; then
Andres AGd9eba4b2016-08-26 14:42:14 +0100295 err_msg "$TOOL not found!"
296 exit 1
297 fi
298 done
299}
300
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100301pre_parse_command_line () {
Gilles Peskineeb39b9b2019-01-08 23:41:00 +0100302 COMMAND_LINE_COMPONENTS=
Gilles Peskineff7238f2019-01-10 00:05:18 +0100303 all_except=0
Gilles Peskine53084872019-01-09 23:13:54 +0100304 no_armcc=
Gilles Peskine6e984232018-11-27 21:37:53 +0100305
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100306 while [ $# -gt 0 ]; do
307 case "$1" in
Gilles Peskine53084872019-01-09 23:13:54 +0100308 --armcc) no_armcc=;;
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100309 --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
310 --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
Gilles Peskineeb39b9b2019-01-08 23:41:00 +0100311 --except) all_except=1;;
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100312 --force|-f) FORCE=1;;
313 --gnutls-cli) shift; GNUTLS_CLI="$1";;
314 --gnutls-legacy-cli) shift; GNUTLS_LEGACY_CLI="$1";;
315 --gnutls-legacy-serv) shift; GNUTLS_LEGACY_SERV="$1";;
316 --gnutls-serv) shift; GNUTLS_SERV="$1";;
317 --help|-h) usage; exit;;
318 --keep-going|-k) KEEP_GOING=1;;
Gilles Peskineb3241cb2019-01-08 23:44:07 +0100319 --list-all-components) printf '%s\n' $ALL_COMPONENTS; exit;;
320 --list-components) printf '%s\n' $SUPPORTED_COMPONENTS; exit;;
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100321 --memory|-m) MEMORY=1;;
Gilles Peskine53084872019-01-09 23:13:54 +0100322 --no-armcc) no_armcc=1;;
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100323 --no-force) FORCE=0;;
324 --no-keep-going) KEEP_GOING=0;;
325 --no-memory) MEMORY=0;;
326 --no-yotta) YOTTA=0;;
327 --openssl) shift; OPENSSL="$1";;
328 --openssl-legacy) shift; OPENSSL_LEGACY="$1";;
329 --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
330 --random-seed) unset SEED;;
331 --release-test|-r) SEED=1;;
332 --seed|-s) shift; SEED="$1";;
333 --yotta) YOTTA=1;;
Gilles Peskine91bd8b72019-01-08 23:01:34 +0100334 -*)
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100335 echo >&2 "Unknown option: $1"
336 echo >&2 "Run $0 --help for usage."
337 exit 120
338 ;;
Gilles Peskineeb39b9b2019-01-08 23:41:00 +0100339 *) COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS $1";;
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100340 esac
341 shift
342 done
Gilles Peskine91bd8b72019-01-08 23:01:34 +0100343
Gilles Peskineff7238f2019-01-10 00:05:18 +0100344 # With no list of components, run everything.
Gilles Peskineeb39b9b2019-01-08 23:41:00 +0100345 if [ -z "$COMMAND_LINE_COMPONENTS" ]; then
346 all_except=1
347 fi
348
Gilles Peskine53084872019-01-09 23:13:54 +0100349 # --no-armcc is a legacy option. The modern way is --except '*_armcc*'.
350 # Ignore it if components are listed explicitly on the command line.
Gilles Peskineff7238f2019-01-10 00:05:18 +0100351 if [ -n "$no_armcc" ] && [ $all_except -eq 1 ]; then
Gilles Peskine53084872019-01-09 23:13:54 +0100352 COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS *_armcc*"
353 # --no-armcc also disables yotta.
354 COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS *_yotta*"
355 fi
356
Gilles Peskineeb39b9b2019-01-08 23:41:00 +0100357 # Build the list of components to run.
Gilles Peskineff7238f2019-01-10 00:05:18 +0100358 RUN_COMPONENTS=
359 for component in $SUPPORTED_COMPONENTS; do
360 if is_component_included "$component"; [ $? -eq $all_except ]; then
361 RUN_COMPONENTS="$RUN_COMPONENTS $component"
362 fi
363 done
Gilles Peskineeb39b9b2019-01-08 23:41:00 +0100364
365 unset all_except
Gilles Peskine53084872019-01-09 23:13:54 +0100366 unset no_armcc
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100367}
SimonB2e23c822016-04-16 21:54:39 +0100368
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100369pre_check_git () {
370 if [ $FORCE -eq 1 ]; then
Gilles Peskinec7800952019-01-09 23:14:09 +0100371 rm -rf "$OUT_OF_SOURCE_DIR"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100372 if [ $YOTTA -eq 1 ]; then
Gilles Peskinec7800952019-01-09 23:14:09 +0100373 rm -rf yotta/module
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100374 fi
375 git checkout-index -f -q $CONFIG_H
376 cleanup
377 else
378
379 if [ $YOTTA -ne 0 ] && [ -d yotta/module ]; then
380 err_msg "Warning - there is an existing yotta module in the directory 'yotta/module'"
381 echo "You can either delete your work and retry, or force the test to overwrite the"
382 echo "test by rerunning the script as: $0 --force"
383 exit 1
384 fi
385
386 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
387 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
388 echo "You can either delete this directory manually, or force the test by rerunning"
389 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
390 exit 1
391 fi
392
Gilles Peskinec9663b12019-01-09 22:30:01 +0100393 if ! git diff --quiet include/mbedtls/config.h; then
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100394 err_msg "Warning - the configuration file 'include/mbedtls/config.h' has been edited. "
395 echo "You can either delete or preserve your work, or force the test by rerunning the"
396 echo "script as: $0 --force"
397 exit 1
398 fi
Gilles Peskineda519252017-11-30 13:22:04 +0100399 fi
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100400}
SimonB2e23c822016-04-16 21:54:39 +0100401
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100402pre_setup_keep_going () {
Gilles Peskine7c652162017-12-11 00:01:40 +0100403 failure_summary=
404 failure_count=0
405 start_red=
406 end_color=
407 if [ -t 1 ]; then
Gilles Peskine9736b9d2018-01-02 21:54:17 +0100408 case "${TERM:-}" in
Gilles Peskine7c652162017-12-11 00:01:40 +0100409 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
410 start_red=$(printf '\033[31m')
411 end_color=$(printf '\033[0m')
412 ;;
413 esac
414 fi
415 record_status () {
416 if "$@"; then
417 last_status=0
418 else
419 last_status=$?
420 text="$current_section: $* -> $last_status"
421 failure_summary="$failure_summary
422$text"
423 failure_count=$((failure_count + 1))
424 echo "${start_red}^^^^$text^^^^${end_color}"
425 fi
426 }
427 make () {
428 case "$*" in
429 *test|*check)
430 if [ $build_status -eq 0 ]; then
431 record_status command make "$@"
432 else
433 echo "(skipped because the build failed)"
434 fi
435 ;;
436 *)
437 record_status command make "$@"
438 build_status=$last_status
439 ;;
440 esac
441 }
442 final_report () {
443 if [ $failure_count -gt 0 ]; then
444 echo
445 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
446 echo "${start_red}FAILED: $failure_count${end_color}$failure_summary"
447 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Jaeden Amero5113bde2018-07-20 16:42:14 +0100448 exit 1
Gilles Peskine7c652162017-12-11 00:01:40 +0100449 elif [ -z "${1-}" ]; then
450 echo "SUCCESS :)"
451 fi
452 if [ -n "${1-}" ]; then
453 echo "Killed by SIG$1."
454 fi
455 }
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100456}
457
Gilles Peskine7c652162017-12-11 00:01:40 +0100458if_build_succeeded () {
459 if [ $build_status -eq 0 ]; then
460 record_status "$@"
461 fi
462}
463
Gilles Peskine30bc3852019-01-09 23:25:25 +0100464# to be used instead of ! for commands run with
465# record_status or if_build_succeeded
466not() {
467 ! "$@"
468}
469
470
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100471pre_print_configuration () {
472 msg "info: $0 configuration"
473 echo "MEMORY: $MEMORY"
474 echo "FORCE: $FORCE"
475 echo "SEED: ${SEED-"UNSET"}"
476 echo "OPENSSL: $OPENSSL"
477 echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
478 echo "GNUTLS_CLI: $GNUTLS_CLI"
479 echo "GNUTLS_SERV: $GNUTLS_SERV"
480 echo "GNUTLS_LEGACY_CLI: $GNUTLS_LEGACY_CLI"
481 echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV"
482 echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
483 echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
484}
Andres AG7770ea82016-10-10 15:46:20 +0100485
Andres AGd9eba4b2016-08-26 14:42:14 +0100486# Make sure the tools we need are available.
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100487pre_check_tools () {
Gilles Peskine541fb1e2019-01-06 22:40:00 +0000488 # Build the list of variables to pass to output_env.sh.
489 set env
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100490
Gilles Peskine541fb1e2019-01-06 22:40:00 +0000491 case " $RUN_COMPONENTS " in
492 # Require OpenSSL and GnuTLS if running any tests (as opposed to
493 # only doing builds). Not all tests run OpenSSL and GnuTLS, but this
494 # is a good enough approximation in practice.
495 *" test_"*)
496 # To avoid setting OpenSSL and GnuTLS for each call to compat.sh
497 # and ssl-opt.sh, we just export the variables they require.
498 export OPENSSL_CMD="$OPENSSL"
499 export GNUTLS_CLI="$GNUTLS_CLI"
500 export GNUTLS_SERV="$GNUTLS_SERV"
501 # Avoid passing --seed flag in every call to ssl-opt.sh
502 if [ -n "${SEED-}" ]; then
503 export SEED
504 fi
505 set "$@" OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY"
506 set "$@" GNUTLS_CLI="$GNUTLS_CLI" GNUTLS_SERV="$GNUTLS_SERV"
507 set "$@" GNUTLS_LEGACY_CLI="$GNUTLS_LEGACY_CLI"
508 set "$@" GNUTLS_LEGACY_SERV="$GNUTLS_LEGACY_SERV"
509 check_tools "$OPENSSL" "$OPENSSL_LEGACY" \
510 "$GNUTLS_CLI" "$GNUTLS_SERV" \
511 "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV"
512 ;;
513 esac
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100514
Gilles Peskine541fb1e2019-01-06 22:40:00 +0000515 case " $RUN_COMPONENTS " in
516 *_doxygen[_\ ]*) check_tools "doxygen" "dot";;
517 esac
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100518
Gilles Peskine541fb1e2019-01-06 22:40:00 +0000519 case " $RUN_COMPONENTS " in
520 *_arm_none_eabi_gcc[_\ ]*) check_tools "arm-none-eabi-gcc";;
521 esac
522
523 case " $RUN_COMPONENTS " in
524 *_mingw[_\ ]*) check_tools "i686-w64-mingw32-gcc";;
525 esac
526
527 case " $RUN_COMPONENTS " in
Gilles Peskine53084872019-01-09 23:13:54 +0100528 *_armcc*|*_yotta*)
Gilles Peskine541fb1e2019-01-06 22:40:00 +0000529 ARMC5_CC="$ARMC5_BIN_DIR/armcc"
530 ARMC5_AR="$ARMC5_BIN_DIR/armar"
531 ARMC6_CC="$ARMC6_BIN_DIR/armclang"
532 ARMC6_AR="$ARMC6_BIN_DIR/armar"
Gilles Peskine53084872019-01-09 23:13:54 +0100533 check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC6_CC" "$ARMC6_AR";;
534 esac
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100535
536 msg "info: output_env.sh"
Gilles Peskine53084872019-01-09 23:13:54 +0100537 case $RUN_COMPONENTS in
538 *_armcc*|*_yotta*)
539 set "$@" ARMC5_CC="$ARMC5_CC" ARMC6_CC="$ARMC6_CC" RUN_ARMCC=1;;
540 *) set "$@" RUN_ARMCC=0;;
541 esac
542 "$@" scripts/output_env.sh
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100543}
Andres AGd9eba4b2016-08-26 14:42:14 +0100544
Gilles Peskine192c72f2017-12-21 15:59:21 +0100545
546
547################################################################
548#### Basic checks
549################################################################
SimonB2e23c822016-04-16 21:54:39 +0100550
551#
552# Test Suites to be executed
553#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200554# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100555# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard61bc57a2014-08-14 11:29:06 +0200556# and/or are more likely to fail than others (eg I use Clang most of the
557# time, so start with a GCC build).
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200558# 2. Minimize total running time, by avoiding useless rebuilds
559#
560# Indicative running times are given for reference.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100561
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100562component_check_recursion () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100563 msg "test: recursion.pl" # < 1s
564 record_status tests/scripts/recursion.pl library/*.c
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100565}
Manuel Pégourié-Gonnardea29d152014-11-20 17:32:33 +0100566
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100567component_check_generated_files () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100568 msg "test: freshness of generated source files" # < 1s
569 record_status tests/scripts/check-generated-files.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100570}
Manuel Pégourié-Gonnardb3b8e432015-02-13 14:52:19 +0000571
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100572component_check_doxy_blocks () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100573 msg "test: doxygen markup outside doxygen blocks" # < 1s
574 record_status tests/scripts/check-doxy-blocks.pl
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100575}
Manuel Pégourié-Gonnardd09a6b52015-04-09 17:19:23 +0200576
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100577component_check_files () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100578 msg "test: check-files.py" # < 1s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100579 record_status tests/scripts/check-files.py
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100580}
Manuel Pégourié-Gonnard77d56bb2015-07-28 15:00:37 +0200581
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100582component_check_names () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100583 msg "test/build: declared and exported names" # < 3s
Gilles Peskinee952fdf2019-05-15 17:52:22 +0200584 record_status tests/scripts/check-names.sh -v
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100585}
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +0200586
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100587component_check_doxygen_warnings () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100588 msg "test: doxygen warnings" # ~ 3s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100589 record_status tests/scripts/doxygen.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100590}
Andres Amaya Garciadd29c2f2017-05-04 11:35:51 +0100591
Simon Butcher948f2642018-07-20 21:27:33 +0100592
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100593################################################################
594#### Build and test many configurations and targets
595################################################################
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100596
k-stachowiak45d0ba12019-06-04 13:14:58 +0200597component_test_large_ecdsa_key_signature () {
598
599 SMALL_MPI_MAX_SIZE=136 # Small enough to interfere with the EC signatures
600
601 msg "build: cmake + MBEDTLS_MPI_MAX_SIZE=${SMALL_MPI_MAX_SIZE}, gcc, ASan" # ~ 1 min 50s
602 scripts/config.pl set MBEDTLS_MPI_MAX_SIZE $SMALL_MPI_MAX_SIZE
603 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
604 make
605
606 INEVITABLY_PRESENT_FILE=Makefile
607 SIGNATURE_FILE="${INEVITABLY_PRESENT_FILE}.sig" # Warning, this is rm -f'ed below
608
609 msg "test: pk_sign secp521r1_prv.der for MBEDTLS_MPI_MAX_SIZE=${SMALL_MPI_MAX_SIZE} (ASan build)" # ~ 5s
610 if_build_succeeded programs/pkey/pk_sign tests/data_files/secp521r1_prv.der $INEVITABLY_PRESENT_FILE
611 rm -f $SIGNATURE_FILE
612}
613
Gilles Peskine1270d322019-04-08 17:00:15 +0200614component_test_default_out_of_box () {
615 msg "build: make, default config (out-of-box)" # ~1min
616 make
617
618 msg "test: main suites make, default config (out-of-box)" # ~10s
619 make test
620
621 msg "selftest: make, default config (out-of-box)" # ~10s
Gilles Peskinebfda0332020-04-23 23:37:45 +0200622 if_build_succeeded programs/test/selftest
Gilles Peskine1270d322019-04-08 17:00:15 +0200623}
624
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100625component_build_yotta () {
Gilles Peskine53084872019-01-09 23:13:54 +0100626 # Note - use of yotta is deprecated, and yotta also requires armcc to be on the
627 # path, and uses whatever version of armcc it finds there.
628 msg "build: create and build yotta module" # ~ 30s
629 record_status tests/scripts/yotta-build.sh
630}
631support_build_yotta () {
632 [ $YOTTA -ne 0 ]
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100633}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100634
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100635component_test_default_cmake_gcc_asan () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100636 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100637 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100638 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +0200639
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100640 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100641 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100642
Gilles Peskinebfda0332020-04-23 23:37:45 +0200643 msg "test: selftest (ASan build)" # ~ 10s
644 if_build_succeeded programs/test/selftest
645
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100646 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
Gilles Peskine7c652162017-12-11 00:01:40 +0100647 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100648
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100649 msg "test: compat.sh (ASan build)" # ~ 6 min
650 if_build_succeeded tests/compat.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100651}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000652
Hanno Becker167ae432019-02-26 14:27:09 +0000653component_test_full_cmake_gcc_asan () {
654 msg "build: full config, cmake, gcc, ASan"
655 scripts/config.pl full
656 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
657 make
658
659 msg "test: main suites (inc. selftests) (full config, ASan build)"
660 make test
661
Gilles Peskinebfda0332020-04-23 23:37:45 +0200662 msg "test: selftest (ASan build)" # ~ 10s
663 if_build_succeeded programs/test/selftest
664
Hanno Becker167ae432019-02-26 14:27:09 +0000665 msg "test: ssl-opt.sh (full config, ASan build)"
666 if_build_succeeded tests/ssl-opt.sh
667
668 msg "test: compat.sh (full config, ASan build)"
669 if_build_succeeded tests/compat.sh
670}
671
Manuel Pégourié-Gonnard51e24942020-01-02 11:45:12 +0100672component_test_zlib_make() {
673 msg "build: zlib enabled, make"
674 scripts/config.pl set MBEDTLS_ZLIB_SUPPORT
675 make ZLIB=1 CFLAGS='-Werror -O1'
676
677 msg "test: main suites (zlib, make)"
678 make test
679
680 msg "test: ssl-opt.sh (zlib, make)"
681 if_build_succeeded tests/ssl-opt.sh
682}
Manuel Pégourié-Gonnard2150fb22020-01-24 10:17:20 +0100683support_test_zlib_make () {
684 base=support_test_zlib_$$
685 cat <<'EOF' > ${base}.c
686#include "zlib.h"
687int main(void) { return 0; }
688EOF
689 gcc -o ${base}.exe ${base}.c -lz 2>/dev/null
690 ret=$?
691 rm -f ${base}.*
692 return $ret
693}
Manuel Pégourié-Gonnard51e24942020-01-02 11:45:12 +0100694
695component_test_zlib_cmake() {
696 msg "build: zlib enabled, cmake"
697 scripts/config.pl set MBEDTLS_ZLIB_SUPPORT
698 cmake -D ENABLE_ZLIB_SUPPORT=On -D CMAKE_BUILD_TYPE:String=Check .
699 make
700
701 msg "test: main suites (zlib, cmake)"
702 make test
703
704 msg "test: ssl-opt.sh (zlib, cmake)"
705 if_build_succeeded tests/ssl-opt.sh
706}
Manuel Pégourié-Gonnard2150fb22020-01-24 10:17:20 +0100707support_test_zlib_cmake () {
708 support_test_zlib_make "$@"
709}
Manuel Pégourié-Gonnard51e24942020-01-02 11:45:12 +0100710
Gilles Peskine3484ed82019-01-08 22:51:19 +0100711component_test_ref_configs () {
712 msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
713 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
714 record_status tests/scripts/test-ref-configs.pl
715}
716
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100717component_test_sslv3 () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100718 msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100719 scripts/config.pl set MBEDTLS_SSL_PROTO_SSL3
720 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
721 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000722
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100723 msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
724 make test
725
726 msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
727 if_build_succeeded tests/compat.sh -m 'tls1 tls1_1 tls1_2 dtls1 dtls1_2'
728 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
729
730 msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
731 if_build_succeeded tests/ssl-opt.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100732}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100733
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100734component_test_no_renegotiation () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100735 msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100736 scripts/config.pl unset MBEDTLS_SSL_RENEGOTIATION
737 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
738 make
739
740 msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
741 make test
742
743 msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
744 if_build_succeeded tests/ssl-opt.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100745}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100746
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100747component_test_rsa_no_crt () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100748 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100749 scripts/config.pl set MBEDTLS_RSA_NO_CRT
750 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
751 make
752
753 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
754 make test
755
756 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
757 if_build_succeeded tests/ssl-opt.sh -f RSA
758
759 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
760 if_build_succeeded tests/compat.sh -t RSA
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100761}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100762
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100763component_test_full_cmake_clang () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100764 msg "build: cmake, full config, clang" # ~ 50s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100765 scripts/config.pl full
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100766 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check -D ENABLE_TESTING=On .
767 make
768
769 msg "test: main suites (full config)" # ~ 5s
770 make test
771
772 msg "test: ssl-opt.sh default (full config)" # ~ 1s
773 if_build_succeeded tests/ssl-opt.sh -f Default
774
Andres Amaya Garcia0a0e5b12019-01-08 21:42:27 +0000775 msg "test: compat.sh RC4, DES, 3DES & NULL (full config)" # ~ 2 min
Andres Amaya Garciafea3d0a2019-02-19 20:20:57 +0000776 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 +0100777}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100778
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100779component_build_deprecated () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100780 msg "build: make, full config + DEPRECATED_WARNING, gcc -O" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100781 scripts/config.pl full
782 scripts/config.pl set MBEDTLS_DEPRECATED_WARNING
783 # Build with -O -Wextra to catch a maximum of issues.
784 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra' lib programs
785 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
786
787 msg "build: make, full config + DEPRECATED_REMOVED, clang -O" # ~ 30s
788 # No cleanup, just tweak the configuration and rebuild
789 make clean
790 scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
791 scripts/config.pl set MBEDTLS_DEPRECATED_REMOVED
792 # Build with -O -Wextra to catch a maximum of issues.
793 make CC=clang CFLAGS='-O -Werror -Wall -Wextra' lib programs
794 make CC=clang CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100795}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100796
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100797component_test_depends_curves () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100798 msg "test/build: curves.pl (gcc)" # ~ 4 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100799 record_status tests/scripts/curves.pl
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_hashes () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100803 msg "test/build: depends-hashes.pl (gcc)" # ~ 2 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100804 record_status tests/scripts/depends-hashes.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_pkalgs () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100808 msg "test/build: depends-pkalgs.pl (gcc)" # ~ 2 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100809 record_status tests/scripts/depends-pkalgs.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_build_key_exchanges () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100813 msg "test/build: key-exchanges (gcc)" # ~ 1 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100814 record_status tests/scripts/key-exchanges.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_default_make_gcc () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100818 msg "build: Unix make, -Os (gcc)" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100819 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100820}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100821
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100822component_test_no_platform () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100823 # Full configuration build, without platform support, file IO and net sockets.
824 # This should catch missing mbedtls_printf definitions, and by disabling file
825 # IO, it should catch missing '#include <stdio.h>'
826 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100827 scripts/config.pl full
828 scripts/config.pl unset MBEDTLS_PLATFORM_C
829 scripts/config.pl unset MBEDTLS_NET_C
830 scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
831 scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
832 scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
833 scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
834 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
835 scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
836 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100837 scripts/config.pl unset MBEDTLS_FS_IO
838 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
839 # to re-enable platform integration features otherwise disabled in C99 builds
Gilles Peskinec9247122019-09-20 19:23:10 +0200840 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -Os -D_DEFAULT_SOURCE' lib programs
841 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os' test
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100842}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100843
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100844component_build_no_std_function () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100845 # catch compile bugs in _uninit functions
846 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100847 scripts/config.pl full
848 scripts/config.pl set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
849 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskinec9247122019-09-20 19:23:10 +0200850 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100851}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100852
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100853component_build_no_ssl_srv () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100854 msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100855 scripts/config.pl full
856 scripts/config.pl unset MBEDTLS_SSL_SRV_C
Gilles Peskinec9247122019-09-20 19:23:10 +0200857 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100858}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100859
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100860component_build_no_ssl_cli () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100861 msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100862 scripts/config.pl full
863 scripts/config.pl unset MBEDTLS_SSL_CLI_C
Gilles Peskinec9247122019-09-20 19:23:10 +0200864 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100865}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100866
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100867component_build_no_sockets () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100868 # Note, C99 compliance can also be tested with the sockets support disabled,
869 # as that requires a POSIX platform (which isn't the same as C99).
870 msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100871 scripts/config.pl full
872 scripts/config.pl unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
873 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
Gilles Peskinec9247122019-09-20 19:23:10 +0200874 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1 -std=c99 -pedantic' lib
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100875}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100876
Andrzej Kurek9a461a12019-09-05 09:27:47 -0400877component_test_memory_buffer_allocator_backtrace () {
878 msg "build: default config with memory buffer allocator and backtrace enabled"
Hanno Beckerf5baaaa2019-02-26 14:34:13 +0000879 scripts/config.pl set MBEDTLS_MEMORY_BUFFER_ALLOC_C
Andrzej Kurek9a461a12019-09-05 09:27:47 -0400880 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
Hanno Beckerf5baaaa2019-02-26 14:34:13 +0000881 scripts/config.pl set MBEDTLS_MEMORY_BACKTRACE
Andrzej Kurek9b1c2482019-09-10 02:58:34 -0400882 scripts/config.pl set MBEDTLS_MEMORY_DEBUG
Andrzej Kurek9a461a12019-09-05 09:27:47 -0400883 CC=gcc cmake .
884 make
885
886 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C and MBEDTLS_MEMORY_BACKTRACE"
887 make test
888}
889
890component_test_memory_buffer_allocator () {
891 msg "build: default config with memory buffer allocator"
892 scripts/config.pl set MBEDTLS_MEMORY_BUFFER_ALLOC_C
Hanno Becker7aad93c2019-06-03 16:35:02 +0100893 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
Hanno Beckerf5baaaa2019-02-26 14:34:13 +0000894 CC=gcc cmake .
895 make
896
897 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C"
898 make test
899
900 msg "test: ssl-opt.sh, MBEDTLS_MEMORY_BUFFER_ALLOC_C"
Andrzej Kurek6addfdd2019-09-05 10:09:37 -0400901 # MBEDTLS_MEMORY_BUFFER_ALLOC is slow. Skip tests that tend to time out.
902 if_build_succeeded tests/ssl-opt.sh -e '^DTLS proxy'
Hanno Beckerf5baaaa2019-02-26 14:34:13 +0000903}
904
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100905component_test_no_max_fragment_length () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100906 msg "build: default config except MFL extension (ASan build)" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100907 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
908 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
909 make
910
911 msg "test: ssl-opt.sh, MFL-related tests"
912 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length"
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100913}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100914
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100915component_test_null_entropy () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100916 msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100917 scripts/config.pl set MBEDTLS_TEST_NULL_ENTROPY
918 scripts/config.pl set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
919 scripts/config.pl set MBEDTLS_ENTROPY_C
920 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
921 scripts/config.pl unset MBEDTLS_ENTROPY_HARDWARE_ALT
922 scripts/config.pl unset MBEDTLS_HAVEGE_C
Gilles Peskine4e7b3232019-01-06 19:48:30 +0000923 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan -D UNSAFE_BUILD=ON .
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100924 make
925
926 msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)"
927 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100928}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100929
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100930component_test_platform_calloc_macro () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100931 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100932 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
933 scripts/config.pl set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
934 scripts/config.pl set MBEDTLS_PLATFORM_FREE_MACRO free
935 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
936 make
937
938 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
939 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100940}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100941
Gilles Peskine0981a5d2019-09-17 19:04:38 +0200942component_test_malloc_0_null () {
943 msg "build: malloc(0) returns NULL (ASan+UBSan build)"
944 scripts/config.pl full
945 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
946 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'
947
948 msg "test: malloc(0) returns NULL (ASan+UBSan build)"
949 make test
950
951 msg "selftest: malloc(0) returns NULL (ASan+UBSan build)"
952 # Just the calloc selftest. "make test" ran the others as part of the
953 # test suites.
954 if_build_succeeded programs/test/selftest calloc
955}
956
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100957component_test_make_shared () {
Gilles Peskine770ad7e2019-01-08 23:19:08 +0100958 msg "build/test: make shared" # ~ 40s
959 make SHARED=1 all check
Gilles Peskine950de1e2019-07-03 20:43:32 +0200960 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100961}
962
Gilles Peskine17ecb242019-07-03 20:43:05 +0200963component_test_cmake_shared () {
964 msg "build/test: cmake shared" # ~ 2min
965 cmake -DUSE_SHARED_MBEDTLS_LIBRARY=On .
966 make
Gilles Peskine950de1e2019-07-03 20:43:32 +0200967 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskine17ecb242019-07-03 20:43:05 +0200968 make test
969}
970
Gilles Peskinefa0e8b52019-09-20 19:56:06 +0200971test_build_opt () {
972 info=$1 cc=$2; shift 2
973 for opt in "$@"; do
974 msg "build/test: $cc $opt, $info" # ~ 30s
975 make CC="$cc" CFLAGS="$opt -Wall -Wextra -Werror"
976 # We're confident enough in compilers to not run _all_ the tests,
977 # but at least run the unit tests. In particular, runs with
978 # optimizations use inline assembly whereas runs with -O0
979 # skip inline assembly.
980 make test # ~30s
981 make clean
982 done
983}
984
985component_test_clang_opt () {
986 scripts/config.pl full
987 test_build_opt 'full config' clang -O0 -Os -O2
988}
989
990component_test_gcc_opt () {
991 scripts/config.pl full
992 test_build_opt 'full config' gcc -O0 -Os -O2
993}
994
Gilles Peskinef852f5f2019-07-03 20:42:16 +0200995component_build_mbedtls_config_file () {
996 msg "build: make with MBEDTLS_CONFIG_FILE" # ~40s
997 # Use the full config so as to catch a maximum of places where
998 # the check of MBEDTLS_CONFIG_FILE might be missing.
999 scripts/config.pl full
1000 sed 's!"check_config.h"!"mbedtls/check_config.h"!' <"$CONFIG_H" >full_config.h
1001 echo '#error "MBEDTLS_CONFIG_FILE is not working"' >"$CONFIG_H"
1002 make CFLAGS="-I '$PWD' -DMBEDTLS_CONFIG_FILE='\"full_config.h\"'"
1003 rm -f full_config.h
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001004}
1005
Gilles Peskine3fbdd212019-01-08 23:33:45 +01001006component_test_m32_o0 () {
1007 # Build once with -O0, to compile out the i386 specific inline assembly
1008 msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
1009 scripts/config.pl full
Gilles Peskinec20a4052019-10-21 17:11:33 +02001010 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O0" LDFLAGS="-m32 $ASAN_CFLAGS"
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001011
Gilles Peskine3fbdd212019-01-08 23:33:45 +01001012 msg "test: i386, make, gcc -O0 (ASan build)"
1013 make test
1014}
1015support_test_m32_o0 () {
1016 case $(uname -m) in
1017 *64*) true;;
1018 *) false;;
1019 esac
1020}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001021
Gilles Peskine3fbdd212019-01-08 23:33:45 +01001022component_test_m32_o1 () {
1023 # Build again with -O1, to compile in the i386 specific inline assembly
1024 msg "build: i386, make, gcc -O1 (ASan build)" # ~ 30s
1025 scripts/config.pl full
Gilles Peskinec20a4052019-10-21 17:11:33 +02001026 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O1" LDFLAGS="-m32 $ASAN_CFLAGS"
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001027
Gilles Peskine3fbdd212019-01-08 23:33:45 +01001028 msg "test: i386, make, gcc -O1 (ASan build)"
1029 make test
Gilles Peskine11064292019-04-08 16:58:02 +02001030
1031 msg "test ssl-opt.sh, i386, make, gcc-O1"
1032 if_build_succeeded tests/ssl-opt.sh
Gilles Peskine3fbdd212019-01-08 23:33:45 +01001033}
1034support_test_m32_o1 () {
1035 support_test_m32_o0 "$@"
1036}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001037
Gilles Peskine3fbdd212019-01-08 23:33:45 +01001038component_test_mx32 () {
1039 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
1040 scripts/config.pl full
Gilles Peskined535f4d2019-06-07 14:50:09 +02001041 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32' LDFLAGS='-mx32'
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001042
Gilles Peskine3fbdd212019-01-08 23:33:45 +01001043 msg "test: 64-bit ILP32, make, gcc"
1044 make test
1045}
1046support_test_mx32 () {
1047 case $(uname -m) in
1048 amd64|x86_64) true;;
1049 *) false;;
1050 esac
1051}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001052
Peter Kolbus16015dd2018-12-27 06:59:04 -06001053component_test_min_mpi_window_size () {
1054 msg "build: Default + MBEDTLS_MPI_WINDOW_SIZE=1 (ASan build)" # ~ 10s
1055 scripts/config.pl set MBEDTLS_MPI_WINDOW_SIZE 1
1056 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1057 make
1058
1059 msg "test: MBEDTLS_MPI_WINDOW_SIZE=1 - main suites (inc. selftests) (ASan build)" # ~ 10s
1060 make test
1061}
1062
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001063component_test_have_int32 () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001064 msg "build: gcc, force 32-bit bignum limbs"
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001065 scripts/config.pl unset MBEDTLS_HAVE_ASM
1066 scripts/config.pl unset MBEDTLS_AESNI_C
1067 scripts/config.pl unset MBEDTLS_PADLOCK_C
1068 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
1069
1070 msg "test: gcc, force 32-bit bignum limbs"
1071 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001072}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001073
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001074component_test_have_int64 () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001075 msg "build: gcc, force 64-bit bignum limbs"
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001076 scripts/config.pl unset MBEDTLS_HAVE_ASM
1077 scripts/config.pl unset MBEDTLS_AESNI_C
1078 scripts/config.pl unset MBEDTLS_PADLOCK_C
1079 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
1080
1081 msg "test: gcc, force 64-bit bignum limbs"
1082 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001083}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001084
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001085component_build_arm_none_eabi_gcc () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001086 msg "build: arm-none-eabi-gcc, make" # ~ 10s
Manuel Pégourié-Gonnard59bc9a12019-04-29 12:44:12 +02001087 scripts/config.pl baremetal
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001088 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001089}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001090
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001091component_build_arm_none_eabi_gcc_no_udbl_division () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001092 msg "build: arm-none-eabi-gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
Manuel Pégourié-Gonnard59bc9a12019-04-29 12:44:12 +02001093 scripts/config.pl baremetal
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001094 scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
1095 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
1096 echo "Checking that software 64-bit division is not required"
Gilles Peskine30bc3852019-01-09 23:25:25 +01001097 if_build_succeeded not grep __aeabi_uldiv library/*.o
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001098}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001099
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001100component_build_armcc () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001101 msg "build: ARM Compiler 5, make"
Manuel Pégourié-Gonnard59bc9a12019-04-29 12:44:12 +02001102 scripts/config.pl baremetal
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001103
Gilles Peskine53084872019-01-09 23:13:54 +01001104 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
1105 make clean
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001106
Gilles Peskine53084872019-01-09 23:13:54 +01001107 # ARM Compiler 6 - Target ARMv7-A
1108 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-a"
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001109
Gilles Peskine53084872019-01-09 23:13:54 +01001110 # ARM Compiler 6 - Target ARMv7-M
1111 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m"
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001112
Gilles Peskine53084872019-01-09 23:13:54 +01001113 # ARM Compiler 6 - Target ARMv8-A - AArch32
1114 armc6_build_test "--target=arm-arm-none-eabi -march=armv8.2-a"
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001115
Gilles Peskine53084872019-01-09 23:13:54 +01001116 # ARM Compiler 6 - Target ARMv8-M
1117 armc6_build_test "--target=arm-arm-none-eabi -march=armv8-m.main"
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001118
Gilles Peskine53084872019-01-09 23:13:54 +01001119 # ARM Compiler 6 - Target ARMv8-A - AArch64
1120 armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a"
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001121}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001122
Andres Amaya Garciabb13e3b2018-12-05 22:03:56 +00001123component_build_ssl_hw_record_accel() {
1124 msg "build: default config with MBEDTLS_SSL_HW_RECORD_ACCEL enabled"
1125 scripts/config.pl set MBEDTLS_SSL_HW_RECORD_ACCEL
1126 make CFLAGS='-Werror -O1'
1127}
1128
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001129component_test_allow_sha1 () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001130 msg "build: allow SHA1 in certificates by default"
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001131 scripts/config.pl set MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
1132 make CFLAGS='-Werror -Wall -Wextra'
1133 msg "test: allow SHA1 in certificates by default"
1134 make test
1135 if_build_succeeded tests/ssl-opt.sh -f SHA-1
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001136}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001137
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001138component_build_mingw () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001139 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001140 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
1141
1142 # note Make tests only builds the tests, but doesn't run them
1143 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror' WINDOWS_BUILD=1 tests
1144 make WINDOWS_BUILD=1 clean
1145
1146 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
1147 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
1148 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
1149 make WINDOWS_BUILD=1 clean
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001150}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001151
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001152component_test_memsan () {
Gilles Peskine770ad7e2019-01-08 23:19:08 +01001153 msg "build: MSan (clang)" # ~ 1 min 20s
1154 scripts/config.pl unset MBEDTLS_AESNI_C # memsan doesn't grok asm
1155 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
1156 make
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001157
Gilles Peskine770ad7e2019-01-08 23:19:08 +01001158 msg "test: main suites (MSan)" # ~ 10s
1159 make test
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001160
Gilles Peskine770ad7e2019-01-08 23:19:08 +01001161 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
1162 if_build_succeeded tests/ssl-opt.sh
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001163
Gilles Peskine770ad7e2019-01-08 23:19:08 +01001164 # Optional part(s)
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001165
Gilles Peskine770ad7e2019-01-08 23:19:08 +01001166 if [ "$MEMORY" -gt 0 ]; then
1167 msg "test: compat.sh (MSan)" # ~ 6 min 20s
1168 if_build_succeeded tests/compat.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001169 fi
1170}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001171
Gilles Peskine9f553642019-01-10 00:11:42 +01001172component_test_valgrind () {
Gilles Peskine770ad7e2019-01-08 23:19:08 +01001173 msg "build: Release (clang)"
1174 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
1175 make
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001176
Gilles Peskine770ad7e2019-01-08 23:19:08 +01001177 msg "test: main suites valgrind (Release)"
1178 make memcheck
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001179
Gilles Peskine26cae712019-04-08 17:00:56 +02001180 # Optional parts (slow; currently broken on OS X because programs don't
1181 # seem to receive signals under valgrind on OS X).
Gilles Peskine770ad7e2019-01-08 23:19:08 +01001182 if [ "$MEMORY" -gt 0 ]; then
1183 msg "test: ssl-opt.sh --memcheck (Release)"
1184 if_build_succeeded tests/ssl-opt.sh --memcheck
1185 fi
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001186
Gilles Peskine770ad7e2019-01-08 23:19:08 +01001187 if [ "$MEMORY" -gt 1 ]; then
1188 msg "test: compat.sh --memcheck (Release)"
1189 if_build_succeeded tests/compat.sh --memcheck
1190 fi
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001191}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001192
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001193component_test_cmake_out_of_source () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001194 msg "build: cmake 'out-of-source' build"
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001195 MBEDTLS_ROOT_DIR="$PWD"
1196 mkdir "$OUT_OF_SOURCE_DIR"
1197 cd "$OUT_OF_SOURCE_DIR"
1198 cmake "$MBEDTLS_ROOT_DIR"
1199 make
1200
1201 msg "test: cmake 'out-of-source' build"
1202 make test
1203 # Test an SSL option that requires an auxiliary script in test/scripts/.
1204 # Also ensure that there are no error messages such as
1205 # "No such file or directory", which would indicate that some required
1206 # file is missing (ssl-opt.sh tolerates the absence of some files so
1207 # may exit with status 0 but emit errors).
1208 if_build_succeeded ./tests/ssl-opt.sh -f 'Fallback SCSV: beginning of list' 2>ssl-opt.err
1209 if [ -s ssl-opt.err ]; then
1210 cat ssl-opt.err >&2
1211 record_status [ ! -s ssl-opt.err ]
1212 rm ssl-opt.err
1213 fi
1214 cd "$MBEDTLS_ROOT_DIR"
1215 rm -rf "$OUT_OF_SOURCE_DIR"
1216 unset MBEDTLS_ROOT_DIR
1217}
Andres AGdc192212016-08-31 17:33:13 +01001218
Gilles Peskine192c72f2017-12-21 15:59:21 +01001219
1220
1221################################################################
1222#### Termination
1223################################################################
1224
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001225post_report () {
1226 msg "Done, cleaning up"
1227 cleanup
1228
1229 final_report
1230}
1231
1232
1233
1234################################################################
1235#### Run all the things
1236################################################################
1237
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001238# Run one component and clean up afterwards.
1239run_component () {
Gilles Peskine72adb432019-01-02 18:57:02 +01001240 # Back up the configuration in case the component modifies it.
1241 # The cleanup function will restore it.
1242 cp -p "$CONFIG_H" "$CONFIG_BAK"
Gilles Peskine11ddca62018-12-04 12:49:28 +01001243 current_component="$1"
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001244 "$@"
1245 cleanup
1246}
1247
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001248# Preliminary setup
1249pre_check_environment
1250pre_initialize_variables
1251pre_parse_command_line "$@"
1252
1253pre_check_git
1254build_status=0
1255if [ $KEEP_GOING -eq 1 ]; then
1256 pre_setup_keep_going
1257else
1258 record_status () {
1259 "$@"
1260 }
1261fi
1262pre_print_configuration
1263pre_check_tools
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001264cleanup
Gilles Peskine7c652162017-12-11 00:01:40 +01001265
Gilles Peskineeb39b9b2019-01-08 23:41:00 +01001266# Run the requested tests.
Gilles Peskine6e984232018-11-27 21:37:53 +01001267for component in $RUN_COMPONENTS; do
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001268 run_component "component_$component"
1269done
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001270
1271# We're done.
1272post_report