blob: d240ddb719be75b21c5ac00062002c9778c38db5 [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
Jaeden Ameroc4cc2512019-01-30 15:35:44 +0000123 # Default commands, can be overridden by the environment
Gilles Peskine8f073122018-11-27 15:58:47 +0100124 : ${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 Peskinea28db922019-01-10 00:05:18 +0100157# Test whether the component $1 is included in the command line patterns.
158is_component_included()
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100159{
160 set -f
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000161 for pattern in $COMMAND_LINE_COMPONENTS; do
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100162 set +f
163 case ${1#component_} in $pattern) return 0;; esac
164 done
165 set +f
166 return 1
167}
Andres AG7770ea82016-10-10 15:46:20 +0100168
Simon Butcher41eeccf2016-09-07 00:07:09 +0100169usage()
Andres AGd9eba4b2016-08-26 14:42:14 +0100170{
Gilles Peskine709346a2017-12-10 23:43:39 +0100171 cat <<EOF
Gilles Peskine92525112018-11-27 18:15:35 +0100172Usage: $0 [OPTION]... [COMPONENT]...
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100173Run mbedtls release validation tests.
Gilles Peskine92525112018-11-27 18:15:35 +0100174By default, run all tests. With one or more COMPONENT, run only those.
Gilles Peskinea28db922019-01-10 00:05:18 +0100175COMPONENT can be the name of a component or a shell wildcard pattern.
176
177Examples:
178 $0 "check_*"
179 Run all sanity checks.
180 $0 --no-armcc --except test_memsan
181 Run everything except builds that require armcc and MemSan.
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100182
183Special options:
184 -h|--help Print this help and exit.
Gilles Peskine878cf602019-01-06 20:50:38 +0000185 --list-all-components List all available test components and exit.
186 --list-components List components supported on this platform and exit.
Gilles Peskine709346a2017-12-10 23:43:39 +0100187
188General options:
189 -f|--force Force the tests to overwrite any modified files.
Gilles Peskine7c652162017-12-11 00:01:40 +0100190 -k|--keep-going Run all tests and report errors at the end.
Gilles Peskine709346a2017-12-10 23:43:39 +0100191 -m|--memory Additional optional memory tests.
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100192 --armcc Run ARM Compiler builds (on by default).
Gilles Peskinea28db922019-01-10 00:05:18 +0100193 --except Exclude the COMPONENTs listed on the command line,
194 instead of running only those.
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100195 --no-armcc Skip ARM Compiler builds.
Gilles Peskine38d81652018-03-21 08:40:26 +0100196 --no-force Refuse to overwrite modified files (default).
197 --no-keep-going Stop at the first error (default).
198 --no-memory No additional memory tests (default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100199 --out-of-source-dir=<path> Directory used for CMake out-of-source build tests.
Gilles Peskine38d81652018-03-21 08:40:26 +0100200 --random-seed Use a random seed value for randomized tests (default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100201 -r|--release-test Run this script in release mode. This fixes the seed value to 1.
202 -s|--seed Integer seed value to use for this test run.
203
204Tool path options:
205 --armc5-bin-dir=<ARMC5_bin_dir_path> ARM Compiler 5 bin directory.
206 --armc6-bin-dir=<ARMC6_bin_dir_path> ARM Compiler 6 bin directory.
207 --gnutls-cli=<GnuTLS_cli_path> GnuTLS client executable to use for most tests.
208 --gnutls-serv=<GnuTLS_serv_path> GnuTLS server executable to use for most tests.
209 --gnutls-legacy-cli=<GnuTLS_cli_path> GnuTLS client executable to use for legacy tests.
210 --gnutls-legacy-serv=<GnuTLS_serv_path> GnuTLS server executable to use for legacy tests.
211 --openssl=<OpenSSL_path> OpenSSL executable to use for most tests.
212 --openssl-legacy=<OpenSSL_path> OpenSSL executable to use for legacy tests e.g. SSLv3.
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100213 --openssl-next=<OpenSSL_path> OpenSSL executable to use for recent things like ARIA
Gilles Peskine709346a2017-12-10 23:43:39 +0100214EOF
SimonB2e23c822016-04-16 21:54:39 +0100215}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100216
217# remove built files as well as the cmake cache/config
218cleanup()
219{
Gilles Peskinea71d64c2018-03-21 12:16:57 +0100220 if [ -n "${MBEDTLS_ROOT_DIR+set}" ]; then
221 cd "$MBEDTLS_ROOT_DIR"
222 fi
223
Gilles Peskine7c652162017-12-11 00:01:40 +0100224 command make clean
Jaeden Ameroed93bdc2018-11-02 16:57:24 +0000225 cd crypto
226 command make clean
227 cd ..
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200228
Gilles Peskine31b07e22018-03-21 12:15:06 +0100229 # Remove CMake artefacts
Jaeden Amero2d0e00f2018-11-07 18:46:41 +0000230 find . -name .git -prune -o \
Gilles Peskine31b07e22018-03-21 12:15:06 +0100231 -iname CMakeFiles -exec rm -rf {} \+ -o \
232 \( -iname cmake_install.cmake -o \
233 -iname CTestTestfile.cmake -o \
234 -iname CMakeCache.txt \) -exec rm {} \+
235 # Recover files overwritten by in-tree CMake builds
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000236 rm -f include/Makefile include/mbedtls/Makefile programs/*/Makefile
Paul Bakkerfe0984d2014-06-13 00:13:45 +0200237 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile
238 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile
Jaeden Ameroed93bdc2018-11-02 16:57:24 +0000239 cd crypto
240 rm -f include/Makefile include/mbedtls/Makefile programs/*/Makefile
241 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile
242 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile
243 cd ..
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200244
Jaeden Ameroab83fdf2019-06-20 17:38:22 +0100245 # Remove any artifacts from the component_test_cmake_as_subdirectory test.
246 rm -rf programs/test/cmake_subproject/build
247 rm -f programs/test/cmake_subproject/Makefile
248 rm -f programs/test/cmake_subproject/cmake_subproject
249
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200250 if [ -f "$CONFIG_BAK" ]; then
251 mv "$CONFIG_BAK" "$CONFIG_H"
252 fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100253}
254
Gilles Peskine7c652162017-12-11 00:01:40 +0100255# Executed on exit. May be redefined depending on command line options.
256final_report () {
257 :
258}
259
260fatal_signal () {
261 cleanup
262 final_report $1
263 trap - $1
264 kill -$1 $$
265}
266
267trap 'fatal_signal HUP' HUP
268trap 'fatal_signal INT' INT
269trap 'fatal_signal TERM' TERM
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200270
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100271msg()
272{
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100273 if [ -n "${current_component:-}" ]; then
274 current_section="${current_component#component_}: $1"
275 else
276 current_section="$1"
277 fi
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100278 echo ""
279 echo "******************************************************************"
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100280 echo "* $current_section "
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000281 printf "* "; date
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100282 echo "******************************************************************"
283}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100284
Gilles Peskine8f073122018-11-27 15:58:47 +0100285armc6_build_test()
286{
287 FLAGS="$1"
Andres AGa5cd9732016-10-17 15:23:10 +0100288
Gilles Peskine8f073122018-11-27 15:58:47 +0100289 msg "build: ARM Compiler 6 ($FLAGS), make"
290 ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \
291 WARNING_CFLAGS='-xc -std=c99' make lib
292 make clean
293}
Andres AGa5cd9732016-10-17 15:23:10 +0100294
Andres AGd9eba4b2016-08-26 14:42:14 +0100295err_msg()
296{
297 echo "$1" >&2
298}
299
300check_tools()
301{
302 for TOOL in "$@"; do
Andres AG98393602017-01-31 17:04:45 +0000303 if ! `type "$TOOL" >/dev/null 2>&1`; then
Andres AGd9eba4b2016-08-26 14:42:14 +0100304 err_msg "$TOOL not found!"
305 exit 1
306 fi
307 done
308}
309
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400310check_headers_in_cpp () {
Peter Kolbus1bc1a4c2019-02-01 17:19:08 -0600311 ls include/mbedtls | grep "\.h$" >headers.txt
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400312 <programs/test/cpp_dummy_build.cpp sed -n 's/"$//; s!^#include "mbedtls/!!p' |
313 sort |
314 diff headers.txt -
315 rm headers.txt
316}
317
Gilles Peskine8f073122018-11-27 15:58:47 +0100318pre_parse_command_line () {
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000319 COMMAND_LINE_COMPONENTS=
Gilles Peskinea28db922019-01-10 00:05:18 +0100320 all_except=0
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000321 no_armcc=
SimonB2e23c822016-04-16 21:54:39 +0100322
Gilles Peskine8f073122018-11-27 15:58:47 +0100323 while [ $# -gt 0 ]; do
Gilles Peskine55f7c942019-01-09 22:28:21 +0100324 case "$1" in
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000325 --armcc) no_armcc=;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100326 --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
327 --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000328 --except) all_except=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100329 --force|-f) FORCE=1;;
330 --gnutls-cli) shift; GNUTLS_CLI="$1";;
331 --gnutls-legacy-cli) shift; GNUTLS_LEGACY_CLI="$1";;
332 --gnutls-legacy-serv) shift; GNUTLS_LEGACY_SERV="$1";;
333 --gnutls-serv) shift; GNUTLS_SERV="$1";;
334 --help|-h) usage; exit;;
335 --keep-going|-k) KEEP_GOING=1;;
Gilles Peskine878cf602019-01-06 20:50:38 +0000336 --list-all-components) printf '%s\n' $ALL_COMPONENTS; exit;;
337 --list-components) printf '%s\n' $SUPPORTED_COMPONENTS; exit;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100338 --memory|-m) MEMORY=1;;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000339 --no-armcc) no_armcc=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100340 --no-force) FORCE=0;;
341 --no-keep-going) KEEP_GOING=0;;
342 --no-memory) MEMORY=0;;
343 --openssl) shift; OPENSSL="$1";;
344 --openssl-legacy) shift; OPENSSL_LEGACY="$1";;
345 --openssl-next) shift; OPENSSL_NEXT="$1";;
346 --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
347 --random-seed) unset SEED;;
348 --release-test|-r) SEED=1;;
349 --seed|-s) shift; SEED="$1";;
350 -*)
351 echo >&2 "Unknown option: $1"
352 echo >&2 "Run $0 --help for usage."
353 exit 120
354 ;;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000355 *) COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS $1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100356 esac
357 shift
Gilles Peskine8f073122018-11-27 15:58:47 +0100358 done
SimonB2e23c822016-04-16 21:54:39 +0100359
Gilles Peskinea28db922019-01-10 00:05:18 +0100360 # With no list of components, run everything.
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000361 if [ -z "$COMMAND_LINE_COMPONENTS" ]; then
362 all_except=1
Andres AGdc192212016-08-31 17:33:13 +0100363 fi
364
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000365 # --no-armcc is a legacy option. The modern way is --except '*_armcc*'.
366 # Ignore it if components are listed explicitly on the command line.
Gilles Peskinea28db922019-01-10 00:05:18 +0100367 if [ -n "$no_armcc" ] && [ $all_except -eq 1 ]; then
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000368 COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS *_armcc*"
SimonB2e23c822016-04-16 21:54:39 +0100369 fi
SimonB2e23c822016-04-16 21:54:39 +0100370
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000371 # Build the list of components to run.
Gilles Peskinea28db922019-01-10 00:05:18 +0100372 RUN_COMPONENTS=
373 for component in $SUPPORTED_COMPONENTS; do
374 if is_component_included "$component"; [ $? -eq $all_except ]; then
375 RUN_COMPONENTS="$RUN_COMPONENTS $component"
376 fi
377 done
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000378
379 unset all_except
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000380 unset no_armcc
Gilles Peskine8f073122018-11-27 15:58:47 +0100381}
SimonB2e23c822016-04-16 21:54:39 +0100382
Gilles Peskine8f073122018-11-27 15:58:47 +0100383pre_check_git () {
384 if [ $FORCE -eq 1 ]; then
Gilles Peskine53190e62019-01-09 23:17:35 +0100385 rm -rf "$OUT_OF_SOURCE_DIR"
Gilles Peskine8f073122018-11-27 15:58:47 +0100386 git checkout-index -f -q $CONFIG_H
387 cleanup
388 else
SimonB2e23c822016-04-16 21:54:39 +0100389
Gilles Peskine8f073122018-11-27 15:58:47 +0100390 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
391 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
392 echo "You can either delete this directory manually, or force the test by rerunning"
393 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
394 exit 1
395 fi
396
Gilles Peskined1174cf2019-01-09 22:30:01 +0100397 if ! git diff --quiet include/mbedtls/config.h; then
Gilles Peskine8f073122018-11-27 15:58:47 +0100398 err_msg "Warning - the configuration file 'include/mbedtls/config.h' has been edited. "
399 echo "You can either delete or preserve your work, or force the test by rerunning the"
400 echo "script as: $0 --force"
401 exit 1
402 fi
SimonB2e23c822016-04-16 21:54:39 +0100403 fi
Andrzej Kureke9c3b812019-02-05 05:34:21 -0500404 if ! [ -f crypto/Makefile ]; then
405 echo "Please initialize the crypto submodule" >&2
406 exit 1
407 fi
Gilles Peskine8f073122018-11-27 15:58:47 +0100408}
SimonB2e23c822016-04-16 21:54:39 +0100409
Andrzej Kurekeb508712019-02-14 07:18:59 -0500410pre_check_seedfile () {
411 if [ ! -f "./tests/seedfile" ]; then
412 dd if=/dev/urandom of=./tests/seedfile bs=32 count=1
413 fi
Jaeden Amero97145102019-03-18 16:31:21 +0000414 if [ ! -f "./crypto/tests/seedfile" ]; then
415 dd if=/dev/urandom of=./crypto/tests/seedfile bs=32 count=1
416 fi
Andrzej Kurekeb508712019-02-14 07:18:59 -0500417}
418
Gilles Peskine8f073122018-11-27 15:58:47 +0100419pre_setup_keep_going () {
Gilles Peskine7c652162017-12-11 00:01:40 +0100420 failure_summary=
421 failure_count=0
422 start_red=
423 end_color=
424 if [ -t 1 ]; then
Gilles Peskine9736b9d2018-01-02 21:54:17 +0100425 case "${TERM:-}" in
Gilles Peskine7c652162017-12-11 00:01:40 +0100426 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
427 start_red=$(printf '\033[31m')
428 end_color=$(printf '\033[0m')
429 ;;
430 esac
431 fi
432 record_status () {
433 if "$@"; then
434 last_status=0
435 else
436 last_status=$?
437 text="$current_section: $* -> $last_status"
438 failure_summary="$failure_summary
439$text"
440 failure_count=$((failure_count + 1))
441 echo "${start_red}^^^^$text^^^^${end_color}"
442 fi
443 }
444 make () {
445 case "$*" in
446 *test|*check)
447 if [ $build_status -eq 0 ]; then
448 record_status command make "$@"
449 else
450 echo "(skipped because the build failed)"
451 fi
452 ;;
453 *)
454 record_status command make "$@"
455 build_status=$last_status
456 ;;
457 esac
458 }
459 final_report () {
460 if [ $failure_count -gt 0 ]; then
461 echo
462 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
463 echo "${start_red}FAILED: $failure_count${end_color}$failure_summary"
464 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Jaeden Amero7c1258d2018-07-20 16:42:14 +0100465 exit 1
Gilles Peskine7c652162017-12-11 00:01:40 +0100466 elif [ -z "${1-}" ]; then
467 echo "SUCCESS :)"
468 fi
469 if [ -n "${1-}" ]; then
470 echo "Killed by SIG$1."
471 fi
472 }
Gilles Peskine8f073122018-11-27 15:58:47 +0100473}
474
Gilles Peskine7c652162017-12-11 00:01:40 +0100475if_build_succeeded () {
476 if [ $build_status -eq 0 ]; then
477 record_status "$@"
478 fi
479}
480
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200481# to be used instead of ! for commands run with
482# record_status or if_build_succeeded
483not() {
484 ! "$@"
485}
486
Gilles Peskine8f073122018-11-27 15:58:47 +0100487pre_print_configuration () {
488 msg "info: $0 configuration"
489 echo "MEMORY: $MEMORY"
490 echo "FORCE: $FORCE"
491 echo "SEED: ${SEED-"UNSET"}"
492 echo "OPENSSL: $OPENSSL"
493 echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
494 echo "OPENSSL_NEXT: $OPENSSL_NEXT"
495 echo "GNUTLS_CLI: $GNUTLS_CLI"
496 echo "GNUTLS_SERV: $GNUTLS_SERV"
497 echo "GNUTLS_LEGACY_CLI: $GNUTLS_LEGACY_CLI"
498 echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV"
499 echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
500 echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
501}
Andres AG7770ea82016-10-10 15:46:20 +0100502
Andres AGd9eba4b2016-08-26 14:42:14 +0100503# Make sure the tools we need are available.
Gilles Peskine8f073122018-11-27 15:58:47 +0100504pre_check_tools () {
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000505 # Build the list of variables to pass to output_env.sh.
506 set env
SimonB2e23c822016-04-16 21:54:39 +0100507
Gilles Peskine87964262019-01-06 22:40:00 +0000508 case " $RUN_COMPONENTS " in
509 # Require OpenSSL and GnuTLS if running any tests (as opposed to
510 # only doing builds). Not all tests run OpenSSL and GnuTLS, but this
511 # is a good enough approximation in practice.
512 *" test_"*)
513 # To avoid setting OpenSSL and GnuTLS for each call to compat.sh
514 # and ssl-opt.sh, we just export the variables they require.
515 export OPENSSL_CMD="$OPENSSL"
516 export GNUTLS_CLI="$GNUTLS_CLI"
517 export GNUTLS_SERV="$GNUTLS_SERV"
518 # Avoid passing --seed flag in every call to ssl-opt.sh
519 if [ -n "${SEED-}" ]; then
520 export SEED
521 fi
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000522 set "$@" OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY"
523 set "$@" GNUTLS_CLI="$GNUTLS_CLI" GNUTLS_SERV="$GNUTLS_SERV"
524 set "$@" GNUTLS_LEGACY_CLI="$GNUTLS_LEGACY_CLI"
525 set "$@" GNUTLS_LEGACY_SERV="$GNUTLS_LEGACY_SERV"
Gilles Peskine87964262019-01-06 22:40:00 +0000526 check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$OPENSSL_NEXT" \
527 "$GNUTLS_CLI" "$GNUTLS_SERV" \
528 "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV"
529 ;;
530 esac
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200531
Gilles Peskine87964262019-01-06 22:40:00 +0000532 case " $RUN_COMPONENTS " in
533 *_doxygen[_\ ]*) check_tools "doxygen" "dot";;
534 esac
Andres AGd9eba4b2016-08-26 14:42:14 +0100535
Gilles Peskine87964262019-01-06 22:40:00 +0000536 case " $RUN_COMPONENTS " in
537 *_arm_none_eabi_gcc[_\ ]*) check_tools "arm-none-eabi-gcc";;
538 esac
Andres AGd9eba4b2016-08-26 14:42:14 +0100539
Gilles Peskine87964262019-01-06 22:40:00 +0000540 case " $RUN_COMPONENTS " in
541 *_mingw[_\ ]*) check_tools "i686-w64-mingw32-gcc";;
542 esac
543
544 case " $RUN_COMPONENTS " in
545 *" test_zeroize "*) check_tools "gdb";;
546 esac
547
548 case " $RUN_COMPONENTS " in
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000549 *_armcc*)
Gilles Peskine87964262019-01-06 22:40:00 +0000550 ARMC5_CC="$ARMC5_BIN_DIR/armcc"
551 ARMC5_AR="$ARMC5_BIN_DIR/armar"
552 ARMC6_CC="$ARMC6_BIN_DIR/armclang"
553 ARMC6_AR="$ARMC6_BIN_DIR/armar"
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000554 check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC6_CC" "$ARMC6_AR";;
555 esac
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000556
557 msg "info: output_env.sh"
558 case $RUN_COMPONENTS in
559 *_armcc*)
560 set "$@" ARMC5_CC="$ARMC5_CC" ARMC6_CC="$ARMC6_CC" RUN_ARMCC=1;;
561 *) set "$@" RUN_ARMCC=0;;
562 esac
563 "$@" scripts/output_env.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100564}
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100565
Gilles Peskine192c72f2017-12-21 15:59:21 +0100566
567
568################################################################
569#### Basic checks
570################################################################
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100571
572#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200573# Test Suites to be executed
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100574#
Manuel Pégourié-Gonnard3d404b42015-07-08 21:59:16 +0100575# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200576# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100577# and/or are more likely to fail than others (eg I use Clang most of the
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200578# time, so start with a GCC build).
579# 2. Minimize total running time, by avoiding useless rebuilds
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100580#
Manuel Pégourié-Gonnard259b08a2016-01-08 16:27:41 +0100581# Indicative running times are given for reference.
582
Gilles Peskine8f073122018-11-27 15:58:47 +0100583component_check_recursion () {
584 msg "test: recursion.pl" # < 1s
585 record_status tests/scripts/recursion.pl library/*.c
586}
Janos Follathb72c6782016-07-19 14:54:17 +0100587
Gilles Peskine8f073122018-11-27 15:58:47 +0100588component_check_generated_files () {
589 msg "test: freshness of generated source files" # < 1s
590 record_status tests/scripts/check-generated-files.sh
591}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200592
Gilles Peskine8f073122018-11-27 15:58:47 +0100593component_check_doxy_blocks () {
594 msg "test: doxygen markup outside doxygen blocks" # < 1s
595 record_status tests/scripts/check-doxy-blocks.pl
596}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200597
Gilles Peskine8f073122018-11-27 15:58:47 +0100598component_check_files () {
599 msg "test: check-files.py" # < 1s
Gilles Peskine8f073122018-11-27 15:58:47 +0100600 record_status tests/scripts/check-files.py
601}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200602
Gilles Peskine8f073122018-11-27 15:58:47 +0100603component_check_names () {
604 msg "test/build: declared and exported names" # < 3s
Gilles Peskine13f97dc2019-05-15 17:52:22 +0200605 record_status tests/scripts/check-names.sh -v
Gilles Peskine8f073122018-11-27 15:58:47 +0100606}
Darryl Greena07039c2018-03-13 16:48:16 +0000607
Gilles Peskine8f073122018-11-27 15:58:47 +0100608component_check_doxygen_warnings () {
609 msg "test: doxygen warnings" # ~ 3s
Gilles Peskine8f073122018-11-27 15:58:47 +0100610 record_status tests/scripts/doxygen.sh
611}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200612
Gilles Peskine192c72f2017-12-21 15:59:21 +0100613
614
615################################################################
616#### Build and test many configurations and targets
617################################################################
618
Gilles Peskine7832c9f2019-04-08 17:00:15 +0200619component_test_default_out_of_box () {
620 msg "build: make, default config (out-of-box)" # ~1min
621 make
622
623 msg "test: main suites make, default config (out-of-box)" # ~10s
624 make test
625
626 msg "selftest: make, default config (out-of-box)" # ~10s
627 programs/test/selftest
628}
629
Gilles Peskine8f073122018-11-27 15:58:47 +0100630component_test_default_cmake_gcc_asan () {
631 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100632 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
633 make
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200634
Gilles Peskine8f073122018-11-27 15:58:47 +0100635 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
636 make test
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200637
Gilles Peskine8f073122018-11-27 15:58:47 +0100638 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
639 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200640
Gilles Peskine8f073122018-11-27 15:58:47 +0100641 msg "test: compat.sh (ASan build)" # ~ 6 min
642 if_build_succeeded tests/compat.sh
643}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200644
Gilles Peskine782f4112018-11-27 16:11:09 +0100645component_test_ref_configs () {
646 msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
647 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
648 record_status tests/scripts/test-ref-configs.pl
649}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200650
Gilles Peskine8f073122018-11-27 15:58:47 +0100651component_test_sslv3 () {
652 msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100653 scripts/config.pl set MBEDTLS_SSL_PROTO_SSL3
654 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
655 make
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200656
Gilles Peskine8f073122018-11-27 15:58:47 +0100657 msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
658 make test
Simon Butcher3ea7f522016-03-07 23:22:10 +0000659
Gilles Peskine8f073122018-11-27 15:58:47 +0100660 msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
661 if_build_succeeded tests/compat.sh -m 'tls1 tls1_1 tls1_2 dtls1 dtls1_2'
662 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
Simon Butcher3ea7f522016-03-07 23:22:10 +0000663
Gilles Peskine8f073122018-11-27 15:58:47 +0100664 msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
665 if_build_succeeded tests/ssl-opt.sh
666}
Simon Butcher3ea7f522016-03-07 23:22:10 +0000667
Gilles Peskine8f073122018-11-27 15:58:47 +0100668component_test_no_renegotiation () {
669 msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100670 scripts/config.pl unset MBEDTLS_SSL_RENEGOTIATION
671 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
672 make
Simon Butcher3ea7f522016-03-07 23:22:10 +0000673
Gilles Peskine8f073122018-11-27 15:58:47 +0100674 msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
675 make test
Hanno Becker134c2ab2017-10-12 15:29:50 +0100676
Gilles Peskine8f073122018-11-27 15:58:47 +0100677 msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
678 if_build_succeeded tests/ssl-opt.sh
679}
Hanno Becker134c2ab2017-10-12 15:29:50 +0100680
Hanno Beckera545be22019-05-10 14:45:37 +0100681component_test_no_pem_no_fs () {
682 msg "build: Default + !MBEDTLS_PEM_PARSE_C + !MBEDTLS_FS_IO (ASan build)"
683 scripts/config.pl unset MBEDTLS_PEM_PARSE_C
684 scripts/config.pl unset MBEDTLS_FS_IO
685 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
686 make
687
688 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - main suites (inc. selftests) (ASan build)" # ~ 50s
689 make test
690
691 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - ssl-opt.sh (ASan build)" # ~ 6 min
692 if_build_succeeded tests/ssl-opt.sh
693}
694
Gilles Peskine8f073122018-11-27 15:58:47 +0100695component_test_rsa_no_crt () {
696 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100697 scripts/config.pl set MBEDTLS_RSA_NO_CRT
698 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
699 make
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +0100700
Gilles Peskine8f073122018-11-27 15:58:47 +0100701 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
702 make test
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100703
Gilles Peskine8f073122018-11-27 15:58:47 +0100704 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
705 if_build_succeeded tests/ssl-opt.sh -f RSA
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100706
Gilles Peskine8f073122018-11-27 15:58:47 +0100707 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
708 if_build_succeeded tests/compat.sh -t RSA
709}
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100710
Gilles Peskine8f073122018-11-27 15:58:47 +0100711component_test_small_ssl_out_content_len () {
712 msg "build: small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100713 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 16384
714 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
715 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
716 make
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100717
Gilles Peskine8f073122018-11-27 15:58:47 +0100718 msg "test: small SSL_OUT_CONTENT_LEN - ssl-opt.sh MFL and large packet tests"
719 if_build_succeeded tests/ssl-opt.sh -f "Max fragment\|Large packet"
720}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000721
Gilles Peskine8f073122018-11-27 15:58:47 +0100722component_test_small_ssl_in_content_len () {
723 msg "build: small SSL_IN_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100724 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 4096
725 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 16384
726 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
727 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000728
Gilles Peskine8f073122018-11-27 15:58:47 +0100729 msg "test: small SSL_IN_CONTENT_LEN - ssl-opt.sh MFL tests"
730 if_build_succeeded tests/ssl-opt.sh -f "Max fragment"
731}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000732
Gilles Peskine8f073122018-11-27 15:58:47 +0100733component_test_small_ssl_dtls_max_buffering () {
734 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0"
Gilles Peskine8f073122018-11-27 15:58:47 +0100735 scripts/config.pl set MBEDTLS_SSL_DTLS_MAX_BUFFERING 1000
736 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
737 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000738
Gilles Peskine8f073122018-11-27 15:58:47 +0100739 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0 - ssl-opt.sh specific reordering test"
740 if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer out-of-order hs msg before reassembling next, free buffered msg"
741}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100742
Gilles Peskine8f073122018-11-27 15:58:47 +0100743component_test_small_mbedtls_ssl_dtls_max_buffering () {
744 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1"
Gilles Peskine8f073122018-11-27 15:58:47 +0100745 scripts/config.pl set MBEDTLS_SSL_DTLS_MAX_BUFFERING 240
746 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
747 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100748
Gilles Peskine8f073122018-11-27 15:58:47 +0100749 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1 - ssl-opt.sh specific reordering test"
750 if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer encrypted Finished message, drop for fragmented NewSessionTicket"
751}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100752
Gilles Peskine8f073122018-11-27 15:58:47 +0100753component_test_full_cmake_clang () {
754 msg "build: cmake, full config, clang" # ~ 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100755 scripts/config.pl full
756 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
757 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check -D ENABLE_TESTING=On .
758 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100759
Gilles Peskine8f073122018-11-27 15:58:47 +0100760 msg "test: main suites (full config)" # ~ 5s
761 make test
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100762
Gilles Peskine8f073122018-11-27 15:58:47 +0100763 msg "test: ssl-opt.sh default, ECJPAKE, SSL async (full config)" # ~ 1s
764 if_build_succeeded tests/ssl-opt.sh -f 'Default\|ECJPAKE\|SSL async private'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200765
Andres Amaya Garcia2dadab72019-01-08 21:42:27 +0000766 msg "test: compat.sh RC4, DES, 3DES & NULL (full config)" # ~ 2 min
Andres Amaya Garcia419bd002019-02-19 20:20:57 +0000767 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" GNUTLS_CLI="$GNUTLS_LEGACY_CLI" GNUTLS_SERV="$GNUTLS_LEGACY_SERV" tests/compat.sh -e '^$' -f 'NULL\|DES\|RC4\|ARCFOUR'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200768
Gilles Peskine8f073122018-11-27 15:58:47 +0100769 msg "test: compat.sh ARIA + ChachaPoly"
770 if_build_succeeded env OPENSSL_CMD="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
771}
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200772
Gilles Peskine8f073122018-11-27 15:58:47 +0100773component_build_deprecated () {
774 msg "build: make, full config + DEPRECATED_WARNING, gcc -O" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100775 scripts/config.pl full
776 scripts/config.pl set MBEDTLS_DEPRECATED_WARNING
777 # Build with -O -Wextra to catch a maximum of issues.
778 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra' lib programs
779 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100780
Gilles Peskine8f073122018-11-27 15:58:47 +0100781 msg "build: make, full config + DEPRECATED_REMOVED, clang -O" # ~ 30s
782 # No cleanup, just tweak the configuration and rebuild
783 make clean
784 scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
785 scripts/config.pl set MBEDTLS_DEPRECATED_REMOVED
786 # Build with -O -Wextra to catch a maximum of issues.
787 make CC=clang CFLAGS='-O -Werror -Wall -Wextra' lib programs
788 make CC=clang CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
789}
Jaeden Ameroed93bdc2018-11-02 16:57:24 +0000790
Gilles Peskine8f073122018-11-27 15:58:47 +0100791component_test_depends_curves () {
792 msg "test/build: curves.pl (gcc)" # ~ 4 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100793 record_status tests/scripts/curves.pl
794}
Jaeden Ameroacaabe72018-11-07 11:52:52 +0000795
Gilles Peskine8f073122018-11-27 15:58:47 +0100796component_test_depends_hashes () {
797 msg "test/build: depends-hashes.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100798 record_status tests/scripts/depends-hashes.pl
799}
Jaeden Ameroacaabe72018-11-07 11:52:52 +0000800
Gilles Peskine8f073122018-11-27 15:58:47 +0100801component_test_depends_pkalgs () {
802 msg "test/build: depends-pkalgs.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100803 record_status tests/scripts/depends-pkalgs.pl
804}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100805
Gilles Peskine8f073122018-11-27 15:58:47 +0100806component_build_key_exchanges () {
807 msg "test/build: key-exchanges (gcc)" # ~ 1 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100808 record_status tests/scripts/key-exchanges.pl
809}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100810
Gilles Peskine8f073122018-11-27 15:58:47 +0100811component_build_default_make_gcc_and_cxx () {
812 msg "build: Unix make, -Os (gcc)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100813 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100814
Gilles Peskine8f073122018-11-27 15:58:47 +0100815 msg "test: verify header list in cpp_dummy_build.cpp"
816 record_status check_headers_in_cpp
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100817
Gilles Peskine8f073122018-11-27 15:58:47 +0100818 msg "build: Unix make, incremental g++"
819 make TEST_CPP=1
820}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100821
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100822component_test_no_use_psa_crypto_full_cmake_asan() {
823 # full minus MBEDTLS_USE_PSA_CRYPTO: run the same set of tests as basic-build-test.sh
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500824 msg "build: cmake, full config + MBEDTLS_USE_PSA_CRYPTO, ASan"
825 scripts/config.pl full
826 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
Hanno Becker241b5242019-02-22 10:26:18 +0000827 scripts/config.pl unset MBEDTLS_ECP_RESTARTABLE # restartable ECC not supported through PSA
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500828 scripts/config.pl set MBEDTLS_PSA_CRYPTO_C
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100829 scripts/config.pl unset MBEDTLS_USE_PSA_CRYPTO
830 scripts/config.pl unset MBEDTLS_PSA_ITS_FILE_C
Andrzej Kurek324b2f72019-04-18 08:59:12 -0400831 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_C
Manuel Pégourié-Gonnardd8167e82019-02-01 11:12:52 +0100832 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500833 make
Manuel Pégourié-Gonnard43be6cd2017-06-20 09:53:42 +0200834
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100835 msg "test: main suites (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500836 make test
Manuel Pégourié-Gonnard503a5ef2015-10-23 09:04:45 +0200837
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100838 msg "test: ssl-opt.sh (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500839 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100840
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100841 msg "test: compat.sh default (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500842 if_build_succeeded tests/compat.sh
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400843
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100844 msg "test: compat.sh ssl3 (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500845 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400846
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100847 msg "test: compat.sh RC4, DES & NULL (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500848 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'
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500849
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100850 msg "test: compat.sh ARIA + ChachaPoly (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500851 if_build_succeeded env OPENSSL_CMD="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
852}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500853
Gilles Peskineadcde5e2019-06-12 16:05:50 +0200854component_test_check_params_functionality () {
855 msg "build+test: MBEDTLS_CHECK_PARAMS functionality"
856 scripts/config.pl full # includes CHECK_PARAMS
857 # Make MBEDTLS_PARAM_FAILED call mbedtls_param_failed().
858 scripts/config.pl unset MBEDTLS_CHECK_PARAMS_ASSERT
859 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
860 # Only build and run tests. Do not build sample programs, because
861 # they don't have a mbedtls_param_failed() function.
862 make CC=gcc CFLAGS='-Werror -O1' lib test
863}
864
Gilles Peskineb28636b2019-01-02 19:06:24 +0100865component_test_check_params_without_platform () {
866 msg "build+test: MBEDTLS_CHECK_PARAMS without MBEDTLS_PLATFORM_C"
867 scripts/config.pl full # includes CHECK_PARAMS
Gilles Peskineadcde5e2019-06-12 16:05:50 +0200868 # Keep MBEDTLS_PARAM_FAILED as assert.
Gilles Peskineb28636b2019-01-02 19:06:24 +0100869 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
870 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
871 scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
872 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
873 scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
874 scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
875 scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
876 scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
877 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
878 scripts/config.pl unset MBEDTLS_PLATFORM_C
879 make CC=gcc CFLAGS='-Werror -O1' all test
880}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500881
Gilles Peskineb28636b2019-01-02 19:06:24 +0100882component_test_check_params_silent () {
883 msg "build+test: MBEDTLS_CHECK_PARAMS with alternative MBEDTLS_PARAM_FAILED()"
884 scripts/config.pl full # includes CHECK_PARAMS
885 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
Gilles Peskineadcde5e2019-06-12 16:05:50 +0200886 # Set MBEDTLS_PARAM_FAILED to nothing.
Gilles Peskineb28636b2019-01-02 19:06:24 +0100887 sed -i 's/.*\(#define MBEDTLS_PARAM_FAILED( cond )\).*/\1/' "$CONFIG_H"
888 make CC=gcc CFLAGS='-Werror -O1' all test
889}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500890
Gilles Peskine8f073122018-11-27 15:58:47 +0100891component_test_no_platform () {
892 # Full configuration build, without platform support, file IO and net sockets.
893 # This should catch missing mbedtls_printf definitions, and by disabling file
894 # IO, it should catch missing '#include <stdio.h>'
895 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100896 scripts/config.pl full
897 scripts/config.pl unset MBEDTLS_PLATFORM_C
898 scripts/config.pl unset MBEDTLS_NET_C
899 scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
900 scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
901 scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
902 scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
903 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
904 scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
905 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
906 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
907 scripts/config.pl unset MBEDTLS_FS_IO
Andrzej Kurek73757082019-04-18 04:14:37 -0400908 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_C
909 scripts/config.pl unset MBEDTLS_PSA_ITS_FILE_C
Gilles Peskine8f073122018-11-27 15:58:47 +0100910 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
911 # to re-enable platform integration features otherwise disabled in C99 builds
912 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -O0 -D_DEFAULT_SOURCE' lib programs
913 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0' test
914}
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +0000915
Gilles Peskine8f073122018-11-27 15:58:47 +0100916component_build_no_std_function () {
917 # catch compile bugs in _uninit functions
918 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100919 scripts/config.pl full
920 scripts/config.pl set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
921 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
922 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
923}
Manuel Pégourié-Gonnarddccb80b2015-06-03 10:20:33 +0100924
Gilles Peskine8f073122018-11-27 15:58:47 +0100925component_build_no_ssl_srv () {
926 msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100927 scripts/config.pl full
928 scripts/config.pl unset MBEDTLS_SSL_SRV_C
929 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
930}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200931
Gilles Peskine8f073122018-11-27 15:58:47 +0100932component_build_no_ssl_cli () {
933 msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100934 scripts/config.pl full
935 scripts/config.pl unset MBEDTLS_SSL_CLI_C
936 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
937}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200938
Gilles Peskine8f073122018-11-27 15:58:47 +0100939component_build_no_sockets () {
940 # Note, C99 compliance can also be tested with the sockets support disabled,
941 # as that requires a POSIX platform (which isn't the same as C99).
942 msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100943 scripts/config.pl full
944 scripts/config.pl unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
945 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
946 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0 -std=c99 -pedantic' lib
947}
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +0200948
Gilles Peskine8f073122018-11-27 15:58:47 +0100949component_test_no_max_fragment_length () {
950 # Run max fragment length tests with MFL disabled
951 msg "build: default config except MFL extension (ASan build)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100952 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
953 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
954 make
Hanno Becker5175ac62017-09-18 15:36:25 +0100955
Gilles Peskine8f073122018-11-27 15:58:47 +0100956 msg "test: ssl-opt.sh, MFL-related tests"
957 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length"
958}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000959
Hanno Becker545ced42019-02-19 11:10:48 +0000960component_test_asan_remove_peer_certificate () {
961 msg "build: default config with MBEDTLS_SSL_KEEP_PEER_CERTIFICATE disabled (ASan build)"
962 scripts/config.pl unset MBEDTLS_SSL_KEEP_PEER_CERTIFICATE
963 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
964 make
965
966 msg "test: !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
967 make test
968
969 msg "test: ssl-opt.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
970 if_build_succeeded tests/ssl-opt.sh
971
972 msg "test: compat.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
973 if_build_succeeded tests/compat.sh
974}
975
Gilles Peskine8f073122018-11-27 15:58:47 +0100976component_test_no_max_fragment_length_small_ssl_out_content_len () {
977 msg "build: no MFL extension, small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100978 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
979 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 16384
980 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
981 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
982 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000983
Gilles Peskine8f073122018-11-27 15:58:47 +0100984 msg "test: MFL tests (disabled MFL extension case) & large packet tests"
985 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length\|Large buffer"
986}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000987
Jaeden Amero2de07f12019-06-05 13:32:08 +0100988component_test_when_no_ciphersuites_have_mac () {
989 msg "build: when no ciphersuites have MAC"
990 scripts/config.pl unset MBEDTLS_CIPHER_NULL_CIPHER
991 scripts/config.pl unset MBEDTLS_ARC4_C
992 scripts/config.pl unset MBEDTLS_CIPHER_MODE_CBC
993 make
994
995 msg "test: !MBEDTLS_SSL_SOME_MODES_USE_MAC"
996 make test
997
998 msg "test ssl-opt.sh: !MBEDTLS_SSL_SOME_MODES_USE_MAC"
Jaeden Amero6b1683d2019-06-05 14:42:50 +0100999 if_build_succeeded tests/ssl-opt.sh -f 'Default\|EtM' -e 'without EtM'
Jaeden Amero2de07f12019-06-05 13:32:08 +01001000}
1001
Gilles Peskine8f073122018-11-27 15:58:47 +01001002component_test_null_entropy () {
1003 msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +01001004 scripts/config.pl set MBEDTLS_TEST_NULL_ENTROPY
1005 scripts/config.pl set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
1006 scripts/config.pl set MBEDTLS_ENTROPY_C
1007 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
1008 scripts/config.pl unset MBEDTLS_ENTROPY_HARDWARE_ALT
1009 scripts/config.pl unset MBEDTLS_HAVEGE_C
Gilles Peskine5fa32a72019-01-06 19:48:30 +00001010 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan -D UNSAFE_BUILD=ON .
Gilles Peskine8f073122018-11-27 15:58:47 +01001011 make
Janos Follath06c54002016-06-09 13:57:40 +01001012
Gilles Peskine8f073122018-11-27 15:58:47 +01001013 msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)"
1014 make test
1015}
Janos Follath06c54002016-06-09 13:57:40 +01001016
Gilles Peskine8f073122018-11-27 15:58:47 +01001017component_test_platform_calloc_macro () {
1018 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +01001019 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
1020 scripts/config.pl set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
1021 scripts/config.pl set MBEDTLS_PLATFORM_FREE_MACRO free
1022 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1023 make
Hanno Beckere5fecec2018-10-11 11:02:52 +01001024
Gilles Peskine8f073122018-11-27 15:58:47 +01001025 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
1026 make test
1027}
Hanno Beckere5fecec2018-10-11 11:02:52 +01001028
Gilles Peskine8f073122018-11-27 15:58:47 +01001029component_test_make_shared () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001030 msg "build/test: make shared" # ~ 40s
Andrzej Kurek87615772019-04-19 15:03:58 -04001031 make SHARED=1 all check -j1
Gilles Peskine8f073122018-11-27 15:58:47 +01001032}
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +02001033
Gilles Peskine8f073122018-11-27 15:58:47 +01001034component_test_m32_o0 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001035 # Build once with -O0, to compile out the i386 specific inline assembly
1036 msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
Simon Butcher7a6da6e2018-06-27 21:52:54 +01001037 scripts/config.pl full
Gilles Peskine5d26e7c2019-06-07 14:50:09 +02001038 make CC=gcc CFLAGS='-O0 -Werror -Wall -Wextra -m32 -fsanitize=address' LDFLAGS='-m32'
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01001039
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001040 msg "test: i386, make, gcc -O0 (ASan build)"
1041 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01001042}
Gilles Peskine878cf602019-01-06 20:50:38 +00001043support_test_m32_o0 () {
1044 case $(uname -m) in
1045 *64*) true;;
1046 *) false;;
1047 esac
1048}
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001049
Gilles Peskine8f073122018-11-27 15:58:47 +01001050component_test_m32_o1 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001051 # Build again with -O1, to compile in the i386 specific inline assembly
1052 msg "build: i386, make, gcc -O1 (ASan build)" # ~ 30s
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001053 scripts/config.pl full
Gilles Peskine4b317612019-04-08 16:58:02 +02001054 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE
1055 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
1056 scripts/config.pl unset MBEDTLS_MEMORY_DEBUG
Gilles Peskine5d26e7c2019-06-07 14:50:09 +02001057 make CC=gcc CFLAGS='-O1 -Werror -Wall -Wextra -m32 -fsanitize=address' LDFLAGS='-m32'
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001058
1059 msg "test: i386, make, gcc -O1 (ASan build)"
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001060 make test
Gilles Peskine4b317612019-04-08 16:58:02 +02001061
1062 msg "test ssl-opt.sh, i386, make, gcc-O1"
1063 if_build_succeeded tests/ssl-opt.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01001064}
Gilles Peskine878cf602019-01-06 20:50:38 +00001065support_test_m32_o1 () {
1066 support_test_m32_o0 "$@"
1067}
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001068
Gilles Peskine8f073122018-11-27 15:58:47 +01001069component_test_mx32 () {
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001070 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
Simon Butcher7a6da6e2018-06-27 21:52:54 +01001071 scripts/config.pl full
Gilles Peskine5d26e7c2019-06-07 14:50:09 +02001072 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32' LDFLAGS='-mx32'
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001073
1074 msg "test: 64-bit ILP32, make, gcc"
1075 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01001076}
Gilles Peskine878cf602019-01-06 20:50:38 +00001077support_test_mx32 () {
1078 case $(uname -m) in
1079 amd64|x86_64) true;;
1080 *) false;;
1081 esac
1082}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001083
Gilles Peskine8f073122018-11-27 15:58:47 +01001084component_build_arm_none_eabi_gcc () {
1085 msg "build: arm-none-eabi-gcc, make" # ~ 10s
Manuel Pégourié-Gonnarddf2bfcf2019-04-29 12:44:12 +02001086 scripts/config.pl baremetal
Gilles Peskine8f073122018-11-27 15:58:47 +01001087 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
1088}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001089
Gilles Peskine8f073122018-11-27 15:58:47 +01001090component_build_arm_none_eabi_gcc_no_udbl_division () {
1091 msg "build: arm-none-eabi-gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
Manuel Pégourié-Gonnarddf2bfcf2019-04-29 12:44:12 +02001092 scripts/config.pl baremetal
Gilles Peskine8f073122018-11-27 15:58:47 +01001093 scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
1094 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
1095 echo "Checking that software 64-bit division is not required"
1096 if_build_succeeded not grep __aeabi_uldiv library/*.o
1097}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001098
Gilles Peskine8f073122018-11-27 15:58:47 +01001099component_build_arm_none_eabi_gcc_no_64bit_multiplication () {
1100 msg "build: arm-none-eabi-gcc MBEDTLS_NO_64BIT_MULTIPLICATION, make" # ~ 10s
Manuel Pégourié-Gonnarddf2bfcf2019-04-29 12:44:12 +02001101 scripts/config.pl baremetal
Gilles Peskine8f073122018-11-27 15:58:47 +01001102 scripts/config.pl set MBEDTLS_NO_64BIT_MULTIPLICATION
1103 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -O1 -march=armv6-m -mthumb' lib
1104 echo "Checking that software 64-bit multiplication is not required"
1105 if_build_succeeded not grep __aeabi_lmul library/*.o
1106}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001107
Gilles Peskine8f073122018-11-27 15:58:47 +01001108component_build_armcc () {
1109 msg "build: ARM Compiler 5, make"
Manuel Pégourié-Gonnarddf2bfcf2019-04-29 12:44:12 +02001110 scripts/config.pl baremetal
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001111
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001112 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
1113 make clean
Andres AG87bb5772016-09-27 15:05:15 +01001114
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001115 # ARM Compiler 6 - Target ARMv7-A
1116 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-a"
Simon Butcher940737f2017-07-23 13:42:36 +02001117
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001118 # ARM Compiler 6 - Target ARMv7-M
1119 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m"
Simon Butcher940737f2017-07-23 13:42:36 +02001120
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001121 # ARM Compiler 6 - Target ARMv8-A - AArch32
1122 armc6_build_test "--target=arm-arm-none-eabi -march=armv8.2-a"
Simon Butcher940737f2017-07-23 13:42:36 +02001123
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001124 # ARM Compiler 6 - Target ARMv8-M
1125 armc6_build_test "--target=arm-arm-none-eabi -march=armv8-m.main"
Simon Butcher940737f2017-07-23 13:42:36 +02001126
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001127 # ARM Compiler 6 - Target ARMv8-A - AArch64
1128 armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a"
Gilles Peskine8f073122018-11-27 15:58:47 +01001129}
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +01001130
Gilles Peskine8f073122018-11-27 15:58:47 +01001131component_test_allow_sha1 () {
1132 msg "build: allow SHA1 in certificates by default"
Gilles Peskine8f073122018-11-27 15:58:47 +01001133 scripts/config.pl set MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
1134 make CFLAGS='-Werror -Wall -Wextra'
1135 msg "test: allow SHA1 in certificates by default"
1136 make test
1137 if_build_succeeded tests/ssl-opt.sh -f SHA-1
1138}
Gilles Peskine2a458da2017-05-12 15:26:58 +02001139
Gilles Peskine8f073122018-11-27 15:58:47 +01001140component_build_mingw () {
1141 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
Andrzej Kurek62faadd2019-04-19 20:10:21 -04001142 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 -j1
Hanno Beckere963efa2018-01-03 10:03:43 +00001143
Gilles Peskine8f073122018-11-27 15:58:47 +01001144 # note Make tests only builds the tests, but doesn't run them
Andrzej Kurek62faadd2019-04-19 20:10:21 -04001145 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror' WINDOWS_BUILD=1 tests -j1
Gilles Peskine8f073122018-11-27 15:58:47 +01001146 make WINDOWS_BUILD=1 clean
Simon Butcher002bc622016-11-17 09:27:45 +00001147
Gilles Peskine8f073122018-11-27 15:58:47 +01001148 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
Andrzej Kurek87615772019-04-19 15:03:58 -04001149 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 -j1
1150 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 -j1
Gilles Peskine8f073122018-11-27 15:58:47 +01001151 make WINDOWS_BUILD=1 clean
1152}
Jaeden Amero117b8a42019-04-17 15:19:26 +01001153support_build_mingw() {
1154 case $(i686-w64-mingw32-gcc -dumpversion) in
1155 [0-5]*) false;;
1156 *) true;;
1157 esac
1158}
Manuel Pégourié-Gonnard6448bce2015-02-16 17:18:36 +01001159
Gilles Peskine8f073122018-11-27 15:58:47 +01001160component_test_memsan () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001161 msg "build: MSan (clang)" # ~ 1 min 20s
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001162 scripts/config.pl unset MBEDTLS_AESNI_C # memsan doesn't grok asm
1163 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
1164 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +02001165
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001166 msg "test: main suites (MSan)" # ~ 10s
1167 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001168
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001169 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
Gilles Peskine7c652162017-12-11 00:01:40 +01001170 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001171
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001172 # Optional part(s)
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001173
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001174 if [ "$MEMORY" -gt 0 ]; then
1175 msg "test: compat.sh (MSan)" # ~ 6 min 20s
Gilles Peskine7c652162017-12-11 00:01:40 +01001176 if_build_succeeded tests/compat.sh
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001177 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001178}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001179
Gilles Peskine69f190e2019-01-10 00:11:42 +01001180component_test_valgrind () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001181 msg "build: Release (clang)"
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001182 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
1183 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001184
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001185 msg "test: main suites valgrind (Release)"
1186 make memcheck
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001187
Gilles Peskinef1349e42019-04-08 17:00:56 +02001188 # Optional parts (slow; currently broken on OS X because programs don't
1189 # seem to receive signals under valgrind on OS X).
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001190 if [ "$MEMORY" -gt 0 ]; then
1191 msg "test: ssl-opt.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +01001192 if_build_succeeded tests/ssl-opt.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001193 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001194
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001195 if [ "$MEMORY" -gt 1 ]; then
1196 msg "test: compat.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +01001197 if_build_succeeded tests/compat.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001198 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001199}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001200
Gilles Peskine8f073122018-11-27 15:58:47 +01001201component_test_cmake_out_of_source () {
1202 msg "build: cmake 'out-of-source' build"
Gilles Peskine8f073122018-11-27 15:58:47 +01001203 MBEDTLS_ROOT_DIR="$PWD"
1204 mkdir "$OUT_OF_SOURCE_DIR"
1205 cd "$OUT_OF_SOURCE_DIR"
1206 cmake "$MBEDTLS_ROOT_DIR"
1207 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001208
Gilles Peskine8f073122018-11-27 15:58:47 +01001209 msg "test: cmake 'out-of-source' build"
1210 make test
1211 # Test an SSL option that requires an auxiliary script in test/scripts/.
1212 # Also ensure that there are no error messages such as
1213 # "No such file or directory", which would indicate that some required
1214 # file is missing (ssl-opt.sh tolerates the absence of some files so
1215 # may exit with status 0 but emit errors).
1216 if_build_succeeded ./tests/ssl-opt.sh -f 'Fallback SCSV: beginning of list' 2>ssl-opt.err
1217 if [ -s ssl-opt.err ]; then
1218 cat ssl-opt.err >&2
1219 record_status [ ! -s ssl-opt.err ]
1220 rm ssl-opt.err
1221 fi
1222 cd "$MBEDTLS_ROOT_DIR"
1223 rm -rf "$OUT_OF_SOURCE_DIR"
1224 unset MBEDTLS_ROOT_DIR
1225}
Andres AGdc192212016-08-31 17:33:13 +01001226
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01001227component_test_cmake_as_subdirectory () {
1228 msg "build: cmake 'as-subdirectory' build"
1229 MBEDTLS_ROOT_DIR="$PWD"
1230
1231 cd programs/test/cmake_subproject
1232 cmake .
1233 make
1234 if_build_succeeded ./cmake_subproject
1235
1236 cd "$MBEDTLS_ROOT_DIR"
1237 unset MBEDTLS_ROOT_DIR
1238}
1239
Gilles Peskine8f073122018-11-27 15:58:47 +01001240component_test_zeroize () {
1241 # Test that the function mbedtls_platform_zeroize() is not optimized away by
1242 # different combinations of compilers and optimization flags by using an
1243 # auxiliary GDB script. Unfortunately, GDB does not return error values to the
1244 # system in all cases that the script fails, so we must manually search the
1245 # output to check whether the pass string is present and no failure strings
1246 # were printed.
Andres AGdc192212016-08-31 17:33:13 +01001247
Gilles Peskine4976e822019-01-06 19:52:22 +00001248 # Don't try to disable ASLR. We don't care about ASLR here. We do care
1249 # about a spurious message if Gdb tries and fails, so suppress that.
1250 gdb_disable_aslr=
1251 if [ -z "$(gdb -batch -nw -ex 'set disable-randomization off' 2>&1)" ]; then
1252 gdb_disable_aslr='set disable-randomization off'
1253 fi
1254
Gilles Peskine8f073122018-11-27 15:58:47 +01001255 for optimization_flag in -O2 -O3 -Ofast -Os; do
Gilles Peskine55f7c942019-01-09 22:28:21 +01001256 for compiler in clang gcc; do
1257 msg "test: $compiler $optimization_flag, mbedtls_platform_zeroize()"
1258 make programs CC="$compiler" DEBUG=1 CFLAGS="$optimization_flag"
Gilles Peskine4976e822019-01-06 19:52:22 +00001259 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 +01001260 if_build_succeeded grep "The buffer was correctly zeroized" test_zeroize.log
1261 if_build_succeeded not grep -i "error" test_zeroize.log
1262 rm -f test_zeroize.log
1263 make clean
1264 done
Andres Amaya Garcia29673812017-10-25 10:35:51 +01001265 done
Andres Amaya Garciad0d7bf62017-10-25 09:01:31 +01001266
Gilles Peskine4976e822019-01-06 19:52:22 +00001267 unset gdb_disable_aslr
Gilles Peskine8f073122018-11-27 15:58:47 +01001268}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001269
Gilles Peskineaad2ebd2019-02-25 20:26:06 +01001270support_check_python_files () {
1271 type pylint3 >/dev/null 2>/dev/null
1272}
Gilles Peskine8f073122018-11-27 15:58:47 +01001273component_check_python_files () {
1274 msg "Lint: Python scripts"
1275 record_status tests/scripts/check-python-files.sh
1276}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001277
Gilles Peskine8f073122018-11-27 15:58:47 +01001278component_check_generate_test_code () {
1279 msg "uint test: generate_test_code.py"
1280 record_status ./tests/scripts/test_generate_test_code.py
1281}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001282
1283################################################################
1284#### Termination
1285################################################################
1286
Gilles Peskine8f073122018-11-27 15:58:47 +01001287post_report () {
1288 msg "Done, cleaning up"
1289 cleanup
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001290
Gilles Peskine8f073122018-11-27 15:58:47 +01001291 final_report
1292}
1293
1294
1295
1296################################################################
1297#### Run all the things
1298################################################################
1299
Gilles Peskinee48351a2018-11-27 16:06:30 +01001300# Run one component and clean up afterwards.
Gilles Peskine8f073122018-11-27 15:58:47 +01001301run_component () {
Gilles Peskine608953e2019-01-02 18:57:02 +01001302 # Back up the configuration in case the component modifies it.
1303 # The cleanup function will restore it.
1304 cp -p "$CONFIG_H" "$CONFIG_BAK"
Gilles Peskineffcdeff2018-12-04 12:49:28 +01001305 current_component="$1"
Gilles Peskine8f073122018-11-27 15:58:47 +01001306 "$@"
Gilles Peskinee48351a2018-11-27 16:06:30 +01001307 cleanup
Gilles Peskine8f073122018-11-27 15:58:47 +01001308}
1309
1310# Preliminary setup
1311pre_check_environment
1312pre_initialize_variables
1313pre_parse_command_line "$@"
Gilles Peskine348fb9a2018-11-27 17:04:29 +01001314
Gilles Peskine878cf602019-01-06 20:50:38 +00001315pre_check_git
Andrzej Kurekeb508712019-02-14 07:18:59 -05001316pre_check_seedfile
1317
Gilles Peskine878cf602019-01-06 20:50:38 +00001318build_status=0
1319if [ $KEEP_GOING -eq 1 ]; then
1320 pre_setup_keep_going
Gilles Peskine92525112018-11-27 18:15:35 +01001321else
Gilles Peskine878cf602019-01-06 20:50:38 +00001322 record_status () {
1323 "$@"
1324 }
Gilles Peskine8f073122018-11-27 15:58:47 +01001325fi
Gilles Peskine878cf602019-01-06 20:50:38 +00001326pre_print_configuration
1327pre_check_tools
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001328cleanup
1329
Gilles Peskinebeb3a812019-01-06 22:11:25 +00001330# Run the requested tests.
1331for component in $RUN_COMPONENTS; do
1332 run_component "component_$component"
1333done
Gilles Peskine8f073122018-11-27 15:58:47 +01001334
1335# We're done.
Gilles Peskine878cf602019-01-06 20:50:38 +00001336post_report