blob: d2eb47debea9aa9fe5340c3b23585b398d29fd1d [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{
226 echo ""
227 echo "******************************************************************"
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100228 echo "* $1 "
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000229 printf "* "; date
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100230 echo "******************************************************************"
Gilles Peskine7c652162017-12-11 00:01:40 +0100231 current_section=$1
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100232}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100233
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100234armc6_build_test()
235{
236 FLAGS="$1"
Andres AGa5cd9732016-10-17 15:23:10 +0100237
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100238 msg "build: ARM Compiler 6 ($FLAGS), make"
239 ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \
240 WARNING_CFLAGS='-xc -std=c99' make lib
241 make clean
242}
Andres AGa5cd9732016-10-17 15:23:10 +0100243
Andres AGd9eba4b2016-08-26 14:42:14 +0100244err_msg()
245{
246 echo "$1" >&2
247}
248
249check_tools()
250{
251 for TOOL in "$@"; do
Andres AG98393602017-01-31 17:04:45 +0000252 if ! `type "$TOOL" >/dev/null 2>&1`; then
Andres AGd9eba4b2016-08-26 14:42:14 +0100253 err_msg "$TOOL not found!"
254 exit 1
255 fi
256 done
257}
258
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100259pre_parse_command_line () {
Gilles Peskine6e984232018-11-27 21:37:53 +0100260 COMPONENTS=
261
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100262 while [ $# -gt 0 ]; do
263 case "$1" in
264 --armcc) RUN_ARMCC=1;;
265 --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
266 --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
Gilles Peskine6e984232018-11-27 21:37:53 +0100267 --except) ALL_EXCEPT=1;;
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100268 --force|-f) FORCE=1;;
269 --gnutls-cli) shift; GNUTLS_CLI="$1";;
270 --gnutls-legacy-cli) shift; GNUTLS_LEGACY_CLI="$1";;
271 --gnutls-legacy-serv) shift; GNUTLS_LEGACY_SERV="$1";;
272 --gnutls-serv) shift; GNUTLS_SERV="$1";;
273 --help|-h) usage; exit;;
274 --keep-going|-k) KEEP_GOING=1;;
275 --memory|-m) MEMORY=1;;
276 --no-armcc) RUN_ARMCC=0;;
277 --no-force) FORCE=0;;
278 --no-keep-going) KEEP_GOING=0;;
279 --no-memory) MEMORY=0;;
280 --no-yotta) YOTTA=0;;
281 --openssl) shift; OPENSSL="$1";;
282 --openssl-legacy) shift; OPENSSL_LEGACY="$1";;
283 --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
284 --random-seed) unset SEED;;
285 --release-test|-r) SEED=1;;
286 --seed|-s) shift; SEED="$1";;
287 --yotta) YOTTA=1;;
Gilles Peskine91bd8b72019-01-08 23:01:34 +0100288 -*)
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100289 echo >&2 "Unknown option: $1"
290 echo >&2 "Run $0 --help for usage."
291 exit 120
292 ;;
Gilles Peskine91bd8b72019-01-08 23:01:34 +0100293 *)
294 COMPONENTS="$COMPONENTS $1";;
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100295 esac
296 shift
297 done
Gilles Peskine91bd8b72019-01-08 23:01:34 +0100298
Gilles Peskine6e984232018-11-27 21:37:53 +0100299 if [ $ALL_EXCEPT -ne 0 ]; then
300 RUN_COMPONENTS=
301 for component in $ALL_COMPONENTS; do
302 if ! is_component_excluded "$component"; then
303 RUN_COMPONENTS="$RUN_COMPONENTS $component"
304 fi
305 done
306 elif [ -z "$COMPONENTS" ]; then
307 RUN_COMPONENTS="$ALL_COMPONENTS"
308 else
309 RUN_COMPONENTS="$COMPONENTS"
Gilles Peskine91bd8b72019-01-08 23:01:34 +0100310 fi
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100311}
SimonB2e23c822016-04-16 21:54:39 +0100312
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100313pre_check_git () {
314 if [ $FORCE -eq 1 ]; then
315 if [ $YOTTA -eq 1 ]; then
316 rm -rf yotta/module "$OUT_OF_SOURCE_DIR"
317 fi
318 git checkout-index -f -q $CONFIG_H
319 cleanup
320 else
321
322 if [ $YOTTA -ne 0 ] && [ -d yotta/module ]; then
323 err_msg "Warning - there is an existing yotta module in the directory 'yotta/module'"
324 echo "You can either delete your work and retry, or force the test to overwrite the"
325 echo "test by rerunning the script as: $0 --force"
326 exit 1
327 fi
328
329 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
330 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
331 echo "You can either delete this directory manually, or force the test by rerunning"
332 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
333 exit 1
334 fi
335
336 if ! git diff-files --quiet include/mbedtls/config.h; then
337 err_msg "Warning - the configuration file 'include/mbedtls/config.h' has been edited. "
338 echo "You can either delete or preserve your work, or force the test by rerunning the"
339 echo "script as: $0 --force"
340 exit 1
341 fi
Gilles Peskineda519252017-11-30 13:22:04 +0100342 fi
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100343}
SimonB2e23c822016-04-16 21:54:39 +0100344
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100345pre_setup_keep_going () {
Gilles Peskine7c652162017-12-11 00:01:40 +0100346 failure_summary=
347 failure_count=0
348 start_red=
349 end_color=
350 if [ -t 1 ]; then
Gilles Peskine9736b9d2018-01-02 21:54:17 +0100351 case "${TERM:-}" in
Gilles Peskine7c652162017-12-11 00:01:40 +0100352 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
353 start_red=$(printf '\033[31m')
354 end_color=$(printf '\033[0m')
355 ;;
356 esac
357 fi
358 record_status () {
359 if "$@"; then
360 last_status=0
361 else
362 last_status=$?
363 text="$current_section: $* -> $last_status"
364 failure_summary="$failure_summary
365$text"
366 failure_count=$((failure_count + 1))
367 echo "${start_red}^^^^$text^^^^${end_color}"
368 fi
369 }
370 make () {
371 case "$*" in
372 *test|*check)
373 if [ $build_status -eq 0 ]; then
374 record_status command make "$@"
375 else
376 echo "(skipped because the build failed)"
377 fi
378 ;;
379 *)
380 record_status command make "$@"
381 build_status=$last_status
382 ;;
383 esac
384 }
385 final_report () {
386 if [ $failure_count -gt 0 ]; then
387 echo
388 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
389 echo "${start_red}FAILED: $failure_count${end_color}$failure_summary"
390 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Jaeden Amero5113bde2018-07-20 16:42:14 +0100391 exit 1
Gilles Peskine7c652162017-12-11 00:01:40 +0100392 elif [ -z "${1-}" ]; then
393 echo "SUCCESS :)"
394 fi
395 if [ -n "${1-}" ]; then
396 echo "Killed by SIG$1."
397 fi
398 }
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100399}
400
Gilles Peskine7c652162017-12-11 00:01:40 +0100401if_build_succeeded () {
402 if [ $build_status -eq 0 ]; then
403 record_status "$@"
404 fi
405}
406
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100407pre_print_configuration () {
408 msg "info: $0 configuration"
409 echo "MEMORY: $MEMORY"
410 echo "FORCE: $FORCE"
411 echo "SEED: ${SEED-"UNSET"}"
412 echo "OPENSSL: $OPENSSL"
413 echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
414 echo "GNUTLS_CLI: $GNUTLS_CLI"
415 echo "GNUTLS_SERV: $GNUTLS_SERV"
416 echo "GNUTLS_LEGACY_CLI: $GNUTLS_LEGACY_CLI"
417 echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV"
418 echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
419 echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
420}
Andres AG7770ea82016-10-10 15:46:20 +0100421
Andres AGd9eba4b2016-08-26 14:42:14 +0100422# Make sure the tools we need are available.
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100423pre_check_tools () {
424 ARMC5_CC="$ARMC5_BIN_DIR/armcc"
425 ARMC5_AR="$ARMC5_BIN_DIR/armar"
426 ARMC6_CC="$ARMC6_BIN_DIR/armclang"
427 ARMC6_AR="$ARMC6_BIN_DIR/armar"
428
429 # To avoid setting OpenSSL and GnuTLS for each call to compat.sh and ssl-opt.sh
430 # we just export the variables they require
431 export OPENSSL_CMD="$OPENSSL"
432 export GNUTLS_CLI="$GNUTLS_CLI"
433 export GNUTLS_SERV="$GNUTLS_SERV"
434
435 # Avoid passing --seed flag in every call to ssl-opt.sh
436 if [ -n "${SEED-}" ]; then
437 export SEED
438 fi
439
440 check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$GNUTLS_CLI" "$GNUTLS_SERV" \
441 "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV" "doxygen" "dot" \
442 "arm-none-eabi-gcc" "i686-w64-mingw32-gcc"
443 if [ $RUN_ARMCC -ne 0 ]; then
444 check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC6_CC" "$ARMC6_AR"
445 fi
446
447 msg "info: output_env.sh"
448 OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY" GNUTLS_CLI="$GNUTLS_CLI" \
449 GNUTLS_SERV="$GNUTLS_SERV" GNUTLS_LEGACY_CLI="$GNUTLS_LEGACY_CLI" \
450 GNUTLS_LEGACY_SERV="$GNUTLS_LEGACY_SERV" ARMC5_CC="$ARMC5_CC" \
451 ARMC6_CC="$ARMC6_CC" RUN_ARMCC="$RUN_ARMCC" scripts/output_env.sh
452}
Andres AGd9eba4b2016-08-26 14:42:14 +0100453
Gilles Peskine192c72f2017-12-21 15:59:21 +0100454
455
456################################################################
457#### Basic checks
458################################################################
SimonB2e23c822016-04-16 21:54:39 +0100459
460#
461# Test Suites to be executed
462#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200463# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100464# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard61bc57a2014-08-14 11:29:06 +0200465# and/or are more likely to fail than others (eg I use Clang most of the
466# time, so start with a GCC build).
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200467# 2. Minimize total running time, by avoiding useless rebuilds
468#
469# Indicative running times are given for reference.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100470
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100471component_check_recursion () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100472 msg "test: recursion.pl" # < 1s
473 record_status tests/scripts/recursion.pl library/*.c
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100474}
Manuel Pégourié-Gonnardea29d152014-11-20 17:32:33 +0100475
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100476component_check_generated_files () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100477 msg "test: freshness of generated source files" # < 1s
478 record_status tests/scripts/check-generated-files.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100479}
Manuel Pégourié-Gonnardb3b8e432015-02-13 14:52:19 +0000480
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100481component_check_doxy_blocks () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100482 msg "test: doxygen markup outside doxygen blocks" # < 1s
483 record_status tests/scripts/check-doxy-blocks.pl
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100484}
Manuel Pégourié-Gonnardd09a6b52015-04-09 17:19:23 +0200485
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100486component_check_files () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100487 msg "test: check-files.py" # < 1s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100488 record_status tests/scripts/check-files.py
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100489}
Manuel Pégourié-Gonnard77d56bb2015-07-28 15:00:37 +0200490
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100491component_check_names () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100492 msg "test/build: declared and exported names" # < 3s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100493 record_status tests/scripts/check-names.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100494}
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +0200495
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100496component_check_doxygen_warnings () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100497 msg "test: doxygen warnings" # ~ 3s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100498 record_status tests/scripts/doxygen.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100499}
Andres Amaya Garciadd29c2f2017-05-04 11:35:51 +0100500
Simon Butcher948f2642018-07-20 21:27:33 +0100501
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100502################################################################
503#### Build and test many configurations and targets
504################################################################
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100505
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100506component_build_yotta () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100507 if [ $RUN_ARMCC -ne 0 ] && [ $YOTTA -ne 0 ]; then
508 # Note - use of yotta is deprecated, and yotta also requires armcc to be on the
509 # path, and uses whatever version of armcc it finds there.
510 msg "build: create and build yotta module" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100511 record_status tests/scripts/yotta-build.sh
512 fi
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100513}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100514
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100515component_test_default_cmake_gcc_asan () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100516 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100517 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100518 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +0200519
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100520 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100521 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100522
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100523 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
Gilles Peskine7c652162017-12-11 00:01:40 +0100524 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100525
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100526 msg "test: compat.sh (ASan build)" # ~ 6 min
527 if_build_succeeded tests/compat.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100528}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000529
Gilles Peskine3484ed82019-01-08 22:51:19 +0100530component_test_ref_configs () {
531 msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
532 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
533 record_status tests/scripts/test-ref-configs.pl
534}
535
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100536component_test_sslv3 () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100537 msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100538 cp "$CONFIG_H" "$CONFIG_BAK"
539 scripts/config.pl set MBEDTLS_SSL_PROTO_SSL3
540 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
541 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000542
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100543 msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
544 make test
545
546 msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
547 if_build_succeeded tests/compat.sh -m 'tls1 tls1_1 tls1_2 dtls1 dtls1_2'
548 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
549
550 msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
551 if_build_succeeded tests/ssl-opt.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100552}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100553
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100554component_test_no_renegotiation () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100555 msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100556 cp "$CONFIG_H" "$CONFIG_BAK"
557 scripts/config.pl unset MBEDTLS_SSL_RENEGOTIATION
558 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
559 make
560
561 msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
562 make test
563
564 msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
565 if_build_succeeded tests/ssl-opt.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100566}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100567
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100568component_test_rsa_no_crt () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100569 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100570 cp "$CONFIG_H" "$CONFIG_BAK"
571 scripts/config.pl set MBEDTLS_RSA_NO_CRT
572 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
573 make
574
575 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
576 make test
577
578 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
579 if_build_succeeded tests/ssl-opt.sh -f RSA
580
581 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
582 if_build_succeeded tests/compat.sh -t RSA
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100583}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100584
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100585component_test_full_cmake_clang () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100586 msg "build: cmake, full config, clang" # ~ 50s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100587 cp "$CONFIG_H" "$CONFIG_BAK"
588 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 cp "$CONFIG_H" "$CONFIG_BAK"
606 scripts/config.pl full
607 scripts/config.pl set MBEDTLS_DEPRECATED_WARNING
608 # Build with -O -Wextra to catch a maximum of issues.
609 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra' lib programs
610 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
611
612 msg "build: make, full config + DEPRECATED_REMOVED, clang -O" # ~ 30s
613 # No cleanup, just tweak the configuration and rebuild
614 make clean
615 scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
616 scripts/config.pl set MBEDTLS_DEPRECATED_REMOVED
617 # Build with -O -Wextra to catch a maximum of issues.
618 make CC=clang CFLAGS='-O -Werror -Wall -Wextra' lib programs
619 make CC=clang CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100620}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100621
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100622component_test_depends_curves () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100623 msg "test/build: curves.pl (gcc)" # ~ 4 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100624 record_status tests/scripts/curves.pl
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100625}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100626
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100627component_test_depends_hashes () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100628 msg "test/build: depends-hashes.pl (gcc)" # ~ 2 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100629 record_status tests/scripts/depends-hashes.pl
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100630}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100631
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100632component_test_depends_pkalgs () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100633 msg "test/build: depends-pkalgs.pl (gcc)" # ~ 2 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100634 record_status tests/scripts/depends-pkalgs.pl
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100635}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100636
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100637component_build_key_exchanges () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100638 msg "test/build: key-exchanges (gcc)" # ~ 1 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100639 record_status tests/scripts/key-exchanges.pl
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100640}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100641
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100642component_build_default_make_gcc () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100643 msg "build: Unix make, -Os (gcc)" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100644 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100645}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100646
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100647component_test_no_platform () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100648 # Full configuration build, without platform support, file IO and net sockets.
649 # This should catch missing mbedtls_printf definitions, and by disabling file
650 # IO, it should catch missing '#include <stdio.h>'
651 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100652 cp "$CONFIG_H" "$CONFIG_BAK"
653 scripts/config.pl full
654 scripts/config.pl unset MBEDTLS_PLATFORM_C
655 scripts/config.pl unset MBEDTLS_NET_C
656 scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
657 scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
658 scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
659 scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
660 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
661 scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
662 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
663 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
664 scripts/config.pl unset MBEDTLS_FS_IO
665 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
666 # to re-enable platform integration features otherwise disabled in C99 builds
667 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -O0 -D_DEFAULT_SOURCE' lib programs
668 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0' test
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100669}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100670
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100671component_build_no_std_function () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100672 # catch compile bugs in _uninit functions
673 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100674 cp "$CONFIG_H" "$CONFIG_BAK"
675 scripts/config.pl full
676 scripts/config.pl set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
677 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
678 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100679}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100680
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100681component_build_no_ssl_srv () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100682 msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100683 cp "$CONFIG_H" "$CONFIG_BAK"
684 scripts/config.pl full
685 scripts/config.pl unset MBEDTLS_SSL_SRV_C
686 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100687}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100688
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100689component_build_no_ssl_cli () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100690 msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100691 cp "$CONFIG_H" "$CONFIG_BAK"
692 scripts/config.pl full
693 scripts/config.pl unset MBEDTLS_SSL_CLI_C
694 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100695}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100696
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100697component_build_no_sockets () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100698 # Note, C99 compliance can also be tested with the sockets support disabled,
699 # as that requires a POSIX platform (which isn't the same as C99).
700 msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100701 cp "$CONFIG_H" "$CONFIG_BAK"
702 scripts/config.pl full
703 scripts/config.pl unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
704 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
705 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0 -std=c99 -pedantic' lib
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100706}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100707
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100708component_test_no_max_fragment_length () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100709 msg "build: default config except MFL extension (ASan build)" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100710 cp "$CONFIG_H" "$CONFIG_BAK"
711 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
712 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
713 make
714
715 msg "test: ssl-opt.sh, MFL-related tests"
716 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length"
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100717}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100718
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100719component_test_null_entropy () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100720 msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100721 cp "$CONFIG_H" "$CONFIG_BAK"
722 scripts/config.pl set MBEDTLS_TEST_NULL_ENTROPY
723 scripts/config.pl set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
724 scripts/config.pl set MBEDTLS_ENTROPY_C
725 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
726 scripts/config.pl unset MBEDTLS_ENTROPY_HARDWARE_ALT
727 scripts/config.pl unset MBEDTLS_HAVEGE_C
728 CC=gcc cmake -D UNSAFE_BUILD=ON -D CMAKE_C_FLAGS:String="-fsanitize=address -fno-common -O3" .
729 make
730
731 msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)"
732 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100733}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100734
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100735component_test_platform_calloc_macro () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100736 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100737 cp "$CONFIG_H" "$CONFIG_BAK"
738 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
739 scripts/config.pl set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
740 scripts/config.pl set MBEDTLS_PLATFORM_FREE_MACRO free
741 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
742 make
743
744 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
745 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100746}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100747
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100748component_test_make_shared () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100749 if uname -a | grep -F Linux >/dev/null; then
750 msg "build/test: make shared" # ~ 40s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100751 make SHARED=1 all check
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100752 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000753
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100754}
755
756component_test_m32_o0 () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100757 if uname -a | grep -F x86_64 >/dev/null; then
758 # Build once with -O0, to compile out the i386 specific inline assembly
759 msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100760 cp "$CONFIG_H" "$CONFIG_BAK"
761 scripts/config.pl full
762 make CC=gcc CFLAGS='-O0 -Werror -Wall -Wextra -m32 -fsanitize=address'
763
764 msg "test: i386, make, gcc -O0 (ASan build)"
765 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100766 fi # x86_64
767}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100768
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100769component_test_m32_o1 () {
770 if uname -a | grep -F x86_64 >/dev/null; then
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100771 # Build again with -O1, to compile in the i386 specific inline assembly
772 msg "build: i386, make, gcc -O1 (ASan build)" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100773 cp "$CONFIG_H" "$CONFIG_BAK"
774 scripts/config.pl full
775 make CC=gcc CFLAGS='-O1 -Werror -Wall -Wextra -m32 -fsanitize=address'
776
777 msg "test: i386, make, gcc -O1 (ASan build)"
778 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100779 fi # x86_64
780}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100781
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100782component_test_mx32 () {
783 if uname -a | grep -F x86_64 >/dev/null; then
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100784 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100785 cp "$CONFIG_H" "$CONFIG_BAK"
786 scripts/config.pl full
787 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32'
788
789 msg "test: 64-bit ILP32, make, gcc"
790 make test
791 fi # x86_64
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100792}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100793
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100794component_test_have_int32 () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100795 msg "build: gcc, force 32-bit bignum limbs"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100796 cp "$CONFIG_H" "$CONFIG_BAK"
797 scripts/config.pl unset MBEDTLS_HAVE_ASM
798 scripts/config.pl unset MBEDTLS_AESNI_C
799 scripts/config.pl unset MBEDTLS_PADLOCK_C
800 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
801
802 msg "test: gcc, force 32-bit bignum limbs"
803 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100804}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100805
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100806component_test_have_int64 () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100807 msg "build: gcc, force 64-bit bignum limbs"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100808 cp "$CONFIG_H" "$CONFIG_BAK"
809 scripts/config.pl unset MBEDTLS_HAVE_ASM
810 scripts/config.pl unset MBEDTLS_AESNI_C
811 scripts/config.pl unset MBEDTLS_PADLOCK_C
812 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
813
814 msg "test: gcc, force 64-bit bignum limbs"
815 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100816}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100817
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100818component_build_arm_none_eabi_gcc () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100819 msg "build: arm-none-eabi-gcc, make" # ~ 10s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100820 cp "$CONFIG_H" "$CONFIG_BAK"
821 scripts/config.pl full
822 scripts/config.pl unset MBEDTLS_NET_C
823 scripts/config.pl unset MBEDTLS_TIMING_C
824 scripts/config.pl unset MBEDTLS_FS_IO
825 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
826 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
827 # following things are not in the default config
828 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
829 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
830 scripts/config.pl unset MBEDTLS_THREADING_C
831 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
832 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
833 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 +0100834}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100835
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100836component_build_arm_none_eabi_gcc_no_udbl_division () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100837 msg "build: arm-none-eabi-gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100838 cp "$CONFIG_H" "$CONFIG_BAK"
839 scripts/config.pl full
840 scripts/config.pl unset MBEDTLS_NET_C
841 scripts/config.pl unset MBEDTLS_TIMING_C
842 scripts/config.pl unset MBEDTLS_FS_IO
843 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
844 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
845 # following things are not in the default config
846 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
847 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
848 scripts/config.pl unset MBEDTLS_THREADING_C
849 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
850 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
851 scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
852 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
853 echo "Checking that software 64-bit division is not required"
854 ! grep __aeabi_uldiv library/*.o
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100855}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100856
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100857component_build_armcc () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100858 msg "build: ARM Compiler 5, make"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100859 cp "$CONFIG_H" "$CONFIG_BAK"
860 scripts/config.pl full
861 scripts/config.pl unset MBEDTLS_NET_C
862 scripts/config.pl unset MBEDTLS_TIMING_C
863 scripts/config.pl unset MBEDTLS_FS_IO
864 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
865 scripts/config.pl unset MBEDTLS_HAVE_TIME
866 scripts/config.pl unset MBEDTLS_HAVE_TIME_DATE
867 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
868 # following things are not in the default config
869 scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
870 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
871 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
872 scripts/config.pl unset MBEDTLS_THREADING_C
873 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
874 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
875 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT # depends on MBEDTLS_HAVE_TIME
876
877 if [ $RUN_ARMCC -ne 0 ]; then
878 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
879 make clean
880
881 # ARM Compiler 6 - Target ARMv7-A
882 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-a"
883
884 # ARM Compiler 6 - Target ARMv7-M
885 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m"
886
887 # ARM Compiler 6 - Target ARMv8-A - AArch32
888 armc6_build_test "--target=arm-arm-none-eabi -march=armv8.2-a"
889
890 # ARM Compiler 6 - Target ARMv8-M
891 armc6_build_test "--target=arm-arm-none-eabi -march=armv8-m.main"
892
893 # ARM Compiler 6 - Target ARMv8-A - AArch64
894 armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a"
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100895 fi
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100896}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000897
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100898component_test_allow_sha1 () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100899 msg "build: allow SHA1 in certificates by default"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100900 cp "$CONFIG_H" "$CONFIG_BAK"
901 scripts/config.pl set MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
902 make CFLAGS='-Werror -Wall -Wextra'
903 msg "test: allow SHA1 in certificates by default"
904 make test
905 if_build_succeeded tests/ssl-opt.sh -f SHA-1
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100906}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000907
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100908component_build_mingw () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100909 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100910 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -Wall -Wextra' WINDOWS_BUILD=1 lib programs
911
912 # note Make tests only builds the tests, but doesn't run them
913 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror' WINDOWS_BUILD=1 tests
914 make WINDOWS_BUILD=1 clean
915
916 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
917 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -Wall -Wextra' WINDOWS_BUILD=1 SHARED=1 lib programs
918 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -Wall -Wextra' WINDOWS_BUILD=1 SHARED=1 tests
919 make WINDOWS_BUILD=1 clean
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100920}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100921
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100922component_test_memsan () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100923 # MemSan currently only available on Linux 64 bits
924 if uname -a | grep 'Linux.*x86_64' >/dev/null; then
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100925 msg "build: MSan (clang)" # ~ 1 min 20s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100926 cp "$CONFIG_H" "$CONFIG_BAK"
927 scripts/config.pl unset MBEDTLS_AESNI_C # memsan doesn't grok asm
928 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
929 make
930
931 msg "test: main suites (MSan)" # ~ 10s
932 make test
933
934 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
935 if_build_succeeded tests/ssl-opt.sh
936
937 # Optional part(s)
938
939 if [ "$MEMORY" -gt 0 ]; then
940 msg "test: compat.sh (MSan)" # ~ 6 min 20s
941 if_build_succeeded tests/compat.sh
942 fi
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100943 fi
944}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100945
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100946component_test_memcheck () {
947 # Only run if MemSan is not available
948 if ! uname -a | grep 'Linux.*x86_64' >/dev/null; then
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100949 msg "build: Release (clang)"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100950 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
951 make
952
953 msg "test: main suites valgrind (Release)"
954 make memcheck
955
956 # Optional part(s)
957 # Currently broken, programs don't seem to receive signals
958 # under valgrind on OS X
959
960 if [ "$MEMORY" -gt 0 ]; then
961 msg "test: ssl-opt.sh --memcheck (Release)"
962 if_build_succeeded tests/ssl-opt.sh --memcheck
963 fi
964
965 if [ "$MEMORY" -gt 1 ]; then
966 msg "test: compat.sh --memcheck (Release)"
967 if_build_succeeded tests/compat.sh --memcheck
968 fi
969
970 fi # MemSan
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100971}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100972
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100973component_test_cmake_out_of_source () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100974 msg "build: cmake 'out-of-source' build"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100975 MBEDTLS_ROOT_DIR="$PWD"
976 mkdir "$OUT_OF_SOURCE_DIR"
977 cd "$OUT_OF_SOURCE_DIR"
978 cmake "$MBEDTLS_ROOT_DIR"
979 make
980
981 msg "test: cmake 'out-of-source' build"
982 make test
983 # Test an SSL option that requires an auxiliary script in test/scripts/.
984 # Also ensure that there are no error messages such as
985 # "No such file or directory", which would indicate that some required
986 # file is missing (ssl-opt.sh tolerates the absence of some files so
987 # may exit with status 0 but emit errors).
988 if_build_succeeded ./tests/ssl-opt.sh -f 'Fallback SCSV: beginning of list' 2>ssl-opt.err
989 if [ -s ssl-opt.err ]; then
990 cat ssl-opt.err >&2
991 record_status [ ! -s ssl-opt.err ]
992 rm ssl-opt.err
993 fi
994 cd "$MBEDTLS_ROOT_DIR"
995 rm -rf "$OUT_OF_SOURCE_DIR"
996 unset MBEDTLS_ROOT_DIR
997}
Andres AGdc192212016-08-31 17:33:13 +0100998
Gilles Peskine192c72f2017-12-21 15:59:21 +0100999
1000
1001################################################################
1002#### Termination
1003################################################################
1004
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001005post_report () {
1006 msg "Done, cleaning up"
1007 cleanup
1008
1009 final_report
1010}
1011
1012
1013
1014################################################################
1015#### Run all the things
1016################################################################
1017
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001018# Run one component and clean up afterwards.
1019run_component () {
1020 "$@"
1021 cleanup
1022}
1023
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001024# Preliminary setup
1025pre_check_environment
1026pre_initialize_variables
1027pre_parse_command_line "$@"
1028
1029pre_check_git
1030build_status=0
1031if [ $KEEP_GOING -eq 1 ]; then
1032 pre_setup_keep_going
1033else
1034 record_status () {
1035 "$@"
1036 }
1037fi
1038pre_print_configuration
1039pre_check_tools
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001040cleanup
Gilles Peskine7c652162017-12-11 00:01:40 +01001041
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001042# Run all the test components.
Gilles Peskine6e984232018-11-27 21:37:53 +01001043for component in $RUN_COMPONENTS; do
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001044 run_component "component_$component"
1045done
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001046
1047# We're done.
1048post_report