blob: 253d62d29809256522c97bf00daae79701e1e271 [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
246 if [ -f "$CONFIG_BAK" ]; then
247 mv "$CONFIG_BAK" "$CONFIG_H"
248 fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100249}
250
Gilles Peskine7c652162017-12-11 00:01:40 +0100251# Executed on exit. May be redefined depending on command line options.
252final_report () {
253 :
254}
255
256fatal_signal () {
257 cleanup
258 final_report $1
259 trap - $1
260 kill -$1 $$
261}
262
263trap 'fatal_signal HUP' HUP
264trap 'fatal_signal INT' INT
265trap 'fatal_signal TERM' TERM
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200266
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100267msg()
268{
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100269 if [ -n "${current_component:-}" ]; then
270 current_section="${current_component#component_}: $1"
271 else
272 current_section="$1"
273 fi
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100274 echo ""
275 echo "******************************************************************"
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100276 echo "* $current_section "
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000277 printf "* "; date
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100278 echo "******************************************************************"
279}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100280
Gilles Peskine8f073122018-11-27 15:58:47 +0100281armc6_build_test()
282{
283 FLAGS="$1"
Andres AGa5cd9732016-10-17 15:23:10 +0100284
Gilles Peskine8f073122018-11-27 15:58:47 +0100285 msg "build: ARM Compiler 6 ($FLAGS), make"
286 ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \
287 WARNING_CFLAGS='-xc -std=c99' make lib
288 make clean
289}
Andres AGa5cd9732016-10-17 15:23:10 +0100290
Andres AGd9eba4b2016-08-26 14:42:14 +0100291err_msg()
292{
293 echo "$1" >&2
294}
295
296check_tools()
297{
298 for TOOL in "$@"; do
Andres AG98393602017-01-31 17:04:45 +0000299 if ! `type "$TOOL" >/dev/null 2>&1`; then
Andres AGd9eba4b2016-08-26 14:42:14 +0100300 err_msg "$TOOL not found!"
301 exit 1
302 fi
303 done
304}
305
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400306check_headers_in_cpp () {
Peter Kolbus1bc1a4c2019-02-01 17:19:08 -0600307 ls include/mbedtls | grep "\.h$" >headers.txt
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400308 <programs/test/cpp_dummy_build.cpp sed -n 's/"$//; s!^#include "mbedtls/!!p' |
309 sort |
310 diff headers.txt -
311 rm headers.txt
312}
313
Gilles Peskine8f073122018-11-27 15:58:47 +0100314pre_parse_command_line () {
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000315 COMMAND_LINE_COMPONENTS=
Gilles Peskinea28db922019-01-10 00:05:18 +0100316 all_except=0
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000317 no_armcc=
SimonB2e23c822016-04-16 21:54:39 +0100318
Gilles Peskine8f073122018-11-27 15:58:47 +0100319 while [ $# -gt 0 ]; do
Gilles Peskine55f7c942019-01-09 22:28:21 +0100320 case "$1" in
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000321 --armcc) no_armcc=;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100322 --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
323 --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000324 --except) all_except=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100325 --force|-f) FORCE=1;;
326 --gnutls-cli) shift; GNUTLS_CLI="$1";;
327 --gnutls-legacy-cli) shift; GNUTLS_LEGACY_CLI="$1";;
328 --gnutls-legacy-serv) shift; GNUTLS_LEGACY_SERV="$1";;
329 --gnutls-serv) shift; GNUTLS_SERV="$1";;
330 --help|-h) usage; exit;;
331 --keep-going|-k) KEEP_GOING=1;;
Gilles Peskine878cf602019-01-06 20:50:38 +0000332 --list-all-components) printf '%s\n' $ALL_COMPONENTS; exit;;
333 --list-components) printf '%s\n' $SUPPORTED_COMPONENTS; exit;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100334 --memory|-m) MEMORY=1;;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000335 --no-armcc) no_armcc=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100336 --no-force) FORCE=0;;
337 --no-keep-going) KEEP_GOING=0;;
338 --no-memory) MEMORY=0;;
339 --openssl) shift; OPENSSL="$1";;
340 --openssl-legacy) shift; OPENSSL_LEGACY="$1";;
341 --openssl-next) shift; OPENSSL_NEXT="$1";;
342 --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
343 --random-seed) unset SEED;;
344 --release-test|-r) SEED=1;;
345 --seed|-s) shift; SEED="$1";;
346 -*)
347 echo >&2 "Unknown option: $1"
348 echo >&2 "Run $0 --help for usage."
349 exit 120
350 ;;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000351 *) COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS $1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100352 esac
353 shift
Gilles Peskine8f073122018-11-27 15:58:47 +0100354 done
SimonB2e23c822016-04-16 21:54:39 +0100355
Gilles Peskinea28db922019-01-10 00:05:18 +0100356 # With no list of components, run everything.
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000357 if [ -z "$COMMAND_LINE_COMPONENTS" ]; then
358 all_except=1
Andres AGdc192212016-08-31 17:33:13 +0100359 fi
360
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000361 # --no-armcc is a legacy option. The modern way is --except '*_armcc*'.
362 # Ignore it if components are listed explicitly on the command line.
Gilles Peskinea28db922019-01-10 00:05:18 +0100363 if [ -n "$no_armcc" ] && [ $all_except -eq 1 ]; then
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000364 COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS *_armcc*"
SimonB2e23c822016-04-16 21:54:39 +0100365 fi
SimonB2e23c822016-04-16 21:54:39 +0100366
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000367 # Build the list of components to run.
Gilles Peskinea28db922019-01-10 00:05:18 +0100368 RUN_COMPONENTS=
369 for component in $SUPPORTED_COMPONENTS; do
370 if is_component_included "$component"; [ $? -eq $all_except ]; then
371 RUN_COMPONENTS="$RUN_COMPONENTS $component"
372 fi
373 done
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000374
375 unset all_except
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000376 unset no_armcc
Gilles Peskine8f073122018-11-27 15:58:47 +0100377}
SimonB2e23c822016-04-16 21:54:39 +0100378
Gilles Peskine8f073122018-11-27 15:58:47 +0100379pre_check_git () {
380 if [ $FORCE -eq 1 ]; then
Gilles Peskine53190e62019-01-09 23:17:35 +0100381 rm -rf "$OUT_OF_SOURCE_DIR"
Gilles Peskine8f073122018-11-27 15:58:47 +0100382 git checkout-index -f -q $CONFIG_H
383 cleanup
384 else
SimonB2e23c822016-04-16 21:54:39 +0100385
Gilles Peskine8f073122018-11-27 15:58:47 +0100386 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
387 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
388 echo "You can either delete this directory manually, or force the test by rerunning"
389 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
390 exit 1
391 fi
392
Gilles Peskined1174cf2019-01-09 22:30:01 +0100393 if ! git diff --quiet include/mbedtls/config.h; then
Gilles Peskine8f073122018-11-27 15:58:47 +0100394 err_msg "Warning - the configuration file 'include/mbedtls/config.h' has been edited. "
395 echo "You can either delete or preserve your work, or force the test by rerunning the"
396 echo "script as: $0 --force"
397 exit 1
398 fi
SimonB2e23c822016-04-16 21:54:39 +0100399 fi
Andrzej Kureke9c3b812019-02-05 05:34:21 -0500400 if ! [ -f crypto/Makefile ]; then
401 echo "Please initialize the crypto submodule" >&2
402 exit 1
403 fi
Gilles Peskine8f073122018-11-27 15:58:47 +0100404}
SimonB2e23c822016-04-16 21:54:39 +0100405
Andrzej Kurekeb508712019-02-14 07:18:59 -0500406pre_check_seedfile () {
407 if [ ! -f "./tests/seedfile" ]; then
408 dd if=/dev/urandom of=./tests/seedfile bs=32 count=1
409 fi
Jaeden Amero97145102019-03-18 16:31:21 +0000410 if [ ! -f "./crypto/tests/seedfile" ]; then
411 dd if=/dev/urandom of=./crypto/tests/seedfile bs=32 count=1
412 fi
Andrzej Kurekeb508712019-02-14 07:18:59 -0500413}
414
Gilles Peskine8f073122018-11-27 15:58:47 +0100415pre_setup_keep_going () {
Gilles Peskine7c652162017-12-11 00:01:40 +0100416 failure_summary=
417 failure_count=0
418 start_red=
419 end_color=
420 if [ -t 1 ]; then
Gilles Peskine9736b9d2018-01-02 21:54:17 +0100421 case "${TERM:-}" in
Gilles Peskine7c652162017-12-11 00:01:40 +0100422 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
423 start_red=$(printf '\033[31m')
424 end_color=$(printf '\033[0m')
425 ;;
426 esac
427 fi
428 record_status () {
429 if "$@"; then
430 last_status=0
431 else
432 last_status=$?
433 text="$current_section: $* -> $last_status"
434 failure_summary="$failure_summary
435$text"
436 failure_count=$((failure_count + 1))
437 echo "${start_red}^^^^$text^^^^${end_color}"
438 fi
439 }
440 make () {
441 case "$*" in
442 *test|*check)
443 if [ $build_status -eq 0 ]; then
444 record_status command make "$@"
445 else
446 echo "(skipped because the build failed)"
447 fi
448 ;;
449 *)
450 record_status command make "$@"
451 build_status=$last_status
452 ;;
453 esac
454 }
455 final_report () {
456 if [ $failure_count -gt 0 ]; then
457 echo
458 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
459 echo "${start_red}FAILED: $failure_count${end_color}$failure_summary"
460 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Jaeden Amero7c1258d2018-07-20 16:42:14 +0100461 exit 1
Gilles Peskine7c652162017-12-11 00:01:40 +0100462 elif [ -z "${1-}" ]; then
463 echo "SUCCESS :)"
464 fi
465 if [ -n "${1-}" ]; then
466 echo "Killed by SIG$1."
467 fi
468 }
Gilles Peskine8f073122018-11-27 15:58:47 +0100469}
470
Gilles Peskine7c652162017-12-11 00:01:40 +0100471if_build_succeeded () {
472 if [ $build_status -eq 0 ]; then
473 record_status "$@"
474 fi
475}
476
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200477# to be used instead of ! for commands run with
478# record_status or if_build_succeeded
479not() {
480 ! "$@"
481}
482
Gilles Peskine8f073122018-11-27 15:58:47 +0100483pre_print_configuration () {
484 msg "info: $0 configuration"
485 echo "MEMORY: $MEMORY"
486 echo "FORCE: $FORCE"
487 echo "SEED: ${SEED-"UNSET"}"
488 echo "OPENSSL: $OPENSSL"
489 echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
490 echo "OPENSSL_NEXT: $OPENSSL_NEXT"
491 echo "GNUTLS_CLI: $GNUTLS_CLI"
492 echo "GNUTLS_SERV: $GNUTLS_SERV"
493 echo "GNUTLS_LEGACY_CLI: $GNUTLS_LEGACY_CLI"
494 echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV"
495 echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
496 echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
497}
Andres AG7770ea82016-10-10 15:46:20 +0100498
Andres AGd9eba4b2016-08-26 14:42:14 +0100499# Make sure the tools we need are available.
Gilles Peskine8f073122018-11-27 15:58:47 +0100500pre_check_tools () {
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000501 # Build the list of variables to pass to output_env.sh.
502 set env
SimonB2e23c822016-04-16 21:54:39 +0100503
Gilles Peskine87964262019-01-06 22:40:00 +0000504 case " $RUN_COMPONENTS " in
505 # Require OpenSSL and GnuTLS if running any tests (as opposed to
506 # only doing builds). Not all tests run OpenSSL and GnuTLS, but this
507 # is a good enough approximation in practice.
508 *" test_"*)
509 # To avoid setting OpenSSL and GnuTLS for each call to compat.sh
510 # and ssl-opt.sh, we just export the variables they require.
511 export OPENSSL_CMD="$OPENSSL"
512 export GNUTLS_CLI="$GNUTLS_CLI"
513 export GNUTLS_SERV="$GNUTLS_SERV"
514 # Avoid passing --seed flag in every call to ssl-opt.sh
515 if [ -n "${SEED-}" ]; then
516 export SEED
517 fi
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000518 set "$@" OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY"
519 set "$@" GNUTLS_CLI="$GNUTLS_CLI" GNUTLS_SERV="$GNUTLS_SERV"
520 set "$@" GNUTLS_LEGACY_CLI="$GNUTLS_LEGACY_CLI"
521 set "$@" GNUTLS_LEGACY_SERV="$GNUTLS_LEGACY_SERV"
Gilles Peskine87964262019-01-06 22:40:00 +0000522 check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$OPENSSL_NEXT" \
523 "$GNUTLS_CLI" "$GNUTLS_SERV" \
524 "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV"
525 ;;
526 esac
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200527
Gilles Peskine87964262019-01-06 22:40:00 +0000528 case " $RUN_COMPONENTS " in
529 *_doxygen[_\ ]*) check_tools "doxygen" "dot";;
530 esac
Andres AGd9eba4b2016-08-26 14:42:14 +0100531
Gilles Peskine87964262019-01-06 22:40:00 +0000532 case " $RUN_COMPONENTS " in
533 *_arm_none_eabi_gcc[_\ ]*) check_tools "arm-none-eabi-gcc";;
534 esac
Andres AGd9eba4b2016-08-26 14:42:14 +0100535
Gilles Peskine87964262019-01-06 22:40:00 +0000536 case " $RUN_COMPONENTS " in
537 *_mingw[_\ ]*) check_tools "i686-w64-mingw32-gcc";;
538 esac
539
540 case " $RUN_COMPONENTS " in
541 *" test_zeroize "*) check_tools "gdb";;
542 esac
543
544 case " $RUN_COMPONENTS " in
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000545 *_armcc*)
Gilles Peskine87964262019-01-06 22:40:00 +0000546 ARMC5_CC="$ARMC5_BIN_DIR/armcc"
547 ARMC5_AR="$ARMC5_BIN_DIR/armar"
548 ARMC6_CC="$ARMC6_BIN_DIR/armclang"
549 ARMC6_AR="$ARMC6_BIN_DIR/armar"
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000550 check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC6_CC" "$ARMC6_AR";;
551 esac
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000552
553 msg "info: output_env.sh"
554 case $RUN_COMPONENTS in
555 *_armcc*)
556 set "$@" ARMC5_CC="$ARMC5_CC" ARMC6_CC="$ARMC6_CC" RUN_ARMCC=1;;
557 *) set "$@" RUN_ARMCC=0;;
558 esac
559 "$@" scripts/output_env.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100560}
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100561
Gilles Peskine192c72f2017-12-21 15:59:21 +0100562
563
564################################################################
565#### Basic checks
566################################################################
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100567
568#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200569# Test Suites to be executed
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100570#
Manuel Pégourié-Gonnard3d404b42015-07-08 21:59:16 +0100571# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200572# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100573# 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 +0200574# time, so start with a GCC build).
575# 2. Minimize total running time, by avoiding useless rebuilds
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100576#
Manuel Pégourié-Gonnard259b08a2016-01-08 16:27:41 +0100577# Indicative running times are given for reference.
578
Gilles Peskine8f073122018-11-27 15:58:47 +0100579component_check_recursion () {
580 msg "test: recursion.pl" # < 1s
581 record_status tests/scripts/recursion.pl library/*.c
582}
Janos Follathb72c6782016-07-19 14:54:17 +0100583
Gilles Peskine8f073122018-11-27 15:58:47 +0100584component_check_generated_files () {
585 msg "test: freshness of generated source files" # < 1s
586 record_status tests/scripts/check-generated-files.sh
587}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200588
Gilles Peskine8f073122018-11-27 15:58:47 +0100589component_check_doxy_blocks () {
590 msg "test: doxygen markup outside doxygen blocks" # < 1s
591 record_status tests/scripts/check-doxy-blocks.pl
592}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200593
Gilles Peskine8f073122018-11-27 15:58:47 +0100594component_check_files () {
595 msg "test: check-files.py" # < 1s
Gilles Peskine8f073122018-11-27 15:58:47 +0100596 record_status tests/scripts/check-files.py
597}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200598
Gilles Peskine8f073122018-11-27 15:58:47 +0100599component_check_names () {
600 msg "test/build: declared and exported names" # < 3s
Gilles Peskine13f97dc2019-05-15 17:52:22 +0200601 record_status tests/scripts/check-names.sh -v
Gilles Peskine8f073122018-11-27 15:58:47 +0100602}
Darryl Greena07039c2018-03-13 16:48:16 +0000603
Gilles Peskine8f073122018-11-27 15:58:47 +0100604component_check_doxygen_warnings () {
605 msg "test: doxygen warnings" # ~ 3s
Gilles Peskine8f073122018-11-27 15:58:47 +0100606 record_status tests/scripts/doxygen.sh
607}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200608
Gilles Peskine192c72f2017-12-21 15:59:21 +0100609
610
611################################################################
612#### Build and test many configurations and targets
613################################################################
614
Gilles Peskine7832c9f2019-04-08 17:00:15 +0200615component_test_default_out_of_box () {
616 msg "build: make, default config (out-of-box)" # ~1min
617 make
618
619 msg "test: main suites make, default config (out-of-box)" # ~10s
620 make test
621
622 msg "selftest: make, default config (out-of-box)" # ~10s
623 programs/test/selftest
624}
625
Gilles Peskine8f073122018-11-27 15:58:47 +0100626component_test_default_cmake_gcc_asan () {
627 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100628 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
629 make
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200630
Gilles Peskine8f073122018-11-27 15:58:47 +0100631 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
632 make test
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200633
Gilles Peskine8f073122018-11-27 15:58:47 +0100634 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
635 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200636
Gilles Peskine8f073122018-11-27 15:58:47 +0100637 msg "test: compat.sh (ASan build)" # ~ 6 min
638 if_build_succeeded tests/compat.sh
639}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200640
Gilles Peskine782f4112018-11-27 16:11:09 +0100641component_test_ref_configs () {
642 msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
643 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
644 record_status tests/scripts/test-ref-configs.pl
645}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200646
Gilles Peskine8f073122018-11-27 15:58:47 +0100647component_test_sslv3 () {
648 msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100649 scripts/config.pl set MBEDTLS_SSL_PROTO_SSL3
650 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: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
654 make test
Simon Butcher3ea7f522016-03-07 23:22:10 +0000655
Gilles Peskine8f073122018-11-27 15:58:47 +0100656 msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
657 if_build_succeeded tests/compat.sh -m 'tls1 tls1_1 tls1_2 dtls1 dtls1_2'
658 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
Simon Butcher3ea7f522016-03-07 23:22:10 +0000659
Gilles Peskine8f073122018-11-27 15:58:47 +0100660 msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
661 if_build_succeeded tests/ssl-opt.sh
662}
Simon Butcher3ea7f522016-03-07 23:22:10 +0000663
Gilles Peskine8f073122018-11-27 15:58:47 +0100664component_test_no_renegotiation () {
665 msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100666 scripts/config.pl unset MBEDTLS_SSL_RENEGOTIATION
667 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
668 make
Simon Butcher3ea7f522016-03-07 23:22:10 +0000669
Gilles Peskine8f073122018-11-27 15:58:47 +0100670 msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
671 make test
Hanno Becker134c2ab2017-10-12 15:29:50 +0100672
Gilles Peskine8f073122018-11-27 15:58:47 +0100673 msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
674 if_build_succeeded tests/ssl-opt.sh
675}
Hanno Becker134c2ab2017-10-12 15:29:50 +0100676
Hanno Beckera545be22019-05-10 14:45:37 +0100677component_test_no_pem_no_fs () {
678 msg "build: Default + !MBEDTLS_PEM_PARSE_C + !MBEDTLS_FS_IO (ASan build)"
679 scripts/config.pl unset MBEDTLS_PEM_PARSE_C
680 scripts/config.pl unset MBEDTLS_FS_IO
681 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
682 make
683
684 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - main suites (inc. selftests) (ASan build)" # ~ 50s
685 make test
686
687 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - ssl-opt.sh (ASan build)" # ~ 6 min
688 if_build_succeeded tests/ssl-opt.sh
689}
690
Gilles Peskine8f073122018-11-27 15:58:47 +0100691component_test_rsa_no_crt () {
692 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100693 scripts/config.pl set MBEDTLS_RSA_NO_CRT
694 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
695 make
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +0100696
Gilles Peskine8f073122018-11-27 15:58:47 +0100697 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
698 make test
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100699
Gilles Peskine8f073122018-11-27 15:58:47 +0100700 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
701 if_build_succeeded tests/ssl-opt.sh -f RSA
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100702
Gilles Peskine8f073122018-11-27 15:58:47 +0100703 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
704 if_build_succeeded tests/compat.sh -t RSA
705}
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100706
Gilles Peskine8f073122018-11-27 15:58:47 +0100707component_test_small_ssl_out_content_len () {
708 msg "build: small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100709 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 16384
710 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
711 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
712 make
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100713
Gilles Peskine8f073122018-11-27 15:58:47 +0100714 msg "test: small SSL_OUT_CONTENT_LEN - ssl-opt.sh MFL and large packet tests"
715 if_build_succeeded tests/ssl-opt.sh -f "Max fragment\|Large packet"
716}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000717
Gilles Peskine8f073122018-11-27 15:58:47 +0100718component_test_small_ssl_in_content_len () {
719 msg "build: small SSL_IN_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100720 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 4096
721 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 16384
722 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
723 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000724
Gilles Peskine8f073122018-11-27 15:58:47 +0100725 msg "test: small SSL_IN_CONTENT_LEN - ssl-opt.sh MFL tests"
726 if_build_succeeded tests/ssl-opt.sh -f "Max fragment"
727}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000728
Gilles Peskine8f073122018-11-27 15:58:47 +0100729component_test_small_ssl_dtls_max_buffering () {
730 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0"
Gilles Peskine8f073122018-11-27 15:58:47 +0100731 scripts/config.pl set MBEDTLS_SSL_DTLS_MAX_BUFFERING 1000
732 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
733 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000734
Gilles Peskine8f073122018-11-27 15:58:47 +0100735 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0 - ssl-opt.sh specific reordering test"
736 if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer out-of-order hs msg before reassembling next, free buffered msg"
737}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100738
Gilles Peskine8f073122018-11-27 15:58:47 +0100739component_test_small_mbedtls_ssl_dtls_max_buffering () {
740 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1"
Gilles Peskine8f073122018-11-27 15:58:47 +0100741 scripts/config.pl set MBEDTLS_SSL_DTLS_MAX_BUFFERING 240
742 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
743 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100744
Gilles Peskine8f073122018-11-27 15:58:47 +0100745 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1 - ssl-opt.sh specific reordering test"
746 if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer encrypted Finished message, drop for fragmented NewSessionTicket"
747}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100748
Gilles Peskine8f073122018-11-27 15:58:47 +0100749component_test_full_cmake_clang () {
750 msg "build: cmake, full config, clang" # ~ 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100751 scripts/config.pl full
752 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
753 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check -D ENABLE_TESTING=On .
754 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100755
Gilles Peskine8f073122018-11-27 15:58:47 +0100756 msg "test: main suites (full config)" # ~ 5s
757 make test
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100758
Gilles Peskine8f073122018-11-27 15:58:47 +0100759 msg "test: ssl-opt.sh default, ECJPAKE, SSL async (full config)" # ~ 1s
760 if_build_succeeded tests/ssl-opt.sh -f 'Default\|ECJPAKE\|SSL async private'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200761
Andres Amaya Garcia2dadab72019-01-08 21:42:27 +0000762 msg "test: compat.sh RC4, DES, 3DES & NULL (full config)" # ~ 2 min
Andres Amaya Garcia419bd002019-02-19 20:20:57 +0000763 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 +0200764
Gilles Peskine8f073122018-11-27 15:58:47 +0100765 msg "test: compat.sh ARIA + ChachaPoly"
766 if_build_succeeded env OPENSSL_CMD="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
767}
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200768
Gilles Peskine8f073122018-11-27 15:58:47 +0100769component_build_deprecated () {
770 msg "build: make, full config + DEPRECATED_WARNING, gcc -O" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100771 scripts/config.pl full
772 scripts/config.pl set MBEDTLS_DEPRECATED_WARNING
773 # Build with -O -Wextra to catch a maximum of issues.
774 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra' lib programs
775 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100776
Gilles Peskine8f073122018-11-27 15:58:47 +0100777 msg "build: make, full config + DEPRECATED_REMOVED, clang -O" # ~ 30s
778 # No cleanup, just tweak the configuration and rebuild
779 make clean
780 scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
781 scripts/config.pl set MBEDTLS_DEPRECATED_REMOVED
782 # Build with -O -Wextra to catch a maximum of issues.
783 make CC=clang CFLAGS='-O -Werror -Wall -Wextra' lib programs
784 make CC=clang CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
785}
Jaeden Ameroed93bdc2018-11-02 16:57:24 +0000786
Gilles Peskine8f073122018-11-27 15:58:47 +0100787component_test_depends_curves () {
788 msg "test/build: curves.pl (gcc)" # ~ 4 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100789 record_status tests/scripts/curves.pl
790}
Jaeden Ameroacaabe72018-11-07 11:52:52 +0000791
Gilles Peskine8f073122018-11-27 15:58:47 +0100792component_test_depends_hashes () {
793 msg "test/build: depends-hashes.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100794 record_status tests/scripts/depends-hashes.pl
795}
Jaeden Ameroacaabe72018-11-07 11:52:52 +0000796
Gilles Peskine8f073122018-11-27 15:58:47 +0100797component_test_depends_pkalgs () {
798 msg "test/build: depends-pkalgs.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100799 record_status tests/scripts/depends-pkalgs.pl
800}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100801
Gilles Peskine8f073122018-11-27 15:58:47 +0100802component_build_key_exchanges () {
803 msg "test/build: key-exchanges (gcc)" # ~ 1 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100804 record_status tests/scripts/key-exchanges.pl
805}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100806
Gilles Peskine8f073122018-11-27 15:58:47 +0100807component_build_default_make_gcc_and_cxx () {
808 msg "build: Unix make, -Os (gcc)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100809 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100810
Gilles Peskine8f073122018-11-27 15:58:47 +0100811 msg "test: verify header list in cpp_dummy_build.cpp"
812 record_status check_headers_in_cpp
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100813
Gilles Peskine8f073122018-11-27 15:58:47 +0100814 msg "build: Unix make, incremental g++"
815 make TEST_CPP=1
816}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100817
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100818component_test_no_use_psa_crypto_full_cmake_asan() {
819 # full minus MBEDTLS_USE_PSA_CRYPTO: run the same set of tests as basic-build-test.sh
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500820 msg "build: cmake, full config + MBEDTLS_USE_PSA_CRYPTO, ASan"
821 scripts/config.pl full
822 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
Hanno Becker241b5242019-02-22 10:26:18 +0000823 scripts/config.pl unset MBEDTLS_ECP_RESTARTABLE # restartable ECC not supported through PSA
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500824 scripts/config.pl set MBEDTLS_PSA_CRYPTO_C
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100825 scripts/config.pl unset MBEDTLS_USE_PSA_CRYPTO
826 scripts/config.pl unset MBEDTLS_PSA_ITS_FILE_C
Andrzej Kurek324b2f72019-04-18 08:59:12 -0400827 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_C
Manuel Pégourié-Gonnardd8167e82019-02-01 11:12:52 +0100828 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500829 make
Manuel Pégourié-Gonnard43be6cd2017-06-20 09:53:42 +0200830
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100831 msg "test: main suites (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500832 make test
Manuel Pégourié-Gonnard503a5ef2015-10-23 09:04:45 +0200833
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100834 msg "test: ssl-opt.sh (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500835 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100836
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100837 msg "test: compat.sh default (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500838 if_build_succeeded tests/compat.sh
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400839
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100840 msg "test: compat.sh ssl3 (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500841 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400842
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100843 msg "test: compat.sh RC4, DES & NULL (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500844 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 -0500845
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100846 msg "test: compat.sh ARIA + ChachaPoly (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500847 if_build_succeeded env OPENSSL_CMD="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
848}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500849
Gilles Peskineadcde5e2019-06-12 16:05:50 +0200850component_test_check_params_functionality () {
851 msg "build+test: MBEDTLS_CHECK_PARAMS functionality"
852 scripts/config.pl full # includes CHECK_PARAMS
853 # Make MBEDTLS_PARAM_FAILED call mbedtls_param_failed().
854 scripts/config.pl unset MBEDTLS_CHECK_PARAMS_ASSERT
855 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
856 # Only build and run tests. Do not build sample programs, because
857 # they don't have a mbedtls_param_failed() function.
858 make CC=gcc CFLAGS='-Werror -O1' lib test
859}
860
Gilles Peskineb28636b2019-01-02 19:06:24 +0100861component_test_check_params_without_platform () {
862 msg "build+test: MBEDTLS_CHECK_PARAMS without MBEDTLS_PLATFORM_C"
863 scripts/config.pl full # includes CHECK_PARAMS
Gilles Peskineadcde5e2019-06-12 16:05:50 +0200864 # Keep MBEDTLS_PARAM_FAILED as assert.
Gilles Peskineb28636b2019-01-02 19:06:24 +0100865 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
866 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
867 scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
868 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
869 scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
870 scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
871 scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
872 scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
873 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
874 scripts/config.pl unset MBEDTLS_PLATFORM_C
875 make CC=gcc CFLAGS='-Werror -O1' all test
876}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500877
Gilles Peskineb28636b2019-01-02 19:06:24 +0100878component_test_check_params_silent () {
879 msg "build+test: MBEDTLS_CHECK_PARAMS with alternative MBEDTLS_PARAM_FAILED()"
880 scripts/config.pl full # includes CHECK_PARAMS
881 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
Gilles Peskineadcde5e2019-06-12 16:05:50 +0200882 # Set MBEDTLS_PARAM_FAILED to nothing.
Gilles Peskineb28636b2019-01-02 19:06:24 +0100883 sed -i 's/.*\(#define MBEDTLS_PARAM_FAILED( cond )\).*/\1/' "$CONFIG_H"
884 make CC=gcc CFLAGS='-Werror -O1' all test
885}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500886
Gilles Peskine8f073122018-11-27 15:58:47 +0100887component_test_no_platform () {
888 # Full configuration build, without platform support, file IO and net sockets.
889 # This should catch missing mbedtls_printf definitions, and by disabling file
890 # IO, it should catch missing '#include <stdio.h>'
891 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100892 scripts/config.pl full
893 scripts/config.pl unset MBEDTLS_PLATFORM_C
894 scripts/config.pl unset MBEDTLS_NET_C
895 scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
896 scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
897 scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
898 scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
899 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
900 scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
901 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
902 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
903 scripts/config.pl unset MBEDTLS_FS_IO
Andrzej Kurek73757082019-04-18 04:14:37 -0400904 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_C
905 scripts/config.pl unset MBEDTLS_PSA_ITS_FILE_C
Gilles Peskine8f073122018-11-27 15:58:47 +0100906 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
907 # to re-enable platform integration features otherwise disabled in C99 builds
908 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -O0 -D_DEFAULT_SOURCE' lib programs
909 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0' test
910}
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +0000911
Gilles Peskine8f073122018-11-27 15:58:47 +0100912component_build_no_std_function () {
913 # catch compile bugs in _uninit functions
914 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100915 scripts/config.pl full
916 scripts/config.pl set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
917 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
918 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
919}
Manuel Pégourié-Gonnarddccb80b2015-06-03 10:20:33 +0100920
Gilles Peskine8f073122018-11-27 15:58:47 +0100921component_build_no_ssl_srv () {
922 msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100923 scripts/config.pl full
924 scripts/config.pl unset MBEDTLS_SSL_SRV_C
925 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
926}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200927
Gilles Peskine8f073122018-11-27 15:58:47 +0100928component_build_no_ssl_cli () {
929 msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100930 scripts/config.pl full
931 scripts/config.pl unset MBEDTLS_SSL_CLI_C
932 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
933}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200934
Gilles Peskine8f073122018-11-27 15:58:47 +0100935component_build_no_sockets () {
936 # Note, C99 compliance can also be tested with the sockets support disabled,
937 # as that requires a POSIX platform (which isn't the same as C99).
938 msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100939 scripts/config.pl full
940 scripts/config.pl unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
941 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
942 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0 -std=c99 -pedantic' lib
943}
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +0200944
Gilles Peskine8f073122018-11-27 15:58:47 +0100945component_test_no_max_fragment_length () {
946 # Run max fragment length tests with MFL disabled
947 msg "build: default config except MFL extension (ASan build)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100948 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
949 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
950 make
Hanno Becker5175ac62017-09-18 15:36:25 +0100951
Gilles Peskine8f073122018-11-27 15:58:47 +0100952 msg "test: ssl-opt.sh, MFL-related tests"
953 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length"
954}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000955
Hanno Becker545ced42019-02-19 11:10:48 +0000956component_test_asan_remove_peer_certificate () {
957 msg "build: default config with MBEDTLS_SSL_KEEP_PEER_CERTIFICATE disabled (ASan build)"
958 scripts/config.pl unset MBEDTLS_SSL_KEEP_PEER_CERTIFICATE
959 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
960 make
961
962 msg "test: !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
963 make test
964
965 msg "test: ssl-opt.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
966 if_build_succeeded tests/ssl-opt.sh
967
968 msg "test: compat.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
969 if_build_succeeded tests/compat.sh
970}
971
Gilles Peskine8f073122018-11-27 15:58:47 +0100972component_test_no_max_fragment_length_small_ssl_out_content_len () {
973 msg "build: no MFL extension, small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100974 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
975 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 16384
976 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
977 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
978 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000979
Gilles Peskine8f073122018-11-27 15:58:47 +0100980 msg "test: MFL tests (disabled MFL extension case) & large packet tests"
981 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length\|Large buffer"
982}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000983
Jaeden Amero2de07f12019-06-05 13:32:08 +0100984component_test_when_no_ciphersuites_have_mac () {
985 msg "build: when no ciphersuites have MAC"
986 scripts/config.pl unset MBEDTLS_CIPHER_NULL_CIPHER
987 scripts/config.pl unset MBEDTLS_ARC4_C
988 scripts/config.pl unset MBEDTLS_CIPHER_MODE_CBC
989 make
990
991 msg "test: !MBEDTLS_SSL_SOME_MODES_USE_MAC"
992 make test
993
994 msg "test ssl-opt.sh: !MBEDTLS_SSL_SOME_MODES_USE_MAC"
Jaeden Amero6b1683d2019-06-05 14:42:50 +0100995 if_build_succeeded tests/ssl-opt.sh -f 'Default\|EtM' -e 'without EtM'
Jaeden Amero2de07f12019-06-05 13:32:08 +0100996}
997
Gilles Peskine8f073122018-11-27 15:58:47 +0100998component_test_null_entropy () {
999 msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +01001000 scripts/config.pl set MBEDTLS_TEST_NULL_ENTROPY
1001 scripts/config.pl set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
1002 scripts/config.pl set MBEDTLS_ENTROPY_C
1003 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
1004 scripts/config.pl unset MBEDTLS_ENTROPY_HARDWARE_ALT
1005 scripts/config.pl unset MBEDTLS_HAVEGE_C
Gilles Peskine5fa32a72019-01-06 19:48:30 +00001006 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan -D UNSAFE_BUILD=ON .
Gilles Peskine8f073122018-11-27 15:58:47 +01001007 make
Janos Follath06c54002016-06-09 13:57:40 +01001008
Gilles Peskine8f073122018-11-27 15:58:47 +01001009 msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)"
1010 make test
1011}
Janos Follath06c54002016-06-09 13:57:40 +01001012
Gilles Peskine8f073122018-11-27 15:58:47 +01001013component_test_platform_calloc_macro () {
1014 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +01001015 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
1016 scripts/config.pl set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
1017 scripts/config.pl set MBEDTLS_PLATFORM_FREE_MACRO free
1018 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1019 make
Hanno Beckere5fecec2018-10-11 11:02:52 +01001020
Gilles Peskine8f073122018-11-27 15:58:47 +01001021 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
1022 make test
1023}
Hanno Beckere5fecec2018-10-11 11:02:52 +01001024
Gilles Peskine8f073122018-11-27 15:58:47 +01001025component_test_make_shared () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001026 msg "build/test: make shared" # ~ 40s
Andrzej Kurek87615772019-04-19 15:03:58 -04001027 make SHARED=1 all check -j1
Gilles Peskine8f073122018-11-27 15:58:47 +01001028}
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +02001029
Gilles Peskine8f073122018-11-27 15:58:47 +01001030component_test_m32_o0 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001031 # Build once with -O0, to compile out the i386 specific inline assembly
1032 msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
Simon Butcher7a6da6e2018-06-27 21:52:54 +01001033 scripts/config.pl full
Philippe Antoinecd2c1272019-06-25 21:50:07 +02001034 make CC=gcc CFLAGS='-O0 -Werror -Wall -Wextra -m32 -fsanitize=address' LDFLAGS='-m32 -fsanitize=address'
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01001035
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001036 msg "test: i386, make, gcc -O0 (ASan build)"
1037 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01001038}
Gilles Peskine878cf602019-01-06 20:50:38 +00001039support_test_m32_o0 () {
1040 case $(uname -m) in
1041 *64*) true;;
1042 *) false;;
1043 esac
1044}
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001045
Gilles Peskine8f073122018-11-27 15:58:47 +01001046component_test_m32_o1 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001047 # Build again with -O1, to compile in the i386 specific inline assembly
1048 msg "build: i386, make, gcc -O1 (ASan build)" # ~ 30s
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001049 scripts/config.pl full
Gilles Peskine4b317612019-04-08 16:58:02 +02001050 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE
1051 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
1052 scripts/config.pl unset MBEDTLS_MEMORY_DEBUG
Philippe Antoinecd2c1272019-06-25 21:50:07 +02001053 make CC=gcc CFLAGS='-O1 -Werror -Wall -Wextra -m32 -fsanitize=address' LDFLAGS='-m32 -fsanitize=address'
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001054
1055 msg "test: i386, make, gcc -O1 (ASan build)"
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001056 make test
Gilles Peskine4b317612019-04-08 16:58:02 +02001057
1058 msg "test ssl-opt.sh, i386, make, gcc-O1"
1059 if_build_succeeded tests/ssl-opt.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01001060}
Gilles Peskine878cf602019-01-06 20:50:38 +00001061support_test_m32_o1 () {
1062 support_test_m32_o0 "$@"
1063}
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001064
Gilles Peskine8f073122018-11-27 15:58:47 +01001065component_test_mx32 () {
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001066 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
Simon Butcher7a6da6e2018-06-27 21:52:54 +01001067 scripts/config.pl full
Gilles Peskine5d26e7c2019-06-07 14:50:09 +02001068 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32' LDFLAGS='-mx32'
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001069
1070 msg "test: 64-bit ILP32, make, gcc"
1071 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01001072}
Gilles Peskine878cf602019-01-06 20:50:38 +00001073support_test_mx32 () {
1074 case $(uname -m) in
1075 amd64|x86_64) true;;
1076 *) false;;
1077 esac
1078}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001079
Gilles Peskine8f073122018-11-27 15:58:47 +01001080component_build_arm_none_eabi_gcc () {
1081 msg "build: arm-none-eabi-gcc, make" # ~ 10s
Manuel Pégourié-Gonnarddf2bfcf2019-04-29 12:44:12 +02001082 scripts/config.pl baremetal
Gilles Peskine8f073122018-11-27 15:58:47 +01001083 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
1084}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001085
Gilles Peskine8f073122018-11-27 15:58:47 +01001086component_build_arm_none_eabi_gcc_no_udbl_division () {
1087 msg "build: arm-none-eabi-gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
Manuel Pégourié-Gonnarddf2bfcf2019-04-29 12:44:12 +02001088 scripts/config.pl baremetal
Gilles Peskine8f073122018-11-27 15:58:47 +01001089 scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
1090 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
1091 echo "Checking that software 64-bit division is not required"
1092 if_build_succeeded not grep __aeabi_uldiv library/*.o
1093}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001094
Gilles Peskine8f073122018-11-27 15:58:47 +01001095component_build_arm_none_eabi_gcc_no_64bit_multiplication () {
1096 msg "build: arm-none-eabi-gcc MBEDTLS_NO_64BIT_MULTIPLICATION, make" # ~ 10s
Manuel Pégourié-Gonnarddf2bfcf2019-04-29 12:44:12 +02001097 scripts/config.pl baremetal
Gilles Peskine8f073122018-11-27 15:58:47 +01001098 scripts/config.pl set MBEDTLS_NO_64BIT_MULTIPLICATION
1099 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -O1 -march=armv6-m -mthumb' lib
1100 echo "Checking that software 64-bit multiplication is not required"
1101 if_build_succeeded not grep __aeabi_lmul library/*.o
1102}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001103
Gilles Peskine8f073122018-11-27 15:58:47 +01001104component_build_armcc () {
1105 msg "build: ARM Compiler 5, make"
Manuel Pégourié-Gonnarddf2bfcf2019-04-29 12:44:12 +02001106 scripts/config.pl baremetal
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001107
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001108 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
1109 make clean
Andres AG87bb5772016-09-27 15:05:15 +01001110
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001111 # ARM Compiler 6 - Target ARMv7-A
1112 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-a"
Simon Butcher940737f2017-07-23 13:42:36 +02001113
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001114 # ARM Compiler 6 - Target ARMv7-M
1115 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m"
Simon Butcher940737f2017-07-23 13:42:36 +02001116
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001117 # ARM Compiler 6 - Target ARMv8-A - AArch32
1118 armc6_build_test "--target=arm-arm-none-eabi -march=armv8.2-a"
Simon Butcher940737f2017-07-23 13:42:36 +02001119
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001120 # ARM Compiler 6 - Target ARMv8-M
1121 armc6_build_test "--target=arm-arm-none-eabi -march=armv8-m.main"
Simon Butcher940737f2017-07-23 13:42:36 +02001122
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001123 # ARM Compiler 6 - Target ARMv8-A - AArch64
1124 armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a"
Gilles Peskine8f073122018-11-27 15:58:47 +01001125}
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +01001126
Gilles Peskine8f073122018-11-27 15:58:47 +01001127component_test_allow_sha1 () {
1128 msg "build: allow SHA1 in certificates by default"
Gilles Peskine8f073122018-11-27 15:58:47 +01001129 scripts/config.pl set MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
1130 make CFLAGS='-Werror -Wall -Wextra'
1131 msg "test: allow SHA1 in certificates by default"
1132 make test
1133 if_build_succeeded tests/ssl-opt.sh -f SHA-1
1134}
Gilles Peskine2a458da2017-05-12 15:26:58 +02001135
Gilles Peskine8f073122018-11-27 15:58:47 +01001136component_build_mingw () {
1137 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
Andrzej Kurek62faadd2019-04-19 20:10:21 -04001138 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 +00001139
Gilles Peskine8f073122018-11-27 15:58:47 +01001140 # note Make tests only builds the tests, but doesn't run them
Andrzej Kurek62faadd2019-04-19 20:10:21 -04001141 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 +01001142 make WINDOWS_BUILD=1 clean
Simon Butcher002bc622016-11-17 09:27:45 +00001143
Gilles Peskine8f073122018-11-27 15:58:47 +01001144 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
Andrzej Kurek87615772019-04-19 15:03:58 -04001145 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
1146 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 +01001147 make WINDOWS_BUILD=1 clean
1148}
Jaeden Amero117b8a42019-04-17 15:19:26 +01001149support_build_mingw() {
1150 case $(i686-w64-mingw32-gcc -dumpversion) in
1151 [0-5]*) false;;
1152 *) true;;
1153 esac
1154}
Manuel Pégourié-Gonnard6448bce2015-02-16 17:18:36 +01001155
Gilles Peskine8f073122018-11-27 15:58:47 +01001156component_test_memsan () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001157 msg "build: MSan (clang)" # ~ 1 min 20s
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001158 scripts/config.pl unset MBEDTLS_AESNI_C # memsan doesn't grok asm
1159 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
1160 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +02001161
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001162 msg "test: main suites (MSan)" # ~ 10s
1163 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001164
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001165 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
Gilles Peskine7c652162017-12-11 00:01:40 +01001166 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001167
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001168 # Optional part(s)
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001169
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001170 if [ "$MEMORY" -gt 0 ]; then
1171 msg "test: compat.sh (MSan)" # ~ 6 min 20s
Gilles Peskine7c652162017-12-11 00:01:40 +01001172 if_build_succeeded tests/compat.sh
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001173 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001174}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001175
Gilles Peskine69f190e2019-01-10 00:11:42 +01001176component_test_valgrind () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001177 msg "build: Release (clang)"
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001178 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
1179 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001180
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001181 msg "test: main suites valgrind (Release)"
1182 make memcheck
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001183
Gilles Peskinef1349e42019-04-08 17:00:56 +02001184 # Optional parts (slow; currently broken on OS X because programs don't
1185 # seem to receive signals under valgrind on OS X).
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001186 if [ "$MEMORY" -gt 0 ]; then
1187 msg "test: ssl-opt.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +01001188 if_build_succeeded tests/ssl-opt.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001189 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001190
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001191 if [ "$MEMORY" -gt 1 ]; then
1192 msg "test: compat.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +01001193 if_build_succeeded tests/compat.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001194 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001195}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001196
Gilles Peskine8f073122018-11-27 15:58:47 +01001197component_test_cmake_out_of_source () {
1198 msg "build: cmake 'out-of-source' build"
Gilles Peskine8f073122018-11-27 15:58:47 +01001199 MBEDTLS_ROOT_DIR="$PWD"
1200 mkdir "$OUT_OF_SOURCE_DIR"
1201 cd "$OUT_OF_SOURCE_DIR"
1202 cmake "$MBEDTLS_ROOT_DIR"
1203 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001204
Gilles Peskine8f073122018-11-27 15:58:47 +01001205 msg "test: cmake 'out-of-source' build"
1206 make test
1207 # Test an SSL option that requires an auxiliary script in test/scripts/.
1208 # Also ensure that there are no error messages such as
1209 # "No such file or directory", which would indicate that some required
1210 # file is missing (ssl-opt.sh tolerates the absence of some files so
1211 # may exit with status 0 but emit errors).
1212 if_build_succeeded ./tests/ssl-opt.sh -f 'Fallback SCSV: beginning of list' 2>ssl-opt.err
1213 if [ -s ssl-opt.err ]; then
1214 cat ssl-opt.err >&2
1215 record_status [ ! -s ssl-opt.err ]
1216 rm ssl-opt.err
1217 fi
1218 cd "$MBEDTLS_ROOT_DIR"
1219 rm -rf "$OUT_OF_SOURCE_DIR"
1220 unset MBEDTLS_ROOT_DIR
1221}
Andres AGdc192212016-08-31 17:33:13 +01001222
Gilles Peskine8f073122018-11-27 15:58:47 +01001223component_test_zeroize () {
1224 # Test that the function mbedtls_platform_zeroize() is not optimized away by
1225 # different combinations of compilers and optimization flags by using an
1226 # auxiliary GDB script. Unfortunately, GDB does not return error values to the
1227 # system in all cases that the script fails, so we must manually search the
1228 # output to check whether the pass string is present and no failure strings
1229 # were printed.
Andres AGdc192212016-08-31 17:33:13 +01001230
Gilles Peskine4976e822019-01-06 19:52:22 +00001231 # Don't try to disable ASLR. We don't care about ASLR here. We do care
1232 # about a spurious message if Gdb tries and fails, so suppress that.
1233 gdb_disable_aslr=
1234 if [ -z "$(gdb -batch -nw -ex 'set disable-randomization off' 2>&1)" ]; then
1235 gdb_disable_aslr='set disable-randomization off'
1236 fi
1237
Gilles Peskine8f073122018-11-27 15:58:47 +01001238 for optimization_flag in -O2 -O3 -Ofast -Os; do
Gilles Peskine55f7c942019-01-09 22:28:21 +01001239 for compiler in clang gcc; do
1240 msg "test: $compiler $optimization_flag, mbedtls_platform_zeroize()"
1241 make programs CC="$compiler" DEBUG=1 CFLAGS="$optimization_flag"
Gilles Peskine4976e822019-01-06 19:52:22 +00001242 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 +01001243 if_build_succeeded grep "The buffer was correctly zeroized" test_zeroize.log
1244 if_build_succeeded not grep -i "error" test_zeroize.log
1245 rm -f test_zeroize.log
1246 make clean
1247 done
Andres Amaya Garcia29673812017-10-25 10:35:51 +01001248 done
Andres Amaya Garciad0d7bf62017-10-25 09:01:31 +01001249
Gilles Peskine4976e822019-01-06 19:52:22 +00001250 unset gdb_disable_aslr
Gilles Peskine8f073122018-11-27 15:58:47 +01001251}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001252
Gilles Peskineaad2ebd2019-02-25 20:26:06 +01001253support_check_python_files () {
1254 type pylint3 >/dev/null 2>/dev/null
1255}
Gilles Peskine8f073122018-11-27 15:58:47 +01001256component_check_python_files () {
1257 msg "Lint: Python scripts"
1258 record_status tests/scripts/check-python-files.sh
1259}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001260
Gilles Peskine8f073122018-11-27 15:58:47 +01001261component_check_generate_test_code () {
1262 msg "uint test: generate_test_code.py"
1263 record_status ./tests/scripts/test_generate_test_code.py
1264}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001265
1266################################################################
1267#### Termination
1268################################################################
1269
Gilles Peskine8f073122018-11-27 15:58:47 +01001270post_report () {
1271 msg "Done, cleaning up"
1272 cleanup
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001273
Gilles Peskine8f073122018-11-27 15:58:47 +01001274 final_report
1275}
1276
1277
1278
1279################################################################
1280#### Run all the things
1281################################################################
1282
Gilles Peskinee48351a2018-11-27 16:06:30 +01001283# Run one component and clean up afterwards.
Gilles Peskine8f073122018-11-27 15:58:47 +01001284run_component () {
Gilles Peskine608953e2019-01-02 18:57:02 +01001285 # Back up the configuration in case the component modifies it.
1286 # The cleanup function will restore it.
1287 cp -p "$CONFIG_H" "$CONFIG_BAK"
Gilles Peskineffcdeff2018-12-04 12:49:28 +01001288 current_component="$1"
Gilles Peskine8f073122018-11-27 15:58:47 +01001289 "$@"
Gilles Peskinee48351a2018-11-27 16:06:30 +01001290 cleanup
Gilles Peskine8f073122018-11-27 15:58:47 +01001291}
1292
1293# Preliminary setup
1294pre_check_environment
1295pre_initialize_variables
1296pre_parse_command_line "$@"
Gilles Peskine348fb9a2018-11-27 17:04:29 +01001297
Gilles Peskine878cf602019-01-06 20:50:38 +00001298pre_check_git
Andrzej Kurekeb508712019-02-14 07:18:59 -05001299pre_check_seedfile
1300
Gilles Peskine878cf602019-01-06 20:50:38 +00001301build_status=0
1302if [ $KEEP_GOING -eq 1 ]; then
1303 pre_setup_keep_going
Gilles Peskine92525112018-11-27 18:15:35 +01001304else
Gilles Peskine878cf602019-01-06 20:50:38 +00001305 record_status () {
1306 "$@"
1307 }
Gilles Peskine8f073122018-11-27 15:58:47 +01001308fi
Gilles Peskine878cf602019-01-06 20:50:38 +00001309pre_print_configuration
1310pre_check_tools
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001311cleanup
1312
Gilles Peskinebeb3a812019-01-06 22:11:25 +00001313# Run the requested tests.
1314for component in $RUN_COMPONENTS; do
1315 run_component "component_$component"
1316done
Gilles Peskine8f073122018-11-27 15:58:47 +01001317
1318# We're done.
Gilles Peskine878cf602019-01-06 20:50:38 +00001319post_report