blob: f3a1da1d1455aea2dc13bb08b9a85c24234c3213 [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 cp "$CONFIG_H" "$CONFIG_BAK"
543 scripts/config.pl set MBEDTLS_SSL_PROTO_SSL3
544 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
545 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000546
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100547 msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
548 make test
549
550 msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
551 if_build_succeeded tests/compat.sh -m 'tls1 tls1_1 tls1_2 dtls1 dtls1_2'
552 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
553
554 msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
555 if_build_succeeded tests/ssl-opt.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100556}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100557
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100558component_test_no_renegotiation () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100559 msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100560 cp "$CONFIG_H" "$CONFIG_BAK"
561 scripts/config.pl unset MBEDTLS_SSL_RENEGOTIATION
562 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
563 make
564
565 msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
566 make test
567
568 msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
569 if_build_succeeded tests/ssl-opt.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100570}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100571
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100572component_test_rsa_no_crt () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100573 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100574 cp "$CONFIG_H" "$CONFIG_BAK"
575 scripts/config.pl set MBEDTLS_RSA_NO_CRT
576 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
577 make
578
579 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
580 make test
581
582 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
583 if_build_succeeded tests/ssl-opt.sh -f RSA
584
585 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
586 if_build_succeeded tests/compat.sh -t RSA
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100587}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100588
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100589component_test_full_cmake_clang () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100590 msg "build: cmake, full config, clang" # ~ 50s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100591 cp "$CONFIG_H" "$CONFIG_BAK"
592 scripts/config.pl full
593 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
594 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check -D ENABLE_TESTING=On .
595 make
596
597 msg "test: main suites (full config)" # ~ 5s
598 make test
599
600 msg "test: ssl-opt.sh default (full config)" # ~ 1s
601 if_build_succeeded tests/ssl-opt.sh -f Default
602
603 msg "test: compat.sh RC4, DES & NULL (full config)" # ~ 2 min
604 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 +0100605}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100606
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100607component_build_deprecated () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100608 msg "build: make, full config + DEPRECATED_WARNING, gcc -O" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100609 cp "$CONFIG_H" "$CONFIG_BAK"
610 scripts/config.pl full
611 scripts/config.pl set MBEDTLS_DEPRECATED_WARNING
612 # Build with -O -Wextra to catch a maximum of issues.
613 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra' lib programs
614 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
615
616 msg "build: make, full config + DEPRECATED_REMOVED, clang -O" # ~ 30s
617 # No cleanup, just tweak the configuration and rebuild
618 make clean
619 scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
620 scripts/config.pl set MBEDTLS_DEPRECATED_REMOVED
621 # Build with -O -Wextra to catch a maximum of issues.
622 make CC=clang CFLAGS='-O -Werror -Wall -Wextra' lib programs
623 make CC=clang CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
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_curves () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100627 msg "test/build: curves.pl (gcc)" # ~ 4 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100628 record_status tests/scripts/curves.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_hashes () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100632 msg "test/build: depends-hashes.pl (gcc)" # ~ 2 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100633 record_status tests/scripts/depends-hashes.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_test_depends_pkalgs () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100637 msg "test/build: depends-pkalgs.pl (gcc)" # ~ 2 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100638 record_status tests/scripts/depends-pkalgs.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_key_exchanges () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100642 msg "test/build: key-exchanges (gcc)" # ~ 1 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100643 record_status tests/scripts/key-exchanges.pl
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100644}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100645
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100646component_build_default_make_gcc () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100647 msg "build: Unix make, -Os (gcc)" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100648 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100649}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100650
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100651component_test_no_platform () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100652 # Full configuration build, without platform support, file IO and net sockets.
653 # This should catch missing mbedtls_printf definitions, and by disabling file
654 # IO, it should catch missing '#include <stdio.h>'
655 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100656 cp "$CONFIG_H" "$CONFIG_BAK"
657 scripts/config.pl full
658 scripts/config.pl unset MBEDTLS_PLATFORM_C
659 scripts/config.pl unset MBEDTLS_NET_C
660 scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
661 scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
662 scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
663 scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
664 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
665 scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
666 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
667 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
668 scripts/config.pl unset MBEDTLS_FS_IO
669 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
670 # to re-enable platform integration features otherwise disabled in C99 builds
671 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -O0 -D_DEFAULT_SOURCE' lib programs
672 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0' test
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100673}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100674
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100675component_build_no_std_function () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100676 # catch compile bugs in _uninit functions
677 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100678 cp "$CONFIG_H" "$CONFIG_BAK"
679 scripts/config.pl full
680 scripts/config.pl set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
681 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
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_srv () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100686 msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100687 cp "$CONFIG_H" "$CONFIG_BAK"
688 scripts/config.pl full
689 scripts/config.pl unset MBEDTLS_SSL_SRV_C
690 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100691}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100692
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100693component_build_no_ssl_cli () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100694 msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100695 cp "$CONFIG_H" "$CONFIG_BAK"
696 scripts/config.pl full
697 scripts/config.pl unset MBEDTLS_SSL_CLI_C
698 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100699}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100700
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100701component_build_no_sockets () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100702 # Note, C99 compliance can also be tested with the sockets support disabled,
703 # as that requires a POSIX platform (which isn't the same as C99).
704 msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100705 cp "$CONFIG_H" "$CONFIG_BAK"
706 scripts/config.pl full
707 scripts/config.pl unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
708 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
709 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0 -std=c99 -pedantic' lib
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_no_max_fragment_length () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100713 msg "build: default config except MFL extension (ASan build)" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100714 cp "$CONFIG_H" "$CONFIG_BAK"
715 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
716 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
717 make
718
719 msg "test: ssl-opt.sh, MFL-related tests"
720 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length"
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100721}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100722
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100723component_test_null_entropy () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100724 msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100725 cp "$CONFIG_H" "$CONFIG_BAK"
726 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
732 CC=gcc cmake -D UNSAFE_BUILD=ON -D CMAKE_C_FLAGS:String="-fsanitize=address -fno-common -O3" .
733 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 cp "$CONFIG_H" "$CONFIG_BAK"
742 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
743 scripts/config.pl set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
744 scripts/config.pl set MBEDTLS_PLATFORM_FREE_MACRO free
745 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
746 make
747
748 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
749 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100750}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100751
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100752component_test_make_shared () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100753 if uname -a | grep -F Linux >/dev/null; then
754 msg "build/test: make shared" # ~ 40s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100755 make SHARED=1 all check
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100756 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000757
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100758}
759
760component_test_m32_o0 () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100761 if uname -a | grep -F x86_64 >/dev/null; then
762 # Build once with -O0, to compile out the i386 specific inline assembly
763 msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100764 cp "$CONFIG_H" "$CONFIG_BAK"
765 scripts/config.pl full
766 make CC=gcc CFLAGS='-O0 -Werror -Wall -Wextra -m32 -fsanitize=address'
767
768 msg "test: i386, make, gcc -O0 (ASan build)"
769 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100770 fi # x86_64
771}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100772
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100773component_test_m32_o1 () {
774 if uname -a | grep -F x86_64 >/dev/null; then
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100775 # Build again with -O1, to compile in the i386 specific inline assembly
776 msg "build: i386, make, gcc -O1 (ASan build)" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100777 cp "$CONFIG_H" "$CONFIG_BAK"
778 scripts/config.pl full
779 make CC=gcc CFLAGS='-O1 -Werror -Wall -Wextra -m32 -fsanitize=address'
780
781 msg "test: i386, make, gcc -O1 (ASan build)"
782 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100783 fi # x86_64
784}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100785
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100786component_test_mx32 () {
787 if uname -a | grep -F x86_64 >/dev/null; then
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100788 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100789 cp "$CONFIG_H" "$CONFIG_BAK"
790 scripts/config.pl full
791 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32'
792
793 msg "test: 64-bit ILP32, make, gcc"
794 make test
795 fi # x86_64
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100796}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100797
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100798component_test_have_int32 () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100799 msg "build: gcc, force 32-bit bignum limbs"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100800 cp "$CONFIG_H" "$CONFIG_BAK"
801 scripts/config.pl unset MBEDTLS_HAVE_ASM
802 scripts/config.pl unset MBEDTLS_AESNI_C
803 scripts/config.pl unset MBEDTLS_PADLOCK_C
804 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
805
806 msg "test: gcc, force 32-bit bignum limbs"
807 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100808}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100809
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100810component_test_have_int64 () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100811 msg "build: gcc, force 64-bit bignum limbs"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100812 cp "$CONFIG_H" "$CONFIG_BAK"
813 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 cp "$CONFIG_H" "$CONFIG_BAK"
825 scripts/config.pl full
826 scripts/config.pl unset MBEDTLS_NET_C
827 scripts/config.pl unset MBEDTLS_TIMING_C
828 scripts/config.pl unset MBEDTLS_FS_IO
829 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
830 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
831 # following things are not in the default config
832 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
833 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
834 scripts/config.pl unset MBEDTLS_THREADING_C
835 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
836 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
837 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 +0100838}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100839
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100840component_build_arm_none_eabi_gcc_no_udbl_division () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100841 msg "build: arm-none-eabi-gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100842 cp "$CONFIG_H" "$CONFIG_BAK"
843 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 set MBEDTLS_NO_PLATFORM_ENTROPY
849 # following things are not in the default config
850 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
851 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
852 scripts/config.pl unset MBEDTLS_THREADING_C
853 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
854 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
855 scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
856 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
857 echo "Checking that software 64-bit division is not required"
858 ! grep __aeabi_uldiv library/*.o
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100859}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100860
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100861component_build_armcc () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100862 msg "build: ARM Compiler 5, make"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100863 cp "$CONFIG_H" "$CONFIG_BAK"
864 scripts/config.pl full
865 scripts/config.pl unset MBEDTLS_NET_C
866 scripts/config.pl unset MBEDTLS_TIMING_C
867 scripts/config.pl unset MBEDTLS_FS_IO
868 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
869 scripts/config.pl unset MBEDTLS_HAVE_TIME
870 scripts/config.pl unset MBEDTLS_HAVE_TIME_DATE
871 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
872 # following things are not in the default config
873 scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
874 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
875 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
876 scripts/config.pl unset MBEDTLS_THREADING_C
877 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
878 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
879 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT # depends on MBEDTLS_HAVE_TIME
880
881 if [ $RUN_ARMCC -ne 0 ]; then
882 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
883 make clean
884
885 # ARM Compiler 6 - Target ARMv7-A
886 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-a"
887
888 # ARM Compiler 6 - Target ARMv7-M
889 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m"
890
891 # ARM Compiler 6 - Target ARMv8-A - AArch32
892 armc6_build_test "--target=arm-arm-none-eabi -march=armv8.2-a"
893
894 # ARM Compiler 6 - Target ARMv8-M
895 armc6_build_test "--target=arm-arm-none-eabi -march=armv8-m.main"
896
897 # ARM Compiler 6 - Target ARMv8-A - AArch64
898 armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a"
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100899 fi
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100900}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000901
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100902component_test_allow_sha1 () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100903 msg "build: allow SHA1 in certificates by default"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100904 cp "$CONFIG_H" "$CONFIG_BAK"
905 scripts/config.pl set MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
906 make CFLAGS='-Werror -Wall -Wextra'
907 msg "test: allow SHA1 in certificates by default"
908 make test
909 if_build_succeeded tests/ssl-opt.sh -f SHA-1
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100910}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000911
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100912component_build_mingw () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100913 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100914 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
915
916 # note Make tests only builds the tests, but doesn't run them
917 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror' WINDOWS_BUILD=1 tests
918 make WINDOWS_BUILD=1 clean
919
920 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
921 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
922 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
923 make WINDOWS_BUILD=1 clean
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100924}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100925
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100926component_test_memsan () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100927 # MemSan currently only available on Linux 64 bits
928 if uname -a | grep 'Linux.*x86_64' >/dev/null; then
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100929 msg "build: MSan (clang)" # ~ 1 min 20s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100930 cp "$CONFIG_H" "$CONFIG_BAK"
931 scripts/config.pl unset MBEDTLS_AESNI_C # memsan doesn't grok asm
932 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
933 make
934
935 msg "test: main suites (MSan)" # ~ 10s
936 make test
937
938 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
939 if_build_succeeded tests/ssl-opt.sh
940
941 # Optional part(s)
942
943 if [ "$MEMORY" -gt 0 ]; then
944 msg "test: compat.sh (MSan)" # ~ 6 min 20s
945 if_build_succeeded tests/compat.sh
946 fi
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100947 fi
948}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100949
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100950component_test_memcheck () {
951 # Only run if MemSan is not available
952 if ! uname -a | grep 'Linux.*x86_64' >/dev/null; then
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100953 msg "build: Release (clang)"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100954 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
955 make
956
957 msg "test: main suites valgrind (Release)"
958 make memcheck
959
960 # Optional part(s)
961 # Currently broken, programs don't seem to receive signals
962 # under valgrind on OS X
963
964 if [ "$MEMORY" -gt 0 ]; then
965 msg "test: ssl-opt.sh --memcheck (Release)"
966 if_build_succeeded tests/ssl-opt.sh --memcheck
967 fi
968
969 if [ "$MEMORY" -gt 1 ]; then
970 msg "test: compat.sh --memcheck (Release)"
971 if_build_succeeded tests/compat.sh --memcheck
972 fi
973
974 fi # MemSan
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100975}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100976
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100977component_test_cmake_out_of_source () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100978 msg "build: cmake 'out-of-source' build"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100979 MBEDTLS_ROOT_DIR="$PWD"
980 mkdir "$OUT_OF_SOURCE_DIR"
981 cd "$OUT_OF_SOURCE_DIR"
982 cmake "$MBEDTLS_ROOT_DIR"
983 make
984
985 msg "test: cmake 'out-of-source' build"
986 make test
987 # Test an SSL option that requires an auxiliary script in test/scripts/.
988 # Also ensure that there are no error messages such as
989 # "No such file or directory", which would indicate that some required
990 # file is missing (ssl-opt.sh tolerates the absence of some files so
991 # may exit with status 0 but emit errors).
992 if_build_succeeded ./tests/ssl-opt.sh -f 'Fallback SCSV: beginning of list' 2>ssl-opt.err
993 if [ -s ssl-opt.err ]; then
994 cat ssl-opt.err >&2
995 record_status [ ! -s ssl-opt.err ]
996 rm ssl-opt.err
997 fi
998 cd "$MBEDTLS_ROOT_DIR"
999 rm -rf "$OUT_OF_SOURCE_DIR"
1000 unset MBEDTLS_ROOT_DIR
1001}
Andres AGdc192212016-08-31 17:33:13 +01001002
Gilles Peskine192c72f2017-12-21 15:59:21 +01001003
1004
1005################################################################
1006#### Termination
1007################################################################
1008
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001009post_report () {
1010 msg "Done, cleaning up"
1011 cleanup
1012
1013 final_report
1014}
1015
1016
1017
1018################################################################
1019#### Run all the things
1020################################################################
1021
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001022# Run one component and clean up afterwards.
1023run_component () {
Gilles Peskine11ddca62018-12-04 12:49:28 +01001024 current_component="$1"
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001025 "$@"
1026 cleanup
1027}
1028
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001029# Preliminary setup
1030pre_check_environment
1031pre_initialize_variables
1032pre_parse_command_line "$@"
1033
1034pre_check_git
1035build_status=0
1036if [ $KEEP_GOING -eq 1 ]; then
1037 pre_setup_keep_going
1038else
1039 record_status () {
1040 "$@"
1041 }
1042fi
1043pre_print_configuration
1044pre_check_tools
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001045cleanup
Gilles Peskine7c652162017-12-11 00:01:40 +01001046
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001047# Run all the test components.
Gilles Peskine6e984232018-11-27 21:37:53 +01001048for component in $RUN_COMPONENTS; do
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001049 run_component "component_$component"
1050done
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001051
1052# We're done.
1053post_report