blob: 5fdb1412db87221c4994929bbfb519b0ad14e6cd [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
27# * Makefile, library/Makefile, programs/Makefile, tests/Makefile
28# After running this script, the CMake cache will be lost and CMake
29# will no longer be initialised.
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +010030#
Gilles Peskine192c72f2017-12-21 15:59:21 +010031# The script assumes the presence of a number of tools:
32# * Basic Unix tools (Windows users note: a Unix-style find must be before
33# the Windows find in the PATH)
34# * Perl
35# * GNU Make
36# * CMake
37# * GCC and Clang (recent enough for using ASan with gcc and MemSan with clang, or valgrind)
Andrzej Kurek05be06c2018-06-28 04:41:50 -040038# * G++
Gilles Peskine192c72f2017-12-21 15:59:21 +010039# * arm-gcc and mingw-gcc
40# * ArmCC 5 and ArmCC 6, unless invoked with --no-armcc
Gilles Peskine192c72f2017-12-21 15:59:21 +010041# * OpenSSL and GnuTLS command line tools, recent enough for the
42# interoperability tests. If they don't support SSLv3 then a legacy
43# version of these tools must be present as well (search for LEGACY
44# below).
45# See the invocation of check_tools below for details.
46#
47# This script must be invoked from the toplevel directory of a git
48# working copy of Mbed TLS.
49#
50# Note that the output is not saved. You may want to run
51# script -c tests/scripts/all.sh
52# or
53# tests/scripts/all.sh >all.log 2>&1
54#
55# Notes for maintainers
56# ---------------------
57#
Gilles Peskine8f073122018-11-27 15:58:47 +010058# The bulk of the code is organized into functions that follow one of the
59# following naming conventions:
60# * pre_XXX: things to do before running the tests, in order.
61# * component_XXX: independent components. They can be run in any order.
62# * component_check_XXX: quick tests that aren't worth parallelizing
63# * component_build_XXX: build things but don't run them
64# * component_test_XXX: build and test
65# * post_XXX: things to do after running the tests.
66# * other: miscellaneous support functions.
67#
Gilles Peskine192c72f2017-12-21 15:59:21 +010068# The tests are roughly in order from fastest to slowest. This doesn't
69# have to be exact, but in general you should add slower tests towards
70# the end and fast checks near the beginning.
71#
72# Sanity checks have the following form:
73# 1. msg "short description of what is about to be done"
74# 2. run sanity check (failure stops the script)
75#
76# Build or build-and-test steps have the following form:
77# 1. msg "short description of what is about to be done"
78# 2. cleanup
79# 3. preparation (config.pl, cmake, ...) (failure stops the script)
80# 4. make
81# 5. Run tests if relevant. All tests must be prefixed with
82# if_build_successful for the sake of --keep-going.
83
84
85
86################################################################
87#### Initialization and command line parsing
88################################################################
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010089
SimonB2e23c822016-04-16 21:54:39 +010090# Abort on errors (and uninitialised variables)
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010091set -eu
92
Gilles Peskine8f073122018-11-27 15:58:47 +010093pre_check_environment () {
Gilles Peskinea16c2b12019-01-06 19:58:02 +000094 if [ -d library -a -d include -a -d tests ]; then :; else
Gilles Peskine8f073122018-11-27 15:58:47 +010095 echo "Must be run from mbed TLS root" >&2
96 exit 1
97 fi
98}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010099
Gilles Peskine8f073122018-11-27 15:58:47 +0100100pre_initialize_variables () {
101 CONFIG_H='include/mbedtls/config.h'
102 CONFIG_BAK="$CONFIG_H.bak"
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200103
Gilles Peskine92525112018-11-27 18:15:35 +0100104 COMPONENTS=
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100105 ALL_EXCEPT=0
Gilles Peskine8f073122018-11-27 15:58:47 +0100106 MEMORY=0
107 FORCE=0
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100108 INTROSPECTION_MODE=
Gilles Peskine8f073122018-11-27 15:58:47 +0100109 KEEP_GOING=0
110 RUN_ARMCC=1
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100111
Gilles Peskine8f073122018-11-27 15:58:47 +0100112 # Default commands, can be overriden by the environment
113 : ${OPENSSL:="openssl"}
114 : ${OPENSSL_LEGACY:="$OPENSSL"}
115 : ${OPENSSL_NEXT:="$OPENSSL"}
116 : ${GNUTLS_CLI:="gnutls-cli"}
117 : ${GNUTLS_SERV:="gnutls-serv"}
118 : ${GNUTLS_LEGACY_CLI:="$GNUTLS_CLI"}
119 : ${GNUTLS_LEGACY_SERV:="$GNUTLS_SERV"}
120 : ${OUT_OF_SOURCE_DIR:=./mbedtls_out_of_source_build}
121 : ${ARMC5_BIN_DIR:=/usr/bin}
122 : ${ARMC6_BIN_DIR:=/usr/bin}
Andres AGdc192212016-08-31 17:33:13 +0100123
Gilles Peskine8f073122018-11-27 15:58:47 +0100124 # if MAKEFLAGS is not set add the -j option to speed up invocations of make
Gilles Peskinea1fc4b52019-01-06 20:15:26 +0000125 if [ -z "${MAKEFLAGS+set}" ]; then
Gilles Peskine8f073122018-11-27 15:58:47 +0100126 export MAKEFLAGS="-j"
127 fi
128}
Andres AG38495a32016-07-12 16:54:33 +0100129
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100130# Test whether $1 is excluded via $COMPONENTS (a space-separated list of
131# wildcard patterns).
132component_is_excluded()
133{
134 set -f
135 for pattern in $COMPONENTS; do
136 set +f
137 case ${1#component_} in $pattern) return 0;; esac
138 done
139 set +f
140 return 1
141}
142
Simon Butcher41eeccf2016-09-07 00:07:09 +0100143usage()
SimonB2e23c822016-04-16 21:54:39 +0100144{
Gilles Peskine709346a2017-12-10 23:43:39 +0100145 cat <<EOF
Gilles Peskine92525112018-11-27 18:15:35 +0100146Usage: $0 [OPTION]... [COMPONENT]...
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100147Run mbedtls release validation tests.
Gilles Peskine92525112018-11-27 18:15:35 +0100148By default, run all tests. With one or more COMPONENT, run only those.
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100149
150Special options:
151 -h|--help Print this help and exit.
152 --list-components List available test components and exit.
Gilles Peskine709346a2017-12-10 23:43:39 +0100153
154General options:
155 -f|--force Force the tests to overwrite any modified files.
Gilles Peskine7c652162017-12-11 00:01:40 +0100156 -k|--keep-going Run all tests and report errors at the end.
Gilles Peskine709346a2017-12-10 23:43:39 +0100157 -m|--memory Additional optional memory tests.
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100158 --armcc Run ARM Compiler builds (on by default).
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100159 --except If some components are passed on the command line,
160 run all the tests except for these components. In
161 this mode, you can pass shell wildcard patterns as
162 component names, e.g. "$0 --except 'test_*'" to
163 exclude all components that run tests.
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100164 --no-armcc Skip ARM Compiler builds.
Gilles Peskine38d81652018-03-21 08:40:26 +0100165 --no-force Refuse to overwrite modified files (default).
166 --no-keep-going Stop at the first error (default).
167 --no-memory No additional memory tests (default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100168 --out-of-source-dir=<path> Directory used for CMake out-of-source build tests.
Gilles Peskine38d81652018-03-21 08:40:26 +0100169 --random-seed Use a random seed value for randomized tests (default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100170 -r|--release-test Run this script in release mode. This fixes the seed value to 1.
171 -s|--seed Integer seed value to use for this test run.
172
173Tool path options:
174 --armc5-bin-dir=<ARMC5_bin_dir_path> ARM Compiler 5 bin directory.
175 --armc6-bin-dir=<ARMC6_bin_dir_path> ARM Compiler 6 bin directory.
176 --gnutls-cli=<GnuTLS_cli_path> GnuTLS client executable to use for most tests.
177 --gnutls-serv=<GnuTLS_serv_path> GnuTLS server executable to use for most tests.
178 --gnutls-legacy-cli=<GnuTLS_cli_path> GnuTLS client executable to use for legacy tests.
179 --gnutls-legacy-serv=<GnuTLS_serv_path> GnuTLS server executable to use for legacy tests.
180 --openssl=<OpenSSL_path> OpenSSL executable to use for most tests.
181 --openssl-legacy=<OpenSSL_path> OpenSSL executable to use for legacy tests e.g. SSLv3.
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100182 --openssl-next=<OpenSSL_path> OpenSSL executable to use for recent things like ARIA
Gilles Peskine709346a2017-12-10 23:43:39 +0100183EOF
SimonB2e23c822016-04-16 21:54:39 +0100184}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100185
186# remove built files as well as the cmake cache/config
187cleanup()
188{
Gilles Peskinea71d64c2018-03-21 12:16:57 +0100189 if [ -n "${MBEDTLS_ROOT_DIR+set}" ]; then
190 cd "$MBEDTLS_ROOT_DIR"
191 fi
192
Gilles Peskine7c652162017-12-11 00:01:40 +0100193 command make clean
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200194
Gilles Peskine31b07e22018-03-21 12:15:06 +0100195 # Remove CMake artefacts
Simon Butcher3ad2efd2018-05-02 14:49:38 +0100196 find . -name .git -prune \
Gilles Peskine31b07e22018-03-21 12:15:06 +0100197 -iname CMakeFiles -exec rm -rf {} \+ -o \
198 \( -iname cmake_install.cmake -o \
199 -iname CTestTestfile.cmake -o \
200 -iname CMakeCache.txt \) -exec rm {} \+
201 # Recover files overwritten by in-tree CMake builds
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000202 rm -f include/Makefile include/mbedtls/Makefile programs/*/Makefile
Paul Bakkerfe0984d2014-06-13 00:13:45 +0200203 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile
204 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200205
206 if [ -f "$CONFIG_BAK" ]; then
207 mv "$CONFIG_BAK" "$CONFIG_H"
208 fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100209}
210
Gilles Peskine7c652162017-12-11 00:01:40 +0100211# Executed on exit. May be redefined depending on command line options.
212final_report () {
213 :
214}
215
216fatal_signal () {
217 cleanup
218 final_report $1
219 trap - $1
220 kill -$1 $$
221}
222
223trap 'fatal_signal HUP' HUP
224trap 'fatal_signal INT' INT
225trap 'fatal_signal TERM' TERM
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200226
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100227msg()
228{
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100229 if [ -n "${current_component:-}" ]; then
230 current_section="${current_component#component_}: $1"
231 else
232 current_section="$1"
233 fi
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100234 echo ""
235 echo "******************************************************************"
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100236 echo "* $current_section "
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000237 printf "* "; date
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100238 echo "******************************************************************"
239}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100240
Gilles Peskine8f073122018-11-27 15:58:47 +0100241armc6_build_test()
242{
243 FLAGS="$1"
Andres AGa5cd9732016-10-17 15:23:10 +0100244
Gilles Peskine8f073122018-11-27 15:58:47 +0100245 msg "build: ARM Compiler 6 ($FLAGS), make"
246 ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \
247 WARNING_CFLAGS='-xc -std=c99' make lib
248 make clean
249}
Andres AGa5cd9732016-10-17 15:23:10 +0100250
Andres AGd9eba4b2016-08-26 14:42:14 +0100251err_msg()
252{
253 echo "$1" >&2
254}
255
256check_tools()
257{
258 for TOOL in "$@"; do
Andres AG98393602017-01-31 17:04:45 +0000259 if ! `type "$TOOL" >/dev/null 2>&1`; then
Andres AGd9eba4b2016-08-26 14:42:14 +0100260 err_msg "$TOOL not found!"
261 exit 1
262 fi
263 done
264}
265
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400266check_headers_in_cpp () {
267 ls include/mbedtls >headers.txt
268 <programs/test/cpp_dummy_build.cpp sed -n 's/"$//; s!^#include "mbedtls/!!p' |
269 sort |
270 diff headers.txt -
271 rm headers.txt
272}
273
Gilles Peskine8f073122018-11-27 15:58:47 +0100274pre_parse_command_line () {
275 while [ $# -gt 0 ]; do
Gilles Peskine55f7c942019-01-09 22:28:21 +0100276 case "$1" in
277 --armcc) RUN_ARMCC=1;;
278 --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
279 --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
280 --except) ALL_EXCEPT=1;;
281 --force|-f) FORCE=1;;
282 --gnutls-cli) shift; GNUTLS_CLI="$1";;
283 --gnutls-legacy-cli) shift; GNUTLS_LEGACY_CLI="$1";;
284 --gnutls-legacy-serv) shift; GNUTLS_LEGACY_SERV="$1";;
285 --gnutls-serv) shift; GNUTLS_SERV="$1";;
286 --help|-h) usage; exit;;
287 --keep-going|-k) KEEP_GOING=1;;
288 --list-components) INTROSPECTION_MODE=list_components;;
289 --memory|-m) MEMORY=1;;
290 --no-armcc) RUN_ARMCC=0;;
291 --no-force) FORCE=0;;
292 --no-keep-going) KEEP_GOING=0;;
293 --no-memory) MEMORY=0;;
294 --openssl) shift; OPENSSL="$1";;
295 --openssl-legacy) shift; OPENSSL_LEGACY="$1";;
296 --openssl-next) shift; OPENSSL_NEXT="$1";;
297 --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
298 --random-seed) unset SEED;;
299 --release-test|-r) SEED=1;;
300 --seed|-s) shift; SEED="$1";;
301 -*)
302 echo >&2 "Unknown option: $1"
303 echo >&2 "Run $0 --help for usage."
304 exit 120
305 ;;
306 *)
307 COMPONENTS="$COMPONENTS $1";;
308 esac
309 shift
Gilles Peskine8f073122018-11-27 15:58:47 +0100310 done
311}
SimonB2e23c822016-04-16 21:54:39 +0100312
Gilles Peskine8f073122018-11-27 15:58:47 +0100313pre_check_git () {
314 if [ $FORCE -eq 1 ]; then
315 git checkout-index -f -q $CONFIG_H
316 cleanup
317 else
SimonB2e23c822016-04-16 21:54:39 +0100318
Gilles Peskine8f073122018-11-27 15:58:47 +0100319 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
320 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
321 echo "You can either delete this directory manually, or force the test by rerunning"
322 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
323 exit 1
324 fi
325
326 if ! git diff-files --quiet include/mbedtls/config.h; then
327 err_msg "Warning - the configuration file 'include/mbedtls/config.h' has been edited. "
328 echo "You can either delete or preserve your work, or force the test by rerunning the"
329 echo "script as: $0 --force"
330 exit 1
331 fi
Andres AGdc192212016-08-31 17:33:13 +0100332 fi
Gilles Peskine8f073122018-11-27 15:58:47 +0100333}
Andres AGdc192212016-08-31 17:33:13 +0100334
Gilles Peskine8f073122018-11-27 15:58:47 +0100335pre_setup_keep_going () {
Gilles Peskine7c652162017-12-11 00:01:40 +0100336 failure_summary=
337 failure_count=0
338 start_red=
339 end_color=
340 if [ -t 1 ]; then
Gilles Peskine9736b9d2018-01-02 21:54:17 +0100341 case "${TERM:-}" in
Gilles Peskine7c652162017-12-11 00:01:40 +0100342 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
343 start_red=$(printf '\033[31m')
344 end_color=$(printf '\033[0m')
345 ;;
346 esac
347 fi
348 record_status () {
349 if "$@"; then
350 last_status=0
351 else
352 last_status=$?
353 text="$current_section: $* -> $last_status"
354 failure_summary="$failure_summary
355$text"
356 failure_count=$((failure_count + 1))
357 echo "${start_red}^^^^$text^^^^${end_color}"
358 fi
359 }
360 make () {
361 case "$*" in
362 *test|*check)
363 if [ $build_status -eq 0 ]; then
364 record_status command make "$@"
365 else
366 echo "(skipped because the build failed)"
367 fi
368 ;;
369 *)
370 record_status command make "$@"
371 build_status=$last_status
372 ;;
373 esac
374 }
375 final_report () {
376 if [ $failure_count -gt 0 ]; then
377 echo
378 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
379 echo "${start_red}FAILED: $failure_count${end_color}$failure_summary"
380 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Jaeden Amero7c1258d2018-07-20 16:42:14 +0100381 exit 1
Gilles Peskine7c652162017-12-11 00:01:40 +0100382 elif [ -z "${1-}" ]; then
383 echo "SUCCESS :)"
384 fi
385 if [ -n "${1-}" ]; then
386 echo "Killed by SIG$1."
387 fi
388 }
Gilles Peskine8f073122018-11-27 15:58:47 +0100389}
390
Gilles Peskine7c652162017-12-11 00:01:40 +0100391if_build_succeeded () {
392 if [ $build_status -eq 0 ]; then
393 record_status "$@"
394 fi
395}
396
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200397# to be used instead of ! for commands run with
398# record_status or if_build_succeeded
399not() {
400 ! "$@"
401}
402
Gilles Peskine8f073122018-11-27 15:58:47 +0100403pre_print_configuration () {
404 msg "info: $0 configuration"
405 echo "MEMORY: $MEMORY"
406 echo "FORCE: $FORCE"
407 echo "SEED: ${SEED-"UNSET"}"
408 echo "OPENSSL: $OPENSSL"
409 echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
410 echo "OPENSSL_NEXT: $OPENSSL_NEXT"
411 echo "GNUTLS_CLI: $GNUTLS_CLI"
412 echo "GNUTLS_SERV: $GNUTLS_SERV"
413 echo "GNUTLS_LEGACY_CLI: $GNUTLS_LEGACY_CLI"
414 echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV"
415 echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
416 echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
417}
Andres AG87bb5772016-09-27 15:05:15 +0100418
Gilles Peskine8f073122018-11-27 15:58:47 +0100419pre_check_tools () {
420 ARMC5_CC="$ARMC5_BIN_DIR/armcc"
421 ARMC5_AR="$ARMC5_BIN_DIR/armar"
422 ARMC6_CC="$ARMC6_BIN_DIR/armclang"
423 ARMC6_AR="$ARMC6_BIN_DIR/armar"
Andres AGd9eba4b2016-08-26 14:42:14 +0100424
Gilles Peskine8f073122018-11-27 15:58:47 +0100425 # To avoid setting OpenSSL and GnuTLS for each call to compat.sh and ssl-opt.sh
426 # we just export the variables they require
427 export OPENSSL_CMD="$OPENSSL"
428 export GNUTLS_CLI="$GNUTLS_CLI"
429 export GNUTLS_SERV="$GNUTLS_SERV"
Andres AGb2fdd042016-09-22 14:17:46 +0100430
Gilles Peskine8f073122018-11-27 15:58:47 +0100431 # Avoid passing --seed flag in every call to ssl-opt.sh
432 if [ -n "${SEED-}" ]; then
433 export SEED
434 fi
Andres AG7770ea82016-10-10 15:46:20 +0100435
Gilles Peskine8f073122018-11-27 15:58:47 +0100436 # Make sure the tools we need are available.
437 check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$OPENSSL_NEXT" \
438 "$GNUTLS_CLI" "$GNUTLS_SERV" \
439 "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV" "doxygen" "dot" \
440 "arm-none-eabi-gcc" "i686-w64-mingw32-gcc" "gdb"
441 if [ $RUN_ARMCC -ne 0 ]; then
442 check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC6_CC" "$ARMC6_AR"
443 fi
444}
Gilles Peskine192c72f2017-12-21 15:59:21 +0100445
446
447################################################################
448#### Basic checks
449################################################################
Andres AGd9eba4b2016-08-26 14:42:14 +0100450
SimonB2e23c822016-04-16 21:54:39 +0100451#
452# Test Suites to be executed
453#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200454# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100455# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard61bc57a2014-08-14 11:29:06 +0200456# and/or are more likely to fail than others (eg I use Clang most of the
457# time, so start with a GCC build).
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200458# 2. Minimize total running time, by avoiding useless rebuilds
459#
460# Indicative running times are given for reference.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100461
Gilles Peskine8f073122018-11-27 15:58:47 +0100462pre_print_tools () {
463 msg "info: output_env.sh"
464 OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY" GNUTLS_CLI="$GNUTLS_CLI" \
465 GNUTLS_SERV="$GNUTLS_SERV" GNUTLS_LEGACY_CLI="$GNUTLS_LEGACY_CLI" \
466 GNUTLS_LEGACY_SERV="$GNUTLS_LEGACY_SERV" ARMC5_CC="$ARMC5_CC" \
467 ARMC6_CC="$ARMC6_CC" RUN_ARMCC="$RUN_ARMCC" scripts/output_env.sh
468}
Janos Follathb72c6782016-07-19 14:54:17 +0100469
Gilles Peskine8f073122018-11-27 15:58:47 +0100470component_check_recursion () {
471 msg "test: recursion.pl" # < 1s
472 record_status tests/scripts/recursion.pl library/*.c
473}
Manuel Pégourié-Gonnardea29d152014-11-20 17:32:33 +0100474
Gilles Peskine8f073122018-11-27 15:58:47 +0100475component_check_generated_files () {
476 msg "test: freshness of generated source files" # < 1s
477 record_status tests/scripts/check-generated-files.sh
478}
Manuel Pégourié-Gonnardb3b8e432015-02-13 14:52:19 +0000479
Gilles Peskine8f073122018-11-27 15:58:47 +0100480component_check_doxy_blocks () {
481 msg "test: doxygen markup outside doxygen blocks" # < 1s
482 record_status tests/scripts/check-doxy-blocks.pl
483}
Manuel Pégourié-Gonnardd09a6b52015-04-09 17:19:23 +0200484
Gilles Peskine8f073122018-11-27 15:58:47 +0100485component_check_files () {
486 msg "test: check-files.py" # < 1s
Gilles Peskine8f073122018-11-27 15:58:47 +0100487 record_status tests/scripts/check-files.py
488}
Darryl Greena07039c2018-03-13 16:48:16 +0000489
Gilles Peskine8f073122018-11-27 15:58:47 +0100490component_check_names () {
491 msg "test/build: declared and exported names" # < 3s
Gilles Peskine8f073122018-11-27 15:58:47 +0100492 record_status tests/scripts/check-names.sh
493}
Manuel Pégourié-Gonnarda687baf2015-04-09 11:09:03 +0200494
Gilles Peskine8f073122018-11-27 15:58:47 +0100495component_check_doxygen_warnings () {
496 msg "test: doxygen warnings" # ~ 3s
Gilles Peskine8f073122018-11-27 15:58:47 +0100497 record_status tests/scripts/doxygen.sh
498}
Manuel Pégourié-Gonnard1d552e72016-01-04 16:49:09 +0100499
Gilles Peskine192c72f2017-12-21 15:59:21 +0100500
501
502################################################################
503#### Build and test many configurations and targets
504################################################################
505
Gilles Peskine8f073122018-11-27 15:58:47 +0100506component_test_default_cmake_gcc_asan () {
507 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100508 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
509 make
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100510
Gilles Peskine8f073122018-11-27 15:58:47 +0100511 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
512 make test
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200513
Gilles Peskine8f073122018-11-27 15:58:47 +0100514 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
515 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200516
Gilles Peskine8f073122018-11-27 15:58:47 +0100517 msg "test: compat.sh (ASan build)" # ~ 6 min
518 if_build_succeeded tests/compat.sh
519}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200520
Gilles Peskine782f4112018-11-27 16:11:09 +0100521component_test_ref_configs () {
522 msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
523 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
524 record_status tests/scripts/test-ref-configs.pl
525}
526
Gilles Peskine8f073122018-11-27 15:58:47 +0100527component_test_sslv3 () {
528 msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100529 scripts/config.pl set MBEDTLS_SSL_PROTO_SSL3
530 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
531 make
Simon Butcher3ea7f522016-03-07 23:22:10 +0000532
Gilles Peskine8f073122018-11-27 15:58:47 +0100533 msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
534 make test
Simon Butcher3ea7f522016-03-07 23:22:10 +0000535
Gilles Peskine8f073122018-11-27 15:58:47 +0100536 msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
537 if_build_succeeded tests/compat.sh -m 'tls1 tls1_1 tls1_2 dtls1 dtls1_2'
538 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
Simon Butcher3ea7f522016-03-07 23:22:10 +0000539
Gilles Peskine8f073122018-11-27 15:58:47 +0100540 msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
541 if_build_succeeded tests/ssl-opt.sh
542}
Simon Butcher3ea7f522016-03-07 23:22:10 +0000543
Gilles Peskine8f073122018-11-27 15:58:47 +0100544component_test_no_renegotiation () {
545 msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100546 scripts/config.pl unset MBEDTLS_SSL_RENEGOTIATION
547 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
548 make
Hanno Becker134c2ab2017-10-12 15:29:50 +0100549
Gilles Peskine8f073122018-11-27 15:58:47 +0100550 msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
551 make test
Hanno Becker134c2ab2017-10-12 15:29:50 +0100552
Gilles Peskine8f073122018-11-27 15:58:47 +0100553 msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
554 if_build_succeeded tests/ssl-opt.sh
555}
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +0100556
Gilles Peskine8f073122018-11-27 15:58:47 +0100557component_test_rsa_no_crt () {
558 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100559 scripts/config.pl set MBEDTLS_RSA_NO_CRT
560 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
561 make
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100562
Gilles Peskine8f073122018-11-27 15:58:47 +0100563 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
564 make test
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100565
Gilles Peskine8f073122018-11-27 15:58:47 +0100566 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
567 if_build_succeeded tests/ssl-opt.sh -f RSA
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100568
Gilles Peskine8f073122018-11-27 15:58:47 +0100569 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
570 if_build_succeeded tests/compat.sh -t RSA
571}
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100572
Gilles Peskine8f073122018-11-27 15:58:47 +0100573component_test_small_ssl_out_content_len () {
574 msg "build: small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100575 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 16384
576 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
577 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
578 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000579
Gilles Peskine8f073122018-11-27 15:58:47 +0100580 msg "test: small SSL_OUT_CONTENT_LEN - ssl-opt.sh MFL and large packet tests"
581 if_build_succeeded tests/ssl-opt.sh -f "Max fragment\|Large packet"
582}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000583
Gilles Peskine8f073122018-11-27 15:58:47 +0100584component_test_small_ssl_in_content_len () {
585 msg "build: small SSL_IN_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100586 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 4096
587 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 16384
588 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
589 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000590
Gilles Peskine8f073122018-11-27 15:58:47 +0100591 msg "test: small SSL_IN_CONTENT_LEN - ssl-opt.sh MFL tests"
592 if_build_succeeded tests/ssl-opt.sh -f "Max fragment"
593}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000594
Gilles Peskine8f073122018-11-27 15:58:47 +0100595component_test_small_ssl_dtls_max_buffering () {
596 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0"
Gilles Peskine8f073122018-11-27 15:58:47 +0100597 scripts/config.pl set MBEDTLS_SSL_DTLS_MAX_BUFFERING 1000
598 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
599 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100600
Gilles Peskine8f073122018-11-27 15:58:47 +0100601 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0 - ssl-opt.sh specific reordering test"
602 if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer out-of-order hs msg before reassembling next, free buffered msg"
603}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100604
Gilles Peskine8f073122018-11-27 15:58:47 +0100605component_test_small_mbedtls_ssl_dtls_max_buffering () {
606 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1"
Gilles Peskine8f073122018-11-27 15:58:47 +0100607 scripts/config.pl set MBEDTLS_SSL_DTLS_MAX_BUFFERING 240
608 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
609 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100610
Gilles Peskine8f073122018-11-27 15:58:47 +0100611 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1 - ssl-opt.sh specific reordering test"
612 if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer encrypted Finished message, drop for fragmented NewSessionTicket"
613}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100614
Gilles Peskine8f073122018-11-27 15:58:47 +0100615component_test_full_cmake_clang () {
616 msg "build: cmake, full config, clang" # ~ 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100617 scripts/config.pl full
618 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
619 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check -D ENABLE_TESTING=On .
620 make
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100621
Gilles Peskine8f073122018-11-27 15:58:47 +0100622 msg "test: main suites (full config)" # ~ 5s
623 make test
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200624
Gilles Peskine8f073122018-11-27 15:58:47 +0100625 msg "test: ssl-opt.sh default, ECJPAKE, SSL async (full config)" # ~ 1s
626 if_build_succeeded tests/ssl-opt.sh -f 'Default\|ECJPAKE\|SSL async private'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200627
Gilles Peskine8f073122018-11-27 15:58:47 +0100628 msg "test: compat.sh RC4, DES & NULL (full config)" # ~ 2 min
629 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'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200630
Gilles Peskine8f073122018-11-27 15:58:47 +0100631 msg "test: compat.sh ARIA + ChachaPoly"
632 if_build_succeeded env OPENSSL_CMD="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
633}
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100634
Gilles Peskine8f073122018-11-27 15:58:47 +0100635component_build_deprecated () {
636 msg "build: make, full config + DEPRECATED_WARNING, gcc -O" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100637 scripts/config.pl full
638 scripts/config.pl set MBEDTLS_DEPRECATED_WARNING
639 # Build with -O -Wextra to catch a maximum of issues.
640 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra' lib programs
641 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
Gilles Peskineb4ef45b2018-03-01 22:23:50 +0100642
Gilles Peskine8f073122018-11-27 15:58:47 +0100643 msg "build: make, full config + DEPRECATED_REMOVED, clang -O" # ~ 30s
644 # No cleanup, just tweak the configuration and rebuild
645 make clean
646 scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
647 scripts/config.pl set MBEDTLS_DEPRECATED_REMOVED
648 # Build with -O -Wextra to catch a maximum of issues.
649 make CC=clang CFLAGS='-O -Werror -Wall -Wextra' lib programs
650 make CC=clang CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
651}
Gilles Peskine0afe6242018-02-21 19:28:12 +0100652
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200653
Gilles Peskine8f073122018-11-27 15:58:47 +0100654component_test_depends_curves () {
655 msg "test/build: curves.pl (gcc)" # ~ 4 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100656 record_status tests/scripts/curves.pl
657}
Manuel Pégourié-Gonnard1fe6bb92017-06-06 11:36:16 +0200658
Gilles Peskine8f073122018-11-27 15:58:47 +0100659component_test_depends_hashes () {
660 msg "test/build: depends-hashes.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100661 record_status tests/scripts/depends-hashes.pl
662}
Manuel Pégourié-Gonnard43be6cd2017-06-20 09:53:42 +0200663
Gilles Peskine8f073122018-11-27 15:58:47 +0100664component_test_depends_pkalgs () {
665 msg "test/build: depends-pkalgs.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100666 record_status tests/scripts/depends-pkalgs.pl
667}
Manuel Pégourié-Gonnard503a5ef2015-10-23 09:04:45 +0200668
Gilles Peskine8f073122018-11-27 15:58:47 +0100669component_build_key_exchanges () {
670 msg "test/build: key-exchanges (gcc)" # ~ 1 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100671 record_status tests/scripts/key-exchanges.pl
672}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100673
Gilles Peskine8f073122018-11-27 15:58:47 +0100674component_build_default_make_gcc_and_cxx () {
675 msg "build: Unix make, -Os (gcc)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100676 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400677
Gilles Peskine8f073122018-11-27 15:58:47 +0100678 msg "test: verify header list in cpp_dummy_build.cpp"
679 record_status check_headers_in_cpp
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400680
Gilles Peskine8f073122018-11-27 15:58:47 +0100681 msg "build: Unix make, incremental g++"
682 make TEST_CPP=1
683}
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +0000684
Gilles Peskineb28636b2019-01-02 19:06:24 +0100685component_test_check_params_without_platform () {
686 msg "build+test: MBEDTLS_CHECK_PARAMS without MBEDTLS_PLATFORM_C"
687 scripts/config.pl full # includes CHECK_PARAMS
688 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
689 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
690 scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
691 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
692 scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
693 scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
694 scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
695 scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
696 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
697 scripts/config.pl unset MBEDTLS_PLATFORM_C
698 make CC=gcc CFLAGS='-Werror -O1' all test
699}
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +0200700
Gilles Peskineb28636b2019-01-02 19:06:24 +0100701component_test_check_params_silent () {
702 msg "build+test: MBEDTLS_CHECK_PARAMS with alternative MBEDTLS_PARAM_FAILED()"
703 scripts/config.pl full # includes CHECK_PARAMS
704 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
705 sed -i 's/.*\(#define MBEDTLS_PARAM_FAILED( cond )\).*/\1/' "$CONFIG_H"
706 make CC=gcc CFLAGS='-Werror -O1' all test
707}
Hanno Becker5175ac62017-09-18 15:36:25 +0100708
Gilles Peskine8f073122018-11-27 15:58:47 +0100709component_test_no_platform () {
710 # Full configuration build, without platform support, file IO and net sockets.
711 # This should catch missing mbedtls_printf definitions, and by disabling file
712 # IO, it should catch missing '#include <stdio.h>'
713 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100714 scripts/config.pl full
715 scripts/config.pl unset MBEDTLS_PLATFORM_C
716 scripts/config.pl unset MBEDTLS_NET_C
717 scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
718 scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
719 scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
720 scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
721 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
722 scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
723 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
724 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
725 scripts/config.pl unset MBEDTLS_FS_IO
726 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
727 # to re-enable platform integration features otherwise disabled in C99 builds
728 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -O0 -D_DEFAULT_SOURCE' lib programs
729 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0' test
730}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200731
Gilles Peskine8f073122018-11-27 15:58:47 +0100732component_build_no_std_function () {
733 # catch compile bugs in _uninit functions
734 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100735 scripts/config.pl full
736 scripts/config.pl set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
737 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
738 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
739}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200740
Gilles Peskine8f073122018-11-27 15:58:47 +0100741component_build_no_ssl_srv () {
742 msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100743 scripts/config.pl full
744 scripts/config.pl unset MBEDTLS_SSL_SRV_C
745 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
746}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200747
Gilles Peskine8f073122018-11-27 15:58:47 +0100748component_build_no_ssl_cli () {
749 msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100750 scripts/config.pl full
751 scripts/config.pl unset MBEDTLS_SSL_CLI_C
752 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
753}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000754
Gilles Peskine8f073122018-11-27 15:58:47 +0100755component_build_no_sockets () {
756 # Note, C99 compliance can also be tested with the sockets support disabled,
757 # as that requires a POSIX platform (which isn't the same as C99).
758 msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100759 scripts/config.pl full
760 scripts/config.pl unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
761 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
762 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0 -std=c99 -pedantic' lib
763}
Hanno Becker5175ac62017-09-18 15:36:25 +0100764
Gilles Peskine8f073122018-11-27 15:58:47 +0100765component_test_no_max_fragment_length () {
766 # Run max fragment length tests with MFL disabled
767 msg "build: default config except MFL extension (ASan build)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100768 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
769 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
770 make
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000771
Gilles Peskine8f073122018-11-27 15:58:47 +0100772 msg "test: ssl-opt.sh, MFL-related tests"
773 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length"
774}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000775
Gilles Peskine8f073122018-11-27 15:58:47 +0100776component_test_no_max_fragment_length_small_ssl_out_content_len () {
777 msg "build: no MFL extension, small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100778 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
779 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 16384
780 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
781 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
782 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000783
Gilles Peskine8f073122018-11-27 15:58:47 +0100784 msg "test: MFL tests (disabled MFL extension case) & large packet tests"
785 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length\|Large buffer"
786}
Janos Follath06c54002016-06-09 13:57:40 +0100787
Gilles Peskine8f073122018-11-27 15:58:47 +0100788component_test_null_entropy () {
789 msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100790 scripts/config.pl set MBEDTLS_TEST_NULL_ENTROPY
791 scripts/config.pl set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
792 scripts/config.pl set MBEDTLS_ENTROPY_C
793 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
794 scripts/config.pl unset MBEDTLS_ENTROPY_HARDWARE_ALT
795 scripts/config.pl unset MBEDTLS_HAVEGE_C
Gilles Peskine5fa32a72019-01-06 19:48:30 +0000796 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan -D UNSAFE_BUILD=ON .
Gilles Peskine8f073122018-11-27 15:58:47 +0100797 make
Janos Follath06c54002016-06-09 13:57:40 +0100798
Gilles Peskine8f073122018-11-27 15:58:47 +0100799 msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)"
800 make test
801}
Hanno Beckere5fecec2018-10-11 11:02:52 +0100802
Gilles Peskine8f073122018-11-27 15:58:47 +0100803component_test_platform_calloc_macro () {
804 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100805 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
806 scripts/config.pl set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
807 scripts/config.pl set MBEDTLS_PLATFORM_FREE_MACRO free
808 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
809 make
Hanno Beckere5fecec2018-10-11 11:02:52 +0100810
Gilles Peskine8f073122018-11-27 15:58:47 +0100811 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
812 make test
813}
Hanno Becker83ebf782017-07-07 12:29:15 +0100814
Gilles Peskine8f073122018-11-27 15:58:47 +0100815component_test_aes_fewer_tables () {
816 msg "build: default config with AES_FEWER_TABLES enabled"
Gilles Peskine8f073122018-11-27 15:58:47 +0100817 scripts/config.pl set MBEDTLS_AES_FEWER_TABLES
818 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +0100819
Gilles Peskine8f073122018-11-27 15:58:47 +0100820 msg "test: AES_FEWER_TABLES"
821 make test
822}
Hanno Becker83ebf782017-07-07 12:29:15 +0100823
Gilles Peskine8f073122018-11-27 15:58:47 +0100824component_test_aes_rom_tables () {
825 msg "build: default config with AES_ROM_TABLES enabled"
Gilles Peskine8f073122018-11-27 15:58:47 +0100826 scripts/config.pl set MBEDTLS_AES_ROM_TABLES
827 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +0100828
Gilles Peskine8f073122018-11-27 15:58:47 +0100829 msg "test: AES_ROM_TABLES"
830 make test
831}
Hanno Becker83ebf782017-07-07 12:29:15 +0100832
Gilles Peskine8f073122018-11-27 15:58:47 +0100833component_test_aes_fewer_tables_and_rom_tables () {
834 msg "build: default config with AES_ROM_TABLES and AES_FEWER_TABLES enabled"
Gilles Peskine8f073122018-11-27 15:58:47 +0100835 scripts/config.pl set MBEDTLS_AES_FEWER_TABLES
836 scripts/config.pl set MBEDTLS_AES_ROM_TABLES
837 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +0100838
Gilles Peskine8f073122018-11-27 15:58:47 +0100839 msg "test: AES_FEWER_TABLES + AES_ROM_TABLES"
840 make test
841}
842
843component_test_make_shared () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100844 msg "build/test: make shared" # ~ 40s
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100845 make SHARED=1 all check
Gilles Peskine8f073122018-11-27 15:58:47 +0100846}
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +0200847
Gilles Peskine8f073122018-11-27 15:58:47 +0100848component_test_m32_o0 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100849 # Build once with -O0, to compile out the i386 specific inline assembly
850 msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
Simon Butcher7a6da6e2018-06-27 21:52:54 +0100851 scripts/config.pl full
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100852 make CC=gcc CFLAGS='-O0 -Werror -Wall -Wextra -m32 -fsanitize=address'
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +0100853
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100854 msg "test: i386, make, gcc -O0 (ASan build)"
855 make test
Gilles Peskine8f073122018-11-27 15:58:47 +0100856}
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100857
Gilles Peskine8f073122018-11-27 15:58:47 +0100858component_test_m32_o1 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100859 # Build again with -O1, to compile in the i386 specific inline assembly
860 msg "build: i386, make, gcc -O1 (ASan build)" # ~ 30s
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100861 scripts/config.pl full
862 make CC=gcc CFLAGS='-O1 -Werror -Wall -Wextra -m32 -fsanitize=address'
863
864 msg "test: i386, make, gcc -O1 (ASan build)"
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +0100865 make test
Gilles Peskine8f073122018-11-27 15:58:47 +0100866}
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +0100867
Gilles Peskine8f073122018-11-27 15:58:47 +0100868component_test_mx32 () {
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +0100869 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
Simon Butcher7a6da6e2018-06-27 21:52:54 +0100870 scripts/config.pl full
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +0100871 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32'
872
873 msg "test: 64-bit ILP32, make, gcc"
874 make test
Gilles Peskine8f073122018-11-27 15:58:47 +0100875}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000876
Gilles Peskine8f073122018-11-27 15:58:47 +0100877component_test_have_int32 () {
878 msg "build: gcc, force 32-bit bignum limbs"
Gilles Peskine8f073122018-11-27 15:58:47 +0100879 scripts/config.pl unset MBEDTLS_HAVE_ASM
880 scripts/config.pl unset MBEDTLS_AESNI_C
881 scripts/config.pl unset MBEDTLS_PADLOCK_C
882 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +0100883
Gilles Peskine8f073122018-11-27 15:58:47 +0100884 msg "test: gcc, force 32-bit bignum limbs"
885 make test
886}
Andres Amaya Garciafe843a32017-07-20 13:21:34 +0100887
Gilles Peskine8f073122018-11-27 15:58:47 +0100888component_test_have_int64 () {
889 msg "build: gcc, force 64-bit bignum limbs"
Gilles Peskine8f073122018-11-27 15:58:47 +0100890 scripts/config.pl unset MBEDTLS_HAVE_ASM
891 scripts/config.pl unset MBEDTLS_AESNI_C
892 scripts/config.pl unset MBEDTLS_PADLOCK_C
893 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
Gilles Peskine14c3c062018-01-29 21:25:12 +0100894
Gilles Peskine8f073122018-11-27 15:58:47 +0100895 msg "test: gcc, force 64-bit bignum limbs"
896 make test
897}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000898
Gilles Peskine8f073122018-11-27 15:58:47 +0100899component_test_no_udbl_division () {
900 msg "build: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +0100901 scripts/config.pl full
902 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
903 scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
904 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200905
Gilles Peskine8f073122018-11-27 15:58:47 +0100906 msg "test: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
907 make test
908}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200909
Gilles Peskine8f073122018-11-27 15:58:47 +0100910component_test_no_64bit_multiplication () {
911 msg "build: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +0100912 scripts/config.pl full
913 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
914 scripts/config.pl set MBEDTLS_NO_64BIT_MULTIPLICATION
915 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200916
Gilles Peskine8f073122018-11-27 15:58:47 +0100917 msg "test: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
918 make test
919}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200920
Gilles Peskine8f073122018-11-27 15:58:47 +0100921component_build_arm_none_eabi_gcc () {
922 msg "build: arm-none-eabi-gcc, make" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +0100923 scripts/config.pl full
924 scripts/config.pl unset MBEDTLS_NET_C
925 scripts/config.pl unset MBEDTLS_TIMING_C
926 scripts/config.pl unset MBEDTLS_FS_IO
927 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
928 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
929 # following things are not in the default config
930 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
931 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
932 scripts/config.pl unset MBEDTLS_THREADING_C
933 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
934 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
935 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
936}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200937
Gilles Peskine8f073122018-11-27 15:58:47 +0100938component_build_arm_none_eabi_gcc_no_udbl_division () {
939 msg "build: arm-none-eabi-gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +0100940 scripts/config.pl full
941 scripts/config.pl unset MBEDTLS_NET_C
942 scripts/config.pl unset MBEDTLS_TIMING_C
943 scripts/config.pl unset MBEDTLS_FS_IO
944 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
945 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
946 # following things are not in the default config
947 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
948 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
949 scripts/config.pl unset MBEDTLS_THREADING_C
950 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
951 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
952 scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
953 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
954 echo "Checking that software 64-bit division is not required"
955 if_build_succeeded not grep __aeabi_uldiv library/*.o
956}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200957
Gilles Peskine8f073122018-11-27 15:58:47 +0100958component_build_arm_none_eabi_gcc_no_64bit_multiplication () {
959 msg "build: arm-none-eabi-gcc MBEDTLS_NO_64BIT_MULTIPLICATION, make" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +0100960 scripts/config.pl full
961 scripts/config.pl unset MBEDTLS_NET_C
962 scripts/config.pl unset MBEDTLS_TIMING_C
963 scripts/config.pl unset MBEDTLS_FS_IO
964 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
965 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
966 # following things are not in the default config
967 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
968 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
969 scripts/config.pl unset MBEDTLS_THREADING_C
970 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
971 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
972 scripts/config.pl set MBEDTLS_NO_64BIT_MULTIPLICATION
973 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -O1 -march=armv6-m -mthumb' lib
974 echo "Checking that software 64-bit multiplication is not required"
975 if_build_succeeded not grep __aeabi_lmul library/*.o
976}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200977
Gilles Peskine8f073122018-11-27 15:58:47 +0100978component_build_armcc () {
979 msg "build: ARM Compiler 5, make"
Gilles Peskine8f073122018-11-27 15:58:47 +0100980 scripts/config.pl full
981 scripts/config.pl unset MBEDTLS_NET_C
982 scripts/config.pl unset MBEDTLS_TIMING_C
983 scripts/config.pl unset MBEDTLS_FS_IO
984 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
985 scripts/config.pl unset MBEDTLS_HAVE_TIME
986 scripts/config.pl unset MBEDTLS_HAVE_TIME_DATE
987 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
988 # following things are not in the default config
989 scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
990 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
991 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
992 scripts/config.pl unset MBEDTLS_THREADING_C
993 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
994 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
995 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT # depends on MBEDTLS_HAVE_TIME
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000996
Gilles Peskine8f073122018-11-27 15:58:47 +0100997 if [ $RUN_ARMCC -ne 0 ]; then
998 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
999 make clean
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001000
Gilles Peskine8f073122018-11-27 15:58:47 +01001001 # ARM Compiler 6 - Target ARMv7-A
1002 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-a"
Gilles Peskineed942f82017-06-08 15:19:20 +02001003
Gilles Peskine8f073122018-11-27 15:58:47 +01001004 # ARM Compiler 6 - Target ARMv7-M
1005 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m"
Andres AG87bb5772016-09-27 15:05:15 +01001006
Gilles Peskine8f073122018-11-27 15:58:47 +01001007 # ARM Compiler 6 - Target ARMv8-A - AArch32
1008 armc6_build_test "--target=arm-arm-none-eabi -march=armv8.2-a"
Andres AG87bb5772016-09-27 15:05:15 +01001009
Gilles Peskine8f073122018-11-27 15:58:47 +01001010 # ARM Compiler 6 - Target ARMv8-M
1011 armc6_build_test "--target=arm-arm-none-eabi -march=armv8-m.main"
Simon Butcher940737f2017-07-23 13:42:36 +02001012
Gilles Peskine8f073122018-11-27 15:58:47 +01001013 # ARM Compiler 6 - Target ARMv8-A - AArch64
1014 armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a"
1015 fi
1016}
Simon Butcher940737f2017-07-23 13:42:36 +02001017
Gilles Peskine8f073122018-11-27 15:58:47 +01001018component_test_allow_sha1 () {
1019 msg "build: allow SHA1 in certificates by default"
Gilles Peskine8f073122018-11-27 15:58:47 +01001020 scripts/config.pl set MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
1021 make CFLAGS='-Werror -Wall -Wextra'
1022 msg "test: allow SHA1 in certificates by default"
1023 make test
1024 if_build_succeeded tests/ssl-opt.sh -f SHA-1
1025}
Simon Butcher940737f2017-07-23 13:42:36 +02001026
Gilles Peskine8f073122018-11-27 15:58:47 +01001027component_build_mingw () {
1028 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +01001029 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
Gilles Peskine2a458da2017-05-12 15:26:58 +02001030
Gilles Peskine8f073122018-11-27 15:58:47 +01001031 # note Make tests only builds the tests, but doesn't run them
1032 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror' WINDOWS_BUILD=1 tests
1033 make WINDOWS_BUILD=1 clean
Hanno Beckere963efa2018-01-03 10:03:43 +00001034
Gilles Peskine8f073122018-11-27 15:58:47 +01001035 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
1036 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
1037 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
1038 make WINDOWS_BUILD=1 clean
1039}
Simon Butcher002bc622016-11-17 09:27:45 +00001040
Gilles Peskine8f073122018-11-27 15:58:47 +01001041component_test_memsan () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001042 msg "build: MSan (clang)" # ~ 1 min 20s
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001043 scripts/config.pl unset MBEDTLS_AESNI_C # memsan doesn't grok asm
1044 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
1045 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +02001046
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001047 msg "test: main suites (MSan)" # ~ 10s
1048 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001049
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001050 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
Gilles Peskine7c652162017-12-11 00:01:40 +01001051 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001052
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001053 # Optional part(s)
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001054
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001055 if [ "$MEMORY" -gt 0 ]; then
1056 msg "test: compat.sh (MSan)" # ~ 6 min 20s
Gilles Peskine7c652162017-12-11 00:01:40 +01001057 if_build_succeeded tests/compat.sh
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001058 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001059}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001060
Gilles Peskine8f073122018-11-27 15:58:47 +01001061component_test_memcheck () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001062 msg "build: Release (clang)"
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001063 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
1064 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001065
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001066 msg "test: main suites valgrind (Release)"
1067 make memcheck
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001068
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001069 # Optional part(s)
1070 # Currently broken, programs don't seem to receive signals
1071 # under valgrind on OS X
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001072
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001073 if [ "$MEMORY" -gt 0 ]; then
1074 msg "test: ssl-opt.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +01001075 if_build_succeeded tests/ssl-opt.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001076 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001077
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001078 if [ "$MEMORY" -gt 1 ]; then
1079 msg "test: compat.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +01001080 if_build_succeeded tests/compat.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001081 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001082}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001083
Gilles Peskine8f073122018-11-27 15:58:47 +01001084component_test_cmake_out_of_source () {
1085 msg "build: cmake 'out-of-source' build"
Gilles Peskine8f073122018-11-27 15:58:47 +01001086 MBEDTLS_ROOT_DIR="$PWD"
1087 mkdir "$OUT_OF_SOURCE_DIR"
1088 cd "$OUT_OF_SOURCE_DIR"
1089 cmake "$MBEDTLS_ROOT_DIR"
1090 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001091
Gilles Peskine8f073122018-11-27 15:58:47 +01001092 msg "test: cmake 'out-of-source' build"
1093 make test
1094 # Test an SSL option that requires an auxiliary script in test/scripts/.
1095 # Also ensure that there are no error messages such as
1096 # "No such file or directory", which would indicate that some required
1097 # file is missing (ssl-opt.sh tolerates the absence of some files so
1098 # may exit with status 0 but emit errors).
1099 if_build_succeeded ./tests/ssl-opt.sh -f 'Fallback SCSV: beginning of list' 2>ssl-opt.err
1100 if [ -s ssl-opt.err ]; then
1101 cat ssl-opt.err >&2
1102 record_status [ ! -s ssl-opt.err ]
1103 rm ssl-opt.err
1104 fi
1105 cd "$MBEDTLS_ROOT_DIR"
1106 rm -rf "$OUT_OF_SOURCE_DIR"
1107 unset MBEDTLS_ROOT_DIR
1108}
Andres AGdc192212016-08-31 17:33:13 +01001109
Gilles Peskine8f073122018-11-27 15:58:47 +01001110component_test_zeroize () {
1111 # Test that the function mbedtls_platform_zeroize() is not optimized away by
1112 # different combinations of compilers and optimization flags by using an
1113 # auxiliary GDB script. Unfortunately, GDB does not return error values to the
1114 # system in all cases that the script fails, so we must manually search the
1115 # output to check whether the pass string is present and no failure strings
1116 # were printed.
Gilles Peskine4976e822019-01-06 19:52:22 +00001117
1118 # Don't try to disable ASLR. We don't care about ASLR here. We do care
1119 # about a spurious message if Gdb tries and fails, so suppress that.
1120 gdb_disable_aslr=
1121 if [ -z "$(gdb -batch -nw -ex 'set disable-randomization off' 2>&1)" ]; then
1122 gdb_disable_aslr='set disable-randomization off'
1123 fi
1124
Gilles Peskine8f073122018-11-27 15:58:47 +01001125 for optimization_flag in -O2 -O3 -Ofast -Os; do
Gilles Peskine55f7c942019-01-09 22:28:21 +01001126 for compiler in clang gcc; do
1127 msg "test: $compiler $optimization_flag, mbedtls_platform_zeroize()"
1128 make programs CC="$compiler" DEBUG=1 CFLAGS="$optimization_flag"
Gilles Peskine4976e822019-01-06 19:52:22 +00001129 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 +01001130 if_build_succeeded grep "The buffer was correctly zeroized" test_zeroize.log
1131 if_build_succeeded not grep -i "error" test_zeroize.log
1132 rm -f test_zeroize.log
1133 make clean
1134 done
Andres Amaya Garcia29673812017-10-25 10:35:51 +01001135 done
Gilles Peskine4976e822019-01-06 19:52:22 +00001136
1137 unset gdb_disable_aslr
Gilles Peskine8f073122018-11-27 15:58:47 +01001138}
Andres Amaya Garciad0d7bf62017-10-25 09:01:31 +01001139
Gilles Peskine8f073122018-11-27 15:58:47 +01001140component_check_python_files () {
1141 msg "Lint: Python scripts"
1142 record_status tests/scripts/check-python-files.sh
1143}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001144
Gilles Peskine8f073122018-11-27 15:58:47 +01001145component_check_generate_test_code () {
1146 msg "uint test: generate_test_code.py"
1147 record_status ./tests/scripts/test_generate_test_code.py
1148}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001149
1150################################################################
1151#### Termination
1152################################################################
1153
Gilles Peskine8f073122018-11-27 15:58:47 +01001154post_report () {
1155 msg "Done, cleaning up"
1156 cleanup
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001157
Gilles Peskine8f073122018-11-27 15:58:47 +01001158 final_report
1159}
1160
1161
1162
1163################################################################
1164#### Run all the things
1165################################################################
1166
Gilles Peskine92525112018-11-27 18:15:35 +01001167run_all_components () {
1168 # Small things
1169 run_component component_check_recursion
1170 run_component component_check_generated_files
1171 run_component component_check_doxy_blocks
1172 run_component component_check_files
1173 run_component component_check_names
1174 run_component component_check_doxygen_warnings
1175
1176 # Test many different configurations
1177 run_component component_test_default_cmake_gcc_asan
1178 run_component component_test_ref_configs
1179 run_component component_test_sslv3
1180 run_component component_test_no_renegotiation
1181 run_component component_test_rsa_no_crt
1182 run_component component_test_small_ssl_out_content_len
1183 run_component component_test_small_ssl_in_content_len
1184 run_component component_test_small_ssl_dtls_max_buffering
1185 run_component component_test_small_mbedtls_ssl_dtls_max_buffering
1186 run_component component_test_full_cmake_clang
1187 run_component component_build_deprecated
1188 run_component component_test_depends_curves
1189 run_component component_test_depends_hashes
1190 run_component component_test_depends_pkalgs
1191 run_component component_build_key_exchanges
1192 run_component component_build_default_make_gcc_and_cxx
Gilles Peskineb28636b2019-01-02 19:06:24 +01001193 run_component component_test_check_params_without_platform
1194 run_component component_test_check_params_silent
Gilles Peskine92525112018-11-27 18:15:35 +01001195 run_component component_test_no_platform
1196 run_component component_build_no_std_function
1197 run_component component_build_no_ssl_srv
1198 run_component component_build_no_ssl_cli
1199 run_component component_build_no_sockets
1200 run_component component_test_no_max_fragment_length
1201 run_component component_test_no_max_fragment_length_small_ssl_out_content_len
1202 run_component component_test_null_entropy
1203 run_component component_test_platform_calloc_macro
1204 run_component component_test_aes_fewer_tables
1205 run_component component_test_aes_rom_tables
1206 run_component component_test_aes_fewer_tables_and_rom_tables
Gilles Peskinea16c2b12019-01-06 19:58:02 +00001207 run_component component_test_make_shared
1208 case $(uname -m) in
1209 amd64|x86_64)
1210 run_component component_test_m32_o0
1211 run_component component_test_m32_o1
1212 run_component component_test_mx32
1213 ;;
1214 esac
Gilles Peskine92525112018-11-27 18:15:35 +01001215 run_component component_test_have_int32
1216 run_component component_test_have_int64
1217 run_component component_test_no_udbl_division
1218 run_component component_test_no_64bit_multiplication
1219 run_component component_build_arm_none_eabi_gcc
1220 run_component component_build_arm_none_eabi_gcc_no_udbl_division
1221 run_component component_build_arm_none_eabi_gcc_no_64bit_multiplication
1222 run_component component_build_armcc
1223 run_component component_test_allow_sha1
1224 run_component component_build_mingw
Gilles Peskinea16c2b12019-01-06 19:58:02 +00001225 run_component component_test_memsan
1226 run_component component_test_memcheck
Gilles Peskine92525112018-11-27 18:15:35 +01001227 run_component component_test_cmake_out_of_source
1228
1229 # More small things
1230 run_component component_test_zeroize
1231 run_component component_check_python_files
1232 run_component component_check_generate_test_code
1233}
1234
Gilles Peskinee48351a2018-11-27 16:06:30 +01001235# Run one component and clean up afterwards.
Gilles Peskine8f073122018-11-27 15:58:47 +01001236run_component () {
Gilles Peskine81b96ed2018-11-27 21:37:53 +01001237 if [ $ALL_EXCEPT -ne 0 ] && component_is_excluded "$1"; then
1238 return
1239 fi
Gilles Peskine608953e2019-01-02 18:57:02 +01001240 # Back up the configuration in case the component modifies it.
1241 # The cleanup function will restore it.
1242 cp -p "$CONFIG_H" "$CONFIG_BAK"
Gilles Peskineffcdeff2018-12-04 12:49:28 +01001243 current_component="$1"
Gilles Peskine8f073122018-11-27 15:58:47 +01001244 "$@"
Gilles Peskinee48351a2018-11-27 16:06:30 +01001245 cleanup
Gilles Peskine8f073122018-11-27 15:58:47 +01001246}
1247
1248# Preliminary setup
1249pre_check_environment
1250pre_initialize_variables
1251pre_parse_command_line "$@"
Gilles Peskine348fb9a2018-11-27 17:04:29 +01001252
1253case "$INTROSPECTION_MODE" in
1254 list_components)
1255 components=
1256 newline='
1257'
1258 run_component () {
Gilles Peskine92525112018-11-27 18:15:35 +01001259 components="${components}${newline}${1#component_}"
Gilles Peskine348fb9a2018-11-27 17:04:29 +01001260 }
1261 ;;
1262
1263 *)
1264 pre_check_git
1265 build_status=0
1266 if [ $KEEP_GOING -eq 1 ]; then
1267 pre_setup_keep_going
1268 else
1269 record_status () {
1270 "$@"
1271 }
1272 fi
1273 pre_print_configuration
1274 pre_check_tools
1275 pre_print_tools
1276 cleanup
1277 ;;
1278esac
Gilles Peskine8f073122018-11-27 15:58:47 +01001279
Gilles Peskine81b96ed2018-11-27 21:37:53 +01001280if [ -n "$COMPONENTS" ] && [ $ALL_EXCEPT -eq 0 ]; then
Gilles Peskine92525112018-11-27 18:15:35 +01001281 for component in $COMPONENTS; do
1282 run_component "component_$component"
1283 done
1284else
1285 run_all_components
Gilles Peskine8f073122018-11-27 15:58:47 +01001286fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001287
1288# We're done.
Gilles Peskine348fb9a2018-11-27 17:04:29 +01001289case "$INTROSPECTION_MODE" in
1290 list_components)
1291 echo "$components" | sort
1292 ;;
1293 *)
1294 post_report
1295 ;;
1296esac