blob: 6d7edd6bb3851b1c504bd99673679460816a376a [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 Peskine67ffdaf2019-09-16 15:55:46 +0200120 append_outcome=0
Gilles Peskine8f073122018-11-27 15:58:47 +0100121 MEMORY=0
122 FORCE=0
123 KEEP_GOING=0
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100124
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200125 : ${MBEDTLS_TEST_OUTCOME_FILE=}
Gilles Peskine9004a172019-09-16 15:20:36 +0200126 : ${MBEDTLS_TEST_PLATFORM="$(uname -s | tr -c \\n0-9A-Za-z _)-$(uname -m | tr -c \\n0-9A-Za-z _)"}
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200127 export MBEDTLS_TEST_OUTCOME_FILE
Gilles Peskine9004a172019-09-16 15:20:36 +0200128 export MBEDTLS_TEST_PLATFORM
129
Jaeden Ameroc4cc2512019-01-30 15:35:44 +0000130 # Default commands, can be overridden by the environment
Gilles Peskine8f073122018-11-27 15:58:47 +0100131 : ${OPENSSL:="openssl"}
132 : ${OPENSSL_LEGACY:="$OPENSSL"}
133 : ${OPENSSL_NEXT:="$OPENSSL"}
134 : ${GNUTLS_CLI:="gnutls-cli"}
135 : ${GNUTLS_SERV:="gnutls-serv"}
136 : ${GNUTLS_LEGACY_CLI:="$GNUTLS_CLI"}
137 : ${GNUTLS_LEGACY_SERV:="$GNUTLS_SERV"}
138 : ${OUT_OF_SOURCE_DIR:=./mbedtls_out_of_source_build}
139 : ${ARMC5_BIN_DIR:=/usr/bin}
140 : ${ARMC6_BIN_DIR:=/usr/bin}
Andres AGdc192212016-08-31 17:33:13 +0100141
Gilles Peskine8f073122018-11-27 15:58:47 +0100142 # if MAKEFLAGS is not set add the -j option to speed up invocations of make
Gilles Peskinea1fc4b52019-01-06 20:15:26 +0000143 if [ -z "${MAKEFLAGS+set}" ]; then
Gilles Peskine8f073122018-11-27 15:58:47 +0100144 export MAKEFLAGS="-j"
145 fi
Gilles Peskine878cf602019-01-06 20:50:38 +0000146
147 # Gather the list of available components. These are the functions
148 # defined in this script whose name starts with "component_".
149 # Parse the script with sed, because in sh there is no way to list
150 # defined functions.
151 ALL_COMPONENTS=$(sed -n 's/^ *component_\([0-9A-Z_a-z]*\) *().*/\1/p' <"$0")
152
153 # Exclude components that are not supported on this platform.
154 SUPPORTED_COMPONENTS=
155 for component in $ALL_COMPONENTS; do
156 case $(type "support_$component" 2>&1) in
157 *' function'*)
158 if ! support_$component; then continue; fi;;
159 esac
160 SUPPORTED_COMPONENTS="$SUPPORTED_COMPONENTS $component"
161 done
Gilles Peskine8f073122018-11-27 15:58:47 +0100162}
Andres AG38495a32016-07-12 16:54:33 +0100163
Gilles Peskinea28db922019-01-10 00:05:18 +0100164# Test whether the component $1 is included in the command line patterns.
165is_component_included()
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100166{
167 set -f
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000168 for pattern in $COMMAND_LINE_COMPONENTS; do
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100169 set +f
170 case ${1#component_} in $pattern) return 0;; esac
171 done
172 set +f
173 return 1
174}
Andres AG7770ea82016-10-10 15:46:20 +0100175
Simon Butcher41eeccf2016-09-07 00:07:09 +0100176usage()
Andres AGd9eba4b2016-08-26 14:42:14 +0100177{
Gilles Peskine709346a2017-12-10 23:43:39 +0100178 cat <<EOF
Gilles Peskine92525112018-11-27 18:15:35 +0100179Usage: $0 [OPTION]... [COMPONENT]...
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100180Run mbedtls release validation tests.
Gilles Peskine92525112018-11-27 18:15:35 +0100181By default, run all tests. With one or more COMPONENT, run only those.
Gilles Peskinea28db922019-01-10 00:05:18 +0100182COMPONENT can be the name of a component or a shell wildcard pattern.
183
184Examples:
185 $0 "check_*"
186 Run all sanity checks.
187 $0 --no-armcc --except test_memsan
188 Run everything except builds that require armcc and MemSan.
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100189
190Special options:
191 -h|--help Print this help and exit.
Gilles Peskine878cf602019-01-06 20:50:38 +0000192 --list-all-components List all available test components and exit.
193 --list-components List components supported on this platform and exit.
Gilles Peskine709346a2017-12-10 23:43:39 +0100194
195General options:
196 -f|--force Force the tests to overwrite any modified files.
Gilles Peskine7c652162017-12-11 00:01:40 +0100197 -k|--keep-going Run all tests and report errors at the end.
Gilles Peskine709346a2017-12-10 23:43:39 +0100198 -m|--memory Additional optional memory tests.
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200199 --append-outcome Append to the outcome file (if used).
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100200 --armcc Run ARM Compiler builds (on by default).
Gilles Peskinea28db922019-01-10 00:05:18 +0100201 --except Exclude the COMPONENTs listed on the command line,
202 instead of running only those.
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200203 --no-append-outcome Write a new outcome file and analyze it (default).
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100204 --no-armcc Skip ARM Compiler builds.
Gilles Peskine38d81652018-03-21 08:40:26 +0100205 --no-force Refuse to overwrite modified files (default).
206 --no-keep-going Stop at the first error (default).
207 --no-memory No additional memory tests (default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100208 --out-of-source-dir=<path> Directory used for CMake out-of-source build tests.
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200209 --outcome-file=<path> File where test outcomes are written (not done if
210 empty; default: \$MBEDTLS_TEST_OUTCOME_FILE).
Gilles Peskine38d81652018-03-21 08:40:26 +0100211 --random-seed Use a random seed value for randomized tests (default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100212 -r|--release-test Run this script in release mode. This fixes the seed value to 1.
213 -s|--seed Integer seed value to use for this test run.
214
215Tool path options:
216 --armc5-bin-dir=<ARMC5_bin_dir_path> ARM Compiler 5 bin directory.
217 --armc6-bin-dir=<ARMC6_bin_dir_path> ARM Compiler 6 bin directory.
218 --gnutls-cli=<GnuTLS_cli_path> GnuTLS client executable to use for most tests.
219 --gnutls-serv=<GnuTLS_serv_path> GnuTLS server executable to use for most tests.
220 --gnutls-legacy-cli=<GnuTLS_cli_path> GnuTLS client executable to use for legacy tests.
221 --gnutls-legacy-serv=<GnuTLS_serv_path> GnuTLS server executable to use for legacy tests.
222 --openssl=<OpenSSL_path> OpenSSL executable to use for most tests.
223 --openssl-legacy=<OpenSSL_path> OpenSSL executable to use for legacy tests e.g. SSLv3.
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100224 --openssl-next=<OpenSSL_path> OpenSSL executable to use for recent things like ARIA
Gilles Peskine709346a2017-12-10 23:43:39 +0100225EOF
SimonB2e23c822016-04-16 21:54:39 +0100226}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100227
228# remove built files as well as the cmake cache/config
229cleanup()
230{
Gilles Peskinea71d64c2018-03-21 12:16:57 +0100231 if [ -n "${MBEDTLS_ROOT_DIR+set}" ]; then
232 cd "$MBEDTLS_ROOT_DIR"
233 fi
234
Gilles Peskine7c652162017-12-11 00:01:40 +0100235 command make clean
Jaeden Ameroed93bdc2018-11-02 16:57:24 +0000236 cd crypto
237 command make clean
238 cd ..
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200239
Gilles Peskine31b07e22018-03-21 12:15:06 +0100240 # Remove CMake artefacts
Jaeden Amero2d0e00f2018-11-07 18:46:41 +0000241 find . -name .git -prune -o \
Gilles Peskine31b07e22018-03-21 12:15:06 +0100242 -iname CMakeFiles -exec rm -rf {} \+ -o \
243 \( -iname cmake_install.cmake -o \
244 -iname CTestTestfile.cmake -o \
245 -iname CMakeCache.txt \) -exec rm {} \+
246 # Recover files overwritten by in-tree CMake builds
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000247 rm -f include/Makefile include/mbedtls/Makefile programs/*/Makefile
Philippe Antoine5dece6d2019-06-27 16:55:07 +0200248 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile
249 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile
Jaeden Ameroed93bdc2018-11-02 16:57:24 +0000250 cd crypto
251 rm -f include/Makefile include/mbedtls/Makefile programs/*/Makefile
252 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile
253 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile
254 cd ..
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200255
Jaeden Ameroab83fdf2019-06-20 17:38:22 +0100256 # Remove any artifacts from the component_test_cmake_as_subdirectory test.
257 rm -rf programs/test/cmake_subproject/build
258 rm -f programs/test/cmake_subproject/Makefile
259 rm -f programs/test/cmake_subproject/cmake_subproject
260
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200261 if [ -f "$CONFIG_BAK" ]; then
262 mv "$CONFIG_BAK" "$CONFIG_H"
263 fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100264}
265
Gilles Peskine7c652162017-12-11 00:01:40 +0100266# Executed on exit. May be redefined depending on command line options.
267final_report () {
268 :
269}
270
271fatal_signal () {
272 cleanup
273 final_report $1
274 trap - $1
275 kill -$1 $$
276}
277
278trap 'fatal_signal HUP' HUP
279trap 'fatal_signal INT' INT
280trap 'fatal_signal TERM' TERM
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200281
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100282msg()
283{
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100284 if [ -n "${current_component:-}" ]; then
285 current_section="${current_component#component_}: $1"
286 else
287 current_section="$1"
288 fi
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100289 echo ""
290 echo "******************************************************************"
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100291 echo "* $current_section "
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000292 printf "* "; date
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100293 echo "******************************************************************"
294}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100295
Gilles Peskine8f073122018-11-27 15:58:47 +0100296armc6_build_test()
297{
298 FLAGS="$1"
Andres AGa5cd9732016-10-17 15:23:10 +0100299
Gilles Peskine8f073122018-11-27 15:58:47 +0100300 msg "build: ARM Compiler 6 ($FLAGS), make"
301 ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \
302 WARNING_CFLAGS='-xc -std=c99' make lib
303 make clean
304}
Andres AGa5cd9732016-10-17 15:23:10 +0100305
Andres AGd9eba4b2016-08-26 14:42:14 +0100306err_msg()
307{
308 echo "$1" >&2
309}
310
311check_tools()
312{
313 for TOOL in "$@"; do
Andres AG98393602017-01-31 17:04:45 +0000314 if ! `type "$TOOL" >/dev/null 2>&1`; then
Andres AGd9eba4b2016-08-26 14:42:14 +0100315 err_msg "$TOOL not found!"
316 exit 1
317 fi
318 done
319}
320
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400321check_headers_in_cpp () {
Peter Kolbus1bc1a4c2019-02-01 17:19:08 -0600322 ls include/mbedtls | grep "\.h$" >headers.txt
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400323 <programs/test/cpp_dummy_build.cpp sed -n 's/"$//; s!^#include "mbedtls/!!p' |
324 sort |
325 diff headers.txt -
326 rm headers.txt
327}
328
Gilles Peskine8f073122018-11-27 15:58:47 +0100329pre_parse_command_line () {
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000330 COMMAND_LINE_COMPONENTS=
Gilles Peskinea28db922019-01-10 00:05:18 +0100331 all_except=0
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000332 no_armcc=
SimonB2e23c822016-04-16 21:54:39 +0100333
Gilles Peskine8f073122018-11-27 15:58:47 +0100334 while [ $# -gt 0 ]; do
Gilles Peskine55f7c942019-01-09 22:28:21 +0100335 case "$1" in
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200336 --append-outcome) append_outcome=1;;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000337 --armcc) no_armcc=;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100338 --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
339 --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000340 --except) all_except=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100341 --force|-f) FORCE=1;;
342 --gnutls-cli) shift; GNUTLS_CLI="$1";;
343 --gnutls-legacy-cli) shift; GNUTLS_LEGACY_CLI="$1";;
344 --gnutls-legacy-serv) shift; GNUTLS_LEGACY_SERV="$1";;
345 --gnutls-serv) shift; GNUTLS_SERV="$1";;
346 --help|-h) usage; exit;;
347 --keep-going|-k) KEEP_GOING=1;;
Gilles Peskine878cf602019-01-06 20:50:38 +0000348 --list-all-components) printf '%s\n' $ALL_COMPONENTS; exit;;
349 --list-components) printf '%s\n' $SUPPORTED_COMPONENTS; exit;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100350 --memory|-m) MEMORY=1;;
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200351 --no-append-outcome) append_outcome=0;;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000352 --no-armcc) no_armcc=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100353 --no-force) FORCE=0;;
354 --no-keep-going) KEEP_GOING=0;;
355 --no-memory) MEMORY=0;;
356 --openssl) shift; OPENSSL="$1";;
357 --openssl-legacy) shift; OPENSSL_LEGACY="$1";;
358 --openssl-next) shift; OPENSSL_NEXT="$1";;
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200359 --outcome-file) shift; MBEDTLS_TEST_OUTCOME_FILE="$1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100360 --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
361 --random-seed) unset SEED;;
362 --release-test|-r) SEED=1;;
363 --seed|-s) shift; SEED="$1";;
364 -*)
365 echo >&2 "Unknown option: $1"
366 echo >&2 "Run $0 --help for usage."
367 exit 120
368 ;;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000369 *) COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS $1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100370 esac
371 shift
Gilles Peskine8f073122018-11-27 15:58:47 +0100372 done
SimonB2e23c822016-04-16 21:54:39 +0100373
Gilles Peskinea28db922019-01-10 00:05:18 +0100374 # With no list of components, run everything.
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000375 if [ -z "$COMMAND_LINE_COMPONENTS" ]; then
376 all_except=1
Andres AGdc192212016-08-31 17:33:13 +0100377 fi
378
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000379 # --no-armcc is a legacy option. The modern way is --except '*_armcc*'.
380 # Ignore it if components are listed explicitly on the command line.
Gilles Peskinea28db922019-01-10 00:05:18 +0100381 if [ -n "$no_armcc" ] && [ $all_except -eq 1 ]; then
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000382 COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS *_armcc*"
SimonB2e23c822016-04-16 21:54:39 +0100383 fi
SimonB2e23c822016-04-16 21:54:39 +0100384
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000385 # Build the list of components to run.
Gilles Peskinea28db922019-01-10 00:05:18 +0100386 RUN_COMPONENTS=
387 for component in $SUPPORTED_COMPONENTS; do
388 if is_component_included "$component"; [ $? -eq $all_except ]; then
389 RUN_COMPONENTS="$RUN_COMPONENTS $component"
390 fi
391 done
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000392
393 unset all_except
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000394 unset no_armcc
Gilles Peskine8f073122018-11-27 15:58:47 +0100395}
SimonB2e23c822016-04-16 21:54:39 +0100396
Gilles Peskine8f073122018-11-27 15:58:47 +0100397pre_check_git () {
398 if [ $FORCE -eq 1 ]; then
Gilles Peskine53190e62019-01-09 23:17:35 +0100399 rm -rf "$OUT_OF_SOURCE_DIR"
Gilles Peskine8f073122018-11-27 15:58:47 +0100400 git checkout-index -f -q $CONFIG_H
401 cleanup
402 else
SimonB2e23c822016-04-16 21:54:39 +0100403
Gilles Peskine8f073122018-11-27 15:58:47 +0100404 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
405 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
406 echo "You can either delete this directory manually, or force the test by rerunning"
407 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
408 exit 1
409 fi
410
Gilles Peskined1174cf2019-01-09 22:30:01 +0100411 if ! git diff --quiet include/mbedtls/config.h; then
Gilles Peskine8f073122018-11-27 15:58:47 +0100412 err_msg "Warning - the configuration file 'include/mbedtls/config.h' has been edited. "
413 echo "You can either delete or preserve your work, or force the test by rerunning the"
414 echo "script as: $0 --force"
415 exit 1
416 fi
SimonB2e23c822016-04-16 21:54:39 +0100417 fi
Andrzej Kureke9c3b812019-02-05 05:34:21 -0500418 if ! [ -f crypto/Makefile ]; then
419 echo "Please initialize the crypto submodule" >&2
420 exit 1
421 fi
Gilles Peskine8f073122018-11-27 15:58:47 +0100422}
SimonB2e23c822016-04-16 21:54:39 +0100423
Andrzej Kurekeb508712019-02-14 07:18:59 -0500424pre_check_seedfile () {
425 if [ ! -f "./tests/seedfile" ]; then
426 dd if=/dev/urandom of=./tests/seedfile bs=32 count=1
427 fi
Jaeden Amero97145102019-03-18 16:31:21 +0000428 if [ ! -f "./crypto/tests/seedfile" ]; then
429 dd if=/dev/urandom of=./crypto/tests/seedfile bs=32 count=1
430 fi
Andrzej Kurekeb508712019-02-14 07:18:59 -0500431}
432
Gilles Peskine8f073122018-11-27 15:58:47 +0100433pre_setup_keep_going () {
Gilles Peskine7c652162017-12-11 00:01:40 +0100434 failure_summary=
435 failure_count=0
436 start_red=
437 end_color=
438 if [ -t 1 ]; then
Gilles Peskine9736b9d2018-01-02 21:54:17 +0100439 case "${TERM:-}" in
Gilles Peskine7c652162017-12-11 00:01:40 +0100440 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
441 start_red=$(printf '\033[31m')
442 end_color=$(printf '\033[0m')
443 ;;
444 esac
445 fi
446 record_status () {
447 if "$@"; then
448 last_status=0
449 else
450 last_status=$?
451 text="$current_section: $* -> $last_status"
452 failure_summary="$failure_summary
453$text"
454 failure_count=$((failure_count + 1))
455 echo "${start_red}^^^^$text^^^^${end_color}"
456 fi
457 }
458 make () {
459 case "$*" in
460 *test|*check)
461 if [ $build_status -eq 0 ]; then
462 record_status command make "$@"
463 else
464 echo "(skipped because the build failed)"
465 fi
466 ;;
467 *)
468 record_status command make "$@"
469 build_status=$last_status
470 ;;
471 esac
472 }
473 final_report () {
474 if [ $failure_count -gt 0 ]; then
475 echo
476 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
477 echo "${start_red}FAILED: $failure_count${end_color}$failure_summary"
478 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Jaeden Amero7c1258d2018-07-20 16:42:14 +0100479 exit 1
Gilles Peskine7c652162017-12-11 00:01:40 +0100480 elif [ -z "${1-}" ]; then
481 echo "SUCCESS :)"
482 fi
483 if [ -n "${1-}" ]; then
484 echo "Killed by SIG$1."
485 fi
486 }
Gilles Peskine8f073122018-11-27 15:58:47 +0100487}
488
Gilles Peskine7c652162017-12-11 00:01:40 +0100489if_build_succeeded () {
490 if [ $build_status -eq 0 ]; then
491 record_status "$@"
492 fi
493}
494
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200495# to be used instead of ! for commands run with
496# record_status or if_build_succeeded
497not() {
498 ! "$@"
499}
500
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200501pre_prepare_outcome_file () {
502 case "$MBEDTLS_TEST_OUTCOME_FILE" in
503 [!/]*) MBEDTLS_TEST_OUTCOME_FILE="$PWD/$MBEDTLS_TEST_OUTCOME_FILE";;
504 esac
505 if [ -n "$MBEDTLS_TEST_OUTCOME_FILE" ] && [ "$append_outcome" -eq 0 ]; then
506 rm -f "$MBEDTLS_TEST_OUTCOME_FILE"
507 fi
508}
509
Gilles Peskine8f073122018-11-27 15:58:47 +0100510pre_print_configuration () {
511 msg "info: $0 configuration"
512 echo "MEMORY: $MEMORY"
513 echo "FORCE: $FORCE"
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200514 echo "MBEDTLS_TEST_OUTCOME_FILE: ${MBEDTLS_TEST_OUTCOME_FILE:-(none)}"
Gilles Peskine8f073122018-11-27 15:58:47 +0100515 echo "SEED: ${SEED-"UNSET"}"
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200516 echo
Gilles Peskine8f073122018-11-27 15:58:47 +0100517 echo "OPENSSL: $OPENSSL"
518 echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
519 echo "OPENSSL_NEXT: $OPENSSL_NEXT"
520 echo "GNUTLS_CLI: $GNUTLS_CLI"
521 echo "GNUTLS_SERV: $GNUTLS_SERV"
522 echo "GNUTLS_LEGACY_CLI: $GNUTLS_LEGACY_CLI"
523 echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV"
524 echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
525 echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
526}
Andres AG7770ea82016-10-10 15:46:20 +0100527
Andres AGd9eba4b2016-08-26 14:42:14 +0100528# Make sure the tools we need are available.
Gilles Peskine8f073122018-11-27 15:58:47 +0100529pre_check_tools () {
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000530 # Build the list of variables to pass to output_env.sh.
531 set env
SimonB2e23c822016-04-16 21:54:39 +0100532
Gilles Peskine87964262019-01-06 22:40:00 +0000533 case " $RUN_COMPONENTS " in
534 # Require OpenSSL and GnuTLS if running any tests (as opposed to
535 # only doing builds). Not all tests run OpenSSL and GnuTLS, but this
536 # is a good enough approximation in practice.
537 *" test_"*)
538 # To avoid setting OpenSSL and GnuTLS for each call to compat.sh
539 # and ssl-opt.sh, we just export the variables they require.
540 export OPENSSL_CMD="$OPENSSL"
541 export GNUTLS_CLI="$GNUTLS_CLI"
542 export GNUTLS_SERV="$GNUTLS_SERV"
543 # Avoid passing --seed flag in every call to ssl-opt.sh
544 if [ -n "${SEED-}" ]; then
545 export SEED
546 fi
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000547 set "$@" OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY"
548 set "$@" GNUTLS_CLI="$GNUTLS_CLI" GNUTLS_SERV="$GNUTLS_SERV"
549 set "$@" GNUTLS_LEGACY_CLI="$GNUTLS_LEGACY_CLI"
550 set "$@" GNUTLS_LEGACY_SERV="$GNUTLS_LEGACY_SERV"
Gilles Peskine87964262019-01-06 22:40:00 +0000551 check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$OPENSSL_NEXT" \
552 "$GNUTLS_CLI" "$GNUTLS_SERV" \
553 "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV"
554 ;;
555 esac
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200556
Gilles Peskine87964262019-01-06 22:40:00 +0000557 case " $RUN_COMPONENTS " in
558 *_doxygen[_\ ]*) check_tools "doxygen" "dot";;
559 esac
Andres AGd9eba4b2016-08-26 14:42:14 +0100560
Gilles Peskine87964262019-01-06 22:40:00 +0000561 case " $RUN_COMPONENTS " in
562 *_arm_none_eabi_gcc[_\ ]*) check_tools "arm-none-eabi-gcc";;
563 esac
Andres AGd9eba4b2016-08-26 14:42:14 +0100564
Gilles Peskine87964262019-01-06 22:40:00 +0000565 case " $RUN_COMPONENTS " in
566 *_mingw[_\ ]*) check_tools "i686-w64-mingw32-gcc";;
567 esac
568
569 case " $RUN_COMPONENTS " in
570 *" test_zeroize "*) check_tools "gdb";;
571 esac
572
573 case " $RUN_COMPONENTS " in
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000574 *_armcc*)
Gilles Peskine87964262019-01-06 22:40:00 +0000575 ARMC5_CC="$ARMC5_BIN_DIR/armcc"
576 ARMC5_AR="$ARMC5_BIN_DIR/armar"
577 ARMC6_CC="$ARMC6_BIN_DIR/armclang"
578 ARMC6_AR="$ARMC6_BIN_DIR/armar"
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000579 check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC6_CC" "$ARMC6_AR";;
580 esac
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000581
582 msg "info: output_env.sh"
583 case $RUN_COMPONENTS in
584 *_armcc*)
585 set "$@" ARMC5_CC="$ARMC5_CC" ARMC6_CC="$ARMC6_CC" RUN_ARMCC=1;;
586 *) set "$@" RUN_ARMCC=0;;
587 esac
588 "$@" scripts/output_env.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100589}
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100590
Gilles Peskine192c72f2017-12-21 15:59:21 +0100591
592
593################################################################
594#### Basic checks
595################################################################
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100596
597#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200598# Test Suites to be executed
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100599#
Manuel Pégourié-Gonnard3d404b42015-07-08 21:59:16 +0100600# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200601# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100602# and/or are more likely to fail than others (eg I use Clang most of the
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200603# time, so start with a GCC build).
604# 2. Minimize total running time, by avoiding useless rebuilds
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100605#
Manuel Pégourié-Gonnard259b08a2016-01-08 16:27:41 +0100606# Indicative running times are given for reference.
607
Gilles Peskine8f073122018-11-27 15:58:47 +0100608component_check_recursion () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200609 msg "Check: recursion.pl" # < 1s
Gilles Peskine8f073122018-11-27 15:58:47 +0100610 record_status tests/scripts/recursion.pl library/*.c
611}
Janos Follathb72c6782016-07-19 14:54:17 +0100612
Gilles Peskine8f073122018-11-27 15:58:47 +0100613component_check_generated_files () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200614 msg "Check: freshness of generated source files" # < 1s
Gilles Peskine8f073122018-11-27 15:58:47 +0100615 record_status tests/scripts/check-generated-files.sh
616}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200617
Gilles Peskine8f073122018-11-27 15:58:47 +0100618component_check_doxy_blocks () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200619 msg "Check: doxygen markup outside doxygen blocks" # < 1s
Gilles Peskine8f073122018-11-27 15:58:47 +0100620 record_status tests/scripts/check-doxy-blocks.pl
621}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200622
Gilles Peskine8f073122018-11-27 15:58:47 +0100623component_check_files () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200624 msg "Check: file sanity checks (permissions, encodings)" # < 1s
Gilles Peskine8f073122018-11-27 15:58:47 +0100625 record_status tests/scripts/check-files.py
626}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200627
Gilles Peskine8f073122018-11-27 15:58:47 +0100628component_check_names () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200629 msg "Check: declared and exported names (builds the library)" # < 3s
Gilles Peskine13f97dc2019-05-15 17:52:22 +0200630 record_status tests/scripts/check-names.sh -v
Gilles Peskine8f073122018-11-27 15:58:47 +0100631}
Darryl Greena07039c2018-03-13 16:48:16 +0000632
Gilles Peskine8f073122018-11-27 15:58:47 +0100633component_check_doxygen_warnings () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200634 msg "Check: doxygen warnings (builds the documentation)" # ~ 3s
Gilles Peskine8f073122018-11-27 15:58:47 +0100635 record_status tests/scripts/doxygen.sh
636}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200637
Gilles Peskine192c72f2017-12-21 15:59:21 +0100638
639
640################################################################
641#### Build and test many configurations and targets
642################################################################
643
k-stachowiakc1955552019-06-10 11:46:18 +0200644component_test_large_ecdsa_key_signature () {
645
646 SMALL_MPI_MAX_SIZE=136 # Small enough to interfere with the EC signatures
647
648 msg "build: cmake + MBEDTLS_MPI_MAX_SIZE=${SMALL_MPI_MAX_SIZE}, gcc, ASan" # ~ 1 min 50s
649 scripts/config.pl set MBEDTLS_MPI_MAX_SIZE $SMALL_MPI_MAX_SIZE
k-stachowiakc1955552019-06-10 11:46:18 +0200650 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
651 make
652
653 INEVITABLY_PRESENT_FILE=Makefile
654 SIGNATURE_FILE="${INEVITABLY_PRESENT_FILE}.sig" # Warning, this is rm -f'ed below
655
656 msg "test: pk_sign secp521r1_prv.der for MBEDTLS_MPI_MAX_SIZE=${SMALL_MPI_MAX_SIZE} (ASan build)" # ~ 5s
657 if_build_succeeded programs/pkey/pk_sign tests/data_files/secp521r1_prv.der $INEVITABLY_PRESENT_FILE
658 rm -f $SIGNATURE_FILE
659}
660
Gilles Peskine7832c9f2019-04-08 17:00:15 +0200661component_test_default_out_of_box () {
662 msg "build: make, default config (out-of-box)" # ~1min
663 make
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200664 # Disable fancy stuff
665 unset MBEDTLS_TEST_OUTCOME_FILE
Gilles Peskine7832c9f2019-04-08 17:00:15 +0200666
667 msg "test: main suites make, default config (out-of-box)" # ~10s
668 make test
669
670 msg "selftest: make, default config (out-of-box)" # ~10s
671 programs/test/selftest
672}
673
Gilles Peskine8f073122018-11-27 15:58:47 +0100674component_test_default_cmake_gcc_asan () {
675 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100676 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
677 make
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200678
Gilles Peskine8f073122018-11-27 15:58:47 +0100679 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
680 make test
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200681
Gilles Peskine8f073122018-11-27 15:58:47 +0100682 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
683 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200684
Gilles Peskine8f073122018-11-27 15:58:47 +0100685 msg "test: compat.sh (ASan build)" # ~ 6 min
686 if_build_succeeded tests/compat.sh
687}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200688
Hanno Becker01635512019-02-26 14:27:09 +0000689component_test_full_cmake_gcc_asan () {
690 msg "build: full config, cmake, gcc, ASan"
691 scripts/config.pl full
692 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
693 make
694
695 msg "test: main suites (inc. selftests) (full config, ASan build)"
696 make test
697
698 msg "test: ssl-opt.sh (full config, ASan build)"
699 if_build_succeeded tests/ssl-opt.sh
700
701 msg "test: compat.sh (full config, ASan build)"
702 if_build_succeeded tests/compat.sh
703}
704
Gilles Peskine782f4112018-11-27 16:11:09 +0100705component_test_ref_configs () {
706 msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
707 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
708 record_status tests/scripts/test-ref-configs.pl
709}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200710
Gilles Peskine8f073122018-11-27 15:58:47 +0100711component_test_sslv3 () {
712 msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100713 scripts/config.pl set MBEDTLS_SSL_PROTO_SSL3
714 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
715 make
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200716
Gilles Peskine8f073122018-11-27 15:58:47 +0100717 msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
718 make test
Simon Butcher3ea7f522016-03-07 23:22:10 +0000719
Gilles Peskine8f073122018-11-27 15:58:47 +0100720 msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
721 if_build_succeeded tests/compat.sh -m 'tls1 tls1_1 tls1_2 dtls1 dtls1_2'
722 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
Simon Butcher3ea7f522016-03-07 23:22:10 +0000723
Gilles Peskine8f073122018-11-27 15:58:47 +0100724 msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
725 if_build_succeeded tests/ssl-opt.sh
726}
Simon Butcher3ea7f522016-03-07 23:22:10 +0000727
Gilles Peskine8f073122018-11-27 15:58:47 +0100728component_test_no_renegotiation () {
729 msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100730 scripts/config.pl unset MBEDTLS_SSL_RENEGOTIATION
731 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
732 make
Simon Butcher3ea7f522016-03-07 23:22:10 +0000733
Gilles Peskine8f073122018-11-27 15:58:47 +0100734 msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
735 make test
Hanno Becker134c2ab2017-10-12 15:29:50 +0100736
Gilles Peskine8f073122018-11-27 15:58:47 +0100737 msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
738 if_build_succeeded tests/ssl-opt.sh
739}
Hanno Becker134c2ab2017-10-12 15:29:50 +0100740
Hanno Beckera545be22019-05-10 14:45:37 +0100741component_test_no_pem_no_fs () {
742 msg "build: Default + !MBEDTLS_PEM_PARSE_C + !MBEDTLS_FS_IO (ASan build)"
743 scripts/config.pl unset MBEDTLS_PEM_PARSE_C
744 scripts/config.pl unset MBEDTLS_FS_IO
745 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
746 make
747
748 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - main suites (inc. selftests) (ASan build)" # ~ 50s
749 make test
750
751 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - ssl-opt.sh (ASan build)" # ~ 6 min
752 if_build_succeeded tests/ssl-opt.sh
753}
754
Gilles Peskine8f073122018-11-27 15:58:47 +0100755component_test_rsa_no_crt () {
756 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100757 scripts/config.pl set MBEDTLS_RSA_NO_CRT
758 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
759 make
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +0100760
Gilles Peskine8f073122018-11-27 15:58:47 +0100761 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
762 make test
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100763
Gilles Peskine8f073122018-11-27 15:58:47 +0100764 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
765 if_build_succeeded tests/ssl-opt.sh -f RSA
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100766
Gilles Peskine8f073122018-11-27 15:58:47 +0100767 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
768 if_build_succeeded tests/compat.sh -t RSA
769}
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100770
Gilles Peskine0c6b7992019-04-12 20:29:48 +0200771component_test_everest () {
772 msg "build: Everest ECDH context (ASan build)" # ~ 6 min
773 scripts/config.pl unset MBEDTLS_ECDH_LEGACY_CONTEXT
774 scripts/config.pl set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
775 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Asan .
776 make
777
778 msg "test: Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
779 make test
780
781 msg "test: Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
782 if_build_succeeded tests/ssl-opt.sh -f ECDH
783
784 msg "test: Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
785 # Exclude some symmetric ciphers that are redundant here to gain time.
786 if_build_succeeded tests/compat.sh -f ECDH -V NO -e 'ARCFOUR\|ARIA\|CAMELLIA\|CHACHA\|DES\|RC4'
787}
788
Gilles Peskine8f073122018-11-27 15:58:47 +0100789component_test_small_ssl_out_content_len () {
790 msg "build: small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100791 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 16384
792 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
793 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
794 make
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100795
Gilles Peskine8f073122018-11-27 15:58:47 +0100796 msg "test: small SSL_OUT_CONTENT_LEN - ssl-opt.sh MFL and large packet tests"
797 if_build_succeeded tests/ssl-opt.sh -f "Max fragment\|Large packet"
798}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000799
Gilles Peskine8f073122018-11-27 15:58:47 +0100800component_test_small_ssl_in_content_len () {
801 msg "build: small SSL_IN_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100802 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 4096
803 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 16384
804 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
805 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000806
Gilles Peskine8f073122018-11-27 15:58:47 +0100807 msg "test: small SSL_IN_CONTENT_LEN - ssl-opt.sh MFL tests"
808 if_build_succeeded tests/ssl-opt.sh -f "Max fragment"
809}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000810
Gilles Peskine8f073122018-11-27 15:58:47 +0100811component_test_small_ssl_dtls_max_buffering () {
812 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0"
Gilles Peskine8f073122018-11-27 15:58:47 +0100813 scripts/config.pl set MBEDTLS_SSL_DTLS_MAX_BUFFERING 1000
814 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
815 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000816
Gilles Peskine8f073122018-11-27 15:58:47 +0100817 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0 - ssl-opt.sh specific reordering test"
818 if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer out-of-order hs msg before reassembling next, free buffered msg"
819}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100820
Gilles Peskine8f073122018-11-27 15:58:47 +0100821component_test_small_mbedtls_ssl_dtls_max_buffering () {
822 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1"
Manuel Pégourié-Gonnardeef4c752019-05-28 10:21:30 +0200823 scripts/config.pl set MBEDTLS_SSL_DTLS_MAX_BUFFERING 190
Gilles Peskine8f073122018-11-27 15:58:47 +0100824 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
825 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100826
Gilles Peskine8f073122018-11-27 15:58:47 +0100827 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1 - ssl-opt.sh specific reordering test"
828 if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer encrypted Finished message, drop for fragmented NewSessionTicket"
829}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100830
Gilles Peskine8f073122018-11-27 15:58:47 +0100831component_test_full_cmake_clang () {
832 msg "build: cmake, full config, clang" # ~ 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100833 scripts/config.pl full
Gilles Peskine8f073122018-11-27 15:58:47 +0100834 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check -D ENABLE_TESTING=On .
835 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100836
Gilles Peskine8f073122018-11-27 15:58:47 +0100837 msg "test: main suites (full config)" # ~ 5s
838 make test
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100839
Gilles Peskine8f073122018-11-27 15:58:47 +0100840 msg "test: ssl-opt.sh default, ECJPAKE, SSL async (full config)" # ~ 1s
841 if_build_succeeded tests/ssl-opt.sh -f 'Default\|ECJPAKE\|SSL async private'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200842
Andres Amaya Garcia2dadab72019-01-08 21:42:27 +0000843 msg "test: compat.sh RC4, DES, 3DES & NULL (full config)" # ~ 2 min
Andres Amaya Garcia419bd002019-02-19 20:20:57 +0000844 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 +0200845
Gilles Peskine8f073122018-11-27 15:58:47 +0100846 msg "test: compat.sh ARIA + ChachaPoly"
847 if_build_succeeded env OPENSSL_CMD="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
848}
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200849
Gilles Peskine8f073122018-11-27 15:58:47 +0100850component_build_deprecated () {
851 msg "build: make, full config + DEPRECATED_WARNING, gcc -O" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100852 scripts/config.pl full
853 scripts/config.pl set MBEDTLS_DEPRECATED_WARNING
854 # Build with -O -Wextra to catch a maximum of issues.
855 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra' lib programs
856 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100857
Gilles Peskine8f073122018-11-27 15:58:47 +0100858 msg "build: make, full config + DEPRECATED_REMOVED, clang -O" # ~ 30s
859 # No cleanup, just tweak the configuration and rebuild
860 make clean
861 scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
862 scripts/config.pl set MBEDTLS_DEPRECATED_REMOVED
863 # Build with -O -Wextra to catch a maximum of issues.
864 make CC=clang CFLAGS='-O -Werror -Wall -Wextra' lib programs
865 make CC=clang CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
866}
Jaeden Ameroed93bdc2018-11-02 16:57:24 +0000867
Gilles Peskine8f073122018-11-27 15:58:47 +0100868component_test_depends_curves () {
869 msg "test/build: curves.pl (gcc)" # ~ 4 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100870 record_status tests/scripts/curves.pl
871}
Jaeden Ameroacaabe72018-11-07 11:52:52 +0000872
Gilles Peskine8f073122018-11-27 15:58:47 +0100873component_test_depends_hashes () {
874 msg "test/build: depends-hashes.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100875 record_status tests/scripts/depends-hashes.pl
876}
Jaeden Ameroacaabe72018-11-07 11:52:52 +0000877
Gilles Peskine8f073122018-11-27 15:58:47 +0100878component_test_depends_pkalgs () {
879 msg "test/build: depends-pkalgs.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100880 record_status tests/scripts/depends-pkalgs.pl
881}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100882
Gilles Peskine8f073122018-11-27 15:58:47 +0100883component_build_key_exchanges () {
884 msg "test/build: key-exchanges (gcc)" # ~ 1 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100885 record_status tests/scripts/key-exchanges.pl
886}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100887
Gilles Peskine8f073122018-11-27 15:58:47 +0100888component_build_default_make_gcc_and_cxx () {
889 msg "build: Unix make, -Os (gcc)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100890 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100891
Gilles Peskine8f073122018-11-27 15:58:47 +0100892 msg "test: verify header list in cpp_dummy_build.cpp"
893 record_status check_headers_in_cpp
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100894
Gilles Peskine8f073122018-11-27 15:58:47 +0100895 msg "build: Unix make, incremental g++"
896 make TEST_CPP=1
897}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100898
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100899component_test_no_use_psa_crypto_full_cmake_asan() {
900 # full minus MBEDTLS_USE_PSA_CRYPTO: run the same set of tests as basic-build-test.sh
Gilles Peskinedc3a1792019-09-03 11:42:04 +0200901 msg "build: cmake, full config minus MBEDTLS_USE_PSA_CRYPTO, ASan"
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500902 scripts/config.pl full
Jaeden Amero0f220ec2019-07-05 15:03:40 +0100903 scripts/config.pl set MBEDTLS_ECP_RESTARTABLE # not using PSA, so enable restartable ECC
Gilles Peskine6ce30722019-07-31 18:13:20 +0200904 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_C
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100905 scripts/config.pl unset MBEDTLS_USE_PSA_CRYPTO
906 scripts/config.pl unset MBEDTLS_PSA_ITS_FILE_C
Andrzej Kurek324b2f72019-04-18 08:59:12 -0400907 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_C
Manuel Pégourié-Gonnardd8167e82019-02-01 11:12:52 +0100908 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500909 make
Manuel Pégourié-Gonnard43be6cd2017-06-20 09:53:42 +0200910
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100911 msg "test: main suites (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500912 make test
Manuel Pégourié-Gonnard503a5ef2015-10-23 09:04:45 +0200913
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100914 msg "test: ssl-opt.sh (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500915 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100916
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100917 msg "test: compat.sh default (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500918 if_build_succeeded tests/compat.sh
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400919
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100920 msg "test: compat.sh ssl3 (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500921 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400922
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100923 msg "test: compat.sh RC4, DES & NULL (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500924 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 -0500925
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100926 msg "test: compat.sh ARIA + ChachaPoly (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500927 if_build_succeeded env OPENSSL_CMD="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
928}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500929
Gilles Peskineadcde5e2019-06-12 16:05:50 +0200930component_test_check_params_functionality () {
931 msg "build+test: MBEDTLS_CHECK_PARAMS functionality"
932 scripts/config.pl full # includes CHECK_PARAMS
933 # Make MBEDTLS_PARAM_FAILED call mbedtls_param_failed().
934 scripts/config.pl unset MBEDTLS_CHECK_PARAMS_ASSERT
Gilles Peskineadcde5e2019-06-12 16:05:50 +0200935 # Only build and run tests. Do not build sample programs, because
936 # they don't have a mbedtls_param_failed() function.
937 make CC=gcc CFLAGS='-Werror -O1' lib test
938}
939
Gilles Peskineb28636b2019-01-02 19:06:24 +0100940component_test_check_params_without_platform () {
941 msg "build+test: MBEDTLS_CHECK_PARAMS without MBEDTLS_PLATFORM_C"
942 scripts/config.pl full # includes CHECK_PARAMS
Gilles Peskineadcde5e2019-06-12 16:05:50 +0200943 # Keep MBEDTLS_PARAM_FAILED as assert.
Gilles Peskineb28636b2019-01-02 19:06:24 +0100944 scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
945 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
946 scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
947 scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
948 scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
949 scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
950 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
951 scripts/config.pl unset MBEDTLS_PLATFORM_C
952 make CC=gcc CFLAGS='-Werror -O1' all test
953}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500954
Gilles Peskineb28636b2019-01-02 19:06:24 +0100955component_test_check_params_silent () {
956 msg "build+test: MBEDTLS_CHECK_PARAMS with alternative MBEDTLS_PARAM_FAILED()"
957 scripts/config.pl full # includes CHECK_PARAMS
Gilles Peskineadcde5e2019-06-12 16:05:50 +0200958 # Set MBEDTLS_PARAM_FAILED to nothing.
Gilles Peskineb28636b2019-01-02 19:06:24 +0100959 sed -i 's/.*\(#define MBEDTLS_PARAM_FAILED( cond )\).*/\1/' "$CONFIG_H"
960 make CC=gcc CFLAGS='-Werror -O1' all test
961}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500962
Gilles Peskine8f073122018-11-27 15:58:47 +0100963component_test_no_platform () {
964 # Full configuration build, without platform support, file IO and net sockets.
965 # This should catch missing mbedtls_printf definitions, and by disabling file
966 # IO, it should catch missing '#include <stdio.h>'
967 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100968 scripts/config.pl full
969 scripts/config.pl unset MBEDTLS_PLATFORM_C
970 scripts/config.pl unset MBEDTLS_NET_C
971 scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
972 scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
973 scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
974 scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
975 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
976 scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
977 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskine8f073122018-11-27 15:58:47 +0100978 scripts/config.pl unset MBEDTLS_FS_IO
Andrzej Kurek73757082019-04-18 04:14:37 -0400979 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_C
980 scripts/config.pl unset MBEDTLS_PSA_ITS_FILE_C
Gilles Peskine8f073122018-11-27 15:58:47 +0100981 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
982 # to re-enable platform integration features otherwise disabled in C99 builds
983 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -O0 -D_DEFAULT_SOURCE' lib programs
984 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0' test
985}
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +0000986
Gilles Peskine8f073122018-11-27 15:58:47 +0100987component_build_no_std_function () {
988 # catch compile bugs in _uninit functions
989 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100990 scripts/config.pl full
991 scripts/config.pl set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
992 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
993 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
994}
Manuel Pégourié-Gonnarddccb80b2015-06-03 10:20:33 +0100995
Gilles Peskine8f073122018-11-27 15:58:47 +0100996component_build_no_ssl_srv () {
997 msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100998 scripts/config.pl full
999 scripts/config.pl unset MBEDTLS_SSL_SRV_C
1000 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
1001}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +02001002
Gilles Peskine8f073122018-11-27 15:58:47 +01001003component_build_no_ssl_cli () {
1004 msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +01001005 scripts/config.pl full
1006 scripts/config.pl unset MBEDTLS_SSL_CLI_C
1007 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
1008}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +02001009
Gilles Peskine8f073122018-11-27 15:58:47 +01001010component_build_no_sockets () {
1011 # Note, C99 compliance can also be tested with the sockets support disabled,
1012 # as that requires a POSIX platform (which isn't the same as C99).
1013 msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +01001014 scripts/config.pl full
1015 scripts/config.pl unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
1016 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
1017 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0 -std=c99 -pedantic' lib
1018}
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +02001019
Andrzej Kurek69f20aa2019-09-05 09:27:47 -04001020component_test_memory_buffer_allocator_backtrace () {
1021 msg "build: default config with memory buffer allocator and backtrace enabled"
Hanno Becker0fb9ba22019-02-26 14:34:13 +00001022 scripts/config.pl set MBEDTLS_MEMORY_BUFFER_ALLOC_C
Andrzej Kurek69f20aa2019-09-05 09:27:47 -04001023 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
Hanno Becker0fb9ba22019-02-26 14:34:13 +00001024 scripts/config.pl set MBEDTLS_MEMORY_BACKTRACE
Andrzej Kurek9f409f62019-09-10 02:58:34 -04001025 scripts/config.pl set MBEDTLS_MEMORY_DEBUG
Andrzej Kurek69f20aa2019-09-05 09:27:47 -04001026 CC=gcc cmake .
1027 make
1028
1029 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C and MBEDTLS_MEMORY_BACKTRACE"
1030 make test
1031}
1032
1033component_test_memory_buffer_allocator () {
1034 msg "build: default config with memory buffer allocator"
1035 scripts/config.pl set MBEDTLS_MEMORY_BUFFER_ALLOC_C
Hanno Beckerd7064202019-06-03 16:35:02 +01001036 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
Hanno Becker0fb9ba22019-02-26 14:34:13 +00001037 CC=gcc cmake .
1038 make
1039
1040 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C"
1041 make test
1042
1043 msg "test: ssl-opt.sh, MBEDTLS_MEMORY_BUFFER_ALLOC_C"
Andrzej Kurek1e56d2c2019-09-05 10:09:37 -04001044 # MBEDTLS_MEMORY_BUFFER_ALLOC is slow. Skip tests that tend to time out.
1045 if_build_succeeded tests/ssl-opt.sh -e '^DTLS proxy'
Hanno Becker0fb9ba22019-02-26 14:34:13 +00001046}
1047
Gilles Peskine8f073122018-11-27 15:58:47 +01001048component_test_no_max_fragment_length () {
1049 # Run max fragment length tests with MFL disabled
1050 msg "build: default config except MFL extension (ASan build)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +01001051 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
1052 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1053 make
Hanno Becker5175ac62017-09-18 15:36:25 +01001054
Gilles Peskine8f073122018-11-27 15:58:47 +01001055 msg "test: ssl-opt.sh, MFL-related tests"
1056 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length"
1057}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001058
Hanno Becker545ced42019-02-19 11:10:48 +00001059component_test_asan_remove_peer_certificate () {
1060 msg "build: default config with MBEDTLS_SSL_KEEP_PEER_CERTIFICATE disabled (ASan build)"
1061 scripts/config.pl unset MBEDTLS_SSL_KEEP_PEER_CERTIFICATE
1062 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1063 make
1064
1065 msg "test: !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
1066 make test
1067
1068 msg "test: ssl-opt.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
1069 if_build_succeeded tests/ssl-opt.sh
1070
1071 msg "test: compat.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
1072 if_build_succeeded tests/compat.sh
1073}
1074
Gilles Peskine8f073122018-11-27 15:58:47 +01001075component_test_no_max_fragment_length_small_ssl_out_content_len () {
1076 msg "build: no MFL extension, small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +01001077 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
1078 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 16384
1079 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
1080 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1081 make
Angus Grattonc4dd0732018-04-11 16:28:39 +10001082
Gilles Peskine8f073122018-11-27 15:58:47 +01001083 msg "test: MFL tests (disabled MFL extension case) & large packet tests"
1084 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length\|Large buffer"
1085}
Angus Grattonc4dd0732018-04-11 16:28:39 +10001086
Jaeden Amero2de07f12019-06-05 13:32:08 +01001087component_test_when_no_ciphersuites_have_mac () {
1088 msg "build: when no ciphersuites have MAC"
1089 scripts/config.pl unset MBEDTLS_CIPHER_NULL_CIPHER
1090 scripts/config.pl unset MBEDTLS_ARC4_C
1091 scripts/config.pl unset MBEDTLS_CIPHER_MODE_CBC
1092 make
1093
1094 msg "test: !MBEDTLS_SSL_SOME_MODES_USE_MAC"
1095 make test
1096
1097 msg "test ssl-opt.sh: !MBEDTLS_SSL_SOME_MODES_USE_MAC"
Jaeden Amero6b1683d2019-06-05 14:42:50 +01001098 if_build_succeeded tests/ssl-opt.sh -f 'Default\|EtM' -e 'without EtM'
Jaeden Amero2de07f12019-06-05 13:32:08 +01001099}
1100
Gilles Peskine8f073122018-11-27 15:58:47 +01001101component_test_null_entropy () {
1102 msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +01001103 scripts/config.pl set MBEDTLS_TEST_NULL_ENTROPY
1104 scripts/config.pl set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
1105 scripts/config.pl set MBEDTLS_ENTROPY_C
1106 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
1107 scripts/config.pl unset MBEDTLS_ENTROPY_HARDWARE_ALT
1108 scripts/config.pl unset MBEDTLS_HAVEGE_C
Gilles Peskine5fa32a72019-01-06 19:48:30 +00001109 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan -D UNSAFE_BUILD=ON .
Gilles Peskine8f073122018-11-27 15:58:47 +01001110 make
Janos Follath06c54002016-06-09 13:57:40 +01001111
Gilles Peskine8f073122018-11-27 15:58:47 +01001112 msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)"
1113 make test
1114}
Janos Follath06c54002016-06-09 13:57:40 +01001115
Gilles Peskine8f073122018-11-27 15:58:47 +01001116component_test_platform_calloc_macro () {
1117 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +01001118 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
1119 scripts/config.pl set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
1120 scripts/config.pl set MBEDTLS_PLATFORM_FREE_MACRO free
1121 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1122 make
Hanno Beckere5fecec2018-10-11 11:02:52 +01001123
Gilles Peskine8f073122018-11-27 15:58:47 +01001124 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
1125 make test
1126}
Hanno Beckere5fecec2018-10-11 11:02:52 +01001127
Gilles Peskine8f073122018-11-27 15:58:47 +01001128component_test_make_shared () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001129 msg "build/test: make shared" # ~ 40s
Andrzej Kurek87615772019-04-19 15:03:58 -04001130 make SHARED=1 all check -j1
Gilles Peskine56c01612019-07-03 20:43:32 +02001131 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskine8f073122018-11-27 15:58:47 +01001132}
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +02001133
Gilles Peskinecf740502019-07-03 20:43:05 +02001134component_test_cmake_shared () {
1135 msg "build/test: cmake shared" # ~ 2min
1136 cmake -DUSE_SHARED_MBEDTLS_LIBRARY=On .
1137 make
Gilles Peskine56c01612019-07-03 20:43:32 +02001138 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskinecf740502019-07-03 20:43:05 +02001139 make test
1140}
1141
Gilles Peskineabf9b4d2019-07-03 20:42:16 +02001142component_build_mbedtls_config_file () {
1143 msg "build: make with MBEDTLS_CONFIG_FILE" # ~40s
1144 # Use the full config so as to catch a maximum of places where
1145 # the check of MBEDTLS_CONFIG_FILE might be missing.
1146 scripts/config.pl full
1147 sed 's!"check_config.h"!"mbedtls/check_config.h"!' <"$CONFIG_H" >full_config.h
1148 echo '#error "MBEDTLS_CONFIG_FILE is not working"' >"$CONFIG_H"
1149 make CFLAGS="-I '$PWD' -DMBEDTLS_CONFIG_FILE='\"full_config.h\"'"
1150 rm -f full_config.h
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001151}
1152
Gilles Peskine8f073122018-11-27 15:58:47 +01001153component_test_m32_o0 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001154 # Build once with -O0, to compile out the i386 specific inline assembly
1155 msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
Simon Butcher7a6da6e2018-06-27 21:52:54 +01001156 scripts/config.pl full
Philippe Antoinecd2c1272019-06-25 21:50:07 +02001157 make CC=gcc CFLAGS='-O0 -Werror -Wall -Wextra -m32 -fsanitize=address' LDFLAGS='-m32 -fsanitize=address'
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01001158
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001159 msg "test: i386, make, gcc -O0 (ASan build)"
1160 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01001161}
Gilles Peskine878cf602019-01-06 20:50:38 +00001162support_test_m32_o0 () {
1163 case $(uname -m) in
1164 *64*) true;;
1165 *) false;;
1166 esac
1167}
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001168
Gilles Peskine8f073122018-11-27 15:58:47 +01001169component_test_m32_o1 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001170 # Build again with -O1, to compile in the i386 specific inline assembly
1171 msg "build: i386, make, gcc -O1 (ASan build)" # ~ 30s
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001172 scripts/config.pl full
Philippe Antoinecd2c1272019-06-25 21:50:07 +02001173 make CC=gcc CFLAGS='-O1 -Werror -Wall -Wextra -m32 -fsanitize=address' LDFLAGS='-m32 -fsanitize=address'
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001174
1175 msg "test: i386, make, gcc -O1 (ASan build)"
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001176 make test
Gilles Peskine4b317612019-04-08 16:58:02 +02001177
1178 msg "test ssl-opt.sh, i386, make, gcc-O1"
1179 if_build_succeeded tests/ssl-opt.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01001180}
Gilles Peskine878cf602019-01-06 20:50:38 +00001181support_test_m32_o1 () {
1182 support_test_m32_o0 "$@"
1183}
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001184
Gilles Peskine0c6b7992019-04-12 20:29:48 +02001185component_test_m32_everest () {
1186 msg "build: i386, Everest ECDH context (ASan build)" # ~ 6 min
1187 scripts/config.pl unset MBEDTLS_ECDH_LEGACY_CONTEXT
1188 scripts/config.pl set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
1189 make CC=gcc CFLAGS='-O2 -Werror -Wall -Wextra -m32 -fsanitize=address' LDFLAGS='-m32 -fsanitize=address'
1190
1191 msg "test: i386, Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
1192 make test
1193
1194 msg "test: i386, Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
1195 if_build_succeeded tests/ssl-opt.sh -f ECDH
1196
1197 msg "test: i386, Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
1198 # Exclude some symmetric ciphers that are redundant here to gain time.
1199 if_build_succeeded tests/compat.sh -f ECDH -V NO -e 'ARCFOUR\|ARIA\|CAMELLIA\|CHACHA\|DES\|RC4'
1200}
1201support_test_m32_everest () {
1202 support_test_m32_o0 "$@"
1203}
1204
Gilles Peskine8f073122018-11-27 15:58:47 +01001205component_test_mx32 () {
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001206 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
Simon Butcher7a6da6e2018-06-27 21:52:54 +01001207 scripts/config.pl full
Gilles Peskine5d26e7c2019-06-07 14:50:09 +02001208 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32' LDFLAGS='-mx32'
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001209
1210 msg "test: 64-bit ILP32, make, gcc"
1211 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01001212}
Gilles Peskine878cf602019-01-06 20:50:38 +00001213support_test_mx32 () {
1214 case $(uname -m) in
1215 amd64|x86_64) true;;
1216 *) false;;
1217 esac
1218}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001219
Gilles Peskine8f073122018-11-27 15:58:47 +01001220component_build_arm_none_eabi_gcc () {
1221 msg "build: arm-none-eabi-gcc, make" # ~ 10s
Manuel Pégourié-Gonnarddf2bfcf2019-04-29 12:44:12 +02001222 scripts/config.pl baremetal
Gilles Peskine8f073122018-11-27 15:58:47 +01001223 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
1224}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001225
Gilles Peskine2c897d72019-08-09 16:05:05 +02001226component_build_arm_none_eabi_gcc_arm5vte () {
Gilles Peskine8a52af92019-08-08 16:09:02 +02001227 msg "build: arm-none-eabi-gcc -march=arm5vte, make" # ~ 10s
Gilles Peskine93e4e032019-08-05 11:34:25 +02001228 scripts/config.pl baremetal
Gilles Peskine2c897d72019-08-09 16:05:05 +02001229 # Build for a target platform that's close to what Debian uses
1230 # for its "armel" distribution (https://wiki.debian.org/ArmEabiPort).
1231 # See https://github.com/ARMmbed/mbedtls/pull/2169 and comments.
1232 # It would be better to build with arm-linux-gnueabi-gcc but
1233 # we don't have that on our CI at this time.
Gilles Peskine8a52af92019-08-08 16:09:02 +02001234 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar CFLAGS='-Werror -Wall -Wextra -march=armv5te -O1' LDFLAGS='-march=armv5te' SHELL='sh -x' lib
Gilles Peskine93e4e032019-08-05 11:34:25 +02001235}
1236
Gilles Peskine8f073122018-11-27 15:58:47 +01001237component_build_arm_none_eabi_gcc_no_udbl_division () {
1238 msg "build: arm-none-eabi-gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
Manuel Pégourié-Gonnarddf2bfcf2019-04-29 12:44:12 +02001239 scripts/config.pl baremetal
Gilles Peskine8f073122018-11-27 15:58:47 +01001240 scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
1241 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
1242 echo "Checking that software 64-bit division is not required"
1243 if_build_succeeded not grep __aeabi_uldiv library/*.o
1244}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001245
Gilles Peskine8f073122018-11-27 15:58:47 +01001246component_build_arm_none_eabi_gcc_no_64bit_multiplication () {
1247 msg "build: arm-none-eabi-gcc MBEDTLS_NO_64BIT_MULTIPLICATION, make" # ~ 10s
Manuel Pégourié-Gonnarddf2bfcf2019-04-29 12:44:12 +02001248 scripts/config.pl baremetal
Gilles Peskine8f073122018-11-27 15:58:47 +01001249 scripts/config.pl set MBEDTLS_NO_64BIT_MULTIPLICATION
1250 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -O1 -march=armv6-m -mthumb' lib
1251 echo "Checking that software 64-bit multiplication is not required"
1252 if_build_succeeded not grep __aeabi_lmul library/*.o
1253}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001254
Gilles Peskine8f073122018-11-27 15:58:47 +01001255component_build_armcc () {
1256 msg "build: ARM Compiler 5, make"
Manuel Pégourié-Gonnarddf2bfcf2019-04-29 12:44:12 +02001257 scripts/config.pl baremetal
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001258
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001259 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
1260 make clean
Andres AG87bb5772016-09-27 15:05:15 +01001261
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001262 # ARM Compiler 6 - Target ARMv7-A
1263 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-a"
Simon Butcher940737f2017-07-23 13:42:36 +02001264
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001265 # ARM Compiler 6 - Target ARMv7-M
1266 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m"
Simon Butcher940737f2017-07-23 13:42:36 +02001267
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001268 # ARM Compiler 6 - Target ARMv8-A - AArch32
1269 armc6_build_test "--target=arm-arm-none-eabi -march=armv8.2-a"
Simon Butcher940737f2017-07-23 13:42:36 +02001270
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001271 # ARM Compiler 6 - Target ARMv8-M
1272 armc6_build_test "--target=arm-arm-none-eabi -march=armv8-m.main"
Simon Butcher940737f2017-07-23 13:42:36 +02001273
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001274 # ARM Compiler 6 - Target ARMv8-A - AArch64
1275 armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a"
Gilles Peskine8f073122018-11-27 15:58:47 +01001276}
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +01001277
Gilles Peskine8f073122018-11-27 15:58:47 +01001278component_test_allow_sha1 () {
1279 msg "build: allow SHA1 in certificates by default"
Gilles Peskine8f073122018-11-27 15:58:47 +01001280 scripts/config.pl set MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
1281 make CFLAGS='-Werror -Wall -Wextra'
1282 msg "test: allow SHA1 in certificates by default"
1283 make test
1284 if_build_succeeded tests/ssl-opt.sh -f SHA-1
1285}
Gilles Peskine2a458da2017-05-12 15:26:58 +02001286
Gilles Peskine8f073122018-11-27 15:58:47 +01001287component_build_mingw () {
1288 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
Andrzej Kurek62faadd2019-04-19 20:10:21 -04001289 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 +00001290
Gilles Peskine8f073122018-11-27 15:58:47 +01001291 # note Make tests only builds the tests, but doesn't run them
Andrzej Kurek62faadd2019-04-19 20:10:21 -04001292 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 +01001293 make WINDOWS_BUILD=1 clean
Simon Butcher002bc622016-11-17 09:27:45 +00001294
Gilles Peskine8f073122018-11-27 15:58:47 +01001295 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
Andrzej Kurek87615772019-04-19 15:03:58 -04001296 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
1297 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 +01001298 make WINDOWS_BUILD=1 clean
1299}
Jaeden Amero117b8a42019-04-17 15:19:26 +01001300support_build_mingw() {
1301 case $(i686-w64-mingw32-gcc -dumpversion) in
1302 [0-5]*) false;;
1303 *) true;;
1304 esac
1305}
Manuel Pégourié-Gonnard6448bce2015-02-16 17:18:36 +01001306
Gilles Peskine8f073122018-11-27 15:58:47 +01001307component_test_memsan () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001308 msg "build: MSan (clang)" # ~ 1 min 20s
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001309 scripts/config.pl unset MBEDTLS_AESNI_C # memsan doesn't grok asm
1310 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
1311 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +02001312
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001313 msg "test: main suites (MSan)" # ~ 10s
1314 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001315
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001316 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
Gilles Peskine7c652162017-12-11 00:01:40 +01001317 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001318
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001319 # Optional part(s)
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001320
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001321 if [ "$MEMORY" -gt 0 ]; then
1322 msg "test: compat.sh (MSan)" # ~ 6 min 20s
Gilles Peskine7c652162017-12-11 00:01:40 +01001323 if_build_succeeded tests/compat.sh
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001324 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001325}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001326
Gilles Peskine69f190e2019-01-10 00:11:42 +01001327component_test_valgrind () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001328 msg "build: Release (clang)"
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001329 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
1330 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001331
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001332 msg "test: main suites valgrind (Release)"
1333 make memcheck
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001334
Gilles Peskinef1349e42019-04-08 17:00:56 +02001335 # Optional parts (slow; currently broken on OS X because programs don't
1336 # seem to receive signals under valgrind on OS X).
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001337 if [ "$MEMORY" -gt 0 ]; then
1338 msg "test: ssl-opt.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +01001339 if_build_succeeded tests/ssl-opt.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001340 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001341
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001342 if [ "$MEMORY" -gt 1 ]; then
1343 msg "test: compat.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +01001344 if_build_succeeded tests/compat.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001345 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001346}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001347
Gilles Peskine8f073122018-11-27 15:58:47 +01001348component_test_cmake_out_of_source () {
1349 msg "build: cmake 'out-of-source' build"
Gilles Peskine8f073122018-11-27 15:58:47 +01001350 MBEDTLS_ROOT_DIR="$PWD"
1351 mkdir "$OUT_OF_SOURCE_DIR"
1352 cd "$OUT_OF_SOURCE_DIR"
1353 cmake "$MBEDTLS_ROOT_DIR"
1354 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001355
Gilles Peskine8f073122018-11-27 15:58:47 +01001356 msg "test: cmake 'out-of-source' build"
1357 make test
1358 # Test an SSL option that requires an auxiliary script in test/scripts/.
1359 # Also ensure that there are no error messages such as
1360 # "No such file or directory", which would indicate that some required
1361 # file is missing (ssl-opt.sh tolerates the absence of some files so
1362 # may exit with status 0 but emit errors).
1363 if_build_succeeded ./tests/ssl-opt.sh -f 'Fallback SCSV: beginning of list' 2>ssl-opt.err
1364 if [ -s ssl-opt.err ]; then
1365 cat ssl-opt.err >&2
1366 record_status [ ! -s ssl-opt.err ]
1367 rm ssl-opt.err
1368 fi
1369 cd "$MBEDTLS_ROOT_DIR"
1370 rm -rf "$OUT_OF_SOURCE_DIR"
1371 unset MBEDTLS_ROOT_DIR
1372}
Andres AGdc192212016-08-31 17:33:13 +01001373
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01001374component_test_cmake_as_subdirectory () {
1375 msg "build: cmake 'as-subdirectory' build"
1376 MBEDTLS_ROOT_DIR="$PWD"
1377
1378 cd programs/test/cmake_subproject
1379 cmake .
1380 make
1381 if_build_succeeded ./cmake_subproject
1382
1383 cd "$MBEDTLS_ROOT_DIR"
1384 unset MBEDTLS_ROOT_DIR
1385}
1386
Gilles Peskine8f073122018-11-27 15:58:47 +01001387component_test_zeroize () {
1388 # Test that the function mbedtls_platform_zeroize() is not optimized away by
1389 # different combinations of compilers and optimization flags by using an
1390 # auxiliary GDB script. Unfortunately, GDB does not return error values to the
1391 # system in all cases that the script fails, so we must manually search the
1392 # output to check whether the pass string is present and no failure strings
1393 # were printed.
Andres AGdc192212016-08-31 17:33:13 +01001394
Gilles Peskine4976e822019-01-06 19:52:22 +00001395 # Don't try to disable ASLR. We don't care about ASLR here. We do care
1396 # about a spurious message if Gdb tries and fails, so suppress that.
1397 gdb_disable_aslr=
1398 if [ -z "$(gdb -batch -nw -ex 'set disable-randomization off' 2>&1)" ]; then
1399 gdb_disable_aslr='set disable-randomization off'
1400 fi
1401
Gilles Peskine8f073122018-11-27 15:58:47 +01001402 for optimization_flag in -O2 -O3 -Ofast -Os; do
Gilles Peskine55f7c942019-01-09 22:28:21 +01001403 for compiler in clang gcc; do
1404 msg "test: $compiler $optimization_flag, mbedtls_platform_zeroize()"
1405 make programs CC="$compiler" DEBUG=1 CFLAGS="$optimization_flag"
Gilles Peskine4976e822019-01-06 19:52:22 +00001406 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 +01001407 if_build_succeeded grep "The buffer was correctly zeroized" test_zeroize.log
1408 if_build_succeeded not grep -i "error" test_zeroize.log
1409 rm -f test_zeroize.log
1410 make clean
1411 done
Andres Amaya Garcia29673812017-10-25 10:35:51 +01001412 done
Andres Amaya Garciad0d7bf62017-10-25 09:01:31 +01001413
Gilles Peskine4976e822019-01-06 19:52:22 +00001414 unset gdb_disable_aslr
Gilles Peskine8f073122018-11-27 15:58:47 +01001415}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001416
Gilles Peskineaad2ebd2019-02-25 20:26:06 +01001417support_check_python_files () {
1418 type pylint3 >/dev/null 2>/dev/null
1419}
Gilles Peskine8f073122018-11-27 15:58:47 +01001420component_check_python_files () {
1421 msg "Lint: Python scripts"
1422 record_status tests/scripts/check-python-files.sh
1423}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001424
Gilles Peskine8f073122018-11-27 15:58:47 +01001425component_check_generate_test_code () {
1426 msg "uint test: generate_test_code.py"
1427 record_status ./tests/scripts/test_generate_test_code.py
1428}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001429
1430################################################################
1431#### Termination
1432################################################################
1433
Gilles Peskine8f073122018-11-27 15:58:47 +01001434post_report () {
1435 msg "Done, cleaning up"
1436 cleanup
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001437
Gilles Peskine8f073122018-11-27 15:58:47 +01001438 final_report
1439}
1440
1441
1442
1443################################################################
1444#### Run all the things
1445################################################################
1446
Gilles Peskinee48351a2018-11-27 16:06:30 +01001447# Run one component and clean up afterwards.
Gilles Peskine8f073122018-11-27 15:58:47 +01001448run_component () {
Gilles Peskine608953e2019-01-02 18:57:02 +01001449 # Back up the configuration in case the component modifies it.
1450 # The cleanup function will restore it.
1451 cp -p "$CONFIG_H" "$CONFIG_BAK"
Gilles Peskineffcdeff2018-12-04 12:49:28 +01001452 current_component="$1"
Gilles Peskine9004a172019-09-16 15:20:36 +02001453 export MBEDTLS_TEST_CONFIGURATION="$current_component"
Gilles Peskine8f073122018-11-27 15:58:47 +01001454 "$@"
Gilles Peskinee48351a2018-11-27 16:06:30 +01001455 cleanup
Gilles Peskine8f073122018-11-27 15:58:47 +01001456}
1457
1458# Preliminary setup
1459pre_check_environment
1460pre_initialize_variables
1461pre_parse_command_line "$@"
Gilles Peskine348fb9a2018-11-27 17:04:29 +01001462
Gilles Peskine878cf602019-01-06 20:50:38 +00001463pre_check_git
Andrzej Kurekeb508712019-02-14 07:18:59 -05001464pre_check_seedfile
1465
Gilles Peskine878cf602019-01-06 20:50:38 +00001466build_status=0
1467if [ $KEEP_GOING -eq 1 ]; then
1468 pre_setup_keep_going
Gilles Peskine92525112018-11-27 18:15:35 +01001469else
Gilles Peskine878cf602019-01-06 20:50:38 +00001470 record_status () {
1471 "$@"
1472 }
Gilles Peskine8f073122018-11-27 15:58:47 +01001473fi
Gilles Peskine67ffdaf2019-09-16 15:55:46 +02001474pre_prepare_outcome_file
Gilles Peskine878cf602019-01-06 20:50:38 +00001475pre_print_configuration
1476pre_check_tools
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001477cleanup
1478
Gilles Peskinebeb3a812019-01-06 22:11:25 +00001479# Run the requested tests.
1480for component in $RUN_COMPONENTS; do
1481 run_component "component_$component"
1482done
Gilles Peskine8f073122018-11-27 15:58:47 +01001483
1484# We're done.
Gilles Peskine878cf602019-01-06 20:50:38 +00001485post_report