blob: a061d10337dc1bad3277e1f7bf07d3116e1069e9 [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.
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
Gilles Peskine10726102019-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 Peskine192c72f2017-12-21 15:59:21 +010070# The tests are roughly in order from fastest to slowest. This doesn't
71# have to be exact, but in general you should add slower tests towards
72# the end and fast checks near the beginning.
73#
74# Sanity checks have the following form:
75# 1. msg "short description of what is about to be done"
76# 2. run sanity check (failure stops the script)
77#
78# Build or build-and-test steps have the following form:
79# 1. msg "short description of what is about to be done"
80# 2. cleanup
81# 3. preparation (config.pl, cmake, ...) (failure stops the script)
82# 4. make
83# 5. Run tests if relevant. All tests must be prefixed with
84# if_build_successful for the sake of --keep-going.
85
86
87
88################################################################
89#### Initialization and command line parsing
90################################################################
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010091
SimonB2e23c822016-04-16 21:54:39 +010092# Abort on errors (and uninitialised variables)
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010093set -eu
94
Gilles Peskine8f073122018-11-27 15:58:47 +010095pre_check_environment () {
Gilles Peskinebdf3f522019-01-06 19:58:02 +000096 if [ -d library -a -d include -a -d tests ]; then :; else
Gilles Peskine8f073122018-11-27 15:58:47 +010097 echo "Must be run from mbed TLS root" >&2
98 exit 1
99 fi
100}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100101
Gilles Peskine8f073122018-11-27 15:58:47 +0100102pre_initialize_variables () {
103 CONFIG_H='include/mbedtls/config.h'
104 CONFIG_BAK="$CONFIG_H.bak"
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200105
Gilles Peskine8f073122018-11-27 15:58:47 +0100106 MEMORY=0
107 FORCE=0
108 KEEP_GOING=0
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100109
Gilles Peskine8f073122018-11-27 15:58:47 +0100110 # Default commands, can be overriden by the environment
111 : ${OPENSSL:="openssl"}
112 : ${OPENSSL_LEGACY:="$OPENSSL"}
113 : ${OPENSSL_NEXT:="$OPENSSL"}
114 : ${GNUTLS_CLI:="gnutls-cli"}
115 : ${GNUTLS_SERV:="gnutls-serv"}
116 : ${GNUTLS_LEGACY_CLI:="$GNUTLS_CLI"}
117 : ${GNUTLS_LEGACY_SERV:="$GNUTLS_SERV"}
118 : ${OUT_OF_SOURCE_DIR:=./mbedtls_out_of_source_build}
119 : ${ARMC5_BIN_DIR:=/usr/bin}
120 : ${ARMC6_BIN_DIR:=/usr/bin}
Andres AGdc192212016-08-31 17:33:13 +0100121
Gilles Peskine8f073122018-11-27 15:58:47 +0100122 # if MAKEFLAGS is not set add the -j option to speed up invocations of make
Gilles Peskine55ae1622019-01-06 20:15:26 +0000123 if [ -z "${MAKEFLAGS+set}" ]; then
Gilles Peskine8f073122018-11-27 15:58:47 +0100124 export MAKEFLAGS="-j"
125 fi
Gilles Peskine10726102019-01-06 20:50:38 +0000126
127 # Gather the list of available components. These are the functions
128 # defined in this script whose name starts with "component_".
129 # Parse the script with sed, because in sh there is no way to list
130 # defined functions.
131 ALL_COMPONENTS=$(sed -n 's/^ *component_\([0-9A-Z_a-z]*\) *().*/\1/p' <"$0")
132
133 # Exclude components that are not supported on this platform.
134 SUPPORTED_COMPONENTS=
135 for component in $ALL_COMPONENTS; do
136 case $(type "support_$component" 2>&1) in
137 *' function'*)
138 if ! support_$component; then continue; fi;;
139 esac
140 SUPPORTED_COMPONENTS="$SUPPORTED_COMPONENTS $component"
141 done
Gilles Peskine8f073122018-11-27 15:58:47 +0100142}
Andres AG38495a32016-07-12 16:54:33 +0100143
Gilles Peskine10726102019-01-06 20:50:38 +0000144# Test whether $1 is excluded via the command line.
145is_component_excluded()
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100146{
Gilles Peskine10726102019-01-06 20:50:38 +0000147 # Is $1 excluded via $COMPONENTS (a space-separated list of wildcard
148 # patterns)?
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100149 set -f
Gilles Peskine1bcb1c82019-01-06 22:11:25 +0000150 for pattern in $COMMAND_LINE_COMPONENTS; do
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100151 set +f
152 case ${1#component_} in $pattern) return 0;; esac
153 done
154 set +f
155 return 1
156}
157
Simon Butcher41eeccf2016-09-07 00:07:09 +0100158usage()
SimonB2e23c822016-04-16 21:54:39 +0100159{
Gilles Peskine709346a2017-12-10 23:43:39 +0100160 cat <<EOF
Gilles Peskine92525112018-11-27 18:15:35 +0100161Usage: $0 [OPTION]... [COMPONENT]...
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100162Run mbedtls release validation tests.
Gilles Peskine92525112018-11-27 18:15:35 +0100163By default, run all tests. With one or more COMPONENT, run only those.
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100164
165Special options:
166 -h|--help Print this help and exit.
Gilles Peskine10726102019-01-06 20:50:38 +0000167 --list-all-components List all available test components and exit.
168 --list-components List components supported on this platform and exit.
Gilles Peskine709346a2017-12-10 23:43:39 +0100169
170General options:
171 -f|--force Force the tests to overwrite any modified files.
Gilles Peskine7c652162017-12-11 00:01:40 +0100172 -k|--keep-going Run all tests and report errors at the end.
Gilles Peskine709346a2017-12-10 23:43:39 +0100173 -m|--memory Additional optional memory tests.
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100174 --armcc Run ARM Compiler builds (on by default).
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100175 --except If some components are passed on the command line,
176 run all the tests except for these components. In
177 this mode, you can pass shell wildcard patterns as
178 component names, e.g. "$0 --except 'test_*'" to
179 exclude all components that run tests.
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100180 --no-armcc Skip ARM Compiler builds.
Gilles Peskine38d81652018-03-21 08:40:26 +0100181 --no-force Refuse to overwrite modified files (default).
182 --no-keep-going Stop at the first error (default).
183 --no-memory No additional memory tests (default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100184 --out-of-source-dir=<path> Directory used for CMake out-of-source build tests.
Gilles Peskine38d81652018-03-21 08:40:26 +0100185 --random-seed Use a random seed value for randomized tests (default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100186 -r|--release-test Run this script in release mode. This fixes the seed value to 1.
187 -s|--seed Integer seed value to use for this test run.
188
189Tool path options:
190 --armc5-bin-dir=<ARMC5_bin_dir_path> ARM Compiler 5 bin directory.
191 --armc6-bin-dir=<ARMC6_bin_dir_path> ARM Compiler 6 bin directory.
192 --gnutls-cli=<GnuTLS_cli_path> GnuTLS client executable to use for most tests.
193 --gnutls-serv=<GnuTLS_serv_path> GnuTLS server executable to use for most tests.
194 --gnutls-legacy-cli=<GnuTLS_cli_path> GnuTLS client executable to use for legacy tests.
195 --gnutls-legacy-serv=<GnuTLS_serv_path> GnuTLS server executable to use for legacy tests.
196 --openssl=<OpenSSL_path> OpenSSL executable to use for most tests.
197 --openssl-legacy=<OpenSSL_path> OpenSSL executable to use for legacy tests e.g. SSLv3.
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100198 --openssl-next=<OpenSSL_path> OpenSSL executable to use for recent things like ARIA
Gilles Peskine709346a2017-12-10 23:43:39 +0100199EOF
SimonB2e23c822016-04-16 21:54:39 +0100200}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100201
202# remove built files as well as the cmake cache/config
203cleanup()
204{
Gilles Peskinea71d64c2018-03-21 12:16:57 +0100205 if [ -n "${MBEDTLS_ROOT_DIR+set}" ]; then
206 cd "$MBEDTLS_ROOT_DIR"
207 fi
208
Gilles Peskine7c652162017-12-11 00:01:40 +0100209 command make clean
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200210
Gilles Peskine31b07e22018-03-21 12:15:06 +0100211 # Remove CMake artefacts
Simon Butcher3ad2efd2018-05-02 14:49:38 +0100212 find . -name .git -prune \
Gilles Peskine31b07e22018-03-21 12:15:06 +0100213 -iname CMakeFiles -exec rm -rf {} \+ -o \
214 \( -iname cmake_install.cmake -o \
215 -iname CTestTestfile.cmake -o \
216 -iname CMakeCache.txt \) -exec rm {} \+
217 # Recover files overwritten by in-tree CMake builds
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000218 rm -f include/Makefile include/mbedtls/Makefile programs/*/Makefile
Paul Bakkerfe0984d2014-06-13 00:13:45 +0200219 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile
220 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200221
222 if [ -f "$CONFIG_BAK" ]; then
223 mv "$CONFIG_BAK" "$CONFIG_H"
224 fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100225}
226
Gilles Peskine7c652162017-12-11 00:01:40 +0100227# Executed on exit. May be redefined depending on command line options.
228final_report () {
229 :
230}
231
232fatal_signal () {
233 cleanup
234 final_report $1
235 trap - $1
236 kill -$1 $$
237}
238
239trap 'fatal_signal HUP' HUP
240trap 'fatal_signal INT' INT
241trap 'fatal_signal TERM' TERM
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200242
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100243msg()
244{
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100245 if [ -n "${current_component:-}" ]; then
246 current_section="${current_component#component_}: $1"
247 else
248 current_section="$1"
249 fi
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100250 echo ""
251 echo "******************************************************************"
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100252 echo "* $current_section "
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000253 printf "* "; date
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100254 echo "******************************************************************"
255}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100256
Gilles Peskine8f073122018-11-27 15:58:47 +0100257armc6_build_test()
258{
259 FLAGS="$1"
Andres AGa5cd9732016-10-17 15:23:10 +0100260
Gilles Peskine8f073122018-11-27 15:58:47 +0100261 msg "build: ARM Compiler 6 ($FLAGS), make"
262 ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \
263 WARNING_CFLAGS='-xc -std=c99' make lib
264 make clean
265}
Andres AGa5cd9732016-10-17 15:23:10 +0100266
Andres AGd9eba4b2016-08-26 14:42:14 +0100267err_msg()
268{
269 echo "$1" >&2
270}
271
272check_tools()
273{
274 for TOOL in "$@"; do
Andres AG98393602017-01-31 17:04:45 +0000275 if ! `type "$TOOL" >/dev/null 2>&1`; then
Andres AGd9eba4b2016-08-26 14:42:14 +0100276 err_msg "$TOOL not found!"
277 exit 1
278 fi
279 done
280}
281
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400282check_headers_in_cpp () {
283 ls include/mbedtls >headers.txt
284 <programs/test/cpp_dummy_build.cpp sed -n 's/"$//; s!^#include "mbedtls/!!p' |
285 sort |
286 diff headers.txt -
287 rm headers.txt
288}
289
Gilles Peskine8f073122018-11-27 15:58:47 +0100290pre_parse_command_line () {
Gilles Peskine1bcb1c82019-01-06 22:11:25 +0000291 COMMAND_LINE_COMPONENTS=
292 all_except=
Gilles Peskinee26ab182019-01-06 22:23:42 +0000293 no_armcc=
Gilles Peskine1bcb1c82019-01-06 22:11:25 +0000294
Gilles Peskine8f073122018-11-27 15:58:47 +0100295 while [ $# -gt 0 ]; do
Gilles Peskine06b385f2019-01-09 22:28:21 +0100296 case "$1" in
Gilles Peskinee26ab182019-01-06 22:23:42 +0000297 --armcc) no_armcc=;;
Gilles Peskine06b385f2019-01-09 22:28:21 +0100298 --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
299 --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
Gilles Peskine1bcb1c82019-01-06 22:11:25 +0000300 --except) all_except=1;;
Gilles Peskine06b385f2019-01-09 22:28:21 +0100301 --force|-f) FORCE=1;;
302 --gnutls-cli) shift; GNUTLS_CLI="$1";;
303 --gnutls-legacy-cli) shift; GNUTLS_LEGACY_CLI="$1";;
304 --gnutls-legacy-serv) shift; GNUTLS_LEGACY_SERV="$1";;
305 --gnutls-serv) shift; GNUTLS_SERV="$1";;
306 --help|-h) usage; exit;;
307 --keep-going|-k) KEEP_GOING=1;;
Gilles Peskine10726102019-01-06 20:50:38 +0000308 --list-all-components) printf '%s\n' $ALL_COMPONENTS; exit;;
309 --list-components) printf '%s\n' $SUPPORTED_COMPONENTS; exit;;
Gilles Peskine06b385f2019-01-09 22:28:21 +0100310 --memory|-m) MEMORY=1;;
Gilles Peskinee26ab182019-01-06 22:23:42 +0000311 --no-armcc) no_armcc=1;;
Gilles Peskine06b385f2019-01-09 22:28:21 +0100312 --no-force) FORCE=0;;
313 --no-keep-going) KEEP_GOING=0;;
314 --no-memory) MEMORY=0;;
315 --openssl) shift; OPENSSL="$1";;
316 --openssl-legacy) shift; OPENSSL_LEGACY="$1";;
317 --openssl-next) shift; OPENSSL_NEXT="$1";;
318 --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
319 --random-seed) unset SEED;;
320 --release-test|-r) SEED=1;;
321 --seed|-s) shift; SEED="$1";;
322 -*)
323 echo >&2 "Unknown option: $1"
324 echo >&2 "Run $0 --help for usage."
325 exit 120
326 ;;
Gilles Peskine1bcb1c82019-01-06 22:11:25 +0000327 *) COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS $1";;
Gilles Peskine06b385f2019-01-09 22:28:21 +0100328 esac
329 shift
Gilles Peskine8f073122018-11-27 15:58:47 +0100330 done
Gilles Peskine1bcb1c82019-01-06 22:11:25 +0000331
332 if [ -z "$COMMAND_LINE_COMPONENTS" ]; then
333 all_except=1
334 fi
335
Gilles Peskinee26ab182019-01-06 22:23:42 +0000336 # --no-armcc is a legacy option. The modern way is --except '*_armcc*'.
337 # Ignore it if components are listed explicitly on the command line.
338 if [ -n "$no_armcc" ] && [ -n "$all_except" ]; then
339 COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS *_armcc*"
340 fi
341
Gilles Peskine1bcb1c82019-01-06 22:11:25 +0000342 # Build the list of components to run.
343 if [ -n "$all_except" ]; then
344 RUN_COMPONENTS=
345 for component in $SUPPORTED_COMPONENTS; do
346 if ! is_component_excluded "$component"; then
347 RUN_COMPONENTS="$RUN_COMPONENTS $component"
348 fi
349 done
350 else
351 RUN_COMPONENTS="$COMMAND_LINE_COMPONENTS"
352 fi
353
354 unset all_except
Gilles Peskinee26ab182019-01-06 22:23:42 +0000355 unset no_armcc
Gilles Peskine8f073122018-11-27 15:58:47 +0100356}
SimonB2e23c822016-04-16 21:54:39 +0100357
Gilles Peskine8f073122018-11-27 15:58:47 +0100358pre_check_git () {
359 if [ $FORCE -eq 1 ]; then
360 git checkout-index -f -q $CONFIG_H
361 cleanup
362 else
SimonB2e23c822016-04-16 21:54:39 +0100363
Gilles Peskine8f073122018-11-27 15:58:47 +0100364 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
365 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
366 echo "You can either delete this directory manually, or force the test by rerunning"
367 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
368 exit 1
369 fi
370
371 if ! git diff-files --quiet include/mbedtls/config.h; then
372 err_msg "Warning - the configuration file 'include/mbedtls/config.h' has been edited. "
373 echo "You can either delete or preserve your work, or force the test by rerunning the"
374 echo "script as: $0 --force"
375 exit 1
376 fi
Andres AGdc192212016-08-31 17:33:13 +0100377 fi
Gilles Peskine8f073122018-11-27 15:58:47 +0100378}
Andres AGdc192212016-08-31 17:33:13 +0100379
Gilles Peskine8f073122018-11-27 15:58:47 +0100380pre_setup_keep_going () {
Gilles Peskine7c652162017-12-11 00:01:40 +0100381 failure_summary=
382 failure_count=0
383 start_red=
384 end_color=
385 if [ -t 1 ]; then
Gilles Peskine9736b9d2018-01-02 21:54:17 +0100386 case "${TERM:-}" in
Gilles Peskine7c652162017-12-11 00:01:40 +0100387 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
388 start_red=$(printf '\033[31m')
389 end_color=$(printf '\033[0m')
390 ;;
391 esac
392 fi
393 record_status () {
394 if "$@"; then
395 last_status=0
396 else
397 last_status=$?
398 text="$current_section: $* -> $last_status"
399 failure_summary="$failure_summary
400$text"
401 failure_count=$((failure_count + 1))
402 echo "${start_red}^^^^$text^^^^${end_color}"
403 fi
404 }
405 make () {
406 case "$*" in
407 *test|*check)
408 if [ $build_status -eq 0 ]; then
409 record_status command make "$@"
410 else
411 echo "(skipped because the build failed)"
412 fi
413 ;;
414 *)
415 record_status command make "$@"
416 build_status=$last_status
417 ;;
418 esac
419 }
420 final_report () {
421 if [ $failure_count -gt 0 ]; then
422 echo
423 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
424 echo "${start_red}FAILED: $failure_count${end_color}$failure_summary"
425 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Jaeden Amero7c1258d2018-07-20 16:42:14 +0100426 exit 1
Gilles Peskine7c652162017-12-11 00:01:40 +0100427 elif [ -z "${1-}" ]; then
428 echo "SUCCESS :)"
429 fi
430 if [ -n "${1-}" ]; then
431 echo "Killed by SIG$1."
432 fi
433 }
Gilles Peskine8f073122018-11-27 15:58:47 +0100434}
435
Gilles Peskine7c652162017-12-11 00:01:40 +0100436if_build_succeeded () {
437 if [ $build_status -eq 0 ]; then
438 record_status "$@"
439 fi
440}
441
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200442# to be used instead of ! for commands run with
443# record_status or if_build_succeeded
444not() {
445 ! "$@"
446}
447
Gilles Peskine8f073122018-11-27 15:58:47 +0100448pre_print_configuration () {
449 msg "info: $0 configuration"
450 echo "MEMORY: $MEMORY"
451 echo "FORCE: $FORCE"
452 echo "SEED: ${SEED-"UNSET"}"
453 echo "OPENSSL: $OPENSSL"
454 echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
455 echo "OPENSSL_NEXT: $OPENSSL_NEXT"
456 echo "GNUTLS_CLI: $GNUTLS_CLI"
457 echo "GNUTLS_SERV: $GNUTLS_SERV"
458 echo "GNUTLS_LEGACY_CLI: $GNUTLS_LEGACY_CLI"
459 echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV"
460 echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
461 echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
462}
Andres AG87bb5772016-09-27 15:05:15 +0100463
Gilles Peskine657f59a2019-01-06 22:40:00 +0000464# Make sure the tools we need are available.
Gilles Peskine8f073122018-11-27 15:58:47 +0100465pre_check_tools () {
Gilles Peskine2edf47c2019-01-06 22:46:21 +0000466 # Build the list of variables to pass to output_env.sh.
467 set env
468
Gilles Peskine657f59a2019-01-06 22:40:00 +0000469 case " $RUN_COMPONENTS " in
470 # Require OpenSSL and GnuTLS if running any tests (as opposed to
471 # only doing builds). Not all tests run OpenSSL and GnuTLS, but this
472 # is a good enough approximation in practice.
473 *" test_"*)
474 # To avoid setting OpenSSL and GnuTLS for each call to compat.sh
475 # and ssl-opt.sh, we just export the variables they require.
476 export OPENSSL_CMD="$OPENSSL"
477 export GNUTLS_CLI="$GNUTLS_CLI"
478 export GNUTLS_SERV="$GNUTLS_SERV"
479 # Avoid passing --seed flag in every call to ssl-opt.sh
480 if [ -n "${SEED-}" ]; then
481 export SEED
482 fi
Gilles Peskine2edf47c2019-01-06 22:46:21 +0000483 set "$@" OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY"
484 set "$@" GNUTLS_CLI="$GNUTLS_CLI" GNUTLS_SERV="$GNUTLS_SERV"
485 set "$@" GNUTLS_LEGACY_CLI="$GNUTLS_LEGACY_CLI"
486 set "$@" GNUTLS_LEGACY_SERV="$GNUTLS_LEGACY_SERV"
Gilles Peskine657f59a2019-01-06 22:40:00 +0000487 check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$OPENSSL_NEXT" \
488 "$GNUTLS_CLI" "$GNUTLS_SERV" \
489 "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV"
490 ;;
491 esac
Andres AGd9eba4b2016-08-26 14:42:14 +0100492
Gilles Peskine657f59a2019-01-06 22:40:00 +0000493 case " $RUN_COMPONENTS " in
494 *_doxygen[_\ ]*) check_tools "doxygen" "dot";;
495 esac
Andres AGb2fdd042016-09-22 14:17:46 +0100496
Gilles Peskine657f59a2019-01-06 22:40:00 +0000497 case " $RUN_COMPONENTS " in
498 *_arm_none_eabi_gcc[_\ ]*) check_tools "arm-none-eabi-gcc";;
499 esac
Andres AG7770ea82016-10-10 15:46:20 +0100500
Gilles Peskine657f59a2019-01-06 22:40:00 +0000501 case " $RUN_COMPONENTS " in
502 *_mingw[_\ ]*) check_tools "i686-w64-mingw32-gcc";;
503 esac
504
505 case " $RUN_COMPONENTS " in
506 *" test_zeroize "*) check_tools "gdb";;
507 esac
508
509 case " $RUN_COMPONENTS " in
Gilles Peskinee26ab182019-01-06 22:23:42 +0000510 *_armcc*)
Gilles Peskine657f59a2019-01-06 22:40:00 +0000511 ARMC5_CC="$ARMC5_BIN_DIR/armcc"
512 ARMC5_AR="$ARMC5_BIN_DIR/armar"
513 ARMC6_CC="$ARMC6_BIN_DIR/armclang"
514 ARMC6_AR="$ARMC6_BIN_DIR/armar"
Gilles Peskinee26ab182019-01-06 22:23:42 +0000515 check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC6_CC" "$ARMC6_AR";;
516 esac
Gilles Peskine2edf47c2019-01-06 22:46:21 +0000517
518 msg "info: output_env.sh"
519 case $RUN_COMPONENTS in
520 *_armcc*)
521 set "$@" ARMC5_CC="$ARMC5_CC" ARMC6_CC="$ARMC6_CC" RUN_ARMCC=1;;
522 *) set "$@" RUN_ARMCC=0;;
523 esac
524 "$@" scripts/output_env.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100525}
Gilles Peskine192c72f2017-12-21 15:59:21 +0100526
527
Gilles Peskine2edf47c2019-01-06 22:46:21 +0000528
Gilles Peskine192c72f2017-12-21 15:59:21 +0100529################################################################
530#### Basic checks
531################################################################
Andres AGd9eba4b2016-08-26 14:42:14 +0100532
SimonB2e23c822016-04-16 21:54:39 +0100533#
534# Test Suites to be executed
535#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200536# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100537# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard61bc57a2014-08-14 11:29:06 +0200538# and/or are more likely to fail than others (eg I use Clang most of the
539# time, so start with a GCC build).
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200540# 2. Minimize total running time, by avoiding useless rebuilds
541#
542# Indicative running times are given for reference.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100543
Gilles Peskine8f073122018-11-27 15:58:47 +0100544component_check_recursion () {
545 msg "test: recursion.pl" # < 1s
546 record_status tests/scripts/recursion.pl library/*.c
547}
Manuel Pégourié-Gonnardea29d152014-11-20 17:32:33 +0100548
Gilles Peskine8f073122018-11-27 15:58:47 +0100549component_check_generated_files () {
550 msg "test: freshness of generated source files" # < 1s
551 record_status tests/scripts/check-generated-files.sh
552}
Manuel Pégourié-Gonnardb3b8e432015-02-13 14:52:19 +0000553
Gilles Peskine8f073122018-11-27 15:58:47 +0100554component_check_doxy_blocks () {
555 msg "test: doxygen markup outside doxygen blocks" # < 1s
556 record_status tests/scripts/check-doxy-blocks.pl
557}
Manuel Pégourié-Gonnardd09a6b52015-04-09 17:19:23 +0200558
Gilles Peskine8f073122018-11-27 15:58:47 +0100559component_check_files () {
560 msg "test: check-files.py" # < 1s
Gilles Peskine8f073122018-11-27 15:58:47 +0100561 record_status tests/scripts/check-files.py
562}
Darryl Greena07039c2018-03-13 16:48:16 +0000563
Gilles Peskine8f073122018-11-27 15:58:47 +0100564component_check_names () {
565 msg "test/build: declared and exported names" # < 3s
Gilles Peskine8f073122018-11-27 15:58:47 +0100566 record_status tests/scripts/check-names.sh
567}
Manuel Pégourié-Gonnarda687baf2015-04-09 11:09:03 +0200568
Gilles Peskine8f073122018-11-27 15:58:47 +0100569component_check_doxygen_warnings () {
570 msg "test: doxygen warnings" # ~ 3s
Gilles Peskine8f073122018-11-27 15:58:47 +0100571 record_status tests/scripts/doxygen.sh
572}
Manuel Pégourié-Gonnard1d552e72016-01-04 16:49:09 +0100573
Gilles Peskine192c72f2017-12-21 15:59:21 +0100574
Gilles Peskine192c72f2017-12-21 15:59:21 +0100575################################################################
576#### Build and test many configurations and targets
577################################################################
578
Gilles Peskine8f073122018-11-27 15:58:47 +0100579component_test_default_cmake_gcc_asan () {
580 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100581 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
582 make
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100583
Gilles Peskine8f073122018-11-27 15:58:47 +0100584 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
585 make test
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200586
Gilles Peskine8f073122018-11-27 15:58:47 +0100587 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
588 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200589
Gilles Peskine8f073122018-11-27 15:58:47 +0100590 msg "test: compat.sh (ASan build)" # ~ 6 min
591 if_build_succeeded tests/compat.sh
592}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200593
Gilles Peskine782f4112018-11-27 16:11:09 +0100594component_test_ref_configs () {
595 msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
596 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
597 record_status tests/scripts/test-ref-configs.pl
598}
599
Gilles Peskine8f073122018-11-27 15:58:47 +0100600component_test_sslv3 () {
601 msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100602 scripts/config.pl set MBEDTLS_SSL_PROTO_SSL3
603 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
604 make
Simon Butcher3ea7f522016-03-07 23:22:10 +0000605
Gilles Peskine8f073122018-11-27 15:58:47 +0100606 msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
607 make test
Simon Butcher3ea7f522016-03-07 23:22:10 +0000608
Gilles Peskine8f073122018-11-27 15:58:47 +0100609 msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
610 if_build_succeeded tests/compat.sh -m 'tls1 tls1_1 tls1_2 dtls1 dtls1_2'
611 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
Simon Butcher3ea7f522016-03-07 23:22:10 +0000612
Gilles Peskine8f073122018-11-27 15:58:47 +0100613 msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
614 if_build_succeeded tests/ssl-opt.sh
615}
Simon Butcher3ea7f522016-03-07 23:22:10 +0000616
Gilles Peskine8f073122018-11-27 15:58:47 +0100617component_test_no_renegotiation () {
618 msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100619 scripts/config.pl unset MBEDTLS_SSL_RENEGOTIATION
620 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
621 make
Hanno Becker134c2ab2017-10-12 15:29:50 +0100622
Gilles Peskine8f073122018-11-27 15:58:47 +0100623 msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
624 make test
Hanno Becker134c2ab2017-10-12 15:29:50 +0100625
Gilles Peskine8f073122018-11-27 15:58:47 +0100626 msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
627 if_build_succeeded tests/ssl-opt.sh
628}
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +0100629
Gilles Peskine8f073122018-11-27 15:58:47 +0100630component_test_rsa_no_crt () {
631 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100632 scripts/config.pl set MBEDTLS_RSA_NO_CRT
633 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
634 make
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100635
Gilles Peskine8f073122018-11-27 15:58:47 +0100636 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
637 make test
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100638
Gilles Peskine8f073122018-11-27 15:58:47 +0100639 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
640 if_build_succeeded tests/ssl-opt.sh -f RSA
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100641
Gilles Peskine8f073122018-11-27 15:58:47 +0100642 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
643 if_build_succeeded tests/compat.sh -t RSA
644}
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100645
Gilles Peskine8f073122018-11-27 15:58:47 +0100646component_test_small_ssl_out_content_len () {
647 msg "build: small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100648 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 16384
649 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
650 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
651 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000652
Gilles Peskine8f073122018-11-27 15:58:47 +0100653 msg "test: small SSL_OUT_CONTENT_LEN - ssl-opt.sh MFL and large packet tests"
654 if_build_succeeded tests/ssl-opt.sh -f "Max fragment\|Large packet"
655}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000656
Gilles Peskine8f073122018-11-27 15:58:47 +0100657component_test_small_ssl_in_content_len () {
658 msg "build: small SSL_IN_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100659 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 4096
660 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 16384
661 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
662 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000663
Gilles Peskine8f073122018-11-27 15:58:47 +0100664 msg "test: small SSL_IN_CONTENT_LEN - ssl-opt.sh MFL tests"
665 if_build_succeeded tests/ssl-opt.sh -f "Max fragment"
666}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000667
Gilles Peskine8f073122018-11-27 15:58:47 +0100668component_test_small_ssl_dtls_max_buffering () {
669 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0"
Gilles Peskine8f073122018-11-27 15:58:47 +0100670 scripts/config.pl set MBEDTLS_SSL_DTLS_MAX_BUFFERING 1000
671 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
672 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100673
Gilles Peskine8f073122018-11-27 15:58:47 +0100674 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0 - ssl-opt.sh specific reordering test"
675 if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer out-of-order hs msg before reassembling next, free buffered msg"
676}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100677
Gilles Peskine8f073122018-11-27 15:58:47 +0100678component_test_small_mbedtls_ssl_dtls_max_buffering () {
679 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1"
Gilles Peskine8f073122018-11-27 15:58:47 +0100680 scripts/config.pl set MBEDTLS_SSL_DTLS_MAX_BUFFERING 240
681 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
682 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100683
Gilles Peskine8f073122018-11-27 15:58:47 +0100684 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1 - ssl-opt.sh specific reordering test"
685 if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer encrypted Finished message, drop for fragmented NewSessionTicket"
686}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100687
Gilles Peskine8f073122018-11-27 15:58:47 +0100688component_test_full_cmake_clang () {
689 msg "build: cmake, full config, clang" # ~ 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100690 scripts/config.pl full
691 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
692 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check -D ENABLE_TESTING=On .
693 make
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100694
Gilles Peskine8f073122018-11-27 15:58:47 +0100695 msg "test: main suites (full config)" # ~ 5s
696 make test
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200697
Gilles Peskine8f073122018-11-27 15:58:47 +0100698 msg "test: ssl-opt.sh default, ECJPAKE, SSL async (full config)" # ~ 1s
699 if_build_succeeded tests/ssl-opt.sh -f 'Default\|ECJPAKE\|SSL async private'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200700
Gilles Peskine8f073122018-11-27 15:58:47 +0100701 msg "test: compat.sh RC4, DES & NULL (full config)" # ~ 2 min
702 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 +0200703
Gilles Peskine8f073122018-11-27 15:58:47 +0100704 msg "test: compat.sh ARIA + ChachaPoly"
705 if_build_succeeded env OPENSSL_CMD="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
706}
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100707
Gilles Peskine8f073122018-11-27 15:58:47 +0100708component_build_deprecated () {
709 msg "build: make, full config + DEPRECATED_WARNING, gcc -O" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100710 scripts/config.pl full
711 scripts/config.pl set MBEDTLS_DEPRECATED_WARNING
712 # Build with -O -Wextra to catch a maximum of issues.
713 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra' lib programs
714 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
Gilles Peskineb4ef45b2018-03-01 22:23:50 +0100715
Gilles Peskine8f073122018-11-27 15:58:47 +0100716 msg "build: make, full config + DEPRECATED_REMOVED, clang -O" # ~ 30s
717 # No cleanup, just tweak the configuration and rebuild
718 make clean
719 scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
720 scripts/config.pl set MBEDTLS_DEPRECATED_REMOVED
721 # Build with -O -Wextra to catch a maximum of issues.
722 make CC=clang CFLAGS='-O -Werror -Wall -Wextra' lib programs
723 make CC=clang CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
724}
Gilles Peskine0afe6242018-02-21 19:28:12 +0100725
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200726
Gilles Peskine8f073122018-11-27 15:58:47 +0100727component_test_depends_curves () {
728 msg "test/build: curves.pl (gcc)" # ~ 4 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100729 record_status tests/scripts/curves.pl
730}
Manuel Pégourié-Gonnard1fe6bb92017-06-06 11:36:16 +0200731
Gilles Peskine8f073122018-11-27 15:58:47 +0100732component_test_depends_hashes () {
733 msg "test/build: depends-hashes.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100734 record_status tests/scripts/depends-hashes.pl
735}
Manuel Pégourié-Gonnard43be6cd2017-06-20 09:53:42 +0200736
Gilles Peskine8f073122018-11-27 15:58:47 +0100737component_test_depends_pkalgs () {
738 msg "test/build: depends-pkalgs.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100739 record_status tests/scripts/depends-pkalgs.pl
740}
Manuel Pégourié-Gonnard503a5ef2015-10-23 09:04:45 +0200741
Gilles Peskine8f073122018-11-27 15:58:47 +0100742component_build_key_exchanges () {
743 msg "test/build: key-exchanges (gcc)" # ~ 1 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100744 record_status tests/scripts/key-exchanges.pl
745}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100746
Gilles Peskine8f073122018-11-27 15:58:47 +0100747component_build_default_make_gcc_and_cxx () {
748 msg "build: Unix make, -Os (gcc)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100749 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400750
Gilles Peskine8f073122018-11-27 15:58:47 +0100751 msg "test: verify header list in cpp_dummy_build.cpp"
752 record_status check_headers_in_cpp
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400753
Gilles Peskine8f073122018-11-27 15:58:47 +0100754 msg "build: Unix make, incremental g++"
755 make TEST_CPP=1
756}
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +0000757
Gilles Peskine8f073122018-11-27 15:58:47 +0100758component_test_no_platform () {
759 # Full configuration build, without platform support, file IO and net sockets.
760 # This should catch missing mbedtls_printf definitions, and by disabling file
761 # IO, it should catch missing '#include <stdio.h>'
762 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100763 scripts/config.pl full
764 scripts/config.pl unset MBEDTLS_PLATFORM_C
765 scripts/config.pl unset MBEDTLS_NET_C
766 scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
767 scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
768 scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
769 scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
770 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
771 scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
772 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
773 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
774 scripts/config.pl unset MBEDTLS_FS_IO
Gilles Peskine51585382019-01-05 10:27:47 +0100775 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_FILE_C
776 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_C
Gilles Peskine8f073122018-11-27 15:58:47 +0100777 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
778 # to re-enable platform integration features otherwise disabled in C99 builds
779 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -O0 -D_DEFAULT_SOURCE' lib programs
780 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0' test
781}
Manuel Pégourié-Gonnarddccb80b2015-06-03 10:20:33 +0100782
Gilles Peskine8f073122018-11-27 15:58:47 +0100783component_build_no_std_function () {
784 # catch compile bugs in _uninit functions
785 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100786 scripts/config.pl full
787 scripts/config.pl set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
788 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
789 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
790}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200791
Gilles Peskine8f073122018-11-27 15:58:47 +0100792component_build_no_ssl_srv () {
793 msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100794 scripts/config.pl full
795 scripts/config.pl unset MBEDTLS_SSL_SRV_C
796 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
797}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200798
Gilles Peskine8f073122018-11-27 15:58:47 +0100799component_build_no_ssl_cli () {
800 msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100801 scripts/config.pl full
802 scripts/config.pl unset MBEDTLS_SSL_CLI_C
803 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
804}
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +0200805
Gilles Peskine8f073122018-11-27 15:58:47 +0100806component_build_no_sockets () {
807 # Note, C99 compliance can also be tested with the sockets support disabled,
808 # as that requires a POSIX platform (which isn't the same as C99).
809 msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100810 scripts/config.pl full
811 scripts/config.pl unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
812 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
813 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0 -std=c99 -pedantic' lib
814}
Hanno Becker5175ac62017-09-18 15:36:25 +0100815
Gilles Peskine8f073122018-11-27 15:58:47 +0100816component_test_no_max_fragment_length () {
817 # Run max fragment length tests with MFL disabled
818 msg "build: default config except MFL extension (ASan build)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100819 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
820 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
821 make
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000822
Gilles Peskine8f073122018-11-27 15:58:47 +0100823 msg "test: ssl-opt.sh, MFL-related tests"
824 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length"
825}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000826
Gilles Peskine8f073122018-11-27 15:58:47 +0100827component_test_no_max_fragment_length_small_ssl_out_content_len () {
828 msg "build: no MFL extension, small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100829 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
830 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 16384
831 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
832 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
833 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000834
Gilles Peskine8f073122018-11-27 15:58:47 +0100835 msg "test: MFL tests (disabled MFL extension case) & large packet tests"
836 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length\|Large buffer"
837}
Janos Follath06c54002016-06-09 13:57:40 +0100838
Gilles Peskine8f073122018-11-27 15:58:47 +0100839component_test_null_entropy () {
840 msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100841 scripts/config.pl set MBEDTLS_TEST_NULL_ENTROPY
842 scripts/config.pl set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
843 scripts/config.pl set MBEDTLS_ENTROPY_C
844 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
845 scripts/config.pl unset MBEDTLS_ENTROPY_HARDWARE_ALT
846 scripts/config.pl unset MBEDTLS_HAVEGE_C
Gilles Peskine19275652019-01-06 19:48:30 +0000847 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan -D UNSAFE_BUILD=ON .
Gilles Peskine8f073122018-11-27 15:58:47 +0100848 make
Janos Follath06c54002016-06-09 13:57:40 +0100849
Gilles Peskine8f073122018-11-27 15:58:47 +0100850 msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)"
851 make test
852}
Hanno Beckere5fecec2018-10-11 11:02:52 +0100853
Gilles Peskine8f073122018-11-27 15:58:47 +0100854component_test_platform_calloc_macro () {
855 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100856 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
857 scripts/config.pl set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
858 scripts/config.pl set MBEDTLS_PLATFORM_FREE_MACRO free
859 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
860 make
Hanno Beckere5fecec2018-10-11 11:02:52 +0100861
Gilles Peskine8f073122018-11-27 15:58:47 +0100862 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
863 make test
864}
Hanno Becker83ebf782017-07-07 12:29:15 +0100865
Gilles Peskine8f073122018-11-27 15:58:47 +0100866component_test_aes_fewer_tables () {
867 msg "build: default config with AES_FEWER_TABLES enabled"
Gilles Peskine8f073122018-11-27 15:58:47 +0100868 scripts/config.pl set MBEDTLS_AES_FEWER_TABLES
869 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +0100870
Gilles Peskine8f073122018-11-27 15:58:47 +0100871 msg "test: AES_FEWER_TABLES"
872 make test
873}
Hanno Becker83ebf782017-07-07 12:29:15 +0100874
Gilles Peskine8f073122018-11-27 15:58:47 +0100875component_test_aes_rom_tables () {
876 msg "build: default config with AES_ROM_TABLES enabled"
Gilles Peskine8f073122018-11-27 15:58:47 +0100877 scripts/config.pl set MBEDTLS_AES_ROM_TABLES
878 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +0100879
Gilles Peskine8f073122018-11-27 15:58:47 +0100880 msg "test: AES_ROM_TABLES"
881 make test
882}
Hanno Becker83ebf782017-07-07 12:29:15 +0100883
Gilles Peskine8f073122018-11-27 15:58:47 +0100884component_test_aes_fewer_tables_and_rom_tables () {
885 msg "build: default config with AES_ROM_TABLES and AES_FEWER_TABLES enabled"
Gilles Peskine8f073122018-11-27 15:58:47 +0100886 scripts/config.pl set MBEDTLS_AES_FEWER_TABLES
887 scripts/config.pl set MBEDTLS_AES_ROM_TABLES
888 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +0100889
Gilles Peskine8f073122018-11-27 15:58:47 +0100890 msg "test: AES_FEWER_TABLES + AES_ROM_TABLES"
891 make test
892}
893
894component_test_make_shared () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100895 msg "build/test: make shared" # ~ 40s
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100896 make SHARED=1 all check
Gilles Peskine8f073122018-11-27 15:58:47 +0100897}
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +0200898
Gilles Peskine8f073122018-11-27 15:58:47 +0100899component_test_m32_o0 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100900 # Build once with -O0, to compile out the i386 specific inline assembly
901 msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
Simon Butcher7a6da6e2018-06-27 21:52:54 +0100902 scripts/config.pl full
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100903 make CC=gcc CFLAGS='-O0 -Werror -Wall -Wextra -m32 -fsanitize=address'
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +0100904
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100905 msg "test: i386, make, gcc -O0 (ASan build)"
906 make test
Gilles Peskine8f073122018-11-27 15:58:47 +0100907}
Gilles Peskine10726102019-01-06 20:50:38 +0000908support_test_m32_o0 () {
909 case $(uname -m) in
910 *64*) true;;
911 *) false;;
912 esac
913}
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100914
Gilles Peskine8f073122018-11-27 15:58:47 +0100915component_test_m32_o1 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100916 # Build again with -O1, to compile in the i386 specific inline assembly
917 msg "build: i386, make, gcc -O1 (ASan build)" # ~ 30s
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100918 scripts/config.pl full
919 make CC=gcc CFLAGS='-O1 -Werror -Wall -Wextra -m32 -fsanitize=address'
920
921 msg "test: i386, make, gcc -O1 (ASan build)"
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +0100922 make test
Gilles Peskine8f073122018-11-27 15:58:47 +0100923}
Gilles Peskine10726102019-01-06 20:50:38 +0000924support_test_m32_o1 () {
925 support_test_m32_o0 "$@"
926}
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +0100927
Gilles Peskine8f073122018-11-27 15:58:47 +0100928component_test_mx32 () {
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +0100929 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
Simon Butcher7a6da6e2018-06-27 21:52:54 +0100930 scripts/config.pl full
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +0100931 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32'
932
933 msg "test: 64-bit ILP32, make, gcc"
934 make test
Gilles Peskine8f073122018-11-27 15:58:47 +0100935}
Gilles Peskine10726102019-01-06 20:50:38 +0000936support_test_mx32 () {
937 case $(uname -m) in
938 amd64|x86_64) true;;
939 *) false;;
940 esac
941}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000942
Gilles Peskine8f073122018-11-27 15:58:47 +0100943component_test_have_int32 () {
944 msg "build: gcc, force 32-bit bignum limbs"
Gilles Peskine8f073122018-11-27 15:58:47 +0100945 scripts/config.pl unset MBEDTLS_HAVE_ASM
946 scripts/config.pl unset MBEDTLS_AESNI_C
947 scripts/config.pl unset MBEDTLS_PADLOCK_C
948 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +0100949
Gilles Peskine8f073122018-11-27 15:58:47 +0100950 msg "test: gcc, force 32-bit bignum limbs"
951 make test
952}
Andres Amaya Garciafe843a32017-07-20 13:21:34 +0100953
Gilles Peskine8f073122018-11-27 15:58:47 +0100954component_test_have_int64 () {
955 msg "build: gcc, force 64-bit bignum limbs"
Gilles Peskine8f073122018-11-27 15:58:47 +0100956 scripts/config.pl unset MBEDTLS_HAVE_ASM
957 scripts/config.pl unset MBEDTLS_AESNI_C
958 scripts/config.pl unset MBEDTLS_PADLOCK_C
959 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
Gilles Peskine14c3c062018-01-29 21:25:12 +0100960
Gilles Peskine8f073122018-11-27 15:58:47 +0100961 msg "test: gcc, force 64-bit bignum limbs"
962 make test
963}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000964
Gilles Peskine8f073122018-11-27 15:58:47 +0100965component_test_no_udbl_division () {
966 msg "build: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +0100967 scripts/config.pl full
968 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
969 scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
970 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200971
Gilles Peskine8f073122018-11-27 15:58:47 +0100972 msg "test: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
973 make test
974}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200975
Gilles Peskine8f073122018-11-27 15:58:47 +0100976component_test_no_64bit_multiplication () {
977 msg "build: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +0100978 scripts/config.pl full
979 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
980 scripts/config.pl set MBEDTLS_NO_64BIT_MULTIPLICATION
981 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200982
Gilles Peskine8f073122018-11-27 15:58:47 +0100983 msg "test: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
984 make test
985}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200986
Gilles Peskine8f073122018-11-27 15:58:47 +0100987component_build_arm_none_eabi_gcc () {
988 msg "build: arm-none-eabi-gcc, make" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +0100989 scripts/config.pl full
990 scripts/config.pl unset MBEDTLS_NET_C
991 scripts/config.pl unset MBEDTLS_TIMING_C
992 scripts/config.pl unset MBEDTLS_FS_IO
Gilles Peskine51585382019-01-05 10:27:47 +0100993 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_FILE_C
994 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_C
Gilles Peskine8f073122018-11-27 15:58:47 +0100995 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
996 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
997 # following things are not in the default config
998 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
999 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
1000 scripts/config.pl unset MBEDTLS_THREADING_C
1001 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
1002 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
1003 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
1004}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001005
Gilles Peskine8f073122018-11-27 15:58:47 +01001006component_build_arm_none_eabi_gcc_no_udbl_division () {
1007 msg "build: arm-none-eabi-gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +01001008 scripts/config.pl full
1009 scripts/config.pl unset MBEDTLS_NET_C
1010 scripts/config.pl unset MBEDTLS_TIMING_C
1011 scripts/config.pl unset MBEDTLS_FS_IO
Gilles Peskine51585382019-01-05 10:27:47 +01001012 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_FILE_C
1013 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_C
Gilles Peskine8f073122018-11-27 15:58:47 +01001014 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
1015 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
1016 # following things are not in the default config
1017 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
1018 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
1019 scripts/config.pl unset MBEDTLS_THREADING_C
1020 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
1021 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
1022 scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
1023 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
1024 echo "Checking that software 64-bit division is not required"
1025 if_build_succeeded not grep __aeabi_uldiv library/*.o
1026}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001027
Gilles Peskine8f073122018-11-27 15:58:47 +01001028component_build_arm_none_eabi_gcc_no_64bit_multiplication () {
1029 msg "build: arm-none-eabi-gcc MBEDTLS_NO_64BIT_MULTIPLICATION, make" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +01001030 scripts/config.pl full
1031 scripts/config.pl unset MBEDTLS_NET_C
1032 scripts/config.pl unset MBEDTLS_TIMING_C
1033 scripts/config.pl unset MBEDTLS_FS_IO
Gilles Peskine51585382019-01-05 10:27:47 +01001034 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_FILE_C
1035 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_C
Gilles Peskine8f073122018-11-27 15:58:47 +01001036 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
1037 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
1038 # following things are not in the default config
1039 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
1040 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
1041 scripts/config.pl unset MBEDTLS_THREADING_C
1042 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
1043 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
1044 scripts/config.pl set MBEDTLS_NO_64BIT_MULTIPLICATION
1045 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -O1 -march=armv6-m -mthumb' lib
1046 echo "Checking that software 64-bit multiplication is not required"
1047 if_build_succeeded not grep __aeabi_lmul library/*.o
1048}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001049
Gilles Peskine8f073122018-11-27 15:58:47 +01001050component_build_armcc () {
1051 msg "build: ARM Compiler 5, make"
Gilles Peskine8f073122018-11-27 15:58:47 +01001052 scripts/config.pl full
1053 scripts/config.pl unset MBEDTLS_NET_C
1054 scripts/config.pl unset MBEDTLS_TIMING_C
1055 scripts/config.pl unset MBEDTLS_FS_IO
Gilles Peskine51585382019-01-05 10:27:47 +01001056 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_FILE_C
1057 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_C
Gilles Peskine8f073122018-11-27 15:58:47 +01001058 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
1059 scripts/config.pl unset MBEDTLS_HAVE_TIME
1060 scripts/config.pl unset MBEDTLS_HAVE_TIME_DATE
1061 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
1062 # following things are not in the default config
1063 scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
1064 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
1065 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
1066 scripts/config.pl unset MBEDTLS_THREADING_C
1067 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
1068 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
1069 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT # depends on MBEDTLS_HAVE_TIME
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001070
Gilles Peskinee26ab182019-01-06 22:23:42 +00001071 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
1072 make clean
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001073
Gilles Peskinee26ab182019-01-06 22:23:42 +00001074 # ARM Compiler 6 - Target ARMv7-A
1075 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-a"
Gilles Peskineed942f82017-06-08 15:19:20 +02001076
Gilles Peskinee26ab182019-01-06 22:23:42 +00001077 # ARM Compiler 6 - Target ARMv7-M
1078 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m"
Andres AG87bb5772016-09-27 15:05:15 +01001079
Gilles Peskinee26ab182019-01-06 22:23:42 +00001080 # ARM Compiler 6 - Target ARMv8-A - AArch32
1081 armc6_build_test "--target=arm-arm-none-eabi -march=armv8.2-a"
Andres AG87bb5772016-09-27 15:05:15 +01001082
Gilles Peskinee26ab182019-01-06 22:23:42 +00001083 # ARM Compiler 6 - Target ARMv8-M
1084 armc6_build_test "--target=arm-arm-none-eabi -march=armv8-m.main"
Simon Butcher940737f2017-07-23 13:42:36 +02001085
Gilles Peskinee26ab182019-01-06 22:23:42 +00001086 # ARM Compiler 6 - Target ARMv8-A - AArch64
1087 armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a"
Gilles Peskine8f073122018-11-27 15:58:47 +01001088}
Simon Butcher940737f2017-07-23 13:42:36 +02001089
Gilles Peskine8f073122018-11-27 15:58:47 +01001090component_test_allow_sha1 () {
1091 msg "build: allow SHA1 in certificates by default"
Gilles Peskine8f073122018-11-27 15:58:47 +01001092 scripts/config.pl set MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
1093 make CFLAGS='-Werror -Wall -Wextra'
1094 msg "test: allow SHA1 in certificates by default"
1095 make test
1096 if_build_succeeded tests/ssl-opt.sh -f SHA-1
1097}
Simon Butcher940737f2017-07-23 13:42:36 +02001098
Gilles Peskine8f073122018-11-27 15:58:47 +01001099component_build_mingw () {
1100 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +01001101 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 +02001102
Gilles Peskine8f073122018-11-27 15:58:47 +01001103 # note Make tests only builds the tests, but doesn't run them
1104 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror' WINDOWS_BUILD=1 tests
1105 make WINDOWS_BUILD=1 clean
Hanno Beckere963efa2018-01-03 10:03:43 +00001106
Gilles Peskine8f073122018-11-27 15:58:47 +01001107 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
1108 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
1109 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
1110 make WINDOWS_BUILD=1 clean
1111}
Simon Butcher002bc622016-11-17 09:27:45 +00001112
Gilles Peskine8f073122018-11-27 15:58:47 +01001113component_test_memsan () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001114 msg "build: MSan (clang)" # ~ 1 min 20s
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001115 scripts/config.pl unset MBEDTLS_AESNI_C # memsan doesn't grok asm
1116 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
1117 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +02001118
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001119 msg "test: main suites (MSan)" # ~ 10s
1120 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001121
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001122 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
Gilles Peskine7c652162017-12-11 00:01:40 +01001123 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001124
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001125 # Optional part(s)
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001126
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001127 if [ "$MEMORY" -gt 0 ]; then
1128 msg "test: compat.sh (MSan)" # ~ 6 min 20s
Gilles Peskine7c652162017-12-11 00:01:40 +01001129 if_build_succeeded tests/compat.sh
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001130 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001131}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001132
Gilles Peskine8f073122018-11-27 15:58:47 +01001133component_test_memcheck () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001134 msg "build: Release (clang)"
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001135 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
1136 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001137
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001138 msg "test: main suites valgrind (Release)"
1139 make memcheck
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001140
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001141 # Optional part(s)
1142 # Currently broken, programs don't seem to receive signals
1143 # under valgrind on OS X
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001144
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001145 if [ "$MEMORY" -gt 0 ]; then
1146 msg "test: ssl-opt.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +01001147 if_build_succeeded tests/ssl-opt.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001148 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001149
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001150 if [ "$MEMORY" -gt 1 ]; then
1151 msg "test: compat.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +01001152 if_build_succeeded tests/compat.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001153 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001154}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001155
Gilles Peskine8f073122018-11-27 15:58:47 +01001156component_test_cmake_out_of_source () {
1157 msg "build: cmake 'out-of-source' build"
Gilles Peskine8f073122018-11-27 15:58:47 +01001158 MBEDTLS_ROOT_DIR="$PWD"
1159 mkdir "$OUT_OF_SOURCE_DIR"
1160 cd "$OUT_OF_SOURCE_DIR"
1161 cmake "$MBEDTLS_ROOT_DIR"
1162 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001163
Gilles Peskine8f073122018-11-27 15:58:47 +01001164 msg "test: cmake 'out-of-source' build"
1165 make test
1166 # Test an SSL option that requires an auxiliary script in test/scripts/.
1167 # Also ensure that there are no error messages such as
1168 # "No such file or directory", which would indicate that some required
1169 # file is missing (ssl-opt.sh tolerates the absence of some files so
1170 # may exit with status 0 but emit errors).
1171 if_build_succeeded ./tests/ssl-opt.sh -f 'Fallback SCSV: beginning of list' 2>ssl-opt.err
1172 if [ -s ssl-opt.err ]; then
1173 cat ssl-opt.err >&2
1174 record_status [ ! -s ssl-opt.err ]
1175 rm ssl-opt.err
1176 fi
1177 cd "$MBEDTLS_ROOT_DIR"
1178 rm -rf "$OUT_OF_SOURCE_DIR"
1179 unset MBEDTLS_ROOT_DIR
1180}
Andres AGdc192212016-08-31 17:33:13 +01001181
Gilles Peskine8f073122018-11-27 15:58:47 +01001182component_test_zeroize () {
1183 # Test that the function mbedtls_platform_zeroize() is not optimized away by
1184 # different combinations of compilers and optimization flags by using an
1185 # auxiliary GDB script. Unfortunately, GDB does not return error values to the
1186 # system in all cases that the script fails, so we must manually search the
1187 # output to check whether the pass string is present and no failure strings
1188 # were printed.
Gilles Peskine74851d82019-01-06 19:52:22 +00001189
1190 # Don't try to disable ASLR. We don't care about ASLR here. We do care
1191 # about a spurious message if Gdb tries and fails, so suppress that.
1192 gdb_disable_aslr=
1193 if [ -z "$(gdb -batch -nw -ex 'set disable-randomization off' 2>&1)" ]; then
1194 gdb_disable_aslr='set disable-randomization off'
1195 fi
1196
Gilles Peskine8f073122018-11-27 15:58:47 +01001197 for optimization_flag in -O2 -O3 -Ofast -Os; do
Gilles Peskine06b385f2019-01-09 22:28:21 +01001198 for compiler in clang gcc; do
1199 msg "test: $compiler $optimization_flag, mbedtls_platform_zeroize()"
1200 make programs CC="$compiler" DEBUG=1 CFLAGS="$optimization_flag"
Gilles Peskine74851d82019-01-06 19:52:22 +00001201 if_build_succeeded gdb -ex "$gdb_disable_aslr" -x tests/scripts/test_zeroize.gdb -nw -batch -nx 2>&1 | tee test_zeroize.log
Gilles Peskine06b385f2019-01-09 22:28:21 +01001202 if_build_succeeded grep "The buffer was correctly zeroized" test_zeroize.log
1203 if_build_succeeded not grep -i "error" test_zeroize.log
1204 rm -f test_zeroize.log
1205 make clean
1206 done
Andres Amaya Garcia29673812017-10-25 10:35:51 +01001207 done
Gilles Peskine74851d82019-01-06 19:52:22 +00001208
1209 unset gdb_disable_aslr
Gilles Peskine8f073122018-11-27 15:58:47 +01001210}
Andres Amaya Garciad0d7bf62017-10-25 09:01:31 +01001211
Gilles Peskine8f073122018-11-27 15:58:47 +01001212component_check_python_files () {
1213 msg "Lint: Python scripts"
1214 record_status tests/scripts/check-python-files.sh
1215}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001216
Gilles Peskine8f073122018-11-27 15:58:47 +01001217component_check_generate_test_code () {
1218 msg "uint test: generate_test_code.py"
1219 record_status ./tests/scripts/test_generate_test_code.py
1220}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001221
1222################################################################
1223#### Termination
1224################################################################
1225
Gilles Peskine8f073122018-11-27 15:58:47 +01001226post_report () {
1227 msg "Done, cleaning up"
1228 cleanup
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001229
Gilles Peskine8f073122018-11-27 15:58:47 +01001230 final_report
1231}
1232
1233
1234
1235################################################################
1236#### Run all the things
1237################################################################
1238
Gilles Peskinee48351a2018-11-27 16:06:30 +01001239# Run one component and clean up afterwards.
Gilles Peskine8f073122018-11-27 15:58:47 +01001240run_component () {
Gilles Peskine8ae15dd2019-01-02 18:57:02 +01001241 # Back up the configuration in case the component modifies it.
1242 # The cleanup function will restore it.
1243 cp -p "$CONFIG_H" "$CONFIG_BAK"
Gilles Peskineffcdeff2018-12-04 12:49:28 +01001244 current_component="$1"
Gilles Peskine8f073122018-11-27 15:58:47 +01001245 "$@"
Gilles Peskinee48351a2018-11-27 16:06:30 +01001246 cleanup
Gilles Peskine8f073122018-11-27 15:58:47 +01001247}
1248
1249# Preliminary setup
1250pre_check_environment
1251pre_initialize_variables
1252pre_parse_command_line "$@"
Gilles Peskine348fb9a2018-11-27 17:04:29 +01001253
Gilles Peskine10726102019-01-06 20:50:38 +00001254pre_check_git
1255build_status=0
1256if [ $KEEP_GOING -eq 1 ]; then
1257 pre_setup_keep_going
1258else
1259 record_status () {
1260 "$@"
1261 }
1262fi
1263pre_print_configuration
1264pre_check_tools
Gilles Peskine10726102019-01-06 20:50:38 +00001265cleanup
Gilles Peskine8f073122018-11-27 15:58:47 +01001266
Gilles Peskine1bcb1c82019-01-06 22:11:25 +00001267# Run the requested tests.
1268for component in $RUN_COMPONENTS; do
1269 run_component "component_$component"
1270done
Gilles Peskine8f073122018-11-27 15:58:47 +01001271
1272# We're done.
Gilles Peskine10726102019-01-06 20:50:38 +00001273post_report