blob: 98d71fddeb35ba4ff8f9366a89590cadcce66a76 [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
Andrzej Kurekccbff2a2019-02-13 04:28:26 -0500225 command make -C crypto clean
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200226
Gilles Peskine31b07e22018-03-21 12:15:06 +0100227 # Remove CMake artefacts
Jaeden Amero2d0e00f2018-11-07 18:46:41 +0000228 find . -name .git -prune -o \
Gilles Peskine31b07e22018-03-21 12:15:06 +0100229 -iname CMakeFiles -exec rm -rf {} \+ -o \
230 \( -iname cmake_install.cmake -o \
231 -iname CTestTestfile.cmake -o \
232 -iname CMakeCache.txt \) -exec rm {} \+
233 # Recover files overwritten by in-tree CMake builds
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000234 rm -f include/Makefile include/mbedtls/Makefile programs/*/Makefile
Paul Bakkerfe0984d2014-06-13 00:13:45 +0200235 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile
236 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile
Andrzej Kurekccbff2a2019-02-13 04:28:26 -0500237
238 # Crypto submodule cleaning
239 rm -f crypto/include/Makefile crypto/include/mbedtls/Makefile crypto/programs/*/Makefile
240 git -C crypto update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile
241 git -C crypto checkout -- Makefile library/Makefile programs/Makefile tests/Makefile
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200242
243 if [ -f "$CONFIG_BAK" ]; then
244 mv "$CONFIG_BAK" "$CONFIG_H"
245 fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100246}
247
Gilles Peskine7c652162017-12-11 00:01:40 +0100248# Executed on exit. May be redefined depending on command line options.
249final_report () {
250 :
251}
252
253fatal_signal () {
254 cleanup
255 final_report $1
256 trap - $1
257 kill -$1 $$
258}
259
260trap 'fatal_signal HUP' HUP
261trap 'fatal_signal INT' INT
262trap 'fatal_signal TERM' TERM
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200263
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100264msg()
265{
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100266 if [ -n "${current_component:-}" ]; then
267 current_section="${current_component#component_}: $1"
268 else
269 current_section="$1"
270 fi
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100271 echo ""
272 echo "******************************************************************"
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100273 echo "* $current_section "
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000274 printf "* "; date
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100275 echo "******************************************************************"
276}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100277
Gilles Peskine8f073122018-11-27 15:58:47 +0100278armc6_build_test()
279{
280 FLAGS="$1"
Andres AGa5cd9732016-10-17 15:23:10 +0100281
Gilles Peskine8f073122018-11-27 15:58:47 +0100282 msg "build: ARM Compiler 6 ($FLAGS), make"
283 ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \
284 WARNING_CFLAGS='-xc -std=c99' make lib
285 make clean
286}
Andres AGa5cd9732016-10-17 15:23:10 +0100287
Andres AGd9eba4b2016-08-26 14:42:14 +0100288err_msg()
289{
290 echo "$1" >&2
291}
292
293check_tools()
294{
295 for TOOL in "$@"; do
Andres AG98393602017-01-31 17:04:45 +0000296 if ! `type "$TOOL" >/dev/null 2>&1`; then
Andres AGd9eba4b2016-08-26 14:42:14 +0100297 err_msg "$TOOL not found!"
298 exit 1
299 fi
300 done
301}
302
Andrzej Kurek4d3e7102019-02-14 04:07:51 -0500303# objdump_must_contain OBJECT_FILE MANDATORY_RE [MATCHING_LINES_MUST_NOT_INCLUDE]
Andrzej Kurekccbff2a2019-02-13 04:28:26 -0500304objdump_must_contain () {
Andrzej Kurek4d3e7102019-02-14 04:07:51 -0500305 objdump -g "$1" | grep -E "$2" |
306 if [ -n "$3" ]; then ! grep -q -E "$3"; else cat; fi
Andrzej Kurekccbff2a2019-02-13 04:28:26 -0500307}
308
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400309check_headers_in_cpp () {
310 ls include/mbedtls >headers.txt
311 <programs/test/cpp_dummy_build.cpp sed -n 's/"$//; s!^#include "mbedtls/!!p' |
312 sort |
313 diff headers.txt -
314 rm headers.txt
315}
316
Gilles Peskine8f073122018-11-27 15:58:47 +0100317pre_parse_command_line () {
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000318 COMMAND_LINE_COMPONENTS=
Gilles Peskinea28db922019-01-10 00:05:18 +0100319 all_except=0
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000320 no_armcc=
SimonB2e23c822016-04-16 21:54:39 +0100321
Gilles Peskine8f073122018-11-27 15:58:47 +0100322 while [ $# -gt 0 ]; do
Gilles Peskine55f7c942019-01-09 22:28:21 +0100323 case "$1" in
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000324 --armcc) no_armcc=;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100325 --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
326 --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000327 --except) all_except=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100328 --force|-f) FORCE=1;;
329 --gnutls-cli) shift; GNUTLS_CLI="$1";;
330 --gnutls-legacy-cli) shift; GNUTLS_LEGACY_CLI="$1";;
331 --gnutls-legacy-serv) shift; GNUTLS_LEGACY_SERV="$1";;
332 --gnutls-serv) shift; GNUTLS_SERV="$1";;
333 --help|-h) usage; exit;;
334 --keep-going|-k) KEEP_GOING=1;;
Gilles Peskine878cf602019-01-06 20:50:38 +0000335 --list-all-components) printf '%s\n' $ALL_COMPONENTS; exit;;
336 --list-components) printf '%s\n' $SUPPORTED_COMPONENTS; exit;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100337 --memory|-m) MEMORY=1;;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000338 --no-armcc) no_armcc=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100339 --no-force) FORCE=0;;
340 --no-keep-going) KEEP_GOING=0;;
341 --no-memory) MEMORY=0;;
342 --openssl) shift; OPENSSL="$1";;
343 --openssl-legacy) shift; OPENSSL_LEGACY="$1";;
344 --openssl-next) shift; OPENSSL_NEXT="$1";;
345 --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
346 --random-seed) unset SEED;;
347 --release-test|-r) SEED=1;;
348 --seed|-s) shift; SEED="$1";;
349 -*)
350 echo >&2 "Unknown option: $1"
351 echo >&2 "Run $0 --help for usage."
352 exit 120
353 ;;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000354 *) COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS $1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100355 esac
356 shift
Gilles Peskine8f073122018-11-27 15:58:47 +0100357 done
SimonB2e23c822016-04-16 21:54:39 +0100358
Gilles Peskinea28db922019-01-10 00:05:18 +0100359 # With no list of components, run everything.
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000360 if [ -z "$COMMAND_LINE_COMPONENTS" ]; then
361 all_except=1
Andres AGdc192212016-08-31 17:33:13 +0100362 fi
363
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000364 # --no-armcc is a legacy option. The modern way is --except '*_armcc*'.
365 # Ignore it if components are listed explicitly on the command line.
Gilles Peskinea28db922019-01-10 00:05:18 +0100366 if [ -n "$no_armcc" ] && [ $all_except -eq 1 ]; then
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000367 COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS *_armcc*"
SimonB2e23c822016-04-16 21:54:39 +0100368 fi
SimonB2e23c822016-04-16 21:54:39 +0100369
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000370 # Build the list of components to run.
Gilles Peskinea28db922019-01-10 00:05:18 +0100371 RUN_COMPONENTS=
372 for component in $SUPPORTED_COMPONENTS; do
373 if is_component_included "$component"; [ $? -eq $all_except ]; then
374 RUN_COMPONENTS="$RUN_COMPONENTS $component"
375 fi
376 done
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000377
378 unset all_except
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000379 unset no_armcc
Gilles Peskine8f073122018-11-27 15:58:47 +0100380}
SimonB2e23c822016-04-16 21:54:39 +0100381
Gilles Peskine8f073122018-11-27 15:58:47 +0100382pre_check_git () {
383 if [ $FORCE -eq 1 ]; then
Gilles Peskine53190e62019-01-09 23:17:35 +0100384 rm -rf "$OUT_OF_SOURCE_DIR"
Gilles Peskine8f073122018-11-27 15:58:47 +0100385 git checkout-index -f -q $CONFIG_H
386 cleanup
387 else
SimonB2e23c822016-04-16 21:54:39 +0100388
Gilles Peskine8f073122018-11-27 15:58:47 +0100389 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
390 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
391 echo "You can either delete this directory manually, or force the test by rerunning"
392 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
393 exit 1
394 fi
395
Gilles Peskined1174cf2019-01-09 22:30:01 +0100396 if ! git diff --quiet include/mbedtls/config.h; then
Gilles Peskine8f073122018-11-27 15:58:47 +0100397 err_msg "Warning - the configuration file 'include/mbedtls/config.h' has been edited. "
398 echo "You can either delete or preserve your work, or force the test by rerunning the"
399 echo "script as: $0 --force"
400 exit 1
401 fi
SimonB2e23c822016-04-16 21:54:39 +0100402 fi
Andrzej Kureke9c3b812019-02-05 05:34:21 -0500403 if ! [ -f crypto/Makefile ]; then
404 echo "Please initialize the crypto submodule" >&2
405 exit 1
406 fi
Gilles Peskine8f073122018-11-27 15:58:47 +0100407}
SimonB2e23c822016-04-16 21:54:39 +0100408
Gilles Peskine8f073122018-11-27 15:58:47 +0100409pre_setup_keep_going () {
Gilles Peskine7c652162017-12-11 00:01:40 +0100410 failure_summary=
411 failure_count=0
412 start_red=
413 end_color=
414 if [ -t 1 ]; then
Gilles Peskine9736b9d2018-01-02 21:54:17 +0100415 case "${TERM:-}" in
Gilles Peskine7c652162017-12-11 00:01:40 +0100416 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
417 start_red=$(printf '\033[31m')
418 end_color=$(printf '\033[0m')
419 ;;
420 esac
421 fi
422 record_status () {
423 if "$@"; then
424 last_status=0
425 else
426 last_status=$?
427 text="$current_section: $* -> $last_status"
428 failure_summary="$failure_summary
429$text"
430 failure_count=$((failure_count + 1))
431 echo "${start_red}^^^^$text^^^^${end_color}"
432 fi
433 }
434 make () {
435 case "$*" in
436 *test|*check)
437 if [ $build_status -eq 0 ]; then
438 record_status command make "$@"
439 else
440 echo "(skipped because the build failed)"
441 fi
442 ;;
443 *)
444 record_status command make "$@"
445 build_status=$last_status
446 ;;
447 esac
448 }
449 final_report () {
450 if [ $failure_count -gt 0 ]; then
451 echo
452 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
453 echo "${start_red}FAILED: $failure_count${end_color}$failure_summary"
454 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Jaeden Amero7c1258d2018-07-20 16:42:14 +0100455 exit 1
Gilles Peskine7c652162017-12-11 00:01:40 +0100456 elif [ -z "${1-}" ]; then
457 echo "SUCCESS :)"
458 fi
459 if [ -n "${1-}" ]; then
460 echo "Killed by SIG$1."
461 fi
462 }
Gilles Peskine8f073122018-11-27 15:58:47 +0100463}
464
Gilles Peskine7c652162017-12-11 00:01:40 +0100465if_build_succeeded () {
466 if [ $build_status -eq 0 ]; then
467 record_status "$@"
468 fi
469}
470
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200471# to be used instead of ! for commands run with
472# record_status or if_build_succeeded
473not() {
474 ! "$@"
475}
476
Gilles Peskine8f073122018-11-27 15:58:47 +0100477pre_print_configuration () {
478 msg "info: $0 configuration"
479 echo "MEMORY: $MEMORY"
480 echo "FORCE: $FORCE"
481 echo "SEED: ${SEED-"UNSET"}"
482 echo "OPENSSL: $OPENSSL"
483 echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
484 echo "OPENSSL_NEXT: $OPENSSL_NEXT"
485 echo "GNUTLS_CLI: $GNUTLS_CLI"
486 echo "GNUTLS_SERV: $GNUTLS_SERV"
487 echo "GNUTLS_LEGACY_CLI: $GNUTLS_LEGACY_CLI"
488 echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV"
489 echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
490 echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
491}
Andres AG7770ea82016-10-10 15:46:20 +0100492
Andres AGd9eba4b2016-08-26 14:42:14 +0100493# Make sure the tools we need are available.
Gilles Peskine8f073122018-11-27 15:58:47 +0100494pre_check_tools () {
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000495 # Build the list of variables to pass to output_env.sh.
496 set env
SimonB2e23c822016-04-16 21:54:39 +0100497
Gilles Peskine87964262019-01-06 22:40:00 +0000498 case " $RUN_COMPONENTS " in
499 # Require OpenSSL and GnuTLS if running any tests (as opposed to
500 # only doing builds). Not all tests run OpenSSL and GnuTLS, but this
501 # is a good enough approximation in practice.
502 *" test_"*)
503 # To avoid setting OpenSSL and GnuTLS for each call to compat.sh
504 # and ssl-opt.sh, we just export the variables they require.
505 export OPENSSL_CMD="$OPENSSL"
506 export GNUTLS_CLI="$GNUTLS_CLI"
507 export GNUTLS_SERV="$GNUTLS_SERV"
508 # Avoid passing --seed flag in every call to ssl-opt.sh
509 if [ -n "${SEED-}" ]; then
510 export SEED
511 fi
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000512 set "$@" OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY"
513 set "$@" GNUTLS_CLI="$GNUTLS_CLI" GNUTLS_SERV="$GNUTLS_SERV"
514 set "$@" GNUTLS_LEGACY_CLI="$GNUTLS_LEGACY_CLI"
515 set "$@" GNUTLS_LEGACY_SERV="$GNUTLS_LEGACY_SERV"
Gilles Peskine87964262019-01-06 22:40:00 +0000516 check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$OPENSSL_NEXT" \
517 "$GNUTLS_CLI" "$GNUTLS_SERV" \
518 "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV"
519 ;;
520 esac
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200521
Gilles Peskine87964262019-01-06 22:40:00 +0000522 case " $RUN_COMPONENTS " in
523 *_doxygen[_\ ]*) check_tools "doxygen" "dot";;
524 esac
Andres AGd9eba4b2016-08-26 14:42:14 +0100525
Gilles Peskine87964262019-01-06 22:40:00 +0000526 case " $RUN_COMPONENTS " in
527 *_arm_none_eabi_gcc[_\ ]*) check_tools "arm-none-eabi-gcc";;
528 esac
Andres AGd9eba4b2016-08-26 14:42:14 +0100529
Gilles Peskine87964262019-01-06 22:40:00 +0000530 case " $RUN_COMPONENTS " in
531 *_mingw[_\ ]*) check_tools "i686-w64-mingw32-gcc";;
532 esac
533
534 case " $RUN_COMPONENTS " in
535 *" test_zeroize "*) check_tools "gdb";;
536 esac
537
538 case " $RUN_COMPONENTS " in
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000539 *_armcc*)
Gilles Peskine87964262019-01-06 22:40:00 +0000540 ARMC5_CC="$ARMC5_BIN_DIR/armcc"
541 ARMC5_AR="$ARMC5_BIN_DIR/armar"
542 ARMC6_CC="$ARMC6_BIN_DIR/armclang"
543 ARMC6_AR="$ARMC6_BIN_DIR/armar"
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000544 check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC6_CC" "$ARMC6_AR";;
545 esac
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000546
547 msg "info: output_env.sh"
548 case $RUN_COMPONENTS in
549 *_armcc*)
550 set "$@" ARMC5_CC="$ARMC5_CC" ARMC6_CC="$ARMC6_CC" RUN_ARMCC=1;;
551 *) set "$@" RUN_ARMCC=0;;
552 esac
553 "$@" scripts/output_env.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100554}
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100555
Gilles Peskine192c72f2017-12-21 15:59:21 +0100556
557
558################################################################
559#### Basic checks
560################################################################
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100561
562#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200563# Test Suites to be executed
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100564#
Manuel Pégourié-Gonnard3d404b42015-07-08 21:59:16 +0100565# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200566# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100567# 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 +0200568# time, so start with a GCC build).
569# 2. Minimize total running time, by avoiding useless rebuilds
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100570#
Manuel Pégourié-Gonnard259b08a2016-01-08 16:27:41 +0100571# Indicative running times are given for reference.
572
Gilles Peskine8f073122018-11-27 15:58:47 +0100573component_check_recursion () {
574 msg "test: recursion.pl" # < 1s
575 record_status tests/scripts/recursion.pl library/*.c
576}
Janos Follathb72c6782016-07-19 14:54:17 +0100577
Gilles Peskine8f073122018-11-27 15:58:47 +0100578component_check_generated_files () {
579 msg "test: freshness of generated source files" # < 1s
580 record_status tests/scripts/check-generated-files.sh
581}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200582
Gilles Peskine8f073122018-11-27 15:58:47 +0100583component_check_doxy_blocks () {
584 msg "test: doxygen markup outside doxygen blocks" # < 1s
585 record_status tests/scripts/check-doxy-blocks.pl
586}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200587
Gilles Peskine8f073122018-11-27 15:58:47 +0100588component_check_files () {
589 msg "test: check-files.py" # < 1s
Gilles Peskine8f073122018-11-27 15:58:47 +0100590 record_status tests/scripts/check-files.py
591}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200592
Gilles Peskine8f073122018-11-27 15:58:47 +0100593component_check_names () {
594 msg "test/build: declared and exported names" # < 3s
Gilles Peskine8f073122018-11-27 15:58:47 +0100595 record_status tests/scripts/check-names.sh
596}
Darryl Greena07039c2018-03-13 16:48:16 +0000597
Gilles Peskine8f073122018-11-27 15:58:47 +0100598component_check_doxygen_warnings () {
599 msg "test: doxygen warnings" # ~ 3s
Gilles Peskine8f073122018-11-27 15:58:47 +0100600 record_status tests/scripts/doxygen.sh
601}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200602
Gilles Peskine192c72f2017-12-21 15:59:21 +0100603
604
605################################################################
606#### Build and test many configurations and targets
607################################################################
608
Gilles Peskine8f073122018-11-27 15:58:47 +0100609component_test_default_cmake_gcc_asan () {
610 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100611 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
612 make
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200613
Gilles Peskine8f073122018-11-27 15:58:47 +0100614 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
615 make test
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200616
Gilles Peskine8f073122018-11-27 15:58:47 +0100617 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
618 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200619
Gilles Peskine8f073122018-11-27 15:58:47 +0100620 msg "test: compat.sh (ASan build)" # ~ 6 min
621 if_build_succeeded tests/compat.sh
622}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200623
Gilles Peskine782f4112018-11-27 16:11:09 +0100624component_test_ref_configs () {
625 msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
626 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
627 record_status tests/scripts/test-ref-configs.pl
628}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200629
Gilles Peskine8f073122018-11-27 15:58:47 +0100630component_test_sslv3 () {
631 msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100632 scripts/config.pl set MBEDTLS_SSL_PROTO_SSL3
633 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
634 make
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200635
Gilles Peskine8f073122018-11-27 15:58:47 +0100636 msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
637 make test
Simon Butcher3ea7f522016-03-07 23:22:10 +0000638
Gilles Peskine8f073122018-11-27 15:58:47 +0100639 msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
640 if_build_succeeded tests/compat.sh -m 'tls1 tls1_1 tls1_2 dtls1 dtls1_2'
641 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
Simon Butcher3ea7f522016-03-07 23:22:10 +0000642
Gilles Peskine8f073122018-11-27 15:58:47 +0100643 msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
644 if_build_succeeded tests/ssl-opt.sh
645}
Simon Butcher3ea7f522016-03-07 23:22:10 +0000646
Gilles Peskine8f073122018-11-27 15:58:47 +0100647component_test_no_renegotiation () {
648 msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100649 scripts/config.pl unset MBEDTLS_SSL_RENEGOTIATION
650 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
651 make
Simon Butcher3ea7f522016-03-07 23:22:10 +0000652
Gilles Peskine8f073122018-11-27 15:58:47 +0100653 msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
654 make test
Hanno Becker134c2ab2017-10-12 15:29:50 +0100655
Gilles Peskine8f073122018-11-27 15:58:47 +0100656 msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
657 if_build_succeeded tests/ssl-opt.sh
658}
Hanno Becker134c2ab2017-10-12 15:29:50 +0100659
Gilles Peskine8f073122018-11-27 15:58:47 +0100660component_test_rsa_no_crt () {
661 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100662 scripts/config.pl set MBEDTLS_RSA_NO_CRT
663 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
664 make
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +0100665
Gilles Peskine8f073122018-11-27 15:58:47 +0100666 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
667 make test
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100668
Gilles Peskine8f073122018-11-27 15:58:47 +0100669 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
670 if_build_succeeded tests/ssl-opt.sh -f RSA
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100671
Gilles Peskine8f073122018-11-27 15:58:47 +0100672 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
673 if_build_succeeded tests/compat.sh -t RSA
674}
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100675
Gilles Peskine8f073122018-11-27 15:58:47 +0100676component_test_small_ssl_out_content_len () {
677 msg "build: small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100678 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 16384
679 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
680 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
681 make
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100682
Gilles Peskine8f073122018-11-27 15:58:47 +0100683 msg "test: small SSL_OUT_CONTENT_LEN - ssl-opt.sh MFL and large packet tests"
684 if_build_succeeded tests/ssl-opt.sh -f "Max fragment\|Large packet"
685}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000686
Gilles Peskine8f073122018-11-27 15:58:47 +0100687component_test_small_ssl_in_content_len () {
688 msg "build: small SSL_IN_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100689 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 4096
690 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 16384
691 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
692 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000693
Gilles Peskine8f073122018-11-27 15:58:47 +0100694 msg "test: small SSL_IN_CONTENT_LEN - ssl-opt.sh MFL tests"
695 if_build_succeeded tests/ssl-opt.sh -f "Max fragment"
696}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000697
Gilles Peskine8f073122018-11-27 15:58:47 +0100698component_test_small_ssl_dtls_max_buffering () {
699 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0"
Gilles Peskine8f073122018-11-27 15:58:47 +0100700 scripts/config.pl set MBEDTLS_SSL_DTLS_MAX_BUFFERING 1000
701 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
702 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000703
Gilles Peskine8f073122018-11-27 15:58:47 +0100704 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0 - ssl-opt.sh specific reordering test"
705 if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer out-of-order hs msg before reassembling next, free buffered msg"
706}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100707
Gilles Peskine8f073122018-11-27 15:58:47 +0100708component_test_small_mbedtls_ssl_dtls_max_buffering () {
709 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1"
Gilles Peskine8f073122018-11-27 15:58:47 +0100710 scripts/config.pl set MBEDTLS_SSL_DTLS_MAX_BUFFERING 240
711 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
712 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100713
Gilles Peskine8f073122018-11-27 15:58:47 +0100714 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1 - ssl-opt.sh specific reordering test"
715 if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer encrypted Finished message, drop for fragmented NewSessionTicket"
716}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100717
Gilles Peskine8f073122018-11-27 15:58:47 +0100718component_test_full_cmake_clang () {
719 msg "build: cmake, full config, clang" # ~ 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100720 scripts/config.pl full
721 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
722 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check -D ENABLE_TESTING=On .
723 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100724
Gilles Peskine8f073122018-11-27 15:58:47 +0100725 msg "test: main suites (full config)" # ~ 5s
726 make test
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100727
Gilles Peskine8f073122018-11-27 15:58:47 +0100728 msg "test: ssl-opt.sh default, ECJPAKE, SSL async (full config)" # ~ 1s
729 if_build_succeeded tests/ssl-opt.sh -f 'Default\|ECJPAKE\|SSL async private'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200730
Gilles Peskine8f073122018-11-27 15:58:47 +0100731 msg "test: compat.sh RC4, DES & NULL (full config)" # ~ 2 min
732 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" GNUTLS_CLI="$GNUTLS_LEGACY_CLI" GNUTLS_SERV="$GNUTLS_LEGACY_SERV" tests/compat.sh -e '3DES\|DES-CBC3' -f 'NULL\|DES\|RC4\|ARCFOUR'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200733
Gilles Peskine8f073122018-11-27 15:58:47 +0100734 msg "test: compat.sh ARIA + ChachaPoly"
735 if_build_succeeded env OPENSSL_CMD="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
736}
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200737
Gilles Peskine8f073122018-11-27 15:58:47 +0100738component_build_deprecated () {
739 msg "build: make, full config + DEPRECATED_WARNING, gcc -O" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100740 scripts/config.pl full
741 scripts/config.pl set MBEDTLS_DEPRECATED_WARNING
742 # Build with -O -Wextra to catch a maximum of issues.
743 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra' lib programs
744 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100745
Gilles Peskine8f073122018-11-27 15:58:47 +0100746 msg "build: make, full config + DEPRECATED_REMOVED, clang -O" # ~ 30s
747 # No cleanup, just tweak the configuration and rebuild
748 make clean
749 scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
750 scripts/config.pl set MBEDTLS_DEPRECATED_REMOVED
751 # Build with -O -Wextra to catch a maximum of issues.
752 make CC=clang CFLAGS='-O -Werror -Wall -Wextra' lib programs
753 make CC=clang CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
754}
Jaeden Ameroed93bdc2018-11-02 16:57:24 +0000755
Jaeden Ameroed93bdc2018-11-02 16:57:24 +0000756
Gilles Peskine8f073122018-11-27 15:58:47 +0100757component_test_depends_curves () {
758 msg "test/build: curves.pl (gcc)" # ~ 4 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100759 record_status tests/scripts/curves.pl
760}
Jaeden Ameroacaabe72018-11-07 11:52:52 +0000761
Gilles Peskine8f073122018-11-27 15:58:47 +0100762component_test_depends_hashes () {
763 msg "test/build: depends-hashes.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100764 record_status tests/scripts/depends-hashes.pl
765}
Jaeden Ameroacaabe72018-11-07 11:52:52 +0000766
Gilles Peskine8f073122018-11-27 15:58:47 +0100767component_test_depends_pkalgs () {
768 msg "test/build: depends-pkalgs.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100769 record_status tests/scripts/depends-pkalgs.pl
770}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100771
Gilles Peskine8f073122018-11-27 15:58:47 +0100772component_build_key_exchanges () {
773 msg "test/build: key-exchanges (gcc)" # ~ 1 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100774 record_status tests/scripts/key-exchanges.pl
775}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100776
Gilles Peskine8f073122018-11-27 15:58:47 +0100777component_build_default_make_gcc_and_cxx () {
778 msg "build: Unix make, -Os (gcc)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100779 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100780
Gilles Peskine8f073122018-11-27 15:58:47 +0100781 msg "test: verify header list in cpp_dummy_build.cpp"
782 record_status check_headers_in_cpp
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100783
Gilles Peskine8f073122018-11-27 15:58:47 +0100784 msg "build: Unix make, incremental g++"
785 make TEST_CPP=1
786}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100787
Andrzej Kurek1767e402019-02-05 06:05:49 -0500788component_test_submodule_cmake () {
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500789 # USE_CRYPTO_SUBMODULE: check that the build works with CMake
790 msg "build: cmake, full config + USE_CRYPTO_SUBMODULE, gcc+debug"
791 scripts/config.pl full # enables md4 and submodule doesn't enable md4
792 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
793 CC=gcc cmake -D USE_CRYPTO_SUBMODULE=1 -D CMAKE_BUILD_TYPE=Debug .
794 make
795 msg "test: top-level libmbedcrypto wasn't built (USE_CRYPTO_SUBMODULE, cmake)"
796 if_build_succeeded not test -f library/libmbedcrypto.a
797 msg "test: libmbedcrypto symbols are from crypto files (USE_CRYPTO_SUBMODULE, cmake)"
Andrzej Kurekccbff2a2019-02-13 04:28:26 -0500798 if_build_succeeded objdump_must_contain crypto/library/libmbedcrypto.a 'crypto/library$'
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500799 msg "test: libmbedcrypto uses top-level config (USE_CRYPTO_SUBMODULE, cmake)"
Andrzej Kurekccbff2a2019-02-13 04:28:26 -0500800 if_build_succeeded objdump_must_contain crypto/library/libmbedcrypto.a '^md4\.c'
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500801 msg "test: main suites (USE_CRYPTO_SUBMODULE, cmake)"
802 make test
803 msg "test: ssl-opt.sh (USE_CRYPTO_SUBMODULE, cmake)"
804 if_build_succeeded tests/ssl-opt.sh
805}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100806
Andrzej Kurek1767e402019-02-05 06:05:49 -0500807component_test_submodule_make () {
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500808 # USE_CRYPTO_SUBMODULE: check that the build works with make
809 msg "build: make, full config + USE_CRYPTO_SUBMODULE, gcc+debug"
810 scripts/config.pl full # enables md4 and submodule doesn't enable md4
811 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
812 make CC=gcc CFLAGS='-g' USE_CRYPTO_SUBMODULE=1
813 msg "test: top-level libmbedcrypto wasn't built (USE_CRYPTO_SUBMODULE, make)"
814 if_build_succeeded not test -f library/libmbedcrypto.a
815 msg "test: libmbedcrypto symbols are from crypto files (USE_CRYPTO_SUBMODULE, make)"
Andrzej Kurekccbff2a2019-02-13 04:28:26 -0500816 if_build_succeeded objdump_must_contain crypto/library/libmbedcrypto.a 'crypto/library$'
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500817 msg "test: libmbedcrypto uses top-level config (USE_CRYPTO_SUBMODULE, make)"
Andrzej Kurekccbff2a2019-02-13 04:28:26 -0500818 if_build_succeeded objdump_must_contain crypto/library/libmbedcrypto.a '^md4\.c'
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500819 msg "test: main suites (USE_CRYPTO_SUBMODULE, make)"
820 make CC=gcc USE_CRYPTO_SUBMODULE=1 test
821 msg "test: ssl-opt.sh (USE_CRYPTO_SUBMODULE, make)"
822 if_build_succeeded tests/ssl-opt.sh
823}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100824
Andrzej Kurek1767e402019-02-05 06:05:49 -0500825component_test_not_submodule_make () {
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500826 # Don't USE_CRYPTO_SUBMODULE: check that the submodule is not used with make
Andrzej Kurekccbff2a2019-02-13 04:28:26 -0500827 msg "build: make, full config without USE_CRYPTO_SUBMODULE, gcc+debug"
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500828 scripts/config.pl full
829 make CC=gcc CFLAGS='-g'
830 msg "test: submodule libmbedcrypto wasn't built (USE_CRYPTO_SUBMODULE, make)"
831 if_build_succeeded not test -f crypto/library/libmbedcrypto.a
832 msg "test: libmbedcrypto symbols are from library files (USE_CRYPTO_SUBMODULE, make)"
Andrzej Kurek4d3e7102019-02-14 04:07:51 -0500833 if_build_succeeded objdump_must_contain library/libmbedcrypto.a 'library$' 'crypto'
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500834}
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200835
Andrzej Kurek1767e402019-02-05 06:05:49 -0500836component_test_not_submodule_cmake () {
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500837 # Don't USE_CRYPTO_SUBMODULE: check that the submodule is not used with CMake
Andrzej Kurekccbff2a2019-02-13 04:28:26 -0500838 msg "build: cmake, full config without USE_CRYPTO_SUBMODULE, gcc+debug"
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500839 scripts/config.pl full
840 CC=gcc cmake -D CMAKE_BUILD_TYPE=Debug .
841 make
842 msg "test: submodule libmbedcrypto wasn't built (USE_CRYPTO_SUBMODULE, cmake)"
843 if_build_succeeded not test -f crypto/library/libmbedcrypto.a
844 msg "test: libmbedcrypto symbols are from library files (USE_CRYPTO_SUBMODULE, cmake)"
Andrzej Kurek4d3e7102019-02-14 04:07:51 -0500845 if_build_succeeded objdump_must_contain library/libmbedcrypto.a 'library$' 'crypto'
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500846}
Manuel Pégourié-Gonnard1fe6bb92017-06-06 11:36:16 +0200847
Andrzej Kurekfd0381a2019-02-05 05:00:02 -0500848component_test_use_psa_crypto_full_cmake_asan() {
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500849 # MBEDTLS_USE_PSA_CRYPTO: run the same set of tests as basic-build-test.sh
850 msg "build: cmake, full config + MBEDTLS_USE_PSA_CRYPTO, ASan"
851 scripts/config.pl full
852 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
853 scripts/config.pl set MBEDTLS_PSA_CRYPTO_C
854 scripts/config.pl set MBEDTLS_USE_PSA_CRYPTO
855 CC=gcc cmake -D USE_CRYPTO_SUBMODULE=1 -D CMAKE_BUILD_TYPE:String=Asan .
856 make
Manuel Pégourié-Gonnard43be6cd2017-06-20 09:53:42 +0200857
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500858 msg "test: main suites (MBEDTLS_USE_PSA_CRYPTO)"
859 make test
Manuel Pégourié-Gonnard503a5ef2015-10-23 09:04:45 +0200860
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500861 msg "test: ssl-opt.sh (MBEDTLS_USE_PSA_CRYPTO)"
862 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100863
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500864 msg "test: compat.sh default (MBEDTLS_USE_PSA_CRYPTO)"
865 if_build_succeeded tests/compat.sh
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400866
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500867 msg "test: compat.sh ssl3 (MBEDTLS_USE_PSA_CRYPTO)"
868 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400869
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500870 msg "test: compat.sh RC4, DES & NULL (MBEDTLS_USE_PSA_CRYPTO)"
871 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 -0500872
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500873 msg "test: compat.sh ARIA + ChachaPoly (MBEDTLS_USE_PSA_CRYPTO)"
874 if_build_succeeded env OPENSSL_CMD="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
875}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500876
Gilles Peskineb28636b2019-01-02 19:06:24 +0100877component_test_check_params_without_platform () {
878 msg "build+test: MBEDTLS_CHECK_PARAMS without MBEDTLS_PLATFORM_C"
879 scripts/config.pl full # includes CHECK_PARAMS
880 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
881 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
882 scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
883 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
884 scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
885 scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
886 scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
887 scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
888 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
889 scripts/config.pl unset MBEDTLS_PLATFORM_C
890 make CC=gcc CFLAGS='-Werror -O1' all test
891}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500892
Gilles Peskineb28636b2019-01-02 19:06:24 +0100893component_test_check_params_silent () {
894 msg "build+test: MBEDTLS_CHECK_PARAMS with alternative MBEDTLS_PARAM_FAILED()"
895 scripts/config.pl full # includes CHECK_PARAMS
896 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
897 sed -i 's/.*\(#define MBEDTLS_PARAM_FAILED( cond )\).*/\1/' "$CONFIG_H"
898 make CC=gcc CFLAGS='-Werror -O1' all test
899}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500900
Gilles Peskine8f073122018-11-27 15:58:47 +0100901component_test_no_platform () {
902 # Full configuration build, without platform support, file IO and net sockets.
903 # This should catch missing mbedtls_printf definitions, and by disabling file
904 # IO, it should catch missing '#include <stdio.h>'
905 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100906 scripts/config.pl full
907 scripts/config.pl unset MBEDTLS_PLATFORM_C
908 scripts/config.pl unset MBEDTLS_NET_C
909 scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
910 scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
911 scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
912 scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
913 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
914 scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
915 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
916 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
917 scripts/config.pl unset MBEDTLS_FS_IO
918 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
919 # to re-enable platform integration features otherwise disabled in C99 builds
920 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -O0 -D_DEFAULT_SOURCE' lib programs
921 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0' test
922}
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +0000923
Gilles Peskine8f073122018-11-27 15:58:47 +0100924component_build_no_std_function () {
925 # catch compile bugs in _uninit functions
926 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100927 scripts/config.pl full
928 scripts/config.pl set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
929 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
930 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
931}
Manuel Pégourié-Gonnarddccb80b2015-06-03 10:20:33 +0100932
Gilles Peskine8f073122018-11-27 15:58:47 +0100933component_build_no_ssl_srv () {
934 msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100935 scripts/config.pl full
936 scripts/config.pl unset MBEDTLS_SSL_SRV_C
937 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
938}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200939
Gilles Peskine8f073122018-11-27 15:58:47 +0100940component_build_no_ssl_cli () {
941 msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100942 scripts/config.pl full
943 scripts/config.pl unset MBEDTLS_SSL_CLI_C
944 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
945}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200946
Gilles Peskine8f073122018-11-27 15:58:47 +0100947component_build_no_sockets () {
948 # Note, C99 compliance can also be tested with the sockets support disabled,
949 # as that requires a POSIX platform (which isn't the same as C99).
950 msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100951 scripts/config.pl full
952 scripts/config.pl unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
953 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
954 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0 -std=c99 -pedantic' lib
955}
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +0200956
Gilles Peskine8f073122018-11-27 15:58:47 +0100957component_test_no_max_fragment_length () {
958 # Run max fragment length tests with MFL disabled
959 msg "build: default config except MFL extension (ASan build)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100960 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
961 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
962 make
Hanno Becker5175ac62017-09-18 15:36:25 +0100963
Gilles Peskine8f073122018-11-27 15:58:47 +0100964 msg "test: ssl-opt.sh, MFL-related tests"
965 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length"
966}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000967
Gilles Peskine8f073122018-11-27 15:58:47 +0100968component_test_no_max_fragment_length_small_ssl_out_content_len () {
969 msg "build: no MFL extension, small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100970 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
971 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 16384
972 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
973 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
974 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000975
Gilles Peskine8f073122018-11-27 15:58:47 +0100976 msg "test: MFL tests (disabled MFL extension case) & large packet tests"
977 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length\|Large buffer"
978}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000979
Gilles Peskine8f073122018-11-27 15:58:47 +0100980component_test_null_entropy () {
981 msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100982 scripts/config.pl set MBEDTLS_TEST_NULL_ENTROPY
983 scripts/config.pl set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
984 scripts/config.pl set MBEDTLS_ENTROPY_C
985 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
986 scripts/config.pl unset MBEDTLS_ENTROPY_HARDWARE_ALT
987 scripts/config.pl unset MBEDTLS_HAVEGE_C
Gilles Peskine5fa32a72019-01-06 19:48:30 +0000988 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan -D UNSAFE_BUILD=ON .
Gilles Peskine8f073122018-11-27 15:58:47 +0100989 make
Janos Follath06c54002016-06-09 13:57:40 +0100990
Gilles Peskine8f073122018-11-27 15:58:47 +0100991 msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)"
992 make test
993}
Janos Follath06c54002016-06-09 13:57:40 +0100994
Gilles Peskine8f073122018-11-27 15:58:47 +0100995component_test_platform_calloc_macro () {
996 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100997 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
998 scripts/config.pl set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
999 scripts/config.pl set MBEDTLS_PLATFORM_FREE_MACRO free
1000 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1001 make
Hanno Beckere5fecec2018-10-11 11:02:52 +01001002
Gilles Peskine8f073122018-11-27 15:58:47 +01001003 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
1004 make test
1005}
Hanno Beckere5fecec2018-10-11 11:02:52 +01001006
Gilles Peskine8f073122018-11-27 15:58:47 +01001007component_test_aes_fewer_tables () {
1008 msg "build: default config with AES_FEWER_TABLES enabled"
Gilles Peskine8f073122018-11-27 15:58:47 +01001009 scripts/config.pl set MBEDTLS_AES_FEWER_TABLES
1010 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01001011
Gilles Peskine8f073122018-11-27 15:58:47 +01001012 msg "test: AES_FEWER_TABLES"
1013 make test
1014}
Hanno Becker83ebf782017-07-07 12:29:15 +01001015
Gilles Peskine8f073122018-11-27 15:58:47 +01001016component_test_aes_rom_tables () {
1017 msg "build: default config with AES_ROM_TABLES enabled"
Gilles Peskine8f073122018-11-27 15:58:47 +01001018 scripts/config.pl set MBEDTLS_AES_ROM_TABLES
1019 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01001020
Gilles Peskine8f073122018-11-27 15:58:47 +01001021 msg "test: AES_ROM_TABLES"
1022 make test
1023}
Hanno Becker83ebf782017-07-07 12:29:15 +01001024
Gilles Peskine8f073122018-11-27 15:58:47 +01001025component_test_aes_fewer_tables_and_rom_tables () {
1026 msg "build: default config with AES_ROM_TABLES and AES_FEWER_TABLES enabled"
Gilles Peskine8f073122018-11-27 15:58:47 +01001027 scripts/config.pl set MBEDTLS_AES_FEWER_TABLES
1028 scripts/config.pl set MBEDTLS_AES_ROM_TABLES
1029 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01001030
Gilles Peskine8f073122018-11-27 15:58:47 +01001031 msg "test: AES_FEWER_TABLES + AES_ROM_TABLES"
1032 make test
1033}
Hanno Becker83ebf782017-07-07 12:29:15 +01001034
Gilles Peskine8f073122018-11-27 15:58:47 +01001035component_test_make_shared () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001036 msg "build/test: make shared" # ~ 40s
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001037 make SHARED=1 all check
Gilles Peskine8f073122018-11-27 15:58:47 +01001038}
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +02001039
Gilles Peskine8f073122018-11-27 15:58:47 +01001040component_test_m32_o0 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001041 # Build once with -O0, to compile out the i386 specific inline assembly
1042 msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
Simon Butcher7a6da6e2018-06-27 21:52:54 +01001043 scripts/config.pl full
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001044 make CC=gcc CFLAGS='-O0 -Werror -Wall -Wextra -m32 -fsanitize=address'
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01001045
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001046 msg "test: i386, make, gcc -O0 (ASan build)"
1047 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01001048}
Gilles Peskine878cf602019-01-06 20:50:38 +00001049support_test_m32_o0 () {
1050 case $(uname -m) in
1051 *64*) true;;
1052 *) false;;
1053 esac
1054}
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001055
Gilles Peskine8f073122018-11-27 15:58:47 +01001056component_test_m32_o1 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001057 # Build again with -O1, to compile in the i386 specific inline assembly
1058 msg "build: i386, make, gcc -O1 (ASan build)" # ~ 30s
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001059 scripts/config.pl full
1060 make CC=gcc CFLAGS='-O1 -Werror -Wall -Wextra -m32 -fsanitize=address'
1061
1062 msg "test: i386, make, gcc -O1 (ASan build)"
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001063 make test
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
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001072 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32'
1073
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_test_have_int32 () {
1085 msg "build: gcc, force 32-bit bignum limbs"
Gilles Peskine8f073122018-11-27 15:58:47 +01001086 scripts/config.pl unset MBEDTLS_HAVE_ASM
1087 scripts/config.pl unset MBEDTLS_AESNI_C
1088 scripts/config.pl unset MBEDTLS_PADLOCK_C
1089 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01001090
Gilles Peskine8f073122018-11-27 15:58:47 +01001091 msg "test: gcc, force 32-bit bignum limbs"
1092 make test
1093}
Andres Amaya Garciafe843a32017-07-20 13:21:34 +01001094
Gilles Peskine8f073122018-11-27 15:58:47 +01001095component_test_have_int64 () {
1096 msg "build: gcc, force 64-bit bignum limbs"
Gilles Peskine8f073122018-11-27 15:58:47 +01001097 scripts/config.pl unset MBEDTLS_HAVE_ASM
1098 scripts/config.pl unset MBEDTLS_AESNI_C
1099 scripts/config.pl unset MBEDTLS_PADLOCK_C
1100 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
Gilles Peskine14c3c062018-01-29 21:25:12 +01001101
Gilles Peskine8f073122018-11-27 15:58:47 +01001102 msg "test: gcc, force 64-bit bignum limbs"
1103 make test
1104}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001105
Gilles Peskine8f073122018-11-27 15:58:47 +01001106component_test_no_udbl_division () {
1107 msg "build: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +01001108 scripts/config.pl full
1109 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
1110 scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
1111 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001112
Gilles Peskine8f073122018-11-27 15:58:47 +01001113 msg "test: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
1114 make test
1115}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001116
Gilles Peskine8f073122018-11-27 15:58:47 +01001117component_test_no_64bit_multiplication () {
1118 msg "build: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +01001119 scripts/config.pl full
1120 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
1121 scripts/config.pl set MBEDTLS_NO_64BIT_MULTIPLICATION
1122 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001123
Gilles Peskine8f073122018-11-27 15:58:47 +01001124 msg "test: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
1125 make test
1126}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001127
Gilles Peskine8f073122018-11-27 15:58:47 +01001128component_build_arm_none_eabi_gcc () {
1129 msg "build: arm-none-eabi-gcc, make" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +01001130 scripts/config.pl full
1131 scripts/config.pl unset MBEDTLS_NET_C
1132 scripts/config.pl unset MBEDTLS_TIMING_C
1133 scripts/config.pl unset MBEDTLS_FS_IO
1134 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
1135 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
1136 # following things are not in the default config
1137 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
1138 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
1139 scripts/config.pl unset MBEDTLS_THREADING_C
1140 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
1141 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
1142 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
1143}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001144
Gilles Peskine8f073122018-11-27 15:58:47 +01001145component_build_arm_none_eabi_gcc_no_udbl_division () {
1146 msg "build: arm-none-eabi-gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +01001147 scripts/config.pl full
1148 scripts/config.pl unset MBEDTLS_NET_C
1149 scripts/config.pl unset MBEDTLS_TIMING_C
1150 scripts/config.pl unset MBEDTLS_FS_IO
1151 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
1152 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
1153 # following things are not in the default config
1154 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
1155 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
1156 scripts/config.pl unset MBEDTLS_THREADING_C
1157 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
1158 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
1159 scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
1160 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
1161 echo "Checking that software 64-bit division is not required"
1162 if_build_succeeded not grep __aeabi_uldiv library/*.o
1163}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001164
Gilles Peskine8f073122018-11-27 15:58:47 +01001165component_build_arm_none_eabi_gcc_no_64bit_multiplication () {
1166 msg "build: arm-none-eabi-gcc MBEDTLS_NO_64BIT_MULTIPLICATION, make" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +01001167 scripts/config.pl full
1168 scripts/config.pl unset MBEDTLS_NET_C
1169 scripts/config.pl unset MBEDTLS_TIMING_C
1170 scripts/config.pl unset MBEDTLS_FS_IO
1171 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
1172 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
1173 # following things are not in the default config
1174 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
1175 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
1176 scripts/config.pl unset MBEDTLS_THREADING_C
1177 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
1178 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
1179 scripts/config.pl set MBEDTLS_NO_64BIT_MULTIPLICATION
1180 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -O1 -march=armv6-m -mthumb' lib
1181 echo "Checking that software 64-bit multiplication is not required"
1182 if_build_succeeded not grep __aeabi_lmul library/*.o
1183}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001184
Gilles Peskine8f073122018-11-27 15:58:47 +01001185component_build_armcc () {
1186 msg "build: ARM Compiler 5, make"
Gilles Peskine8f073122018-11-27 15:58:47 +01001187 scripts/config.pl full
1188 scripts/config.pl unset MBEDTLS_NET_C
1189 scripts/config.pl unset MBEDTLS_TIMING_C
1190 scripts/config.pl unset MBEDTLS_FS_IO
1191 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
1192 scripts/config.pl unset MBEDTLS_HAVE_TIME
1193 scripts/config.pl unset MBEDTLS_HAVE_TIME_DATE
1194 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
1195 # following things are not in the default config
1196 scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
1197 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
1198 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
1199 scripts/config.pl unset MBEDTLS_THREADING_C
1200 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
1201 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
1202 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT # depends on MBEDTLS_HAVE_TIME
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001203
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001204 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
1205 make clean
Andres AG87bb5772016-09-27 15:05:15 +01001206
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001207 # ARM Compiler 6 - Target ARMv7-A
1208 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-a"
Simon Butcher940737f2017-07-23 13:42:36 +02001209
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001210 # ARM Compiler 6 - Target ARMv7-M
1211 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m"
Simon Butcher940737f2017-07-23 13:42:36 +02001212
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001213 # ARM Compiler 6 - Target ARMv8-A - AArch32
1214 armc6_build_test "--target=arm-arm-none-eabi -march=armv8.2-a"
Simon Butcher940737f2017-07-23 13:42:36 +02001215
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001216 # ARM Compiler 6 - Target ARMv8-M
1217 armc6_build_test "--target=arm-arm-none-eabi -march=armv8-m.main"
Simon Butcher940737f2017-07-23 13:42:36 +02001218
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001219 # ARM Compiler 6 - Target ARMv8-A - AArch64
1220 armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a"
Gilles Peskine8f073122018-11-27 15:58:47 +01001221}
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +01001222
Gilles Peskine8f073122018-11-27 15:58:47 +01001223component_test_allow_sha1 () {
1224 msg "build: allow SHA1 in certificates by default"
Gilles Peskine8f073122018-11-27 15:58:47 +01001225 scripts/config.pl set MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
1226 make CFLAGS='-Werror -Wall -Wextra'
1227 msg "test: allow SHA1 in certificates by default"
1228 make test
1229 if_build_succeeded tests/ssl-opt.sh -f SHA-1
1230}
Gilles Peskine2a458da2017-05-12 15:26:58 +02001231
Gilles Peskine8f073122018-11-27 15:58:47 +01001232component_build_mingw () {
1233 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +01001234 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
Hanno Beckere963efa2018-01-03 10:03:43 +00001235
Gilles Peskine8f073122018-11-27 15:58:47 +01001236 # note Make tests only builds the tests, but doesn't run them
1237 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror' WINDOWS_BUILD=1 tests
1238 make WINDOWS_BUILD=1 clean
Simon Butcher002bc622016-11-17 09:27:45 +00001239
Gilles Peskine8f073122018-11-27 15:58:47 +01001240 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
1241 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
1242 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
1243 make WINDOWS_BUILD=1 clean
1244}
Manuel Pégourié-Gonnard6448bce2015-02-16 17:18:36 +01001245
Gilles Peskine8f073122018-11-27 15:58:47 +01001246component_test_memsan () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001247 msg "build: MSan (clang)" # ~ 1 min 20s
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001248 scripts/config.pl unset MBEDTLS_AESNI_C # memsan doesn't grok asm
1249 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
1250 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +02001251
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001252 msg "test: main suites (MSan)" # ~ 10s
1253 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001254
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001255 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
Gilles Peskine7c652162017-12-11 00:01:40 +01001256 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001257
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001258 # Optional part(s)
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001259
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001260 if [ "$MEMORY" -gt 0 ]; then
1261 msg "test: compat.sh (MSan)" # ~ 6 min 20s
Gilles Peskine7c652162017-12-11 00:01:40 +01001262 if_build_succeeded tests/compat.sh
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001263 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001264}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001265
Gilles Peskine69f190e2019-01-10 00:11:42 +01001266component_test_valgrind () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001267 msg "build: Release (clang)"
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001268 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
1269 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001270
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001271 msg "test: main suites valgrind (Release)"
1272 make memcheck
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001273
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001274 # Optional part(s)
1275 # Currently broken, programs don't seem to receive signals
1276 # under valgrind on OS X
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001277
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001278 if [ "$MEMORY" -gt 0 ]; then
1279 msg "test: ssl-opt.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +01001280 if_build_succeeded tests/ssl-opt.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001281 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001282
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001283 if [ "$MEMORY" -gt 1 ]; then
1284 msg "test: compat.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +01001285 if_build_succeeded tests/compat.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001286 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001287}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001288
Gilles Peskine8f073122018-11-27 15:58:47 +01001289component_test_cmake_out_of_source () {
1290 msg "build: cmake 'out-of-source' build"
Gilles Peskine8f073122018-11-27 15:58:47 +01001291 MBEDTLS_ROOT_DIR="$PWD"
1292 mkdir "$OUT_OF_SOURCE_DIR"
1293 cd "$OUT_OF_SOURCE_DIR"
1294 cmake "$MBEDTLS_ROOT_DIR"
1295 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001296
Gilles Peskine8f073122018-11-27 15:58:47 +01001297 msg "test: cmake 'out-of-source' build"
1298 make test
1299 # Test an SSL option that requires an auxiliary script in test/scripts/.
1300 # Also ensure that there are no error messages such as
1301 # "No such file or directory", which would indicate that some required
1302 # file is missing (ssl-opt.sh tolerates the absence of some files so
1303 # may exit with status 0 but emit errors).
1304 if_build_succeeded ./tests/ssl-opt.sh -f 'Fallback SCSV: beginning of list' 2>ssl-opt.err
1305 if [ -s ssl-opt.err ]; then
1306 cat ssl-opt.err >&2
1307 record_status [ ! -s ssl-opt.err ]
1308 rm ssl-opt.err
1309 fi
1310 cd "$MBEDTLS_ROOT_DIR"
1311 rm -rf "$OUT_OF_SOURCE_DIR"
1312 unset MBEDTLS_ROOT_DIR
1313}
Andres AGdc192212016-08-31 17:33:13 +01001314
Gilles Peskine8f073122018-11-27 15:58:47 +01001315component_test_zeroize () {
1316 # Test that the function mbedtls_platform_zeroize() is not optimized away by
1317 # different combinations of compilers and optimization flags by using an
1318 # auxiliary GDB script. Unfortunately, GDB does not return error values to the
1319 # system in all cases that the script fails, so we must manually search the
1320 # output to check whether the pass string is present and no failure strings
1321 # were printed.
Andres AGdc192212016-08-31 17:33:13 +01001322
Gilles Peskine4976e822019-01-06 19:52:22 +00001323 # Don't try to disable ASLR. We don't care about ASLR here. We do care
1324 # about a spurious message if Gdb tries and fails, so suppress that.
1325 gdb_disable_aslr=
1326 if [ -z "$(gdb -batch -nw -ex 'set disable-randomization off' 2>&1)" ]; then
1327 gdb_disable_aslr='set disable-randomization off'
1328 fi
1329
Gilles Peskine8f073122018-11-27 15:58:47 +01001330 for optimization_flag in -O2 -O3 -Ofast -Os; do
Gilles Peskine55f7c942019-01-09 22:28:21 +01001331 for compiler in clang gcc; do
1332 msg "test: $compiler $optimization_flag, mbedtls_platform_zeroize()"
1333 make programs CC="$compiler" DEBUG=1 CFLAGS="$optimization_flag"
Gilles Peskine4976e822019-01-06 19:52:22 +00001334 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 +01001335 if_build_succeeded grep "The buffer was correctly zeroized" test_zeroize.log
1336 if_build_succeeded not grep -i "error" test_zeroize.log
1337 rm -f test_zeroize.log
1338 make clean
1339 done
Andres Amaya Garcia29673812017-10-25 10:35:51 +01001340 done
Andres Amaya Garciad0d7bf62017-10-25 09:01:31 +01001341
Gilles Peskine4976e822019-01-06 19:52:22 +00001342 unset gdb_disable_aslr
Gilles Peskine8f073122018-11-27 15:58:47 +01001343}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001344
Gilles Peskine8f073122018-11-27 15:58:47 +01001345component_check_python_files () {
1346 msg "Lint: Python scripts"
1347 record_status tests/scripts/check-python-files.sh
1348}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001349
Gilles Peskine8f073122018-11-27 15:58:47 +01001350component_check_generate_test_code () {
1351 msg "uint test: generate_test_code.py"
1352 record_status ./tests/scripts/test_generate_test_code.py
1353}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001354
1355################################################################
1356#### Termination
1357################################################################
1358
Gilles Peskine8f073122018-11-27 15:58:47 +01001359post_report () {
1360 msg "Done, cleaning up"
1361 cleanup
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001362
Gilles Peskine8f073122018-11-27 15:58:47 +01001363 final_report
1364}
1365
1366
1367
1368################################################################
1369#### Run all the things
1370################################################################
1371
Gilles Peskinee48351a2018-11-27 16:06:30 +01001372# Run one component and clean up afterwards.
Gilles Peskine8f073122018-11-27 15:58:47 +01001373run_component () {
Gilles Peskine608953e2019-01-02 18:57:02 +01001374 # Back up the configuration in case the component modifies it.
1375 # The cleanup function will restore it.
1376 cp -p "$CONFIG_H" "$CONFIG_BAK"
Gilles Peskineffcdeff2018-12-04 12:49:28 +01001377 current_component="$1"
Gilles Peskine8f073122018-11-27 15:58:47 +01001378 "$@"
Gilles Peskinee48351a2018-11-27 16:06:30 +01001379 cleanup
Gilles Peskine8f073122018-11-27 15:58:47 +01001380}
1381
1382# Preliminary setup
1383pre_check_environment
1384pre_initialize_variables
1385pre_parse_command_line "$@"
Gilles Peskine348fb9a2018-11-27 17:04:29 +01001386
Gilles Peskine878cf602019-01-06 20:50:38 +00001387pre_check_git
1388build_status=0
1389if [ $KEEP_GOING -eq 1 ]; then
1390 pre_setup_keep_going
Gilles Peskine92525112018-11-27 18:15:35 +01001391else
Gilles Peskine878cf602019-01-06 20:50:38 +00001392 record_status () {
1393 "$@"
1394 }
Gilles Peskine8f073122018-11-27 15:58:47 +01001395fi
Gilles Peskine878cf602019-01-06 20:50:38 +00001396pre_print_configuration
1397pre_check_tools
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001398cleanup
1399
Gilles Peskinebeb3a812019-01-06 22:11:25 +00001400# Run the requested tests.
1401for component in $RUN_COMPONENTS; do
1402 run_component "component_$component"
1403done
Gilles Peskine8f073122018-11-27 15:58:47 +01001404
1405# We're done.
Gilles Peskine878cf602019-01-06 20:50:38 +00001406post_report