blob: b1a76acb68b5933597a38d37cc41d6f37903ee32 [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 Peskine57db6ff2019-01-08 22:04:31 +010097 MEMORY=0
98 FORCE=0
99 KEEP_GOING=0
100 RUN_ARMCC=1
101 YOTTA=1
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100102
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100103 # Default commands, can be overriden by the environment
104 : ${OPENSSL:="openssl"}
105 : ${OPENSSL_LEGACY:="$OPENSSL"}
106 : ${GNUTLS_CLI:="gnutls-cli"}
107 : ${GNUTLS_SERV:="gnutls-serv"}
108 : ${GNUTLS_LEGACY_CLI:="$GNUTLS_CLI"}
109 : ${GNUTLS_LEGACY_SERV:="$GNUTLS_SERV"}
110 : ${OUT_OF_SOURCE_DIR:=./mbedtls_out_of_source_build}
111 : ${ARMC5_BIN_DIR:=/usr/bin}
112 : ${ARMC6_BIN_DIR:=/usr/bin}
Andres AGdc192212016-08-31 17:33:13 +0100113
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100114 # if MAKEFLAGS is not set add the -j option to speed up invocations of make
115 if [ -n "${MAKEFLAGS+set}" ]; then
116 export MAKEFLAGS="-j"
117 fi
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100118
119 # Gather the list of available components. These are the functions
120 # defined in this script whose name starts with "component_".
121 # Parse the script with sed, because in sh there is no way to list
122 # defined functions.
123 ALL_COMPONENTS=$(sed -n 's/^ *component_\([0-9A-Z_a-z]*\) *().*/\1/p' <"$0")
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100124}
Andres AG38495a32016-07-12 16:54:33 +0100125
Simon Butcher41eeccf2016-09-07 00:07:09 +0100126usage()
SimonB2e23c822016-04-16 21:54:39 +0100127{
Gilles Peskine709346a2017-12-10 23:43:39 +0100128 cat <<EOF
129Usage: $0 [OPTION]...
130 -h|--help Print this help.
131
132General options:
133 -f|--force Force the tests to overwrite any modified files.
Gilles Peskine7c652162017-12-11 00:01:40 +0100134 -k|--keep-going Run all tests and report errors at the end.
Gilles Peskine709346a2017-12-10 23:43:39 +0100135 -m|--memory Additional optional memory tests.
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100136 --armcc Run ARM Compiler builds (on by default).
137 --no-armcc Skip ARM Compiler builds.
Gilles Peskine19ceb712018-03-21 08:40:26 +0100138 --no-force Refuse to overwrite modified files (default).
139 --no-keep-going Stop at the first error (default).
140 --no-memory No additional memory tests (default).
Gilles Peskine2a22a802017-12-21 15:19:00 +0100141 --no-yotta Skip yotta module build.
Gilles Peskine709346a2017-12-10 23:43:39 +0100142 --out-of-source-dir=<path> Directory used for CMake out-of-source build tests.
Gilles Peskine19ceb712018-03-21 08:40:26 +0100143 --random-seed Use a random seed value for randomized tests (default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100144 -r|--release-test Run this script in release mode. This fixes the seed value to 1.
145 -s|--seed Integer seed value to use for this test run.
Gilles Peskine2a22a802017-12-21 15:19:00 +0100146 --yotta Build yotta module (on by default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100147
148Tool path options:
149 --armc5-bin-dir=<ARMC5_bin_dir_path> ARM Compiler 5 bin directory.
150 --armc6-bin-dir=<ARMC6_bin_dir_path> ARM Compiler 6 bin directory.
151 --gnutls-cli=<GnuTLS_cli_path> GnuTLS client executable to use for most tests.
152 --gnutls-serv=<GnuTLS_serv_path> GnuTLS server executable to use for most tests.
153 --gnutls-legacy-cli=<GnuTLS_cli_path> GnuTLS client executable to use for legacy tests.
154 --gnutls-legacy-serv=<GnuTLS_serv_path> GnuTLS server executable to use for legacy tests.
155 --openssl=<OpenSSL_path> OpenSSL executable to use for most tests.
156 --openssl-legacy=<OpenSSL_path> OpenSSL executable to use for legacy tests e.g. SSLv3.
157EOF
SimonB2e23c822016-04-16 21:54:39 +0100158}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100159
160# remove built files as well as the cmake cache/config
161cleanup()
162{
Gilles Peskinea71d64c2018-03-21 12:16:57 +0100163 if [ -n "${MBEDTLS_ROOT_DIR+set}" ]; then
164 cd "$MBEDTLS_ROOT_DIR"
165 fi
166
Gilles Peskine7c652162017-12-11 00:01:40 +0100167 command make clean
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200168
Gilles Peskine31b07e22018-03-21 12:15:06 +0100169 # Remove CMake artefacts
170 find . -name .git -prune -o -name yotta -prune -o \
171 -iname CMakeFiles -exec rm -rf {} \+ -o \
172 \( -iname cmake_install.cmake -o \
173 -iname CTestTestfile.cmake -o \
174 -iname CMakeCache.txt \) -exec rm {} \+
175 # Recover files overwritten by in-tree CMake builds
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000176 rm -f include/Makefile include/mbedtls/Makefile programs/*/Makefile
Paul Bakkerfe0984d2014-06-13 00:13:45 +0200177 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile
178 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200179
180 if [ -f "$CONFIG_BAK" ]; then
181 mv "$CONFIG_BAK" "$CONFIG_H"
182 fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100183}
184
Gilles Peskine7c652162017-12-11 00:01:40 +0100185# Executed on exit. May be redefined depending on command line options.
186final_report () {
187 :
188}
189
190fatal_signal () {
191 cleanup
192 final_report $1
193 trap - $1
194 kill -$1 $$
195}
196
197trap 'fatal_signal HUP' HUP
198trap 'fatal_signal INT' INT
199trap 'fatal_signal TERM' TERM
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200200
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100201msg()
202{
203 echo ""
204 echo "******************************************************************"
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100205 echo "* $1 "
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000206 printf "* "; date
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100207 echo "******************************************************************"
Gilles Peskine7c652162017-12-11 00:01:40 +0100208 current_section=$1
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100209}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100210
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100211armc6_build_test()
212{
213 FLAGS="$1"
Andres AGa5cd9732016-10-17 15:23:10 +0100214
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100215 msg "build: ARM Compiler 6 ($FLAGS), make"
216 ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \
217 WARNING_CFLAGS='-xc -std=c99' make lib
218 make clean
219}
Andres AGa5cd9732016-10-17 15:23:10 +0100220
Andres AGd9eba4b2016-08-26 14:42:14 +0100221err_msg()
222{
223 echo "$1" >&2
224}
225
226check_tools()
227{
228 for TOOL in "$@"; do
Andres AG98393602017-01-31 17:04:45 +0000229 if ! `type "$TOOL" >/dev/null 2>&1`; then
Andres AGd9eba4b2016-08-26 14:42:14 +0100230 err_msg "$TOOL not found!"
231 exit 1
232 fi
233 done
234}
235
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100236pre_parse_command_line () {
237 while [ $# -gt 0 ]; do
238 case "$1" in
239 --armcc) RUN_ARMCC=1;;
240 --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
241 --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
242 --force|-f) FORCE=1;;
243 --gnutls-cli) shift; GNUTLS_CLI="$1";;
244 --gnutls-legacy-cli) shift; GNUTLS_LEGACY_CLI="$1";;
245 --gnutls-legacy-serv) shift; GNUTLS_LEGACY_SERV="$1";;
246 --gnutls-serv) shift; GNUTLS_SERV="$1";;
247 --help|-h) usage; exit;;
248 --keep-going|-k) KEEP_GOING=1;;
249 --memory|-m) MEMORY=1;;
250 --no-armcc) RUN_ARMCC=0;;
251 --no-force) FORCE=0;;
252 --no-keep-going) KEEP_GOING=0;;
253 --no-memory) MEMORY=0;;
254 --no-yotta) YOTTA=0;;
255 --openssl) shift; OPENSSL="$1";;
256 --openssl-legacy) shift; OPENSSL_LEGACY="$1";;
257 --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
258 --random-seed) unset SEED;;
259 --release-test|-r) SEED=1;;
260 --seed|-s) shift; SEED="$1";;
261 --yotta) YOTTA=1;;
262 *)
263 echo >&2 "Unknown option: $1"
264 echo >&2 "Run $0 --help for usage."
265 exit 120
266 ;;
267 esac
268 shift
269 done
270}
SimonB2e23c822016-04-16 21:54:39 +0100271
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100272pre_check_git () {
273 if [ $FORCE -eq 1 ]; then
274 if [ $YOTTA -eq 1 ]; then
275 rm -rf yotta/module "$OUT_OF_SOURCE_DIR"
276 fi
277 git checkout-index -f -q $CONFIG_H
278 cleanup
279 else
280
281 if [ $YOTTA -ne 0 ] && [ -d yotta/module ]; then
282 err_msg "Warning - there is an existing yotta module in the directory 'yotta/module'"
283 echo "You can either delete your work and retry, or force the test to overwrite the"
284 echo "test by rerunning the script as: $0 --force"
285 exit 1
286 fi
287
288 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
289 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
290 echo "You can either delete this directory manually, or force the test by rerunning"
291 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
292 exit 1
293 fi
294
295 if ! git diff-files --quiet include/mbedtls/config.h; then
296 err_msg "Warning - the configuration file 'include/mbedtls/config.h' has been edited. "
297 echo "You can either delete or preserve your work, or force the test by rerunning the"
298 echo "script as: $0 --force"
299 exit 1
300 fi
Gilles Peskineda519252017-11-30 13:22:04 +0100301 fi
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100302}
SimonB2e23c822016-04-16 21:54:39 +0100303
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100304pre_setup_keep_going () {
Gilles Peskine7c652162017-12-11 00:01:40 +0100305 failure_summary=
306 failure_count=0
307 start_red=
308 end_color=
309 if [ -t 1 ]; then
Gilles Peskine9736b9d2018-01-02 21:54:17 +0100310 case "${TERM:-}" in
Gilles Peskine7c652162017-12-11 00:01:40 +0100311 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
312 start_red=$(printf '\033[31m')
313 end_color=$(printf '\033[0m')
314 ;;
315 esac
316 fi
317 record_status () {
318 if "$@"; then
319 last_status=0
320 else
321 last_status=$?
322 text="$current_section: $* -> $last_status"
323 failure_summary="$failure_summary
324$text"
325 failure_count=$((failure_count + 1))
326 echo "${start_red}^^^^$text^^^^${end_color}"
327 fi
328 }
329 make () {
330 case "$*" in
331 *test|*check)
332 if [ $build_status -eq 0 ]; then
333 record_status command make "$@"
334 else
335 echo "(skipped because the build failed)"
336 fi
337 ;;
338 *)
339 record_status command make "$@"
340 build_status=$last_status
341 ;;
342 esac
343 }
344 final_report () {
345 if [ $failure_count -gt 0 ]; then
346 echo
347 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
348 echo "${start_red}FAILED: $failure_count${end_color}$failure_summary"
349 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Jaeden Amero5113bde2018-07-20 16:42:14 +0100350 exit 1
Gilles Peskine7c652162017-12-11 00:01:40 +0100351 elif [ -z "${1-}" ]; then
352 echo "SUCCESS :)"
353 fi
354 if [ -n "${1-}" ]; then
355 echo "Killed by SIG$1."
356 fi
357 }
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100358}
359
Gilles Peskine7c652162017-12-11 00:01:40 +0100360if_build_succeeded () {
361 if [ $build_status -eq 0 ]; then
362 record_status "$@"
363 fi
364}
365
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100366pre_print_configuration () {
367 msg "info: $0 configuration"
368 echo "MEMORY: $MEMORY"
369 echo "FORCE: $FORCE"
370 echo "SEED: ${SEED-"UNSET"}"
371 echo "OPENSSL: $OPENSSL"
372 echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
373 echo "GNUTLS_CLI: $GNUTLS_CLI"
374 echo "GNUTLS_SERV: $GNUTLS_SERV"
375 echo "GNUTLS_LEGACY_CLI: $GNUTLS_LEGACY_CLI"
376 echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV"
377 echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
378 echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
379}
Andres AG7770ea82016-10-10 15:46:20 +0100380
Andres AGd9eba4b2016-08-26 14:42:14 +0100381# Make sure the tools we need are available.
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100382pre_check_tools () {
383 ARMC5_CC="$ARMC5_BIN_DIR/armcc"
384 ARMC5_AR="$ARMC5_BIN_DIR/armar"
385 ARMC6_CC="$ARMC6_BIN_DIR/armclang"
386 ARMC6_AR="$ARMC6_BIN_DIR/armar"
387
388 # To avoid setting OpenSSL and GnuTLS for each call to compat.sh and ssl-opt.sh
389 # we just export the variables they require
390 export OPENSSL_CMD="$OPENSSL"
391 export GNUTLS_CLI="$GNUTLS_CLI"
392 export GNUTLS_SERV="$GNUTLS_SERV"
393
394 # Avoid passing --seed flag in every call to ssl-opt.sh
395 if [ -n "${SEED-}" ]; then
396 export SEED
397 fi
398
399 check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$GNUTLS_CLI" "$GNUTLS_SERV" \
400 "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV" "doxygen" "dot" \
401 "arm-none-eabi-gcc" "i686-w64-mingw32-gcc"
402 if [ $RUN_ARMCC -ne 0 ]; then
403 check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC6_CC" "$ARMC6_AR"
404 fi
405
406 msg "info: output_env.sh"
407 OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY" GNUTLS_CLI="$GNUTLS_CLI" \
408 GNUTLS_SERV="$GNUTLS_SERV" GNUTLS_LEGACY_CLI="$GNUTLS_LEGACY_CLI" \
409 GNUTLS_LEGACY_SERV="$GNUTLS_LEGACY_SERV" ARMC5_CC="$ARMC5_CC" \
410 ARMC6_CC="$ARMC6_CC" RUN_ARMCC="$RUN_ARMCC" scripts/output_env.sh
411}
Andres AGd9eba4b2016-08-26 14:42:14 +0100412
Gilles Peskine192c72f2017-12-21 15:59:21 +0100413
414
415################################################################
416#### Basic checks
417################################################################
SimonB2e23c822016-04-16 21:54:39 +0100418
419#
420# Test Suites to be executed
421#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200422# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100423# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard61bc57a2014-08-14 11:29:06 +0200424# and/or are more likely to fail than others (eg I use Clang most of the
425# time, so start with a GCC build).
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200426# 2. Minimize total running time, by avoiding useless rebuilds
427#
428# Indicative running times are given for reference.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100429
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100430component_check_recursion () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100431 msg "test: recursion.pl" # < 1s
432 record_status tests/scripts/recursion.pl library/*.c
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100433}
Manuel Pégourié-Gonnardea29d152014-11-20 17:32:33 +0100434
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100435component_check_generated_files () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100436 msg "test: freshness of generated source files" # < 1s
437 record_status tests/scripts/check-generated-files.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100438}
Manuel Pégourié-Gonnardb3b8e432015-02-13 14:52:19 +0000439
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100440component_check_doxy_blocks () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100441 msg "test: doxygen markup outside doxygen blocks" # < 1s
442 record_status tests/scripts/check-doxy-blocks.pl
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100443}
Manuel Pégourié-Gonnardd09a6b52015-04-09 17:19:23 +0200444
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100445component_check_files () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100446 msg "test: check-files.py" # < 1s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100447 record_status tests/scripts/check-files.py
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100448}
Manuel Pégourié-Gonnard77d56bb2015-07-28 15:00:37 +0200449
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100450component_check_names () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100451 msg "test/build: declared and exported names" # < 3s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100452 record_status tests/scripts/check-names.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100453}
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +0200454
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100455component_check_doxygen_warnings () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100456 msg "test: doxygen warnings" # ~ 3s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100457 record_status tests/scripts/doxygen.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100458}
Andres Amaya Garciadd29c2f2017-05-04 11:35:51 +0100459
Simon Butcher948f2642018-07-20 21:27:33 +0100460
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100461################################################################
462#### Build and test many configurations and targets
463################################################################
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100464
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100465component_build_yotta () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100466 if [ $RUN_ARMCC -ne 0 ] && [ $YOTTA -ne 0 ]; then
467 # Note - use of yotta is deprecated, and yotta also requires armcc to be on the
468 # path, and uses whatever version of armcc it finds there.
469 msg "build: create and build yotta module" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100470 record_status tests/scripts/yotta-build.sh
471 fi
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100472}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100473
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100474component_test_default_cmake_gcc_asan () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100475 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100476 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100477 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +0200478
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100479 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100480 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100481
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100482 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
Gilles Peskine7c652162017-12-11 00:01:40 +0100483 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100484
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100485 msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
486 record_status tests/scripts/test-ref-configs.pl
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100487
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100488 msg "build: with ASan (rebuild after ref-configs)" # ~ 1 min
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100489 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000490
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100491 msg "test: compat.sh (ASan build)" # ~ 6 min
492 if_build_succeeded tests/compat.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100493}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000494
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100495component_test_sslv3 () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100496 msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100497 cp "$CONFIG_H" "$CONFIG_BAK"
498 scripts/config.pl set MBEDTLS_SSL_PROTO_SSL3
499 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
500 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000501
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100502 msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
503 make test
504
505 msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
506 if_build_succeeded tests/compat.sh -m 'tls1 tls1_1 tls1_2 dtls1 dtls1_2'
507 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
508
509 msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
510 if_build_succeeded tests/ssl-opt.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100511}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100512
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100513component_test_no_renegotiation () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100514 msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100515 cp "$CONFIG_H" "$CONFIG_BAK"
516 scripts/config.pl unset MBEDTLS_SSL_RENEGOTIATION
517 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
518 make
519
520 msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
521 make test
522
523 msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
524 if_build_succeeded tests/ssl-opt.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100525}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100526
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100527component_test_rsa_no_crt () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100528 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100529 cp "$CONFIG_H" "$CONFIG_BAK"
530 scripts/config.pl set MBEDTLS_RSA_NO_CRT
531 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
532 make
533
534 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
535 make test
536
537 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
538 if_build_succeeded tests/ssl-opt.sh -f RSA
539
540 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
541 if_build_succeeded tests/compat.sh -t RSA
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100542}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100543
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100544component_test_full_cmake_clang () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100545 msg "build: cmake, full config, clang" # ~ 50s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100546 cp "$CONFIG_H" "$CONFIG_BAK"
547 scripts/config.pl full
548 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
549 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check -D ENABLE_TESTING=On .
550 make
551
552 msg "test: main suites (full config)" # ~ 5s
553 make test
554
555 msg "test: ssl-opt.sh default (full config)" # ~ 1s
556 if_build_succeeded tests/ssl-opt.sh -f Default
557
558 msg "test: compat.sh RC4, DES & NULL (full config)" # ~ 2 min
559 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 +0100560}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100561
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100562component_build_deprecated () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100563 msg "build: make, full config + DEPRECATED_WARNING, gcc -O" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100564 cp "$CONFIG_H" "$CONFIG_BAK"
565 scripts/config.pl full
566 scripts/config.pl set MBEDTLS_DEPRECATED_WARNING
567 # Build with -O -Wextra to catch a maximum of issues.
568 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra' lib programs
569 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
570
571 msg "build: make, full config + DEPRECATED_REMOVED, clang -O" # ~ 30s
572 # No cleanup, just tweak the configuration and rebuild
573 make clean
574 scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
575 scripts/config.pl set MBEDTLS_DEPRECATED_REMOVED
576 # Build with -O -Wextra to catch a maximum of issues.
577 make CC=clang CFLAGS='-O -Werror -Wall -Wextra' lib programs
578 make CC=clang CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100579}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100580
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100581component_test_depends_curves () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100582 msg "test/build: curves.pl (gcc)" # ~ 4 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100583 record_status tests/scripts/curves.pl
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_depends_hashes () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100587 msg "test/build: depends-hashes.pl (gcc)" # ~ 2 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100588 record_status tests/scripts/depends-hashes.pl
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100589}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100590
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100591component_test_depends_pkalgs () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100592 msg "test/build: depends-pkalgs.pl (gcc)" # ~ 2 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100593 record_status tests/scripts/depends-pkalgs.pl
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100594}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100595
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100596component_build_key_exchanges () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100597 msg "test/build: key-exchanges (gcc)" # ~ 1 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100598 record_status tests/scripts/key-exchanges.pl
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100599}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100600
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100601component_build_default_make_gcc () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100602 msg "build: Unix make, -Os (gcc)" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100603 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100604}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100605
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100606component_test_no_platform () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100607 # Full configuration build, without platform support, file IO and net sockets.
608 # This should catch missing mbedtls_printf definitions, and by disabling file
609 # IO, it should catch missing '#include <stdio.h>'
610 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100611 cp "$CONFIG_H" "$CONFIG_BAK"
612 scripts/config.pl full
613 scripts/config.pl unset MBEDTLS_PLATFORM_C
614 scripts/config.pl unset MBEDTLS_NET_C
615 scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
616 scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
617 scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
618 scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
619 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
620 scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
621 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
622 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
623 scripts/config.pl unset MBEDTLS_FS_IO
624 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
625 # to re-enable platform integration features otherwise disabled in C99 builds
626 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -O0 -D_DEFAULT_SOURCE' lib programs
627 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0' test
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100628}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100629
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100630component_build_no_std_function () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100631 # catch compile bugs in _uninit functions
632 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100633 cp "$CONFIG_H" "$CONFIG_BAK"
634 scripts/config.pl full
635 scripts/config.pl set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
636 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
637 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100638}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100639
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100640component_build_no_ssl_srv () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100641 msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100642 cp "$CONFIG_H" "$CONFIG_BAK"
643 scripts/config.pl full
644 scripts/config.pl unset MBEDTLS_SSL_SRV_C
645 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100646}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100647
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100648component_build_no_ssl_cli () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100649 msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100650 cp "$CONFIG_H" "$CONFIG_BAK"
651 scripts/config.pl full
652 scripts/config.pl unset MBEDTLS_SSL_CLI_C
653 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100654}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100655
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100656component_build_no_sockets () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100657 # Note, C99 compliance can also be tested with the sockets support disabled,
658 # as that requires a POSIX platform (which isn't the same as C99).
659 msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100660 cp "$CONFIG_H" "$CONFIG_BAK"
661 scripts/config.pl full
662 scripts/config.pl unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
663 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
664 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0 -std=c99 -pedantic' lib
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100665}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100666
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100667component_test_no_max_fragment_length () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100668 msg "build: default config except MFL extension (ASan build)" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100669 cp "$CONFIG_H" "$CONFIG_BAK"
670 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
671 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
672 make
673
674 msg "test: ssl-opt.sh, MFL-related tests"
675 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length"
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100676}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100677
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100678component_test_null_entropy () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100679 msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100680 cp "$CONFIG_H" "$CONFIG_BAK"
681 scripts/config.pl set MBEDTLS_TEST_NULL_ENTROPY
682 scripts/config.pl set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
683 scripts/config.pl set MBEDTLS_ENTROPY_C
684 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
685 scripts/config.pl unset MBEDTLS_ENTROPY_HARDWARE_ALT
686 scripts/config.pl unset MBEDTLS_HAVEGE_C
687 CC=gcc cmake -D UNSAFE_BUILD=ON -D CMAKE_C_FLAGS:String="-fsanitize=address -fno-common -O3" .
688 make
689
690 msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)"
691 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100692}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100693
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100694component_test_platform_calloc_macro () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100695 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100696 cp "$CONFIG_H" "$CONFIG_BAK"
697 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
698 scripts/config.pl set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
699 scripts/config.pl set MBEDTLS_PLATFORM_FREE_MACRO free
700 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
701 make
702
703 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
704 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100705}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100706
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100707component_test_make_shared () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100708 if uname -a | grep -F Linux >/dev/null; then
709 msg "build/test: make shared" # ~ 40s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100710 make SHARED=1 all check
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100711 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000712
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100713}
714
715component_test_m32_o0 () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100716 if uname -a | grep -F x86_64 >/dev/null; then
717 # Build once with -O0, to compile out the i386 specific inline assembly
718 msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100719 cp "$CONFIG_H" "$CONFIG_BAK"
720 scripts/config.pl full
721 make CC=gcc CFLAGS='-O0 -Werror -Wall -Wextra -m32 -fsanitize=address'
722
723 msg "test: i386, make, gcc -O0 (ASan build)"
724 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100725 fi # x86_64
726}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100727
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100728component_test_m32_o1 () {
729 if uname -a | grep -F x86_64 >/dev/null; then
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100730 # Build again with -O1, to compile in the i386 specific inline assembly
731 msg "build: i386, make, gcc -O1 (ASan build)" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100732 cp "$CONFIG_H" "$CONFIG_BAK"
733 scripts/config.pl full
734 make CC=gcc CFLAGS='-O1 -Werror -Wall -Wextra -m32 -fsanitize=address'
735
736 msg "test: i386, make, gcc -O1 (ASan build)"
737 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100738 fi # x86_64
739}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100740
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100741component_test_mx32 () {
742 if uname -a | grep -F x86_64 >/dev/null; then
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100743 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100744 cp "$CONFIG_H" "$CONFIG_BAK"
745 scripts/config.pl full
746 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32'
747
748 msg "test: 64-bit ILP32, make, gcc"
749 make test
750 fi # x86_64
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100751}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100752
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100753component_test_have_int32 () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100754 msg "build: gcc, force 32-bit bignum limbs"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100755 cp "$CONFIG_H" "$CONFIG_BAK"
756 scripts/config.pl unset MBEDTLS_HAVE_ASM
757 scripts/config.pl unset MBEDTLS_AESNI_C
758 scripts/config.pl unset MBEDTLS_PADLOCK_C
759 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
760
761 msg "test: gcc, force 32-bit bignum limbs"
762 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100763}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100764
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100765component_test_have_int64 () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100766 msg "build: gcc, force 64-bit bignum limbs"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100767 cp "$CONFIG_H" "$CONFIG_BAK"
768 scripts/config.pl unset MBEDTLS_HAVE_ASM
769 scripts/config.pl unset MBEDTLS_AESNI_C
770 scripts/config.pl unset MBEDTLS_PADLOCK_C
771 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
772
773 msg "test: gcc, force 64-bit bignum limbs"
774 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100775}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100776
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100777component_build_arm_none_eabi_gcc () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100778 msg "build: arm-none-eabi-gcc, make" # ~ 10s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100779 cp "$CONFIG_H" "$CONFIG_BAK"
780 scripts/config.pl full
781 scripts/config.pl unset MBEDTLS_NET_C
782 scripts/config.pl unset MBEDTLS_TIMING_C
783 scripts/config.pl unset MBEDTLS_FS_IO
784 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
785 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
786 # following things are not in the default config
787 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
788 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
789 scripts/config.pl unset MBEDTLS_THREADING_C
790 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
791 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
792 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 +0100793}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100794
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100795component_build_arm_none_eabi_gcc_no_udbl_division () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100796 msg "build: arm-none-eabi-gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100797 cp "$CONFIG_H" "$CONFIG_BAK"
798 scripts/config.pl full
799 scripts/config.pl unset MBEDTLS_NET_C
800 scripts/config.pl unset MBEDTLS_TIMING_C
801 scripts/config.pl unset MBEDTLS_FS_IO
802 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
803 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
804 # following things are not in the default config
805 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
806 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
807 scripts/config.pl unset MBEDTLS_THREADING_C
808 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
809 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
810 scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
811 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
812 echo "Checking that software 64-bit division is not required"
813 ! grep __aeabi_uldiv library/*.o
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100814}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100815
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100816component_build_armcc () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100817 msg "build: ARM Compiler 5, make"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100818 cp "$CONFIG_H" "$CONFIG_BAK"
819 scripts/config.pl full
820 scripts/config.pl unset MBEDTLS_NET_C
821 scripts/config.pl unset MBEDTLS_TIMING_C
822 scripts/config.pl unset MBEDTLS_FS_IO
823 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
824 scripts/config.pl unset MBEDTLS_HAVE_TIME
825 scripts/config.pl unset MBEDTLS_HAVE_TIME_DATE
826 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
827 # following things are not in the default config
828 scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
829 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
830 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
831 scripts/config.pl unset MBEDTLS_THREADING_C
832 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
833 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
834 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT # depends on MBEDTLS_HAVE_TIME
835
836 if [ $RUN_ARMCC -ne 0 ]; then
837 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
838 make clean
839
840 # ARM Compiler 6 - Target ARMv7-A
841 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-a"
842
843 # ARM Compiler 6 - Target ARMv7-M
844 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m"
845
846 # ARM Compiler 6 - Target ARMv8-A - AArch32
847 armc6_build_test "--target=arm-arm-none-eabi -march=armv8.2-a"
848
849 # ARM Compiler 6 - Target ARMv8-M
850 armc6_build_test "--target=arm-arm-none-eabi -march=armv8-m.main"
851
852 # ARM Compiler 6 - Target ARMv8-A - AArch64
853 armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a"
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100854 fi
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100855}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000856
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100857component_test_allow_sha1 () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100858 msg "build: allow SHA1 in certificates by default"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100859 cp "$CONFIG_H" "$CONFIG_BAK"
860 scripts/config.pl set MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
861 make CFLAGS='-Werror -Wall -Wextra'
862 msg "test: allow SHA1 in certificates by default"
863 make test
864 if_build_succeeded tests/ssl-opt.sh -f SHA-1
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100865}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000866
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100867component_build_mingw () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100868 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100869 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
870
871 # note Make tests only builds the tests, but doesn't run them
872 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror' WINDOWS_BUILD=1 tests
873 make WINDOWS_BUILD=1 clean
874
875 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
876 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
877 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
878 make WINDOWS_BUILD=1 clean
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100879}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100880
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100881component_test_memsan () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100882 # MemSan currently only available on Linux 64 bits
883 if uname -a | grep 'Linux.*x86_64' >/dev/null; then
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100884 msg "build: MSan (clang)" # ~ 1 min 20s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100885 cp "$CONFIG_H" "$CONFIG_BAK"
886 scripts/config.pl unset MBEDTLS_AESNI_C # memsan doesn't grok asm
887 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
888 make
889
890 msg "test: main suites (MSan)" # ~ 10s
891 make test
892
893 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
894 if_build_succeeded tests/ssl-opt.sh
895
896 # Optional part(s)
897
898 if [ "$MEMORY" -gt 0 ]; then
899 msg "test: compat.sh (MSan)" # ~ 6 min 20s
900 if_build_succeeded tests/compat.sh
901 fi
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100902 fi
903}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100904
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100905component_test_memcheck () {
906 # Only run if MemSan is not available
907 if ! uname -a | grep 'Linux.*x86_64' >/dev/null; then
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100908 msg "build: Release (clang)"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100909 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
910 make
911
912 msg "test: main suites valgrind (Release)"
913 make memcheck
914
915 # Optional part(s)
916 # Currently broken, programs don't seem to receive signals
917 # under valgrind on OS X
918
919 if [ "$MEMORY" -gt 0 ]; then
920 msg "test: ssl-opt.sh --memcheck (Release)"
921 if_build_succeeded tests/ssl-opt.sh --memcheck
922 fi
923
924 if [ "$MEMORY" -gt 1 ]; then
925 msg "test: compat.sh --memcheck (Release)"
926 if_build_succeeded tests/compat.sh --memcheck
927 fi
928
929 fi # MemSan
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100930}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100931
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100932component_test_cmake_out_of_source () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100933 msg "build: cmake 'out-of-source' build"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100934 MBEDTLS_ROOT_DIR="$PWD"
935 mkdir "$OUT_OF_SOURCE_DIR"
936 cd "$OUT_OF_SOURCE_DIR"
937 cmake "$MBEDTLS_ROOT_DIR"
938 make
939
940 msg "test: cmake 'out-of-source' build"
941 make test
942 # Test an SSL option that requires an auxiliary script in test/scripts/.
943 # Also ensure that there are no error messages such as
944 # "No such file or directory", which would indicate that some required
945 # file is missing (ssl-opt.sh tolerates the absence of some files so
946 # may exit with status 0 but emit errors).
947 if_build_succeeded ./tests/ssl-opt.sh -f 'Fallback SCSV: beginning of list' 2>ssl-opt.err
948 if [ -s ssl-opt.err ]; then
949 cat ssl-opt.err >&2
950 record_status [ ! -s ssl-opt.err ]
951 rm ssl-opt.err
952 fi
953 cd "$MBEDTLS_ROOT_DIR"
954 rm -rf "$OUT_OF_SOURCE_DIR"
955 unset MBEDTLS_ROOT_DIR
956}
Andres AGdc192212016-08-31 17:33:13 +0100957
Gilles Peskine192c72f2017-12-21 15:59:21 +0100958
959
960################################################################
961#### Termination
962################################################################
963
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100964post_report () {
965 msg "Done, cleaning up"
966 cleanup
967
968 final_report
969}
970
971
972
973################################################################
974#### Run all the things
975################################################################
976
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100977# Run one component and clean up afterwards.
978run_component () {
979 "$@"
980 cleanup
981}
982
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100983# Preliminary setup
984pre_check_environment
985pre_initialize_variables
986pre_parse_command_line "$@"
987
988pre_check_git
989build_status=0
990if [ $KEEP_GOING -eq 1 ]; then
991 pre_setup_keep_going
992else
993 record_status () {
994 "$@"
995 }
996fi
997pre_print_configuration
998pre_check_tools
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100999cleanup
Gilles Peskine7c652162017-12-11 00:01:40 +01001000
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001001# Run all the test components.
1002for component in $ALL_COMPONENTS; do
1003 run_component "component_$component"
1004done
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001005
1006# We're done.
1007post_report