blob: ecb845253058b84f004c2fa1f88e18c476d41554 [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
Antonin Décimod5f47592019-01-23 15:24:37 +0100123 # 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}
Gilles Peskine67c3c3f2020-04-25 22:21:30 +0200134 : ${ARM_GCC_PREFIX:=arm-none-eabi-}
Andres AGdc192212016-08-31 17:33:13 +0100135
Gilles Peskine8f073122018-11-27 15:58:47 +0100136 # if MAKEFLAGS is not set add the -j option to speed up invocations of make
Gilles Peskinea1fc4b52019-01-06 20:15:26 +0000137 if [ -z "${MAKEFLAGS+set}" ]; then
Gilles Peskine8f073122018-11-27 15:58:47 +0100138 export MAKEFLAGS="-j"
139 fi
Gilles Peskine878cf602019-01-06 20:50:38 +0000140
Gilles Peskineff26b042019-10-21 17:11:33 +0200141 # CFLAGS and LDFLAGS for Asan builds that don't use CMake
Gilles Peskineac479062019-10-21 19:06:33 +0200142 ASAN_CFLAGS='-Werror -Wall -Wextra -fsanitize=address,undefined -fno-sanitize-recover=all'
Gilles Peskineff26b042019-10-21 17:11:33 +0200143
Gilles Peskine878cf602019-01-06 20:50:38 +0000144 # Gather the list of available components. These are the functions
145 # defined in this script whose name starts with "component_".
146 # Parse the script with sed, because in sh there is no way to list
147 # defined functions.
148 ALL_COMPONENTS=$(sed -n 's/^ *component_\([0-9A-Z_a-z]*\) *().*/\1/p' <"$0")
149
150 # Exclude components that are not supported on this platform.
151 SUPPORTED_COMPONENTS=
152 for component in $ALL_COMPONENTS; do
153 case $(type "support_$component" 2>&1) in
154 *' function'*)
155 if ! support_$component; then continue; fi;;
156 esac
157 SUPPORTED_COMPONENTS="$SUPPORTED_COMPONENTS $component"
158 done
Gilles Peskine8f073122018-11-27 15:58:47 +0100159}
Andres AG38495a32016-07-12 16:54:33 +0100160
Gilles Peskinea28db922019-01-10 00:05:18 +0100161# Test whether the component $1 is included in the command line patterns.
162is_component_included()
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100163{
164 set -f
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000165 for pattern in $COMMAND_LINE_COMPONENTS; do
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100166 set +f
167 case ${1#component_} in $pattern) return 0;; esac
168 done
169 set +f
170 return 1
171}
172
Simon Butcher41eeccf2016-09-07 00:07:09 +0100173usage()
SimonB2e23c822016-04-16 21:54:39 +0100174{
Gilles Peskine709346a2017-12-10 23:43:39 +0100175 cat <<EOF
Gilles Peskine92525112018-11-27 18:15:35 +0100176Usage: $0 [OPTION]... [COMPONENT]...
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100177Run mbedtls release validation tests.
Gilles Peskine92525112018-11-27 18:15:35 +0100178By default, run all tests. With one or more COMPONENT, run only those.
Gilles Peskinea28db922019-01-10 00:05:18 +0100179COMPONENT can be the name of a component or a shell wildcard pattern.
180
181Examples:
182 $0 "check_*"
183 Run all sanity checks.
184 $0 --no-armcc --except test_memsan
185 Run everything except builds that require armcc and MemSan.
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100186
187Special options:
188 -h|--help Print this help and exit.
Gilles Peskine878cf602019-01-06 20:50:38 +0000189 --list-all-components List all available test components and exit.
190 --list-components List components supported on this platform and exit.
Gilles Peskine709346a2017-12-10 23:43:39 +0100191
192General options:
193 -f|--force Force the tests to overwrite any modified files.
Gilles Peskine7c652162017-12-11 00:01:40 +0100194 -k|--keep-going Run all tests and report errors at the end.
Gilles Peskine709346a2017-12-10 23:43:39 +0100195 -m|--memory Additional optional memory tests.
Gilles Peskine67c3c3f2020-04-25 22:21:30 +0200196 --arm-gcc-prefix=<string> Prefix for gcc as a cross-compiler for arm
197 (default: "${ARM_GCC_PREFIX}")
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100198 --armcc Run ARM Compiler builds (on by default).
Gilles Peskinea28db922019-01-10 00:05:18 +0100199 --except Exclude the COMPONENTs listed on the command line,
200 instead of running only those.
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100201 --no-armcc Skip ARM Compiler builds.
Gilles Peskine38d81652018-03-21 08:40:26 +0100202 --no-force Refuse to overwrite modified files (default).
203 --no-keep-going Stop at the first error (default).
204 --no-memory No additional memory tests (default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100205 --out-of-source-dir=<path> Directory used for CMake out-of-source build tests.
Gilles Peskine38d81652018-03-21 08:40:26 +0100206 --random-seed Use a random seed value for randomized tests (default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100207 -r|--release-test Run this script in release mode. This fixes the seed value to 1.
208 -s|--seed Integer seed value to use for this test run.
209
210Tool path options:
211 --armc5-bin-dir=<ARMC5_bin_dir_path> ARM Compiler 5 bin directory.
212 --armc6-bin-dir=<ARMC6_bin_dir_path> ARM Compiler 6 bin directory.
213 --gnutls-cli=<GnuTLS_cli_path> GnuTLS client executable to use for most tests.
214 --gnutls-serv=<GnuTLS_serv_path> GnuTLS server executable to use for most tests.
215 --gnutls-legacy-cli=<GnuTLS_cli_path> GnuTLS client executable to use for legacy tests.
216 --gnutls-legacy-serv=<GnuTLS_serv_path> GnuTLS server executable to use for legacy tests.
217 --openssl=<OpenSSL_path> OpenSSL executable to use for most tests.
218 --openssl-legacy=<OpenSSL_path> OpenSSL executable to use for legacy tests e.g. SSLv3.
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100219 --openssl-next=<OpenSSL_path> OpenSSL executable to use for recent things like ARIA
Gilles Peskine709346a2017-12-10 23:43:39 +0100220EOF
SimonB2e23c822016-04-16 21:54:39 +0100221}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100222
223# remove built files as well as the cmake cache/config
224cleanup()
225{
Gilles Peskinea71d64c2018-03-21 12:16:57 +0100226 if [ -n "${MBEDTLS_ROOT_DIR+set}" ]; then
227 cd "$MBEDTLS_ROOT_DIR"
228 fi
229
Gilles Peskine7c652162017-12-11 00:01:40 +0100230 command make clean
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200231
Gilles Peskine31b07e22018-03-21 12:15:06 +0100232 # Remove CMake artefacts
Simon Butcher3ad2efd2018-05-02 14:49:38 +0100233 find . -name .git -prune \
Gilles Peskine31b07e22018-03-21 12:15:06 +0100234 -iname CMakeFiles -exec rm -rf {} \+ -o \
235 \( -iname cmake_install.cmake -o \
236 -iname CTestTestfile.cmake -o \
237 -iname CMakeCache.txt \) -exec rm {} \+
238 # Recover files overwritten by in-tree CMake builds
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000239 rm -f include/Makefile include/mbedtls/Makefile programs/*/Makefile
Paul Bakkerfe0984d2014-06-13 00:13:45 +0200240 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile
241 git 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 Kurek991f9fe2018-07-02 09:08:21 -0400303check_headers_in_cpp () {
Peter Kolbus30987072019-02-01 17:19:08 -0600304 ls include/mbedtls | grep "\.h$" >headers.txt
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400305 <programs/test/cpp_dummy_build.cpp sed -n 's/"$//; s!^#include "mbedtls/!!p' |
306 sort |
307 diff headers.txt -
308 rm headers.txt
309}
310
Gilles Peskine8f073122018-11-27 15:58:47 +0100311pre_parse_command_line () {
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000312 COMMAND_LINE_COMPONENTS=
Gilles Peskinea28db922019-01-10 00:05:18 +0100313 all_except=0
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000314 no_armcc=
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000315
Gilles Peskine8f073122018-11-27 15:58:47 +0100316 while [ $# -gt 0 ]; do
Gilles Peskine55f7c942019-01-09 22:28:21 +0100317 case "$1" in
Gilles Peskine67c3c3f2020-04-25 22:21:30 +0200318 --arm-gcc-prefix) shift; ARM_GCC_PREFIX="$1";;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000319 --armcc) no_armcc=;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100320 --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
321 --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000322 --except) all_except=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100323 --force|-f) FORCE=1;;
324 --gnutls-cli) shift; GNUTLS_CLI="$1";;
325 --gnutls-legacy-cli) shift; GNUTLS_LEGACY_CLI="$1";;
326 --gnutls-legacy-serv) shift; GNUTLS_LEGACY_SERV="$1";;
327 --gnutls-serv) shift; GNUTLS_SERV="$1";;
328 --help|-h) usage; exit;;
329 --keep-going|-k) KEEP_GOING=1;;
Gilles Peskine878cf602019-01-06 20:50:38 +0000330 --list-all-components) printf '%s\n' $ALL_COMPONENTS; exit;;
331 --list-components) printf '%s\n' $SUPPORTED_COMPONENTS; exit;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100332 --memory|-m) MEMORY=1;;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000333 --no-armcc) no_armcc=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100334 --no-force) FORCE=0;;
335 --no-keep-going) KEEP_GOING=0;;
336 --no-memory) MEMORY=0;;
337 --openssl) shift; OPENSSL="$1";;
338 --openssl-legacy) shift; OPENSSL_LEGACY="$1";;
339 --openssl-next) shift; OPENSSL_NEXT="$1";;
340 --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
341 --random-seed) unset SEED;;
342 --release-test|-r) SEED=1;;
343 --seed|-s) shift; SEED="$1";;
344 -*)
345 echo >&2 "Unknown option: $1"
346 echo >&2 "Run $0 --help for usage."
347 exit 120
348 ;;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000349 *) COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS $1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100350 esac
351 shift
Gilles Peskine8f073122018-11-27 15:58:47 +0100352 done
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000353
Gilles Peskinea28db922019-01-10 00:05:18 +0100354 # With no list of components, run everything.
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000355 if [ -z "$COMMAND_LINE_COMPONENTS" ]; then
356 all_except=1
357 fi
358
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000359 # --no-armcc is a legacy option. The modern way is --except '*_armcc*'.
360 # Ignore it if components are listed explicitly on the command line.
Gilles Peskinea28db922019-01-10 00:05:18 +0100361 if [ -n "$no_armcc" ] && [ $all_except -eq 1 ]; then
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000362 COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS *_armcc*"
363 fi
364
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000365 # Build the list of components to run.
Gilles Peskinea28db922019-01-10 00:05:18 +0100366 RUN_COMPONENTS=
367 for component in $SUPPORTED_COMPONENTS; do
368 if is_component_included "$component"; [ $? -eq $all_except ]; then
369 RUN_COMPONENTS="$RUN_COMPONENTS $component"
370 fi
371 done
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000372
373 unset all_except
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000374 unset no_armcc
Gilles Peskine8f073122018-11-27 15:58:47 +0100375}
SimonB2e23c822016-04-16 21:54:39 +0100376
Gilles Peskine8f073122018-11-27 15:58:47 +0100377pre_check_git () {
378 if [ $FORCE -eq 1 ]; then
Gilles Peskine53190e62019-01-09 23:17:35 +0100379 rm -rf "$OUT_OF_SOURCE_DIR"
Gilles Peskine8f073122018-11-27 15:58:47 +0100380 git checkout-index -f -q $CONFIG_H
381 cleanup
382 else
SimonB2e23c822016-04-16 21:54:39 +0100383
Gilles Peskine8f073122018-11-27 15:58:47 +0100384 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
385 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
386 echo "You can either delete this directory manually, or force the test by rerunning"
387 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
388 exit 1
389 fi
390
Gilles Peskined1174cf2019-01-09 22:30:01 +0100391 if ! git diff --quiet include/mbedtls/config.h; then
Gilles Peskine8f073122018-11-27 15:58:47 +0100392 err_msg "Warning - the configuration file 'include/mbedtls/config.h' has been edited. "
393 echo "You can either delete or preserve your work, or force the test by rerunning the"
394 echo "script as: $0 --force"
395 exit 1
396 fi
Andres AGdc192212016-08-31 17:33:13 +0100397 fi
Gilles Peskine8f073122018-11-27 15:58:47 +0100398}
Andres AGdc192212016-08-31 17:33:13 +0100399
Gilles Peskine8f073122018-11-27 15:58:47 +0100400pre_setup_keep_going () {
Gilles Peskine7c652162017-12-11 00:01:40 +0100401 failure_summary=
402 failure_count=0
403 start_red=
404 end_color=
405 if [ -t 1 ]; then
Gilles Peskine9736b9d2018-01-02 21:54:17 +0100406 case "${TERM:-}" in
Gilles Peskine7c652162017-12-11 00:01:40 +0100407 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
408 start_red=$(printf '\033[31m')
409 end_color=$(printf '\033[0m')
410 ;;
411 esac
412 fi
413 record_status () {
414 if "$@"; then
415 last_status=0
416 else
417 last_status=$?
418 text="$current_section: $* -> $last_status"
419 failure_summary="$failure_summary
420$text"
421 failure_count=$((failure_count + 1))
422 echo "${start_red}^^^^$text^^^^${end_color}"
423 fi
424 }
425 make () {
426 case "$*" in
427 *test|*check)
428 if [ $build_status -eq 0 ]; then
429 record_status command make "$@"
430 else
431 echo "(skipped because the build failed)"
432 fi
433 ;;
434 *)
435 record_status command make "$@"
436 build_status=$last_status
437 ;;
438 esac
439 }
440 final_report () {
441 if [ $failure_count -gt 0 ]; then
442 echo
443 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
444 echo "${start_red}FAILED: $failure_count${end_color}$failure_summary"
445 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Jaeden Amero7c1258d2018-07-20 16:42:14 +0100446 exit 1
Gilles Peskine7c652162017-12-11 00:01:40 +0100447 elif [ -z "${1-}" ]; then
448 echo "SUCCESS :)"
449 fi
450 if [ -n "${1-}" ]; then
451 echo "Killed by SIG$1."
452 fi
453 }
Gilles Peskine8f073122018-11-27 15:58:47 +0100454}
455
Gilles Peskine7c652162017-12-11 00:01:40 +0100456if_build_succeeded () {
457 if [ $build_status -eq 0 ]; then
458 record_status "$@"
459 fi
460}
461
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200462# to be used instead of ! for commands run with
463# record_status or if_build_succeeded
464not() {
465 ! "$@"
466}
467
Gilles Peskine8f073122018-11-27 15:58:47 +0100468pre_print_configuration () {
469 msg "info: $0 configuration"
470 echo "MEMORY: $MEMORY"
471 echo "FORCE: $FORCE"
472 echo "SEED: ${SEED-"UNSET"}"
473 echo "OPENSSL: $OPENSSL"
474 echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
475 echo "OPENSSL_NEXT: $OPENSSL_NEXT"
476 echo "GNUTLS_CLI: $GNUTLS_CLI"
477 echo "GNUTLS_SERV: $GNUTLS_SERV"
478 echo "GNUTLS_LEGACY_CLI: $GNUTLS_LEGACY_CLI"
479 echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV"
480 echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
481 echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
482}
Andres AG87bb5772016-09-27 15:05:15 +0100483
Gilles Peskine87964262019-01-06 22:40:00 +0000484# Make sure the tools we need are available.
Gilles Peskine8f073122018-11-27 15:58:47 +0100485pre_check_tools () {
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000486 # Build the list of variables to pass to output_env.sh.
487 set env
488
Gilles Peskine87964262019-01-06 22:40:00 +0000489 case " $RUN_COMPONENTS " in
490 # Require OpenSSL and GnuTLS if running any tests (as opposed to
491 # only doing builds). Not all tests run OpenSSL and GnuTLS, but this
492 # is a good enough approximation in practice.
493 *" test_"*)
494 # To avoid setting OpenSSL and GnuTLS for each call to compat.sh
495 # and ssl-opt.sh, we just export the variables they require.
496 export OPENSSL_CMD="$OPENSSL"
497 export GNUTLS_CLI="$GNUTLS_CLI"
498 export GNUTLS_SERV="$GNUTLS_SERV"
499 # Avoid passing --seed flag in every call to ssl-opt.sh
500 if [ -n "${SEED-}" ]; then
501 export SEED
502 fi
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000503 set "$@" OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY"
504 set "$@" GNUTLS_CLI="$GNUTLS_CLI" GNUTLS_SERV="$GNUTLS_SERV"
505 set "$@" GNUTLS_LEGACY_CLI="$GNUTLS_LEGACY_CLI"
506 set "$@" GNUTLS_LEGACY_SERV="$GNUTLS_LEGACY_SERV"
Gilles Peskine87964262019-01-06 22:40:00 +0000507 check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$OPENSSL_NEXT" \
508 "$GNUTLS_CLI" "$GNUTLS_SERV" \
509 "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV"
510 ;;
511 esac
Andres AGd9eba4b2016-08-26 14:42:14 +0100512
Gilles Peskine87964262019-01-06 22:40:00 +0000513 case " $RUN_COMPONENTS " in
514 *_doxygen[_\ ]*) check_tools "doxygen" "dot";;
515 esac
Andres AGb2fdd042016-09-22 14:17:46 +0100516
Gilles Peskine87964262019-01-06 22:40:00 +0000517 case " $RUN_COMPONENTS " in
Gilles Peskine67c3c3f2020-04-25 22:21:30 +0200518 *_arm_none_eabi_gcc[_\ ]*) check_tools "${ARM_GCC_PREFIX}gcc";;
Gilles Peskine87964262019-01-06 22:40:00 +0000519 esac
Andres AG7770ea82016-10-10 15:46:20 +0100520
Gilles Peskine87964262019-01-06 22:40:00 +0000521 case " $RUN_COMPONENTS " in
522 *_mingw[_\ ]*) check_tools "i686-w64-mingw32-gcc";;
523 esac
524
525 case " $RUN_COMPONENTS " in
526 *" test_zeroize "*) check_tools "gdb";;
527 esac
528
529 case " $RUN_COMPONENTS " in
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000530 *_armcc*)
Gilles Peskine87964262019-01-06 22:40:00 +0000531 ARMC5_CC="$ARMC5_BIN_DIR/armcc"
532 ARMC5_AR="$ARMC5_BIN_DIR/armar"
533 ARMC6_CC="$ARMC6_BIN_DIR/armclang"
534 ARMC6_AR="$ARMC6_BIN_DIR/armar"
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000535 check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC6_CC" "$ARMC6_AR";;
536 esac
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000537
538 msg "info: output_env.sh"
539 case $RUN_COMPONENTS in
540 *_armcc*)
541 set "$@" ARMC5_CC="$ARMC5_CC" ARMC6_CC="$ARMC6_CC" RUN_ARMCC=1;;
542 *) set "$@" RUN_ARMCC=0;;
543 esac
544 "$@" scripts/output_env.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100545}
Gilles Peskine192c72f2017-12-21 15:59:21 +0100546
547
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000548
Gilles Peskine192c72f2017-12-21 15:59:21 +0100549################################################################
550#### Basic checks
551################################################################
Andres AGd9eba4b2016-08-26 14:42:14 +0100552
SimonB2e23c822016-04-16 21:54:39 +0100553#
554# Test Suites to be executed
555#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200556# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100557# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard61bc57a2014-08-14 11:29:06 +0200558# and/or are more likely to fail than others (eg I use Clang most of the
559# time, so start with a GCC build).
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200560# 2. Minimize total running time, by avoiding useless rebuilds
561#
562# Indicative running times are given for reference.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100563
Gilles Peskine8f073122018-11-27 15:58:47 +0100564component_check_recursion () {
565 msg "test: recursion.pl" # < 1s
566 record_status tests/scripts/recursion.pl library/*.c
567}
Manuel Pégourié-Gonnardea29d152014-11-20 17:32:33 +0100568
Gilles Peskine8f073122018-11-27 15:58:47 +0100569component_check_generated_files () {
570 msg "test: freshness of generated source files" # < 1s
571 record_status tests/scripts/check-generated-files.sh
572}
Manuel Pégourié-Gonnardb3b8e432015-02-13 14:52:19 +0000573
Gilles Peskine8f073122018-11-27 15:58:47 +0100574component_check_doxy_blocks () {
575 msg "test: doxygen markup outside doxygen blocks" # < 1s
576 record_status tests/scripts/check-doxy-blocks.pl
577}
Manuel Pégourié-Gonnardd09a6b52015-04-09 17:19:23 +0200578
Gilles Peskine8f073122018-11-27 15:58:47 +0100579component_check_files () {
580 msg "test: check-files.py" # < 1s
Gilles Peskine8f073122018-11-27 15:58:47 +0100581 record_status tests/scripts/check-files.py
582}
Darryl Greena07039c2018-03-13 16:48:16 +0000583
Gilles Peskine8f073122018-11-27 15:58:47 +0100584component_check_names () {
585 msg "test/build: declared and exported names" # < 3s
Gilles Peskine473f2d42019-05-15 17:52:22 +0200586 record_status tests/scripts/check-names.sh -v
Gilles Peskine8f073122018-11-27 15:58:47 +0100587}
Manuel Pégourié-Gonnarda687baf2015-04-09 11:09:03 +0200588
Gilles Peskine8f073122018-11-27 15:58:47 +0100589component_check_doxygen_warnings () {
590 msg "test: doxygen warnings" # ~ 3s
Gilles Peskine8f073122018-11-27 15:58:47 +0100591 record_status tests/scripts/doxygen.sh
592}
Manuel Pégourié-Gonnard1d552e72016-01-04 16:49:09 +0100593
Gilles Peskine192c72f2017-12-21 15:59:21 +0100594
595
596################################################################
597#### Build and test many configurations and targets
598################################################################
599
k-stachowiak11f38e22019-06-04 13:14:58 +0200600component_test_large_ecdsa_key_signature () {
601
602 SMALL_MPI_MAX_SIZE=136 # Small enough to interfere with the EC signatures
603
604 msg "build: cmake + MBEDTLS_MPI_MAX_SIZE=${SMALL_MPI_MAX_SIZE}, gcc, ASan" # ~ 1 min 50s
605 scripts/config.pl set MBEDTLS_MPI_MAX_SIZE $SMALL_MPI_MAX_SIZE
606 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
607 make
608
609 INEVITABLY_PRESENT_FILE=Makefile
610 SIGNATURE_FILE="${INEVITABLY_PRESENT_FILE}.sig" # Warning, this is rm -f'ed below
611
612 msg "test: pk_sign secp521r1_prv.der for MBEDTLS_MPI_MAX_SIZE=${SMALL_MPI_MAX_SIZE} (ASan build)" # ~ 5s
613 if_build_succeeded programs/pkey/pk_sign tests/data_files/secp521r1_prv.der $INEVITABLY_PRESENT_FILE
614 rm -f $SIGNATURE_FILE
615}
616
Gilles Peskine99a33102019-04-08 17:00:15 +0200617component_test_default_out_of_box () {
618 msg "build: make, default config (out-of-box)" # ~1min
619 make
620
621 msg "test: main suites make, default config (out-of-box)" # ~10s
622 make test
623
624 msg "selftest: make, default config (out-of-box)" # ~10s
Gilles Peskine5bd9f562020-04-23 23:37:45 +0200625 if_build_succeeded programs/test/selftest
Gilles Peskine99a33102019-04-08 17:00:15 +0200626}
627
Gilles Peskine8f073122018-11-27 15:58:47 +0100628component_test_default_cmake_gcc_asan () {
629 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100630 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
631 make
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100632
Gilles Peskine8f073122018-11-27 15:58:47 +0100633 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
634 make test
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200635
Gilles Peskine5bd9f562020-04-23 23:37:45 +0200636 msg "test: selftest (ASan build)" # ~ 10s
637 if_build_succeeded programs/test/selftest
638
Gilles Peskine8f073122018-11-27 15:58:47 +0100639 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
640 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200641
Gilles Peskine8f073122018-11-27 15:58:47 +0100642 msg "test: compat.sh (ASan build)" # ~ 6 min
643 if_build_succeeded tests/compat.sh
644}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200645
Hanno Beckerf8799e82019-02-26 14:27:09 +0000646component_test_full_cmake_gcc_asan () {
647 msg "build: full config, cmake, gcc, ASan"
648 scripts/config.pl full
649 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
650 make
651
652 msg "test: main suites (inc. selftests) (full config, ASan build)"
653 make test
654
Gilles Peskine5bd9f562020-04-23 23:37:45 +0200655 msg "test: selftest (ASan build)" # ~ 10s
656 if_build_succeeded programs/test/selftest
657
Hanno Beckerf8799e82019-02-26 14:27:09 +0000658 msg "test: ssl-opt.sh (full config, ASan build)"
659 if_build_succeeded tests/ssl-opt.sh
660
661 msg "test: compat.sh (full config, ASan build)"
662 if_build_succeeded tests/compat.sh
663}
664
Manuel Pégourié-Gonnard4ef189d2020-01-02 11:45:12 +0100665component_test_zlib_make() {
666 msg "build: zlib enabled, make"
667 scripts/config.pl set MBEDTLS_ZLIB_SUPPORT
668 make ZLIB=1 CFLAGS='-Werror -O1'
669
670 msg "test: main suites (zlib, make)"
671 make test
672
673 msg "test: ssl-opt.sh (zlib, make)"
674 if_build_succeeded tests/ssl-opt.sh
675}
Manuel Pégourié-Gonnard114d3392020-01-24 10:17:20 +0100676support_test_zlib_make () {
677 base=support_test_zlib_$$
678 cat <<'EOF' > ${base}.c
679#include "zlib.h"
680int main(void) { return 0; }
681EOF
682 gcc -o ${base}.exe ${base}.c -lz 2>/dev/null
683 ret=$?
684 rm -f ${base}.*
685 return $ret
686}
Manuel Pégourié-Gonnard4ef189d2020-01-02 11:45:12 +0100687
688component_test_zlib_cmake() {
689 msg "build: zlib enabled, cmake"
690 scripts/config.pl set MBEDTLS_ZLIB_SUPPORT
691 cmake -D ENABLE_ZLIB_SUPPORT=On -D CMAKE_BUILD_TYPE:String=Check .
692 make
693
694 msg "test: main suites (zlib, cmake)"
695 make test
696
697 msg "test: ssl-opt.sh (zlib, cmake)"
698 if_build_succeeded tests/ssl-opt.sh
699}
Manuel Pégourié-Gonnard114d3392020-01-24 10:17:20 +0100700support_test_zlib_cmake () {
701 support_test_zlib_make "$@"
702}
Manuel Pégourié-Gonnard4ef189d2020-01-02 11:45:12 +0100703
Gilles Peskine782f4112018-11-27 16:11:09 +0100704component_test_ref_configs () {
705 msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
706 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
707 record_status tests/scripts/test-ref-configs.pl
708}
709
Gilles Peskine8f073122018-11-27 15:58:47 +0100710component_test_sslv3 () {
711 msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100712 scripts/config.pl set MBEDTLS_SSL_PROTO_SSL3
713 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
714 make
Simon Butcher3ea7f522016-03-07 23:22:10 +0000715
Gilles Peskine8f073122018-11-27 15:58:47 +0100716 msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
717 make test
Simon Butcher3ea7f522016-03-07 23:22:10 +0000718
Gilles Peskine8f073122018-11-27 15:58:47 +0100719 msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
720 if_build_succeeded tests/compat.sh -m 'tls1 tls1_1 tls1_2 dtls1 dtls1_2'
721 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
Simon Butcher3ea7f522016-03-07 23:22:10 +0000722
Gilles Peskine8f073122018-11-27 15:58:47 +0100723 msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
724 if_build_succeeded tests/ssl-opt.sh
725}
Simon Butcher3ea7f522016-03-07 23:22:10 +0000726
Gilles Peskine8f073122018-11-27 15:58:47 +0100727component_test_no_renegotiation () {
728 msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100729 scripts/config.pl unset MBEDTLS_SSL_RENEGOTIATION
730 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
731 make
Hanno Becker134c2ab2017-10-12 15:29:50 +0100732
Gilles Peskine8f073122018-11-27 15:58:47 +0100733 msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
734 make test
Hanno Becker134c2ab2017-10-12 15:29:50 +0100735
Gilles Peskine8f073122018-11-27 15:58:47 +0100736 msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
737 if_build_succeeded tests/ssl-opt.sh
738}
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +0100739
Hanno Beckere562e7d2019-05-10 14:45:37 +0100740component_test_no_pem_no_fs () {
741 msg "build: Default + !MBEDTLS_PEM_PARSE_C + !MBEDTLS_FS_IO (ASan build)"
742 scripts/config.pl unset MBEDTLS_PEM_PARSE_C
743 scripts/config.pl unset MBEDTLS_FS_IO
744 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
745 make
746
747 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - main suites (inc. selftests) (ASan build)" # ~ 50s
748 make test
749
750 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - ssl-opt.sh (ASan build)" # ~ 6 min
751 if_build_succeeded tests/ssl-opt.sh
752}
753
Gilles Peskine8f073122018-11-27 15:58:47 +0100754component_test_rsa_no_crt () {
755 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100756 scripts/config.pl set MBEDTLS_RSA_NO_CRT
757 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
758 make
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100759
Gilles Peskine8f073122018-11-27 15:58:47 +0100760 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
761 make test
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100762
Gilles Peskine8f073122018-11-27 15:58:47 +0100763 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
764 if_build_succeeded tests/ssl-opt.sh -f RSA
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100765
Gilles Peskine8f073122018-11-27 15:58:47 +0100766 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
767 if_build_succeeded tests/compat.sh -t RSA
768}
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100769
Gilles Peskine8f073122018-11-27 15:58:47 +0100770component_test_small_ssl_out_content_len () {
771 msg "build: small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100772 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 16384
773 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
774 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
775 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000776
Gilles Peskine8f073122018-11-27 15:58:47 +0100777 msg "test: small SSL_OUT_CONTENT_LEN - ssl-opt.sh MFL and large packet tests"
778 if_build_succeeded tests/ssl-opt.sh -f "Max fragment\|Large packet"
779}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000780
Gilles Peskine8f073122018-11-27 15:58:47 +0100781component_test_small_ssl_in_content_len () {
782 msg "build: small SSL_IN_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100783 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 4096
784 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 16384
785 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
786 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000787
Gilles Peskine8f073122018-11-27 15:58:47 +0100788 msg "test: small SSL_IN_CONTENT_LEN - ssl-opt.sh MFL tests"
789 if_build_succeeded tests/ssl-opt.sh -f "Max fragment"
790}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000791
Gilles Peskine8f073122018-11-27 15:58:47 +0100792component_test_small_ssl_dtls_max_buffering () {
793 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0"
Gilles Peskine8f073122018-11-27 15:58:47 +0100794 scripts/config.pl set MBEDTLS_SSL_DTLS_MAX_BUFFERING 1000
795 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
796 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100797
Gilles Peskine8f073122018-11-27 15:58:47 +0100798 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0 - ssl-opt.sh specific reordering test"
799 if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer out-of-order hs msg before reassembling next, free buffered msg"
800}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100801
Gilles Peskine8f073122018-11-27 15:58:47 +0100802component_test_small_mbedtls_ssl_dtls_max_buffering () {
803 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1"
Gilles Peskine8f073122018-11-27 15:58:47 +0100804 scripts/config.pl set MBEDTLS_SSL_DTLS_MAX_BUFFERING 240
805 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
806 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100807
Gilles Peskine8f073122018-11-27 15:58:47 +0100808 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1 - ssl-opt.sh specific reordering test"
809 if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer encrypted Finished message, drop for fragmented NewSessionTicket"
810}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100811
Gilles Peskine8f073122018-11-27 15:58:47 +0100812component_test_full_cmake_clang () {
813 msg "build: cmake, full config, clang" # ~ 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100814 scripts/config.pl full
Gilles Peskine8f073122018-11-27 15:58:47 +0100815 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check -D ENABLE_TESTING=On .
816 make
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100817
Gilles Peskine8f073122018-11-27 15:58:47 +0100818 msg "test: main suites (full config)" # ~ 5s
819 make test
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200820
Gilles Peskine8f073122018-11-27 15:58:47 +0100821 msg "test: ssl-opt.sh default, ECJPAKE, SSL async (full config)" # ~ 1s
822 if_build_succeeded tests/ssl-opt.sh -f 'Default\|ECJPAKE\|SSL async private'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200823
Andres Amaya Garciaac9c5222019-01-08 21:42:27 +0000824 msg "test: compat.sh RC4, DES, 3DES & NULL (full config)" # ~ 2 min
Andres Amaya Garcia37e0a8c2019-02-19 20:20:57 +0000825 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" GNUTLS_CLI="$GNUTLS_LEGACY_CLI" GNUTLS_SERV="$GNUTLS_LEGACY_SERV" tests/compat.sh -e '^$' -f 'NULL\|DES\|RC4\|ARCFOUR'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200826
Gilles Peskine8f073122018-11-27 15:58:47 +0100827 msg "test: compat.sh ARIA + ChachaPoly"
828 if_build_succeeded env OPENSSL_CMD="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
829}
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100830
Gilles Peskine8f073122018-11-27 15:58:47 +0100831component_build_deprecated () {
832 msg "build: make, full config + DEPRECATED_WARNING, gcc -O" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100833 scripts/config.pl full
834 scripts/config.pl set MBEDTLS_DEPRECATED_WARNING
835 # Build with -O -Wextra to catch a maximum of issues.
836 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra' lib programs
837 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
Gilles Peskineb4ef45b2018-03-01 22:23:50 +0100838
Gilles Peskine8f073122018-11-27 15:58:47 +0100839 msg "build: make, full config + DEPRECATED_REMOVED, clang -O" # ~ 30s
840 # No cleanup, just tweak the configuration and rebuild
841 make clean
842 scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
843 scripts/config.pl set MBEDTLS_DEPRECATED_REMOVED
844 # Build with -O -Wextra to catch a maximum of issues.
845 make CC=clang CFLAGS='-O -Werror -Wall -Wextra' lib programs
846 make CC=clang CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
847}
Gilles Peskine0afe6242018-02-21 19:28:12 +0100848
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200849
Gilles Peskine8f073122018-11-27 15:58:47 +0100850component_test_depends_curves () {
851 msg "test/build: curves.pl (gcc)" # ~ 4 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100852 record_status tests/scripts/curves.pl
853}
Manuel Pégourié-Gonnard1fe6bb92017-06-06 11:36:16 +0200854
Gilles Peskine8f073122018-11-27 15:58:47 +0100855component_test_depends_hashes () {
856 msg "test/build: depends-hashes.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100857 record_status tests/scripts/depends-hashes.pl
858}
Manuel Pégourié-Gonnard43be6cd2017-06-20 09:53:42 +0200859
Gilles Peskine8f073122018-11-27 15:58:47 +0100860component_test_depends_pkalgs () {
861 msg "test/build: depends-pkalgs.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100862 record_status tests/scripts/depends-pkalgs.pl
863}
Manuel Pégourié-Gonnard503a5ef2015-10-23 09:04:45 +0200864
Gilles Peskine8f073122018-11-27 15:58:47 +0100865component_build_key_exchanges () {
866 msg "test/build: key-exchanges (gcc)" # ~ 1 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100867 record_status tests/scripts/key-exchanges.pl
868}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100869
Gilles Peskine8f073122018-11-27 15:58:47 +0100870component_build_default_make_gcc_and_cxx () {
871 msg "build: Unix make, -Os (gcc)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100872 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400873
Gilles Peskine8f073122018-11-27 15:58:47 +0100874 msg "test: verify header list in cpp_dummy_build.cpp"
875 record_status check_headers_in_cpp
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400876
Gilles Peskine8f073122018-11-27 15:58:47 +0100877 msg "build: Unix make, incremental g++"
878 make TEST_CPP=1
879}
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +0000880
Gilles Peskinedcab2022019-06-12 16:05:50 +0200881component_test_check_params_functionality () {
882 msg "build+test: MBEDTLS_CHECK_PARAMS functionality"
883 scripts/config.pl full # includes CHECK_PARAMS
884 # Make MBEDTLS_PARAM_FAILED call mbedtls_param_failed().
885 scripts/config.pl unset MBEDTLS_CHECK_PARAMS_ASSERT
Gilles Peskinedcab2022019-06-12 16:05:50 +0200886 # Only build and run tests. Do not build sample programs, because
887 # they don't have a mbedtls_param_failed() function.
888 make CC=gcc CFLAGS='-Werror -O1' lib test
889}
890
Gilles Peskineb28636b2019-01-02 19:06:24 +0100891component_test_check_params_without_platform () {
892 msg "build+test: MBEDTLS_CHECK_PARAMS without MBEDTLS_PLATFORM_C"
893 scripts/config.pl full # includes CHECK_PARAMS
Gilles Peskinedcab2022019-06-12 16:05:50 +0200894 # Keep MBEDTLS_PARAM_FAILED as assert.
Gilles Peskineb28636b2019-01-02 19:06:24 +0100895 scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
896 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
897 scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
898 scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
899 scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
900 scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
901 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
902 scripts/config.pl unset MBEDTLS_PLATFORM_C
903 make CC=gcc CFLAGS='-Werror -O1' all test
904}
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +0200905
Gilles Peskineb28636b2019-01-02 19:06:24 +0100906component_test_check_params_silent () {
907 msg "build+test: MBEDTLS_CHECK_PARAMS with alternative MBEDTLS_PARAM_FAILED()"
908 scripts/config.pl full # includes CHECK_PARAMS
Gilles Peskinedcab2022019-06-12 16:05:50 +0200909 # Set MBEDTLS_PARAM_FAILED to nothing.
Gilles Peskineb28636b2019-01-02 19:06:24 +0100910 sed -i 's/.*\(#define MBEDTLS_PARAM_FAILED( cond )\).*/\1/' "$CONFIG_H"
911 make CC=gcc CFLAGS='-Werror -O1' all test
912}
Hanno Becker5175ac62017-09-18 15:36:25 +0100913
Gilles Peskine8f073122018-11-27 15:58:47 +0100914component_test_no_platform () {
915 # Full configuration build, without platform support, file IO and net sockets.
916 # This should catch missing mbedtls_printf definitions, and by disabling file
917 # IO, it should catch missing '#include <stdio.h>'
918 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100919 scripts/config.pl full
920 scripts/config.pl unset MBEDTLS_PLATFORM_C
921 scripts/config.pl unset MBEDTLS_NET_C
922 scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
923 scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
924 scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
925 scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
926 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
927 scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
928 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskine8f073122018-11-27 15:58:47 +0100929 scripts/config.pl unset MBEDTLS_FS_IO
930 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
931 # to re-enable platform integration features otherwise disabled in C99 builds
Gilles Peskine99d70d82019-09-20 19:23:10 +0200932 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -Os -D_DEFAULT_SOURCE' lib programs
933 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os' test
Gilles Peskine8f073122018-11-27 15:58:47 +0100934}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200935
Gilles Peskine8f073122018-11-27 15:58:47 +0100936component_build_no_std_function () {
937 # catch compile bugs in _uninit functions
938 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100939 scripts/config.pl full
940 scripts/config.pl set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
941 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskine99d70d82019-09-20 19:23:10 +0200942 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Gilles Peskine8f073122018-11-27 15:58:47 +0100943}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200944
Gilles Peskine8f073122018-11-27 15:58:47 +0100945component_build_no_ssl_srv () {
946 msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100947 scripts/config.pl full
948 scripts/config.pl unset MBEDTLS_SSL_SRV_C
Gilles Peskine99d70d82019-09-20 19:23:10 +0200949 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
Gilles Peskine8f073122018-11-27 15:58:47 +0100950}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200951
Gilles Peskine8f073122018-11-27 15:58:47 +0100952component_build_no_ssl_cli () {
953 msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100954 scripts/config.pl full
955 scripts/config.pl unset MBEDTLS_SSL_CLI_C
Gilles Peskine99d70d82019-09-20 19:23:10 +0200956 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
Gilles Peskine8f073122018-11-27 15:58:47 +0100957}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000958
Gilles Peskine8f073122018-11-27 15:58:47 +0100959component_build_no_sockets () {
960 # Note, C99 compliance can also be tested with the sockets support disabled,
961 # as that requires a POSIX platform (which isn't the same as C99).
962 msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100963 scripts/config.pl full
964 scripts/config.pl unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
965 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
Gilles Peskine99d70d82019-09-20 19:23:10 +0200966 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1 -std=c99 -pedantic' lib
Gilles Peskine8f073122018-11-27 15:58:47 +0100967}
Hanno Becker5175ac62017-09-18 15:36:25 +0100968
Andrzej Kurek1d070822019-09-05 09:27:47 -0400969component_test_memory_buffer_allocator_backtrace () {
970 msg "build: default config with memory buffer allocator and backtrace enabled"
Hanno Becker74b5e342019-02-26 14:34:13 +0000971 scripts/config.pl set MBEDTLS_MEMORY_BUFFER_ALLOC_C
Andrzej Kurek1d070822019-09-05 09:27:47 -0400972 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
Hanno Becker74b5e342019-02-26 14:34:13 +0000973 scripts/config.pl set MBEDTLS_MEMORY_BACKTRACE
Andrzej Kurek60ebd982019-09-10 02:58:34 -0400974 scripts/config.pl set MBEDTLS_MEMORY_DEBUG
Andrzej Kurek1d070822019-09-05 09:27:47 -0400975 CC=gcc cmake .
976 make
977
978 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C and MBEDTLS_MEMORY_BACKTRACE"
979 make test
980}
981
982component_test_memory_buffer_allocator () {
983 msg "build: default config with memory buffer allocator"
984 scripts/config.pl set MBEDTLS_MEMORY_BUFFER_ALLOC_C
Hanno Beckerd130b982019-06-03 16:35:02 +0100985 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
Hanno Becker74b5e342019-02-26 14:34:13 +0000986 CC=gcc cmake .
987 make
988
989 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C"
990 make test
991
992 msg "test: ssl-opt.sh, MBEDTLS_MEMORY_BUFFER_ALLOC_C"
Andrzej Kurek1f5a5962019-09-05 10:09:37 -0400993 # MBEDTLS_MEMORY_BUFFER_ALLOC is slow. Skip tests that tend to time out.
994 if_build_succeeded tests/ssl-opt.sh -e '^DTLS proxy'
Hanno Becker74b5e342019-02-26 14:34:13 +0000995}
996
Gilles Peskine8f073122018-11-27 15:58:47 +0100997component_test_no_max_fragment_length () {
998 # Run max fragment length tests with MFL disabled
999 msg "build: default config except MFL extension (ASan build)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +01001000 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
1001 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1002 make
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001003
Gilles Peskine8f073122018-11-27 15:58:47 +01001004 msg "test: ssl-opt.sh, MFL-related tests"
1005 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length"
1006}
Angus Grattonc4dd0732018-04-11 16:28:39 +10001007
Gilles Peskine8f073122018-11-27 15:58:47 +01001008component_test_no_max_fragment_length_small_ssl_out_content_len () {
1009 msg "build: no MFL extension, small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +01001010 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
1011 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 16384
1012 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
1013 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1014 make
Angus Grattonc4dd0732018-04-11 16:28:39 +10001015
Gilles Peskine8f073122018-11-27 15:58:47 +01001016 msg "test: MFL tests (disabled MFL extension case) & large packet tests"
1017 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length\|Large buffer"
1018}
Janos Follath06c54002016-06-09 13:57:40 +01001019
Gilles Peskine8f073122018-11-27 15:58:47 +01001020component_test_null_entropy () {
1021 msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +01001022 scripts/config.pl set MBEDTLS_TEST_NULL_ENTROPY
1023 scripts/config.pl set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
1024 scripts/config.pl set MBEDTLS_ENTROPY_C
1025 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
1026 scripts/config.pl unset MBEDTLS_ENTROPY_HARDWARE_ALT
1027 scripts/config.pl unset MBEDTLS_HAVEGE_C
Gilles Peskine5fa32a72019-01-06 19:48:30 +00001028 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan -D UNSAFE_BUILD=ON .
Gilles Peskine8f073122018-11-27 15:58:47 +01001029 make
Janos Follath06c54002016-06-09 13:57:40 +01001030
Gilles Peskine8f073122018-11-27 15:58:47 +01001031 msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)"
1032 make test
1033}
Hanno Beckere5fecec2018-10-11 11:02:52 +01001034
Gilles Peskine8f073122018-11-27 15:58:47 +01001035component_test_platform_calloc_macro () {
1036 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +01001037 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
1038 scripts/config.pl set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
1039 scripts/config.pl set MBEDTLS_PLATFORM_FREE_MACRO free
1040 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1041 make
Hanno Beckere5fecec2018-10-11 11:02:52 +01001042
Gilles Peskine8f073122018-11-27 15:58:47 +01001043 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
1044 make test
1045}
Hanno Becker83ebf782017-07-07 12:29:15 +01001046
Gilles Peskinec6b09862019-09-17 19:04:38 +02001047component_test_malloc_0_null () {
1048 msg "build: malloc(0) returns NULL (ASan+UBSan build)"
1049 scripts/config.pl full
1050 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
1051 make CC=gcc CFLAGS="'-DMBEDTLS_CONFIG_FILE=\"$PWD/tests/configs/config-wrapper-malloc-0-null.h\"' -O -Werror -Wall -Wextra -fsanitize=address,undefined" LDFLAGS='-fsanitize=address,undefined'
1052
1053 msg "test: malloc(0) returns NULL (ASan+UBSan build)"
1054 make test
1055
1056 msg "selftest: malloc(0) returns NULL (ASan+UBSan build)"
1057 # Just the calloc selftest. "make test" ran the others as part of the
1058 # test suites.
1059 if_build_succeeded programs/test/selftest calloc
1060}
1061
Gilles Peskine8f073122018-11-27 15:58:47 +01001062component_test_aes_fewer_tables () {
1063 msg "build: default config with AES_FEWER_TABLES enabled"
Gilles Peskine8f073122018-11-27 15:58:47 +01001064 scripts/config.pl set MBEDTLS_AES_FEWER_TABLES
1065 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01001066
Gilles Peskine8f073122018-11-27 15:58:47 +01001067 msg "test: AES_FEWER_TABLES"
1068 make test
1069}
Hanno Becker83ebf782017-07-07 12:29:15 +01001070
Gilles Peskine8f073122018-11-27 15:58:47 +01001071component_test_aes_rom_tables () {
1072 msg "build: default config with AES_ROM_TABLES enabled"
Gilles Peskine8f073122018-11-27 15:58:47 +01001073 scripts/config.pl set MBEDTLS_AES_ROM_TABLES
1074 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01001075
Gilles Peskine8f073122018-11-27 15:58:47 +01001076 msg "test: AES_ROM_TABLES"
1077 make test
1078}
Hanno Becker83ebf782017-07-07 12:29:15 +01001079
Gilles Peskine8f073122018-11-27 15:58:47 +01001080component_test_aes_fewer_tables_and_rom_tables () {
1081 msg "build: default config with AES_ROM_TABLES and AES_FEWER_TABLES enabled"
Gilles Peskine8f073122018-11-27 15:58:47 +01001082 scripts/config.pl set MBEDTLS_AES_FEWER_TABLES
1083 scripts/config.pl set MBEDTLS_AES_ROM_TABLES
1084 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01001085
Gilles Peskine8f073122018-11-27 15:58:47 +01001086 msg "test: AES_FEWER_TABLES + AES_ROM_TABLES"
1087 make test
1088}
1089
1090component_test_make_shared () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001091 msg "build/test: make shared" # ~ 40s
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001092 make SHARED=1 all check
Gilles Peskinedc25c322019-07-03 20:43:32 +02001093 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskine8f073122018-11-27 15:58:47 +01001094}
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +02001095
Gilles Peskine2c47ffc2019-07-03 20:43:05 +02001096component_test_cmake_shared () {
1097 msg "build/test: cmake shared" # ~ 2min
1098 cmake -DUSE_SHARED_MBEDTLS_LIBRARY=On .
1099 make
Gilles Peskinedc25c322019-07-03 20:43:32 +02001100 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskine2c47ffc2019-07-03 20:43:05 +02001101 make test
1102}
1103
Gilles Peskine0fe92c22019-09-20 19:56:06 +02001104test_build_opt () {
1105 info=$1 cc=$2; shift 2
1106 for opt in "$@"; do
1107 msg "build/test: $cc $opt, $info" # ~ 30s
1108 make CC="$cc" CFLAGS="$opt -Wall -Wextra -Werror"
1109 # We're confident enough in compilers to not run _all_ the tests,
1110 # but at least run the unit tests. In particular, runs with
1111 # optimizations use inline assembly whereas runs with -O0
1112 # skip inline assembly.
1113 make test # ~30s
1114 make clean
1115 done
1116}
1117
1118component_test_clang_opt () {
1119 scripts/config.pl full
1120 test_build_opt 'full config' clang -O0 -Os -O2
1121}
1122
1123component_test_gcc_opt () {
1124 scripts/config.pl full
1125 test_build_opt 'full config' gcc -O0 -Os -O2
1126}
1127
Gilles Peskine87bf1b52019-07-03 20:42:16 +02001128component_build_mbedtls_config_file () {
1129 msg "build: make with MBEDTLS_CONFIG_FILE" # ~40s
1130 # Use the full config so as to catch a maximum of places where
1131 # the check of MBEDTLS_CONFIG_FILE might be missing.
1132 scripts/config.pl full
1133 sed 's!"check_config.h"!"mbedtls/check_config.h"!' <"$CONFIG_H" >full_config.h
1134 echo '#error "MBEDTLS_CONFIG_FILE is not working"' >"$CONFIG_H"
1135 make CFLAGS="-I '$PWD' -DMBEDTLS_CONFIG_FILE='\"full_config.h\"'"
1136 rm -f full_config.h
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001137}
1138
Gilles Peskine8f073122018-11-27 15:58:47 +01001139component_test_m32_o0 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001140 # Build once with -O0, to compile out the i386 specific inline assembly
1141 msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
Simon Butcher7a6da6e2018-06-27 21:52:54 +01001142 scripts/config.pl full
Gilles Peskineff26b042019-10-21 17:11:33 +02001143 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O0" LDFLAGS="-m32 $ASAN_CFLAGS"
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01001144
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001145 msg "test: i386, make, gcc -O0 (ASan build)"
1146 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01001147}
Gilles Peskine878cf602019-01-06 20:50:38 +00001148support_test_m32_o0 () {
1149 case $(uname -m) in
1150 *64*) true;;
1151 *) false;;
1152 esac
1153}
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001154
Gilles Peskine8f073122018-11-27 15:58:47 +01001155component_test_m32_o1 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001156 # Build again with -O1, to compile in the i386 specific inline assembly
1157 msg "build: i386, make, gcc -O1 (ASan build)" # ~ 30s
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001158 scripts/config.pl full
Gilles Peskineff26b042019-10-21 17:11:33 +02001159 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O1" LDFLAGS="-m32 $ASAN_CFLAGS"
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001160
1161 msg "test: i386, make, gcc -O1 (ASan build)"
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001162 make test
Gilles Peskine7dd44b22019-04-08 16:58:02 +02001163
1164 msg "test ssl-opt.sh, i386, make, gcc-O1"
1165 if_build_succeeded tests/ssl-opt.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01001166}
Gilles Peskine878cf602019-01-06 20:50:38 +00001167support_test_m32_o1 () {
1168 support_test_m32_o0 "$@"
1169}
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001170
Gilles Peskine8f073122018-11-27 15:58:47 +01001171component_test_mx32 () {
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001172 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
Simon Butcher7a6da6e2018-06-27 21:52:54 +01001173 scripts/config.pl full
Gilles Peskine8118e462019-06-07 14:50:09 +02001174 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32' LDFLAGS='-mx32'
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001175
1176 msg "test: 64-bit ILP32, make, gcc"
1177 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01001178}
Gilles Peskine878cf602019-01-06 20:50:38 +00001179support_test_mx32 () {
1180 case $(uname -m) in
1181 amd64|x86_64) true;;
1182 *) false;;
1183 esac
1184}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001185
Peter Kolbus1e2aa722018-12-27 06:59:04 -06001186component_test_min_mpi_window_size () {
1187 msg "build: Default + MBEDTLS_MPI_WINDOW_SIZE=1 (ASan build)" # ~ 10s
1188 scripts/config.pl set MBEDTLS_MPI_WINDOW_SIZE 1
1189 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1190 make
1191
1192 msg "test: MBEDTLS_MPI_WINDOW_SIZE=1 - main suites (inc. selftests) (ASan build)" # ~ 10s
1193 make test
1194}
1195
Gilles Peskine8f073122018-11-27 15:58:47 +01001196component_test_have_int32 () {
1197 msg "build: gcc, force 32-bit bignum limbs"
Gilles Peskine8f073122018-11-27 15:58:47 +01001198 scripts/config.pl unset MBEDTLS_HAVE_ASM
1199 scripts/config.pl unset MBEDTLS_AESNI_C
1200 scripts/config.pl unset MBEDTLS_PADLOCK_C
1201 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01001202
Gilles Peskine8f073122018-11-27 15:58:47 +01001203 msg "test: gcc, force 32-bit bignum limbs"
1204 make test
1205}
Andres Amaya Garciafe843a32017-07-20 13:21:34 +01001206
Gilles Peskine8f073122018-11-27 15:58:47 +01001207component_test_have_int64 () {
1208 msg "build: gcc, force 64-bit bignum limbs"
Gilles Peskine8f073122018-11-27 15:58:47 +01001209 scripts/config.pl unset MBEDTLS_HAVE_ASM
1210 scripts/config.pl unset MBEDTLS_AESNI_C
1211 scripts/config.pl unset MBEDTLS_PADLOCK_C
1212 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
Gilles Peskine14c3c062018-01-29 21:25:12 +01001213
Gilles Peskine8f073122018-11-27 15:58:47 +01001214 msg "test: gcc, force 64-bit bignum limbs"
1215 make test
1216}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001217
Gilles Peskine8f073122018-11-27 15:58:47 +01001218component_test_no_udbl_division () {
1219 msg "build: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +01001220 scripts/config.pl full
Gilles Peskine8f073122018-11-27 15:58:47 +01001221 scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
1222 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001223
Gilles Peskine8f073122018-11-27 15:58:47 +01001224 msg "test: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
1225 make test
1226}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001227
Gilles Peskine8f073122018-11-27 15:58:47 +01001228component_test_no_64bit_multiplication () {
1229 msg "build: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +01001230 scripts/config.pl full
Gilles Peskine8f073122018-11-27 15:58:47 +01001231 scripts/config.pl set MBEDTLS_NO_64BIT_MULTIPLICATION
1232 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001233
Gilles Peskine8f073122018-11-27 15:58:47 +01001234 msg "test: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
1235 make test
1236}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001237
Gilles Peskine8f073122018-11-27 15:58:47 +01001238component_build_arm_none_eabi_gcc () {
Gilles Peskine67c3c3f2020-04-25 22:21:30 +02001239 msg "build: ${ARM_GCC_PREFIX}, make" # ~ 10s
Manuel Pégourié-Gonnard6e6ae9b2019-04-29 12:44:12 +02001240 scripts/config.pl baremetal
Gilles Peskine67c3c3f2020-04-25 22:21:30 +02001241 make CC="${ARM_GCC_PREFIX}gcc" AR="${ARM_GCC_PREFIX}ar" LD="${ARM_GCC_PREFIX}ld" CFLAGS='-Werror -Wall -Wextra' lib
Gilles Peskine8f073122018-11-27 15:58:47 +01001242}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001243
Gilles Peskine560f3322019-08-09 16:05:05 +02001244component_build_arm_none_eabi_gcc_arm5vte () {
Gilles Peskine67c3c3f2020-04-25 22:21:30 +02001245 msg "build: ${ARM_GCC_PREFIX} -march=arm5vte, make" # ~ 10s
Gilles Peskine0bd284d2019-08-05 11:34:25 +02001246 scripts/config.pl baremetal
Gilles Peskine560f3322019-08-09 16:05:05 +02001247 # Build for a target platform that's close to what Debian uses
1248 # for its "armel" distribution (https://wiki.debian.org/ArmEabiPort).
1249 # See https://github.com/ARMmbed/mbedtls/pull/2169 and comments.
1250 # It would be better to build with arm-linux-gnueabi-gcc but
1251 # we don't have that on our CI at this time.
Gilles Peskine67c3c3f2020-04-25 22:21:30 +02001252 make CC="${ARM_GCC_PREFIX}gcc" AR="${ARM_GCC_PREFIX}ar" CFLAGS='-Werror -Wall -Wextra -march=armv5te -O1' LDFLAGS='-march=armv5te' SHELL='sh -x' lib
Gilles Peskine0bd284d2019-08-05 11:34:25 +02001253}
1254
Gilles Peskine8f073122018-11-27 15:58:47 +01001255component_build_arm_none_eabi_gcc_no_udbl_division () {
Gilles Peskine67c3c3f2020-04-25 22:21:30 +02001256 msg "build: ${ARM_GCC_PREFIX} -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
Manuel Pégourié-Gonnard6e6ae9b2019-04-29 12:44:12 +02001257 scripts/config.pl baremetal
Gilles Peskine8f073122018-11-27 15:58:47 +01001258 scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
Gilles Peskine67c3c3f2020-04-25 22:21:30 +02001259 make CC="${ARM_GCC_PREFIX}gcc" AR="${ARM_GCC_PREFIX}ar" LD="${ARM_GCC_PREFIX}ld" CFLAGS='-Werror -Wall -Wextra' lib
Gilles Peskine8f073122018-11-27 15:58:47 +01001260 echo "Checking that software 64-bit division is not required"
1261 if_build_succeeded not grep __aeabi_uldiv library/*.o
1262}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001263
Gilles Peskine8f073122018-11-27 15:58:47 +01001264component_build_arm_none_eabi_gcc_no_64bit_multiplication () {
Gilles Peskine67c3c3f2020-04-25 22:21:30 +02001265 msg "build: ${ARM_GCC_PREFIX} MBEDTLS_NO_64BIT_MULTIPLICATION, make" # ~ 10s
Manuel Pégourié-Gonnard6e6ae9b2019-04-29 12:44:12 +02001266 scripts/config.pl baremetal
Gilles Peskine8f073122018-11-27 15:58:47 +01001267 scripts/config.pl set MBEDTLS_NO_64BIT_MULTIPLICATION
Gilles Peskine67c3c3f2020-04-25 22:21:30 +02001268 make CC="${ARM_GCC_PREFIX}gcc" AR="${ARM_GCC_PREFIX}ar" LD="${ARM_GCC_PREFIX}ld" CFLAGS='-Werror -O1 -march=armv6-m -mthumb' lib
Gilles Peskine8f073122018-11-27 15:58:47 +01001269 echo "Checking that software 64-bit multiplication is not required"
1270 if_build_succeeded not grep __aeabi_lmul library/*.o
1271}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001272
Gilles Peskine8f073122018-11-27 15:58:47 +01001273component_build_armcc () {
1274 msg "build: ARM Compiler 5, make"
Manuel Pégourié-Gonnard6e6ae9b2019-04-29 12:44:12 +02001275 scripts/config.pl baremetal
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001276
Gilles Peskine5331c6e2019-01-06 22:23:42 +00001277 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
1278 make clean
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001279
Gilles Peskine5331c6e2019-01-06 22:23:42 +00001280 # ARM Compiler 6 - Target ARMv7-A
1281 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-a"
Gilles Peskineed942f82017-06-08 15:19:20 +02001282
Gilles Peskine5331c6e2019-01-06 22:23:42 +00001283 # ARM Compiler 6 - Target ARMv7-M
1284 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m"
Andres AG87bb5772016-09-27 15:05:15 +01001285
Gilles Peskine5331c6e2019-01-06 22:23:42 +00001286 # ARM Compiler 6 - Target ARMv8-A - AArch32
1287 armc6_build_test "--target=arm-arm-none-eabi -march=armv8.2-a"
Andres AG87bb5772016-09-27 15:05:15 +01001288
Gilles Peskine5331c6e2019-01-06 22:23:42 +00001289 # ARM Compiler 6 - Target ARMv8-M
1290 armc6_build_test "--target=arm-arm-none-eabi -march=armv8-m.main"
Simon Butcher940737f2017-07-23 13:42:36 +02001291
Gilles Peskine5331c6e2019-01-06 22:23:42 +00001292 # ARM Compiler 6 - Target ARMv8-A - AArch64
1293 armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a"
Gilles Peskine8f073122018-11-27 15:58:47 +01001294}
Simon Butcher940737f2017-07-23 13:42:36 +02001295
Andres Amaya Garcia9f3bdb82018-12-05 22:03:56 +00001296component_build_ssl_hw_record_accel() {
1297 msg "build: default config with MBEDTLS_SSL_HW_RECORD_ACCEL enabled"
1298 scripts/config.pl set MBEDTLS_SSL_HW_RECORD_ACCEL
1299 make CFLAGS='-Werror -O1'
1300}
1301
Gilles Peskine8f073122018-11-27 15:58:47 +01001302component_test_allow_sha1 () {
1303 msg "build: allow SHA1 in certificates by default"
Gilles Peskine8f073122018-11-27 15:58:47 +01001304 scripts/config.pl set MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
1305 make CFLAGS='-Werror -Wall -Wextra'
1306 msg "test: allow SHA1 in certificates by default"
1307 make test
1308 if_build_succeeded tests/ssl-opt.sh -f SHA-1
1309}
Simon Butcher940737f2017-07-23 13:42:36 +02001310
Gilles Peskine8f073122018-11-27 15:58:47 +01001311component_build_mingw () {
1312 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +01001313 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -Wall -Wextra' WINDOWS_BUILD=1 lib programs
Gilles Peskine2a458da2017-05-12 15:26:58 +02001314
Gilles Peskine8f073122018-11-27 15:58:47 +01001315 # note Make tests only builds the tests, but doesn't run them
1316 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror' WINDOWS_BUILD=1 tests
1317 make WINDOWS_BUILD=1 clean
Hanno Beckere963efa2018-01-03 10:03:43 +00001318
Gilles Peskine8f073122018-11-27 15:58:47 +01001319 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
1320 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
1321 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
1322 make WINDOWS_BUILD=1 clean
1323}
Simon Butcher002bc622016-11-17 09:27:45 +00001324
Gilles Peskine8f073122018-11-27 15:58:47 +01001325component_test_memsan () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001326 msg "build: MSan (clang)" # ~ 1 min 20s
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001327 scripts/config.pl unset MBEDTLS_AESNI_C # memsan doesn't grok asm
1328 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
1329 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +02001330
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001331 msg "test: main suites (MSan)" # ~ 10s
1332 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001333
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001334 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
Gilles Peskine7c652162017-12-11 00:01:40 +01001335 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001336
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001337 # Optional part(s)
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001338
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001339 if [ "$MEMORY" -gt 0 ]; then
1340 msg "test: compat.sh (MSan)" # ~ 6 min 20s
Gilles Peskine7c652162017-12-11 00:01:40 +01001341 if_build_succeeded tests/compat.sh
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001342 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001343}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001344
Gilles Peskine69f190e2019-01-10 00:11:42 +01001345component_test_valgrind () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001346 msg "build: Release (clang)"
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001347 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
1348 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001349
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001350 msg "test: main suites valgrind (Release)"
1351 make memcheck
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001352
Gilles Peskine0a47c4f2019-04-08 17:00:56 +02001353 # Optional parts (slow; currently broken on OS X because programs don't
1354 # seem to receive signals under valgrind on OS X).
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001355 if [ "$MEMORY" -gt 0 ]; then
1356 msg "test: ssl-opt.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +01001357 if_build_succeeded tests/ssl-opt.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001358 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001359
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001360 if [ "$MEMORY" -gt 1 ]; then
1361 msg "test: compat.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +01001362 if_build_succeeded tests/compat.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001363 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001364}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001365
Gilles Peskine8f073122018-11-27 15:58:47 +01001366component_test_cmake_out_of_source () {
1367 msg "build: cmake 'out-of-source' build"
Gilles Peskine8f073122018-11-27 15:58:47 +01001368 MBEDTLS_ROOT_DIR="$PWD"
1369 mkdir "$OUT_OF_SOURCE_DIR"
1370 cd "$OUT_OF_SOURCE_DIR"
1371 cmake "$MBEDTLS_ROOT_DIR"
1372 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001373
Gilles Peskine8f073122018-11-27 15:58:47 +01001374 msg "test: cmake 'out-of-source' build"
1375 make test
1376 # Test an SSL option that requires an auxiliary script in test/scripts/.
1377 # Also ensure that there are no error messages such as
1378 # "No such file or directory", which would indicate that some required
1379 # file is missing (ssl-opt.sh tolerates the absence of some files so
1380 # may exit with status 0 but emit errors).
1381 if_build_succeeded ./tests/ssl-opt.sh -f 'Fallback SCSV: beginning of list' 2>ssl-opt.err
1382 if [ -s ssl-opt.err ]; then
1383 cat ssl-opt.err >&2
1384 record_status [ ! -s ssl-opt.err ]
1385 rm ssl-opt.err
1386 fi
1387 cd "$MBEDTLS_ROOT_DIR"
1388 rm -rf "$OUT_OF_SOURCE_DIR"
1389 unset MBEDTLS_ROOT_DIR
1390}
Andres AGdc192212016-08-31 17:33:13 +01001391
Gilles Peskine8f073122018-11-27 15:58:47 +01001392component_test_zeroize () {
1393 # Test that the function mbedtls_platform_zeroize() is not optimized away by
1394 # different combinations of compilers and optimization flags by using an
1395 # auxiliary GDB script. Unfortunately, GDB does not return error values to the
1396 # system in all cases that the script fails, so we must manually search the
1397 # output to check whether the pass string is present and no failure strings
1398 # were printed.
Gilles Peskine4976e822019-01-06 19:52:22 +00001399
1400 # Don't try to disable ASLR. We don't care about ASLR here. We do care
1401 # about a spurious message if Gdb tries and fails, so suppress that.
1402 gdb_disable_aslr=
1403 if [ -z "$(gdb -batch -nw -ex 'set disable-randomization off' 2>&1)" ]; then
1404 gdb_disable_aslr='set disable-randomization off'
1405 fi
1406
Gilles Peskine8f073122018-11-27 15:58:47 +01001407 for optimization_flag in -O2 -O3 -Ofast -Os; do
Gilles Peskine55f7c942019-01-09 22:28:21 +01001408 for compiler in clang gcc; do
1409 msg "test: $compiler $optimization_flag, mbedtls_platform_zeroize()"
1410 make programs CC="$compiler" DEBUG=1 CFLAGS="$optimization_flag"
Gilles Peskine4976e822019-01-06 19:52:22 +00001411 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 +01001412 if_build_succeeded grep "The buffer was correctly zeroized" test_zeroize.log
1413 if_build_succeeded not grep -i "error" test_zeroize.log
1414 rm -f test_zeroize.log
1415 make clean
1416 done
Andres Amaya Garcia29673812017-10-25 10:35:51 +01001417 done
Gilles Peskine4976e822019-01-06 19:52:22 +00001418
1419 unset gdb_disable_aslr
Gilles Peskine8f073122018-11-27 15:58:47 +01001420}
Andres Amaya Garciad0d7bf62017-10-25 09:01:31 +01001421
Gilles Peskine8f073122018-11-27 15:58:47 +01001422component_check_python_files () {
1423 msg "Lint: Python scripts"
1424 record_status tests/scripts/check-python-files.sh
1425}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001426
Gilles Peskine8f073122018-11-27 15:58:47 +01001427component_check_generate_test_code () {
1428 msg "uint test: generate_test_code.py"
1429 record_status ./tests/scripts/test_generate_test_code.py
1430}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001431
1432################################################################
1433#### Termination
1434################################################################
1435
Gilles Peskine8f073122018-11-27 15:58:47 +01001436post_report () {
1437 msg "Done, cleaning up"
1438 cleanup
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001439
Gilles Peskine8f073122018-11-27 15:58:47 +01001440 final_report
1441}
1442
1443
1444
1445################################################################
1446#### Run all the things
1447################################################################
1448
Gilles Peskinee48351a2018-11-27 16:06:30 +01001449# Run one component and clean up afterwards.
Gilles Peskine8f073122018-11-27 15:58:47 +01001450run_component () {
Gilles Peskine608953e2019-01-02 18:57:02 +01001451 # Back up the configuration in case the component modifies it.
1452 # The cleanup function will restore it.
1453 cp -p "$CONFIG_H" "$CONFIG_BAK"
Gilles Peskineffcdeff2018-12-04 12:49:28 +01001454 current_component="$1"
Gilles Peskine8f073122018-11-27 15:58:47 +01001455 "$@"
Gilles Peskinee48351a2018-11-27 16:06:30 +01001456 cleanup
Gilles Peskine8f073122018-11-27 15:58:47 +01001457}
1458
1459# Preliminary setup
1460pre_check_environment
1461pre_initialize_variables
1462pre_parse_command_line "$@"
Gilles Peskine348fb9a2018-11-27 17:04:29 +01001463
Gilles Peskine878cf602019-01-06 20:50:38 +00001464pre_check_git
1465build_status=0
1466if [ $KEEP_GOING -eq 1 ]; then
1467 pre_setup_keep_going
1468else
1469 record_status () {
1470 "$@"
1471 }
1472fi
1473pre_print_configuration
1474pre_check_tools
Gilles Peskine878cf602019-01-06 20:50:38 +00001475cleanup
Gilles Peskine8f073122018-11-27 15:58:47 +01001476
Gilles Peskinebeb3a812019-01-06 22:11:25 +00001477# Run the requested tests.
1478for component in $RUN_COMPONENTS; do
1479 run_component "component_$component"
1480done
Gilles Peskine8f073122018-11-27 15:58:47 +01001481
1482# We're done.
Gilles Peskine878cf602019-01-06 20:50:38 +00001483post_report