blob: 22c81296c8f2336c817c569f02b602502ff42260 [file] [log] [blame]
Andres AG31f9b5b2016-10-04 17:14:38 +01001#! /usr/bin/env sh
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01002
Simon Butcher3ea7f522016-03-07 23:22:10 +00003# all.sh
4#
SimonB2e23c822016-04-16 21:54:39 +01005# This file is part of mbed TLS (https://tls.mbed.org)
6#
Gilles Peskine192c72f2017-12-21 15:59:21 +01007# Copyright (c) 2014-2017, ARM Limited, All Rights Reserved
8
9
10
11################################################################
12#### Documentation
13################################################################
14
Simon Butcher3ea7f522016-03-07 23:22:10 +000015# Purpose
Gilles Peskine192c72f2017-12-21 15:59:21 +010016# -------
Simon Butcher3ea7f522016-03-07 23:22:10 +000017#
SimonB2e23c822016-04-16 21:54:39 +010018# To run all tests possible or available on the platform.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010019#
Gilles Peskine192c72f2017-12-21 15:59:21 +010020# Notes for users
21# ---------------
22#
SimonB2e23c822016-04-16 21:54:39 +010023# Warning: the test is destructive. It includes various build modes and
24# configurations, and can and will arbitrarily change the current CMake
Gilles Peskine192c72f2017-12-21 15:59:21 +010025# configuration. The following files must be committed into git:
26# * include/mbedtls/config.h
Philippe Antoine1c582c32019-06-25 21:55:21 +020027# * Makefile, library/Makefile, programs/Makefile, tests/Makefile,
Philippe Antoine5dece6d2019-06-27 16:55:07 +020028# programs/fuzz/Makefile
Gilles Peskine192c72f2017-12-21 15:59:21 +010029# After running this script, the CMake cache will be lost and CMake
30# will no longer be initialised.
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +010031#
Gilles Peskine192c72f2017-12-21 15:59:21 +010032# The script assumes the presence of a number of tools:
33# * Basic Unix tools (Windows users note: a Unix-style find must be before
34# the Windows find in the PATH)
35# * Perl
36# * GNU Make
37# * CMake
38# * GCC and Clang (recent enough for using ASan with gcc and MemSan with clang, or valgrind)
Andrzej Kurek05be06c2018-06-28 04:41:50 -040039# * G++
Gilles Peskine192c72f2017-12-21 15:59:21 +010040# * arm-gcc and mingw-gcc
41# * ArmCC 5 and ArmCC 6, unless invoked with --no-armcc
Gilles Peskine192c72f2017-12-21 15:59:21 +010042# * OpenSSL and GnuTLS command line tools, recent enough for the
43# interoperability tests. If they don't support SSLv3 then a legacy
44# version of these tools must be present as well (search for LEGACY
45# below).
46# See the invocation of check_tools below for details.
47#
48# This script must be invoked from the toplevel directory of a git
49# working copy of Mbed TLS.
50#
51# Note that the output is not saved. You may want to run
52# script -c tests/scripts/all.sh
53# or
54# tests/scripts/all.sh >all.log 2>&1
55#
56# Notes for maintainers
57# ---------------------
58#
Gilles Peskine8f073122018-11-27 15:58:47 +010059# The bulk of the code is organized into functions that follow one of the
60# following naming conventions:
61# * pre_XXX: things to do before running the tests, in order.
62# * component_XXX: independent components. They can be run in any order.
Gilles Peskinec70637a2019-01-09 22:29:17 +010063# * component_check_XXX: quick tests that aren't worth parallelizing.
64# * component_build_XXX: build things but don't run them.
65# * component_test_XXX: build and test.
Gilles Peskine878cf602019-01-06 20:50:38 +000066# * support_XXX: if support_XXX exists and returns false then
67# component_XXX is not run by default.
Gilles Peskine8f073122018-11-27 15:58:47 +010068# * post_XXX: things to do after running the tests.
69# * other: miscellaneous support functions.
70#
Gilles Peskinec70637a2019-01-09 22:29:17 +010071# Each component must start by invoking `msg` with a short informative message.
72#
73# The framework performs some cleanup tasks after each component. This
74# means that components can assume that the working directory is in a
75# cleaned-up state, and don't need to perform the cleanup themselves.
76# * Run `make clean`.
77# * Restore `include/mbedtks/config.h` from a backup made before running
78# the component.
Philippe Antoine1c582c32019-06-25 21:55:21 +020079# * Check out `Makefile`, `library/Makefile`, `programs/Makefile`,
Philippe Antoine5dece6d2019-06-27 16:55:07 +020080# `tests/Makefile` and `programs/fuzz/Makefile` from git.
Philippe Antoine1c582c32019-06-25 21:55:21 +020081# This cleans up after an in-tree use of CMake.
Gilles Peskinec70637a2019-01-09 22:29:17 +010082#
83# Any command that is expected to fail must be protected so that the
84# script keeps running in --keep-going mode despite `set -e`. In keep-going
85# mode, if a protected command fails, this is logged as a failure and the
86# script will exit with a failure status once it has run all components.
87# Commands can be protected in any of the following ways:
88# * `make` is a function which runs the `make` command with protection.
89# Note that you must write `make VAR=value`, not `VAR=value make`,
90# because the `VAR=value make` syntax doesn't work with functions.
91# * Put `report_status` before the command to protect it.
92# * Put `if_build_successful` before a command. This protects it, and
93# additionally skips it if a prior invocation of `make` in the same
94# component failed.
95#
Gilles Peskine192c72f2017-12-21 15:59:21 +010096# The tests are roughly in order from fastest to slowest. This doesn't
97# have to be exact, but in general you should add slower tests towards
98# the end and fast checks near the beginning.
Gilles Peskine192c72f2017-12-21 15:59:21 +010099
100
101
102################################################################
103#### Initialization and command line parsing
104################################################################
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100105
SimonB2e23c822016-04-16 21:54:39 +0100106# Abort on errors (and uninitialised variables)
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100107set -eu
108
Gilles Peskine8f073122018-11-27 15:58:47 +0100109pre_check_environment () {
Gilles Peskinea16c2b12019-01-06 19:58:02 +0000110 if [ -d library -a -d include -a -d tests ]; then :; else
Gilles Peskine8f073122018-11-27 15:58:47 +0100111 echo "Must be run from mbed TLS root" >&2
112 exit 1
113 fi
114}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100115
Gilles Peskine8f073122018-11-27 15:58:47 +0100116pre_initialize_variables () {
117 CONFIG_H='include/mbedtls/config.h'
118 CONFIG_BAK="$CONFIG_H.bak"
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200119
Gilles Peskine8f073122018-11-27 15:58:47 +0100120 MEMORY=0
121 FORCE=0
Gilles Peskine8f073122018-11-27 15:58:47 +0100122 KEEP_GOING=0
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100123
Jaeden Ameroc4cc2512019-01-30 15:35:44 +0000124 # Default commands, can be overridden by the environment
Gilles Peskine8f073122018-11-27 15:58:47 +0100125 : ${OPENSSL:="openssl"}
126 : ${OPENSSL_LEGACY:="$OPENSSL"}
127 : ${OPENSSL_NEXT:="$OPENSSL"}
128 : ${GNUTLS_CLI:="gnutls-cli"}
129 : ${GNUTLS_SERV:="gnutls-serv"}
130 : ${GNUTLS_LEGACY_CLI:="$GNUTLS_CLI"}
131 : ${GNUTLS_LEGACY_SERV:="$GNUTLS_SERV"}
132 : ${OUT_OF_SOURCE_DIR:=./mbedtls_out_of_source_build}
133 : ${ARMC5_BIN_DIR:=/usr/bin}
134 : ${ARMC6_BIN_DIR:=/usr/bin}
Andres AGdc192212016-08-31 17:33:13 +0100135
Gilles Peskine8f073122018-11-27 15:58:47 +0100136 # if MAKEFLAGS is not set add the -j option to speed up invocations of make
Gilles Peskinea1fc4b52019-01-06 20:15:26 +0000137 if [ -z "${MAKEFLAGS+set}" ]; then
Gilles Peskine8f073122018-11-27 15:58:47 +0100138 export MAKEFLAGS="-j"
139 fi
Gilles Peskine878cf602019-01-06 20:50:38 +0000140
141 # Gather the list of available components. These are the functions
142 # defined in this script whose name starts with "component_".
143 # Parse the script with sed, because in sh there is no way to list
144 # defined functions.
145 ALL_COMPONENTS=$(sed -n 's/^ *component_\([0-9A-Z_a-z]*\) *().*/\1/p' <"$0")
146
147 # Exclude components that are not supported on this platform.
148 SUPPORTED_COMPONENTS=
149 for component in $ALL_COMPONENTS; do
150 case $(type "support_$component" 2>&1) in
151 *' function'*)
152 if ! support_$component; then continue; fi;;
153 esac
154 SUPPORTED_COMPONENTS="$SUPPORTED_COMPONENTS $component"
155 done
Gilles Peskine8f073122018-11-27 15:58:47 +0100156}
Andres AG38495a32016-07-12 16:54:33 +0100157
Gilles Peskinea28db922019-01-10 00:05:18 +0100158# Test whether the component $1 is included in the command line patterns.
159is_component_included()
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100160{
161 set -f
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000162 for pattern in $COMMAND_LINE_COMPONENTS; do
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100163 set +f
164 case ${1#component_} in $pattern) return 0;; esac
165 done
166 set +f
167 return 1
168}
Andres AG38495a32016-07-12 16:54:33 +0100169
Simon Butcher41eeccf2016-09-07 00:07:09 +0100170usage()
SimonB2e23c822016-04-16 21:54:39 +0100171{
Gilles Peskine709346a2017-12-10 23:43:39 +0100172 cat <<EOF
Gilles Peskine92525112018-11-27 18:15:35 +0100173Usage: $0 [OPTION]... [COMPONENT]...
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100174Run mbedtls release validation tests.
Gilles Peskine92525112018-11-27 18:15:35 +0100175By default, run all tests. With one or more COMPONENT, run only those.
Gilles Peskinea28db922019-01-10 00:05:18 +0100176COMPONENT can be the name of a component or a shell wildcard pattern.
177
178Examples:
179 $0 "check_*"
180 Run all sanity checks.
181 $0 --no-armcc --except test_memsan
182 Run everything except builds that require armcc and MemSan.
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100183
184Special options:
185 -h|--help Print this help and exit.
Gilles Peskine878cf602019-01-06 20:50:38 +0000186 --list-all-components List all available test components and exit.
187 --list-components List components supported on this platform and exit.
Gilles Peskine709346a2017-12-10 23:43:39 +0100188
189General options:
190 -f|--force Force the tests to overwrite any modified files.
Gilles Peskine7c652162017-12-11 00:01:40 +0100191 -k|--keep-going Run all tests and report errors at the end.
Gilles Peskine709346a2017-12-10 23:43:39 +0100192 -m|--memory Additional optional memory tests.
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100193 --armcc Run ARM Compiler builds (on by default).
Gilles Peskinea28db922019-01-10 00:05:18 +0100194 --except Exclude the COMPONENTs listed on the command line,
195 instead of running only those.
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100196 --no-armcc Skip ARM Compiler builds.
Gilles Peskine38d81652018-03-21 08:40:26 +0100197 --no-force Refuse to overwrite modified files (default).
198 --no-keep-going Stop at the first error (default).
199 --no-memory No additional memory tests (default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100200 --out-of-source-dir=<path> Directory used for CMake out-of-source build tests.
Gilles Peskine38d81652018-03-21 08:40:26 +0100201 --random-seed Use a random seed value for randomized tests (default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100202 -r|--release-test Run this script in release mode. This fixes the seed value to 1.
203 -s|--seed Integer seed value to use for this test run.
204
205Tool path options:
206 --armc5-bin-dir=<ARMC5_bin_dir_path> ARM Compiler 5 bin directory.
207 --armc6-bin-dir=<ARMC6_bin_dir_path> ARM Compiler 6 bin directory.
208 --gnutls-cli=<GnuTLS_cli_path> GnuTLS client executable to use for most tests.
209 --gnutls-serv=<GnuTLS_serv_path> GnuTLS server executable to use for most tests.
210 --gnutls-legacy-cli=<GnuTLS_cli_path> GnuTLS client executable to use for legacy tests.
211 --gnutls-legacy-serv=<GnuTLS_serv_path> GnuTLS server executable to use for legacy tests.
212 --openssl=<OpenSSL_path> OpenSSL executable to use for most tests.
213 --openssl-legacy=<OpenSSL_path> OpenSSL executable to use for legacy tests e.g. SSLv3.
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100214 --openssl-next=<OpenSSL_path> OpenSSL executable to use for recent things like ARIA
Gilles Peskine709346a2017-12-10 23:43:39 +0100215EOF
SimonB2e23c822016-04-16 21:54:39 +0100216}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100217
218# remove built files as well as the cmake cache/config
219cleanup()
220{
Gilles Peskinea71d64c2018-03-21 12:16:57 +0100221 if [ -n "${MBEDTLS_ROOT_DIR+set}" ]; then
222 cd "$MBEDTLS_ROOT_DIR"
223 fi
224
Gilles Peskine7c652162017-12-11 00:01:40 +0100225 command make clean
Jaeden Ameroed93bdc2018-11-02 16:57:24 +0000226 cd crypto
227 command make clean
228 cd ..
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200229
Gilles Peskine31b07e22018-03-21 12:15:06 +0100230 # Remove CMake artefacts
Jaeden Amero2d0e00f2018-11-07 18:46:41 +0000231 find . -name .git -prune -o \
Gilles Peskine31b07e22018-03-21 12:15:06 +0100232 -iname CMakeFiles -exec rm -rf {} \+ -o \
233 \( -iname cmake_install.cmake -o \
234 -iname CTestTestfile.cmake -o \
235 -iname CMakeCache.txt \) -exec rm {} \+
236 # Recover files overwritten by in-tree CMake builds
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000237 rm -f include/Makefile include/mbedtls/Makefile programs/*/Makefile
Philippe Antoine5dece6d2019-06-27 16:55:07 +0200238 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile
239 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile
Jaeden Ameroed93bdc2018-11-02 16:57:24 +0000240 cd crypto
241 rm -f include/Makefile include/mbedtls/Makefile programs/*/Makefile
242 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile
243 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile
244 cd ..
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200245
Jaeden Ameroab83fdf2019-06-20 17:38:22 +0100246 # Remove any artifacts from the component_test_cmake_as_subdirectory test.
247 rm -rf programs/test/cmake_subproject/build
248 rm -f programs/test/cmake_subproject/Makefile
249 rm -f programs/test/cmake_subproject/cmake_subproject
250
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200251 if [ -f "$CONFIG_BAK" ]; then
252 mv "$CONFIG_BAK" "$CONFIG_H"
253 fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100254}
255
Gilles Peskine7c652162017-12-11 00:01:40 +0100256# Executed on exit. May be redefined depending on command line options.
257final_report () {
258 :
259}
260
261fatal_signal () {
262 cleanup
263 final_report $1
264 trap - $1
265 kill -$1 $$
266}
267
268trap 'fatal_signal HUP' HUP
269trap 'fatal_signal INT' INT
270trap 'fatal_signal TERM' TERM
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200271
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100272msg()
273{
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100274 if [ -n "${current_component:-}" ]; then
275 current_section="${current_component#component_}: $1"
276 else
277 current_section="$1"
278 fi
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100279 echo ""
280 echo "******************************************************************"
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100281 echo "* $current_section "
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000282 printf "* "; date
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100283 echo "******************************************************************"
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100284}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100285
Gilles Peskine8f073122018-11-27 15:58:47 +0100286armc6_build_test()
287{
288 FLAGS="$1"
Andres AGa5cd9732016-10-17 15:23:10 +0100289
Gilles Peskine8f073122018-11-27 15:58:47 +0100290 msg "build: ARM Compiler 6 ($FLAGS), make"
291 ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \
292 WARNING_CFLAGS='-xc -std=c99' make lib
293 make clean
294}
Andres AGa5cd9732016-10-17 15:23:10 +0100295
Andres AGd9eba4b2016-08-26 14:42:14 +0100296err_msg()
297{
298 echo "$1" >&2
299}
300
301check_tools()
302{
303 for TOOL in "$@"; do
Andres AG98393602017-01-31 17:04:45 +0000304 if ! `type "$TOOL" >/dev/null 2>&1`; then
Andres AGd9eba4b2016-08-26 14:42:14 +0100305 err_msg "$TOOL not found!"
306 exit 1
307 fi
308 done
309}
310
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400311check_headers_in_cpp () {
Peter Kolbus1bc1a4c2019-02-01 17:19:08 -0600312 ls include/mbedtls | grep "\.h$" >headers.txt
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400313 <programs/test/cpp_dummy_build.cpp sed -n 's/"$//; s!^#include "mbedtls/!!p' |
314 sort |
315 diff headers.txt -
316 rm headers.txt
317}
318
Gilles Peskine8f073122018-11-27 15:58:47 +0100319pre_parse_command_line () {
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000320 COMMAND_LINE_COMPONENTS=
Gilles Peskinea28db922019-01-10 00:05:18 +0100321 all_except=0
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000322 no_armcc=
SimonB2e23c822016-04-16 21:54:39 +0100323
Gilles Peskine8f073122018-11-27 15:58:47 +0100324 while [ $# -gt 0 ]; do
Gilles Peskine55f7c942019-01-09 22:28:21 +0100325 case "$1" in
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000326 --armcc) no_armcc=;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100327 --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
328 --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000329 --except) all_except=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100330 --force|-f) FORCE=1;;
331 --gnutls-cli) shift; GNUTLS_CLI="$1";;
332 --gnutls-legacy-cli) shift; GNUTLS_LEGACY_CLI="$1";;
333 --gnutls-legacy-serv) shift; GNUTLS_LEGACY_SERV="$1";;
334 --gnutls-serv) shift; GNUTLS_SERV="$1";;
335 --help|-h) usage; exit;;
336 --keep-going|-k) KEEP_GOING=1;;
Gilles Peskine878cf602019-01-06 20:50:38 +0000337 --list-all-components) printf '%s\n' $ALL_COMPONENTS; exit;;
338 --list-components) printf '%s\n' $SUPPORTED_COMPONENTS; exit;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100339 --memory|-m) MEMORY=1;;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000340 --no-armcc) no_armcc=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100341 --no-force) FORCE=0;;
342 --no-keep-going) KEEP_GOING=0;;
343 --no-memory) MEMORY=0;;
344 --openssl) shift; OPENSSL="$1";;
345 --openssl-legacy) shift; OPENSSL_LEGACY="$1";;
346 --openssl-next) shift; OPENSSL_NEXT="$1";;
347 --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
348 --random-seed) unset SEED;;
349 --release-test|-r) SEED=1;;
350 --seed|-s) shift; SEED="$1";;
351 -*)
352 echo >&2 "Unknown option: $1"
353 echo >&2 "Run $0 --help for usage."
354 exit 120
355 ;;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000356 *) COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS $1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100357 esac
358 shift
Gilles Peskine8f073122018-11-27 15:58:47 +0100359 done
SimonB2e23c822016-04-16 21:54:39 +0100360
Gilles Peskinea28db922019-01-10 00:05:18 +0100361 # With no list of components, run everything.
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000362 if [ -z "$COMMAND_LINE_COMPONENTS" ]; then
363 all_except=1
Andres AGdc192212016-08-31 17:33:13 +0100364 fi
365
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000366 # --no-armcc is a legacy option. The modern way is --except '*_armcc*'.
367 # Ignore it if components are listed explicitly on the command line.
Gilles Peskinea28db922019-01-10 00:05:18 +0100368 if [ -n "$no_armcc" ] && [ $all_except -eq 1 ]; then
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000369 COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS *_armcc*"
SimonB2e23c822016-04-16 21:54:39 +0100370 fi
SimonB2e23c822016-04-16 21:54:39 +0100371
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000372 # Build the list of components to run.
Gilles Peskinea28db922019-01-10 00:05:18 +0100373 RUN_COMPONENTS=
374 for component in $SUPPORTED_COMPONENTS; do
375 if is_component_included "$component"; [ $? -eq $all_except ]; then
376 RUN_COMPONENTS="$RUN_COMPONENTS $component"
377 fi
378 done
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000379
380 unset all_except
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000381 unset no_armcc
Gilles Peskine8f073122018-11-27 15:58:47 +0100382}
SimonB2e23c822016-04-16 21:54:39 +0100383
Gilles Peskine8f073122018-11-27 15:58:47 +0100384pre_check_git () {
385 if [ $FORCE -eq 1 ]; then
Gilles Peskine53190e62019-01-09 23:17:35 +0100386 rm -rf "$OUT_OF_SOURCE_DIR"
Gilles Peskine8f073122018-11-27 15:58:47 +0100387 git checkout-index -f -q $CONFIG_H
388 cleanup
389 else
SimonB2e23c822016-04-16 21:54:39 +0100390
Gilles Peskine8f073122018-11-27 15:58:47 +0100391 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
392 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
393 echo "You can either delete this directory manually, or force the test by rerunning"
394 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
395 exit 1
396 fi
397
Gilles Peskined1174cf2019-01-09 22:30:01 +0100398 if ! git diff --quiet include/mbedtls/config.h; then
Gilles Peskine8f073122018-11-27 15:58:47 +0100399 err_msg "Warning - the configuration file 'include/mbedtls/config.h' has been edited. "
400 echo "You can either delete or preserve your work, or force the test by rerunning the"
401 echo "script as: $0 --force"
402 exit 1
403 fi
Andres AGdc192212016-08-31 17:33:13 +0100404 fi
Andrzej Kureke9c3b812019-02-05 05:34:21 -0500405 if ! [ -f crypto/Makefile ]; then
406 echo "Please initialize the crypto submodule" >&2
407 exit 1
408 fi
Gilles Peskine8f073122018-11-27 15:58:47 +0100409}
Andres AGdc192212016-08-31 17:33:13 +0100410
Andrzej Kurekeb508712019-02-14 07:18:59 -0500411pre_check_seedfile () {
412 if [ ! -f "./tests/seedfile" ]; then
413 dd if=/dev/urandom of=./tests/seedfile bs=32 count=1
414 fi
Jaeden Amero97145102019-03-18 16:31:21 +0000415 if [ ! -f "./crypto/tests/seedfile" ]; then
416 dd if=/dev/urandom of=./crypto/tests/seedfile bs=32 count=1
417 fi
Andrzej Kurekeb508712019-02-14 07:18:59 -0500418}
419
Gilles Peskine8f073122018-11-27 15:58:47 +0100420pre_setup_keep_going () {
Gilles Peskine7c652162017-12-11 00:01:40 +0100421 failure_summary=
422 failure_count=0
423 start_red=
424 end_color=
425 if [ -t 1 ]; then
Gilles Peskine9736b9d2018-01-02 21:54:17 +0100426 case "${TERM:-}" in
Gilles Peskine7c652162017-12-11 00:01:40 +0100427 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
428 start_red=$(printf '\033[31m')
429 end_color=$(printf '\033[0m')
430 ;;
431 esac
432 fi
433 record_status () {
434 if "$@"; then
435 last_status=0
436 else
437 last_status=$?
438 text="$current_section: $* -> $last_status"
439 failure_summary="$failure_summary
440$text"
441 failure_count=$((failure_count + 1))
442 echo "${start_red}^^^^$text^^^^${end_color}"
443 fi
444 }
445 make () {
446 case "$*" in
447 *test|*check)
448 if [ $build_status -eq 0 ]; then
449 record_status command make "$@"
450 else
451 echo "(skipped because the build failed)"
452 fi
453 ;;
454 *)
455 record_status command make "$@"
456 build_status=$last_status
457 ;;
458 esac
459 }
460 final_report () {
461 if [ $failure_count -gt 0 ]; then
462 echo
463 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
464 echo "${start_red}FAILED: $failure_count${end_color}$failure_summary"
465 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Jaeden Amero7c1258d2018-07-20 16:42:14 +0100466 exit 1
Gilles Peskine7c652162017-12-11 00:01:40 +0100467 elif [ -z "${1-}" ]; then
468 echo "SUCCESS :)"
469 fi
470 if [ -n "${1-}" ]; then
471 echo "Killed by SIG$1."
472 fi
473 }
Gilles Peskine8f073122018-11-27 15:58:47 +0100474}
475
Gilles Peskine7c652162017-12-11 00:01:40 +0100476if_build_succeeded () {
477 if [ $build_status -eq 0 ]; then
478 record_status "$@"
479 fi
480}
481
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200482# to be used instead of ! for commands run with
483# record_status or if_build_succeeded
484not() {
485 ! "$@"
486}
487
Gilles Peskine8f073122018-11-27 15:58:47 +0100488pre_print_configuration () {
489 msg "info: $0 configuration"
490 echo "MEMORY: $MEMORY"
491 echo "FORCE: $FORCE"
492 echo "SEED: ${SEED-"UNSET"}"
493 echo "OPENSSL: $OPENSSL"
494 echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
495 echo "OPENSSL_NEXT: $OPENSSL_NEXT"
496 echo "GNUTLS_CLI: $GNUTLS_CLI"
497 echo "GNUTLS_SERV: $GNUTLS_SERV"
498 echo "GNUTLS_LEGACY_CLI: $GNUTLS_LEGACY_CLI"
499 echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV"
500 echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
501 echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
502}
Andres AG7770ea82016-10-10 15:46:20 +0100503
Andres AGd9eba4b2016-08-26 14:42:14 +0100504# Make sure the tools we need are available.
Gilles Peskine8f073122018-11-27 15:58:47 +0100505pre_check_tools () {
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000506 # Build the list of variables to pass to output_env.sh.
507 set env
Andres AGd9eba4b2016-08-26 14:42:14 +0100508
Gilles Peskine87964262019-01-06 22:40:00 +0000509 case " $RUN_COMPONENTS " in
510 # Require OpenSSL and GnuTLS if running any tests (as opposed to
511 # only doing builds). Not all tests run OpenSSL and GnuTLS, but this
512 # is a good enough approximation in practice.
513 *" test_"*)
514 # To avoid setting OpenSSL and GnuTLS for each call to compat.sh
515 # and ssl-opt.sh, we just export the variables they require.
516 export OPENSSL_CMD="$OPENSSL"
517 export GNUTLS_CLI="$GNUTLS_CLI"
518 export GNUTLS_SERV="$GNUTLS_SERV"
519 # Avoid passing --seed flag in every call to ssl-opt.sh
520 if [ -n "${SEED-}" ]; then
521 export SEED
522 fi
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000523 set "$@" OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY"
524 set "$@" GNUTLS_CLI="$GNUTLS_CLI" GNUTLS_SERV="$GNUTLS_SERV"
525 set "$@" GNUTLS_LEGACY_CLI="$GNUTLS_LEGACY_CLI"
526 set "$@" GNUTLS_LEGACY_SERV="$GNUTLS_LEGACY_SERV"
Gilles Peskine87964262019-01-06 22:40:00 +0000527 check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$OPENSSL_NEXT" \
528 "$GNUTLS_CLI" "$GNUTLS_SERV" \
529 "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV"
530 ;;
531 esac
Andres AGb2fdd042016-09-22 14:17:46 +0100532
Gilles Peskine87964262019-01-06 22:40:00 +0000533 case " $RUN_COMPONENTS " in
534 *_doxygen[_\ ]*) check_tools "doxygen" "dot";;
535 esac
Andres AG7770ea82016-10-10 15:46:20 +0100536
Gilles Peskine87964262019-01-06 22:40:00 +0000537 case " $RUN_COMPONENTS " in
538 *_arm_none_eabi_gcc[_\ ]*) check_tools "arm-none-eabi-gcc";;
539 esac
Andres AG7770ea82016-10-10 15:46:20 +0100540
Gilles Peskine87964262019-01-06 22:40:00 +0000541 case " $RUN_COMPONENTS " in
542 *_mingw[_\ ]*) check_tools "i686-w64-mingw32-gcc";;
543 esac
544
545 case " $RUN_COMPONENTS " in
546 *" test_zeroize "*) check_tools "gdb";;
547 esac
548
549 case " $RUN_COMPONENTS " in
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000550 *_armcc*)
Gilles Peskine87964262019-01-06 22:40:00 +0000551 ARMC5_CC="$ARMC5_BIN_DIR/armcc"
552 ARMC5_AR="$ARMC5_BIN_DIR/armar"
553 ARMC6_CC="$ARMC6_BIN_DIR/armclang"
554 ARMC6_AR="$ARMC6_BIN_DIR/armar"
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000555 check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC6_CC" "$ARMC6_AR";;
556 esac
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000557
558 msg "info: output_env.sh"
559 case $RUN_COMPONENTS in
560 *_armcc*)
561 set "$@" ARMC5_CC="$ARMC5_CC" ARMC6_CC="$ARMC6_CC" RUN_ARMCC=1;;
562 *) set "$@" RUN_ARMCC=0;;
563 esac
564 "$@" scripts/output_env.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100565}
Andres AGd9eba4b2016-08-26 14:42:14 +0100566
Gilles Peskine192c72f2017-12-21 15:59:21 +0100567
568
569################################################################
570#### Basic checks
571################################################################
Andres AGd9eba4b2016-08-26 14:42:14 +0100572
SimonB2e23c822016-04-16 21:54:39 +0100573#
574# Test Suites to be executed
575#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200576# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100577# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard61bc57a2014-08-14 11:29:06 +0200578# and/or are more likely to fail than others (eg I use Clang most of the
579# time, so start with a GCC build).
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200580# 2. Minimize total running time, by avoiding useless rebuilds
581#
582# Indicative running times are given for reference.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100583
Gilles Peskine8f073122018-11-27 15:58:47 +0100584component_check_recursion () {
585 msg "test: recursion.pl" # < 1s
586 record_status tests/scripts/recursion.pl library/*.c
587}
Janos Follathb72c6782016-07-19 14:54:17 +0100588
Gilles Peskine8f073122018-11-27 15:58:47 +0100589component_check_generated_files () {
590 msg "test: freshness of generated source files" # < 1s
591 record_status tests/scripts/check-generated-files.sh
592}
Manuel Pégourié-Gonnardea29d152014-11-20 17:32:33 +0100593
Gilles Peskine8f073122018-11-27 15:58:47 +0100594component_check_doxy_blocks () {
595 msg "test: doxygen markup outside doxygen blocks" # < 1s
596 record_status tests/scripts/check-doxy-blocks.pl
597}
Manuel Pégourié-Gonnardb3b8e432015-02-13 14:52:19 +0000598
Gilles Peskine8f073122018-11-27 15:58:47 +0100599component_check_files () {
600 msg "test: check-files.py" # < 1s
Gilles Peskine8f073122018-11-27 15:58:47 +0100601 record_status tests/scripts/check-files.py
602}
Manuel Pégourié-Gonnardd09a6b52015-04-09 17:19:23 +0200603
Gilles Peskine8f073122018-11-27 15:58:47 +0100604component_check_names () {
605 msg "test/build: declared and exported names" # < 3s
Gilles Peskine13f97dc2019-05-15 17:52:22 +0200606 record_status tests/scripts/check-names.sh -v
Gilles Peskine8f073122018-11-27 15:58:47 +0100607}
Darryl Greena07039c2018-03-13 16:48:16 +0000608
Gilles Peskine8f073122018-11-27 15:58:47 +0100609component_check_doxygen_warnings () {
610 msg "test: doxygen warnings" # ~ 3s
Gilles Peskine8f073122018-11-27 15:58:47 +0100611 record_status tests/scripts/doxygen.sh
612}
Manuel Pégourié-Gonnard1d552e72016-01-04 16:49:09 +0100613
Gilles Peskine192c72f2017-12-21 15:59:21 +0100614
615
616################################################################
617#### Build and test many configurations and targets
618################################################################
619
Gilles Peskine7832c9f2019-04-08 17:00:15 +0200620component_test_default_out_of_box () {
621 msg "build: make, default config (out-of-box)" # ~1min
622 make
623
624 msg "test: main suites make, default config (out-of-box)" # ~10s
625 make test
626
627 msg "selftest: make, default config (out-of-box)" # ~10s
628 programs/test/selftest
629}
630
Gilles Peskine8f073122018-11-27 15:58:47 +0100631component_test_default_cmake_gcc_asan () {
632 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100633 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
634 make
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100635
Gilles Peskine8f073122018-11-27 15:58:47 +0100636 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
637 make test
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200638
Gilles Peskine8f073122018-11-27 15:58:47 +0100639 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
640 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200641
Gilles Peskine8f073122018-11-27 15:58:47 +0100642 msg "test: compat.sh (ASan build)" # ~ 6 min
643 if_build_succeeded tests/compat.sh
644}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200645
Gilles Peskine782f4112018-11-27 16:11:09 +0100646component_test_ref_configs () {
647 msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
648 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
649 record_status tests/scripts/test-ref-configs.pl
650}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200651
Gilles Peskine8f073122018-11-27 15:58:47 +0100652component_test_sslv3 () {
653 msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100654 scripts/config.pl set MBEDTLS_SSL_PROTO_SSL3
655 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
656 make
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200657
Gilles Peskine8f073122018-11-27 15:58:47 +0100658 msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
659 make test
Simon Butcher3ea7f522016-03-07 23:22:10 +0000660
Gilles Peskine8f073122018-11-27 15:58:47 +0100661 msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
662 if_build_succeeded tests/compat.sh -m 'tls1 tls1_1 tls1_2 dtls1 dtls1_2'
663 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
Simon Butcher3ea7f522016-03-07 23:22:10 +0000664
Gilles Peskine8f073122018-11-27 15:58:47 +0100665 msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
666 if_build_succeeded tests/ssl-opt.sh
667}
Simon Butcher3ea7f522016-03-07 23:22:10 +0000668
Gilles Peskine8f073122018-11-27 15:58:47 +0100669component_test_no_renegotiation () {
670 msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100671 scripts/config.pl unset MBEDTLS_SSL_RENEGOTIATION
672 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
673 make
Simon Butcher3ea7f522016-03-07 23:22:10 +0000674
Gilles Peskine8f073122018-11-27 15:58:47 +0100675 msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
676 make test
Hanno Becker134c2ab2017-10-12 15:29:50 +0100677
Gilles Peskine8f073122018-11-27 15:58:47 +0100678 msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
679 if_build_succeeded tests/ssl-opt.sh
680}
Hanno Becker134c2ab2017-10-12 15:29:50 +0100681
Hanno Beckera545be22019-05-10 14:45:37 +0100682component_test_no_pem_no_fs () {
683 msg "build: Default + !MBEDTLS_PEM_PARSE_C + !MBEDTLS_FS_IO (ASan build)"
684 scripts/config.pl unset MBEDTLS_PEM_PARSE_C
685 scripts/config.pl unset MBEDTLS_FS_IO
686 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
687 make
688
689 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - main suites (inc. selftests) (ASan build)" # ~ 50s
690 make test
691
692 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - ssl-opt.sh (ASan build)" # ~ 6 min
693 if_build_succeeded tests/ssl-opt.sh
694}
695
Gilles Peskine8f073122018-11-27 15:58:47 +0100696component_test_rsa_no_crt () {
697 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100698 scripts/config.pl set MBEDTLS_RSA_NO_CRT
699 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
700 make
Simon Butcher3ea7f522016-03-07 23:22:10 +0000701
Gilles Peskine8f073122018-11-27 15:58:47 +0100702 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
703 make test
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100704
Gilles Peskine8f073122018-11-27 15:58:47 +0100705 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
706 if_build_succeeded tests/ssl-opt.sh -f RSA
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100707
Gilles Peskine8f073122018-11-27 15:58:47 +0100708 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
709 if_build_succeeded tests/compat.sh -t RSA
710}
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100711
Gilles Peskine8f073122018-11-27 15:58:47 +0100712component_test_small_ssl_out_content_len () {
713 msg "build: small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100714 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 16384
715 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
716 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
717 make
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100718
Gilles Peskine8f073122018-11-27 15:58:47 +0100719 msg "test: small SSL_OUT_CONTENT_LEN - ssl-opt.sh MFL and large packet tests"
720 if_build_succeeded tests/ssl-opt.sh -f "Max fragment\|Large packet"
721}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000722
Gilles Peskine8f073122018-11-27 15:58:47 +0100723component_test_small_ssl_in_content_len () {
724 msg "build: small SSL_IN_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100725 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 4096
726 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 16384
727 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
728 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000729
Gilles Peskine8f073122018-11-27 15:58:47 +0100730 msg "test: small SSL_IN_CONTENT_LEN - ssl-opt.sh MFL tests"
731 if_build_succeeded tests/ssl-opt.sh -f "Max fragment"
732}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000733
Gilles Peskine8f073122018-11-27 15:58:47 +0100734component_test_small_ssl_dtls_max_buffering () {
735 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0"
Gilles Peskine8f073122018-11-27 15:58:47 +0100736 scripts/config.pl set MBEDTLS_SSL_DTLS_MAX_BUFFERING 1000
737 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
738 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000739
Gilles Peskine8f073122018-11-27 15:58:47 +0100740 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0 - ssl-opt.sh specific reordering test"
741 if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer out-of-order hs msg before reassembling next, free buffered msg"
742}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100743
Gilles Peskine8f073122018-11-27 15:58:47 +0100744component_test_small_mbedtls_ssl_dtls_max_buffering () {
745 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1"
Gilles Peskine8f073122018-11-27 15:58:47 +0100746 scripts/config.pl set MBEDTLS_SSL_DTLS_MAX_BUFFERING 240
747 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
748 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100749
Gilles Peskine8f073122018-11-27 15:58:47 +0100750 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1 - ssl-opt.sh specific reordering test"
751 if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer encrypted Finished message, drop for fragmented NewSessionTicket"
752}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100753
Gilles Peskine8f073122018-11-27 15:58:47 +0100754component_test_full_cmake_clang () {
755 msg "build: cmake, full config, clang" # ~ 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100756 scripts/config.pl full
757 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
758 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check -D ENABLE_TESTING=On .
759 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100760
Gilles Peskine8f073122018-11-27 15:58:47 +0100761 msg "test: main suites (full config)" # ~ 5s
762 make test
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100763
Gilles Peskine8f073122018-11-27 15:58:47 +0100764 msg "test: ssl-opt.sh default, ECJPAKE, SSL async (full config)" # ~ 1s
765 if_build_succeeded tests/ssl-opt.sh -f 'Default\|ECJPAKE\|SSL async private'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200766
Andres Amaya Garcia2dadab72019-01-08 21:42:27 +0000767 msg "test: compat.sh RC4, DES, 3DES & NULL (full config)" # ~ 2 min
Andres Amaya Garcia419bd002019-02-19 20:20:57 +0000768 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 +0200769
Gilles Peskine8f073122018-11-27 15:58:47 +0100770 msg "test: compat.sh ARIA + ChachaPoly"
771 if_build_succeeded env OPENSSL_CMD="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
772}
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200773
Gilles Peskine8f073122018-11-27 15:58:47 +0100774component_build_deprecated () {
775 msg "build: make, full config + DEPRECATED_WARNING, gcc -O" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100776 scripts/config.pl full
777 scripts/config.pl set MBEDTLS_DEPRECATED_WARNING
778 # Build with -O -Wextra to catch a maximum of issues.
779 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra' lib programs
780 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100781
Gilles Peskine8f073122018-11-27 15:58:47 +0100782 msg "build: make, full config + DEPRECATED_REMOVED, clang -O" # ~ 30s
783 # No cleanup, just tweak the configuration and rebuild
784 make clean
785 scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
786 scripts/config.pl set MBEDTLS_DEPRECATED_REMOVED
787 # Build with -O -Wextra to catch a maximum of issues.
788 make CC=clang CFLAGS='-O -Werror -Wall -Wextra' lib programs
789 make CC=clang CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
790}
Jaeden Ameroed93bdc2018-11-02 16:57:24 +0000791
Gilles Peskine8f073122018-11-27 15:58:47 +0100792component_test_depends_curves () {
793 msg "test/build: curves.pl (gcc)" # ~ 4 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100794 record_status tests/scripts/curves.pl
795}
Jaeden Ameroacaabe72018-11-07 11:52:52 +0000796
Gilles Peskine8f073122018-11-27 15:58:47 +0100797component_test_depends_hashes () {
798 msg "test/build: depends-hashes.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100799 record_status tests/scripts/depends-hashes.pl
800}
Jaeden Ameroacaabe72018-11-07 11:52:52 +0000801
Gilles Peskine8f073122018-11-27 15:58:47 +0100802component_test_depends_pkalgs () {
803 msg "test/build: depends-pkalgs.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100804 record_status tests/scripts/depends-pkalgs.pl
805}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100806
Gilles Peskine8f073122018-11-27 15:58:47 +0100807component_build_key_exchanges () {
808 msg "test/build: key-exchanges (gcc)" # ~ 1 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100809 record_status tests/scripts/key-exchanges.pl
810}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100811
Gilles Peskine8f073122018-11-27 15:58:47 +0100812component_build_default_make_gcc_and_cxx () {
813 msg "build: Unix make, -Os (gcc)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100814 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100815
Gilles Peskine8f073122018-11-27 15:58:47 +0100816 msg "test: verify header list in cpp_dummy_build.cpp"
817 record_status check_headers_in_cpp
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100818
Gilles Peskine8f073122018-11-27 15:58:47 +0100819 msg "build: Unix make, incremental g++"
820 make TEST_CPP=1
821}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100822
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100823component_test_no_use_psa_crypto_full_cmake_asan() {
824 # full minus MBEDTLS_USE_PSA_CRYPTO: run the same set of tests as basic-build-test.sh
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500825 msg "build: cmake, full config + MBEDTLS_USE_PSA_CRYPTO, ASan"
826 scripts/config.pl full
827 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
Jaeden Amero0f220ec2019-07-05 15:03:40 +0100828 scripts/config.pl set MBEDTLS_ECP_RESTARTABLE # not using PSA, so enable restartable ECC
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500829 scripts/config.pl set MBEDTLS_PSA_CRYPTO_C
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100830 scripts/config.pl unset MBEDTLS_USE_PSA_CRYPTO
831 scripts/config.pl unset MBEDTLS_PSA_ITS_FILE_C
Andrzej Kurek324b2f72019-04-18 08:59:12 -0400832 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_C
Manuel Pégourié-Gonnardd8167e82019-02-01 11:12:52 +0100833 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500834 make
Manuel Pégourié-Gonnard43be6cd2017-06-20 09:53:42 +0200835
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100836 msg "test: main suites (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500837 make test
Manuel Pégourié-Gonnard503a5ef2015-10-23 09:04:45 +0200838
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100839 msg "test: ssl-opt.sh (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500840 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100841
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100842 msg "test: compat.sh default (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500843 if_build_succeeded tests/compat.sh
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400844
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100845 msg "test: compat.sh ssl3 (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500846 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400847
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100848 msg "test: compat.sh RC4, DES & NULL (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500849 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" GNUTLS_CLI="$GNUTLS_LEGACY_CLI" GNUTLS_SERV="$GNUTLS_LEGACY_SERV" tests/compat.sh -e '3DES\|DES-CBC3' -f 'NULL\|DES\|RC4\|ARCFOUR'
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500850
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100851 msg "test: compat.sh ARIA + ChachaPoly (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500852 if_build_succeeded env OPENSSL_CMD="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
853}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500854
Gilles Peskineadcde5e2019-06-12 16:05:50 +0200855component_test_check_params_functionality () {
856 msg "build+test: MBEDTLS_CHECK_PARAMS functionality"
857 scripts/config.pl full # includes CHECK_PARAMS
858 # Make MBEDTLS_PARAM_FAILED call mbedtls_param_failed().
859 scripts/config.pl unset MBEDTLS_CHECK_PARAMS_ASSERT
860 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
861 # Only build and run tests. Do not build sample programs, because
862 # they don't have a mbedtls_param_failed() function.
863 make CC=gcc CFLAGS='-Werror -O1' lib test
864}
865
Gilles Peskineb28636b2019-01-02 19:06:24 +0100866component_test_check_params_without_platform () {
867 msg "build+test: MBEDTLS_CHECK_PARAMS without MBEDTLS_PLATFORM_C"
868 scripts/config.pl full # includes CHECK_PARAMS
Gilles Peskineadcde5e2019-06-12 16:05:50 +0200869 # Keep MBEDTLS_PARAM_FAILED as assert.
Gilles Peskineb28636b2019-01-02 19:06:24 +0100870 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
871 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
872 scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
873 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
874 scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
875 scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
876 scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
877 scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
878 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
879 scripts/config.pl unset MBEDTLS_PLATFORM_C
880 make CC=gcc CFLAGS='-Werror -O1' all test
881}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500882
Gilles Peskineb28636b2019-01-02 19:06:24 +0100883component_test_check_params_silent () {
884 msg "build+test: MBEDTLS_CHECK_PARAMS with alternative MBEDTLS_PARAM_FAILED()"
885 scripts/config.pl full # includes CHECK_PARAMS
886 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
Gilles Peskineadcde5e2019-06-12 16:05:50 +0200887 # Set MBEDTLS_PARAM_FAILED to nothing.
Gilles Peskineb28636b2019-01-02 19:06:24 +0100888 sed -i 's/.*\(#define MBEDTLS_PARAM_FAILED( cond )\).*/\1/' "$CONFIG_H"
889 make CC=gcc CFLAGS='-Werror -O1' all test
890}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500891
Gilles Peskine8f073122018-11-27 15:58:47 +0100892component_test_no_platform () {
893 # Full configuration build, without platform support, file IO and net sockets.
894 # This should catch missing mbedtls_printf definitions, and by disabling file
895 # IO, it should catch missing '#include <stdio.h>'
896 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100897 scripts/config.pl full
898 scripts/config.pl unset MBEDTLS_PLATFORM_C
899 scripts/config.pl unset MBEDTLS_NET_C
900 scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
901 scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
902 scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
903 scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
904 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
905 scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
906 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
907 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
908 scripts/config.pl unset MBEDTLS_FS_IO
Andrzej Kurek73757082019-04-18 04:14:37 -0400909 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_C
910 scripts/config.pl unset MBEDTLS_PSA_ITS_FILE_C
Gilles Peskine8f073122018-11-27 15:58:47 +0100911 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
912 # to re-enable platform integration features otherwise disabled in C99 builds
913 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -O0 -D_DEFAULT_SOURCE' lib programs
914 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0' test
915}
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +0000916
Gilles Peskine8f073122018-11-27 15:58:47 +0100917component_build_no_std_function () {
918 # catch compile bugs in _uninit functions
919 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100920 scripts/config.pl full
921 scripts/config.pl set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
922 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
923 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
924}
Manuel Pégourié-Gonnarddccb80b2015-06-03 10:20:33 +0100925
Gilles Peskine8f073122018-11-27 15:58:47 +0100926component_build_no_ssl_srv () {
927 msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100928 scripts/config.pl full
929 scripts/config.pl unset MBEDTLS_SSL_SRV_C
930 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
931}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200932
Gilles Peskine8f073122018-11-27 15:58:47 +0100933component_build_no_ssl_cli () {
934 msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100935 scripts/config.pl full
936 scripts/config.pl unset MBEDTLS_SSL_CLI_C
937 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
938}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200939
Gilles Peskine8f073122018-11-27 15:58:47 +0100940component_build_no_sockets () {
941 # Note, C99 compliance can also be tested with the sockets support disabled,
942 # as that requires a POSIX platform (which isn't the same as C99).
943 msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100944 scripts/config.pl full
945 scripts/config.pl unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
946 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
947 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0 -std=c99 -pedantic' lib
948}
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +0200949
Gilles Peskine8f073122018-11-27 15:58:47 +0100950component_test_no_max_fragment_length () {
951 # Run max fragment length tests with MFL disabled
952 msg "build: default config except MFL extension (ASan build)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100953 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
954 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
955 make
Hanno Becker5175ac62017-09-18 15:36:25 +0100956
Gilles Peskine8f073122018-11-27 15:58:47 +0100957 msg "test: ssl-opt.sh, MFL-related tests"
958 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length"
959}
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +0200960
Hanno Becker545ced42019-02-19 11:10:48 +0000961component_test_asan_remove_peer_certificate () {
962 msg "build: default config with MBEDTLS_SSL_KEEP_PEER_CERTIFICATE disabled (ASan build)"
963 scripts/config.pl unset MBEDTLS_SSL_KEEP_PEER_CERTIFICATE
964 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
965 make
966
967 msg "test: !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
968 make test
969
970 msg "test: ssl-opt.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
971 if_build_succeeded tests/ssl-opt.sh
972
973 msg "test: compat.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
974 if_build_succeeded tests/compat.sh
975}
976
Gilles Peskine8f073122018-11-27 15:58:47 +0100977component_test_no_max_fragment_length_small_ssl_out_content_len () {
978 msg "build: no MFL extension, small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100979 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
980 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 16384
981 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
982 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
983 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000984
Gilles Peskine8f073122018-11-27 15:58:47 +0100985 msg "test: MFL tests (disabled MFL extension case) & large packet tests"
986 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length\|Large buffer"
987}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000988
Jaeden Amero2de07f12019-06-05 13:32:08 +0100989component_test_when_no_ciphersuites_have_mac () {
990 msg "build: when no ciphersuites have MAC"
991 scripts/config.pl unset MBEDTLS_CIPHER_NULL_CIPHER
992 scripts/config.pl unset MBEDTLS_ARC4_C
993 scripts/config.pl unset MBEDTLS_CIPHER_MODE_CBC
994 make
995
996 msg "test: !MBEDTLS_SSL_SOME_MODES_USE_MAC"
997 make test
998
999 msg "test ssl-opt.sh: !MBEDTLS_SSL_SOME_MODES_USE_MAC"
Jaeden Amero6b1683d2019-06-05 14:42:50 +01001000 if_build_succeeded tests/ssl-opt.sh -f 'Default\|EtM' -e 'without EtM'
Jaeden Amero2de07f12019-06-05 13:32:08 +01001001}
1002
Gilles Peskine8f073122018-11-27 15:58:47 +01001003component_test_null_entropy () {
1004 msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +01001005 scripts/config.pl set MBEDTLS_TEST_NULL_ENTROPY
1006 scripts/config.pl set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
1007 scripts/config.pl set MBEDTLS_ENTROPY_C
1008 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
1009 scripts/config.pl unset MBEDTLS_ENTROPY_HARDWARE_ALT
1010 scripts/config.pl unset MBEDTLS_HAVEGE_C
Gilles Peskine5fa32a72019-01-06 19:48:30 +00001011 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan -D UNSAFE_BUILD=ON .
Gilles Peskine8f073122018-11-27 15:58:47 +01001012 make
Janos Follath06c54002016-06-09 13:57:40 +01001013
Gilles Peskine8f073122018-11-27 15:58:47 +01001014 msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)"
1015 make test
1016}
Janos Follath06c54002016-06-09 13:57:40 +01001017
Gilles Peskine8f073122018-11-27 15:58:47 +01001018component_test_platform_calloc_macro () {
1019 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +01001020 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
1021 scripts/config.pl set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
1022 scripts/config.pl set MBEDTLS_PLATFORM_FREE_MACRO free
1023 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1024 make
Hanno Beckere5fecec2018-10-11 11:02:52 +01001025
Gilles Peskine8f073122018-11-27 15:58:47 +01001026 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
1027 make test
1028}
Hanno Beckere5fecec2018-10-11 11:02:52 +01001029
Gilles Peskine8f073122018-11-27 15:58:47 +01001030component_test_make_shared () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001031 msg "build/test: make shared" # ~ 40s
Andrzej Kurek87615772019-04-19 15:03:58 -04001032 make SHARED=1 all check -j1
Gilles Peskine8f073122018-11-27 15:58:47 +01001033}
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +02001034
Gilles Peskine8f073122018-11-27 15:58:47 +01001035component_test_m32_o0 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001036 # Build once with -O0, to compile out the i386 specific inline assembly
1037 msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
Simon Butcher7a6da6e2018-06-27 21:52:54 +01001038 scripts/config.pl full
Philippe Antoinecd2c1272019-06-25 21:50:07 +02001039 make CC=gcc CFLAGS='-O0 -Werror -Wall -Wextra -m32 -fsanitize=address' LDFLAGS='-m32 -fsanitize=address'
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01001040
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001041 msg "test: i386, make, gcc -O0 (ASan build)"
1042 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01001043}
Gilles Peskine878cf602019-01-06 20:50:38 +00001044support_test_m32_o0 () {
1045 case $(uname -m) in
1046 *64*) true;;
1047 *) false;;
1048 esac
1049}
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001050
Gilles Peskine8f073122018-11-27 15:58:47 +01001051component_test_m32_o1 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001052 # Build again with -O1, to compile in the i386 specific inline assembly
1053 msg "build: i386, make, gcc -O1 (ASan build)" # ~ 30s
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001054 scripts/config.pl full
Gilles Peskine4b317612019-04-08 16:58:02 +02001055 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE
1056 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
1057 scripts/config.pl unset MBEDTLS_MEMORY_DEBUG
Philippe Antoinecd2c1272019-06-25 21:50:07 +02001058 make CC=gcc CFLAGS='-O1 -Werror -Wall -Wextra -m32 -fsanitize=address' LDFLAGS='-m32 -fsanitize=address'
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001059
1060 msg "test: i386, make, gcc -O1 (ASan build)"
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001061 make test
Gilles Peskine4b317612019-04-08 16:58:02 +02001062
1063 msg "test ssl-opt.sh, i386, make, gcc-O1"
1064 if_build_succeeded tests/ssl-opt.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01001065}
Gilles Peskine878cf602019-01-06 20:50:38 +00001066support_test_m32_o1 () {
1067 support_test_m32_o0 "$@"
1068}
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001069
Gilles Peskine8f073122018-11-27 15:58:47 +01001070component_test_mx32 () {
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001071 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
Simon Butcher7a6da6e2018-06-27 21:52:54 +01001072 scripts/config.pl full
Gilles Peskine5d26e7c2019-06-07 14:50:09 +02001073 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32' LDFLAGS='-mx32'
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001074
1075 msg "test: 64-bit ILP32, make, gcc"
1076 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01001077}
Gilles Peskine878cf602019-01-06 20:50:38 +00001078support_test_mx32 () {
1079 case $(uname -m) in
1080 amd64|x86_64) true;;
1081 *) false;;
1082 esac
1083}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001084
Gilles Peskine8f073122018-11-27 15:58:47 +01001085component_build_arm_none_eabi_gcc () {
1086 msg "build: arm-none-eabi-gcc, make" # ~ 10s
Manuel Pégourié-Gonnarddf2bfcf2019-04-29 12:44:12 +02001087 scripts/config.pl baremetal
Gilles Peskine8f073122018-11-27 15:58:47 +01001088 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
1089}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001090
Gilles Peskine8f073122018-11-27 15:58:47 +01001091component_build_arm_none_eabi_gcc_no_udbl_division () {
1092 msg "build: arm-none-eabi-gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
Manuel Pégourié-Gonnarddf2bfcf2019-04-29 12:44:12 +02001093 scripts/config.pl baremetal
Gilles Peskine8f073122018-11-27 15:58:47 +01001094 scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
1095 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
1096 echo "Checking that software 64-bit division is not required"
1097 if_build_succeeded not grep __aeabi_uldiv library/*.o
1098}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001099
Gilles Peskine8f073122018-11-27 15:58:47 +01001100component_build_arm_none_eabi_gcc_no_64bit_multiplication () {
1101 msg "build: arm-none-eabi-gcc MBEDTLS_NO_64BIT_MULTIPLICATION, make" # ~ 10s
Manuel Pégourié-Gonnarddf2bfcf2019-04-29 12:44:12 +02001102 scripts/config.pl baremetal
Gilles Peskine8f073122018-11-27 15:58:47 +01001103 scripts/config.pl set MBEDTLS_NO_64BIT_MULTIPLICATION
1104 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -O1 -march=armv6-m -mthumb' lib
1105 echo "Checking that software 64-bit multiplication is not required"
1106 if_build_succeeded not grep __aeabi_lmul library/*.o
1107}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001108
Gilles Peskine8f073122018-11-27 15:58:47 +01001109component_build_armcc () {
1110 msg "build: ARM Compiler 5, make"
Manuel Pégourié-Gonnarddf2bfcf2019-04-29 12:44:12 +02001111 scripts/config.pl baremetal
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001112
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001113 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
1114 make clean
Andres AG87bb5772016-09-27 15:05:15 +01001115
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001116 # ARM Compiler 6 - Target ARMv7-A
1117 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-a"
Simon Butcher940737f2017-07-23 13:42:36 +02001118
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001119 # ARM Compiler 6 - Target ARMv7-M
1120 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m"
Simon Butcher940737f2017-07-23 13:42:36 +02001121
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001122 # ARM Compiler 6 - Target ARMv8-A - AArch32
1123 armc6_build_test "--target=arm-arm-none-eabi -march=armv8.2-a"
Simon Butcher940737f2017-07-23 13:42:36 +02001124
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001125 # ARM Compiler 6 - Target ARMv8-M
1126 armc6_build_test "--target=arm-arm-none-eabi -march=armv8-m.main"
Simon Butcher940737f2017-07-23 13:42:36 +02001127
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001128 # ARM Compiler 6 - Target ARMv8-A - AArch64
1129 armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a"
Gilles Peskine8f073122018-11-27 15:58:47 +01001130}
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +01001131
Gilles Peskine8f073122018-11-27 15:58:47 +01001132component_test_allow_sha1 () {
1133 msg "build: allow SHA1 in certificates by default"
Gilles Peskine8f073122018-11-27 15:58:47 +01001134 scripts/config.pl set MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
1135 make CFLAGS='-Werror -Wall -Wextra'
1136 msg "test: allow SHA1 in certificates by default"
1137 make test
1138 if_build_succeeded tests/ssl-opt.sh -f SHA-1
1139}
Gilles Peskine2a458da2017-05-12 15:26:58 +02001140
Gilles Peskine8f073122018-11-27 15:58:47 +01001141component_build_mingw () {
1142 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
Andrzej Kurek62faadd2019-04-19 20:10:21 -04001143 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -Wall -Wextra' WINDOWS_BUILD=1 lib programs -j1
Hanno Beckere963efa2018-01-03 10:03:43 +00001144
Gilles Peskine8f073122018-11-27 15:58:47 +01001145 # note Make tests only builds the tests, but doesn't run them
Andrzej Kurek62faadd2019-04-19 20:10:21 -04001146 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror' WINDOWS_BUILD=1 tests -j1
Gilles Peskine8f073122018-11-27 15:58:47 +01001147 make WINDOWS_BUILD=1 clean
Gilles Peskine2a458da2017-05-12 15:26:58 +02001148
Gilles Peskine8f073122018-11-27 15:58:47 +01001149 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
Andrzej Kurek87615772019-04-19 15:03:58 -04001150 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -Wall -Wextra' WINDOWS_BUILD=1 SHARED=1 lib programs -j1
1151 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -Wall -Wextra' WINDOWS_BUILD=1 SHARED=1 tests -j1
Gilles Peskine8f073122018-11-27 15:58:47 +01001152 make WINDOWS_BUILD=1 clean
1153}
Jaeden Amero117b8a42019-04-17 15:19:26 +01001154support_build_mingw() {
1155 case $(i686-w64-mingw32-gcc -dumpversion) in
1156 [0-5]*) false;;
1157 *) true;;
1158 esac
1159}
Simon Butcher91aef332016-11-17 09:20:50 +00001160
Gilles Peskine8f073122018-11-27 15:58:47 +01001161component_test_memsan () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001162 msg "build: MSan (clang)" # ~ 1 min 20s
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001163 scripts/config.pl unset MBEDTLS_AESNI_C # memsan doesn't grok asm
1164 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
1165 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +02001166
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001167 msg "test: main suites (MSan)" # ~ 10s
1168 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001169
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001170 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
Gilles Peskine7c652162017-12-11 00:01:40 +01001171 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001172
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001173 # Optional part(s)
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001174
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001175 if [ "$MEMORY" -gt 0 ]; then
1176 msg "test: compat.sh (MSan)" # ~ 6 min 20s
Gilles Peskine7c652162017-12-11 00:01:40 +01001177 if_build_succeeded tests/compat.sh
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001178 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001179}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001180
Gilles Peskine69f190e2019-01-10 00:11:42 +01001181component_test_valgrind () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001182 msg "build: Release (clang)"
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001183 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
1184 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001185
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001186 msg "test: main suites valgrind (Release)"
1187 make memcheck
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001188
Gilles Peskinef1349e42019-04-08 17:00:56 +02001189 # Optional parts (slow; currently broken on OS X because programs don't
1190 # seem to receive signals under valgrind on OS X).
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001191 if [ "$MEMORY" -gt 0 ]; then
1192 msg "test: ssl-opt.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +01001193 if_build_succeeded tests/ssl-opt.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001194 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001195
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001196 if [ "$MEMORY" -gt 1 ]; then
1197 msg "test: compat.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +01001198 if_build_succeeded tests/compat.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001199 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001200}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001201
Gilles Peskine8f073122018-11-27 15:58:47 +01001202component_test_cmake_out_of_source () {
1203 msg "build: cmake 'out-of-source' build"
Gilles Peskine8f073122018-11-27 15:58:47 +01001204 MBEDTLS_ROOT_DIR="$PWD"
1205 mkdir "$OUT_OF_SOURCE_DIR"
1206 cd "$OUT_OF_SOURCE_DIR"
1207 cmake "$MBEDTLS_ROOT_DIR"
1208 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001209
Gilles Peskine8f073122018-11-27 15:58:47 +01001210 msg "test: cmake 'out-of-source' build"
1211 make test
1212 # Test an SSL option that requires an auxiliary script in test/scripts/.
1213 # Also ensure that there are no error messages such as
1214 # "No such file or directory", which would indicate that some required
1215 # file is missing (ssl-opt.sh tolerates the absence of some files so
1216 # may exit with status 0 but emit errors).
1217 if_build_succeeded ./tests/ssl-opt.sh -f 'Fallback SCSV: beginning of list' 2>ssl-opt.err
1218 if [ -s ssl-opt.err ]; then
1219 cat ssl-opt.err >&2
1220 record_status [ ! -s ssl-opt.err ]
1221 rm ssl-opt.err
1222 fi
1223 cd "$MBEDTLS_ROOT_DIR"
1224 rm -rf "$OUT_OF_SOURCE_DIR"
1225 unset MBEDTLS_ROOT_DIR
1226}
Andres AGdc192212016-08-31 17:33:13 +01001227
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01001228component_test_cmake_as_subdirectory () {
1229 msg "build: cmake 'as-subdirectory' build"
1230 MBEDTLS_ROOT_DIR="$PWD"
1231
1232 cd programs/test/cmake_subproject
1233 cmake .
1234 make
1235 if_build_succeeded ./cmake_subproject
1236
1237 cd "$MBEDTLS_ROOT_DIR"
1238 unset MBEDTLS_ROOT_DIR
1239}
1240
Gilles Peskine8f073122018-11-27 15:58:47 +01001241component_test_zeroize () {
1242 # Test that the function mbedtls_platform_zeroize() is not optimized away by
1243 # different combinations of compilers and optimization flags by using an
1244 # auxiliary GDB script. Unfortunately, GDB does not return error values to the
1245 # system in all cases that the script fails, so we must manually search the
1246 # output to check whether the pass string is present and no failure strings
1247 # were printed.
Andres AGdc192212016-08-31 17:33:13 +01001248
Gilles Peskine4976e822019-01-06 19:52:22 +00001249 # Don't try to disable ASLR. We don't care about ASLR here. We do care
1250 # about a spurious message if Gdb tries and fails, so suppress that.
1251 gdb_disable_aslr=
1252 if [ -z "$(gdb -batch -nw -ex 'set disable-randomization off' 2>&1)" ]; then
1253 gdb_disable_aslr='set disable-randomization off'
1254 fi
1255
Gilles Peskine8f073122018-11-27 15:58:47 +01001256 for optimization_flag in -O2 -O3 -Ofast -Os; do
Gilles Peskine55f7c942019-01-09 22:28:21 +01001257 for compiler in clang gcc; do
1258 msg "test: $compiler $optimization_flag, mbedtls_platform_zeroize()"
1259 make programs CC="$compiler" DEBUG=1 CFLAGS="$optimization_flag"
Gilles Peskine4976e822019-01-06 19:52:22 +00001260 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 +01001261 if_build_succeeded grep "The buffer was correctly zeroized" test_zeroize.log
1262 if_build_succeeded not grep -i "error" test_zeroize.log
1263 rm -f test_zeroize.log
1264 make clean
1265 done
Andres Amaya Garcia29673812017-10-25 10:35:51 +01001266 done
Andres Amaya Garciad0d7bf62017-10-25 09:01:31 +01001267
Gilles Peskine4976e822019-01-06 19:52:22 +00001268 unset gdb_disable_aslr
Gilles Peskine8f073122018-11-27 15:58:47 +01001269}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001270
Gilles Peskineaad2ebd2019-02-25 20:26:06 +01001271support_check_python_files () {
1272 type pylint3 >/dev/null 2>/dev/null
1273}
Gilles Peskine8f073122018-11-27 15:58:47 +01001274component_check_python_files () {
1275 msg "Lint: Python scripts"
1276 record_status tests/scripts/check-python-files.sh
1277}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001278
Gilles Peskine8f073122018-11-27 15:58:47 +01001279component_check_generate_test_code () {
1280 msg "uint test: generate_test_code.py"
1281 record_status ./tests/scripts/test_generate_test_code.py
1282}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001283
1284################################################################
1285#### Termination
1286################################################################
1287
Gilles Peskine8f073122018-11-27 15:58:47 +01001288post_report () {
1289 msg "Done, cleaning up"
1290 cleanup
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001291
Gilles Peskine8f073122018-11-27 15:58:47 +01001292 final_report
1293}
1294
1295
1296
1297################################################################
1298#### Run all the things
1299################################################################
1300
Gilles Peskinee48351a2018-11-27 16:06:30 +01001301# Run one component and clean up afterwards.
Gilles Peskine8f073122018-11-27 15:58:47 +01001302run_component () {
Gilles Peskine608953e2019-01-02 18:57:02 +01001303 # Back up the configuration in case the component modifies it.
1304 # The cleanup function will restore it.
1305 cp -p "$CONFIG_H" "$CONFIG_BAK"
Gilles Peskineffcdeff2018-12-04 12:49:28 +01001306 current_component="$1"
Gilles Peskine8f073122018-11-27 15:58:47 +01001307 "$@"
Gilles Peskinee48351a2018-11-27 16:06:30 +01001308 cleanup
Gilles Peskine8f073122018-11-27 15:58:47 +01001309}
1310
1311# Preliminary setup
1312pre_check_environment
1313pre_initialize_variables
1314pre_parse_command_line "$@"
Gilles Peskine348fb9a2018-11-27 17:04:29 +01001315
Gilles Peskine878cf602019-01-06 20:50:38 +00001316pre_check_git
Andrzej Kurekeb508712019-02-14 07:18:59 -05001317pre_check_seedfile
1318
Gilles Peskine878cf602019-01-06 20:50:38 +00001319build_status=0
1320if [ $KEEP_GOING -eq 1 ]; then
1321 pre_setup_keep_going
Gilles Peskine92525112018-11-27 18:15:35 +01001322else
Gilles Peskine878cf602019-01-06 20:50:38 +00001323 record_status () {
1324 "$@"
1325 }
Gilles Peskine8f073122018-11-27 15:58:47 +01001326fi
Gilles Peskine878cf602019-01-06 20:50:38 +00001327pre_print_configuration
1328pre_check_tools
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001329cleanup
1330
Gilles Peskinebeb3a812019-01-06 22:11:25 +00001331# Run the requested tests.
1332for component in $RUN_COMPONENTS; do
1333 run_component "component_$component"
1334done
Gilles Peskine8f073122018-11-27 15:58:47 +01001335
1336# We're done.
Gilles Peskine878cf602019-01-06 20:50:38 +00001337post_report