blob: 618205e81355414f1a9e130fa49aaf4db6cf7c82 [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
Gilles Peskine8f073122018-11-27 15:58:47 +0100121 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 AG38495a32016-07-12 16:54:33 +0100168
Simon Butcher41eeccf2016-09-07 00:07:09 +0100169usage()
SimonB2e23c822016-04-16 21:54:39 +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
245 if [ -f "$CONFIG_BAK" ]; then
246 mv "$CONFIG_BAK" "$CONFIG_H"
247 fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100248}
249
Gilles Peskine7c652162017-12-11 00:01:40 +0100250# Executed on exit. May be redefined depending on command line options.
251final_report () {
252 :
253}
254
255fatal_signal () {
256 cleanup
257 final_report $1
258 trap - $1
259 kill -$1 $$
260}
261
262trap 'fatal_signal HUP' HUP
263trap 'fatal_signal INT' INT
264trap 'fatal_signal TERM' TERM
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200265
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100266msg()
267{
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100268 if [ -n "${current_component:-}" ]; then
269 current_section="${current_component#component_}: $1"
270 else
271 current_section="$1"
272 fi
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100273 echo ""
274 echo "******************************************************************"
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100275 echo "* $current_section "
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000276 printf "* "; date
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100277 echo "******************************************************************"
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100278}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100279
Gilles Peskine8f073122018-11-27 15:58:47 +0100280armc6_build_test()
281{
282 FLAGS="$1"
Andres AGa5cd9732016-10-17 15:23:10 +0100283
Gilles Peskine8f073122018-11-27 15:58:47 +0100284 msg "build: ARM Compiler 6 ($FLAGS), make"
285 ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \
286 WARNING_CFLAGS='-xc -std=c99' make lib
287 make clean
288}
Andres AGa5cd9732016-10-17 15:23:10 +0100289
Andres AGd9eba4b2016-08-26 14:42:14 +0100290err_msg()
291{
292 echo "$1" >&2
293}
294
295check_tools()
296{
297 for TOOL in "$@"; do
Andres AG98393602017-01-31 17:04:45 +0000298 if ! `type "$TOOL" >/dev/null 2>&1`; then
Andres AGd9eba4b2016-08-26 14:42:14 +0100299 err_msg "$TOOL not found!"
300 exit 1
301 fi
302 done
303}
304
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400305check_headers_in_cpp () {
Peter Kolbus1bc1a4c2019-02-01 17:19:08 -0600306 ls include/mbedtls | grep "\.h$" >headers.txt
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400307 <programs/test/cpp_dummy_build.cpp sed -n 's/"$//; s!^#include "mbedtls/!!p' |
308 sort |
309 diff headers.txt -
310 rm headers.txt
311}
312
Gilles Peskine8f073122018-11-27 15:58:47 +0100313pre_parse_command_line () {
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000314 COMMAND_LINE_COMPONENTS=
Gilles Peskinea28db922019-01-10 00:05:18 +0100315 all_except=0
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000316 no_armcc=
SimonB2e23c822016-04-16 21:54:39 +0100317
Gilles Peskine8f073122018-11-27 15:58:47 +0100318 while [ $# -gt 0 ]; do
Gilles Peskine55f7c942019-01-09 22:28:21 +0100319 case "$1" in
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000320 --armcc) no_armcc=;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100321 --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
322 --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000323 --except) all_except=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100324 --force|-f) FORCE=1;;
325 --gnutls-cli) shift; GNUTLS_CLI="$1";;
326 --gnutls-legacy-cli) shift; GNUTLS_LEGACY_CLI="$1";;
327 --gnutls-legacy-serv) shift; GNUTLS_LEGACY_SERV="$1";;
328 --gnutls-serv) shift; GNUTLS_SERV="$1";;
329 --help|-h) usage; exit;;
330 --keep-going|-k) KEEP_GOING=1;;
Gilles Peskine878cf602019-01-06 20:50:38 +0000331 --list-all-components) printf '%s\n' $ALL_COMPONENTS; exit;;
332 --list-components) printf '%s\n' $SUPPORTED_COMPONENTS; exit;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100333 --memory|-m) MEMORY=1;;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000334 --no-armcc) no_armcc=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100335 --no-force) FORCE=0;;
336 --no-keep-going) KEEP_GOING=0;;
337 --no-memory) MEMORY=0;;
338 --openssl) shift; OPENSSL="$1";;
339 --openssl-legacy) shift; OPENSSL_LEGACY="$1";;
340 --openssl-next) shift; OPENSSL_NEXT="$1";;
341 --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
342 --random-seed) unset SEED;;
343 --release-test|-r) SEED=1;;
344 --seed|-s) shift; SEED="$1";;
345 -*)
346 echo >&2 "Unknown option: $1"
347 echo >&2 "Run $0 --help for usage."
348 exit 120
349 ;;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000350 *) COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS $1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100351 esac
352 shift
Gilles Peskine8f073122018-11-27 15:58:47 +0100353 done
SimonB2e23c822016-04-16 21:54:39 +0100354
Gilles Peskinea28db922019-01-10 00:05:18 +0100355 # With no list of components, run everything.
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000356 if [ -z "$COMMAND_LINE_COMPONENTS" ]; then
357 all_except=1
Andres AGdc192212016-08-31 17:33:13 +0100358 fi
359
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000360 # --no-armcc is a legacy option. The modern way is --except '*_armcc*'.
361 # Ignore it if components are listed explicitly on the command line.
Gilles Peskinea28db922019-01-10 00:05:18 +0100362 if [ -n "$no_armcc" ] && [ $all_except -eq 1 ]; then
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000363 COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS *_armcc*"
SimonB2e23c822016-04-16 21:54:39 +0100364 fi
SimonB2e23c822016-04-16 21:54:39 +0100365
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000366 # Build the list of components to run.
Gilles Peskinea28db922019-01-10 00:05:18 +0100367 RUN_COMPONENTS=
368 for component in $SUPPORTED_COMPONENTS; do
369 if is_component_included "$component"; [ $? -eq $all_except ]; then
370 RUN_COMPONENTS="$RUN_COMPONENTS $component"
371 fi
372 done
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000373
374 unset all_except
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000375 unset no_armcc
Gilles Peskine8f073122018-11-27 15:58:47 +0100376}
SimonB2e23c822016-04-16 21:54:39 +0100377
Gilles Peskine8f073122018-11-27 15:58:47 +0100378pre_check_git () {
379 if [ $FORCE -eq 1 ]; then
Gilles Peskine53190e62019-01-09 23:17:35 +0100380 rm -rf "$OUT_OF_SOURCE_DIR"
Gilles Peskine8f073122018-11-27 15:58:47 +0100381 git checkout-index -f -q $CONFIG_H
382 cleanup
383 else
SimonB2e23c822016-04-16 21:54:39 +0100384
Gilles Peskine8f073122018-11-27 15:58:47 +0100385 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
386 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
387 echo "You can either delete this directory manually, or force the test by rerunning"
388 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
389 exit 1
390 fi
391
Gilles Peskined1174cf2019-01-09 22:30:01 +0100392 if ! git diff --quiet include/mbedtls/config.h; then
Gilles Peskine8f073122018-11-27 15:58:47 +0100393 err_msg "Warning - the configuration file 'include/mbedtls/config.h' has been edited. "
394 echo "You can either delete or preserve your work, or force the test by rerunning the"
395 echo "script as: $0 --force"
396 exit 1
397 fi
Andres AGdc192212016-08-31 17:33:13 +0100398 fi
Andrzej Kureke9c3b812019-02-05 05:34:21 -0500399 if ! [ -f crypto/Makefile ]; then
400 echo "Please initialize the crypto submodule" >&2
401 exit 1
402 fi
Gilles Peskine8f073122018-11-27 15:58:47 +0100403}
Andres AGdc192212016-08-31 17:33:13 +0100404
Andrzej Kurekeb508712019-02-14 07:18:59 -0500405pre_check_seedfile () {
406 if [ ! -f "./tests/seedfile" ]; then
407 dd if=/dev/urandom of=./tests/seedfile bs=32 count=1
408 fi
Jaeden Amero97145102019-03-18 16:31:21 +0000409 if [ ! -f "./crypto/tests/seedfile" ]; then
410 dd if=/dev/urandom of=./crypto/tests/seedfile bs=32 count=1
411 fi
Andrzej Kurekeb508712019-02-14 07:18:59 -0500412}
413
Gilles Peskine8f073122018-11-27 15:58:47 +0100414pre_setup_keep_going () {
Gilles Peskine7c652162017-12-11 00:01:40 +0100415 failure_summary=
416 failure_count=0
417 start_red=
418 end_color=
419 if [ -t 1 ]; then
Gilles Peskine9736b9d2018-01-02 21:54:17 +0100420 case "${TERM:-}" in
Gilles Peskine7c652162017-12-11 00:01:40 +0100421 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
422 start_red=$(printf '\033[31m')
423 end_color=$(printf '\033[0m')
424 ;;
425 esac
426 fi
427 record_status () {
428 if "$@"; then
429 last_status=0
430 else
431 last_status=$?
432 text="$current_section: $* -> $last_status"
433 failure_summary="$failure_summary
434$text"
435 failure_count=$((failure_count + 1))
436 echo "${start_red}^^^^$text^^^^${end_color}"
437 fi
438 }
439 make () {
440 case "$*" in
441 *test|*check)
442 if [ $build_status -eq 0 ]; then
443 record_status command make "$@"
444 else
445 echo "(skipped because the build failed)"
446 fi
447 ;;
448 *)
449 record_status command make "$@"
450 build_status=$last_status
451 ;;
452 esac
453 }
454 final_report () {
455 if [ $failure_count -gt 0 ]; then
456 echo
457 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
458 echo "${start_red}FAILED: $failure_count${end_color}$failure_summary"
459 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Jaeden Amero7c1258d2018-07-20 16:42:14 +0100460 exit 1
Gilles Peskine7c652162017-12-11 00:01:40 +0100461 elif [ -z "${1-}" ]; then
462 echo "SUCCESS :)"
463 fi
464 if [ -n "${1-}" ]; then
465 echo "Killed by SIG$1."
466 fi
467 }
Gilles Peskine8f073122018-11-27 15:58:47 +0100468}
469
Gilles Peskine7c652162017-12-11 00:01:40 +0100470if_build_succeeded () {
471 if [ $build_status -eq 0 ]; then
472 record_status "$@"
473 fi
474}
475
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200476# to be used instead of ! for commands run with
477# record_status or if_build_succeeded
478not() {
479 ! "$@"
480}
481
Gilles Peskine8f073122018-11-27 15:58:47 +0100482pre_print_configuration () {
483 msg "info: $0 configuration"
484 echo "MEMORY: $MEMORY"
485 echo "FORCE: $FORCE"
486 echo "SEED: ${SEED-"UNSET"}"
487 echo "OPENSSL: $OPENSSL"
488 echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
489 echo "OPENSSL_NEXT: $OPENSSL_NEXT"
490 echo "GNUTLS_CLI: $GNUTLS_CLI"
491 echo "GNUTLS_SERV: $GNUTLS_SERV"
492 echo "GNUTLS_LEGACY_CLI: $GNUTLS_LEGACY_CLI"
493 echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV"
494 echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
495 echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
496}
Andres AG7770ea82016-10-10 15:46:20 +0100497
Andres AGd9eba4b2016-08-26 14:42:14 +0100498# Make sure the tools we need are available.
Gilles Peskine8f073122018-11-27 15:58:47 +0100499pre_check_tools () {
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000500 # Build the list of variables to pass to output_env.sh.
501 set env
Andres AGd9eba4b2016-08-26 14:42:14 +0100502
Gilles Peskine87964262019-01-06 22:40:00 +0000503 case " $RUN_COMPONENTS " in
504 # Require OpenSSL and GnuTLS if running any tests (as opposed to
505 # only doing builds). Not all tests run OpenSSL and GnuTLS, but this
506 # is a good enough approximation in practice.
507 *" test_"*)
508 # To avoid setting OpenSSL and GnuTLS for each call to compat.sh
509 # and ssl-opt.sh, we just export the variables they require.
510 export OPENSSL_CMD="$OPENSSL"
511 export GNUTLS_CLI="$GNUTLS_CLI"
512 export GNUTLS_SERV="$GNUTLS_SERV"
513 # Avoid passing --seed flag in every call to ssl-opt.sh
514 if [ -n "${SEED-}" ]; then
515 export SEED
516 fi
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000517 set "$@" OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY"
518 set "$@" GNUTLS_CLI="$GNUTLS_CLI" GNUTLS_SERV="$GNUTLS_SERV"
519 set "$@" GNUTLS_LEGACY_CLI="$GNUTLS_LEGACY_CLI"
520 set "$@" GNUTLS_LEGACY_SERV="$GNUTLS_LEGACY_SERV"
Gilles Peskine87964262019-01-06 22:40:00 +0000521 check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$OPENSSL_NEXT" \
522 "$GNUTLS_CLI" "$GNUTLS_SERV" \
523 "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV"
524 ;;
525 esac
Andres AGb2fdd042016-09-22 14:17:46 +0100526
Gilles Peskine87964262019-01-06 22:40:00 +0000527 case " $RUN_COMPONENTS " in
528 *_doxygen[_\ ]*) check_tools "doxygen" "dot";;
529 esac
Andres AG7770ea82016-10-10 15:46:20 +0100530
Gilles Peskine87964262019-01-06 22:40:00 +0000531 case " $RUN_COMPONENTS " in
532 *_arm_none_eabi_gcc[_\ ]*) check_tools "arm-none-eabi-gcc";;
533 esac
Andres AG7770ea82016-10-10 15:46:20 +0100534
Gilles Peskine87964262019-01-06 22:40:00 +0000535 case " $RUN_COMPONENTS " in
536 *_mingw[_\ ]*) check_tools "i686-w64-mingw32-gcc";;
537 esac
538
539 case " $RUN_COMPONENTS " in
540 *" test_zeroize "*) check_tools "gdb";;
541 esac
542
543 case " $RUN_COMPONENTS " in
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000544 *_armcc*)
Gilles Peskine87964262019-01-06 22:40:00 +0000545 ARMC5_CC="$ARMC5_BIN_DIR/armcc"
546 ARMC5_AR="$ARMC5_BIN_DIR/armar"
547 ARMC6_CC="$ARMC6_BIN_DIR/armclang"
548 ARMC6_AR="$ARMC6_BIN_DIR/armar"
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000549 check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC6_CC" "$ARMC6_AR";;
550 esac
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000551
552 msg "info: output_env.sh"
553 case $RUN_COMPONENTS in
554 *_armcc*)
555 set "$@" ARMC5_CC="$ARMC5_CC" ARMC6_CC="$ARMC6_CC" RUN_ARMCC=1;;
556 *) set "$@" RUN_ARMCC=0;;
557 esac
558 "$@" scripts/output_env.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100559}
Andres AGd9eba4b2016-08-26 14:42:14 +0100560
Gilles Peskine192c72f2017-12-21 15:59:21 +0100561
562
563################################################################
564#### Basic checks
565################################################################
Andres AGd9eba4b2016-08-26 14:42:14 +0100566
SimonB2e23c822016-04-16 21:54:39 +0100567#
568# Test Suites to be executed
569#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200570# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100571# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard61bc57a2014-08-14 11:29:06 +0200572# and/or are more likely to fail than others (eg I use Clang most of the
573# time, so start with a GCC build).
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200574# 2. Minimize total running time, by avoiding useless rebuilds
575#
576# Indicative running times are given for reference.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100577
Gilles Peskine8f073122018-11-27 15:58:47 +0100578component_check_recursion () {
579 msg "test: recursion.pl" # < 1s
580 record_status tests/scripts/recursion.pl library/*.c
581}
Janos Follathb72c6782016-07-19 14:54:17 +0100582
Gilles Peskine8f073122018-11-27 15:58:47 +0100583component_check_generated_files () {
584 msg "test: freshness of generated source files" # < 1s
585 record_status tests/scripts/check-generated-files.sh
586}
Manuel Pégourié-Gonnardea29d152014-11-20 17:32:33 +0100587
Gilles Peskine8f073122018-11-27 15:58:47 +0100588component_check_doxy_blocks () {
589 msg "test: doxygen markup outside doxygen blocks" # < 1s
590 record_status tests/scripts/check-doxy-blocks.pl
591}
Manuel Pégourié-Gonnardb3b8e432015-02-13 14:52:19 +0000592
Gilles Peskine8f073122018-11-27 15:58:47 +0100593component_check_files () {
594 msg "test: check-files.py" # < 1s
Gilles Peskine8f073122018-11-27 15:58:47 +0100595 record_status tests/scripts/check-files.py
596}
Manuel Pégourié-Gonnardd09a6b52015-04-09 17:19:23 +0200597
Gilles Peskine8f073122018-11-27 15:58:47 +0100598component_check_names () {
599 msg "test/build: declared and exported names" # < 3s
Gilles Peskine13f97dc2019-05-15 17:52:22 +0200600 record_status tests/scripts/check-names.sh -v
Gilles Peskine8f073122018-11-27 15:58:47 +0100601}
Darryl Greena07039c2018-03-13 16:48:16 +0000602
Gilles Peskine8f073122018-11-27 15:58:47 +0100603component_check_doxygen_warnings () {
604 msg "test: doxygen warnings" # ~ 3s
Gilles Peskine8f073122018-11-27 15:58:47 +0100605 record_status tests/scripts/doxygen.sh
606}
Manuel Pégourié-Gonnard1d552e72016-01-04 16:49:09 +0100607
Gilles Peskine192c72f2017-12-21 15:59:21 +0100608
609
610################################################################
611#### Build and test many configurations and targets
612################################################################
613
Gilles Peskine7832c9f2019-04-08 17:00:15 +0200614component_test_default_out_of_box () {
615 msg "build: make, default config (out-of-box)" # ~1min
616 make
617
618 msg "test: main suites make, default config (out-of-box)" # ~10s
619 make test
620
621 msg "selftest: make, default config (out-of-box)" # ~10s
622 programs/test/selftest
623}
624
Gilles Peskine8f073122018-11-27 15:58:47 +0100625component_test_default_cmake_gcc_asan () {
626 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100627 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
628 make
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100629
Gilles Peskine8f073122018-11-27 15:58:47 +0100630 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
631 make test
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200632
Gilles Peskine8f073122018-11-27 15:58:47 +0100633 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
634 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200635
Gilles Peskine8f073122018-11-27 15:58:47 +0100636 msg "test: compat.sh (ASan build)" # ~ 6 min
637 if_build_succeeded tests/compat.sh
638}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200639
Gilles Peskine782f4112018-11-27 16:11:09 +0100640component_test_ref_configs () {
641 msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
642 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
643 record_status tests/scripts/test-ref-configs.pl
644}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200645
Gilles Peskine8f073122018-11-27 15:58:47 +0100646component_test_sslv3 () {
647 msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100648 scripts/config.pl set MBEDTLS_SSL_PROTO_SSL3
649 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
650 make
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200651
Gilles Peskine8f073122018-11-27 15:58:47 +0100652 msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
653 make test
Simon Butcher3ea7f522016-03-07 23:22:10 +0000654
Gilles Peskine8f073122018-11-27 15:58:47 +0100655 msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
656 if_build_succeeded tests/compat.sh -m 'tls1 tls1_1 tls1_2 dtls1 dtls1_2'
657 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
Simon Butcher3ea7f522016-03-07 23:22:10 +0000658
Gilles Peskine8f073122018-11-27 15:58:47 +0100659 msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
660 if_build_succeeded tests/ssl-opt.sh
661}
Simon Butcher3ea7f522016-03-07 23:22:10 +0000662
Gilles Peskine8f073122018-11-27 15:58:47 +0100663component_test_no_renegotiation () {
664 msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100665 scripts/config.pl unset MBEDTLS_SSL_RENEGOTIATION
666 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
667 make
Simon Butcher3ea7f522016-03-07 23:22:10 +0000668
Gilles Peskine8f073122018-11-27 15:58:47 +0100669 msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
670 make test
Hanno Becker134c2ab2017-10-12 15:29:50 +0100671
Gilles Peskine8f073122018-11-27 15:58:47 +0100672 msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
673 if_build_succeeded tests/ssl-opt.sh
674}
Hanno Becker134c2ab2017-10-12 15:29:50 +0100675
Hanno Beckera545be22019-05-10 14:45:37 +0100676component_test_no_pem_no_fs () {
677 msg "build: Default + !MBEDTLS_PEM_PARSE_C + !MBEDTLS_FS_IO (ASan build)"
678 scripts/config.pl unset MBEDTLS_PEM_PARSE_C
679 scripts/config.pl unset MBEDTLS_FS_IO
680 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
681 make
682
683 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - main suites (inc. selftests) (ASan build)" # ~ 50s
684 make test
685
686 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - ssl-opt.sh (ASan build)" # ~ 6 min
687 if_build_succeeded tests/ssl-opt.sh
688}
689
Gilles Peskine8f073122018-11-27 15:58:47 +0100690component_test_rsa_no_crt () {
691 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100692 scripts/config.pl set MBEDTLS_RSA_NO_CRT
693 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
694 make
Simon Butcher3ea7f522016-03-07 23:22:10 +0000695
Gilles Peskine8f073122018-11-27 15:58:47 +0100696 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
697 make test
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100698
Gilles Peskine8f073122018-11-27 15:58:47 +0100699 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
700 if_build_succeeded tests/ssl-opt.sh -f RSA
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100701
Gilles Peskine8f073122018-11-27 15:58:47 +0100702 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
703 if_build_succeeded tests/compat.sh -t RSA
704}
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100705
Gilles Peskine8f073122018-11-27 15:58:47 +0100706component_test_small_ssl_out_content_len () {
707 msg "build: small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100708 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 16384
709 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
710 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
711 make
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100712
Gilles Peskine8f073122018-11-27 15:58:47 +0100713 msg "test: small SSL_OUT_CONTENT_LEN - ssl-opt.sh MFL and large packet tests"
714 if_build_succeeded tests/ssl-opt.sh -f "Max fragment\|Large packet"
715}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000716
Gilles Peskine8f073122018-11-27 15:58:47 +0100717component_test_small_ssl_in_content_len () {
718 msg "build: small SSL_IN_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100719 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 4096
720 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 16384
721 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
722 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000723
Gilles Peskine8f073122018-11-27 15:58:47 +0100724 msg "test: small SSL_IN_CONTENT_LEN - ssl-opt.sh MFL tests"
725 if_build_succeeded tests/ssl-opt.sh -f "Max fragment"
726}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000727
Gilles Peskine8f073122018-11-27 15:58:47 +0100728component_test_small_ssl_dtls_max_buffering () {
729 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0"
Gilles Peskine8f073122018-11-27 15:58:47 +0100730 scripts/config.pl set MBEDTLS_SSL_DTLS_MAX_BUFFERING 1000
731 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
732 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000733
Gilles Peskine8f073122018-11-27 15:58:47 +0100734 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0 - ssl-opt.sh specific reordering test"
735 if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer out-of-order hs msg before reassembling next, free buffered msg"
736}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100737
Gilles Peskine8f073122018-11-27 15:58:47 +0100738component_test_small_mbedtls_ssl_dtls_max_buffering () {
739 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1"
Gilles Peskine8f073122018-11-27 15:58:47 +0100740 scripts/config.pl set MBEDTLS_SSL_DTLS_MAX_BUFFERING 240
741 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
742 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100743
Gilles Peskine8f073122018-11-27 15:58:47 +0100744 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1 - ssl-opt.sh specific reordering test"
745 if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer encrypted Finished message, drop for fragmented NewSessionTicket"
746}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100747
Gilles Peskine8f073122018-11-27 15:58:47 +0100748component_test_full_cmake_clang () {
749 msg "build: cmake, full config, clang" # ~ 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100750 scripts/config.pl full
751 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
752 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check -D ENABLE_TESTING=On .
753 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100754
Gilles Peskine8f073122018-11-27 15:58:47 +0100755 msg "test: main suites (full config)" # ~ 5s
756 make test
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100757
Gilles Peskine8f073122018-11-27 15:58:47 +0100758 msg "test: ssl-opt.sh default, ECJPAKE, SSL async (full config)" # ~ 1s
759 if_build_succeeded tests/ssl-opt.sh -f 'Default\|ECJPAKE\|SSL async private'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200760
Andres Amaya Garcia2dadab72019-01-08 21:42:27 +0000761 msg "test: compat.sh RC4, DES, 3DES & NULL (full config)" # ~ 2 min
Andres Amaya Garcia419bd002019-02-19 20:20:57 +0000762 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 +0200763
Gilles Peskine8f073122018-11-27 15:58:47 +0100764 msg "test: compat.sh ARIA + ChachaPoly"
765 if_build_succeeded env OPENSSL_CMD="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
766}
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200767
Gilles Peskine8f073122018-11-27 15:58:47 +0100768component_build_deprecated () {
769 msg "build: make, full config + DEPRECATED_WARNING, gcc -O" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100770 scripts/config.pl full
771 scripts/config.pl set MBEDTLS_DEPRECATED_WARNING
772 # Build with -O -Wextra to catch a maximum of issues.
773 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra' lib programs
774 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100775
Gilles Peskine8f073122018-11-27 15:58:47 +0100776 msg "build: make, full config + DEPRECATED_REMOVED, clang -O" # ~ 30s
777 # No cleanup, just tweak the configuration and rebuild
778 make clean
779 scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
780 scripts/config.pl set MBEDTLS_DEPRECATED_REMOVED
781 # Build with -O -Wextra to catch a maximum of issues.
782 make CC=clang CFLAGS='-O -Werror -Wall -Wextra' lib programs
783 make CC=clang CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
784}
Jaeden Ameroed93bdc2018-11-02 16:57:24 +0000785
Gilles Peskine8f073122018-11-27 15:58:47 +0100786component_test_depends_curves () {
787 msg "test/build: curves.pl (gcc)" # ~ 4 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100788 record_status tests/scripts/curves.pl
789}
Jaeden Ameroacaabe72018-11-07 11:52:52 +0000790
Gilles Peskine8f073122018-11-27 15:58:47 +0100791component_test_depends_hashes () {
792 msg "test/build: depends-hashes.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100793 record_status tests/scripts/depends-hashes.pl
794}
Jaeden Ameroacaabe72018-11-07 11:52:52 +0000795
Gilles Peskine8f073122018-11-27 15:58:47 +0100796component_test_depends_pkalgs () {
797 msg "test/build: depends-pkalgs.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100798 record_status tests/scripts/depends-pkalgs.pl
799}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100800
Gilles Peskine8f073122018-11-27 15:58:47 +0100801component_build_key_exchanges () {
802 msg "test/build: key-exchanges (gcc)" # ~ 1 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100803 record_status tests/scripts/key-exchanges.pl
804}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100805
Gilles Peskine8f073122018-11-27 15:58:47 +0100806component_build_default_make_gcc_and_cxx () {
807 msg "build: Unix make, -Os (gcc)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100808 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100809
Gilles Peskine8f073122018-11-27 15:58:47 +0100810 msg "test: verify header list in cpp_dummy_build.cpp"
811 record_status check_headers_in_cpp
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100812
Gilles Peskine8f073122018-11-27 15:58:47 +0100813 msg "build: Unix make, incremental g++"
814 make TEST_CPP=1
815}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100816
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100817component_test_no_use_psa_crypto_full_cmake_asan() {
818 # full minus MBEDTLS_USE_PSA_CRYPTO: run the same set of tests as basic-build-test.sh
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500819 msg "build: cmake, full config + MBEDTLS_USE_PSA_CRYPTO, ASan"
820 scripts/config.pl full
821 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
Hanno Becker241b5242019-02-22 10:26:18 +0000822 scripts/config.pl unset MBEDTLS_ECP_RESTARTABLE # restartable ECC not supported through PSA
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500823 scripts/config.pl set MBEDTLS_PSA_CRYPTO_C
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100824 scripts/config.pl unset MBEDTLS_USE_PSA_CRYPTO
825 scripts/config.pl unset MBEDTLS_PSA_ITS_FILE_C
Andrzej Kurek324b2f72019-04-18 08:59:12 -0400826 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_C
Manuel Pégourié-Gonnardd8167e82019-02-01 11:12:52 +0100827 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500828 make
Manuel Pégourié-Gonnard43be6cd2017-06-20 09:53:42 +0200829
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100830 msg "test: main suites (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500831 make test
Manuel Pégourié-Gonnard503a5ef2015-10-23 09:04:45 +0200832
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100833 msg "test: ssl-opt.sh (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500834 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100835
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100836 msg "test: compat.sh default (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500837 if_build_succeeded tests/compat.sh
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400838
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100839 msg "test: compat.sh ssl3 (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500840 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400841
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100842 msg "test: compat.sh RC4, DES & NULL (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500843 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 -0500844
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100845 msg "test: compat.sh ARIA + ChachaPoly (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500846 if_build_succeeded env OPENSSL_CMD="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
847}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500848
Gilles Peskineb28636b2019-01-02 19:06:24 +0100849component_test_check_params_without_platform () {
850 msg "build+test: MBEDTLS_CHECK_PARAMS without MBEDTLS_PLATFORM_C"
851 scripts/config.pl full # includes CHECK_PARAMS
852 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
853 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
854 scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
855 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
856 scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
857 scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
858 scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
859 scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
860 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
861 scripts/config.pl unset MBEDTLS_PLATFORM_C
862 make CC=gcc CFLAGS='-Werror -O1' all test
863}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500864
Gilles Peskineb28636b2019-01-02 19:06:24 +0100865component_test_check_params_silent () {
866 msg "build+test: MBEDTLS_CHECK_PARAMS with alternative MBEDTLS_PARAM_FAILED()"
867 scripts/config.pl full # includes CHECK_PARAMS
868 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
869 sed -i 's/.*\(#define MBEDTLS_PARAM_FAILED( cond )\).*/\1/' "$CONFIG_H"
870 make CC=gcc CFLAGS='-Werror -O1' all test
871}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500872
Gilles Peskine8f073122018-11-27 15:58:47 +0100873component_test_no_platform () {
874 # Full configuration build, without platform support, file IO and net sockets.
875 # This should catch missing mbedtls_printf definitions, and by disabling file
876 # IO, it should catch missing '#include <stdio.h>'
877 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100878 scripts/config.pl full
879 scripts/config.pl unset MBEDTLS_PLATFORM_C
880 scripts/config.pl unset MBEDTLS_NET_C
881 scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
882 scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
883 scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
884 scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
885 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
886 scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
887 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
888 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
889 scripts/config.pl unset MBEDTLS_FS_IO
Andrzej Kurek73757082019-04-18 04:14:37 -0400890 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_C
891 scripts/config.pl unset MBEDTLS_PSA_ITS_FILE_C
Gilles Peskine8f073122018-11-27 15:58:47 +0100892 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
893 # to re-enable platform integration features otherwise disabled in C99 builds
894 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -O0 -D_DEFAULT_SOURCE' lib programs
895 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0' test
896}
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +0000897
Gilles Peskine8f073122018-11-27 15:58:47 +0100898component_build_no_std_function () {
899 # catch compile bugs in _uninit functions
900 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100901 scripts/config.pl full
902 scripts/config.pl set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
903 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
904 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
905}
Manuel Pégourié-Gonnarddccb80b2015-06-03 10:20:33 +0100906
Gilles Peskine8f073122018-11-27 15:58:47 +0100907component_build_no_ssl_srv () {
908 msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100909 scripts/config.pl full
910 scripts/config.pl unset MBEDTLS_SSL_SRV_C
911 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
912}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200913
Gilles Peskine8f073122018-11-27 15:58:47 +0100914component_build_no_ssl_cli () {
915 msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100916 scripts/config.pl full
917 scripts/config.pl unset MBEDTLS_SSL_CLI_C
918 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
919}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200920
Gilles Peskine8f073122018-11-27 15:58:47 +0100921component_build_no_sockets () {
922 # Note, C99 compliance can also be tested with the sockets support disabled,
923 # as that requires a POSIX platform (which isn't the same as C99).
924 msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100925 scripts/config.pl full
926 scripts/config.pl unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
927 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
928 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0 -std=c99 -pedantic' lib
929}
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +0200930
Gilles Peskine8f073122018-11-27 15:58:47 +0100931component_test_no_max_fragment_length () {
932 # Run max fragment length tests with MFL disabled
933 msg "build: default config except MFL extension (ASan build)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100934 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
935 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
936 make
Hanno Becker5175ac62017-09-18 15:36:25 +0100937
Gilles Peskine8f073122018-11-27 15:58:47 +0100938 msg "test: ssl-opt.sh, MFL-related tests"
939 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length"
940}
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +0200941
Hanno Becker545ced42019-02-19 11:10:48 +0000942component_test_asan_remove_peer_certificate () {
943 msg "build: default config with MBEDTLS_SSL_KEEP_PEER_CERTIFICATE disabled (ASan build)"
944 scripts/config.pl unset MBEDTLS_SSL_KEEP_PEER_CERTIFICATE
945 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
946 make
947
948 msg "test: !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
949 make test
950
951 msg "test: ssl-opt.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
952 if_build_succeeded tests/ssl-opt.sh
953
954 msg "test: compat.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
955 if_build_succeeded tests/compat.sh
956}
957
Gilles Peskine8f073122018-11-27 15:58:47 +0100958component_test_no_max_fragment_length_small_ssl_out_content_len () {
959 msg "build: no MFL extension, small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100960 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
961 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 16384
962 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
963 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
964 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000965
Gilles Peskine8f073122018-11-27 15:58:47 +0100966 msg "test: MFL tests (disabled MFL extension case) & large packet tests"
967 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length\|Large buffer"
968}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000969
Gilles Peskine8f073122018-11-27 15:58:47 +0100970component_test_null_entropy () {
971 msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100972 scripts/config.pl set MBEDTLS_TEST_NULL_ENTROPY
973 scripts/config.pl set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
974 scripts/config.pl set MBEDTLS_ENTROPY_C
975 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
976 scripts/config.pl unset MBEDTLS_ENTROPY_HARDWARE_ALT
977 scripts/config.pl unset MBEDTLS_HAVEGE_C
Gilles Peskine5fa32a72019-01-06 19:48:30 +0000978 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan -D UNSAFE_BUILD=ON .
Gilles Peskine8f073122018-11-27 15:58:47 +0100979 make
Janos Follath06c54002016-06-09 13:57:40 +0100980
Gilles Peskine8f073122018-11-27 15:58:47 +0100981 msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)"
982 make test
983}
Janos Follath06c54002016-06-09 13:57:40 +0100984
Gilles Peskine8f073122018-11-27 15:58:47 +0100985component_test_platform_calloc_macro () {
986 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100987 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
988 scripts/config.pl set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
989 scripts/config.pl set MBEDTLS_PLATFORM_FREE_MACRO free
990 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
991 make
Hanno Beckere5fecec2018-10-11 11:02:52 +0100992
Gilles Peskine8f073122018-11-27 15:58:47 +0100993 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
994 make test
995}
Hanno Beckere5fecec2018-10-11 11:02:52 +0100996
Gilles Peskine8f073122018-11-27 15:58:47 +0100997component_test_make_shared () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100998 msg "build/test: make shared" # ~ 40s
Andrzej Kurek87615772019-04-19 15:03:58 -0400999 make SHARED=1 all check -j1
Gilles Peskine8f073122018-11-27 15:58:47 +01001000}
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +02001001
Gilles Peskine8f073122018-11-27 15:58:47 +01001002component_test_m32_o0 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001003 # Build once with -O0, to compile out the i386 specific inline assembly
1004 msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
Simon Butcher7a6da6e2018-06-27 21:52:54 +01001005 scripts/config.pl full
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001006 make CC=gcc CFLAGS='-O0 -Werror -Wall -Wextra -m32 -fsanitize=address'
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01001007
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001008 msg "test: i386, make, gcc -O0 (ASan build)"
1009 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01001010}
Gilles Peskine878cf602019-01-06 20:50:38 +00001011support_test_m32_o0 () {
1012 case $(uname -m) in
1013 *64*) true;;
1014 *) false;;
1015 esac
1016}
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001017
Gilles Peskine8f073122018-11-27 15:58:47 +01001018component_test_m32_o1 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001019 # Build again with -O1, to compile in the i386 specific inline assembly
1020 msg "build: i386, make, gcc -O1 (ASan build)" # ~ 30s
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001021 scripts/config.pl full
Gilles Peskine4b317612019-04-08 16:58:02 +02001022 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE
1023 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
1024 scripts/config.pl unset MBEDTLS_MEMORY_DEBUG
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001025 make CC=gcc CFLAGS='-O1 -Werror -Wall -Wextra -m32 -fsanitize=address'
1026
1027 msg "test: i386, make, gcc -O1 (ASan build)"
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001028 make test
Gilles Peskine4b317612019-04-08 16:58:02 +02001029
1030 msg "test ssl-opt.sh, i386, make, gcc-O1"
1031 if_build_succeeded tests/ssl-opt.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01001032}
Gilles Peskine878cf602019-01-06 20:50:38 +00001033support_test_m32_o1 () {
1034 support_test_m32_o0 "$@"
1035}
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001036
Gilles Peskine8f073122018-11-27 15:58:47 +01001037component_test_mx32 () {
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001038 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
Simon Butcher7a6da6e2018-06-27 21:52:54 +01001039 scripts/config.pl full
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001040 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32'
1041
1042 msg "test: 64-bit ILP32, make, gcc"
1043 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01001044}
Gilles Peskine878cf602019-01-06 20:50:38 +00001045support_test_mx32 () {
1046 case $(uname -m) in
1047 amd64|x86_64) true;;
1048 *) false;;
1049 esac
1050}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001051
Gilles Peskine8f073122018-11-27 15:58:47 +01001052component_build_arm_none_eabi_gcc () {
1053 msg "build: arm-none-eabi-gcc, make" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +01001054 scripts/config.pl full
1055 scripts/config.pl unset MBEDTLS_NET_C
1056 scripts/config.pl unset MBEDTLS_TIMING_C
1057 scripts/config.pl unset MBEDTLS_FS_IO
1058 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
1059 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
Andrzej Kurek73757082019-04-18 04:14:37 -04001060 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_C
1061 scripts/config.pl unset MBEDTLS_PSA_ITS_FILE_C
Gilles Peskine8f073122018-11-27 15:58:47 +01001062 # following things are not in the default config
1063 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
1064 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
1065 scripts/config.pl unset MBEDTLS_THREADING_C
1066 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
1067 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
1068 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
1069}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001070
Gilles Peskine8f073122018-11-27 15:58:47 +01001071component_build_arm_none_eabi_gcc_no_udbl_division () {
1072 msg "build: arm-none-eabi-gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +01001073 scripts/config.pl full
1074 scripts/config.pl unset MBEDTLS_NET_C
1075 scripts/config.pl unset MBEDTLS_TIMING_C
1076 scripts/config.pl unset MBEDTLS_FS_IO
1077 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
1078 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
Andrzej Kurek73757082019-04-18 04:14:37 -04001079 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_C
1080 scripts/config.pl unset MBEDTLS_PSA_ITS_FILE_C
Gilles Peskine8f073122018-11-27 15:58:47 +01001081 # following things are not in the default config
1082 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
1083 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
1084 scripts/config.pl unset MBEDTLS_THREADING_C
1085 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
1086 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
1087 scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
1088 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
1089 echo "Checking that software 64-bit division is not required"
1090 if_build_succeeded not grep __aeabi_uldiv library/*.o
1091}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001092
Gilles Peskine8f073122018-11-27 15:58:47 +01001093component_build_arm_none_eabi_gcc_no_64bit_multiplication () {
1094 msg "build: arm-none-eabi-gcc MBEDTLS_NO_64BIT_MULTIPLICATION, make" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +01001095 scripts/config.pl full
1096 scripts/config.pl unset MBEDTLS_NET_C
1097 scripts/config.pl unset MBEDTLS_TIMING_C
1098 scripts/config.pl unset MBEDTLS_FS_IO
1099 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
Andrzej Kurek73757082019-04-18 04:14:37 -04001100 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_C
1101 scripts/config.pl unset MBEDTLS_PSA_ITS_FILE_C
Gilles Peskine8f073122018-11-27 15:58:47 +01001102 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
1103 # following things are not in the default config
1104 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
1105 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
1106 scripts/config.pl unset MBEDTLS_THREADING_C
1107 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
1108 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
1109 scripts/config.pl set MBEDTLS_NO_64BIT_MULTIPLICATION
1110 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -O1 -march=armv6-m -mthumb' lib
1111 echo "Checking that software 64-bit multiplication is not required"
1112 if_build_succeeded not grep __aeabi_lmul library/*.o
1113}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001114
Gilles Peskine8f073122018-11-27 15:58:47 +01001115component_build_armcc () {
1116 msg "build: ARM Compiler 5, make"
Gilles Peskine8f073122018-11-27 15:58:47 +01001117 scripts/config.pl full
1118 scripts/config.pl unset MBEDTLS_NET_C
1119 scripts/config.pl unset MBEDTLS_TIMING_C
1120 scripts/config.pl unset MBEDTLS_FS_IO
1121 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
1122 scripts/config.pl unset MBEDTLS_HAVE_TIME
1123 scripts/config.pl unset MBEDTLS_HAVE_TIME_DATE
1124 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
Andrzej Kurek73757082019-04-18 04:14:37 -04001125 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_C
1126 scripts/config.pl unset MBEDTLS_PSA_ITS_FILE_C
Gilles Peskine8f073122018-11-27 15:58:47 +01001127 # following things are not in the default config
1128 scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
1129 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
1130 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
1131 scripts/config.pl unset MBEDTLS_THREADING_C
1132 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
1133 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
1134 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT # depends on MBEDTLS_HAVE_TIME
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001135
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001136 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
1137 make clean
Andres AG87bb5772016-09-27 15:05:15 +01001138
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001139 # ARM Compiler 6 - Target ARMv7-A
1140 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-a"
Simon Butcher940737f2017-07-23 13:42:36 +02001141
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001142 # ARM Compiler 6 - Target ARMv7-M
1143 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m"
Simon Butcher940737f2017-07-23 13:42:36 +02001144
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001145 # ARM Compiler 6 - Target ARMv8-A - AArch32
1146 armc6_build_test "--target=arm-arm-none-eabi -march=armv8.2-a"
Simon Butcher940737f2017-07-23 13:42:36 +02001147
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001148 # ARM Compiler 6 - Target ARMv8-M
1149 armc6_build_test "--target=arm-arm-none-eabi -march=armv8-m.main"
Simon Butcher940737f2017-07-23 13:42:36 +02001150
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001151 # ARM Compiler 6 - Target ARMv8-A - AArch64
1152 armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a"
Gilles Peskine8f073122018-11-27 15:58:47 +01001153}
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +01001154
Gilles Peskine8f073122018-11-27 15:58:47 +01001155component_test_allow_sha1 () {
1156 msg "build: allow SHA1 in certificates by default"
Gilles Peskine8f073122018-11-27 15:58:47 +01001157 scripts/config.pl set MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
1158 make CFLAGS='-Werror -Wall -Wextra'
1159 msg "test: allow SHA1 in certificates by default"
1160 make test
1161 if_build_succeeded tests/ssl-opt.sh -f SHA-1
1162}
Gilles Peskine2a458da2017-05-12 15:26:58 +02001163
Gilles Peskine8f073122018-11-27 15:58:47 +01001164component_build_mingw () {
1165 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
Andrzej Kurek62faadd2019-04-19 20:10:21 -04001166 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 +00001167
Gilles Peskine8f073122018-11-27 15:58:47 +01001168 # note Make tests only builds the tests, but doesn't run them
Andrzej Kurek62faadd2019-04-19 20:10:21 -04001169 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 +01001170 make WINDOWS_BUILD=1 clean
Gilles Peskine2a458da2017-05-12 15:26:58 +02001171
Gilles Peskine8f073122018-11-27 15:58:47 +01001172 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
Andrzej Kurek87615772019-04-19 15:03:58 -04001173 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
1174 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 +01001175 make WINDOWS_BUILD=1 clean
1176}
Jaeden Amero117b8a42019-04-17 15:19:26 +01001177support_build_mingw() {
1178 case $(i686-w64-mingw32-gcc -dumpversion) in
1179 [0-5]*) false;;
1180 *) true;;
1181 esac
1182}
Simon Butcher91aef332016-11-17 09:20:50 +00001183
Gilles Peskine8f073122018-11-27 15:58:47 +01001184component_test_memsan () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001185 msg "build: MSan (clang)" # ~ 1 min 20s
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001186 scripts/config.pl unset MBEDTLS_AESNI_C # memsan doesn't grok asm
1187 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
1188 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +02001189
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001190 msg "test: main suites (MSan)" # ~ 10s
1191 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001192
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001193 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
Gilles Peskine7c652162017-12-11 00:01:40 +01001194 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001195
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001196 # Optional part(s)
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001197
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001198 if [ "$MEMORY" -gt 0 ]; then
1199 msg "test: compat.sh (MSan)" # ~ 6 min 20s
Gilles Peskine7c652162017-12-11 00:01:40 +01001200 if_build_succeeded tests/compat.sh
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001201 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001202}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001203
Gilles Peskine69f190e2019-01-10 00:11:42 +01001204component_test_valgrind () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001205 msg "build: Release (clang)"
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001206 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
1207 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001208
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001209 msg "test: main suites valgrind (Release)"
1210 make memcheck
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001211
Gilles Peskinef1349e42019-04-08 17:00:56 +02001212 # Optional parts (slow; currently broken on OS X because programs don't
1213 # seem to receive signals under valgrind on OS X).
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001214 if [ "$MEMORY" -gt 0 ]; then
1215 msg "test: ssl-opt.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +01001216 if_build_succeeded tests/ssl-opt.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001217 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001218
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001219 if [ "$MEMORY" -gt 1 ]; then
1220 msg "test: compat.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +01001221 if_build_succeeded tests/compat.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001222 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001223}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001224
Gilles Peskine8f073122018-11-27 15:58:47 +01001225component_test_cmake_out_of_source () {
1226 msg "build: cmake 'out-of-source' build"
Gilles Peskine8f073122018-11-27 15:58:47 +01001227 MBEDTLS_ROOT_DIR="$PWD"
1228 mkdir "$OUT_OF_SOURCE_DIR"
1229 cd "$OUT_OF_SOURCE_DIR"
1230 cmake "$MBEDTLS_ROOT_DIR"
1231 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001232
Gilles Peskine8f073122018-11-27 15:58:47 +01001233 msg "test: cmake 'out-of-source' build"
1234 make test
1235 # Test an SSL option that requires an auxiliary script in test/scripts/.
1236 # Also ensure that there are no error messages such as
1237 # "No such file or directory", which would indicate that some required
1238 # file is missing (ssl-opt.sh tolerates the absence of some files so
1239 # may exit with status 0 but emit errors).
1240 if_build_succeeded ./tests/ssl-opt.sh -f 'Fallback SCSV: beginning of list' 2>ssl-opt.err
1241 if [ -s ssl-opt.err ]; then
1242 cat ssl-opt.err >&2
1243 record_status [ ! -s ssl-opt.err ]
1244 rm ssl-opt.err
1245 fi
1246 cd "$MBEDTLS_ROOT_DIR"
1247 rm -rf "$OUT_OF_SOURCE_DIR"
1248 unset MBEDTLS_ROOT_DIR
1249}
Andres AGdc192212016-08-31 17:33:13 +01001250
Gilles Peskine8f073122018-11-27 15:58:47 +01001251component_test_zeroize () {
1252 # Test that the function mbedtls_platform_zeroize() is not optimized away by
1253 # different combinations of compilers and optimization flags by using an
1254 # auxiliary GDB script. Unfortunately, GDB does not return error values to the
1255 # system in all cases that the script fails, so we must manually search the
1256 # output to check whether the pass string is present and no failure strings
1257 # were printed.
Andres AGdc192212016-08-31 17:33:13 +01001258
Gilles Peskine4976e822019-01-06 19:52:22 +00001259 # Don't try to disable ASLR. We don't care about ASLR here. We do care
1260 # about a spurious message if Gdb tries and fails, so suppress that.
1261 gdb_disable_aslr=
1262 if [ -z "$(gdb -batch -nw -ex 'set disable-randomization off' 2>&1)" ]; then
1263 gdb_disable_aslr='set disable-randomization off'
1264 fi
1265
Gilles Peskine8f073122018-11-27 15:58:47 +01001266 for optimization_flag in -O2 -O3 -Ofast -Os; do
Gilles Peskine55f7c942019-01-09 22:28:21 +01001267 for compiler in clang gcc; do
1268 msg "test: $compiler $optimization_flag, mbedtls_platform_zeroize()"
1269 make programs CC="$compiler" DEBUG=1 CFLAGS="$optimization_flag"
Gilles Peskine4976e822019-01-06 19:52:22 +00001270 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 +01001271 if_build_succeeded grep "The buffer was correctly zeroized" test_zeroize.log
1272 if_build_succeeded not grep -i "error" test_zeroize.log
1273 rm -f test_zeroize.log
1274 make clean
1275 done
Andres Amaya Garcia29673812017-10-25 10:35:51 +01001276 done
Andres Amaya Garciad0d7bf62017-10-25 09:01:31 +01001277
Gilles Peskine4976e822019-01-06 19:52:22 +00001278 unset gdb_disable_aslr
Gilles Peskine8f073122018-11-27 15:58:47 +01001279}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001280
Gilles Peskineaad2ebd2019-02-25 20:26:06 +01001281support_check_python_files () {
1282 type pylint3 >/dev/null 2>/dev/null
1283}
Gilles Peskine8f073122018-11-27 15:58:47 +01001284component_check_python_files () {
1285 msg "Lint: Python scripts"
1286 record_status tests/scripts/check-python-files.sh
1287}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001288
Gilles Peskine8f073122018-11-27 15:58:47 +01001289component_check_generate_test_code () {
1290 msg "uint test: generate_test_code.py"
1291 record_status ./tests/scripts/test_generate_test_code.py
1292}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001293
1294################################################################
1295#### Termination
1296################################################################
1297
Gilles Peskine8f073122018-11-27 15:58:47 +01001298post_report () {
1299 msg "Done, cleaning up"
1300 cleanup
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001301
Gilles Peskine8f073122018-11-27 15:58:47 +01001302 final_report
1303}
1304
1305
1306
1307################################################################
1308#### Run all the things
1309################################################################
1310
Gilles Peskinee48351a2018-11-27 16:06:30 +01001311# Run one component and clean up afterwards.
Gilles Peskine8f073122018-11-27 15:58:47 +01001312run_component () {
Gilles Peskine608953e2019-01-02 18:57:02 +01001313 # Back up the configuration in case the component modifies it.
1314 # The cleanup function will restore it.
1315 cp -p "$CONFIG_H" "$CONFIG_BAK"
Gilles Peskineffcdeff2018-12-04 12:49:28 +01001316 current_component="$1"
Gilles Peskine8f073122018-11-27 15:58:47 +01001317 "$@"
Gilles Peskinee48351a2018-11-27 16:06:30 +01001318 cleanup
Gilles Peskine8f073122018-11-27 15:58:47 +01001319}
1320
1321# Preliminary setup
1322pre_check_environment
1323pre_initialize_variables
1324pre_parse_command_line "$@"
Gilles Peskine348fb9a2018-11-27 17:04:29 +01001325
Gilles Peskine878cf602019-01-06 20:50:38 +00001326pre_check_git
Andrzej Kurekeb508712019-02-14 07:18:59 -05001327pre_check_seedfile
1328
Gilles Peskine878cf602019-01-06 20:50:38 +00001329build_status=0
1330if [ $KEEP_GOING -eq 1 ]; then
1331 pre_setup_keep_going
Gilles Peskine92525112018-11-27 18:15:35 +01001332else
Gilles Peskine878cf602019-01-06 20:50:38 +00001333 record_status () {
1334 "$@"
1335 }
Gilles Peskine8f073122018-11-27 15:58:47 +01001336fi
Gilles Peskine878cf602019-01-06 20:50:38 +00001337pre_print_configuration
1338pre_check_tools
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001339cleanup
1340
Gilles Peskinebeb3a812019-01-06 22:11:25 +00001341# Run the requested tests.
1342for component in $RUN_COMPONENTS; do
1343 run_component "component_$component"
1344done
Gilles Peskine8f073122018-11-27 15:58:47 +01001345
1346# We're done.
Gilles Peskine878cf602019-01-06 20:50:38 +00001347post_report