blob: 5ba531b865001496c6903c6a50109751abb2af65 [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}
Andres AGdc192212016-08-31 17:33:13 +0100134
Gilles Peskine8f073122018-11-27 15:58:47 +0100135 # if MAKEFLAGS is not set add the -j option to speed up invocations of make
Gilles Peskinea1fc4b52019-01-06 20:15:26 +0000136 if [ -z "${MAKEFLAGS+set}" ]; then
Gilles Peskine8f073122018-11-27 15:58:47 +0100137 export MAKEFLAGS="-j"
138 fi
Gilles Peskine878cf602019-01-06 20:50:38 +0000139
140 # Gather the list of available components. These are the functions
141 # defined in this script whose name starts with "component_".
142 # Parse the script with sed, because in sh there is no way to list
143 # defined functions.
144 ALL_COMPONENTS=$(sed -n 's/^ *component_\([0-9A-Z_a-z]*\) *().*/\1/p' <"$0")
145
146 # Exclude components that are not supported on this platform.
147 SUPPORTED_COMPONENTS=
148 for component in $ALL_COMPONENTS; do
149 case $(type "support_$component" 2>&1) in
150 *' function'*)
151 if ! support_$component; then continue; fi;;
152 esac
153 SUPPORTED_COMPONENTS="$SUPPORTED_COMPONENTS $component"
154 done
Gilles Peskine8f073122018-11-27 15:58:47 +0100155}
Andres AG38495a32016-07-12 16:54:33 +0100156
Gilles Peskinea28db922019-01-10 00:05:18 +0100157# Test whether the component $1 is included in the command line patterns.
158is_component_included()
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100159{
160 set -f
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000161 for pattern in $COMMAND_LINE_COMPONENTS; do
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100162 set +f
163 case ${1#component_} in $pattern) return 0;; esac
164 done
165 set +f
166 return 1
167}
168
Simon Butcher41eeccf2016-09-07 00:07:09 +0100169usage()
SimonB2e23c822016-04-16 21:54:39 +0100170{
Gilles Peskine709346a2017-12-10 23:43:39 +0100171 cat <<EOF
Gilles Peskine92525112018-11-27 18:15:35 +0100172Usage: $0 [OPTION]... [COMPONENT]...
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100173Run mbedtls release validation tests.
Gilles Peskine92525112018-11-27 18:15:35 +0100174By default, run all tests. With one or more COMPONENT, run only those.
Gilles Peskinea28db922019-01-10 00:05:18 +0100175COMPONENT can be the name of a component or a shell wildcard pattern.
176
177Examples:
178 $0 "check_*"
179 Run all sanity checks.
180 $0 --no-armcc --except test_memsan
181 Run everything except builds that require armcc and MemSan.
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100182
183Special options:
184 -h|--help Print this help and exit.
Gilles Peskine878cf602019-01-06 20:50:38 +0000185 --list-all-components List all available test components and exit.
186 --list-components List components supported on this platform and exit.
Gilles Peskine709346a2017-12-10 23:43:39 +0100187
188General options:
189 -f|--force Force the tests to overwrite any modified files.
Gilles Peskine7c652162017-12-11 00:01:40 +0100190 -k|--keep-going Run all tests and report errors at the end.
Gilles Peskine709346a2017-12-10 23:43:39 +0100191 -m|--memory Additional optional memory tests.
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100192 --armcc Run ARM Compiler builds (on by default).
Gilles Peskinea28db922019-01-10 00:05:18 +0100193 --except Exclude the COMPONENTs listed on the command line,
194 instead of running only those.
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100195 --no-armcc Skip ARM Compiler builds.
Gilles Peskine38d81652018-03-21 08:40:26 +0100196 --no-force Refuse to overwrite modified files (default).
197 --no-keep-going Stop at the first error (default).
198 --no-memory No additional memory tests (default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100199 --out-of-source-dir=<path> Directory used for CMake out-of-source build tests.
Gilles Peskine38d81652018-03-21 08:40:26 +0100200 --random-seed Use a random seed value for randomized tests (default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100201 -r|--release-test Run this script in release mode. This fixes the seed value to 1.
202 -s|--seed Integer seed value to use for this test run.
203
204Tool path options:
205 --armc5-bin-dir=<ARMC5_bin_dir_path> ARM Compiler 5 bin directory.
206 --armc6-bin-dir=<ARMC6_bin_dir_path> ARM Compiler 6 bin directory.
207 --gnutls-cli=<GnuTLS_cli_path> GnuTLS client executable to use for most tests.
208 --gnutls-serv=<GnuTLS_serv_path> GnuTLS server executable to use for most tests.
209 --gnutls-legacy-cli=<GnuTLS_cli_path> GnuTLS client executable to use for legacy tests.
210 --gnutls-legacy-serv=<GnuTLS_serv_path> GnuTLS server executable to use for legacy tests.
211 --openssl=<OpenSSL_path> OpenSSL executable to use for most tests.
212 --openssl-legacy=<OpenSSL_path> OpenSSL executable to use for legacy tests e.g. SSLv3.
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100213 --openssl-next=<OpenSSL_path> OpenSSL executable to use for recent things like ARIA
Gilles Peskine709346a2017-12-10 23:43:39 +0100214EOF
SimonB2e23c822016-04-16 21:54:39 +0100215}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100216
217# remove built files as well as the cmake cache/config
218cleanup()
219{
Gilles Peskinea71d64c2018-03-21 12:16:57 +0100220 if [ -n "${MBEDTLS_ROOT_DIR+set}" ]; then
221 cd "$MBEDTLS_ROOT_DIR"
222 fi
223
Gilles Peskine7c652162017-12-11 00:01:40 +0100224 command make clean
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200225
Gilles Peskine31b07e22018-03-21 12:15:06 +0100226 # Remove CMake artefacts
Simon Butcher3ad2efd2018-05-02 14:49:38 +0100227 find . -name .git -prune \
Gilles Peskine31b07e22018-03-21 12:15:06 +0100228 -iname CMakeFiles -exec rm -rf {} \+ -o \
229 \( -iname cmake_install.cmake -o \
230 -iname CTestTestfile.cmake -o \
231 -iname CMakeCache.txt \) -exec rm {} \+
232 # Recover files overwritten by in-tree CMake builds
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000233 rm -f include/Makefile include/mbedtls/Makefile programs/*/Makefile
Paul Bakkerfe0984d2014-06-13 00:13:45 +0200234 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile
235 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200236
237 if [ -f "$CONFIG_BAK" ]; then
238 mv "$CONFIG_BAK" "$CONFIG_H"
239 fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100240}
241
Gilles Peskine7c652162017-12-11 00:01:40 +0100242# Executed on exit. May be redefined depending on command line options.
243final_report () {
244 :
245}
246
247fatal_signal () {
248 cleanup
249 final_report $1
250 trap - $1
251 kill -$1 $$
252}
253
254trap 'fatal_signal HUP' HUP
255trap 'fatal_signal INT' INT
256trap 'fatal_signal TERM' TERM
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200257
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100258msg()
259{
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100260 if [ -n "${current_component:-}" ]; then
261 current_section="${current_component#component_}: $1"
262 else
263 current_section="$1"
264 fi
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100265 echo ""
266 echo "******************************************************************"
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100267 echo "* $current_section "
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000268 printf "* "; date
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100269 echo "******************************************************************"
270}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100271
Gilles Peskine8f073122018-11-27 15:58:47 +0100272armc6_build_test()
273{
274 FLAGS="$1"
Andres AGa5cd9732016-10-17 15:23:10 +0100275
Gilles Peskine8f073122018-11-27 15:58:47 +0100276 msg "build: ARM Compiler 6 ($FLAGS), make"
277 ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \
278 WARNING_CFLAGS='-xc -std=c99' make lib
279 make clean
280}
Andres AGa5cd9732016-10-17 15:23:10 +0100281
Andres AGd9eba4b2016-08-26 14:42:14 +0100282err_msg()
283{
284 echo "$1" >&2
285}
286
287check_tools()
288{
289 for TOOL in "$@"; do
Andres AG98393602017-01-31 17:04:45 +0000290 if ! `type "$TOOL" >/dev/null 2>&1`; then
Andres AGd9eba4b2016-08-26 14:42:14 +0100291 err_msg "$TOOL not found!"
292 exit 1
293 fi
294 done
295}
296
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400297check_headers_in_cpp () {
Peter Kolbus30987072019-02-01 17:19:08 -0600298 ls include/mbedtls | grep "\.h$" >headers.txt
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400299 <programs/test/cpp_dummy_build.cpp sed -n 's/"$//; s!^#include "mbedtls/!!p' |
300 sort |
301 diff headers.txt -
302 rm headers.txt
303}
304
Gilles Peskine8f073122018-11-27 15:58:47 +0100305pre_parse_command_line () {
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000306 COMMAND_LINE_COMPONENTS=
Gilles Peskinea28db922019-01-10 00:05:18 +0100307 all_except=0
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000308 no_armcc=
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000309
Gilles Peskine8f073122018-11-27 15:58:47 +0100310 while [ $# -gt 0 ]; do
Gilles Peskine55f7c942019-01-09 22:28:21 +0100311 case "$1" in
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000312 --armcc) no_armcc=;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100313 --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
314 --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000315 --except) all_except=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100316 --force|-f) FORCE=1;;
317 --gnutls-cli) shift; GNUTLS_CLI="$1";;
318 --gnutls-legacy-cli) shift; GNUTLS_LEGACY_CLI="$1";;
319 --gnutls-legacy-serv) shift; GNUTLS_LEGACY_SERV="$1";;
320 --gnutls-serv) shift; GNUTLS_SERV="$1";;
321 --help|-h) usage; exit;;
322 --keep-going|-k) KEEP_GOING=1;;
Gilles Peskine878cf602019-01-06 20:50:38 +0000323 --list-all-components) printf '%s\n' $ALL_COMPONENTS; exit;;
324 --list-components) printf '%s\n' $SUPPORTED_COMPONENTS; exit;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100325 --memory|-m) MEMORY=1;;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000326 --no-armcc) no_armcc=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100327 --no-force) FORCE=0;;
328 --no-keep-going) KEEP_GOING=0;;
329 --no-memory) MEMORY=0;;
330 --openssl) shift; OPENSSL="$1";;
331 --openssl-legacy) shift; OPENSSL_LEGACY="$1";;
332 --openssl-next) shift; OPENSSL_NEXT="$1";;
333 --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
334 --random-seed) unset SEED;;
335 --release-test|-r) SEED=1;;
336 --seed|-s) shift; SEED="$1";;
337 -*)
338 echo >&2 "Unknown option: $1"
339 echo >&2 "Run $0 --help for usage."
340 exit 120
341 ;;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000342 *) COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS $1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100343 esac
344 shift
Gilles Peskine8f073122018-11-27 15:58:47 +0100345 done
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000346
Gilles Peskinea28db922019-01-10 00:05:18 +0100347 # With no list of components, run everything.
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000348 if [ -z "$COMMAND_LINE_COMPONENTS" ]; then
349 all_except=1
350 fi
351
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000352 # --no-armcc is a legacy option. The modern way is --except '*_armcc*'.
353 # Ignore it if components are listed explicitly on the command line.
Gilles Peskinea28db922019-01-10 00:05:18 +0100354 if [ -n "$no_armcc" ] && [ $all_except -eq 1 ]; then
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000355 COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS *_armcc*"
356 fi
357
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000358 # Build the list of components to run.
Gilles Peskinea28db922019-01-10 00:05:18 +0100359 RUN_COMPONENTS=
360 for component in $SUPPORTED_COMPONENTS; do
361 if is_component_included "$component"; [ $? -eq $all_except ]; then
362 RUN_COMPONENTS="$RUN_COMPONENTS $component"
363 fi
364 done
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000365
366 unset all_except
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000367 unset no_armcc
Gilles Peskine8f073122018-11-27 15:58:47 +0100368}
SimonB2e23c822016-04-16 21:54:39 +0100369
Gilles Peskine8f073122018-11-27 15:58:47 +0100370pre_check_git () {
371 if [ $FORCE -eq 1 ]; then
Gilles Peskine53190e62019-01-09 23:17:35 +0100372 rm -rf "$OUT_OF_SOURCE_DIR"
Gilles Peskine8f073122018-11-27 15:58:47 +0100373 git checkout-index -f -q $CONFIG_H
374 cleanup
375 else
SimonB2e23c822016-04-16 21:54:39 +0100376
Gilles Peskine8f073122018-11-27 15:58:47 +0100377 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
378 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
379 echo "You can either delete this directory manually, or force the test by rerunning"
380 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
381 exit 1
382 fi
383
Gilles Peskined1174cf2019-01-09 22:30:01 +0100384 if ! git diff --quiet include/mbedtls/config.h; then
Gilles Peskine8f073122018-11-27 15:58:47 +0100385 err_msg "Warning - the configuration file 'include/mbedtls/config.h' has been edited. "
386 echo "You can either delete or preserve your work, or force the test by rerunning the"
387 echo "script as: $0 --force"
388 exit 1
389 fi
Andres AGdc192212016-08-31 17:33:13 +0100390 fi
Gilles Peskine8f073122018-11-27 15:58:47 +0100391}
Andres AGdc192212016-08-31 17:33:13 +0100392
Gilles Peskine8f073122018-11-27 15:58:47 +0100393pre_setup_keep_going () {
Gilles Peskine7c652162017-12-11 00:01:40 +0100394 failure_summary=
395 failure_count=0
396 start_red=
397 end_color=
398 if [ -t 1 ]; then
Gilles Peskine9736b9d2018-01-02 21:54:17 +0100399 case "${TERM:-}" in
Gilles Peskine7c652162017-12-11 00:01:40 +0100400 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
401 start_red=$(printf '\033[31m')
402 end_color=$(printf '\033[0m')
403 ;;
404 esac
405 fi
406 record_status () {
407 if "$@"; then
408 last_status=0
409 else
410 last_status=$?
411 text="$current_section: $* -> $last_status"
412 failure_summary="$failure_summary
413$text"
414 failure_count=$((failure_count + 1))
415 echo "${start_red}^^^^$text^^^^${end_color}"
416 fi
417 }
418 make () {
419 case "$*" in
420 *test|*check)
421 if [ $build_status -eq 0 ]; then
422 record_status command make "$@"
423 else
424 echo "(skipped because the build failed)"
425 fi
426 ;;
427 *)
428 record_status command make "$@"
429 build_status=$last_status
430 ;;
431 esac
432 }
433 final_report () {
434 if [ $failure_count -gt 0 ]; then
435 echo
436 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
437 echo "${start_red}FAILED: $failure_count${end_color}$failure_summary"
438 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Jaeden Amero7c1258d2018-07-20 16:42:14 +0100439 exit 1
Gilles Peskine7c652162017-12-11 00:01:40 +0100440 elif [ -z "${1-}" ]; then
441 echo "SUCCESS :)"
442 fi
443 if [ -n "${1-}" ]; then
444 echo "Killed by SIG$1."
445 fi
446 }
Gilles Peskine8f073122018-11-27 15:58:47 +0100447}
448
Gilles Peskine7c652162017-12-11 00:01:40 +0100449if_build_succeeded () {
450 if [ $build_status -eq 0 ]; then
451 record_status "$@"
452 fi
453}
454
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200455# to be used instead of ! for commands run with
456# record_status or if_build_succeeded
457not() {
458 ! "$@"
459}
460
Gilles Peskine8f073122018-11-27 15:58:47 +0100461pre_print_configuration () {
462 msg "info: $0 configuration"
463 echo "MEMORY: $MEMORY"
464 echo "FORCE: $FORCE"
465 echo "SEED: ${SEED-"UNSET"}"
466 echo "OPENSSL: $OPENSSL"
467 echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
468 echo "OPENSSL_NEXT: $OPENSSL_NEXT"
469 echo "GNUTLS_CLI: $GNUTLS_CLI"
470 echo "GNUTLS_SERV: $GNUTLS_SERV"
471 echo "GNUTLS_LEGACY_CLI: $GNUTLS_LEGACY_CLI"
472 echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV"
473 echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
474 echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
475}
Andres AG87bb5772016-09-27 15:05:15 +0100476
Gilles Peskine87964262019-01-06 22:40:00 +0000477# Make sure the tools we need are available.
Gilles Peskine8f073122018-11-27 15:58:47 +0100478pre_check_tools () {
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000479 # Build the list of variables to pass to output_env.sh.
480 set env
481
Gilles Peskine87964262019-01-06 22:40:00 +0000482 case " $RUN_COMPONENTS " in
483 # Require OpenSSL and GnuTLS if running any tests (as opposed to
484 # only doing builds). Not all tests run OpenSSL and GnuTLS, but this
485 # is a good enough approximation in practice.
486 *" test_"*)
487 # To avoid setting OpenSSL and GnuTLS for each call to compat.sh
488 # and ssl-opt.sh, we just export the variables they require.
489 export OPENSSL_CMD="$OPENSSL"
490 export GNUTLS_CLI="$GNUTLS_CLI"
491 export GNUTLS_SERV="$GNUTLS_SERV"
492 # Avoid passing --seed flag in every call to ssl-opt.sh
493 if [ -n "${SEED-}" ]; then
494 export SEED
495 fi
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000496 set "$@" OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY"
497 set "$@" GNUTLS_CLI="$GNUTLS_CLI" GNUTLS_SERV="$GNUTLS_SERV"
498 set "$@" GNUTLS_LEGACY_CLI="$GNUTLS_LEGACY_CLI"
499 set "$@" GNUTLS_LEGACY_SERV="$GNUTLS_LEGACY_SERV"
Gilles Peskine87964262019-01-06 22:40:00 +0000500 check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$OPENSSL_NEXT" \
501 "$GNUTLS_CLI" "$GNUTLS_SERV" \
502 "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV"
503 ;;
504 esac
Andres AGd9eba4b2016-08-26 14:42:14 +0100505
Gilles Peskine87964262019-01-06 22:40:00 +0000506 case " $RUN_COMPONENTS " in
507 *_doxygen[_\ ]*) check_tools "doxygen" "dot";;
508 esac
Andres AGb2fdd042016-09-22 14:17:46 +0100509
Gilles Peskine87964262019-01-06 22:40:00 +0000510 case " $RUN_COMPONENTS " in
511 *_arm_none_eabi_gcc[_\ ]*) check_tools "arm-none-eabi-gcc";;
512 esac
Andres AG7770ea82016-10-10 15:46:20 +0100513
Gilles Peskine87964262019-01-06 22:40:00 +0000514 case " $RUN_COMPONENTS " in
515 *_mingw[_\ ]*) check_tools "i686-w64-mingw32-gcc";;
516 esac
517
518 case " $RUN_COMPONENTS " in
519 *" test_zeroize "*) check_tools "gdb";;
520 esac
521
522 case " $RUN_COMPONENTS " in
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000523 *_armcc*)
Gilles Peskine87964262019-01-06 22:40:00 +0000524 ARMC5_CC="$ARMC5_BIN_DIR/armcc"
525 ARMC5_AR="$ARMC5_BIN_DIR/armar"
526 ARMC6_CC="$ARMC6_BIN_DIR/armclang"
527 ARMC6_AR="$ARMC6_BIN_DIR/armar"
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000528 check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC6_CC" "$ARMC6_AR";;
529 esac
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000530
531 msg "info: output_env.sh"
532 case $RUN_COMPONENTS in
533 *_armcc*)
534 set "$@" ARMC5_CC="$ARMC5_CC" ARMC6_CC="$ARMC6_CC" RUN_ARMCC=1;;
535 *) set "$@" RUN_ARMCC=0;;
536 esac
537 "$@" scripts/output_env.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100538}
Gilles Peskine192c72f2017-12-21 15:59:21 +0100539
540
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000541
Gilles Peskine192c72f2017-12-21 15:59:21 +0100542################################################################
543#### Basic checks
544################################################################
Andres AGd9eba4b2016-08-26 14:42:14 +0100545
SimonB2e23c822016-04-16 21:54:39 +0100546#
547# Test Suites to be executed
548#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200549# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100550# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard61bc57a2014-08-14 11:29:06 +0200551# and/or are more likely to fail than others (eg I use Clang most of the
552# time, so start with a GCC build).
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200553# 2. Minimize total running time, by avoiding useless rebuilds
554#
555# Indicative running times are given for reference.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100556
Gilles Peskine8f073122018-11-27 15:58:47 +0100557component_check_recursion () {
558 msg "test: recursion.pl" # < 1s
559 record_status tests/scripts/recursion.pl library/*.c
560}
Manuel Pégourié-Gonnardea29d152014-11-20 17:32:33 +0100561
Gilles Peskine8f073122018-11-27 15:58:47 +0100562component_check_generated_files () {
563 msg "test: freshness of generated source files" # < 1s
564 record_status tests/scripts/check-generated-files.sh
565}
Manuel Pégourié-Gonnardb3b8e432015-02-13 14:52:19 +0000566
Gilles Peskine8f073122018-11-27 15:58:47 +0100567component_check_doxy_blocks () {
568 msg "test: doxygen markup outside doxygen blocks" # < 1s
569 record_status tests/scripts/check-doxy-blocks.pl
570}
Manuel Pégourié-Gonnardd09a6b52015-04-09 17:19:23 +0200571
Gilles Peskine8f073122018-11-27 15:58:47 +0100572component_check_files () {
573 msg "test: check-files.py" # < 1s
Gilles Peskine8f073122018-11-27 15:58:47 +0100574 record_status tests/scripts/check-files.py
575}
Darryl Greena07039c2018-03-13 16:48:16 +0000576
Gilles Peskine8f073122018-11-27 15:58:47 +0100577component_check_names () {
578 msg "test/build: declared and exported names" # < 3s
Gilles Peskine473f2d42019-05-15 17:52:22 +0200579 record_status tests/scripts/check-names.sh -v
Gilles Peskine8f073122018-11-27 15:58:47 +0100580}
Manuel Pégourié-Gonnarda687baf2015-04-09 11:09:03 +0200581
Gilles Peskine8f073122018-11-27 15:58:47 +0100582component_check_doxygen_warnings () {
583 msg "test: doxygen warnings" # ~ 3s
Gilles Peskine8f073122018-11-27 15:58:47 +0100584 record_status tests/scripts/doxygen.sh
585}
Manuel Pégourié-Gonnard1d552e72016-01-04 16:49:09 +0100586
Gilles Peskine192c72f2017-12-21 15:59:21 +0100587
588
589################################################################
590#### Build and test many configurations and targets
591################################################################
592
Gilles Peskine99a33102019-04-08 17:00:15 +0200593component_test_default_out_of_box () {
594 msg "build: make, default config (out-of-box)" # ~1min
595 make
596
597 msg "test: main suites make, default config (out-of-box)" # ~10s
598 make test
599
600 msg "selftest: make, default config (out-of-box)" # ~10s
601 programs/test/selftest
602}
603
Gilles Peskine8f073122018-11-27 15:58:47 +0100604component_test_default_cmake_gcc_asan () {
605 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100606 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
607 make
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100608
Gilles Peskine8f073122018-11-27 15:58:47 +0100609 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
610 make test
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200611
Gilles Peskine8f073122018-11-27 15:58:47 +0100612 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
613 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200614
Gilles Peskine8f073122018-11-27 15:58:47 +0100615 msg "test: compat.sh (ASan build)" # ~ 6 min
616 if_build_succeeded tests/compat.sh
617}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200618
Gilles Peskine782f4112018-11-27 16:11:09 +0100619component_test_ref_configs () {
620 msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
621 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
622 record_status tests/scripts/test-ref-configs.pl
623}
624
Gilles Peskine8f073122018-11-27 15:58:47 +0100625component_test_sslv3 () {
626 msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100627 scripts/config.pl set MBEDTLS_SSL_PROTO_SSL3
628 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
629 make
Simon Butcher3ea7f522016-03-07 23:22:10 +0000630
Gilles Peskine8f073122018-11-27 15:58:47 +0100631 msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
632 make test
Simon Butcher3ea7f522016-03-07 23:22:10 +0000633
Gilles Peskine8f073122018-11-27 15:58:47 +0100634 msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
635 if_build_succeeded tests/compat.sh -m 'tls1 tls1_1 tls1_2 dtls1 dtls1_2'
636 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
Simon Butcher3ea7f522016-03-07 23:22:10 +0000637
Gilles Peskine8f073122018-11-27 15:58:47 +0100638 msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
639 if_build_succeeded tests/ssl-opt.sh
640}
Simon Butcher3ea7f522016-03-07 23:22:10 +0000641
Gilles Peskine8f073122018-11-27 15:58:47 +0100642component_test_no_renegotiation () {
643 msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100644 scripts/config.pl unset MBEDTLS_SSL_RENEGOTIATION
645 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
646 make
Hanno Becker134c2ab2017-10-12 15:29:50 +0100647
Gilles Peskine8f073122018-11-27 15:58:47 +0100648 msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
649 make test
Hanno Becker134c2ab2017-10-12 15:29:50 +0100650
Gilles Peskine8f073122018-11-27 15:58:47 +0100651 msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
652 if_build_succeeded tests/ssl-opt.sh
653}
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +0100654
Hanno Beckere562e7d2019-05-10 14:45:37 +0100655component_test_no_pem_no_fs () {
656 msg "build: Default + !MBEDTLS_PEM_PARSE_C + !MBEDTLS_FS_IO (ASan build)"
657 scripts/config.pl unset MBEDTLS_PEM_PARSE_C
658 scripts/config.pl unset MBEDTLS_FS_IO
659 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
660 make
661
662 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - main suites (inc. selftests) (ASan build)" # ~ 50s
663 make test
664
665 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - ssl-opt.sh (ASan build)" # ~ 6 min
666 if_build_succeeded tests/ssl-opt.sh
667}
668
Gilles Peskine8f073122018-11-27 15:58:47 +0100669component_test_rsa_no_crt () {
670 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100671 scripts/config.pl set MBEDTLS_RSA_NO_CRT
672 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
673 make
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100674
Gilles Peskine8f073122018-11-27 15:58:47 +0100675 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
676 make test
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100677
Gilles Peskine8f073122018-11-27 15:58:47 +0100678 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
679 if_build_succeeded tests/ssl-opt.sh -f RSA
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100680
Gilles Peskine8f073122018-11-27 15:58:47 +0100681 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
682 if_build_succeeded tests/compat.sh -t RSA
683}
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100684
Jarno Lamsa0905c3d2019-06-19 14:04:31 +0300685component_test_no_resumption () {
Jarno Lamsa29f2dd02019-06-20 15:31:52 +0300686 msg "build: Default + MBEDTLS_SSL_NO_SESSION_RESUMPTION (ASan build)" # ~ 6 min
Jarno Lamsa0905c3d2019-06-19 14:04:31 +0300687 scripts/config.pl unset MBEDTLS_SSL_SESSION_TICKETS
Jarno Lamsa29f2dd02019-06-20 15:31:52 +0300688 scripts/config.pl set MBEDTLS_SSL_NO_SESSION_CACHE
689 scripts/config.pl set MBEDTLS_SSL_NO_SESSION_RESUMPTION
Jarno Lamsa0905c3d2019-06-19 14:04:31 +0300690 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
691 make
692
Jarno Lamsa29f2dd02019-06-20 15:31:52 +0300693 msg "test: MBEDTLS_SSL_NO_SESSION_RESUMPTION - main suites (inc. selftests) (ASan build)" # ~ 50s
Jarno Lamsa0905c3d2019-06-19 14:04:31 +0300694 make test
695
Jarno Lamsa29f2dd02019-06-20 15:31:52 +0300696 msg "test: MBEDTLS_SSL_NO_SESSION_RESUMPTION - ssl-opt.sh (ASan build)" # ~ 6 min
Jarno Lamsa0905c3d2019-06-19 14:04:31 +0300697 if_build_succeeded tests/ssl-opt.sh
698}
699
Gilles Peskine8f073122018-11-27 15:58:47 +0100700component_test_small_ssl_out_content_len () {
701 msg "build: small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100702 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 16384
703 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
704 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
705 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000706
Gilles Peskine8f073122018-11-27 15:58:47 +0100707 msg "test: small SSL_OUT_CONTENT_LEN - ssl-opt.sh MFL and large packet tests"
708 if_build_succeeded tests/ssl-opt.sh -f "Max fragment\|Large packet"
709}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000710
Gilles Peskine8f073122018-11-27 15:58:47 +0100711component_test_small_ssl_in_content_len () {
712 msg "build: small SSL_IN_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100713 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 4096
714 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 16384
715 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
716 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000717
Gilles Peskine8f073122018-11-27 15:58:47 +0100718 msg "test: small SSL_IN_CONTENT_LEN - ssl-opt.sh MFL tests"
719 if_build_succeeded tests/ssl-opt.sh -f "Max fragment"
720}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000721
Gilles Peskine8f073122018-11-27 15:58:47 +0100722component_test_small_ssl_dtls_max_buffering () {
723 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0"
Gilles Peskine8f073122018-11-27 15:58:47 +0100724 scripts/config.pl set MBEDTLS_SSL_DTLS_MAX_BUFFERING 1000
725 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
726 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100727
Gilles Peskine8f073122018-11-27 15:58:47 +0100728 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0 - ssl-opt.sh specific reordering test"
729 if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer out-of-order hs msg before reassembling next, free buffered msg"
730}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100731
Gilles Peskine8f073122018-11-27 15:58:47 +0100732component_test_small_mbedtls_ssl_dtls_max_buffering () {
733 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1"
Manuel Pégourié-Gonnardf8c355a2019-05-28 10:21:30 +0200734 scripts/config.pl set MBEDTLS_SSL_DTLS_MAX_BUFFERING 190
Gilles Peskine8f073122018-11-27 15:58:47 +0100735 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
736 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100737
Gilles Peskine8f073122018-11-27 15:58:47 +0100738 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1 - ssl-opt.sh specific reordering test"
739 if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer encrypted Finished message, drop for fragmented NewSessionTicket"
740}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100741
Gilles Peskine8f073122018-11-27 15:58:47 +0100742component_test_full_cmake_clang () {
743 msg "build: cmake, full config, clang" # ~ 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100744 scripts/config.pl full
745 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
Hanno Becker22cf2552019-05-28 16:45:21 +0100746 CC=clang cmake -D LINK_WITH_PTHREAD=1 -D CMAKE_BUILD_TYPE:String=Check -D ENABLE_TESTING=On .
Gilles Peskine8f073122018-11-27 15:58:47 +0100747 make
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100748
Gilles Peskine8f073122018-11-27 15:58:47 +0100749 msg "test: main suites (full config)" # ~ 5s
750 make test
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200751
Gilles Peskine8f073122018-11-27 15:58:47 +0100752 msg "test: ssl-opt.sh default, ECJPAKE, SSL async (full config)" # ~ 1s
753 if_build_succeeded tests/ssl-opt.sh -f 'Default\|ECJPAKE\|SSL async private'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200754
Andres Amaya Garciaac9c5222019-01-08 21:42:27 +0000755 msg "test: compat.sh RC4, DES, 3DES & NULL (full config)" # ~ 2 min
Andres Amaya Garcia37e0a8c2019-02-19 20:20:57 +0000756 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 +0200757
Gilles Peskine8f073122018-11-27 15:58:47 +0100758 msg "test: compat.sh ARIA + ChachaPoly"
759 if_build_succeeded env OPENSSL_CMD="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
760}
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100761
Hanno Beckerefe13272019-07-03 13:32:01 +0100762component_test_hardcoded_ciphersuite_cmake_clang() {
763 msg "build: cmake, full config + MBEDTLS_SSL_CONF_SINGLE_CIPHERSUITE, clang" # ~ 50s
764 scripts/config.pl full
Hanno Beckerffb45b92019-07-19 15:07:03 +0100765 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE
766 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
Hanno Beckerefe13272019-07-03 13:32:01 +0100767 scripts/config.pl set MBEDTLS_SSL_CONF_SINGLE_CIPHERSUITE MBEDTLS_SUITE_TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8
Hanno Beckerffb45b92019-07-19 15:07:03 +0100768 CC=clang cmake -D LINK_WITH_PTHREAD=1 -D CMAKE_BUILD_TYPE:String=ASanDbg -D ENABLE_TESTING=On .
769 make
770
771 msg "test: main suites (full config + MBEDTLS_SSL_CONF_SINGLE_CIPHERSUITE)" # ~ 5s
772 make test
773
774 msg "test: ssl-opt.sh default (full config + MBEDTLS_SSL_CONF_SINGLE_CIPHERSUITE)" # ~ 5s
775 if_build_succeeded tests/ssl-opt.sh -f '^Default$\|^Default, DTLS$'
776}
777
778component_test_hardcoded_timer_callback_cmake_clang() {
779 msg "build: cmake, full config + MBEDTLS_SSL_CONF_SINGLE_CIPHERSUITE, clang" # ~ 50s
780 scripts/config.pl full
781 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE
782 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
783 scripts/config.pl set MBEDTLS_SSL_CONF_GET_TIMER mbedtls_timing_get_delay
784 scripts/config.pl set MBEDTLS_SSL_CONF_SET_TIMER mbedtls_timing_set_delay
785 CC=clang cmake -D LINK_WITH_PTHREAD=1 -D CMAKE_BUILD_TYPE:String=ASanDbg -D ENABLE_TESTING=On .
Hanno Beckerefe13272019-07-03 13:32:01 +0100786 make
787
788 msg "test: main suites (full config + MBEDTLS_SSL_CONF_SINGLE_CIPHERSUITE)" # ~ 5s
789 make test
790
791 msg "test: ssl-opt.sh default (full config + MBEDTLS_SSL_CONF_SINGLE_CIPHERSUITE)" # ~ 5s
792 if_build_succeeded tests/ssl-opt.sh -f '^Default$\|^Default, DTLS$'
793}
794
Hanno Becker9fb3f1e2019-07-19 16:55:35 +0100795component_test_hardcoded_version_cmake_clang() {
796 msg "build: cmake, full config + hardcoded version, clang" # ~ 50s
797 scripts/config.pl full
798 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE
799 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
800 scripts/config.pl set MBEDTLS_SSL_CONF_MIN_MINOR_VER MBEDTLS_SSL_MINOR_VERSION_3
801 scripts/config.pl set MBEDTLS_SSL_CONF_MAX_MINOR_VER MBEDTLS_SSL_MINOR_VERSION_3
802 scripts/config.pl set MBEDTLS_SSL_CONF_MIN_MAJOR_VER MBEDTLS_SSL_MAJOR_VERSION_3
803 scripts/config.pl set MBEDTLS_SSL_CONF_MAX_MAJOR_VER MBEDTLS_SSL_MAJOR_VERSION_3
804 CC=clang cmake -D LINK_WITH_PTHREAD=1 -D CMAKE_BUILD_TYPE:String=ASanDbg -D ENABLE_TESTING=On .
805 make
806
807 msg "test: main suites (full config + hardcoded version)" # ~ 5s
808 make test
809
810 msg "test: ssl-opt.sh default (full config + hardcoded version)" # ~ 5s
811 if_build_succeeded tests/ssl-opt.sh -f '^Default$\|^Default, DTLS$'
812}
813
Hanno Becker2a0cd5a2019-07-19 17:07:20 +0100814component_test_hardcoded_io_callbacks_cmake_clang() {
815 msg "build: cmake, full config + hardcoded IO callbacks, clang" # ~ 50s
816 scripts/config.pl full
817 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE
818 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
819 scripts/config.pl set MBEDTLS_SSL_CONF_RECV mbedtls_net_recv
820 scripts/config.pl set MBEDTLS_SSL_CONF_SEND mbedtls_net_send
821 scripts/config.pl set MBEDTLS_SSL_CONF_RECV_TIMEOUT mbedtls_net_recv_timeout
822 CC=clang cmake -D LINK_WITH_PTHREAD=1 -D CMAKE_BUILD_TYPE:String=ASanDbg -D ENABLE_TESTING=On .
823 make
824
825 msg "test: main suites (full config + hardcoded IO callbacks)" # ~ 5s
826 make test
827
828 msg "test: ssl-opt.sh default (full config + hardcoded IO callbacks)" # ~ 5s
829 if_build_succeeded tests/ssl-opt.sh -f '^Default$\|^Default, DTLS$'
830}
831
Hanno Becker6dd8e1c2019-07-22 11:04:12 +0100832component_test_hardcoded_misc_options_cmake_clang() {
833 msg "build: cmake, full config + hardcode various SSL config options, clang" # ~ 50s
834 scripts/config.pl full
835 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE
836 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
837 scripts/config.pl set MBEDTLS_SSL_CONF_READ_TIMEOUT 0
838 scripts/config.pl set MBEDTLS_SSL_CONF_HS_TIMEOUT_MIN MBEDTLS_SSL_DTLS_TIMEOUT_DFL_MIN
839 scripts/config.pl set MBEDTLS_SSL_CONF_HS_TIMEOUT_MAX MBEDTLS_SSL_DTLS_TIMEOUT_DFL_MAX
840 scripts/config.pl set MBEDTLS_SSL_CONF_CERT_REQ_CA_LIST MBEDTLS_SSL_CERT_REQ_CA_LIST_ENABLED
841 scripts/config.pl set MBEDTLS_SSL_CONF_ANTI_REPLAY MBEDTLS_SSL_ANTI_REPLAY_ENABLED
842 scripts/config.pl set MBEDTLS_SSL_CONF_BADMAC_LIMIT 0
843 scripts/config.pl set MBEDTLS_SSL_CONF_AUTHMODE MBEDTLS_SSL_VERIFY_REQUIRED
844 scripts/config.pl set MBEDTLS_SSL_CONF_ALLOW_LEGACY_RENEGOTIATION MBEDTLS_SSL_LEGACY_NO_RENEGOTIATION
845 CC=clang cmake -D LINK_WITH_PTHREAD=1 -D CMAKE_BUILD_TYPE:String=ASanDbg -D ENABLE_TESTING=On .
846 make
847
848 msg "test: main suites (full config + hardcode various SSL config options)" # ~ 5s
849 make test
850
851 msg "test: ssl-opt.sh default (full config + hardcode various SSL config options)" # ~ 5s
852 if_build_succeeded tests/ssl-opt.sh -f '^Default$\|^Default, DTLS$'
853}
854
Hanno Beckerfe1bd782019-07-19 17:32:14 +0100855component_test_hardcoded_elliptic_curve_cmake_clang() {
856 msg "build: cmake, full config + hardcode elliptic curve, clang" # ~ 50s
857 scripts/config.pl full
858 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE
859 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
860 scripts/config.pl set MBEDTLS_SSL_CONF_SINGLE_EC
861 scripts/config.pl set MBEDTLS_SSL_CONF_SINGLE_EC_GRP_ID MBEDTLS_ECP_DP_SECP256R1
862 scripts/config.pl set MBEDTLS_SSL_CONF_SINGLE_EC_TLS_ID 23
863 CC=clang cmake -D LINK_WITH_PTHREAD=1 -D CMAKE_BUILD_TYPE:String=ASanDbg -D ENABLE_TESTING=On .
864 make
865
866 msg "test: main suites (full config + hardcode elliptic curve)" # ~ 5s
867 make test
868
869 msg "test: ssl-opt.sh default (full config + hardcode elliptic curve)" # ~ 5s
870 if_build_succeeded tests/ssl-opt.sh -f '^Default$\|^Default, DTLS$'
871}
872
Gilles Peskine8f073122018-11-27 15:58:47 +0100873component_build_deprecated () {
874 msg "build: make, full config + DEPRECATED_WARNING, gcc -O" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100875 scripts/config.pl full
876 scripts/config.pl set MBEDTLS_DEPRECATED_WARNING
877 # Build with -O -Wextra to catch a maximum of issues.
878 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra' lib programs
Hanno Becker22cf2552019-05-28 16:45:21 +0100879 make PTHREAD=1 CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
Gilles Peskineb4ef45b2018-03-01 22:23:50 +0100880
Gilles Peskine8f073122018-11-27 15:58:47 +0100881 msg "build: make, full config + DEPRECATED_REMOVED, clang -O" # ~ 30s
882 # No cleanup, just tweak the configuration and rebuild
883 make clean
884 scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
885 scripts/config.pl set MBEDTLS_DEPRECATED_REMOVED
886 # Build with -O -Wextra to catch a maximum of issues.
887 make CC=clang CFLAGS='-O -Werror -Wall -Wextra' lib programs
Hanno Becker22cf2552019-05-28 16:45:21 +0100888 make PTHREAD=1 CC=clang CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
Gilles Peskine8f073122018-11-27 15:58:47 +0100889}
Gilles Peskine0afe6242018-02-21 19:28:12 +0100890
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200891
Gilles Peskine8f073122018-11-27 15:58:47 +0100892component_test_depends_curves () {
893 msg "test/build: curves.pl (gcc)" # ~ 4 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100894 record_status tests/scripts/curves.pl
895}
Manuel Pégourié-Gonnard1fe6bb92017-06-06 11:36:16 +0200896
Gilles Peskine8f073122018-11-27 15:58:47 +0100897component_test_depends_hashes () {
898 msg "test/build: depends-hashes.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100899 record_status tests/scripts/depends-hashes.pl
900}
Manuel Pégourié-Gonnard43be6cd2017-06-20 09:53:42 +0200901
Gilles Peskine8f073122018-11-27 15:58:47 +0100902component_test_depends_pkalgs () {
903 msg "test/build: depends-pkalgs.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100904 record_status tests/scripts/depends-pkalgs.pl
905}
Manuel Pégourié-Gonnard503a5ef2015-10-23 09:04:45 +0200906
Gilles Peskine8f073122018-11-27 15:58:47 +0100907component_build_key_exchanges () {
908 msg "test/build: key-exchanges (gcc)" # ~ 1 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100909 record_status tests/scripts/key-exchanges.pl
910}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100911
Gilles Peskine8f073122018-11-27 15:58:47 +0100912component_build_default_make_gcc_and_cxx () {
913 msg "build: Unix make, -Os (gcc)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100914 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400915
Gilles Peskine8f073122018-11-27 15:58:47 +0100916 msg "test: verify header list in cpp_dummy_build.cpp"
917 record_status check_headers_in_cpp
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400918
Gilles Peskine8f073122018-11-27 15:58:47 +0100919 msg "build: Unix make, incremental g++"
920 make TEST_CPP=1
921}
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +0000922
Gilles Peskinedcab2022019-06-12 16:05:50 +0200923component_test_check_params_functionality () {
924 msg "build+test: MBEDTLS_CHECK_PARAMS functionality"
925 scripts/config.pl full # includes CHECK_PARAMS
926 # Make MBEDTLS_PARAM_FAILED call mbedtls_param_failed().
927 scripts/config.pl unset MBEDTLS_CHECK_PARAMS_ASSERT
928 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
929 # Only build and run tests. Do not build sample programs, because
930 # they don't have a mbedtls_param_failed() function.
931 make CC=gcc CFLAGS='-Werror -O1' lib test
932}
933
Gilles Peskineb28636b2019-01-02 19:06:24 +0100934component_test_check_params_without_platform () {
935 msg "build+test: MBEDTLS_CHECK_PARAMS without MBEDTLS_PLATFORM_C"
936 scripts/config.pl full # includes CHECK_PARAMS
Gilles Peskinedcab2022019-06-12 16:05:50 +0200937 # Keep MBEDTLS_PARAM_FAILED as assert.
Gilles Peskineb28636b2019-01-02 19:06:24 +0100938 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
939 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
940 scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
941 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
942 scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
943 scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
944 scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
945 scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
946 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
947 scripts/config.pl unset MBEDTLS_PLATFORM_C
Hanno Becker22cf2552019-05-28 16:45:21 +0100948 make CC=gcc PTHREAD=1 CFLAGS='-Werror -O1' all test
Gilles Peskineb28636b2019-01-02 19:06:24 +0100949}
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +0200950
Gilles Peskineb28636b2019-01-02 19:06:24 +0100951component_test_check_params_silent () {
952 msg "build+test: MBEDTLS_CHECK_PARAMS with alternative MBEDTLS_PARAM_FAILED()"
953 scripts/config.pl full # includes CHECK_PARAMS
954 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
Gilles Peskinedcab2022019-06-12 16:05:50 +0200955 # Set MBEDTLS_PARAM_FAILED to nothing.
Gilles Peskineb28636b2019-01-02 19:06:24 +0100956 sed -i 's/.*\(#define MBEDTLS_PARAM_FAILED( cond )\).*/\1/' "$CONFIG_H"
Hanno Becker22cf2552019-05-28 16:45:21 +0100957 make CC=gcc PTHREAD=1 CFLAGS='-Werror -O1' all test
Gilles Peskineb28636b2019-01-02 19:06:24 +0100958}
Hanno Becker5175ac62017-09-18 15:36:25 +0100959
Gilles Peskine8f073122018-11-27 15:58:47 +0100960component_test_no_platform () {
961 # Full configuration build, without platform support, file IO and net sockets.
962 # This should catch missing mbedtls_printf definitions, and by disabling file
963 # IO, it should catch missing '#include <stdio.h>'
964 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100965 scripts/config.pl full
966 scripts/config.pl unset MBEDTLS_PLATFORM_C
967 scripts/config.pl unset MBEDTLS_NET_C
968 scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
969 scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
970 scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
971 scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
972 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
973 scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
974 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
975 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
976 scripts/config.pl unset MBEDTLS_FS_IO
977 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
978 # to re-enable platform integration features otherwise disabled in C99 builds
Hanno Becker22cf2552019-05-28 16:45:21 +0100979 make CC=gcc PTHREAD=1 CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -O0 -D_DEFAULT_SOURCE' lib programs
980 make CC=gcc PTHREAD=1 CFLAGS='-Werror -Wall -Wextra -O0' test
Gilles Peskine8f073122018-11-27 15:58:47 +0100981}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200982
Gilles Peskine8f073122018-11-27 15:58:47 +0100983component_build_no_std_function () {
984 # catch compile bugs in _uninit functions
985 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100986 scripts/config.pl full
987 scripts/config.pl set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
988 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
Hanno Becker22cf2552019-05-28 16:45:21 +0100989 make CC=gcc PTHREAD=1 CFLAGS='-Werror -Wall -Wextra -O0'
Gilles Peskine8f073122018-11-27 15:58:47 +0100990}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200991
Gilles Peskine8f073122018-11-27 15:58:47 +0100992component_build_no_ssl_srv () {
993 msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100994 scripts/config.pl full
995 scripts/config.pl unset MBEDTLS_SSL_SRV_C
Hanno Becker22cf2552019-05-28 16:45:21 +0100996 make CC=gcc PTHREAD=1 CFLAGS='-Werror -Wall -Wextra -O0'
Gilles Peskine8f073122018-11-27 15:58:47 +0100997}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200998
Gilles Peskine8f073122018-11-27 15:58:47 +0100999component_build_no_ssl_cli () {
1000 msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +01001001 scripts/config.pl full
1002 scripts/config.pl unset MBEDTLS_SSL_CLI_C
Hanno Becker22cf2552019-05-28 16:45:21 +01001003 make CC=gcc PTHREAD=1 CFLAGS='-Werror -Wall -Wextra -O0'
Gilles Peskine8f073122018-11-27 15:58:47 +01001004}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001005
Gilles Peskine8f073122018-11-27 15:58:47 +01001006component_build_no_sockets () {
1007 # Note, C99 compliance can also be tested with the sockets support disabled,
1008 # as that requires a POSIX platform (which isn't the same as C99).
1009 msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +01001010 scripts/config.pl full
1011 scripts/config.pl unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
1012 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
Hanno Becker22cf2552019-05-28 16:45:21 +01001013 make CC=gcc PTHREAD=1 CFLAGS='-Werror -Wall -Wextra -O0 -std=c99 -pedantic' lib
Gilles Peskine8f073122018-11-27 15:58:47 +01001014}
Hanno Becker5175ac62017-09-18 15:36:25 +01001015
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
Hanno Becker92820a12019-02-19 11:10:48 +00001027component_test_asan_remove_peer_certificate () {
1028 msg "build: default config with MBEDTLS_SSL_KEEP_PEER_CERTIFICATE disabled (ASan build)"
1029 scripts/config.pl unset MBEDTLS_SSL_KEEP_PEER_CERTIFICATE
1030 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1031 make
1032
1033 msg "test: !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
1034 make test
1035
1036 msg "test: ssl-opt.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
1037 if_build_succeeded tests/ssl-opt.sh
1038
1039 msg "test: compat.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
1040 if_build_succeeded tests/compat.sh
1041}
1042
Hanno Beckere256f7c2019-06-07 11:14:53 +01001043component_test_asan_remove_peer_certificate_no_renego () {
1044 msg "build: default config with MBEDTLS_SSL_KEEP_PEER_CERTIFICATE and MBEDTLS_SSL_RENEGOTIATION disabled (ASan build)"
1045 scripts/config.pl unset MBEDTLS_SSL_KEEP_PEER_CERTIFICATE
1046 scripts/config.pl unset MBEDTLS_SSL_RENEGOTIATION
1047 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1048 make
1049
1050 msg "test: !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
1051 make test
1052
1053 msg "test: ssl-opt.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE + !MBEDTLS_SSL_RENEGOTIATION"
1054 if_build_succeeded tests/ssl-opt.sh
1055
1056 msg "test: compat.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE + !MBEDTLS_SSL_RENEGOTIATION"
1057 if_build_succeeded tests/compat.sh
1058}
1059
Hanno Beckerbfabd1d2019-02-28 17:31:54 +00001060component_test_asan_on_demand_parsing_remove_peer_cert () {
1061 msg "build: default config, no peer CRT, on-demand CRT parsing (ASan build)"
1062 scripts/config.pl unset MBEDTLS_SSL_KEEP_PEER_CERTIFICATE
1063 scripts/config.pl set MBEDTLS_X509_ON_DEMAND_PARSING
Hanno Becker7dbf49a2019-03-04 16:30:14 +00001064 scripts/config.pl set MBEDTLS_THREADING_C
1065 scripts/config.pl set MBEDTLS_THREADING_PTHREAD
Hanno Becker22cf2552019-05-28 16:45:21 +01001066 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan -D LINK_WITH_PTHREAD=1 .
Hanno Beckerbfabd1d2019-02-28 17:31:54 +00001067 make
1068
1069 msg "test: !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE, MBEDTLS_X509_ON_DEMAND_PARSING"
1070 make test
1071
1072 msg "test: ssl-opt.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE, MBEDTLS_X509_ON_DEMAND_PARSING"
1073 if_build_succeeded tests/ssl-opt.sh
1074}
1075
Gilles Peskine8f073122018-11-27 15:58:47 +01001076component_test_no_max_fragment_length_small_ssl_out_content_len () {
1077 msg "build: no MFL extension, small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +01001078 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
1079 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 16384
1080 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
1081 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1082 make
Angus Grattonc4dd0732018-04-11 16:28:39 +10001083
Gilles Peskine8f073122018-11-27 15:58:47 +01001084 msg "test: MFL tests (disabled MFL extension case) & large packet tests"
1085 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length\|Large buffer"
1086}
Janos Follath06c54002016-06-09 13:57:40 +01001087
Jaeden Amero2eaf2c72019-06-05 13:32:08 +01001088component_test_when_no_ciphersuites_have_mac () {
1089 msg "build: when no ciphersuites have MAC"
1090 scripts/config.pl unset MBEDTLS_CIPHER_NULL_CIPHER
1091 scripts/config.pl unset MBEDTLS_ARC4_C
1092 scripts/config.pl unset MBEDTLS_CIPHER_MODE_CBC
1093 make
1094
1095 msg "test: !MBEDTLS_SSL_SOME_MODES_USE_MAC"
1096 make test
1097
1098 msg "test ssl-opt.sh: !MBEDTLS_SSL_SOME_MODES_USE_MAC"
Jaeden Amerofa8e6da2019-06-05 14:42:50 +01001099 if_build_succeeded tests/ssl-opt.sh -f 'Default\|EtM' -e 'without EtM'
Jaeden Amero2eaf2c72019-06-05 13:32:08 +01001100}
1101
Gilles Peskine8f073122018-11-27 15:58:47 +01001102component_test_null_entropy () {
1103 msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +01001104 scripts/config.pl set MBEDTLS_TEST_NULL_ENTROPY
1105 scripts/config.pl set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
1106 scripts/config.pl set MBEDTLS_ENTROPY_C
1107 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
1108 scripts/config.pl unset MBEDTLS_ENTROPY_HARDWARE_ALT
1109 scripts/config.pl unset MBEDTLS_HAVEGE_C
Gilles Peskine5fa32a72019-01-06 19:48:30 +00001110 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan -D UNSAFE_BUILD=ON .
Gilles Peskine8f073122018-11-27 15:58:47 +01001111 make
Janos Follath06c54002016-06-09 13:57:40 +01001112
Gilles Peskine8f073122018-11-27 15:58:47 +01001113 msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)"
1114 make test
1115}
Hanno Beckere5fecec2018-10-11 11:02:52 +01001116
Gilles Peskine8f073122018-11-27 15:58:47 +01001117component_test_platform_calloc_macro () {
1118 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +01001119 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
1120 scripts/config.pl set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
1121 scripts/config.pl set MBEDTLS_PLATFORM_FREE_MACRO free
1122 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1123 make
Hanno Beckere5fecec2018-10-11 11:02:52 +01001124
Gilles Peskine8f073122018-11-27 15:58:47 +01001125 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
1126 make test
1127}
Hanno Becker83ebf782017-07-07 12:29:15 +01001128
Gilles Peskine8f073122018-11-27 15:58:47 +01001129component_test_aes_fewer_tables () {
1130 msg "build: default config with AES_FEWER_TABLES enabled"
Gilles Peskine8f073122018-11-27 15:58:47 +01001131 scripts/config.pl set MBEDTLS_AES_FEWER_TABLES
1132 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01001133
Gilles Peskine8f073122018-11-27 15:58:47 +01001134 msg "test: AES_FEWER_TABLES"
1135 make test
1136}
Hanno Becker83ebf782017-07-07 12:29:15 +01001137
Gilles Peskine8f073122018-11-27 15:58:47 +01001138component_test_aes_rom_tables () {
1139 msg "build: default config with AES_ROM_TABLES enabled"
Gilles Peskine8f073122018-11-27 15:58:47 +01001140 scripts/config.pl set MBEDTLS_AES_ROM_TABLES
1141 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01001142
Gilles Peskine8f073122018-11-27 15:58:47 +01001143 msg "test: AES_ROM_TABLES"
1144 make test
1145}
Hanno Becker83ebf782017-07-07 12:29:15 +01001146
Gilles Peskine8f073122018-11-27 15:58:47 +01001147component_test_aes_fewer_tables_and_rom_tables () {
1148 msg "build: default config with AES_ROM_TABLES and AES_FEWER_TABLES enabled"
Gilles Peskine8f073122018-11-27 15:58:47 +01001149 scripts/config.pl set MBEDTLS_AES_FEWER_TABLES
1150 scripts/config.pl set MBEDTLS_AES_ROM_TABLES
1151 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01001152
Gilles Peskine8f073122018-11-27 15:58:47 +01001153 msg "test: AES_FEWER_TABLES + AES_ROM_TABLES"
1154 make test
1155}
1156
1157component_test_make_shared () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001158 msg "build/test: make shared" # ~ 40s
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001159 make SHARED=1 all check
Gilles Peskine8f073122018-11-27 15:58:47 +01001160}
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +02001161
Gilles Peskine8f073122018-11-27 15:58:47 +01001162component_test_m32_o0 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001163 # Build once with -O0, to compile out the i386 specific inline assembly
1164 msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
Simon Butcher7a6da6e2018-06-27 21:52:54 +01001165 scripts/config.pl full
Hanno Becker94a94f62019-06-28 13:43:33 +01001166 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE
1167 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
1168 scripts/config.pl unset MBEDTLS_MEMORY_DEBUG
Manuel Pégourié-Gonnardde8869c2019-07-03 10:31:46 +02001169 make CC=gcc PTHREAD=1 CFLAGS='-O0 -Werror -Wall -Wextra -m32 -fsanitize=address' LDFLAGS='-m32'
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01001170
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001171 msg "test: i386, make, gcc -O0 (ASan build)"
1172 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01001173}
Gilles Peskine878cf602019-01-06 20:50:38 +00001174support_test_m32_o0 () {
1175 case $(uname -m) in
1176 *64*) true;;
1177 *) false;;
1178 esac
1179}
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001180
Gilles Peskine8f073122018-11-27 15:58:47 +01001181component_test_m32_o1 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001182 # Build again with -O1, to compile in the i386 specific inline assembly
1183 msg "build: i386, make, gcc -O1 (ASan build)" # ~ 30s
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001184 scripts/config.pl full
Gilles Peskine7dd44b22019-04-08 16:58:02 +02001185 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE
1186 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
1187 scripts/config.pl unset MBEDTLS_MEMORY_DEBUG
Manuel Pégourié-Gonnardde8869c2019-07-03 10:31:46 +02001188 make CC=gcc PTHREAD=1 CFLAGS='-O1 -Werror -Wall -Wextra -m32 -fsanitize=address' LDFLAGS='-m32'
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001189
1190 msg "test: i386, make, gcc -O1 (ASan build)"
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001191 make test
Gilles Peskine7dd44b22019-04-08 16:58:02 +02001192
1193 msg "test ssl-opt.sh, i386, make, gcc-O1"
1194 if_build_succeeded tests/ssl-opt.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01001195}
Gilles Peskine878cf602019-01-06 20:50:38 +00001196support_test_m32_o1 () {
1197 support_test_m32_o0 "$@"
1198}
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001199
Gilles Peskine8f073122018-11-27 15:58:47 +01001200component_test_mx32 () {
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001201 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
Simon Butcher7a6da6e2018-06-27 21:52:54 +01001202 scripts/config.pl full
Manuel Pégourié-Gonnardde8869c2019-07-03 10:31:46 +02001203 make CC=gcc PTHREAD=1 CFLAGS='-Werror -Wall -Wextra -mx32' LDFLAGS='-mx32'
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001204
1205 msg "test: 64-bit ILP32, make, gcc"
1206 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01001207}
Gilles Peskine878cf602019-01-06 20:50:38 +00001208support_test_mx32 () {
1209 case $(uname -m) in
1210 amd64|x86_64) true;;
1211 *) false;;
1212 esac
1213}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001214
Peter Kolbus1e2aa722018-12-27 06:59:04 -06001215component_test_min_mpi_window_size () {
1216 msg "build: Default + MBEDTLS_MPI_WINDOW_SIZE=1 (ASan build)" # ~ 10s
1217 scripts/config.pl set MBEDTLS_MPI_WINDOW_SIZE 1
1218 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1219 make
1220
1221 msg "test: MBEDTLS_MPI_WINDOW_SIZE=1 - main suites (inc. selftests) (ASan build)" # ~ 10s
1222 make test
1223}
1224
Gilles Peskine8f073122018-11-27 15:58:47 +01001225component_test_have_int32 () {
1226 msg "build: gcc, force 32-bit bignum limbs"
Gilles Peskine8f073122018-11-27 15:58:47 +01001227 scripts/config.pl unset MBEDTLS_HAVE_ASM
1228 scripts/config.pl unset MBEDTLS_AESNI_C
1229 scripts/config.pl unset MBEDTLS_PADLOCK_C
1230 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01001231
Gilles Peskine8f073122018-11-27 15:58:47 +01001232 msg "test: gcc, force 32-bit bignum limbs"
1233 make test
1234}
Andres Amaya Garciafe843a32017-07-20 13:21:34 +01001235
Gilles Peskine8f073122018-11-27 15:58:47 +01001236component_test_have_int64 () {
1237 msg "build: gcc, force 64-bit bignum limbs"
Gilles Peskine8f073122018-11-27 15:58:47 +01001238 scripts/config.pl unset MBEDTLS_HAVE_ASM
1239 scripts/config.pl unset MBEDTLS_AESNI_C
1240 scripts/config.pl unset MBEDTLS_PADLOCK_C
1241 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
Gilles Peskine14c3c062018-01-29 21:25:12 +01001242
Gilles Peskine8f073122018-11-27 15:58:47 +01001243 msg "test: gcc, force 64-bit bignum limbs"
1244 make test
1245}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001246
Gilles Peskine8f073122018-11-27 15:58:47 +01001247component_test_no_udbl_division () {
1248 msg "build: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +01001249 scripts/config.pl full
1250 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
1251 scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
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_UDBL_DIVISION native" # ~ 10s
1255 make test
1256}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001257
Gilles Peskine8f073122018-11-27 15:58:47 +01001258component_test_no_64bit_multiplication () {
1259 msg "build: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +01001260 scripts/config.pl full
1261 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
1262 scripts/config.pl set MBEDTLS_NO_64BIT_MULTIPLICATION
1263 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001264
Gilles Peskine8f073122018-11-27 15:58:47 +01001265 msg "test: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
1266 make test
1267}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001268
Manuel Pégourié-Gonnardafdc1b52019-05-09 11:24:11 +02001269component_build_tinycrypt_cmake () {
1270 msg "build: tinycrypt native, cmake"
1271 scripts/config.pl set MBEDTLS_USE_TINYCRYPT
Jarno Lamsad91f7fa2019-04-30 14:29:23 +03001272 CC=gcc cmake .
1273 make
1274}
1275
Manuel Pégourié-Gonnardafdc1b52019-05-09 11:24:11 +02001276component_build_tinycrypt_make () {
1277 msg "build: tinycrypt native, make"
1278 scripts/config.pl set MBEDTLS_USE_TINYCRYPT
Jarno Lamsa4498de52019-05-02 11:45:57 +03001279 make CC=gcc CFLAGS='-Werror -O1'
Jarno Lamsad91f7fa2019-04-30 14:29:23 +03001280}
1281
Peter Kolbusb1cb0bd2019-01-29 17:42:02 -06001282component_test_no_x509_info () {
1283 msg "build: full + MBEDTLS_X509_REMOVE_INFO" # ~ 10s
1284 scripts/config.pl full
1285 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
1286 scripts/config.pl set MBEDTLS_X509_REMOVE_INFO
1287 make CFLAGS='-Werror -O1'
1288
1289 msg "test: full + MBEDTLS_X509_REMOVE_INFO" # ~ 10s
1290 make test
1291
1292 msg "test: ssl-opt.sh, full + MBEDTLS_X509_REMOVE_INFO" # ~ 1 min
1293 if_build_succeeded tests/ssl-opt.sh
1294}
1295
Gilles Peskine8f073122018-11-27 15:58:47 +01001296component_build_arm_none_eabi_gcc () {
1297 msg "build: arm-none-eabi-gcc, make" # ~ 10s
Manuel Pégourié-Gonnard6e6ae9b2019-04-29 12:44:12 +02001298 scripts/config.pl baremetal
Gilles Peskine8f073122018-11-27 15:58:47 +01001299 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
1300}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001301
Gilles Peskine8f073122018-11-27 15:58:47 +01001302component_build_arm_none_eabi_gcc_no_udbl_division () {
1303 msg "build: arm-none-eabi-gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
Manuel Pégourié-Gonnard6e6ae9b2019-04-29 12:44:12 +02001304 scripts/config.pl baremetal
Gilles Peskine8f073122018-11-27 15:58:47 +01001305 scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
1306 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
1307 echo "Checking that software 64-bit division is not required"
1308 if_build_succeeded not grep __aeabi_uldiv library/*.o
1309}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001310
Gilles Peskine8f073122018-11-27 15:58:47 +01001311component_build_arm_none_eabi_gcc_no_64bit_multiplication () {
1312 msg "build: arm-none-eabi-gcc MBEDTLS_NO_64BIT_MULTIPLICATION, make" # ~ 10s
Manuel Pégourié-Gonnard6e6ae9b2019-04-29 12:44:12 +02001313 scripts/config.pl baremetal
Gilles Peskine8f073122018-11-27 15:58:47 +01001314 scripts/config.pl set MBEDTLS_NO_64BIT_MULTIPLICATION
1315 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -O1 -march=armv6-m -mthumb' lib
1316 echo "Checking that software 64-bit multiplication is not required"
1317 if_build_succeeded not grep __aeabi_lmul library/*.o
1318}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001319
Gilles Peskine8f073122018-11-27 15:58:47 +01001320component_build_armcc () {
1321 msg "build: ARM Compiler 5, make"
Manuel Pégourié-Gonnard6e6ae9b2019-04-29 12:44:12 +02001322 scripts/config.pl baremetal
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001323
Gilles Peskine5331c6e2019-01-06 22:23:42 +00001324 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
1325 make clean
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001326
Gilles Peskine5331c6e2019-01-06 22:23:42 +00001327 # ARM Compiler 6 - Target ARMv7-A
1328 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-a"
Gilles Peskineed942f82017-06-08 15:19:20 +02001329
Gilles Peskine5331c6e2019-01-06 22:23:42 +00001330 # ARM Compiler 6 - Target ARMv7-M
1331 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m"
Andres AG87bb5772016-09-27 15:05:15 +01001332
Gilles Peskine5331c6e2019-01-06 22:23:42 +00001333 # ARM Compiler 6 - Target ARMv8-A - AArch32
1334 armc6_build_test "--target=arm-arm-none-eabi -march=armv8.2-a"
Andres AG87bb5772016-09-27 15:05:15 +01001335
Gilles Peskine5331c6e2019-01-06 22:23:42 +00001336 # ARM Compiler 6 - Target ARMv8-M
1337 armc6_build_test "--target=arm-arm-none-eabi -march=armv8-m.main"
Simon Butcher940737f2017-07-23 13:42:36 +02001338
Gilles Peskine5331c6e2019-01-06 22:23:42 +00001339 # ARM Compiler 6 - Target ARMv8-A - AArch64
1340 armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a"
Gilles Peskine8f073122018-11-27 15:58:47 +01001341}
Simon Butcher940737f2017-07-23 13:42:36 +02001342
Manuel Pégourié-Gonnard31ae7fa2019-06-18 12:03:51 +02001343# need _armcc in the name for pre_check_tools()
Hanno Beckere7895aa2019-07-22 12:47:20 +01001344component_baremetal_raw_build () {
Manuel Pégourié-Gonnard31ae7fa2019-06-18 12:03:51 +02001345 msg "build: scripts/baremetal.sh gcc/armc5/armc6"
1346 scripts/baremetal.sh --rom --gcc --armc5 --armc6 --check
1347}
1348
Hanno Beckere7895aa2019-07-22 12:47:20 +01001349component_baremetal_test_build () {
1350 msg "build: lib+test+programs for baremetal.h + baremetal_test.h"
1351 record_status scripts/baremetal.sh --ram --build-only
1352
1353 msg "test: baremetal.h + baremetal_test.h"
1354 if_build_succeeded make test
1355 if_build_succeeded tests/ssl-opt.sh --filter "^Default, DTLS$"
1356}
1357
Manuel Pégourié-Gonnardafdc1b52019-05-09 11:24:11 +02001358component_build_armcc_tinycrypt_baremetal () {
1359 msg "build: ARM Compiler 5, make with tinycrypt and baremetal"
Jarno Lamsaf6371ff2019-04-30 10:10:03 +03001360 scripts/config.pl baremetal
Manuel Pégourié-Gonnardafdc1b52019-05-09 11:24:11 +02001361 scripts/config.pl set MBEDTLS_USE_TINYCRYPT
Jarno Lamsaf6371ff2019-04-30 10:10:03 +03001362
1363 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
1364 make clean
1365}
1366
Gilles Peskine8f073122018-11-27 15:58:47 +01001367component_test_allow_sha1 () {
1368 msg "build: allow SHA1 in certificates by default"
Gilles Peskine8f073122018-11-27 15:58:47 +01001369 scripts/config.pl set MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
1370 make CFLAGS='-Werror -Wall -Wextra'
1371 msg "test: allow SHA1 in certificates by default"
1372 make test
1373 if_build_succeeded tests/ssl-opt.sh -f SHA-1
1374}
Simon Butcher940737f2017-07-23 13:42:36 +02001375
Gilles Peskine8f073122018-11-27 15:58:47 +01001376component_build_mingw () {
1377 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +01001378 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 +02001379
Gilles Peskine8f073122018-11-27 15:58:47 +01001380 # note Make tests only builds the tests, but doesn't run them
1381 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror' WINDOWS_BUILD=1 tests
1382 make WINDOWS_BUILD=1 clean
Hanno Beckere963efa2018-01-03 10:03:43 +00001383
Gilles Peskine8f073122018-11-27 15:58:47 +01001384 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
1385 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
1386 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
1387 make WINDOWS_BUILD=1 clean
1388}
Simon Butcher002bc622016-11-17 09:27:45 +00001389
Gilles Peskine8f073122018-11-27 15:58:47 +01001390component_test_memsan () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001391 msg "build: MSan (clang)" # ~ 1 min 20s
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001392 scripts/config.pl unset MBEDTLS_AESNI_C # memsan doesn't grok asm
1393 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
1394 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +02001395
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001396 msg "test: main suites (MSan)" # ~ 10s
1397 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001398
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001399 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
Gilles Peskine7c652162017-12-11 00:01:40 +01001400 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001401
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001402 # Optional part(s)
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001403
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001404 if [ "$MEMORY" -gt 0 ]; then
1405 msg "test: compat.sh (MSan)" # ~ 6 min 20s
Gilles Peskine7c652162017-12-11 00:01:40 +01001406 if_build_succeeded tests/compat.sh
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001407 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001408}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001409
Gilles Peskine69f190e2019-01-10 00:11:42 +01001410component_test_valgrind () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001411 msg "build: Release (clang)"
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001412 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
1413 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001414
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001415 msg "test: main suites valgrind (Release)"
1416 make memcheck
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001417
Gilles Peskine0a47c4f2019-04-08 17:00:56 +02001418 # Optional parts (slow; currently broken on OS X because programs don't
1419 # seem to receive signals under valgrind on OS X).
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001420 if [ "$MEMORY" -gt 0 ]; then
1421 msg "test: ssl-opt.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +01001422 if_build_succeeded tests/ssl-opt.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001423 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001424
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001425 if [ "$MEMORY" -gt 1 ]; then
1426 msg "test: compat.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +01001427 if_build_succeeded tests/compat.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001428 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001429}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001430
Gilles Peskine8f073122018-11-27 15:58:47 +01001431component_test_cmake_out_of_source () {
1432 msg "build: cmake 'out-of-source' build"
Gilles Peskine8f073122018-11-27 15:58:47 +01001433 MBEDTLS_ROOT_DIR="$PWD"
1434 mkdir "$OUT_OF_SOURCE_DIR"
1435 cd "$OUT_OF_SOURCE_DIR"
1436 cmake "$MBEDTLS_ROOT_DIR"
1437 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001438
Gilles Peskine8f073122018-11-27 15:58:47 +01001439 msg "test: cmake 'out-of-source' build"
1440 make test
1441 # Test an SSL option that requires an auxiliary script in test/scripts/.
1442 # Also ensure that there are no error messages such as
1443 # "No such file or directory", which would indicate that some required
1444 # file is missing (ssl-opt.sh tolerates the absence of some files so
1445 # may exit with status 0 but emit errors).
1446 if_build_succeeded ./tests/ssl-opt.sh -f 'Fallback SCSV: beginning of list' 2>ssl-opt.err
1447 if [ -s ssl-opt.err ]; then
1448 cat ssl-opt.err >&2
1449 record_status [ ! -s ssl-opt.err ]
1450 rm ssl-opt.err
1451 fi
1452 cd "$MBEDTLS_ROOT_DIR"
1453 rm -rf "$OUT_OF_SOURCE_DIR"
1454 unset MBEDTLS_ROOT_DIR
1455}
Andres AGdc192212016-08-31 17:33:13 +01001456
Gilles Peskine8f073122018-11-27 15:58:47 +01001457component_test_zeroize () {
1458 # Test that the function mbedtls_platform_zeroize() is not optimized away by
1459 # different combinations of compilers and optimization flags by using an
1460 # auxiliary GDB script. Unfortunately, GDB does not return error values to the
1461 # system in all cases that the script fails, so we must manually search the
1462 # output to check whether the pass string is present and no failure strings
1463 # were printed.
Gilles Peskine4976e822019-01-06 19:52:22 +00001464
1465 # Don't try to disable ASLR. We don't care about ASLR here. We do care
1466 # about a spurious message if Gdb tries and fails, so suppress that.
1467 gdb_disable_aslr=
1468 if [ -z "$(gdb -batch -nw -ex 'set disable-randomization off' 2>&1)" ]; then
1469 gdb_disable_aslr='set disable-randomization off'
1470 fi
1471
Gilles Peskine8f073122018-11-27 15:58:47 +01001472 for optimization_flag in -O2 -O3 -Ofast -Os; do
Gilles Peskine55f7c942019-01-09 22:28:21 +01001473 for compiler in clang gcc; do
1474 msg "test: $compiler $optimization_flag, mbedtls_platform_zeroize()"
1475 make programs CC="$compiler" DEBUG=1 CFLAGS="$optimization_flag"
Gilles Peskine4976e822019-01-06 19:52:22 +00001476 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 +01001477 if_build_succeeded grep "The buffer was correctly zeroized" test_zeroize.log
1478 if_build_succeeded not grep -i "error" test_zeroize.log
1479 rm -f test_zeroize.log
1480 make clean
1481 done
Andres Amaya Garcia29673812017-10-25 10:35:51 +01001482 done
Gilles Peskine4976e822019-01-06 19:52:22 +00001483
1484 unset gdb_disable_aslr
Gilles Peskine8f073122018-11-27 15:58:47 +01001485}
Andres Amaya Garciad0d7bf62017-10-25 09:01:31 +01001486
Gilles Peskine7b9fcdc2019-02-25 20:26:06 +01001487support_check_python_files () {
1488 type pylint3 >/dev/null 2>/dev/null
1489}
Gilles Peskine8f073122018-11-27 15:58:47 +01001490component_check_python_files () {
1491 msg "Lint: Python scripts"
1492 record_status tests/scripts/check-python-files.sh
1493}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001494
Gilles Peskine8f073122018-11-27 15:58:47 +01001495component_check_generate_test_code () {
1496 msg "uint test: generate_test_code.py"
1497 record_status ./tests/scripts/test_generate_test_code.py
1498}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001499
1500################################################################
1501#### Termination
1502################################################################
1503
Gilles Peskine8f073122018-11-27 15:58:47 +01001504post_report () {
1505 msg "Done, cleaning up"
1506 cleanup
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001507
Gilles Peskine8f073122018-11-27 15:58:47 +01001508 final_report
1509}
1510
1511
1512
1513################################################################
1514#### Run all the things
1515################################################################
1516
Gilles Peskinee48351a2018-11-27 16:06:30 +01001517# Run one component and clean up afterwards.
Gilles Peskine8f073122018-11-27 15:58:47 +01001518run_component () {
Gilles Peskine608953e2019-01-02 18:57:02 +01001519 # Back up the configuration in case the component modifies it.
1520 # The cleanup function will restore it.
1521 cp -p "$CONFIG_H" "$CONFIG_BAK"
Gilles Peskineffcdeff2018-12-04 12:49:28 +01001522 current_component="$1"
Gilles Peskine8f073122018-11-27 15:58:47 +01001523 "$@"
Gilles Peskinee48351a2018-11-27 16:06:30 +01001524 cleanup
Gilles Peskine8f073122018-11-27 15:58:47 +01001525}
1526
1527# Preliminary setup
1528pre_check_environment
1529pre_initialize_variables
1530pre_parse_command_line "$@"
Gilles Peskine348fb9a2018-11-27 17:04:29 +01001531
Gilles Peskine878cf602019-01-06 20:50:38 +00001532pre_check_git
1533build_status=0
1534if [ $KEEP_GOING -eq 1 ]; then
1535 pre_setup_keep_going
1536else
1537 record_status () {
1538 "$@"
1539 }
1540fi
1541pre_print_configuration
1542pre_check_tools
Gilles Peskine878cf602019-01-06 20:50:38 +00001543cleanup
Gilles Peskine8f073122018-11-27 15:58:47 +01001544
Gilles Peskinebeb3a812019-01-06 22:11:25 +00001545# Run the requested tests.
1546for component in $RUN_COMPONENTS; do
1547 run_component "component_$component"
1548done
Gilles Peskine8f073122018-11-27 15:58:47 +01001549
1550# We're done.
Gilles Peskine878cf602019-01-06 20:50:38 +00001551post_report