blob: 038657296c9747df18d237a9cd49738785e2ac0c [file] [log] [blame]
Andres AG31f9b5b2016-10-04 17:14:38 +01001#! /usr/bin/env sh
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01002
Simon Butcher3ea7f522016-03-07 23:22:10 +00003# all.sh
4#
SimonB2e23c822016-04-16 21:54:39 +01005# This file is part of mbed TLS (https://tls.mbed.org)
6#
Gilles Peskine192c72f2017-12-21 15:59:21 +01007# Copyright (c) 2014-2017, ARM Limited, All Rights Reserved
8
9
10
11################################################################
12#### Documentation
13################################################################
14
Simon Butcher3ea7f522016-03-07 23:22:10 +000015# Purpose
Gilles Peskine192c72f2017-12-21 15:59:21 +010016# -------
Simon Butcher3ea7f522016-03-07 23:22:10 +000017#
SimonB2e23c822016-04-16 21:54:39 +010018# To run all tests possible or available on the platform.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010019#
Gilles Peskine192c72f2017-12-21 15:59:21 +010020# Notes for users
21# ---------------
22#
SimonB2e23c822016-04-16 21:54:39 +010023# Warning: the test is destructive. It includes various build modes and
24# configurations, and can and will arbitrarily change the current CMake
Gilles Peskine192c72f2017-12-21 15:59:21 +010025# configuration. The following files must be committed into git:
26# * include/mbedtls/config.h
27# * Makefile, library/Makefile, programs/Makefile, tests/Makefile
28# After running this script, the CMake cache will be lost and CMake
29# will no longer be initialised.
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +010030#
Gilles Peskine192c72f2017-12-21 15:59:21 +010031# The script assumes the presence of a number of tools:
32# * Basic Unix tools (Windows users note: a Unix-style find must be before
33# the Windows find in the PATH)
34# * Perl
35# * GNU Make
36# * CMake
37# * GCC and Clang (recent enough for using ASan with gcc and MemSan with clang, or valgrind)
38# * arm-gcc and mingw-gcc
39# * ArmCC 5 and ArmCC 6, unless invoked with --no-armcc
40# * Yotta build dependencies, unless invoked with --no-yotta
41# * OpenSSL and GnuTLS command line tools, recent enough for the
42# interoperability tests. If they don't support SSLv3 then a legacy
43# version of these tools must be present as well (search for LEGACY
44# below).
45# See the invocation of check_tools below for details.
46#
47# This script must be invoked from the toplevel directory of a git
48# working copy of Mbed TLS.
49#
50# Note that the output is not saved. You may want to run
51# script -c tests/scripts/all.sh
52# or
53# tests/scripts/all.sh >all.log 2>&1
54#
55# Notes for maintainers
56# ---------------------
57#
58# The tests are roughly in order from fastest to slowest. This doesn't
59# have to be exact, but in general you should add slower tests towards
60# the end and fast checks near the beginning.
61#
62# Sanity checks have the following form:
63# 1. msg "short description of what is about to be done"
64# 2. run sanity check (failure stops the script)
65#
66# Build or build-and-test steps have the following form:
67# 1. msg "short description of what is about to be done"
68# 2. cleanup
69# 3. preparation (config.pl, cmake, ...) (failure stops the script)
70# 4. make
71# 5. Run tests if relevant. All tests must be prefixed with
72# if_build_successful for the sake of --keep-going.
73
74
75
76################################################################
77#### Initialization and command line parsing
78################################################################
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010079
SimonB2e23c822016-04-16 21:54:39 +010080# Abort on errors (and uninitialised variables)
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010081set -eu
82
Gilles Peskine57db6ff2019-01-08 22:04:31 +010083pre_check_environment () {
Gilles Peskine770ad7e2019-01-08 23:19:08 +010084 if [ -d library -a -d include -a -d tests ]; then :; else
Gilles Peskine57db6ff2019-01-08 22:04:31 +010085 echo "Must be run from mbed TLS root" >&2
86 exit 1
87 fi
88}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010089
Gilles Peskine57db6ff2019-01-08 22:04:31 +010090pre_initialize_variables () {
91 CONFIG_H='include/mbedtls/config.h'
92 CONFIG_BAK="$CONFIG_H.bak"
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +020093
Gilles Peskine57db6ff2019-01-08 22:04:31 +010094 MEMORY=0
95 FORCE=0
96 KEEP_GOING=0
97 RUN_ARMCC=1
98 YOTTA=1
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010099
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100100 # Default commands, can be overriden by the environment
101 : ${OPENSSL:="openssl"}
102 : ${OPENSSL_LEGACY:="$OPENSSL"}
103 : ${GNUTLS_CLI:="gnutls-cli"}
104 : ${GNUTLS_SERV:="gnutls-serv"}
105 : ${GNUTLS_LEGACY_CLI:="$GNUTLS_CLI"}
106 : ${GNUTLS_LEGACY_SERV:="$GNUTLS_SERV"}
107 : ${OUT_OF_SOURCE_DIR:=./mbedtls_out_of_source_build}
108 : ${ARMC5_BIN_DIR:=/usr/bin}
109 : ${ARMC6_BIN_DIR:=/usr/bin}
Andres AGdc192212016-08-31 17:33:13 +0100110
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100111 # if MAKEFLAGS is not set add the -j option to speed up invocations of make
Gilles Peskine7120f772019-01-06 20:15:26 +0000112 if [ -z "${MAKEFLAGS+set}" ]; then
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100113 export MAKEFLAGS="-j"
114 fi
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100115
116 # Gather the list of available components. These are the functions
117 # defined in this script whose name starts with "component_".
118 # Parse the script with sed, because in sh there is no way to list
119 # defined functions.
120 ALL_COMPONENTS=$(sed -n 's/^ *component_\([0-9A-Z_a-z]*\) *().*/\1/p' <"$0")
Gilles Peskine3fbdd212019-01-08 23:33:45 +0100121
122 # Exclude components that are not supported on this platform.
123 SUPPORTED_COMPONENTS=
124 for component in $ALL_COMPONENTS; do
125 case $(type "support_$component" 2>&1) in
126 *' function'*)
127 if ! support_$component; then continue; fi;;
128 esac
129 SUPPORTED_COMPONENTS="$SUPPORTED_COMPONENTS $component"
130 done
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100131}
Andres AG38495a32016-07-12 16:54:33 +0100132
Gilles Peskine3fbdd212019-01-08 23:33:45 +0100133# Test whether $1 is excluded via the command line.
Gilles Peskine6e984232018-11-27 21:37:53 +0100134is_component_excluded()
135{
Gilles Peskine3fbdd212019-01-08 23:33:45 +0100136 # Is $1 excluded via $COMPONENTS (a space-separated list of wildcard
137 # patterns)?
Gilles Peskine6e984232018-11-27 21:37:53 +0100138 set -f
Gilles Peskineeb39b9b2019-01-08 23:41:00 +0100139 for pattern in $COMMAND_LINE_COMPONENTS; do
Gilles Peskine6e984232018-11-27 21:37:53 +0100140 set +f
141 case ${1#component_} in $pattern) return 0;; esac
142 done
143 set +f
144 return 1
145}
146
Simon Butcher41eeccf2016-09-07 00:07:09 +0100147usage()
SimonB2e23c822016-04-16 21:54:39 +0100148{
Gilles Peskine709346a2017-12-10 23:43:39 +0100149 cat <<EOF
Gilles Peskine91bd8b72019-01-08 23:01:34 +0100150Usage: $0 [OPTION]... [COMPONENT]...
151Run mbedtls release validation tests.
152By default, run all tests. With one or more COMPONENT, run only those.
153
154Special options:
155 -h|--help Print this help and exit.
Gilles Peskineb3241cb2019-01-08 23:44:07 +0100156 --list-all-components List all available test components and exit.
157 --list-components List components supported on this platform and exit.
Gilles Peskine709346a2017-12-10 23:43:39 +0100158
159General options:
160 -f|--force Force the tests to overwrite any modified files.
Gilles Peskine7c652162017-12-11 00:01:40 +0100161 -k|--keep-going Run all tests and report errors at the end.
Gilles Peskine709346a2017-12-10 23:43:39 +0100162 -m|--memory Additional optional memory tests.
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100163 --armcc Run ARM Compiler builds (on by default).
Gilles Peskine6e984232018-11-27 21:37:53 +0100164 --except If some components are passed on the command line,
165 run all the tests except for these components. In
166 this mode, you can pass shell wildcard patterns as
167 component names, e.g. "$0 --except 'test_*'" to
168 exclude all components that run tests.
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100169 --no-armcc Skip ARM Compiler builds.
Gilles Peskine19ceb712018-03-21 08:40:26 +0100170 --no-force Refuse to overwrite modified files (default).
171 --no-keep-going Stop at the first error (default).
172 --no-memory No additional memory tests (default).
Gilles Peskine2a22a802017-12-21 15:19:00 +0100173 --no-yotta Skip yotta module build.
Gilles Peskine709346a2017-12-10 23:43:39 +0100174 --out-of-source-dir=<path> Directory used for CMake out-of-source build tests.
Gilles Peskine19ceb712018-03-21 08:40:26 +0100175 --random-seed Use a random seed value for randomized tests (default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100176 -r|--release-test Run this script in release mode. This fixes the seed value to 1.
177 -s|--seed Integer seed value to use for this test run.
Gilles Peskine2a22a802017-12-21 15:19:00 +0100178 --yotta Build yotta module (on by default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100179
180Tool path options:
181 --armc5-bin-dir=<ARMC5_bin_dir_path> ARM Compiler 5 bin directory.
182 --armc6-bin-dir=<ARMC6_bin_dir_path> ARM Compiler 6 bin directory.
183 --gnutls-cli=<GnuTLS_cli_path> GnuTLS client executable to use for most tests.
184 --gnutls-serv=<GnuTLS_serv_path> GnuTLS server executable to use for most tests.
185 --gnutls-legacy-cli=<GnuTLS_cli_path> GnuTLS client executable to use for legacy tests.
186 --gnutls-legacy-serv=<GnuTLS_serv_path> GnuTLS server executable to use for legacy tests.
187 --openssl=<OpenSSL_path> OpenSSL executable to use for most tests.
188 --openssl-legacy=<OpenSSL_path> OpenSSL executable to use for legacy tests e.g. SSLv3.
189EOF
SimonB2e23c822016-04-16 21:54:39 +0100190}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100191
192# remove built files as well as the cmake cache/config
193cleanup()
194{
Gilles Peskinea71d64c2018-03-21 12:16:57 +0100195 if [ -n "${MBEDTLS_ROOT_DIR+set}" ]; then
196 cd "$MBEDTLS_ROOT_DIR"
197 fi
198
Gilles Peskine7c652162017-12-11 00:01:40 +0100199 command make clean
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200200
Gilles Peskine31b07e22018-03-21 12:15:06 +0100201 # Remove CMake artefacts
202 find . -name .git -prune -o -name yotta -prune -o \
203 -iname CMakeFiles -exec rm -rf {} \+ -o \
204 \( -iname cmake_install.cmake -o \
205 -iname CTestTestfile.cmake -o \
206 -iname CMakeCache.txt \) -exec rm {} \+
207 # Recover files overwritten by in-tree CMake builds
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000208 rm -f include/Makefile include/mbedtls/Makefile programs/*/Makefile
Paul Bakkerfe0984d2014-06-13 00:13:45 +0200209 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile
210 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200211
212 if [ -f "$CONFIG_BAK" ]; then
213 mv "$CONFIG_BAK" "$CONFIG_H"
214 fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100215}
216
Gilles Peskine7c652162017-12-11 00:01:40 +0100217# Executed on exit. May be redefined depending on command line options.
218final_report () {
219 :
220}
221
222fatal_signal () {
223 cleanup
224 final_report $1
225 trap - $1
226 kill -$1 $$
227}
228
229trap 'fatal_signal HUP' HUP
230trap 'fatal_signal INT' INT
231trap 'fatal_signal TERM' TERM
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200232
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100233msg()
234{
Gilles Peskine11ddca62018-12-04 12:49:28 +0100235 if [ -n "${current_component:-}" ]; then
236 current_section="${current_component#component_}: $1"
237 else
238 current_section="$1"
239 fi
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100240 echo ""
241 echo "******************************************************************"
Gilles Peskine11ddca62018-12-04 12:49:28 +0100242 echo "* $current_section "
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000243 printf "* "; date
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100244 echo "******************************************************************"
245}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100246
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100247armc6_build_test()
248{
249 FLAGS="$1"
Andres AGa5cd9732016-10-17 15:23:10 +0100250
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100251 msg "build: ARM Compiler 6 ($FLAGS), make"
252 ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \
253 WARNING_CFLAGS='-xc -std=c99' make lib
254 make clean
255}
Andres AGa5cd9732016-10-17 15:23:10 +0100256
Andres AGd9eba4b2016-08-26 14:42:14 +0100257err_msg()
258{
259 echo "$1" >&2
260}
261
262check_tools()
263{
264 for TOOL in "$@"; do
Andres AG98393602017-01-31 17:04:45 +0000265 if ! `type "$TOOL" >/dev/null 2>&1`; then
Andres AGd9eba4b2016-08-26 14:42:14 +0100266 err_msg "$TOOL not found!"
267 exit 1
268 fi
269 done
270}
271
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100272pre_parse_command_line () {
Gilles Peskineeb39b9b2019-01-08 23:41:00 +0100273 COMMAND_LINE_COMPONENTS=
274 all_except=
Gilles Peskine6e984232018-11-27 21:37:53 +0100275
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100276 while [ $# -gt 0 ]; do
277 case "$1" in
278 --armcc) RUN_ARMCC=1;;
279 --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
280 --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
Gilles Peskineeb39b9b2019-01-08 23:41:00 +0100281 --except) all_except=1;;
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100282 --force|-f) FORCE=1;;
283 --gnutls-cli) shift; GNUTLS_CLI="$1";;
284 --gnutls-legacy-cli) shift; GNUTLS_LEGACY_CLI="$1";;
285 --gnutls-legacy-serv) shift; GNUTLS_LEGACY_SERV="$1";;
286 --gnutls-serv) shift; GNUTLS_SERV="$1";;
287 --help|-h) usage; exit;;
288 --keep-going|-k) KEEP_GOING=1;;
Gilles Peskineb3241cb2019-01-08 23:44:07 +0100289 --list-all-components) printf '%s\n' $ALL_COMPONENTS; exit;;
290 --list-components) printf '%s\n' $SUPPORTED_COMPONENTS; exit;;
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100291 --memory|-m) MEMORY=1;;
292 --no-armcc) RUN_ARMCC=0;;
293 --no-force) FORCE=0;;
294 --no-keep-going) KEEP_GOING=0;;
295 --no-memory) MEMORY=0;;
296 --no-yotta) YOTTA=0;;
297 --openssl) shift; OPENSSL="$1";;
298 --openssl-legacy) shift; OPENSSL_LEGACY="$1";;
299 --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
300 --random-seed) unset SEED;;
301 --release-test|-r) SEED=1;;
302 --seed|-s) shift; SEED="$1";;
303 --yotta) YOTTA=1;;
Gilles Peskine91bd8b72019-01-08 23:01:34 +0100304 -*)
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100305 echo >&2 "Unknown option: $1"
306 echo >&2 "Run $0 --help for usage."
307 exit 120
308 ;;
Gilles Peskineeb39b9b2019-01-08 23:41:00 +0100309 *) COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS $1";;
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100310 esac
311 shift
312 done
Gilles Peskine91bd8b72019-01-08 23:01:34 +0100313
Gilles Peskineeb39b9b2019-01-08 23:41:00 +0100314 if [ -z "$COMMAND_LINE_COMPONENTS" ]; then
315 all_except=1
316 fi
317
318 # Build the list of components to run.
319 if [ -n "$all_except" ]; then
Gilles Peskine6e984232018-11-27 21:37:53 +0100320 RUN_COMPONENTS=
Gilles Peskine3fbdd212019-01-08 23:33:45 +0100321 for component in $SUPPORTED_COMPONENTS; do
Gilles Peskine6e984232018-11-27 21:37:53 +0100322 if ! is_component_excluded "$component"; then
323 RUN_COMPONENTS="$RUN_COMPONENTS $component"
324 fi
325 done
Gilles Peskine6e984232018-11-27 21:37:53 +0100326 else
Gilles Peskineeb39b9b2019-01-08 23:41:00 +0100327 RUN_COMPONENTS="$COMMAND_LINE_COMPONENTS"
Gilles Peskine91bd8b72019-01-08 23:01:34 +0100328 fi
Gilles Peskineeb39b9b2019-01-08 23:41:00 +0100329
330 unset all_except
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100331}
SimonB2e23c822016-04-16 21:54:39 +0100332
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100333pre_check_git () {
334 if [ $FORCE -eq 1 ]; then
335 if [ $YOTTA -eq 1 ]; then
336 rm -rf yotta/module "$OUT_OF_SOURCE_DIR"
337 fi
338 git checkout-index -f -q $CONFIG_H
339 cleanup
340 else
341
342 if [ $YOTTA -ne 0 ] && [ -d yotta/module ]; then
343 err_msg "Warning - there is an existing yotta module in the directory 'yotta/module'"
344 echo "You can either delete your work and retry, or force the test to overwrite the"
345 echo "test by rerunning the script as: $0 --force"
346 exit 1
347 fi
348
349 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
350 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
351 echo "You can either delete this directory manually, or force the test by rerunning"
352 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
353 exit 1
354 fi
355
356 if ! git diff-files --quiet include/mbedtls/config.h; then
357 err_msg "Warning - the configuration file 'include/mbedtls/config.h' has been edited. "
358 echo "You can either delete or preserve your work, or force the test by rerunning the"
359 echo "script as: $0 --force"
360 exit 1
361 fi
Gilles Peskineda519252017-11-30 13:22:04 +0100362 fi
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100363}
SimonB2e23c822016-04-16 21:54:39 +0100364
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100365pre_setup_keep_going () {
Gilles Peskine7c652162017-12-11 00:01:40 +0100366 failure_summary=
367 failure_count=0
368 start_red=
369 end_color=
370 if [ -t 1 ]; then
Gilles Peskine9736b9d2018-01-02 21:54:17 +0100371 case "${TERM:-}" in
Gilles Peskine7c652162017-12-11 00:01:40 +0100372 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
373 start_red=$(printf '\033[31m')
374 end_color=$(printf '\033[0m')
375 ;;
376 esac
377 fi
378 record_status () {
379 if "$@"; then
380 last_status=0
381 else
382 last_status=$?
383 text="$current_section: $* -> $last_status"
384 failure_summary="$failure_summary
385$text"
386 failure_count=$((failure_count + 1))
387 echo "${start_red}^^^^$text^^^^${end_color}"
388 fi
389 }
390 make () {
391 case "$*" in
392 *test|*check)
393 if [ $build_status -eq 0 ]; then
394 record_status command make "$@"
395 else
396 echo "(skipped because the build failed)"
397 fi
398 ;;
399 *)
400 record_status command make "$@"
401 build_status=$last_status
402 ;;
403 esac
404 }
405 final_report () {
406 if [ $failure_count -gt 0 ]; then
407 echo
408 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
409 echo "${start_red}FAILED: $failure_count${end_color}$failure_summary"
410 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Jaeden Amero5113bde2018-07-20 16:42:14 +0100411 exit 1
Gilles Peskine7c652162017-12-11 00:01:40 +0100412 elif [ -z "${1-}" ]; then
413 echo "SUCCESS :)"
414 fi
415 if [ -n "${1-}" ]; then
416 echo "Killed by SIG$1."
417 fi
418 }
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100419}
420
Gilles Peskine7c652162017-12-11 00:01:40 +0100421if_build_succeeded () {
422 if [ $build_status -eq 0 ]; then
423 record_status "$@"
424 fi
425}
426
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100427pre_print_configuration () {
428 msg "info: $0 configuration"
429 echo "MEMORY: $MEMORY"
430 echo "FORCE: $FORCE"
431 echo "SEED: ${SEED-"UNSET"}"
432 echo "OPENSSL: $OPENSSL"
433 echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
434 echo "GNUTLS_CLI: $GNUTLS_CLI"
435 echo "GNUTLS_SERV: $GNUTLS_SERV"
436 echo "GNUTLS_LEGACY_CLI: $GNUTLS_LEGACY_CLI"
437 echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV"
438 echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
439 echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
440}
Andres AG7770ea82016-10-10 15:46:20 +0100441
Andres AGd9eba4b2016-08-26 14:42:14 +0100442# Make sure the tools we need are available.
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100443pre_check_tools () {
444 ARMC5_CC="$ARMC5_BIN_DIR/armcc"
445 ARMC5_AR="$ARMC5_BIN_DIR/armar"
446 ARMC6_CC="$ARMC6_BIN_DIR/armclang"
447 ARMC6_AR="$ARMC6_BIN_DIR/armar"
448
449 # To avoid setting OpenSSL and GnuTLS for each call to compat.sh and ssl-opt.sh
450 # we just export the variables they require
451 export OPENSSL_CMD="$OPENSSL"
452 export GNUTLS_CLI="$GNUTLS_CLI"
453 export GNUTLS_SERV="$GNUTLS_SERV"
454
455 # Avoid passing --seed flag in every call to ssl-opt.sh
456 if [ -n "${SEED-}" ]; then
457 export SEED
458 fi
459
460 check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$GNUTLS_CLI" "$GNUTLS_SERV" \
461 "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV" "doxygen" "dot" \
462 "arm-none-eabi-gcc" "i686-w64-mingw32-gcc"
463 if [ $RUN_ARMCC -ne 0 ]; then
464 check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC6_CC" "$ARMC6_AR"
465 fi
466
467 msg "info: output_env.sh"
468 OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY" GNUTLS_CLI="$GNUTLS_CLI" \
469 GNUTLS_SERV="$GNUTLS_SERV" GNUTLS_LEGACY_CLI="$GNUTLS_LEGACY_CLI" \
470 GNUTLS_LEGACY_SERV="$GNUTLS_LEGACY_SERV" ARMC5_CC="$ARMC5_CC" \
471 ARMC6_CC="$ARMC6_CC" RUN_ARMCC="$RUN_ARMCC" scripts/output_env.sh
472}
Andres AGd9eba4b2016-08-26 14:42:14 +0100473
Gilles Peskine192c72f2017-12-21 15:59:21 +0100474
475
476################################################################
477#### Basic checks
478################################################################
SimonB2e23c822016-04-16 21:54:39 +0100479
480#
481# Test Suites to be executed
482#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200483# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100484# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard61bc57a2014-08-14 11:29:06 +0200485# and/or are more likely to fail than others (eg I use Clang most of the
486# time, so start with a GCC build).
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200487# 2. Minimize total running time, by avoiding useless rebuilds
488#
489# Indicative running times are given for reference.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100490
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100491component_check_recursion () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100492 msg "test: recursion.pl" # < 1s
493 record_status tests/scripts/recursion.pl library/*.c
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100494}
Manuel Pégourié-Gonnardea29d152014-11-20 17:32:33 +0100495
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100496component_check_generated_files () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100497 msg "test: freshness of generated source files" # < 1s
498 record_status tests/scripts/check-generated-files.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100499}
Manuel Pégourié-Gonnardb3b8e432015-02-13 14:52:19 +0000500
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100501component_check_doxy_blocks () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100502 msg "test: doxygen markup outside doxygen blocks" # < 1s
503 record_status tests/scripts/check-doxy-blocks.pl
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100504}
Manuel Pégourié-Gonnardd09a6b52015-04-09 17:19:23 +0200505
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100506component_check_files () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100507 msg "test: check-files.py" # < 1s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100508 record_status tests/scripts/check-files.py
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100509}
Manuel Pégourié-Gonnard77d56bb2015-07-28 15:00:37 +0200510
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100511component_check_names () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100512 msg "test/build: declared and exported names" # < 3s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100513 record_status tests/scripts/check-names.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100514}
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +0200515
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100516component_check_doxygen_warnings () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100517 msg "test: doxygen warnings" # ~ 3s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100518 record_status tests/scripts/doxygen.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100519}
Andres Amaya Garciadd29c2f2017-05-04 11:35:51 +0100520
Simon Butcher948f2642018-07-20 21:27:33 +0100521
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100522################################################################
523#### Build and test many configurations and targets
524################################################################
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100525
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100526component_build_yotta () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100527 if [ $RUN_ARMCC -ne 0 ] && [ $YOTTA -ne 0 ]; then
528 # Note - use of yotta is deprecated, and yotta also requires armcc to be on the
529 # path, and uses whatever version of armcc it finds there.
530 msg "build: create and build yotta module" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100531 record_status tests/scripts/yotta-build.sh
532 fi
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100533}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100534
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100535component_test_default_cmake_gcc_asan () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100536 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100537 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100538 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +0200539
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100540 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100541 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100542
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100543 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
Gilles Peskine7c652162017-12-11 00:01:40 +0100544 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100545
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100546 msg "test: compat.sh (ASan build)" # ~ 6 min
547 if_build_succeeded tests/compat.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100548}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000549
Gilles Peskine3484ed82019-01-08 22:51:19 +0100550component_test_ref_configs () {
551 msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
552 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
553 record_status tests/scripts/test-ref-configs.pl
554}
555
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100556component_test_sslv3 () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100557 msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100558 scripts/config.pl set MBEDTLS_SSL_PROTO_SSL3
559 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
560 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000561
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100562 msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
563 make test
564
565 msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
566 if_build_succeeded tests/compat.sh -m 'tls1 tls1_1 tls1_2 dtls1 dtls1_2'
567 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
568
569 msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
570 if_build_succeeded tests/ssl-opt.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100571}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100572
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100573component_test_no_renegotiation () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100574 msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100575 scripts/config.pl unset MBEDTLS_SSL_RENEGOTIATION
576 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
577 make
578
579 msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
580 make test
581
582 msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
583 if_build_succeeded tests/ssl-opt.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100584}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100585
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100586component_test_rsa_no_crt () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100587 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100588 scripts/config.pl set MBEDTLS_RSA_NO_CRT
589 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
590 make
591
592 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
593 make test
594
595 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
596 if_build_succeeded tests/ssl-opt.sh -f RSA
597
598 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
599 if_build_succeeded tests/compat.sh -t RSA
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100600}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100601
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100602component_test_full_cmake_clang () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100603 msg "build: cmake, full config, clang" # ~ 50s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100604 scripts/config.pl full
605 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
606 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check -D ENABLE_TESTING=On .
607 make
608
609 msg "test: main suites (full config)" # ~ 5s
610 make test
611
612 msg "test: ssl-opt.sh default (full config)" # ~ 1s
613 if_build_succeeded tests/ssl-opt.sh -f Default
614
615 msg "test: compat.sh RC4, DES & NULL (full config)" # ~ 2 min
616 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 +0100617}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100618
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100619component_build_deprecated () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100620 msg "build: make, full config + DEPRECATED_WARNING, gcc -O" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100621 scripts/config.pl full
622 scripts/config.pl set MBEDTLS_DEPRECATED_WARNING
623 # Build with -O -Wextra to catch a maximum of issues.
624 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra' lib programs
625 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
626
627 msg "build: make, full config + DEPRECATED_REMOVED, clang -O" # ~ 30s
628 # No cleanup, just tweak the configuration and rebuild
629 make clean
630 scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
631 scripts/config.pl set MBEDTLS_DEPRECATED_REMOVED
632 # Build with -O -Wextra to catch a maximum of issues.
633 make CC=clang CFLAGS='-O -Werror -Wall -Wextra' lib programs
634 make CC=clang CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100635}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100636
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100637component_test_depends_curves () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100638 msg "test/build: curves.pl (gcc)" # ~ 4 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100639 record_status tests/scripts/curves.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_test_depends_hashes () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100643 msg "test/build: depends-hashes.pl (gcc)" # ~ 2 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100644 record_status tests/scripts/depends-hashes.pl
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_depends_pkalgs () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100648 msg "test/build: depends-pkalgs.pl (gcc)" # ~ 2 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100649 record_status tests/scripts/depends-pkalgs.pl
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100650}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100651
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100652component_build_key_exchanges () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100653 msg "test/build: key-exchanges (gcc)" # ~ 1 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100654 record_status tests/scripts/key-exchanges.pl
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100655}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100656
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100657component_build_default_make_gcc () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100658 msg "build: Unix make, -Os (gcc)" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100659 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100660}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100661
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100662component_test_no_platform () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100663 # Full configuration build, without platform support, file IO and net sockets.
664 # This should catch missing mbedtls_printf definitions, and by disabling file
665 # IO, it should catch missing '#include <stdio.h>'
666 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100667 scripts/config.pl full
668 scripts/config.pl unset MBEDTLS_PLATFORM_C
669 scripts/config.pl unset MBEDTLS_NET_C
670 scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
671 scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
672 scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
673 scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
674 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
675 scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
676 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
677 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
678 scripts/config.pl unset MBEDTLS_FS_IO
679 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
680 # to re-enable platform integration features otherwise disabled in C99 builds
681 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -O0 -D_DEFAULT_SOURCE' lib programs
682 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0' test
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_std_function () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100686 # catch compile bugs in _uninit functions
687 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100688 scripts/config.pl full
689 scripts/config.pl set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
690 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
691 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100692}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100693
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100694component_build_no_ssl_srv () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100695 msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100696 scripts/config.pl full
697 scripts/config.pl unset MBEDTLS_SSL_SRV_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_ssl_cli () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100702 msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100703 scripts/config.pl full
704 scripts/config.pl unset MBEDTLS_SSL_CLI_C
705 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100706}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100707
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100708component_build_no_sockets () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100709 # Note, C99 compliance can also be tested with the sockets support disabled,
710 # as that requires a POSIX platform (which isn't the same as C99).
711 msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100712 scripts/config.pl full
713 scripts/config.pl unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
714 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
715 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0 -std=c99 -pedantic' lib
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100716}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100717
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100718component_test_no_max_fragment_length () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100719 msg "build: default config except MFL extension (ASan build)" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100720 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
721 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
722 make
723
724 msg "test: ssl-opt.sh, MFL-related tests"
725 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length"
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100726}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100727
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100728component_test_null_entropy () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100729 msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100730 scripts/config.pl set MBEDTLS_TEST_NULL_ENTROPY
731 scripts/config.pl set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
732 scripts/config.pl set MBEDTLS_ENTROPY_C
733 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
734 scripts/config.pl unset MBEDTLS_ENTROPY_HARDWARE_ALT
735 scripts/config.pl unset MBEDTLS_HAVEGE_C
Gilles Peskine4e7b3232019-01-06 19:48:30 +0000736 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan -D UNSAFE_BUILD=ON .
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100737 make
738
739 msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)"
740 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100741}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100742
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100743component_test_platform_calloc_macro () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100744 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100745 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
746 scripts/config.pl set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
747 scripts/config.pl set MBEDTLS_PLATFORM_FREE_MACRO free
748 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
749 make
750
751 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
752 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100753}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100754
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100755component_test_make_shared () {
Gilles Peskine770ad7e2019-01-08 23:19:08 +0100756 msg "build/test: make shared" # ~ 40s
757 make SHARED=1 all check
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100758}
759
Gilles Peskine3fbdd212019-01-08 23:33:45 +0100760component_test_m32_o0 () {
761 # Build once with -O0, to compile out the i386 specific inline assembly
762 msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
763 scripts/config.pl full
764 make CC=gcc CFLAGS='-O0 -Werror -Wall -Wextra -m32 -fsanitize=address'
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100765
Gilles Peskine3fbdd212019-01-08 23:33:45 +0100766 msg "test: i386, make, gcc -O0 (ASan build)"
767 make test
768}
769support_test_m32_o0 () {
770 case $(uname -m) in
771 *64*) true;;
772 *) false;;
773 esac
774}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100775
Gilles Peskine3fbdd212019-01-08 23:33:45 +0100776component_test_m32_o1 () {
777 # Build again with -O1, to compile in the i386 specific inline assembly
778 msg "build: i386, make, gcc -O1 (ASan build)" # ~ 30s
779 scripts/config.pl full
780 make CC=gcc CFLAGS='-O1 -Werror -Wall -Wextra -m32 -fsanitize=address'
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100781
Gilles Peskine3fbdd212019-01-08 23:33:45 +0100782 msg "test: i386, make, gcc -O1 (ASan build)"
783 make test
784}
785support_test_m32_o1 () {
786 support_test_m32_o0 "$@"
787}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100788
Gilles Peskine3fbdd212019-01-08 23:33:45 +0100789component_test_mx32 () {
790 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
791 scripts/config.pl full
792 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32'
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100793
Gilles Peskine3fbdd212019-01-08 23:33:45 +0100794 msg "test: 64-bit ILP32, make, gcc"
795 make test
796}
797support_test_mx32 () {
798 case $(uname -m) in
799 amd64|x86_64) true;;
800 *) false;;
801 esac
802}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100803
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100804component_test_have_int32 () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100805 msg "build: gcc, force 32-bit bignum limbs"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100806 scripts/config.pl unset MBEDTLS_HAVE_ASM
807 scripts/config.pl unset MBEDTLS_AESNI_C
808 scripts/config.pl unset MBEDTLS_PADLOCK_C
809 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
810
811 msg "test: gcc, force 32-bit bignum limbs"
812 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100813}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100814
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100815component_test_have_int64 () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100816 msg "build: gcc, force 64-bit bignum limbs"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100817 scripts/config.pl unset MBEDTLS_HAVE_ASM
818 scripts/config.pl unset MBEDTLS_AESNI_C
819 scripts/config.pl unset MBEDTLS_PADLOCK_C
820 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
821
822 msg "test: gcc, force 64-bit bignum limbs"
823 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100824}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100825
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100826component_build_arm_none_eabi_gcc () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100827 msg "build: arm-none-eabi-gcc, make" # ~ 10s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100828 scripts/config.pl full
829 scripts/config.pl unset MBEDTLS_NET_C
830 scripts/config.pl unset MBEDTLS_TIMING_C
831 scripts/config.pl unset MBEDTLS_FS_IO
832 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
833 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
834 # following things are not in the default config
835 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
836 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
837 scripts/config.pl unset MBEDTLS_THREADING_C
838 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
839 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
840 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 +0100841}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100842
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100843component_build_arm_none_eabi_gcc_no_udbl_division () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100844 msg "build: arm-none-eabi-gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100845 scripts/config.pl full
846 scripts/config.pl unset MBEDTLS_NET_C
847 scripts/config.pl unset MBEDTLS_TIMING_C
848 scripts/config.pl unset MBEDTLS_FS_IO
849 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
850 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
851 # following things are not in the default config
852 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
853 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
854 scripts/config.pl unset MBEDTLS_THREADING_C
855 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
856 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
857 scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
858 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
859 echo "Checking that software 64-bit division is not required"
860 ! grep __aeabi_uldiv library/*.o
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100861}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100862
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100863component_build_armcc () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100864 msg "build: ARM Compiler 5, make"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100865 scripts/config.pl full
866 scripts/config.pl unset MBEDTLS_NET_C
867 scripts/config.pl unset MBEDTLS_TIMING_C
868 scripts/config.pl unset MBEDTLS_FS_IO
869 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
870 scripts/config.pl unset MBEDTLS_HAVE_TIME
871 scripts/config.pl unset MBEDTLS_HAVE_TIME_DATE
872 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
873 # following things are not in the default config
874 scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
875 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
876 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
877 scripts/config.pl unset MBEDTLS_THREADING_C
878 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
879 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
880 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT # depends on MBEDTLS_HAVE_TIME
881
882 if [ $RUN_ARMCC -ne 0 ]; then
883 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
884 make clean
885
886 # ARM Compiler 6 - Target ARMv7-A
887 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-a"
888
889 # ARM Compiler 6 - Target ARMv7-M
890 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m"
891
892 # ARM Compiler 6 - Target ARMv8-A - AArch32
893 armc6_build_test "--target=arm-arm-none-eabi -march=armv8.2-a"
894
895 # ARM Compiler 6 - Target ARMv8-M
896 armc6_build_test "--target=arm-arm-none-eabi -march=armv8-m.main"
897
898 # ARM Compiler 6 - Target ARMv8-A - AArch64
899 armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a"
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100900 fi
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100901}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000902
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100903component_test_allow_sha1 () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100904 msg "build: allow SHA1 in certificates by default"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100905 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 Peskine770ad7e2019-01-08 23:19:08 +0100927 msg "build: MSan (clang)" # ~ 1 min 20s
928 scripts/config.pl unset MBEDTLS_AESNI_C # memsan doesn't grok asm
929 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
930 make
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100931
Gilles Peskine770ad7e2019-01-08 23:19:08 +0100932 msg "test: main suites (MSan)" # ~ 10s
933 make test
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100934
Gilles Peskine770ad7e2019-01-08 23:19:08 +0100935 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
936 if_build_succeeded tests/ssl-opt.sh
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100937
Gilles Peskine770ad7e2019-01-08 23:19:08 +0100938 # Optional part(s)
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100939
Gilles Peskine770ad7e2019-01-08 23:19:08 +0100940 if [ "$MEMORY" -gt 0 ]; then
941 msg "test: compat.sh (MSan)" # ~ 6 min 20s
942 if_build_succeeded tests/compat.sh
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 () {
Gilles Peskine770ad7e2019-01-08 23:19:08 +0100947 msg "build: Release (clang)"
948 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
949 make
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100950
Gilles Peskine770ad7e2019-01-08 23:19:08 +0100951 msg "test: main suites valgrind (Release)"
952 make memcheck
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100953
Gilles Peskine770ad7e2019-01-08 23:19:08 +0100954 # Optional part(s)
955 # Currently broken, programs don't seem to receive signals
956 # under valgrind on OS X
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100957
Gilles Peskine770ad7e2019-01-08 23:19:08 +0100958 if [ "$MEMORY" -gt 0 ]; then
959 msg "test: ssl-opt.sh --memcheck (Release)"
960 if_build_succeeded tests/ssl-opt.sh --memcheck
961 fi
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100962
Gilles Peskine770ad7e2019-01-08 23:19:08 +0100963 if [ "$MEMORY" -gt 1 ]; then
964 msg "test: compat.sh --memcheck (Release)"
965 if_build_succeeded tests/compat.sh --memcheck
966 fi
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100967}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100968
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100969component_test_cmake_out_of_source () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100970 msg "build: cmake 'out-of-source' build"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100971 MBEDTLS_ROOT_DIR="$PWD"
972 mkdir "$OUT_OF_SOURCE_DIR"
973 cd "$OUT_OF_SOURCE_DIR"
974 cmake "$MBEDTLS_ROOT_DIR"
975 make
976
977 msg "test: cmake 'out-of-source' build"
978 make test
979 # Test an SSL option that requires an auxiliary script in test/scripts/.
980 # Also ensure that there are no error messages such as
981 # "No such file or directory", which would indicate that some required
982 # file is missing (ssl-opt.sh tolerates the absence of some files so
983 # may exit with status 0 but emit errors).
984 if_build_succeeded ./tests/ssl-opt.sh -f 'Fallback SCSV: beginning of list' 2>ssl-opt.err
985 if [ -s ssl-opt.err ]; then
986 cat ssl-opt.err >&2
987 record_status [ ! -s ssl-opt.err ]
988 rm ssl-opt.err
989 fi
990 cd "$MBEDTLS_ROOT_DIR"
991 rm -rf "$OUT_OF_SOURCE_DIR"
992 unset MBEDTLS_ROOT_DIR
993}
Andres AGdc192212016-08-31 17:33:13 +0100994
Gilles Peskine192c72f2017-12-21 15:59:21 +0100995
996
997################################################################
998#### Termination
999################################################################
1000
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001001post_report () {
1002 msg "Done, cleaning up"
1003 cleanup
1004
1005 final_report
1006}
1007
1008
1009
1010################################################################
1011#### Run all the things
1012################################################################
1013
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001014# Run one component and clean up afterwards.
1015run_component () {
Gilles Peskine72adb432019-01-02 18:57:02 +01001016 # Back up the configuration in case the component modifies it.
1017 # The cleanup function will restore it.
1018 cp -p "$CONFIG_H" "$CONFIG_BAK"
Gilles Peskine11ddca62018-12-04 12:49:28 +01001019 current_component="$1"
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001020 "$@"
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 Peskineeb39b9b2019-01-08 23:41:00 +01001042# Run the requested tests.
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