blob: 89ccfc86660c219828b533714e89c56586a239ff [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
97 RUN_ARMCC=1
98 YOTTA=1
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010099
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100100 # Default commands, can be overriden by the environment
101 : ${OPENSSL:="openssl"}
102 : ${OPENSSL_LEGACY:="$OPENSSL"}
103 : ${GNUTLS_CLI:="gnutls-cli"}
104 : ${GNUTLS_SERV:="gnutls-serv"}
105 : ${GNUTLS_LEGACY_CLI:="$GNUTLS_CLI"}
106 : ${GNUTLS_LEGACY_SERV:="$GNUTLS_SERV"}
107 : ${OUT_OF_SOURCE_DIR:=./mbedtls_out_of_source_build}
108 : ${ARMC5_BIN_DIR:=/usr/bin}
109 : ${ARMC6_BIN_DIR:=/usr/bin}
Andres AGdc192212016-08-31 17:33:13 +0100110
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100111 # if MAKEFLAGS is not set add the -j option to speed up invocations of make
Gilles Peskine7120f772019-01-06 20:15:26 +0000112 if [ -z "${MAKEFLAGS+set}" ]; then
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100113 export MAKEFLAGS="-j"
114 fi
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100115
116 # Gather the list of available components. These are the functions
117 # defined in this script whose name starts with "component_".
118 # Parse the script with sed, because in sh there is no way to list
119 # defined functions.
120 ALL_COMPONENTS=$(sed -n 's/^ *component_\([0-9A-Z_a-z]*\) *().*/\1/p' <"$0")
Gilles Peskine3fbdd212019-01-08 23:33:45 +0100121
122 # Exclude components that are not supported on this platform.
123 SUPPORTED_COMPONENTS=
124 for component in $ALL_COMPONENTS; do
125 case $(type "support_$component" 2>&1) in
126 *' function'*)
127 if ! support_$component; then continue; fi;;
128 esac
129 SUPPORTED_COMPONENTS="$SUPPORTED_COMPONENTS $component"
130 done
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100131}
Andres AG38495a32016-07-12 16:54:33 +0100132
Gilles Peskine3fbdd212019-01-08 23:33:45 +0100133# Test whether $1 is excluded via the command line.
Gilles Peskine6e984232018-11-27 21:37:53 +0100134is_component_excluded()
135{
Gilles Peskine3fbdd212019-01-08 23:33:45 +0100136 # Is $1 excluded via $COMPONENTS (a space-separated list of wildcard
137 # patterns)?
Gilles Peskine6e984232018-11-27 21:37:53 +0100138 set -f
Gilles Peskineeb39b9b2019-01-08 23:41:00 +0100139 for pattern in $COMMAND_LINE_COMPONENTS; do
Gilles Peskine6e984232018-11-27 21:37:53 +0100140 set +f
141 case ${1#component_} in $pattern) return 0;; esac
142 done
143 set +f
144 return 1
145}
146
Simon Butcher41eeccf2016-09-07 00:07:09 +0100147usage()
SimonB2e23c822016-04-16 21:54:39 +0100148{
Gilles Peskine709346a2017-12-10 23:43:39 +0100149 cat <<EOF
Gilles Peskine91bd8b72019-01-08 23:01:34 +0100150Usage: $0 [OPTION]... [COMPONENT]...
151Run mbedtls release validation tests.
152By default, run all tests. With one or more COMPONENT, run only those.
153
154Special options:
155 -h|--help Print this help and exit.
Gilles Peskine709346a2017-12-10 23:43:39 +0100156
157General options:
158 -f|--force Force the tests to overwrite any modified files.
Gilles Peskine7c652162017-12-11 00:01:40 +0100159 -k|--keep-going Run all tests and report errors at the end.
Gilles Peskine709346a2017-12-10 23:43:39 +0100160 -m|--memory Additional optional memory tests.
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100161 --armcc Run ARM Compiler builds (on by default).
Gilles Peskine6e984232018-11-27 21:37:53 +0100162 --except If some components are passed on the command line,
163 run all the tests except for these components. In
164 this mode, you can pass shell wildcard patterns as
165 component names, e.g. "$0 --except 'test_*'" to
166 exclude all components that run tests.
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100167 --no-armcc Skip ARM Compiler builds.
Gilles Peskine19ceb712018-03-21 08:40:26 +0100168 --no-force Refuse to overwrite modified files (default).
169 --no-keep-going Stop at the first error (default).
170 --no-memory No additional memory tests (default).
Gilles Peskine2a22a802017-12-21 15:19:00 +0100171 --no-yotta Skip yotta module build.
Gilles Peskine709346a2017-12-10 23:43:39 +0100172 --out-of-source-dir=<path> Directory used for CMake out-of-source build tests.
Gilles Peskine19ceb712018-03-21 08:40:26 +0100173 --random-seed Use a random seed value for randomized tests (default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100174 -r|--release-test Run this script in release mode. This fixes the seed value to 1.
175 -s|--seed Integer seed value to use for this test run.
Gilles Peskine2a22a802017-12-21 15:19:00 +0100176 --yotta Build yotta module (on by default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100177
178Tool path options:
179 --armc5-bin-dir=<ARMC5_bin_dir_path> ARM Compiler 5 bin directory.
180 --armc6-bin-dir=<ARMC6_bin_dir_path> ARM Compiler 6 bin directory.
181 --gnutls-cli=<GnuTLS_cli_path> GnuTLS client executable to use for most tests.
182 --gnutls-serv=<GnuTLS_serv_path> GnuTLS server executable to use for most tests.
183 --gnutls-legacy-cli=<GnuTLS_cli_path> GnuTLS client executable to use for legacy tests.
184 --gnutls-legacy-serv=<GnuTLS_serv_path> GnuTLS server executable to use for legacy tests.
185 --openssl=<OpenSSL_path> OpenSSL executable to use for most tests.
186 --openssl-legacy=<OpenSSL_path> OpenSSL executable to use for legacy tests e.g. SSLv3.
187EOF
SimonB2e23c822016-04-16 21:54:39 +0100188}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100189
190# remove built files as well as the cmake cache/config
191cleanup()
192{
Gilles Peskinea71d64c2018-03-21 12:16:57 +0100193 if [ -n "${MBEDTLS_ROOT_DIR+set}" ]; then
194 cd "$MBEDTLS_ROOT_DIR"
195 fi
196
Gilles Peskine7c652162017-12-11 00:01:40 +0100197 command make clean
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200198
Gilles Peskine31b07e22018-03-21 12:15:06 +0100199 # Remove CMake artefacts
200 find . -name .git -prune -o -name yotta -prune -o \
201 -iname CMakeFiles -exec rm -rf {} \+ -o \
202 \( -iname cmake_install.cmake -o \
203 -iname CTestTestfile.cmake -o \
204 -iname CMakeCache.txt \) -exec rm {} \+
205 # Recover files overwritten by in-tree CMake builds
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000206 rm -f include/Makefile include/mbedtls/Makefile programs/*/Makefile
Paul Bakkerfe0984d2014-06-13 00:13:45 +0200207 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile
208 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200209
210 if [ -f "$CONFIG_BAK" ]; then
211 mv "$CONFIG_BAK" "$CONFIG_H"
212 fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100213}
214
Gilles Peskine7c652162017-12-11 00:01:40 +0100215# Executed on exit. May be redefined depending on command line options.
216final_report () {
217 :
218}
219
220fatal_signal () {
221 cleanup
222 final_report $1
223 trap - $1
224 kill -$1 $$
225}
226
227trap 'fatal_signal HUP' HUP
228trap 'fatal_signal INT' INT
229trap 'fatal_signal TERM' TERM
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200230
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100231msg()
232{
Gilles Peskine11ddca62018-12-04 12:49:28 +0100233 if [ -n "${current_component:-}" ]; then
234 current_section="${current_component#component_}: $1"
235 else
236 current_section="$1"
237 fi
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100238 echo ""
239 echo "******************************************************************"
Gilles Peskine11ddca62018-12-04 12:49:28 +0100240 echo "* $current_section "
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000241 printf "* "; date
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100242 echo "******************************************************************"
243}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100244
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100245armc6_build_test()
246{
247 FLAGS="$1"
Andres AGa5cd9732016-10-17 15:23:10 +0100248
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100249 msg "build: ARM Compiler 6 ($FLAGS), make"
250 ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \
251 WARNING_CFLAGS='-xc -std=c99' make lib
252 make clean
253}
Andres AGa5cd9732016-10-17 15:23:10 +0100254
Andres AGd9eba4b2016-08-26 14:42:14 +0100255err_msg()
256{
257 echo "$1" >&2
258}
259
260check_tools()
261{
262 for TOOL in "$@"; do
Andres AG98393602017-01-31 17:04:45 +0000263 if ! `type "$TOOL" >/dev/null 2>&1`; then
Andres AGd9eba4b2016-08-26 14:42:14 +0100264 err_msg "$TOOL not found!"
265 exit 1
266 fi
267 done
268}
269
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100270pre_parse_command_line () {
Gilles Peskineeb39b9b2019-01-08 23:41:00 +0100271 COMMAND_LINE_COMPONENTS=
272 all_except=
Gilles Peskine6e984232018-11-27 21:37:53 +0100273
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100274 while [ $# -gt 0 ]; do
275 case "$1" in
276 --armcc) RUN_ARMCC=1;;
277 --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
278 --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
Gilles Peskineeb39b9b2019-01-08 23:41:00 +0100279 --except) all_except=1;;
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100280 --force|-f) FORCE=1;;
281 --gnutls-cli) shift; GNUTLS_CLI="$1";;
282 --gnutls-legacy-cli) shift; GNUTLS_LEGACY_CLI="$1";;
283 --gnutls-legacy-serv) shift; GNUTLS_LEGACY_SERV="$1";;
284 --gnutls-serv) shift; GNUTLS_SERV="$1";;
285 --help|-h) usage; exit;;
286 --keep-going|-k) KEEP_GOING=1;;
287 --memory|-m) MEMORY=1;;
288 --no-armcc) RUN_ARMCC=0;;
289 --no-force) FORCE=0;;
290 --no-keep-going) KEEP_GOING=0;;
291 --no-memory) MEMORY=0;;
292 --no-yotta) YOTTA=0;;
293 --openssl) shift; OPENSSL="$1";;
294 --openssl-legacy) shift; OPENSSL_LEGACY="$1";;
295 --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
296 --random-seed) unset SEED;;
297 --release-test|-r) SEED=1;;
298 --seed|-s) shift; SEED="$1";;
299 --yotta) YOTTA=1;;
Gilles Peskine91bd8b72019-01-08 23:01:34 +0100300 -*)
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100301 echo >&2 "Unknown option: $1"
302 echo >&2 "Run $0 --help for usage."
303 exit 120
304 ;;
Gilles Peskineeb39b9b2019-01-08 23:41:00 +0100305 *) COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS $1";;
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100306 esac
307 shift
308 done
Gilles Peskine91bd8b72019-01-08 23:01:34 +0100309
Gilles Peskineeb39b9b2019-01-08 23:41:00 +0100310 if [ -z "$COMMAND_LINE_COMPONENTS" ]; then
311 all_except=1
312 fi
313
314 # Build the list of components to run.
315 if [ -n "$all_except" ]; then
Gilles Peskine6e984232018-11-27 21:37:53 +0100316 RUN_COMPONENTS=
Gilles Peskine3fbdd212019-01-08 23:33:45 +0100317 for component in $SUPPORTED_COMPONENTS; do
Gilles Peskine6e984232018-11-27 21:37:53 +0100318 if ! is_component_excluded "$component"; then
319 RUN_COMPONENTS="$RUN_COMPONENTS $component"
320 fi
321 done
Gilles Peskine6e984232018-11-27 21:37:53 +0100322 else
Gilles Peskineeb39b9b2019-01-08 23:41:00 +0100323 RUN_COMPONENTS="$COMMAND_LINE_COMPONENTS"
Gilles Peskine91bd8b72019-01-08 23:01:34 +0100324 fi
Gilles Peskineeb39b9b2019-01-08 23:41:00 +0100325
326 unset all_except
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100327}
SimonB2e23c822016-04-16 21:54:39 +0100328
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100329pre_check_git () {
330 if [ $FORCE -eq 1 ]; then
331 if [ $YOTTA -eq 1 ]; then
332 rm -rf yotta/module "$OUT_OF_SOURCE_DIR"
333 fi
334 git checkout-index -f -q $CONFIG_H
335 cleanup
336 else
337
338 if [ $YOTTA -ne 0 ] && [ -d yotta/module ]; then
339 err_msg "Warning - there is an existing yotta module in the directory 'yotta/module'"
340 echo "You can either delete your work and retry, or force the test to overwrite the"
341 echo "test by rerunning the script as: $0 --force"
342 exit 1
343 fi
344
345 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
346 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
347 echo "You can either delete this directory manually, or force the test by rerunning"
348 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
349 exit 1
350 fi
351
352 if ! git diff-files --quiet include/mbedtls/config.h; then
353 err_msg "Warning - the configuration file 'include/mbedtls/config.h' has been edited. "
354 echo "You can either delete or preserve your work, or force the test by rerunning the"
355 echo "script as: $0 --force"
356 exit 1
357 fi
Gilles Peskineda519252017-11-30 13:22:04 +0100358 fi
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100359}
SimonB2e23c822016-04-16 21:54:39 +0100360
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100361pre_setup_keep_going () {
Gilles Peskine7c652162017-12-11 00:01:40 +0100362 failure_summary=
363 failure_count=0
364 start_red=
365 end_color=
366 if [ -t 1 ]; then
Gilles Peskine9736b9d2018-01-02 21:54:17 +0100367 case "${TERM:-}" in
Gilles Peskine7c652162017-12-11 00:01:40 +0100368 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
369 start_red=$(printf '\033[31m')
370 end_color=$(printf '\033[0m')
371 ;;
372 esac
373 fi
374 record_status () {
375 if "$@"; then
376 last_status=0
377 else
378 last_status=$?
379 text="$current_section: $* -> $last_status"
380 failure_summary="$failure_summary
381$text"
382 failure_count=$((failure_count + 1))
383 echo "${start_red}^^^^$text^^^^${end_color}"
384 fi
385 }
386 make () {
387 case "$*" in
388 *test|*check)
389 if [ $build_status -eq 0 ]; then
390 record_status command make "$@"
391 else
392 echo "(skipped because the build failed)"
393 fi
394 ;;
395 *)
396 record_status command make "$@"
397 build_status=$last_status
398 ;;
399 esac
400 }
401 final_report () {
402 if [ $failure_count -gt 0 ]; then
403 echo
404 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
405 echo "${start_red}FAILED: $failure_count${end_color}$failure_summary"
406 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Jaeden Amero5113bde2018-07-20 16:42:14 +0100407 exit 1
Gilles Peskine7c652162017-12-11 00:01:40 +0100408 elif [ -z "${1-}" ]; then
409 echo "SUCCESS :)"
410 fi
411 if [ -n "${1-}" ]; then
412 echo "Killed by SIG$1."
413 fi
414 }
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100415}
416
Gilles Peskine7c652162017-12-11 00:01:40 +0100417if_build_succeeded () {
418 if [ $build_status -eq 0 ]; then
419 record_status "$@"
420 fi
421}
422
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100423pre_print_configuration () {
424 msg "info: $0 configuration"
425 echo "MEMORY: $MEMORY"
426 echo "FORCE: $FORCE"
427 echo "SEED: ${SEED-"UNSET"}"
428 echo "OPENSSL: $OPENSSL"
429 echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
430 echo "GNUTLS_CLI: $GNUTLS_CLI"
431 echo "GNUTLS_SERV: $GNUTLS_SERV"
432 echo "GNUTLS_LEGACY_CLI: $GNUTLS_LEGACY_CLI"
433 echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV"
434 echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
435 echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
436}
Andres AG7770ea82016-10-10 15:46:20 +0100437
Andres AGd9eba4b2016-08-26 14:42:14 +0100438# Make sure the tools we need are available.
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100439pre_check_tools () {
440 ARMC5_CC="$ARMC5_BIN_DIR/armcc"
441 ARMC5_AR="$ARMC5_BIN_DIR/armar"
442 ARMC6_CC="$ARMC6_BIN_DIR/armclang"
443 ARMC6_AR="$ARMC6_BIN_DIR/armar"
444
445 # To avoid setting OpenSSL and GnuTLS for each call to compat.sh and ssl-opt.sh
446 # we just export the variables they require
447 export OPENSSL_CMD="$OPENSSL"
448 export GNUTLS_CLI="$GNUTLS_CLI"
449 export GNUTLS_SERV="$GNUTLS_SERV"
450
451 # Avoid passing --seed flag in every call to ssl-opt.sh
452 if [ -n "${SEED-}" ]; then
453 export SEED
454 fi
455
456 check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$GNUTLS_CLI" "$GNUTLS_SERV" \
457 "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV" "doxygen" "dot" \
458 "arm-none-eabi-gcc" "i686-w64-mingw32-gcc"
459 if [ $RUN_ARMCC -ne 0 ]; then
460 check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC6_CC" "$ARMC6_AR"
461 fi
462
463 msg "info: output_env.sh"
464 OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY" GNUTLS_CLI="$GNUTLS_CLI" \
465 GNUTLS_SERV="$GNUTLS_SERV" GNUTLS_LEGACY_CLI="$GNUTLS_LEGACY_CLI" \
466 GNUTLS_LEGACY_SERV="$GNUTLS_LEGACY_SERV" ARMC5_CC="$ARMC5_CC" \
467 ARMC6_CC="$ARMC6_CC" RUN_ARMCC="$RUN_ARMCC" scripts/output_env.sh
468}
Andres AGd9eba4b2016-08-26 14:42:14 +0100469
Gilles Peskine192c72f2017-12-21 15:59:21 +0100470
471
472################################################################
473#### Basic checks
474################################################################
SimonB2e23c822016-04-16 21:54:39 +0100475
476#
477# Test Suites to be executed
478#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200479# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100480# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard61bc57a2014-08-14 11:29:06 +0200481# and/or are more likely to fail than others (eg I use Clang most of the
482# time, so start with a GCC build).
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200483# 2. Minimize total running time, by avoiding useless rebuilds
484#
485# Indicative running times are given for reference.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100486
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100487component_check_recursion () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100488 msg "test: recursion.pl" # < 1s
489 record_status tests/scripts/recursion.pl library/*.c
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100490}
Manuel Pégourié-Gonnardea29d152014-11-20 17:32:33 +0100491
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100492component_check_generated_files () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100493 msg "test: freshness of generated source files" # < 1s
494 record_status tests/scripts/check-generated-files.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100495}
Manuel Pégourié-Gonnardb3b8e432015-02-13 14:52:19 +0000496
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100497component_check_doxy_blocks () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100498 msg "test: doxygen markup outside doxygen blocks" # < 1s
499 record_status tests/scripts/check-doxy-blocks.pl
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100500}
Manuel Pégourié-Gonnardd09a6b52015-04-09 17:19:23 +0200501
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100502component_check_files () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100503 msg "test: check-files.py" # < 1s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100504 record_status tests/scripts/check-files.py
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100505}
Manuel Pégourié-Gonnard77d56bb2015-07-28 15:00:37 +0200506
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100507component_check_names () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100508 msg "test/build: declared and exported names" # < 3s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100509 record_status tests/scripts/check-names.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100510}
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +0200511
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100512component_check_doxygen_warnings () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100513 msg "test: doxygen warnings" # ~ 3s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100514 record_status tests/scripts/doxygen.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100515}
Andres Amaya Garciadd29c2f2017-05-04 11:35:51 +0100516
Simon Butcher948f2642018-07-20 21:27:33 +0100517
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100518################################################################
519#### Build and test many configurations and targets
520################################################################
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100521
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100522component_build_yotta () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100523 if [ $RUN_ARMCC -ne 0 ] && [ $YOTTA -ne 0 ]; then
524 # Note - use of yotta is deprecated, and yotta also requires armcc to be on the
525 # path, and uses whatever version of armcc it finds there.
526 msg "build: create and build yotta module" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100527 record_status tests/scripts/yotta-build.sh
528 fi
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100529}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100530
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100531component_test_default_cmake_gcc_asan () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100532 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100533 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100534 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +0200535
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100536 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100537 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100538
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100539 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
Gilles Peskine7c652162017-12-11 00:01:40 +0100540 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100541
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100542 msg "test: compat.sh (ASan build)" # ~ 6 min
543 if_build_succeeded tests/compat.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100544}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000545
Gilles Peskine3484ed82019-01-08 22:51:19 +0100546component_test_ref_configs () {
547 msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
548 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
549 record_status tests/scripts/test-ref-configs.pl
550}
551
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100552component_test_sslv3 () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100553 msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100554 scripts/config.pl set MBEDTLS_SSL_PROTO_SSL3
555 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
556 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000557
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100558 msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
559 make test
560
561 msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
562 if_build_succeeded tests/compat.sh -m 'tls1 tls1_1 tls1_2 dtls1 dtls1_2'
563 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
564
565 msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
566 if_build_succeeded tests/ssl-opt.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100567}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100568
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100569component_test_no_renegotiation () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100570 msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100571 scripts/config.pl unset MBEDTLS_SSL_RENEGOTIATION
572 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
573 make
574
575 msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
576 make test
577
578 msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
579 if_build_succeeded tests/ssl-opt.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100580}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100581
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100582component_test_rsa_no_crt () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100583 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100584 scripts/config.pl set MBEDTLS_RSA_NO_CRT
585 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
586 make
587
588 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
589 make test
590
591 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
592 if_build_succeeded tests/ssl-opt.sh -f RSA
593
594 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
595 if_build_succeeded tests/compat.sh -t RSA
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100596}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100597
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100598component_test_full_cmake_clang () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100599 msg "build: cmake, full config, clang" # ~ 50s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100600 scripts/config.pl full
601 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
602 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check -D ENABLE_TESTING=On .
603 make
604
605 msg "test: main suites (full config)" # ~ 5s
606 make test
607
608 msg "test: ssl-opt.sh default (full config)" # ~ 1s
609 if_build_succeeded tests/ssl-opt.sh -f Default
610
611 msg "test: compat.sh RC4, DES & NULL (full config)" # ~ 2 min
612 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 +0100613}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100614
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100615component_build_deprecated () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100616 msg "build: make, full config + DEPRECATED_WARNING, gcc -O" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100617 scripts/config.pl full
618 scripts/config.pl set MBEDTLS_DEPRECATED_WARNING
619 # Build with -O -Wextra to catch a maximum of issues.
620 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra' lib programs
621 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
622
623 msg "build: make, full config + DEPRECATED_REMOVED, clang -O" # ~ 30s
624 # No cleanup, just tweak the configuration and rebuild
625 make clean
626 scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
627 scripts/config.pl set MBEDTLS_DEPRECATED_REMOVED
628 # Build with -O -Wextra to catch a maximum of issues.
629 make CC=clang CFLAGS='-O -Werror -Wall -Wextra' lib programs
630 make CC=clang CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100631}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100632
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100633component_test_depends_curves () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100634 msg "test/build: curves.pl (gcc)" # ~ 4 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100635 record_status tests/scripts/curves.pl
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100636}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100637
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100638component_test_depends_hashes () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100639 msg "test/build: depends-hashes.pl (gcc)" # ~ 2 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100640 record_status tests/scripts/depends-hashes.pl
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100641}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100642
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100643component_test_depends_pkalgs () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100644 msg "test/build: depends-pkalgs.pl (gcc)" # ~ 2 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100645 record_status tests/scripts/depends-pkalgs.pl
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100646}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100647
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100648component_build_key_exchanges () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100649 msg "test/build: key-exchanges (gcc)" # ~ 1 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100650 record_status tests/scripts/key-exchanges.pl
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100651}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100652
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100653component_build_default_make_gcc () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100654 msg "build: Unix make, -Os (gcc)" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100655 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100656}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100657
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100658component_test_no_platform () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100659 # Full configuration build, without platform support, file IO and net sockets.
660 # This should catch missing mbedtls_printf definitions, and by disabling file
661 # IO, it should catch missing '#include <stdio.h>'
662 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100663 scripts/config.pl full
664 scripts/config.pl unset MBEDTLS_PLATFORM_C
665 scripts/config.pl unset MBEDTLS_NET_C
666 scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
667 scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
668 scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
669 scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
670 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
671 scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
672 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
673 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
674 scripts/config.pl unset MBEDTLS_FS_IO
675 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
676 # to re-enable platform integration features otherwise disabled in C99 builds
677 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -O0 -D_DEFAULT_SOURCE' lib programs
678 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0' test
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100679}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100680
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100681component_build_no_std_function () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100682 # catch compile bugs in _uninit functions
683 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100684 scripts/config.pl full
685 scripts/config.pl set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
686 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
687 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100688}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100689
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100690component_build_no_ssl_srv () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100691 msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100692 scripts/config.pl full
693 scripts/config.pl unset MBEDTLS_SSL_SRV_C
694 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100695}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100696
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100697component_build_no_ssl_cli () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100698 msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100699 scripts/config.pl full
700 scripts/config.pl unset MBEDTLS_SSL_CLI_C
701 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100702}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100703
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100704component_build_no_sockets () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100705 # Note, C99 compliance can also be tested with the sockets support disabled,
706 # as that requires a POSIX platform (which isn't the same as C99).
707 msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100708 scripts/config.pl full
709 scripts/config.pl unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
710 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
711 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0 -std=c99 -pedantic' lib
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100712}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100713
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100714component_test_no_max_fragment_length () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100715 msg "build: default config except MFL extension (ASan build)" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100716 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
717 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
718 make
719
720 msg "test: ssl-opt.sh, MFL-related tests"
721 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length"
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100722}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100723
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100724component_test_null_entropy () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100725 msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100726 scripts/config.pl set MBEDTLS_TEST_NULL_ENTROPY
727 scripts/config.pl set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
728 scripts/config.pl set MBEDTLS_ENTROPY_C
729 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
730 scripts/config.pl unset MBEDTLS_ENTROPY_HARDWARE_ALT
731 scripts/config.pl unset MBEDTLS_HAVEGE_C
Gilles Peskine4e7b3232019-01-06 19:48:30 +0000732 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan -D UNSAFE_BUILD=ON .
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100733 make
734
735 msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)"
736 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100737}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100738
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100739component_test_platform_calloc_macro () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100740 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100741 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
742 scripts/config.pl set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
743 scripts/config.pl set MBEDTLS_PLATFORM_FREE_MACRO free
744 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
745 make
746
747 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
748 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100749}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100750
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100751component_test_make_shared () {
Gilles Peskine770ad7e2019-01-08 23:19:08 +0100752 msg "build/test: make shared" # ~ 40s
753 make SHARED=1 all check
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100754}
755
Gilles Peskine3fbdd212019-01-08 23:33:45 +0100756component_test_m32_o0 () {
757 # Build once with -O0, to compile out the i386 specific inline assembly
758 msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
759 scripts/config.pl full
760 make CC=gcc CFLAGS='-O0 -Werror -Wall -Wextra -m32 -fsanitize=address'
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100761
Gilles Peskine3fbdd212019-01-08 23:33:45 +0100762 msg "test: i386, make, gcc -O0 (ASan build)"
763 make test
764}
765support_test_m32_o0 () {
766 case $(uname -m) in
767 *64*) true;;
768 *) false;;
769 esac
770}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100771
Gilles Peskine3fbdd212019-01-08 23:33:45 +0100772component_test_m32_o1 () {
773 # Build again with -O1, to compile in the i386 specific inline assembly
774 msg "build: i386, make, gcc -O1 (ASan build)" # ~ 30s
775 scripts/config.pl full
776 make CC=gcc CFLAGS='-O1 -Werror -Wall -Wextra -m32 -fsanitize=address'
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100777
Gilles Peskine3fbdd212019-01-08 23:33:45 +0100778 msg "test: i386, make, gcc -O1 (ASan build)"
779 make test
780}
781support_test_m32_o1 () {
782 support_test_m32_o0 "$@"
783}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100784
Gilles Peskine3fbdd212019-01-08 23:33:45 +0100785component_test_mx32 () {
786 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
787 scripts/config.pl full
788 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32'
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100789
Gilles Peskine3fbdd212019-01-08 23:33:45 +0100790 msg "test: 64-bit ILP32, make, gcc"
791 make test
792}
793support_test_mx32 () {
794 case $(uname -m) in
795 amd64|x86_64) true;;
796 *) false;;
797 esac
798}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100799
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100800component_test_have_int32 () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100801 msg "build: gcc, force 32-bit bignum limbs"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100802 scripts/config.pl unset MBEDTLS_HAVE_ASM
803 scripts/config.pl unset MBEDTLS_AESNI_C
804 scripts/config.pl unset MBEDTLS_PADLOCK_C
805 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
806
807 msg "test: gcc, force 32-bit bignum limbs"
808 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100809}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100810
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100811component_test_have_int64 () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100812 msg "build: gcc, force 64-bit bignum limbs"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100813 scripts/config.pl unset MBEDTLS_HAVE_ASM
814 scripts/config.pl unset MBEDTLS_AESNI_C
815 scripts/config.pl unset MBEDTLS_PADLOCK_C
816 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
817
818 msg "test: gcc, force 64-bit bignum limbs"
819 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100820}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100821
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100822component_build_arm_none_eabi_gcc () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100823 msg "build: arm-none-eabi-gcc, make" # ~ 10s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100824 scripts/config.pl full
825 scripts/config.pl unset MBEDTLS_NET_C
826 scripts/config.pl unset MBEDTLS_TIMING_C
827 scripts/config.pl unset MBEDTLS_FS_IO
828 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
829 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
830 # following things are not in the default config
831 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
832 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
833 scripts/config.pl unset MBEDTLS_THREADING_C
834 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
835 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
836 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 +0100837}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100838
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100839component_build_arm_none_eabi_gcc_no_udbl_division () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100840 msg "build: arm-none-eabi-gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100841 scripts/config.pl full
842 scripts/config.pl unset MBEDTLS_NET_C
843 scripts/config.pl unset MBEDTLS_TIMING_C
844 scripts/config.pl unset MBEDTLS_FS_IO
845 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
846 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
847 # following things are not in the default config
848 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
849 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
850 scripts/config.pl unset MBEDTLS_THREADING_C
851 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
852 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
853 scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
854 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
855 echo "Checking that software 64-bit division is not required"
856 ! grep __aeabi_uldiv library/*.o
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100857}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100858
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100859component_build_armcc () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100860 msg "build: ARM Compiler 5, make"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100861 scripts/config.pl full
862 scripts/config.pl unset MBEDTLS_NET_C
863 scripts/config.pl unset MBEDTLS_TIMING_C
864 scripts/config.pl unset MBEDTLS_FS_IO
865 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
866 scripts/config.pl unset MBEDTLS_HAVE_TIME
867 scripts/config.pl unset MBEDTLS_HAVE_TIME_DATE
868 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
869 # following things are not in the default config
870 scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
871 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
872 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
873 scripts/config.pl unset MBEDTLS_THREADING_C
874 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
875 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
876 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT # depends on MBEDTLS_HAVE_TIME
877
878 if [ $RUN_ARMCC -ne 0 ]; then
879 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
880 make clean
881
882 # ARM Compiler 6 - Target ARMv7-A
883 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-a"
884
885 # ARM Compiler 6 - Target ARMv7-M
886 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m"
887
888 # ARM Compiler 6 - Target ARMv8-A - AArch32
889 armc6_build_test "--target=arm-arm-none-eabi -march=armv8.2-a"
890
891 # ARM Compiler 6 - Target ARMv8-M
892 armc6_build_test "--target=arm-arm-none-eabi -march=armv8-m.main"
893
894 # ARM Compiler 6 - Target ARMv8-A - AArch64
895 armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a"
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100896 fi
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100897}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000898
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100899component_test_allow_sha1 () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100900 msg "build: allow SHA1 in certificates by default"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100901 scripts/config.pl set MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
902 make CFLAGS='-Werror -Wall -Wextra'
903 msg "test: allow SHA1 in certificates by default"
904 make test
905 if_build_succeeded tests/ssl-opt.sh -f SHA-1
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100906}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000907
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100908component_build_mingw () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100909 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100910 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
911
912 # note Make tests only builds the tests, but doesn't run them
913 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror' WINDOWS_BUILD=1 tests
914 make WINDOWS_BUILD=1 clean
915
916 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
917 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
918 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
919 make WINDOWS_BUILD=1 clean
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100920}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100921
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100922component_test_memsan () {
Gilles Peskine770ad7e2019-01-08 23:19:08 +0100923 msg "build: MSan (clang)" # ~ 1 min 20s
924 scripts/config.pl unset MBEDTLS_AESNI_C # memsan doesn't grok asm
925 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
926 make
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100927
Gilles Peskine770ad7e2019-01-08 23:19:08 +0100928 msg "test: main suites (MSan)" # ~ 10s
929 make test
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100930
Gilles Peskine770ad7e2019-01-08 23:19:08 +0100931 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
932 if_build_succeeded tests/ssl-opt.sh
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100933
Gilles Peskine770ad7e2019-01-08 23:19:08 +0100934 # Optional part(s)
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100935
Gilles Peskine770ad7e2019-01-08 23:19:08 +0100936 if [ "$MEMORY" -gt 0 ]; then
937 msg "test: compat.sh (MSan)" # ~ 6 min 20s
938 if_build_succeeded tests/compat.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100939 fi
940}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100941
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100942component_test_memcheck () {
Gilles Peskine770ad7e2019-01-08 23:19:08 +0100943 msg "build: Release (clang)"
944 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
945 make
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100946
Gilles Peskine770ad7e2019-01-08 23:19:08 +0100947 msg "test: main suites valgrind (Release)"
948 make memcheck
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100949
Gilles Peskine770ad7e2019-01-08 23:19:08 +0100950 # Optional part(s)
951 # Currently broken, programs don't seem to receive signals
952 # under valgrind on OS X
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100953
Gilles Peskine770ad7e2019-01-08 23:19:08 +0100954 if [ "$MEMORY" -gt 0 ]; then
955 msg "test: ssl-opt.sh --memcheck (Release)"
956 if_build_succeeded tests/ssl-opt.sh --memcheck
957 fi
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100958
Gilles Peskine770ad7e2019-01-08 23:19:08 +0100959 if [ "$MEMORY" -gt 1 ]; then
960 msg "test: compat.sh --memcheck (Release)"
961 if_build_succeeded tests/compat.sh --memcheck
962 fi
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100963}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100964
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100965component_test_cmake_out_of_source () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100966 msg "build: cmake 'out-of-source' build"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100967 MBEDTLS_ROOT_DIR="$PWD"
968 mkdir "$OUT_OF_SOURCE_DIR"
969 cd "$OUT_OF_SOURCE_DIR"
970 cmake "$MBEDTLS_ROOT_DIR"
971 make
972
973 msg "test: cmake 'out-of-source' build"
974 make test
975 # Test an SSL option that requires an auxiliary script in test/scripts/.
976 # Also ensure that there are no error messages such as
977 # "No such file or directory", which would indicate that some required
978 # file is missing (ssl-opt.sh tolerates the absence of some files so
979 # may exit with status 0 but emit errors).
980 if_build_succeeded ./tests/ssl-opt.sh -f 'Fallback SCSV: beginning of list' 2>ssl-opt.err
981 if [ -s ssl-opt.err ]; then
982 cat ssl-opt.err >&2
983 record_status [ ! -s ssl-opt.err ]
984 rm ssl-opt.err
985 fi
986 cd "$MBEDTLS_ROOT_DIR"
987 rm -rf "$OUT_OF_SOURCE_DIR"
988 unset MBEDTLS_ROOT_DIR
989}
Andres AGdc192212016-08-31 17:33:13 +0100990
Gilles Peskine192c72f2017-12-21 15:59:21 +0100991
992
993################################################################
994#### Termination
995################################################################
996
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100997post_report () {
998 msg "Done, cleaning up"
999 cleanup
1000
1001 final_report
1002}
1003
1004
1005
1006################################################################
1007#### Run all the things
1008################################################################
1009
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001010# Run one component and clean up afterwards.
1011run_component () {
Gilles Peskine72adb432019-01-02 18:57:02 +01001012 # Back up the configuration in case the component modifies it.
1013 # The cleanup function will restore it.
1014 cp -p "$CONFIG_H" "$CONFIG_BAK"
Gilles Peskine11ddca62018-12-04 12:49:28 +01001015 current_component="$1"
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001016 "$@"
1017 cleanup
1018}
1019
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001020# Preliminary setup
1021pre_check_environment
1022pre_initialize_variables
1023pre_parse_command_line "$@"
1024
1025pre_check_git
1026build_status=0
1027if [ $KEEP_GOING -eq 1 ]; then
1028 pre_setup_keep_going
1029else
1030 record_status () {
1031 "$@"
1032 }
1033fi
1034pre_print_configuration
1035pre_check_tools
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001036cleanup
Gilles Peskine7c652162017-12-11 00:01:40 +01001037
Gilles Peskineeb39b9b2019-01-08 23:41:00 +01001038# Run the requested tests.
Gilles Peskine6e984232018-11-27 21:37:53 +01001039for component in $RUN_COMPONENTS; do
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001040 run_component "component_$component"
1041done
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001042
1043# We're done.
1044post_report