blob: cc5ab95699324829ba52cd5a23ad0c68cc52e07f [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)
38# * arm-gcc and mingw-gcc
39# * ArmCC 5 and ArmCC 6, unless invoked with --no-armcc
40# * Yotta build dependencies, unless invoked with --no-yotta
41# * 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#
58# The tests are roughly in order from fastest to slowest. This doesn't
59# have to be exact, but in general you should add slower tests towards
60# the end and fast checks near the beginning.
61#
62# Sanity checks have the following form:
63# 1. msg "short description of what is about to be done"
64# 2. run sanity check (failure stops the script)
65#
66# Build or build-and-test steps have the following form:
67# 1. msg "short description of what is about to be done"
68# 2. cleanup
69# 3. preparation (config.pl, cmake, ...) (failure stops the script)
70# 4. make
71# 5. Run tests if relevant. All tests must be prefixed with
72# if_build_successful for the sake of --keep-going.
73
74
75
76################################################################
77#### Initialization and command line parsing
78################################################################
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010079
SimonB2e23c822016-04-16 21:54:39 +010080# Abort on errors (and uninitialised variables)
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010081set -eu
82
Gilles Peskine57db6ff2019-01-08 22:04:31 +010083pre_check_environment () {
Gilles Peskine770ad7e2019-01-08 23:19:08 +010084 if [ -d library -a -d include -a -d tests ]; then :; else
Gilles Peskine57db6ff2019-01-08 22:04:31 +010085 echo "Must be run from mbed TLS root" >&2
86 exit 1
87 fi
88}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010089
Gilles Peskine57db6ff2019-01-08 22:04:31 +010090pre_initialize_variables () {
91 CONFIG_H='include/mbedtls/config.h'
92 CONFIG_BAK="$CONFIG_H.bak"
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +020093
Gilles Peskine6e984232018-11-27 21:37:53 +010094 ALL_EXCEPT=0
Gilles Peskine57db6ff2019-01-08 22:04:31 +010095 MEMORY=0
96 FORCE=0
97 KEEP_GOING=0
98 RUN_ARMCC=1
99 YOTTA=1
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100100
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100101 # Default commands, can be overriden by the environment
102 : ${OPENSSL:="openssl"}
103 : ${OPENSSL_LEGACY:="$OPENSSL"}
104 : ${GNUTLS_CLI:="gnutls-cli"}
105 : ${GNUTLS_SERV:="gnutls-serv"}
106 : ${GNUTLS_LEGACY_CLI:="$GNUTLS_CLI"}
107 : ${GNUTLS_LEGACY_SERV:="$GNUTLS_SERV"}
108 : ${OUT_OF_SOURCE_DIR:=./mbedtls_out_of_source_build}
109 : ${ARMC5_BIN_DIR:=/usr/bin}
110 : ${ARMC6_BIN_DIR:=/usr/bin}
Andres AGdc192212016-08-31 17:33:13 +0100111
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100112 # if MAKEFLAGS is not set add the -j option to speed up invocations of make
113 if [ -n "${MAKEFLAGS+set}" ]; then
114 export MAKEFLAGS="-j"
115 fi
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100116
117 # Gather the list of available components. These are the functions
118 # defined in this script whose name starts with "component_".
119 # Parse the script with sed, because in sh there is no way to list
120 # defined functions.
121 ALL_COMPONENTS=$(sed -n 's/^ *component_\([0-9A-Z_a-z]*\) *().*/\1/p' <"$0")
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100122}
Andres AG38495a32016-07-12 16:54:33 +0100123
Gilles Peskine6e984232018-11-27 21:37:53 +0100124# Test whether $1 is excluded via $COMPONENTS (a space-separated list of
125# wildcard patterns).
126is_component_excluded()
127{
128 set -f
129 for pattern in $COMPONENTS; do
130 set +f
131 case ${1#component_} in $pattern) return 0;; esac
132 done
133 set +f
134 return 1
135}
136
Simon Butcher41eeccf2016-09-07 00:07:09 +0100137usage()
SimonB2e23c822016-04-16 21:54:39 +0100138{
Gilles Peskine709346a2017-12-10 23:43:39 +0100139 cat <<EOF
Gilles Peskine91bd8b72019-01-08 23:01:34 +0100140Usage: $0 [OPTION]... [COMPONENT]...
141Run mbedtls release validation tests.
142By default, run all tests. With one or more COMPONENT, run only those.
143
144Special options:
145 -h|--help Print this help and exit.
Gilles Peskine709346a2017-12-10 23:43:39 +0100146
147General options:
148 -f|--force Force the tests to overwrite any modified files.
Gilles Peskine7c652162017-12-11 00:01:40 +0100149 -k|--keep-going Run all tests and report errors at the end.
Gilles Peskine709346a2017-12-10 23:43:39 +0100150 -m|--memory Additional optional memory tests.
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100151 --armcc Run ARM Compiler builds (on by default).
Gilles Peskine6e984232018-11-27 21:37:53 +0100152 --except If some components are passed on the command line,
153 run all the tests except for these components. In
154 this mode, you can pass shell wildcard patterns as
155 component names, e.g. "$0 --except 'test_*'" to
156 exclude all components that run tests.
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100157 --no-armcc Skip ARM Compiler builds.
Gilles Peskine19ceb712018-03-21 08:40:26 +0100158 --no-force Refuse to overwrite modified files (default).
159 --no-keep-going Stop at the first error (default).
160 --no-memory No additional memory tests (default).
Gilles Peskine2a22a802017-12-21 15:19:00 +0100161 --no-yotta Skip yotta module build.
Gilles Peskine709346a2017-12-10 23:43:39 +0100162 --out-of-source-dir=<path> Directory used for CMake out-of-source build tests.
Gilles Peskine19ceb712018-03-21 08:40:26 +0100163 --random-seed Use a random seed value for randomized tests (default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100164 -r|--release-test Run this script in release mode. This fixes the seed value to 1.
165 -s|--seed Integer seed value to use for this test run.
Gilles Peskine2a22a802017-12-21 15:19:00 +0100166 --yotta Build yotta module (on by default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100167
168Tool path options:
169 --armc5-bin-dir=<ARMC5_bin_dir_path> ARM Compiler 5 bin directory.
170 --armc6-bin-dir=<ARMC6_bin_dir_path> ARM Compiler 6 bin directory.
171 --gnutls-cli=<GnuTLS_cli_path> GnuTLS client executable to use for most tests.
172 --gnutls-serv=<GnuTLS_serv_path> GnuTLS server executable to use for most tests.
173 --gnutls-legacy-cli=<GnuTLS_cli_path> GnuTLS client executable to use for legacy tests.
174 --gnutls-legacy-serv=<GnuTLS_serv_path> GnuTLS server executable to use for legacy tests.
175 --openssl=<OpenSSL_path> OpenSSL executable to use for most tests.
176 --openssl-legacy=<OpenSSL_path> OpenSSL executable to use for legacy tests e.g. SSLv3.
177EOF
SimonB2e23c822016-04-16 21:54:39 +0100178}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100179
180# remove built files as well as the cmake cache/config
181cleanup()
182{
Gilles Peskinea71d64c2018-03-21 12:16:57 +0100183 if [ -n "${MBEDTLS_ROOT_DIR+set}" ]; then
184 cd "$MBEDTLS_ROOT_DIR"
185 fi
186
Gilles Peskine7c652162017-12-11 00:01:40 +0100187 command make clean
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200188
Gilles Peskine31b07e22018-03-21 12:15:06 +0100189 # Remove CMake artefacts
190 find . -name .git -prune -o -name yotta -prune -o \
191 -iname CMakeFiles -exec rm -rf {} \+ -o \
192 \( -iname cmake_install.cmake -o \
193 -iname CTestTestfile.cmake -o \
194 -iname CMakeCache.txt \) -exec rm {} \+
195 # Recover files overwritten by in-tree CMake builds
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000196 rm -f include/Makefile include/mbedtls/Makefile programs/*/Makefile
Paul Bakkerfe0984d2014-06-13 00:13:45 +0200197 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile
198 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200199
200 if [ -f "$CONFIG_BAK" ]; then
201 mv "$CONFIG_BAK" "$CONFIG_H"
202 fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100203}
204
Gilles Peskine7c652162017-12-11 00:01:40 +0100205# Executed on exit. May be redefined depending on command line options.
206final_report () {
207 :
208}
209
210fatal_signal () {
211 cleanup
212 final_report $1
213 trap - $1
214 kill -$1 $$
215}
216
217trap 'fatal_signal HUP' HUP
218trap 'fatal_signal INT' INT
219trap 'fatal_signal TERM' TERM
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200220
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100221msg()
222{
Gilles Peskine11ddca62018-12-04 12:49:28 +0100223 if [ -n "${current_component:-}" ]; then
224 current_section="${current_component#component_}: $1"
225 else
226 current_section="$1"
227 fi
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100228 echo ""
229 echo "******************************************************************"
Gilles Peskine11ddca62018-12-04 12:49:28 +0100230 echo "* $current_section "
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000231 printf "* "; date
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100232 echo "******************************************************************"
233}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100234
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100235armc6_build_test()
236{
237 FLAGS="$1"
Andres AGa5cd9732016-10-17 15:23:10 +0100238
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100239 msg "build: ARM Compiler 6 ($FLAGS), make"
240 ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \
241 WARNING_CFLAGS='-xc -std=c99' make lib
242 make clean
243}
Andres AGa5cd9732016-10-17 15:23:10 +0100244
Andres AGd9eba4b2016-08-26 14:42:14 +0100245err_msg()
246{
247 echo "$1" >&2
248}
249
250check_tools()
251{
252 for TOOL in "$@"; do
Andres AG98393602017-01-31 17:04:45 +0000253 if ! `type "$TOOL" >/dev/null 2>&1`; then
Andres AGd9eba4b2016-08-26 14:42:14 +0100254 err_msg "$TOOL not found!"
255 exit 1
256 fi
257 done
258}
259
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100260pre_parse_command_line () {
Gilles Peskine6e984232018-11-27 21:37:53 +0100261 COMPONENTS=
262
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100263 while [ $# -gt 0 ]; do
264 case "$1" in
265 --armcc) RUN_ARMCC=1;;
266 --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
267 --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
Gilles Peskine6e984232018-11-27 21:37:53 +0100268 --except) ALL_EXCEPT=1;;
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100269 --force|-f) FORCE=1;;
270 --gnutls-cli) shift; GNUTLS_CLI="$1";;
271 --gnutls-legacy-cli) shift; GNUTLS_LEGACY_CLI="$1";;
272 --gnutls-legacy-serv) shift; GNUTLS_LEGACY_SERV="$1";;
273 --gnutls-serv) shift; GNUTLS_SERV="$1";;
274 --help|-h) usage; exit;;
275 --keep-going|-k) KEEP_GOING=1;;
276 --memory|-m) MEMORY=1;;
277 --no-armcc) RUN_ARMCC=0;;
278 --no-force) FORCE=0;;
279 --no-keep-going) KEEP_GOING=0;;
280 --no-memory) MEMORY=0;;
281 --no-yotta) YOTTA=0;;
282 --openssl) shift; OPENSSL="$1";;
283 --openssl-legacy) shift; OPENSSL_LEGACY="$1";;
284 --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
285 --random-seed) unset SEED;;
286 --release-test|-r) SEED=1;;
287 --seed|-s) shift; SEED="$1";;
288 --yotta) YOTTA=1;;
Gilles Peskine91bd8b72019-01-08 23:01:34 +0100289 -*)
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100290 echo >&2 "Unknown option: $1"
291 echo >&2 "Run $0 --help for usage."
292 exit 120
293 ;;
Gilles Peskine91bd8b72019-01-08 23:01:34 +0100294 *)
295 COMPONENTS="$COMPONENTS $1";;
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100296 esac
297 shift
298 done
Gilles Peskine91bd8b72019-01-08 23:01:34 +0100299
Gilles Peskine6e984232018-11-27 21:37:53 +0100300 if [ $ALL_EXCEPT -ne 0 ]; then
301 RUN_COMPONENTS=
302 for component in $ALL_COMPONENTS; do
303 if ! is_component_excluded "$component"; then
304 RUN_COMPONENTS="$RUN_COMPONENTS $component"
305 fi
306 done
307 elif [ -z "$COMPONENTS" ]; then
308 RUN_COMPONENTS="$ALL_COMPONENTS"
309 else
310 RUN_COMPONENTS="$COMPONENTS"
Gilles Peskine91bd8b72019-01-08 23:01:34 +0100311 fi
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100312}
SimonB2e23c822016-04-16 21:54:39 +0100313
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100314pre_check_git () {
315 if [ $FORCE -eq 1 ]; then
316 if [ $YOTTA -eq 1 ]; then
317 rm -rf yotta/module "$OUT_OF_SOURCE_DIR"
318 fi
319 git checkout-index -f -q $CONFIG_H
320 cleanup
321 else
322
323 if [ $YOTTA -ne 0 ] && [ -d yotta/module ]; then
324 err_msg "Warning - there is an existing yotta module in the directory 'yotta/module'"
325 echo "You can either delete your work and retry, or force the test to overwrite the"
326 echo "test by rerunning the script as: $0 --force"
327 exit 1
328 fi
329
330 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
331 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
332 echo "You can either delete this directory manually, or force the test by rerunning"
333 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
334 exit 1
335 fi
336
337 if ! git diff-files --quiet include/mbedtls/config.h; then
338 err_msg "Warning - the configuration file 'include/mbedtls/config.h' has been edited. "
339 echo "You can either delete or preserve your work, or force the test by rerunning the"
340 echo "script as: $0 --force"
341 exit 1
342 fi
Gilles Peskineda519252017-11-30 13:22:04 +0100343 fi
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100344}
SimonB2e23c822016-04-16 21:54:39 +0100345
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100346pre_setup_keep_going () {
Gilles Peskine7c652162017-12-11 00:01:40 +0100347 failure_summary=
348 failure_count=0
349 start_red=
350 end_color=
351 if [ -t 1 ]; then
Gilles Peskine9736b9d2018-01-02 21:54:17 +0100352 case "${TERM:-}" in
Gilles Peskine7c652162017-12-11 00:01:40 +0100353 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
354 start_red=$(printf '\033[31m')
355 end_color=$(printf '\033[0m')
356 ;;
357 esac
358 fi
359 record_status () {
360 if "$@"; then
361 last_status=0
362 else
363 last_status=$?
364 text="$current_section: $* -> $last_status"
365 failure_summary="$failure_summary
366$text"
367 failure_count=$((failure_count + 1))
368 echo "${start_red}^^^^$text^^^^${end_color}"
369 fi
370 }
371 make () {
372 case "$*" in
373 *test|*check)
374 if [ $build_status -eq 0 ]; then
375 record_status command make "$@"
376 else
377 echo "(skipped because the build failed)"
378 fi
379 ;;
380 *)
381 record_status command make "$@"
382 build_status=$last_status
383 ;;
384 esac
385 }
386 final_report () {
387 if [ $failure_count -gt 0 ]; then
388 echo
389 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
390 echo "${start_red}FAILED: $failure_count${end_color}$failure_summary"
391 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Jaeden Amero5113bde2018-07-20 16:42:14 +0100392 exit 1
Gilles Peskine7c652162017-12-11 00:01:40 +0100393 elif [ -z "${1-}" ]; then
394 echo "SUCCESS :)"
395 fi
396 if [ -n "${1-}" ]; then
397 echo "Killed by SIG$1."
398 fi
399 }
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100400}
401
Gilles Peskine7c652162017-12-11 00:01:40 +0100402if_build_succeeded () {
403 if [ $build_status -eq 0 ]; then
404 record_status "$@"
405 fi
406}
407
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100408pre_print_configuration () {
409 msg "info: $0 configuration"
410 echo "MEMORY: $MEMORY"
411 echo "FORCE: $FORCE"
412 echo "SEED: ${SEED-"UNSET"}"
413 echo "OPENSSL: $OPENSSL"
414 echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
415 echo "GNUTLS_CLI: $GNUTLS_CLI"
416 echo "GNUTLS_SERV: $GNUTLS_SERV"
417 echo "GNUTLS_LEGACY_CLI: $GNUTLS_LEGACY_CLI"
418 echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV"
419 echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
420 echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
421}
Andres AG7770ea82016-10-10 15:46:20 +0100422
Andres AGd9eba4b2016-08-26 14:42:14 +0100423# Make sure the tools we need are available.
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100424pre_check_tools () {
425 ARMC5_CC="$ARMC5_BIN_DIR/armcc"
426 ARMC5_AR="$ARMC5_BIN_DIR/armar"
427 ARMC6_CC="$ARMC6_BIN_DIR/armclang"
428 ARMC6_AR="$ARMC6_BIN_DIR/armar"
429
430 # To avoid setting OpenSSL and GnuTLS for each call to compat.sh and ssl-opt.sh
431 # we just export the variables they require
432 export OPENSSL_CMD="$OPENSSL"
433 export GNUTLS_CLI="$GNUTLS_CLI"
434 export GNUTLS_SERV="$GNUTLS_SERV"
435
436 # Avoid passing --seed flag in every call to ssl-opt.sh
437 if [ -n "${SEED-}" ]; then
438 export SEED
439 fi
440
441 check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$GNUTLS_CLI" "$GNUTLS_SERV" \
442 "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV" "doxygen" "dot" \
443 "arm-none-eabi-gcc" "i686-w64-mingw32-gcc"
444 if [ $RUN_ARMCC -ne 0 ]; then
445 check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC6_CC" "$ARMC6_AR"
446 fi
447
448 msg "info: output_env.sh"
449 OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY" GNUTLS_CLI="$GNUTLS_CLI" \
450 GNUTLS_SERV="$GNUTLS_SERV" GNUTLS_LEGACY_CLI="$GNUTLS_LEGACY_CLI" \
451 GNUTLS_LEGACY_SERV="$GNUTLS_LEGACY_SERV" ARMC5_CC="$ARMC5_CC" \
452 ARMC6_CC="$ARMC6_CC" RUN_ARMCC="$RUN_ARMCC" scripts/output_env.sh
453}
Andres AGd9eba4b2016-08-26 14:42:14 +0100454
Gilles Peskine192c72f2017-12-21 15:59:21 +0100455
456
457################################################################
458#### Basic checks
459################################################################
SimonB2e23c822016-04-16 21:54:39 +0100460
461#
462# Test Suites to be executed
463#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200464# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100465# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard61bc57a2014-08-14 11:29:06 +0200466# and/or are more likely to fail than others (eg I use Clang most of the
467# time, so start with a GCC build).
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200468# 2. Minimize total running time, by avoiding useless rebuilds
469#
470# Indicative running times are given for reference.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100471
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100472component_check_recursion () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100473 msg "test: recursion.pl" # < 1s
474 record_status tests/scripts/recursion.pl library/*.c
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100475}
Manuel Pégourié-Gonnardea29d152014-11-20 17:32:33 +0100476
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100477component_check_generated_files () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100478 msg "test: freshness of generated source files" # < 1s
479 record_status tests/scripts/check-generated-files.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100480}
Manuel Pégourié-Gonnardb3b8e432015-02-13 14:52:19 +0000481
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100482component_check_doxy_blocks () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100483 msg "test: doxygen markup outside doxygen blocks" # < 1s
484 record_status tests/scripts/check-doxy-blocks.pl
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100485}
Manuel Pégourié-Gonnardd09a6b52015-04-09 17:19:23 +0200486
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100487component_check_files () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100488 msg "test: check-files.py" # < 1s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100489 record_status tests/scripts/check-files.py
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100490}
Manuel Pégourié-Gonnard77d56bb2015-07-28 15:00:37 +0200491
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100492component_check_names () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100493 msg "test/build: declared and exported names" # < 3s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100494 record_status tests/scripts/check-names.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100495}
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +0200496
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100497component_check_doxygen_warnings () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100498 msg "test: doxygen warnings" # ~ 3s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100499 record_status tests/scripts/doxygen.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100500}
Andres Amaya Garciadd29c2f2017-05-04 11:35:51 +0100501
Simon Butcher948f2642018-07-20 21:27:33 +0100502
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100503################################################################
504#### Build and test many configurations and targets
505################################################################
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100506
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100507component_build_yotta () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100508 if [ $RUN_ARMCC -ne 0 ] && [ $YOTTA -ne 0 ]; then
509 # Note - use of yotta is deprecated, and yotta also requires armcc to be on the
510 # path, and uses whatever version of armcc it finds there.
511 msg "build: create and build yotta module" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100512 record_status tests/scripts/yotta-build.sh
513 fi
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100514}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100515
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100516component_test_default_cmake_gcc_asan () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100517 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100518 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100519 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +0200520
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100521 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100522 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100523
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100524 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
Gilles Peskine7c652162017-12-11 00:01:40 +0100525 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100526
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100527 msg "test: compat.sh (ASan build)" # ~ 6 min
528 if_build_succeeded tests/compat.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100529}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000530
Gilles Peskine3484ed82019-01-08 22:51:19 +0100531component_test_ref_configs () {
532 msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
533 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
534 record_status tests/scripts/test-ref-configs.pl
535}
536
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100537component_test_sslv3 () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100538 msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100539 scripts/config.pl set MBEDTLS_SSL_PROTO_SSL3
540 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
541 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000542
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100543 msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
544 make test
545
546 msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
547 if_build_succeeded tests/compat.sh -m 'tls1 tls1_1 tls1_2 dtls1 dtls1_2'
548 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
549
550 msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
551 if_build_succeeded tests/ssl-opt.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100552}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100553
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100554component_test_no_renegotiation () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100555 msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100556 scripts/config.pl unset MBEDTLS_SSL_RENEGOTIATION
557 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
558 make
559
560 msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
561 make test
562
563 msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
564 if_build_succeeded tests/ssl-opt.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100565}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100566
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100567component_test_rsa_no_crt () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100568 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100569 scripts/config.pl set MBEDTLS_RSA_NO_CRT
570 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
571 make
572
573 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
574 make test
575
576 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
577 if_build_succeeded tests/ssl-opt.sh -f RSA
578
579 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
580 if_build_succeeded tests/compat.sh -t RSA
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100581}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100582
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100583component_test_full_cmake_clang () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100584 msg "build: cmake, full config, clang" # ~ 50s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100585 scripts/config.pl full
586 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
587 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check -D ENABLE_TESTING=On .
588 make
589
590 msg "test: main suites (full config)" # ~ 5s
591 make test
592
593 msg "test: ssl-opt.sh default (full config)" # ~ 1s
594 if_build_succeeded tests/ssl-opt.sh -f Default
595
596 msg "test: compat.sh RC4, DES & NULL (full config)" # ~ 2 min
597 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'
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100598}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100599
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100600component_build_deprecated () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100601 msg "build: make, full config + DEPRECATED_WARNING, gcc -O" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100602 scripts/config.pl full
603 scripts/config.pl set MBEDTLS_DEPRECATED_WARNING
604 # Build with -O -Wextra to catch a maximum of issues.
605 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra' lib programs
606 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
607
608 msg "build: make, full config + DEPRECATED_REMOVED, clang -O" # ~ 30s
609 # No cleanup, just tweak the configuration and rebuild
610 make clean
611 scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
612 scripts/config.pl set MBEDTLS_DEPRECATED_REMOVED
613 # Build with -O -Wextra to catch a maximum of issues.
614 make CC=clang CFLAGS='-O -Werror -Wall -Wextra' lib programs
615 make CC=clang CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100616}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100617
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100618component_test_depends_curves () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100619 msg "test/build: curves.pl (gcc)" # ~ 4 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100620 record_status tests/scripts/curves.pl
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100621}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100622
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100623component_test_depends_hashes () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100624 msg "test/build: depends-hashes.pl (gcc)" # ~ 2 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100625 record_status tests/scripts/depends-hashes.pl
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100626}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100627
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100628component_test_depends_pkalgs () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100629 msg "test/build: depends-pkalgs.pl (gcc)" # ~ 2 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100630 record_status tests/scripts/depends-pkalgs.pl
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100631}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100632
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100633component_build_key_exchanges () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100634 msg "test/build: key-exchanges (gcc)" # ~ 1 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100635 record_status tests/scripts/key-exchanges.pl
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100636}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100637
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100638component_build_default_make_gcc () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100639 msg "build: Unix make, -Os (gcc)" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100640 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100641}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100642
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100643component_test_no_platform () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100644 # Full configuration build, without platform support, file IO and net sockets.
645 # This should catch missing mbedtls_printf definitions, and by disabling file
646 # IO, it should catch missing '#include <stdio.h>'
647 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100648 scripts/config.pl full
649 scripts/config.pl unset MBEDTLS_PLATFORM_C
650 scripts/config.pl unset MBEDTLS_NET_C
651 scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
652 scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
653 scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
654 scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
655 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
656 scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
657 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
658 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
659 scripts/config.pl unset MBEDTLS_FS_IO
660 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
661 # to re-enable platform integration features otherwise disabled in C99 builds
662 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -O0 -D_DEFAULT_SOURCE' lib programs
663 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0' test
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100664}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100665
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100666component_build_no_std_function () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100667 # catch compile bugs in _uninit functions
668 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100669 scripts/config.pl full
670 scripts/config.pl set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
671 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
672 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100673}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100674
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100675component_build_no_ssl_srv () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100676 msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100677 scripts/config.pl full
678 scripts/config.pl unset MBEDTLS_SSL_SRV_C
679 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100680}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100681
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100682component_build_no_ssl_cli () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100683 msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100684 scripts/config.pl full
685 scripts/config.pl unset MBEDTLS_SSL_CLI_C
686 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100687}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100688
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100689component_build_no_sockets () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100690 # Note, C99 compliance can also be tested with the sockets support disabled,
691 # as that requires a POSIX platform (which isn't the same as C99).
692 msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100693 scripts/config.pl full
694 scripts/config.pl unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
695 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
696 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0 -std=c99 -pedantic' lib
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100697}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100698
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100699component_test_no_max_fragment_length () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100700 msg "build: default config except MFL extension (ASan build)" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100701 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
702 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
703 make
704
705 msg "test: ssl-opt.sh, MFL-related tests"
706 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length"
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100707}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100708
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100709component_test_null_entropy () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100710 msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100711 scripts/config.pl set MBEDTLS_TEST_NULL_ENTROPY
712 scripts/config.pl set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
713 scripts/config.pl set MBEDTLS_ENTROPY_C
714 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
715 scripts/config.pl unset MBEDTLS_ENTROPY_HARDWARE_ALT
716 scripts/config.pl unset MBEDTLS_HAVEGE_C
Gilles Peskine4e7b3232019-01-06 19:48:30 +0000717 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan -D UNSAFE_BUILD=ON .
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100718 make
719
720 msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)"
721 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100722}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100723
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100724component_test_platform_calloc_macro () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100725 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100726 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
727 scripts/config.pl set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
728 scripts/config.pl set MBEDTLS_PLATFORM_FREE_MACRO free
729 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
730 make
731
732 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
733 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100734}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100735
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100736component_test_make_shared () {
Gilles Peskine770ad7e2019-01-08 23:19:08 +0100737 msg "build/test: make shared" # ~ 40s
738 make SHARED=1 all check
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100739}
740
Gilles Peskine770ad7e2019-01-08 23:19:08 +0100741case $(uname -m) in
742 amd64|x86_64)
743 component_test_m32_o0 () {
744 # Build once with -O0, to compile out the i386 specific inline assembly
745 msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
746 scripts/config.pl full
747 make CC=gcc CFLAGS='-O0 -Werror -Wall -Wextra -m32 -fsanitize=address'
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100748
Gilles Peskine770ad7e2019-01-08 23:19:08 +0100749 msg "test: i386, make, gcc -O0 (ASan build)"
750 make test
751 }
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100752
Gilles Peskine770ad7e2019-01-08 23:19:08 +0100753 component_test_m32_o1 () {
754 # Build again with -O1, to compile in the i386 specific inline assembly
755 msg "build: i386, make, gcc -O1 (ASan build)" # ~ 30s
756 scripts/config.pl full
757 make CC=gcc CFLAGS='-O1 -Werror -Wall -Wextra -m32 -fsanitize=address'
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100758
Gilles Peskine770ad7e2019-01-08 23:19:08 +0100759 msg "test: i386, make, gcc -O1 (ASan build)"
760 make test
761 }
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100762
Gilles Peskine770ad7e2019-01-08 23:19:08 +0100763 component_test_mx32 () {
764 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
765 scripts/config.pl full
766 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32'
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100767
Gilles Peskine770ad7e2019-01-08 23:19:08 +0100768 msg "test: 64-bit ILP32, make, gcc"
769 make test
770 }
771 ;;
772esac
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100773
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100774component_test_have_int32 () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100775 msg "build: gcc, force 32-bit bignum limbs"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100776 scripts/config.pl unset MBEDTLS_HAVE_ASM
777 scripts/config.pl unset MBEDTLS_AESNI_C
778 scripts/config.pl unset MBEDTLS_PADLOCK_C
779 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
780
781 msg "test: gcc, force 32-bit bignum limbs"
782 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100783}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100784
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100785component_test_have_int64 () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100786 msg "build: gcc, force 64-bit bignum limbs"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100787 scripts/config.pl unset MBEDTLS_HAVE_ASM
788 scripts/config.pl unset MBEDTLS_AESNI_C
789 scripts/config.pl unset MBEDTLS_PADLOCK_C
790 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
791
792 msg "test: gcc, force 64-bit bignum limbs"
793 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100794}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100795
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100796component_build_arm_none_eabi_gcc () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100797 msg "build: arm-none-eabi-gcc, make" # ~ 10s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100798 scripts/config.pl full
799 scripts/config.pl unset MBEDTLS_NET_C
800 scripts/config.pl unset MBEDTLS_TIMING_C
801 scripts/config.pl unset MBEDTLS_FS_IO
802 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
803 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
804 # following things are not in the default config
805 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
806 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
807 scripts/config.pl unset MBEDTLS_THREADING_C
808 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
809 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
810 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100811}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100812
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100813component_build_arm_none_eabi_gcc_no_udbl_division () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100814 msg "build: arm-none-eabi-gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100815 scripts/config.pl full
816 scripts/config.pl unset MBEDTLS_NET_C
817 scripts/config.pl unset MBEDTLS_TIMING_C
818 scripts/config.pl unset MBEDTLS_FS_IO
819 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
820 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
821 # following things are not in the default config
822 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
823 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
824 scripts/config.pl unset MBEDTLS_THREADING_C
825 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
826 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
827 scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
828 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
829 echo "Checking that software 64-bit division is not required"
830 ! grep __aeabi_uldiv library/*.o
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100831}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100832
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100833component_build_armcc () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100834 msg "build: ARM Compiler 5, make"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100835 scripts/config.pl full
836 scripts/config.pl unset MBEDTLS_NET_C
837 scripts/config.pl unset MBEDTLS_TIMING_C
838 scripts/config.pl unset MBEDTLS_FS_IO
839 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
840 scripts/config.pl unset MBEDTLS_HAVE_TIME
841 scripts/config.pl unset MBEDTLS_HAVE_TIME_DATE
842 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
843 # following things are not in the default config
844 scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
845 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
846 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
847 scripts/config.pl unset MBEDTLS_THREADING_C
848 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
849 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
850 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT # depends on MBEDTLS_HAVE_TIME
851
852 if [ $RUN_ARMCC -ne 0 ]; then
853 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
854 make clean
855
856 # ARM Compiler 6 - Target ARMv7-A
857 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-a"
858
859 # ARM Compiler 6 - Target ARMv7-M
860 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m"
861
862 # ARM Compiler 6 - Target ARMv8-A - AArch32
863 armc6_build_test "--target=arm-arm-none-eabi -march=armv8.2-a"
864
865 # ARM Compiler 6 - Target ARMv8-M
866 armc6_build_test "--target=arm-arm-none-eabi -march=armv8-m.main"
867
868 # ARM Compiler 6 - Target ARMv8-A - AArch64
869 armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a"
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100870 fi
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100871}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000872
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100873component_test_allow_sha1 () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100874 msg "build: allow SHA1 in certificates by default"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100875 scripts/config.pl set MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
876 make CFLAGS='-Werror -Wall -Wextra'
877 msg "test: allow SHA1 in certificates by default"
878 make test
879 if_build_succeeded tests/ssl-opt.sh -f SHA-1
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100880}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000881
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100882component_build_mingw () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100883 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100884 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
885
886 # note Make tests only builds the tests, but doesn't run them
887 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror' WINDOWS_BUILD=1 tests
888 make WINDOWS_BUILD=1 clean
889
890 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
891 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
892 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
893 make WINDOWS_BUILD=1 clean
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100894}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100895
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100896component_test_memsan () {
Gilles Peskine770ad7e2019-01-08 23:19:08 +0100897 msg "build: MSan (clang)" # ~ 1 min 20s
898 scripts/config.pl unset MBEDTLS_AESNI_C # memsan doesn't grok asm
899 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
900 make
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100901
Gilles Peskine770ad7e2019-01-08 23:19:08 +0100902 msg "test: main suites (MSan)" # ~ 10s
903 make test
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100904
Gilles Peskine770ad7e2019-01-08 23:19:08 +0100905 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
906 if_build_succeeded tests/ssl-opt.sh
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100907
Gilles Peskine770ad7e2019-01-08 23:19:08 +0100908 # Optional part(s)
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100909
Gilles Peskine770ad7e2019-01-08 23:19:08 +0100910 if [ "$MEMORY" -gt 0 ]; then
911 msg "test: compat.sh (MSan)" # ~ 6 min 20s
912 if_build_succeeded tests/compat.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100913 fi
914}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100915
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100916component_test_memcheck () {
Gilles Peskine770ad7e2019-01-08 23:19:08 +0100917 msg "build: Release (clang)"
918 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
919 make
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100920
Gilles Peskine770ad7e2019-01-08 23:19:08 +0100921 msg "test: main suites valgrind (Release)"
922 make memcheck
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100923
Gilles Peskine770ad7e2019-01-08 23:19:08 +0100924 # Optional part(s)
925 # Currently broken, programs don't seem to receive signals
926 # under valgrind on OS X
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100927
Gilles Peskine770ad7e2019-01-08 23:19:08 +0100928 if [ "$MEMORY" -gt 0 ]; then
929 msg "test: ssl-opt.sh --memcheck (Release)"
930 if_build_succeeded tests/ssl-opt.sh --memcheck
931 fi
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100932
Gilles Peskine770ad7e2019-01-08 23:19:08 +0100933 if [ "$MEMORY" -gt 1 ]; then
934 msg "test: compat.sh --memcheck (Release)"
935 if_build_succeeded tests/compat.sh --memcheck
936 fi
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100937}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100938
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100939component_test_cmake_out_of_source () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100940 msg "build: cmake 'out-of-source' build"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100941 MBEDTLS_ROOT_DIR="$PWD"
942 mkdir "$OUT_OF_SOURCE_DIR"
943 cd "$OUT_OF_SOURCE_DIR"
944 cmake "$MBEDTLS_ROOT_DIR"
945 make
946
947 msg "test: cmake 'out-of-source' build"
948 make test
949 # Test an SSL option that requires an auxiliary script in test/scripts/.
950 # Also ensure that there are no error messages such as
951 # "No such file or directory", which would indicate that some required
952 # file is missing (ssl-opt.sh tolerates the absence of some files so
953 # may exit with status 0 but emit errors).
954 if_build_succeeded ./tests/ssl-opt.sh -f 'Fallback SCSV: beginning of list' 2>ssl-opt.err
955 if [ -s ssl-opt.err ]; then
956 cat ssl-opt.err >&2
957 record_status [ ! -s ssl-opt.err ]
958 rm ssl-opt.err
959 fi
960 cd "$MBEDTLS_ROOT_DIR"
961 rm -rf "$OUT_OF_SOURCE_DIR"
962 unset MBEDTLS_ROOT_DIR
963}
Andres AGdc192212016-08-31 17:33:13 +0100964
Gilles Peskine192c72f2017-12-21 15:59:21 +0100965
966
967################################################################
968#### Termination
969################################################################
970
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100971post_report () {
972 msg "Done, cleaning up"
973 cleanup
974
975 final_report
976}
977
978
979
980################################################################
981#### Run all the things
982################################################################
983
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100984# Run one component and clean up afterwards.
985run_component () {
Gilles Peskine72adb432019-01-02 18:57:02 +0100986 # Back up the configuration in case the component modifies it.
987 # The cleanup function will restore it.
988 cp -p "$CONFIG_H" "$CONFIG_BAK"
Gilles Peskine11ddca62018-12-04 12:49:28 +0100989 current_component="$1"
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100990 "$@"
991 cleanup
992}
993
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100994# Preliminary setup
995pre_check_environment
996pre_initialize_variables
997pre_parse_command_line "$@"
998
999pre_check_git
1000build_status=0
1001if [ $KEEP_GOING -eq 1 ]; then
1002 pre_setup_keep_going
1003else
1004 record_status () {
1005 "$@"
1006 }
1007fi
1008pre_print_configuration
1009pre_check_tools
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001010cleanup
Gilles Peskine7c652162017-12-11 00:01:40 +01001011
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001012# Run all the test components.
Gilles Peskine6e984232018-11-27 21:37:53 +01001013for component in $RUN_COMPONENTS; do
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001014 run_component "component_$component"
1015done
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001016
1017# We're done.
1018post_report