blob: 215a93d0f6e872bedcad3ffd23238eab72c447ea [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 () {
84 if [ "$( uname )" != "Linux" ]; then
85 echo "This script only works in Linux" >&2
86 exit 1
87 elif [ -d library -a -d include -a -d tests ]; then :; else
88 echo "Must be run from mbed TLS root" >&2
89 exit 1
90 fi
91}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010092
Gilles Peskine57db6ff2019-01-08 22:04:31 +010093pre_initialize_variables () {
94 CONFIG_H='include/mbedtls/config.h'
95 CONFIG_BAK="$CONFIG_H.bak"
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +020096
Gilles Peskine6e984232018-11-27 21:37:53 +010097 ALL_EXCEPT=0
Gilles Peskine57db6ff2019-01-08 22:04:31 +010098 MEMORY=0
99 FORCE=0
100 KEEP_GOING=0
101 RUN_ARMCC=1
102 YOTTA=1
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100103
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100104 # Default commands, can be overriden by the environment
105 : ${OPENSSL:="openssl"}
106 : ${OPENSSL_LEGACY:="$OPENSSL"}
107 : ${GNUTLS_CLI:="gnutls-cli"}
108 : ${GNUTLS_SERV:="gnutls-serv"}
109 : ${GNUTLS_LEGACY_CLI:="$GNUTLS_CLI"}
110 : ${GNUTLS_LEGACY_SERV:="$GNUTLS_SERV"}
111 : ${OUT_OF_SOURCE_DIR:=./mbedtls_out_of_source_build}
112 : ${ARMC5_BIN_DIR:=/usr/bin}
113 : ${ARMC6_BIN_DIR:=/usr/bin}
Andres AGdc192212016-08-31 17:33:13 +0100114
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100115 # if MAKEFLAGS is not set add the -j option to speed up invocations of make
116 if [ -n "${MAKEFLAGS+set}" ]; then
117 export MAKEFLAGS="-j"
118 fi
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100119
120 # Gather the list of available components. These are the functions
121 # defined in this script whose name starts with "component_".
122 # Parse the script with sed, because in sh there is no way to list
123 # defined functions.
124 ALL_COMPONENTS=$(sed -n 's/^ *component_\([0-9A-Z_a-z]*\) *().*/\1/p' <"$0")
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100125}
Andres AG38495a32016-07-12 16:54:33 +0100126
Gilles Peskine6e984232018-11-27 21:37:53 +0100127# Test whether $1 is excluded via $COMPONENTS (a space-separated list of
128# wildcard patterns).
129is_component_excluded()
130{
131 set -f
132 for pattern in $COMPONENTS; do
133 set +f
134 case ${1#component_} in $pattern) return 0;; esac
135 done
136 set +f
137 return 1
138}
139
Simon Butcher41eeccf2016-09-07 00:07:09 +0100140usage()
SimonB2e23c822016-04-16 21:54:39 +0100141{
Gilles Peskine709346a2017-12-10 23:43:39 +0100142 cat <<EOF
Gilles Peskine91bd8b72019-01-08 23:01:34 +0100143Usage: $0 [OPTION]... [COMPONENT]...
144Run mbedtls release validation tests.
145By default, run all tests. With one or more COMPONENT, run only those.
146
147Special options:
148 -h|--help Print this help and exit.
Gilles Peskine709346a2017-12-10 23:43:39 +0100149
150General options:
151 -f|--force Force the tests to overwrite any modified files.
Gilles Peskine7c652162017-12-11 00:01:40 +0100152 -k|--keep-going Run all tests and report errors at the end.
Gilles Peskine709346a2017-12-10 23:43:39 +0100153 -m|--memory Additional optional memory tests.
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100154 --armcc Run ARM Compiler builds (on by default).
Gilles Peskine6e984232018-11-27 21:37:53 +0100155 --except If some components are passed on the command line,
156 run all the tests except for these components. In
157 this mode, you can pass shell wildcard patterns as
158 component names, e.g. "$0 --except 'test_*'" to
159 exclude all components that run tests.
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100160 --no-armcc Skip ARM Compiler builds.
Gilles Peskine19ceb712018-03-21 08:40:26 +0100161 --no-force Refuse to overwrite modified files (default).
162 --no-keep-going Stop at the first error (default).
163 --no-memory No additional memory tests (default).
Gilles Peskine2a22a802017-12-21 15:19:00 +0100164 --no-yotta Skip yotta module build.
Gilles Peskine709346a2017-12-10 23:43:39 +0100165 --out-of-source-dir=<path> Directory used for CMake out-of-source build tests.
Gilles Peskine19ceb712018-03-21 08:40:26 +0100166 --random-seed Use a random seed value for randomized tests (default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100167 -r|--release-test Run this script in release mode. This fixes the seed value to 1.
168 -s|--seed Integer seed value to use for this test run.
Gilles Peskine2a22a802017-12-21 15:19:00 +0100169 --yotta Build yotta module (on by default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100170
171Tool path options:
172 --armc5-bin-dir=<ARMC5_bin_dir_path> ARM Compiler 5 bin directory.
173 --armc6-bin-dir=<ARMC6_bin_dir_path> ARM Compiler 6 bin directory.
174 --gnutls-cli=<GnuTLS_cli_path> GnuTLS client executable to use for most tests.
175 --gnutls-serv=<GnuTLS_serv_path> GnuTLS server executable to use for most tests.
176 --gnutls-legacy-cli=<GnuTLS_cli_path> GnuTLS client executable to use for legacy tests.
177 --gnutls-legacy-serv=<GnuTLS_serv_path> GnuTLS server executable to use for legacy tests.
178 --openssl=<OpenSSL_path> OpenSSL executable to use for most tests.
179 --openssl-legacy=<OpenSSL_path> OpenSSL executable to use for legacy tests e.g. SSLv3.
180EOF
SimonB2e23c822016-04-16 21:54:39 +0100181}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100182
183# remove built files as well as the cmake cache/config
184cleanup()
185{
Gilles Peskinea71d64c2018-03-21 12:16:57 +0100186 if [ -n "${MBEDTLS_ROOT_DIR+set}" ]; then
187 cd "$MBEDTLS_ROOT_DIR"
188 fi
189
Gilles Peskine7c652162017-12-11 00:01:40 +0100190 command make clean
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200191
Gilles Peskine31b07e22018-03-21 12:15:06 +0100192 # Remove CMake artefacts
193 find . -name .git -prune -o -name yotta -prune -o \
194 -iname CMakeFiles -exec rm -rf {} \+ -o \
195 \( -iname cmake_install.cmake -o \
196 -iname CTestTestfile.cmake -o \
197 -iname CMakeCache.txt \) -exec rm {} \+
198 # Recover files overwritten by in-tree CMake builds
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000199 rm -f include/Makefile include/mbedtls/Makefile programs/*/Makefile
Paul Bakkerfe0984d2014-06-13 00:13:45 +0200200 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile
201 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200202
203 if [ -f "$CONFIG_BAK" ]; then
204 mv "$CONFIG_BAK" "$CONFIG_H"
205 fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100206}
207
Gilles Peskine7c652162017-12-11 00:01:40 +0100208# Executed on exit. May be redefined depending on command line options.
209final_report () {
210 :
211}
212
213fatal_signal () {
214 cleanup
215 final_report $1
216 trap - $1
217 kill -$1 $$
218}
219
220trap 'fatal_signal HUP' HUP
221trap 'fatal_signal INT' INT
222trap 'fatal_signal TERM' TERM
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200223
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100224msg()
225{
Gilles Peskine11ddca62018-12-04 12:49:28 +0100226 if [ -n "${current_component:-}" ]; then
227 current_section="${current_component#component_}: $1"
228 else
229 current_section="$1"
230 fi
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100231 echo ""
232 echo "******************************************************************"
Gilles Peskine11ddca62018-12-04 12:49:28 +0100233 echo "* $current_section "
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000234 printf "* "; date
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100235 echo "******************************************************************"
236}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100237
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100238armc6_build_test()
239{
240 FLAGS="$1"
Andres AGa5cd9732016-10-17 15:23:10 +0100241
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100242 msg "build: ARM Compiler 6 ($FLAGS), make"
243 ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \
244 WARNING_CFLAGS='-xc -std=c99' make lib
245 make clean
246}
Andres AGa5cd9732016-10-17 15:23:10 +0100247
Andres AGd9eba4b2016-08-26 14:42:14 +0100248err_msg()
249{
250 echo "$1" >&2
251}
252
253check_tools()
254{
255 for TOOL in "$@"; do
Andres AG98393602017-01-31 17:04:45 +0000256 if ! `type "$TOOL" >/dev/null 2>&1`; then
Andres AGd9eba4b2016-08-26 14:42:14 +0100257 err_msg "$TOOL not found!"
258 exit 1
259 fi
260 done
261}
262
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100263pre_parse_command_line () {
Gilles Peskine6e984232018-11-27 21:37:53 +0100264 COMPONENTS=
265
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100266 while [ $# -gt 0 ]; do
267 case "$1" in
268 --armcc) RUN_ARMCC=1;;
269 --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
270 --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
Gilles Peskine6e984232018-11-27 21:37:53 +0100271 --except) ALL_EXCEPT=1;;
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100272 --force|-f) FORCE=1;;
273 --gnutls-cli) shift; GNUTLS_CLI="$1";;
274 --gnutls-legacy-cli) shift; GNUTLS_LEGACY_CLI="$1";;
275 --gnutls-legacy-serv) shift; GNUTLS_LEGACY_SERV="$1";;
276 --gnutls-serv) shift; GNUTLS_SERV="$1";;
277 --help|-h) usage; exit;;
278 --keep-going|-k) KEEP_GOING=1;;
279 --memory|-m) MEMORY=1;;
280 --no-armcc) RUN_ARMCC=0;;
281 --no-force) FORCE=0;;
282 --no-keep-going) KEEP_GOING=0;;
283 --no-memory) MEMORY=0;;
284 --no-yotta) YOTTA=0;;
285 --openssl) shift; OPENSSL="$1";;
286 --openssl-legacy) shift; OPENSSL_LEGACY="$1";;
287 --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
288 --random-seed) unset SEED;;
289 --release-test|-r) SEED=1;;
290 --seed|-s) shift; SEED="$1";;
291 --yotta) YOTTA=1;;
Gilles Peskine91bd8b72019-01-08 23:01:34 +0100292 -*)
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100293 echo >&2 "Unknown option: $1"
294 echo >&2 "Run $0 --help for usage."
295 exit 120
296 ;;
Gilles Peskine91bd8b72019-01-08 23:01:34 +0100297 *)
298 COMPONENTS="$COMPONENTS $1";;
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100299 esac
300 shift
301 done
Gilles Peskine91bd8b72019-01-08 23:01:34 +0100302
Gilles Peskine6e984232018-11-27 21:37:53 +0100303 if [ $ALL_EXCEPT -ne 0 ]; then
304 RUN_COMPONENTS=
305 for component in $ALL_COMPONENTS; do
306 if ! is_component_excluded "$component"; then
307 RUN_COMPONENTS="$RUN_COMPONENTS $component"
308 fi
309 done
310 elif [ -z "$COMPONENTS" ]; then
311 RUN_COMPONENTS="$ALL_COMPONENTS"
312 else
313 RUN_COMPONENTS="$COMPONENTS"
Gilles Peskine91bd8b72019-01-08 23:01:34 +0100314 fi
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100315}
SimonB2e23c822016-04-16 21:54:39 +0100316
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100317pre_check_git () {
318 if [ $FORCE -eq 1 ]; then
319 if [ $YOTTA -eq 1 ]; then
320 rm -rf yotta/module "$OUT_OF_SOURCE_DIR"
321 fi
322 git checkout-index -f -q $CONFIG_H
323 cleanup
324 else
325
326 if [ $YOTTA -ne 0 ] && [ -d yotta/module ]; then
327 err_msg "Warning - there is an existing yotta module in the directory 'yotta/module'"
328 echo "You can either delete your work and retry, or force the test to overwrite the"
329 echo "test by rerunning the script as: $0 --force"
330 exit 1
331 fi
332
333 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
334 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
335 echo "You can either delete this directory manually, or force the test by rerunning"
336 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
337 exit 1
338 fi
339
340 if ! git diff-files --quiet include/mbedtls/config.h; then
341 err_msg "Warning - the configuration file 'include/mbedtls/config.h' has been edited. "
342 echo "You can either delete or preserve your work, or force the test by rerunning the"
343 echo "script as: $0 --force"
344 exit 1
345 fi
Gilles Peskineda519252017-11-30 13:22:04 +0100346 fi
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100347}
SimonB2e23c822016-04-16 21:54:39 +0100348
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100349pre_setup_keep_going () {
Gilles Peskine7c652162017-12-11 00:01:40 +0100350 failure_summary=
351 failure_count=0
352 start_red=
353 end_color=
354 if [ -t 1 ]; then
Gilles Peskine9736b9d2018-01-02 21:54:17 +0100355 case "${TERM:-}" in
Gilles Peskine7c652162017-12-11 00:01:40 +0100356 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
357 start_red=$(printf '\033[31m')
358 end_color=$(printf '\033[0m')
359 ;;
360 esac
361 fi
362 record_status () {
363 if "$@"; then
364 last_status=0
365 else
366 last_status=$?
367 text="$current_section: $* -> $last_status"
368 failure_summary="$failure_summary
369$text"
370 failure_count=$((failure_count + 1))
371 echo "${start_red}^^^^$text^^^^${end_color}"
372 fi
373 }
374 make () {
375 case "$*" in
376 *test|*check)
377 if [ $build_status -eq 0 ]; then
378 record_status command make "$@"
379 else
380 echo "(skipped because the build failed)"
381 fi
382 ;;
383 *)
384 record_status command make "$@"
385 build_status=$last_status
386 ;;
387 esac
388 }
389 final_report () {
390 if [ $failure_count -gt 0 ]; then
391 echo
392 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
393 echo "${start_red}FAILED: $failure_count${end_color}$failure_summary"
394 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Jaeden Amero5113bde2018-07-20 16:42:14 +0100395 exit 1
Gilles Peskine7c652162017-12-11 00:01:40 +0100396 elif [ -z "${1-}" ]; then
397 echo "SUCCESS :)"
398 fi
399 if [ -n "${1-}" ]; then
400 echo "Killed by SIG$1."
401 fi
402 }
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100403}
404
Gilles Peskine7c652162017-12-11 00:01:40 +0100405if_build_succeeded () {
406 if [ $build_status -eq 0 ]; then
407 record_status "$@"
408 fi
409}
410
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100411pre_print_configuration () {
412 msg "info: $0 configuration"
413 echo "MEMORY: $MEMORY"
414 echo "FORCE: $FORCE"
415 echo "SEED: ${SEED-"UNSET"}"
416 echo "OPENSSL: $OPENSSL"
417 echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
418 echo "GNUTLS_CLI: $GNUTLS_CLI"
419 echo "GNUTLS_SERV: $GNUTLS_SERV"
420 echo "GNUTLS_LEGACY_CLI: $GNUTLS_LEGACY_CLI"
421 echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV"
422 echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
423 echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
424}
Andres AG7770ea82016-10-10 15:46:20 +0100425
Andres AGd9eba4b2016-08-26 14:42:14 +0100426# Make sure the tools we need are available.
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100427pre_check_tools () {
428 ARMC5_CC="$ARMC5_BIN_DIR/armcc"
429 ARMC5_AR="$ARMC5_BIN_DIR/armar"
430 ARMC6_CC="$ARMC6_BIN_DIR/armclang"
431 ARMC6_AR="$ARMC6_BIN_DIR/armar"
432
433 # To avoid setting OpenSSL and GnuTLS for each call to compat.sh and ssl-opt.sh
434 # we just export the variables they require
435 export OPENSSL_CMD="$OPENSSL"
436 export GNUTLS_CLI="$GNUTLS_CLI"
437 export GNUTLS_SERV="$GNUTLS_SERV"
438
439 # Avoid passing --seed flag in every call to ssl-opt.sh
440 if [ -n "${SEED-}" ]; then
441 export SEED
442 fi
443
444 check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$GNUTLS_CLI" "$GNUTLS_SERV" \
445 "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV" "doxygen" "dot" \
446 "arm-none-eabi-gcc" "i686-w64-mingw32-gcc"
447 if [ $RUN_ARMCC -ne 0 ]; then
448 check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC6_CC" "$ARMC6_AR"
449 fi
450
451 msg "info: output_env.sh"
452 OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY" GNUTLS_CLI="$GNUTLS_CLI" \
453 GNUTLS_SERV="$GNUTLS_SERV" GNUTLS_LEGACY_CLI="$GNUTLS_LEGACY_CLI" \
454 GNUTLS_LEGACY_SERV="$GNUTLS_LEGACY_SERV" ARMC5_CC="$ARMC5_CC" \
455 ARMC6_CC="$ARMC6_CC" RUN_ARMCC="$RUN_ARMCC" scripts/output_env.sh
456}
Andres AGd9eba4b2016-08-26 14:42:14 +0100457
Gilles Peskine192c72f2017-12-21 15:59:21 +0100458
459
460################################################################
461#### Basic checks
462################################################################
SimonB2e23c822016-04-16 21:54:39 +0100463
464#
465# Test Suites to be executed
466#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200467# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100468# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard61bc57a2014-08-14 11:29:06 +0200469# and/or are more likely to fail than others (eg I use Clang most of the
470# time, so start with a GCC build).
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200471# 2. Minimize total running time, by avoiding useless rebuilds
472#
473# Indicative running times are given for reference.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100474
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100475component_check_recursion () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100476 msg "test: recursion.pl" # < 1s
477 record_status tests/scripts/recursion.pl library/*.c
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100478}
Manuel Pégourié-Gonnardea29d152014-11-20 17:32:33 +0100479
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100480component_check_generated_files () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100481 msg "test: freshness of generated source files" # < 1s
482 record_status tests/scripts/check-generated-files.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100483}
Manuel Pégourié-Gonnardb3b8e432015-02-13 14:52:19 +0000484
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100485component_check_doxy_blocks () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100486 msg "test: doxygen markup outside doxygen blocks" # < 1s
487 record_status tests/scripts/check-doxy-blocks.pl
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100488}
Manuel Pégourié-Gonnardd09a6b52015-04-09 17:19:23 +0200489
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100490component_check_files () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100491 msg "test: check-files.py" # < 1s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100492 record_status tests/scripts/check-files.py
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100493}
Manuel Pégourié-Gonnard77d56bb2015-07-28 15:00:37 +0200494
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100495component_check_names () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100496 msg "test/build: declared and exported names" # < 3s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100497 record_status tests/scripts/check-names.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100498}
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +0200499
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100500component_check_doxygen_warnings () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100501 msg "test: doxygen warnings" # ~ 3s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100502 record_status tests/scripts/doxygen.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100503}
Andres Amaya Garciadd29c2f2017-05-04 11:35:51 +0100504
Simon Butcher948f2642018-07-20 21:27:33 +0100505
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100506################################################################
507#### Build and test many configurations and targets
508################################################################
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100509
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100510component_build_yotta () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100511 if [ $RUN_ARMCC -ne 0 ] && [ $YOTTA -ne 0 ]; then
512 # Note - use of yotta is deprecated, and yotta also requires armcc to be on the
513 # path, and uses whatever version of armcc it finds there.
514 msg "build: create and build yotta module" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100515 record_status tests/scripts/yotta-build.sh
516 fi
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100517}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100518
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100519component_test_default_cmake_gcc_asan () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100520 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100521 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100522 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +0200523
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100524 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100525 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100526
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100527 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
Gilles Peskine7c652162017-12-11 00:01:40 +0100528 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100529
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100530 msg "test: compat.sh (ASan build)" # ~ 6 min
531 if_build_succeeded tests/compat.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100532}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000533
Gilles Peskine3484ed82019-01-08 22:51:19 +0100534component_test_ref_configs () {
535 msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
536 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
537 record_status tests/scripts/test-ref-configs.pl
538}
539
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100540component_test_sslv3 () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100541 msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100542 scripts/config.pl set MBEDTLS_SSL_PROTO_SSL3
543 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
544 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000545
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100546 msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
547 make test
548
549 msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
550 if_build_succeeded tests/compat.sh -m 'tls1 tls1_1 tls1_2 dtls1 dtls1_2'
551 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
552
553 msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
554 if_build_succeeded tests/ssl-opt.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100555}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100556
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100557component_test_no_renegotiation () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100558 msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100559 scripts/config.pl unset MBEDTLS_SSL_RENEGOTIATION
560 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
561 make
562
563 msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
564 make test
565
566 msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
567 if_build_succeeded tests/ssl-opt.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100568}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100569
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100570component_test_rsa_no_crt () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100571 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100572 scripts/config.pl set MBEDTLS_RSA_NO_CRT
573 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
574 make
575
576 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
577 make test
578
579 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
580 if_build_succeeded tests/ssl-opt.sh -f RSA
581
582 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
583 if_build_succeeded tests/compat.sh -t RSA
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100584}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100585
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100586component_test_full_cmake_clang () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100587 msg "build: cmake, full config, clang" # ~ 50s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100588 scripts/config.pl full
589 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
590 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check -D ENABLE_TESTING=On .
591 make
592
593 msg "test: main suites (full config)" # ~ 5s
594 make test
595
596 msg "test: ssl-opt.sh default (full config)" # ~ 1s
597 if_build_succeeded tests/ssl-opt.sh -f Default
598
599 msg "test: compat.sh RC4, DES & NULL (full config)" # ~ 2 min
600 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 +0100601}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100602
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100603component_build_deprecated () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100604 msg "build: make, full config + DEPRECATED_WARNING, gcc -O" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100605 scripts/config.pl full
606 scripts/config.pl set MBEDTLS_DEPRECATED_WARNING
607 # Build with -O -Wextra to catch a maximum of issues.
608 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra' lib programs
609 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
610
611 msg "build: make, full config + DEPRECATED_REMOVED, clang -O" # ~ 30s
612 # No cleanup, just tweak the configuration and rebuild
613 make clean
614 scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
615 scripts/config.pl set MBEDTLS_DEPRECATED_REMOVED
616 # Build with -O -Wextra to catch a maximum of issues.
617 make CC=clang CFLAGS='-O -Werror -Wall -Wextra' lib programs
618 make CC=clang CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100619}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100620
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100621component_test_depends_curves () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100622 msg "test/build: curves.pl (gcc)" # ~ 4 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100623 record_status tests/scripts/curves.pl
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100624}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100625
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100626component_test_depends_hashes () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100627 msg "test/build: depends-hashes.pl (gcc)" # ~ 2 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100628 record_status tests/scripts/depends-hashes.pl
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100629}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100630
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100631component_test_depends_pkalgs () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100632 msg "test/build: depends-pkalgs.pl (gcc)" # ~ 2 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100633 record_status tests/scripts/depends-pkalgs.pl
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100634}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100635
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100636component_build_key_exchanges () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100637 msg "test/build: key-exchanges (gcc)" # ~ 1 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100638 record_status tests/scripts/key-exchanges.pl
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100639}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100640
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100641component_build_default_make_gcc () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100642 msg "build: Unix make, -Os (gcc)" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100643 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100644}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100645
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100646component_test_no_platform () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100647 # Full configuration build, without platform support, file IO and net sockets.
648 # This should catch missing mbedtls_printf definitions, and by disabling file
649 # IO, it should catch missing '#include <stdio.h>'
650 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100651 scripts/config.pl full
652 scripts/config.pl unset MBEDTLS_PLATFORM_C
653 scripts/config.pl unset MBEDTLS_NET_C
654 scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
655 scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
656 scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
657 scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
658 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
659 scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
660 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
661 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
662 scripts/config.pl unset MBEDTLS_FS_IO
663 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
664 # to re-enable platform integration features otherwise disabled in C99 builds
665 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -O0 -D_DEFAULT_SOURCE' lib programs
666 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0' test
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100667}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100668
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100669component_build_no_std_function () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100670 # catch compile bugs in _uninit functions
671 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100672 scripts/config.pl full
673 scripts/config.pl set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
674 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
675 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100676}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100677
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100678component_build_no_ssl_srv () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100679 msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100680 scripts/config.pl full
681 scripts/config.pl unset MBEDTLS_SSL_SRV_C
682 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100683}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100684
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100685component_build_no_ssl_cli () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100686 msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100687 scripts/config.pl full
688 scripts/config.pl unset MBEDTLS_SSL_CLI_C
689 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100690}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100691
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100692component_build_no_sockets () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100693 # Note, C99 compliance can also be tested with the sockets support disabled,
694 # as that requires a POSIX platform (which isn't the same as C99).
695 msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100696 scripts/config.pl full
697 scripts/config.pl unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
698 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
699 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0 -std=c99 -pedantic' lib
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100700}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100701
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100702component_test_no_max_fragment_length () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100703 msg "build: default config except MFL extension (ASan build)" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100704 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
705 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
706 make
707
708 msg "test: ssl-opt.sh, MFL-related tests"
709 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length"
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100710}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100711
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100712component_test_null_entropy () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100713 msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100714 scripts/config.pl set MBEDTLS_TEST_NULL_ENTROPY
715 scripts/config.pl set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
716 scripts/config.pl set MBEDTLS_ENTROPY_C
717 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
718 scripts/config.pl unset MBEDTLS_ENTROPY_HARDWARE_ALT
719 scripts/config.pl unset MBEDTLS_HAVEGE_C
720 CC=gcc cmake -D UNSAFE_BUILD=ON -D CMAKE_C_FLAGS:String="-fsanitize=address -fno-common -O3" .
721 make
722
723 msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)"
724 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100725}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100726
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100727component_test_platform_calloc_macro () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100728 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100729 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
730 scripts/config.pl set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
731 scripts/config.pl set MBEDTLS_PLATFORM_FREE_MACRO free
732 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
733 make
734
735 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (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_make_shared () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100740 if uname -a | grep -F Linux >/dev/null; then
741 msg "build/test: make shared" # ~ 40s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100742 make SHARED=1 all check
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100743 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000744
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100745}
746
747component_test_m32_o0 () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100748 if uname -a | grep -F x86_64 >/dev/null; then
749 # Build once with -O0, to compile out the i386 specific inline assembly
750 msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100751 scripts/config.pl full
752 make CC=gcc CFLAGS='-O0 -Werror -Wall -Wextra -m32 -fsanitize=address'
753
754 msg "test: i386, make, gcc -O0 (ASan build)"
755 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100756 fi # x86_64
757}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100758
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100759component_test_m32_o1 () {
760 if uname -a | grep -F x86_64 >/dev/null; then
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100761 # Build again with -O1, to compile in the i386 specific inline assembly
762 msg "build: i386, make, gcc -O1 (ASan build)" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100763 scripts/config.pl full
764 make CC=gcc CFLAGS='-O1 -Werror -Wall -Wextra -m32 -fsanitize=address'
765
766 msg "test: i386, make, gcc -O1 (ASan build)"
767 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100768 fi # x86_64
769}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100770
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100771component_test_mx32 () {
772 if uname -a | grep -F x86_64 >/dev/null; then
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100773 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100774 scripts/config.pl full
775 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32'
776
777 msg "test: 64-bit ILP32, make, gcc"
778 make test
779 fi # x86_64
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100780}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100781
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100782component_test_have_int32 () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100783 msg "build: gcc, force 32-bit bignum limbs"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100784 scripts/config.pl unset MBEDTLS_HAVE_ASM
785 scripts/config.pl unset MBEDTLS_AESNI_C
786 scripts/config.pl unset MBEDTLS_PADLOCK_C
787 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
788
789 msg "test: gcc, force 32-bit bignum limbs"
790 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100791}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100792
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100793component_test_have_int64 () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100794 msg "build: gcc, force 64-bit bignum limbs"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100795 scripts/config.pl unset MBEDTLS_HAVE_ASM
796 scripts/config.pl unset MBEDTLS_AESNI_C
797 scripts/config.pl unset MBEDTLS_PADLOCK_C
798 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
799
800 msg "test: gcc, force 64-bit bignum limbs"
801 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100802}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100803
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100804component_build_arm_none_eabi_gcc () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100805 msg "build: arm-none-eabi-gcc, make" # ~ 10s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100806 scripts/config.pl full
807 scripts/config.pl unset MBEDTLS_NET_C
808 scripts/config.pl unset MBEDTLS_TIMING_C
809 scripts/config.pl unset MBEDTLS_FS_IO
810 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
811 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
812 # following things are not in the default config
813 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
814 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
815 scripts/config.pl unset MBEDTLS_THREADING_C
816 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
817 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
818 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 +0100819}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100820
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100821component_build_arm_none_eabi_gcc_no_udbl_division () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100822 msg "build: arm-none-eabi-gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100823 scripts/config.pl full
824 scripts/config.pl unset MBEDTLS_NET_C
825 scripts/config.pl unset MBEDTLS_TIMING_C
826 scripts/config.pl unset MBEDTLS_FS_IO
827 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
828 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
829 # following things are not in the default config
830 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
831 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
832 scripts/config.pl unset MBEDTLS_THREADING_C
833 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
834 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
835 scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
836 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
837 echo "Checking that software 64-bit division is not required"
838 ! grep __aeabi_uldiv library/*.o
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100839}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100840
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100841component_build_armcc () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100842 msg "build: ARM Compiler 5, make"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100843 scripts/config.pl full
844 scripts/config.pl unset MBEDTLS_NET_C
845 scripts/config.pl unset MBEDTLS_TIMING_C
846 scripts/config.pl unset MBEDTLS_FS_IO
847 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
848 scripts/config.pl unset MBEDTLS_HAVE_TIME
849 scripts/config.pl unset MBEDTLS_HAVE_TIME_DATE
850 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
851 # following things are not in the default config
852 scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
853 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
854 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
855 scripts/config.pl unset MBEDTLS_THREADING_C
856 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
857 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
858 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT # depends on MBEDTLS_HAVE_TIME
859
860 if [ $RUN_ARMCC -ne 0 ]; then
861 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
862 make clean
863
864 # ARM Compiler 6 - Target ARMv7-A
865 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-a"
866
867 # ARM Compiler 6 - Target ARMv7-M
868 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m"
869
870 # ARM Compiler 6 - Target ARMv8-A - AArch32
871 armc6_build_test "--target=arm-arm-none-eabi -march=armv8.2-a"
872
873 # ARM Compiler 6 - Target ARMv8-M
874 armc6_build_test "--target=arm-arm-none-eabi -march=armv8-m.main"
875
876 # ARM Compiler 6 - Target ARMv8-A - AArch64
877 armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a"
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100878 fi
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100879}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000880
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100881component_test_allow_sha1 () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100882 msg "build: allow SHA1 in certificates by default"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100883 scripts/config.pl set MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
884 make CFLAGS='-Werror -Wall -Wextra'
885 msg "test: allow SHA1 in certificates by default"
886 make test
887 if_build_succeeded tests/ssl-opt.sh -f SHA-1
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100888}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000889
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100890component_build_mingw () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100891 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100892 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
893
894 # note Make tests only builds the tests, but doesn't run them
895 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror' WINDOWS_BUILD=1 tests
896 make WINDOWS_BUILD=1 clean
897
898 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
899 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
900 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
901 make WINDOWS_BUILD=1 clean
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100902}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100903
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100904component_test_memsan () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100905 # MemSan currently only available on Linux 64 bits
906 if uname -a | grep 'Linux.*x86_64' >/dev/null; then
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100907 msg "build: MSan (clang)" # ~ 1 min 20s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100908 scripts/config.pl unset MBEDTLS_AESNI_C # memsan doesn't grok asm
909 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
910 make
911
912 msg "test: main suites (MSan)" # ~ 10s
913 make test
914
915 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
916 if_build_succeeded tests/ssl-opt.sh
917
918 # Optional part(s)
919
920 if [ "$MEMORY" -gt 0 ]; then
921 msg "test: compat.sh (MSan)" # ~ 6 min 20s
922 if_build_succeeded tests/compat.sh
923 fi
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100924 fi
925}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100926
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100927component_test_memcheck () {
928 # Only run if MemSan is not available
929 if ! uname -a | grep 'Linux.*x86_64' >/dev/null; then
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100930 msg "build: Release (clang)"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100931 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
932 make
933
934 msg "test: main suites valgrind (Release)"
935 make memcheck
936
937 # Optional part(s)
938 # Currently broken, programs don't seem to receive signals
939 # under valgrind on OS X
940
941 if [ "$MEMORY" -gt 0 ]; then
942 msg "test: ssl-opt.sh --memcheck (Release)"
943 if_build_succeeded tests/ssl-opt.sh --memcheck
944 fi
945
946 if [ "$MEMORY" -gt 1 ]; then
947 msg "test: compat.sh --memcheck (Release)"
948 if_build_succeeded tests/compat.sh --memcheck
949 fi
950
951 fi # MemSan
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100952}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100953
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100954component_test_cmake_out_of_source () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100955 msg "build: cmake 'out-of-source' build"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100956 MBEDTLS_ROOT_DIR="$PWD"
957 mkdir "$OUT_OF_SOURCE_DIR"
958 cd "$OUT_OF_SOURCE_DIR"
959 cmake "$MBEDTLS_ROOT_DIR"
960 make
961
962 msg "test: cmake 'out-of-source' build"
963 make test
964 # Test an SSL option that requires an auxiliary script in test/scripts/.
965 # Also ensure that there are no error messages such as
966 # "No such file or directory", which would indicate that some required
967 # file is missing (ssl-opt.sh tolerates the absence of some files so
968 # may exit with status 0 but emit errors).
969 if_build_succeeded ./tests/ssl-opt.sh -f 'Fallback SCSV: beginning of list' 2>ssl-opt.err
970 if [ -s ssl-opt.err ]; then
971 cat ssl-opt.err >&2
972 record_status [ ! -s ssl-opt.err ]
973 rm ssl-opt.err
974 fi
975 cd "$MBEDTLS_ROOT_DIR"
976 rm -rf "$OUT_OF_SOURCE_DIR"
977 unset MBEDTLS_ROOT_DIR
978}
Andres AGdc192212016-08-31 17:33:13 +0100979
Gilles Peskine192c72f2017-12-21 15:59:21 +0100980
981
982################################################################
983#### Termination
984################################################################
985
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100986post_report () {
987 msg "Done, cleaning up"
988 cleanup
989
990 final_report
991}
992
993
994
995################################################################
996#### Run all the things
997################################################################
998
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100999# Run one component and clean up afterwards.
1000run_component () {
Gilles Peskine72adb432019-01-02 18:57:02 +01001001 # Back up the configuration in case the component modifies it.
1002 # The cleanup function will restore it.
1003 cp -p "$CONFIG_H" "$CONFIG_BAK"
Gilles Peskine11ddca62018-12-04 12:49:28 +01001004 current_component="$1"
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001005 "$@"
1006 cleanup
1007}
1008
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001009# Preliminary setup
1010pre_check_environment
1011pre_initialize_variables
1012pre_parse_command_line "$@"
1013
1014pre_check_git
1015build_status=0
1016if [ $KEEP_GOING -eq 1 ]; then
1017 pre_setup_keep_going
1018else
1019 record_status () {
1020 "$@"
1021 }
1022fi
1023pre_print_configuration
1024pre_check_tools
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001025cleanup
Gilles Peskine7c652162017-12-11 00:01:40 +01001026
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001027# Run all the test components.
Gilles Peskine6e984232018-11-27 21:37:53 +01001028for component in $RUN_COMPONENTS; do
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001029 run_component "component_$component"
1030done
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001031
1032# We're done.
1033post_report