blob: b723f02b44def443a0424f5f9cb016b4693461fc [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 Peskine57db6ff2019-01-08 22:04:31 +010094 MEMORY=0
95 FORCE=0
96 KEEP_GOING=0
Gilles Peskine57db6ff2019-01-08 22:04:31 +010097 YOTTA=1
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010098
Gilles Peskine57db6ff2019-01-08 22:04:31 +010099 # Default commands, can be overriden by the environment
100 : ${OPENSSL:="openssl"}
101 : ${OPENSSL_LEGACY:="$OPENSSL"}
102 : ${GNUTLS_CLI:="gnutls-cli"}
103 : ${GNUTLS_SERV:="gnutls-serv"}
104 : ${GNUTLS_LEGACY_CLI:="$GNUTLS_CLI"}
105 : ${GNUTLS_LEGACY_SERV:="$GNUTLS_SERV"}
106 : ${OUT_OF_SOURCE_DIR:=./mbedtls_out_of_source_build}
107 : ${ARMC5_BIN_DIR:=/usr/bin}
108 : ${ARMC6_BIN_DIR:=/usr/bin}
Andres AGdc192212016-08-31 17:33:13 +0100109
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100110 # if MAKEFLAGS is not set add the -j option to speed up invocations of make
Gilles Peskine7120f772019-01-06 20:15:26 +0000111 if [ -z "${MAKEFLAGS+set}" ]; then
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100112 export MAKEFLAGS="-j"
113 fi
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100114
115 # Gather the list of available components. These are the functions
116 # defined in this script whose name starts with "component_".
117 # Parse the script with sed, because in sh there is no way to list
118 # defined functions.
119 ALL_COMPONENTS=$(sed -n 's/^ *component_\([0-9A-Z_a-z]*\) *().*/\1/p' <"$0")
Gilles Peskine3fbdd212019-01-08 23:33:45 +0100120
121 # Exclude components that are not supported on this platform.
122 SUPPORTED_COMPONENTS=
123 for component in $ALL_COMPONENTS; do
124 case $(type "support_$component" 2>&1) in
125 *' function'*)
126 if ! support_$component; then continue; fi;;
127 esac
128 SUPPORTED_COMPONENTS="$SUPPORTED_COMPONENTS $component"
129 done
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100130}
Andres AG38495a32016-07-12 16:54:33 +0100131
Gilles Peskine3fbdd212019-01-08 23:33:45 +0100132# Test whether $1 is excluded via the command line.
Gilles Peskine6e984232018-11-27 21:37:53 +0100133is_component_excluded()
134{
Gilles Peskine3fbdd212019-01-08 23:33:45 +0100135 # Is $1 excluded via $COMPONENTS (a space-separated list of wildcard
136 # patterns)?
Gilles Peskine6e984232018-11-27 21:37:53 +0100137 set -f
Gilles Peskineeb39b9b2019-01-08 23:41:00 +0100138 for pattern in $COMMAND_LINE_COMPONENTS; do
Gilles Peskine6e984232018-11-27 21:37:53 +0100139 set +f
140 case ${1#component_} in $pattern) return 0;; esac
141 done
142 set +f
143 return 1
144}
145
Simon Butcher41eeccf2016-09-07 00:07:09 +0100146usage()
SimonB2e23c822016-04-16 21:54:39 +0100147{
Gilles Peskine709346a2017-12-10 23:43:39 +0100148 cat <<EOF
Gilles Peskine91bd8b72019-01-08 23:01:34 +0100149Usage: $0 [OPTION]... [COMPONENT]...
150Run mbedtls release validation tests.
151By default, run all tests. With one or more COMPONENT, run only those.
152
153Special options:
154 -h|--help Print this help and exit.
Gilles Peskineb3241cb2019-01-08 23:44:07 +0100155 --list-all-components List all available test components and exit.
156 --list-components List components supported on this platform 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 Peskineeb39b9b2019-01-08 23:41:00 +0100272 COMMAND_LINE_COMPONENTS=
273 all_except=
Gilles Peskine53084872019-01-09 23:13:54 +0100274 no_armcc=
Gilles Peskine6e984232018-11-27 21:37:53 +0100275
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100276 while [ $# -gt 0 ]; do
277 case "$1" in
Gilles Peskine53084872019-01-09 23:13:54 +0100278 --armcc) no_armcc=;;
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100279 --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
280 --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
Gilles Peskineeb39b9b2019-01-08 23:41:00 +0100281 --except) all_except=1;;
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100282 --force|-f) FORCE=1;;
283 --gnutls-cli) shift; GNUTLS_CLI="$1";;
284 --gnutls-legacy-cli) shift; GNUTLS_LEGACY_CLI="$1";;
285 --gnutls-legacy-serv) shift; GNUTLS_LEGACY_SERV="$1";;
286 --gnutls-serv) shift; GNUTLS_SERV="$1";;
287 --help|-h) usage; exit;;
288 --keep-going|-k) KEEP_GOING=1;;
Gilles Peskineb3241cb2019-01-08 23:44:07 +0100289 --list-all-components) printf '%s\n' $ALL_COMPONENTS; exit;;
290 --list-components) printf '%s\n' $SUPPORTED_COMPONENTS; exit;;
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100291 --memory|-m) MEMORY=1;;
Gilles Peskine53084872019-01-09 23:13:54 +0100292 --no-armcc) no_armcc=1;;
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100293 --no-force) FORCE=0;;
294 --no-keep-going) KEEP_GOING=0;;
295 --no-memory) MEMORY=0;;
296 --no-yotta) YOTTA=0;;
297 --openssl) shift; OPENSSL="$1";;
298 --openssl-legacy) shift; OPENSSL_LEGACY="$1";;
299 --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
300 --random-seed) unset SEED;;
301 --release-test|-r) SEED=1;;
302 --seed|-s) shift; SEED="$1";;
303 --yotta) YOTTA=1;;
Gilles Peskine91bd8b72019-01-08 23:01:34 +0100304 -*)
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100305 echo >&2 "Unknown option: $1"
306 echo >&2 "Run $0 --help for usage."
307 exit 120
308 ;;
Gilles Peskineeb39b9b2019-01-08 23:41:00 +0100309 *) COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS $1";;
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100310 esac
311 shift
312 done
Gilles Peskine91bd8b72019-01-08 23:01:34 +0100313
Gilles Peskineeb39b9b2019-01-08 23:41:00 +0100314 if [ -z "$COMMAND_LINE_COMPONENTS" ]; then
315 all_except=1
316 fi
317
Gilles Peskine53084872019-01-09 23:13:54 +0100318 # --no-armcc is a legacy option. The modern way is --except '*_armcc*'.
319 # Ignore it if components are listed explicitly on the command line.
320 if [ -n "$no_armcc" ] && [ -n "$all_except" ]; then
321 COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS *_armcc*"
322 # --no-armcc also disables yotta.
323 COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS *_yotta*"
324 fi
325
Gilles Peskineeb39b9b2019-01-08 23:41:00 +0100326 # Build the list of components to run.
327 if [ -n "$all_except" ]; then
Gilles Peskine6e984232018-11-27 21:37:53 +0100328 RUN_COMPONENTS=
Gilles Peskine3fbdd212019-01-08 23:33:45 +0100329 for component in $SUPPORTED_COMPONENTS; do
Gilles Peskine6e984232018-11-27 21:37:53 +0100330 if ! is_component_excluded "$component"; then
331 RUN_COMPONENTS="$RUN_COMPONENTS $component"
332 fi
333 done
Gilles Peskine6e984232018-11-27 21:37:53 +0100334 else
Gilles Peskineeb39b9b2019-01-08 23:41:00 +0100335 RUN_COMPONENTS="$COMMAND_LINE_COMPONENTS"
Gilles Peskine91bd8b72019-01-08 23:01:34 +0100336 fi
Gilles Peskineeb39b9b2019-01-08 23:41:00 +0100337
338 unset all_except
Gilles Peskine53084872019-01-09 23:13:54 +0100339 unset no_armcc
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100340}
SimonB2e23c822016-04-16 21:54:39 +0100341
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100342pre_check_git () {
343 if [ $FORCE -eq 1 ]; then
344 if [ $YOTTA -eq 1 ]; then
345 rm -rf yotta/module "$OUT_OF_SOURCE_DIR"
346 fi
347 git checkout-index -f -q $CONFIG_H
348 cleanup
349 else
350
351 if [ $YOTTA -ne 0 ] && [ -d yotta/module ]; then
352 err_msg "Warning - there is an existing yotta module in the directory 'yotta/module'"
353 echo "You can either delete your work and retry, or force the test to overwrite the"
354 echo "test by rerunning the script as: $0 --force"
355 exit 1
356 fi
357
358 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
359 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
360 echo "You can either delete this directory manually, or force the test by rerunning"
361 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
362 exit 1
363 fi
364
365 if ! git diff-files --quiet include/mbedtls/config.h; then
366 err_msg "Warning - the configuration file 'include/mbedtls/config.h' has been edited. "
367 echo "You can either delete or preserve your work, or force the test by rerunning the"
368 echo "script as: $0 --force"
369 exit 1
370 fi
Gilles Peskineda519252017-11-30 13:22:04 +0100371 fi
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100372}
SimonB2e23c822016-04-16 21:54:39 +0100373
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100374pre_setup_keep_going () {
Gilles Peskine7c652162017-12-11 00:01:40 +0100375 failure_summary=
376 failure_count=0
377 start_red=
378 end_color=
379 if [ -t 1 ]; then
Gilles Peskine9736b9d2018-01-02 21:54:17 +0100380 case "${TERM:-}" in
Gilles Peskine7c652162017-12-11 00:01:40 +0100381 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
382 start_red=$(printf '\033[31m')
383 end_color=$(printf '\033[0m')
384 ;;
385 esac
386 fi
387 record_status () {
388 if "$@"; then
389 last_status=0
390 else
391 last_status=$?
392 text="$current_section: $* -> $last_status"
393 failure_summary="$failure_summary
394$text"
395 failure_count=$((failure_count + 1))
396 echo "${start_red}^^^^$text^^^^${end_color}"
397 fi
398 }
399 make () {
400 case "$*" in
401 *test|*check)
402 if [ $build_status -eq 0 ]; then
403 record_status command make "$@"
404 else
405 echo "(skipped because the build failed)"
406 fi
407 ;;
408 *)
409 record_status command make "$@"
410 build_status=$last_status
411 ;;
412 esac
413 }
414 final_report () {
415 if [ $failure_count -gt 0 ]; then
416 echo
417 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
418 echo "${start_red}FAILED: $failure_count${end_color}$failure_summary"
419 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Jaeden Amero5113bde2018-07-20 16:42:14 +0100420 exit 1
Gilles Peskine7c652162017-12-11 00:01:40 +0100421 elif [ -z "${1-}" ]; then
422 echo "SUCCESS :)"
423 fi
424 if [ -n "${1-}" ]; then
425 echo "Killed by SIG$1."
426 fi
427 }
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100428}
429
Gilles Peskine7c652162017-12-11 00:01:40 +0100430if_build_succeeded () {
431 if [ $build_status -eq 0 ]; then
432 record_status "$@"
433 fi
434}
435
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100436pre_print_configuration () {
437 msg "info: $0 configuration"
438 echo "MEMORY: $MEMORY"
439 echo "FORCE: $FORCE"
440 echo "SEED: ${SEED-"UNSET"}"
441 echo "OPENSSL: $OPENSSL"
442 echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
443 echo "GNUTLS_CLI: $GNUTLS_CLI"
444 echo "GNUTLS_SERV: $GNUTLS_SERV"
445 echo "GNUTLS_LEGACY_CLI: $GNUTLS_LEGACY_CLI"
446 echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV"
447 echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
448 echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
449}
Andres AG7770ea82016-10-10 15:46:20 +0100450
Andres AGd9eba4b2016-08-26 14:42:14 +0100451# Make sure the tools we need are available.
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100452pre_check_tools () {
453 ARMC5_CC="$ARMC5_BIN_DIR/armcc"
454 ARMC5_AR="$ARMC5_BIN_DIR/armar"
455 ARMC6_CC="$ARMC6_BIN_DIR/armclang"
456 ARMC6_AR="$ARMC6_BIN_DIR/armar"
457
458 # To avoid setting OpenSSL and GnuTLS for each call to compat.sh and ssl-opt.sh
459 # we just export the variables they require
460 export OPENSSL_CMD="$OPENSSL"
461 export GNUTLS_CLI="$GNUTLS_CLI"
462 export GNUTLS_SERV="$GNUTLS_SERV"
463
464 # Avoid passing --seed flag in every call to ssl-opt.sh
465 if [ -n "${SEED-}" ]; then
466 export SEED
467 fi
468
469 check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$GNUTLS_CLI" "$GNUTLS_SERV" \
470 "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV" "doxygen" "dot" \
471 "arm-none-eabi-gcc" "i686-w64-mingw32-gcc"
Gilles Peskine53084872019-01-09 23:13:54 +0100472 case $RUN_COMPONENTS in
473 *_armcc*|*_yotta*)
474 check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC6_CC" "$ARMC6_AR";;
475 esac
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100476
477 msg "info: output_env.sh"
Gilles Peskine53084872019-01-09 23:13:54 +0100478 set env
479 set "$@" OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY"
480 set "$@" GNUTLS_CLI="$GNUTLS_CLI" GNUTLS_SERV="$GNUTLS_SERV"
481 set "$@" GNUTLS_LEGACY_CLI="$GNUTLS_LEGACY_CLI" GNUTLS_LEGACY_SERV="$GNUTLS_LEGACY_SERV"
482 case $RUN_COMPONENTS in
483 *_armcc*|*_yotta*)
484 set "$@" ARMC5_CC="$ARMC5_CC" ARMC6_CC="$ARMC6_CC" RUN_ARMCC=1;;
485 *) set "$@" RUN_ARMCC=0;;
486 esac
487 "$@" scripts/output_env.sh
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100488}
Andres AGd9eba4b2016-08-26 14:42:14 +0100489
Gilles Peskine192c72f2017-12-21 15:59:21 +0100490
491
492################################################################
493#### Basic checks
494################################################################
SimonB2e23c822016-04-16 21:54:39 +0100495
496#
497# Test Suites to be executed
498#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200499# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100500# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard61bc57a2014-08-14 11:29:06 +0200501# and/or are more likely to fail than others (eg I use Clang most of the
502# time, so start with a GCC build).
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200503# 2. Minimize total running time, by avoiding useless rebuilds
504#
505# Indicative running times are given for reference.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100506
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100507component_check_recursion () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100508 msg "test: recursion.pl" # < 1s
509 record_status tests/scripts/recursion.pl library/*.c
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100510}
Manuel Pégourié-Gonnardea29d152014-11-20 17:32:33 +0100511
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100512component_check_generated_files () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100513 msg "test: freshness of generated source files" # < 1s
514 record_status tests/scripts/check-generated-files.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100515}
Manuel Pégourié-Gonnardb3b8e432015-02-13 14:52:19 +0000516
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100517component_check_doxy_blocks () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100518 msg "test: doxygen markup outside doxygen blocks" # < 1s
519 record_status tests/scripts/check-doxy-blocks.pl
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100520}
Manuel Pégourié-Gonnardd09a6b52015-04-09 17:19:23 +0200521
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100522component_check_files () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100523 msg "test: check-files.py" # < 1s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100524 record_status tests/scripts/check-files.py
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100525}
Manuel Pégourié-Gonnard77d56bb2015-07-28 15:00:37 +0200526
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100527component_check_names () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100528 msg "test/build: declared and exported names" # < 3s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100529 record_status tests/scripts/check-names.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100530}
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +0200531
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100532component_check_doxygen_warnings () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100533 msg "test: doxygen warnings" # ~ 3s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100534 record_status tests/scripts/doxygen.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100535}
Andres Amaya Garciadd29c2f2017-05-04 11:35:51 +0100536
Simon Butcher948f2642018-07-20 21:27:33 +0100537
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100538################################################################
539#### Build and test many configurations and targets
540################################################################
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100541
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100542component_build_yotta () {
Gilles Peskine53084872019-01-09 23:13:54 +0100543 # Note - use of yotta is deprecated, and yotta also requires armcc to be on the
544 # path, and uses whatever version of armcc it finds there.
545 msg "build: create and build yotta module" # ~ 30s
546 record_status tests/scripts/yotta-build.sh
547}
548support_build_yotta () {
549 [ $YOTTA -ne 0 ]
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100550}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100551
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100552component_test_default_cmake_gcc_asan () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100553 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100554 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100555 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +0200556
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100557 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100558 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100559
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100560 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
Gilles Peskine7c652162017-12-11 00:01:40 +0100561 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100562
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100563 msg "test: compat.sh (ASan build)" # ~ 6 min
564 if_build_succeeded tests/compat.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100565}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000566
Gilles Peskine3484ed82019-01-08 22:51:19 +0100567component_test_ref_configs () {
568 msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
569 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
570 record_status tests/scripts/test-ref-configs.pl
571}
572
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100573component_test_sslv3 () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100574 msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100575 scripts/config.pl set MBEDTLS_SSL_PROTO_SSL3
576 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
577 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000578
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100579 msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
580 make test
581
582 msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
583 if_build_succeeded tests/compat.sh -m 'tls1 tls1_1 tls1_2 dtls1 dtls1_2'
584 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
585
586 msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
587 if_build_succeeded tests/ssl-opt.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100588}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100589
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100590component_test_no_renegotiation () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100591 msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100592 scripts/config.pl unset MBEDTLS_SSL_RENEGOTIATION
593 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
594 make
595
596 msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
597 make test
598
599 msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
600 if_build_succeeded tests/ssl-opt.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100601}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100602
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100603component_test_rsa_no_crt () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100604 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100605 scripts/config.pl set MBEDTLS_RSA_NO_CRT
606 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
607 make
608
609 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
610 make test
611
612 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
613 if_build_succeeded tests/ssl-opt.sh -f RSA
614
615 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
616 if_build_succeeded tests/compat.sh -t RSA
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100617}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100618
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100619component_test_full_cmake_clang () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100620 msg "build: cmake, full config, clang" # ~ 50s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100621 scripts/config.pl full
622 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
623 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check -D ENABLE_TESTING=On .
624 make
625
626 msg "test: main suites (full config)" # ~ 5s
627 make test
628
629 msg "test: ssl-opt.sh default (full config)" # ~ 1s
630 if_build_succeeded tests/ssl-opt.sh -f Default
631
632 msg "test: compat.sh RC4, DES & NULL (full config)" # ~ 2 min
633 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 +0100634}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100635
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100636component_build_deprecated () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100637 msg "build: make, full config + DEPRECATED_WARNING, gcc -O" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100638 scripts/config.pl full
639 scripts/config.pl set MBEDTLS_DEPRECATED_WARNING
640 # Build with -O -Wextra to catch a maximum of issues.
641 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra' lib programs
642 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
643
644 msg "build: make, full config + DEPRECATED_REMOVED, clang -O" # ~ 30s
645 # No cleanup, just tweak the configuration and rebuild
646 make clean
647 scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
648 scripts/config.pl set MBEDTLS_DEPRECATED_REMOVED
649 # Build with -O -Wextra to catch a maximum of issues.
650 make CC=clang CFLAGS='-O -Werror -Wall -Wextra' lib programs
651 make CC=clang CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
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_depends_curves () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100655 msg "test/build: curves.pl (gcc)" # ~ 4 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100656 record_status tests/scripts/curves.pl
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100657}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100658
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100659component_test_depends_hashes () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100660 msg "test/build: depends-hashes.pl (gcc)" # ~ 2 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100661 record_status tests/scripts/depends-hashes.pl
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100662}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100663
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100664component_test_depends_pkalgs () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100665 msg "test/build: depends-pkalgs.pl (gcc)" # ~ 2 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100666 record_status tests/scripts/depends-pkalgs.pl
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100667}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100668
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100669component_build_key_exchanges () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100670 msg "test/build: key-exchanges (gcc)" # ~ 1 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100671 record_status tests/scripts/key-exchanges.pl
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100672}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100673
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100674component_build_default_make_gcc () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100675 msg "build: Unix make, -Os (gcc)" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100676 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100677}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100678
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100679component_test_no_platform () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100680 # Full configuration build, without platform support, file IO and net sockets.
681 # This should catch missing mbedtls_printf definitions, and by disabling file
682 # IO, it should catch missing '#include <stdio.h>'
683 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100684 scripts/config.pl full
685 scripts/config.pl unset MBEDTLS_PLATFORM_C
686 scripts/config.pl unset MBEDTLS_NET_C
687 scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
688 scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
689 scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
690 scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
691 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
692 scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
693 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
694 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
695 scripts/config.pl unset MBEDTLS_FS_IO
696 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
697 # to re-enable platform integration features otherwise disabled in C99 builds
698 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -O0 -D_DEFAULT_SOURCE' lib programs
699 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0' test
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100700}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100701
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100702component_build_no_std_function () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100703 # catch compile bugs in _uninit functions
704 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100705 scripts/config.pl full
706 scripts/config.pl set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
707 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
708 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100709}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100710
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100711component_build_no_ssl_srv () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100712 msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100713 scripts/config.pl full
714 scripts/config.pl unset MBEDTLS_SSL_SRV_C
715 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100716}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100717
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100718component_build_no_ssl_cli () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100719 msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100720 scripts/config.pl full
721 scripts/config.pl unset MBEDTLS_SSL_CLI_C
722 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100723}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100724
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100725component_build_no_sockets () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100726 # Note, C99 compliance can also be tested with the sockets support disabled,
727 # as that requires a POSIX platform (which isn't the same as C99).
728 msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100729 scripts/config.pl full
730 scripts/config.pl unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
731 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
732 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0 -std=c99 -pedantic' lib
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_no_max_fragment_length () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100736 msg "build: default config except MFL extension (ASan build)" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100737 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
738 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
739 make
740
741 msg "test: ssl-opt.sh, MFL-related tests"
742 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length"
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100743}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100744
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100745component_test_null_entropy () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100746 msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100747 scripts/config.pl set MBEDTLS_TEST_NULL_ENTROPY
748 scripts/config.pl set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
749 scripts/config.pl set MBEDTLS_ENTROPY_C
750 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
751 scripts/config.pl unset MBEDTLS_ENTROPY_HARDWARE_ALT
752 scripts/config.pl unset MBEDTLS_HAVEGE_C
Gilles Peskine4e7b3232019-01-06 19:48:30 +0000753 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan -D UNSAFE_BUILD=ON .
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100754 make
755
756 msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)"
757 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100758}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100759
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100760component_test_platform_calloc_macro () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100761 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100762 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
763 scripts/config.pl set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
764 scripts/config.pl set MBEDTLS_PLATFORM_FREE_MACRO free
765 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
766 make
767
768 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
769 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100770}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100771
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100772component_test_make_shared () {
Gilles Peskine770ad7e2019-01-08 23:19:08 +0100773 msg "build/test: make shared" # ~ 40s
774 make SHARED=1 all check
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100775}
776
Gilles Peskine3fbdd212019-01-08 23:33:45 +0100777component_test_m32_o0 () {
778 # Build once with -O0, to compile out the i386 specific inline assembly
779 msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
780 scripts/config.pl full
781 make CC=gcc CFLAGS='-O0 -Werror -Wall -Wextra -m32 -fsanitize=address'
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100782
Gilles Peskine3fbdd212019-01-08 23:33:45 +0100783 msg "test: i386, make, gcc -O0 (ASan build)"
784 make test
785}
786support_test_m32_o0 () {
787 case $(uname -m) in
788 *64*) true;;
789 *) false;;
790 esac
791}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100792
Gilles Peskine3fbdd212019-01-08 23:33:45 +0100793component_test_m32_o1 () {
794 # Build again with -O1, to compile in the i386 specific inline assembly
795 msg "build: i386, make, gcc -O1 (ASan build)" # ~ 30s
796 scripts/config.pl full
797 make CC=gcc CFLAGS='-O1 -Werror -Wall -Wextra -m32 -fsanitize=address'
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100798
Gilles Peskine3fbdd212019-01-08 23:33:45 +0100799 msg "test: i386, make, gcc -O1 (ASan build)"
800 make test
801}
802support_test_m32_o1 () {
803 support_test_m32_o0 "$@"
804}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100805
Gilles Peskine3fbdd212019-01-08 23:33:45 +0100806component_test_mx32 () {
807 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
808 scripts/config.pl full
809 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32'
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100810
Gilles Peskine3fbdd212019-01-08 23:33:45 +0100811 msg "test: 64-bit ILP32, make, gcc"
812 make test
813}
814support_test_mx32 () {
815 case $(uname -m) in
816 amd64|x86_64) true;;
817 *) false;;
818 esac
819}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100820
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100821component_test_have_int32 () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100822 msg "build: gcc, force 32-bit bignum limbs"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100823 scripts/config.pl unset MBEDTLS_HAVE_ASM
824 scripts/config.pl unset MBEDTLS_AESNI_C
825 scripts/config.pl unset MBEDTLS_PADLOCK_C
826 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
827
828 msg "test: gcc, force 32-bit bignum limbs"
829 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100830}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100831
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100832component_test_have_int64 () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100833 msg "build: gcc, force 64-bit bignum limbs"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100834 scripts/config.pl unset MBEDTLS_HAVE_ASM
835 scripts/config.pl unset MBEDTLS_AESNI_C
836 scripts/config.pl unset MBEDTLS_PADLOCK_C
837 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
838
839 msg "test: gcc, force 64-bit bignum limbs"
840 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100841}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100842
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100843component_build_arm_none_eabi_gcc () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100844 msg "build: arm-none-eabi-gcc, make" # ~ 10s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100845 scripts/config.pl full
846 scripts/config.pl unset MBEDTLS_NET_C
847 scripts/config.pl unset MBEDTLS_TIMING_C
848 scripts/config.pl unset MBEDTLS_FS_IO
849 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
850 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
851 # following things are not in the default config
852 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
853 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
854 scripts/config.pl unset MBEDTLS_THREADING_C
855 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
856 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
857 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 +0100858}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100859
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100860component_build_arm_none_eabi_gcc_no_udbl_division () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100861 msg "build: arm-none-eabi-gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100862 scripts/config.pl full
863 scripts/config.pl unset MBEDTLS_NET_C
864 scripts/config.pl unset MBEDTLS_TIMING_C
865 scripts/config.pl unset MBEDTLS_FS_IO
866 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
867 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
868 # following things are not in the default config
869 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
870 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
871 scripts/config.pl unset MBEDTLS_THREADING_C
872 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
873 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
874 scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
875 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
876 echo "Checking that software 64-bit division is not required"
877 ! grep __aeabi_uldiv library/*.o
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100878}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100879
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100880component_build_armcc () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100881 msg "build: ARM Compiler 5, make"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100882 scripts/config.pl full
883 scripts/config.pl unset MBEDTLS_NET_C
884 scripts/config.pl unset MBEDTLS_TIMING_C
885 scripts/config.pl unset MBEDTLS_FS_IO
886 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
887 scripts/config.pl unset MBEDTLS_HAVE_TIME
888 scripts/config.pl unset MBEDTLS_HAVE_TIME_DATE
889 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
890 # following things are not in the default config
891 scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
892 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
893 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
894 scripts/config.pl unset MBEDTLS_THREADING_C
895 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
896 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
897 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT # depends on MBEDTLS_HAVE_TIME
898
Gilles Peskine53084872019-01-09 23:13:54 +0100899 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
900 make clean
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100901
Gilles Peskine53084872019-01-09 23:13:54 +0100902 # ARM Compiler 6 - Target ARMv7-A
903 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-a"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100904
Gilles Peskine53084872019-01-09 23:13:54 +0100905 # ARM Compiler 6 - Target ARMv7-M
906 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100907
Gilles Peskine53084872019-01-09 23:13:54 +0100908 # ARM Compiler 6 - Target ARMv8-A - AArch32
909 armc6_build_test "--target=arm-arm-none-eabi -march=armv8.2-a"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100910
Gilles Peskine53084872019-01-09 23:13:54 +0100911 # ARM Compiler 6 - Target ARMv8-M
912 armc6_build_test "--target=arm-arm-none-eabi -march=armv8-m.main"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100913
Gilles Peskine53084872019-01-09 23:13:54 +0100914 # ARM Compiler 6 - Target ARMv8-A - AArch64
915 armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a"
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100916}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000917
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100918component_test_allow_sha1 () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100919 msg "build: allow SHA1 in certificates by default"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100920 scripts/config.pl set MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
921 make CFLAGS='-Werror -Wall -Wextra'
922 msg "test: allow SHA1 in certificates by default"
923 make test
924 if_build_succeeded tests/ssl-opt.sh -f SHA-1
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100925}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000926
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100927component_build_mingw () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100928 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100929 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
930
931 # note Make tests only builds the tests, but doesn't run them
932 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror' WINDOWS_BUILD=1 tests
933 make WINDOWS_BUILD=1 clean
934
935 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
936 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
937 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
938 make WINDOWS_BUILD=1 clean
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100939}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100940
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100941component_test_memsan () {
Gilles Peskine770ad7e2019-01-08 23:19:08 +0100942 msg "build: MSan (clang)" # ~ 1 min 20s
943 scripts/config.pl unset MBEDTLS_AESNI_C # memsan doesn't grok asm
944 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
945 make
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100946
Gilles Peskine770ad7e2019-01-08 23:19:08 +0100947 msg "test: main suites (MSan)" # ~ 10s
948 make test
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100949
Gilles Peskine770ad7e2019-01-08 23:19:08 +0100950 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
951 if_build_succeeded tests/ssl-opt.sh
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100952
Gilles Peskine770ad7e2019-01-08 23:19:08 +0100953 # Optional part(s)
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100954
Gilles Peskine770ad7e2019-01-08 23:19:08 +0100955 if [ "$MEMORY" -gt 0 ]; then
956 msg "test: compat.sh (MSan)" # ~ 6 min 20s
957 if_build_succeeded tests/compat.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100958 fi
959}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100960
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100961component_test_memcheck () {
Gilles Peskine770ad7e2019-01-08 23:19:08 +0100962 msg "build: Release (clang)"
963 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
964 make
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100965
Gilles Peskine770ad7e2019-01-08 23:19:08 +0100966 msg "test: main suites valgrind (Release)"
967 make memcheck
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100968
Gilles Peskine770ad7e2019-01-08 23:19:08 +0100969 # Optional part(s)
970 # Currently broken, programs don't seem to receive signals
971 # under valgrind on OS X
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100972
Gilles Peskine770ad7e2019-01-08 23:19:08 +0100973 if [ "$MEMORY" -gt 0 ]; then
974 msg "test: ssl-opt.sh --memcheck (Release)"
975 if_build_succeeded tests/ssl-opt.sh --memcheck
976 fi
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100977
Gilles Peskine770ad7e2019-01-08 23:19:08 +0100978 if [ "$MEMORY" -gt 1 ]; then
979 msg "test: compat.sh --memcheck (Release)"
980 if_build_succeeded tests/compat.sh --memcheck
981 fi
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100982}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100983
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100984component_test_cmake_out_of_source () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100985 msg "build: cmake 'out-of-source' build"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100986 MBEDTLS_ROOT_DIR="$PWD"
987 mkdir "$OUT_OF_SOURCE_DIR"
988 cd "$OUT_OF_SOURCE_DIR"
989 cmake "$MBEDTLS_ROOT_DIR"
990 make
991
992 msg "test: cmake 'out-of-source' build"
993 make test
994 # Test an SSL option that requires an auxiliary script in test/scripts/.
995 # Also ensure that there are no error messages such as
996 # "No such file or directory", which would indicate that some required
997 # file is missing (ssl-opt.sh tolerates the absence of some files so
998 # may exit with status 0 but emit errors).
999 if_build_succeeded ./tests/ssl-opt.sh -f 'Fallback SCSV: beginning of list' 2>ssl-opt.err
1000 if [ -s ssl-opt.err ]; then
1001 cat ssl-opt.err >&2
1002 record_status [ ! -s ssl-opt.err ]
1003 rm ssl-opt.err
1004 fi
1005 cd "$MBEDTLS_ROOT_DIR"
1006 rm -rf "$OUT_OF_SOURCE_DIR"
1007 unset MBEDTLS_ROOT_DIR
1008}
Andres AGdc192212016-08-31 17:33:13 +01001009
Gilles Peskine192c72f2017-12-21 15:59:21 +01001010
1011
1012################################################################
1013#### Termination
1014################################################################
1015
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001016post_report () {
1017 msg "Done, cleaning up"
1018 cleanup
1019
1020 final_report
1021}
1022
1023
1024
1025################################################################
1026#### Run all the things
1027################################################################
1028
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001029# Run one component and clean up afterwards.
1030run_component () {
Gilles Peskine72adb432019-01-02 18:57:02 +01001031 # Back up the configuration in case the component modifies it.
1032 # The cleanup function will restore it.
1033 cp -p "$CONFIG_H" "$CONFIG_BAK"
Gilles Peskine11ddca62018-12-04 12:49:28 +01001034 current_component="$1"
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001035 "$@"
1036 cleanup
1037}
1038
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001039# Preliminary setup
1040pre_check_environment
1041pre_initialize_variables
1042pre_parse_command_line "$@"
1043
1044pre_check_git
1045build_status=0
1046if [ $KEEP_GOING -eq 1 ]; then
1047 pre_setup_keep_going
1048else
1049 record_status () {
1050 "$@"
1051 }
1052fi
1053pre_print_configuration
1054pre_check_tools
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001055cleanup
Gilles Peskine7c652162017-12-11 00:01:40 +01001056
Gilles Peskineeb39b9b2019-01-08 23:41:00 +01001057# Run the requested tests.
Gilles Peskine6e984232018-11-27 21:37:53 +01001058for component in $RUN_COMPONENTS; do
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001059 run_component "component_$component"
1060done
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001061
1062# We're done.
1063post_report