blob: 9246eaeafda8e1cb300f89aebd0be160251684a0 [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
Gilles Peskine8fd59422019-10-21 17:11:33 +0200147 # CFLAGS and LDFLAGS for Asan builds that don't use CMake
Gilles Peskine5ca393f2019-10-21 19:06:33 +0200148 ASAN_CFLAGS='-Werror -Wall -Wextra -fsanitize=address,undefined -fno-sanitize-recover=all'
Gilles Peskine8fd59422019-10-21 17:11:33 +0200149
Gilles Peskine878cf602019-01-06 20:50:38 +0000150 # Gather the list of available components. These are the functions
151 # defined in this script whose name starts with "component_".
152 # Parse the script with sed, because in sh there is no way to list
153 # defined functions.
154 ALL_COMPONENTS=$(sed -n 's/^ *component_\([0-9A-Z_a-z]*\) *().*/\1/p' <"$0")
155
156 # Exclude components that are not supported on this platform.
157 SUPPORTED_COMPONENTS=
158 for component in $ALL_COMPONENTS; do
159 case $(type "support_$component" 2>&1) in
160 *' function'*)
161 if ! support_$component; then continue; fi;;
162 esac
163 SUPPORTED_COMPONENTS="$SUPPORTED_COMPONENTS $component"
164 done
Gilles Peskine8f073122018-11-27 15:58:47 +0100165}
Andres AG38495a32016-07-12 16:54:33 +0100166
Gilles Peskinea28db922019-01-10 00:05:18 +0100167# Test whether the component $1 is included in the command line patterns.
168is_component_included()
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100169{
170 set -f
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000171 for pattern in $COMMAND_LINE_COMPONENTS; do
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100172 set +f
173 case ${1#component_} in $pattern) return 0;; esac
174 done
175 set +f
176 return 1
177}
Andres AG7770ea82016-10-10 15:46:20 +0100178
Simon Butcher41eeccf2016-09-07 00:07:09 +0100179usage()
Andres AGd9eba4b2016-08-26 14:42:14 +0100180{
Gilles Peskine709346a2017-12-10 23:43:39 +0100181 cat <<EOF
Gilles Peskine92525112018-11-27 18:15:35 +0100182Usage: $0 [OPTION]... [COMPONENT]...
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100183Run mbedtls release validation tests.
Gilles Peskine92525112018-11-27 18:15:35 +0100184By default, run all tests. With one or more COMPONENT, run only those.
Gilles Peskinea28db922019-01-10 00:05:18 +0100185COMPONENT can be the name of a component or a shell wildcard pattern.
186
187Examples:
188 $0 "check_*"
189 Run all sanity checks.
190 $0 --no-armcc --except test_memsan
191 Run everything except builds that require armcc and MemSan.
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100192
193Special options:
194 -h|--help Print this help and exit.
Gilles Peskine878cf602019-01-06 20:50:38 +0000195 --list-all-components List all available test components and exit.
196 --list-components List components supported on this platform and exit.
Gilles Peskine709346a2017-12-10 23:43:39 +0100197
198General options:
199 -f|--force Force the tests to overwrite any modified files.
Gilles Peskine7c652162017-12-11 00:01:40 +0100200 -k|--keep-going Run all tests and report errors at the end.
Gilles Peskine709346a2017-12-10 23:43:39 +0100201 -m|--memory Additional optional memory tests.
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200202 --append-outcome Append to the outcome file (if used).
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100203 --armcc Run ARM Compiler builds (on by default).
Gilles Peskinea28db922019-01-10 00:05:18 +0100204 --except Exclude the COMPONENTs listed on the command line,
205 instead of running only those.
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200206 --no-append-outcome Write a new outcome file and analyze it (default).
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100207 --no-armcc Skip ARM Compiler builds.
Gilles Peskine38d81652018-03-21 08:40:26 +0100208 --no-force Refuse to overwrite modified files (default).
209 --no-keep-going Stop at the first error (default).
210 --no-memory No additional memory tests (default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100211 --out-of-source-dir=<path> Directory used for CMake out-of-source build tests.
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200212 --outcome-file=<path> File where test outcomes are written (not done if
213 empty; default: \$MBEDTLS_TEST_OUTCOME_FILE).
Gilles Peskine38d81652018-03-21 08:40:26 +0100214 --random-seed Use a random seed value for randomized tests (default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100215 -r|--release-test Run this script in release mode. This fixes the seed value to 1.
216 -s|--seed Integer seed value to use for this test run.
217
218Tool path options:
219 --armc5-bin-dir=<ARMC5_bin_dir_path> ARM Compiler 5 bin directory.
220 --armc6-bin-dir=<ARMC6_bin_dir_path> ARM Compiler 6 bin directory.
221 --gnutls-cli=<GnuTLS_cli_path> GnuTLS client executable to use for most tests.
222 --gnutls-serv=<GnuTLS_serv_path> GnuTLS server executable to use for most tests.
223 --gnutls-legacy-cli=<GnuTLS_cli_path> GnuTLS client executable to use for legacy tests.
224 --gnutls-legacy-serv=<GnuTLS_serv_path> GnuTLS server executable to use for legacy tests.
225 --openssl=<OpenSSL_path> OpenSSL executable to use for most tests.
226 --openssl-legacy=<OpenSSL_path> OpenSSL executable to use for legacy tests e.g. SSLv3.
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100227 --openssl-next=<OpenSSL_path> OpenSSL executable to use for recent things like ARIA
Gilles Peskine709346a2017-12-10 23:43:39 +0100228EOF
SimonB2e23c822016-04-16 21:54:39 +0100229}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100230
231# remove built files as well as the cmake cache/config
232cleanup()
233{
Gilles Peskinea71d64c2018-03-21 12:16:57 +0100234 if [ -n "${MBEDTLS_ROOT_DIR+set}" ]; then
235 cd "$MBEDTLS_ROOT_DIR"
236 fi
237
Gilles Peskine7c652162017-12-11 00:01:40 +0100238 command make clean
Jaeden Ameroed93bdc2018-11-02 16:57:24 +0000239 cd crypto
240 command make clean
241 cd ..
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200242
Gilles Peskine31b07e22018-03-21 12:15:06 +0100243 # Remove CMake artefacts
Jaeden Amero2d0e00f2018-11-07 18:46:41 +0000244 find . -name .git -prune -o \
Gilles Peskine31b07e22018-03-21 12:15:06 +0100245 -iname CMakeFiles -exec rm -rf {} \+ -o \
246 \( -iname cmake_install.cmake -o \
247 -iname CTestTestfile.cmake -o \
248 -iname CMakeCache.txt \) -exec rm {} \+
249 # Recover files overwritten by in-tree CMake builds
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000250 rm -f include/Makefile include/mbedtls/Makefile programs/*/Makefile
Philippe Antoine5dece6d2019-06-27 16:55:07 +0200251 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile
252 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile
Jaeden Ameroed93bdc2018-11-02 16:57:24 +0000253 cd crypto
254 rm -f include/Makefile include/mbedtls/Makefile programs/*/Makefile
255 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile
256 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile
257 cd ..
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200258
Jaeden Ameroab83fdf2019-06-20 17:38:22 +0100259 # Remove any artifacts from the component_test_cmake_as_subdirectory test.
260 rm -rf programs/test/cmake_subproject/build
261 rm -f programs/test/cmake_subproject/Makefile
262 rm -f programs/test/cmake_subproject/cmake_subproject
263
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200264 if [ -f "$CONFIG_BAK" ]; then
265 mv "$CONFIG_BAK" "$CONFIG_H"
266 fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100267}
268
Gilles Peskine7c652162017-12-11 00:01:40 +0100269# Executed on exit. May be redefined depending on command line options.
270final_report () {
271 :
272}
273
274fatal_signal () {
275 cleanup
276 final_report $1
277 trap - $1
278 kill -$1 $$
279}
280
281trap 'fatal_signal HUP' HUP
282trap 'fatal_signal INT' INT
283trap 'fatal_signal TERM' TERM
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200284
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100285msg()
286{
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100287 if [ -n "${current_component:-}" ]; then
288 current_section="${current_component#component_}: $1"
289 else
290 current_section="$1"
291 fi
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100292 echo ""
293 echo "******************************************************************"
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100294 echo "* $current_section "
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000295 printf "* "; date
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100296 echo "******************************************************************"
297}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100298
Gilles Peskine8f073122018-11-27 15:58:47 +0100299armc6_build_test()
300{
301 FLAGS="$1"
Andres AGa5cd9732016-10-17 15:23:10 +0100302
Gilles Peskine8f073122018-11-27 15:58:47 +0100303 msg "build: ARM Compiler 6 ($FLAGS), make"
304 ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \
305 WARNING_CFLAGS='-xc -std=c99' make lib
306 make clean
307}
Andres AGa5cd9732016-10-17 15:23:10 +0100308
Andres AGd9eba4b2016-08-26 14:42:14 +0100309err_msg()
310{
311 echo "$1" >&2
312}
313
314check_tools()
315{
316 for TOOL in "$@"; do
Andres AG98393602017-01-31 17:04:45 +0000317 if ! `type "$TOOL" >/dev/null 2>&1`; then
Andres AGd9eba4b2016-08-26 14:42:14 +0100318 err_msg "$TOOL not found!"
319 exit 1
320 fi
321 done
322}
323
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400324check_headers_in_cpp () {
Peter Kolbus1bc1a4c2019-02-01 17:19:08 -0600325 ls include/mbedtls | grep "\.h$" >headers.txt
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400326 <programs/test/cpp_dummy_build.cpp sed -n 's/"$//; s!^#include "mbedtls/!!p' |
327 sort |
328 diff headers.txt -
329 rm headers.txt
330}
331
Gilles Peskine8f073122018-11-27 15:58:47 +0100332pre_parse_command_line () {
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000333 COMMAND_LINE_COMPONENTS=
Gilles Peskinea28db922019-01-10 00:05:18 +0100334 all_except=0
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000335 no_armcc=
SimonB2e23c822016-04-16 21:54:39 +0100336
Gilles Peskine8f073122018-11-27 15:58:47 +0100337 while [ $# -gt 0 ]; do
Gilles Peskine55f7c942019-01-09 22:28:21 +0100338 case "$1" in
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200339 --append-outcome) append_outcome=1;;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000340 --armcc) no_armcc=;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100341 --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
342 --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000343 --except) all_except=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100344 --force|-f) FORCE=1;;
345 --gnutls-cli) shift; GNUTLS_CLI="$1";;
346 --gnutls-legacy-cli) shift; GNUTLS_LEGACY_CLI="$1";;
347 --gnutls-legacy-serv) shift; GNUTLS_LEGACY_SERV="$1";;
348 --gnutls-serv) shift; GNUTLS_SERV="$1";;
349 --help|-h) usage; exit;;
350 --keep-going|-k) KEEP_GOING=1;;
Gilles Peskine878cf602019-01-06 20:50:38 +0000351 --list-all-components) printf '%s\n' $ALL_COMPONENTS; exit;;
352 --list-components) printf '%s\n' $SUPPORTED_COMPONENTS; exit;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100353 --memory|-m) MEMORY=1;;
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200354 --no-append-outcome) append_outcome=0;;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000355 --no-armcc) no_armcc=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100356 --no-force) FORCE=0;;
357 --no-keep-going) KEEP_GOING=0;;
358 --no-memory) MEMORY=0;;
359 --openssl) shift; OPENSSL="$1";;
360 --openssl-legacy) shift; OPENSSL_LEGACY="$1";;
361 --openssl-next) shift; OPENSSL_NEXT="$1";;
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200362 --outcome-file) shift; MBEDTLS_TEST_OUTCOME_FILE="$1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100363 --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
364 --random-seed) unset SEED;;
365 --release-test|-r) SEED=1;;
366 --seed|-s) shift; SEED="$1";;
367 -*)
368 echo >&2 "Unknown option: $1"
369 echo >&2 "Run $0 --help for usage."
370 exit 120
371 ;;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000372 *) COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS $1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100373 esac
374 shift
Gilles Peskine8f073122018-11-27 15:58:47 +0100375 done
SimonB2e23c822016-04-16 21:54:39 +0100376
Gilles Peskinea28db922019-01-10 00:05:18 +0100377 # With no list of components, run everything.
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000378 if [ -z "$COMMAND_LINE_COMPONENTS" ]; then
379 all_except=1
Andres AGdc192212016-08-31 17:33:13 +0100380 fi
381
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000382 # --no-armcc is a legacy option. The modern way is --except '*_armcc*'.
383 # Ignore it if components are listed explicitly on the command line.
Gilles Peskinea28db922019-01-10 00:05:18 +0100384 if [ -n "$no_armcc" ] && [ $all_except -eq 1 ]; then
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000385 COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS *_armcc*"
SimonB2e23c822016-04-16 21:54:39 +0100386 fi
SimonB2e23c822016-04-16 21:54:39 +0100387
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000388 # Build the list of components to run.
Gilles Peskinea28db922019-01-10 00:05:18 +0100389 RUN_COMPONENTS=
390 for component in $SUPPORTED_COMPONENTS; do
391 if is_component_included "$component"; [ $? -eq $all_except ]; then
392 RUN_COMPONENTS="$RUN_COMPONENTS $component"
393 fi
394 done
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000395
396 unset all_except
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000397 unset no_armcc
Gilles Peskine8f073122018-11-27 15:58:47 +0100398}
SimonB2e23c822016-04-16 21:54:39 +0100399
Gilles Peskine8f073122018-11-27 15:58:47 +0100400pre_check_git () {
401 if [ $FORCE -eq 1 ]; then
Gilles Peskine53190e62019-01-09 23:17:35 +0100402 rm -rf "$OUT_OF_SOURCE_DIR"
Gilles Peskine8f073122018-11-27 15:58:47 +0100403 git checkout-index -f -q $CONFIG_H
404 cleanup
405 else
SimonB2e23c822016-04-16 21:54:39 +0100406
Gilles Peskine8f073122018-11-27 15:58:47 +0100407 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
408 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
409 echo "You can either delete this directory manually, or force the test by rerunning"
410 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
411 exit 1
412 fi
413
Gilles Peskined1174cf2019-01-09 22:30:01 +0100414 if ! git diff --quiet include/mbedtls/config.h; then
Gilles Peskine8f073122018-11-27 15:58:47 +0100415 err_msg "Warning - the configuration file 'include/mbedtls/config.h' has been edited. "
416 echo "You can either delete or preserve your work, or force the test by rerunning the"
417 echo "script as: $0 --force"
418 exit 1
419 fi
SimonB2e23c822016-04-16 21:54:39 +0100420 fi
Andrzej Kureke9c3b812019-02-05 05:34:21 -0500421 if ! [ -f crypto/Makefile ]; then
422 echo "Please initialize the crypto submodule" >&2
423 exit 1
424 fi
Gilles Peskine8f073122018-11-27 15:58:47 +0100425}
SimonB2e23c822016-04-16 21:54:39 +0100426
Andrzej Kurekeb508712019-02-14 07:18:59 -0500427pre_check_seedfile () {
428 if [ ! -f "./tests/seedfile" ]; then
429 dd if=/dev/urandom of=./tests/seedfile bs=32 count=1
430 fi
Jaeden Amero97145102019-03-18 16:31:21 +0000431 if [ ! -f "./crypto/tests/seedfile" ]; then
432 dd if=/dev/urandom of=./crypto/tests/seedfile bs=32 count=1
433 fi
Andrzej Kurekeb508712019-02-14 07:18:59 -0500434}
435
Gilles Peskine8f073122018-11-27 15:58:47 +0100436pre_setup_keep_going () {
Gilles Peskine7c652162017-12-11 00:01:40 +0100437 failure_summary=
438 failure_count=0
439 start_red=
440 end_color=
441 if [ -t 1 ]; then
Gilles Peskine9736b9d2018-01-02 21:54:17 +0100442 case "${TERM:-}" in
Gilles Peskine7c652162017-12-11 00:01:40 +0100443 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
444 start_red=$(printf '\033[31m')
445 end_color=$(printf '\033[0m')
446 ;;
447 esac
448 fi
449 record_status () {
450 if "$@"; then
451 last_status=0
452 else
453 last_status=$?
454 text="$current_section: $* -> $last_status"
455 failure_summary="$failure_summary
456$text"
457 failure_count=$((failure_count + 1))
458 echo "${start_red}^^^^$text^^^^${end_color}"
459 fi
460 }
461 make () {
462 case "$*" in
463 *test|*check)
464 if [ $build_status -eq 0 ]; then
465 record_status command make "$@"
466 else
467 echo "(skipped because the build failed)"
468 fi
469 ;;
470 *)
471 record_status command make "$@"
472 build_status=$last_status
473 ;;
474 esac
475 }
476 final_report () {
477 if [ $failure_count -gt 0 ]; then
478 echo
479 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
480 echo "${start_red}FAILED: $failure_count${end_color}$failure_summary"
481 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Jaeden Amero7c1258d2018-07-20 16:42:14 +0100482 exit 1
Gilles Peskine7c652162017-12-11 00:01:40 +0100483 elif [ -z "${1-}" ]; then
484 echo "SUCCESS :)"
485 fi
486 if [ -n "${1-}" ]; then
487 echo "Killed by SIG$1."
488 fi
489 }
Gilles Peskine8f073122018-11-27 15:58:47 +0100490}
491
Gilles Peskine7c652162017-12-11 00:01:40 +0100492if_build_succeeded () {
493 if [ $build_status -eq 0 ]; then
494 record_status "$@"
495 fi
496}
497
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200498# to be used instead of ! for commands run with
499# record_status or if_build_succeeded
500not() {
501 ! "$@"
502}
503
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200504pre_prepare_outcome_file () {
505 case "$MBEDTLS_TEST_OUTCOME_FILE" in
506 [!/]*) MBEDTLS_TEST_OUTCOME_FILE="$PWD/$MBEDTLS_TEST_OUTCOME_FILE";;
507 esac
508 if [ -n "$MBEDTLS_TEST_OUTCOME_FILE" ] && [ "$append_outcome" -eq 0 ]; then
509 rm -f "$MBEDTLS_TEST_OUTCOME_FILE"
510 fi
511}
512
Gilles Peskine8f073122018-11-27 15:58:47 +0100513pre_print_configuration () {
514 msg "info: $0 configuration"
515 echo "MEMORY: $MEMORY"
516 echo "FORCE: $FORCE"
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200517 echo "MBEDTLS_TEST_OUTCOME_FILE: ${MBEDTLS_TEST_OUTCOME_FILE:-(none)}"
Gilles Peskine8f073122018-11-27 15:58:47 +0100518 echo "SEED: ${SEED-"UNSET"}"
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200519 echo
Gilles Peskine8f073122018-11-27 15:58:47 +0100520 echo "OPENSSL: $OPENSSL"
521 echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
522 echo "OPENSSL_NEXT: $OPENSSL_NEXT"
523 echo "GNUTLS_CLI: $GNUTLS_CLI"
524 echo "GNUTLS_SERV: $GNUTLS_SERV"
525 echo "GNUTLS_LEGACY_CLI: $GNUTLS_LEGACY_CLI"
526 echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV"
527 echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
528 echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
529}
Andres AG7770ea82016-10-10 15:46:20 +0100530
Andres AGd9eba4b2016-08-26 14:42:14 +0100531# Make sure the tools we need are available.
Gilles Peskine8f073122018-11-27 15:58:47 +0100532pre_check_tools () {
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000533 # Build the list of variables to pass to output_env.sh.
534 set env
SimonB2e23c822016-04-16 21:54:39 +0100535
Gilles Peskine87964262019-01-06 22:40:00 +0000536 case " $RUN_COMPONENTS " in
537 # Require OpenSSL and GnuTLS if running any tests (as opposed to
538 # only doing builds). Not all tests run OpenSSL and GnuTLS, but this
539 # is a good enough approximation in practice.
540 *" test_"*)
541 # To avoid setting OpenSSL and GnuTLS for each call to compat.sh
542 # and ssl-opt.sh, we just export the variables they require.
543 export OPENSSL_CMD="$OPENSSL"
544 export GNUTLS_CLI="$GNUTLS_CLI"
545 export GNUTLS_SERV="$GNUTLS_SERV"
546 # Avoid passing --seed flag in every call to ssl-opt.sh
547 if [ -n "${SEED-}" ]; then
548 export SEED
549 fi
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000550 set "$@" OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY"
551 set "$@" GNUTLS_CLI="$GNUTLS_CLI" GNUTLS_SERV="$GNUTLS_SERV"
552 set "$@" GNUTLS_LEGACY_CLI="$GNUTLS_LEGACY_CLI"
553 set "$@" GNUTLS_LEGACY_SERV="$GNUTLS_LEGACY_SERV"
Gilles Peskine87964262019-01-06 22:40:00 +0000554 check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$OPENSSL_NEXT" \
555 "$GNUTLS_CLI" "$GNUTLS_SERV" \
556 "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV"
557 ;;
558 esac
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200559
Gilles Peskine87964262019-01-06 22:40:00 +0000560 case " $RUN_COMPONENTS " in
561 *_doxygen[_\ ]*) check_tools "doxygen" "dot";;
562 esac
Andres AGd9eba4b2016-08-26 14:42:14 +0100563
Gilles Peskine87964262019-01-06 22:40:00 +0000564 case " $RUN_COMPONENTS " in
565 *_arm_none_eabi_gcc[_\ ]*) check_tools "arm-none-eabi-gcc";;
566 esac
Andres AGd9eba4b2016-08-26 14:42:14 +0100567
Gilles Peskine87964262019-01-06 22:40:00 +0000568 case " $RUN_COMPONENTS " in
569 *_mingw[_\ ]*) check_tools "i686-w64-mingw32-gcc";;
570 esac
571
572 case " $RUN_COMPONENTS " in
573 *" test_zeroize "*) check_tools "gdb";;
574 esac
575
576 case " $RUN_COMPONENTS " in
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000577 *_armcc*)
Gilles Peskine87964262019-01-06 22:40:00 +0000578 ARMC5_CC="$ARMC5_BIN_DIR/armcc"
579 ARMC5_AR="$ARMC5_BIN_DIR/armar"
580 ARMC6_CC="$ARMC6_BIN_DIR/armclang"
581 ARMC6_AR="$ARMC6_BIN_DIR/armar"
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000582 check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC6_CC" "$ARMC6_AR";;
583 esac
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000584
585 msg "info: output_env.sh"
586 case $RUN_COMPONENTS in
587 *_armcc*)
588 set "$@" ARMC5_CC="$ARMC5_CC" ARMC6_CC="$ARMC6_CC" RUN_ARMCC=1;;
589 *) set "$@" RUN_ARMCC=0;;
590 esac
591 "$@" scripts/output_env.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100592}
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100593
Gilles Peskine192c72f2017-12-21 15:59:21 +0100594
595
596################################################################
597#### Basic checks
598################################################################
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100599
600#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200601# Test Suites to be executed
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100602#
Manuel Pégourié-Gonnard3d404b42015-07-08 21:59:16 +0100603# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200604# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100605# 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 +0200606# time, so start with a GCC build).
607# 2. Minimize total running time, by avoiding useless rebuilds
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100608#
Manuel Pégourié-Gonnard259b08a2016-01-08 16:27:41 +0100609# Indicative running times are given for reference.
610
Gilles Peskine8f073122018-11-27 15:58:47 +0100611component_check_recursion () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200612 msg "Check: recursion.pl" # < 1s
Gilles Peskine8f073122018-11-27 15:58:47 +0100613 record_status tests/scripts/recursion.pl library/*.c
614}
Janos Follathb72c6782016-07-19 14:54:17 +0100615
Gilles Peskine8f073122018-11-27 15:58:47 +0100616component_check_generated_files () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200617 msg "Check: freshness of generated source files" # < 1s
Gilles Peskine8f073122018-11-27 15:58:47 +0100618 record_status tests/scripts/check-generated-files.sh
619}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200620
Gilles Peskine8f073122018-11-27 15:58:47 +0100621component_check_doxy_blocks () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200622 msg "Check: doxygen markup outside doxygen blocks" # < 1s
Gilles Peskine8f073122018-11-27 15:58:47 +0100623 record_status tests/scripts/check-doxy-blocks.pl
624}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200625
Gilles Peskine8f073122018-11-27 15:58:47 +0100626component_check_files () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200627 msg "Check: file sanity checks (permissions, encodings)" # < 1s
Gilles Peskine8f073122018-11-27 15:58:47 +0100628 record_status tests/scripts/check-files.py
629}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200630
Gilles Peskine8f073122018-11-27 15:58:47 +0100631component_check_names () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200632 msg "Check: declared and exported names (builds the library)" # < 3s
Gilles Peskine13f97dc2019-05-15 17:52:22 +0200633 record_status tests/scripts/check-names.sh -v
Gilles Peskine8f073122018-11-27 15:58:47 +0100634}
Darryl Greena07039c2018-03-13 16:48:16 +0000635
Gilles Peskine895868b2019-09-19 21:30:05 +0200636component_check_test_cases () {
637 msg "Check: test case descriptions" # < 1s
638 record_status tests/scripts/check-test-cases.py
639}
640
Gilles Peskine8f073122018-11-27 15:58:47 +0100641component_check_doxygen_warnings () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200642 msg "Check: doxygen warnings (builds the documentation)" # ~ 3s
Gilles Peskine8f073122018-11-27 15:58:47 +0100643 record_status tests/scripts/doxygen.sh
644}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200645
Gilles Peskine192c72f2017-12-21 15:59:21 +0100646
647
648################################################################
649#### Build and test many configurations and targets
650################################################################
651
Gilles Peskine7832c9f2019-04-08 17:00:15 +0200652component_test_default_out_of_box () {
653 msg "build: make, default config (out-of-box)" # ~1min
654 make
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200655 # Disable fancy stuff
Gilles Peskine717cd762019-09-27 20:21:11 +0200656 SAVE_MBEDTLS_TEST_OUTCOME_FILE="$MBEDTLS_TEST_OUTCOME_FILE"
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200657 unset MBEDTLS_TEST_OUTCOME_FILE
Gilles Peskine7832c9f2019-04-08 17:00:15 +0200658
659 msg "test: main suites make, default config (out-of-box)" # ~10s
660 make test
661
662 msg "selftest: make, default config (out-of-box)" # ~10s
663 programs/test/selftest
Gilles Peskine717cd762019-09-27 20:21:11 +0200664
665 export MBEDTLS_TEST_OUTCOME_FILE="$SAVE_MBEDTLS_TEST_OUTCOME_FILE"
666 unset SAVE_MBEDTLS_TEST_OUTCOME_FILE
Gilles Peskine7832c9f2019-04-08 17:00:15 +0200667}
668
Gilles Peskine8f073122018-11-27 15:58:47 +0100669component_test_default_cmake_gcc_asan () {
670 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100671 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
672 make
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200673
Gilles Peskine8f073122018-11-27 15:58:47 +0100674 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
675 make test
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200676
Gilles Peskine8f073122018-11-27 15:58:47 +0100677 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
678 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200679
Gilles Peskine8f073122018-11-27 15:58:47 +0100680 msg "test: compat.sh (ASan build)" # ~ 6 min
681 if_build_succeeded tests/compat.sh
682}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200683
Hanno Becker01635512019-02-26 14:27:09 +0000684component_test_full_cmake_gcc_asan () {
685 msg "build: full config, cmake, gcc, ASan"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200686 scripts/config.py full
Hanno Becker01635512019-02-26 14:27:09 +0000687 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
688 make
689
690 msg "test: main suites (inc. selftests) (full config, ASan build)"
691 make test
692
693 msg "test: ssl-opt.sh (full config, ASan build)"
694 if_build_succeeded tests/ssl-opt.sh
695
696 msg "test: compat.sh (full config, ASan build)"
697 if_build_succeeded tests/compat.sh
698}
699
Manuel Pégourié-Gonnard95e04492020-01-02 11:45:12 +0100700component_test_zlib_make() {
701 msg "build: zlib enabled, make"
702 scripts/config.py set MBEDTLS_ZLIB_SUPPORT
703 make ZLIB=1 CFLAGS='-Werror -O1'
704
705 msg "test: main suites (zlib, make)"
706 make test
707
708 msg "test: ssl-opt.sh (zlib, make)"
709 if_build_succeeded tests/ssl-opt.sh
710}
Manuel Pégourié-Gonnardf2e29022020-01-24 10:17:20 +0100711support_test_zlib_make () {
712 base=support_test_zlib_$$
713 cat <<'EOF' > ${base}.c
714#include "zlib.h"
715int main(void) { return 0; }
716EOF
717 gcc -o ${base}.exe ${base}.c -lz 2>/dev/null
718 ret=$?
719 rm -f ${base}.*
720 return $ret
721}
Manuel Pégourié-Gonnard95e04492020-01-02 11:45:12 +0100722
723component_test_zlib_cmake() {
724 msg "build: zlib enabled, cmake"
725 scripts/config.py set MBEDTLS_ZLIB_SUPPORT
726 cmake -D ENABLE_ZLIB_SUPPORT=On -D CMAKE_BUILD_TYPE:String=Check .
727 make
728
729 msg "test: main suites (zlib, cmake)"
730 make test
731
732 msg "test: ssl-opt.sh (zlib, cmake)"
733 if_build_succeeded tests/ssl-opt.sh
734}
Manuel Pégourié-Gonnardf2e29022020-01-24 10:17:20 +0100735support_test_zlib_cmake () {
736 support_test_zlib_make "$@"
737}
Manuel Pégourié-Gonnard95e04492020-01-02 11:45:12 +0100738
Gilles Peskine782f4112018-11-27 16:11:09 +0100739component_test_ref_configs () {
740 msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
741 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
742 record_status tests/scripts/test-ref-configs.pl
743}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200744
Gilles Peskine8f073122018-11-27 15:58:47 +0100745component_test_sslv3 () {
746 msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200747 scripts/config.py set MBEDTLS_SSL_PROTO_SSL3
Gilles Peskine8f073122018-11-27 15:58:47 +0100748 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
749 make
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200750
Gilles Peskine8f073122018-11-27 15:58:47 +0100751 msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
752 make test
Simon Butcher3ea7f522016-03-07 23:22:10 +0000753
Gilles Peskine8f073122018-11-27 15:58:47 +0100754 msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
755 if_build_succeeded tests/compat.sh -m 'tls1 tls1_1 tls1_2 dtls1 dtls1_2'
756 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
Simon Butcher3ea7f522016-03-07 23:22:10 +0000757
Gilles Peskine8f073122018-11-27 15:58:47 +0100758 msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
759 if_build_succeeded tests/ssl-opt.sh
760}
Simon Butcher3ea7f522016-03-07 23:22:10 +0000761
Gilles Peskine8f073122018-11-27 15:58:47 +0100762component_test_no_renegotiation () {
763 msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200764 scripts/config.py unset MBEDTLS_SSL_RENEGOTIATION
Gilles Peskine8f073122018-11-27 15:58:47 +0100765 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
766 make
Simon Butcher3ea7f522016-03-07 23:22:10 +0000767
Gilles Peskine8f073122018-11-27 15:58:47 +0100768 msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
769 make test
Hanno Becker134c2ab2017-10-12 15:29:50 +0100770
Gilles Peskine8f073122018-11-27 15:58:47 +0100771 msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
772 if_build_succeeded tests/ssl-opt.sh
773}
Hanno Becker134c2ab2017-10-12 15:29:50 +0100774
Hanno Beckera545be22019-05-10 14:45:37 +0100775component_test_no_pem_no_fs () {
776 msg "build: Default + !MBEDTLS_PEM_PARSE_C + !MBEDTLS_FS_IO (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200777 scripts/config.py unset MBEDTLS_PEM_PARSE_C
778 scripts/config.py unset MBEDTLS_FS_IO
Hanno Beckera545be22019-05-10 14:45:37 +0100779 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
780 make
781
782 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - main suites (inc. selftests) (ASan build)" # ~ 50s
783 make test
784
785 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - ssl-opt.sh (ASan build)" # ~ 6 min
786 if_build_succeeded tests/ssl-opt.sh
787}
788
Gilles Peskine8f073122018-11-27 15:58:47 +0100789component_test_rsa_no_crt () {
790 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200791 scripts/config.py set MBEDTLS_RSA_NO_CRT
Gilles Peskine8f073122018-11-27 15:58:47 +0100792 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
793 make
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +0100794
Gilles Peskine8f073122018-11-27 15:58:47 +0100795 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
796 make test
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100797
Gilles Peskine8f073122018-11-27 15:58:47 +0100798 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
799 if_build_succeeded tests/ssl-opt.sh -f RSA
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100800
Gilles Peskine8f073122018-11-27 15:58:47 +0100801 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
802 if_build_succeeded tests/compat.sh -t RSA
803}
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100804
Gilles Peskine0c6b7992019-04-12 20:29:48 +0200805component_test_everest () {
806 msg "build: Everest ECDH context (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200807 scripts/config.py unset MBEDTLS_ECDH_LEGACY_CONTEXT
808 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
Gilles Peskine0c6b7992019-04-12 20:29:48 +0200809 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Asan .
810 make
811
812 msg "test: Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
813 make test
814
815 msg "test: Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
816 if_build_succeeded tests/ssl-opt.sh -f ECDH
817
818 msg "test: Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
819 # Exclude some symmetric ciphers that are redundant here to gain time.
820 if_build_succeeded tests/compat.sh -f ECDH -V NO -e 'ARCFOUR\|ARIA\|CAMELLIA\|CHACHA\|DES\|RC4'
821}
822
Gilles Peskine8f073122018-11-27 15:58:47 +0100823component_test_small_ssl_out_content_len () {
824 msg "build: small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200825 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 16384
826 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
Gilles Peskine8f073122018-11-27 15:58:47 +0100827 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
828 make
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100829
Gilles Peskine8f073122018-11-27 15:58:47 +0100830 msg "test: small SSL_OUT_CONTENT_LEN - ssl-opt.sh MFL and large packet tests"
831 if_build_succeeded tests/ssl-opt.sh -f "Max fragment\|Large packet"
832}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000833
Gilles Peskine8f073122018-11-27 15:58:47 +0100834component_test_small_ssl_in_content_len () {
835 msg "build: small SSL_IN_CONTENT_LEN (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200836 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 4096
837 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 16384
Gilles Peskine8f073122018-11-27 15:58:47 +0100838 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
839 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000840
Gilles Peskine8f073122018-11-27 15:58:47 +0100841 msg "test: small SSL_IN_CONTENT_LEN - ssl-opt.sh MFL tests"
842 if_build_succeeded tests/ssl-opt.sh -f "Max fragment"
843}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000844
Gilles Peskine8f073122018-11-27 15:58:47 +0100845component_test_small_ssl_dtls_max_buffering () {
846 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200847 scripts/config.py set MBEDTLS_SSL_DTLS_MAX_BUFFERING 1000
Gilles Peskine8f073122018-11-27 15:58:47 +0100848 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
849 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000850
Gilles Peskine8f073122018-11-27 15:58:47 +0100851 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0 - ssl-opt.sh specific reordering test"
852 if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer out-of-order hs msg before reassembling next, free buffered msg"
853}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100854
Gilles Peskine8f073122018-11-27 15:58:47 +0100855component_test_small_mbedtls_ssl_dtls_max_buffering () {
856 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200857 scripts/config.py set MBEDTLS_SSL_DTLS_MAX_BUFFERING 190
Gilles Peskine8f073122018-11-27 15:58:47 +0100858 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
859 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100860
Gilles Peskine8f073122018-11-27 15:58:47 +0100861 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1 - ssl-opt.sh specific reordering test"
862 if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer encrypted Finished message, drop for fragmented NewSessionTicket"
863}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100864
Gilles Peskine8f073122018-11-27 15:58:47 +0100865component_test_full_cmake_clang () {
866 msg "build: cmake, full config, clang" # ~ 50s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200867 scripts/config.py full
Gilles Peskine8f073122018-11-27 15:58:47 +0100868 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check -D ENABLE_TESTING=On .
869 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100870
Gilles Peskine8f073122018-11-27 15:58:47 +0100871 msg "test: main suites (full config)" # ~ 5s
872 make test
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100873
Gilles Peskine8f073122018-11-27 15:58:47 +0100874 msg "test: ssl-opt.sh default, ECJPAKE, SSL async (full config)" # ~ 1s
875 if_build_succeeded tests/ssl-opt.sh -f 'Default\|ECJPAKE\|SSL async private'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200876
Andres Amaya Garcia2dadab72019-01-08 21:42:27 +0000877 msg "test: compat.sh RC4, DES, 3DES & NULL (full config)" # ~ 2 min
Andres Amaya Garcia419bd002019-02-19 20:20:57 +0000878 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 +0200879
Gilles Peskine8f073122018-11-27 15:58:47 +0100880 msg "test: compat.sh ARIA + ChachaPoly"
881 if_build_succeeded env OPENSSL_CMD="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
882}
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200883
Gilles Peskine8f073122018-11-27 15:58:47 +0100884component_build_deprecated () {
885 msg "build: make, full config + DEPRECATED_WARNING, gcc -O" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200886 scripts/config.py full
887 scripts/config.py set MBEDTLS_DEPRECATED_WARNING
Gilles Peskine8f073122018-11-27 15:58:47 +0100888 # Build with -O -Wextra to catch a maximum of issues.
889 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra' lib programs
890 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100891
Gilles Peskine8f073122018-11-27 15:58:47 +0100892 msg "build: make, full config + DEPRECATED_REMOVED, clang -O" # ~ 30s
893 # No cleanup, just tweak the configuration and rebuild
894 make clean
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200895 scripts/config.py unset MBEDTLS_DEPRECATED_WARNING
896 scripts/config.py set MBEDTLS_DEPRECATED_REMOVED
Gilles Peskine8f073122018-11-27 15:58:47 +0100897 # Build with -O -Wextra to catch a maximum of issues.
898 make CC=clang CFLAGS='-O -Werror -Wall -Wextra' lib programs
899 make CC=clang CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
900}
Jaeden Ameroed93bdc2018-11-02 16:57:24 +0000901
Gilles Peskineec541fe2020-01-31 14:24:14 +0100902# Check that the specified libraries exist and are empty.
903are_empty_libraries () {
904 nm "$@" >/dev/null 2>/dev/null
905 ! nm "$@" 2>/dev/null | grep -v ':$' | grep .
906}
907
908component_build_crypto_default () {
909 msg "build: make, crypto only"
910 scripts/config.py crypto
Gilles Peskine6bb39152020-02-03 11:59:20 +0100911 make CFLAGS='-O1 -Werror'
Gilles Peskineec541fe2020-01-31 14:24:14 +0100912 if_build_succeeded are_empty_libraries library/libmbedx509.* library/libmbedtls.*
913}
914
915component_build_crypto_full () {
916 msg "build: make, crypto only, full config"
917 scripts/config.py crypto_full
Gilles Peskine6bb39152020-02-03 11:59:20 +0100918 make CFLAGS='-O1 -Werror'
Gilles Peskineec541fe2020-01-31 14:24:14 +0100919 if_build_succeeded are_empty_libraries library/libmbedx509.* library/libmbedtls.*
920}
921
922component_build_crypto_baremetal () {
923 msg "build: make, crypto only, baremetal config"
924 scripts/config.py crypto_baremetal
Gilles Peskine6bb39152020-02-03 11:59:20 +0100925 make CFLAGS='-O1 -Werror'
Gilles Peskineec541fe2020-01-31 14:24:14 +0100926 if_build_succeeded are_empty_libraries library/libmbedx509.* library/libmbedtls.*
927}
928
Gilles Peskine8f073122018-11-27 15:58:47 +0100929component_test_depends_curves () {
930 msg "test/build: curves.pl (gcc)" # ~ 4 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100931 record_status tests/scripts/curves.pl
932}
Jaeden Ameroacaabe72018-11-07 11:52:52 +0000933
Gilles Peskine8f073122018-11-27 15:58:47 +0100934component_test_depends_hashes () {
935 msg "test/build: depends-hashes.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100936 record_status tests/scripts/depends-hashes.pl
937}
Jaeden Ameroacaabe72018-11-07 11:52:52 +0000938
Gilles Peskine8f073122018-11-27 15:58:47 +0100939component_test_depends_pkalgs () {
940 msg "test/build: depends-pkalgs.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100941 record_status tests/scripts/depends-pkalgs.pl
942}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100943
Gilles Peskine8f073122018-11-27 15:58:47 +0100944component_build_key_exchanges () {
945 msg "test/build: key-exchanges (gcc)" # ~ 1 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100946 record_status tests/scripts/key-exchanges.pl
947}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100948
Gilles Peskine8f073122018-11-27 15:58:47 +0100949component_build_default_make_gcc_and_cxx () {
950 msg "build: Unix make, -Os (gcc)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100951 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100952
Gilles Peskine8f073122018-11-27 15:58:47 +0100953 msg "test: verify header list in cpp_dummy_build.cpp"
954 record_status check_headers_in_cpp
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100955
Gilles Peskine8f073122018-11-27 15:58:47 +0100956 msg "build: Unix make, incremental g++"
957 make TEST_CPP=1
958}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100959
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100960component_test_no_use_psa_crypto_full_cmake_asan() {
961 # full minus MBEDTLS_USE_PSA_CRYPTO: run the same set of tests as basic-build-test.sh
Gilles Peskinedc3a1792019-09-03 11:42:04 +0200962 msg "build: cmake, full config minus MBEDTLS_USE_PSA_CRYPTO, ASan"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200963 scripts/config.py full
964 scripts/config.py set MBEDTLS_ECP_RESTARTABLE # not using PSA, so enable restartable ECC
965 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C
966 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
967 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C
968 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
Manuel Pégourié-Gonnardd8167e82019-02-01 11:12:52 +0100969 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500970 make
Manuel Pégourié-Gonnard43be6cd2017-06-20 09:53:42 +0200971
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100972 msg "test: main suites (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500973 make test
Manuel Pégourié-Gonnard503a5ef2015-10-23 09:04:45 +0200974
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100975 msg "test: ssl-opt.sh (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500976 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100977
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100978 msg "test: compat.sh default (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500979 if_build_succeeded tests/compat.sh
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400980
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100981 msg "test: compat.sh RC4, DES & NULL (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500982 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 -0500983
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100984 msg "test: compat.sh ARIA + ChachaPoly (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500985 if_build_succeeded env OPENSSL_CMD="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
986}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500987
Gilles Peskineadcde5e2019-06-12 16:05:50 +0200988component_test_check_params_functionality () {
989 msg "build+test: MBEDTLS_CHECK_PARAMS functionality"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200990 scripts/config.py full # includes CHECK_PARAMS
Gilles Peskineadcde5e2019-06-12 16:05:50 +0200991 # Make MBEDTLS_PARAM_FAILED call mbedtls_param_failed().
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200992 scripts/config.py unset MBEDTLS_CHECK_PARAMS_ASSERT
Gilles Peskineadcde5e2019-06-12 16:05:50 +0200993 # Only build and run tests. Do not build sample programs, because
994 # they don't have a mbedtls_param_failed() function.
995 make CC=gcc CFLAGS='-Werror -O1' lib test
996}
997
Gilles Peskineb28636b2019-01-02 19:06:24 +0100998component_test_check_params_without_platform () {
999 msg "build+test: MBEDTLS_CHECK_PARAMS without MBEDTLS_PLATFORM_C"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001000 scripts/config.py full # includes CHECK_PARAMS
Gilles Peskineadcde5e2019-06-12 16:05:50 +02001001 # Keep MBEDTLS_PARAM_FAILED as assert.
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001002 scripts/config.py unset MBEDTLS_PLATFORM_EXIT_ALT
1003 scripts/config.py unset MBEDTLS_PLATFORM_TIME_ALT
1004 scripts/config.py unset MBEDTLS_PLATFORM_FPRINTF_ALT
1005 scripts/config.py unset MBEDTLS_PLATFORM_MEMORY
1006 scripts/config.py unset MBEDTLS_PLATFORM_PRINTF_ALT
1007 scripts/config.py unset MBEDTLS_PLATFORM_SNPRINTF_ALT
1008 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
1009 scripts/config.py unset MBEDTLS_PLATFORM_C
Gilles Peskineb28636b2019-01-02 19:06:24 +01001010 make CC=gcc CFLAGS='-Werror -O1' all test
1011}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -05001012
Gilles Peskineb28636b2019-01-02 19:06:24 +01001013component_test_check_params_silent () {
1014 msg "build+test: MBEDTLS_CHECK_PARAMS with alternative MBEDTLS_PARAM_FAILED()"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001015 scripts/config.py full # includes CHECK_PARAMS
Gilles Peskineadcde5e2019-06-12 16:05:50 +02001016 # Set MBEDTLS_PARAM_FAILED to nothing.
Gilles Peskineb28636b2019-01-02 19:06:24 +01001017 sed -i 's/.*\(#define MBEDTLS_PARAM_FAILED( cond )\).*/\1/' "$CONFIG_H"
1018 make CC=gcc CFLAGS='-Werror -O1' all test
1019}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -05001020
Gilles Peskine8f073122018-11-27 15:58:47 +01001021component_test_no_platform () {
1022 # Full configuration build, without platform support, file IO and net sockets.
1023 # This should catch missing mbedtls_printf definitions, and by disabling file
1024 # IO, it should catch missing '#include <stdio.h>'
1025 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001026 scripts/config.py full
1027 scripts/config.py unset MBEDTLS_PLATFORM_C
1028 scripts/config.py unset MBEDTLS_NET_C
1029 scripts/config.py unset MBEDTLS_PLATFORM_MEMORY
1030 scripts/config.py unset MBEDTLS_PLATFORM_PRINTF_ALT
1031 scripts/config.py unset MBEDTLS_PLATFORM_FPRINTF_ALT
1032 scripts/config.py unset MBEDTLS_PLATFORM_SNPRINTF_ALT
1033 scripts/config.py unset MBEDTLS_PLATFORM_TIME_ALT
1034 scripts/config.py unset MBEDTLS_PLATFORM_EXIT_ALT
1035 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
1036 scripts/config.py unset MBEDTLS_FS_IO
1037 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
1038 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C
Gilles Peskine8f073122018-11-27 15:58:47 +01001039 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
1040 # to re-enable platform integration features otherwise disabled in C99 builds
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02001041 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -Os -D_DEFAULT_SOURCE' lib programs
1042 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os' test
Gilles Peskine8f073122018-11-27 15:58:47 +01001043}
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +00001044
Gilles Peskine8f073122018-11-27 15:58:47 +01001045component_build_no_std_function () {
1046 # catch compile bugs in _uninit functions
1047 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001048 scripts/config.py full
1049 scripts/config.py set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
1050 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02001051 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Gilles Peskine8f073122018-11-27 15:58:47 +01001052}
Manuel Pégourié-Gonnarddccb80b2015-06-03 10:20:33 +01001053
Gilles Peskine8f073122018-11-27 15:58:47 +01001054component_build_no_ssl_srv () {
1055 msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001056 scripts/config.py full
1057 scripts/config.py unset MBEDTLS_SSL_SRV_C
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02001058 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
Gilles Peskine8f073122018-11-27 15:58:47 +01001059}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +02001060
Gilles Peskine8f073122018-11-27 15:58:47 +01001061component_build_no_ssl_cli () {
1062 msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001063 scripts/config.py full
1064 scripts/config.py unset MBEDTLS_SSL_CLI_C
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02001065 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
Gilles Peskine8f073122018-11-27 15:58:47 +01001066}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +02001067
Gilles Peskine8f073122018-11-27 15:58:47 +01001068component_build_no_sockets () {
1069 # Note, C99 compliance can also be tested with the sockets support disabled,
1070 # as that requires a POSIX platform (which isn't the same as C99).
1071 msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001072 scripts/config.py full
1073 scripts/config.py unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
1074 scripts/config.py set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02001075 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1 -std=c99 -pedantic' lib
Gilles Peskine8f073122018-11-27 15:58:47 +01001076}
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +02001077
Andrzej Kurek69f20aa2019-09-05 09:27:47 -04001078component_test_memory_buffer_allocator_backtrace () {
1079 msg "build: default config with memory buffer allocator and backtrace enabled"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001080 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
1081 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
1082 scripts/config.py set MBEDTLS_MEMORY_BACKTRACE
1083 scripts/config.py set MBEDTLS_MEMORY_DEBUG
Andrzej Kurek69f20aa2019-09-05 09:27:47 -04001084 CC=gcc cmake .
1085 make
1086
1087 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C and MBEDTLS_MEMORY_BACKTRACE"
1088 make test
1089}
1090
1091component_test_memory_buffer_allocator () {
1092 msg "build: default config with memory buffer allocator"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001093 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
1094 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
Hanno Becker0fb9ba22019-02-26 14:34:13 +00001095 CC=gcc cmake .
1096 make
1097
1098 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C"
1099 make test
1100
1101 msg "test: ssl-opt.sh, MBEDTLS_MEMORY_BUFFER_ALLOC_C"
Andrzej Kurek1e56d2c2019-09-05 10:09:37 -04001102 # MBEDTLS_MEMORY_BUFFER_ALLOC is slow. Skip tests that tend to time out.
1103 if_build_succeeded tests/ssl-opt.sh -e '^DTLS proxy'
Hanno Becker0fb9ba22019-02-26 14:34:13 +00001104}
1105
Gilles Peskine8f073122018-11-27 15:58:47 +01001106component_test_no_max_fragment_length () {
1107 # Run max fragment length tests with MFL disabled
1108 msg "build: default config except MFL extension (ASan build)" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001109 scripts/config.py unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
Gilles Peskine8f073122018-11-27 15:58:47 +01001110 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1111 make
Hanno Becker5175ac62017-09-18 15:36:25 +01001112
Gilles Peskine8f073122018-11-27 15:58:47 +01001113 msg "test: ssl-opt.sh, MFL-related tests"
1114 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length"
1115}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001116
Hanno Becker545ced42019-02-19 11:10:48 +00001117component_test_asan_remove_peer_certificate () {
1118 msg "build: default config with MBEDTLS_SSL_KEEP_PEER_CERTIFICATE disabled (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001119 scripts/config.py unset MBEDTLS_SSL_KEEP_PEER_CERTIFICATE
Hanno Becker545ced42019-02-19 11:10:48 +00001120 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1121 make
1122
1123 msg "test: !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
1124 make test
1125
1126 msg "test: ssl-opt.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
1127 if_build_succeeded tests/ssl-opt.sh
1128
1129 msg "test: compat.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
1130 if_build_succeeded tests/compat.sh
1131}
1132
Gilles Peskine8f073122018-11-27 15:58:47 +01001133component_test_no_max_fragment_length_small_ssl_out_content_len () {
1134 msg "build: no MFL extension, small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001135 scripts/config.py unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
1136 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 16384
1137 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
Gilles Peskine8f073122018-11-27 15:58:47 +01001138 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1139 make
Angus Grattonc4dd0732018-04-11 16:28:39 +10001140
Gilles Peskine8f073122018-11-27 15:58:47 +01001141 msg "test: MFL tests (disabled MFL extension case) & large packet tests"
1142 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length\|Large buffer"
1143}
Angus Grattonc4dd0732018-04-11 16:28:39 +10001144
Darryl Greenaad82f92019-12-02 10:53:11 +00001145component_test_variable_ssl_in_out_buffer_len () {
1146 msg "build: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled (ASan build)"
1147 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
1148 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1149 make
1150
1151 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
1152 make test
1153
1154 msg "test: ssl-opt.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
1155 if_build_succeeded tests/ssl-opt.sh
1156
1157 msg "test: compat.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
1158 if_build_succeeded tests/compat.sh
1159}
1160
1161component_test_variable_ssl_in_out_buffer_len_CID () {
1162 msg "build: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_DTLS_CONNECTION_ID enabled (ASan build)"
1163 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
1164 scripts/config.py set MBEDTLS_SSL_DTLS_CONNECTION_ID
1165
1166 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1167 make
1168
1169 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_DTLS_CONNECTION_ID"
1170 make test
1171
1172 msg "test: ssl-opt.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_DTLS_CONNECTION_ID enabled"
1173 if_build_succeeded tests/ssl-opt.sh
1174
1175 msg "test: compat.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_DTLS_CONNECTION_ID enabled"
1176 if_build_succeeded tests/compat.sh
1177}
1178
1179component_test_variable_ssl_in_out_buffer_len_record_splitting () {
1180 msg "build: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_CBC_RECORD_SPLITTING enabled (ASan build)"
1181 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
1182 scripts/config.py set MBEDTLS_SSL_CBC_RECORD_SPLITTING
1183
1184 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1185 make
1186
1187 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_CBC_RECORD_SPLITTING"
1188 make test
1189
1190 msg "test: ssl-opt.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_CBC_RECORD_SPLITTING enabled"
1191 if_build_succeeded tests/ssl-opt.sh
1192
1193 msg "test: compat.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_CBC_RECORD_SPLITTING enabled"
1194 if_build_succeeded tests/compat.sh
1195}
1196
Piotr Nowicki195a8f72019-11-26 16:32:40 +01001197component_test_ssl_alloc_buffer_and_mfl () {
1198 msg "build: default config with memory buffer allocator and MFL extension"
1199 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
1200 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
1201 scripts/config.py set MBEDTLS_MEMORY_DEBUG
1202 scripts/config.py set MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
1203 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
1204 CC=gcc cmake .
1205 make
1206
1207 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH, MBEDTLS_MEMORY_BUFFER_ALLOC_C, MBEDTLS_MEMORY_DEBUG and MBEDTLS_SSL_MAX_FRAGMENT_LENGTH"
1208 make test
1209
1210 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH, MBEDTLS_MEMORY_BUFFER_ALLOC_C, MBEDTLS_MEMORY_DEBUG and MBEDTLS_SSL_MAX_FRAGMENT_LENGTH"
1211 if_build_succeeded tests/ssl-opt.sh -f "Handshake memory usage"
1212}
1213
Jaeden Amero2de07f12019-06-05 13:32:08 +01001214component_test_when_no_ciphersuites_have_mac () {
1215 msg "build: when no ciphersuites have MAC"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001216 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
1217 scripts/config.py unset MBEDTLS_ARC4_C
1218 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
Jaeden Amero2de07f12019-06-05 13:32:08 +01001219 make
1220
1221 msg "test: !MBEDTLS_SSL_SOME_MODES_USE_MAC"
1222 make test
1223
1224 msg "test ssl-opt.sh: !MBEDTLS_SSL_SOME_MODES_USE_MAC"
Jaeden Amero6b1683d2019-06-05 14:42:50 +01001225 if_build_succeeded tests/ssl-opt.sh -f 'Default\|EtM' -e 'without EtM'
Jaeden Amero2de07f12019-06-05 13:32:08 +01001226}
1227
Gilles Peskine8f073122018-11-27 15:58:47 +01001228component_test_null_entropy () {
1229 msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001230 scripts/config.py set MBEDTLS_TEST_NULL_ENTROPY
1231 scripts/config.py set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
1232 scripts/config.py set MBEDTLS_ENTROPY_C
1233 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
1234 scripts/config.py unset MBEDTLS_ENTROPY_HARDWARE_ALT
1235 scripts/config.py unset MBEDTLS_HAVEGE_C
Gilles Peskine5fa32a72019-01-06 19:48:30 +00001236 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan -D UNSAFE_BUILD=ON .
Gilles Peskine8f073122018-11-27 15:58:47 +01001237 make
Janos Follath06c54002016-06-09 13:57:40 +01001238
Gilles Peskine8f073122018-11-27 15:58:47 +01001239 msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)"
1240 make test
1241}
Janos Follath06c54002016-06-09 13:57:40 +01001242
Gilles Peskine8f073122018-11-27 15:58:47 +01001243component_test_platform_calloc_macro () {
1244 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001245 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
1246 scripts/config.py set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
1247 scripts/config.py set MBEDTLS_PLATFORM_FREE_MACRO free
Gilles Peskine8f073122018-11-27 15:58:47 +01001248 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1249 make
Hanno Beckere5fecec2018-10-11 11:02:52 +01001250
Gilles Peskine8f073122018-11-27 15:58:47 +01001251 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
1252 make test
1253}
Hanno Beckere5fecec2018-10-11 11:02:52 +01001254
Gilles Peskinec4ef7a92019-09-17 19:04:38 +02001255component_test_malloc_0_null () {
1256 msg "build: malloc(0) returns NULL (ASan+UBSan build)"
1257 scripts/config.pl full
1258 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
1259 make CC=gcc CFLAGS="'-DMBEDTLS_CONFIG_FILE=\"$PWD/tests/configs/config-wrapper-malloc-0-null.h\"' -O -Werror -Wall -Wextra -fsanitize=address,undefined" LDFLAGS='-fsanitize=address,undefined'
1260
1261 msg "test: malloc(0) returns NULL (ASan+UBSan build)"
1262 make test
1263
1264 msg "selftest: malloc(0) returns NULL (ASan+UBSan build)"
1265 # Just the calloc selftest. "make test" ran the others as part of the
1266 # test suites.
1267 if_build_succeeded programs/test/selftest calloc
Gilles Peskine765d2402020-02-11 18:26:34 +01001268
1269 msg "test ssl-opt.sh: malloc(0) returns NULL (ASan+UBSan build)"
1270 # Run a subset of the tests. The choice is a balance between coverage
1271 # and time (including time indirectly wasted due to flaky tests).
1272 # The current choice is to skip tests whose description includes
1273 # "proxy", which is an approximation of skipping tests that use the
1274 # UDP proxy, which tend to be slower and flakier.
1275 if_build_succeeded tests/ssl-opt.sh -e 'proxy'
Gilles Peskinec4ef7a92019-09-17 19:04:38 +02001276}
1277
Gilles Peskine8f073122018-11-27 15:58:47 +01001278component_test_make_shared () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001279 msg "build/test: make shared" # ~ 40s
Andrzej Kurek232e8f92019-10-03 03:18:01 -04001280 make SHARED=1 all check
Gilles Peskine56c01612019-07-03 20:43:32 +02001281 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskine8f073122018-11-27 15:58:47 +01001282}
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +02001283
Gilles Peskinecf740502019-07-03 20:43:05 +02001284component_test_cmake_shared () {
1285 msg "build/test: cmake shared" # ~ 2min
1286 cmake -DUSE_SHARED_MBEDTLS_LIBRARY=On .
1287 make
Gilles Peskine56c01612019-07-03 20:43:32 +02001288 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskinecf740502019-07-03 20:43:05 +02001289 make test
1290}
1291
Gilles Peskineec10bf12019-09-20 19:56:06 +02001292test_build_opt () {
1293 info=$1 cc=$2; shift 2
1294 for opt in "$@"; do
1295 msg "build/test: $cc $opt, $info" # ~ 30s
1296 make CC="$cc" CFLAGS="$opt -Wall -Wextra -Werror"
1297 # We're confident enough in compilers to not run _all_ the tests,
1298 # but at least run the unit tests. In particular, runs with
1299 # optimizations use inline assembly whereas runs with -O0
1300 # skip inline assembly.
1301 make test # ~30s
1302 make clean
1303 done
1304}
1305
1306component_test_clang_opt () {
1307 scripts/config.pl full
1308 test_build_opt 'full config' clang -O0 -Os -O2
1309}
1310
1311component_test_gcc_opt () {
1312 scripts/config.pl full
1313 test_build_opt 'full config' gcc -O0 -Os -O2
1314}
1315
Gilles Peskineabf9b4d2019-07-03 20:42:16 +02001316component_build_mbedtls_config_file () {
1317 msg "build: make with MBEDTLS_CONFIG_FILE" # ~40s
1318 # Use the full config so as to catch a maximum of places where
1319 # the check of MBEDTLS_CONFIG_FILE might be missing.
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001320 scripts/config.py full
Gilles Peskineabf9b4d2019-07-03 20:42:16 +02001321 sed 's!"check_config.h"!"mbedtls/check_config.h"!' <"$CONFIG_H" >full_config.h
1322 echo '#error "MBEDTLS_CONFIG_FILE is not working"' >"$CONFIG_H"
1323 make CFLAGS="-I '$PWD' -DMBEDTLS_CONFIG_FILE='\"full_config.h\"'"
1324 rm -f full_config.h
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001325}
1326
Gilles Peskine8f073122018-11-27 15:58:47 +01001327component_test_m32_o0 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001328 # Build once with -O0, to compile out the i386 specific inline assembly
1329 msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001330 scripts/config.py full
Gilles Peskine8fd59422019-10-21 17:11:33 +02001331 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O0" LDFLAGS="-m32 $ASAN_CFLAGS"
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01001332
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001333 msg "test: i386, make, gcc -O0 (ASan build)"
1334 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01001335}
Gilles Peskine878cf602019-01-06 20:50:38 +00001336support_test_m32_o0 () {
1337 case $(uname -m) in
1338 *64*) true;;
1339 *) false;;
1340 esac
1341}
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001342
Gilles Peskine8f073122018-11-27 15:58:47 +01001343component_test_m32_o1 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001344 # Build again with -O1, to compile in the i386 specific inline assembly
1345 msg "build: i386, make, gcc -O1 (ASan build)" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001346 scripts/config.py full
Gilles Peskine8fd59422019-10-21 17:11:33 +02001347 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O1" LDFLAGS="-m32 $ASAN_CFLAGS"
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001348
1349 msg "test: i386, make, gcc -O1 (ASan build)"
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001350 make test
Gilles Peskine4b317612019-04-08 16:58:02 +02001351
1352 msg "test ssl-opt.sh, i386, make, gcc-O1"
1353 if_build_succeeded tests/ssl-opt.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01001354}
Gilles Peskine878cf602019-01-06 20:50:38 +00001355support_test_m32_o1 () {
1356 support_test_m32_o0 "$@"
1357}
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001358
Gilles Peskine0c6b7992019-04-12 20:29:48 +02001359component_test_m32_everest () {
1360 msg "build: i386, Everest ECDH context (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001361 scripts/config.py unset MBEDTLS_ECDH_LEGACY_CONTEXT
1362 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
Gilles Peskine8fd59422019-10-21 17:11:33 +02001363 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O2" LDFLAGS="-m32 $ASAN_CFLAGS"
Gilles Peskine0c6b7992019-04-12 20:29:48 +02001364
1365 msg "test: i386, Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
1366 make test
1367
1368 msg "test: i386, Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
1369 if_build_succeeded tests/ssl-opt.sh -f ECDH
1370
1371 msg "test: i386, Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
1372 # Exclude some symmetric ciphers that are redundant here to gain time.
1373 if_build_succeeded tests/compat.sh -f ECDH -V NO -e 'ARCFOUR\|ARIA\|CAMELLIA\|CHACHA\|DES\|RC4'
1374}
1375support_test_m32_everest () {
1376 support_test_m32_o0 "$@"
1377}
1378
Gilles Peskine8f073122018-11-27 15:58:47 +01001379component_test_mx32 () {
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001380 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001381 scripts/config.py full
Gilles Peskine5d26e7c2019-06-07 14:50:09 +02001382 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32' LDFLAGS='-mx32'
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001383
1384 msg "test: 64-bit ILP32, make, gcc"
1385 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01001386}
Gilles Peskine878cf602019-01-06 20:50:38 +00001387support_test_mx32 () {
1388 case $(uname -m) in
1389 amd64|x86_64) true;;
1390 *) false;;
1391 esac
1392}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001393
Gilles Peskine8f073122018-11-27 15:58:47 +01001394component_build_arm_none_eabi_gcc () {
1395 msg "build: arm-none-eabi-gcc, make" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001396 scripts/config.py baremetal
Gilles Peskine8f073122018-11-27 15:58:47 +01001397 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
1398}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001399
Gilles Peskine2c897d72019-08-09 16:05:05 +02001400component_build_arm_none_eabi_gcc_arm5vte () {
Gilles Peskine8a52af92019-08-08 16:09:02 +02001401 msg "build: arm-none-eabi-gcc -march=arm5vte, make" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001402 scripts/config.py baremetal
Gilles Peskine2c897d72019-08-09 16:05:05 +02001403 # Build for a target platform that's close to what Debian uses
1404 # for its "armel" distribution (https://wiki.debian.org/ArmEabiPort).
1405 # See https://github.com/ARMmbed/mbedtls/pull/2169 and comments.
1406 # It would be better to build with arm-linux-gnueabi-gcc but
1407 # we don't have that on our CI at this time.
Gilles Peskine8a52af92019-08-08 16:09:02 +02001408 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 +02001409}
1410
Gilles Peskine8f073122018-11-27 15:58:47 +01001411component_build_arm_none_eabi_gcc_no_udbl_division () {
1412 msg "build: arm-none-eabi-gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001413 scripts/config.py baremetal
1414 scripts/config.py set MBEDTLS_NO_UDBL_DIVISION
Gilles Peskine8f073122018-11-27 15:58:47 +01001415 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
1416 echo "Checking that software 64-bit division is not required"
1417 if_build_succeeded not grep __aeabi_uldiv library/*.o
1418}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001419
Gilles Peskine8f073122018-11-27 15:58:47 +01001420component_build_arm_none_eabi_gcc_no_64bit_multiplication () {
1421 msg "build: arm-none-eabi-gcc MBEDTLS_NO_64BIT_MULTIPLICATION, make" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001422 scripts/config.py baremetal
1423 scripts/config.py set MBEDTLS_NO_64BIT_MULTIPLICATION
Gilles Peskine8f073122018-11-27 15:58:47 +01001424 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -O1 -march=armv6-m -mthumb' lib
1425 echo "Checking that software 64-bit multiplication is not required"
1426 if_build_succeeded not grep __aeabi_lmul library/*.o
1427}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001428
Gilles Peskine8f073122018-11-27 15:58:47 +01001429component_build_armcc () {
1430 msg "build: ARM Compiler 5, make"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001431 scripts/config.py baremetal
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001432
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001433 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
1434 make clean
Andres AG87bb5772016-09-27 15:05:15 +01001435
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001436 # ARM Compiler 6 - Target ARMv7-A
1437 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-a"
Simon Butcher940737f2017-07-23 13:42:36 +02001438
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001439 # ARM Compiler 6 - Target ARMv7-M
1440 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m"
Simon Butcher940737f2017-07-23 13:42:36 +02001441
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001442 # ARM Compiler 6 - Target ARMv8-A - AArch32
1443 armc6_build_test "--target=arm-arm-none-eabi -march=armv8.2-a"
Simon Butcher940737f2017-07-23 13:42:36 +02001444
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001445 # ARM Compiler 6 - Target ARMv8-M
1446 armc6_build_test "--target=arm-arm-none-eabi -march=armv8-m.main"
Simon Butcher940737f2017-07-23 13:42:36 +02001447
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001448 # ARM Compiler 6 - Target ARMv8-A - AArch64
1449 armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a"
Gilles Peskine8f073122018-11-27 15:58:47 +01001450}
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +01001451
Gilles Peskine8f073122018-11-27 15:58:47 +01001452component_test_allow_sha1 () {
1453 msg "build: allow SHA1 in certificates by default"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001454 scripts/config.py set MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
Gilles Peskine8f073122018-11-27 15:58:47 +01001455 make CFLAGS='-Werror -Wall -Wextra'
1456 msg "test: allow SHA1 in certificates by default"
1457 make test
1458 if_build_succeeded tests/ssl-opt.sh -f SHA-1
1459}
Gilles Peskine2a458da2017-05-12 15:26:58 +02001460
Gilles Peskine8f073122018-11-27 15:58:47 +01001461component_build_mingw () {
1462 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
Andrzej Kurek232e8f92019-10-03 03:18:01 -04001463 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
Hanno Beckere963efa2018-01-03 10:03:43 +00001464
Gilles Peskine8f073122018-11-27 15:58:47 +01001465 # note Make tests only builds the tests, but doesn't run them
Andrzej Kurek232e8f92019-10-03 03:18:01 -04001466 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror' WINDOWS_BUILD=1 tests
Gilles Peskine8f073122018-11-27 15:58:47 +01001467 make WINDOWS_BUILD=1 clean
Simon Butcher002bc622016-11-17 09:27:45 +00001468
Gilles Peskine8f073122018-11-27 15:58:47 +01001469 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
Andrzej Kurek232e8f92019-10-03 03:18:01 -04001470 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
1471 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
Gilles Peskine8f073122018-11-27 15:58:47 +01001472 make WINDOWS_BUILD=1 clean
1473}
Jaeden Amero117b8a42019-04-17 15:19:26 +01001474support_build_mingw() {
1475 case $(i686-w64-mingw32-gcc -dumpversion) in
1476 [0-5]*) false;;
1477 *) true;;
1478 esac
1479}
Manuel Pégourié-Gonnard6448bce2015-02-16 17:18:36 +01001480
Gilles Peskine8f073122018-11-27 15:58:47 +01001481component_test_memsan () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001482 msg "build: MSan (clang)" # ~ 1 min 20s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001483 scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001484 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
1485 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +02001486
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001487 msg "test: main suites (MSan)" # ~ 10s
1488 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001489
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001490 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
Gilles Peskine7c652162017-12-11 00:01:40 +01001491 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001492
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001493 # Optional part(s)
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001494
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001495 if [ "$MEMORY" -gt 0 ]; then
1496 msg "test: compat.sh (MSan)" # ~ 6 min 20s
Gilles Peskine7c652162017-12-11 00:01:40 +01001497 if_build_succeeded tests/compat.sh
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001498 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001499}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001500
Gilles Peskine69f190e2019-01-10 00:11:42 +01001501component_test_valgrind () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001502 msg "build: Release (clang)"
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001503 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
1504 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001505
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001506 msg "test: main suites valgrind (Release)"
1507 make memcheck
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001508
Gilles Peskinef1349e42019-04-08 17:00:56 +02001509 # Optional parts (slow; currently broken on OS X because programs don't
1510 # seem to receive signals under valgrind on OS X).
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001511 if [ "$MEMORY" -gt 0 ]; then
1512 msg "test: ssl-opt.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +01001513 if_build_succeeded tests/ssl-opt.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001514 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001515
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001516 if [ "$MEMORY" -gt 1 ]; then
1517 msg "test: compat.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +01001518 if_build_succeeded tests/compat.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001519 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001520}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001521
Gilles Peskine8f073122018-11-27 15:58:47 +01001522component_test_cmake_out_of_source () {
1523 msg "build: cmake 'out-of-source' build"
Gilles Peskine8f073122018-11-27 15:58:47 +01001524 MBEDTLS_ROOT_DIR="$PWD"
1525 mkdir "$OUT_OF_SOURCE_DIR"
1526 cd "$OUT_OF_SOURCE_DIR"
1527 cmake "$MBEDTLS_ROOT_DIR"
1528 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001529
Gilles Peskine8f073122018-11-27 15:58:47 +01001530 msg "test: cmake 'out-of-source' build"
1531 make test
1532 # Test an SSL option that requires an auxiliary script in test/scripts/.
1533 # Also ensure that there are no error messages such as
1534 # "No such file or directory", which would indicate that some required
1535 # file is missing (ssl-opt.sh tolerates the absence of some files so
1536 # may exit with status 0 but emit errors).
1537 if_build_succeeded ./tests/ssl-opt.sh -f 'Fallback SCSV: beginning of list' 2>ssl-opt.err
1538 if [ -s ssl-opt.err ]; then
1539 cat ssl-opt.err >&2
1540 record_status [ ! -s ssl-opt.err ]
1541 rm ssl-opt.err
1542 fi
1543 cd "$MBEDTLS_ROOT_DIR"
1544 rm -rf "$OUT_OF_SOURCE_DIR"
1545 unset MBEDTLS_ROOT_DIR
1546}
Andres AGdc192212016-08-31 17:33:13 +01001547
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01001548component_test_cmake_as_subdirectory () {
1549 msg "build: cmake 'as-subdirectory' build"
1550 MBEDTLS_ROOT_DIR="$PWD"
1551
1552 cd programs/test/cmake_subproject
1553 cmake .
1554 make
1555 if_build_succeeded ./cmake_subproject
1556
1557 cd "$MBEDTLS_ROOT_DIR"
1558 unset MBEDTLS_ROOT_DIR
1559}
1560
Gilles Peskine8f073122018-11-27 15:58:47 +01001561component_test_zeroize () {
1562 # Test that the function mbedtls_platform_zeroize() is not optimized away by
1563 # different combinations of compilers and optimization flags by using an
1564 # auxiliary GDB script. Unfortunately, GDB does not return error values to the
1565 # system in all cases that the script fails, so we must manually search the
1566 # output to check whether the pass string is present and no failure strings
1567 # were printed.
Andres AGdc192212016-08-31 17:33:13 +01001568
Gilles Peskine4976e822019-01-06 19:52:22 +00001569 # Don't try to disable ASLR. We don't care about ASLR here. We do care
1570 # about a spurious message if Gdb tries and fails, so suppress that.
1571 gdb_disable_aslr=
1572 if [ -z "$(gdb -batch -nw -ex 'set disable-randomization off' 2>&1)" ]; then
1573 gdb_disable_aslr='set disable-randomization off'
1574 fi
1575
Gilles Peskine8f073122018-11-27 15:58:47 +01001576 for optimization_flag in -O2 -O3 -Ofast -Os; do
Gilles Peskine55f7c942019-01-09 22:28:21 +01001577 for compiler in clang gcc; do
1578 msg "test: $compiler $optimization_flag, mbedtls_platform_zeroize()"
1579 make programs CC="$compiler" DEBUG=1 CFLAGS="$optimization_flag"
Gilles Peskine4976e822019-01-06 19:52:22 +00001580 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 +01001581 if_build_succeeded grep "The buffer was correctly zeroized" test_zeroize.log
1582 if_build_succeeded not grep -i "error" test_zeroize.log
1583 rm -f test_zeroize.log
1584 make clean
1585 done
Andres Amaya Garcia29673812017-10-25 10:35:51 +01001586 done
Andres Amaya Garciad0d7bf62017-10-25 09:01:31 +01001587
Gilles Peskine4976e822019-01-06 19:52:22 +00001588 unset gdb_disable_aslr
Gilles Peskine8f073122018-11-27 15:58:47 +01001589}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001590
Gilles Peskineaad2ebd2019-02-25 20:26:06 +01001591support_check_python_files () {
1592 type pylint3 >/dev/null 2>/dev/null
1593}
Gilles Peskine8f073122018-11-27 15:58:47 +01001594component_check_python_files () {
1595 msg "Lint: Python scripts"
1596 record_status tests/scripts/check-python-files.sh
1597}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001598
Gilles Peskine8f073122018-11-27 15:58:47 +01001599component_check_generate_test_code () {
1600 msg "uint test: generate_test_code.py"
1601 record_status ./tests/scripts/test_generate_test_code.py
1602}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001603
1604################################################################
1605#### Termination
1606################################################################
1607
Gilles Peskine8f073122018-11-27 15:58:47 +01001608post_report () {
1609 msg "Done, cleaning up"
1610 cleanup
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001611
Gilles Peskine8f073122018-11-27 15:58:47 +01001612 final_report
1613}
1614
1615
1616
1617################################################################
1618#### Run all the things
1619################################################################
1620
Gilles Peskinee48351a2018-11-27 16:06:30 +01001621# Run one component and clean up afterwards.
Gilles Peskine8f073122018-11-27 15:58:47 +01001622run_component () {
Gilles Peskine608953e2019-01-02 18:57:02 +01001623 # Back up the configuration in case the component modifies it.
1624 # The cleanup function will restore it.
1625 cp -p "$CONFIG_H" "$CONFIG_BAK"
Gilles Peskineffcdeff2018-12-04 12:49:28 +01001626 current_component="$1"
Gilles Peskine9004a172019-09-16 15:20:36 +02001627 export MBEDTLS_TEST_CONFIGURATION="$current_component"
Gilles Peskine8f073122018-11-27 15:58:47 +01001628 "$@"
Gilles Peskinee48351a2018-11-27 16:06:30 +01001629 cleanup
Gilles Peskine8f073122018-11-27 15:58:47 +01001630}
1631
1632# Preliminary setup
1633pre_check_environment
1634pre_initialize_variables
1635pre_parse_command_line "$@"
Gilles Peskine348fb9a2018-11-27 17:04:29 +01001636
Gilles Peskine878cf602019-01-06 20:50:38 +00001637pre_check_git
Andrzej Kurekeb508712019-02-14 07:18:59 -05001638pre_check_seedfile
1639
Gilles Peskine878cf602019-01-06 20:50:38 +00001640build_status=0
1641if [ $KEEP_GOING -eq 1 ]; then
1642 pre_setup_keep_going
Gilles Peskine92525112018-11-27 18:15:35 +01001643else
Gilles Peskine878cf602019-01-06 20:50:38 +00001644 record_status () {
1645 "$@"
1646 }
Gilles Peskine8f073122018-11-27 15:58:47 +01001647fi
Gilles Peskine67ffdaf2019-09-16 15:55:46 +02001648pre_prepare_outcome_file
Gilles Peskine878cf602019-01-06 20:50:38 +00001649pre_print_configuration
1650pre_check_tools
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001651cleanup
1652
Gilles Peskinebeb3a812019-01-06 22:11:25 +00001653# Run the requested tests.
1654for component in $RUN_COMPONENTS; do
1655 run_component "component_$component"
1656done
Gilles Peskine8f073122018-11-27 15:58:47 +01001657
1658# We're done.
Gilles Peskine878cf602019-01-06 20:50:38 +00001659post_report