blob: b95429b2944a879715afcc9ca9a4a40a91503822 [file] [log] [blame]
Andres AG31f9b5b2016-10-04 17:14:38 +01001#! /usr/bin/env sh
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01002
Simon Butcher3ea7f522016-03-07 23:22:10 +00003# all.sh
4#
SimonB2e23c822016-04-16 21:54:39 +01005# This file is part of mbed TLS (https://tls.mbed.org)
6#
Gilles Peskine192c72f2017-12-21 15:59:21 +01007# Copyright (c) 2014-2017, ARM Limited, All Rights Reserved
8
9
10
11################################################################
12#### Documentation
13################################################################
14
Simon Butcher3ea7f522016-03-07 23:22:10 +000015# Purpose
Gilles Peskine192c72f2017-12-21 15:59:21 +010016# -------
Simon Butcher3ea7f522016-03-07 23:22:10 +000017#
SimonB2e23c822016-04-16 21:54:39 +010018# To run all tests possible or available on the platform.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010019#
Gilles Peskine192c72f2017-12-21 15:59:21 +010020# Notes for users
21# ---------------
22#
SimonB2e23c822016-04-16 21:54:39 +010023# Warning: the test is destructive. It includes various build modes and
24# configurations, and can and will arbitrarily change the current CMake
Gilles Peskine192c72f2017-12-21 15:59:21 +010025# configuration. The following files must be committed into git:
26# * include/mbedtls/config.h
27# * Makefile, library/Makefile, programs/Makefile, tests/Makefile
28# After running this script, the CMake cache will be lost and CMake
29# will no longer be initialised.
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +010030#
Gilles Peskine192c72f2017-12-21 15:59:21 +010031# The script assumes the presence of a number of tools:
32# * Basic Unix tools (Windows users note: a Unix-style find must be before
33# the Windows find in the PATH)
34# * Perl
35# * GNU Make
36# * CMake
37# * GCC and Clang (recent enough for using ASan with gcc and MemSan with clang, or valgrind)
Andrzej Kurek05be06c2018-06-28 04:41:50 -040038# * G++
Gilles Peskine192c72f2017-12-21 15:59:21 +010039# * arm-gcc and mingw-gcc
40# * ArmCC 5 and ArmCC 6, unless invoked with --no-armcc
Gilles Peskine192c72f2017-12-21 15:59:21 +010041# * OpenSSL and GnuTLS command line tools, recent enough for the
42# interoperability tests. If they don't support SSLv3 then a legacy
43# version of these tools must be present as well (search for LEGACY
44# below).
45# See the invocation of check_tools below for details.
46#
47# This script must be invoked from the toplevel directory of a git
48# working copy of Mbed TLS.
49#
50# Note that the output is not saved. You may want to run
51# script -c tests/scripts/all.sh
52# or
53# tests/scripts/all.sh >all.log 2>&1
54#
55# Notes for maintainers
56# ---------------------
57#
Gilles Peskine8f073122018-11-27 15:58:47 +010058# The bulk of the code is organized into functions that follow one of the
59# following naming conventions:
60# * pre_XXX: things to do before running the tests, in order.
61# * component_XXX: independent components. They can be run in any order.
Gilles Peskinec70637a2019-01-09 22:29:17 +010062# * component_check_XXX: quick tests that aren't worth parallelizing.
63# * component_build_XXX: build things but don't run them.
64# * component_test_XXX: build and test.
Gilles Peskine878cf602019-01-06 20:50:38 +000065# * support_XXX: if support_XXX exists and returns false then
66# component_XXX is not run by default.
Gilles Peskine8f073122018-11-27 15:58:47 +010067# * post_XXX: things to do after running the tests.
68# * other: miscellaneous support functions.
69#
Gilles Peskinec70637a2019-01-09 22:29:17 +010070# Each component must start by invoking `msg` with a short informative message.
71#
72# The framework performs some cleanup tasks after each component. This
73# means that components can assume that the working directory is in a
74# cleaned-up state, and don't need to perform the cleanup themselves.
75# * Run `make clean`.
76# * Restore `include/mbedtks/config.h` from a backup made before running
77# the component.
78# * Check out `Makefile`, `library/Makefile`, `programs/Makefile` and
79# `tests/Makefile` from git. This cleans up after an in-tree use of
80# CMake.
81#
82# Any command that is expected to fail must be protected so that the
83# script keeps running in --keep-going mode despite `set -e`. In keep-going
84# mode, if a protected command fails, this is logged as a failure and the
85# script will exit with a failure status once it has run all components.
86# Commands can be protected in any of the following ways:
87# * `make` is a function which runs the `make` command with protection.
88# Note that you must write `make VAR=value`, not `VAR=value make`,
89# because the `VAR=value make` syntax doesn't work with functions.
90# * Put `report_status` before the command to protect it.
91# * Put `if_build_successful` before a command. This protects it, and
92# additionally skips it if a prior invocation of `make` in the same
93# component failed.
94#
Gilles Peskine192c72f2017-12-21 15:59:21 +010095# The tests are roughly in order from fastest to slowest. This doesn't
96# have to be exact, but in general you should add slower tests towards
97# the end and fast checks near the beginning.
Gilles Peskine192c72f2017-12-21 15:59:21 +010098
99
100
101################################################################
102#### Initialization and command line parsing
103################################################################
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100104
SimonB2e23c822016-04-16 21:54:39 +0100105# Abort on errors (and uninitialised variables)
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100106set -eu
107
Gilles Peskine8f073122018-11-27 15:58:47 +0100108pre_check_environment () {
Gilles Peskinea16c2b12019-01-06 19:58:02 +0000109 if [ -d library -a -d include -a -d tests ]; then :; else
Gilles Peskine8f073122018-11-27 15:58:47 +0100110 echo "Must be run from mbed TLS root" >&2
111 exit 1
112 fi
113}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100114
Gilles Peskine8f073122018-11-27 15:58:47 +0100115pre_initialize_variables () {
116 CONFIG_H='include/mbedtls/config.h'
117 CONFIG_BAK="$CONFIG_H.bak"
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200118
Gilles Peskine8f073122018-11-27 15:58:47 +0100119 MEMORY=0
120 FORCE=0
121 KEEP_GOING=0
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100122
Gilles Peskine8f073122018-11-27 15:58:47 +0100123 # Default commands, can be overriden by the environment
124 : ${OPENSSL:="openssl"}
125 : ${OPENSSL_LEGACY:="$OPENSSL"}
126 : ${OPENSSL_NEXT:="$OPENSSL"}
127 : ${GNUTLS_CLI:="gnutls-cli"}
128 : ${GNUTLS_SERV:="gnutls-serv"}
129 : ${GNUTLS_LEGACY_CLI:="$GNUTLS_CLI"}
130 : ${GNUTLS_LEGACY_SERV:="$GNUTLS_SERV"}
131 : ${OUT_OF_SOURCE_DIR:=./mbedtls_out_of_source_build}
132 : ${ARMC5_BIN_DIR:=/usr/bin}
133 : ${ARMC6_BIN_DIR:=/usr/bin}
Andres AGdc192212016-08-31 17:33:13 +0100134
Gilles Peskine8f073122018-11-27 15:58:47 +0100135 # if MAKEFLAGS is not set add the -j option to speed up invocations of make
Gilles Peskinea1fc4b52019-01-06 20:15:26 +0000136 if [ -z "${MAKEFLAGS+set}" ]; then
Gilles Peskine8f073122018-11-27 15:58:47 +0100137 export MAKEFLAGS="-j"
138 fi
Gilles Peskine878cf602019-01-06 20:50:38 +0000139
140 # Gather the list of available components. These are the functions
141 # defined in this script whose name starts with "component_".
142 # Parse the script with sed, because in sh there is no way to list
143 # defined functions.
144 ALL_COMPONENTS=$(sed -n 's/^ *component_\([0-9A-Z_a-z]*\) *().*/\1/p' <"$0")
145
146 # Exclude components that are not supported on this platform.
147 SUPPORTED_COMPONENTS=
148 for component in $ALL_COMPONENTS; do
149 case $(type "support_$component" 2>&1) in
150 *' function'*)
151 if ! support_$component; then continue; fi;;
152 esac
153 SUPPORTED_COMPONENTS="$SUPPORTED_COMPONENTS $component"
154 done
Gilles Peskine8f073122018-11-27 15:58:47 +0100155}
Andres AG38495a32016-07-12 16:54:33 +0100156
Gilles Peskine878cf602019-01-06 20:50:38 +0000157# Test whether $1 is excluded via the command line.
158is_component_excluded()
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100159{
Gilles Peskine878cf602019-01-06 20:50:38 +0000160 # Is $1 excluded via $COMPONENTS (a space-separated list of wildcard
161 # patterns)?
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100162 set -f
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000163 for pattern in $COMMAND_LINE_COMPONENTS; do
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100164 set +f
165 case ${1#component_} in $pattern) return 0;; esac
166 done
167 set +f
168 return 1
169}
170
Simon Butcher41eeccf2016-09-07 00:07:09 +0100171usage()
SimonB2e23c822016-04-16 21:54:39 +0100172{
Gilles Peskine709346a2017-12-10 23:43:39 +0100173 cat <<EOF
Gilles Peskine92525112018-11-27 18:15:35 +0100174Usage: $0 [OPTION]... [COMPONENT]...
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100175Run mbedtls release validation tests.
Gilles Peskine92525112018-11-27 18:15:35 +0100176By default, run all tests. With one or more COMPONENT, run only those.
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100177
178Special options:
179 -h|--help Print this help and exit.
Gilles Peskine878cf602019-01-06 20:50:38 +0000180 --list-all-components List all available test components and exit.
181 --list-components List components supported on this platform and exit.
Gilles Peskine709346a2017-12-10 23:43:39 +0100182
183General options:
184 -f|--force Force the tests to overwrite any modified files.
Gilles Peskine7c652162017-12-11 00:01:40 +0100185 -k|--keep-going Run all tests and report errors at the end.
Gilles Peskine709346a2017-12-10 23:43:39 +0100186 -m|--memory Additional optional memory tests.
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100187 --armcc Run ARM Compiler builds (on by default).
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100188 --except If some components are passed on the command line,
189 run all the tests except for these components. In
190 this mode, you can pass shell wildcard patterns as
191 component names, e.g. "$0 --except 'test_*'" to
192 exclude all components that run tests.
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100193 --no-armcc Skip ARM Compiler builds.
Gilles Peskine38d81652018-03-21 08:40:26 +0100194 --no-force Refuse to overwrite modified files (default).
195 --no-keep-going Stop at the first error (default).
196 --no-memory No additional memory tests (default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100197 --out-of-source-dir=<path> Directory used for CMake out-of-source build tests.
Gilles Peskine38d81652018-03-21 08:40:26 +0100198 --random-seed Use a random seed value for randomized tests (default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100199 -r|--release-test Run this script in release mode. This fixes the seed value to 1.
200 -s|--seed Integer seed value to use for this test run.
201
202Tool path options:
203 --armc5-bin-dir=<ARMC5_bin_dir_path> ARM Compiler 5 bin directory.
204 --armc6-bin-dir=<ARMC6_bin_dir_path> ARM Compiler 6 bin directory.
205 --gnutls-cli=<GnuTLS_cli_path> GnuTLS client executable to use for most tests.
206 --gnutls-serv=<GnuTLS_serv_path> GnuTLS server executable to use for most tests.
207 --gnutls-legacy-cli=<GnuTLS_cli_path> GnuTLS client executable to use for legacy tests.
208 --gnutls-legacy-serv=<GnuTLS_serv_path> GnuTLS server executable to use for legacy tests.
209 --openssl=<OpenSSL_path> OpenSSL executable to use for most tests.
210 --openssl-legacy=<OpenSSL_path> OpenSSL executable to use for legacy tests e.g. SSLv3.
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100211 --openssl-next=<OpenSSL_path> OpenSSL executable to use for recent things like ARIA
Gilles Peskine709346a2017-12-10 23:43:39 +0100212EOF
SimonB2e23c822016-04-16 21:54:39 +0100213}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100214
215# remove built files as well as the cmake cache/config
216cleanup()
217{
Gilles Peskinea71d64c2018-03-21 12:16:57 +0100218 if [ -n "${MBEDTLS_ROOT_DIR+set}" ]; then
219 cd "$MBEDTLS_ROOT_DIR"
220 fi
221
Gilles Peskine7c652162017-12-11 00:01:40 +0100222 command make clean
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200223
Gilles Peskine31b07e22018-03-21 12:15:06 +0100224 # Remove CMake artefacts
Simon Butcher3ad2efd2018-05-02 14:49:38 +0100225 find . -name .git -prune \
Gilles Peskine31b07e22018-03-21 12:15:06 +0100226 -iname CMakeFiles -exec rm -rf {} \+ -o \
227 \( -iname cmake_install.cmake -o \
228 -iname CTestTestfile.cmake -o \
229 -iname CMakeCache.txt \) -exec rm {} \+
230 # Recover files overwritten by in-tree CMake builds
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000231 rm -f include/Makefile include/mbedtls/Makefile programs/*/Makefile
Paul Bakkerfe0984d2014-06-13 00:13:45 +0200232 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile
233 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200234
235 if [ -f "$CONFIG_BAK" ]; then
236 mv "$CONFIG_BAK" "$CONFIG_H"
237 fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100238}
239
Gilles Peskine7c652162017-12-11 00:01:40 +0100240# Executed on exit. May be redefined depending on command line options.
241final_report () {
242 :
243}
244
245fatal_signal () {
246 cleanup
247 final_report $1
248 trap - $1
249 kill -$1 $$
250}
251
252trap 'fatal_signal HUP' HUP
253trap 'fatal_signal INT' INT
254trap 'fatal_signal TERM' TERM
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200255
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100256msg()
257{
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100258 if [ -n "${current_component:-}" ]; then
259 current_section="${current_component#component_}: $1"
260 else
261 current_section="$1"
262 fi
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100263 echo ""
264 echo "******************************************************************"
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100265 echo "* $current_section "
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000266 printf "* "; date
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100267 echo "******************************************************************"
268}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100269
Gilles Peskine8f073122018-11-27 15:58:47 +0100270armc6_build_test()
271{
272 FLAGS="$1"
Andres AGa5cd9732016-10-17 15:23:10 +0100273
Gilles Peskine8f073122018-11-27 15:58:47 +0100274 msg "build: ARM Compiler 6 ($FLAGS), make"
275 ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \
276 WARNING_CFLAGS='-xc -std=c99' make lib
277 make clean
278}
Andres AGa5cd9732016-10-17 15:23:10 +0100279
Andres AGd9eba4b2016-08-26 14:42:14 +0100280err_msg()
281{
282 echo "$1" >&2
283}
284
285check_tools()
286{
287 for TOOL in "$@"; do
Andres AG98393602017-01-31 17:04:45 +0000288 if ! `type "$TOOL" >/dev/null 2>&1`; then
Andres AGd9eba4b2016-08-26 14:42:14 +0100289 err_msg "$TOOL not found!"
290 exit 1
291 fi
292 done
293}
294
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400295check_headers_in_cpp () {
296 ls include/mbedtls >headers.txt
297 <programs/test/cpp_dummy_build.cpp sed -n 's/"$//; s!^#include "mbedtls/!!p' |
298 sort |
299 diff headers.txt -
300 rm headers.txt
301}
302
Gilles Peskine8f073122018-11-27 15:58:47 +0100303pre_parse_command_line () {
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000304 COMMAND_LINE_COMPONENTS=
305 all_except=
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000306 no_armcc=
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000307
Gilles Peskine8f073122018-11-27 15:58:47 +0100308 while [ $# -gt 0 ]; do
Gilles Peskine55f7c942019-01-09 22:28:21 +0100309 case "$1" in
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000310 --armcc) no_armcc=;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100311 --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
312 --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000313 --except) all_except=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100314 --force|-f) FORCE=1;;
315 --gnutls-cli) shift; GNUTLS_CLI="$1";;
316 --gnutls-legacy-cli) shift; GNUTLS_LEGACY_CLI="$1";;
317 --gnutls-legacy-serv) shift; GNUTLS_LEGACY_SERV="$1";;
318 --gnutls-serv) shift; GNUTLS_SERV="$1";;
319 --help|-h) usage; exit;;
320 --keep-going|-k) KEEP_GOING=1;;
Gilles Peskine878cf602019-01-06 20:50:38 +0000321 --list-all-components) printf '%s\n' $ALL_COMPONENTS; exit;;
322 --list-components) printf '%s\n' $SUPPORTED_COMPONENTS; exit;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100323 --memory|-m) MEMORY=1;;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000324 --no-armcc) no_armcc=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100325 --no-force) FORCE=0;;
326 --no-keep-going) KEEP_GOING=0;;
327 --no-memory) MEMORY=0;;
328 --openssl) shift; OPENSSL="$1";;
329 --openssl-legacy) shift; OPENSSL_LEGACY="$1";;
330 --openssl-next) shift; OPENSSL_NEXT="$1";;
331 --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
332 --random-seed) unset SEED;;
333 --release-test|-r) SEED=1;;
334 --seed|-s) shift; SEED="$1";;
335 -*)
336 echo >&2 "Unknown option: $1"
337 echo >&2 "Run $0 --help for usage."
338 exit 120
339 ;;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000340 *) COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS $1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100341 esac
342 shift
Gilles Peskine8f073122018-11-27 15:58:47 +0100343 done
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000344
345 if [ -z "$COMMAND_LINE_COMPONENTS" ]; then
346 all_except=1
347 fi
348
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000349 # --no-armcc is a legacy option. The modern way is --except '*_armcc*'.
350 # Ignore it if components are listed explicitly on the command line.
351 if [ -n "$no_armcc" ] && [ -n "$all_except" ]; then
352 COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS *_armcc*"
353 fi
354
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000355 # Build the list of components to run.
356 if [ -n "$all_except" ]; then
357 RUN_COMPONENTS=
358 for component in $SUPPORTED_COMPONENTS; do
359 if ! is_component_excluded "$component"; then
360 RUN_COMPONENTS="$RUN_COMPONENTS $component"
361 fi
362 done
363 else
364 RUN_COMPONENTS="$COMMAND_LINE_COMPONENTS"
365 fi
366
367 unset all_except
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000368 unset no_armcc
Gilles Peskine8f073122018-11-27 15:58:47 +0100369}
SimonB2e23c822016-04-16 21:54:39 +0100370
Gilles Peskine8f073122018-11-27 15:58:47 +0100371pre_check_git () {
372 if [ $FORCE -eq 1 ]; then
Gilles Peskine53190e62019-01-09 23:17:35 +0100373 rm -rf "$OUT_OF_SOURCE_DIR"
Gilles Peskine8f073122018-11-27 15:58:47 +0100374 git checkout-index -f -q $CONFIG_H
375 cleanup
376 else
SimonB2e23c822016-04-16 21:54:39 +0100377
Gilles Peskine8f073122018-11-27 15:58:47 +0100378 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
379 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
380 echo "You can either delete this directory manually, or force the test by rerunning"
381 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
382 exit 1
383 fi
384
Gilles Peskined1174cf2019-01-09 22:30:01 +0100385 if ! git diff --quiet include/mbedtls/config.h; then
Gilles Peskine8f073122018-11-27 15:58:47 +0100386 err_msg "Warning - the configuration file 'include/mbedtls/config.h' has been edited. "
387 echo "You can either delete or preserve your work, or force the test by rerunning the"
388 echo "script as: $0 --force"
389 exit 1
390 fi
Andres AGdc192212016-08-31 17:33:13 +0100391 fi
Gilles Peskine8f073122018-11-27 15:58:47 +0100392}
Andres AGdc192212016-08-31 17:33:13 +0100393
Gilles Peskine8f073122018-11-27 15:58:47 +0100394pre_setup_keep_going () {
Gilles Peskine7c652162017-12-11 00:01:40 +0100395 failure_summary=
396 failure_count=0
397 start_red=
398 end_color=
399 if [ -t 1 ]; then
Gilles Peskine9736b9d2018-01-02 21:54:17 +0100400 case "${TERM:-}" in
Gilles Peskine7c652162017-12-11 00:01:40 +0100401 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
402 start_red=$(printf '\033[31m')
403 end_color=$(printf '\033[0m')
404 ;;
405 esac
406 fi
407 record_status () {
408 if "$@"; then
409 last_status=0
410 else
411 last_status=$?
412 text="$current_section: $* -> $last_status"
413 failure_summary="$failure_summary
414$text"
415 failure_count=$((failure_count + 1))
416 echo "${start_red}^^^^$text^^^^${end_color}"
417 fi
418 }
419 make () {
420 case "$*" in
421 *test|*check)
422 if [ $build_status -eq 0 ]; then
423 record_status command make "$@"
424 else
425 echo "(skipped because the build failed)"
426 fi
427 ;;
428 *)
429 record_status command make "$@"
430 build_status=$last_status
431 ;;
432 esac
433 }
434 final_report () {
435 if [ $failure_count -gt 0 ]; then
436 echo
437 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
438 echo "${start_red}FAILED: $failure_count${end_color}$failure_summary"
439 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Jaeden Amero7c1258d2018-07-20 16:42:14 +0100440 exit 1
Gilles Peskine7c652162017-12-11 00:01:40 +0100441 elif [ -z "${1-}" ]; then
442 echo "SUCCESS :)"
443 fi
444 if [ -n "${1-}" ]; then
445 echo "Killed by SIG$1."
446 fi
447 }
Gilles Peskine8f073122018-11-27 15:58:47 +0100448}
449
Gilles Peskine7c652162017-12-11 00:01:40 +0100450if_build_succeeded () {
451 if [ $build_status -eq 0 ]; then
452 record_status "$@"
453 fi
454}
455
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200456# to be used instead of ! for commands run with
457# record_status or if_build_succeeded
458not() {
459 ! "$@"
460}
461
Gilles Peskine8f073122018-11-27 15:58:47 +0100462pre_print_configuration () {
463 msg "info: $0 configuration"
464 echo "MEMORY: $MEMORY"
465 echo "FORCE: $FORCE"
466 echo "SEED: ${SEED-"UNSET"}"
467 echo "OPENSSL: $OPENSSL"
468 echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
469 echo "OPENSSL_NEXT: $OPENSSL_NEXT"
470 echo "GNUTLS_CLI: $GNUTLS_CLI"
471 echo "GNUTLS_SERV: $GNUTLS_SERV"
472 echo "GNUTLS_LEGACY_CLI: $GNUTLS_LEGACY_CLI"
473 echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV"
474 echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
475 echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
476}
Andres AG87bb5772016-09-27 15:05:15 +0100477
Gilles Peskine87964262019-01-06 22:40:00 +0000478# Make sure the tools we need are available.
Gilles Peskine8f073122018-11-27 15:58:47 +0100479pre_check_tools () {
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000480 # Build the list of variables to pass to output_env.sh.
481 set env
482
Gilles Peskine87964262019-01-06 22:40:00 +0000483 case " $RUN_COMPONENTS " in
484 # Require OpenSSL and GnuTLS if running any tests (as opposed to
485 # only doing builds). Not all tests run OpenSSL and GnuTLS, but this
486 # is a good enough approximation in practice.
487 *" test_"*)
488 # To avoid setting OpenSSL and GnuTLS for each call to compat.sh
489 # and ssl-opt.sh, we just export the variables they require.
490 export OPENSSL_CMD="$OPENSSL"
491 export GNUTLS_CLI="$GNUTLS_CLI"
492 export GNUTLS_SERV="$GNUTLS_SERV"
493 # Avoid passing --seed flag in every call to ssl-opt.sh
494 if [ -n "${SEED-}" ]; then
495 export SEED
496 fi
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000497 set "$@" OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY"
498 set "$@" GNUTLS_CLI="$GNUTLS_CLI" GNUTLS_SERV="$GNUTLS_SERV"
499 set "$@" GNUTLS_LEGACY_CLI="$GNUTLS_LEGACY_CLI"
500 set "$@" GNUTLS_LEGACY_SERV="$GNUTLS_LEGACY_SERV"
Gilles Peskine87964262019-01-06 22:40:00 +0000501 check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$OPENSSL_NEXT" \
502 "$GNUTLS_CLI" "$GNUTLS_SERV" \
503 "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV"
504 ;;
505 esac
Andres AGd9eba4b2016-08-26 14:42:14 +0100506
Gilles Peskine87964262019-01-06 22:40:00 +0000507 case " $RUN_COMPONENTS " in
508 *_doxygen[_\ ]*) check_tools "doxygen" "dot";;
509 esac
Andres AGb2fdd042016-09-22 14:17:46 +0100510
Gilles Peskine87964262019-01-06 22:40:00 +0000511 case " $RUN_COMPONENTS " in
512 *_arm_none_eabi_gcc[_\ ]*) check_tools "arm-none-eabi-gcc";;
513 esac
Andres AG7770ea82016-10-10 15:46:20 +0100514
Gilles Peskine87964262019-01-06 22:40:00 +0000515 case " $RUN_COMPONENTS " in
516 *_mingw[_\ ]*) check_tools "i686-w64-mingw32-gcc";;
517 esac
518
519 case " $RUN_COMPONENTS " in
520 *" test_zeroize "*) check_tools "gdb";;
521 esac
522
523 case " $RUN_COMPONENTS " in
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000524 *_armcc*)
Gilles Peskine87964262019-01-06 22:40:00 +0000525 ARMC5_CC="$ARMC5_BIN_DIR/armcc"
526 ARMC5_AR="$ARMC5_BIN_DIR/armar"
527 ARMC6_CC="$ARMC6_BIN_DIR/armclang"
528 ARMC6_AR="$ARMC6_BIN_DIR/armar"
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000529 check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC6_CC" "$ARMC6_AR";;
530 esac
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000531
532 msg "info: output_env.sh"
533 case $RUN_COMPONENTS in
534 *_armcc*)
535 set "$@" ARMC5_CC="$ARMC5_CC" ARMC6_CC="$ARMC6_CC" RUN_ARMCC=1;;
536 *) set "$@" RUN_ARMCC=0;;
537 esac
538 "$@" scripts/output_env.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100539}
Gilles Peskine192c72f2017-12-21 15:59:21 +0100540
541
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000542
Gilles Peskine192c72f2017-12-21 15:59:21 +0100543################################################################
544#### Basic checks
545################################################################
Andres AGd9eba4b2016-08-26 14:42:14 +0100546
SimonB2e23c822016-04-16 21:54:39 +0100547#
548# Test Suites to be executed
549#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200550# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100551# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard61bc57a2014-08-14 11:29:06 +0200552# and/or are more likely to fail than others (eg I use Clang most of the
553# time, so start with a GCC build).
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200554# 2. Minimize total running time, by avoiding useless rebuilds
555#
556# Indicative running times are given for reference.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100557
Gilles Peskine8f073122018-11-27 15:58:47 +0100558component_check_recursion () {
559 msg "test: recursion.pl" # < 1s
560 record_status tests/scripts/recursion.pl library/*.c
561}
Manuel Pégourié-Gonnardea29d152014-11-20 17:32:33 +0100562
Gilles Peskine8f073122018-11-27 15:58:47 +0100563component_check_generated_files () {
564 msg "test: freshness of generated source files" # < 1s
565 record_status tests/scripts/check-generated-files.sh
566}
Manuel Pégourié-Gonnardb3b8e432015-02-13 14:52:19 +0000567
Gilles Peskine8f073122018-11-27 15:58:47 +0100568component_check_doxy_blocks () {
569 msg "test: doxygen markup outside doxygen blocks" # < 1s
570 record_status tests/scripts/check-doxy-blocks.pl
571}
Manuel Pégourié-Gonnardd09a6b52015-04-09 17:19:23 +0200572
Gilles Peskine8f073122018-11-27 15:58:47 +0100573component_check_files () {
574 msg "test: check-files.py" # < 1s
Gilles Peskine8f073122018-11-27 15:58:47 +0100575 record_status tests/scripts/check-files.py
576}
Darryl Greena07039c2018-03-13 16:48:16 +0000577
Gilles Peskine8f073122018-11-27 15:58:47 +0100578component_check_names () {
579 msg "test/build: declared and exported names" # < 3s
Gilles Peskine8f073122018-11-27 15:58:47 +0100580 record_status tests/scripts/check-names.sh
581}
Manuel Pégourié-Gonnarda687baf2015-04-09 11:09:03 +0200582
Gilles Peskine8f073122018-11-27 15:58:47 +0100583component_check_doxygen_warnings () {
584 msg "test: doxygen warnings" # ~ 3s
Gilles Peskine8f073122018-11-27 15:58:47 +0100585 record_status tests/scripts/doxygen.sh
586}
Manuel Pégourié-Gonnard1d552e72016-01-04 16:49:09 +0100587
Gilles Peskine192c72f2017-12-21 15:59:21 +0100588
589
590################################################################
591#### Build and test many configurations and targets
592################################################################
593
Gilles Peskine8f073122018-11-27 15:58:47 +0100594component_test_default_cmake_gcc_asan () {
595 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100596 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
597 make
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100598
Gilles Peskine8f073122018-11-27 15:58:47 +0100599 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
600 make test
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200601
Gilles Peskine8f073122018-11-27 15:58:47 +0100602 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
603 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200604
Gilles Peskine8f073122018-11-27 15:58:47 +0100605 msg "test: compat.sh (ASan build)" # ~ 6 min
606 if_build_succeeded tests/compat.sh
607}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200608
Gilles Peskine782f4112018-11-27 16:11:09 +0100609component_test_ref_configs () {
610 msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
611 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
612 record_status tests/scripts/test-ref-configs.pl
613}
614
Gilles Peskine8f073122018-11-27 15:58:47 +0100615component_test_sslv3 () {
616 msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100617 scripts/config.pl set MBEDTLS_SSL_PROTO_SSL3
618 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
619 make
Simon Butcher3ea7f522016-03-07 23:22:10 +0000620
Gilles Peskine8f073122018-11-27 15:58:47 +0100621 msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
622 make test
Simon Butcher3ea7f522016-03-07 23:22:10 +0000623
Gilles Peskine8f073122018-11-27 15:58:47 +0100624 msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
625 if_build_succeeded tests/compat.sh -m 'tls1 tls1_1 tls1_2 dtls1 dtls1_2'
626 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
Simon Butcher3ea7f522016-03-07 23:22:10 +0000627
Gilles Peskine8f073122018-11-27 15:58:47 +0100628 msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
629 if_build_succeeded tests/ssl-opt.sh
630}
Simon Butcher3ea7f522016-03-07 23:22:10 +0000631
Gilles Peskine8f073122018-11-27 15:58:47 +0100632component_test_no_renegotiation () {
633 msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100634 scripts/config.pl unset MBEDTLS_SSL_RENEGOTIATION
635 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
636 make
Hanno Becker134c2ab2017-10-12 15:29:50 +0100637
Gilles Peskine8f073122018-11-27 15:58:47 +0100638 msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
639 make test
Hanno Becker134c2ab2017-10-12 15:29:50 +0100640
Gilles Peskine8f073122018-11-27 15:58:47 +0100641 msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
642 if_build_succeeded tests/ssl-opt.sh
643}
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +0100644
Gilles Peskine8f073122018-11-27 15:58:47 +0100645component_test_rsa_no_crt () {
646 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100647 scripts/config.pl set MBEDTLS_RSA_NO_CRT
648 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
649 make
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100650
Gilles Peskine8f073122018-11-27 15:58:47 +0100651 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
652 make test
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100653
Gilles Peskine8f073122018-11-27 15:58:47 +0100654 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
655 if_build_succeeded tests/ssl-opt.sh -f RSA
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100656
Gilles Peskine8f073122018-11-27 15:58:47 +0100657 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
658 if_build_succeeded tests/compat.sh -t RSA
659}
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100660
Gilles Peskine8f073122018-11-27 15:58:47 +0100661component_test_small_ssl_out_content_len () {
662 msg "build: small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100663 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 16384
664 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
665 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
666 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000667
Gilles Peskine8f073122018-11-27 15:58:47 +0100668 msg "test: small SSL_OUT_CONTENT_LEN - ssl-opt.sh MFL and large packet tests"
669 if_build_succeeded tests/ssl-opt.sh -f "Max fragment\|Large packet"
670}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000671
Gilles Peskine8f073122018-11-27 15:58:47 +0100672component_test_small_ssl_in_content_len () {
673 msg "build: small SSL_IN_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100674 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 4096
675 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 16384
676 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
677 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000678
Gilles Peskine8f073122018-11-27 15:58:47 +0100679 msg "test: small SSL_IN_CONTENT_LEN - ssl-opt.sh MFL tests"
680 if_build_succeeded tests/ssl-opt.sh -f "Max fragment"
681}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000682
Gilles Peskine8f073122018-11-27 15:58:47 +0100683component_test_small_ssl_dtls_max_buffering () {
684 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0"
Gilles Peskine8f073122018-11-27 15:58:47 +0100685 scripts/config.pl set MBEDTLS_SSL_DTLS_MAX_BUFFERING 1000
686 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
687 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100688
Gilles Peskine8f073122018-11-27 15:58:47 +0100689 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0 - ssl-opt.sh specific reordering test"
690 if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer out-of-order hs msg before reassembling next, free buffered msg"
691}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100692
Gilles Peskine8f073122018-11-27 15:58:47 +0100693component_test_small_mbedtls_ssl_dtls_max_buffering () {
694 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1"
Gilles Peskine8f073122018-11-27 15:58:47 +0100695 scripts/config.pl set MBEDTLS_SSL_DTLS_MAX_BUFFERING 240
696 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
697 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100698
Gilles Peskine8f073122018-11-27 15:58:47 +0100699 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1 - ssl-opt.sh specific reordering test"
700 if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer encrypted Finished message, drop for fragmented NewSessionTicket"
701}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100702
Gilles Peskine8f073122018-11-27 15:58:47 +0100703component_test_full_cmake_clang () {
704 msg "build: cmake, full config, clang" # ~ 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100705 scripts/config.pl full
706 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
707 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check -D ENABLE_TESTING=On .
708 make
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100709
Gilles Peskine8f073122018-11-27 15:58:47 +0100710 msg "test: main suites (full config)" # ~ 5s
711 make test
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200712
Gilles Peskine8f073122018-11-27 15:58:47 +0100713 msg "test: ssl-opt.sh default, ECJPAKE, SSL async (full config)" # ~ 1s
714 if_build_succeeded tests/ssl-opt.sh -f 'Default\|ECJPAKE\|SSL async private'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200715
Gilles Peskine8f073122018-11-27 15:58:47 +0100716 msg "test: compat.sh RC4, DES & NULL (full config)" # ~ 2 min
717 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" GNUTLS_CLI="$GNUTLS_LEGACY_CLI" GNUTLS_SERV="$GNUTLS_LEGACY_SERV" tests/compat.sh -e '3DES\|DES-CBC3' -f 'NULL\|DES\|RC4\|ARCFOUR'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200718
Gilles Peskine8f073122018-11-27 15:58:47 +0100719 msg "test: compat.sh ARIA + ChachaPoly"
720 if_build_succeeded env OPENSSL_CMD="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
721}
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100722
Gilles Peskine8f073122018-11-27 15:58:47 +0100723component_build_deprecated () {
724 msg "build: make, full config + DEPRECATED_WARNING, gcc -O" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100725 scripts/config.pl full
726 scripts/config.pl set MBEDTLS_DEPRECATED_WARNING
727 # Build with -O -Wextra to catch a maximum of issues.
728 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra' lib programs
729 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
Gilles Peskineb4ef45b2018-03-01 22:23:50 +0100730
Gilles Peskine8f073122018-11-27 15:58:47 +0100731 msg "build: make, full config + DEPRECATED_REMOVED, clang -O" # ~ 30s
732 # No cleanup, just tweak the configuration and rebuild
733 make clean
734 scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
735 scripts/config.pl set MBEDTLS_DEPRECATED_REMOVED
736 # Build with -O -Wextra to catch a maximum of issues.
737 make CC=clang CFLAGS='-O -Werror -Wall -Wextra' lib programs
738 make CC=clang CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
739}
Gilles Peskine0afe6242018-02-21 19:28:12 +0100740
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200741
Gilles Peskine8f073122018-11-27 15:58:47 +0100742component_test_depends_curves () {
743 msg "test/build: curves.pl (gcc)" # ~ 4 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100744 record_status tests/scripts/curves.pl
745}
Manuel Pégourié-Gonnard1fe6bb92017-06-06 11:36:16 +0200746
Gilles Peskine8f073122018-11-27 15:58:47 +0100747component_test_depends_hashes () {
748 msg "test/build: depends-hashes.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100749 record_status tests/scripts/depends-hashes.pl
750}
Manuel Pégourié-Gonnard43be6cd2017-06-20 09:53:42 +0200751
Gilles Peskine8f073122018-11-27 15:58:47 +0100752component_test_depends_pkalgs () {
753 msg "test/build: depends-pkalgs.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100754 record_status tests/scripts/depends-pkalgs.pl
755}
Manuel Pégourié-Gonnard503a5ef2015-10-23 09:04:45 +0200756
Gilles Peskine8f073122018-11-27 15:58:47 +0100757component_build_key_exchanges () {
758 msg "test/build: key-exchanges (gcc)" # ~ 1 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100759 record_status tests/scripts/key-exchanges.pl
760}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100761
Gilles Peskine8f073122018-11-27 15:58:47 +0100762component_build_default_make_gcc_and_cxx () {
763 msg "build: Unix make, -Os (gcc)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100764 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400765
Gilles Peskine8f073122018-11-27 15:58:47 +0100766 msg "test: verify header list in cpp_dummy_build.cpp"
767 record_status check_headers_in_cpp
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400768
Gilles Peskine8f073122018-11-27 15:58:47 +0100769 msg "build: Unix make, incremental g++"
770 make TEST_CPP=1
771}
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +0000772
Gilles Peskineb28636b2019-01-02 19:06:24 +0100773component_test_check_params_without_platform () {
774 msg "build+test: MBEDTLS_CHECK_PARAMS without MBEDTLS_PLATFORM_C"
775 scripts/config.pl full # includes CHECK_PARAMS
776 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
777 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
778 scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
779 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
780 scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
781 scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
782 scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
783 scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
784 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
785 scripts/config.pl unset MBEDTLS_PLATFORM_C
786 make CC=gcc CFLAGS='-Werror -O1' all test
787}
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +0200788
Gilles Peskineb28636b2019-01-02 19:06:24 +0100789component_test_check_params_silent () {
790 msg "build+test: MBEDTLS_CHECK_PARAMS with alternative MBEDTLS_PARAM_FAILED()"
791 scripts/config.pl full # includes CHECK_PARAMS
792 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
793 sed -i 's/.*\(#define MBEDTLS_PARAM_FAILED( cond )\).*/\1/' "$CONFIG_H"
794 make CC=gcc CFLAGS='-Werror -O1' all test
795}
Hanno Becker5175ac62017-09-18 15:36:25 +0100796
Gilles Peskine8f073122018-11-27 15:58:47 +0100797component_test_no_platform () {
798 # Full configuration build, without platform support, file IO and net sockets.
799 # This should catch missing mbedtls_printf definitions, and by disabling file
800 # IO, it should catch missing '#include <stdio.h>'
801 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100802 scripts/config.pl full
803 scripts/config.pl unset MBEDTLS_PLATFORM_C
804 scripts/config.pl unset MBEDTLS_NET_C
805 scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
806 scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
807 scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
808 scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
809 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
810 scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
811 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
812 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
813 scripts/config.pl unset MBEDTLS_FS_IO
814 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
815 # to re-enable platform integration features otherwise disabled in C99 builds
816 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -O0 -D_DEFAULT_SOURCE' lib programs
817 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0' test
818}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200819
Gilles Peskine8f073122018-11-27 15:58:47 +0100820component_build_no_std_function () {
821 # catch compile bugs in _uninit functions
822 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100823 scripts/config.pl full
824 scripts/config.pl set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
825 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
826 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
827}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200828
Gilles Peskine8f073122018-11-27 15:58:47 +0100829component_build_no_ssl_srv () {
830 msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100831 scripts/config.pl full
832 scripts/config.pl unset MBEDTLS_SSL_SRV_C
833 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
834}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200835
Gilles Peskine8f073122018-11-27 15:58:47 +0100836component_build_no_ssl_cli () {
837 msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100838 scripts/config.pl full
839 scripts/config.pl unset MBEDTLS_SSL_CLI_C
840 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
841}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000842
Gilles Peskine8f073122018-11-27 15:58:47 +0100843component_build_no_sockets () {
844 # Note, C99 compliance can also be tested with the sockets support disabled,
845 # as that requires a POSIX platform (which isn't the same as C99).
846 msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100847 scripts/config.pl full
848 scripts/config.pl unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
849 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
850 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0 -std=c99 -pedantic' lib
851}
Hanno Becker5175ac62017-09-18 15:36:25 +0100852
Gilles Peskine8f073122018-11-27 15:58:47 +0100853component_test_no_max_fragment_length () {
854 # Run max fragment length tests with MFL disabled
855 msg "build: default config except MFL extension (ASan build)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100856 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
857 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
858 make
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000859
Gilles Peskine8f073122018-11-27 15:58:47 +0100860 msg "test: ssl-opt.sh, MFL-related tests"
861 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length"
862}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000863
Gilles Peskine8f073122018-11-27 15:58:47 +0100864component_test_no_max_fragment_length_small_ssl_out_content_len () {
865 msg "build: no MFL extension, small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100866 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
867 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 16384
868 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
869 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
870 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000871
Gilles Peskine8f073122018-11-27 15:58:47 +0100872 msg "test: MFL tests (disabled MFL extension case) & large packet tests"
873 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length\|Large buffer"
874}
Janos Follath06c54002016-06-09 13:57:40 +0100875
Gilles Peskine8f073122018-11-27 15:58:47 +0100876component_test_null_entropy () {
877 msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100878 scripts/config.pl set MBEDTLS_TEST_NULL_ENTROPY
879 scripts/config.pl set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
880 scripts/config.pl set MBEDTLS_ENTROPY_C
881 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
882 scripts/config.pl unset MBEDTLS_ENTROPY_HARDWARE_ALT
883 scripts/config.pl unset MBEDTLS_HAVEGE_C
Gilles Peskine5fa32a72019-01-06 19:48:30 +0000884 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan -D UNSAFE_BUILD=ON .
Gilles Peskine8f073122018-11-27 15:58:47 +0100885 make
Janos Follath06c54002016-06-09 13:57:40 +0100886
Gilles Peskine8f073122018-11-27 15:58:47 +0100887 msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)"
888 make test
889}
Hanno Beckere5fecec2018-10-11 11:02:52 +0100890
Gilles Peskine8f073122018-11-27 15:58:47 +0100891component_test_platform_calloc_macro () {
892 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100893 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
894 scripts/config.pl set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
895 scripts/config.pl set MBEDTLS_PLATFORM_FREE_MACRO free
896 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
897 make
Hanno Beckere5fecec2018-10-11 11:02:52 +0100898
Gilles Peskine8f073122018-11-27 15:58:47 +0100899 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
900 make test
901}
Hanno Becker83ebf782017-07-07 12:29:15 +0100902
Gilles Peskine8f073122018-11-27 15:58:47 +0100903component_test_aes_fewer_tables () {
904 msg "build: default config with AES_FEWER_TABLES enabled"
Gilles Peskine8f073122018-11-27 15:58:47 +0100905 scripts/config.pl set MBEDTLS_AES_FEWER_TABLES
906 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +0100907
Gilles Peskine8f073122018-11-27 15:58:47 +0100908 msg "test: AES_FEWER_TABLES"
909 make test
910}
Hanno Becker83ebf782017-07-07 12:29:15 +0100911
Gilles Peskine8f073122018-11-27 15:58:47 +0100912component_test_aes_rom_tables () {
913 msg "build: default config with AES_ROM_TABLES enabled"
Gilles Peskine8f073122018-11-27 15:58:47 +0100914 scripts/config.pl set MBEDTLS_AES_ROM_TABLES
915 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +0100916
Gilles Peskine8f073122018-11-27 15:58:47 +0100917 msg "test: AES_ROM_TABLES"
918 make test
919}
Hanno Becker83ebf782017-07-07 12:29:15 +0100920
Gilles Peskine8f073122018-11-27 15:58:47 +0100921component_test_aes_fewer_tables_and_rom_tables () {
922 msg "build: default config with AES_ROM_TABLES and AES_FEWER_TABLES enabled"
Gilles Peskine8f073122018-11-27 15:58:47 +0100923 scripts/config.pl set MBEDTLS_AES_FEWER_TABLES
924 scripts/config.pl set MBEDTLS_AES_ROM_TABLES
925 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +0100926
Gilles Peskine8f073122018-11-27 15:58:47 +0100927 msg "test: AES_FEWER_TABLES + AES_ROM_TABLES"
928 make test
929}
930
931component_test_make_shared () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100932 msg "build/test: make shared" # ~ 40s
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100933 make SHARED=1 all check
Gilles Peskine8f073122018-11-27 15:58:47 +0100934}
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +0200935
Gilles Peskine8f073122018-11-27 15:58:47 +0100936component_test_m32_o0 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100937 # Build once with -O0, to compile out the i386 specific inline assembly
938 msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
Simon Butcher7a6da6e2018-06-27 21:52:54 +0100939 scripts/config.pl full
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100940 make CC=gcc CFLAGS='-O0 -Werror -Wall -Wextra -m32 -fsanitize=address'
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +0100941
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100942 msg "test: i386, make, gcc -O0 (ASan build)"
943 make test
Gilles Peskine8f073122018-11-27 15:58:47 +0100944}
Gilles Peskine878cf602019-01-06 20:50:38 +0000945support_test_m32_o0 () {
946 case $(uname -m) in
947 *64*) true;;
948 *) false;;
949 esac
950}
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100951
Gilles Peskine8f073122018-11-27 15:58:47 +0100952component_test_m32_o1 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100953 # Build again with -O1, to compile in the i386 specific inline assembly
954 msg "build: i386, make, gcc -O1 (ASan build)" # ~ 30s
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100955 scripts/config.pl full
956 make CC=gcc CFLAGS='-O1 -Werror -Wall -Wextra -m32 -fsanitize=address'
957
958 msg "test: i386, make, gcc -O1 (ASan build)"
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +0100959 make test
Gilles Peskine8f073122018-11-27 15:58:47 +0100960}
Gilles Peskine878cf602019-01-06 20:50:38 +0000961support_test_m32_o1 () {
962 support_test_m32_o0 "$@"
963}
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +0100964
Gilles Peskine8f073122018-11-27 15:58:47 +0100965component_test_mx32 () {
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +0100966 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
Simon Butcher7a6da6e2018-06-27 21:52:54 +0100967 scripts/config.pl full
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +0100968 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32'
969
970 msg "test: 64-bit ILP32, make, gcc"
971 make test
Gilles Peskine8f073122018-11-27 15:58:47 +0100972}
Gilles Peskine878cf602019-01-06 20:50:38 +0000973support_test_mx32 () {
974 case $(uname -m) in
975 amd64|x86_64) true;;
976 *) false;;
977 esac
978}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000979
Gilles Peskine8f073122018-11-27 15:58:47 +0100980component_test_have_int32 () {
981 msg "build: gcc, force 32-bit bignum limbs"
Gilles Peskine8f073122018-11-27 15:58:47 +0100982 scripts/config.pl unset MBEDTLS_HAVE_ASM
983 scripts/config.pl unset MBEDTLS_AESNI_C
984 scripts/config.pl unset MBEDTLS_PADLOCK_C
985 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +0100986
Gilles Peskine8f073122018-11-27 15:58:47 +0100987 msg "test: gcc, force 32-bit bignum limbs"
988 make test
989}
Andres Amaya Garciafe843a32017-07-20 13:21:34 +0100990
Gilles Peskine8f073122018-11-27 15:58:47 +0100991component_test_have_int64 () {
992 msg "build: gcc, force 64-bit bignum limbs"
Gilles Peskine8f073122018-11-27 15:58:47 +0100993 scripts/config.pl unset MBEDTLS_HAVE_ASM
994 scripts/config.pl unset MBEDTLS_AESNI_C
995 scripts/config.pl unset MBEDTLS_PADLOCK_C
996 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
Gilles Peskine14c3c062018-01-29 21:25:12 +0100997
Gilles Peskine8f073122018-11-27 15:58:47 +0100998 msg "test: gcc, force 64-bit bignum limbs"
999 make test
1000}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001001
Gilles Peskine8f073122018-11-27 15:58:47 +01001002component_test_no_udbl_division () {
1003 msg "build: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +01001004 scripts/config.pl full
1005 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
1006 scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
1007 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001008
Gilles Peskine8f073122018-11-27 15:58:47 +01001009 msg "test: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
1010 make test
1011}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001012
Gilles Peskine8f073122018-11-27 15:58:47 +01001013component_test_no_64bit_multiplication () {
1014 msg "build: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +01001015 scripts/config.pl full
1016 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
1017 scripts/config.pl set MBEDTLS_NO_64BIT_MULTIPLICATION
1018 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001019
Gilles Peskine8f073122018-11-27 15:58:47 +01001020 msg "test: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
1021 make test
1022}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001023
Gilles Peskine8f073122018-11-27 15:58:47 +01001024component_build_arm_none_eabi_gcc () {
1025 msg "build: arm-none-eabi-gcc, make" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +01001026 scripts/config.pl full
1027 scripts/config.pl unset MBEDTLS_NET_C
1028 scripts/config.pl unset MBEDTLS_TIMING_C
1029 scripts/config.pl unset MBEDTLS_FS_IO
1030 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
1031 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
1032 # following things are not in the default config
1033 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
1034 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
1035 scripts/config.pl unset MBEDTLS_THREADING_C
1036 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
1037 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
1038 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
1039}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001040
Gilles Peskine8f073122018-11-27 15:58:47 +01001041component_build_arm_none_eabi_gcc_no_udbl_division () {
1042 msg "build: arm-none-eabi-gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +01001043 scripts/config.pl full
1044 scripts/config.pl unset MBEDTLS_NET_C
1045 scripts/config.pl unset MBEDTLS_TIMING_C
1046 scripts/config.pl unset MBEDTLS_FS_IO
1047 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
1048 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
1049 # following things are not in the default config
1050 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
1051 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
1052 scripts/config.pl unset MBEDTLS_THREADING_C
1053 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
1054 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
1055 scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
1056 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
1057 echo "Checking that software 64-bit division is not required"
1058 if_build_succeeded not grep __aeabi_uldiv library/*.o
1059}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001060
Gilles Peskine8f073122018-11-27 15:58:47 +01001061component_build_arm_none_eabi_gcc_no_64bit_multiplication () {
1062 msg "build: arm-none-eabi-gcc MBEDTLS_NO_64BIT_MULTIPLICATION, make" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +01001063 scripts/config.pl full
1064 scripts/config.pl unset MBEDTLS_NET_C
1065 scripts/config.pl unset MBEDTLS_TIMING_C
1066 scripts/config.pl unset MBEDTLS_FS_IO
1067 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
1068 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
1069 # following things are not in the default config
1070 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
1071 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
1072 scripts/config.pl unset MBEDTLS_THREADING_C
1073 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
1074 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
1075 scripts/config.pl set MBEDTLS_NO_64BIT_MULTIPLICATION
1076 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -O1 -march=armv6-m -mthumb' lib
1077 echo "Checking that software 64-bit multiplication is not required"
1078 if_build_succeeded not grep __aeabi_lmul library/*.o
1079}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001080
Gilles Peskine8f073122018-11-27 15:58:47 +01001081component_build_armcc () {
1082 msg "build: ARM Compiler 5, make"
Gilles Peskine8f073122018-11-27 15:58:47 +01001083 scripts/config.pl full
1084 scripts/config.pl unset MBEDTLS_NET_C
1085 scripts/config.pl unset MBEDTLS_TIMING_C
1086 scripts/config.pl unset MBEDTLS_FS_IO
1087 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
1088 scripts/config.pl unset MBEDTLS_HAVE_TIME
1089 scripts/config.pl unset MBEDTLS_HAVE_TIME_DATE
1090 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
1091 # following things are not in the default config
1092 scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
1093 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
1094 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
1095 scripts/config.pl unset MBEDTLS_THREADING_C
1096 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
1097 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
1098 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT # depends on MBEDTLS_HAVE_TIME
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001099
Gilles Peskine5331c6e2019-01-06 22:23:42 +00001100 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
1101 make clean
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001102
Gilles Peskine5331c6e2019-01-06 22:23:42 +00001103 # ARM Compiler 6 - Target ARMv7-A
1104 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-a"
Gilles Peskineed942f82017-06-08 15:19:20 +02001105
Gilles Peskine5331c6e2019-01-06 22:23:42 +00001106 # ARM Compiler 6 - Target ARMv7-M
1107 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m"
Andres AG87bb5772016-09-27 15:05:15 +01001108
Gilles Peskine5331c6e2019-01-06 22:23:42 +00001109 # ARM Compiler 6 - Target ARMv8-A - AArch32
1110 armc6_build_test "--target=arm-arm-none-eabi -march=armv8.2-a"
Andres AG87bb5772016-09-27 15:05:15 +01001111
Gilles Peskine5331c6e2019-01-06 22:23:42 +00001112 # ARM Compiler 6 - Target ARMv8-M
1113 armc6_build_test "--target=arm-arm-none-eabi -march=armv8-m.main"
Simon Butcher940737f2017-07-23 13:42:36 +02001114
Gilles Peskine5331c6e2019-01-06 22:23:42 +00001115 # ARM Compiler 6 - Target ARMv8-A - AArch64
1116 armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a"
Gilles Peskine8f073122018-11-27 15:58:47 +01001117}
Simon Butcher940737f2017-07-23 13:42:36 +02001118
Gilles Peskine8f073122018-11-27 15:58:47 +01001119component_test_allow_sha1 () {
1120 msg "build: allow SHA1 in certificates by default"
Gilles Peskine8f073122018-11-27 15:58:47 +01001121 scripts/config.pl set MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
1122 make CFLAGS='-Werror -Wall -Wextra'
1123 msg "test: allow SHA1 in certificates by default"
1124 make test
1125 if_build_succeeded tests/ssl-opt.sh -f SHA-1
1126}
Simon Butcher940737f2017-07-23 13:42:36 +02001127
Gilles Peskine8f073122018-11-27 15:58:47 +01001128component_build_mingw () {
1129 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +01001130 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -Wall -Wextra' WINDOWS_BUILD=1 lib programs
Gilles Peskine2a458da2017-05-12 15:26:58 +02001131
Gilles Peskine8f073122018-11-27 15:58:47 +01001132 # note Make tests only builds the tests, but doesn't run them
1133 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror' WINDOWS_BUILD=1 tests
1134 make WINDOWS_BUILD=1 clean
Hanno Beckere963efa2018-01-03 10:03:43 +00001135
Gilles Peskine8f073122018-11-27 15:58:47 +01001136 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
1137 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
1138 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
1139 make WINDOWS_BUILD=1 clean
1140}
Simon Butcher002bc622016-11-17 09:27:45 +00001141
Gilles Peskine8f073122018-11-27 15:58:47 +01001142component_test_memsan () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001143 msg "build: MSan (clang)" # ~ 1 min 20s
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001144 scripts/config.pl unset MBEDTLS_AESNI_C # memsan doesn't grok asm
1145 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
1146 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +02001147
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001148 msg "test: main suites (MSan)" # ~ 10s
1149 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001150
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001151 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
Gilles Peskine7c652162017-12-11 00:01:40 +01001152 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001153
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001154 # Optional part(s)
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001155
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001156 if [ "$MEMORY" -gt 0 ]; then
1157 msg "test: compat.sh (MSan)" # ~ 6 min 20s
Gilles Peskine7c652162017-12-11 00:01:40 +01001158 if_build_succeeded tests/compat.sh
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001159 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001160}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001161
Gilles Peskine8f073122018-11-27 15:58:47 +01001162component_test_memcheck () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001163 msg "build: Release (clang)"
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001164 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
1165 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001166
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001167 msg "test: main suites valgrind (Release)"
1168 make memcheck
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001169
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001170 # Optional part(s)
1171 # Currently broken, programs don't seem to receive signals
1172 # under valgrind on OS X
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001173
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001174 if [ "$MEMORY" -gt 0 ]; then
1175 msg "test: ssl-opt.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +01001176 if_build_succeeded tests/ssl-opt.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001177 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001178
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001179 if [ "$MEMORY" -gt 1 ]; then
1180 msg "test: compat.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +01001181 if_build_succeeded tests/compat.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001182 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001183}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001184
Gilles Peskine8f073122018-11-27 15:58:47 +01001185component_test_cmake_out_of_source () {
1186 msg "build: cmake 'out-of-source' build"
Gilles Peskine8f073122018-11-27 15:58:47 +01001187 MBEDTLS_ROOT_DIR="$PWD"
1188 mkdir "$OUT_OF_SOURCE_DIR"
1189 cd "$OUT_OF_SOURCE_DIR"
1190 cmake "$MBEDTLS_ROOT_DIR"
1191 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001192
Gilles Peskine8f073122018-11-27 15:58:47 +01001193 msg "test: cmake 'out-of-source' build"
1194 make test
1195 # Test an SSL option that requires an auxiliary script in test/scripts/.
1196 # Also ensure that there are no error messages such as
1197 # "No such file or directory", which would indicate that some required
1198 # file is missing (ssl-opt.sh tolerates the absence of some files so
1199 # may exit with status 0 but emit errors).
1200 if_build_succeeded ./tests/ssl-opt.sh -f 'Fallback SCSV: beginning of list' 2>ssl-opt.err
1201 if [ -s ssl-opt.err ]; then
1202 cat ssl-opt.err >&2
1203 record_status [ ! -s ssl-opt.err ]
1204 rm ssl-opt.err
1205 fi
1206 cd "$MBEDTLS_ROOT_DIR"
1207 rm -rf "$OUT_OF_SOURCE_DIR"
1208 unset MBEDTLS_ROOT_DIR
1209}
Andres AGdc192212016-08-31 17:33:13 +01001210
Gilles Peskine8f073122018-11-27 15:58:47 +01001211component_test_zeroize () {
1212 # Test that the function mbedtls_platform_zeroize() is not optimized away by
1213 # different combinations of compilers and optimization flags by using an
1214 # auxiliary GDB script. Unfortunately, GDB does not return error values to the
1215 # system in all cases that the script fails, so we must manually search the
1216 # output to check whether the pass string is present and no failure strings
1217 # were printed.
Gilles Peskine4976e822019-01-06 19:52:22 +00001218
1219 # Don't try to disable ASLR. We don't care about ASLR here. We do care
1220 # about a spurious message if Gdb tries and fails, so suppress that.
1221 gdb_disable_aslr=
1222 if [ -z "$(gdb -batch -nw -ex 'set disable-randomization off' 2>&1)" ]; then
1223 gdb_disable_aslr='set disable-randomization off'
1224 fi
1225
Gilles Peskine8f073122018-11-27 15:58:47 +01001226 for optimization_flag in -O2 -O3 -Ofast -Os; do
Gilles Peskine55f7c942019-01-09 22:28:21 +01001227 for compiler in clang gcc; do
1228 msg "test: $compiler $optimization_flag, mbedtls_platform_zeroize()"
1229 make programs CC="$compiler" DEBUG=1 CFLAGS="$optimization_flag"
Gilles Peskine4976e822019-01-06 19:52:22 +00001230 if_build_succeeded gdb -ex "$gdb_disable_aslr" -x tests/scripts/test_zeroize.gdb -nw -batch -nx 2>&1 | tee test_zeroize.log
Gilles Peskine55f7c942019-01-09 22:28:21 +01001231 if_build_succeeded grep "The buffer was correctly zeroized" test_zeroize.log
1232 if_build_succeeded not grep -i "error" test_zeroize.log
1233 rm -f test_zeroize.log
1234 make clean
1235 done
Andres Amaya Garcia29673812017-10-25 10:35:51 +01001236 done
Gilles Peskine4976e822019-01-06 19:52:22 +00001237
1238 unset gdb_disable_aslr
Gilles Peskine8f073122018-11-27 15:58:47 +01001239}
Andres Amaya Garciad0d7bf62017-10-25 09:01:31 +01001240
Gilles Peskine8f073122018-11-27 15:58:47 +01001241component_check_python_files () {
1242 msg "Lint: Python scripts"
1243 record_status tests/scripts/check-python-files.sh
1244}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001245
Gilles Peskine8f073122018-11-27 15:58:47 +01001246component_check_generate_test_code () {
1247 msg "uint test: generate_test_code.py"
1248 record_status ./tests/scripts/test_generate_test_code.py
1249}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001250
1251################################################################
1252#### Termination
1253################################################################
1254
Gilles Peskine8f073122018-11-27 15:58:47 +01001255post_report () {
1256 msg "Done, cleaning up"
1257 cleanup
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001258
Gilles Peskine8f073122018-11-27 15:58:47 +01001259 final_report
1260}
1261
1262
1263
1264################################################################
1265#### Run all the things
1266################################################################
1267
Gilles Peskinee48351a2018-11-27 16:06:30 +01001268# Run one component and clean up afterwards.
Gilles Peskine8f073122018-11-27 15:58:47 +01001269run_component () {
Gilles Peskine608953e2019-01-02 18:57:02 +01001270 # Back up the configuration in case the component modifies it.
1271 # The cleanup function will restore it.
1272 cp -p "$CONFIG_H" "$CONFIG_BAK"
Gilles Peskineffcdeff2018-12-04 12:49:28 +01001273 current_component="$1"
Gilles Peskine8f073122018-11-27 15:58:47 +01001274 "$@"
Gilles Peskinee48351a2018-11-27 16:06:30 +01001275 cleanup
Gilles Peskine8f073122018-11-27 15:58:47 +01001276}
1277
1278# Preliminary setup
1279pre_check_environment
1280pre_initialize_variables
1281pre_parse_command_line "$@"
Gilles Peskine348fb9a2018-11-27 17:04:29 +01001282
Gilles Peskine878cf602019-01-06 20:50:38 +00001283pre_check_git
1284build_status=0
1285if [ $KEEP_GOING -eq 1 ]; then
1286 pre_setup_keep_going
1287else
1288 record_status () {
1289 "$@"
1290 }
1291fi
1292pre_print_configuration
1293pre_check_tools
Gilles Peskine878cf602019-01-06 20:50:38 +00001294cleanup
Gilles Peskine8f073122018-11-27 15:58:47 +01001295
Gilles Peskinebeb3a812019-01-06 22:11:25 +00001296# Run the requested tests.
1297for component in $RUN_COMPONENTS; do
1298 run_component "component_$component"
1299done
Gilles Peskine8f073122018-11-27 15:58:47 +01001300
1301# We're done.
Gilles Peskine878cf602019-01-06 20:50:38 +00001302post_report