blob: 397a758afe16cfdf8afd0000aa3fb079dded3be8 [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
Philippe Antoine1c582c32019-06-25 21:55:21 +020027# * Makefile, library/Makefile, programs/Makefile, tests/Makefile,
Philippe Antoine5dece6d2019-06-27 16:55:07 +020028# programs/fuzz/Makefile
Gilles Peskine192c72f2017-12-21 15:59:21 +010029# After running this script, the CMake cache will be lost and CMake
30# will no longer be initialised.
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +010031#
Gilles Peskine192c72f2017-12-21 15:59:21 +010032# The script assumes the presence of a number of tools:
33# * Basic Unix tools (Windows users note: a Unix-style find must be before
34# the Windows find in the PATH)
35# * Perl
36# * GNU Make
37# * CMake
38# * GCC and Clang (recent enough for using ASan with gcc and MemSan with clang, or valgrind)
Andrzej Kurek05be06c2018-06-28 04:41:50 -040039# * G++
Gilles Peskine192c72f2017-12-21 15:59:21 +010040# * arm-gcc and mingw-gcc
41# * ArmCC 5 and ArmCC 6, unless invoked with --no-armcc
Gilles Peskine192c72f2017-12-21 15:59:21 +010042# * OpenSSL and GnuTLS command line tools, recent enough for the
43# interoperability tests. If they don't support SSLv3 then a legacy
44# version of these tools must be present as well (search for LEGACY
45# below).
46# See the invocation of check_tools below for details.
47#
48# This script must be invoked from the toplevel directory of a git
49# working copy of Mbed TLS.
50#
51# Note that the output is not saved. You may want to run
52# script -c tests/scripts/all.sh
53# or
54# tests/scripts/all.sh >all.log 2>&1
55#
56# Notes for maintainers
57# ---------------------
58#
Gilles Peskine8f073122018-11-27 15:58:47 +010059# The bulk of the code is organized into functions that follow one of the
60# following naming conventions:
61# * pre_XXX: things to do before running the tests, in order.
62# * component_XXX: independent components. They can be run in any order.
Gilles Peskinec70637a2019-01-09 22:29:17 +010063# * component_check_XXX: quick tests that aren't worth parallelizing.
64# * component_build_XXX: build things but don't run them.
65# * component_test_XXX: build and test.
Gilles Peskine878cf602019-01-06 20:50:38 +000066# * support_XXX: if support_XXX exists and returns false then
67# component_XXX is not run by default.
Gilles Peskine8f073122018-11-27 15:58:47 +010068# * post_XXX: things to do after running the tests.
69# * other: miscellaneous support functions.
70#
Gilles Peskinec70637a2019-01-09 22:29:17 +010071# Each component must start by invoking `msg` with a short informative message.
72#
73# The framework performs some cleanup tasks after each component. This
74# means that components can assume that the working directory is in a
75# cleaned-up state, and don't need to perform the cleanup themselves.
76# * Run `make clean`.
77# * Restore `include/mbedtks/config.h` from a backup made before running
78# the component.
Philippe Antoine1c582c32019-06-25 21:55:21 +020079# * Check out `Makefile`, `library/Makefile`, `programs/Makefile`,
Philippe Antoine5dece6d2019-06-27 16:55:07 +020080# `tests/Makefile` and `programs/fuzz/Makefile` from git.
Philippe Antoine1c582c32019-06-25 21:55:21 +020081# This cleans up after an in-tree use of CMake.
Gilles Peskinec70637a2019-01-09 22:29:17 +010082#
83# Any command that is expected to fail must be protected so that the
84# script keeps running in --keep-going mode despite `set -e`. In keep-going
85# mode, if a protected command fails, this is logged as a failure and the
86# script will exit with a failure status once it has run all components.
87# Commands can be protected in any of the following ways:
88# * `make` is a function which runs the `make` command with protection.
89# Note that you must write `make VAR=value`, not `VAR=value make`,
90# because the `VAR=value make` syntax doesn't work with functions.
91# * Put `report_status` before the command to protect it.
92# * Put `if_build_successful` before a command. This protects it, and
93# additionally skips it if a prior invocation of `make` in the same
94# component failed.
95#
Gilles Peskine192c72f2017-12-21 15:59:21 +010096# The tests are roughly in order from fastest to slowest. This doesn't
97# have to be exact, but in general you should add slower tests towards
98# the end and fast checks near the beginning.
Gilles Peskine192c72f2017-12-21 15:59:21 +010099
100
101
102################################################################
103#### Initialization and command line parsing
104################################################################
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100105
SimonB2e23c822016-04-16 21:54:39 +0100106# Abort on errors (and uninitialised variables)
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100107set -eu
108
Gilles Peskine8f073122018-11-27 15:58:47 +0100109pre_check_environment () {
Gilles Peskinea16c2b12019-01-06 19:58:02 +0000110 if [ -d library -a -d include -a -d tests ]; then :; else
Gilles Peskine8f073122018-11-27 15:58:47 +0100111 echo "Must be run from mbed TLS root" >&2
112 exit 1
113 fi
114}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100115
Gilles Peskine8f073122018-11-27 15:58:47 +0100116pre_initialize_variables () {
117 CONFIG_H='include/mbedtls/config.h'
118 CONFIG_BAK="$CONFIG_H.bak"
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200119
Gilles Peskine8f073122018-11-27 15:58:47 +0100120 MEMORY=0
121 FORCE=0
122 KEEP_GOING=0
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100123
Jaeden Ameroc4cc2512019-01-30 15:35:44 +0000124 # Default commands, can be overridden by the environment
Gilles Peskine8f073122018-11-27 15:58:47 +0100125 : ${OPENSSL:="openssl"}
126 : ${OPENSSL_LEGACY:="$OPENSSL"}
127 : ${OPENSSL_NEXT:="$OPENSSL"}
128 : ${GNUTLS_CLI:="gnutls-cli"}
129 : ${GNUTLS_SERV:="gnutls-serv"}
130 : ${GNUTLS_LEGACY_CLI:="$GNUTLS_CLI"}
131 : ${GNUTLS_LEGACY_SERV:="$GNUTLS_SERV"}
132 : ${OUT_OF_SOURCE_DIR:=./mbedtls_out_of_source_build}
133 : ${ARMC5_BIN_DIR:=/usr/bin}
134 : ${ARMC6_BIN_DIR:=/usr/bin}
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
141 # Gather the list of available components. These are the functions
142 # defined in this script whose name starts with "component_".
143 # Parse the script with sed, because in sh there is no way to list
144 # defined functions.
145 ALL_COMPONENTS=$(sed -n 's/^ *component_\([0-9A-Z_a-z]*\) *().*/\1/p' <"$0")
146
147 # Exclude components that are not supported on this platform.
148 SUPPORTED_COMPONENTS=
149 for component in $ALL_COMPONENTS; do
150 case $(type "support_$component" 2>&1) in
151 *' function'*)
152 if ! support_$component; then continue; fi;;
153 esac
154 SUPPORTED_COMPONENTS="$SUPPORTED_COMPONENTS $component"
155 done
Gilles Peskine8f073122018-11-27 15:58:47 +0100156}
Andres AG38495a32016-07-12 16:54:33 +0100157
Gilles Peskinea28db922019-01-10 00:05:18 +0100158# Test whether the component $1 is included in the command line patterns.
159is_component_included()
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100160{
161 set -f
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000162 for pattern in $COMMAND_LINE_COMPONENTS; do
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100163 set +f
164 case ${1#component_} in $pattern) return 0;; esac
165 done
166 set +f
167 return 1
168}
Andres AG7770ea82016-10-10 15:46:20 +0100169
Simon Butcher41eeccf2016-09-07 00:07:09 +0100170usage()
Andres AGd9eba4b2016-08-26 14:42:14 +0100171{
Gilles Peskine709346a2017-12-10 23:43:39 +0100172 cat <<EOF
Gilles Peskine92525112018-11-27 18:15:35 +0100173Usage: $0 [OPTION]... [COMPONENT]...
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100174Run mbedtls release validation tests.
Gilles Peskine92525112018-11-27 18:15:35 +0100175By default, run all tests. With one or more COMPONENT, run only those.
Gilles Peskinea28db922019-01-10 00:05:18 +0100176COMPONENT can be the name of a component or a shell wildcard pattern.
177
178Examples:
179 $0 "check_*"
180 Run all sanity checks.
181 $0 --no-armcc --except test_memsan
182 Run everything except builds that require armcc and MemSan.
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100183
184Special options:
185 -h|--help Print this help and exit.
Gilles Peskine878cf602019-01-06 20:50:38 +0000186 --list-all-components List all available test components and exit.
187 --list-components List components supported on this platform and exit.
Gilles Peskine709346a2017-12-10 23:43:39 +0100188
189General options:
190 -f|--force Force the tests to overwrite any modified files.
Gilles Peskine7c652162017-12-11 00:01:40 +0100191 -k|--keep-going Run all tests and report errors at the end.
Gilles Peskine709346a2017-12-10 23:43:39 +0100192 -m|--memory Additional optional memory tests.
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100193 --armcc Run ARM Compiler builds (on by default).
Gilles Peskinea28db922019-01-10 00:05:18 +0100194 --except Exclude the COMPONENTs listed on the command line,
195 instead of running only those.
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100196 --no-armcc Skip ARM Compiler builds.
Gilles Peskine38d81652018-03-21 08:40:26 +0100197 --no-force Refuse to overwrite modified files (default).
198 --no-keep-going Stop at the first error (default).
199 --no-memory No additional memory tests (default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100200 --out-of-source-dir=<path> Directory used for CMake out-of-source build tests.
Gilles Peskine38d81652018-03-21 08:40:26 +0100201 --random-seed Use a random seed value for randomized tests (default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100202 -r|--release-test Run this script in release mode. This fixes the seed value to 1.
203 -s|--seed Integer seed value to use for this test run.
204
205Tool path options:
206 --armc5-bin-dir=<ARMC5_bin_dir_path> ARM Compiler 5 bin directory.
207 --armc6-bin-dir=<ARMC6_bin_dir_path> ARM Compiler 6 bin directory.
208 --gnutls-cli=<GnuTLS_cli_path> GnuTLS client executable to use for most tests.
209 --gnutls-serv=<GnuTLS_serv_path> GnuTLS server executable to use for most tests.
210 --gnutls-legacy-cli=<GnuTLS_cli_path> GnuTLS client executable to use for legacy tests.
211 --gnutls-legacy-serv=<GnuTLS_serv_path> GnuTLS server executable to use for legacy tests.
212 --openssl=<OpenSSL_path> OpenSSL executable to use for most tests.
213 --openssl-legacy=<OpenSSL_path> OpenSSL executable to use for legacy tests e.g. SSLv3.
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100214 --openssl-next=<OpenSSL_path> OpenSSL executable to use for recent things like ARIA
Gilles Peskine709346a2017-12-10 23:43:39 +0100215EOF
SimonB2e23c822016-04-16 21:54:39 +0100216}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100217
218# remove built files as well as the cmake cache/config
219cleanup()
220{
Gilles Peskinea71d64c2018-03-21 12:16:57 +0100221 if [ -n "${MBEDTLS_ROOT_DIR+set}" ]; then
222 cd "$MBEDTLS_ROOT_DIR"
223 fi
224
Gilles Peskine7c652162017-12-11 00:01:40 +0100225 command make clean
Jaeden Ameroed93bdc2018-11-02 16:57:24 +0000226 cd crypto
227 command make clean
228 cd ..
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200229
Gilles Peskine31b07e22018-03-21 12:15:06 +0100230 # Remove CMake artefacts
Jaeden Amero2d0e00f2018-11-07 18:46:41 +0000231 find . -name .git -prune -o \
Gilles Peskine31b07e22018-03-21 12:15:06 +0100232 -iname CMakeFiles -exec rm -rf {} \+ -o \
233 \( -iname cmake_install.cmake -o \
234 -iname CTestTestfile.cmake -o \
235 -iname CMakeCache.txt \) -exec rm {} \+
236 # Recover files overwritten by in-tree CMake builds
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000237 rm -f include/Makefile include/mbedtls/Makefile programs/*/Makefile
Philippe Antoine5dece6d2019-06-27 16:55:07 +0200238 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile
239 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile
Jaeden Ameroed93bdc2018-11-02 16:57:24 +0000240 cd crypto
241 rm -f include/Makefile include/mbedtls/Makefile programs/*/Makefile
242 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile
243 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile
244 cd ..
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200245
Jaeden Ameroab83fdf2019-06-20 17:38:22 +0100246 # Remove any artifacts from the component_test_cmake_as_subdirectory test.
247 rm -rf programs/test/cmake_subproject/build
248 rm -f programs/test/cmake_subproject/Makefile
249 rm -f programs/test/cmake_subproject/cmake_subproject
250
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200251 if [ -f "$CONFIG_BAK" ]; then
252 mv "$CONFIG_BAK" "$CONFIG_H"
253 fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100254}
255
Gilles Peskine7c652162017-12-11 00:01:40 +0100256# Executed on exit. May be redefined depending on command line options.
257final_report () {
258 :
259}
260
261fatal_signal () {
262 cleanup
263 final_report $1
264 trap - $1
265 kill -$1 $$
266}
267
268trap 'fatal_signal HUP' HUP
269trap 'fatal_signal INT' INT
270trap 'fatal_signal TERM' TERM
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200271
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100272msg()
273{
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100274 if [ -n "${current_component:-}" ]; then
275 current_section="${current_component#component_}: $1"
276 else
277 current_section="$1"
278 fi
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100279 echo ""
280 echo "******************************************************************"
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100281 echo "* $current_section "
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000282 printf "* "; date
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100283 echo "******************************************************************"
284}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100285
Gilles Peskine8f073122018-11-27 15:58:47 +0100286armc6_build_test()
287{
288 FLAGS="$1"
Andres AGa5cd9732016-10-17 15:23:10 +0100289
Gilles Peskine8f073122018-11-27 15:58:47 +0100290 msg "build: ARM Compiler 6 ($FLAGS), make"
291 ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \
292 WARNING_CFLAGS='-xc -std=c99' make lib
293 make clean
294}
Andres AGa5cd9732016-10-17 15:23:10 +0100295
Andres AGd9eba4b2016-08-26 14:42:14 +0100296err_msg()
297{
298 echo "$1" >&2
299}
300
301check_tools()
302{
303 for TOOL in "$@"; do
Andres AG98393602017-01-31 17:04:45 +0000304 if ! `type "$TOOL" >/dev/null 2>&1`; then
Andres AGd9eba4b2016-08-26 14:42:14 +0100305 err_msg "$TOOL not found!"
306 exit 1
307 fi
308 done
309}
310
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400311check_headers_in_cpp () {
Peter Kolbus1bc1a4c2019-02-01 17:19:08 -0600312 ls include/mbedtls | grep "\.h$" >headers.txt
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400313 <programs/test/cpp_dummy_build.cpp sed -n 's/"$//; s!^#include "mbedtls/!!p' |
314 sort |
315 diff headers.txt -
316 rm headers.txt
317}
318
Gilles Peskine8f073122018-11-27 15:58:47 +0100319pre_parse_command_line () {
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000320 COMMAND_LINE_COMPONENTS=
Gilles Peskinea28db922019-01-10 00:05:18 +0100321 all_except=0
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000322 no_armcc=
SimonB2e23c822016-04-16 21:54:39 +0100323
Gilles Peskine8f073122018-11-27 15:58:47 +0100324 while [ $# -gt 0 ]; do
Gilles Peskine55f7c942019-01-09 22:28:21 +0100325 case "$1" in
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000326 --armcc) no_armcc=;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100327 --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
328 --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000329 --except) all_except=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100330 --force|-f) FORCE=1;;
331 --gnutls-cli) shift; GNUTLS_CLI="$1";;
332 --gnutls-legacy-cli) shift; GNUTLS_LEGACY_CLI="$1";;
333 --gnutls-legacy-serv) shift; GNUTLS_LEGACY_SERV="$1";;
334 --gnutls-serv) shift; GNUTLS_SERV="$1";;
335 --help|-h) usage; exit;;
336 --keep-going|-k) KEEP_GOING=1;;
Gilles Peskine878cf602019-01-06 20:50:38 +0000337 --list-all-components) printf '%s\n' $ALL_COMPONENTS; exit;;
338 --list-components) printf '%s\n' $SUPPORTED_COMPONENTS; exit;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100339 --memory|-m) MEMORY=1;;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000340 --no-armcc) no_armcc=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100341 --no-force) FORCE=0;;
342 --no-keep-going) KEEP_GOING=0;;
343 --no-memory) MEMORY=0;;
344 --openssl) shift; OPENSSL="$1";;
345 --openssl-legacy) shift; OPENSSL_LEGACY="$1";;
346 --openssl-next) shift; OPENSSL_NEXT="$1";;
347 --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
348 --random-seed) unset SEED;;
349 --release-test|-r) SEED=1;;
350 --seed|-s) shift; SEED="$1";;
351 -*)
352 echo >&2 "Unknown option: $1"
353 echo >&2 "Run $0 --help for usage."
354 exit 120
355 ;;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000356 *) COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS $1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100357 esac
358 shift
Gilles Peskine8f073122018-11-27 15:58:47 +0100359 done
SimonB2e23c822016-04-16 21:54:39 +0100360
Gilles Peskinea28db922019-01-10 00:05:18 +0100361 # With no list of components, run everything.
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000362 if [ -z "$COMMAND_LINE_COMPONENTS" ]; then
363 all_except=1
Andres AGdc192212016-08-31 17:33:13 +0100364 fi
365
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000366 # --no-armcc is a legacy option. The modern way is --except '*_armcc*'.
367 # Ignore it if components are listed explicitly on the command line.
Gilles Peskinea28db922019-01-10 00:05:18 +0100368 if [ -n "$no_armcc" ] && [ $all_except -eq 1 ]; then
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000369 COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS *_armcc*"
SimonB2e23c822016-04-16 21:54:39 +0100370 fi
SimonB2e23c822016-04-16 21:54:39 +0100371
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000372 # Build the list of components to run.
Gilles Peskinea28db922019-01-10 00:05:18 +0100373 RUN_COMPONENTS=
374 for component in $SUPPORTED_COMPONENTS; do
375 if is_component_included "$component"; [ $? -eq $all_except ]; then
376 RUN_COMPONENTS="$RUN_COMPONENTS $component"
377 fi
378 done
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000379
380 unset all_except
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000381 unset no_armcc
Gilles Peskine8f073122018-11-27 15:58:47 +0100382}
SimonB2e23c822016-04-16 21:54:39 +0100383
Gilles Peskine8f073122018-11-27 15:58:47 +0100384pre_check_git () {
385 if [ $FORCE -eq 1 ]; then
Gilles Peskine53190e62019-01-09 23:17:35 +0100386 rm -rf "$OUT_OF_SOURCE_DIR"
Gilles Peskine8f073122018-11-27 15:58:47 +0100387 git checkout-index -f -q $CONFIG_H
388 cleanup
389 else
SimonB2e23c822016-04-16 21:54:39 +0100390
Gilles Peskine8f073122018-11-27 15:58:47 +0100391 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
392 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
393 echo "You can either delete this directory manually, or force the test by rerunning"
394 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
395 exit 1
396 fi
397
Gilles Peskined1174cf2019-01-09 22:30:01 +0100398 if ! git diff --quiet include/mbedtls/config.h; then
Gilles Peskine8f073122018-11-27 15:58:47 +0100399 err_msg "Warning - the configuration file 'include/mbedtls/config.h' has been edited. "
400 echo "You can either delete or preserve your work, or force the test by rerunning the"
401 echo "script as: $0 --force"
402 exit 1
403 fi
SimonB2e23c822016-04-16 21:54:39 +0100404 fi
Andrzej Kureke9c3b812019-02-05 05:34:21 -0500405 if ! [ -f crypto/Makefile ]; then
406 echo "Please initialize the crypto submodule" >&2
407 exit 1
408 fi
Gilles Peskine8f073122018-11-27 15:58:47 +0100409}
SimonB2e23c822016-04-16 21:54:39 +0100410
Andrzej Kurekeb508712019-02-14 07:18:59 -0500411pre_check_seedfile () {
412 if [ ! -f "./tests/seedfile" ]; then
413 dd if=/dev/urandom of=./tests/seedfile bs=32 count=1
414 fi
Jaeden Amero97145102019-03-18 16:31:21 +0000415 if [ ! -f "./crypto/tests/seedfile" ]; then
416 dd if=/dev/urandom of=./crypto/tests/seedfile bs=32 count=1
417 fi
Andrzej Kurekeb508712019-02-14 07:18:59 -0500418}
419
Gilles Peskine8f073122018-11-27 15:58:47 +0100420pre_setup_keep_going () {
Gilles Peskine7c652162017-12-11 00:01:40 +0100421 failure_summary=
422 failure_count=0
423 start_red=
424 end_color=
425 if [ -t 1 ]; then
Gilles Peskine9736b9d2018-01-02 21:54:17 +0100426 case "${TERM:-}" in
Gilles Peskine7c652162017-12-11 00:01:40 +0100427 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
428 start_red=$(printf '\033[31m')
429 end_color=$(printf '\033[0m')
430 ;;
431 esac
432 fi
433 record_status () {
434 if "$@"; then
435 last_status=0
436 else
437 last_status=$?
438 text="$current_section: $* -> $last_status"
439 failure_summary="$failure_summary
440$text"
441 failure_count=$((failure_count + 1))
442 echo "${start_red}^^^^$text^^^^${end_color}"
443 fi
444 }
445 make () {
446 case "$*" in
447 *test|*check)
448 if [ $build_status -eq 0 ]; then
449 record_status command make "$@"
450 else
451 echo "(skipped because the build failed)"
452 fi
453 ;;
454 *)
455 record_status command make "$@"
456 build_status=$last_status
457 ;;
458 esac
459 }
460 final_report () {
461 if [ $failure_count -gt 0 ]; then
462 echo
463 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
464 echo "${start_red}FAILED: $failure_count${end_color}$failure_summary"
465 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Jaeden Amero7c1258d2018-07-20 16:42:14 +0100466 exit 1
Gilles Peskine7c652162017-12-11 00:01:40 +0100467 elif [ -z "${1-}" ]; then
468 echo "SUCCESS :)"
469 fi
470 if [ -n "${1-}" ]; then
471 echo "Killed by SIG$1."
472 fi
473 }
Gilles Peskine8f073122018-11-27 15:58:47 +0100474}
475
Gilles Peskine7c652162017-12-11 00:01:40 +0100476if_build_succeeded () {
477 if [ $build_status -eq 0 ]; then
478 record_status "$@"
479 fi
480}
481
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200482# to be used instead of ! for commands run with
483# record_status or if_build_succeeded
484not() {
485 ! "$@"
486}
487
Gilles Peskine8f073122018-11-27 15:58:47 +0100488pre_print_configuration () {
489 msg "info: $0 configuration"
490 echo "MEMORY: $MEMORY"
491 echo "FORCE: $FORCE"
492 echo "SEED: ${SEED-"UNSET"}"
493 echo "OPENSSL: $OPENSSL"
494 echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
495 echo "OPENSSL_NEXT: $OPENSSL_NEXT"
496 echo "GNUTLS_CLI: $GNUTLS_CLI"
497 echo "GNUTLS_SERV: $GNUTLS_SERV"
498 echo "GNUTLS_LEGACY_CLI: $GNUTLS_LEGACY_CLI"
499 echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV"
500 echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
501 echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
502}
Andres AG7770ea82016-10-10 15:46:20 +0100503
Andres AGd9eba4b2016-08-26 14:42:14 +0100504# Make sure the tools we need are available.
Gilles Peskine8f073122018-11-27 15:58:47 +0100505pre_check_tools () {
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000506 # Build the list of variables to pass to output_env.sh.
507 set env
SimonB2e23c822016-04-16 21:54:39 +0100508
Gilles Peskine87964262019-01-06 22:40:00 +0000509 case " $RUN_COMPONENTS " in
510 # Require OpenSSL and GnuTLS if running any tests (as opposed to
511 # only doing builds). Not all tests run OpenSSL and GnuTLS, but this
512 # is a good enough approximation in practice.
513 *" test_"*)
514 # To avoid setting OpenSSL and GnuTLS for each call to compat.sh
515 # and ssl-opt.sh, we just export the variables they require.
516 export OPENSSL_CMD="$OPENSSL"
517 export GNUTLS_CLI="$GNUTLS_CLI"
518 export GNUTLS_SERV="$GNUTLS_SERV"
519 # Avoid passing --seed flag in every call to ssl-opt.sh
520 if [ -n "${SEED-}" ]; then
521 export SEED
522 fi
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000523 set "$@" OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY"
524 set "$@" GNUTLS_CLI="$GNUTLS_CLI" GNUTLS_SERV="$GNUTLS_SERV"
525 set "$@" GNUTLS_LEGACY_CLI="$GNUTLS_LEGACY_CLI"
526 set "$@" GNUTLS_LEGACY_SERV="$GNUTLS_LEGACY_SERV"
Gilles Peskine87964262019-01-06 22:40:00 +0000527 check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$OPENSSL_NEXT" \
528 "$GNUTLS_CLI" "$GNUTLS_SERV" \
529 "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV"
530 ;;
531 esac
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200532
Gilles Peskine87964262019-01-06 22:40:00 +0000533 case " $RUN_COMPONENTS " in
534 *_doxygen[_\ ]*) check_tools "doxygen" "dot";;
535 esac
Andres AGd9eba4b2016-08-26 14:42:14 +0100536
Gilles Peskine87964262019-01-06 22:40:00 +0000537 case " $RUN_COMPONENTS " in
538 *_arm_none_eabi_gcc[_\ ]*) check_tools "arm-none-eabi-gcc";;
539 esac
Andres AGd9eba4b2016-08-26 14:42:14 +0100540
Gilles Peskine87964262019-01-06 22:40:00 +0000541 case " $RUN_COMPONENTS " in
542 *_mingw[_\ ]*) check_tools "i686-w64-mingw32-gcc";;
543 esac
544
545 case " $RUN_COMPONENTS " in
546 *" test_zeroize "*) check_tools "gdb";;
547 esac
548
549 case " $RUN_COMPONENTS " in
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000550 *_armcc*)
Gilles Peskine87964262019-01-06 22:40:00 +0000551 ARMC5_CC="$ARMC5_BIN_DIR/armcc"
552 ARMC5_AR="$ARMC5_BIN_DIR/armar"
553 ARMC6_CC="$ARMC6_BIN_DIR/armclang"
554 ARMC6_AR="$ARMC6_BIN_DIR/armar"
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000555 check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC6_CC" "$ARMC6_AR";;
556 esac
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000557
558 msg "info: output_env.sh"
559 case $RUN_COMPONENTS in
560 *_armcc*)
561 set "$@" ARMC5_CC="$ARMC5_CC" ARMC6_CC="$ARMC6_CC" RUN_ARMCC=1;;
562 *) set "$@" RUN_ARMCC=0;;
563 esac
564 "$@" scripts/output_env.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100565}
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100566
Gilles Peskine192c72f2017-12-21 15:59:21 +0100567
568
569################################################################
570#### Basic checks
571################################################################
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100572
573#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200574# Test Suites to be executed
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100575#
Manuel Pégourié-Gonnard3d404b42015-07-08 21:59:16 +0100576# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200577# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100578# 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 +0200579# time, so start with a GCC build).
580# 2. Minimize total running time, by avoiding useless rebuilds
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100581#
Manuel Pégourié-Gonnard259b08a2016-01-08 16:27:41 +0100582# Indicative running times are given for reference.
583
Gilles Peskine8f073122018-11-27 15:58:47 +0100584component_check_recursion () {
585 msg "test: recursion.pl" # < 1s
586 record_status tests/scripts/recursion.pl library/*.c
587}
Janos Follathb72c6782016-07-19 14:54:17 +0100588
Gilles Peskine8f073122018-11-27 15:58:47 +0100589component_check_generated_files () {
590 msg "test: freshness of generated source files" # < 1s
591 record_status tests/scripts/check-generated-files.sh
592}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200593
Gilles Peskine8f073122018-11-27 15:58:47 +0100594component_check_doxy_blocks () {
595 msg "test: doxygen markup outside doxygen blocks" # < 1s
596 record_status tests/scripts/check-doxy-blocks.pl
597}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200598
Gilles Peskine8f073122018-11-27 15:58:47 +0100599component_check_files () {
600 msg "test: check-files.py" # < 1s
Gilles Peskine8f073122018-11-27 15:58:47 +0100601 record_status tests/scripts/check-files.py
602}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200603
Gilles Peskine8f073122018-11-27 15:58:47 +0100604component_check_names () {
605 msg "test/build: declared and exported names" # < 3s
Gilles Peskine13f97dc2019-05-15 17:52:22 +0200606 record_status tests/scripts/check-names.sh -v
Gilles Peskine8f073122018-11-27 15:58:47 +0100607}
Darryl Greena07039c2018-03-13 16:48:16 +0000608
Gilles Peskine8f073122018-11-27 15:58:47 +0100609component_check_doxygen_warnings () {
610 msg "test: doxygen warnings" # ~ 3s
Gilles Peskine8f073122018-11-27 15:58:47 +0100611 record_status tests/scripts/doxygen.sh
612}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200613
Gilles Peskine192c72f2017-12-21 15:59:21 +0100614
615
616################################################################
617#### Build and test many configurations and targets
618################################################################
619
Gilles Peskine7832c9f2019-04-08 17:00:15 +0200620component_test_default_out_of_box () {
621 msg "build: make, default config (out-of-box)" # ~1min
622 make
623
624 msg "test: main suites make, default config (out-of-box)" # ~10s
625 make test
626
627 msg "selftest: make, default config (out-of-box)" # ~10s
628 programs/test/selftest
629}
630
Gilles Peskine8f073122018-11-27 15:58:47 +0100631component_test_default_cmake_gcc_asan () {
632 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100633 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
634 make
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200635
Gilles Peskine8f073122018-11-27 15:58:47 +0100636 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
637 make test
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200638
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 Becker01635512019-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
655 msg "test: ssl-opt.sh (full config, ASan build)"
656 if_build_succeeded tests/ssl-opt.sh
657
658 msg "test: compat.sh (full config, ASan build)"
659 if_build_succeeded tests/compat.sh
660}
661
Gilles Peskine782f4112018-11-27 16:11:09 +0100662component_test_ref_configs () {
663 msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
664 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
665 record_status tests/scripts/test-ref-configs.pl
666}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200667
Gilles Peskine8f073122018-11-27 15:58:47 +0100668component_test_sslv3 () {
669 msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100670 scripts/config.pl set MBEDTLS_SSL_PROTO_SSL3
671 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
672 make
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200673
Gilles Peskine8f073122018-11-27 15:58:47 +0100674 msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
675 make test
Simon Butcher3ea7f522016-03-07 23:22:10 +0000676
Gilles Peskine8f073122018-11-27 15:58:47 +0100677 msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
678 if_build_succeeded tests/compat.sh -m 'tls1 tls1_1 tls1_2 dtls1 dtls1_2'
679 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
Simon Butcher3ea7f522016-03-07 23:22:10 +0000680
Gilles Peskine8f073122018-11-27 15:58:47 +0100681 msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
682 if_build_succeeded tests/ssl-opt.sh
683}
Simon Butcher3ea7f522016-03-07 23:22:10 +0000684
Gilles Peskine8f073122018-11-27 15:58:47 +0100685component_test_no_renegotiation () {
686 msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100687 scripts/config.pl unset MBEDTLS_SSL_RENEGOTIATION
688 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
689 make
Simon Butcher3ea7f522016-03-07 23:22:10 +0000690
Gilles Peskine8f073122018-11-27 15:58:47 +0100691 msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
692 make test
Hanno Becker134c2ab2017-10-12 15:29:50 +0100693
Gilles Peskine8f073122018-11-27 15:58:47 +0100694 msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
695 if_build_succeeded tests/ssl-opt.sh
696}
Hanno Becker134c2ab2017-10-12 15:29:50 +0100697
Hanno Beckera545be22019-05-10 14:45:37 +0100698component_test_no_pem_no_fs () {
699 msg "build: Default + !MBEDTLS_PEM_PARSE_C + !MBEDTLS_FS_IO (ASan build)"
700 scripts/config.pl unset MBEDTLS_PEM_PARSE_C
701 scripts/config.pl unset MBEDTLS_FS_IO
702 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
703 make
704
705 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - main suites (inc. selftests) (ASan build)" # ~ 50s
706 make test
707
708 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - ssl-opt.sh (ASan build)" # ~ 6 min
709 if_build_succeeded tests/ssl-opt.sh
710}
711
Gilles Peskine8f073122018-11-27 15:58:47 +0100712component_test_rsa_no_crt () {
713 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100714 scripts/config.pl set MBEDTLS_RSA_NO_CRT
715 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
716 make
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +0100717
Gilles Peskine8f073122018-11-27 15:58:47 +0100718 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
719 make test
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100720
Gilles Peskine8f073122018-11-27 15:58:47 +0100721 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
722 if_build_succeeded tests/ssl-opt.sh -f RSA
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100723
Gilles Peskine8f073122018-11-27 15:58:47 +0100724 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
725 if_build_succeeded tests/compat.sh -t RSA
726}
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100727
Gilles Peskine0c6b7992019-04-12 20:29:48 +0200728component_test_everest () {
729 msg "build: Everest ECDH context (ASan build)" # ~ 6 min
730 scripts/config.pl unset MBEDTLS_ECDH_LEGACY_CONTEXT
731 scripts/config.pl set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
732 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Asan .
733 make
734
735 msg "test: Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
736 make test
737
738 msg "test: Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
739 if_build_succeeded tests/ssl-opt.sh -f ECDH
740
741 msg "test: Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
742 # Exclude some symmetric ciphers that are redundant here to gain time.
743 if_build_succeeded tests/compat.sh -f ECDH -V NO -e 'ARCFOUR\|ARIA\|CAMELLIA\|CHACHA\|DES\|RC4'
744}
745
Gilles Peskine8f073122018-11-27 15:58:47 +0100746component_test_small_ssl_out_content_len () {
747 msg "build: small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100748 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 16384
749 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
750 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
751 make
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100752
Gilles Peskine8f073122018-11-27 15:58:47 +0100753 msg "test: small SSL_OUT_CONTENT_LEN - ssl-opt.sh MFL and large packet tests"
754 if_build_succeeded tests/ssl-opt.sh -f "Max fragment\|Large packet"
755}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000756
Gilles Peskine8f073122018-11-27 15:58:47 +0100757component_test_small_ssl_in_content_len () {
758 msg "build: small SSL_IN_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100759 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 4096
760 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 16384
761 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
762 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000763
Gilles Peskine8f073122018-11-27 15:58:47 +0100764 msg "test: small SSL_IN_CONTENT_LEN - ssl-opt.sh MFL tests"
765 if_build_succeeded tests/ssl-opt.sh -f "Max fragment"
766}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000767
Gilles Peskine8f073122018-11-27 15:58:47 +0100768component_test_small_ssl_dtls_max_buffering () {
769 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0"
Gilles Peskine8f073122018-11-27 15:58:47 +0100770 scripts/config.pl set MBEDTLS_SSL_DTLS_MAX_BUFFERING 1000
771 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
772 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000773
Gilles Peskine8f073122018-11-27 15:58:47 +0100774 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0 - ssl-opt.sh specific reordering test"
775 if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer out-of-order hs msg before reassembling next, free buffered msg"
776}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100777
Gilles Peskine8f073122018-11-27 15:58:47 +0100778component_test_small_mbedtls_ssl_dtls_max_buffering () {
779 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1"
Manuel Pégourié-Gonnardeef4c752019-05-28 10:21:30 +0200780 scripts/config.pl set MBEDTLS_SSL_DTLS_MAX_BUFFERING 190
Gilles Peskine8f073122018-11-27 15:58:47 +0100781 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
782 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100783
Gilles Peskine8f073122018-11-27 15:58:47 +0100784 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1 - ssl-opt.sh specific reordering test"
785 if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer encrypted Finished message, drop for fragmented NewSessionTicket"
786}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100787
Gilles Peskine8f073122018-11-27 15:58:47 +0100788component_test_full_cmake_clang () {
789 msg "build: cmake, full config, clang" # ~ 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100790 scripts/config.pl full
Gilles Peskine8f073122018-11-27 15:58:47 +0100791 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check -D ENABLE_TESTING=On .
792 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100793
Gilles Peskine8f073122018-11-27 15:58:47 +0100794 msg "test: main suites (full config)" # ~ 5s
795 make test
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100796
Gilles Peskine8f073122018-11-27 15:58:47 +0100797 msg "test: ssl-opt.sh default, ECJPAKE, SSL async (full config)" # ~ 1s
798 if_build_succeeded tests/ssl-opt.sh -f 'Default\|ECJPAKE\|SSL async private'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200799
Andres Amaya Garcia2dadab72019-01-08 21:42:27 +0000800 msg "test: compat.sh RC4, DES, 3DES & NULL (full config)" # ~ 2 min
Andres Amaya Garcia419bd002019-02-19 20:20:57 +0000801 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 +0200802
Gilles Peskine8f073122018-11-27 15:58:47 +0100803 msg "test: compat.sh ARIA + ChachaPoly"
804 if_build_succeeded env OPENSSL_CMD="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
805}
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200806
Gilles Peskine8f073122018-11-27 15:58:47 +0100807component_build_deprecated () {
808 msg "build: make, full config + DEPRECATED_WARNING, gcc -O" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100809 scripts/config.pl full
810 scripts/config.pl set MBEDTLS_DEPRECATED_WARNING
811 # Build with -O -Wextra to catch a maximum of issues.
812 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra' lib programs
813 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100814
Gilles Peskine8f073122018-11-27 15:58:47 +0100815 msg "build: make, full config + DEPRECATED_REMOVED, clang -O" # ~ 30s
816 # No cleanup, just tweak the configuration and rebuild
817 make clean
818 scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
819 scripts/config.pl set MBEDTLS_DEPRECATED_REMOVED
820 # Build with -O -Wextra to catch a maximum of issues.
821 make CC=clang CFLAGS='-O -Werror -Wall -Wextra' lib programs
822 make CC=clang CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
823}
Jaeden Ameroed93bdc2018-11-02 16:57:24 +0000824
Gilles Peskine8f073122018-11-27 15:58:47 +0100825component_test_depends_curves () {
826 msg "test/build: curves.pl (gcc)" # ~ 4 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100827 record_status tests/scripts/curves.pl
828}
Jaeden Ameroacaabe72018-11-07 11:52:52 +0000829
Gilles Peskine8f073122018-11-27 15:58:47 +0100830component_test_depends_hashes () {
831 msg "test/build: depends-hashes.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100832 record_status tests/scripts/depends-hashes.pl
833}
Jaeden Ameroacaabe72018-11-07 11:52:52 +0000834
Gilles Peskine8f073122018-11-27 15:58:47 +0100835component_test_depends_pkalgs () {
836 msg "test/build: depends-pkalgs.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100837 record_status tests/scripts/depends-pkalgs.pl
838}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100839
Gilles Peskine8f073122018-11-27 15:58:47 +0100840component_build_key_exchanges () {
841 msg "test/build: key-exchanges (gcc)" # ~ 1 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100842 record_status tests/scripts/key-exchanges.pl
843}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100844
Gilles Peskine8f073122018-11-27 15:58:47 +0100845component_build_default_make_gcc_and_cxx () {
846 msg "build: Unix make, -Os (gcc)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100847 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100848
Gilles Peskine8f073122018-11-27 15:58:47 +0100849 msg "test: verify header list in cpp_dummy_build.cpp"
850 record_status check_headers_in_cpp
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100851
Gilles Peskine8f073122018-11-27 15:58:47 +0100852 msg "build: Unix make, incremental g++"
853 make TEST_CPP=1
854}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100855
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100856component_test_no_use_psa_crypto_full_cmake_asan() {
857 # full minus MBEDTLS_USE_PSA_CRYPTO: run the same set of tests as basic-build-test.sh
Gilles Peskinedc3a1792019-09-03 11:42:04 +0200858 msg "build: cmake, full config minus MBEDTLS_USE_PSA_CRYPTO, ASan"
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500859 scripts/config.pl full
Jaeden Amero0f220ec2019-07-05 15:03:40 +0100860 scripts/config.pl set MBEDTLS_ECP_RESTARTABLE # not using PSA, so enable restartable ECC
Gilles Peskine6ce30722019-07-31 18:13:20 +0200861 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_C
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100862 scripts/config.pl unset MBEDTLS_USE_PSA_CRYPTO
863 scripts/config.pl unset MBEDTLS_PSA_ITS_FILE_C
Andrzej Kurek324b2f72019-04-18 08:59:12 -0400864 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_C
Manuel Pégourié-Gonnardd8167e82019-02-01 11:12:52 +0100865 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500866 make
Manuel Pégourié-Gonnard43be6cd2017-06-20 09:53:42 +0200867
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100868 msg "test: main suites (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500869 make test
Manuel Pégourié-Gonnard503a5ef2015-10-23 09:04:45 +0200870
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100871 msg "test: ssl-opt.sh (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500872 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100873
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100874 msg "test: compat.sh default (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500875 if_build_succeeded tests/compat.sh
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400876
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100877 msg "test: compat.sh ssl3 (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500878 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400879
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100880 msg "test: compat.sh RC4, DES & NULL (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500881 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 -0500882
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100883 msg "test: compat.sh ARIA + ChachaPoly (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500884 if_build_succeeded env OPENSSL_CMD="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
885}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500886
Gilles Peskineadcde5e2019-06-12 16:05:50 +0200887component_test_check_params_functionality () {
888 msg "build+test: MBEDTLS_CHECK_PARAMS functionality"
889 scripts/config.pl full # includes CHECK_PARAMS
890 # Make MBEDTLS_PARAM_FAILED call mbedtls_param_failed().
891 scripts/config.pl unset MBEDTLS_CHECK_PARAMS_ASSERT
892 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
893 # Only build and run tests. Do not build sample programs, because
894 # they don't have a mbedtls_param_failed() function.
895 make CC=gcc CFLAGS='-Werror -O1' lib test
896}
897
Gilles Peskineb28636b2019-01-02 19:06:24 +0100898component_test_check_params_without_platform () {
899 msg "build+test: MBEDTLS_CHECK_PARAMS without MBEDTLS_PLATFORM_C"
900 scripts/config.pl full # includes CHECK_PARAMS
Gilles Peskineadcde5e2019-06-12 16:05:50 +0200901 # Keep MBEDTLS_PARAM_FAILED as assert.
Gilles Peskineb28636b2019-01-02 19:06:24 +0100902 scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
903 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
904 scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
905 scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
906 scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
907 scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
908 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
909 scripts/config.pl unset MBEDTLS_PLATFORM_C
910 make CC=gcc CFLAGS='-Werror -O1' all test
911}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500912
Gilles Peskineb28636b2019-01-02 19:06:24 +0100913component_test_check_params_silent () {
914 msg "build+test: MBEDTLS_CHECK_PARAMS with alternative MBEDTLS_PARAM_FAILED()"
915 scripts/config.pl full # includes CHECK_PARAMS
Gilles Peskineadcde5e2019-06-12 16:05:50 +0200916 # Set MBEDTLS_PARAM_FAILED to nothing.
Gilles Peskineb28636b2019-01-02 19:06:24 +0100917 sed -i 's/.*\(#define MBEDTLS_PARAM_FAILED( cond )\).*/\1/' "$CONFIG_H"
918 make CC=gcc CFLAGS='-Werror -O1' all test
919}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500920
Gilles Peskine8f073122018-11-27 15:58:47 +0100921component_test_no_platform () {
922 # Full configuration build, without platform support, file IO and net sockets.
923 # This should catch missing mbedtls_printf definitions, and by disabling file
924 # IO, it should catch missing '#include <stdio.h>'
925 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100926 scripts/config.pl full
927 scripts/config.pl unset MBEDTLS_PLATFORM_C
928 scripts/config.pl unset MBEDTLS_NET_C
929 scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
930 scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
931 scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
932 scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
933 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
934 scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
935 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskine8f073122018-11-27 15:58:47 +0100936 scripts/config.pl unset MBEDTLS_FS_IO
Andrzej Kurek73757082019-04-18 04:14:37 -0400937 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_C
938 scripts/config.pl unset MBEDTLS_PSA_ITS_FILE_C
Gilles Peskine8f073122018-11-27 15:58:47 +0100939 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
940 # to re-enable platform integration features otherwise disabled in C99 builds
941 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -O0 -D_DEFAULT_SOURCE' lib programs
942 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0' test
943}
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +0000944
Gilles Peskine8f073122018-11-27 15:58:47 +0100945component_build_no_std_function () {
946 # catch compile bugs in _uninit functions
947 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100948 scripts/config.pl full
949 scripts/config.pl set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
950 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
951 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
952}
Manuel Pégourié-Gonnarddccb80b2015-06-03 10:20:33 +0100953
Gilles Peskine8f073122018-11-27 15:58:47 +0100954component_build_no_ssl_srv () {
955 msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100956 scripts/config.pl full
957 scripts/config.pl unset MBEDTLS_SSL_SRV_C
958 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
959}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200960
Gilles Peskine8f073122018-11-27 15:58:47 +0100961component_build_no_ssl_cli () {
962 msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100963 scripts/config.pl full
964 scripts/config.pl unset MBEDTLS_SSL_CLI_C
965 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
966}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200967
Gilles Peskine8f073122018-11-27 15:58:47 +0100968component_build_no_sockets () {
969 # Note, C99 compliance can also be tested with the sockets support disabled,
970 # as that requires a POSIX platform (which isn't the same as C99).
971 msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100972 scripts/config.pl full
973 scripts/config.pl unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
974 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
975 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0 -std=c99 -pedantic' lib
976}
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +0200977
Andrzej Kurek69f20aa2019-09-05 09:27:47 -0400978component_test_memory_buffer_allocator_backtrace () {
979 msg "build: default config with memory buffer allocator and backtrace enabled"
Hanno Becker0fb9ba22019-02-26 14:34:13 +0000980 scripts/config.pl set MBEDTLS_MEMORY_BUFFER_ALLOC_C
Andrzej Kurek69f20aa2019-09-05 09:27:47 -0400981 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
Hanno Becker0fb9ba22019-02-26 14:34:13 +0000982 scripts/config.pl set MBEDTLS_MEMORY_BACKTRACE
Andrzej Kurek69f20aa2019-09-05 09:27:47 -0400983 CC=gcc cmake .
984 make
985
986 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C and MBEDTLS_MEMORY_BACKTRACE"
987 make test
988}
989
990component_test_memory_buffer_allocator () {
991 msg "build: default config with memory buffer allocator"
992 scripts/config.pl set MBEDTLS_MEMORY_BUFFER_ALLOC_C
Hanno Beckerd7064202019-06-03 16:35:02 +0100993 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
Hanno Becker0fb9ba22019-02-26 14:34:13 +0000994 CC=gcc cmake .
995 make
996
997 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C"
998 make test
999
1000 msg "test: ssl-opt.sh, MBEDTLS_MEMORY_BUFFER_ALLOC_C"
Andrzej Kurek1e56d2c2019-09-05 10:09:37 -04001001 # MBEDTLS_MEMORY_BUFFER_ALLOC is slow. Skip tests that tend to time out.
1002 if_build_succeeded tests/ssl-opt.sh -e '^DTLS proxy'
Hanno Becker0fb9ba22019-02-26 14:34:13 +00001003}
1004
Gilles Peskine8f073122018-11-27 15:58:47 +01001005component_test_no_max_fragment_length () {
1006 # Run max fragment length tests with MFL disabled
1007 msg "build: default config except MFL extension (ASan build)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +01001008 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
1009 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1010 make
Hanno Becker5175ac62017-09-18 15:36:25 +01001011
Gilles Peskine8f073122018-11-27 15:58:47 +01001012 msg "test: ssl-opt.sh, MFL-related tests"
1013 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length"
1014}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001015
Hanno Becker545ced42019-02-19 11:10:48 +00001016component_test_asan_remove_peer_certificate () {
1017 msg "build: default config with MBEDTLS_SSL_KEEP_PEER_CERTIFICATE disabled (ASan build)"
1018 scripts/config.pl unset MBEDTLS_SSL_KEEP_PEER_CERTIFICATE
1019 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1020 make
1021
1022 msg "test: !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
1023 make test
1024
1025 msg "test: ssl-opt.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
1026 if_build_succeeded tests/ssl-opt.sh
1027
1028 msg "test: compat.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
1029 if_build_succeeded tests/compat.sh
1030}
1031
Gilles Peskine8f073122018-11-27 15:58:47 +01001032component_test_no_max_fragment_length_small_ssl_out_content_len () {
1033 msg "build: no MFL extension, small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +01001034 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
1035 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 16384
1036 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
1037 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1038 make
Angus Grattonc4dd0732018-04-11 16:28:39 +10001039
Gilles Peskine8f073122018-11-27 15:58:47 +01001040 msg "test: MFL tests (disabled MFL extension case) & large packet tests"
1041 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length\|Large buffer"
1042}
Angus Grattonc4dd0732018-04-11 16:28:39 +10001043
Jaeden Amero2de07f12019-06-05 13:32:08 +01001044component_test_when_no_ciphersuites_have_mac () {
1045 msg "build: when no ciphersuites have MAC"
1046 scripts/config.pl unset MBEDTLS_CIPHER_NULL_CIPHER
1047 scripts/config.pl unset MBEDTLS_ARC4_C
1048 scripts/config.pl unset MBEDTLS_CIPHER_MODE_CBC
1049 make
1050
1051 msg "test: !MBEDTLS_SSL_SOME_MODES_USE_MAC"
1052 make test
1053
1054 msg "test ssl-opt.sh: !MBEDTLS_SSL_SOME_MODES_USE_MAC"
Jaeden Amero6b1683d2019-06-05 14:42:50 +01001055 if_build_succeeded tests/ssl-opt.sh -f 'Default\|EtM' -e 'without EtM'
Jaeden Amero2de07f12019-06-05 13:32:08 +01001056}
1057
Gilles Peskine8f073122018-11-27 15:58:47 +01001058component_test_null_entropy () {
1059 msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +01001060 scripts/config.pl set MBEDTLS_TEST_NULL_ENTROPY
1061 scripts/config.pl set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
1062 scripts/config.pl set MBEDTLS_ENTROPY_C
1063 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
1064 scripts/config.pl unset MBEDTLS_ENTROPY_HARDWARE_ALT
1065 scripts/config.pl unset MBEDTLS_HAVEGE_C
Gilles Peskine5fa32a72019-01-06 19:48:30 +00001066 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan -D UNSAFE_BUILD=ON .
Gilles Peskine8f073122018-11-27 15:58:47 +01001067 make
Janos Follath06c54002016-06-09 13:57:40 +01001068
Gilles Peskine8f073122018-11-27 15:58:47 +01001069 msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)"
1070 make test
1071}
Janos Follath06c54002016-06-09 13:57:40 +01001072
Gilles Peskine8f073122018-11-27 15:58:47 +01001073component_test_platform_calloc_macro () {
1074 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +01001075 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
1076 scripts/config.pl set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
1077 scripts/config.pl set MBEDTLS_PLATFORM_FREE_MACRO free
1078 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1079 make
Hanno Beckere5fecec2018-10-11 11:02:52 +01001080
Gilles Peskine8f073122018-11-27 15:58:47 +01001081 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
1082 make test
1083}
Hanno Beckere5fecec2018-10-11 11:02:52 +01001084
Gilles Peskine8f073122018-11-27 15:58:47 +01001085component_test_make_shared () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001086 msg "build/test: make shared" # ~ 40s
Andrzej Kurek87615772019-04-19 15:03:58 -04001087 make SHARED=1 all check -j1
Gilles Peskine56c01612019-07-03 20:43:32 +02001088 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskine8f073122018-11-27 15:58:47 +01001089}
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +02001090
Gilles Peskinecf740502019-07-03 20:43:05 +02001091component_test_cmake_shared () {
1092 msg "build/test: cmake shared" # ~ 2min
1093 cmake -DUSE_SHARED_MBEDTLS_LIBRARY=On .
1094 make
Gilles Peskine56c01612019-07-03 20:43:32 +02001095 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskinecf740502019-07-03 20:43:05 +02001096 make test
1097}
1098
Gilles Peskineabf9b4d2019-07-03 20:42:16 +02001099component_build_mbedtls_config_file () {
1100 msg "build: make with MBEDTLS_CONFIG_FILE" # ~40s
1101 # Use the full config so as to catch a maximum of places where
1102 # the check of MBEDTLS_CONFIG_FILE might be missing.
1103 scripts/config.pl full
1104 sed 's!"check_config.h"!"mbedtls/check_config.h"!' <"$CONFIG_H" >full_config.h
1105 echo '#error "MBEDTLS_CONFIG_FILE is not working"' >"$CONFIG_H"
1106 make CFLAGS="-I '$PWD' -DMBEDTLS_CONFIG_FILE='\"full_config.h\"'"
1107 rm -f full_config.h
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001108}
1109
Gilles Peskine8f073122018-11-27 15:58:47 +01001110component_test_m32_o0 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001111 # Build once with -O0, to compile out the i386 specific inline assembly
1112 msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
Simon Butcher7a6da6e2018-06-27 21:52:54 +01001113 scripts/config.pl full
Gilles Peskine751bb4c2019-07-31 18:12:10 +02001114 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # slow and makes ASan mostly ineffective
Philippe Antoinecd2c1272019-06-25 21:50:07 +02001115 make CC=gcc CFLAGS='-O0 -Werror -Wall -Wextra -m32 -fsanitize=address' LDFLAGS='-m32 -fsanitize=address'
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01001116
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001117 msg "test: i386, make, gcc -O0 (ASan build)"
1118 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01001119}
Gilles Peskine878cf602019-01-06 20:50:38 +00001120support_test_m32_o0 () {
1121 case $(uname -m) in
1122 *64*) true;;
1123 *) false;;
1124 esac
1125}
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001126
Gilles Peskine8f073122018-11-27 15:58:47 +01001127component_test_m32_o1 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001128 # Build again with -O1, to compile in the i386 specific inline assembly
1129 msg "build: i386, make, gcc -O1 (ASan build)" # ~ 30s
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001130 scripts/config.pl full
Philippe Antoinecd2c1272019-06-25 21:50:07 +02001131 make CC=gcc CFLAGS='-O1 -Werror -Wall -Wextra -m32 -fsanitize=address' LDFLAGS='-m32 -fsanitize=address'
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001132
1133 msg "test: i386, make, gcc -O1 (ASan build)"
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001134 make test
Gilles Peskine4b317612019-04-08 16:58:02 +02001135
1136 msg "test ssl-opt.sh, i386, make, gcc-O1"
1137 if_build_succeeded tests/ssl-opt.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01001138}
Gilles Peskine878cf602019-01-06 20:50:38 +00001139support_test_m32_o1 () {
1140 support_test_m32_o0 "$@"
1141}
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001142
Gilles Peskine0c6b7992019-04-12 20:29:48 +02001143component_test_m32_everest () {
1144 msg "build: i386, Everest ECDH context (ASan build)" # ~ 6 min
1145 scripts/config.pl unset MBEDTLS_ECDH_LEGACY_CONTEXT
1146 scripts/config.pl set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
1147 make CC=gcc CFLAGS='-O2 -Werror -Wall -Wextra -m32 -fsanitize=address' LDFLAGS='-m32 -fsanitize=address'
1148
1149 msg "test: i386, Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
1150 make test
1151
1152 msg "test: i386, Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
1153 if_build_succeeded tests/ssl-opt.sh -f ECDH
1154
1155 msg "test: i386, Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
1156 # Exclude some symmetric ciphers that are redundant here to gain time.
1157 if_build_succeeded tests/compat.sh -f ECDH -V NO -e 'ARCFOUR\|ARIA\|CAMELLIA\|CHACHA\|DES\|RC4'
1158}
1159support_test_m32_everest () {
1160 support_test_m32_o0 "$@"
1161}
1162
Gilles Peskine8f073122018-11-27 15:58:47 +01001163component_test_mx32 () {
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001164 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
Simon Butcher7a6da6e2018-06-27 21:52:54 +01001165 scripts/config.pl full
Gilles Peskine5d26e7c2019-06-07 14:50:09 +02001166 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32' LDFLAGS='-mx32'
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001167
1168 msg "test: 64-bit ILP32, make, gcc"
1169 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01001170}
Gilles Peskine878cf602019-01-06 20:50:38 +00001171support_test_mx32 () {
1172 case $(uname -m) in
1173 amd64|x86_64) true;;
1174 *) false;;
1175 esac
1176}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001177
Gilles Peskine8f073122018-11-27 15:58:47 +01001178component_build_arm_none_eabi_gcc () {
1179 msg "build: arm-none-eabi-gcc, make" # ~ 10s
Manuel Pégourié-Gonnarddf2bfcf2019-04-29 12:44:12 +02001180 scripts/config.pl baremetal
Gilles Peskine8f073122018-11-27 15:58:47 +01001181 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
1182}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001183
Gilles Peskine2c897d72019-08-09 16:05:05 +02001184component_build_arm_none_eabi_gcc_arm5vte () {
Gilles Peskine8a52af92019-08-08 16:09:02 +02001185 msg "build: arm-none-eabi-gcc -march=arm5vte, make" # ~ 10s
Gilles Peskine93e4e032019-08-05 11:34:25 +02001186 scripts/config.pl baremetal
Gilles Peskine2c897d72019-08-09 16:05:05 +02001187 # Build for a target platform that's close to what Debian uses
1188 # for its "armel" distribution (https://wiki.debian.org/ArmEabiPort).
1189 # See https://github.com/ARMmbed/mbedtls/pull/2169 and comments.
1190 # It would be better to build with arm-linux-gnueabi-gcc but
1191 # we don't have that on our CI at this time.
Gilles Peskine8a52af92019-08-08 16:09:02 +02001192 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar CFLAGS='-Werror -Wall -Wextra -march=armv5te -O1' LDFLAGS='-march=armv5te' SHELL='sh -x' lib
Gilles Peskine93e4e032019-08-05 11:34:25 +02001193}
1194
Gilles Peskine8f073122018-11-27 15:58:47 +01001195component_build_arm_none_eabi_gcc_no_udbl_division () {
1196 msg "build: arm-none-eabi-gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
Manuel Pégourié-Gonnarddf2bfcf2019-04-29 12:44:12 +02001197 scripts/config.pl baremetal
Gilles Peskine8f073122018-11-27 15:58:47 +01001198 scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
1199 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
1200 echo "Checking that software 64-bit division is not required"
1201 if_build_succeeded not grep __aeabi_uldiv library/*.o
1202}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001203
Gilles Peskine8f073122018-11-27 15:58:47 +01001204component_build_arm_none_eabi_gcc_no_64bit_multiplication () {
1205 msg "build: arm-none-eabi-gcc MBEDTLS_NO_64BIT_MULTIPLICATION, make" # ~ 10s
Manuel Pégourié-Gonnarddf2bfcf2019-04-29 12:44:12 +02001206 scripts/config.pl baremetal
Gilles Peskine8f073122018-11-27 15:58:47 +01001207 scripts/config.pl set MBEDTLS_NO_64BIT_MULTIPLICATION
1208 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -O1 -march=armv6-m -mthumb' lib
1209 echo "Checking that software 64-bit multiplication is not required"
1210 if_build_succeeded not grep __aeabi_lmul library/*.o
1211}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001212
Gilles Peskine8f073122018-11-27 15:58:47 +01001213component_build_armcc () {
1214 msg "build: ARM Compiler 5, make"
Manuel Pégourié-Gonnarddf2bfcf2019-04-29 12:44:12 +02001215 scripts/config.pl baremetal
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001216
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001217 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
1218 make clean
Andres AG87bb5772016-09-27 15:05:15 +01001219
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001220 # ARM Compiler 6 - Target ARMv7-A
1221 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-a"
Simon Butcher940737f2017-07-23 13:42:36 +02001222
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001223 # ARM Compiler 6 - Target ARMv7-M
1224 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m"
Simon Butcher940737f2017-07-23 13:42:36 +02001225
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001226 # ARM Compiler 6 - Target ARMv8-A - AArch32
1227 armc6_build_test "--target=arm-arm-none-eabi -march=armv8.2-a"
Simon Butcher940737f2017-07-23 13:42:36 +02001228
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001229 # ARM Compiler 6 - Target ARMv8-M
1230 armc6_build_test "--target=arm-arm-none-eabi -march=armv8-m.main"
Simon Butcher940737f2017-07-23 13:42:36 +02001231
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001232 # ARM Compiler 6 - Target ARMv8-A - AArch64
1233 armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a"
Gilles Peskine8f073122018-11-27 15:58:47 +01001234}
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +01001235
Gilles Peskine8f073122018-11-27 15:58:47 +01001236component_test_allow_sha1 () {
1237 msg "build: allow SHA1 in certificates by default"
Gilles Peskine8f073122018-11-27 15:58:47 +01001238 scripts/config.pl set MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
1239 make CFLAGS='-Werror -Wall -Wextra'
1240 msg "test: allow SHA1 in certificates by default"
1241 make test
1242 if_build_succeeded tests/ssl-opt.sh -f SHA-1
1243}
Gilles Peskine2a458da2017-05-12 15:26:58 +02001244
Gilles Peskine8f073122018-11-27 15:58:47 +01001245component_build_mingw () {
1246 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
Andrzej Kurek62faadd2019-04-19 20:10:21 -04001247 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -Wall -Wextra' WINDOWS_BUILD=1 lib programs -j1
Hanno Beckere963efa2018-01-03 10:03:43 +00001248
Gilles Peskine8f073122018-11-27 15:58:47 +01001249 # note Make tests only builds the tests, but doesn't run them
Andrzej Kurek62faadd2019-04-19 20:10:21 -04001250 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror' WINDOWS_BUILD=1 tests -j1
Gilles Peskine8f073122018-11-27 15:58:47 +01001251 make WINDOWS_BUILD=1 clean
Simon Butcher002bc622016-11-17 09:27:45 +00001252
Gilles Peskine8f073122018-11-27 15:58:47 +01001253 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
Andrzej Kurek87615772019-04-19 15:03:58 -04001254 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -Wall -Wextra' WINDOWS_BUILD=1 SHARED=1 lib programs -j1
1255 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -Wall -Wextra' WINDOWS_BUILD=1 SHARED=1 tests -j1
Gilles Peskine8f073122018-11-27 15:58:47 +01001256 make WINDOWS_BUILD=1 clean
1257}
Jaeden Amero117b8a42019-04-17 15:19:26 +01001258support_build_mingw() {
1259 case $(i686-w64-mingw32-gcc -dumpversion) in
1260 [0-5]*) false;;
1261 *) true;;
1262 esac
1263}
Manuel Pégourié-Gonnard6448bce2015-02-16 17:18:36 +01001264
Gilles Peskine8f073122018-11-27 15:58:47 +01001265component_test_memsan () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001266 msg "build: MSan (clang)" # ~ 1 min 20s
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001267 scripts/config.pl unset MBEDTLS_AESNI_C # memsan doesn't grok asm
1268 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
1269 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +02001270
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001271 msg "test: main suites (MSan)" # ~ 10s
1272 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001273
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001274 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
Gilles Peskine7c652162017-12-11 00:01:40 +01001275 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001276
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001277 # Optional part(s)
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001278
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001279 if [ "$MEMORY" -gt 0 ]; then
1280 msg "test: compat.sh (MSan)" # ~ 6 min 20s
Gilles Peskine7c652162017-12-11 00:01:40 +01001281 if_build_succeeded tests/compat.sh
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001282 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001283}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001284
Gilles Peskine69f190e2019-01-10 00:11:42 +01001285component_test_valgrind () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001286 msg "build: Release (clang)"
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001287 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
1288 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001289
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001290 msg "test: main suites valgrind (Release)"
1291 make memcheck
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001292
Gilles Peskinef1349e42019-04-08 17:00:56 +02001293 # Optional parts (slow; currently broken on OS X because programs don't
1294 # seem to receive signals under valgrind on OS X).
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001295 if [ "$MEMORY" -gt 0 ]; then
1296 msg "test: ssl-opt.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +01001297 if_build_succeeded tests/ssl-opt.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001298 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001299
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001300 if [ "$MEMORY" -gt 1 ]; then
1301 msg "test: compat.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +01001302 if_build_succeeded tests/compat.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001303 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001304}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001305
Gilles Peskine8f073122018-11-27 15:58:47 +01001306component_test_cmake_out_of_source () {
1307 msg "build: cmake 'out-of-source' build"
Gilles Peskine8f073122018-11-27 15:58:47 +01001308 MBEDTLS_ROOT_DIR="$PWD"
1309 mkdir "$OUT_OF_SOURCE_DIR"
1310 cd "$OUT_OF_SOURCE_DIR"
1311 cmake "$MBEDTLS_ROOT_DIR"
1312 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001313
Gilles Peskine8f073122018-11-27 15:58:47 +01001314 msg "test: cmake 'out-of-source' build"
1315 make test
1316 # Test an SSL option that requires an auxiliary script in test/scripts/.
1317 # Also ensure that there are no error messages such as
1318 # "No such file or directory", which would indicate that some required
1319 # file is missing (ssl-opt.sh tolerates the absence of some files so
1320 # may exit with status 0 but emit errors).
1321 if_build_succeeded ./tests/ssl-opt.sh -f 'Fallback SCSV: beginning of list' 2>ssl-opt.err
1322 if [ -s ssl-opt.err ]; then
1323 cat ssl-opt.err >&2
1324 record_status [ ! -s ssl-opt.err ]
1325 rm ssl-opt.err
1326 fi
1327 cd "$MBEDTLS_ROOT_DIR"
1328 rm -rf "$OUT_OF_SOURCE_DIR"
1329 unset MBEDTLS_ROOT_DIR
1330}
Andres AGdc192212016-08-31 17:33:13 +01001331
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01001332component_test_cmake_as_subdirectory () {
1333 msg "build: cmake 'as-subdirectory' build"
1334 MBEDTLS_ROOT_DIR="$PWD"
1335
1336 cd programs/test/cmake_subproject
1337 cmake .
1338 make
1339 if_build_succeeded ./cmake_subproject
1340
1341 cd "$MBEDTLS_ROOT_DIR"
1342 unset MBEDTLS_ROOT_DIR
1343}
1344
Gilles Peskine8f073122018-11-27 15:58:47 +01001345component_test_zeroize () {
1346 # Test that the function mbedtls_platform_zeroize() is not optimized away by
1347 # different combinations of compilers and optimization flags by using an
1348 # auxiliary GDB script. Unfortunately, GDB does not return error values to the
1349 # system in all cases that the script fails, so we must manually search the
1350 # output to check whether the pass string is present and no failure strings
1351 # were printed.
Andres AGdc192212016-08-31 17:33:13 +01001352
Gilles Peskine4976e822019-01-06 19:52:22 +00001353 # Don't try to disable ASLR. We don't care about ASLR here. We do care
1354 # about a spurious message if Gdb tries and fails, so suppress that.
1355 gdb_disable_aslr=
1356 if [ -z "$(gdb -batch -nw -ex 'set disable-randomization off' 2>&1)" ]; then
1357 gdb_disable_aslr='set disable-randomization off'
1358 fi
1359
Gilles Peskine8f073122018-11-27 15:58:47 +01001360 for optimization_flag in -O2 -O3 -Ofast -Os; do
Gilles Peskine55f7c942019-01-09 22:28:21 +01001361 for compiler in clang gcc; do
1362 msg "test: $compiler $optimization_flag, mbedtls_platform_zeroize()"
1363 make programs CC="$compiler" DEBUG=1 CFLAGS="$optimization_flag"
Gilles Peskine4976e822019-01-06 19:52:22 +00001364 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 +01001365 if_build_succeeded grep "The buffer was correctly zeroized" test_zeroize.log
1366 if_build_succeeded not grep -i "error" test_zeroize.log
1367 rm -f test_zeroize.log
1368 make clean
1369 done
Andres Amaya Garcia29673812017-10-25 10:35:51 +01001370 done
Andres Amaya Garciad0d7bf62017-10-25 09:01:31 +01001371
Gilles Peskine4976e822019-01-06 19:52:22 +00001372 unset gdb_disable_aslr
Gilles Peskine8f073122018-11-27 15:58:47 +01001373}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001374
Gilles Peskineaad2ebd2019-02-25 20:26:06 +01001375support_check_python_files () {
1376 type pylint3 >/dev/null 2>/dev/null
1377}
Gilles Peskine8f073122018-11-27 15:58:47 +01001378component_check_python_files () {
1379 msg "Lint: Python scripts"
1380 record_status tests/scripts/check-python-files.sh
1381}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001382
Gilles Peskine8f073122018-11-27 15:58:47 +01001383component_check_generate_test_code () {
1384 msg "uint test: generate_test_code.py"
1385 record_status ./tests/scripts/test_generate_test_code.py
1386}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001387
1388################################################################
1389#### Termination
1390################################################################
1391
Gilles Peskine8f073122018-11-27 15:58:47 +01001392post_report () {
1393 msg "Done, cleaning up"
1394 cleanup
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001395
Gilles Peskine8f073122018-11-27 15:58:47 +01001396 final_report
1397}
1398
1399
1400
1401################################################################
1402#### Run all the things
1403################################################################
1404
Gilles Peskinee48351a2018-11-27 16:06:30 +01001405# Run one component and clean up afterwards.
Gilles Peskine8f073122018-11-27 15:58:47 +01001406run_component () {
Gilles Peskine608953e2019-01-02 18:57:02 +01001407 # Back up the configuration in case the component modifies it.
1408 # The cleanup function will restore it.
1409 cp -p "$CONFIG_H" "$CONFIG_BAK"
Gilles Peskineffcdeff2018-12-04 12:49:28 +01001410 current_component="$1"
Gilles Peskine8f073122018-11-27 15:58:47 +01001411 "$@"
Gilles Peskinee48351a2018-11-27 16:06:30 +01001412 cleanup
Gilles Peskine8f073122018-11-27 15:58:47 +01001413}
1414
1415# Preliminary setup
1416pre_check_environment
1417pre_initialize_variables
1418pre_parse_command_line "$@"
Gilles Peskine348fb9a2018-11-27 17:04:29 +01001419
Gilles Peskine878cf602019-01-06 20:50:38 +00001420pre_check_git
Andrzej Kurekeb508712019-02-14 07:18:59 -05001421pre_check_seedfile
1422
Gilles Peskine878cf602019-01-06 20:50:38 +00001423build_status=0
1424if [ $KEEP_GOING -eq 1 ]; then
1425 pre_setup_keep_going
Gilles Peskine92525112018-11-27 18:15:35 +01001426else
Gilles Peskine878cf602019-01-06 20:50:38 +00001427 record_status () {
1428 "$@"
1429 }
Gilles Peskine8f073122018-11-27 15:58:47 +01001430fi
Gilles Peskine878cf602019-01-06 20:50:38 +00001431pre_print_configuration
1432pre_check_tools
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001433cleanup
1434
Gilles Peskinebeb3a812019-01-06 22:11:25 +00001435# Run the requested tests.
1436for component in $RUN_COMPONENTS; do
1437 run_component "component_$component"
1438done
Gilles Peskine8f073122018-11-27 15:58:47 +01001439
1440# We're done.
Gilles Peskine878cf602019-01-06 20:50:38 +00001441post_report