blob: 2b7f2cd82a1470b55288b1a5bef417b6cbd08e98 [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 Kurekccbff2a2019-02-13 04:28:26 -0500303objdump_must_contain () {
304 objdump -g "$1" | grep -E "$2"
305}
306
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400307check_headers_in_cpp () {
308 ls include/mbedtls >headers.txt
309 <programs/test/cpp_dummy_build.cpp sed -n 's/"$//; s!^#include "mbedtls/!!p' |
310 sort |
311 diff headers.txt -
312 rm headers.txt
313}
314
Gilles Peskine8f073122018-11-27 15:58:47 +0100315pre_parse_command_line () {
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000316 COMMAND_LINE_COMPONENTS=
Gilles Peskinea28db922019-01-10 00:05:18 +0100317 all_except=0
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000318 no_armcc=
SimonB2e23c822016-04-16 21:54:39 +0100319
Gilles Peskine8f073122018-11-27 15:58:47 +0100320 while [ $# -gt 0 ]; do
Gilles Peskine55f7c942019-01-09 22:28:21 +0100321 case "$1" in
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000322 --armcc) no_armcc=;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100323 --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
324 --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000325 --except) all_except=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100326 --force|-f) FORCE=1;;
327 --gnutls-cli) shift; GNUTLS_CLI="$1";;
328 --gnutls-legacy-cli) shift; GNUTLS_LEGACY_CLI="$1";;
329 --gnutls-legacy-serv) shift; GNUTLS_LEGACY_SERV="$1";;
330 --gnutls-serv) shift; GNUTLS_SERV="$1";;
331 --help|-h) usage; exit;;
332 --keep-going|-k) KEEP_GOING=1;;
Gilles Peskine878cf602019-01-06 20:50:38 +0000333 --list-all-components) printf '%s\n' $ALL_COMPONENTS; exit;;
334 --list-components) printf '%s\n' $SUPPORTED_COMPONENTS; exit;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100335 --memory|-m) MEMORY=1;;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000336 --no-armcc) no_armcc=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100337 --no-force) FORCE=0;;
338 --no-keep-going) KEEP_GOING=0;;
339 --no-memory) MEMORY=0;;
340 --openssl) shift; OPENSSL="$1";;
341 --openssl-legacy) shift; OPENSSL_LEGACY="$1";;
342 --openssl-next) shift; OPENSSL_NEXT="$1";;
343 --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
344 --random-seed) unset SEED;;
345 --release-test|-r) SEED=1;;
346 --seed|-s) shift; SEED="$1";;
347 -*)
348 echo >&2 "Unknown option: $1"
349 echo >&2 "Run $0 --help for usage."
350 exit 120
351 ;;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000352 *) COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS $1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100353 esac
354 shift
Gilles Peskine8f073122018-11-27 15:58:47 +0100355 done
SimonB2e23c822016-04-16 21:54:39 +0100356
Gilles Peskinea28db922019-01-10 00:05:18 +0100357 # With no list of components, run everything.
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000358 if [ -z "$COMMAND_LINE_COMPONENTS" ]; then
359 all_except=1
Andres AGdc192212016-08-31 17:33:13 +0100360 fi
361
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000362 # --no-armcc is a legacy option. The modern way is --except '*_armcc*'.
363 # Ignore it if components are listed explicitly on the command line.
Gilles Peskinea28db922019-01-10 00:05:18 +0100364 if [ -n "$no_armcc" ] && [ $all_except -eq 1 ]; then
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000365 COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS *_armcc*"
SimonB2e23c822016-04-16 21:54:39 +0100366 fi
SimonB2e23c822016-04-16 21:54:39 +0100367
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000368 # Build the list of components to run.
Gilles Peskinea28db922019-01-10 00:05:18 +0100369 RUN_COMPONENTS=
370 for component in $SUPPORTED_COMPONENTS; do
371 if is_component_included "$component"; [ $? -eq $all_except ]; then
372 RUN_COMPONENTS="$RUN_COMPONENTS $component"
373 fi
374 done
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000375
376 unset all_except
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000377 unset no_armcc
Gilles Peskine8f073122018-11-27 15:58:47 +0100378}
SimonB2e23c822016-04-16 21:54:39 +0100379
Gilles Peskine8f073122018-11-27 15:58:47 +0100380pre_check_git () {
381 if [ $FORCE -eq 1 ]; then
Gilles Peskine53190e62019-01-09 23:17:35 +0100382 rm -rf "$OUT_OF_SOURCE_DIR"
Gilles Peskine8f073122018-11-27 15:58:47 +0100383 git checkout-index -f -q $CONFIG_H
384 cleanup
385 else
SimonB2e23c822016-04-16 21:54:39 +0100386
Gilles Peskine8f073122018-11-27 15:58:47 +0100387 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
388 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
389 echo "You can either delete this directory manually, or force the test by rerunning"
390 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
391 exit 1
392 fi
393
Gilles Peskined1174cf2019-01-09 22:30:01 +0100394 if ! git diff --quiet include/mbedtls/config.h; then
Gilles Peskine8f073122018-11-27 15:58:47 +0100395 err_msg "Warning - the configuration file 'include/mbedtls/config.h' has been edited. "
396 echo "You can either delete or preserve your work, or force the test by rerunning the"
397 echo "script as: $0 --force"
398 exit 1
399 fi
SimonB2e23c822016-04-16 21:54:39 +0100400 fi
Andrzej Kureke9c3b812019-02-05 05:34:21 -0500401 if ! [ -f crypto/Makefile ]; then
402 echo "Please initialize the crypto submodule" >&2
403 exit 1
404 fi
Gilles Peskine8f073122018-11-27 15:58:47 +0100405}
SimonB2e23c822016-04-16 21:54:39 +0100406
Gilles Peskine8f073122018-11-27 15:58:47 +0100407pre_setup_keep_going () {
Gilles Peskine7c652162017-12-11 00:01:40 +0100408 failure_summary=
409 failure_count=0
410 start_red=
411 end_color=
412 if [ -t 1 ]; then
Gilles Peskine9736b9d2018-01-02 21:54:17 +0100413 case "${TERM:-}" in
Gilles Peskine7c652162017-12-11 00:01:40 +0100414 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
415 start_red=$(printf '\033[31m')
416 end_color=$(printf '\033[0m')
417 ;;
418 esac
419 fi
420 record_status () {
421 if "$@"; then
422 last_status=0
423 else
424 last_status=$?
425 text="$current_section: $* -> $last_status"
426 failure_summary="$failure_summary
427$text"
428 failure_count=$((failure_count + 1))
429 echo "${start_red}^^^^$text^^^^${end_color}"
430 fi
431 }
432 make () {
433 case "$*" in
434 *test|*check)
435 if [ $build_status -eq 0 ]; then
436 record_status command make "$@"
437 else
438 echo "(skipped because the build failed)"
439 fi
440 ;;
441 *)
442 record_status command make "$@"
443 build_status=$last_status
444 ;;
445 esac
446 }
447 final_report () {
448 if [ $failure_count -gt 0 ]; then
449 echo
450 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
451 echo "${start_red}FAILED: $failure_count${end_color}$failure_summary"
452 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Jaeden Amero7c1258d2018-07-20 16:42:14 +0100453 exit 1
Gilles Peskine7c652162017-12-11 00:01:40 +0100454 elif [ -z "${1-}" ]; then
455 echo "SUCCESS :)"
456 fi
457 if [ -n "${1-}" ]; then
458 echo "Killed by SIG$1."
459 fi
460 }
Gilles Peskine8f073122018-11-27 15:58:47 +0100461}
462
Gilles Peskine7c652162017-12-11 00:01:40 +0100463if_build_succeeded () {
464 if [ $build_status -eq 0 ]; then
465 record_status "$@"
466 fi
467}
468
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200469# to be used instead of ! for commands run with
470# record_status or if_build_succeeded
471not() {
472 ! "$@"
473}
474
Gilles Peskine8f073122018-11-27 15:58:47 +0100475pre_print_configuration () {
476 msg "info: $0 configuration"
477 echo "MEMORY: $MEMORY"
478 echo "FORCE: $FORCE"
479 echo "SEED: ${SEED-"UNSET"}"
480 echo "OPENSSL: $OPENSSL"
481 echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
482 echo "OPENSSL_NEXT: $OPENSSL_NEXT"
483 echo "GNUTLS_CLI: $GNUTLS_CLI"
484 echo "GNUTLS_SERV: $GNUTLS_SERV"
485 echo "GNUTLS_LEGACY_CLI: $GNUTLS_LEGACY_CLI"
486 echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV"
487 echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
488 echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
489}
Andres AG7770ea82016-10-10 15:46:20 +0100490
Andres AGd9eba4b2016-08-26 14:42:14 +0100491# Make sure the tools we need are available.
Gilles Peskine8f073122018-11-27 15:58:47 +0100492pre_check_tools () {
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000493 # Build the list of variables to pass to output_env.sh.
494 set env
SimonB2e23c822016-04-16 21:54:39 +0100495
Gilles Peskine87964262019-01-06 22:40:00 +0000496 case " $RUN_COMPONENTS " in
497 # Require OpenSSL and GnuTLS if running any tests (as opposed to
498 # only doing builds). Not all tests run OpenSSL and GnuTLS, but this
499 # is a good enough approximation in practice.
500 *" test_"*)
501 # To avoid setting OpenSSL and GnuTLS for each call to compat.sh
502 # and ssl-opt.sh, we just export the variables they require.
503 export OPENSSL_CMD="$OPENSSL"
504 export GNUTLS_CLI="$GNUTLS_CLI"
505 export GNUTLS_SERV="$GNUTLS_SERV"
506 # Avoid passing --seed flag in every call to ssl-opt.sh
507 if [ -n "${SEED-}" ]; then
508 export SEED
509 fi
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000510 set "$@" OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY"
511 set "$@" GNUTLS_CLI="$GNUTLS_CLI" GNUTLS_SERV="$GNUTLS_SERV"
512 set "$@" GNUTLS_LEGACY_CLI="$GNUTLS_LEGACY_CLI"
513 set "$@" GNUTLS_LEGACY_SERV="$GNUTLS_LEGACY_SERV"
Gilles Peskine87964262019-01-06 22:40:00 +0000514 check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$OPENSSL_NEXT" \
515 "$GNUTLS_CLI" "$GNUTLS_SERV" \
516 "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV"
517 ;;
518 esac
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200519
Gilles Peskine87964262019-01-06 22:40:00 +0000520 case " $RUN_COMPONENTS " in
521 *_doxygen[_\ ]*) check_tools "doxygen" "dot";;
522 esac
Andres AGd9eba4b2016-08-26 14:42:14 +0100523
Gilles Peskine87964262019-01-06 22:40:00 +0000524 case " $RUN_COMPONENTS " in
525 *_arm_none_eabi_gcc[_\ ]*) check_tools "arm-none-eabi-gcc";;
526 esac
Andres AGd9eba4b2016-08-26 14:42:14 +0100527
Gilles Peskine87964262019-01-06 22:40:00 +0000528 case " $RUN_COMPONENTS " in
529 *_mingw[_\ ]*) check_tools "i686-w64-mingw32-gcc";;
530 esac
531
532 case " $RUN_COMPONENTS " in
533 *" test_zeroize "*) check_tools "gdb";;
534 esac
535
536 case " $RUN_COMPONENTS " in
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000537 *_armcc*)
Gilles Peskine87964262019-01-06 22:40:00 +0000538 ARMC5_CC="$ARMC5_BIN_DIR/armcc"
539 ARMC5_AR="$ARMC5_BIN_DIR/armar"
540 ARMC6_CC="$ARMC6_BIN_DIR/armclang"
541 ARMC6_AR="$ARMC6_BIN_DIR/armar"
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000542 check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC6_CC" "$ARMC6_AR";;
543 esac
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000544
545 msg "info: output_env.sh"
546 case $RUN_COMPONENTS in
547 *_armcc*)
548 set "$@" ARMC5_CC="$ARMC5_CC" ARMC6_CC="$ARMC6_CC" RUN_ARMCC=1;;
549 *) set "$@" RUN_ARMCC=0;;
550 esac
551 "$@" scripts/output_env.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100552}
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100553
Gilles Peskine192c72f2017-12-21 15:59:21 +0100554
555
556################################################################
557#### Basic checks
558################################################################
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100559
560#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200561# Test Suites to be executed
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100562#
Manuel Pégourié-Gonnard3d404b42015-07-08 21:59:16 +0100563# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200564# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100565# 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 +0200566# time, so start with a GCC build).
567# 2. Minimize total running time, by avoiding useless rebuilds
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100568#
Manuel Pégourié-Gonnard259b08a2016-01-08 16:27:41 +0100569# Indicative running times are given for reference.
570
Gilles Peskine8f073122018-11-27 15:58:47 +0100571component_check_recursion () {
572 msg "test: recursion.pl" # < 1s
573 record_status tests/scripts/recursion.pl library/*.c
574}
Janos Follathb72c6782016-07-19 14:54:17 +0100575
Gilles Peskine8f073122018-11-27 15:58:47 +0100576component_check_generated_files () {
577 msg "test: freshness of generated source files" # < 1s
578 record_status tests/scripts/check-generated-files.sh
579}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200580
Gilles Peskine8f073122018-11-27 15:58:47 +0100581component_check_doxy_blocks () {
582 msg "test: doxygen markup outside doxygen blocks" # < 1s
583 record_status tests/scripts/check-doxy-blocks.pl
584}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200585
Gilles Peskine8f073122018-11-27 15:58:47 +0100586component_check_files () {
587 msg "test: check-files.py" # < 1s
Gilles Peskine8f073122018-11-27 15:58:47 +0100588 record_status tests/scripts/check-files.py
589}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200590
Gilles Peskine8f073122018-11-27 15:58:47 +0100591component_check_names () {
592 msg "test/build: declared and exported names" # < 3s
Gilles Peskine8f073122018-11-27 15:58:47 +0100593 record_status tests/scripts/check-names.sh
594}
Darryl Greena07039c2018-03-13 16:48:16 +0000595
Gilles Peskine8f073122018-11-27 15:58:47 +0100596component_check_doxygen_warnings () {
597 msg "test: doxygen warnings" # ~ 3s
Gilles Peskine8f073122018-11-27 15:58:47 +0100598 record_status tests/scripts/doxygen.sh
599}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200600
Gilles Peskine192c72f2017-12-21 15:59:21 +0100601
602
603################################################################
604#### Build and test many configurations and targets
605################################################################
606
Gilles Peskine8f073122018-11-27 15:58:47 +0100607component_test_default_cmake_gcc_asan () {
608 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100609 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
610 make
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200611
Gilles Peskine8f073122018-11-27 15:58:47 +0100612 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
613 make test
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200614
Gilles Peskine8f073122018-11-27 15:58:47 +0100615 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
616 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200617
Gilles Peskine8f073122018-11-27 15:58:47 +0100618 msg "test: compat.sh (ASan build)" # ~ 6 min
619 if_build_succeeded tests/compat.sh
620}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200621
Gilles Peskine782f4112018-11-27 16:11:09 +0100622component_test_ref_configs () {
623 msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
624 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
625 record_status tests/scripts/test-ref-configs.pl
626}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200627
Gilles Peskine8f073122018-11-27 15:58:47 +0100628component_test_sslv3 () {
629 msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100630 scripts/config.pl set MBEDTLS_SSL_PROTO_SSL3
631 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
632 make
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200633
Gilles Peskine8f073122018-11-27 15:58:47 +0100634 msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
635 make test
Simon Butcher3ea7f522016-03-07 23:22:10 +0000636
Gilles Peskine8f073122018-11-27 15:58:47 +0100637 msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
638 if_build_succeeded tests/compat.sh -m 'tls1 tls1_1 tls1_2 dtls1 dtls1_2'
639 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
Simon Butcher3ea7f522016-03-07 23:22:10 +0000640
Gilles Peskine8f073122018-11-27 15:58:47 +0100641 msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
642 if_build_succeeded tests/ssl-opt.sh
643}
Simon Butcher3ea7f522016-03-07 23:22:10 +0000644
Gilles Peskine8f073122018-11-27 15:58:47 +0100645component_test_no_renegotiation () {
646 msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100647 scripts/config.pl unset MBEDTLS_SSL_RENEGOTIATION
648 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
649 make
Simon Butcher3ea7f522016-03-07 23:22:10 +0000650
Gilles Peskine8f073122018-11-27 15:58:47 +0100651 msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
652 make test
Hanno Becker134c2ab2017-10-12 15:29:50 +0100653
Gilles Peskine8f073122018-11-27 15:58:47 +0100654 msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
655 if_build_succeeded tests/ssl-opt.sh
656}
Hanno Becker134c2ab2017-10-12 15:29:50 +0100657
Gilles Peskine8f073122018-11-27 15:58:47 +0100658component_test_rsa_no_crt () {
659 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100660 scripts/config.pl set MBEDTLS_RSA_NO_CRT
661 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
662 make
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +0100663
Gilles Peskine8f073122018-11-27 15:58:47 +0100664 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
665 make test
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100666
Gilles Peskine8f073122018-11-27 15:58:47 +0100667 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
668 if_build_succeeded tests/ssl-opt.sh -f RSA
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100669
Gilles Peskine8f073122018-11-27 15:58:47 +0100670 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
671 if_build_succeeded tests/compat.sh -t RSA
672}
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100673
Gilles Peskine8f073122018-11-27 15:58:47 +0100674component_test_small_ssl_out_content_len () {
675 msg "build: small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100676 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 16384
677 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
678 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
679 make
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100680
Gilles Peskine8f073122018-11-27 15:58:47 +0100681 msg "test: small SSL_OUT_CONTENT_LEN - ssl-opt.sh MFL and large packet tests"
682 if_build_succeeded tests/ssl-opt.sh -f "Max fragment\|Large packet"
683}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000684
Gilles Peskine8f073122018-11-27 15:58:47 +0100685component_test_small_ssl_in_content_len () {
686 msg "build: small SSL_IN_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100687 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 4096
688 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 16384
689 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
690 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000691
Gilles Peskine8f073122018-11-27 15:58:47 +0100692 msg "test: small SSL_IN_CONTENT_LEN - ssl-opt.sh MFL tests"
693 if_build_succeeded tests/ssl-opt.sh -f "Max fragment"
694}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000695
Gilles Peskine8f073122018-11-27 15:58:47 +0100696component_test_small_ssl_dtls_max_buffering () {
697 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0"
Gilles Peskine8f073122018-11-27 15:58:47 +0100698 scripts/config.pl set MBEDTLS_SSL_DTLS_MAX_BUFFERING 1000
699 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
700 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000701
Gilles Peskine8f073122018-11-27 15:58:47 +0100702 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0 - ssl-opt.sh specific reordering test"
703 if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer out-of-order hs msg before reassembling next, free buffered msg"
704}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100705
Gilles Peskine8f073122018-11-27 15:58:47 +0100706component_test_small_mbedtls_ssl_dtls_max_buffering () {
707 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1"
Gilles Peskine8f073122018-11-27 15:58:47 +0100708 scripts/config.pl set MBEDTLS_SSL_DTLS_MAX_BUFFERING 240
709 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
710 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100711
Gilles Peskine8f073122018-11-27 15:58:47 +0100712 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1 - ssl-opt.sh specific reordering test"
713 if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer encrypted Finished message, drop for fragmented NewSessionTicket"
714}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100715
Gilles Peskine8f073122018-11-27 15:58:47 +0100716component_test_full_cmake_clang () {
717 msg "build: cmake, full config, clang" # ~ 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100718 scripts/config.pl full
719 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
720 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check -D ENABLE_TESTING=On .
721 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100722
Gilles Peskine8f073122018-11-27 15:58:47 +0100723 msg "test: main suites (full config)" # ~ 5s
724 make test
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100725
Gilles Peskine8f073122018-11-27 15:58:47 +0100726 msg "test: ssl-opt.sh default, ECJPAKE, SSL async (full config)" # ~ 1s
727 if_build_succeeded tests/ssl-opt.sh -f 'Default\|ECJPAKE\|SSL async private'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200728
Gilles Peskine8f073122018-11-27 15:58:47 +0100729 msg "test: compat.sh RC4, DES & NULL (full config)" # ~ 2 min
730 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 +0200731
Gilles Peskine8f073122018-11-27 15:58:47 +0100732 msg "test: compat.sh ARIA + ChachaPoly"
733 if_build_succeeded env OPENSSL_CMD="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
734}
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200735
Gilles Peskine8f073122018-11-27 15:58:47 +0100736component_build_deprecated () {
737 msg "build: make, full config + DEPRECATED_WARNING, gcc -O" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100738 scripts/config.pl full
739 scripts/config.pl set MBEDTLS_DEPRECATED_WARNING
740 # Build with -O -Wextra to catch a maximum of issues.
741 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra' lib programs
742 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100743
Gilles Peskine8f073122018-11-27 15:58:47 +0100744 msg "build: make, full config + DEPRECATED_REMOVED, clang -O" # ~ 30s
745 # No cleanup, just tweak the configuration and rebuild
746 make clean
747 scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
748 scripts/config.pl set MBEDTLS_DEPRECATED_REMOVED
749 # Build with -O -Wextra to catch a maximum of issues.
750 make CC=clang CFLAGS='-O -Werror -Wall -Wextra' lib programs
751 make CC=clang CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
752}
Jaeden Ameroed93bdc2018-11-02 16:57:24 +0000753
Jaeden Ameroed93bdc2018-11-02 16:57:24 +0000754
Gilles Peskine8f073122018-11-27 15:58:47 +0100755component_test_depends_curves () {
756 msg "test/build: curves.pl (gcc)" # ~ 4 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100757 record_status tests/scripts/curves.pl
758}
Jaeden Ameroacaabe72018-11-07 11:52:52 +0000759
Gilles Peskine8f073122018-11-27 15:58:47 +0100760component_test_depends_hashes () {
761 msg "test/build: depends-hashes.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100762 record_status tests/scripts/depends-hashes.pl
763}
Jaeden Ameroacaabe72018-11-07 11:52:52 +0000764
Gilles Peskine8f073122018-11-27 15:58:47 +0100765component_test_depends_pkalgs () {
766 msg "test/build: depends-pkalgs.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100767 record_status tests/scripts/depends-pkalgs.pl
768}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100769
Gilles Peskine8f073122018-11-27 15:58:47 +0100770component_build_key_exchanges () {
771 msg "test/build: key-exchanges (gcc)" # ~ 1 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100772 record_status tests/scripts/key-exchanges.pl
773}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100774
Gilles Peskine8f073122018-11-27 15:58:47 +0100775component_build_default_make_gcc_and_cxx () {
776 msg "build: Unix make, -Os (gcc)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100777 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100778
Gilles Peskine8f073122018-11-27 15:58:47 +0100779 msg "test: verify header list in cpp_dummy_build.cpp"
780 record_status check_headers_in_cpp
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100781
Gilles Peskine8f073122018-11-27 15:58:47 +0100782 msg "build: Unix make, incremental g++"
783 make TEST_CPP=1
784}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100785
Andrzej Kurek1767e402019-02-05 06:05:49 -0500786component_test_submodule_cmake () {
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500787 # USE_CRYPTO_SUBMODULE: check that the build works with CMake
788 msg "build: cmake, full config + USE_CRYPTO_SUBMODULE, gcc+debug"
789 scripts/config.pl full # enables md4 and submodule doesn't enable md4
790 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
791 CC=gcc cmake -D USE_CRYPTO_SUBMODULE=1 -D CMAKE_BUILD_TYPE=Debug .
792 make
793 msg "test: top-level libmbedcrypto wasn't built (USE_CRYPTO_SUBMODULE, cmake)"
794 if_build_succeeded not test -f library/libmbedcrypto.a
795 msg "test: libmbedcrypto symbols are from crypto files (USE_CRYPTO_SUBMODULE, cmake)"
Andrzej Kurekccbff2a2019-02-13 04:28:26 -0500796 if_build_succeeded objdump_must_contain crypto/library/libmbedcrypto.a 'crypto/library$'
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500797 msg "test: libmbedcrypto uses top-level config (USE_CRYPTO_SUBMODULE, cmake)"
Andrzej Kurekccbff2a2019-02-13 04:28:26 -0500798 if_build_succeeded objdump_must_contain crypto/library/libmbedcrypto.a '^md4\.c'
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500799 msg "test: main suites (USE_CRYPTO_SUBMODULE, cmake)"
800 make test
801 msg "test: ssl-opt.sh (USE_CRYPTO_SUBMODULE, cmake)"
802 if_build_succeeded tests/ssl-opt.sh
803}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100804
Andrzej Kurek1767e402019-02-05 06:05:49 -0500805component_test_submodule_make () {
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500806 # USE_CRYPTO_SUBMODULE: check that the build works with make
807 msg "build: make, full config + USE_CRYPTO_SUBMODULE, gcc+debug"
808 scripts/config.pl full # enables md4 and submodule doesn't enable md4
809 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
810 make CC=gcc CFLAGS='-g' USE_CRYPTO_SUBMODULE=1
811 msg "test: top-level libmbedcrypto wasn't built (USE_CRYPTO_SUBMODULE, make)"
812 if_build_succeeded not test -f library/libmbedcrypto.a
813 msg "test: libmbedcrypto symbols are from crypto files (USE_CRYPTO_SUBMODULE, make)"
Andrzej Kurekccbff2a2019-02-13 04:28:26 -0500814 if_build_succeeded objdump_must_contain crypto/library/libmbedcrypto.a 'crypto/library$'
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500815 msg "test: libmbedcrypto uses top-level config (USE_CRYPTO_SUBMODULE, make)"
Andrzej Kurekccbff2a2019-02-13 04:28:26 -0500816 if_build_succeeded objdump_must_contain crypto/library/libmbedcrypto.a '^md4\.c'
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500817 msg "test: main suites (USE_CRYPTO_SUBMODULE, make)"
818 make CC=gcc USE_CRYPTO_SUBMODULE=1 test
819 msg "test: ssl-opt.sh (USE_CRYPTO_SUBMODULE, make)"
820 if_build_succeeded tests/ssl-opt.sh
821}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100822
Andrzej Kurek1767e402019-02-05 06:05:49 -0500823component_test_not_submodule_make () {
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500824 # Don't USE_CRYPTO_SUBMODULE: check that the submodule is not used with make
Andrzej Kurekccbff2a2019-02-13 04:28:26 -0500825 msg "build: make, full config without USE_CRYPTO_SUBMODULE, gcc+debug"
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500826 scripts/config.pl full
827 make CC=gcc CFLAGS='-g'
828 msg "test: submodule libmbedcrypto wasn't built (USE_CRYPTO_SUBMODULE, make)"
829 if_build_succeeded not test -f crypto/library/libmbedcrypto.a
830 msg "test: libmbedcrypto symbols are from library files (USE_CRYPTO_SUBMODULE, make)"
Andrzej Kurekccbff2a2019-02-13 04:28:26 -0500831 if_build_succeeded objdump -g library/libmbedcrypto.a | if_build_succeeded grep -E 'library$' | if_build_succeeded not grep 'crypto' > /dev/null
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500832}
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200833
Andrzej Kurek1767e402019-02-05 06:05:49 -0500834component_test_not_submodule_cmake () {
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500835 # Don't USE_CRYPTO_SUBMODULE: check that the submodule is not used with CMake
Andrzej Kurekccbff2a2019-02-13 04:28:26 -0500836 msg "build: cmake, full config without USE_CRYPTO_SUBMODULE, gcc+debug"
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500837 scripts/config.pl full
838 CC=gcc cmake -D CMAKE_BUILD_TYPE=Debug .
839 make
840 msg "test: submodule libmbedcrypto wasn't built (USE_CRYPTO_SUBMODULE, cmake)"
841 if_build_succeeded not test -f crypto/library/libmbedcrypto.a
842 msg "test: libmbedcrypto symbols are from library files (USE_CRYPTO_SUBMODULE, cmake)"
Andrzej Kurekccbff2a2019-02-13 04:28:26 -0500843 if_build_succeeded objdump -g library/libmbedcrypto.a | if_build_succeeded grep -E 'library$' | if_build_succeeded not grep 'crypto' > /dev/null
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500844}
Manuel Pégourié-Gonnard1fe6bb92017-06-06 11:36:16 +0200845
Andrzej Kurekfd0381a2019-02-05 05:00:02 -0500846component_test_use_psa_crypto_full_cmake_asan() {
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500847 # MBEDTLS_USE_PSA_CRYPTO: run the same set of tests as basic-build-test.sh
848 msg "build: cmake, full config + MBEDTLS_USE_PSA_CRYPTO, ASan"
849 scripts/config.pl full
850 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
851 scripts/config.pl set MBEDTLS_PSA_CRYPTO_C
852 scripts/config.pl set MBEDTLS_USE_PSA_CRYPTO
853 CC=gcc cmake -D USE_CRYPTO_SUBMODULE=1 -D CMAKE_BUILD_TYPE:String=Asan .
854 make
Manuel Pégourié-Gonnard43be6cd2017-06-20 09:53:42 +0200855
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500856 msg "test: main suites (MBEDTLS_USE_PSA_CRYPTO)"
857 make test
Manuel Pégourié-Gonnard503a5ef2015-10-23 09:04:45 +0200858
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500859 msg "test: ssl-opt.sh (MBEDTLS_USE_PSA_CRYPTO)"
860 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100861
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500862 msg "test: compat.sh default (MBEDTLS_USE_PSA_CRYPTO)"
863 if_build_succeeded tests/compat.sh
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400864
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500865 msg "test: compat.sh ssl3 (MBEDTLS_USE_PSA_CRYPTO)"
866 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400867
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500868 msg "test: compat.sh RC4, DES & NULL (MBEDTLS_USE_PSA_CRYPTO)"
869 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 -0500870
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500871 msg "test: compat.sh ARIA + ChachaPoly (MBEDTLS_USE_PSA_CRYPTO)"
872 if_build_succeeded env OPENSSL_CMD="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
873}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500874
Gilles Peskineb28636b2019-01-02 19:06:24 +0100875component_test_check_params_without_platform () {
876 msg "build+test: MBEDTLS_CHECK_PARAMS without MBEDTLS_PLATFORM_C"
877 scripts/config.pl full # includes CHECK_PARAMS
878 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
879 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
880 scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
881 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
882 scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
883 scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
884 scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
885 scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
886 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
887 scripts/config.pl unset MBEDTLS_PLATFORM_C
888 make CC=gcc CFLAGS='-Werror -O1' all test
889}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500890
Gilles Peskineb28636b2019-01-02 19:06:24 +0100891component_test_check_params_silent () {
892 msg "build+test: MBEDTLS_CHECK_PARAMS with alternative MBEDTLS_PARAM_FAILED()"
893 scripts/config.pl full # includes CHECK_PARAMS
894 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
895 sed -i 's/.*\(#define MBEDTLS_PARAM_FAILED( cond )\).*/\1/' "$CONFIG_H"
896 make CC=gcc CFLAGS='-Werror -O1' all test
897}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500898
Gilles Peskine8f073122018-11-27 15:58:47 +0100899component_test_no_platform () {
900 # Full configuration build, without platform support, file IO and net sockets.
901 # This should catch missing mbedtls_printf definitions, and by disabling file
902 # IO, it should catch missing '#include <stdio.h>'
903 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100904 scripts/config.pl full
905 scripts/config.pl unset MBEDTLS_PLATFORM_C
906 scripts/config.pl unset MBEDTLS_NET_C
907 scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
908 scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
909 scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
910 scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
911 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
912 scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
913 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
914 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
915 scripts/config.pl unset MBEDTLS_FS_IO
916 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
917 # to re-enable platform integration features otherwise disabled in C99 builds
918 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -O0 -D_DEFAULT_SOURCE' lib programs
919 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0' test
920}
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +0000921
Gilles Peskine8f073122018-11-27 15:58:47 +0100922component_build_no_std_function () {
923 # catch compile bugs in _uninit functions
924 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100925 scripts/config.pl full
926 scripts/config.pl set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
927 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
928 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
929}
Manuel Pégourié-Gonnarddccb80b2015-06-03 10:20:33 +0100930
Gilles Peskine8f073122018-11-27 15:58:47 +0100931component_build_no_ssl_srv () {
932 msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100933 scripts/config.pl full
934 scripts/config.pl unset MBEDTLS_SSL_SRV_C
935 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
936}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200937
Gilles Peskine8f073122018-11-27 15:58:47 +0100938component_build_no_ssl_cli () {
939 msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100940 scripts/config.pl full
941 scripts/config.pl unset MBEDTLS_SSL_CLI_C
942 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
943}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200944
Gilles Peskine8f073122018-11-27 15:58:47 +0100945component_build_no_sockets () {
946 # Note, C99 compliance can also be tested with the sockets support disabled,
947 # as that requires a POSIX platform (which isn't the same as C99).
948 msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100949 scripts/config.pl full
950 scripts/config.pl unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
951 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
952 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0 -std=c99 -pedantic' lib
953}
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +0200954
Gilles Peskine8f073122018-11-27 15:58:47 +0100955component_test_no_max_fragment_length () {
956 # Run max fragment length tests with MFL disabled
957 msg "build: default config except MFL extension (ASan build)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100958 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
959 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
960 make
Hanno Becker5175ac62017-09-18 15:36:25 +0100961
Gilles Peskine8f073122018-11-27 15:58:47 +0100962 msg "test: ssl-opt.sh, MFL-related tests"
963 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length"
964}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000965
Gilles Peskine8f073122018-11-27 15:58:47 +0100966component_test_no_max_fragment_length_small_ssl_out_content_len () {
967 msg "build: no MFL extension, small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100968 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
969 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 16384
970 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
971 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
972 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000973
Gilles Peskine8f073122018-11-27 15:58:47 +0100974 msg "test: MFL tests (disabled MFL extension case) & large packet tests"
975 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length\|Large buffer"
976}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000977
Gilles Peskine8f073122018-11-27 15:58:47 +0100978component_test_null_entropy () {
979 msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100980 scripts/config.pl set MBEDTLS_TEST_NULL_ENTROPY
981 scripts/config.pl set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
982 scripts/config.pl set MBEDTLS_ENTROPY_C
983 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
984 scripts/config.pl unset MBEDTLS_ENTROPY_HARDWARE_ALT
985 scripts/config.pl unset MBEDTLS_HAVEGE_C
Gilles Peskine5fa32a72019-01-06 19:48:30 +0000986 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan -D UNSAFE_BUILD=ON .
Gilles Peskine8f073122018-11-27 15:58:47 +0100987 make
Janos Follath06c54002016-06-09 13:57:40 +0100988
Gilles Peskine8f073122018-11-27 15:58:47 +0100989 msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)"
990 make test
991}
Janos Follath06c54002016-06-09 13:57:40 +0100992
Gilles Peskine8f073122018-11-27 15:58:47 +0100993component_test_platform_calloc_macro () {
994 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100995 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
996 scripts/config.pl set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
997 scripts/config.pl set MBEDTLS_PLATFORM_FREE_MACRO free
998 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
999 make
Hanno Beckere5fecec2018-10-11 11:02:52 +01001000
Gilles Peskine8f073122018-11-27 15:58:47 +01001001 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
1002 make test
1003}
Hanno Beckere5fecec2018-10-11 11:02:52 +01001004
Gilles Peskine8f073122018-11-27 15:58:47 +01001005component_test_aes_fewer_tables () {
1006 msg "build: default config with AES_FEWER_TABLES enabled"
Gilles Peskine8f073122018-11-27 15:58:47 +01001007 scripts/config.pl set MBEDTLS_AES_FEWER_TABLES
1008 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01001009
Gilles Peskine8f073122018-11-27 15:58:47 +01001010 msg "test: AES_FEWER_TABLES"
1011 make test
1012}
Hanno Becker83ebf782017-07-07 12:29:15 +01001013
Gilles Peskine8f073122018-11-27 15:58:47 +01001014component_test_aes_rom_tables () {
1015 msg "build: default config with AES_ROM_TABLES enabled"
Gilles Peskine8f073122018-11-27 15:58:47 +01001016 scripts/config.pl set MBEDTLS_AES_ROM_TABLES
1017 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01001018
Gilles Peskine8f073122018-11-27 15:58:47 +01001019 msg "test: AES_ROM_TABLES"
1020 make test
1021}
Hanno Becker83ebf782017-07-07 12:29:15 +01001022
Gilles Peskine8f073122018-11-27 15:58:47 +01001023component_test_aes_fewer_tables_and_rom_tables () {
1024 msg "build: default config with AES_ROM_TABLES and AES_FEWER_TABLES enabled"
Gilles Peskine8f073122018-11-27 15:58:47 +01001025 scripts/config.pl set MBEDTLS_AES_FEWER_TABLES
1026 scripts/config.pl set MBEDTLS_AES_ROM_TABLES
1027 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01001028
Gilles Peskine8f073122018-11-27 15:58:47 +01001029 msg "test: AES_FEWER_TABLES + AES_ROM_TABLES"
1030 make test
1031}
Hanno Becker83ebf782017-07-07 12:29:15 +01001032
Gilles Peskine8f073122018-11-27 15:58:47 +01001033component_test_make_shared () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001034 msg "build/test: make shared" # ~ 40s
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001035 make SHARED=1 all check
Gilles Peskine8f073122018-11-27 15:58:47 +01001036}
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +02001037
Gilles Peskine8f073122018-11-27 15:58:47 +01001038component_test_m32_o0 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001039 # Build once with -O0, to compile out the i386 specific inline assembly
1040 msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
Simon Butcher7a6da6e2018-06-27 21:52:54 +01001041 scripts/config.pl full
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001042 make CC=gcc CFLAGS='-O0 -Werror -Wall -Wextra -m32 -fsanitize=address'
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01001043
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001044 msg "test: i386, make, gcc -O0 (ASan build)"
1045 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01001046}
Gilles Peskine878cf602019-01-06 20:50:38 +00001047support_test_m32_o0 () {
1048 case $(uname -m) in
1049 *64*) true;;
1050 *) false;;
1051 esac
1052}
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001053
Gilles Peskine8f073122018-11-27 15:58:47 +01001054component_test_m32_o1 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001055 # Build again with -O1, to compile in the i386 specific inline assembly
1056 msg "build: i386, make, gcc -O1 (ASan build)" # ~ 30s
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001057 scripts/config.pl full
1058 make CC=gcc CFLAGS='-O1 -Werror -Wall -Wextra -m32 -fsanitize=address'
1059
1060 msg "test: i386, make, gcc -O1 (ASan build)"
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001061 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01001062}
Gilles Peskine878cf602019-01-06 20:50:38 +00001063support_test_m32_o1 () {
1064 support_test_m32_o0 "$@"
1065}
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001066
Gilles Peskine8f073122018-11-27 15:58:47 +01001067component_test_mx32 () {
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001068 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
Simon Butcher7a6da6e2018-06-27 21:52:54 +01001069 scripts/config.pl full
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001070 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32'
1071
1072 msg "test: 64-bit ILP32, make, gcc"
1073 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01001074}
Gilles Peskine878cf602019-01-06 20:50:38 +00001075support_test_mx32 () {
1076 case $(uname -m) in
1077 amd64|x86_64) true;;
1078 *) false;;
1079 esac
1080}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001081
Gilles Peskine8f073122018-11-27 15:58:47 +01001082component_test_have_int32 () {
1083 msg "build: gcc, force 32-bit bignum limbs"
Gilles Peskine8f073122018-11-27 15:58:47 +01001084 scripts/config.pl unset MBEDTLS_HAVE_ASM
1085 scripts/config.pl unset MBEDTLS_AESNI_C
1086 scripts/config.pl unset MBEDTLS_PADLOCK_C
1087 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01001088
Gilles Peskine8f073122018-11-27 15:58:47 +01001089 msg "test: gcc, force 32-bit bignum limbs"
1090 make test
1091}
Andres Amaya Garciafe843a32017-07-20 13:21:34 +01001092
Gilles Peskine8f073122018-11-27 15:58:47 +01001093component_test_have_int64 () {
1094 msg "build: gcc, force 64-bit bignum limbs"
Gilles Peskine8f073122018-11-27 15:58:47 +01001095 scripts/config.pl unset MBEDTLS_HAVE_ASM
1096 scripts/config.pl unset MBEDTLS_AESNI_C
1097 scripts/config.pl unset MBEDTLS_PADLOCK_C
1098 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
Gilles Peskine14c3c062018-01-29 21:25:12 +01001099
Gilles Peskine8f073122018-11-27 15:58:47 +01001100 msg "test: gcc, force 64-bit bignum limbs"
1101 make test
1102}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001103
Gilles Peskine8f073122018-11-27 15:58:47 +01001104component_test_no_udbl_division () {
1105 msg "build: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +01001106 scripts/config.pl full
1107 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
1108 scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
1109 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001110
Gilles Peskine8f073122018-11-27 15:58:47 +01001111 msg "test: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
1112 make test
1113}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001114
Gilles Peskine8f073122018-11-27 15:58:47 +01001115component_test_no_64bit_multiplication () {
1116 msg "build: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +01001117 scripts/config.pl full
1118 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
1119 scripts/config.pl set MBEDTLS_NO_64BIT_MULTIPLICATION
1120 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001121
Gilles Peskine8f073122018-11-27 15:58:47 +01001122 msg "test: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
1123 make test
1124}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001125
Gilles Peskine8f073122018-11-27 15:58:47 +01001126component_build_arm_none_eabi_gcc () {
1127 msg "build: arm-none-eabi-gcc, make" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +01001128 scripts/config.pl full
1129 scripts/config.pl unset MBEDTLS_NET_C
1130 scripts/config.pl unset MBEDTLS_TIMING_C
1131 scripts/config.pl unset MBEDTLS_FS_IO
1132 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
1133 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
1134 # following things are not in the default config
1135 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
1136 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
1137 scripts/config.pl unset MBEDTLS_THREADING_C
1138 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
1139 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
1140 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
1141}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001142
Gilles Peskine8f073122018-11-27 15:58:47 +01001143component_build_arm_none_eabi_gcc_no_udbl_division () {
1144 msg "build: arm-none-eabi-gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +01001145 scripts/config.pl full
1146 scripts/config.pl unset MBEDTLS_NET_C
1147 scripts/config.pl unset MBEDTLS_TIMING_C
1148 scripts/config.pl unset MBEDTLS_FS_IO
1149 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
1150 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
1151 # following things are not in the default config
1152 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
1153 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
1154 scripts/config.pl unset MBEDTLS_THREADING_C
1155 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
1156 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
1157 scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
1158 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
1159 echo "Checking that software 64-bit division is not required"
1160 if_build_succeeded not grep __aeabi_uldiv library/*.o
1161}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001162
Gilles Peskine8f073122018-11-27 15:58:47 +01001163component_build_arm_none_eabi_gcc_no_64bit_multiplication () {
1164 msg "build: arm-none-eabi-gcc MBEDTLS_NO_64BIT_MULTIPLICATION, make" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +01001165 scripts/config.pl full
1166 scripts/config.pl unset MBEDTLS_NET_C
1167 scripts/config.pl unset MBEDTLS_TIMING_C
1168 scripts/config.pl unset MBEDTLS_FS_IO
1169 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
1170 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
1171 # following things are not in the default config
1172 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
1173 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
1174 scripts/config.pl unset MBEDTLS_THREADING_C
1175 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
1176 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
1177 scripts/config.pl set MBEDTLS_NO_64BIT_MULTIPLICATION
1178 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -O1 -march=armv6-m -mthumb' lib
1179 echo "Checking that software 64-bit multiplication is not required"
1180 if_build_succeeded not grep __aeabi_lmul library/*.o
1181}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001182
Gilles Peskine8f073122018-11-27 15:58:47 +01001183component_build_armcc () {
1184 msg "build: ARM Compiler 5, make"
Gilles Peskine8f073122018-11-27 15:58:47 +01001185 scripts/config.pl full
1186 scripts/config.pl unset MBEDTLS_NET_C
1187 scripts/config.pl unset MBEDTLS_TIMING_C
1188 scripts/config.pl unset MBEDTLS_FS_IO
1189 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
1190 scripts/config.pl unset MBEDTLS_HAVE_TIME
1191 scripts/config.pl unset MBEDTLS_HAVE_TIME_DATE
1192 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
1193 # following things are not in the default config
1194 scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
1195 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
1196 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
1197 scripts/config.pl unset MBEDTLS_THREADING_C
1198 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
1199 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
1200 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT # depends on MBEDTLS_HAVE_TIME
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001201
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001202 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
1203 make clean
Andres AG87bb5772016-09-27 15:05:15 +01001204
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001205 # ARM Compiler 6 - Target ARMv7-A
1206 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-a"
Simon Butcher940737f2017-07-23 13:42:36 +02001207
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001208 # ARM Compiler 6 - Target ARMv7-M
1209 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m"
Simon Butcher940737f2017-07-23 13:42:36 +02001210
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001211 # ARM Compiler 6 - Target ARMv8-A - AArch32
1212 armc6_build_test "--target=arm-arm-none-eabi -march=armv8.2-a"
Simon Butcher940737f2017-07-23 13:42:36 +02001213
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001214 # ARM Compiler 6 - Target ARMv8-M
1215 armc6_build_test "--target=arm-arm-none-eabi -march=armv8-m.main"
Simon Butcher940737f2017-07-23 13:42:36 +02001216
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001217 # ARM Compiler 6 - Target ARMv8-A - AArch64
1218 armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a"
Gilles Peskine8f073122018-11-27 15:58:47 +01001219}
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +01001220
Gilles Peskine8f073122018-11-27 15:58:47 +01001221component_test_allow_sha1 () {
1222 msg "build: allow SHA1 in certificates by default"
Gilles Peskine8f073122018-11-27 15:58:47 +01001223 scripts/config.pl set MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
1224 make CFLAGS='-Werror -Wall -Wextra'
1225 msg "test: allow SHA1 in certificates by default"
1226 make test
1227 if_build_succeeded tests/ssl-opt.sh -f SHA-1
1228}
Gilles Peskine2a458da2017-05-12 15:26:58 +02001229
Gilles Peskine8f073122018-11-27 15:58:47 +01001230component_build_mingw () {
1231 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +01001232 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 +00001233
Gilles Peskine8f073122018-11-27 15:58:47 +01001234 # note Make tests only builds the tests, but doesn't run them
1235 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror' WINDOWS_BUILD=1 tests
1236 make WINDOWS_BUILD=1 clean
Simon Butcher002bc622016-11-17 09:27:45 +00001237
Gilles Peskine8f073122018-11-27 15:58:47 +01001238 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
1239 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
1240 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
1241 make WINDOWS_BUILD=1 clean
1242}
Manuel Pégourié-Gonnard6448bce2015-02-16 17:18:36 +01001243
Gilles Peskine8f073122018-11-27 15:58:47 +01001244component_test_memsan () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001245 msg "build: MSan (clang)" # ~ 1 min 20s
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001246 scripts/config.pl unset MBEDTLS_AESNI_C # memsan doesn't grok asm
1247 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
1248 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +02001249
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001250 msg "test: main suites (MSan)" # ~ 10s
1251 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001252
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001253 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
Gilles Peskine7c652162017-12-11 00:01:40 +01001254 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001255
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001256 # Optional part(s)
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001257
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001258 if [ "$MEMORY" -gt 0 ]; then
1259 msg "test: compat.sh (MSan)" # ~ 6 min 20s
Gilles Peskine7c652162017-12-11 00:01:40 +01001260 if_build_succeeded tests/compat.sh
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001261 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001262}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001263
Gilles Peskine69f190e2019-01-10 00:11:42 +01001264component_test_valgrind () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001265 msg "build: Release (clang)"
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001266 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
1267 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001268
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001269 msg "test: main suites valgrind (Release)"
1270 make memcheck
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001271
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001272 # Optional part(s)
1273 # Currently broken, programs don't seem to receive signals
1274 # under valgrind on OS X
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001275
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001276 if [ "$MEMORY" -gt 0 ]; then
1277 msg "test: ssl-opt.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +01001278 if_build_succeeded tests/ssl-opt.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001279 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001280
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001281 if [ "$MEMORY" -gt 1 ]; then
1282 msg "test: compat.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +01001283 if_build_succeeded tests/compat.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001284 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001285}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001286
Gilles Peskine8f073122018-11-27 15:58:47 +01001287component_test_cmake_out_of_source () {
1288 msg "build: cmake 'out-of-source' build"
Gilles Peskine8f073122018-11-27 15:58:47 +01001289 MBEDTLS_ROOT_DIR="$PWD"
1290 mkdir "$OUT_OF_SOURCE_DIR"
1291 cd "$OUT_OF_SOURCE_DIR"
1292 cmake "$MBEDTLS_ROOT_DIR"
1293 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001294
Gilles Peskine8f073122018-11-27 15:58:47 +01001295 msg "test: cmake 'out-of-source' build"
1296 make test
1297 # Test an SSL option that requires an auxiliary script in test/scripts/.
1298 # Also ensure that there are no error messages such as
1299 # "No such file or directory", which would indicate that some required
1300 # file is missing (ssl-opt.sh tolerates the absence of some files so
1301 # may exit with status 0 but emit errors).
1302 if_build_succeeded ./tests/ssl-opt.sh -f 'Fallback SCSV: beginning of list' 2>ssl-opt.err
1303 if [ -s ssl-opt.err ]; then
1304 cat ssl-opt.err >&2
1305 record_status [ ! -s ssl-opt.err ]
1306 rm ssl-opt.err
1307 fi
1308 cd "$MBEDTLS_ROOT_DIR"
1309 rm -rf "$OUT_OF_SOURCE_DIR"
1310 unset MBEDTLS_ROOT_DIR
1311}
Andres AGdc192212016-08-31 17:33:13 +01001312
Gilles Peskine8f073122018-11-27 15:58:47 +01001313component_test_zeroize () {
1314 # Test that the function mbedtls_platform_zeroize() is not optimized away by
1315 # different combinations of compilers and optimization flags by using an
1316 # auxiliary GDB script. Unfortunately, GDB does not return error values to the
1317 # system in all cases that the script fails, so we must manually search the
1318 # output to check whether the pass string is present and no failure strings
1319 # were printed.
Andres AGdc192212016-08-31 17:33:13 +01001320
Gilles Peskine4976e822019-01-06 19:52:22 +00001321 # Don't try to disable ASLR. We don't care about ASLR here. We do care
1322 # about a spurious message if Gdb tries and fails, so suppress that.
1323 gdb_disable_aslr=
1324 if [ -z "$(gdb -batch -nw -ex 'set disable-randomization off' 2>&1)" ]; then
1325 gdb_disable_aslr='set disable-randomization off'
1326 fi
1327
Gilles Peskine8f073122018-11-27 15:58:47 +01001328 for optimization_flag in -O2 -O3 -Ofast -Os; do
Gilles Peskine55f7c942019-01-09 22:28:21 +01001329 for compiler in clang gcc; do
1330 msg "test: $compiler $optimization_flag, mbedtls_platform_zeroize()"
1331 make programs CC="$compiler" DEBUG=1 CFLAGS="$optimization_flag"
Gilles Peskine4976e822019-01-06 19:52:22 +00001332 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 +01001333 if_build_succeeded grep "The buffer was correctly zeroized" test_zeroize.log
1334 if_build_succeeded not grep -i "error" test_zeroize.log
1335 rm -f test_zeroize.log
1336 make clean
1337 done
Andres Amaya Garcia29673812017-10-25 10:35:51 +01001338 done
Andres Amaya Garciad0d7bf62017-10-25 09:01:31 +01001339
Gilles Peskine4976e822019-01-06 19:52:22 +00001340 unset gdb_disable_aslr
Gilles Peskine8f073122018-11-27 15:58:47 +01001341}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001342
Gilles Peskine8f073122018-11-27 15:58:47 +01001343component_check_python_files () {
1344 msg "Lint: Python scripts"
1345 record_status tests/scripts/check-python-files.sh
1346}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001347
Gilles Peskine8f073122018-11-27 15:58:47 +01001348component_check_generate_test_code () {
1349 msg "uint test: generate_test_code.py"
1350 record_status ./tests/scripts/test_generate_test_code.py
1351}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001352
1353################################################################
1354#### Termination
1355################################################################
1356
Gilles Peskine8f073122018-11-27 15:58:47 +01001357post_report () {
1358 msg "Done, cleaning up"
1359 cleanup
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001360
Gilles Peskine8f073122018-11-27 15:58:47 +01001361 final_report
1362}
1363
1364
1365
1366################################################################
1367#### Run all the things
1368################################################################
1369
Gilles Peskinee48351a2018-11-27 16:06:30 +01001370# Run one component and clean up afterwards.
Gilles Peskine8f073122018-11-27 15:58:47 +01001371run_component () {
Gilles Peskine608953e2019-01-02 18:57:02 +01001372 # Back up the configuration in case the component modifies it.
1373 # The cleanup function will restore it.
1374 cp -p "$CONFIG_H" "$CONFIG_BAK"
Gilles Peskineffcdeff2018-12-04 12:49:28 +01001375 current_component="$1"
Gilles Peskine8f073122018-11-27 15:58:47 +01001376 "$@"
Gilles Peskinee48351a2018-11-27 16:06:30 +01001377 cleanup
Gilles Peskine8f073122018-11-27 15:58:47 +01001378}
1379
1380# Preliminary setup
1381pre_check_environment
1382pre_initialize_variables
1383pre_parse_command_line "$@"
Gilles Peskine348fb9a2018-11-27 17:04:29 +01001384
Gilles Peskine878cf602019-01-06 20:50:38 +00001385pre_check_git
1386build_status=0
1387if [ $KEEP_GOING -eq 1 ]; then
1388 pre_setup_keep_going
Gilles Peskine92525112018-11-27 18:15:35 +01001389else
Gilles Peskine878cf602019-01-06 20:50:38 +00001390 record_status () {
1391 "$@"
1392 }
Gilles Peskine8f073122018-11-27 15:58:47 +01001393fi
Gilles Peskine878cf602019-01-06 20:50:38 +00001394pre_print_configuration
1395pre_check_tools
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001396cleanup
1397
Gilles Peskinebeb3a812019-01-06 22:11:25 +00001398# Run the requested tests.
1399for component in $RUN_COMPONENTS; do
1400 run_component "component_$component"
1401done
Gilles Peskine8f073122018-11-27 15:58:47 +01001402
1403# We're done.
Gilles Peskine878cf602019-01-06 20:50:38 +00001404post_report