blob: 6d3dea533162577e9d353a8b27dec54c02580da6 [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
Gilles Peskine7120f772019-01-06 20:15:26 +0000113 if [ -z "${MAKEFLAGS+set}" ]; then
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100114 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 Peskine3fbdd212019-01-08 23:33:45 +0100122
123 # Exclude components that are not supported on this platform.
124 SUPPORTED_COMPONENTS=
125 for component in $ALL_COMPONENTS; do
126 case $(type "support_$component" 2>&1) in
127 *' function'*)
128 if ! support_$component; then continue; fi;;
129 esac
130 SUPPORTED_COMPONENTS="$SUPPORTED_COMPONENTS $component"
131 done
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100132}
Andres AG38495a32016-07-12 16:54:33 +0100133
Gilles Peskine3fbdd212019-01-08 23:33:45 +0100134# Test whether $1 is excluded via the command line.
Gilles Peskine6e984232018-11-27 21:37:53 +0100135is_component_excluded()
136{
Gilles Peskine3fbdd212019-01-08 23:33:45 +0100137 # Is $1 excluded via $COMPONENTS (a space-separated list of wildcard
138 # patterns)?
Gilles Peskine6e984232018-11-27 21:37:53 +0100139 set -f
140 for pattern in $COMPONENTS; do
141 set +f
142 case ${1#component_} in $pattern) return 0;; esac
143 done
144 set +f
145 return 1
146}
147
Simon Butcher41eeccf2016-09-07 00:07:09 +0100148usage()
SimonB2e23c822016-04-16 21:54:39 +0100149{
Gilles Peskine709346a2017-12-10 23:43:39 +0100150 cat <<EOF
Gilles Peskine91bd8b72019-01-08 23:01:34 +0100151Usage: $0 [OPTION]... [COMPONENT]...
152Run mbedtls release validation tests.
153By default, run all tests. With one or more COMPONENT, run only those.
154
155Special options:
156 -h|--help Print this help and exit.
Gilles Peskine709346a2017-12-10 23:43:39 +0100157
158General options:
159 -f|--force Force the tests to overwrite any modified files.
Gilles Peskine7c652162017-12-11 00:01:40 +0100160 -k|--keep-going Run all tests and report errors at the end.
Gilles Peskine709346a2017-12-10 23:43:39 +0100161 -m|--memory Additional optional memory tests.
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100162 --armcc Run ARM Compiler builds (on by default).
Gilles Peskine6e984232018-11-27 21:37:53 +0100163 --except If some components are passed on the command line,
164 run all the tests except for these components. In
165 this mode, you can pass shell wildcard patterns as
166 component names, e.g. "$0 --except 'test_*'" to
167 exclude all components that run tests.
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100168 --no-armcc Skip ARM Compiler builds.
Gilles Peskine19ceb712018-03-21 08:40:26 +0100169 --no-force Refuse to overwrite modified files (default).
170 --no-keep-going Stop at the first error (default).
171 --no-memory No additional memory tests (default).
Gilles Peskine2a22a802017-12-21 15:19:00 +0100172 --no-yotta Skip yotta module build.
Gilles Peskine709346a2017-12-10 23:43:39 +0100173 --out-of-source-dir=<path> Directory used for CMake out-of-source build tests.
Gilles Peskine19ceb712018-03-21 08:40:26 +0100174 --random-seed Use a random seed value for randomized tests (default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100175 -r|--release-test Run this script in release mode. This fixes the seed value to 1.
176 -s|--seed Integer seed value to use for this test run.
Gilles Peskine2a22a802017-12-21 15:19:00 +0100177 --yotta Build yotta module (on by default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100178
179Tool path options:
180 --armc5-bin-dir=<ARMC5_bin_dir_path> ARM Compiler 5 bin directory.
181 --armc6-bin-dir=<ARMC6_bin_dir_path> ARM Compiler 6 bin directory.
182 --gnutls-cli=<GnuTLS_cli_path> GnuTLS client executable to use for most tests.
183 --gnutls-serv=<GnuTLS_serv_path> GnuTLS server executable to use for most tests.
184 --gnutls-legacy-cli=<GnuTLS_cli_path> GnuTLS client executable to use for legacy tests.
185 --gnutls-legacy-serv=<GnuTLS_serv_path> GnuTLS server executable to use for legacy tests.
186 --openssl=<OpenSSL_path> OpenSSL executable to use for most tests.
187 --openssl-legacy=<OpenSSL_path> OpenSSL executable to use for legacy tests e.g. SSLv3.
188EOF
SimonB2e23c822016-04-16 21:54:39 +0100189}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100190
191# remove built files as well as the cmake cache/config
192cleanup()
193{
Gilles Peskinea71d64c2018-03-21 12:16:57 +0100194 if [ -n "${MBEDTLS_ROOT_DIR+set}" ]; then
195 cd "$MBEDTLS_ROOT_DIR"
196 fi
197
Gilles Peskine7c652162017-12-11 00:01:40 +0100198 command make clean
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200199
Gilles Peskine31b07e22018-03-21 12:15:06 +0100200 # Remove CMake artefacts
201 find . -name .git -prune -o -name yotta -prune -o \
202 -iname CMakeFiles -exec rm -rf {} \+ -o \
203 \( -iname cmake_install.cmake -o \
204 -iname CTestTestfile.cmake -o \
205 -iname CMakeCache.txt \) -exec rm {} \+
206 # Recover files overwritten by in-tree CMake builds
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000207 rm -f include/Makefile include/mbedtls/Makefile programs/*/Makefile
Paul Bakkerfe0984d2014-06-13 00:13:45 +0200208 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile
209 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200210
211 if [ -f "$CONFIG_BAK" ]; then
212 mv "$CONFIG_BAK" "$CONFIG_H"
213 fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100214}
215
Gilles Peskine7c652162017-12-11 00:01:40 +0100216# Executed on exit. May be redefined depending on command line options.
217final_report () {
218 :
219}
220
221fatal_signal () {
222 cleanup
223 final_report $1
224 trap - $1
225 kill -$1 $$
226}
227
228trap 'fatal_signal HUP' HUP
229trap 'fatal_signal INT' INT
230trap 'fatal_signal TERM' TERM
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200231
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100232msg()
233{
Gilles Peskine11ddca62018-12-04 12:49:28 +0100234 if [ -n "${current_component:-}" ]; then
235 current_section="${current_component#component_}: $1"
236 else
237 current_section="$1"
238 fi
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100239 echo ""
240 echo "******************************************************************"
Gilles Peskine11ddca62018-12-04 12:49:28 +0100241 echo "* $current_section "
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000242 printf "* "; date
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100243 echo "******************************************************************"
244}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100245
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100246armc6_build_test()
247{
248 FLAGS="$1"
Andres AGa5cd9732016-10-17 15:23:10 +0100249
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100250 msg "build: ARM Compiler 6 ($FLAGS), make"
251 ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \
252 WARNING_CFLAGS='-xc -std=c99' make lib
253 make clean
254}
Andres AGa5cd9732016-10-17 15:23:10 +0100255
Andres AGd9eba4b2016-08-26 14:42:14 +0100256err_msg()
257{
258 echo "$1" >&2
259}
260
261check_tools()
262{
263 for TOOL in "$@"; do
Andres AG98393602017-01-31 17:04:45 +0000264 if ! `type "$TOOL" >/dev/null 2>&1`; then
Andres AGd9eba4b2016-08-26 14:42:14 +0100265 err_msg "$TOOL not found!"
266 exit 1
267 fi
268 done
269}
270
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100271pre_parse_command_line () {
Gilles Peskine6e984232018-11-27 21:37:53 +0100272 COMPONENTS=
273
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100274 while [ $# -gt 0 ]; do
275 case "$1" in
276 --armcc) RUN_ARMCC=1;;
277 --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
278 --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
Gilles Peskine6e984232018-11-27 21:37:53 +0100279 --except) ALL_EXCEPT=1;;
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100280 --force|-f) FORCE=1;;
281 --gnutls-cli) shift; GNUTLS_CLI="$1";;
282 --gnutls-legacy-cli) shift; GNUTLS_LEGACY_CLI="$1";;
283 --gnutls-legacy-serv) shift; GNUTLS_LEGACY_SERV="$1";;
284 --gnutls-serv) shift; GNUTLS_SERV="$1";;
285 --help|-h) usage; exit;;
286 --keep-going|-k) KEEP_GOING=1;;
287 --memory|-m) MEMORY=1;;
288 --no-armcc) RUN_ARMCC=0;;
289 --no-force) FORCE=0;;
290 --no-keep-going) KEEP_GOING=0;;
291 --no-memory) MEMORY=0;;
292 --no-yotta) YOTTA=0;;
293 --openssl) shift; OPENSSL="$1";;
294 --openssl-legacy) shift; OPENSSL_LEGACY="$1";;
295 --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
296 --random-seed) unset SEED;;
297 --release-test|-r) SEED=1;;
298 --seed|-s) shift; SEED="$1";;
299 --yotta) YOTTA=1;;
Gilles Peskine91bd8b72019-01-08 23:01:34 +0100300 -*)
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100301 echo >&2 "Unknown option: $1"
302 echo >&2 "Run $0 --help for usage."
303 exit 120
304 ;;
Gilles Peskine91bd8b72019-01-08 23:01:34 +0100305 *)
306 COMPONENTS="$COMPONENTS $1";;
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100307 esac
308 shift
309 done
Gilles Peskine91bd8b72019-01-08 23:01:34 +0100310
Gilles Peskine6e984232018-11-27 21:37:53 +0100311 if [ $ALL_EXCEPT -ne 0 ]; then
312 RUN_COMPONENTS=
Gilles Peskine3fbdd212019-01-08 23:33:45 +0100313 for component in $SUPPORTED_COMPONENTS; do
Gilles Peskine6e984232018-11-27 21:37:53 +0100314 if ! is_component_excluded "$component"; then
315 RUN_COMPONENTS="$RUN_COMPONENTS $component"
316 fi
317 done
318 elif [ -z "$COMPONENTS" ]; then
319 RUN_COMPONENTS="$ALL_COMPONENTS"
320 else
321 RUN_COMPONENTS="$COMPONENTS"
Gilles Peskine91bd8b72019-01-08 23:01:34 +0100322 fi
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100323}
SimonB2e23c822016-04-16 21:54:39 +0100324
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100325pre_check_git () {
326 if [ $FORCE -eq 1 ]; then
327 if [ $YOTTA -eq 1 ]; then
328 rm -rf yotta/module "$OUT_OF_SOURCE_DIR"
329 fi
330 git checkout-index -f -q $CONFIG_H
331 cleanup
332 else
333
334 if [ $YOTTA -ne 0 ] && [ -d yotta/module ]; then
335 err_msg "Warning - there is an existing yotta module in the directory 'yotta/module'"
336 echo "You can either delete your work and retry, or force the test to overwrite the"
337 echo "test by rerunning the script as: $0 --force"
338 exit 1
339 fi
340
341 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
342 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
343 echo "You can either delete this directory manually, or force the test by rerunning"
344 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
345 exit 1
346 fi
347
348 if ! git diff-files --quiet include/mbedtls/config.h; then
349 err_msg "Warning - the configuration file 'include/mbedtls/config.h' has been edited. "
350 echo "You can either delete or preserve your work, or force the test by rerunning the"
351 echo "script as: $0 --force"
352 exit 1
353 fi
Gilles Peskineda519252017-11-30 13:22:04 +0100354 fi
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100355}
SimonB2e23c822016-04-16 21:54:39 +0100356
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100357pre_setup_keep_going () {
Gilles Peskine7c652162017-12-11 00:01:40 +0100358 failure_summary=
359 failure_count=0
360 start_red=
361 end_color=
362 if [ -t 1 ]; then
Gilles Peskine9736b9d2018-01-02 21:54:17 +0100363 case "${TERM:-}" in
Gilles Peskine7c652162017-12-11 00:01:40 +0100364 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
365 start_red=$(printf '\033[31m')
366 end_color=$(printf '\033[0m')
367 ;;
368 esac
369 fi
370 record_status () {
371 if "$@"; then
372 last_status=0
373 else
374 last_status=$?
375 text="$current_section: $* -> $last_status"
376 failure_summary="$failure_summary
377$text"
378 failure_count=$((failure_count + 1))
379 echo "${start_red}^^^^$text^^^^${end_color}"
380 fi
381 }
382 make () {
383 case "$*" in
384 *test|*check)
385 if [ $build_status -eq 0 ]; then
386 record_status command make "$@"
387 else
388 echo "(skipped because the build failed)"
389 fi
390 ;;
391 *)
392 record_status command make "$@"
393 build_status=$last_status
394 ;;
395 esac
396 }
397 final_report () {
398 if [ $failure_count -gt 0 ]; then
399 echo
400 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
401 echo "${start_red}FAILED: $failure_count${end_color}$failure_summary"
402 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Jaeden Amero5113bde2018-07-20 16:42:14 +0100403 exit 1
Gilles Peskine7c652162017-12-11 00:01:40 +0100404 elif [ -z "${1-}" ]; then
405 echo "SUCCESS :)"
406 fi
407 if [ -n "${1-}" ]; then
408 echo "Killed by SIG$1."
409 fi
410 }
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100411}
412
Gilles Peskine7c652162017-12-11 00:01:40 +0100413if_build_succeeded () {
414 if [ $build_status -eq 0 ]; then
415 record_status "$@"
416 fi
417}
418
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100419pre_print_configuration () {
420 msg "info: $0 configuration"
421 echo "MEMORY: $MEMORY"
422 echo "FORCE: $FORCE"
423 echo "SEED: ${SEED-"UNSET"}"
424 echo "OPENSSL: $OPENSSL"
425 echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
426 echo "GNUTLS_CLI: $GNUTLS_CLI"
427 echo "GNUTLS_SERV: $GNUTLS_SERV"
428 echo "GNUTLS_LEGACY_CLI: $GNUTLS_LEGACY_CLI"
429 echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV"
430 echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
431 echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
432}
Andres AG7770ea82016-10-10 15:46:20 +0100433
Andres AGd9eba4b2016-08-26 14:42:14 +0100434# Make sure the tools we need are available.
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100435pre_check_tools () {
436 ARMC5_CC="$ARMC5_BIN_DIR/armcc"
437 ARMC5_AR="$ARMC5_BIN_DIR/armar"
438 ARMC6_CC="$ARMC6_BIN_DIR/armclang"
439 ARMC6_AR="$ARMC6_BIN_DIR/armar"
440
441 # To avoid setting OpenSSL and GnuTLS for each call to compat.sh and ssl-opt.sh
442 # we just export the variables they require
443 export OPENSSL_CMD="$OPENSSL"
444 export GNUTLS_CLI="$GNUTLS_CLI"
445 export GNUTLS_SERV="$GNUTLS_SERV"
446
447 # Avoid passing --seed flag in every call to ssl-opt.sh
448 if [ -n "${SEED-}" ]; then
449 export SEED
450 fi
451
452 check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$GNUTLS_CLI" "$GNUTLS_SERV" \
453 "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV" "doxygen" "dot" \
454 "arm-none-eabi-gcc" "i686-w64-mingw32-gcc"
455 if [ $RUN_ARMCC -ne 0 ]; then
456 check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC6_CC" "$ARMC6_AR"
457 fi
458
459 msg "info: output_env.sh"
460 OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY" GNUTLS_CLI="$GNUTLS_CLI" \
461 GNUTLS_SERV="$GNUTLS_SERV" GNUTLS_LEGACY_CLI="$GNUTLS_LEGACY_CLI" \
462 GNUTLS_LEGACY_SERV="$GNUTLS_LEGACY_SERV" ARMC5_CC="$ARMC5_CC" \
463 ARMC6_CC="$ARMC6_CC" RUN_ARMCC="$RUN_ARMCC" scripts/output_env.sh
464}
Andres AGd9eba4b2016-08-26 14:42:14 +0100465
Gilles Peskine192c72f2017-12-21 15:59:21 +0100466
467
468################################################################
469#### Basic checks
470################################################################
SimonB2e23c822016-04-16 21:54:39 +0100471
472#
473# Test Suites to be executed
474#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200475# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100476# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard61bc57a2014-08-14 11:29:06 +0200477# and/or are more likely to fail than others (eg I use Clang most of the
478# time, so start with a GCC build).
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200479# 2. Minimize total running time, by avoiding useless rebuilds
480#
481# Indicative running times are given for reference.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100482
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100483component_check_recursion () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100484 msg "test: recursion.pl" # < 1s
485 record_status tests/scripts/recursion.pl library/*.c
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100486}
Manuel Pégourié-Gonnardea29d152014-11-20 17:32:33 +0100487
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100488component_check_generated_files () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100489 msg "test: freshness of generated source files" # < 1s
490 record_status tests/scripts/check-generated-files.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100491}
Manuel Pégourié-Gonnardb3b8e432015-02-13 14:52:19 +0000492
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100493component_check_doxy_blocks () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100494 msg "test: doxygen markup outside doxygen blocks" # < 1s
495 record_status tests/scripts/check-doxy-blocks.pl
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100496}
Manuel Pégourié-Gonnardd09a6b52015-04-09 17:19:23 +0200497
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100498component_check_files () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100499 msg "test: check-files.py" # < 1s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100500 record_status tests/scripts/check-files.py
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100501}
Manuel Pégourié-Gonnard77d56bb2015-07-28 15:00:37 +0200502
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100503component_check_names () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100504 msg "test/build: declared and exported names" # < 3s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100505 record_status tests/scripts/check-names.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100506}
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +0200507
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100508component_check_doxygen_warnings () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100509 msg "test: doxygen warnings" # ~ 3s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100510 record_status tests/scripts/doxygen.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100511}
Andres Amaya Garciadd29c2f2017-05-04 11:35:51 +0100512
Simon Butcher948f2642018-07-20 21:27:33 +0100513
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100514################################################################
515#### Build and test many configurations and targets
516################################################################
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100517
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100518component_build_yotta () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100519 if [ $RUN_ARMCC -ne 0 ] && [ $YOTTA -ne 0 ]; then
520 # Note - use of yotta is deprecated, and yotta also requires armcc to be on the
521 # path, and uses whatever version of armcc it finds there.
522 msg "build: create and build yotta module" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100523 record_status tests/scripts/yotta-build.sh
524 fi
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100525}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100526
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100527component_test_default_cmake_gcc_asan () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100528 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100529 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100530 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +0200531
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100532 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100533 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100534
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100535 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
Gilles Peskine7c652162017-12-11 00:01:40 +0100536 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100537
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100538 msg "test: compat.sh (ASan build)" # ~ 6 min
539 if_build_succeeded tests/compat.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100540}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000541
Gilles Peskine3484ed82019-01-08 22:51:19 +0100542component_test_ref_configs () {
543 msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
544 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
545 record_status tests/scripts/test-ref-configs.pl
546}
547
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100548component_test_sslv3 () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100549 msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100550 scripts/config.pl set MBEDTLS_SSL_PROTO_SSL3
551 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
552 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000553
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100554 msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
555 make test
556
557 msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
558 if_build_succeeded tests/compat.sh -m 'tls1 tls1_1 tls1_2 dtls1 dtls1_2'
559 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
560
561 msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
562 if_build_succeeded tests/ssl-opt.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100563}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100564
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100565component_test_no_renegotiation () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100566 msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100567 scripts/config.pl unset MBEDTLS_SSL_RENEGOTIATION
568 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
569 make
570
571 msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
572 make test
573
574 msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
575 if_build_succeeded tests/ssl-opt.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100576}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100577
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100578component_test_rsa_no_crt () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100579 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100580 scripts/config.pl set MBEDTLS_RSA_NO_CRT
581 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
582 make
583
584 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
585 make test
586
587 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
588 if_build_succeeded tests/ssl-opt.sh -f RSA
589
590 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
591 if_build_succeeded tests/compat.sh -t RSA
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100592}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100593
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100594component_test_full_cmake_clang () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100595 msg "build: cmake, full config, clang" # ~ 50s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100596 scripts/config.pl full
597 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
598 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check -D ENABLE_TESTING=On .
599 make
600
601 msg "test: main suites (full config)" # ~ 5s
602 make test
603
604 msg "test: ssl-opt.sh default (full config)" # ~ 1s
605 if_build_succeeded tests/ssl-opt.sh -f Default
606
607 msg "test: compat.sh RC4, DES & NULL (full config)" # ~ 2 min
608 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 +0100609}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100610
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100611component_build_deprecated () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100612 msg "build: make, full config + DEPRECATED_WARNING, gcc -O" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100613 scripts/config.pl full
614 scripts/config.pl set MBEDTLS_DEPRECATED_WARNING
615 # Build with -O -Wextra to catch a maximum of issues.
616 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra' lib programs
617 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
618
619 msg "build: make, full config + DEPRECATED_REMOVED, clang -O" # ~ 30s
620 # No cleanup, just tweak the configuration and rebuild
621 make clean
622 scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
623 scripts/config.pl set MBEDTLS_DEPRECATED_REMOVED
624 # Build with -O -Wextra to catch a maximum of issues.
625 make CC=clang CFLAGS='-O -Werror -Wall -Wextra' lib programs
626 make CC=clang CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100627}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100628
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100629component_test_depends_curves () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100630 msg "test/build: curves.pl (gcc)" # ~ 4 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100631 record_status tests/scripts/curves.pl
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100632}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100633
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100634component_test_depends_hashes () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100635 msg "test/build: depends-hashes.pl (gcc)" # ~ 2 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100636 record_status tests/scripts/depends-hashes.pl
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100637}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100638
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100639component_test_depends_pkalgs () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100640 msg "test/build: depends-pkalgs.pl (gcc)" # ~ 2 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100641 record_status tests/scripts/depends-pkalgs.pl
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100642}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100643
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100644component_build_key_exchanges () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100645 msg "test/build: key-exchanges (gcc)" # ~ 1 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100646 record_status tests/scripts/key-exchanges.pl
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100647}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100648
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100649component_build_default_make_gcc () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100650 msg "build: Unix make, -Os (gcc)" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100651 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100652}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100653
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100654component_test_no_platform () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100655 # Full configuration build, without platform support, file IO and net sockets.
656 # This should catch missing mbedtls_printf definitions, and by disabling file
657 # IO, it should catch missing '#include <stdio.h>'
658 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100659 scripts/config.pl full
660 scripts/config.pl unset MBEDTLS_PLATFORM_C
661 scripts/config.pl unset MBEDTLS_NET_C
662 scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
663 scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
664 scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
665 scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
666 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
667 scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
668 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
669 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
670 scripts/config.pl unset MBEDTLS_FS_IO
671 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
672 # to re-enable platform integration features otherwise disabled in C99 builds
673 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -O0 -D_DEFAULT_SOURCE' lib programs
674 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0' test
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100675}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100676
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100677component_build_no_std_function () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100678 # catch compile bugs in _uninit functions
679 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100680 scripts/config.pl full
681 scripts/config.pl set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
682 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
683 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100684}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100685
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100686component_build_no_ssl_srv () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100687 msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100688 scripts/config.pl full
689 scripts/config.pl unset MBEDTLS_SSL_SRV_C
690 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100691}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100692
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100693component_build_no_ssl_cli () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100694 msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100695 scripts/config.pl full
696 scripts/config.pl unset MBEDTLS_SSL_CLI_C
697 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100698}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100699
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100700component_build_no_sockets () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100701 # Note, C99 compliance can also be tested with the sockets support disabled,
702 # as that requires a POSIX platform (which isn't the same as C99).
703 msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100704 scripts/config.pl full
705 scripts/config.pl unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
706 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
707 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0 -std=c99 -pedantic' lib
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100708}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100709
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100710component_test_no_max_fragment_length () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100711 msg "build: default config except MFL extension (ASan build)" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100712 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
713 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
714 make
715
716 msg "test: ssl-opt.sh, MFL-related tests"
717 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length"
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100718}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100719
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100720component_test_null_entropy () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100721 msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100722 scripts/config.pl set MBEDTLS_TEST_NULL_ENTROPY
723 scripts/config.pl set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
724 scripts/config.pl set MBEDTLS_ENTROPY_C
725 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
726 scripts/config.pl unset MBEDTLS_ENTROPY_HARDWARE_ALT
727 scripts/config.pl unset MBEDTLS_HAVEGE_C
Gilles Peskine4e7b3232019-01-06 19:48:30 +0000728 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan -D UNSAFE_BUILD=ON .
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100729 make
730
731 msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)"
732 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100733}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100734
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100735component_test_platform_calloc_macro () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100736 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100737 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
738 scripts/config.pl set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
739 scripts/config.pl set MBEDTLS_PLATFORM_FREE_MACRO free
740 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
741 make
742
743 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
744 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100745}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100746
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100747component_test_make_shared () {
Gilles Peskine770ad7e2019-01-08 23:19:08 +0100748 msg "build/test: make shared" # ~ 40s
749 make SHARED=1 all check
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100750}
751
Gilles Peskine3fbdd212019-01-08 23:33:45 +0100752component_test_m32_o0 () {
753 # Build once with -O0, to compile out the i386 specific inline assembly
754 msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
755 scripts/config.pl full
756 make CC=gcc CFLAGS='-O0 -Werror -Wall -Wextra -m32 -fsanitize=address'
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100757
Gilles Peskine3fbdd212019-01-08 23:33:45 +0100758 msg "test: i386, make, gcc -O0 (ASan build)"
759 make test
760}
761support_test_m32_o0 () {
762 case $(uname -m) in
763 *64*) true;;
764 *) false;;
765 esac
766}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100767
Gilles Peskine3fbdd212019-01-08 23:33:45 +0100768component_test_m32_o1 () {
769 # Build again with -O1, to compile in the i386 specific inline assembly
770 msg "build: i386, make, gcc -O1 (ASan build)" # ~ 30s
771 scripts/config.pl full
772 make CC=gcc CFLAGS='-O1 -Werror -Wall -Wextra -m32 -fsanitize=address'
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100773
Gilles Peskine3fbdd212019-01-08 23:33:45 +0100774 msg "test: i386, make, gcc -O1 (ASan build)"
775 make test
776}
777support_test_m32_o1 () {
778 support_test_m32_o0 "$@"
779}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100780
Gilles Peskine3fbdd212019-01-08 23:33:45 +0100781component_test_mx32 () {
782 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
783 scripts/config.pl full
784 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32'
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100785
Gilles Peskine3fbdd212019-01-08 23:33:45 +0100786 msg "test: 64-bit ILP32, make, gcc"
787 make test
788}
789support_test_mx32 () {
790 case $(uname -m) in
791 amd64|x86_64) true;;
792 *) false;;
793 esac
794}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100795
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100796component_test_have_int32 () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100797 msg "build: gcc, force 32-bit bignum limbs"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100798 scripts/config.pl unset MBEDTLS_HAVE_ASM
799 scripts/config.pl unset MBEDTLS_AESNI_C
800 scripts/config.pl unset MBEDTLS_PADLOCK_C
801 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
802
803 msg "test: gcc, force 32-bit bignum limbs"
804 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100805}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100806
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100807component_test_have_int64 () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100808 msg "build: gcc, force 64-bit bignum limbs"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100809 scripts/config.pl unset MBEDTLS_HAVE_ASM
810 scripts/config.pl unset MBEDTLS_AESNI_C
811 scripts/config.pl unset MBEDTLS_PADLOCK_C
812 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
813
814 msg "test: gcc, force 64-bit bignum limbs"
815 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100816}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100817
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100818component_build_arm_none_eabi_gcc () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100819 msg "build: arm-none-eabi-gcc, make" # ~ 10s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100820 scripts/config.pl full
821 scripts/config.pl unset MBEDTLS_NET_C
822 scripts/config.pl unset MBEDTLS_TIMING_C
823 scripts/config.pl unset MBEDTLS_FS_IO
824 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
825 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
826 # following things are not in the default config
827 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
828 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
829 scripts/config.pl unset MBEDTLS_THREADING_C
830 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
831 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
832 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 +0100833}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100834
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100835component_build_arm_none_eabi_gcc_no_udbl_division () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100836 msg "build: arm-none-eabi-gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100837 scripts/config.pl full
838 scripts/config.pl unset MBEDTLS_NET_C
839 scripts/config.pl unset MBEDTLS_TIMING_C
840 scripts/config.pl unset MBEDTLS_FS_IO
841 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
842 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
843 # following things are not in the default config
844 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
845 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
846 scripts/config.pl unset MBEDTLS_THREADING_C
847 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
848 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
849 scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
850 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
851 echo "Checking that software 64-bit division is not required"
852 ! grep __aeabi_uldiv library/*.o
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100853}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100854
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100855component_build_armcc () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100856 msg "build: ARM Compiler 5, make"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100857 scripts/config.pl full
858 scripts/config.pl unset MBEDTLS_NET_C
859 scripts/config.pl unset MBEDTLS_TIMING_C
860 scripts/config.pl unset MBEDTLS_FS_IO
861 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
862 scripts/config.pl unset MBEDTLS_HAVE_TIME
863 scripts/config.pl unset MBEDTLS_HAVE_TIME_DATE
864 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
865 # following things are not in the default config
866 scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
867 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
868 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
869 scripts/config.pl unset MBEDTLS_THREADING_C
870 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
871 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
872 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT # depends on MBEDTLS_HAVE_TIME
873
874 if [ $RUN_ARMCC -ne 0 ]; then
875 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
876 make clean
877
878 # ARM Compiler 6 - Target ARMv7-A
879 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-a"
880
881 # ARM Compiler 6 - Target ARMv7-M
882 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m"
883
884 # ARM Compiler 6 - Target ARMv8-A - AArch32
885 armc6_build_test "--target=arm-arm-none-eabi -march=armv8.2-a"
886
887 # ARM Compiler 6 - Target ARMv8-M
888 armc6_build_test "--target=arm-arm-none-eabi -march=armv8-m.main"
889
890 # ARM Compiler 6 - Target ARMv8-A - AArch64
891 armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a"
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100892 fi
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100893}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000894
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100895component_test_allow_sha1 () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100896 msg "build: allow SHA1 in certificates by default"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100897 scripts/config.pl set MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
898 make CFLAGS='-Werror -Wall -Wextra'
899 msg "test: allow SHA1 in certificates by default"
900 make test
901 if_build_succeeded tests/ssl-opt.sh -f SHA-1
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100902}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000903
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100904component_build_mingw () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100905 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100906 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
907
908 # note Make tests only builds the tests, but doesn't run them
909 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror' WINDOWS_BUILD=1 tests
910 make WINDOWS_BUILD=1 clean
911
912 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
913 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
914 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
915 make WINDOWS_BUILD=1 clean
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100916}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100917
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100918component_test_memsan () {
Gilles Peskine770ad7e2019-01-08 23:19:08 +0100919 msg "build: MSan (clang)" # ~ 1 min 20s
920 scripts/config.pl unset MBEDTLS_AESNI_C # memsan doesn't grok asm
921 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
922 make
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100923
Gilles Peskine770ad7e2019-01-08 23:19:08 +0100924 msg "test: main suites (MSan)" # ~ 10s
925 make test
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100926
Gilles Peskine770ad7e2019-01-08 23:19:08 +0100927 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
928 if_build_succeeded tests/ssl-opt.sh
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100929
Gilles Peskine770ad7e2019-01-08 23:19:08 +0100930 # Optional part(s)
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100931
Gilles Peskine770ad7e2019-01-08 23:19:08 +0100932 if [ "$MEMORY" -gt 0 ]; then
933 msg "test: compat.sh (MSan)" # ~ 6 min 20s
934 if_build_succeeded tests/compat.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100935 fi
936}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100937
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100938component_test_memcheck () {
Gilles Peskine770ad7e2019-01-08 23:19:08 +0100939 msg "build: Release (clang)"
940 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
941 make
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100942
Gilles Peskine770ad7e2019-01-08 23:19:08 +0100943 msg "test: main suites valgrind (Release)"
944 make memcheck
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100945
Gilles Peskine770ad7e2019-01-08 23:19:08 +0100946 # Optional part(s)
947 # Currently broken, programs don't seem to receive signals
948 # under valgrind on OS X
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100949
Gilles Peskine770ad7e2019-01-08 23:19:08 +0100950 if [ "$MEMORY" -gt 0 ]; then
951 msg "test: ssl-opt.sh --memcheck (Release)"
952 if_build_succeeded tests/ssl-opt.sh --memcheck
953 fi
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100954
Gilles Peskine770ad7e2019-01-08 23:19:08 +0100955 if [ "$MEMORY" -gt 1 ]; then
956 msg "test: compat.sh --memcheck (Release)"
957 if_build_succeeded tests/compat.sh --memcheck
958 fi
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100959}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100960
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100961component_test_cmake_out_of_source () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100962 msg "build: cmake 'out-of-source' build"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100963 MBEDTLS_ROOT_DIR="$PWD"
964 mkdir "$OUT_OF_SOURCE_DIR"
965 cd "$OUT_OF_SOURCE_DIR"
966 cmake "$MBEDTLS_ROOT_DIR"
967 make
968
969 msg "test: cmake 'out-of-source' build"
970 make test
971 # Test an SSL option that requires an auxiliary script in test/scripts/.
972 # Also ensure that there are no error messages such as
973 # "No such file or directory", which would indicate that some required
974 # file is missing (ssl-opt.sh tolerates the absence of some files so
975 # may exit with status 0 but emit errors).
976 if_build_succeeded ./tests/ssl-opt.sh -f 'Fallback SCSV: beginning of list' 2>ssl-opt.err
977 if [ -s ssl-opt.err ]; then
978 cat ssl-opt.err >&2
979 record_status [ ! -s ssl-opt.err ]
980 rm ssl-opt.err
981 fi
982 cd "$MBEDTLS_ROOT_DIR"
983 rm -rf "$OUT_OF_SOURCE_DIR"
984 unset MBEDTLS_ROOT_DIR
985}
Andres AGdc192212016-08-31 17:33:13 +0100986
Gilles Peskine192c72f2017-12-21 15:59:21 +0100987
988
989################################################################
990#### Termination
991################################################################
992
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100993post_report () {
994 msg "Done, cleaning up"
995 cleanup
996
997 final_report
998}
999
1000
1001
1002################################################################
1003#### Run all the things
1004################################################################
1005
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001006# Run one component and clean up afterwards.
1007run_component () {
Gilles Peskine72adb432019-01-02 18:57:02 +01001008 # Back up the configuration in case the component modifies it.
1009 # The cleanup function will restore it.
1010 cp -p "$CONFIG_H" "$CONFIG_BAK"
Gilles Peskine11ddca62018-12-04 12:49:28 +01001011 current_component="$1"
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001012 "$@"
1013 cleanup
1014}
1015
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001016# Preliminary setup
1017pre_check_environment
1018pre_initialize_variables
1019pre_parse_command_line "$@"
1020
1021pre_check_git
1022build_status=0
1023if [ $KEEP_GOING -eq 1 ]; then
1024 pre_setup_keep_going
1025else
1026 record_status () {
1027 "$@"
1028 }
1029fi
1030pre_print_configuration
1031pre_check_tools
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001032cleanup
Gilles Peskine7c652162017-12-11 00:01:40 +01001033
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001034# Run all the test components.
Gilles Peskine6e984232018-11-27 21:37:53 +01001035for component in $RUN_COMPONENTS; do
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001036 run_component "component_$component"
1037done
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001038
1039# We're done.
1040post_report