blob: 1d92c80427f13e280edcf525637b0097b64f036a [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 () {
Gilles Peskine541fb1e2019-01-06 22:40:00 +0000453 # Build the list of variables to pass to output_env.sh.
454 set env
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100455
Gilles Peskine541fb1e2019-01-06 22:40:00 +0000456 case " $RUN_COMPONENTS " in
457 # Require OpenSSL and GnuTLS if running any tests (as opposed to
458 # only doing builds). Not all tests run OpenSSL and GnuTLS, but this
459 # is a good enough approximation in practice.
460 *" test_"*)
461 # To avoid setting OpenSSL and GnuTLS for each call to compat.sh
462 # and ssl-opt.sh, we just export the variables they require.
463 export OPENSSL_CMD="$OPENSSL"
464 export GNUTLS_CLI="$GNUTLS_CLI"
465 export GNUTLS_SERV="$GNUTLS_SERV"
466 # Avoid passing --seed flag in every call to ssl-opt.sh
467 if [ -n "${SEED-}" ]; then
468 export SEED
469 fi
470 set "$@" OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY"
471 set "$@" GNUTLS_CLI="$GNUTLS_CLI" GNUTLS_SERV="$GNUTLS_SERV"
472 set "$@" GNUTLS_LEGACY_CLI="$GNUTLS_LEGACY_CLI"
473 set "$@" GNUTLS_LEGACY_SERV="$GNUTLS_LEGACY_SERV"
474 check_tools "$OPENSSL" "$OPENSSL_LEGACY" \
475 "$GNUTLS_CLI" "$GNUTLS_SERV" \
476 "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV"
477 ;;
478 esac
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100479
Gilles Peskine541fb1e2019-01-06 22:40:00 +0000480 case " $RUN_COMPONENTS " in
481 *_doxygen[_\ ]*) check_tools "doxygen" "dot";;
482 esac
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100483
Gilles Peskine541fb1e2019-01-06 22:40:00 +0000484 case " $RUN_COMPONENTS " in
485 *_arm_none_eabi_gcc[_\ ]*) check_tools "arm-none-eabi-gcc";;
486 esac
487
488 case " $RUN_COMPONENTS " in
489 *_mingw[_\ ]*) check_tools "i686-w64-mingw32-gcc";;
490 esac
491
492 case " $RUN_COMPONENTS " in
Gilles Peskine53084872019-01-09 23:13:54 +0100493 *_armcc*|*_yotta*)
Gilles Peskine541fb1e2019-01-06 22:40:00 +0000494 ARMC5_CC="$ARMC5_BIN_DIR/armcc"
495 ARMC5_AR="$ARMC5_BIN_DIR/armar"
496 ARMC6_CC="$ARMC6_BIN_DIR/armclang"
497 ARMC6_AR="$ARMC6_BIN_DIR/armar"
Gilles Peskine53084872019-01-09 23:13:54 +0100498 check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC6_CC" "$ARMC6_AR";;
499 esac
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100500
501 msg "info: output_env.sh"
Gilles Peskine53084872019-01-09 23:13:54 +0100502 case $RUN_COMPONENTS in
503 *_armcc*|*_yotta*)
504 set "$@" ARMC5_CC="$ARMC5_CC" ARMC6_CC="$ARMC6_CC" RUN_ARMCC=1;;
505 *) set "$@" RUN_ARMCC=0;;
506 esac
507 "$@" scripts/output_env.sh
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100508}
Andres AGd9eba4b2016-08-26 14:42:14 +0100509
Gilles Peskine192c72f2017-12-21 15:59:21 +0100510
511
512################################################################
513#### Basic checks
514################################################################
SimonB2e23c822016-04-16 21:54:39 +0100515
516#
517# Test Suites to be executed
518#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200519# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100520# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard61bc57a2014-08-14 11:29:06 +0200521# and/or are more likely to fail than others (eg I use Clang most of the
522# time, so start with a GCC build).
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200523# 2. Minimize total running time, by avoiding useless rebuilds
524#
525# Indicative running times are given for reference.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100526
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100527component_check_recursion () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100528 msg "test: recursion.pl" # < 1s
529 record_status tests/scripts/recursion.pl library/*.c
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100530}
Manuel Pégourié-Gonnardea29d152014-11-20 17:32:33 +0100531
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100532component_check_generated_files () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100533 msg "test: freshness of generated source files" # < 1s
534 record_status tests/scripts/check-generated-files.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100535}
Manuel Pégourié-Gonnardb3b8e432015-02-13 14:52:19 +0000536
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100537component_check_doxy_blocks () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100538 msg "test: doxygen markup outside doxygen blocks" # < 1s
539 record_status tests/scripts/check-doxy-blocks.pl
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100540}
Manuel Pégourié-Gonnardd09a6b52015-04-09 17:19:23 +0200541
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100542component_check_files () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100543 msg "test: check-files.py" # < 1s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100544 record_status tests/scripts/check-files.py
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100545}
Manuel Pégourié-Gonnard77d56bb2015-07-28 15:00:37 +0200546
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100547component_check_names () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100548 msg "test/build: declared and exported names" # < 3s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100549 record_status tests/scripts/check-names.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100550}
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +0200551
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100552component_check_doxygen_warnings () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100553 msg "test: doxygen warnings" # ~ 3s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100554 record_status tests/scripts/doxygen.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100555}
Andres Amaya Garciadd29c2f2017-05-04 11:35:51 +0100556
Simon Butcher948f2642018-07-20 21:27:33 +0100557
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100558################################################################
559#### Build and test many configurations and targets
560################################################################
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100561
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100562component_build_yotta () {
Gilles Peskine53084872019-01-09 23:13:54 +0100563 # Note - use of yotta is deprecated, and yotta also requires armcc to be on the
564 # path, and uses whatever version of armcc it finds there.
565 msg "build: create and build yotta module" # ~ 30s
566 record_status tests/scripts/yotta-build.sh
567}
568support_build_yotta () {
569 [ $YOTTA -ne 0 ]
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100570}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100571
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100572component_test_default_cmake_gcc_asan () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100573 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100574 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100575 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +0200576
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100577 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100578 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100579
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100580 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
Gilles Peskine7c652162017-12-11 00:01:40 +0100581 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100582
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100583 msg "test: compat.sh (ASan build)" # ~ 6 min
584 if_build_succeeded tests/compat.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100585}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000586
Gilles Peskine3484ed82019-01-08 22:51:19 +0100587component_test_ref_configs () {
588 msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
589 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
590 record_status tests/scripts/test-ref-configs.pl
591}
592
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100593component_test_sslv3 () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100594 msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100595 scripts/config.pl set MBEDTLS_SSL_PROTO_SSL3
596 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
597 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000598
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100599 msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
600 make test
601
602 msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
603 if_build_succeeded tests/compat.sh -m 'tls1 tls1_1 tls1_2 dtls1 dtls1_2'
604 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
605
606 msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
607 if_build_succeeded tests/ssl-opt.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100608}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100609
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100610component_test_no_renegotiation () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100611 msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100612 scripts/config.pl unset MBEDTLS_SSL_RENEGOTIATION
613 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
614 make
615
616 msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
617 make test
618
619 msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
620 if_build_succeeded tests/ssl-opt.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100621}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100622
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100623component_test_rsa_no_crt () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100624 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100625 scripts/config.pl set MBEDTLS_RSA_NO_CRT
626 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
627 make
628
629 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
630 make test
631
632 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
633 if_build_succeeded tests/ssl-opt.sh -f RSA
634
635 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
636 if_build_succeeded tests/compat.sh -t RSA
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_full_cmake_clang () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100640 msg "build: cmake, full config, clang" # ~ 50s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100641 scripts/config.pl full
642 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
643 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check -D ENABLE_TESTING=On .
644 make
645
646 msg "test: main suites (full config)" # ~ 5s
647 make test
648
649 msg "test: ssl-opt.sh default (full config)" # ~ 1s
650 if_build_succeeded tests/ssl-opt.sh -f Default
651
652 msg "test: compat.sh RC4, DES & NULL (full config)" # ~ 2 min
653 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 +0100654}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100655
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100656component_build_deprecated () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100657 msg "build: make, full config + DEPRECATED_WARNING, gcc -O" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100658 scripts/config.pl full
659 scripts/config.pl set MBEDTLS_DEPRECATED_WARNING
660 # Build with -O -Wextra to catch a maximum of issues.
661 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra' lib programs
662 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
663
664 msg "build: make, full config + DEPRECATED_REMOVED, clang -O" # ~ 30s
665 # No cleanup, just tweak the configuration and rebuild
666 make clean
667 scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
668 scripts/config.pl set MBEDTLS_DEPRECATED_REMOVED
669 # Build with -O -Wextra to catch a maximum of issues.
670 make CC=clang CFLAGS='-O -Werror -Wall -Wextra' lib programs
671 make CC=clang CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100672}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100673
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100674component_test_depends_curves () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100675 msg "test/build: curves.pl (gcc)" # ~ 4 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100676 record_status tests/scripts/curves.pl
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_depends_hashes () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100680 msg "test/build: depends-hashes.pl (gcc)" # ~ 2 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100681 record_status tests/scripts/depends-hashes.pl
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100682}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100683
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100684component_test_depends_pkalgs () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100685 msg "test/build: depends-pkalgs.pl (gcc)" # ~ 2 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100686 record_status tests/scripts/depends-pkalgs.pl
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100687}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100688
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100689component_build_key_exchanges () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100690 msg "test/build: key-exchanges (gcc)" # ~ 1 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100691 record_status tests/scripts/key-exchanges.pl
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100692}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100693
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100694component_build_default_make_gcc () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100695 msg "build: Unix make, -Os (gcc)" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100696 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100697}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100698
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100699component_test_no_platform () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100700 # Full configuration build, without platform support, file IO and net sockets.
701 # This should catch missing mbedtls_printf definitions, and by disabling file
702 # IO, it should catch missing '#include <stdio.h>'
703 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100704 scripts/config.pl full
705 scripts/config.pl unset MBEDTLS_PLATFORM_C
706 scripts/config.pl unset MBEDTLS_NET_C
707 scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
708 scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
709 scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
710 scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
711 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
712 scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
713 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
714 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
715 scripts/config.pl unset MBEDTLS_FS_IO
716 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
717 # to re-enable platform integration features otherwise disabled in C99 builds
718 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -O0 -D_DEFAULT_SOURCE' lib programs
719 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0' test
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100720}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100721
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100722component_build_no_std_function () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100723 # catch compile bugs in _uninit functions
724 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100725 scripts/config.pl full
726 scripts/config.pl set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
727 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
728 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100729}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100730
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100731component_build_no_ssl_srv () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100732 msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100733 scripts/config.pl full
734 scripts/config.pl unset MBEDTLS_SSL_SRV_C
735 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100736}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100737
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100738component_build_no_ssl_cli () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100739 msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100740 scripts/config.pl full
741 scripts/config.pl unset MBEDTLS_SSL_CLI_C
742 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100743}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100744
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100745component_build_no_sockets () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100746 # Note, C99 compliance can also be tested with the sockets support disabled,
747 # as that requires a POSIX platform (which isn't the same as C99).
748 msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100749 scripts/config.pl full
750 scripts/config.pl unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
751 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
752 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0 -std=c99 -pedantic' lib
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100753}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100754
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100755component_test_no_max_fragment_length () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100756 msg "build: default config except MFL extension (ASan build)" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100757 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
758 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
759 make
760
761 msg "test: ssl-opt.sh, MFL-related tests"
762 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length"
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100763}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100764
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100765component_test_null_entropy () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100766 msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100767 scripts/config.pl set MBEDTLS_TEST_NULL_ENTROPY
768 scripts/config.pl set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
769 scripts/config.pl set MBEDTLS_ENTROPY_C
770 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
771 scripts/config.pl unset MBEDTLS_ENTROPY_HARDWARE_ALT
772 scripts/config.pl unset MBEDTLS_HAVEGE_C
Gilles Peskine4e7b3232019-01-06 19:48:30 +0000773 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan -D UNSAFE_BUILD=ON .
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100774 make
775
776 msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)"
777 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100778}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100779
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100780component_test_platform_calloc_macro () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100781 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100782 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
783 scripts/config.pl set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
784 scripts/config.pl set MBEDTLS_PLATFORM_FREE_MACRO free
785 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
786 make
787
788 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
789 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100790}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100791
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100792component_test_make_shared () {
Gilles Peskine770ad7e2019-01-08 23:19:08 +0100793 msg "build/test: make shared" # ~ 40s
794 make SHARED=1 all check
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100795}
796
Gilles Peskine3fbdd212019-01-08 23:33:45 +0100797component_test_m32_o0 () {
798 # Build once with -O0, to compile out the i386 specific inline assembly
799 msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
800 scripts/config.pl full
801 make CC=gcc CFLAGS='-O0 -Werror -Wall -Wextra -m32 -fsanitize=address'
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100802
Gilles Peskine3fbdd212019-01-08 23:33:45 +0100803 msg "test: i386, make, gcc -O0 (ASan build)"
804 make test
805}
806support_test_m32_o0 () {
807 case $(uname -m) in
808 *64*) true;;
809 *) false;;
810 esac
811}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100812
Gilles Peskine3fbdd212019-01-08 23:33:45 +0100813component_test_m32_o1 () {
814 # Build again with -O1, to compile in the i386 specific inline assembly
815 msg "build: i386, make, gcc -O1 (ASan build)" # ~ 30s
816 scripts/config.pl full
817 make CC=gcc CFLAGS='-O1 -Werror -Wall -Wextra -m32 -fsanitize=address'
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100818
Gilles Peskine3fbdd212019-01-08 23:33:45 +0100819 msg "test: i386, make, gcc -O1 (ASan build)"
820 make test
821}
822support_test_m32_o1 () {
823 support_test_m32_o0 "$@"
824}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100825
Gilles Peskine3fbdd212019-01-08 23:33:45 +0100826component_test_mx32 () {
827 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
828 scripts/config.pl full
829 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32'
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100830
Gilles Peskine3fbdd212019-01-08 23:33:45 +0100831 msg "test: 64-bit ILP32, make, gcc"
832 make test
833}
834support_test_mx32 () {
835 case $(uname -m) in
836 amd64|x86_64) true;;
837 *) false;;
838 esac
839}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100840
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100841component_test_have_int32 () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100842 msg "build: gcc, force 32-bit bignum limbs"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100843 scripts/config.pl unset MBEDTLS_HAVE_ASM
844 scripts/config.pl unset MBEDTLS_AESNI_C
845 scripts/config.pl unset MBEDTLS_PADLOCK_C
846 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
847
848 msg "test: gcc, force 32-bit bignum limbs"
849 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100850}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100851
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100852component_test_have_int64 () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100853 msg "build: gcc, force 64-bit bignum limbs"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100854 scripts/config.pl unset MBEDTLS_HAVE_ASM
855 scripts/config.pl unset MBEDTLS_AESNI_C
856 scripts/config.pl unset MBEDTLS_PADLOCK_C
857 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
858
859 msg "test: gcc, force 64-bit bignum limbs"
860 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100861}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100862
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100863component_build_arm_none_eabi_gcc () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100864 msg "build: arm-none-eabi-gcc, make" # ~ 10s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100865 scripts/config.pl full
866 scripts/config.pl unset MBEDTLS_NET_C
867 scripts/config.pl unset MBEDTLS_TIMING_C
868 scripts/config.pl unset MBEDTLS_FS_IO
869 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
870 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
871 # following things are not in the default config
872 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
873 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
874 scripts/config.pl unset MBEDTLS_THREADING_C
875 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
876 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
877 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 +0100878}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100879
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100880component_build_arm_none_eabi_gcc_no_udbl_division () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100881 msg "build: arm-none-eabi-gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
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 set MBEDTLS_NO_PLATFORM_ENTROPY
888 # following things are not in the default config
889 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
890 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
891 scripts/config.pl unset MBEDTLS_THREADING_C
892 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
893 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
894 scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
895 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
896 echo "Checking that software 64-bit division is not required"
897 ! grep __aeabi_uldiv library/*.o
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100898}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100899
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100900component_build_armcc () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100901 msg "build: ARM Compiler 5, make"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100902 scripts/config.pl full
903 scripts/config.pl unset MBEDTLS_NET_C
904 scripts/config.pl unset MBEDTLS_TIMING_C
905 scripts/config.pl unset MBEDTLS_FS_IO
906 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
907 scripts/config.pl unset MBEDTLS_HAVE_TIME
908 scripts/config.pl unset MBEDTLS_HAVE_TIME_DATE
909 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
910 # following things are not in the default config
911 scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
912 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
913 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
914 scripts/config.pl unset MBEDTLS_THREADING_C
915 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
916 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
917 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT # depends on MBEDTLS_HAVE_TIME
918
Gilles Peskine53084872019-01-09 23:13:54 +0100919 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
920 make clean
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100921
Gilles Peskine53084872019-01-09 23:13:54 +0100922 # ARM Compiler 6 - Target ARMv7-A
923 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-a"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100924
Gilles Peskine53084872019-01-09 23:13:54 +0100925 # ARM Compiler 6 - Target ARMv7-M
926 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100927
Gilles Peskine53084872019-01-09 23:13:54 +0100928 # ARM Compiler 6 - Target ARMv8-A - AArch32
929 armc6_build_test "--target=arm-arm-none-eabi -march=armv8.2-a"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100930
Gilles Peskine53084872019-01-09 23:13:54 +0100931 # ARM Compiler 6 - Target ARMv8-M
932 armc6_build_test "--target=arm-arm-none-eabi -march=armv8-m.main"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100933
Gilles Peskine53084872019-01-09 23:13:54 +0100934 # ARM Compiler 6 - Target ARMv8-A - AArch64
935 armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a"
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100936}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000937
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100938component_test_allow_sha1 () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100939 msg "build: allow SHA1 in certificates by default"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100940 scripts/config.pl set MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
941 make CFLAGS='-Werror -Wall -Wextra'
942 msg "test: allow SHA1 in certificates by default"
943 make test
944 if_build_succeeded tests/ssl-opt.sh -f SHA-1
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100945}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000946
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100947component_build_mingw () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100948 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100949 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
950
951 # note Make tests only builds the tests, but doesn't run them
952 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror' WINDOWS_BUILD=1 tests
953 make WINDOWS_BUILD=1 clean
954
955 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
956 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
957 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
958 make WINDOWS_BUILD=1 clean
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_memsan () {
Gilles Peskine770ad7e2019-01-08 23:19:08 +0100962 msg "build: MSan (clang)" # ~ 1 min 20s
963 scripts/config.pl unset MBEDTLS_AESNI_C # memsan doesn't grok asm
964 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
965 make
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100966
Gilles Peskine770ad7e2019-01-08 23:19:08 +0100967 msg "test: main suites (MSan)" # ~ 10s
968 make test
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100969
Gilles Peskine770ad7e2019-01-08 23:19:08 +0100970 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
971 if_build_succeeded tests/ssl-opt.sh
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100972
Gilles Peskine770ad7e2019-01-08 23:19:08 +0100973 # Optional part(s)
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100974
Gilles Peskine770ad7e2019-01-08 23:19:08 +0100975 if [ "$MEMORY" -gt 0 ]; then
976 msg "test: compat.sh (MSan)" # ~ 6 min 20s
977 if_build_succeeded tests/compat.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100978 fi
979}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100980
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100981component_test_memcheck () {
Gilles Peskine770ad7e2019-01-08 23:19:08 +0100982 msg "build: Release (clang)"
983 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
984 make
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100985
Gilles Peskine770ad7e2019-01-08 23:19:08 +0100986 msg "test: main suites valgrind (Release)"
987 make memcheck
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100988
Gilles Peskine770ad7e2019-01-08 23:19:08 +0100989 # Optional part(s)
990 # Currently broken, programs don't seem to receive signals
991 # under valgrind on OS X
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100992
Gilles Peskine770ad7e2019-01-08 23:19:08 +0100993 if [ "$MEMORY" -gt 0 ]; then
994 msg "test: ssl-opt.sh --memcheck (Release)"
995 if_build_succeeded tests/ssl-opt.sh --memcheck
996 fi
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100997
Gilles Peskine770ad7e2019-01-08 23:19:08 +0100998 if [ "$MEMORY" -gt 1 ]; then
999 msg "test: compat.sh --memcheck (Release)"
1000 if_build_succeeded tests/compat.sh --memcheck
1001 fi
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001002}
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001003
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001004component_test_cmake_out_of_source () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001005 msg "build: cmake 'out-of-source' build"
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001006 MBEDTLS_ROOT_DIR="$PWD"
1007 mkdir "$OUT_OF_SOURCE_DIR"
1008 cd "$OUT_OF_SOURCE_DIR"
1009 cmake "$MBEDTLS_ROOT_DIR"
1010 make
1011
1012 msg "test: cmake 'out-of-source' build"
1013 make test
1014 # Test an SSL option that requires an auxiliary script in test/scripts/.
1015 # Also ensure that there are no error messages such as
1016 # "No such file or directory", which would indicate that some required
1017 # file is missing (ssl-opt.sh tolerates the absence of some files so
1018 # may exit with status 0 but emit errors).
1019 if_build_succeeded ./tests/ssl-opt.sh -f 'Fallback SCSV: beginning of list' 2>ssl-opt.err
1020 if [ -s ssl-opt.err ]; then
1021 cat ssl-opt.err >&2
1022 record_status [ ! -s ssl-opt.err ]
1023 rm ssl-opt.err
1024 fi
1025 cd "$MBEDTLS_ROOT_DIR"
1026 rm -rf "$OUT_OF_SOURCE_DIR"
1027 unset MBEDTLS_ROOT_DIR
1028}
Andres AGdc192212016-08-31 17:33:13 +01001029
Gilles Peskine192c72f2017-12-21 15:59:21 +01001030
1031
1032################################################################
1033#### Termination
1034################################################################
1035
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001036post_report () {
1037 msg "Done, cleaning up"
1038 cleanup
1039
1040 final_report
1041}
1042
1043
1044
1045################################################################
1046#### Run all the things
1047################################################################
1048
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001049# Run one component and clean up afterwards.
1050run_component () {
Gilles Peskine72adb432019-01-02 18:57:02 +01001051 # Back up the configuration in case the component modifies it.
1052 # The cleanup function will restore it.
1053 cp -p "$CONFIG_H" "$CONFIG_BAK"
Gilles Peskine11ddca62018-12-04 12:49:28 +01001054 current_component="$1"
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001055 "$@"
1056 cleanup
1057}
1058
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001059# Preliminary setup
1060pre_check_environment
1061pre_initialize_variables
1062pre_parse_command_line "$@"
1063
1064pre_check_git
1065build_status=0
1066if [ $KEEP_GOING -eq 1 ]; then
1067 pre_setup_keep_going
1068else
1069 record_status () {
1070 "$@"
1071 }
1072fi
1073pre_print_configuration
1074pre_check_tools
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001075cleanup
Gilles Peskine7c652162017-12-11 00:01:40 +01001076
Gilles Peskineeb39b9b2019-01-08 23:41:00 +01001077# Run the requested tests.
Gilles Peskine6e984232018-11-27 21:37:53 +01001078for component in $RUN_COMPONENTS; do
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001079 run_component "component_$component"
1080done
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001081
1082# We're done.
1083post_report