blob: 6a5b849fba726efc8ea2e53c4b33b07034ee6b38 [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 "$@"
Manuel Pégourié-Gonnard66491e12019-10-22 12:50:13 +0200429 if [ $build_status -eq 0 ]; then
430 build_status=$last_status
431 fi
Gilles Peskine7c652162017-12-11 00:01:40 +0100432 ;;
433 esac
434 }
435 final_report () {
436 if [ $failure_count -gt 0 ]; then
437 echo
438 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
439 echo "${start_red}FAILED: $failure_count${end_color}$failure_summary"
440 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Jaeden Amero7c1258d2018-07-20 16:42:14 +0100441 exit 1
Gilles Peskine7c652162017-12-11 00:01:40 +0100442 elif [ -z "${1-}" ]; then
443 echo "SUCCESS :)"
444 fi
445 if [ -n "${1-}" ]; then
446 echo "Killed by SIG$1."
447 fi
448 }
Gilles Peskine8f073122018-11-27 15:58:47 +0100449}
450
Gilles Peskine7c652162017-12-11 00:01:40 +0100451if_build_succeeded () {
452 if [ $build_status -eq 0 ]; then
453 record_status "$@"
454 fi
455}
456
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200457# to be used instead of ! for commands run with
458# record_status or if_build_succeeded
459not() {
460 ! "$@"
461}
462
Gilles Peskine8f073122018-11-27 15:58:47 +0100463pre_print_configuration () {
464 msg "info: $0 configuration"
465 echo "MEMORY: $MEMORY"
466 echo "FORCE: $FORCE"
467 echo "SEED: ${SEED-"UNSET"}"
468 echo "OPENSSL: $OPENSSL"
469 echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
470 echo "OPENSSL_NEXT: $OPENSSL_NEXT"
471 echo "GNUTLS_CLI: $GNUTLS_CLI"
472 echo "GNUTLS_SERV: $GNUTLS_SERV"
473 echo "GNUTLS_LEGACY_CLI: $GNUTLS_LEGACY_CLI"
474 echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV"
475 echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
476 echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
477}
Andres AG87bb5772016-09-27 15:05:15 +0100478
Gilles Peskine87964262019-01-06 22:40:00 +0000479# Make sure the tools we need are available.
Gilles Peskine8f073122018-11-27 15:58:47 +0100480pre_check_tools () {
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000481 # Build the list of variables to pass to output_env.sh.
482 set env
483
Gilles Peskine87964262019-01-06 22:40:00 +0000484 case " $RUN_COMPONENTS " in
485 # Require OpenSSL and GnuTLS if running any tests (as opposed to
486 # only doing builds). Not all tests run OpenSSL and GnuTLS, but this
487 # is a good enough approximation in practice.
488 *" test_"*)
489 # To avoid setting OpenSSL and GnuTLS for each call to compat.sh
490 # and ssl-opt.sh, we just export the variables they require.
491 export OPENSSL_CMD="$OPENSSL"
492 export GNUTLS_CLI="$GNUTLS_CLI"
493 export GNUTLS_SERV="$GNUTLS_SERV"
494 # Avoid passing --seed flag in every call to ssl-opt.sh
495 if [ -n "${SEED-}" ]; then
496 export SEED
497 fi
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000498 set "$@" OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY"
499 set "$@" GNUTLS_CLI="$GNUTLS_CLI" GNUTLS_SERV="$GNUTLS_SERV"
500 set "$@" GNUTLS_LEGACY_CLI="$GNUTLS_LEGACY_CLI"
501 set "$@" GNUTLS_LEGACY_SERV="$GNUTLS_LEGACY_SERV"
Gilles Peskine87964262019-01-06 22:40:00 +0000502 check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$OPENSSL_NEXT" \
503 "$GNUTLS_CLI" "$GNUTLS_SERV" \
504 "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV"
505 ;;
506 esac
Andres AGd9eba4b2016-08-26 14:42:14 +0100507
Gilles Peskine87964262019-01-06 22:40:00 +0000508 case " $RUN_COMPONENTS " in
509 *_doxygen[_\ ]*) check_tools "doxygen" "dot";;
510 esac
Andres AGb2fdd042016-09-22 14:17:46 +0100511
Gilles Peskine87964262019-01-06 22:40:00 +0000512 case " $RUN_COMPONENTS " in
513 *_arm_none_eabi_gcc[_\ ]*) check_tools "arm-none-eabi-gcc";;
514 esac
Andres AG7770ea82016-10-10 15:46:20 +0100515
Gilles Peskine87964262019-01-06 22:40:00 +0000516 case " $RUN_COMPONENTS " in
517 *_mingw[_\ ]*) check_tools "i686-w64-mingw32-gcc";;
518 esac
519
520 case " $RUN_COMPONENTS " in
521 *" test_zeroize "*) check_tools "gdb";;
522 esac
523
524 case " $RUN_COMPONENTS " in
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000525 *_armcc*)
Gilles Peskine87964262019-01-06 22:40:00 +0000526 ARMC5_CC="$ARMC5_BIN_DIR/armcc"
527 ARMC5_AR="$ARMC5_BIN_DIR/armar"
528 ARMC6_CC="$ARMC6_BIN_DIR/armclang"
529 ARMC6_AR="$ARMC6_BIN_DIR/armar"
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000530 check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC6_CC" "$ARMC6_AR";;
531 esac
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000532
533 msg "info: output_env.sh"
534 case $RUN_COMPONENTS in
535 *_armcc*)
536 set "$@" ARMC5_CC="$ARMC5_CC" ARMC6_CC="$ARMC6_CC" RUN_ARMCC=1;;
537 *) set "$@" RUN_ARMCC=0;;
538 esac
539 "$@" scripts/output_env.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100540}
Gilles Peskine192c72f2017-12-21 15:59:21 +0100541
542
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000543
Gilles Peskine192c72f2017-12-21 15:59:21 +0100544################################################################
545#### Basic checks
546################################################################
Andres AGd9eba4b2016-08-26 14:42:14 +0100547
SimonB2e23c822016-04-16 21:54:39 +0100548#
549# Test Suites to be executed
550#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200551# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100552# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard61bc57a2014-08-14 11:29:06 +0200553# and/or are more likely to fail than others (eg I use Clang most of the
554# time, so start with a GCC build).
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200555# 2. Minimize total running time, by avoiding useless rebuilds
556#
557# Indicative running times are given for reference.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100558
Gilles Peskine8f073122018-11-27 15:58:47 +0100559component_check_recursion () {
560 msg "test: recursion.pl" # < 1s
561 record_status tests/scripts/recursion.pl library/*.c
562}
Manuel Pégourié-Gonnardea29d152014-11-20 17:32:33 +0100563
Gilles Peskine8f073122018-11-27 15:58:47 +0100564component_check_generated_files () {
565 msg "test: freshness of generated source files" # < 1s
566 record_status tests/scripts/check-generated-files.sh
567}
Manuel Pégourié-Gonnardb3b8e432015-02-13 14:52:19 +0000568
Gilles Peskine8f073122018-11-27 15:58:47 +0100569component_check_doxy_blocks () {
570 msg "test: doxygen markup outside doxygen blocks" # < 1s
571 record_status tests/scripts/check-doxy-blocks.pl
572}
Manuel Pégourié-Gonnardd09a6b52015-04-09 17:19:23 +0200573
Gilles Peskine8f073122018-11-27 15:58:47 +0100574component_check_files () {
575 msg "test: check-files.py" # < 1s
Gilles Peskine8f073122018-11-27 15:58:47 +0100576 record_status tests/scripts/check-files.py
577}
Darryl Greena07039c2018-03-13 16:48:16 +0000578
Gilles Peskine8f073122018-11-27 15:58:47 +0100579component_check_names () {
580 msg "test/build: declared and exported names" # < 3s
Gilles Peskine473f2d42019-05-15 17:52:22 +0200581 record_status tests/scripts/check-names.sh -v
Gilles Peskine8f073122018-11-27 15:58:47 +0100582}
Manuel Pégourié-Gonnarda687baf2015-04-09 11:09:03 +0200583
Gilles Peskine8f073122018-11-27 15:58:47 +0100584component_check_doxygen_warnings () {
585 msg "test: doxygen warnings" # ~ 3s
Gilles Peskine8f073122018-11-27 15:58:47 +0100586 record_status tests/scripts/doxygen.sh
587}
Manuel Pégourié-Gonnard1d552e72016-01-04 16:49:09 +0100588
Gilles Peskine192c72f2017-12-21 15:59:21 +0100589
590
591################################################################
592#### Build and test many configurations and targets
593################################################################
594
k-stachowiak11f38e22019-06-04 13:14:58 +0200595component_test_large_ecdsa_key_signature () {
596
597 SMALL_MPI_MAX_SIZE=136 # Small enough to interfere with the EC signatures
598
599 msg "build: cmake + MBEDTLS_MPI_MAX_SIZE=${SMALL_MPI_MAX_SIZE}, gcc, ASan" # ~ 1 min 50s
600 scripts/config.pl set MBEDTLS_MPI_MAX_SIZE $SMALL_MPI_MAX_SIZE
601 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
602 make
603
604 INEVITABLY_PRESENT_FILE=Makefile
605 SIGNATURE_FILE="${INEVITABLY_PRESENT_FILE}.sig" # Warning, this is rm -f'ed below
606
607 msg "test: pk_sign secp521r1_prv.der for MBEDTLS_MPI_MAX_SIZE=${SMALL_MPI_MAX_SIZE} (ASan build)" # ~ 5s
608 if_build_succeeded programs/pkey/pk_sign tests/data_files/secp521r1_prv.der $INEVITABLY_PRESENT_FILE
609 rm -f $SIGNATURE_FILE
610}
611
Gilles Peskine99a33102019-04-08 17:00:15 +0200612component_test_default_out_of_box () {
613 msg "build: make, default config (out-of-box)" # ~1min
614 make
615
616 msg "test: main suites make, default config (out-of-box)" # ~10s
617 make test
618
619 msg "selftest: make, default config (out-of-box)" # ~10s
620 programs/test/selftest
621}
622
Gilles Peskine8f073122018-11-27 15:58:47 +0100623component_test_default_cmake_gcc_asan () {
624 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100625 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
626 make
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100627
Gilles Peskine8f073122018-11-27 15:58:47 +0100628 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
629 make test
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200630
Gilles Peskine8f073122018-11-27 15:58:47 +0100631 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
632 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200633
Gilles Peskine8f073122018-11-27 15:58:47 +0100634 msg "test: compat.sh (ASan build)" # ~ 6 min
635 if_build_succeeded tests/compat.sh
636}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200637
Hanno Beckerf8799e82019-02-26 14:27:09 +0000638component_test_full_cmake_gcc_asan () {
639 msg "build: full config, cmake, gcc, ASan"
640 scripts/config.pl full
641 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
642 make
643
644 msg "test: main suites (inc. selftests) (full config, ASan build)"
645 make test
646
647 msg "test: ssl-opt.sh (full config, ASan build)"
648 if_build_succeeded tests/ssl-opt.sh
649
650 msg "test: compat.sh (full config, ASan build)"
651 if_build_succeeded tests/compat.sh
652}
653
Manuel Pégourié-Gonnarddf59bfc2020-01-02 11:45:12 +0100654component_test_zlib_make() {
655 msg "build: zlib enabled, make"
656 scripts/config.pl set MBEDTLS_ZLIB_SUPPORT
657 make ZLIB=1 CFLAGS='-Werror -O1'
658
659 msg "test: main suites (zlib, make)"
660 make test
661
662 msg "test: ssl-opt.sh (zlib, make)"
663 if_build_succeeded tests/ssl-opt.sh
664}
665
666component_test_zlib_cmake() {
667 msg "build: zlib enabled, cmake"
668 scripts/config.pl set MBEDTLS_ZLIB_SUPPORT
669 cmake -D ENABLE_ZLIB_SUPPORT=On -D CMAKE_BUILD_TYPE:String=Check .
670 make
671
672 msg "test: main suites (zlib, cmake)"
673 make test
674
675 msg "test: ssl-opt.sh (zlib, cmake)"
676 if_build_succeeded tests/ssl-opt.sh
677}
678
Gilles Peskine782f4112018-11-27 16:11:09 +0100679component_test_ref_configs () {
680 msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
681 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
682 record_status tests/scripts/test-ref-configs.pl
683}
684
Gilles Peskine8f073122018-11-27 15:58:47 +0100685component_test_sslv3 () {
686 msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100687 scripts/config.pl set MBEDTLS_SSL_PROTO_SSL3
688 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
689 make
Simon Butcher3ea7f522016-03-07 23:22:10 +0000690
Gilles Peskine8f073122018-11-27 15:58:47 +0100691 msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
692 make test
Simon Butcher3ea7f522016-03-07 23:22:10 +0000693
Gilles Peskine8f073122018-11-27 15:58:47 +0100694 msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
695 if_build_succeeded tests/compat.sh -m 'tls1 tls1_1 tls1_2 dtls1 dtls1_2'
696 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
Simon Butcher3ea7f522016-03-07 23:22:10 +0000697
Gilles Peskine8f073122018-11-27 15:58:47 +0100698 msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
699 if_build_succeeded tests/ssl-opt.sh
700}
Simon Butcher3ea7f522016-03-07 23:22:10 +0000701
Hanno Beckerbaac25d2019-07-26 12:22:50 +0100702component_test_dtls_only () {
703 msg "build: Default + DTLS only (ASan build)" # ~ 6 min
704 scripts/config.pl set MBEDTLS_SSL_PROTO_NO_TLS
705 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
706 make
707
708 msg "test: DTLS only - main suites (inc. selftests) (ASan build)" # ~ 50s
709 make test
710
Hanno Beckerfcda6dd2019-09-05 14:49:53 +0100711 msg "test: DTLS only - ssl-opt.sh (ASan build)" # ~ 6 min
Hanno Beckerbaac25d2019-07-26 12:22:50 +0100712 if_build_succeeded tests/ssl-opt.sh
713}
714
Gilles Peskine8f073122018-11-27 15:58:47 +0100715component_test_no_renegotiation () {
716 msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100717 scripts/config.pl unset MBEDTLS_SSL_RENEGOTIATION
718 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
719 make
Hanno Becker134c2ab2017-10-12 15:29:50 +0100720
Gilles Peskine8f073122018-11-27 15:58:47 +0100721 msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
722 make test
Hanno Becker134c2ab2017-10-12 15:29:50 +0100723
Gilles Peskine8f073122018-11-27 15:58:47 +0100724 msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
725 if_build_succeeded tests/ssl-opt.sh
726}
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +0100727
Hanno Beckere562e7d2019-05-10 14:45:37 +0100728component_test_no_pem_no_fs () {
729 msg "build: Default + !MBEDTLS_PEM_PARSE_C + !MBEDTLS_FS_IO (ASan build)"
730 scripts/config.pl unset MBEDTLS_PEM_PARSE_C
731 scripts/config.pl unset MBEDTLS_FS_IO
732 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
733 make
734
735 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - main suites (inc. selftests) (ASan build)" # ~ 50s
736 make test
737
738 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - ssl-opt.sh (ASan build)" # ~ 6 min
739 if_build_succeeded tests/ssl-opt.sh
740}
741
Gilles Peskine8f073122018-11-27 15:58:47 +0100742component_test_rsa_no_crt () {
743 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100744 scripts/config.pl set MBEDTLS_RSA_NO_CRT
745 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
746 make
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100747
Gilles Peskine8f073122018-11-27 15:58:47 +0100748 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
749 make test
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100750
Gilles Peskine8f073122018-11-27 15:58:47 +0100751 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
752 if_build_succeeded tests/ssl-opt.sh -f RSA
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100753
Gilles Peskine8f073122018-11-27 15:58:47 +0100754 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
755 if_build_succeeded tests/compat.sh -t RSA
756}
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100757
Hanno Beckerc973fde2019-08-26 13:35:56 +0100758component_test_no_ctr_drbg () {
759 msg "build: Default + !MBEDTLS_CTR_DRBG_C"
760 scripts/config.pl unset MBEDTLS_CTR_DRBG_C
761 CC=gcc cmake .
762 make
763
764 msg "test: !MBEDTLS_CTR_DRBG_C - ssl-opt.sh" # ~ 5s
765 if_build_succeeded tests/ssl-opt.sh --filter "Default"
766}
767
768component_test_no_ctr_drbg_no_sha512 () {
769 msg "build: Default + !MBEDTLS_CTR_DRBG_C + !MBEDTLS_SHA512_C"
770 scripts/config.pl unset MBEDTLS_CTR_DRBG_C
771 scripts/config.pl unset MBEDTLS_SHA512_C
772 CC=gcc cmake .
773 make
774
775 msg "test: !MBEDTLS_CTR_DRBG_C + !MBEDTLS_SHA512_C - ssl-opt.sh" # ~ 5s
776 if_build_succeeded tests/ssl-opt.sh --filter "Default"
777}
778
Jarno Lamsa0905c3d2019-06-19 14:04:31 +0300779component_test_no_resumption () {
Jarno Lamsa29f2dd02019-06-20 15:31:52 +0300780 msg "build: Default + MBEDTLS_SSL_NO_SESSION_RESUMPTION (ASan build)" # ~ 6 min
Jarno Lamsa0905c3d2019-06-19 14:04:31 +0300781 scripts/config.pl unset MBEDTLS_SSL_SESSION_TICKETS
Jarno Lamsa29f2dd02019-06-20 15:31:52 +0300782 scripts/config.pl set MBEDTLS_SSL_NO_SESSION_CACHE
783 scripts/config.pl set MBEDTLS_SSL_NO_SESSION_RESUMPTION
Jarno Lamsa0905c3d2019-06-19 14:04:31 +0300784 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
785 make
786
Jarno Lamsa29f2dd02019-06-20 15:31:52 +0300787 msg "test: MBEDTLS_SSL_NO_SESSION_RESUMPTION - main suites (inc. selftests) (ASan build)" # ~ 50s
Jarno Lamsa0905c3d2019-06-19 14:04:31 +0300788 make test
789
Jarno Lamsa29f2dd02019-06-20 15:31:52 +0300790 msg "test: MBEDTLS_SSL_NO_SESSION_RESUMPTION - ssl-opt.sh (ASan build)" # ~ 6 min
Jarno Lamsa0905c3d2019-06-19 14:04:31 +0300791 if_build_succeeded tests/ssl-opt.sh
792}
793
Gilles Peskine8f073122018-11-27 15:58:47 +0100794component_test_small_ssl_out_content_len () {
795 msg "build: small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100796 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 16384
797 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
798 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
799 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000800
Gilles Peskine8f073122018-11-27 15:58:47 +0100801 msg "test: small SSL_OUT_CONTENT_LEN - ssl-opt.sh MFL and large packet tests"
802 if_build_succeeded tests/ssl-opt.sh -f "Max fragment\|Large packet"
803}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000804
Gilles Peskine8f073122018-11-27 15:58:47 +0100805component_test_small_ssl_in_content_len () {
806 msg "build: small SSL_IN_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100807 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 4096
808 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 16384
809 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
810 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000811
Gilles Peskine8f073122018-11-27 15:58:47 +0100812 msg "test: small SSL_IN_CONTENT_LEN - ssl-opt.sh MFL tests"
813 if_build_succeeded tests/ssl-opt.sh -f "Max fragment"
814}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000815
Gilles Peskine8f073122018-11-27 15:58:47 +0100816component_test_small_ssl_dtls_max_buffering () {
817 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0"
Gilles Peskine8f073122018-11-27 15:58:47 +0100818 scripts/config.pl set MBEDTLS_SSL_DTLS_MAX_BUFFERING 1000
819 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
820 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100821
Gilles Peskine8f073122018-11-27 15:58:47 +0100822 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0 - ssl-opt.sh specific reordering test"
823 if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer out-of-order hs msg before reassembling next, free buffered msg"
824}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100825
Gilles Peskine8f073122018-11-27 15:58:47 +0100826component_test_small_mbedtls_ssl_dtls_max_buffering () {
827 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1"
Manuel Pégourié-Gonnardf8c355a2019-05-28 10:21:30 +0200828 scripts/config.pl set MBEDTLS_SSL_DTLS_MAX_BUFFERING 190
Gilles Peskine8f073122018-11-27 15:58:47 +0100829 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
830 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100831
Gilles Peskine8f073122018-11-27 15:58:47 +0100832 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1 - ssl-opt.sh specific reordering test"
833 if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer encrypted Finished message, drop for fragmented NewSessionTicket"
834}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100835
Gilles Peskine8f073122018-11-27 15:58:47 +0100836component_test_full_cmake_clang () {
837 msg "build: cmake, full config, clang" # ~ 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100838 scripts/config.pl full
Hanno Becker22cf2552019-05-28 16:45:21 +0100839 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 +0100840 make
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100841
Gilles Peskine8f073122018-11-27 15:58:47 +0100842 msg "test: main suites (full config)" # ~ 5s
843 make test
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200844
Gilles Peskine8f073122018-11-27 15:58:47 +0100845 msg "test: ssl-opt.sh default, ECJPAKE, SSL async (full config)" # ~ 1s
846 if_build_succeeded tests/ssl-opt.sh -f 'Default\|ECJPAKE\|SSL async private'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200847
Andres Amaya Garciaac9c5222019-01-08 21:42:27 +0000848 msg "test: compat.sh RC4, DES, 3DES & NULL (full config)" # ~ 2 min
Andres Amaya Garcia37e0a8c2019-02-19 20:20:57 +0000849 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 +0200850
Gilles Peskine8f073122018-11-27 15:58:47 +0100851 msg "test: compat.sh ARIA + ChachaPoly"
852 if_build_succeeded env OPENSSL_CMD="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
853}
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100854
Hanno Beckerefe13272019-07-03 13:32:01 +0100855component_test_hardcoded_ciphersuite_cmake_clang() {
856 msg "build: cmake, full config + MBEDTLS_SSL_CONF_SINGLE_CIPHERSUITE, clang" # ~ 50s
857 scripts/config.pl full
Hanno Beckerffb45b92019-07-19 15:07:03 +0100858 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE
859 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
Hanno Beckerefe13272019-07-03 13:32:01 +0100860 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 +0100861 CC=clang cmake -D LINK_WITH_PTHREAD=1 -D CMAKE_BUILD_TYPE:String=ASanDbg -D ENABLE_TESTING=On .
862 make
863
864 msg "test: main suites (full config + MBEDTLS_SSL_CONF_SINGLE_CIPHERSUITE)" # ~ 5s
865 make test
866
867 msg "test: ssl-opt.sh default (full config + MBEDTLS_SSL_CONF_SINGLE_CIPHERSUITE)" # ~ 5s
868 if_build_succeeded tests/ssl-opt.sh -f '^Default$\|^Default, DTLS$'
869}
870
871component_test_hardcoded_timer_callback_cmake_clang() {
872 msg "build: cmake, full config + MBEDTLS_SSL_CONF_SINGLE_CIPHERSUITE, clang" # ~ 50s
873 scripts/config.pl full
874 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE
875 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
876 scripts/config.pl set MBEDTLS_SSL_CONF_GET_TIMER mbedtls_timing_get_delay
877 scripts/config.pl set MBEDTLS_SSL_CONF_SET_TIMER mbedtls_timing_set_delay
878 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 +0100879 make
880
881 msg "test: main suites (full config + MBEDTLS_SSL_CONF_SINGLE_CIPHERSUITE)" # ~ 5s
882 make test
883
884 msg "test: ssl-opt.sh default (full config + MBEDTLS_SSL_CONF_SINGLE_CIPHERSUITE)" # ~ 5s
885 if_build_succeeded tests/ssl-opt.sh -f '^Default$\|^Default, DTLS$'
886}
887
Hanno Becker9fb3f1e2019-07-19 16:55:35 +0100888component_test_hardcoded_version_cmake_clang() {
889 msg "build: cmake, full config + hardcoded version, clang" # ~ 50s
890 scripts/config.pl full
891 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE
892 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
893 scripts/config.pl set MBEDTLS_SSL_CONF_MIN_MINOR_VER MBEDTLS_SSL_MINOR_VERSION_3
894 scripts/config.pl set MBEDTLS_SSL_CONF_MAX_MINOR_VER MBEDTLS_SSL_MINOR_VERSION_3
895 scripts/config.pl set MBEDTLS_SSL_CONF_MIN_MAJOR_VER MBEDTLS_SSL_MAJOR_VERSION_3
896 scripts/config.pl set MBEDTLS_SSL_CONF_MAX_MAJOR_VER MBEDTLS_SSL_MAJOR_VERSION_3
897 CC=clang cmake -D LINK_WITH_PTHREAD=1 -D CMAKE_BUILD_TYPE:String=ASanDbg -D ENABLE_TESTING=On .
898 make
899
900 msg "test: main suites (full config + hardcoded version)" # ~ 5s
901 make test
902
903 msg "test: ssl-opt.sh default (full config + hardcoded version)" # ~ 5s
904 if_build_succeeded tests/ssl-opt.sh -f '^Default$\|^Default, DTLS$'
905}
906
Hanno Becker2a0cd5a2019-07-19 17:07:20 +0100907component_test_hardcoded_io_callbacks_cmake_clang() {
908 msg "build: cmake, full config + hardcoded IO callbacks, clang" # ~ 50s
909 scripts/config.pl full
910 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE
911 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
912 scripts/config.pl set MBEDTLS_SSL_CONF_RECV mbedtls_net_recv
913 scripts/config.pl set MBEDTLS_SSL_CONF_SEND mbedtls_net_send
914 scripts/config.pl set MBEDTLS_SSL_CONF_RECV_TIMEOUT mbedtls_net_recv_timeout
915 CC=clang cmake -D LINK_WITH_PTHREAD=1 -D CMAKE_BUILD_TYPE:String=ASanDbg -D ENABLE_TESTING=On .
916 make
917
918 msg "test: main suites (full config + hardcoded IO callbacks)" # ~ 5s
919 make test
920
921 msg "test: ssl-opt.sh default (full config + hardcoded IO callbacks)" # ~ 5s
922 if_build_succeeded tests/ssl-opt.sh -f '^Default$\|^Default, DTLS$'
923}
924
Hanno Becker6dd8e1c2019-07-22 11:04:12 +0100925component_test_hardcoded_misc_options_cmake_clang() {
926 msg "build: cmake, full config + hardcode various SSL config options, clang" # ~ 50s
927 scripts/config.pl full
928 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE
929 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
930 scripts/config.pl set MBEDTLS_SSL_CONF_READ_TIMEOUT 0
931 scripts/config.pl set MBEDTLS_SSL_CONF_HS_TIMEOUT_MIN MBEDTLS_SSL_DTLS_TIMEOUT_DFL_MIN
932 scripts/config.pl set MBEDTLS_SSL_CONF_HS_TIMEOUT_MAX MBEDTLS_SSL_DTLS_TIMEOUT_DFL_MAX
933 scripts/config.pl set MBEDTLS_SSL_CONF_CERT_REQ_CA_LIST MBEDTLS_SSL_CERT_REQ_CA_LIST_ENABLED
934 scripts/config.pl set MBEDTLS_SSL_CONF_ANTI_REPLAY MBEDTLS_SSL_ANTI_REPLAY_ENABLED
935 scripts/config.pl set MBEDTLS_SSL_CONF_BADMAC_LIMIT 0
936 scripts/config.pl set MBEDTLS_SSL_CONF_AUTHMODE MBEDTLS_SSL_VERIFY_REQUIRED
937 scripts/config.pl set MBEDTLS_SSL_CONF_ALLOW_LEGACY_RENEGOTIATION MBEDTLS_SSL_LEGACY_NO_RENEGOTIATION
938 CC=clang cmake -D LINK_WITH_PTHREAD=1 -D CMAKE_BUILD_TYPE:String=ASanDbg -D ENABLE_TESTING=On .
939 make
940
941 msg "test: main suites (full config + hardcode various SSL config options)" # ~ 5s
942 make test
943
944 msg "test: ssl-opt.sh default (full config + hardcode various SSL config options)" # ~ 5s
945 if_build_succeeded tests/ssl-opt.sh -f '^Default$\|^Default, DTLS$'
946}
947
Hanno Beckerfe1bd782019-07-19 17:32:14 +0100948component_test_hardcoded_elliptic_curve_cmake_clang() {
949 msg "build: cmake, full config + hardcode elliptic curve, clang" # ~ 50s
950 scripts/config.pl full
951 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE
952 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
953 scripts/config.pl set MBEDTLS_SSL_CONF_SINGLE_EC
954 scripts/config.pl set MBEDTLS_SSL_CONF_SINGLE_EC_GRP_ID MBEDTLS_ECP_DP_SECP256R1
955 scripts/config.pl set MBEDTLS_SSL_CONF_SINGLE_EC_TLS_ID 23
956 CC=clang cmake -D LINK_WITH_PTHREAD=1 -D CMAKE_BUILD_TYPE:String=ASanDbg -D ENABLE_TESTING=On .
957 make
958
959 msg "test: main suites (full config + hardcode elliptic curve)" # ~ 5s
960 make test
961
962 msg "test: ssl-opt.sh default (full config + hardcode elliptic curve)" # ~ 5s
963 if_build_succeeded tests/ssl-opt.sh -f '^Default$\|^Default, DTLS$'
964}
965
Hanno Beckerc763e9d2019-09-03 12:46:51 +0100966component_test_hardcoded_hash_cmake_clang() {
967 msg "build: cmake, full config + MBEDTLS_MD_SINGLE_HASH, clang" # ~ 50s
968 scripts/config.pl full
969 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
970 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
971 scripts/config.pl unset MBEDTLS_SHA1_C
972 scripts/config.pl unset MBEDTLS_SHA512_C
973 scripts/config.pl set MBEDTLS_SHA256_NO_SHA224
974 scripts/config.pl unset MBEDTLS_MD2_C
975 scripts/config.pl unset MBEDTLS_MD4_C
976 scripts/config.pl unset MBEDTLS_MD5_C
977 scripts/config.pl unset MBEDTLS_RIPEMD160_C
978 scripts/config.pl unset MBEDTLS_SSL_PROTO_SSL3
979 scripts/config.pl unset MBEDTLS_SSL_PROTO_TLS1
980 scripts/config.pl unset MBEDTLS_SSL_PROTO_TLS1_1
981 scripts/config.pl unset MBEDTLS_SSL_CBC_RECORD_SPLITTING
982 scripts/config.pl set MBEDTLS_MD_SINGLE_HASH MBEDTLS_MD_INFO_SHA256
983
984 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check -D ENABLE_TESTING=On .
985 make
986
987 msg "test: main suites (full config + MBEDTLS_MD_SINGLE_HASH)" # ~ 5s
988 make test
989
Hanno Beckerf2075622019-09-06 11:58:41 +0100990 msg "test: ssl-opt.sh default (full config + MBEDTLS_MD_SINGLE_HASH)" # ~ 5s
Hanno Beckerc763e9d2019-09-03 12:46:51 +0100991 if_build_succeeded tests/ssl-opt.sh -f '^Default$\|^Default, DTLS$'
992}
993
Gilles Peskine8f073122018-11-27 15:58:47 +0100994component_build_deprecated () {
995 msg "build: make, full config + DEPRECATED_WARNING, gcc -O" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100996 scripts/config.pl full
997 scripts/config.pl set MBEDTLS_DEPRECATED_WARNING
998 # Build with -O -Wextra to catch a maximum of issues.
999 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra' lib programs
Hanno Becker22cf2552019-05-28 16:45:21 +01001000 make PTHREAD=1 CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
Gilles Peskineb4ef45b2018-03-01 22:23:50 +01001001
Gilles Peskine8f073122018-11-27 15:58:47 +01001002 msg "build: make, full config + DEPRECATED_REMOVED, clang -O" # ~ 30s
1003 # No cleanup, just tweak the configuration and rebuild
1004 make clean
1005 scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
1006 scripts/config.pl set MBEDTLS_DEPRECATED_REMOVED
1007 # Build with -O -Wextra to catch a maximum of issues.
1008 make CC=clang CFLAGS='-O -Werror -Wall -Wextra' lib programs
Hanno Becker22cf2552019-05-28 16:45:21 +01001009 make PTHREAD=1 CC=clang CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
Gilles Peskine8f073122018-11-27 15:58:47 +01001010}
Gilles Peskine0afe6242018-02-21 19:28:12 +01001011
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +02001012
Gilles Peskine8f073122018-11-27 15:58:47 +01001013component_test_depends_curves () {
1014 msg "test/build: curves.pl (gcc)" # ~ 4 min
Gilles Peskine8f073122018-11-27 15:58:47 +01001015 record_status tests/scripts/curves.pl
1016}
Manuel Pégourié-Gonnard1fe6bb92017-06-06 11:36:16 +02001017
Gilles Peskine8f073122018-11-27 15:58:47 +01001018component_test_depends_hashes () {
1019 msg "test/build: depends-hashes.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +01001020 record_status tests/scripts/depends-hashes.pl
1021}
Manuel Pégourié-Gonnard43be6cd2017-06-20 09:53:42 +02001022
Gilles Peskine8f073122018-11-27 15:58:47 +01001023component_test_depends_pkalgs () {
1024 msg "test/build: depends-pkalgs.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +01001025 record_status tests/scripts/depends-pkalgs.pl
1026}
Manuel Pégourié-Gonnard503a5ef2015-10-23 09:04:45 +02001027
Gilles Peskine8f073122018-11-27 15:58:47 +01001028component_build_key_exchanges () {
1029 msg "test/build: key-exchanges (gcc)" # ~ 1 min
Gilles Peskine8f073122018-11-27 15:58:47 +01001030 record_status tests/scripts/key-exchanges.pl
1031}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001032
Gilles Peskine8f073122018-11-27 15:58:47 +01001033component_build_default_make_gcc_and_cxx () {
1034 msg "build: Unix make, -Os (gcc)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +01001035 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Andrzej Kurek991f9fe2018-07-02 09:08:21 -04001036
Gilles Peskine8f073122018-11-27 15:58:47 +01001037 msg "test: verify header list in cpp_dummy_build.cpp"
1038 record_status check_headers_in_cpp
Andrzej Kurek991f9fe2018-07-02 09:08:21 -04001039
Gilles Peskine8f073122018-11-27 15:58:47 +01001040 msg "build: Unix make, incremental g++"
1041 make TEST_CPP=1
1042}
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +00001043
Gilles Peskinedcab2022019-06-12 16:05:50 +02001044component_test_check_params_functionality () {
1045 msg "build+test: MBEDTLS_CHECK_PARAMS functionality"
1046 scripts/config.pl full # includes CHECK_PARAMS
1047 # Make MBEDTLS_PARAM_FAILED call mbedtls_param_failed().
1048 scripts/config.pl unset MBEDTLS_CHECK_PARAMS_ASSERT
Gilles Peskinedcab2022019-06-12 16:05:50 +02001049 # Only build and run tests. Do not build sample programs, because
1050 # they don't have a mbedtls_param_failed() function.
1051 make CC=gcc CFLAGS='-Werror -O1' lib test
1052}
1053
Gilles Peskineb28636b2019-01-02 19:06:24 +01001054component_test_check_params_without_platform () {
1055 msg "build+test: MBEDTLS_CHECK_PARAMS without MBEDTLS_PLATFORM_C"
1056 scripts/config.pl full # includes CHECK_PARAMS
Gilles Peskinedcab2022019-06-12 16:05:50 +02001057 # Keep MBEDTLS_PARAM_FAILED as assert.
Gilles Peskineb28636b2019-01-02 19:06:24 +01001058 scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
1059 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
1060 scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
1061 scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
1062 scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
1063 scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
1064 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
1065 scripts/config.pl unset MBEDTLS_PLATFORM_C
Hanno Becker22cf2552019-05-28 16:45:21 +01001066 make CC=gcc PTHREAD=1 CFLAGS='-Werror -O1' all test
Gilles Peskineb28636b2019-01-02 19:06:24 +01001067}
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +02001068
Gilles Peskineb28636b2019-01-02 19:06:24 +01001069component_test_check_params_silent () {
1070 msg "build+test: MBEDTLS_CHECK_PARAMS with alternative MBEDTLS_PARAM_FAILED()"
1071 scripts/config.pl full # includes CHECK_PARAMS
Gilles Peskinedcab2022019-06-12 16:05:50 +02001072 # Set MBEDTLS_PARAM_FAILED to nothing.
Gilles Peskineb28636b2019-01-02 19:06:24 +01001073 sed -i 's/.*\(#define MBEDTLS_PARAM_FAILED( cond )\).*/\1/' "$CONFIG_H"
Hanno Becker22cf2552019-05-28 16:45:21 +01001074 make CC=gcc PTHREAD=1 CFLAGS='-Werror -O1' all test
Gilles Peskineb28636b2019-01-02 19:06:24 +01001075}
Hanno Becker5175ac62017-09-18 15:36:25 +01001076
Gilles Peskine8f073122018-11-27 15:58:47 +01001077component_test_no_platform () {
1078 # Full configuration build, without platform support, file IO and net sockets.
1079 # This should catch missing mbedtls_printf definitions, and by disabling file
1080 # IO, it should catch missing '#include <stdio.h>'
1081 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +01001082 scripts/config.pl full
1083 scripts/config.pl unset MBEDTLS_PLATFORM_C
1084 scripts/config.pl unset MBEDTLS_NET_C
1085 scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
1086 scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
1087 scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
1088 scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
1089 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
1090 scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
1091 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskine8f073122018-11-27 15:58:47 +01001092 scripts/config.pl unset MBEDTLS_FS_IO
1093 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
1094 # to re-enable platform integration features otherwise disabled in C99 builds
Hanno Becker22cf2552019-05-28 16:45:21 +01001095 make CC=gcc PTHREAD=1 CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -O0 -D_DEFAULT_SOURCE' lib programs
1096 make CC=gcc PTHREAD=1 CFLAGS='-Werror -Wall -Wextra -O0' test
Gilles Peskine8f073122018-11-27 15:58:47 +01001097}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +02001098
Gilles Peskine8f073122018-11-27 15:58:47 +01001099component_build_no_std_function () {
1100 # catch compile bugs in _uninit functions
1101 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +01001102 scripts/config.pl full
1103 scripts/config.pl set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
1104 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
Hanno Becker22cf2552019-05-28 16:45:21 +01001105 make CC=gcc PTHREAD=1 CFLAGS='-Werror -Wall -Wextra -O0'
Gilles Peskine8f073122018-11-27 15:58:47 +01001106}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +02001107
Gilles Peskine8f073122018-11-27 15:58:47 +01001108component_build_no_ssl_srv () {
1109 msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +01001110 scripts/config.pl full
1111 scripts/config.pl unset MBEDTLS_SSL_SRV_C
Hanno Becker22cf2552019-05-28 16:45:21 +01001112 make CC=gcc PTHREAD=1 CFLAGS='-Werror -Wall -Wextra -O0'
Gilles Peskine8f073122018-11-27 15:58:47 +01001113}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +02001114
Gilles Peskine8f073122018-11-27 15:58:47 +01001115component_build_no_ssl_cli () {
1116 msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +01001117 scripts/config.pl full
1118 scripts/config.pl unset MBEDTLS_SSL_CLI_C
Hanno Becker22cf2552019-05-28 16:45:21 +01001119 make CC=gcc PTHREAD=1 CFLAGS='-Werror -Wall -Wextra -O0'
Gilles Peskine8f073122018-11-27 15:58:47 +01001120}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001121
Gilles Peskine8f073122018-11-27 15:58:47 +01001122component_build_no_sockets () {
1123 # Note, C99 compliance can also be tested with the sockets support disabled,
1124 # as that requires a POSIX platform (which isn't the same as C99).
1125 msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +01001126 scripts/config.pl full
1127 scripts/config.pl unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
1128 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
Hanno Becker22cf2552019-05-28 16:45:21 +01001129 make CC=gcc PTHREAD=1 CFLAGS='-Werror -Wall -Wextra -O0 -std=c99 -pedantic' lib
Gilles Peskine8f073122018-11-27 15:58:47 +01001130}
Hanno Becker5175ac62017-09-18 15:36:25 +01001131
Andrzej Kurek1d070822019-09-05 09:27:47 -04001132component_test_memory_buffer_allocator_backtrace () {
1133 msg "build: default config with memory buffer allocator and backtrace enabled"
Hanno Becker74b5e342019-02-26 14:34:13 +00001134 scripts/config.pl set MBEDTLS_MEMORY_BUFFER_ALLOC_C
Andrzej Kurek1d070822019-09-05 09:27:47 -04001135 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
Hanno Becker74b5e342019-02-26 14:34:13 +00001136 scripts/config.pl set MBEDTLS_MEMORY_BACKTRACE
Andrzej Kurek60ebd982019-09-10 02:58:34 -04001137 scripts/config.pl set MBEDTLS_MEMORY_DEBUG
Andrzej Kurek1d070822019-09-05 09:27:47 -04001138 CC=gcc cmake .
1139 make
1140
1141 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C and MBEDTLS_MEMORY_BACKTRACE"
1142 make test
1143}
1144
1145component_test_memory_buffer_allocator () {
1146 msg "build: default config with memory buffer allocator"
1147 scripts/config.pl set MBEDTLS_MEMORY_BUFFER_ALLOC_C
Hanno Beckerd130b982019-06-03 16:35:02 +01001148 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
Hanno Becker74b5e342019-02-26 14:34:13 +00001149 CC=gcc cmake .
1150 make
1151
1152 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C"
1153 make test
1154
1155 msg "test: ssl-opt.sh, MBEDTLS_MEMORY_BUFFER_ALLOC_C"
Andrzej Kurek1f5a5962019-09-05 10:09:37 -04001156 # MBEDTLS_MEMORY_BUFFER_ALLOC is slow. Skip tests that tend to time out.
1157 if_build_succeeded tests/ssl-opt.sh -e '^DTLS proxy'
Hanno Becker74b5e342019-02-26 14:34:13 +00001158}
1159
Gilles Peskine8f073122018-11-27 15:58:47 +01001160component_test_no_max_fragment_length () {
1161 # Run max fragment length tests with MFL disabled
1162 msg "build: default config except MFL extension (ASan build)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +01001163 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
1164 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1165 make
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001166
Gilles Peskine8f073122018-11-27 15:58:47 +01001167 msg "test: ssl-opt.sh, MFL-related tests"
1168 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length"
1169}
Angus Grattonc4dd0732018-04-11 16:28:39 +10001170
Hanno Becker92820a12019-02-19 11:10:48 +00001171component_test_asan_remove_peer_certificate () {
1172 msg "build: default config with MBEDTLS_SSL_KEEP_PEER_CERTIFICATE disabled (ASan build)"
1173 scripts/config.pl unset MBEDTLS_SSL_KEEP_PEER_CERTIFICATE
1174 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1175 make
1176
1177 msg "test: !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
1178 make test
1179
1180 msg "test: ssl-opt.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
1181 if_build_succeeded tests/ssl-opt.sh
1182
1183 msg "test: compat.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
1184 if_build_succeeded tests/compat.sh
1185}
1186
Hanno Beckere256f7c2019-06-07 11:14:53 +01001187component_test_asan_remove_peer_certificate_no_renego () {
1188 msg "build: default config with MBEDTLS_SSL_KEEP_PEER_CERTIFICATE and MBEDTLS_SSL_RENEGOTIATION disabled (ASan build)"
1189 scripts/config.pl unset MBEDTLS_SSL_KEEP_PEER_CERTIFICATE
1190 scripts/config.pl unset MBEDTLS_SSL_RENEGOTIATION
1191 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1192 make
1193
1194 msg "test: !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
1195 make test
1196
1197 msg "test: ssl-opt.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE + !MBEDTLS_SSL_RENEGOTIATION"
1198 if_build_succeeded tests/ssl-opt.sh
1199
1200 msg "test: compat.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE + !MBEDTLS_SSL_RENEGOTIATION"
1201 if_build_succeeded tests/compat.sh
1202}
1203
Hanno Beckerbfabd1d2019-02-28 17:31:54 +00001204component_test_asan_on_demand_parsing_remove_peer_cert () {
1205 msg "build: default config, no peer CRT, on-demand CRT parsing (ASan build)"
1206 scripts/config.pl unset MBEDTLS_SSL_KEEP_PEER_CERTIFICATE
1207 scripts/config.pl set MBEDTLS_X509_ON_DEMAND_PARSING
Hanno Becker7dbf49a2019-03-04 16:30:14 +00001208 scripts/config.pl set MBEDTLS_THREADING_C
1209 scripts/config.pl set MBEDTLS_THREADING_PTHREAD
Hanno Becker22cf2552019-05-28 16:45:21 +01001210 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan -D LINK_WITH_PTHREAD=1 .
Hanno Beckerbfabd1d2019-02-28 17:31:54 +00001211 make
1212
1213 msg "test: !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE, MBEDTLS_X509_ON_DEMAND_PARSING"
1214 make test
1215
1216 msg "test: ssl-opt.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE, MBEDTLS_X509_ON_DEMAND_PARSING"
1217 if_build_succeeded tests/ssl-opt.sh
1218}
1219
Gilles Peskine8f073122018-11-27 15:58:47 +01001220component_test_no_max_fragment_length_small_ssl_out_content_len () {
1221 msg "build: no MFL extension, small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +01001222 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
1223 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 16384
1224 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
1225 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1226 make
Angus Grattonc4dd0732018-04-11 16:28:39 +10001227
Gilles Peskine8f073122018-11-27 15:58:47 +01001228 msg "test: MFL tests (disabled MFL extension case) & large packet tests"
1229 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length\|Large buffer"
1230}
Janos Follath06c54002016-06-09 13:57:40 +01001231
Jaeden Amero2eaf2c72019-06-05 13:32:08 +01001232component_test_when_no_ciphersuites_have_mac () {
1233 msg "build: when no ciphersuites have MAC"
1234 scripts/config.pl unset MBEDTLS_CIPHER_NULL_CIPHER
1235 scripts/config.pl unset MBEDTLS_ARC4_C
1236 scripts/config.pl unset MBEDTLS_CIPHER_MODE_CBC
1237 make
1238
1239 msg "test: !MBEDTLS_SSL_SOME_MODES_USE_MAC"
1240 make test
1241
1242 msg "test ssl-opt.sh: !MBEDTLS_SSL_SOME_MODES_USE_MAC"
Jaeden Amerofa8e6da2019-06-05 14:42:50 +01001243 if_build_succeeded tests/ssl-opt.sh -f 'Default\|EtM' -e 'without EtM'
Jaeden Amero2eaf2c72019-06-05 13:32:08 +01001244}
1245
Gilles Peskine8f073122018-11-27 15:58:47 +01001246component_test_null_entropy () {
1247 msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +01001248 scripts/config.pl set MBEDTLS_TEST_NULL_ENTROPY
1249 scripts/config.pl set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
1250 scripts/config.pl set MBEDTLS_ENTROPY_C
1251 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
1252 scripts/config.pl unset MBEDTLS_ENTROPY_HARDWARE_ALT
1253 scripts/config.pl unset MBEDTLS_HAVEGE_C
Gilles Peskine5fa32a72019-01-06 19:48:30 +00001254 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan -D UNSAFE_BUILD=ON .
Gilles Peskine8f073122018-11-27 15:58:47 +01001255 make
Janos Follath06c54002016-06-09 13:57:40 +01001256
Gilles Peskine8f073122018-11-27 15:58:47 +01001257 msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)"
1258 make test
1259}
Hanno Beckere5fecec2018-10-11 11:02:52 +01001260
Gilles Peskine8f073122018-11-27 15:58:47 +01001261component_test_platform_calloc_macro () {
1262 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +01001263 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
1264 scripts/config.pl set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
1265 scripts/config.pl set MBEDTLS_PLATFORM_FREE_MACRO free
1266 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1267 make
Hanno Beckere5fecec2018-10-11 11:02:52 +01001268
Gilles Peskine8f073122018-11-27 15:58:47 +01001269 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
1270 make test
1271}
Hanno Becker83ebf782017-07-07 12:29:15 +01001272
Gilles Peskine8f073122018-11-27 15:58:47 +01001273component_test_aes_fewer_tables () {
1274 msg "build: default config with AES_FEWER_TABLES enabled"
Gilles Peskine8f073122018-11-27 15:58:47 +01001275 scripts/config.pl set MBEDTLS_AES_FEWER_TABLES
1276 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01001277
Gilles Peskine8f073122018-11-27 15:58:47 +01001278 msg "test: AES_FEWER_TABLES"
1279 make test
1280}
Hanno Becker83ebf782017-07-07 12:29:15 +01001281
Gilles Peskine8f073122018-11-27 15:58:47 +01001282component_test_aes_rom_tables () {
1283 msg "build: default config with AES_ROM_TABLES enabled"
Gilles Peskine8f073122018-11-27 15:58:47 +01001284 scripts/config.pl set MBEDTLS_AES_ROM_TABLES
1285 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01001286
Gilles Peskine8f073122018-11-27 15:58:47 +01001287 msg "test: AES_ROM_TABLES"
1288 make test
1289}
Hanno Becker83ebf782017-07-07 12:29:15 +01001290
Arto Kinnunen4ab702b2019-08-30 16:03:15 +03001291component_test_aes_only_128_bit_keys () {
1292 msg "build: default config with AES_ONLY_128_BIT_KEY_LENGTH enabled"
1293 scripts/config.pl set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
1294 scripts/config.pl set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
Arto Kinnunen4c003ca2019-10-21 10:24:05 +03001295 scripts/config.pl unset MBEDTLS_PADLOCK_C
1296
1297 make CC=gcc CFLAGS='-Werror -O1'
Arto Kinnunen4ab702b2019-08-30 16:03:15 +03001298
1299 msg "test: AES_ONLY_128_BIT_KEY_LENGTH"
1300 make test
1301}
1302
Arto Kinnunenc0a8bd42019-10-16 14:23:14 +03001303component_test_aes_only_encrypt () {
1304 msg "build: default config with MBEDTLS_AES_ONLY_ENCRYPT enabled"
1305 scripts/config.pl set MBEDTLS_AES_ONLY_ENCRYPT
Arto Kinnunen0fa65aa2019-10-21 14:43:37 +03001306 make CC=gcc CFLAGS='-Werror -O1'
Arto Kinnunenc0a8bd42019-10-16 14:23:14 +03001307
Arto Kinnunen0fa65aa2019-10-21 14:43:37 +03001308 msg "test: AES_ONLY_ENCRYPT"
Arto Kinnunenc0a8bd42019-10-16 14:23:14 +03001309 make test
1310}
1311
Gilles Peskine8f073122018-11-27 15:58:47 +01001312component_test_aes_fewer_tables_and_rom_tables () {
1313 msg "build: default config with AES_ROM_TABLES and AES_FEWER_TABLES enabled"
Gilles Peskine8f073122018-11-27 15:58:47 +01001314 scripts/config.pl set MBEDTLS_AES_FEWER_TABLES
1315 scripts/config.pl set MBEDTLS_AES_ROM_TABLES
1316 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01001317
Gilles Peskine8f073122018-11-27 15:58:47 +01001318 msg "test: AES_FEWER_TABLES + AES_ROM_TABLES"
1319 make test
1320}
1321
Arto Kinnunen430ac132019-10-14 10:42:28 +03001322component_test_aes_sca_countermeasures () {
1323 msg "build: default config + MBEDTLS_AES_SCA_COUNTERMEASURES + MBEDTLS_ENTROPY_HARDWARE_ALT + !MBEDTLS_AESNI_C"
1324 scripts/config.pl set MBEDTLS_AES_SCA_COUNTERMEASURES
1325 scripts/config.pl set MBEDTLS_ENTROPY_HARDWARE_ALT
1326 scripts/config.pl unset MBEDTLS_AESNI_C
1327
1328 msg "test: AES SCA countermeasures"
1329 make test
1330}
1331
Gilles Peskine8f073122018-11-27 15:58:47 +01001332component_test_make_shared () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001333 msg "build/test: make shared" # ~ 40s
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001334 make SHARED=1 all check
Gilles Peskinedc25c322019-07-03 20:43:32 +02001335 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskine8f073122018-11-27 15:58:47 +01001336}
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +02001337
Gilles Peskine2c47ffc2019-07-03 20:43:05 +02001338component_test_cmake_shared () {
1339 msg "build/test: cmake shared" # ~ 2min
1340 cmake -DUSE_SHARED_MBEDTLS_LIBRARY=On .
1341 make
Gilles Peskinedc25c322019-07-03 20:43:32 +02001342 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskine2c47ffc2019-07-03 20:43:05 +02001343 make test
1344}
1345
Gilles Peskine87bf1b52019-07-03 20:42:16 +02001346component_build_mbedtls_config_file () {
1347 msg "build: make with MBEDTLS_CONFIG_FILE" # ~40s
1348 # Use the full config so as to catch a maximum of places where
1349 # the check of MBEDTLS_CONFIG_FILE might be missing.
1350 scripts/config.pl full
1351 sed 's!"check_config.h"!"mbedtls/check_config.h"!' <"$CONFIG_H" >full_config.h
1352 echo '#error "MBEDTLS_CONFIG_FILE is not working"' >"$CONFIG_H"
1353 make CFLAGS="-I '$PWD' -DMBEDTLS_CONFIG_FILE='\"full_config.h\"'"
1354 rm -f full_config.h
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001355}
1356
Gilles Peskine8f073122018-11-27 15:58:47 +01001357component_test_m32_o0 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001358 # Build once with -O0, to compile out the i386 specific inline assembly
1359 msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
Simon Butcher7a6da6e2018-06-27 21:52:54 +01001360 scripts/config.pl full
Manuel Pégourié-Gonnardde8869c2019-07-03 10:31:46 +02001361 make CC=gcc PTHREAD=1 CFLAGS='-O0 -Werror -Wall -Wextra -m32 -fsanitize=address' LDFLAGS='-m32'
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01001362
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001363 msg "test: i386, make, gcc -O0 (ASan build)"
1364 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01001365}
Gilles Peskine878cf602019-01-06 20:50:38 +00001366support_test_m32_o0 () {
1367 case $(uname -m) in
1368 *64*) true;;
1369 *) false;;
1370 esac
1371}
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001372
Gilles Peskine8f073122018-11-27 15:58:47 +01001373component_test_m32_o1 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001374 # Build again with -O1, to compile in the i386 specific inline assembly
1375 msg "build: i386, make, gcc -O1 (ASan build)" # ~ 30s
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001376 scripts/config.pl full
Manuel Pégourié-Gonnardde8869c2019-07-03 10:31:46 +02001377 make CC=gcc PTHREAD=1 CFLAGS='-O1 -Werror -Wall -Wextra -m32 -fsanitize=address' LDFLAGS='-m32'
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001378
1379 msg "test: i386, make, gcc -O1 (ASan build)"
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001380 make test
Gilles Peskine7dd44b22019-04-08 16:58:02 +02001381
1382 msg "test ssl-opt.sh, i386, make, gcc-O1"
1383 if_build_succeeded tests/ssl-opt.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01001384}
Gilles Peskine878cf602019-01-06 20:50:38 +00001385support_test_m32_o1 () {
1386 support_test_m32_o0 "$@"
1387}
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001388
Gilles Peskine8f073122018-11-27 15:58:47 +01001389component_test_mx32 () {
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001390 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
Simon Butcher7a6da6e2018-06-27 21:52:54 +01001391 scripts/config.pl full
Manuel Pégourié-Gonnardde8869c2019-07-03 10:31:46 +02001392 make CC=gcc PTHREAD=1 CFLAGS='-Werror -Wall -Wextra -mx32' LDFLAGS='-mx32'
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001393
1394 msg "test: 64-bit ILP32, make, gcc"
1395 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01001396}
Gilles Peskine878cf602019-01-06 20:50:38 +00001397support_test_mx32 () {
1398 case $(uname -m) in
1399 amd64|x86_64) true;;
1400 *) false;;
1401 esac
1402}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001403
Peter Kolbus1e2aa722018-12-27 06:59:04 -06001404component_test_min_mpi_window_size () {
1405 msg "build: Default + MBEDTLS_MPI_WINDOW_SIZE=1 (ASan build)" # ~ 10s
1406 scripts/config.pl set MBEDTLS_MPI_WINDOW_SIZE 1
1407 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1408 make
1409
1410 msg "test: MBEDTLS_MPI_WINDOW_SIZE=1 - main suites (inc. selftests) (ASan build)" # ~ 10s
1411 make test
1412}
1413
Gilles Peskine8f073122018-11-27 15:58:47 +01001414component_test_have_int32 () {
1415 msg "build: gcc, force 32-bit bignum limbs"
Gilles Peskine8f073122018-11-27 15:58:47 +01001416 scripts/config.pl unset MBEDTLS_HAVE_ASM
1417 scripts/config.pl unset MBEDTLS_AESNI_C
1418 scripts/config.pl unset MBEDTLS_PADLOCK_C
1419 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01001420
Gilles Peskine8f073122018-11-27 15:58:47 +01001421 msg "test: gcc, force 32-bit bignum limbs"
1422 make test
1423}
Andres Amaya Garciafe843a32017-07-20 13:21:34 +01001424
Gilles Peskine8f073122018-11-27 15:58:47 +01001425component_test_have_int64 () {
1426 msg "build: gcc, force 64-bit bignum limbs"
Gilles Peskine8f073122018-11-27 15:58:47 +01001427 scripts/config.pl unset MBEDTLS_HAVE_ASM
1428 scripts/config.pl unset MBEDTLS_AESNI_C
1429 scripts/config.pl unset MBEDTLS_PADLOCK_C
1430 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
Gilles Peskine14c3c062018-01-29 21:25:12 +01001431
Gilles Peskine8f073122018-11-27 15:58:47 +01001432 msg "test: gcc, force 64-bit bignum limbs"
1433 make test
1434}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001435
Gilles Peskine8f073122018-11-27 15:58:47 +01001436component_test_no_udbl_division () {
1437 msg "build: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +01001438 scripts/config.pl full
Gilles Peskine8f073122018-11-27 15:58:47 +01001439 scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
1440 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001441
Gilles Peskine8f073122018-11-27 15:58:47 +01001442 msg "test: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
1443 make test
1444}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001445
Gilles Peskine8f073122018-11-27 15:58:47 +01001446component_test_no_64bit_multiplication () {
1447 msg "build: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +01001448 scripts/config.pl full
Gilles Peskine8f073122018-11-27 15:58:47 +01001449 scripts/config.pl set MBEDTLS_NO_64BIT_MULTIPLICATION
1450 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001451
Gilles Peskine8f073122018-11-27 15:58:47 +01001452 msg "test: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
1453 make test
1454}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001455
Peter Kolbusb1cb0bd2019-01-29 17:42:02 -06001456component_test_no_x509_info () {
1457 msg "build: full + MBEDTLS_X509_REMOVE_INFO" # ~ 10s
1458 scripts/config.pl full
1459 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
1460 scripts/config.pl set MBEDTLS_X509_REMOVE_INFO
1461 make CFLAGS='-Werror -O1'
1462
1463 msg "test: full + MBEDTLS_X509_REMOVE_INFO" # ~ 10s
1464 make test
1465
1466 msg "test: ssl-opt.sh, full + MBEDTLS_X509_REMOVE_INFO" # ~ 1 min
1467 if_build_succeeded tests/ssl-opt.sh
1468}
1469
Teppo Järvelin4009d8f2019-08-19 14:48:09 +03001470component_test_no_hostname_verification () {
1471 msg "build: full + MBEDTLS_X509_REMOVE_HOSTNAME_VERIFICATION" # ~ 10s
1472 scripts/config.pl full
1473 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
1474 scripts/config.pl set MBEDTLS_X509_REMOVE_HOSTNAME_VERIFICATION
1475 make CFLAGS='-Werror -O1'
1476
1477 msg "test: full + MBEDTLS_X509_REMOVE_HOSTNAME_VERIFICATION" # ~ 10s
1478 make test
1479
1480 msg "test: ssl-opt.sh, full + MBEDTLS_X509_REMOVE_HOSTNAME_VERIFICATION" # ~ 1 min
1481 if_build_succeeded tests/ssl-opt.sh
1482}
1483
Hanno Becker9ec3fe02019-07-01 17:36:12 +01001484component_test_no_x509_verify_callback () {
1485 msg "build: full + MBEDTLS_X509_REMOVE_VERIFY_CALLBACK" # ~ 10s
1486 scripts/config.pl full
1487 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
1488 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
1489 scripts/config.pl set MBEDTLS_X509_REMOVE_VERIFY_CALLBACK
1490 make CFLAGS='-Werror -O1'
1491
1492 msg "test: full + MBEDTLS_X509_REMOVE_VERIFY_CALLBACK" # ~ 10s
1493 make test
1494
1495 msg "test: ssl-opt.sh, full + MBEDTLS_X509_REMOVE_VERIFY_CALLBACK" # ~ 1 min
1496 if_build_succeeded tests/ssl-opt.sh
1497}
1498
Gilles Peskine8f073122018-11-27 15:58:47 +01001499component_build_arm_none_eabi_gcc () {
1500 msg "build: arm-none-eabi-gcc, make" # ~ 10s
Manuel Pégourié-Gonnard6e6ae9b2019-04-29 12:44:12 +02001501 scripts/config.pl baremetal
Gilles Peskine8f073122018-11-27 15:58:47 +01001502 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
1503}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001504
Gilles Peskine560f3322019-08-09 16:05:05 +02001505component_build_arm_none_eabi_gcc_arm5vte () {
Gilles Peskinee07b9ff2019-08-08 16:09:02 +02001506 msg "build: arm-none-eabi-gcc -march=arm5vte, make" # ~ 10s
Gilles Peskine0bd284d2019-08-05 11:34:25 +02001507 scripts/config.pl baremetal
Gilles Peskine560f3322019-08-09 16:05:05 +02001508 # Build for a target platform that's close to what Debian uses
1509 # for its "armel" distribution (https://wiki.debian.org/ArmEabiPort).
1510 # See https://github.com/ARMmbed/mbedtls/pull/2169 and comments.
1511 # It would be better to build with arm-linux-gnueabi-gcc but
1512 # we don't have that on our CI at this time.
Gilles Peskinee07b9ff2019-08-08 16:09:02 +02001513 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar CFLAGS='-Werror -Wall -Wextra -march=armv5te -O1' LDFLAGS='-march=armv5te' SHELL='sh -x' lib
Gilles Peskine0bd284d2019-08-05 11:34:25 +02001514}
1515
Gilles Peskine8f073122018-11-27 15:58:47 +01001516component_build_arm_none_eabi_gcc_no_udbl_division () {
1517 msg "build: arm-none-eabi-gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
Manuel Pégourié-Gonnard6e6ae9b2019-04-29 12:44:12 +02001518 scripts/config.pl baremetal
Gilles Peskine8f073122018-11-27 15:58:47 +01001519 scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
1520 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
1521 echo "Checking that software 64-bit division is not required"
1522 if_build_succeeded not grep __aeabi_uldiv library/*.o
1523}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001524
Gilles Peskine8f073122018-11-27 15:58:47 +01001525component_build_arm_none_eabi_gcc_no_64bit_multiplication () {
1526 msg "build: arm-none-eabi-gcc MBEDTLS_NO_64BIT_MULTIPLICATION, make" # ~ 10s
Manuel Pégourié-Gonnard6e6ae9b2019-04-29 12:44:12 +02001527 scripts/config.pl baremetal
Gilles Peskine8f073122018-11-27 15:58:47 +01001528 scripts/config.pl set MBEDTLS_NO_64BIT_MULTIPLICATION
Simon Butcher96998872019-11-22 15:09:39 +00001529 make TINYCRYPT_BUILD=0 CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -O1 -march=armv6-m -mthumb' lib
Gilles Peskine8f073122018-11-27 15:58:47 +01001530 echo "Checking that software 64-bit multiplication is not required"
1531 if_build_succeeded not grep __aeabi_lmul library/*.o
1532}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001533
Gilles Peskine8f073122018-11-27 15:58:47 +01001534component_build_armcc () {
1535 msg "build: ARM Compiler 5, make"
Manuel Pégourié-Gonnard6e6ae9b2019-04-29 12:44:12 +02001536 scripts/config.pl baremetal
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001537
Gilles Peskine5331c6e2019-01-06 22:23:42 +00001538 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
1539 make clean
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001540
Gilles Peskine5331c6e2019-01-06 22:23:42 +00001541 # ARM Compiler 6 - Target ARMv7-A
1542 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-a"
Gilles Peskineed942f82017-06-08 15:19:20 +02001543
Gilles Peskine5331c6e2019-01-06 22:23:42 +00001544 # ARM Compiler 6 - Target ARMv7-M
1545 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m"
Andres AG87bb5772016-09-27 15:05:15 +01001546
Gilles Peskine5331c6e2019-01-06 22:23:42 +00001547 # ARM Compiler 6 - Target ARMv8-A - AArch32
1548 armc6_build_test "--target=arm-arm-none-eabi -march=armv8.2-a"
Andres AG87bb5772016-09-27 15:05:15 +01001549
Gilles Peskine5331c6e2019-01-06 22:23:42 +00001550 # ARM Compiler 6 - Target ARMv8-M
1551 armc6_build_test "--target=arm-arm-none-eabi -march=armv8-m.main"
Simon Butcher940737f2017-07-23 13:42:36 +02001552
Gilles Peskine5331c6e2019-01-06 22:23:42 +00001553 # ARM Compiler 6 - Target ARMv8-A - AArch64
1554 armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a"
Gilles Peskine8f073122018-11-27 15:58:47 +01001555}
Simon Butcher940737f2017-07-23 13:42:36 +02001556
Manuel Pégourié-Gonnard31ae7fa2019-06-18 12:03:51 +02001557# need _armcc in the name for pre_check_tools()
Hanno Becker62daad32019-07-25 12:41:40 +01001558component_build_baremetal_raw_armcc () {
Manuel Pégourié-Gonnard31ae7fa2019-06-18 12:03:51 +02001559 msg "build: scripts/baremetal.sh gcc/armc5/armc6"
1560 scripts/baremetal.sh --rom --gcc --armc5 --armc6 --check
1561}
1562
Hanno Beckerb1074972019-09-02 12:27:03 +01001563component_test_default_tinycrypt_without_legacy_ecc () {
1564 msg "test default config with tinycrypt enabled and legacy ECC disabled"
Jarno Lamsa7ba62882019-08-02 11:45:44 +03001565
1566 scripts/config.pl set MBEDTLS_USE_TINYCRYPT
1567 scripts/config.pl set MBEDTLS_SSL_CONF_RNG rng_wrap
1568 scripts/config.pl set MBEDTLS_SSL_CONF_SINGLE_EC
1569 scripts/config.pl set MBEDTLS_SSL_CONF_SINGLE_EC_TLS_ID 23
Hanno Becker49ac40b2019-08-29 16:25:49 +01001570 scripts/config.pl set MBEDTLS_SSL_CONF_SINGLE_UECC_GRP_ID MBEDTLS_UECC_DP_SECP256R1
Hanno Beckerb1074972019-09-02 12:27:03 +01001571 scripts/config.pl unset MBEDTLS_ECP_C
Jarno Lamsa7ba62882019-08-02 11:45:44 +03001572 scripts/config.pl unset MBEDTLS_ECDH_C
Hanno Beckerb1074972019-09-02 12:27:03 +01001573 scripts/config.pl unset MBEDTLS_ECDSA_C
Jarno Lamsa7ba62882019-08-02 11:45:44 +03001574 scripts/config.pl unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
1575 scripts/config.pl unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
1576 scripts/config.pl unset MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
Hanno Becker325eb332019-09-02 13:47:19 +01001577 scripts/config.pl unset MBEDTLS_ECP_DP_SECP192R1_ENABLED
1578 scripts/config.pl unset MBEDTLS_ECP_DP_SECP224R1_ENABLED
1579 scripts/config.pl unset MBEDTLS_ECP_DP_SECP256R1_ENABLED
1580 scripts/config.pl unset MBEDTLS_ECP_DP_SECP384R1_ENABLED
1581 scripts/config.pl unset MBEDTLS_ECP_DP_SECP521R1_ENABLED
1582 scripts/config.pl unset MBEDTLS_ECP_DP_BP256R1_ENABLED
1583 scripts/config.pl unset MBEDTLS_ECP_DP_BP384R1_ENABLED
1584 scripts/config.pl unset MBEDTLS_ECP_DP_BP512R1_ENABLED
1585 scripts/config.pl unset MBEDTLS_ECP_DP_SECP192K1_ENABLED
1586 scripts/config.pl unset MBEDTLS_ECP_DP_SECP224K1_ENABLED
1587 scripts/config.pl unset MBEDTLS_ECP_DP_SECP256K1_ENABLED
Jarno Lamsa7ba62882019-08-02 11:45:44 +03001588 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
1589
Hanno Beckerb1074972019-09-02 12:27:03 +01001590 msg "test: default config with tinycrypt enabled and legacy ECC disabled"
Jarno Lamsa7ba62882019-08-02 11:45:44 +03001591 make test
Hanno Becker8b3408f2019-09-02 14:35:23 +01001592 if_build_succeeded tests/ssl-opt.sh
Hanno Becker7c2cd3e2019-09-02 09:15:23 +01001593
1594 export SRV_ECDSA_CRT=data_files/server11.crt.pem
1595 export SRV_ECDSA_KEY=data_files/server11.key.pem
1596 export CLI_ECDSA_CRT=data_files/cli3.crt.pem
1597 export CLI_ECDSA_KEY=data_files/cli3.key.pem
1598 export CA_FILE=data_files/test-ca3.crt.pem
Hanno Beckerfe088442019-09-02 13:07:20 +01001599 if_build_succeeded tests/compat.sh -f 'ECDHE-ECDSA\|ECDHE-PSK\|ECDH-ECDSA'
Jarno Lamsa7ba62882019-08-02 11:45:44 +03001600}
1601
Manuel Pégourié-Gonnard1c1cc0d2019-09-19 10:45:14 +02001602component_test_hardcoded_pk_type () {
1603 msg "build: default config + single PK type harcoded (tinycrypt)"
1604 # need to enable tinycrypt first - copied from tinycrypt component
1605 scripts/config.pl set MBEDTLS_USE_TINYCRYPT
1606 scripts/config.pl set MBEDTLS_SSL_CONF_RNG rng_wrap
1607 scripts/config.pl set MBEDTLS_SSL_CONF_SINGLE_EC
1608 scripts/config.pl set MBEDTLS_SSL_CONF_SINGLE_EC_TLS_ID 23
1609 scripts/config.pl set MBEDTLS_SSL_CONF_SINGLE_UECC_GRP_ID MBEDTLS_UECC_DP_SECP256R1
1610 scripts/config.pl unset MBEDTLS_ECP_C
1611 scripts/config.pl unset MBEDTLS_ECDH_C
1612 scripts/config.pl unset MBEDTLS_ECDSA_C
1613 scripts/config.pl unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
1614 scripts/config.pl unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
1615 scripts/config.pl unset MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
1616 scripts/config.pl unset MBEDTLS_ECP_DP_SECP192R1_ENABLED
1617 scripts/config.pl unset MBEDTLS_ECP_DP_SECP224R1_ENABLED
1618 scripts/config.pl unset MBEDTLS_ECP_DP_SECP256R1_ENABLED
1619 scripts/config.pl unset MBEDTLS_ECP_DP_SECP384R1_ENABLED
1620 scripts/config.pl unset MBEDTLS_ECP_DP_SECP521R1_ENABLED
1621 scripts/config.pl unset MBEDTLS_ECP_DP_BP256R1_ENABLED
1622 scripts/config.pl unset MBEDTLS_ECP_DP_BP384R1_ENABLED
1623 scripts/config.pl unset MBEDTLS_ECP_DP_BP512R1_ENABLED
1624 scripts/config.pl unset MBEDTLS_ECP_DP_SECP192K1_ENABLED
1625 scripts/config.pl unset MBEDTLS_ECP_DP_SECP224K1_ENABLED
1626 scripts/config.pl unset MBEDTLS_ECP_DP_SECP256K1_ENABLED
1627 # now single-PK specific configs
1628 scripts/config.pl set MBEDTLS_PK_SINGLE_TYPE MBEDTLS_PK_INFO_ECKEY
1629 scripts/config.pl unset MBEDTLS_PK_RSA_ALT_SUPPORT
1630 scripts/config.pl unset MBEDTLS_RSA_C
1631 scripts/config.pl unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
1632 scripts/config.pl unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
1633 scripts/config.pl unset MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
1634 scripts/config.pl unset MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
1635 scripts/config.pl unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
1636 make CFLAGS='-Werror -O1'
1637
1638 msg "test: default config + single PK type harcoded (tinycrypt)"
1639 make test
1640 if_build_succeeded tests/ssl-opt.sh -f '^Default, DTLS$'
1641}
1642
Hanno Becker62daad32019-07-25 12:41:40 +01001643component_test_baremetal () {
Hanno Beckere7895aa2019-07-22 12:47:20 +01001644 msg "build: lib+test+programs for baremetal.h + baremetal_test.h"
1645 record_status scripts/baremetal.sh --ram --build-only
1646
1647 msg "test: baremetal.h + baremetal_test.h"
1648 if_build_succeeded make test
Jarno Lamsa08d6cf22019-10-18 11:49:52 +03001649 if_build_succeeded tests/ssl-opt.sh
Hanno Beckere7895aa2019-07-22 12:47:20 +01001650}
1651
Jarno Lamsa990135e2019-10-04 13:09:10 +03001652component_test_hardware_entropy () {
1653 msg "build: default config + MBEDTLS_ENTROPY_HARDWARE_ALT"
1654 scripts/config.pl set MBEDTLS_ENTROPY_HARDWARE_ALT
Manuel Pégourié-Gonnard66491e12019-10-22 12:50:13 +02001655 make CFLAGS='-Werror -O1' lib tests
1656 make CFLAGS='-Werror -O1' -C programs ssl/ssl_server2 ssl/ssl_client2 test/udp_proxy
Jarno Lamsa990135e2019-10-04 13:09:10 +03001657
1658 msg "test: default config + MBEDTLS_ENTROPY_HARDWARE_ALT"
1659 if_build_succeeded make test
1660 if_build_succeeded tests/ssl-opt.sh --filter "^Default, DTLS$"
1661}
1662
Gilles Peskine8f073122018-11-27 15:58:47 +01001663component_test_allow_sha1 () {
1664 msg "build: allow SHA1 in certificates by default"
Gilles Peskine8f073122018-11-27 15:58:47 +01001665 scripts/config.pl set MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
1666 make CFLAGS='-Werror -Wall -Wextra'
1667 msg "test: allow SHA1 in certificates by default"
1668 make test
1669 if_build_succeeded tests/ssl-opt.sh -f SHA-1
1670}
Simon Butcher940737f2017-07-23 13:42:36 +02001671
Gilles Peskine8f073122018-11-27 15:58:47 +01001672component_build_mingw () {
1673 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +01001674 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 +02001675
Gilles Peskine8f073122018-11-27 15:58:47 +01001676 # note Make tests only builds the tests, but doesn't run them
1677 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror' WINDOWS_BUILD=1 tests
1678 make WINDOWS_BUILD=1 clean
Hanno Beckere963efa2018-01-03 10:03:43 +00001679
Gilles Peskine8f073122018-11-27 15:58:47 +01001680 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
1681 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
1682 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
1683 make WINDOWS_BUILD=1 clean
1684}
Simon Butcher002bc622016-11-17 09:27:45 +00001685
Gilles Peskine8f073122018-11-27 15:58:47 +01001686component_test_memsan () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001687 msg "build: MSan (clang)" # ~ 1 min 20s
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001688 scripts/config.pl unset MBEDTLS_AESNI_C # memsan doesn't grok asm
1689 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
1690 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +02001691
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001692 msg "test: main suites (MSan)" # ~ 10s
1693 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001694
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001695 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
Gilles Peskine7c652162017-12-11 00:01:40 +01001696 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001697
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001698 # Optional part(s)
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001699
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001700 if [ "$MEMORY" -gt 0 ]; then
1701 msg "test: compat.sh (MSan)" # ~ 6 min 20s
Gilles Peskine7c652162017-12-11 00:01:40 +01001702 if_build_succeeded tests/compat.sh
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001703 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001704}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001705
Gilles Peskine69f190e2019-01-10 00:11:42 +01001706component_test_valgrind () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001707 msg "build: Release (clang)"
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001708 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
1709 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001710
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001711 msg "test: main suites valgrind (Release)"
1712 make memcheck
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001713
Gilles Peskine0a47c4f2019-04-08 17:00:56 +02001714 # Optional parts (slow; currently broken on OS X because programs don't
1715 # seem to receive signals under valgrind on OS X).
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001716 if [ "$MEMORY" -gt 0 ]; then
1717 msg "test: ssl-opt.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +01001718 if_build_succeeded tests/ssl-opt.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001719 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001720
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001721 if [ "$MEMORY" -gt 1 ]; then
1722 msg "test: compat.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +01001723 if_build_succeeded tests/compat.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001724 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001725}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001726
Gilles Peskine8f073122018-11-27 15:58:47 +01001727component_test_cmake_out_of_source () {
1728 msg "build: cmake 'out-of-source' build"
Gilles Peskine8f073122018-11-27 15:58:47 +01001729 MBEDTLS_ROOT_DIR="$PWD"
1730 mkdir "$OUT_OF_SOURCE_DIR"
1731 cd "$OUT_OF_SOURCE_DIR"
1732 cmake "$MBEDTLS_ROOT_DIR"
1733 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001734
Gilles Peskine8f073122018-11-27 15:58:47 +01001735 msg "test: cmake 'out-of-source' build"
1736 make test
1737 # Test an SSL option that requires an auxiliary script in test/scripts/.
1738 # Also ensure that there are no error messages such as
1739 # "No such file or directory", which would indicate that some required
1740 # file is missing (ssl-opt.sh tolerates the absence of some files so
1741 # may exit with status 0 but emit errors).
1742 if_build_succeeded ./tests/ssl-opt.sh -f 'Fallback SCSV: beginning of list' 2>ssl-opt.err
1743 if [ -s ssl-opt.err ]; then
1744 cat ssl-opt.err >&2
1745 record_status [ ! -s ssl-opt.err ]
1746 rm ssl-opt.err
1747 fi
1748 cd "$MBEDTLS_ROOT_DIR"
1749 rm -rf "$OUT_OF_SOURCE_DIR"
1750 unset MBEDTLS_ROOT_DIR
1751}
Andres AGdc192212016-08-31 17:33:13 +01001752
Gilles Peskine8f073122018-11-27 15:58:47 +01001753component_test_zeroize () {
1754 # Test that the function mbedtls_platform_zeroize() is not optimized away by
1755 # different combinations of compilers and optimization flags by using an
1756 # auxiliary GDB script. Unfortunately, GDB does not return error values to the
1757 # system in all cases that the script fails, so we must manually search the
1758 # output to check whether the pass string is present and no failure strings
1759 # were printed.
Gilles Peskine4976e822019-01-06 19:52:22 +00001760
1761 # Don't try to disable ASLR. We don't care about ASLR here. We do care
1762 # about a spurious message if Gdb tries and fails, so suppress that.
1763 gdb_disable_aslr=
1764 if [ -z "$(gdb -batch -nw -ex 'set disable-randomization off' 2>&1)" ]; then
1765 gdb_disable_aslr='set disable-randomization off'
1766 fi
1767
Gilles Peskine8f073122018-11-27 15:58:47 +01001768 for optimization_flag in -O2 -O3 -Ofast -Os; do
Gilles Peskine55f7c942019-01-09 22:28:21 +01001769 for compiler in clang gcc; do
1770 msg "test: $compiler $optimization_flag, mbedtls_platform_zeroize()"
1771 make programs CC="$compiler" DEBUG=1 CFLAGS="$optimization_flag"
Gilles Peskine4976e822019-01-06 19:52:22 +00001772 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 +01001773 if_build_succeeded grep "The buffer was correctly zeroized" test_zeroize.log
1774 if_build_succeeded not grep -i "error" test_zeroize.log
1775 rm -f test_zeroize.log
1776 make clean
1777 done
Andres Amaya Garcia29673812017-10-25 10:35:51 +01001778 done
Gilles Peskine4976e822019-01-06 19:52:22 +00001779
1780 unset gdb_disable_aslr
Gilles Peskine8f073122018-11-27 15:58:47 +01001781}
Andres Amaya Garciad0d7bf62017-10-25 09:01:31 +01001782
Gilles Peskine7b9fcdc2019-02-25 20:26:06 +01001783support_check_python_files () {
1784 type pylint3 >/dev/null 2>/dev/null
1785}
Gilles Peskine8f073122018-11-27 15:58:47 +01001786component_check_python_files () {
1787 msg "Lint: Python scripts"
1788 record_status tests/scripts/check-python-files.sh
1789}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001790
Gilles Peskine8f073122018-11-27 15:58:47 +01001791component_check_generate_test_code () {
1792 msg "uint test: generate_test_code.py"
1793 record_status ./tests/scripts/test_generate_test_code.py
1794}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001795
1796################################################################
1797#### Termination
1798################################################################
1799
Gilles Peskine8f073122018-11-27 15:58:47 +01001800post_report () {
1801 msg "Done, cleaning up"
1802 cleanup
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001803
Gilles Peskine8f073122018-11-27 15:58:47 +01001804 final_report
1805}
1806
1807
1808
1809################################################################
1810#### Run all the things
1811################################################################
1812
Gilles Peskinee48351a2018-11-27 16:06:30 +01001813# Run one component and clean up afterwards.
Gilles Peskine8f073122018-11-27 15:58:47 +01001814run_component () {
Gilles Peskine608953e2019-01-02 18:57:02 +01001815 # Back up the configuration in case the component modifies it.
1816 # The cleanup function will restore it.
1817 cp -p "$CONFIG_H" "$CONFIG_BAK"
Gilles Peskineffcdeff2018-12-04 12:49:28 +01001818 current_component="$1"
Gilles Peskine8f073122018-11-27 15:58:47 +01001819 "$@"
Gilles Peskinee48351a2018-11-27 16:06:30 +01001820 cleanup
Gilles Peskine8f073122018-11-27 15:58:47 +01001821}
1822
1823# Preliminary setup
1824pre_check_environment
1825pre_initialize_variables
1826pre_parse_command_line "$@"
Gilles Peskine348fb9a2018-11-27 17:04:29 +01001827
Gilles Peskine878cf602019-01-06 20:50:38 +00001828pre_check_git
1829build_status=0
1830if [ $KEEP_GOING -eq 1 ]; then
1831 pre_setup_keep_going
1832else
1833 record_status () {
1834 "$@"
1835 }
1836fi
1837pre_print_configuration
1838pre_check_tools
Gilles Peskine878cf602019-01-06 20:50:38 +00001839cleanup
Gilles Peskine8f073122018-11-27 15:58:47 +01001840
Gilles Peskinebeb3a812019-01-06 22:11:25 +00001841# Run the requested tests.
1842for component in $RUN_COMPONENTS; do
1843 run_component "component_$component"
1844done
Gilles Peskine8f073122018-11-27 15:58:47 +01001845
1846# We're done.
Gilles Peskine878cf602019-01-06 20:50:38 +00001847post_report