blob: fc8f5ece6bb1ec8c9e4b45bbbdbedbf774143289 [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
Jaeden Ameroc4cc2512019-01-30 15:35:44 +0000124 # Default commands, can be overridden by the environment
Gilles Peskine8f073122018-11-27 15:58:47 +0100125 : ${OPENSSL:="openssl"}
126 : ${OPENSSL_LEGACY:="$OPENSSL"}
127 : ${OPENSSL_NEXT:="$OPENSSL"}
128 : ${GNUTLS_CLI:="gnutls-cli"}
129 : ${GNUTLS_SERV:="gnutls-serv"}
130 : ${GNUTLS_LEGACY_CLI:="$GNUTLS_CLI"}
131 : ${GNUTLS_LEGACY_SERV:="$GNUTLS_SERV"}
132 : ${OUT_OF_SOURCE_DIR:=./mbedtls_out_of_source_build}
133 : ${ARMC5_BIN_DIR:=/usr/bin}
134 : ${ARMC6_BIN_DIR:=/usr/bin}
Andres AGdc192212016-08-31 17:33:13 +0100135
Gilles Peskine8f073122018-11-27 15:58:47 +0100136 # if MAKEFLAGS is not set add the -j option to speed up invocations of make
Gilles Peskinea1fc4b52019-01-06 20:15:26 +0000137 if [ -z "${MAKEFLAGS+set}" ]; then
Gilles Peskine8f073122018-11-27 15:58:47 +0100138 export MAKEFLAGS="-j"
139 fi
Gilles Peskine878cf602019-01-06 20:50:38 +0000140
141 # Gather the list of available components. These are the functions
142 # defined in this script whose name starts with "component_".
143 # Parse the script with sed, because in sh there is no way to list
144 # defined functions.
145 ALL_COMPONENTS=$(sed -n 's/^ *component_\([0-9A-Z_a-z]*\) *().*/\1/p' <"$0")
146
147 # Exclude components that are not supported on this platform.
148 SUPPORTED_COMPONENTS=
149 for component in $ALL_COMPONENTS; do
150 case $(type "support_$component" 2>&1) in
151 *' function'*)
152 if ! support_$component; then continue; fi;;
153 esac
154 SUPPORTED_COMPONENTS="$SUPPORTED_COMPONENTS $component"
155 done
Gilles Peskine8f073122018-11-27 15:58:47 +0100156}
Andres AG38495a32016-07-12 16:54:33 +0100157
Gilles Peskinea28db922019-01-10 00:05:18 +0100158# Test whether the component $1 is included in the command line patterns.
159is_component_included()
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100160{
161 set -f
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000162 for pattern in $COMMAND_LINE_COMPONENTS; do
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100163 set +f
164 case ${1#component_} in $pattern) return 0;; esac
165 done
166 set +f
167 return 1
168}
Andres AG7770ea82016-10-10 15:46:20 +0100169
Simon Butcher41eeccf2016-09-07 00:07:09 +0100170usage()
Andres AGd9eba4b2016-08-26 14:42:14 +0100171{
Gilles Peskine709346a2017-12-10 23:43:39 +0100172 cat <<EOF
Gilles Peskine92525112018-11-27 18:15:35 +0100173Usage: $0 [OPTION]... [COMPONENT]...
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100174Run mbedtls release validation tests.
Gilles Peskine92525112018-11-27 18:15:35 +0100175By default, run all tests. With one or more COMPONENT, run only those.
Gilles Peskinea28db922019-01-10 00:05:18 +0100176COMPONENT can be the name of a component or a shell wildcard pattern.
177
178Examples:
179 $0 "check_*"
180 Run all sanity checks.
181 $0 --no-armcc --except test_memsan
182 Run everything except builds that require armcc and MemSan.
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100183
184Special options:
185 -h|--help Print this help and exit.
Gilles Peskine878cf602019-01-06 20:50:38 +0000186 --list-all-components List all available test components and exit.
187 --list-components List components supported on this platform and exit.
Gilles Peskine709346a2017-12-10 23:43:39 +0100188
189General options:
190 -f|--force Force the tests to overwrite any modified files.
Gilles Peskine7c652162017-12-11 00:01:40 +0100191 -k|--keep-going Run all tests and report errors at the end.
Gilles Peskine709346a2017-12-10 23:43:39 +0100192 -m|--memory Additional optional memory tests.
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100193 --armcc Run ARM Compiler builds (on by default).
Gilles Peskinea28db922019-01-10 00:05:18 +0100194 --except Exclude the COMPONENTs listed on the command line,
195 instead of running only those.
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100196 --no-armcc Skip ARM Compiler builds.
Gilles Peskine38d81652018-03-21 08:40:26 +0100197 --no-force Refuse to overwrite modified files (default).
198 --no-keep-going Stop at the first error (default).
199 --no-memory No additional memory tests (default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100200 --out-of-source-dir=<path> Directory used for CMake out-of-source build tests.
Gilles Peskine38d81652018-03-21 08:40:26 +0100201 --random-seed Use a random seed value for randomized tests (default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100202 -r|--release-test Run this script in release mode. This fixes the seed value to 1.
203 -s|--seed Integer seed value to use for this test run.
204
205Tool path options:
206 --armc5-bin-dir=<ARMC5_bin_dir_path> ARM Compiler 5 bin directory.
207 --armc6-bin-dir=<ARMC6_bin_dir_path> ARM Compiler 6 bin directory.
208 --gnutls-cli=<GnuTLS_cli_path> GnuTLS client executable to use for most tests.
209 --gnutls-serv=<GnuTLS_serv_path> GnuTLS server executable to use for most tests.
210 --gnutls-legacy-cli=<GnuTLS_cli_path> GnuTLS client executable to use for legacy tests.
211 --gnutls-legacy-serv=<GnuTLS_serv_path> GnuTLS server executable to use for legacy tests.
212 --openssl=<OpenSSL_path> OpenSSL executable to use for most tests.
213 --openssl-legacy=<OpenSSL_path> OpenSSL executable to use for legacy tests e.g. SSLv3.
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100214 --openssl-next=<OpenSSL_path> OpenSSL executable to use for recent things like ARIA
Gilles Peskine709346a2017-12-10 23:43:39 +0100215EOF
SimonB2e23c822016-04-16 21:54:39 +0100216}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100217
218# remove built files as well as the cmake cache/config
219cleanup()
220{
Gilles Peskinea71d64c2018-03-21 12:16:57 +0100221 if [ -n "${MBEDTLS_ROOT_DIR+set}" ]; then
222 cd "$MBEDTLS_ROOT_DIR"
223 fi
224
Gilles Peskine7c652162017-12-11 00:01:40 +0100225 command make clean
Jaeden Ameroed93bdc2018-11-02 16:57:24 +0000226 cd crypto
227 command make clean
228 cd ..
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200229
Gilles Peskine31b07e22018-03-21 12:15:06 +0100230 # Remove CMake artefacts
Jaeden Amero2d0e00f2018-11-07 18:46:41 +0000231 find . -name .git -prune -o \
Gilles Peskine31b07e22018-03-21 12:15:06 +0100232 -iname CMakeFiles -exec rm -rf {} \+ -o \
233 \( -iname cmake_install.cmake -o \
234 -iname CTestTestfile.cmake -o \
235 -iname CMakeCache.txt \) -exec rm {} \+
236 # Recover files overwritten by in-tree CMake builds
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000237 rm -f include/Makefile include/mbedtls/Makefile programs/*/Makefile
Philippe Antoine5dece6d2019-06-27 16:55:07 +0200238 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile
239 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile
Jaeden Ameroed93bdc2018-11-02 16:57:24 +0000240 cd crypto
241 rm -f include/Makefile include/mbedtls/Makefile programs/*/Makefile
242 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile
243 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile
244 cd ..
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200245
Jaeden Ameroab83fdf2019-06-20 17:38:22 +0100246 # Remove any artifacts from the component_test_cmake_as_subdirectory test.
247 rm -rf programs/test/cmake_subproject/build
248 rm -f programs/test/cmake_subproject/Makefile
249 rm -f programs/test/cmake_subproject/cmake_subproject
250
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200251 if [ -f "$CONFIG_BAK" ]; then
252 mv "$CONFIG_BAK" "$CONFIG_H"
253 fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100254}
255
Gilles Peskine7c652162017-12-11 00:01:40 +0100256# Executed on exit. May be redefined depending on command line options.
257final_report () {
258 :
259}
260
261fatal_signal () {
262 cleanup
263 final_report $1
264 trap - $1
265 kill -$1 $$
266}
267
268trap 'fatal_signal HUP' HUP
269trap 'fatal_signal INT' INT
270trap 'fatal_signal TERM' TERM
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200271
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100272msg()
273{
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100274 if [ -n "${current_component:-}" ]; then
275 current_section="${current_component#component_}: $1"
276 else
277 current_section="$1"
278 fi
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100279 echo ""
280 echo "******************************************************************"
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100281 echo "* $current_section "
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000282 printf "* "; date
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100283 echo "******************************************************************"
284}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100285
Gilles Peskine8f073122018-11-27 15:58:47 +0100286armc6_build_test()
287{
288 FLAGS="$1"
Andres AGa5cd9732016-10-17 15:23:10 +0100289
Gilles Peskine8f073122018-11-27 15:58:47 +0100290 msg "build: ARM Compiler 6 ($FLAGS), make"
291 ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \
292 WARNING_CFLAGS='-xc -std=c99' make lib
293 make clean
294}
Andres AGa5cd9732016-10-17 15:23:10 +0100295
Andres AGd9eba4b2016-08-26 14:42:14 +0100296err_msg()
297{
298 echo "$1" >&2
299}
300
301check_tools()
302{
303 for TOOL in "$@"; do
Andres AG98393602017-01-31 17:04:45 +0000304 if ! `type "$TOOL" >/dev/null 2>&1`; then
Andres AGd9eba4b2016-08-26 14:42:14 +0100305 err_msg "$TOOL not found!"
306 exit 1
307 fi
308 done
309}
310
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400311check_headers_in_cpp () {
Peter Kolbus1bc1a4c2019-02-01 17:19:08 -0600312 ls include/mbedtls | grep "\.h$" >headers.txt
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400313 <programs/test/cpp_dummy_build.cpp sed -n 's/"$//; s!^#include "mbedtls/!!p' |
314 sort |
315 diff headers.txt -
316 rm headers.txt
317}
318
Gilles Peskine8f073122018-11-27 15:58:47 +0100319pre_parse_command_line () {
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000320 COMMAND_LINE_COMPONENTS=
Gilles Peskinea28db922019-01-10 00:05:18 +0100321 all_except=0
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000322 no_armcc=
SimonB2e23c822016-04-16 21:54:39 +0100323
Gilles Peskine8f073122018-11-27 15:58:47 +0100324 while [ $# -gt 0 ]; do
Gilles Peskine55f7c942019-01-09 22:28:21 +0100325 case "$1" in
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000326 --armcc) no_armcc=;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100327 --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
328 --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000329 --except) all_except=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100330 --force|-f) FORCE=1;;
331 --gnutls-cli) shift; GNUTLS_CLI="$1";;
332 --gnutls-legacy-cli) shift; GNUTLS_LEGACY_CLI="$1";;
333 --gnutls-legacy-serv) shift; GNUTLS_LEGACY_SERV="$1";;
334 --gnutls-serv) shift; GNUTLS_SERV="$1";;
335 --help|-h) usage; exit;;
336 --keep-going|-k) KEEP_GOING=1;;
Gilles Peskine878cf602019-01-06 20:50:38 +0000337 --list-all-components) printf '%s\n' $ALL_COMPONENTS; exit;;
338 --list-components) printf '%s\n' $SUPPORTED_COMPONENTS; exit;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100339 --memory|-m) MEMORY=1;;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000340 --no-armcc) no_armcc=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100341 --no-force) FORCE=0;;
342 --no-keep-going) KEEP_GOING=0;;
343 --no-memory) MEMORY=0;;
344 --openssl) shift; OPENSSL="$1";;
345 --openssl-legacy) shift; OPENSSL_LEGACY="$1";;
346 --openssl-next) shift; OPENSSL_NEXT="$1";;
347 --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
348 --random-seed) unset SEED;;
349 --release-test|-r) SEED=1;;
350 --seed|-s) shift; SEED="$1";;
351 -*)
352 echo >&2 "Unknown option: $1"
353 echo >&2 "Run $0 --help for usage."
354 exit 120
355 ;;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000356 *) COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS $1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100357 esac
358 shift
Gilles Peskine8f073122018-11-27 15:58:47 +0100359 done
SimonB2e23c822016-04-16 21:54:39 +0100360
Gilles Peskinea28db922019-01-10 00:05:18 +0100361 # With no list of components, run everything.
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000362 if [ -z "$COMMAND_LINE_COMPONENTS" ]; then
363 all_except=1
Andres AGdc192212016-08-31 17:33:13 +0100364 fi
365
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000366 # --no-armcc is a legacy option. The modern way is --except '*_armcc*'.
367 # Ignore it if components are listed explicitly on the command line.
Gilles Peskinea28db922019-01-10 00:05:18 +0100368 if [ -n "$no_armcc" ] && [ $all_except -eq 1 ]; then
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000369 COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS *_armcc*"
SimonB2e23c822016-04-16 21:54:39 +0100370 fi
SimonB2e23c822016-04-16 21:54:39 +0100371
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000372 # Build the list of components to run.
Gilles Peskinea28db922019-01-10 00:05:18 +0100373 RUN_COMPONENTS=
374 for component in $SUPPORTED_COMPONENTS; do
375 if is_component_included "$component"; [ $? -eq $all_except ]; then
376 RUN_COMPONENTS="$RUN_COMPONENTS $component"
377 fi
378 done
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000379
380 unset all_except
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000381 unset no_armcc
Gilles Peskine8f073122018-11-27 15:58:47 +0100382}
SimonB2e23c822016-04-16 21:54:39 +0100383
Gilles Peskine8f073122018-11-27 15:58:47 +0100384pre_check_git () {
385 if [ $FORCE -eq 1 ]; then
Gilles Peskine53190e62019-01-09 23:17:35 +0100386 rm -rf "$OUT_OF_SOURCE_DIR"
Gilles Peskine8f073122018-11-27 15:58:47 +0100387 git checkout-index -f -q $CONFIG_H
388 cleanup
389 else
SimonB2e23c822016-04-16 21:54:39 +0100390
Gilles Peskine8f073122018-11-27 15:58:47 +0100391 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
392 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
393 echo "You can either delete this directory manually, or force the test by rerunning"
394 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
395 exit 1
396 fi
397
Gilles Peskined1174cf2019-01-09 22:30:01 +0100398 if ! git diff --quiet include/mbedtls/config.h; then
Gilles Peskine8f073122018-11-27 15:58:47 +0100399 err_msg "Warning - the configuration file 'include/mbedtls/config.h' has been edited. "
400 echo "You can either delete or preserve your work, or force the test by rerunning the"
401 echo "script as: $0 --force"
402 exit 1
403 fi
SimonB2e23c822016-04-16 21:54:39 +0100404 fi
Andrzej Kureke9c3b812019-02-05 05:34:21 -0500405 if ! [ -f crypto/Makefile ]; then
406 echo "Please initialize the crypto submodule" >&2
407 exit 1
408 fi
Gilles Peskine8f073122018-11-27 15:58:47 +0100409}
SimonB2e23c822016-04-16 21:54:39 +0100410
Andrzej Kurekeb508712019-02-14 07:18:59 -0500411pre_check_seedfile () {
412 if [ ! -f "./tests/seedfile" ]; then
413 dd if=/dev/urandom of=./tests/seedfile bs=32 count=1
414 fi
Jaeden Amero97145102019-03-18 16:31:21 +0000415 if [ ! -f "./crypto/tests/seedfile" ]; then
416 dd if=/dev/urandom of=./crypto/tests/seedfile bs=32 count=1
417 fi
Andrzej Kurekeb508712019-02-14 07:18:59 -0500418}
419
Gilles Peskine8f073122018-11-27 15:58:47 +0100420pre_setup_keep_going () {
Gilles Peskine7c652162017-12-11 00:01:40 +0100421 failure_summary=
422 failure_count=0
423 start_red=
424 end_color=
425 if [ -t 1 ]; then
Gilles Peskine9736b9d2018-01-02 21:54:17 +0100426 case "${TERM:-}" in
Gilles Peskine7c652162017-12-11 00:01:40 +0100427 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
428 start_red=$(printf '\033[31m')
429 end_color=$(printf '\033[0m')
430 ;;
431 esac
432 fi
433 record_status () {
434 if "$@"; then
435 last_status=0
436 else
437 last_status=$?
438 text="$current_section: $* -> $last_status"
439 failure_summary="$failure_summary
440$text"
441 failure_count=$((failure_count + 1))
442 echo "${start_red}^^^^$text^^^^${end_color}"
443 fi
444 }
445 make () {
446 case "$*" in
447 *test|*check)
448 if [ $build_status -eq 0 ]; then
449 record_status command make "$@"
450 else
451 echo "(skipped because the build failed)"
452 fi
453 ;;
454 *)
455 record_status command make "$@"
456 build_status=$last_status
457 ;;
458 esac
459 }
460 final_report () {
461 if [ $failure_count -gt 0 ]; then
462 echo
463 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
464 echo "${start_red}FAILED: $failure_count${end_color}$failure_summary"
465 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Jaeden Amero7c1258d2018-07-20 16:42:14 +0100466 exit 1
Gilles Peskine7c652162017-12-11 00:01:40 +0100467 elif [ -z "${1-}" ]; then
468 echo "SUCCESS :)"
469 fi
470 if [ -n "${1-}" ]; then
471 echo "Killed by SIG$1."
472 fi
473 }
Gilles Peskine8f073122018-11-27 15:58:47 +0100474}
475
Gilles Peskine7c652162017-12-11 00:01:40 +0100476if_build_succeeded () {
477 if [ $build_status -eq 0 ]; then
478 record_status "$@"
479 fi
480}
481
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200482# to be used instead of ! for commands run with
483# record_status or if_build_succeeded
484not() {
485 ! "$@"
486}
487
Gilles Peskine8f073122018-11-27 15:58:47 +0100488pre_print_configuration () {
489 msg "info: $0 configuration"
490 echo "MEMORY: $MEMORY"
491 echo "FORCE: $FORCE"
492 echo "SEED: ${SEED-"UNSET"}"
493 echo "OPENSSL: $OPENSSL"
494 echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
495 echo "OPENSSL_NEXT: $OPENSSL_NEXT"
496 echo "GNUTLS_CLI: $GNUTLS_CLI"
497 echo "GNUTLS_SERV: $GNUTLS_SERV"
498 echo "GNUTLS_LEGACY_CLI: $GNUTLS_LEGACY_CLI"
499 echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV"
500 echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
501 echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
502}
Andres AG7770ea82016-10-10 15:46:20 +0100503
Andres AGd9eba4b2016-08-26 14:42:14 +0100504# Make sure the tools we need are available.
Gilles Peskine8f073122018-11-27 15:58:47 +0100505pre_check_tools () {
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000506 # Build the list of variables to pass to output_env.sh.
507 set env
SimonB2e23c822016-04-16 21:54:39 +0100508
Gilles Peskine87964262019-01-06 22:40:00 +0000509 case " $RUN_COMPONENTS " in
510 # Require OpenSSL and GnuTLS if running any tests (as opposed to
511 # only doing builds). Not all tests run OpenSSL and GnuTLS, but this
512 # is a good enough approximation in practice.
513 *" test_"*)
514 # To avoid setting OpenSSL and GnuTLS for each call to compat.sh
515 # and ssl-opt.sh, we just export the variables they require.
516 export OPENSSL_CMD="$OPENSSL"
517 export GNUTLS_CLI="$GNUTLS_CLI"
518 export GNUTLS_SERV="$GNUTLS_SERV"
519 # Avoid passing --seed flag in every call to ssl-opt.sh
520 if [ -n "${SEED-}" ]; then
521 export SEED
522 fi
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000523 set "$@" OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY"
524 set "$@" GNUTLS_CLI="$GNUTLS_CLI" GNUTLS_SERV="$GNUTLS_SERV"
525 set "$@" GNUTLS_LEGACY_CLI="$GNUTLS_LEGACY_CLI"
526 set "$@" GNUTLS_LEGACY_SERV="$GNUTLS_LEGACY_SERV"
Gilles Peskine87964262019-01-06 22:40:00 +0000527 check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$OPENSSL_NEXT" \
528 "$GNUTLS_CLI" "$GNUTLS_SERV" \
529 "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV"
530 ;;
531 esac
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200532
Gilles Peskine87964262019-01-06 22:40:00 +0000533 case " $RUN_COMPONENTS " in
534 *_doxygen[_\ ]*) check_tools "doxygen" "dot";;
535 esac
Andres AGd9eba4b2016-08-26 14:42:14 +0100536
Gilles Peskine87964262019-01-06 22:40:00 +0000537 case " $RUN_COMPONENTS " in
538 *_arm_none_eabi_gcc[_\ ]*) check_tools "arm-none-eabi-gcc";;
539 esac
Andres AGd9eba4b2016-08-26 14:42:14 +0100540
Gilles Peskine87964262019-01-06 22:40:00 +0000541 case " $RUN_COMPONENTS " in
542 *_mingw[_\ ]*) check_tools "i686-w64-mingw32-gcc";;
543 esac
544
545 case " $RUN_COMPONENTS " in
546 *" test_zeroize "*) check_tools "gdb";;
547 esac
548
549 case " $RUN_COMPONENTS " in
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000550 *_armcc*)
Gilles Peskine87964262019-01-06 22:40:00 +0000551 ARMC5_CC="$ARMC5_BIN_DIR/armcc"
552 ARMC5_AR="$ARMC5_BIN_DIR/armar"
553 ARMC6_CC="$ARMC6_BIN_DIR/armclang"
554 ARMC6_AR="$ARMC6_BIN_DIR/armar"
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000555 check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC6_CC" "$ARMC6_AR";;
556 esac
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000557
558 msg "info: output_env.sh"
559 case $RUN_COMPONENTS in
560 *_armcc*)
561 set "$@" ARMC5_CC="$ARMC5_CC" ARMC6_CC="$ARMC6_CC" RUN_ARMCC=1;;
562 *) set "$@" RUN_ARMCC=0;;
563 esac
564 "$@" scripts/output_env.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100565}
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100566
Gilles Peskine192c72f2017-12-21 15:59:21 +0100567
568
569################################################################
570#### Basic checks
571################################################################
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100572
573#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200574# Test Suites to be executed
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100575#
Manuel Pégourié-Gonnard3d404b42015-07-08 21:59:16 +0100576# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200577# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100578# 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 +0200579# time, so start with a GCC build).
580# 2. Minimize total running time, by avoiding useless rebuilds
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100581#
Manuel Pégourié-Gonnard259b08a2016-01-08 16:27:41 +0100582# Indicative running times are given for reference.
583
Gilles Peskine8f073122018-11-27 15:58:47 +0100584component_check_recursion () {
585 msg "test: recursion.pl" # < 1s
586 record_status tests/scripts/recursion.pl library/*.c
587}
Janos Follathb72c6782016-07-19 14:54:17 +0100588
Gilles Peskine8f073122018-11-27 15:58:47 +0100589component_check_generated_files () {
590 msg "test: freshness of generated source files" # < 1s
591 record_status tests/scripts/check-generated-files.sh
592}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200593
Gilles Peskine8f073122018-11-27 15:58:47 +0100594component_check_doxy_blocks () {
595 msg "test: doxygen markup outside doxygen blocks" # < 1s
596 record_status tests/scripts/check-doxy-blocks.pl
597}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200598
Gilles Peskine8f073122018-11-27 15:58:47 +0100599component_check_files () {
600 msg "test: check-files.py" # < 1s
Gilles Peskine8f073122018-11-27 15:58:47 +0100601 record_status tests/scripts/check-files.py
602}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200603
Gilles Peskine8f073122018-11-27 15:58:47 +0100604component_check_names () {
605 msg "test/build: declared and exported names" # < 3s
Gilles Peskine13f97dc2019-05-15 17:52:22 +0200606 record_status tests/scripts/check-names.sh -v
Gilles Peskine8f073122018-11-27 15:58:47 +0100607}
Darryl Greena07039c2018-03-13 16:48:16 +0000608
Gilles Peskine8f073122018-11-27 15:58:47 +0100609component_check_doxygen_warnings () {
610 msg "test: doxygen warnings" # ~ 3s
Gilles Peskine8f073122018-11-27 15:58:47 +0100611 record_status tests/scripts/doxygen.sh
612}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200613
Gilles Peskine192c72f2017-12-21 15:59:21 +0100614
615
616################################################################
617#### Build and test many configurations and targets
618################################################################
619
k-stachowiakc1955552019-06-10 11:46:18 +0200620component_test_large_ecdsa_key_signature () {
621
622 SMALL_MPI_MAX_SIZE=136 # Small enough to interfere with the EC signatures
623
624 msg "build: cmake + MBEDTLS_MPI_MAX_SIZE=${SMALL_MPI_MAX_SIZE}, gcc, ASan" # ~ 1 min 50s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200625 scripts/config.py set MBEDTLS_MPI_MAX_SIZE $SMALL_MPI_MAX_SIZE
k-stachowiakc1955552019-06-10 11:46:18 +0200626 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
627 make
628
629 INEVITABLY_PRESENT_FILE=Makefile
630 SIGNATURE_FILE="${INEVITABLY_PRESENT_FILE}.sig" # Warning, this is rm -f'ed below
631
632 msg "test: pk_sign secp521r1_prv.der for MBEDTLS_MPI_MAX_SIZE=${SMALL_MPI_MAX_SIZE} (ASan build)" # ~ 5s
633 if_build_succeeded programs/pkey/pk_sign tests/data_files/secp521r1_prv.der $INEVITABLY_PRESENT_FILE
634 rm -f $SIGNATURE_FILE
635}
636
Gilles Peskine7832c9f2019-04-08 17:00:15 +0200637component_test_default_out_of_box () {
638 msg "build: make, default config (out-of-box)" # ~1min
639 make
640
641 msg "test: main suites make, default config (out-of-box)" # ~10s
642 make test
643
644 msg "selftest: make, default config (out-of-box)" # ~10s
645 programs/test/selftest
646}
647
Gilles Peskine8f073122018-11-27 15:58:47 +0100648component_test_default_cmake_gcc_asan () {
649 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100650 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
651 make
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200652
Gilles Peskine8f073122018-11-27 15:58:47 +0100653 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
654 make test
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200655
Gilles Peskine8f073122018-11-27 15:58:47 +0100656 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
657 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200658
Gilles Peskine8f073122018-11-27 15:58:47 +0100659 msg "test: compat.sh (ASan build)" # ~ 6 min
660 if_build_succeeded tests/compat.sh
661}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200662
Hanno Becker01635512019-02-26 14:27:09 +0000663component_test_full_cmake_gcc_asan () {
664 msg "build: full config, cmake, gcc, ASan"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200665 scripts/config.py full
Hanno Becker01635512019-02-26 14:27:09 +0000666 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
667 make
668
669 msg "test: main suites (inc. selftests) (full config, ASan build)"
670 make test
671
672 msg "test: ssl-opt.sh (full config, ASan build)"
673 if_build_succeeded tests/ssl-opt.sh
674
675 msg "test: compat.sh (full config, ASan build)"
676 if_build_succeeded tests/compat.sh
677}
678
Gilles Peskine782f4112018-11-27 16:11:09 +0100679component_test_ref_configs () {
680 msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
681 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
682 record_status tests/scripts/test-ref-configs.pl
683}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200684
Gilles Peskine8f073122018-11-27 15:58:47 +0100685component_test_sslv3 () {
686 msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200687 scripts/config.py set MBEDTLS_SSL_PROTO_SSL3
Gilles Peskine8f073122018-11-27 15:58:47 +0100688 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
689 make
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200690
Gilles Peskine8f073122018-11-27 15:58:47 +0100691 msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
692 make test
Simon Butcher3ea7f522016-03-07 23:22:10 +0000693
Gilles Peskine8f073122018-11-27 15:58:47 +0100694 msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
695 if_build_succeeded tests/compat.sh -m 'tls1 tls1_1 tls1_2 dtls1 dtls1_2'
696 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
Simon Butcher3ea7f522016-03-07 23:22:10 +0000697
Gilles Peskine8f073122018-11-27 15:58:47 +0100698 msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
699 if_build_succeeded tests/ssl-opt.sh
700}
Simon Butcher3ea7f522016-03-07 23:22:10 +0000701
Gilles Peskine8f073122018-11-27 15:58:47 +0100702component_test_no_renegotiation () {
703 msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200704 scripts/config.py unset MBEDTLS_SSL_RENEGOTIATION
Gilles Peskine8f073122018-11-27 15:58:47 +0100705 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
706 make
Simon Butcher3ea7f522016-03-07 23:22:10 +0000707
Gilles Peskine8f073122018-11-27 15:58:47 +0100708 msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
709 make test
Hanno Becker134c2ab2017-10-12 15:29:50 +0100710
Gilles Peskine8f073122018-11-27 15:58:47 +0100711 msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
712 if_build_succeeded tests/ssl-opt.sh
713}
Hanno Becker134c2ab2017-10-12 15:29:50 +0100714
Hanno Beckera545be22019-05-10 14:45:37 +0100715component_test_no_pem_no_fs () {
716 msg "build: Default + !MBEDTLS_PEM_PARSE_C + !MBEDTLS_FS_IO (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200717 scripts/config.py unset MBEDTLS_PEM_PARSE_C
718 scripts/config.py unset MBEDTLS_FS_IO
Hanno Beckera545be22019-05-10 14:45:37 +0100719 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
720 make
721
722 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - main suites (inc. selftests) (ASan build)" # ~ 50s
723 make test
724
725 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - ssl-opt.sh (ASan build)" # ~ 6 min
726 if_build_succeeded tests/ssl-opt.sh
727}
728
Gilles Peskine8f073122018-11-27 15:58:47 +0100729component_test_rsa_no_crt () {
730 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200731 scripts/config.py set MBEDTLS_RSA_NO_CRT
Gilles Peskine8f073122018-11-27 15:58:47 +0100732 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
733 make
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +0100734
Gilles Peskine8f073122018-11-27 15:58:47 +0100735 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
736 make test
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100737
Gilles Peskine8f073122018-11-27 15:58:47 +0100738 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
739 if_build_succeeded tests/ssl-opt.sh -f RSA
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 compat.sh (ASan build)" # ~ 3 min
742 if_build_succeeded tests/compat.sh -t RSA
743}
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100744
Gilles Peskine0c6b7992019-04-12 20:29:48 +0200745component_test_everest () {
746 msg "build: Everest ECDH context (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200747 scripts/config.py unset MBEDTLS_ECDH_LEGACY_CONTEXT
748 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
Gilles Peskine0c6b7992019-04-12 20:29:48 +0200749 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Asan .
750 make
751
752 msg "test: Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
753 make test
754
755 msg "test: Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
756 if_build_succeeded tests/ssl-opt.sh -f ECDH
757
758 msg "test: Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
759 # Exclude some symmetric ciphers that are redundant here to gain time.
760 if_build_succeeded tests/compat.sh -f ECDH -V NO -e 'ARCFOUR\|ARIA\|CAMELLIA\|CHACHA\|DES\|RC4'
761}
762
Gilles Peskine8f073122018-11-27 15:58:47 +0100763component_test_small_ssl_out_content_len () {
764 msg "build: small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200765 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 16384
766 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
Gilles Peskine8f073122018-11-27 15:58:47 +0100767 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
768 make
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100769
Gilles Peskine8f073122018-11-27 15:58:47 +0100770 msg "test: small SSL_OUT_CONTENT_LEN - ssl-opt.sh MFL and large packet tests"
771 if_build_succeeded tests/ssl-opt.sh -f "Max fragment\|Large packet"
772}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000773
Gilles Peskine8f073122018-11-27 15:58:47 +0100774component_test_small_ssl_in_content_len () {
775 msg "build: small SSL_IN_CONTENT_LEN (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200776 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 4096
777 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 16384
Gilles Peskine8f073122018-11-27 15:58:47 +0100778 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
779 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000780
Gilles Peskine8f073122018-11-27 15:58:47 +0100781 msg "test: small SSL_IN_CONTENT_LEN - ssl-opt.sh MFL tests"
782 if_build_succeeded tests/ssl-opt.sh -f "Max fragment"
783}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000784
Gilles Peskine8f073122018-11-27 15:58:47 +0100785component_test_small_ssl_dtls_max_buffering () {
786 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200787 scripts/config.py set MBEDTLS_SSL_DTLS_MAX_BUFFERING 1000
Gilles Peskine8f073122018-11-27 15:58:47 +0100788 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
789 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000790
Gilles Peskine8f073122018-11-27 15:58:47 +0100791 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0 - ssl-opt.sh specific reordering test"
792 if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer out-of-order hs msg before reassembling next, free buffered msg"
793}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100794
Gilles Peskine8f073122018-11-27 15:58:47 +0100795component_test_small_mbedtls_ssl_dtls_max_buffering () {
796 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200797 scripts/config.py set MBEDTLS_SSL_DTLS_MAX_BUFFERING 190
Gilles Peskine8f073122018-11-27 15:58:47 +0100798 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
799 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100800
Gilles Peskine8f073122018-11-27 15:58:47 +0100801 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1 - ssl-opt.sh specific reordering test"
802 if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer encrypted Finished message, drop for fragmented NewSessionTicket"
803}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100804
Gilles Peskine8f073122018-11-27 15:58:47 +0100805component_test_full_cmake_clang () {
806 msg "build: cmake, full config, clang" # ~ 50s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200807 scripts/config.py full
Gilles Peskine8f073122018-11-27 15:58:47 +0100808 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check -D ENABLE_TESTING=On .
809 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100810
Gilles Peskine8f073122018-11-27 15:58:47 +0100811 msg "test: main suites (full config)" # ~ 5s
812 make test
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100813
Gilles Peskine8f073122018-11-27 15:58:47 +0100814 msg "test: ssl-opt.sh default, ECJPAKE, SSL async (full config)" # ~ 1s
815 if_build_succeeded tests/ssl-opt.sh -f 'Default\|ECJPAKE\|SSL async private'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200816
Andres Amaya Garcia2dadab72019-01-08 21:42:27 +0000817 msg "test: compat.sh RC4, DES, 3DES & NULL (full config)" # ~ 2 min
Andres Amaya Garcia419bd002019-02-19 20:20:57 +0000818 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 +0200819
Gilles Peskine8f073122018-11-27 15:58:47 +0100820 msg "test: compat.sh ARIA + ChachaPoly"
821 if_build_succeeded env OPENSSL_CMD="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
822}
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200823
Gilles Peskine8f073122018-11-27 15:58:47 +0100824component_build_deprecated () {
825 msg "build: make, full config + DEPRECATED_WARNING, gcc -O" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200826 scripts/config.py full
827 scripts/config.py set MBEDTLS_DEPRECATED_WARNING
Gilles Peskine8f073122018-11-27 15:58:47 +0100828 # Build with -O -Wextra to catch a maximum of issues.
829 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra' lib programs
830 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100831
Gilles Peskine8f073122018-11-27 15:58:47 +0100832 msg "build: make, full config + DEPRECATED_REMOVED, clang -O" # ~ 30s
833 # No cleanup, just tweak the configuration and rebuild
834 make clean
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200835 scripts/config.py unset MBEDTLS_DEPRECATED_WARNING
836 scripts/config.py set MBEDTLS_DEPRECATED_REMOVED
Gilles Peskine8f073122018-11-27 15:58:47 +0100837 # Build with -O -Wextra to catch a maximum of issues.
838 make CC=clang CFLAGS='-O -Werror -Wall -Wextra' lib programs
839 make CC=clang CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
840}
Jaeden Ameroed93bdc2018-11-02 16:57:24 +0000841
Gilles Peskine8f073122018-11-27 15:58:47 +0100842component_test_depends_curves () {
843 msg "test/build: curves.pl (gcc)" # ~ 4 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100844 record_status tests/scripts/curves.pl
845}
Jaeden Ameroacaabe72018-11-07 11:52:52 +0000846
Gilles Peskine8f073122018-11-27 15:58:47 +0100847component_test_depends_hashes () {
848 msg "test/build: depends-hashes.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100849 record_status tests/scripts/depends-hashes.pl
850}
Jaeden Ameroacaabe72018-11-07 11:52:52 +0000851
Gilles Peskine8f073122018-11-27 15:58:47 +0100852component_test_depends_pkalgs () {
853 msg "test/build: depends-pkalgs.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100854 record_status tests/scripts/depends-pkalgs.pl
855}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100856
Gilles Peskine8f073122018-11-27 15:58:47 +0100857component_build_key_exchanges () {
858 msg "test/build: key-exchanges (gcc)" # ~ 1 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100859 record_status tests/scripts/key-exchanges.pl
860}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100861
Gilles Peskine8f073122018-11-27 15:58:47 +0100862component_build_default_make_gcc_and_cxx () {
863 msg "build: Unix make, -Os (gcc)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100864 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100865
Gilles Peskine8f073122018-11-27 15:58:47 +0100866 msg "test: verify header list in cpp_dummy_build.cpp"
867 record_status check_headers_in_cpp
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100868
Gilles Peskine8f073122018-11-27 15:58:47 +0100869 msg "build: Unix make, incremental g++"
870 make TEST_CPP=1
871}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100872
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100873component_test_no_use_psa_crypto_full_cmake_asan() {
874 # full minus MBEDTLS_USE_PSA_CRYPTO: run the same set of tests as basic-build-test.sh
Gilles Peskinedc3a1792019-09-03 11:42:04 +0200875 msg "build: cmake, full config minus MBEDTLS_USE_PSA_CRYPTO, ASan"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200876 scripts/config.py full
877 scripts/config.py set MBEDTLS_ECP_RESTARTABLE # not using PSA, so enable restartable ECC
878 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C
879 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
880 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C
881 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
Manuel Pégourié-Gonnardd8167e82019-02-01 11:12:52 +0100882 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500883 make
Manuel Pégourié-Gonnard43be6cd2017-06-20 09:53:42 +0200884
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100885 msg "test: main suites (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500886 make test
Manuel Pégourié-Gonnard503a5ef2015-10-23 09:04:45 +0200887
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100888 msg "test: ssl-opt.sh (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500889 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100890
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100891 msg "test: compat.sh default (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500892 if_build_succeeded tests/compat.sh
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400893
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100894 msg "test: compat.sh ssl3 (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500895 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400896
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100897 msg "test: compat.sh RC4, DES & NULL (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500898 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 -0500899
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100900 msg "test: compat.sh ARIA + ChachaPoly (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500901 if_build_succeeded env OPENSSL_CMD="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
902}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500903
Gilles Peskineadcde5e2019-06-12 16:05:50 +0200904component_test_check_params_functionality () {
905 msg "build+test: MBEDTLS_CHECK_PARAMS functionality"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200906 scripts/config.py full # includes CHECK_PARAMS
Gilles Peskineadcde5e2019-06-12 16:05:50 +0200907 # Make MBEDTLS_PARAM_FAILED call mbedtls_param_failed().
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200908 scripts/config.py unset MBEDTLS_CHECK_PARAMS_ASSERT
Gilles Peskineadcde5e2019-06-12 16:05:50 +0200909 # Only build and run tests. Do not build sample programs, because
910 # they don't have a mbedtls_param_failed() function.
911 make CC=gcc CFLAGS='-Werror -O1' lib test
912}
913
Gilles Peskineb28636b2019-01-02 19:06:24 +0100914component_test_check_params_without_platform () {
915 msg "build+test: MBEDTLS_CHECK_PARAMS without MBEDTLS_PLATFORM_C"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200916 scripts/config.py full # includes CHECK_PARAMS
Gilles Peskineadcde5e2019-06-12 16:05:50 +0200917 # Keep MBEDTLS_PARAM_FAILED as assert.
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200918 scripts/config.py unset MBEDTLS_PLATFORM_EXIT_ALT
919 scripts/config.py unset MBEDTLS_PLATFORM_TIME_ALT
920 scripts/config.py unset MBEDTLS_PLATFORM_FPRINTF_ALT
921 scripts/config.py unset MBEDTLS_PLATFORM_MEMORY
922 scripts/config.py unset MBEDTLS_PLATFORM_PRINTF_ALT
923 scripts/config.py unset MBEDTLS_PLATFORM_SNPRINTF_ALT
924 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
925 scripts/config.py unset MBEDTLS_PLATFORM_C
Gilles Peskineb28636b2019-01-02 19:06:24 +0100926 make CC=gcc CFLAGS='-Werror -O1' all test
927}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500928
Gilles Peskineb28636b2019-01-02 19:06:24 +0100929component_test_check_params_silent () {
930 msg "build+test: MBEDTLS_CHECK_PARAMS with alternative MBEDTLS_PARAM_FAILED()"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200931 scripts/config.py full # includes CHECK_PARAMS
Gilles Peskineadcde5e2019-06-12 16:05:50 +0200932 # Set MBEDTLS_PARAM_FAILED to nothing.
Gilles Peskineb28636b2019-01-02 19:06:24 +0100933 sed -i 's/.*\(#define MBEDTLS_PARAM_FAILED( cond )\).*/\1/' "$CONFIG_H"
934 make CC=gcc CFLAGS='-Werror -O1' all test
935}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500936
Gilles Peskine8f073122018-11-27 15:58:47 +0100937component_test_no_platform () {
938 # Full configuration build, without platform support, file IO and net sockets.
939 # This should catch missing mbedtls_printf definitions, and by disabling file
940 # IO, it should catch missing '#include <stdio.h>'
941 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200942 scripts/config.py full
943 scripts/config.py unset MBEDTLS_PLATFORM_C
944 scripts/config.py unset MBEDTLS_NET_C
945 scripts/config.py unset MBEDTLS_PLATFORM_MEMORY
946 scripts/config.py unset MBEDTLS_PLATFORM_PRINTF_ALT
947 scripts/config.py unset MBEDTLS_PLATFORM_FPRINTF_ALT
948 scripts/config.py unset MBEDTLS_PLATFORM_SNPRINTF_ALT
949 scripts/config.py unset MBEDTLS_PLATFORM_TIME_ALT
950 scripts/config.py unset MBEDTLS_PLATFORM_EXIT_ALT
951 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
952 scripts/config.py unset MBEDTLS_FS_IO
953 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
954 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C
Gilles Peskine8f073122018-11-27 15:58:47 +0100955 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
956 # to re-enable platform integration features otherwise disabled in C99 builds
957 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -O0 -D_DEFAULT_SOURCE' lib programs
958 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0' test
959}
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +0000960
Gilles Peskine8f073122018-11-27 15:58:47 +0100961component_build_no_std_function () {
962 # catch compile bugs in _uninit functions
963 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200964 scripts/config.py full
965 scripts/config.py set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
966 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskine8f073122018-11-27 15:58:47 +0100967 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
968}
Manuel Pégourié-Gonnarddccb80b2015-06-03 10:20:33 +0100969
Gilles Peskine8f073122018-11-27 15:58:47 +0100970component_build_no_ssl_srv () {
971 msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200972 scripts/config.py full
973 scripts/config.py unset MBEDTLS_SSL_SRV_C
Gilles Peskine8f073122018-11-27 15:58:47 +0100974 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
975}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200976
Gilles Peskine8f073122018-11-27 15:58:47 +0100977component_build_no_ssl_cli () {
978 msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200979 scripts/config.py full
980 scripts/config.py unset MBEDTLS_SSL_CLI_C
Gilles Peskine8f073122018-11-27 15:58:47 +0100981 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
982}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200983
Gilles Peskine8f073122018-11-27 15:58:47 +0100984component_build_no_sockets () {
985 # Note, C99 compliance can also be tested with the sockets support disabled,
986 # as that requires a POSIX platform (which isn't the same as C99).
987 msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200988 scripts/config.py full
989 scripts/config.py unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
990 scripts/config.py set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
Gilles Peskine8f073122018-11-27 15:58:47 +0100991 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0 -std=c99 -pedantic' lib
992}
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +0200993
Andrzej Kurek69f20aa2019-09-05 09:27:47 -0400994component_test_memory_buffer_allocator_backtrace () {
995 msg "build: default config with memory buffer allocator and backtrace enabled"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200996 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
997 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
998 scripts/config.py set MBEDTLS_MEMORY_BACKTRACE
999 scripts/config.py set MBEDTLS_MEMORY_DEBUG
Andrzej Kurek69f20aa2019-09-05 09:27:47 -04001000 CC=gcc cmake .
1001 make
1002
1003 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C and MBEDTLS_MEMORY_BACKTRACE"
1004 make test
1005}
1006
1007component_test_memory_buffer_allocator () {
1008 msg "build: default config with memory buffer allocator"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001009 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
1010 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
Hanno Becker0fb9ba22019-02-26 14:34:13 +00001011 CC=gcc cmake .
1012 make
1013
1014 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C"
1015 make test
1016
1017 msg "test: ssl-opt.sh, MBEDTLS_MEMORY_BUFFER_ALLOC_C"
Andrzej Kurek1e56d2c2019-09-05 10:09:37 -04001018 # MBEDTLS_MEMORY_BUFFER_ALLOC is slow. Skip tests that tend to time out.
1019 if_build_succeeded tests/ssl-opt.sh -e '^DTLS proxy'
Hanno Becker0fb9ba22019-02-26 14:34:13 +00001020}
1021
Gilles Peskine8f073122018-11-27 15:58:47 +01001022component_test_no_max_fragment_length () {
1023 # Run max fragment length tests with MFL disabled
1024 msg "build: default config except MFL extension (ASan build)" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001025 scripts/config.py unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
Gilles Peskine8f073122018-11-27 15:58:47 +01001026 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1027 make
Hanno Becker5175ac62017-09-18 15:36:25 +01001028
Gilles Peskine8f073122018-11-27 15:58:47 +01001029 msg "test: ssl-opt.sh, MFL-related tests"
1030 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length"
1031}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001032
Hanno Becker545ced42019-02-19 11:10:48 +00001033component_test_asan_remove_peer_certificate () {
1034 msg "build: default config with MBEDTLS_SSL_KEEP_PEER_CERTIFICATE disabled (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001035 scripts/config.py unset MBEDTLS_SSL_KEEP_PEER_CERTIFICATE
Hanno Becker545ced42019-02-19 11:10:48 +00001036 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1037 make
1038
1039 msg "test: !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
1040 make test
1041
1042 msg "test: ssl-opt.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
1043 if_build_succeeded tests/ssl-opt.sh
1044
1045 msg "test: compat.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
1046 if_build_succeeded tests/compat.sh
1047}
1048
Gilles Peskine8f073122018-11-27 15:58:47 +01001049component_test_no_max_fragment_length_small_ssl_out_content_len () {
1050 msg "build: no MFL extension, small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001051 scripts/config.py unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
1052 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 16384
1053 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
Gilles Peskine8f073122018-11-27 15:58:47 +01001054 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1055 make
Angus Grattonc4dd0732018-04-11 16:28:39 +10001056
Gilles Peskine8f073122018-11-27 15:58:47 +01001057 msg "test: MFL tests (disabled MFL extension case) & large packet tests"
1058 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length\|Large buffer"
1059}
Angus Grattonc4dd0732018-04-11 16:28:39 +10001060
Jaeden Amero2de07f12019-06-05 13:32:08 +01001061component_test_when_no_ciphersuites_have_mac () {
1062 msg "build: when no ciphersuites have MAC"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001063 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
1064 scripts/config.py unset MBEDTLS_ARC4_C
1065 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
Jaeden Amero2de07f12019-06-05 13:32:08 +01001066 make
1067
1068 msg "test: !MBEDTLS_SSL_SOME_MODES_USE_MAC"
1069 make test
1070
1071 msg "test ssl-opt.sh: !MBEDTLS_SSL_SOME_MODES_USE_MAC"
Jaeden Amero6b1683d2019-06-05 14:42:50 +01001072 if_build_succeeded tests/ssl-opt.sh -f 'Default\|EtM' -e 'without EtM'
Jaeden Amero2de07f12019-06-05 13:32:08 +01001073}
1074
Gilles Peskine8f073122018-11-27 15:58:47 +01001075component_test_null_entropy () {
1076 msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001077 scripts/config.py set MBEDTLS_TEST_NULL_ENTROPY
1078 scripts/config.py set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
1079 scripts/config.py set MBEDTLS_ENTROPY_C
1080 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
1081 scripts/config.py unset MBEDTLS_ENTROPY_HARDWARE_ALT
1082 scripts/config.py unset MBEDTLS_HAVEGE_C
Gilles Peskine5fa32a72019-01-06 19:48:30 +00001083 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan -D UNSAFE_BUILD=ON .
Gilles Peskine8f073122018-11-27 15:58:47 +01001084 make
Janos Follath06c54002016-06-09 13:57:40 +01001085
Gilles Peskine8f073122018-11-27 15:58:47 +01001086 msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)"
1087 make test
1088}
Janos Follath06c54002016-06-09 13:57:40 +01001089
Gilles Peskine8f073122018-11-27 15:58:47 +01001090component_test_platform_calloc_macro () {
1091 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001092 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
1093 scripts/config.py set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
1094 scripts/config.py set MBEDTLS_PLATFORM_FREE_MACRO free
Gilles Peskine8f073122018-11-27 15:58:47 +01001095 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1096 make
Hanno Beckere5fecec2018-10-11 11:02:52 +01001097
Gilles Peskine8f073122018-11-27 15:58:47 +01001098 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
1099 make test
1100}
Hanno Beckere5fecec2018-10-11 11:02:52 +01001101
Gilles Peskine8f073122018-11-27 15:58:47 +01001102component_test_make_shared () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001103 msg "build/test: make shared" # ~ 40s
Andrzej Kurek232e8f92019-10-03 03:18:01 -04001104 make SHARED=1 all check
Gilles Peskine56c01612019-07-03 20:43:32 +02001105 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskine8f073122018-11-27 15:58:47 +01001106}
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +02001107
Gilles Peskinecf740502019-07-03 20:43:05 +02001108component_test_cmake_shared () {
1109 msg "build/test: cmake shared" # ~ 2min
1110 cmake -DUSE_SHARED_MBEDTLS_LIBRARY=On .
1111 make
Gilles Peskine56c01612019-07-03 20:43:32 +02001112 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskinecf740502019-07-03 20:43:05 +02001113 make test
1114}
1115
Gilles Peskineabf9b4d2019-07-03 20:42:16 +02001116component_build_mbedtls_config_file () {
1117 msg "build: make with MBEDTLS_CONFIG_FILE" # ~40s
1118 # Use the full config so as to catch a maximum of places where
1119 # the check of MBEDTLS_CONFIG_FILE might be missing.
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001120 scripts/config.py full
Gilles Peskineabf9b4d2019-07-03 20:42:16 +02001121 sed 's!"check_config.h"!"mbedtls/check_config.h"!' <"$CONFIG_H" >full_config.h
1122 echo '#error "MBEDTLS_CONFIG_FILE is not working"' >"$CONFIG_H"
1123 make CFLAGS="-I '$PWD' -DMBEDTLS_CONFIG_FILE='\"full_config.h\"'"
1124 rm -f full_config.h
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001125}
1126
Gilles Peskine8f073122018-11-27 15:58:47 +01001127component_test_m32_o0 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001128 # Build once with -O0, to compile out the i386 specific inline assembly
1129 msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001130 scripts/config.py full
Philippe Antoinecd2c1272019-06-25 21:50:07 +02001131 make CC=gcc CFLAGS='-O0 -Werror -Wall -Wextra -m32 -fsanitize=address' LDFLAGS='-m32 -fsanitize=address'
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01001132
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001133 msg "test: i386, make, gcc -O0 (ASan build)"
1134 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01001135}
Gilles Peskine878cf602019-01-06 20:50:38 +00001136support_test_m32_o0 () {
1137 case $(uname -m) in
1138 *64*) true;;
1139 *) false;;
1140 esac
1141}
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001142
Gilles Peskine8f073122018-11-27 15:58:47 +01001143component_test_m32_o1 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001144 # Build again with -O1, to compile in the i386 specific inline assembly
1145 msg "build: i386, make, gcc -O1 (ASan build)" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001146 scripts/config.py full
Philippe Antoinecd2c1272019-06-25 21:50:07 +02001147 make CC=gcc CFLAGS='-O1 -Werror -Wall -Wextra -m32 -fsanitize=address' LDFLAGS='-m32 -fsanitize=address'
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001148
1149 msg "test: i386, make, gcc -O1 (ASan build)"
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001150 make test
Gilles Peskine4b317612019-04-08 16:58:02 +02001151
1152 msg "test ssl-opt.sh, i386, make, gcc-O1"
1153 if_build_succeeded tests/ssl-opt.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01001154}
Gilles Peskine878cf602019-01-06 20:50:38 +00001155support_test_m32_o1 () {
1156 support_test_m32_o0 "$@"
1157}
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001158
Gilles Peskine0c6b7992019-04-12 20:29:48 +02001159component_test_m32_everest () {
1160 msg "build: i386, Everest ECDH context (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001161 scripts/config.py unset MBEDTLS_ECDH_LEGACY_CONTEXT
1162 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
Gilles Peskine0c6b7992019-04-12 20:29:48 +02001163 make CC=gcc CFLAGS='-O2 -Werror -Wall -Wextra -m32 -fsanitize=address' LDFLAGS='-m32 -fsanitize=address'
1164
1165 msg "test: i386, Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
1166 make test
1167
1168 msg "test: i386, Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
1169 if_build_succeeded tests/ssl-opt.sh -f ECDH
1170
1171 msg "test: i386, Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
1172 # Exclude some symmetric ciphers that are redundant here to gain time.
1173 if_build_succeeded tests/compat.sh -f ECDH -V NO -e 'ARCFOUR\|ARIA\|CAMELLIA\|CHACHA\|DES\|RC4'
1174}
1175support_test_m32_everest () {
1176 support_test_m32_o0 "$@"
1177}
1178
Gilles Peskine8f073122018-11-27 15:58:47 +01001179component_test_mx32 () {
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001180 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001181 scripts/config.py full
Gilles Peskine5d26e7c2019-06-07 14:50:09 +02001182 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32' LDFLAGS='-mx32'
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001183
1184 msg "test: 64-bit ILP32, make, gcc"
1185 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01001186}
Gilles Peskine878cf602019-01-06 20:50:38 +00001187support_test_mx32 () {
1188 case $(uname -m) in
1189 amd64|x86_64) true;;
1190 *) false;;
1191 esac
1192}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001193
Gilles Peskine8f073122018-11-27 15:58:47 +01001194component_build_arm_none_eabi_gcc () {
1195 msg "build: arm-none-eabi-gcc, make" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001196 scripts/config.py baremetal
Gilles Peskine8f073122018-11-27 15:58:47 +01001197 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
1198}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001199
Gilles Peskine2c897d72019-08-09 16:05:05 +02001200component_build_arm_none_eabi_gcc_arm5vte () {
Gilles Peskine8a52af92019-08-08 16:09:02 +02001201 msg "build: arm-none-eabi-gcc -march=arm5vte, make" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001202 scripts/config.py baremetal
Gilles Peskine2c897d72019-08-09 16:05:05 +02001203 # Build for a target platform that's close to what Debian uses
1204 # for its "armel" distribution (https://wiki.debian.org/ArmEabiPort).
1205 # See https://github.com/ARMmbed/mbedtls/pull/2169 and comments.
1206 # It would be better to build with arm-linux-gnueabi-gcc but
1207 # we don't have that on our CI at this time.
Gilles Peskine8a52af92019-08-08 16:09:02 +02001208 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 +02001209}
1210
Gilles Peskine8f073122018-11-27 15:58:47 +01001211component_build_arm_none_eabi_gcc_no_udbl_division () {
1212 msg "build: arm-none-eabi-gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001213 scripts/config.py baremetal
1214 scripts/config.py set MBEDTLS_NO_UDBL_DIVISION
Gilles Peskine8f073122018-11-27 15:58:47 +01001215 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
1216 echo "Checking that software 64-bit division is not required"
1217 if_build_succeeded not grep __aeabi_uldiv library/*.o
1218}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001219
Gilles Peskine8f073122018-11-27 15:58:47 +01001220component_build_arm_none_eabi_gcc_no_64bit_multiplication () {
1221 msg "build: arm-none-eabi-gcc MBEDTLS_NO_64BIT_MULTIPLICATION, make" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001222 scripts/config.py baremetal
1223 scripts/config.py set MBEDTLS_NO_64BIT_MULTIPLICATION
Gilles Peskine8f073122018-11-27 15:58:47 +01001224 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -O1 -march=armv6-m -mthumb' lib
1225 echo "Checking that software 64-bit multiplication is not required"
1226 if_build_succeeded not grep __aeabi_lmul library/*.o
1227}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001228
Gilles Peskine8f073122018-11-27 15:58:47 +01001229component_build_armcc () {
1230 msg "build: ARM Compiler 5, make"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001231 scripts/config.py baremetal
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001232
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001233 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
1234 make clean
Andres AG87bb5772016-09-27 15:05:15 +01001235
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001236 # ARM Compiler 6 - Target ARMv7-A
1237 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-a"
Simon Butcher940737f2017-07-23 13:42:36 +02001238
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001239 # ARM Compiler 6 - Target ARMv7-M
1240 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m"
Simon Butcher940737f2017-07-23 13:42:36 +02001241
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001242 # ARM Compiler 6 - Target ARMv8-A - AArch32
1243 armc6_build_test "--target=arm-arm-none-eabi -march=armv8.2-a"
Simon Butcher940737f2017-07-23 13:42:36 +02001244
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001245 # ARM Compiler 6 - Target ARMv8-M
1246 armc6_build_test "--target=arm-arm-none-eabi -march=armv8-m.main"
Simon Butcher940737f2017-07-23 13:42:36 +02001247
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001248 # ARM Compiler 6 - Target ARMv8-A - AArch64
1249 armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a"
Gilles Peskine8f073122018-11-27 15:58:47 +01001250}
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +01001251
Gilles Peskine8f073122018-11-27 15:58:47 +01001252component_test_allow_sha1 () {
1253 msg "build: allow SHA1 in certificates by default"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001254 scripts/config.py set MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
Gilles Peskine8f073122018-11-27 15:58:47 +01001255 make CFLAGS='-Werror -Wall -Wextra'
1256 msg "test: allow SHA1 in certificates by default"
1257 make test
1258 if_build_succeeded tests/ssl-opt.sh -f SHA-1
1259}
Gilles Peskine2a458da2017-05-12 15:26:58 +02001260
Gilles Peskine8f073122018-11-27 15:58:47 +01001261component_build_mingw () {
1262 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
Andrzej Kurek232e8f92019-10-03 03:18:01 -04001263 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 +00001264
Gilles Peskine8f073122018-11-27 15:58:47 +01001265 # note Make tests only builds the tests, but doesn't run them
Andrzej Kurek232e8f92019-10-03 03:18:01 -04001266 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 +01001267 make WINDOWS_BUILD=1 clean
Simon Butcher002bc622016-11-17 09:27:45 +00001268
Gilles Peskine8f073122018-11-27 15:58:47 +01001269 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
Andrzej Kurek232e8f92019-10-03 03:18:01 -04001270 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
1271 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 +01001272 make WINDOWS_BUILD=1 clean
1273}
Jaeden Amero117b8a42019-04-17 15:19:26 +01001274support_build_mingw() {
1275 case $(i686-w64-mingw32-gcc -dumpversion) in
1276 [0-5]*) false;;
1277 *) true;;
1278 esac
1279}
Manuel Pégourié-Gonnard6448bce2015-02-16 17:18:36 +01001280
Gilles Peskine8f073122018-11-27 15:58:47 +01001281component_test_memsan () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001282 msg "build: MSan (clang)" # ~ 1 min 20s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001283 scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001284 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
1285 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +02001286
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001287 msg "test: main suites (MSan)" # ~ 10s
1288 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001289
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001290 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
Gilles Peskine7c652162017-12-11 00:01:40 +01001291 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001292
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001293 # Optional part(s)
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001294
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001295 if [ "$MEMORY" -gt 0 ]; then
1296 msg "test: compat.sh (MSan)" # ~ 6 min 20s
Gilles Peskine7c652162017-12-11 00:01:40 +01001297 if_build_succeeded tests/compat.sh
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001298 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001299}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001300
Gilles Peskine69f190e2019-01-10 00:11:42 +01001301component_test_valgrind () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001302 msg "build: Release (clang)"
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001303 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
1304 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001305
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001306 msg "test: main suites valgrind (Release)"
1307 make memcheck
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001308
Gilles Peskinef1349e42019-04-08 17:00:56 +02001309 # Optional parts (slow; currently broken on OS X because programs don't
1310 # seem to receive signals under valgrind on OS X).
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001311 if [ "$MEMORY" -gt 0 ]; then
1312 msg "test: ssl-opt.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +01001313 if_build_succeeded tests/ssl-opt.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001314 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001315
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001316 if [ "$MEMORY" -gt 1 ]; then
1317 msg "test: compat.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +01001318 if_build_succeeded tests/compat.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001319 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001320}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001321
Gilles Peskine8f073122018-11-27 15:58:47 +01001322component_test_cmake_out_of_source () {
1323 msg "build: cmake 'out-of-source' build"
Gilles Peskine8f073122018-11-27 15:58:47 +01001324 MBEDTLS_ROOT_DIR="$PWD"
1325 mkdir "$OUT_OF_SOURCE_DIR"
1326 cd "$OUT_OF_SOURCE_DIR"
1327 cmake "$MBEDTLS_ROOT_DIR"
1328 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001329
Gilles Peskine8f073122018-11-27 15:58:47 +01001330 msg "test: cmake 'out-of-source' build"
1331 make test
1332 # Test an SSL option that requires an auxiliary script in test/scripts/.
1333 # Also ensure that there are no error messages such as
1334 # "No such file or directory", which would indicate that some required
1335 # file is missing (ssl-opt.sh tolerates the absence of some files so
1336 # may exit with status 0 but emit errors).
1337 if_build_succeeded ./tests/ssl-opt.sh -f 'Fallback SCSV: beginning of list' 2>ssl-opt.err
1338 if [ -s ssl-opt.err ]; then
1339 cat ssl-opt.err >&2
1340 record_status [ ! -s ssl-opt.err ]
1341 rm ssl-opt.err
1342 fi
1343 cd "$MBEDTLS_ROOT_DIR"
1344 rm -rf "$OUT_OF_SOURCE_DIR"
1345 unset MBEDTLS_ROOT_DIR
1346}
Andres AGdc192212016-08-31 17:33:13 +01001347
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01001348component_test_cmake_as_subdirectory () {
1349 msg "build: cmake 'as-subdirectory' build"
1350 MBEDTLS_ROOT_DIR="$PWD"
1351
1352 cd programs/test/cmake_subproject
1353 cmake .
1354 make
1355 if_build_succeeded ./cmake_subproject
1356
1357 cd "$MBEDTLS_ROOT_DIR"
1358 unset MBEDTLS_ROOT_DIR
1359}
1360
Gilles Peskine8f073122018-11-27 15:58:47 +01001361component_test_zeroize () {
1362 # Test that the function mbedtls_platform_zeroize() is not optimized away by
1363 # different combinations of compilers and optimization flags by using an
1364 # auxiliary GDB script. Unfortunately, GDB does not return error values to the
1365 # system in all cases that the script fails, so we must manually search the
1366 # output to check whether the pass string is present and no failure strings
1367 # were printed.
Andres AGdc192212016-08-31 17:33:13 +01001368
Gilles Peskine4976e822019-01-06 19:52:22 +00001369 # Don't try to disable ASLR. We don't care about ASLR here. We do care
1370 # about a spurious message if Gdb tries and fails, so suppress that.
1371 gdb_disable_aslr=
1372 if [ -z "$(gdb -batch -nw -ex 'set disable-randomization off' 2>&1)" ]; then
1373 gdb_disable_aslr='set disable-randomization off'
1374 fi
1375
Gilles Peskine8f073122018-11-27 15:58:47 +01001376 for optimization_flag in -O2 -O3 -Ofast -Os; do
Gilles Peskine55f7c942019-01-09 22:28:21 +01001377 for compiler in clang gcc; do
1378 msg "test: $compiler $optimization_flag, mbedtls_platform_zeroize()"
1379 make programs CC="$compiler" DEBUG=1 CFLAGS="$optimization_flag"
Gilles Peskine4976e822019-01-06 19:52:22 +00001380 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 +01001381 if_build_succeeded grep "The buffer was correctly zeroized" test_zeroize.log
1382 if_build_succeeded not grep -i "error" test_zeroize.log
1383 rm -f test_zeroize.log
1384 make clean
1385 done
Andres Amaya Garcia29673812017-10-25 10:35:51 +01001386 done
Andres Amaya Garciad0d7bf62017-10-25 09:01:31 +01001387
Gilles Peskine4976e822019-01-06 19:52:22 +00001388 unset gdb_disable_aslr
Gilles Peskine8f073122018-11-27 15:58:47 +01001389}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001390
Gilles Peskineaad2ebd2019-02-25 20:26:06 +01001391support_check_python_files () {
1392 type pylint3 >/dev/null 2>/dev/null
1393}
Gilles Peskine8f073122018-11-27 15:58:47 +01001394component_check_python_files () {
1395 msg "Lint: Python scripts"
1396 record_status tests/scripts/check-python-files.sh
1397}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001398
Gilles Peskine8f073122018-11-27 15:58:47 +01001399component_check_generate_test_code () {
1400 msg "uint test: generate_test_code.py"
1401 record_status ./tests/scripts/test_generate_test_code.py
1402}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001403
1404################################################################
1405#### Termination
1406################################################################
1407
Gilles Peskine8f073122018-11-27 15:58:47 +01001408post_report () {
1409 msg "Done, cleaning up"
1410 cleanup
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001411
Gilles Peskine8f073122018-11-27 15:58:47 +01001412 final_report
1413}
1414
1415
1416
1417################################################################
1418#### Run all the things
1419################################################################
1420
Gilles Peskinee48351a2018-11-27 16:06:30 +01001421# Run one component and clean up afterwards.
Gilles Peskine8f073122018-11-27 15:58:47 +01001422run_component () {
Gilles Peskine608953e2019-01-02 18:57:02 +01001423 # Back up the configuration in case the component modifies it.
1424 # The cleanup function will restore it.
1425 cp -p "$CONFIG_H" "$CONFIG_BAK"
Gilles Peskineffcdeff2018-12-04 12:49:28 +01001426 current_component="$1"
Gilles Peskine8f073122018-11-27 15:58:47 +01001427 "$@"
Gilles Peskinee48351a2018-11-27 16:06:30 +01001428 cleanup
Gilles Peskine8f073122018-11-27 15:58:47 +01001429}
1430
1431# Preliminary setup
1432pre_check_environment
1433pre_initialize_variables
1434pre_parse_command_line "$@"
Gilles Peskine348fb9a2018-11-27 17:04:29 +01001435
Gilles Peskine878cf602019-01-06 20:50:38 +00001436pre_check_git
Andrzej Kurekeb508712019-02-14 07:18:59 -05001437pre_check_seedfile
1438
Gilles Peskine878cf602019-01-06 20:50:38 +00001439build_status=0
1440if [ $KEEP_GOING -eq 1 ]; then
1441 pre_setup_keep_going
Gilles Peskine92525112018-11-27 18:15:35 +01001442else
Gilles Peskine878cf602019-01-06 20:50:38 +00001443 record_status () {
1444 "$@"
1445 }
Gilles Peskine8f073122018-11-27 15:58:47 +01001446fi
Gilles Peskine878cf602019-01-06 20:50:38 +00001447pre_print_configuration
1448pre_check_tools
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001449cleanup
1450
Gilles Peskinebeb3a812019-01-06 22:11:25 +00001451# Run the requested tests.
1452for component in $RUN_COMPONENTS; do
1453 run_component "component_$component"
1454done
Gilles Peskine8f073122018-11-27 15:58:47 +01001455
1456# We're done.
Gilles Peskine878cf602019-01-06 20:50:38 +00001457post_report