blob: 62156da60bd793117001e82b6924b6e459403560 [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 Peskinea3c6c8a2020-04-30 18:19:32 +0200134 : ${ARM_NONE_EABI_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 Peskinea3c6c8a2020-04-30 18:19:32 +0200196 --arm-none-eabi-gcc-prefix=<string>
197 Prefix for a cross-compiler for arm-none-eabi
198 (default: "${ARM_NONE_EABI_GCC_PREFIX}")
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100199 --armcc Run ARM Compiler builds (on by default).
Gilles Peskinea28db922019-01-10 00:05:18 +0100200 --except Exclude the COMPONENTs listed on the command line,
201 instead of running only those.
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100202 --no-armcc Skip ARM Compiler builds.
Gilles Peskine38d81652018-03-21 08:40:26 +0100203 --no-force Refuse to overwrite modified files (default).
204 --no-keep-going Stop at the first error (default).
205 --no-memory No additional memory tests (default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100206 --out-of-source-dir=<path> Directory used for CMake out-of-source build tests.
Gilles Peskine38d81652018-03-21 08:40:26 +0100207 --random-seed Use a random seed value for randomized tests (default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100208 -r|--release-test Run this script in release mode. This fixes the seed value to 1.
209 -s|--seed Integer seed value to use for this test run.
210
211Tool path options:
212 --armc5-bin-dir=<ARMC5_bin_dir_path> ARM Compiler 5 bin directory.
213 --armc6-bin-dir=<ARMC6_bin_dir_path> ARM Compiler 6 bin directory.
214 --gnutls-cli=<GnuTLS_cli_path> GnuTLS client executable to use for most tests.
215 --gnutls-serv=<GnuTLS_serv_path> GnuTLS server executable to use for most tests.
216 --gnutls-legacy-cli=<GnuTLS_cli_path> GnuTLS client executable to use for legacy tests.
217 --gnutls-legacy-serv=<GnuTLS_serv_path> GnuTLS server executable to use for legacy tests.
218 --openssl=<OpenSSL_path> OpenSSL executable to use for most tests.
219 --openssl-legacy=<OpenSSL_path> OpenSSL executable to use for legacy tests e.g. SSLv3.
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100220 --openssl-next=<OpenSSL_path> OpenSSL executable to use for recent things like ARIA
Gilles Peskine709346a2017-12-10 23:43:39 +0100221EOF
SimonB2e23c822016-04-16 21:54:39 +0100222}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100223
224# remove built files as well as the cmake cache/config
225cleanup()
226{
Gilles Peskinea71d64c2018-03-21 12:16:57 +0100227 if [ -n "${MBEDTLS_ROOT_DIR+set}" ]; then
228 cd "$MBEDTLS_ROOT_DIR"
229 fi
230
Gilles Peskine7c652162017-12-11 00:01:40 +0100231 command make clean
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200232
Gilles Peskine31b07e22018-03-21 12:15:06 +0100233 # Remove CMake artefacts
Simon Butcher3ad2efd2018-05-02 14:49:38 +0100234 find . -name .git -prune \
Gilles Peskine31b07e22018-03-21 12:15:06 +0100235 -iname CMakeFiles -exec rm -rf {} \+ -o \
236 \( -iname cmake_install.cmake -o \
237 -iname CTestTestfile.cmake -o \
238 -iname CMakeCache.txt \) -exec rm {} \+
239 # Recover files overwritten by in-tree CMake builds
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000240 rm -f include/Makefile include/mbedtls/Makefile programs/*/Makefile
Paul Bakkerfe0984d2014-06-13 00:13:45 +0200241 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile
242 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200243
244 if [ -f "$CONFIG_BAK" ]; then
245 mv "$CONFIG_BAK" "$CONFIG_H"
246 fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100247}
248
Gilles Peskine7c652162017-12-11 00:01:40 +0100249# Executed on exit. May be redefined depending on command line options.
250final_report () {
251 :
252}
253
254fatal_signal () {
255 cleanup
256 final_report $1
257 trap - $1
258 kill -$1 $$
259}
260
261trap 'fatal_signal HUP' HUP
262trap 'fatal_signal INT' INT
263trap 'fatal_signal TERM' TERM
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200264
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100265msg()
266{
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100267 if [ -n "${current_component:-}" ]; then
268 current_section="${current_component#component_}: $1"
269 else
270 current_section="$1"
271 fi
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100272 echo ""
273 echo "******************************************************************"
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100274 echo "* $current_section "
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000275 printf "* "; date
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100276 echo "******************************************************************"
277}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100278
Gilles Peskine8f073122018-11-27 15:58:47 +0100279armc6_build_test()
280{
281 FLAGS="$1"
Andres AGa5cd9732016-10-17 15:23:10 +0100282
Gilles Peskinee6c0c7d2020-04-30 23:11:54 +0200283 msg "build: ARM Compiler 6 ($FLAGS)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100284 ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \
285 WARNING_CFLAGS='-xc -std=c99' make lib
Gilles Peskinee6c0c7d2020-04-30 23:11:54 +0200286
287 msg "size: ARM Compiler 6 ($FLAGS)"
288 "$ARMC6_FROMELF" -z library/*.o
289
Gilles Peskine8f073122018-11-27 15:58:47 +0100290 make clean
291}
Andres AGa5cd9732016-10-17 15:23:10 +0100292
Andres AGd9eba4b2016-08-26 14:42:14 +0100293err_msg()
294{
295 echo "$1" >&2
296}
297
298check_tools()
299{
300 for TOOL in "$@"; do
Andres AG98393602017-01-31 17:04:45 +0000301 if ! `type "$TOOL" >/dev/null 2>&1`; then
Andres AGd9eba4b2016-08-26 14:42:14 +0100302 err_msg "$TOOL not found!"
303 exit 1
304 fi
305 done
306}
307
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400308check_headers_in_cpp () {
Peter Kolbus30987072019-02-01 17:19:08 -0600309 ls include/mbedtls | grep "\.h$" >headers.txt
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400310 <programs/test/cpp_dummy_build.cpp sed -n 's/"$//; s!^#include "mbedtls/!!p' |
311 sort |
312 diff headers.txt -
313 rm headers.txt
314}
315
Gilles Peskine8f073122018-11-27 15:58:47 +0100316pre_parse_command_line () {
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000317 COMMAND_LINE_COMPONENTS=
Gilles Peskinea28db922019-01-10 00:05:18 +0100318 all_except=0
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000319 no_armcc=
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000320
Gilles Peskine8f073122018-11-27 15:58:47 +0100321 while [ $# -gt 0 ]; do
Gilles Peskine55f7c942019-01-09 22:28:21 +0100322 case "$1" in
Gilles Peskinea3c6c8a2020-04-30 18:19:32 +0200323 --arm-none-eabi-gcc-prefix) shift; ARM_NONE_EABI_GCC_PREFIX="$1";;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000324 --armcc) no_armcc=;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100325 --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
326 --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000327 --except) all_except=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100328 --force|-f) FORCE=1;;
329 --gnutls-cli) shift; GNUTLS_CLI="$1";;
330 --gnutls-legacy-cli) shift; GNUTLS_LEGACY_CLI="$1";;
331 --gnutls-legacy-serv) shift; GNUTLS_LEGACY_SERV="$1";;
332 --gnutls-serv) shift; GNUTLS_SERV="$1";;
333 --help|-h) usage; exit;;
334 --keep-going|-k) KEEP_GOING=1;;
Gilles Peskine878cf602019-01-06 20:50:38 +0000335 --list-all-components) printf '%s\n' $ALL_COMPONENTS; exit;;
336 --list-components) printf '%s\n' $SUPPORTED_COMPONENTS; exit;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100337 --memory|-m) MEMORY=1;;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000338 --no-armcc) no_armcc=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100339 --no-force) FORCE=0;;
340 --no-keep-going) KEEP_GOING=0;;
341 --no-memory) MEMORY=0;;
342 --openssl) shift; OPENSSL="$1";;
343 --openssl-legacy) shift; OPENSSL_LEGACY="$1";;
344 --openssl-next) shift; OPENSSL_NEXT="$1";;
345 --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
346 --random-seed) unset SEED;;
347 --release-test|-r) SEED=1;;
348 --seed|-s) shift; SEED="$1";;
349 -*)
350 echo >&2 "Unknown option: $1"
351 echo >&2 "Run $0 --help for usage."
352 exit 120
353 ;;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000354 *) COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS $1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100355 esac
356 shift
Gilles Peskine8f073122018-11-27 15:58:47 +0100357 done
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000358
Gilles Peskinea28db922019-01-10 00:05:18 +0100359 # With no list of components, run everything.
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000360 if [ -z "$COMMAND_LINE_COMPONENTS" ]; then
361 all_except=1
362 fi
363
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000364 # --no-armcc is a legacy option. The modern way is --except '*_armcc*'.
365 # Ignore it if components are listed explicitly on the command line.
Gilles Peskinea28db922019-01-10 00:05:18 +0100366 if [ -n "$no_armcc" ] && [ $all_except -eq 1 ]; then
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000367 COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS *_armcc*"
368 fi
369
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000370 # Build the list of components to run.
Gilles Peskinea28db922019-01-10 00:05:18 +0100371 RUN_COMPONENTS=
372 for component in $SUPPORTED_COMPONENTS; do
373 if is_component_included "$component"; [ $? -eq $all_except ]; then
374 RUN_COMPONENTS="$RUN_COMPONENTS $component"
375 fi
376 done
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000377
378 unset all_except
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000379 unset no_armcc
Gilles Peskine8f073122018-11-27 15:58:47 +0100380}
SimonB2e23c822016-04-16 21:54:39 +0100381
Gilles Peskine8f073122018-11-27 15:58:47 +0100382pre_check_git () {
383 if [ $FORCE -eq 1 ]; then
Gilles Peskine53190e62019-01-09 23:17:35 +0100384 rm -rf "$OUT_OF_SOURCE_DIR"
Gilles Peskine8f073122018-11-27 15:58:47 +0100385 git checkout-index -f -q $CONFIG_H
386 cleanup
387 else
SimonB2e23c822016-04-16 21:54:39 +0100388
Gilles Peskine8f073122018-11-27 15:58:47 +0100389 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
390 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
391 echo "You can either delete this directory manually, or force the test by rerunning"
392 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
393 exit 1
394 fi
395
Gilles Peskined1174cf2019-01-09 22:30:01 +0100396 if ! git diff --quiet include/mbedtls/config.h; then
Gilles Peskine8f073122018-11-27 15:58:47 +0100397 err_msg "Warning - the configuration file 'include/mbedtls/config.h' has been edited. "
398 echo "You can either delete or preserve your work, or force the test by rerunning the"
399 echo "script as: $0 --force"
400 exit 1
401 fi
Andres AGdc192212016-08-31 17:33:13 +0100402 fi
Gilles Peskine8f073122018-11-27 15:58:47 +0100403}
Andres AGdc192212016-08-31 17:33:13 +0100404
Gilles Peskine8f073122018-11-27 15:58:47 +0100405pre_setup_keep_going () {
Gilles Peskine7c652162017-12-11 00:01:40 +0100406 failure_summary=
407 failure_count=0
408 start_red=
409 end_color=
410 if [ -t 1 ]; then
Gilles Peskine9736b9d2018-01-02 21:54:17 +0100411 case "${TERM:-}" in
Gilles Peskine7c652162017-12-11 00:01:40 +0100412 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
413 start_red=$(printf '\033[31m')
414 end_color=$(printf '\033[0m')
415 ;;
416 esac
417 fi
418 record_status () {
419 if "$@"; then
420 last_status=0
421 else
422 last_status=$?
423 text="$current_section: $* -> $last_status"
424 failure_summary="$failure_summary
425$text"
426 failure_count=$((failure_count + 1))
427 echo "${start_red}^^^^$text^^^^${end_color}"
428 fi
429 }
430 make () {
431 case "$*" in
432 *test|*check)
433 if [ $build_status -eq 0 ]; then
434 record_status command make "$@"
435 else
436 echo "(skipped because the build failed)"
437 fi
438 ;;
439 *)
440 record_status command make "$@"
441 build_status=$last_status
442 ;;
443 esac
444 }
445 final_report () {
446 if [ $failure_count -gt 0 ]; then
447 echo
448 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
449 echo "${start_red}FAILED: $failure_count${end_color}$failure_summary"
450 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Jaeden Amero7c1258d2018-07-20 16:42:14 +0100451 exit 1
Gilles Peskine7c652162017-12-11 00:01:40 +0100452 elif [ -z "${1-}" ]; then
453 echo "SUCCESS :)"
454 fi
455 if [ -n "${1-}" ]; then
456 echo "Killed by SIG$1."
457 fi
458 }
Gilles Peskine8f073122018-11-27 15:58:47 +0100459}
460
Gilles Peskine7c652162017-12-11 00:01:40 +0100461if_build_succeeded () {
462 if [ $build_status -eq 0 ]; then
463 record_status "$@"
464 fi
465}
466
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200467# to be used instead of ! for commands run with
468# record_status or if_build_succeeded
469not() {
470 ! "$@"
471}
472
Gilles Peskine8f073122018-11-27 15:58:47 +0100473pre_print_configuration () {
474 msg "info: $0 configuration"
475 echo "MEMORY: $MEMORY"
476 echo "FORCE: $FORCE"
477 echo "SEED: ${SEED-"UNSET"}"
478 echo "OPENSSL: $OPENSSL"
479 echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
480 echo "OPENSSL_NEXT: $OPENSSL_NEXT"
481 echo "GNUTLS_CLI: $GNUTLS_CLI"
482 echo "GNUTLS_SERV: $GNUTLS_SERV"
483 echo "GNUTLS_LEGACY_CLI: $GNUTLS_LEGACY_CLI"
484 echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV"
485 echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
486 echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
487}
Andres AG87bb5772016-09-27 15:05:15 +0100488
Gilles Peskine87964262019-01-06 22:40:00 +0000489# Make sure the tools we need are available.
Gilles Peskine8f073122018-11-27 15:58:47 +0100490pre_check_tools () {
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000491 # Build the list of variables to pass to output_env.sh.
492 set env
493
Gilles Peskine87964262019-01-06 22:40:00 +0000494 case " $RUN_COMPONENTS " in
495 # Require OpenSSL and GnuTLS if running any tests (as opposed to
496 # only doing builds). Not all tests run OpenSSL and GnuTLS, but this
497 # is a good enough approximation in practice.
498 *" test_"*)
499 # To avoid setting OpenSSL and GnuTLS for each call to compat.sh
500 # and ssl-opt.sh, we just export the variables they require.
501 export OPENSSL_CMD="$OPENSSL"
502 export GNUTLS_CLI="$GNUTLS_CLI"
503 export GNUTLS_SERV="$GNUTLS_SERV"
504 # Avoid passing --seed flag in every call to ssl-opt.sh
505 if [ -n "${SEED-}" ]; then
506 export SEED
507 fi
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000508 set "$@" OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY"
509 set "$@" GNUTLS_CLI="$GNUTLS_CLI" GNUTLS_SERV="$GNUTLS_SERV"
510 set "$@" GNUTLS_LEGACY_CLI="$GNUTLS_LEGACY_CLI"
511 set "$@" GNUTLS_LEGACY_SERV="$GNUTLS_LEGACY_SERV"
Gilles Peskine87964262019-01-06 22:40:00 +0000512 check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$OPENSSL_NEXT" \
513 "$GNUTLS_CLI" "$GNUTLS_SERV" \
514 "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV"
515 ;;
516 esac
Andres AGd9eba4b2016-08-26 14:42:14 +0100517
Gilles Peskine87964262019-01-06 22:40:00 +0000518 case " $RUN_COMPONENTS " in
519 *_doxygen[_\ ]*) check_tools "doxygen" "dot";;
520 esac
Andres AGb2fdd042016-09-22 14:17:46 +0100521
Gilles Peskine87964262019-01-06 22:40:00 +0000522 case " $RUN_COMPONENTS " in
Gilles Peskinea3c6c8a2020-04-30 18:19:32 +0200523 *_arm_none_eabi_gcc[_\ ]*) check_tools "${ARM_NONE_EABI_GCC_PREFIX}gcc";;
Gilles Peskine87964262019-01-06 22:40:00 +0000524 esac
Andres AG7770ea82016-10-10 15:46:20 +0100525
Gilles Peskine87964262019-01-06 22:40:00 +0000526 case " $RUN_COMPONENTS " in
527 *_mingw[_\ ]*) check_tools "i686-w64-mingw32-gcc";;
528 esac
529
530 case " $RUN_COMPONENTS " in
531 *" test_zeroize "*) check_tools "gdb";;
532 esac
533
534 case " $RUN_COMPONENTS " in
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000535 *_armcc*)
Gilles Peskine87964262019-01-06 22:40:00 +0000536 ARMC5_CC="$ARMC5_BIN_DIR/armcc"
537 ARMC5_AR="$ARMC5_BIN_DIR/armar"
Gilles Peskinee6c0c7d2020-04-30 23:11:54 +0200538 ARMC5_FROMELF="$ARMC5_BIN_DIR/fromelf"
Gilles Peskine87964262019-01-06 22:40:00 +0000539 ARMC6_CC="$ARMC6_BIN_DIR/armclang"
540 ARMC6_AR="$ARMC6_BIN_DIR/armar"
Gilles Peskinee6c0c7d2020-04-30 23:11:54 +0200541 ARMC6_FROMELF="$ARMC6_BIN_DIR/fromelf"
542 check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC5_FROMELF" \
543 "$ARMC6_CC" "$ARMC6_AR" "$ARMC6_FROMELF";;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000544 esac
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000545
546 msg "info: output_env.sh"
547 case $RUN_COMPONENTS in
548 *_armcc*)
549 set "$@" ARMC5_CC="$ARMC5_CC" ARMC6_CC="$ARMC6_CC" RUN_ARMCC=1;;
550 *) set "$@" RUN_ARMCC=0;;
551 esac
552 "$@" scripts/output_env.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100553}
Gilles Peskine192c72f2017-12-21 15:59:21 +0100554
555
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000556
Gilles Peskine192c72f2017-12-21 15:59:21 +0100557################################################################
558#### Basic checks
559################################################################
Andres AGd9eba4b2016-08-26 14:42:14 +0100560
SimonB2e23c822016-04-16 21:54:39 +0100561#
562# Test Suites to be executed
563#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200564# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100565# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard61bc57a2014-08-14 11:29:06 +0200566# and/or are more likely to fail than others (eg I use Clang most of the
567# time, so start with a GCC build).
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200568# 2. Minimize total running time, by avoiding useless rebuilds
569#
570# Indicative running times are given for reference.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100571
Gilles Peskine8f073122018-11-27 15:58:47 +0100572component_check_recursion () {
573 msg "test: recursion.pl" # < 1s
574 record_status tests/scripts/recursion.pl library/*.c
575}
Manuel Pégourié-Gonnardea29d152014-11-20 17:32:33 +0100576
Gilles Peskine8f073122018-11-27 15:58:47 +0100577component_check_generated_files () {
578 msg "test: freshness of generated source files" # < 1s
579 record_status tests/scripts/check-generated-files.sh
580}
Manuel Pégourié-Gonnardb3b8e432015-02-13 14:52:19 +0000581
Gilles Peskine8f073122018-11-27 15:58:47 +0100582component_check_doxy_blocks () {
583 msg "test: doxygen markup outside doxygen blocks" # < 1s
584 record_status tests/scripts/check-doxy-blocks.pl
585}
Manuel Pégourié-Gonnardd09a6b52015-04-09 17:19:23 +0200586
Gilles Peskine8f073122018-11-27 15:58:47 +0100587component_check_files () {
588 msg "test: check-files.py" # < 1s
Gilles Peskine8f073122018-11-27 15:58:47 +0100589 record_status tests/scripts/check-files.py
590}
Darryl Greena07039c2018-03-13 16:48:16 +0000591
Gilles Peskine8f073122018-11-27 15:58:47 +0100592component_check_names () {
593 msg "test/build: declared and exported names" # < 3s
Gilles Peskine473f2d42019-05-15 17:52:22 +0200594 record_status tests/scripts/check-names.sh -v
Gilles Peskine8f073122018-11-27 15:58:47 +0100595}
Manuel Pégourié-Gonnarda687baf2015-04-09 11:09:03 +0200596
Gilles Peskine8f073122018-11-27 15:58:47 +0100597component_check_doxygen_warnings () {
598 msg "test: doxygen warnings" # ~ 3s
Gilles Peskine8f073122018-11-27 15:58:47 +0100599 record_status tests/scripts/doxygen.sh
600}
Manuel Pégourié-Gonnard1d552e72016-01-04 16:49:09 +0100601
Gilles Peskine192c72f2017-12-21 15:59:21 +0100602
603
604################################################################
605#### Build and test many configurations and targets
606################################################################
607
k-stachowiak11f38e22019-06-04 13:14:58 +0200608component_test_large_ecdsa_key_signature () {
609
610 SMALL_MPI_MAX_SIZE=136 # Small enough to interfere with the EC signatures
611
612 msg "build: cmake + MBEDTLS_MPI_MAX_SIZE=${SMALL_MPI_MAX_SIZE}, gcc, ASan" # ~ 1 min 50s
613 scripts/config.pl set MBEDTLS_MPI_MAX_SIZE $SMALL_MPI_MAX_SIZE
614 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
615 make
616
617 INEVITABLY_PRESENT_FILE=Makefile
618 SIGNATURE_FILE="${INEVITABLY_PRESENT_FILE}.sig" # Warning, this is rm -f'ed below
619
620 msg "test: pk_sign secp521r1_prv.der for MBEDTLS_MPI_MAX_SIZE=${SMALL_MPI_MAX_SIZE} (ASan build)" # ~ 5s
621 if_build_succeeded programs/pkey/pk_sign tests/data_files/secp521r1_prv.der $INEVITABLY_PRESENT_FILE
622 rm -f $SIGNATURE_FILE
623}
624
Gilles Peskine99a33102019-04-08 17:00:15 +0200625component_test_default_out_of_box () {
626 msg "build: make, default config (out-of-box)" # ~1min
627 make
628
629 msg "test: main suites make, default config (out-of-box)" # ~10s
630 make test
631
632 msg "selftest: make, default config (out-of-box)" # ~10s
Gilles Peskine5bd9f562020-04-23 23:37:45 +0200633 if_build_succeeded programs/test/selftest
Gilles Peskine99a33102019-04-08 17:00:15 +0200634}
635
Gilles Peskine8f073122018-11-27 15:58:47 +0100636component_test_default_cmake_gcc_asan () {
637 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100638 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
639 make
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100640
Gilles Peskine8f073122018-11-27 15:58:47 +0100641 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
642 make test
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200643
Gilles Peskine5bd9f562020-04-23 23:37:45 +0200644 msg "test: selftest (ASan build)" # ~ 10s
645 if_build_succeeded programs/test/selftest
646
Gilles Peskine8f073122018-11-27 15:58:47 +0100647 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
648 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200649
Gilles Peskine8f073122018-11-27 15:58:47 +0100650 msg "test: compat.sh (ASan build)" # ~ 6 min
651 if_build_succeeded tests/compat.sh
652}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200653
Hanno Beckerf8799e82019-02-26 14:27:09 +0000654component_test_full_cmake_gcc_asan () {
655 msg "build: full config, cmake, gcc, ASan"
656 scripts/config.pl full
657 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
658 make
659
660 msg "test: main suites (inc. selftests) (full config, ASan build)"
661 make test
662
Gilles Peskine5bd9f562020-04-23 23:37:45 +0200663 msg "test: selftest (ASan build)" # ~ 10s
664 if_build_succeeded programs/test/selftest
665
Hanno Beckerf8799e82019-02-26 14:27:09 +0000666 msg "test: ssl-opt.sh (full config, ASan build)"
667 if_build_succeeded tests/ssl-opt.sh
668
669 msg "test: compat.sh (full config, ASan build)"
670 if_build_succeeded tests/compat.sh
671}
672
Manuel Pégourié-Gonnard4ef189d2020-01-02 11:45:12 +0100673component_test_zlib_make() {
674 msg "build: zlib enabled, make"
675 scripts/config.pl set MBEDTLS_ZLIB_SUPPORT
676 make ZLIB=1 CFLAGS='-Werror -O1'
677
678 msg "test: main suites (zlib, make)"
679 make test
680
681 msg "test: ssl-opt.sh (zlib, make)"
682 if_build_succeeded tests/ssl-opt.sh
683}
Manuel Pégourié-Gonnard114d3392020-01-24 10:17:20 +0100684support_test_zlib_make () {
685 base=support_test_zlib_$$
686 cat <<'EOF' > ${base}.c
687#include "zlib.h"
688int main(void) { return 0; }
689EOF
690 gcc -o ${base}.exe ${base}.c -lz 2>/dev/null
691 ret=$?
692 rm -f ${base}.*
693 return $ret
694}
Manuel Pégourié-Gonnard4ef189d2020-01-02 11:45:12 +0100695
696component_test_zlib_cmake() {
697 msg "build: zlib enabled, cmake"
698 scripts/config.pl set MBEDTLS_ZLIB_SUPPORT
699 cmake -D ENABLE_ZLIB_SUPPORT=On -D CMAKE_BUILD_TYPE:String=Check .
700 make
701
702 msg "test: main suites (zlib, cmake)"
703 make test
704
705 msg "test: ssl-opt.sh (zlib, cmake)"
706 if_build_succeeded tests/ssl-opt.sh
707}
Manuel Pégourié-Gonnard114d3392020-01-24 10:17:20 +0100708support_test_zlib_cmake () {
709 support_test_zlib_make "$@"
710}
Manuel Pégourié-Gonnard4ef189d2020-01-02 11:45:12 +0100711
Gilles Peskine782f4112018-11-27 16:11:09 +0100712component_test_ref_configs () {
713 msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
714 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
715 record_status tests/scripts/test-ref-configs.pl
716}
717
Gilles Peskine8f073122018-11-27 15:58:47 +0100718component_test_sslv3 () {
719 msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100720 scripts/config.pl set MBEDTLS_SSL_PROTO_SSL3
721 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
722 make
Simon Butcher3ea7f522016-03-07 23:22:10 +0000723
Gilles Peskine8f073122018-11-27 15:58:47 +0100724 msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
725 make test
Simon Butcher3ea7f522016-03-07 23:22:10 +0000726
Gilles Peskine8f073122018-11-27 15:58:47 +0100727 msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
728 if_build_succeeded tests/compat.sh -m 'tls1 tls1_1 tls1_2 dtls1 dtls1_2'
729 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
Simon Butcher3ea7f522016-03-07 23:22:10 +0000730
Gilles Peskine8f073122018-11-27 15:58:47 +0100731 msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
732 if_build_succeeded tests/ssl-opt.sh
733}
Simon Butcher3ea7f522016-03-07 23:22:10 +0000734
Gilles Peskine8f073122018-11-27 15:58:47 +0100735component_test_no_renegotiation () {
736 msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100737 scripts/config.pl unset MBEDTLS_SSL_RENEGOTIATION
738 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
739 make
Hanno Becker134c2ab2017-10-12 15:29:50 +0100740
Gilles Peskine8f073122018-11-27 15:58:47 +0100741 msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
742 make test
Hanno Becker134c2ab2017-10-12 15:29:50 +0100743
Gilles Peskine8f073122018-11-27 15:58:47 +0100744 msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
745 if_build_succeeded tests/ssl-opt.sh
746}
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +0100747
Hanno Beckere562e7d2019-05-10 14:45:37 +0100748component_test_no_pem_no_fs () {
749 msg "build: Default + !MBEDTLS_PEM_PARSE_C + !MBEDTLS_FS_IO (ASan build)"
750 scripts/config.pl unset MBEDTLS_PEM_PARSE_C
751 scripts/config.pl unset MBEDTLS_FS_IO
752 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
753 make
754
755 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - main suites (inc. selftests) (ASan build)" # ~ 50s
756 make test
757
758 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - ssl-opt.sh (ASan build)" # ~ 6 min
759 if_build_succeeded tests/ssl-opt.sh
760}
761
Gilles Peskine8f073122018-11-27 15:58:47 +0100762component_test_rsa_no_crt () {
763 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100764 scripts/config.pl set MBEDTLS_RSA_NO_CRT
765 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
766 make
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100767
Gilles Peskine8f073122018-11-27 15:58:47 +0100768 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
769 make test
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100770
Gilles Peskine8f073122018-11-27 15:58:47 +0100771 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
772 if_build_succeeded tests/ssl-opt.sh -f RSA
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100773
Gilles Peskine8f073122018-11-27 15:58:47 +0100774 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
775 if_build_succeeded tests/compat.sh -t RSA
776}
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100777
Gilles Peskine8f073122018-11-27 15:58:47 +0100778component_test_small_ssl_out_content_len () {
779 msg "build: small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100780 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 16384
781 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
782 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
783 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000784
Gilles Peskine8f073122018-11-27 15:58:47 +0100785 msg "test: small SSL_OUT_CONTENT_LEN - ssl-opt.sh MFL and large packet tests"
786 if_build_succeeded tests/ssl-opt.sh -f "Max fragment\|Large packet"
787}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000788
Gilles Peskine8f073122018-11-27 15:58:47 +0100789component_test_small_ssl_in_content_len () {
790 msg "build: small SSL_IN_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100791 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 4096
792 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 16384
793 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
794 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000795
Gilles Peskine8f073122018-11-27 15:58:47 +0100796 msg "test: small SSL_IN_CONTENT_LEN - ssl-opt.sh MFL tests"
797 if_build_succeeded tests/ssl-opt.sh -f "Max fragment"
798}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000799
Gilles Peskine8f073122018-11-27 15:58:47 +0100800component_test_small_ssl_dtls_max_buffering () {
801 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0"
Gilles Peskine8f073122018-11-27 15:58:47 +0100802 scripts/config.pl set MBEDTLS_SSL_DTLS_MAX_BUFFERING 1000
803 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
804 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100805
Gilles Peskine8f073122018-11-27 15:58:47 +0100806 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0 - ssl-opt.sh specific reordering test"
807 if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer out-of-order hs msg before reassembling next, free buffered msg"
808}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100809
Gilles Peskine8f073122018-11-27 15:58:47 +0100810component_test_small_mbedtls_ssl_dtls_max_buffering () {
811 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1"
Gilles Peskine8f073122018-11-27 15:58:47 +0100812 scripts/config.pl set MBEDTLS_SSL_DTLS_MAX_BUFFERING 240
813 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
814 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100815
Gilles Peskine8f073122018-11-27 15:58:47 +0100816 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1 - ssl-opt.sh specific reordering test"
817 if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer encrypted Finished message, drop for fragmented NewSessionTicket"
818}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100819
Gilles Peskine8f073122018-11-27 15:58:47 +0100820component_test_full_cmake_clang () {
821 msg "build: cmake, full config, clang" # ~ 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100822 scripts/config.pl full
Gilles Peskine8f073122018-11-27 15:58:47 +0100823 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check -D ENABLE_TESTING=On .
824 make
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100825
Gilles Peskine8f073122018-11-27 15:58:47 +0100826 msg "test: main suites (full config)" # ~ 5s
827 make test
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200828
Gilles Peskine8f073122018-11-27 15:58:47 +0100829 msg "test: ssl-opt.sh default, ECJPAKE, SSL async (full config)" # ~ 1s
830 if_build_succeeded tests/ssl-opt.sh -f 'Default\|ECJPAKE\|SSL async private'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200831
Andres Amaya Garciaac9c5222019-01-08 21:42:27 +0000832 msg "test: compat.sh RC4, DES, 3DES & NULL (full config)" # ~ 2 min
Andres Amaya Garcia37e0a8c2019-02-19 20:20:57 +0000833 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 +0200834
Gilles Peskine8f073122018-11-27 15:58:47 +0100835 msg "test: compat.sh ARIA + ChachaPoly"
836 if_build_succeeded env OPENSSL_CMD="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
837}
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100838
Gilles Peskine77b1f302020-04-28 14:04:28 +0200839component_test_default_no_deprecated () {
840 # Test that removing the deprecated features from the default
841 # configuration leaves something consistent.
842 msg "build: make, default + MBEDTLS_DEPRECATED_REMOVED" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100843 scripts/config.pl set MBEDTLS_DEPRECATED_REMOVED
Gilles Peskine77b1f302020-04-28 14:04:28 +0200844 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra'
845
846 msg "test: make, default + MBEDTLS_DEPRECATED_REMOVED" # ~ 5s
847 make test
Gilles Peskine8f073122018-11-27 15:58:47 +0100848}
Gilles Peskine0afe6242018-02-21 19:28:12 +0100849
Gilles Peskine77b1f302020-04-28 14:04:28 +0200850component_test_full_deprecated_warning () {
851 # Test that there is nothing deprecated in the full configuration.
852 # A deprecated feature would trigger a warning (made fatal) from
853 # MBEDTLS_DEPRECATED_WARNING.
854 msg "build: make, full + MBEDTLS_DEPRECATED_WARNING" # ~ 30s
855 scripts/config.pl full
856 scripts/config.pl unset MBEDTLS_DEPRECATED_REMOVED
857 scripts/config.pl set MBEDTLS_DEPRECATED_WARNING
858 # There are currently no tests for any deprecated feature.
859 # If some are added, 'make test' would trigger warnings here.
860 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra'
861
862 msg "test: make, full + MBEDTLS_DEPRECATED_WARNING" # ~ 5s
863 make test
864}
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200865
Gilles Peskine8f073122018-11-27 15:58:47 +0100866component_test_depends_curves () {
867 msg "test/build: curves.pl (gcc)" # ~ 4 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100868 record_status tests/scripts/curves.pl
869}
Manuel Pégourié-Gonnard1fe6bb92017-06-06 11:36:16 +0200870
Gilles Peskine8f073122018-11-27 15:58:47 +0100871component_test_depends_hashes () {
872 msg "test/build: depends-hashes.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100873 record_status tests/scripts/depends-hashes.pl
874}
Manuel Pégourié-Gonnard43be6cd2017-06-20 09:53:42 +0200875
Gilles Peskine8f073122018-11-27 15:58:47 +0100876component_test_depends_pkalgs () {
877 msg "test/build: depends-pkalgs.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100878 record_status tests/scripts/depends-pkalgs.pl
879}
Manuel Pégourié-Gonnard503a5ef2015-10-23 09:04:45 +0200880
Gilles Peskine8f073122018-11-27 15:58:47 +0100881component_build_key_exchanges () {
882 msg "test/build: key-exchanges (gcc)" # ~ 1 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100883 record_status tests/scripts/key-exchanges.pl
884}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100885
Gilles Peskine8f073122018-11-27 15:58:47 +0100886component_build_default_make_gcc_and_cxx () {
887 msg "build: Unix make, -Os (gcc)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100888 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400889
Gilles Peskine8f073122018-11-27 15:58:47 +0100890 msg "test: verify header list in cpp_dummy_build.cpp"
891 record_status check_headers_in_cpp
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400892
Gilles Peskine8f073122018-11-27 15:58:47 +0100893 msg "build: Unix make, incremental g++"
894 make TEST_CPP=1
895}
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +0000896
Gilles Peskinedcab2022019-06-12 16:05:50 +0200897component_test_check_params_functionality () {
898 msg "build+test: MBEDTLS_CHECK_PARAMS functionality"
899 scripts/config.pl full # includes CHECK_PARAMS
900 # Make MBEDTLS_PARAM_FAILED call mbedtls_param_failed().
901 scripts/config.pl unset MBEDTLS_CHECK_PARAMS_ASSERT
Gilles Peskinedcab2022019-06-12 16:05:50 +0200902 # Only build and run tests. Do not build sample programs, because
903 # they don't have a mbedtls_param_failed() function.
904 make CC=gcc CFLAGS='-Werror -O1' lib test
905}
906
Gilles Peskineb28636b2019-01-02 19:06:24 +0100907component_test_check_params_without_platform () {
908 msg "build+test: MBEDTLS_CHECK_PARAMS without MBEDTLS_PLATFORM_C"
909 scripts/config.pl full # includes CHECK_PARAMS
Gilles Peskinedcab2022019-06-12 16:05:50 +0200910 # Keep MBEDTLS_PARAM_FAILED as assert.
Gilles Peskineb28636b2019-01-02 19:06:24 +0100911 scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
912 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
913 scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
914 scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
Gilles Peskinedf4f7c12020-04-28 10:41:20 +0200915 scripts/config.pl unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskineb28636b2019-01-02 19:06:24 +0100916 scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
917 scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
918 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
919 scripts/config.pl unset MBEDTLS_PLATFORM_C
920 make CC=gcc CFLAGS='-Werror -O1' all test
921}
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +0200922
Gilles Peskineb28636b2019-01-02 19:06:24 +0100923component_test_check_params_silent () {
924 msg "build+test: MBEDTLS_CHECK_PARAMS with alternative MBEDTLS_PARAM_FAILED()"
925 scripts/config.pl full # includes CHECK_PARAMS
Gilles Peskinedcab2022019-06-12 16:05:50 +0200926 # Set MBEDTLS_PARAM_FAILED to nothing.
Gilles Peskineb28636b2019-01-02 19:06:24 +0100927 sed -i 's/.*\(#define MBEDTLS_PARAM_FAILED( cond )\).*/\1/' "$CONFIG_H"
928 make CC=gcc CFLAGS='-Werror -O1' all test
929}
Hanno Becker5175ac62017-09-18 15:36:25 +0100930
Gilles Peskine8f073122018-11-27 15:58:47 +0100931component_test_no_platform () {
932 # Full configuration build, without platform support, file IO and net sockets.
933 # This should catch missing mbedtls_printf definitions, and by disabling file
934 # IO, it should catch missing '#include <stdio.h>'
935 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100936 scripts/config.pl full
937 scripts/config.pl unset MBEDTLS_PLATFORM_C
938 scripts/config.pl unset MBEDTLS_NET_C
939 scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
940 scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
941 scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
942 scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
943 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
944 scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
Gilles Peskinedf4f7c12020-04-28 10:41:20 +0200945 scripts/config.pl unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine8f073122018-11-27 15:58:47 +0100946 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskine8f073122018-11-27 15:58:47 +0100947 scripts/config.pl unset MBEDTLS_FS_IO
948 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
949 # to re-enable platform integration features otherwise disabled in C99 builds
Gilles Peskine99d70d82019-09-20 19:23:10 +0200950 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -Os -D_DEFAULT_SOURCE' lib programs
951 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os' test
Gilles Peskine8f073122018-11-27 15:58:47 +0100952}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200953
Gilles Peskine8f073122018-11-27 15:58:47 +0100954component_build_no_std_function () {
955 # catch compile bugs in _uninit functions
956 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100957 scripts/config.pl full
958 scripts/config.pl set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
959 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskinedf4f7c12020-04-28 10:41:20 +0200960 scripts/config.pl unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine99d70d82019-09-20 19:23:10 +0200961 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Gilles Peskine8f073122018-11-27 15:58:47 +0100962}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200963
Gilles Peskine8f073122018-11-27 15:58:47 +0100964component_build_no_ssl_srv () {
965 msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100966 scripts/config.pl full
967 scripts/config.pl unset MBEDTLS_SSL_SRV_C
Gilles Peskine99d70d82019-09-20 19:23:10 +0200968 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
Gilles Peskine8f073122018-11-27 15:58:47 +0100969}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200970
Gilles Peskine8f073122018-11-27 15:58:47 +0100971component_build_no_ssl_cli () {
972 msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100973 scripts/config.pl full
974 scripts/config.pl unset MBEDTLS_SSL_CLI_C
Gilles Peskine99d70d82019-09-20 19:23:10 +0200975 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
Gilles Peskine8f073122018-11-27 15:58:47 +0100976}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000977
Gilles Peskine8f073122018-11-27 15:58:47 +0100978component_build_no_sockets () {
979 # Note, C99 compliance can also be tested with the sockets support disabled,
980 # as that requires a POSIX platform (which isn't the same as C99).
981 msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100982 scripts/config.pl full
983 scripts/config.pl unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
984 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
Gilles Peskine99d70d82019-09-20 19:23:10 +0200985 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1 -std=c99 -pedantic' lib
Gilles Peskine8f073122018-11-27 15:58:47 +0100986}
Hanno Becker5175ac62017-09-18 15:36:25 +0100987
Andrzej Kurek1d070822019-09-05 09:27:47 -0400988component_test_memory_buffer_allocator_backtrace () {
989 msg "build: default config with memory buffer allocator and backtrace enabled"
Hanno Becker74b5e342019-02-26 14:34:13 +0000990 scripts/config.pl set MBEDTLS_MEMORY_BUFFER_ALLOC_C
Andrzej Kurek1d070822019-09-05 09:27:47 -0400991 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
Hanno Becker74b5e342019-02-26 14:34:13 +0000992 scripts/config.pl set MBEDTLS_MEMORY_BACKTRACE
Andrzej Kurek60ebd982019-09-10 02:58:34 -0400993 scripts/config.pl set MBEDTLS_MEMORY_DEBUG
Andrzej Kurek1d070822019-09-05 09:27:47 -0400994 CC=gcc cmake .
995 make
996
997 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C and MBEDTLS_MEMORY_BACKTRACE"
998 make test
999}
1000
1001component_test_memory_buffer_allocator () {
1002 msg "build: default config with memory buffer allocator"
1003 scripts/config.pl set MBEDTLS_MEMORY_BUFFER_ALLOC_C
Hanno Beckerd130b982019-06-03 16:35:02 +01001004 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
Hanno Becker74b5e342019-02-26 14:34:13 +00001005 CC=gcc cmake .
1006 make
1007
1008 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C"
1009 make test
1010
1011 msg "test: ssl-opt.sh, MBEDTLS_MEMORY_BUFFER_ALLOC_C"
Andrzej Kurek1f5a5962019-09-05 10:09:37 -04001012 # MBEDTLS_MEMORY_BUFFER_ALLOC is slow. Skip tests that tend to time out.
1013 if_build_succeeded tests/ssl-opt.sh -e '^DTLS proxy'
Hanno Becker74b5e342019-02-26 14:34:13 +00001014}
1015
Gilles Peskine8f073122018-11-27 15:58:47 +01001016component_test_no_max_fragment_length () {
1017 # Run max fragment length tests with MFL disabled
1018 msg "build: default config except MFL extension (ASan build)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +01001019 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
1020 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1021 make
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001022
Gilles Peskine8f073122018-11-27 15:58:47 +01001023 msg "test: ssl-opt.sh, MFL-related tests"
1024 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length"
1025}
Angus Grattonc4dd0732018-04-11 16:28:39 +10001026
Gilles Peskine8f073122018-11-27 15:58:47 +01001027component_test_no_max_fragment_length_small_ssl_out_content_len () {
1028 msg "build: no MFL extension, small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +01001029 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
1030 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 16384
1031 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
1032 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1033 make
Angus Grattonc4dd0732018-04-11 16:28:39 +10001034
Gilles Peskine8f073122018-11-27 15:58:47 +01001035 msg "test: MFL tests (disabled MFL extension case) & large packet tests"
1036 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length\|Large buffer"
1037}
Janos Follath06c54002016-06-09 13:57:40 +01001038
Gilles Peskine8f073122018-11-27 15:58:47 +01001039component_test_null_entropy () {
1040 msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +01001041 scripts/config.pl set MBEDTLS_TEST_NULL_ENTROPY
1042 scripts/config.pl set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
1043 scripts/config.pl set MBEDTLS_ENTROPY_C
1044 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskinedf4f7c12020-04-28 10:41:20 +02001045 scripts/config.pl unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine8f073122018-11-27 15:58:47 +01001046 scripts/config.pl unset MBEDTLS_ENTROPY_HARDWARE_ALT
1047 scripts/config.pl unset MBEDTLS_HAVEGE_C
Gilles Peskine5fa32a72019-01-06 19:48:30 +00001048 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan -D UNSAFE_BUILD=ON .
Gilles Peskine8f073122018-11-27 15:58:47 +01001049 make
Janos Follath06c54002016-06-09 13:57:40 +01001050
Gilles Peskine8f073122018-11-27 15:58:47 +01001051 msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)"
1052 make test
1053}
Hanno Beckere5fecec2018-10-11 11:02:52 +01001054
Gilles Peskine8f073122018-11-27 15:58:47 +01001055component_test_platform_calloc_macro () {
1056 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +01001057 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
1058 scripts/config.pl set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
1059 scripts/config.pl set MBEDTLS_PLATFORM_FREE_MACRO free
1060 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1061 make
Hanno Beckere5fecec2018-10-11 11:02:52 +01001062
Gilles Peskine8f073122018-11-27 15:58:47 +01001063 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
1064 make test
1065}
Hanno Becker83ebf782017-07-07 12:29:15 +01001066
Gilles Peskinec6b09862019-09-17 19:04:38 +02001067component_test_malloc_0_null () {
1068 msg "build: malloc(0) returns NULL (ASan+UBSan build)"
1069 scripts/config.pl full
1070 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
1071 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'
1072
1073 msg "test: malloc(0) returns NULL (ASan+UBSan build)"
1074 make test
1075
1076 msg "selftest: malloc(0) returns NULL (ASan+UBSan build)"
1077 # Just the calloc selftest. "make test" ran the others as part of the
1078 # test suites.
1079 if_build_succeeded programs/test/selftest calloc
1080}
1081
Gilles Peskine8f073122018-11-27 15:58:47 +01001082component_test_aes_fewer_tables () {
1083 msg "build: default config with AES_FEWER_TABLES enabled"
Gilles Peskine8f073122018-11-27 15:58:47 +01001084 scripts/config.pl set MBEDTLS_AES_FEWER_TABLES
1085 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01001086
Gilles Peskine8f073122018-11-27 15:58:47 +01001087 msg "test: AES_FEWER_TABLES"
1088 make test
1089}
Hanno Becker83ebf782017-07-07 12:29:15 +01001090
Gilles Peskine8f073122018-11-27 15:58:47 +01001091component_test_aes_rom_tables () {
1092 msg "build: default config with AES_ROM_TABLES enabled"
Gilles Peskine8f073122018-11-27 15:58:47 +01001093 scripts/config.pl set MBEDTLS_AES_ROM_TABLES
1094 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01001095
Gilles Peskine8f073122018-11-27 15:58:47 +01001096 msg "test: AES_ROM_TABLES"
1097 make test
1098}
Hanno Becker83ebf782017-07-07 12:29:15 +01001099
Gilles Peskine8f073122018-11-27 15:58:47 +01001100component_test_aes_fewer_tables_and_rom_tables () {
1101 msg "build: default config with AES_ROM_TABLES and AES_FEWER_TABLES enabled"
Gilles Peskine8f073122018-11-27 15:58:47 +01001102 scripts/config.pl set MBEDTLS_AES_FEWER_TABLES
1103 scripts/config.pl set MBEDTLS_AES_ROM_TABLES
1104 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01001105
Gilles Peskine8f073122018-11-27 15:58:47 +01001106 msg "test: AES_FEWER_TABLES + AES_ROM_TABLES"
1107 make test
1108}
1109
1110component_test_make_shared () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001111 msg "build/test: make shared" # ~ 40s
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001112 make SHARED=1 all check
Gilles Peskinedc25c322019-07-03 20:43:32 +02001113 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskine8f073122018-11-27 15:58:47 +01001114}
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +02001115
Gilles Peskine2c47ffc2019-07-03 20:43:05 +02001116component_test_cmake_shared () {
1117 msg "build/test: cmake shared" # ~ 2min
1118 cmake -DUSE_SHARED_MBEDTLS_LIBRARY=On .
1119 make
Gilles Peskinedc25c322019-07-03 20:43:32 +02001120 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskine2c47ffc2019-07-03 20:43:05 +02001121 make test
1122}
1123
Gilles Peskine0fe92c22019-09-20 19:56:06 +02001124test_build_opt () {
1125 info=$1 cc=$2; shift 2
1126 for opt in "$@"; do
1127 msg "build/test: $cc $opt, $info" # ~ 30s
Gilles Peskine313bb502020-04-14 20:08:41 +02001128 make CC="$cc" CFLAGS="$opt -std=c99 -pedantic -Wall -Wextra -Werror"
Gilles Peskine0fe92c22019-09-20 19:56:06 +02001129 # We're confident enough in compilers to not run _all_ the tests,
1130 # but at least run the unit tests. In particular, runs with
1131 # optimizations use inline assembly whereas runs with -O0
1132 # skip inline assembly.
1133 make test # ~30s
1134 make clean
1135 done
1136}
1137
1138component_test_clang_opt () {
1139 scripts/config.pl full
1140 test_build_opt 'full config' clang -O0 -Os -O2
1141}
1142
1143component_test_gcc_opt () {
1144 scripts/config.pl full
1145 test_build_opt 'full config' gcc -O0 -Os -O2
1146}
1147
Gilles Peskine87bf1b52019-07-03 20:42:16 +02001148component_build_mbedtls_config_file () {
1149 msg "build: make with MBEDTLS_CONFIG_FILE" # ~40s
1150 # Use the full config so as to catch a maximum of places where
1151 # the check of MBEDTLS_CONFIG_FILE might be missing.
1152 scripts/config.pl full
1153 sed 's!"check_config.h"!"mbedtls/check_config.h"!' <"$CONFIG_H" >full_config.h
1154 echo '#error "MBEDTLS_CONFIG_FILE is not working"' >"$CONFIG_H"
1155 make CFLAGS="-I '$PWD' -DMBEDTLS_CONFIG_FILE='\"full_config.h\"'"
1156 rm -f full_config.h
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001157}
1158
Gilles Peskine8f073122018-11-27 15:58:47 +01001159component_test_m32_o0 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001160 # Build once with -O0, to compile out the i386 specific inline assembly
1161 msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
Simon Butcher7a6da6e2018-06-27 21:52:54 +01001162 scripts/config.pl full
Gilles Peskineff26b042019-10-21 17:11:33 +02001163 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O0" LDFLAGS="-m32 $ASAN_CFLAGS"
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01001164
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001165 msg "test: i386, make, gcc -O0 (ASan build)"
1166 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01001167}
Gilles Peskine878cf602019-01-06 20:50:38 +00001168support_test_m32_o0 () {
1169 case $(uname -m) in
1170 *64*) true;;
1171 *) false;;
1172 esac
1173}
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001174
Gilles Peskine8f073122018-11-27 15:58:47 +01001175component_test_m32_o1 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001176 # Build again with -O1, to compile in the i386 specific inline assembly
1177 msg "build: i386, make, gcc -O1 (ASan build)" # ~ 30s
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001178 scripts/config.pl full
Gilles Peskineff26b042019-10-21 17:11:33 +02001179 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O1" LDFLAGS="-m32 $ASAN_CFLAGS"
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001180
1181 msg "test: i386, make, gcc -O1 (ASan build)"
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001182 make test
Gilles Peskine7dd44b22019-04-08 16:58:02 +02001183
1184 msg "test ssl-opt.sh, i386, make, gcc-O1"
1185 if_build_succeeded tests/ssl-opt.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01001186}
Gilles Peskine878cf602019-01-06 20:50:38 +00001187support_test_m32_o1 () {
1188 support_test_m32_o0 "$@"
1189}
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001190
Gilles Peskine8f073122018-11-27 15:58:47 +01001191component_test_mx32 () {
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001192 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
Simon Butcher7a6da6e2018-06-27 21:52:54 +01001193 scripts/config.pl full
Gilles Peskine8118e462019-06-07 14:50:09 +02001194 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32' LDFLAGS='-mx32'
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001195
1196 msg "test: 64-bit ILP32, make, gcc"
1197 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01001198}
Gilles Peskine878cf602019-01-06 20:50:38 +00001199support_test_mx32 () {
1200 case $(uname -m) in
1201 amd64|x86_64) true;;
1202 *) false;;
1203 esac
1204}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001205
Peter Kolbus1e2aa722018-12-27 06:59:04 -06001206component_test_min_mpi_window_size () {
1207 msg "build: Default + MBEDTLS_MPI_WINDOW_SIZE=1 (ASan build)" # ~ 10s
1208 scripts/config.pl set MBEDTLS_MPI_WINDOW_SIZE 1
1209 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1210 make
1211
1212 msg "test: MBEDTLS_MPI_WINDOW_SIZE=1 - main suites (inc. selftests) (ASan build)" # ~ 10s
1213 make test
1214}
1215
Gilles Peskine8f073122018-11-27 15:58:47 +01001216component_test_have_int32 () {
1217 msg "build: gcc, force 32-bit bignum limbs"
Gilles Peskine8f073122018-11-27 15:58:47 +01001218 scripts/config.pl unset MBEDTLS_HAVE_ASM
1219 scripts/config.pl unset MBEDTLS_AESNI_C
1220 scripts/config.pl unset MBEDTLS_PADLOCK_C
1221 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01001222
Gilles Peskine8f073122018-11-27 15:58:47 +01001223 msg "test: gcc, force 32-bit bignum limbs"
1224 make test
1225}
Andres Amaya Garciafe843a32017-07-20 13:21:34 +01001226
Gilles Peskine8f073122018-11-27 15:58:47 +01001227component_test_have_int64 () {
1228 msg "build: gcc, force 64-bit bignum limbs"
Gilles Peskine8f073122018-11-27 15:58:47 +01001229 scripts/config.pl unset MBEDTLS_HAVE_ASM
1230 scripts/config.pl unset MBEDTLS_AESNI_C
1231 scripts/config.pl unset MBEDTLS_PADLOCK_C
1232 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
Gilles Peskine14c3c062018-01-29 21:25:12 +01001233
Gilles Peskine8f073122018-11-27 15:58:47 +01001234 msg "test: gcc, force 64-bit bignum limbs"
1235 make test
1236}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001237
Gilles Peskine8f073122018-11-27 15:58:47 +01001238component_test_no_udbl_division () {
1239 msg "build: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +01001240 scripts/config.pl full
Gilles Peskine8f073122018-11-27 15:58:47 +01001241 scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
1242 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001243
Gilles Peskine8f073122018-11-27 15:58:47 +01001244 msg "test: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
1245 make test
1246}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001247
Gilles Peskine8f073122018-11-27 15:58:47 +01001248component_test_no_64bit_multiplication () {
1249 msg "build: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +01001250 scripts/config.pl full
Gilles Peskine8f073122018-11-27 15:58:47 +01001251 scripts/config.pl set MBEDTLS_NO_64BIT_MULTIPLICATION
1252 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001253
Gilles Peskine8f073122018-11-27 15:58:47 +01001254 msg "test: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
1255 make test
1256}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001257
Gilles Peskine8f073122018-11-27 15:58:47 +01001258component_build_arm_none_eabi_gcc () {
Gilles Peskinee6c0c7d2020-04-30 23:11:54 +02001259 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1" # ~ 10s
Manuel Pégourié-Gonnard6e6ae9b2019-04-29 12:44:12 +02001260 scripts/config.pl baremetal
Gilles Peskinefcccfbc2020-04-30 22:54:00 +02001261 make CC="${ARM_NONE_EABI_GCC_PREFIX}gcc" AR="${ARM_NONE_EABI_GCC_PREFIX}ar" LD="${ARM_NONE_EABI_GCC_PREFIX}ld" CFLAGS='-Werror -Wall -Wextra -O1' lib
Gilles Peskinee6c0c7d2020-04-30 23:11:54 +02001262
1263 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1"
1264 ${ARM_NONE_EABI_GCC_PREFIX}size library/*.o
Gilles Peskine8f073122018-11-27 15:58:47 +01001265}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001266
Gilles Peskine560f3322019-08-09 16:05:05 +02001267component_build_arm_none_eabi_gcc_arm5vte () {
Gilles Peskinee6c0c7d2020-04-30 23:11:54 +02001268 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=arm5vte" # ~ 10s
Gilles Peskine0bd284d2019-08-05 11:34:25 +02001269 scripts/config.pl baremetal
Gilles Peskine560f3322019-08-09 16:05:05 +02001270 # Build for a target platform that's close to what Debian uses
1271 # for its "armel" distribution (https://wiki.debian.org/ArmEabiPort).
1272 # See https://github.com/ARMmbed/mbedtls/pull/2169 and comments.
1273 # It would be better to build with arm-linux-gnueabi-gcc but
1274 # we don't have that on our CI at this time.
Gilles Peskinea3c6c8a2020-04-30 18:19:32 +02001275 make CC="${ARM_NONE_EABI_GCC_PREFIX}gcc" AR="${ARM_NONE_EABI_GCC_PREFIX}ar" CFLAGS='-Werror -Wall -Wextra -march=armv5te -O1' LDFLAGS='-march=armv5te' SHELL='sh -x' lib
Gilles Peskinee6c0c7d2020-04-30 23:11:54 +02001276
1277 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=armv5te -O1"
1278 ${ARM_NONE_EABI_GCC_PREFIX}size library/*.o
Gilles Peskine0bd284d2019-08-05 11:34:25 +02001279}
1280
Gilles Peskinedac156b2020-04-30 23:00:53 +02001281component_build_arm_none_eabi_gcc_m0plus () {
1282 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus" # ~ 10s
1283 scripts/config.pl baremetal
1284 make CC="${ARM_NONE_EABI_GCC_PREFIX}gcc" AR="${ARM_NONE_EABI_GCC_PREFIX}ar" LD="${ARM_NONE_EABI_GCC_PREFIX}ld" CFLAGS='-Werror -Wall -Wextra -mthumb -mcpu=cortex-m0plus -Os' lib
Gilles Peskinee6c0c7d2020-04-30 23:11:54 +02001285
1286 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus -Os"
1287 ${ARM_NONE_EABI_GCC_PREFIX}size library/*.o
Gilles Peskine5331c6e2019-01-06 22:23:42 +00001288}
Andres AG87bb5772016-09-27 15:05:15 +01001289
Gilles Peskine5331c6e2019-01-06 22:23:42 +00001290component_build_arm_none_eabi_gcc_no_udbl_division () {
Gilles Peskinea3c6c8a2020-04-30 18:19:32 +02001291 msg "build: ${ARM_NONE_EABI_GCC_PREFIX} -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001292 scripts/config.pl baremetal
Simon Butcher1c719652016-06-27 19:02:12 +01001293 scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
Gilles Peskinea3c6c8a2020-04-30 18:19:32 +02001294 make CC="${ARM_NONE_EABI_GCC_PREFIX}gcc" AR="${ARM_NONE_EABI_GCC_PREFIX}ar" LD="${ARM_NONE_EABI_GCC_PREFIX}ld" CFLAGS='-Werror -Wall -Wextra' lib
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001295 echo "Checking that software 64-bit division is not required"
1296 if_build_succeeded not grep __aeabi_uldiv library/*.o
1297}
1298
Manuel Pégourié-Gonnardbbc60db2015-06-22 14:31:50 +02001299component_build_arm_none_eabi_gcc_no_64bit_multiplication () {
Gilles Peskinea3c6c8a2020-04-30 18:19:32 +02001300 msg "build: ${ARM_NONE_EABI_GCC_PREFIX} MBEDTLS_NO_64BIT_MULTIPLICATION, make" # ~ 10s
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +01001301 scripts/config.pl baremetal
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001302 scripts/config.pl set MBEDTLS_NO_64BIT_MULTIPLICATION
Gilles Peskinea3c6c8a2020-04-30 18:19:32 +02001303 make CC="${ARM_NONE_EABI_GCC_PREFIX}gcc" AR="${ARM_NONE_EABI_GCC_PREFIX}ar" LD="${ARM_NONE_EABI_GCC_PREFIX}ld" CFLAGS='-Werror -O1 -march=armv6-m -mthumb' lib
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001304 echo "Checking that software 64-bit multiplication is not required"
1305 if_build_succeeded not grep __aeabi_lmul library/*.o
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +01001306}
Simon Butcherbc6a4862016-03-07 17:35:59 +00001307
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +01001308component_build_armcc () {
Gilles Peskinee6c0c7d2020-04-30 23:11:54 +02001309 msg "build: ARM Compiler 5"
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001310 scripts/config.pl baremetal
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +01001311 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
Gilles Peskinee6c0c7d2020-04-30 23:11:54 +02001312
1313 msg "size: ARM Compiler 5"
1314 "$ARMC5_FROMELF" -z library/*.o
1315
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001316 make clean
1317
1318 # ARM Compiler 6 - Target ARMv7-A
1319 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-a"
1320
1321 # ARM Compiler 6 - Target ARMv7-M
Simon Butcher4df5eaf2016-08-24 22:58:31 +03001322 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m"
Andres AG87bb5772016-09-27 15:05:15 +01001323
Gilles Peskine5331c6e2019-01-06 22:23:42 +00001324 # ARM Compiler 6 - Target ARMv8-A - AArch32
1325 armc6_build_test "--target=arm-arm-none-eabi -march=armv8.2-a"
Andres AG87bb5772016-09-27 15:05:15 +01001326
Gilles Peskine5331c6e2019-01-06 22:23:42 +00001327 # ARM Compiler 6 - Target ARMv8-M
1328 armc6_build_test "--target=arm-arm-none-eabi -march=armv8-m.main"
Simon Butcher940737f2017-07-23 13:42:36 +02001329
Gilles Peskine5331c6e2019-01-06 22:23:42 +00001330 # ARM Compiler 6 - Target ARMv8-A - AArch64
1331 armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a"
Gilles Peskine8f073122018-11-27 15:58:47 +01001332}
Simon Butcher940737f2017-07-23 13:42:36 +02001333
Andres Amaya Garcia9f3bdb82018-12-05 22:03:56 +00001334component_build_ssl_hw_record_accel() {
1335 msg "build: default config with MBEDTLS_SSL_HW_RECORD_ACCEL enabled"
1336 scripts/config.pl set MBEDTLS_SSL_HW_RECORD_ACCEL
1337 make CFLAGS='-Werror -O1'
1338}
1339
Gilles Peskine8f073122018-11-27 15:58:47 +01001340component_test_allow_sha1 () {
1341 msg "build: allow SHA1 in certificates by default"
Gilles Peskine8f073122018-11-27 15:58:47 +01001342 scripts/config.pl set MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
1343 make CFLAGS='-Werror -Wall -Wextra'
1344 msg "test: allow SHA1 in certificates by default"
1345 make test
1346 if_build_succeeded tests/ssl-opt.sh -f SHA-1
1347}
Simon Butcher940737f2017-07-23 13:42:36 +02001348
Gilles Peskine8f073122018-11-27 15:58:47 +01001349component_build_mingw () {
1350 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +01001351 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 +02001352
Gilles Peskine8f073122018-11-27 15:58:47 +01001353 # note Make tests only builds the tests, but doesn't run them
1354 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror' WINDOWS_BUILD=1 tests
1355 make WINDOWS_BUILD=1 clean
Hanno Beckere963efa2018-01-03 10:03:43 +00001356
Gilles Peskine8f073122018-11-27 15:58:47 +01001357 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
1358 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
1359 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
1360 make WINDOWS_BUILD=1 clean
1361}
Simon Butcher002bc622016-11-17 09:27:45 +00001362
Gilles Peskine8f073122018-11-27 15:58:47 +01001363component_test_memsan () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001364 msg "build: MSan (clang)" # ~ 1 min 20s
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001365 scripts/config.pl unset MBEDTLS_AESNI_C # memsan doesn't grok asm
1366 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
1367 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +02001368
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001369 msg "test: main suites (MSan)" # ~ 10s
1370 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001371
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001372 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
Gilles Peskine7c652162017-12-11 00:01:40 +01001373 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001374
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001375 # Optional part(s)
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001376
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001377 if [ "$MEMORY" -gt 0 ]; then
1378 msg "test: compat.sh (MSan)" # ~ 6 min 20s
Gilles Peskine7c652162017-12-11 00:01:40 +01001379 if_build_succeeded tests/compat.sh
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001380 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001381}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001382
Gilles Peskine69f190e2019-01-10 00:11:42 +01001383component_test_valgrind () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001384 msg "build: Release (clang)"
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001385 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
1386 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001387
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001388 msg "test: main suites valgrind (Release)"
1389 make memcheck
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001390
Gilles Peskine0a47c4f2019-04-08 17:00:56 +02001391 # Optional parts (slow; currently broken on OS X because programs don't
1392 # seem to receive signals under valgrind on OS X).
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001393 if [ "$MEMORY" -gt 0 ]; then
1394 msg "test: ssl-opt.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +01001395 if_build_succeeded tests/ssl-opt.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001396 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001397
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001398 if [ "$MEMORY" -gt 1 ]; then
1399 msg "test: compat.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +01001400 if_build_succeeded tests/compat.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001401 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001402}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001403
Gilles Peskine8f073122018-11-27 15:58:47 +01001404component_test_cmake_out_of_source () {
1405 msg "build: cmake 'out-of-source' build"
Gilles Peskine8f073122018-11-27 15:58:47 +01001406 MBEDTLS_ROOT_DIR="$PWD"
1407 mkdir "$OUT_OF_SOURCE_DIR"
1408 cd "$OUT_OF_SOURCE_DIR"
1409 cmake "$MBEDTLS_ROOT_DIR"
1410 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001411
Gilles Peskine8f073122018-11-27 15:58:47 +01001412 msg "test: cmake 'out-of-source' build"
1413 make test
1414 # Test an SSL option that requires an auxiliary script in test/scripts/.
1415 # Also ensure that there are no error messages such as
1416 # "No such file or directory", which would indicate that some required
1417 # file is missing (ssl-opt.sh tolerates the absence of some files so
1418 # may exit with status 0 but emit errors).
1419 if_build_succeeded ./tests/ssl-opt.sh -f 'Fallback SCSV: beginning of list' 2>ssl-opt.err
1420 if [ -s ssl-opt.err ]; then
1421 cat ssl-opt.err >&2
1422 record_status [ ! -s ssl-opt.err ]
1423 rm ssl-opt.err
1424 fi
1425 cd "$MBEDTLS_ROOT_DIR"
1426 rm -rf "$OUT_OF_SOURCE_DIR"
1427 unset MBEDTLS_ROOT_DIR
1428}
Andres AGdc192212016-08-31 17:33:13 +01001429
Gilles Peskine8f073122018-11-27 15:58:47 +01001430component_test_zeroize () {
1431 # Test that the function mbedtls_platform_zeroize() is not optimized away by
1432 # different combinations of compilers and optimization flags by using an
1433 # auxiliary GDB script. Unfortunately, GDB does not return error values to the
1434 # system in all cases that the script fails, so we must manually search the
1435 # output to check whether the pass string is present and no failure strings
1436 # were printed.
Gilles Peskine4976e822019-01-06 19:52:22 +00001437
1438 # Don't try to disable ASLR. We don't care about ASLR here. We do care
1439 # about a spurious message if Gdb tries and fails, so suppress that.
1440 gdb_disable_aslr=
1441 if [ -z "$(gdb -batch -nw -ex 'set disable-randomization off' 2>&1)" ]; then
1442 gdb_disable_aslr='set disable-randomization off'
1443 fi
1444
Gilles Peskine8f073122018-11-27 15:58:47 +01001445 for optimization_flag in -O2 -O3 -Ofast -Os; do
Gilles Peskine55f7c942019-01-09 22:28:21 +01001446 for compiler in clang gcc; do
1447 msg "test: $compiler $optimization_flag, mbedtls_platform_zeroize()"
1448 make programs CC="$compiler" DEBUG=1 CFLAGS="$optimization_flag"
Gilles Peskine4976e822019-01-06 19:52:22 +00001449 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 +01001450 if_build_succeeded grep "The buffer was correctly zeroized" test_zeroize.log
1451 if_build_succeeded not grep -i "error" test_zeroize.log
1452 rm -f test_zeroize.log
1453 make clean
1454 done
Andres Amaya Garcia29673812017-10-25 10:35:51 +01001455 done
Gilles Peskine4976e822019-01-06 19:52:22 +00001456
1457 unset gdb_disable_aslr
Gilles Peskine8f073122018-11-27 15:58:47 +01001458}
Andres Amaya Garciad0d7bf62017-10-25 09:01:31 +01001459
Gilles Peskine8f073122018-11-27 15:58:47 +01001460component_check_python_files () {
1461 msg "Lint: Python scripts"
1462 record_status tests/scripts/check-python-files.sh
1463}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001464
Gilles Peskine8f073122018-11-27 15:58:47 +01001465component_check_generate_test_code () {
1466 msg "uint test: generate_test_code.py"
1467 record_status ./tests/scripts/test_generate_test_code.py
1468}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001469
1470################################################################
1471#### Termination
1472################################################################
1473
Gilles Peskine8f073122018-11-27 15:58:47 +01001474post_report () {
1475 msg "Done, cleaning up"
1476 cleanup
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001477
Gilles Peskine8f073122018-11-27 15:58:47 +01001478 final_report
1479}
1480
1481
1482
1483################################################################
1484#### Run all the things
1485################################################################
1486
Gilles Peskinee48351a2018-11-27 16:06:30 +01001487# Run one component and clean up afterwards.
Gilles Peskine8f073122018-11-27 15:58:47 +01001488run_component () {
Gilles Peskine608953e2019-01-02 18:57:02 +01001489 # Back up the configuration in case the component modifies it.
1490 # The cleanup function will restore it.
1491 cp -p "$CONFIG_H" "$CONFIG_BAK"
Gilles Peskineffcdeff2018-12-04 12:49:28 +01001492 current_component="$1"
Gilles Peskine8f073122018-11-27 15:58:47 +01001493 "$@"
Gilles Peskinee48351a2018-11-27 16:06:30 +01001494 cleanup
Gilles Peskine8f073122018-11-27 15:58:47 +01001495}
1496
1497# Preliminary setup
1498pre_check_environment
1499pre_initialize_variables
1500pre_parse_command_line "$@"
Gilles Peskine348fb9a2018-11-27 17:04:29 +01001501
Gilles Peskine878cf602019-01-06 20:50:38 +00001502pre_check_git
1503build_status=0
1504if [ $KEEP_GOING -eq 1 ]; then
1505 pre_setup_keep_going
1506else
1507 record_status () {
1508 "$@"
1509 }
1510fi
1511pre_print_configuration
1512pre_check_tools
Gilles Peskine878cf602019-01-06 20:50:38 +00001513cleanup
Gilles Peskine8f073122018-11-27 15:58:47 +01001514
Gilles Peskinebeb3a812019-01-06 22:11:25 +00001515# Run the requested tests.
1516for component in $RUN_COMPONENTS; do
1517 run_component "component_$component"
1518done
Gilles Peskine8f073122018-11-27 15:58:47 +01001519
1520# We're done.
Gilles Peskine878cf602019-01-06 20:50:38 +00001521post_report