blob: a97189a90cdd33d3028dae07455c78ff8056642b [file] [log] [blame]
Andres AG31f9b5b2016-10-04 17:14:38 +01001#! /usr/bin/env sh
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01002
Simon Butcher3ea7f522016-03-07 23:22:10 +00003# all.sh
4#
SimonB2e23c822016-04-16 21:54:39 +01005# This file is part of mbed TLS (https://tls.mbed.org)
6#
Gilles Peskine192c72f2017-12-21 15:59:21 +01007# Copyright (c) 2014-2017, ARM Limited, All Rights Reserved
8
9
10
11################################################################
12#### Documentation
13################################################################
14
Simon Butcher3ea7f522016-03-07 23:22:10 +000015# Purpose
Gilles Peskine192c72f2017-12-21 15:59:21 +010016# -------
Simon Butcher3ea7f522016-03-07 23:22:10 +000017#
SimonB2e23c822016-04-16 21:54:39 +010018# To run all tests possible or available on the platform.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010019#
Gilles Peskine192c72f2017-12-21 15:59:21 +010020# Notes for users
21# ---------------
22#
SimonB2e23c822016-04-16 21:54:39 +010023# Warning: the test is destructive. It includes various build modes and
24# configurations, and can and will arbitrarily change the current CMake
Gilles Peskine192c72f2017-12-21 15:59:21 +010025# configuration. The following files must be committed into git:
26# * include/mbedtls/config.h
Philippe Antoine1c582c32019-06-25 21:55:21 +020027# * Makefile, library/Makefile, programs/Makefile, tests/Makefile,
Philippe Antoine5dece6d2019-06-27 16:55:07 +020028# programs/fuzz/Makefile
Gilles Peskine192c72f2017-12-21 15:59:21 +010029# After running this script, the CMake cache will be lost and CMake
30# will no longer be initialised.
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +010031#
Gilles Peskine192c72f2017-12-21 15:59:21 +010032# The script assumes the presence of a number of tools:
33# * Basic Unix tools (Windows users note: a Unix-style find must be before
34# the Windows find in the PATH)
35# * Perl
36# * GNU Make
37# * CMake
38# * GCC and Clang (recent enough for using ASan with gcc and MemSan with clang, or valgrind)
Andrzej Kurek05be06c2018-06-28 04:41:50 -040039# * G++
Gilles Peskine192c72f2017-12-21 15:59:21 +010040# * arm-gcc and mingw-gcc
41# * ArmCC 5 and ArmCC 6, unless invoked with --no-armcc
Gilles Peskine192c72f2017-12-21 15:59:21 +010042# * OpenSSL and GnuTLS command line tools, recent enough for the
43# interoperability tests. If they don't support SSLv3 then a legacy
44# version of these tools must be present as well (search for LEGACY
45# below).
46# See the invocation of check_tools below for details.
47#
48# This script must be invoked from the toplevel directory of a git
49# working copy of Mbed TLS.
50#
51# Note that the output is not saved. You may want to run
52# script -c tests/scripts/all.sh
53# or
54# tests/scripts/all.sh >all.log 2>&1
55#
56# Notes for maintainers
57# ---------------------
58#
Gilles Peskine8f073122018-11-27 15:58:47 +010059# The bulk of the code is organized into functions that follow one of the
60# following naming conventions:
61# * pre_XXX: things to do before running the tests, in order.
62# * component_XXX: independent components. They can be run in any order.
Gilles Peskinec70637a2019-01-09 22:29:17 +010063# * component_check_XXX: quick tests that aren't worth parallelizing.
64# * component_build_XXX: build things but don't run them.
65# * component_test_XXX: build and test.
Gilles Peskine878cf602019-01-06 20:50:38 +000066# * support_XXX: if support_XXX exists and returns false then
67# component_XXX is not run by default.
Gilles Peskine8f073122018-11-27 15:58:47 +010068# * post_XXX: things to do after running the tests.
69# * other: miscellaneous support functions.
70#
Gilles Peskinec70637a2019-01-09 22:29:17 +010071# Each component must start by invoking `msg` with a short informative message.
72#
73# The framework performs some cleanup tasks after each component. This
74# means that components can assume that the working directory is in a
75# cleaned-up state, and don't need to perform the cleanup themselves.
76# * Run `make clean`.
77# * Restore `include/mbedtks/config.h` from a backup made before running
78# the component.
Philippe Antoine1c582c32019-06-25 21:55:21 +020079# * Check out `Makefile`, `library/Makefile`, `programs/Makefile`,
Philippe Antoine5dece6d2019-06-27 16:55:07 +020080# `tests/Makefile` and `programs/fuzz/Makefile` from git.
Philippe Antoine1c582c32019-06-25 21:55:21 +020081# This cleans up after an in-tree use of CMake.
Gilles Peskinec70637a2019-01-09 22:29:17 +010082#
83# Any command that is expected to fail must be protected so that the
84# script keeps running in --keep-going mode despite `set -e`. In keep-going
85# mode, if a protected command fails, this is logged as a failure and the
86# script will exit with a failure status once it has run all components.
87# Commands can be protected in any of the following ways:
88# * `make` is a function which runs the `make` command with protection.
89# Note that you must write `make VAR=value`, not `VAR=value make`,
90# because the `VAR=value make` syntax doesn't work with functions.
91# * Put `report_status` before the command to protect it.
92# * Put `if_build_successful` before a command. This protects it, and
93# additionally skips it if a prior invocation of `make` in the same
94# component failed.
95#
Gilles Peskine192c72f2017-12-21 15:59:21 +010096# The tests are roughly in order from fastest to slowest. This doesn't
97# have to be exact, but in general you should add slower tests towards
98# the end and fast checks near the beginning.
Gilles Peskine192c72f2017-12-21 15:59:21 +010099
100
101
102################################################################
103#### Initialization and command line parsing
104################################################################
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100105
SimonB2e23c822016-04-16 21:54:39 +0100106# Abort on errors (and uninitialised variables)
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100107set -eu
108
Gilles Peskine8f073122018-11-27 15:58:47 +0100109pre_check_environment () {
Gilles Peskinea16c2b12019-01-06 19:58:02 +0000110 if [ -d library -a -d include -a -d tests ]; then :; else
Gilles Peskine8f073122018-11-27 15:58:47 +0100111 echo "Must be run from mbed TLS root" >&2
112 exit 1
113 fi
114}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100115
Gilles Peskine8f073122018-11-27 15:58:47 +0100116pre_initialize_variables () {
117 CONFIG_H='include/mbedtls/config.h'
118 CONFIG_BAK="$CONFIG_H.bak"
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200119
Gilles Peskine8f073122018-11-27 15:58:47 +0100120 MEMORY=0
121 FORCE=0
122 KEEP_GOING=0
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100123
Gilles Peskine9004a172019-09-16 15:20:36 +0200124 : ${MBEDTLS_TEST_PLATFORM="$(uname -s | tr -c \\n0-9A-Za-z _)-$(uname -m | tr -c \\n0-9A-Za-z _)"}
125 export MBEDTLS_TEST_PLATFORM
126
Jaeden Ameroc4cc2512019-01-30 15:35:44 +0000127 # Default commands, can be overridden by the environment
Gilles Peskine8f073122018-11-27 15:58:47 +0100128 : ${OPENSSL:="openssl"}
129 : ${OPENSSL_LEGACY:="$OPENSSL"}
130 : ${OPENSSL_NEXT:="$OPENSSL"}
131 : ${GNUTLS_CLI:="gnutls-cli"}
132 : ${GNUTLS_SERV:="gnutls-serv"}
133 : ${GNUTLS_LEGACY_CLI:="$GNUTLS_CLI"}
134 : ${GNUTLS_LEGACY_SERV:="$GNUTLS_SERV"}
135 : ${OUT_OF_SOURCE_DIR:=./mbedtls_out_of_source_build}
136 : ${ARMC5_BIN_DIR:=/usr/bin}
137 : ${ARMC6_BIN_DIR:=/usr/bin}
Andres AGdc192212016-08-31 17:33:13 +0100138
Gilles Peskine8f073122018-11-27 15:58:47 +0100139 # if MAKEFLAGS is not set add the -j option to speed up invocations of make
Gilles Peskinea1fc4b52019-01-06 20:15:26 +0000140 if [ -z "${MAKEFLAGS+set}" ]; then
Gilles Peskine8f073122018-11-27 15:58:47 +0100141 export MAKEFLAGS="-j"
142 fi
Gilles Peskine878cf602019-01-06 20:50:38 +0000143
144 # Gather the list of available components. These are the functions
145 # defined in this script whose name starts with "component_".
146 # Parse the script with sed, because in sh there is no way to list
147 # defined functions.
148 ALL_COMPONENTS=$(sed -n 's/^ *component_\([0-9A-Z_a-z]*\) *().*/\1/p' <"$0")
149
150 # Exclude components that are not supported on this platform.
151 SUPPORTED_COMPONENTS=
152 for component in $ALL_COMPONENTS; do
153 case $(type "support_$component" 2>&1) in
154 *' function'*)
155 if ! support_$component; then continue; fi;;
156 esac
157 SUPPORTED_COMPONENTS="$SUPPORTED_COMPONENTS $component"
158 done
Gilles Peskine8f073122018-11-27 15:58:47 +0100159}
Andres AG38495a32016-07-12 16:54:33 +0100160
Gilles Peskinea28db922019-01-10 00:05:18 +0100161# Test whether the component $1 is included in the command line patterns.
162is_component_included()
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100163{
164 set -f
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000165 for pattern in $COMMAND_LINE_COMPONENTS; do
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100166 set +f
167 case ${1#component_} in $pattern) return 0;; esac
168 done
169 set +f
170 return 1
171}
Andres AG7770ea82016-10-10 15:46:20 +0100172
Simon Butcher41eeccf2016-09-07 00:07:09 +0100173usage()
Andres AGd9eba4b2016-08-26 14:42:14 +0100174{
Gilles Peskine709346a2017-12-10 23:43:39 +0100175 cat <<EOF
Gilles Peskine92525112018-11-27 18:15:35 +0100176Usage: $0 [OPTION]... [COMPONENT]...
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100177Run mbedtls release validation tests.
Gilles Peskine92525112018-11-27 18:15:35 +0100178By default, run all tests. With one or more COMPONENT, run only those.
Gilles Peskinea28db922019-01-10 00:05:18 +0100179COMPONENT can be the name of a component or a shell wildcard pattern.
180
181Examples:
182 $0 "check_*"
183 Run all sanity checks.
184 $0 --no-armcc --except test_memsan
185 Run everything except builds that require armcc and MemSan.
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100186
187Special options:
188 -h|--help Print this help and exit.
Gilles Peskine878cf602019-01-06 20:50:38 +0000189 --list-all-components List all available test components and exit.
190 --list-components List components supported on this platform and exit.
Gilles Peskine709346a2017-12-10 23:43:39 +0100191
192General options:
193 -f|--force Force the tests to overwrite any modified files.
Gilles Peskine7c652162017-12-11 00:01:40 +0100194 -k|--keep-going Run all tests and report errors at the end.
Gilles Peskine709346a2017-12-10 23:43:39 +0100195 -m|--memory Additional optional memory tests.
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100196 --armcc Run ARM Compiler builds (on by default).
Gilles Peskinea28db922019-01-10 00:05:18 +0100197 --except Exclude the COMPONENTs listed on the command line,
198 instead of running only those.
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100199 --no-armcc Skip ARM Compiler builds.
Gilles Peskine38d81652018-03-21 08:40:26 +0100200 --no-force Refuse to overwrite modified files (default).
201 --no-keep-going Stop at the first error (default).
202 --no-memory No additional memory tests (default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100203 --out-of-source-dir=<path> Directory used for CMake out-of-source build tests.
Gilles Peskine38d81652018-03-21 08:40:26 +0100204 --random-seed Use a random seed value for randomized tests (default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100205 -r|--release-test Run this script in release mode. This fixes the seed value to 1.
206 -s|--seed Integer seed value to use for this test run.
207
208Tool path options:
209 --armc5-bin-dir=<ARMC5_bin_dir_path> ARM Compiler 5 bin directory.
210 --armc6-bin-dir=<ARMC6_bin_dir_path> ARM Compiler 6 bin directory.
211 --gnutls-cli=<GnuTLS_cli_path> GnuTLS client executable to use for most tests.
212 --gnutls-serv=<GnuTLS_serv_path> GnuTLS server executable to use for most tests.
213 --gnutls-legacy-cli=<GnuTLS_cli_path> GnuTLS client executable to use for legacy tests.
214 --gnutls-legacy-serv=<GnuTLS_serv_path> GnuTLS server executable to use for legacy tests.
215 --openssl=<OpenSSL_path> OpenSSL executable to use for most tests.
216 --openssl-legacy=<OpenSSL_path> OpenSSL executable to use for legacy tests e.g. SSLv3.
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100217 --openssl-next=<OpenSSL_path> OpenSSL executable to use for recent things like ARIA
Gilles Peskine709346a2017-12-10 23:43:39 +0100218EOF
SimonB2e23c822016-04-16 21:54:39 +0100219}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100220
221# remove built files as well as the cmake cache/config
222cleanup()
223{
Gilles Peskinea71d64c2018-03-21 12:16:57 +0100224 if [ -n "${MBEDTLS_ROOT_DIR+set}" ]; then
225 cd "$MBEDTLS_ROOT_DIR"
226 fi
227
Gilles Peskine7c652162017-12-11 00:01:40 +0100228 command make clean
Jaeden Ameroed93bdc2018-11-02 16:57:24 +0000229 cd crypto
230 command make clean
231 cd ..
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200232
Gilles Peskine31b07e22018-03-21 12:15:06 +0100233 # Remove CMake artefacts
Jaeden Amero2d0e00f2018-11-07 18:46:41 +0000234 find . -name .git -prune -o \
Gilles Peskine31b07e22018-03-21 12:15:06 +0100235 -iname CMakeFiles -exec rm -rf {} \+ -o \
236 \( -iname cmake_install.cmake -o \
237 -iname CTestTestfile.cmake -o \
238 -iname CMakeCache.txt \) -exec rm {} \+
239 # Recover files overwritten by in-tree CMake builds
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000240 rm -f include/Makefile include/mbedtls/Makefile programs/*/Makefile
Philippe Antoine5dece6d2019-06-27 16:55:07 +0200241 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile
242 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile
Jaeden Ameroed93bdc2018-11-02 16:57:24 +0000243 cd crypto
244 rm -f include/Makefile include/mbedtls/Makefile programs/*/Makefile
245 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile
246 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile
247 cd ..
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200248
Jaeden Ameroab83fdf2019-06-20 17:38:22 +0100249 # Remove any artifacts from the component_test_cmake_as_subdirectory test.
250 rm -rf programs/test/cmake_subproject/build
251 rm -f programs/test/cmake_subproject/Makefile
252 rm -f programs/test/cmake_subproject/cmake_subproject
253
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200254 if [ -f "$CONFIG_BAK" ]; then
255 mv "$CONFIG_BAK" "$CONFIG_H"
256 fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100257}
258
Gilles Peskine7c652162017-12-11 00:01:40 +0100259# Executed on exit. May be redefined depending on command line options.
260final_report () {
261 :
262}
263
264fatal_signal () {
265 cleanup
266 final_report $1
267 trap - $1
268 kill -$1 $$
269}
270
271trap 'fatal_signal HUP' HUP
272trap 'fatal_signal INT' INT
273trap 'fatal_signal TERM' TERM
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200274
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100275msg()
276{
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100277 if [ -n "${current_component:-}" ]; then
278 current_section="${current_component#component_}: $1"
279 else
280 current_section="$1"
281 fi
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100282 echo ""
283 echo "******************************************************************"
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100284 echo "* $current_section "
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000285 printf "* "; date
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100286 echo "******************************************************************"
287}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100288
Gilles Peskine8f073122018-11-27 15:58:47 +0100289armc6_build_test()
290{
291 FLAGS="$1"
Andres AGa5cd9732016-10-17 15:23:10 +0100292
Gilles Peskine8f073122018-11-27 15:58:47 +0100293 msg "build: ARM Compiler 6 ($FLAGS), make"
294 ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \
295 WARNING_CFLAGS='-xc -std=c99' make lib
296 make clean
297}
Andres AGa5cd9732016-10-17 15:23:10 +0100298
Andres AGd9eba4b2016-08-26 14:42:14 +0100299err_msg()
300{
301 echo "$1" >&2
302}
303
304check_tools()
305{
306 for TOOL in "$@"; do
Andres AG98393602017-01-31 17:04:45 +0000307 if ! `type "$TOOL" >/dev/null 2>&1`; then
Andres AGd9eba4b2016-08-26 14:42:14 +0100308 err_msg "$TOOL not found!"
309 exit 1
310 fi
311 done
312}
313
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400314check_headers_in_cpp () {
Peter Kolbus1bc1a4c2019-02-01 17:19:08 -0600315 ls include/mbedtls | grep "\.h$" >headers.txt
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400316 <programs/test/cpp_dummy_build.cpp sed -n 's/"$//; s!^#include "mbedtls/!!p' |
317 sort |
318 diff headers.txt -
319 rm headers.txt
320}
321
Gilles Peskine8f073122018-11-27 15:58:47 +0100322pre_parse_command_line () {
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000323 COMMAND_LINE_COMPONENTS=
Gilles Peskinea28db922019-01-10 00:05:18 +0100324 all_except=0
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000325 no_armcc=
SimonB2e23c822016-04-16 21:54:39 +0100326
Gilles Peskine8f073122018-11-27 15:58:47 +0100327 while [ $# -gt 0 ]; do
Gilles Peskine55f7c942019-01-09 22:28:21 +0100328 case "$1" in
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000329 --armcc) no_armcc=;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100330 --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
331 --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000332 --except) all_except=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100333 --force|-f) FORCE=1;;
334 --gnutls-cli) shift; GNUTLS_CLI="$1";;
335 --gnutls-legacy-cli) shift; GNUTLS_LEGACY_CLI="$1";;
336 --gnutls-legacy-serv) shift; GNUTLS_LEGACY_SERV="$1";;
337 --gnutls-serv) shift; GNUTLS_SERV="$1";;
338 --help|-h) usage; exit;;
339 --keep-going|-k) KEEP_GOING=1;;
Gilles Peskine878cf602019-01-06 20:50:38 +0000340 --list-all-components) printf '%s\n' $ALL_COMPONENTS; exit;;
341 --list-components) printf '%s\n' $SUPPORTED_COMPONENTS; exit;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100342 --memory|-m) MEMORY=1;;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000343 --no-armcc) no_armcc=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100344 --no-force) FORCE=0;;
345 --no-keep-going) KEEP_GOING=0;;
346 --no-memory) MEMORY=0;;
347 --openssl) shift; OPENSSL="$1";;
348 --openssl-legacy) shift; OPENSSL_LEGACY="$1";;
349 --openssl-next) shift; OPENSSL_NEXT="$1";;
350 --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
351 --random-seed) unset SEED;;
352 --release-test|-r) SEED=1;;
353 --seed|-s) shift; SEED="$1";;
354 -*)
355 echo >&2 "Unknown option: $1"
356 echo >&2 "Run $0 --help for usage."
357 exit 120
358 ;;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000359 *) COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS $1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100360 esac
361 shift
Gilles Peskine8f073122018-11-27 15:58:47 +0100362 done
SimonB2e23c822016-04-16 21:54:39 +0100363
Gilles Peskinea28db922019-01-10 00:05:18 +0100364 # With no list of components, run everything.
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000365 if [ -z "$COMMAND_LINE_COMPONENTS" ]; then
366 all_except=1
Andres AGdc192212016-08-31 17:33:13 +0100367 fi
368
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000369 # --no-armcc is a legacy option. The modern way is --except '*_armcc*'.
370 # Ignore it if components are listed explicitly on the command line.
Gilles Peskinea28db922019-01-10 00:05:18 +0100371 if [ -n "$no_armcc" ] && [ $all_except -eq 1 ]; then
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000372 COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS *_armcc*"
SimonB2e23c822016-04-16 21:54:39 +0100373 fi
SimonB2e23c822016-04-16 21:54:39 +0100374
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000375 # Build the list of components to run.
Gilles Peskinea28db922019-01-10 00:05:18 +0100376 RUN_COMPONENTS=
377 for component in $SUPPORTED_COMPONENTS; do
378 if is_component_included "$component"; [ $? -eq $all_except ]; then
379 RUN_COMPONENTS="$RUN_COMPONENTS $component"
380 fi
381 done
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000382
383 unset all_except
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000384 unset no_armcc
Gilles Peskine8f073122018-11-27 15:58:47 +0100385}
SimonB2e23c822016-04-16 21:54:39 +0100386
Gilles Peskine8f073122018-11-27 15:58:47 +0100387pre_check_git () {
388 if [ $FORCE -eq 1 ]; then
Gilles Peskine53190e62019-01-09 23:17:35 +0100389 rm -rf "$OUT_OF_SOURCE_DIR"
Gilles Peskine8f073122018-11-27 15:58:47 +0100390 git checkout-index -f -q $CONFIG_H
391 cleanup
392 else
SimonB2e23c822016-04-16 21:54:39 +0100393
Gilles Peskine8f073122018-11-27 15:58:47 +0100394 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
395 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
396 echo "You can either delete this directory manually, or force the test by rerunning"
397 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
398 exit 1
399 fi
400
Gilles Peskined1174cf2019-01-09 22:30:01 +0100401 if ! git diff --quiet include/mbedtls/config.h; then
Gilles Peskine8f073122018-11-27 15:58:47 +0100402 err_msg "Warning - the configuration file 'include/mbedtls/config.h' has been edited. "
403 echo "You can either delete or preserve your work, or force the test by rerunning the"
404 echo "script as: $0 --force"
405 exit 1
406 fi
SimonB2e23c822016-04-16 21:54:39 +0100407 fi
Andrzej Kureke9c3b812019-02-05 05:34:21 -0500408 if ! [ -f crypto/Makefile ]; then
409 echo "Please initialize the crypto submodule" >&2
410 exit 1
411 fi
Gilles Peskine8f073122018-11-27 15:58:47 +0100412}
SimonB2e23c822016-04-16 21:54:39 +0100413
Andrzej Kurekeb508712019-02-14 07:18:59 -0500414pre_check_seedfile () {
415 if [ ! -f "./tests/seedfile" ]; then
416 dd if=/dev/urandom of=./tests/seedfile bs=32 count=1
417 fi
Jaeden Amero97145102019-03-18 16:31:21 +0000418 if [ ! -f "./crypto/tests/seedfile" ]; then
419 dd if=/dev/urandom of=./crypto/tests/seedfile bs=32 count=1
420 fi
Andrzej Kurekeb508712019-02-14 07:18:59 -0500421}
422
Gilles Peskine8f073122018-11-27 15:58:47 +0100423pre_setup_keep_going () {
Gilles Peskine7c652162017-12-11 00:01:40 +0100424 failure_summary=
425 failure_count=0
426 start_red=
427 end_color=
428 if [ -t 1 ]; then
Gilles Peskine9736b9d2018-01-02 21:54:17 +0100429 case "${TERM:-}" in
Gilles Peskine7c652162017-12-11 00:01:40 +0100430 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
431 start_red=$(printf '\033[31m')
432 end_color=$(printf '\033[0m')
433 ;;
434 esac
435 fi
436 record_status () {
437 if "$@"; then
438 last_status=0
439 else
440 last_status=$?
441 text="$current_section: $* -> $last_status"
442 failure_summary="$failure_summary
443$text"
444 failure_count=$((failure_count + 1))
445 echo "${start_red}^^^^$text^^^^${end_color}"
446 fi
447 }
448 make () {
449 case "$*" in
450 *test|*check)
451 if [ $build_status -eq 0 ]; then
452 record_status command make "$@"
453 else
454 echo "(skipped because the build failed)"
455 fi
456 ;;
457 *)
458 record_status command make "$@"
459 build_status=$last_status
460 ;;
461 esac
462 }
463 final_report () {
464 if [ $failure_count -gt 0 ]; then
465 echo
466 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
467 echo "${start_red}FAILED: $failure_count${end_color}$failure_summary"
468 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Jaeden Amero7c1258d2018-07-20 16:42:14 +0100469 exit 1
Gilles Peskine7c652162017-12-11 00:01:40 +0100470 elif [ -z "${1-}" ]; then
471 echo "SUCCESS :)"
472 fi
473 if [ -n "${1-}" ]; then
474 echo "Killed by SIG$1."
475 fi
476 }
Gilles Peskine8f073122018-11-27 15:58:47 +0100477}
478
Gilles Peskine7c652162017-12-11 00:01:40 +0100479if_build_succeeded () {
480 if [ $build_status -eq 0 ]; then
481 record_status "$@"
482 fi
483}
484
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200485# to be used instead of ! for commands run with
486# record_status or if_build_succeeded
487not() {
488 ! "$@"
489}
490
Gilles Peskine8f073122018-11-27 15:58:47 +0100491pre_print_configuration () {
492 msg "info: $0 configuration"
493 echo "MEMORY: $MEMORY"
494 echo "FORCE: $FORCE"
495 echo "SEED: ${SEED-"UNSET"}"
496 echo "OPENSSL: $OPENSSL"
497 echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
498 echo "OPENSSL_NEXT: $OPENSSL_NEXT"
499 echo "GNUTLS_CLI: $GNUTLS_CLI"
500 echo "GNUTLS_SERV: $GNUTLS_SERV"
501 echo "GNUTLS_LEGACY_CLI: $GNUTLS_LEGACY_CLI"
502 echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV"
503 echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
504 echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
505}
Andres AG7770ea82016-10-10 15:46:20 +0100506
Andres AGd9eba4b2016-08-26 14:42:14 +0100507# Make sure the tools we need are available.
Gilles Peskine8f073122018-11-27 15:58:47 +0100508pre_check_tools () {
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000509 # Build the list of variables to pass to output_env.sh.
510 set env
SimonB2e23c822016-04-16 21:54:39 +0100511
Gilles Peskine87964262019-01-06 22:40:00 +0000512 case " $RUN_COMPONENTS " in
513 # Require OpenSSL and GnuTLS if running any tests (as opposed to
514 # only doing builds). Not all tests run OpenSSL and GnuTLS, but this
515 # is a good enough approximation in practice.
516 *" test_"*)
517 # To avoid setting OpenSSL and GnuTLS for each call to compat.sh
518 # and ssl-opt.sh, we just export the variables they require.
519 export OPENSSL_CMD="$OPENSSL"
520 export GNUTLS_CLI="$GNUTLS_CLI"
521 export GNUTLS_SERV="$GNUTLS_SERV"
522 # Avoid passing --seed flag in every call to ssl-opt.sh
523 if [ -n "${SEED-}" ]; then
524 export SEED
525 fi
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000526 set "$@" OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY"
527 set "$@" GNUTLS_CLI="$GNUTLS_CLI" GNUTLS_SERV="$GNUTLS_SERV"
528 set "$@" GNUTLS_LEGACY_CLI="$GNUTLS_LEGACY_CLI"
529 set "$@" GNUTLS_LEGACY_SERV="$GNUTLS_LEGACY_SERV"
Gilles Peskine87964262019-01-06 22:40:00 +0000530 check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$OPENSSL_NEXT" \
531 "$GNUTLS_CLI" "$GNUTLS_SERV" \
532 "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV"
533 ;;
534 esac
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200535
Gilles Peskine87964262019-01-06 22:40:00 +0000536 case " $RUN_COMPONENTS " in
537 *_doxygen[_\ ]*) check_tools "doxygen" "dot";;
538 esac
Andres AGd9eba4b2016-08-26 14:42:14 +0100539
Gilles Peskine87964262019-01-06 22:40:00 +0000540 case " $RUN_COMPONENTS " in
541 *_arm_none_eabi_gcc[_\ ]*) check_tools "arm-none-eabi-gcc";;
542 esac
Andres AGd9eba4b2016-08-26 14:42:14 +0100543
Gilles Peskine87964262019-01-06 22:40:00 +0000544 case " $RUN_COMPONENTS " in
545 *_mingw[_\ ]*) check_tools "i686-w64-mingw32-gcc";;
546 esac
547
548 case " $RUN_COMPONENTS " in
549 *" test_zeroize "*) check_tools "gdb";;
550 esac
551
552 case " $RUN_COMPONENTS " in
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000553 *_armcc*)
Gilles Peskine87964262019-01-06 22:40:00 +0000554 ARMC5_CC="$ARMC5_BIN_DIR/armcc"
555 ARMC5_AR="$ARMC5_BIN_DIR/armar"
556 ARMC6_CC="$ARMC6_BIN_DIR/armclang"
557 ARMC6_AR="$ARMC6_BIN_DIR/armar"
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000558 check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC6_CC" "$ARMC6_AR";;
559 esac
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000560
561 msg "info: output_env.sh"
562 case $RUN_COMPONENTS in
563 *_armcc*)
564 set "$@" ARMC5_CC="$ARMC5_CC" ARMC6_CC="$ARMC6_CC" RUN_ARMCC=1;;
565 *) set "$@" RUN_ARMCC=0;;
566 esac
567 "$@" scripts/output_env.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100568}
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100569
Gilles Peskine192c72f2017-12-21 15:59:21 +0100570
571
572################################################################
573#### Basic checks
574################################################################
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100575
576#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200577# Test Suites to be executed
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100578#
Manuel Pégourié-Gonnard3d404b42015-07-08 21:59:16 +0100579# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200580# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100581# 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 +0200582# time, so start with a GCC build).
583# 2. Minimize total running time, by avoiding useless rebuilds
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100584#
Manuel Pégourié-Gonnard259b08a2016-01-08 16:27:41 +0100585# Indicative running times are given for reference.
586
Gilles Peskine8f073122018-11-27 15:58:47 +0100587component_check_recursion () {
588 msg "test: recursion.pl" # < 1s
589 record_status tests/scripts/recursion.pl library/*.c
590}
Janos Follathb72c6782016-07-19 14:54:17 +0100591
Gilles Peskine8f073122018-11-27 15:58:47 +0100592component_check_generated_files () {
593 msg "test: freshness of generated source files" # < 1s
594 record_status tests/scripts/check-generated-files.sh
595}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200596
Gilles Peskine8f073122018-11-27 15:58:47 +0100597component_check_doxy_blocks () {
598 msg "test: doxygen markup outside doxygen blocks" # < 1s
599 record_status tests/scripts/check-doxy-blocks.pl
600}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200601
Gilles Peskine8f073122018-11-27 15:58:47 +0100602component_check_files () {
603 msg "test: check-files.py" # < 1s
Gilles Peskine8f073122018-11-27 15:58:47 +0100604 record_status tests/scripts/check-files.py
605}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200606
Gilles Peskine8f073122018-11-27 15:58:47 +0100607component_check_names () {
608 msg "test/build: declared and exported names" # < 3s
Gilles Peskine13f97dc2019-05-15 17:52:22 +0200609 record_status tests/scripts/check-names.sh -v
Gilles Peskine8f073122018-11-27 15:58:47 +0100610}
Darryl Greena07039c2018-03-13 16:48:16 +0000611
Gilles Peskine8f073122018-11-27 15:58:47 +0100612component_check_doxygen_warnings () {
613 msg "test: doxygen warnings" # ~ 3s
Gilles Peskine8f073122018-11-27 15:58:47 +0100614 record_status tests/scripts/doxygen.sh
615}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200616
Gilles Peskine192c72f2017-12-21 15:59:21 +0100617
618
619################################################################
620#### Build and test many configurations and targets
621################################################################
622
k-stachowiakc1955552019-06-10 11:46:18 +0200623component_test_large_ecdsa_key_signature () {
624
625 SMALL_MPI_MAX_SIZE=136 # Small enough to interfere with the EC signatures
626
627 msg "build: cmake + MBEDTLS_MPI_MAX_SIZE=${SMALL_MPI_MAX_SIZE}, gcc, ASan" # ~ 1 min 50s
628 scripts/config.pl set MBEDTLS_MPI_MAX_SIZE $SMALL_MPI_MAX_SIZE
k-stachowiakc1955552019-06-10 11:46:18 +0200629 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
630 make
631
632 INEVITABLY_PRESENT_FILE=Makefile
633 SIGNATURE_FILE="${INEVITABLY_PRESENT_FILE}.sig" # Warning, this is rm -f'ed below
634
635 msg "test: pk_sign secp521r1_prv.der for MBEDTLS_MPI_MAX_SIZE=${SMALL_MPI_MAX_SIZE} (ASan build)" # ~ 5s
636 if_build_succeeded programs/pkey/pk_sign tests/data_files/secp521r1_prv.der $INEVITABLY_PRESENT_FILE
637 rm -f $SIGNATURE_FILE
638}
639
Gilles Peskine7832c9f2019-04-08 17:00:15 +0200640component_test_default_out_of_box () {
641 msg "build: make, default config (out-of-box)" # ~1min
642 make
643
644 msg "test: main suites make, default config (out-of-box)" # ~10s
645 make test
646
647 msg "selftest: make, default config (out-of-box)" # ~10s
648 programs/test/selftest
649}
650
Gilles Peskine8f073122018-11-27 15:58:47 +0100651component_test_default_cmake_gcc_asan () {
652 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100653 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
654 make
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200655
Gilles Peskine8f073122018-11-27 15:58:47 +0100656 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
657 make test
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200658
Gilles Peskine8f073122018-11-27 15:58:47 +0100659 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
660 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200661
Gilles Peskine8f073122018-11-27 15:58:47 +0100662 msg "test: compat.sh (ASan build)" # ~ 6 min
663 if_build_succeeded tests/compat.sh
664}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200665
Hanno Becker01635512019-02-26 14:27:09 +0000666component_test_full_cmake_gcc_asan () {
667 msg "build: full config, cmake, gcc, ASan"
668 scripts/config.pl full
669 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
670 make
671
672 msg "test: main suites (inc. selftests) (full config, ASan build)"
673 make test
674
675 msg "test: ssl-opt.sh (full config, ASan build)"
676 if_build_succeeded tests/ssl-opt.sh
677
678 msg "test: compat.sh (full config, ASan build)"
679 if_build_succeeded tests/compat.sh
680}
681
Gilles Peskine782f4112018-11-27 16:11:09 +0100682component_test_ref_configs () {
683 msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
684 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
685 record_status tests/scripts/test-ref-configs.pl
686}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200687
Gilles Peskine8f073122018-11-27 15:58:47 +0100688component_test_sslv3 () {
689 msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100690 scripts/config.pl set MBEDTLS_SSL_PROTO_SSL3
691 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
692 make
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200693
Gilles Peskine8f073122018-11-27 15:58:47 +0100694 msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
695 make test
Simon Butcher3ea7f522016-03-07 23:22:10 +0000696
Gilles Peskine8f073122018-11-27 15:58:47 +0100697 msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
698 if_build_succeeded tests/compat.sh -m 'tls1 tls1_1 tls1_2 dtls1 dtls1_2'
699 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
Simon Butcher3ea7f522016-03-07 23:22:10 +0000700
Gilles Peskine8f073122018-11-27 15:58:47 +0100701 msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
702 if_build_succeeded tests/ssl-opt.sh
703}
Simon Butcher3ea7f522016-03-07 23:22:10 +0000704
Gilles Peskine8f073122018-11-27 15:58:47 +0100705component_test_no_renegotiation () {
706 msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100707 scripts/config.pl unset MBEDTLS_SSL_RENEGOTIATION
708 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
709 make
Simon Butcher3ea7f522016-03-07 23:22:10 +0000710
Gilles Peskine8f073122018-11-27 15:58:47 +0100711 msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
712 make test
Hanno Becker134c2ab2017-10-12 15:29:50 +0100713
Gilles Peskine8f073122018-11-27 15:58:47 +0100714 msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
715 if_build_succeeded tests/ssl-opt.sh
716}
Hanno Becker134c2ab2017-10-12 15:29:50 +0100717
Hanno Beckera545be22019-05-10 14:45:37 +0100718component_test_no_pem_no_fs () {
719 msg "build: Default + !MBEDTLS_PEM_PARSE_C + !MBEDTLS_FS_IO (ASan build)"
720 scripts/config.pl unset MBEDTLS_PEM_PARSE_C
721 scripts/config.pl unset MBEDTLS_FS_IO
722 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
723 make
724
725 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - main suites (inc. selftests) (ASan build)" # ~ 50s
726 make test
727
728 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - ssl-opt.sh (ASan build)" # ~ 6 min
729 if_build_succeeded tests/ssl-opt.sh
730}
731
Gilles Peskine8f073122018-11-27 15:58:47 +0100732component_test_rsa_no_crt () {
733 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100734 scripts/config.pl set MBEDTLS_RSA_NO_CRT
735 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
736 make
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +0100737
Gilles Peskine8f073122018-11-27 15:58:47 +0100738 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
739 make test
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100740
Gilles Peskine8f073122018-11-27 15:58:47 +0100741 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
742 if_build_succeeded tests/ssl-opt.sh -f RSA
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100743
Gilles Peskine8f073122018-11-27 15:58:47 +0100744 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
745 if_build_succeeded tests/compat.sh -t RSA
746}
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100747
Gilles Peskine0c6b7992019-04-12 20:29:48 +0200748component_test_everest () {
749 msg "build: Everest ECDH context (ASan build)" # ~ 6 min
750 scripts/config.pl unset MBEDTLS_ECDH_LEGACY_CONTEXT
751 scripts/config.pl set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
752 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Asan .
753 make
754
755 msg "test: Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
756 make test
757
758 msg "test: Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
759 if_build_succeeded tests/ssl-opt.sh -f ECDH
760
761 msg "test: Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
762 # Exclude some symmetric ciphers that are redundant here to gain time.
763 if_build_succeeded tests/compat.sh -f ECDH -V NO -e 'ARCFOUR\|ARIA\|CAMELLIA\|CHACHA\|DES\|RC4'
764}
765
Gilles Peskine8f073122018-11-27 15:58:47 +0100766component_test_small_ssl_out_content_len () {
767 msg "build: small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100768 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 16384
769 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
770 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
771 make
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100772
Gilles Peskine8f073122018-11-27 15:58:47 +0100773 msg "test: small SSL_OUT_CONTENT_LEN - ssl-opt.sh MFL and large packet tests"
774 if_build_succeeded tests/ssl-opt.sh -f "Max fragment\|Large packet"
775}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000776
Gilles Peskine8f073122018-11-27 15:58:47 +0100777component_test_small_ssl_in_content_len () {
778 msg "build: small SSL_IN_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100779 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 4096
780 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 16384
781 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
782 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000783
Gilles Peskine8f073122018-11-27 15:58:47 +0100784 msg "test: small SSL_IN_CONTENT_LEN - ssl-opt.sh MFL tests"
785 if_build_succeeded tests/ssl-opt.sh -f "Max fragment"
786}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000787
Gilles Peskine8f073122018-11-27 15:58:47 +0100788component_test_small_ssl_dtls_max_buffering () {
789 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0"
Gilles Peskine8f073122018-11-27 15:58:47 +0100790 scripts/config.pl set MBEDTLS_SSL_DTLS_MAX_BUFFERING 1000
791 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
792 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000793
Gilles Peskine8f073122018-11-27 15:58:47 +0100794 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0 - ssl-opt.sh specific reordering test"
795 if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer out-of-order hs msg before reassembling next, free buffered msg"
796}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100797
Gilles Peskine8f073122018-11-27 15:58:47 +0100798component_test_small_mbedtls_ssl_dtls_max_buffering () {
799 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1"
Manuel Pégourié-Gonnardeef4c752019-05-28 10:21:30 +0200800 scripts/config.pl set MBEDTLS_SSL_DTLS_MAX_BUFFERING 190
Gilles Peskine8f073122018-11-27 15:58:47 +0100801 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
802 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100803
Gilles Peskine8f073122018-11-27 15:58:47 +0100804 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1 - ssl-opt.sh specific reordering test"
805 if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer encrypted Finished message, drop for fragmented NewSessionTicket"
806}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100807
Gilles Peskine8f073122018-11-27 15:58:47 +0100808component_test_full_cmake_clang () {
809 msg "build: cmake, full config, clang" # ~ 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100810 scripts/config.pl full
Gilles Peskine8f073122018-11-27 15:58:47 +0100811 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check -D ENABLE_TESTING=On .
812 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100813
Gilles Peskine8f073122018-11-27 15:58:47 +0100814 msg "test: main suites (full config)" # ~ 5s
815 make test
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100816
Gilles Peskine8f073122018-11-27 15:58:47 +0100817 msg "test: ssl-opt.sh default, ECJPAKE, SSL async (full config)" # ~ 1s
818 if_build_succeeded tests/ssl-opt.sh -f 'Default\|ECJPAKE\|SSL async private'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200819
Andres Amaya Garcia2dadab72019-01-08 21:42:27 +0000820 msg "test: compat.sh RC4, DES, 3DES & NULL (full config)" # ~ 2 min
Andres Amaya Garcia419bd002019-02-19 20:20:57 +0000821 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 +0200822
Gilles Peskine8f073122018-11-27 15:58:47 +0100823 msg "test: compat.sh ARIA + ChachaPoly"
824 if_build_succeeded env OPENSSL_CMD="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
825}
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200826
Gilles Peskine8f073122018-11-27 15:58:47 +0100827component_build_deprecated () {
828 msg "build: make, full config + DEPRECATED_WARNING, gcc -O" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100829 scripts/config.pl full
830 scripts/config.pl set MBEDTLS_DEPRECATED_WARNING
831 # Build with -O -Wextra to catch a maximum of issues.
832 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra' lib programs
833 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100834
Gilles Peskine8f073122018-11-27 15:58:47 +0100835 msg "build: make, full config + DEPRECATED_REMOVED, clang -O" # ~ 30s
836 # No cleanup, just tweak the configuration and rebuild
837 make clean
838 scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
839 scripts/config.pl set MBEDTLS_DEPRECATED_REMOVED
840 # Build with -O -Wextra to catch a maximum of issues.
841 make CC=clang CFLAGS='-O -Werror -Wall -Wextra' lib programs
842 make CC=clang CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
843}
Jaeden Ameroed93bdc2018-11-02 16:57:24 +0000844
Gilles Peskine8f073122018-11-27 15:58:47 +0100845component_test_depends_curves () {
846 msg "test/build: curves.pl (gcc)" # ~ 4 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100847 record_status tests/scripts/curves.pl
848}
Jaeden Ameroacaabe72018-11-07 11:52:52 +0000849
Gilles Peskine8f073122018-11-27 15:58:47 +0100850component_test_depends_hashes () {
851 msg "test/build: depends-hashes.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100852 record_status tests/scripts/depends-hashes.pl
853}
Jaeden Ameroacaabe72018-11-07 11:52:52 +0000854
Gilles Peskine8f073122018-11-27 15:58:47 +0100855component_test_depends_pkalgs () {
856 msg "test/build: depends-pkalgs.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100857 record_status tests/scripts/depends-pkalgs.pl
858}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100859
Gilles Peskine8f073122018-11-27 15:58:47 +0100860component_build_key_exchanges () {
861 msg "test/build: key-exchanges (gcc)" # ~ 1 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100862 record_status tests/scripts/key-exchanges.pl
863}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100864
Gilles Peskine8f073122018-11-27 15:58:47 +0100865component_build_default_make_gcc_and_cxx () {
866 msg "build: Unix make, -Os (gcc)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100867 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100868
Gilles Peskine8f073122018-11-27 15:58:47 +0100869 msg "test: verify header list in cpp_dummy_build.cpp"
870 record_status check_headers_in_cpp
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100871
Gilles Peskine8f073122018-11-27 15:58:47 +0100872 msg "build: Unix make, incremental g++"
873 make TEST_CPP=1
874}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100875
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100876component_test_no_use_psa_crypto_full_cmake_asan() {
877 # full minus MBEDTLS_USE_PSA_CRYPTO: run the same set of tests as basic-build-test.sh
Gilles Peskinedc3a1792019-09-03 11:42:04 +0200878 msg "build: cmake, full config minus MBEDTLS_USE_PSA_CRYPTO, ASan"
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500879 scripts/config.pl full
Jaeden Amero0f220ec2019-07-05 15:03:40 +0100880 scripts/config.pl set MBEDTLS_ECP_RESTARTABLE # not using PSA, so enable restartable ECC
Gilles Peskine6ce30722019-07-31 18:13:20 +0200881 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_C
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100882 scripts/config.pl unset MBEDTLS_USE_PSA_CRYPTO
883 scripts/config.pl unset MBEDTLS_PSA_ITS_FILE_C
Andrzej Kurek324b2f72019-04-18 08:59:12 -0400884 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_C
Manuel Pégourié-Gonnardd8167e82019-02-01 11:12:52 +0100885 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500886 make
Manuel Pégourié-Gonnard43be6cd2017-06-20 09:53:42 +0200887
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100888 msg "test: main suites (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500889 make test
Manuel Pégourié-Gonnard503a5ef2015-10-23 09:04:45 +0200890
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100891 msg "test: ssl-opt.sh (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500892 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100893
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100894 msg "test: compat.sh default (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500895 if_build_succeeded tests/compat.sh
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400896
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100897 msg "test: compat.sh ssl3 (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500898 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400899
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100900 msg "test: compat.sh RC4, DES & NULL (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500901 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 -0500902
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100903 msg "test: compat.sh ARIA + ChachaPoly (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500904 if_build_succeeded env OPENSSL_CMD="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
905}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500906
Gilles Peskineadcde5e2019-06-12 16:05:50 +0200907component_test_check_params_functionality () {
908 msg "build+test: MBEDTLS_CHECK_PARAMS functionality"
909 scripts/config.pl full # includes CHECK_PARAMS
910 # Make MBEDTLS_PARAM_FAILED call mbedtls_param_failed().
911 scripts/config.pl unset MBEDTLS_CHECK_PARAMS_ASSERT
Gilles Peskineadcde5e2019-06-12 16:05:50 +0200912 # Only build and run tests. Do not build sample programs, because
913 # they don't have a mbedtls_param_failed() function.
914 make CC=gcc CFLAGS='-Werror -O1' lib test
915}
916
Gilles Peskineb28636b2019-01-02 19:06:24 +0100917component_test_check_params_without_platform () {
918 msg "build+test: MBEDTLS_CHECK_PARAMS without MBEDTLS_PLATFORM_C"
919 scripts/config.pl full # includes CHECK_PARAMS
Gilles Peskineadcde5e2019-06-12 16:05:50 +0200920 # Keep MBEDTLS_PARAM_FAILED as assert.
Gilles Peskineb28636b2019-01-02 19:06:24 +0100921 scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
922 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
923 scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
924 scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
925 scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
926 scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
927 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
928 scripts/config.pl unset MBEDTLS_PLATFORM_C
929 make CC=gcc CFLAGS='-Werror -O1' all test
930}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500931
Gilles Peskineb28636b2019-01-02 19:06:24 +0100932component_test_check_params_silent () {
933 msg "build+test: MBEDTLS_CHECK_PARAMS with alternative MBEDTLS_PARAM_FAILED()"
934 scripts/config.pl full # includes CHECK_PARAMS
Gilles Peskineadcde5e2019-06-12 16:05:50 +0200935 # Set MBEDTLS_PARAM_FAILED to nothing.
Gilles Peskineb28636b2019-01-02 19:06:24 +0100936 sed -i 's/.*\(#define MBEDTLS_PARAM_FAILED( cond )\).*/\1/' "$CONFIG_H"
937 make CC=gcc CFLAGS='-Werror -O1' all test
938}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500939
Gilles Peskine8f073122018-11-27 15:58:47 +0100940component_test_no_platform () {
941 # Full configuration build, without platform support, file IO and net sockets.
942 # This should catch missing mbedtls_printf definitions, and by disabling file
943 # IO, it should catch missing '#include <stdio.h>'
944 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100945 scripts/config.pl full
946 scripts/config.pl unset MBEDTLS_PLATFORM_C
947 scripts/config.pl unset MBEDTLS_NET_C
948 scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
949 scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
950 scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
951 scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
952 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
953 scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
954 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskine8f073122018-11-27 15:58:47 +0100955 scripts/config.pl unset MBEDTLS_FS_IO
Andrzej Kurek73757082019-04-18 04:14:37 -0400956 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_C
957 scripts/config.pl unset MBEDTLS_PSA_ITS_FILE_C
Gilles Peskine8f073122018-11-27 15:58:47 +0100958 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
959 # to re-enable platform integration features otherwise disabled in C99 builds
960 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -O0 -D_DEFAULT_SOURCE' lib programs
961 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0' test
962}
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +0000963
Gilles Peskine8f073122018-11-27 15:58:47 +0100964component_build_no_std_function () {
965 # catch compile bugs in _uninit functions
966 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100967 scripts/config.pl full
968 scripts/config.pl set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
969 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
970 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
971}
Manuel Pégourié-Gonnarddccb80b2015-06-03 10:20:33 +0100972
Gilles Peskine8f073122018-11-27 15:58:47 +0100973component_build_no_ssl_srv () {
974 msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100975 scripts/config.pl full
976 scripts/config.pl unset MBEDTLS_SSL_SRV_C
977 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
978}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200979
Gilles Peskine8f073122018-11-27 15:58:47 +0100980component_build_no_ssl_cli () {
981 msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100982 scripts/config.pl full
983 scripts/config.pl unset MBEDTLS_SSL_CLI_C
984 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
985}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200986
Gilles Peskine8f073122018-11-27 15:58:47 +0100987component_build_no_sockets () {
988 # Note, C99 compliance can also be tested with the sockets support disabled,
989 # as that requires a POSIX platform (which isn't the same as C99).
990 msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100991 scripts/config.pl full
992 scripts/config.pl unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
993 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
994 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0 -std=c99 -pedantic' lib
995}
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +0200996
Andrzej Kurek69f20aa2019-09-05 09:27:47 -0400997component_test_memory_buffer_allocator_backtrace () {
998 msg "build: default config with memory buffer allocator and backtrace enabled"
Hanno Becker0fb9ba22019-02-26 14:34:13 +0000999 scripts/config.pl set MBEDTLS_MEMORY_BUFFER_ALLOC_C
Andrzej Kurek69f20aa2019-09-05 09:27:47 -04001000 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
Hanno Becker0fb9ba22019-02-26 14:34:13 +00001001 scripts/config.pl set MBEDTLS_MEMORY_BACKTRACE
Andrzej Kurek9f409f62019-09-10 02:58:34 -04001002 scripts/config.pl set MBEDTLS_MEMORY_DEBUG
Andrzej Kurek69f20aa2019-09-05 09:27:47 -04001003 CC=gcc cmake .
1004 make
1005
1006 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C and MBEDTLS_MEMORY_BACKTRACE"
1007 make test
1008}
1009
1010component_test_memory_buffer_allocator () {
1011 msg "build: default config with memory buffer allocator"
1012 scripts/config.pl set MBEDTLS_MEMORY_BUFFER_ALLOC_C
Hanno Beckerd7064202019-06-03 16:35:02 +01001013 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
Hanno Becker0fb9ba22019-02-26 14:34:13 +00001014 CC=gcc cmake .
1015 make
1016
1017 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C"
1018 make test
1019
1020 msg "test: ssl-opt.sh, MBEDTLS_MEMORY_BUFFER_ALLOC_C"
Andrzej Kurek1e56d2c2019-09-05 10:09:37 -04001021 # MBEDTLS_MEMORY_BUFFER_ALLOC is slow. Skip tests that tend to time out.
1022 if_build_succeeded tests/ssl-opt.sh -e '^DTLS proxy'
Hanno Becker0fb9ba22019-02-26 14:34:13 +00001023}
1024
Gilles Peskine8f073122018-11-27 15:58:47 +01001025component_test_no_max_fragment_length () {
1026 # Run max fragment length tests with MFL disabled
1027 msg "build: default config except MFL extension (ASan build)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +01001028 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
1029 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1030 make
Hanno Becker5175ac62017-09-18 15:36:25 +01001031
Gilles Peskine8f073122018-11-27 15:58:47 +01001032 msg "test: ssl-opt.sh, MFL-related tests"
1033 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length"
1034}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001035
Hanno Becker545ced42019-02-19 11:10:48 +00001036component_test_asan_remove_peer_certificate () {
1037 msg "build: default config with MBEDTLS_SSL_KEEP_PEER_CERTIFICATE disabled (ASan build)"
1038 scripts/config.pl unset MBEDTLS_SSL_KEEP_PEER_CERTIFICATE
1039 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1040 make
1041
1042 msg "test: !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
1043 make test
1044
1045 msg "test: ssl-opt.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
1046 if_build_succeeded tests/ssl-opt.sh
1047
1048 msg "test: compat.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
1049 if_build_succeeded tests/compat.sh
1050}
1051
Gilles Peskine8f073122018-11-27 15:58:47 +01001052component_test_no_max_fragment_length_small_ssl_out_content_len () {
1053 msg "build: no MFL extension, small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +01001054 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
1055 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 16384
1056 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
1057 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1058 make
Angus Grattonc4dd0732018-04-11 16:28:39 +10001059
Gilles Peskine8f073122018-11-27 15:58:47 +01001060 msg "test: MFL tests (disabled MFL extension case) & large packet tests"
1061 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length\|Large buffer"
1062}
Angus Grattonc4dd0732018-04-11 16:28:39 +10001063
Jaeden Amero2de07f12019-06-05 13:32:08 +01001064component_test_when_no_ciphersuites_have_mac () {
1065 msg "build: when no ciphersuites have MAC"
1066 scripts/config.pl unset MBEDTLS_CIPHER_NULL_CIPHER
1067 scripts/config.pl unset MBEDTLS_ARC4_C
1068 scripts/config.pl unset MBEDTLS_CIPHER_MODE_CBC
1069 make
1070
1071 msg "test: !MBEDTLS_SSL_SOME_MODES_USE_MAC"
1072 make test
1073
1074 msg "test ssl-opt.sh: !MBEDTLS_SSL_SOME_MODES_USE_MAC"
Jaeden Amero6b1683d2019-06-05 14:42:50 +01001075 if_build_succeeded tests/ssl-opt.sh -f 'Default\|EtM' -e 'without EtM'
Jaeden Amero2de07f12019-06-05 13:32:08 +01001076}
1077
Gilles Peskine8f073122018-11-27 15:58:47 +01001078component_test_null_entropy () {
1079 msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +01001080 scripts/config.pl set MBEDTLS_TEST_NULL_ENTROPY
1081 scripts/config.pl set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
1082 scripts/config.pl set MBEDTLS_ENTROPY_C
1083 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
1084 scripts/config.pl unset MBEDTLS_ENTROPY_HARDWARE_ALT
1085 scripts/config.pl unset MBEDTLS_HAVEGE_C
Gilles Peskine5fa32a72019-01-06 19:48:30 +00001086 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan -D UNSAFE_BUILD=ON .
Gilles Peskine8f073122018-11-27 15:58:47 +01001087 make
Janos Follath06c54002016-06-09 13:57:40 +01001088
Gilles Peskine8f073122018-11-27 15:58:47 +01001089 msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)"
1090 make test
1091}
Janos Follath06c54002016-06-09 13:57:40 +01001092
Gilles Peskine8f073122018-11-27 15:58:47 +01001093component_test_platform_calloc_macro () {
1094 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +01001095 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
1096 scripts/config.pl set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
1097 scripts/config.pl set MBEDTLS_PLATFORM_FREE_MACRO free
1098 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1099 make
Hanno Beckere5fecec2018-10-11 11:02:52 +01001100
Gilles Peskine8f073122018-11-27 15:58:47 +01001101 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
1102 make test
1103}
Hanno Beckere5fecec2018-10-11 11:02:52 +01001104
Gilles Peskine8f073122018-11-27 15:58:47 +01001105component_test_make_shared () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001106 msg "build/test: make shared" # ~ 40s
Andrzej Kurek87615772019-04-19 15:03:58 -04001107 make SHARED=1 all check -j1
Gilles Peskine56c01612019-07-03 20:43:32 +02001108 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskine8f073122018-11-27 15:58:47 +01001109}
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +02001110
Gilles Peskinecf740502019-07-03 20:43:05 +02001111component_test_cmake_shared () {
1112 msg "build/test: cmake shared" # ~ 2min
1113 cmake -DUSE_SHARED_MBEDTLS_LIBRARY=On .
1114 make
Gilles Peskine56c01612019-07-03 20:43:32 +02001115 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskinecf740502019-07-03 20:43:05 +02001116 make test
1117}
1118
Gilles Peskineabf9b4d2019-07-03 20:42:16 +02001119component_build_mbedtls_config_file () {
1120 msg "build: make with MBEDTLS_CONFIG_FILE" # ~40s
1121 # Use the full config so as to catch a maximum of places where
1122 # the check of MBEDTLS_CONFIG_FILE might be missing.
1123 scripts/config.pl full
1124 sed 's!"check_config.h"!"mbedtls/check_config.h"!' <"$CONFIG_H" >full_config.h
1125 echo '#error "MBEDTLS_CONFIG_FILE is not working"' >"$CONFIG_H"
1126 make CFLAGS="-I '$PWD' -DMBEDTLS_CONFIG_FILE='\"full_config.h\"'"
1127 rm -f full_config.h
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001128}
1129
Gilles Peskine8f073122018-11-27 15:58:47 +01001130component_test_m32_o0 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001131 # Build once with -O0, to compile out the i386 specific inline assembly
1132 msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
Simon Butcher7a6da6e2018-06-27 21:52:54 +01001133 scripts/config.pl full
Philippe Antoinecd2c1272019-06-25 21:50:07 +02001134 make CC=gcc CFLAGS='-O0 -Werror -Wall -Wextra -m32 -fsanitize=address' LDFLAGS='-m32 -fsanitize=address'
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01001135
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001136 msg "test: i386, make, gcc -O0 (ASan build)"
1137 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01001138}
Gilles Peskine878cf602019-01-06 20:50:38 +00001139support_test_m32_o0 () {
1140 case $(uname -m) in
1141 *64*) true;;
1142 *) false;;
1143 esac
1144}
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001145
Gilles Peskine8f073122018-11-27 15:58:47 +01001146component_test_m32_o1 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001147 # Build again with -O1, to compile in the i386 specific inline assembly
1148 msg "build: i386, make, gcc -O1 (ASan build)" # ~ 30s
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001149 scripts/config.pl full
Philippe Antoinecd2c1272019-06-25 21:50:07 +02001150 make CC=gcc CFLAGS='-O1 -Werror -Wall -Wextra -m32 -fsanitize=address' LDFLAGS='-m32 -fsanitize=address'
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001151
1152 msg "test: i386, make, gcc -O1 (ASan build)"
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001153 make test
Gilles Peskine4b317612019-04-08 16:58:02 +02001154
1155 msg "test ssl-opt.sh, i386, make, gcc-O1"
1156 if_build_succeeded tests/ssl-opt.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01001157}
Gilles Peskine878cf602019-01-06 20:50:38 +00001158support_test_m32_o1 () {
1159 support_test_m32_o0 "$@"
1160}
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001161
Gilles Peskine0c6b7992019-04-12 20:29:48 +02001162component_test_m32_everest () {
1163 msg "build: i386, Everest ECDH context (ASan build)" # ~ 6 min
1164 scripts/config.pl unset MBEDTLS_ECDH_LEGACY_CONTEXT
1165 scripts/config.pl set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
1166 make CC=gcc CFLAGS='-O2 -Werror -Wall -Wextra -m32 -fsanitize=address' LDFLAGS='-m32 -fsanitize=address'
1167
1168 msg "test: i386, Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
1169 make test
1170
1171 msg "test: i386, Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
1172 if_build_succeeded tests/ssl-opt.sh -f ECDH
1173
1174 msg "test: i386, Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
1175 # Exclude some symmetric ciphers that are redundant here to gain time.
1176 if_build_succeeded tests/compat.sh -f ECDH -V NO -e 'ARCFOUR\|ARIA\|CAMELLIA\|CHACHA\|DES\|RC4'
1177}
1178support_test_m32_everest () {
1179 support_test_m32_o0 "$@"
1180}
1181
Gilles Peskine8f073122018-11-27 15:58:47 +01001182component_test_mx32 () {
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001183 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
Simon Butcher7a6da6e2018-06-27 21:52:54 +01001184 scripts/config.pl full
Gilles Peskine5d26e7c2019-06-07 14:50:09 +02001185 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32' LDFLAGS='-mx32'
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001186
1187 msg "test: 64-bit ILP32, make, gcc"
1188 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01001189}
Gilles Peskine878cf602019-01-06 20:50:38 +00001190support_test_mx32 () {
1191 case $(uname -m) in
1192 amd64|x86_64) true;;
1193 *) false;;
1194 esac
1195}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001196
Gilles Peskine8f073122018-11-27 15:58:47 +01001197component_build_arm_none_eabi_gcc () {
1198 msg "build: arm-none-eabi-gcc, make" # ~ 10s
Manuel Pégourié-Gonnarddf2bfcf2019-04-29 12:44:12 +02001199 scripts/config.pl baremetal
Gilles Peskine8f073122018-11-27 15:58:47 +01001200 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
1201}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001202
Gilles Peskine2c897d72019-08-09 16:05:05 +02001203component_build_arm_none_eabi_gcc_arm5vte () {
Gilles Peskine8a52af92019-08-08 16:09:02 +02001204 msg "build: arm-none-eabi-gcc -march=arm5vte, make" # ~ 10s
Gilles Peskine93e4e032019-08-05 11:34:25 +02001205 scripts/config.pl baremetal
Gilles Peskine2c897d72019-08-09 16:05:05 +02001206 # Build for a target platform that's close to what Debian uses
1207 # for its "armel" distribution (https://wiki.debian.org/ArmEabiPort).
1208 # See https://github.com/ARMmbed/mbedtls/pull/2169 and comments.
1209 # It would be better to build with arm-linux-gnueabi-gcc but
1210 # we don't have that on our CI at this time.
Gilles Peskine8a52af92019-08-08 16:09:02 +02001211 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 +02001212}
1213
Gilles Peskine8f073122018-11-27 15:58:47 +01001214component_build_arm_none_eabi_gcc_no_udbl_division () {
1215 msg "build: arm-none-eabi-gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
Manuel Pégourié-Gonnarddf2bfcf2019-04-29 12:44:12 +02001216 scripts/config.pl baremetal
Gilles Peskine8f073122018-11-27 15:58:47 +01001217 scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
1218 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
1219 echo "Checking that software 64-bit division is not required"
1220 if_build_succeeded not grep __aeabi_uldiv library/*.o
1221}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001222
Gilles Peskine8f073122018-11-27 15:58:47 +01001223component_build_arm_none_eabi_gcc_no_64bit_multiplication () {
1224 msg "build: arm-none-eabi-gcc MBEDTLS_NO_64BIT_MULTIPLICATION, make" # ~ 10s
Manuel Pégourié-Gonnarddf2bfcf2019-04-29 12:44:12 +02001225 scripts/config.pl baremetal
Gilles Peskine8f073122018-11-27 15:58:47 +01001226 scripts/config.pl set MBEDTLS_NO_64BIT_MULTIPLICATION
1227 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -O1 -march=armv6-m -mthumb' lib
1228 echo "Checking that software 64-bit multiplication is not required"
1229 if_build_succeeded not grep __aeabi_lmul library/*.o
1230}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001231
Gilles Peskine8f073122018-11-27 15:58:47 +01001232component_build_armcc () {
1233 msg "build: ARM Compiler 5, make"
Manuel Pégourié-Gonnarddf2bfcf2019-04-29 12:44:12 +02001234 scripts/config.pl baremetal
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001235
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001236 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
1237 make clean
Andres AG87bb5772016-09-27 15:05:15 +01001238
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001239 # ARM Compiler 6 - Target ARMv7-A
1240 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-a"
Simon Butcher940737f2017-07-23 13:42:36 +02001241
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001242 # ARM Compiler 6 - Target ARMv7-M
1243 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m"
Simon Butcher940737f2017-07-23 13:42:36 +02001244
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001245 # ARM Compiler 6 - Target ARMv8-A - AArch32
1246 armc6_build_test "--target=arm-arm-none-eabi -march=armv8.2-a"
Simon Butcher940737f2017-07-23 13:42:36 +02001247
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001248 # ARM Compiler 6 - Target ARMv8-M
1249 armc6_build_test "--target=arm-arm-none-eabi -march=armv8-m.main"
Simon Butcher940737f2017-07-23 13:42:36 +02001250
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001251 # ARM Compiler 6 - Target ARMv8-A - AArch64
1252 armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a"
Gilles Peskine8f073122018-11-27 15:58:47 +01001253}
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +01001254
Gilles Peskine8f073122018-11-27 15:58:47 +01001255component_test_allow_sha1 () {
1256 msg "build: allow SHA1 in certificates by default"
Gilles Peskine8f073122018-11-27 15:58:47 +01001257 scripts/config.pl set MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
1258 make CFLAGS='-Werror -Wall -Wextra'
1259 msg "test: allow SHA1 in certificates by default"
1260 make test
1261 if_build_succeeded tests/ssl-opt.sh -f SHA-1
1262}
Gilles Peskine2a458da2017-05-12 15:26:58 +02001263
Gilles Peskine8f073122018-11-27 15:58:47 +01001264component_build_mingw () {
1265 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
Andrzej Kurek62faadd2019-04-19 20:10:21 -04001266 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 +00001267
Gilles Peskine8f073122018-11-27 15:58:47 +01001268 # note Make tests only builds the tests, but doesn't run them
Andrzej Kurek62faadd2019-04-19 20:10:21 -04001269 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 +01001270 make WINDOWS_BUILD=1 clean
Simon Butcher002bc622016-11-17 09:27:45 +00001271
Gilles Peskine8f073122018-11-27 15:58:47 +01001272 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
Andrzej Kurek87615772019-04-19 15:03:58 -04001273 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
1274 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 +01001275 make WINDOWS_BUILD=1 clean
1276}
Jaeden Amero117b8a42019-04-17 15:19:26 +01001277support_build_mingw() {
1278 case $(i686-w64-mingw32-gcc -dumpversion) in
1279 [0-5]*) false;;
1280 *) true;;
1281 esac
1282}
Manuel Pégourié-Gonnard6448bce2015-02-16 17:18:36 +01001283
Gilles Peskine8f073122018-11-27 15:58:47 +01001284component_test_memsan () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001285 msg "build: MSan (clang)" # ~ 1 min 20s
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001286 scripts/config.pl unset MBEDTLS_AESNI_C # memsan doesn't grok asm
1287 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
1288 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +02001289
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001290 msg "test: main suites (MSan)" # ~ 10s
1291 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001292
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001293 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
Gilles Peskine7c652162017-12-11 00:01:40 +01001294 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001295
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001296 # Optional part(s)
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001297
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001298 if [ "$MEMORY" -gt 0 ]; then
1299 msg "test: compat.sh (MSan)" # ~ 6 min 20s
Gilles Peskine7c652162017-12-11 00:01:40 +01001300 if_build_succeeded tests/compat.sh
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001301 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001302}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001303
Gilles Peskine69f190e2019-01-10 00:11:42 +01001304component_test_valgrind () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001305 msg "build: Release (clang)"
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001306 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
1307 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001308
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001309 msg "test: main suites valgrind (Release)"
1310 make memcheck
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001311
Gilles Peskinef1349e42019-04-08 17:00:56 +02001312 # Optional parts (slow; currently broken on OS X because programs don't
1313 # seem to receive signals under valgrind on OS X).
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001314 if [ "$MEMORY" -gt 0 ]; then
1315 msg "test: ssl-opt.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +01001316 if_build_succeeded tests/ssl-opt.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001317 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001318
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001319 if [ "$MEMORY" -gt 1 ]; then
1320 msg "test: compat.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +01001321 if_build_succeeded tests/compat.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001322 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001323}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001324
Gilles Peskine8f073122018-11-27 15:58:47 +01001325component_test_cmake_out_of_source () {
1326 msg "build: cmake 'out-of-source' build"
Gilles Peskine8f073122018-11-27 15:58:47 +01001327 MBEDTLS_ROOT_DIR="$PWD"
1328 mkdir "$OUT_OF_SOURCE_DIR"
1329 cd "$OUT_OF_SOURCE_DIR"
1330 cmake "$MBEDTLS_ROOT_DIR"
1331 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001332
Gilles Peskine8f073122018-11-27 15:58:47 +01001333 msg "test: cmake 'out-of-source' build"
1334 make test
1335 # Test an SSL option that requires an auxiliary script in test/scripts/.
1336 # Also ensure that there are no error messages such as
1337 # "No such file or directory", which would indicate that some required
1338 # file is missing (ssl-opt.sh tolerates the absence of some files so
1339 # may exit with status 0 but emit errors).
1340 if_build_succeeded ./tests/ssl-opt.sh -f 'Fallback SCSV: beginning of list' 2>ssl-opt.err
1341 if [ -s ssl-opt.err ]; then
1342 cat ssl-opt.err >&2
1343 record_status [ ! -s ssl-opt.err ]
1344 rm ssl-opt.err
1345 fi
1346 cd "$MBEDTLS_ROOT_DIR"
1347 rm -rf "$OUT_OF_SOURCE_DIR"
1348 unset MBEDTLS_ROOT_DIR
1349}
Andres AGdc192212016-08-31 17:33:13 +01001350
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01001351component_test_cmake_as_subdirectory () {
1352 msg "build: cmake 'as-subdirectory' build"
1353 MBEDTLS_ROOT_DIR="$PWD"
1354
1355 cd programs/test/cmake_subproject
1356 cmake .
1357 make
1358 if_build_succeeded ./cmake_subproject
1359
1360 cd "$MBEDTLS_ROOT_DIR"
1361 unset MBEDTLS_ROOT_DIR
1362}
1363
Gilles Peskine8f073122018-11-27 15:58:47 +01001364component_test_zeroize () {
1365 # Test that the function mbedtls_platform_zeroize() is not optimized away by
1366 # different combinations of compilers and optimization flags by using an
1367 # auxiliary GDB script. Unfortunately, GDB does not return error values to the
1368 # system in all cases that the script fails, so we must manually search the
1369 # output to check whether the pass string is present and no failure strings
1370 # were printed.
Andres AGdc192212016-08-31 17:33:13 +01001371
Gilles Peskine4976e822019-01-06 19:52:22 +00001372 # Don't try to disable ASLR. We don't care about ASLR here. We do care
1373 # about a spurious message if Gdb tries and fails, so suppress that.
1374 gdb_disable_aslr=
1375 if [ -z "$(gdb -batch -nw -ex 'set disable-randomization off' 2>&1)" ]; then
1376 gdb_disable_aslr='set disable-randomization off'
1377 fi
1378
Gilles Peskine8f073122018-11-27 15:58:47 +01001379 for optimization_flag in -O2 -O3 -Ofast -Os; do
Gilles Peskine55f7c942019-01-09 22:28:21 +01001380 for compiler in clang gcc; do
1381 msg "test: $compiler $optimization_flag, mbedtls_platform_zeroize()"
1382 make programs CC="$compiler" DEBUG=1 CFLAGS="$optimization_flag"
Gilles Peskine4976e822019-01-06 19:52:22 +00001383 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 +01001384 if_build_succeeded grep "The buffer was correctly zeroized" test_zeroize.log
1385 if_build_succeeded not grep -i "error" test_zeroize.log
1386 rm -f test_zeroize.log
1387 make clean
1388 done
Andres Amaya Garcia29673812017-10-25 10:35:51 +01001389 done
Andres Amaya Garciad0d7bf62017-10-25 09:01:31 +01001390
Gilles Peskine4976e822019-01-06 19:52:22 +00001391 unset gdb_disable_aslr
Gilles Peskine8f073122018-11-27 15:58:47 +01001392}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001393
Gilles Peskineaad2ebd2019-02-25 20:26:06 +01001394support_check_python_files () {
1395 type pylint3 >/dev/null 2>/dev/null
1396}
Gilles Peskine8f073122018-11-27 15:58:47 +01001397component_check_python_files () {
1398 msg "Lint: Python scripts"
1399 record_status tests/scripts/check-python-files.sh
1400}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001401
Gilles Peskine8f073122018-11-27 15:58:47 +01001402component_check_generate_test_code () {
1403 msg "uint test: generate_test_code.py"
1404 record_status ./tests/scripts/test_generate_test_code.py
1405}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001406
1407################################################################
1408#### Termination
1409################################################################
1410
Gilles Peskine8f073122018-11-27 15:58:47 +01001411post_report () {
1412 msg "Done, cleaning up"
1413 cleanup
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001414
Gilles Peskine8f073122018-11-27 15:58:47 +01001415 final_report
1416}
1417
1418
1419
1420################################################################
1421#### Run all the things
1422################################################################
1423
Gilles Peskinee48351a2018-11-27 16:06:30 +01001424# Run one component and clean up afterwards.
Gilles Peskine8f073122018-11-27 15:58:47 +01001425run_component () {
Gilles Peskine608953e2019-01-02 18:57:02 +01001426 # Back up the configuration in case the component modifies it.
1427 # The cleanup function will restore it.
1428 cp -p "$CONFIG_H" "$CONFIG_BAK"
Gilles Peskineffcdeff2018-12-04 12:49:28 +01001429 current_component="$1"
Gilles Peskine9004a172019-09-16 15:20:36 +02001430 export MBEDTLS_TEST_CONFIGURATION="$current_component"
Gilles Peskine8f073122018-11-27 15:58:47 +01001431 "$@"
Gilles Peskinee48351a2018-11-27 16:06:30 +01001432 cleanup
Gilles Peskine8f073122018-11-27 15:58:47 +01001433}
1434
1435# Preliminary setup
1436pre_check_environment
1437pre_initialize_variables
1438pre_parse_command_line "$@"
Gilles Peskine348fb9a2018-11-27 17:04:29 +01001439
Gilles Peskine878cf602019-01-06 20:50:38 +00001440pre_check_git
Andrzej Kurekeb508712019-02-14 07:18:59 -05001441pre_check_seedfile
1442
Gilles Peskine878cf602019-01-06 20:50:38 +00001443build_status=0
1444if [ $KEEP_GOING -eq 1 ]; then
1445 pre_setup_keep_going
Gilles Peskine92525112018-11-27 18:15:35 +01001446else
Gilles Peskine878cf602019-01-06 20:50:38 +00001447 record_status () {
1448 "$@"
1449 }
Gilles Peskine8f073122018-11-27 15:58:47 +01001450fi
Gilles Peskine878cf602019-01-06 20:50:38 +00001451pre_print_configuration
1452pre_check_tools
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001453cleanup
1454
Gilles Peskinebeb3a812019-01-06 22:11:25 +00001455# Run the requested tests.
1456for component in $RUN_COMPONENTS; do
1457 run_component "component_$component"
1458done
Gilles Peskine8f073122018-11-27 15:58:47 +01001459
1460# We're done.
Gilles Peskine878cf602019-01-06 20:50:38 +00001461post_report