blob: d5c6ddc2a1de7a831d92bd4e3fe254b1517413a2 [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 Peskine91bd8b72019-01-08 23:01:34 +010097 COMPONENTS=
Gilles Peskine57db6ff2019-01-08 22:04:31 +010098 MEMORY=0
99 FORCE=0
100 KEEP_GOING=0
101 RUN_ARMCC=1
102 YOTTA=1
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100103
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100104 # Default commands, can be overriden by the environment
105 : ${OPENSSL:="openssl"}
106 : ${OPENSSL_LEGACY:="$OPENSSL"}
107 : ${GNUTLS_CLI:="gnutls-cli"}
108 : ${GNUTLS_SERV:="gnutls-serv"}
109 : ${GNUTLS_LEGACY_CLI:="$GNUTLS_CLI"}
110 : ${GNUTLS_LEGACY_SERV:="$GNUTLS_SERV"}
111 : ${OUT_OF_SOURCE_DIR:=./mbedtls_out_of_source_build}
112 : ${ARMC5_BIN_DIR:=/usr/bin}
113 : ${ARMC6_BIN_DIR:=/usr/bin}
Andres AGdc192212016-08-31 17:33:13 +0100114
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100115 # if MAKEFLAGS is not set add the -j option to speed up invocations of make
116 if [ -n "${MAKEFLAGS+set}" ]; then
117 export MAKEFLAGS="-j"
118 fi
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100119
120 # Gather the list of available components. These are the functions
121 # defined in this script whose name starts with "component_".
122 # Parse the script with sed, because in sh there is no way to list
123 # defined functions.
124 ALL_COMPONENTS=$(sed -n 's/^ *component_\([0-9A-Z_a-z]*\) *().*/\1/p' <"$0")
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100125}
Andres AG38495a32016-07-12 16:54:33 +0100126
Simon Butcher41eeccf2016-09-07 00:07:09 +0100127usage()
SimonB2e23c822016-04-16 21:54:39 +0100128{
Gilles Peskine709346a2017-12-10 23:43:39 +0100129 cat <<EOF
Gilles Peskine91bd8b72019-01-08 23:01:34 +0100130Usage: $0 [OPTION]... [COMPONENT]...
131Run mbedtls release validation tests.
132By default, run all tests. With one or more COMPONENT, run only those.
133
134Special options:
135 -h|--help Print this help and exit.
Gilles Peskine709346a2017-12-10 23:43:39 +0100136
137General options:
138 -f|--force Force the tests to overwrite any modified files.
Gilles Peskine7c652162017-12-11 00:01:40 +0100139 -k|--keep-going Run all tests and report errors at the end.
Gilles Peskine709346a2017-12-10 23:43:39 +0100140 -m|--memory Additional optional memory tests.
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100141 --armcc Run ARM Compiler builds (on by default).
142 --no-armcc Skip ARM Compiler builds.
Gilles Peskine19ceb712018-03-21 08:40:26 +0100143 --no-force Refuse to overwrite modified files (default).
144 --no-keep-going Stop at the first error (default).
145 --no-memory No additional memory tests (default).
Gilles Peskine2a22a802017-12-21 15:19:00 +0100146 --no-yotta Skip yotta module build.
Gilles Peskine709346a2017-12-10 23:43:39 +0100147 --out-of-source-dir=<path> Directory used for CMake out-of-source build tests.
Gilles Peskine19ceb712018-03-21 08:40:26 +0100148 --random-seed Use a random seed value for randomized tests (default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100149 -r|--release-test Run this script in release mode. This fixes the seed value to 1.
150 -s|--seed Integer seed value to use for this test run.
Gilles Peskine2a22a802017-12-21 15:19:00 +0100151 --yotta Build yotta module (on by default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100152
153Tool path options:
154 --armc5-bin-dir=<ARMC5_bin_dir_path> ARM Compiler 5 bin directory.
155 --armc6-bin-dir=<ARMC6_bin_dir_path> ARM Compiler 6 bin directory.
156 --gnutls-cli=<GnuTLS_cli_path> GnuTLS client executable to use for most tests.
157 --gnutls-serv=<GnuTLS_serv_path> GnuTLS server executable to use for most tests.
158 --gnutls-legacy-cli=<GnuTLS_cli_path> GnuTLS client executable to use for legacy tests.
159 --gnutls-legacy-serv=<GnuTLS_serv_path> GnuTLS server executable to use for legacy tests.
160 --openssl=<OpenSSL_path> OpenSSL executable to use for most tests.
161 --openssl-legacy=<OpenSSL_path> OpenSSL executable to use for legacy tests e.g. SSLv3.
162EOF
SimonB2e23c822016-04-16 21:54:39 +0100163}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100164
165# remove built files as well as the cmake cache/config
166cleanup()
167{
Gilles Peskinea71d64c2018-03-21 12:16:57 +0100168 if [ -n "${MBEDTLS_ROOT_DIR+set}" ]; then
169 cd "$MBEDTLS_ROOT_DIR"
170 fi
171
Gilles Peskine7c652162017-12-11 00:01:40 +0100172 command make clean
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200173
Gilles Peskine31b07e22018-03-21 12:15:06 +0100174 # Remove CMake artefacts
175 find . -name .git -prune -o -name yotta -prune -o \
176 -iname CMakeFiles -exec rm -rf {} \+ -o \
177 \( -iname cmake_install.cmake -o \
178 -iname CTestTestfile.cmake -o \
179 -iname CMakeCache.txt \) -exec rm {} \+
180 # Recover files overwritten by in-tree CMake builds
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000181 rm -f include/Makefile include/mbedtls/Makefile programs/*/Makefile
Paul Bakkerfe0984d2014-06-13 00:13:45 +0200182 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile
183 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200184
185 if [ -f "$CONFIG_BAK" ]; then
186 mv "$CONFIG_BAK" "$CONFIG_H"
187 fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100188}
189
Gilles Peskine7c652162017-12-11 00:01:40 +0100190# Executed on exit. May be redefined depending on command line options.
191final_report () {
192 :
193}
194
195fatal_signal () {
196 cleanup
197 final_report $1
198 trap - $1
199 kill -$1 $$
200}
201
202trap 'fatal_signal HUP' HUP
203trap 'fatal_signal INT' INT
204trap 'fatal_signal TERM' TERM
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200205
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100206msg()
207{
208 echo ""
209 echo "******************************************************************"
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100210 echo "* $1 "
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000211 printf "* "; date
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100212 echo "******************************************************************"
Gilles Peskine7c652162017-12-11 00:01:40 +0100213 current_section=$1
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100214}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100215
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100216armc6_build_test()
217{
218 FLAGS="$1"
Andres AGa5cd9732016-10-17 15:23:10 +0100219
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100220 msg "build: ARM Compiler 6 ($FLAGS), make"
221 ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \
222 WARNING_CFLAGS='-xc -std=c99' make lib
223 make clean
224}
Andres AGa5cd9732016-10-17 15:23:10 +0100225
Andres AGd9eba4b2016-08-26 14:42:14 +0100226err_msg()
227{
228 echo "$1" >&2
229}
230
231check_tools()
232{
233 for TOOL in "$@"; do
Andres AG98393602017-01-31 17:04:45 +0000234 if ! `type "$TOOL" >/dev/null 2>&1`; then
Andres AGd9eba4b2016-08-26 14:42:14 +0100235 err_msg "$TOOL not found!"
236 exit 1
237 fi
238 done
239}
240
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100241pre_parse_command_line () {
242 while [ $# -gt 0 ]; do
243 case "$1" in
244 --armcc) RUN_ARMCC=1;;
245 --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
246 --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
247 --force|-f) FORCE=1;;
248 --gnutls-cli) shift; GNUTLS_CLI="$1";;
249 --gnutls-legacy-cli) shift; GNUTLS_LEGACY_CLI="$1";;
250 --gnutls-legacy-serv) shift; GNUTLS_LEGACY_SERV="$1";;
251 --gnutls-serv) shift; GNUTLS_SERV="$1";;
252 --help|-h) usage; exit;;
253 --keep-going|-k) KEEP_GOING=1;;
254 --memory|-m) MEMORY=1;;
255 --no-armcc) RUN_ARMCC=0;;
256 --no-force) FORCE=0;;
257 --no-keep-going) KEEP_GOING=0;;
258 --no-memory) MEMORY=0;;
259 --no-yotta) YOTTA=0;;
260 --openssl) shift; OPENSSL="$1";;
261 --openssl-legacy) shift; OPENSSL_LEGACY="$1";;
262 --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
263 --random-seed) unset SEED;;
264 --release-test|-r) SEED=1;;
265 --seed|-s) shift; SEED="$1";;
266 --yotta) YOTTA=1;;
Gilles Peskine91bd8b72019-01-08 23:01:34 +0100267 -*)
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100268 echo >&2 "Unknown option: $1"
269 echo >&2 "Run $0 --help for usage."
270 exit 120
271 ;;
Gilles Peskine91bd8b72019-01-08 23:01:34 +0100272 *)
273 COMPONENTS="$COMPONENTS $1";;
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100274 esac
275 shift
276 done
Gilles Peskine91bd8b72019-01-08 23:01:34 +0100277
278 if [ -z "$COMPONENTS" ]; then
279 COMPONENTS="$ALL_COMPONENTS"
280 fi
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100281}
SimonB2e23c822016-04-16 21:54:39 +0100282
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100283pre_check_git () {
284 if [ $FORCE -eq 1 ]; then
285 if [ $YOTTA -eq 1 ]; then
286 rm -rf yotta/module "$OUT_OF_SOURCE_DIR"
287 fi
288 git checkout-index -f -q $CONFIG_H
289 cleanup
290 else
291
292 if [ $YOTTA -ne 0 ] && [ -d yotta/module ]; then
293 err_msg "Warning - there is an existing yotta module in the directory 'yotta/module'"
294 echo "You can either delete your work and retry, or force the test to overwrite the"
295 echo "test by rerunning the script as: $0 --force"
296 exit 1
297 fi
298
299 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
300 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
301 echo "You can either delete this directory manually, or force the test by rerunning"
302 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
303 exit 1
304 fi
305
306 if ! git diff-files --quiet include/mbedtls/config.h; then
307 err_msg "Warning - the configuration file 'include/mbedtls/config.h' has been edited. "
308 echo "You can either delete or preserve your work, or force the test by rerunning the"
309 echo "script as: $0 --force"
310 exit 1
311 fi
Gilles Peskineda519252017-11-30 13:22:04 +0100312 fi
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100313}
SimonB2e23c822016-04-16 21:54:39 +0100314
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100315pre_setup_keep_going () {
Gilles Peskine7c652162017-12-11 00:01:40 +0100316 failure_summary=
317 failure_count=0
318 start_red=
319 end_color=
320 if [ -t 1 ]; then
Gilles Peskine9736b9d2018-01-02 21:54:17 +0100321 case "${TERM:-}" in
Gilles Peskine7c652162017-12-11 00:01:40 +0100322 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
323 start_red=$(printf '\033[31m')
324 end_color=$(printf '\033[0m')
325 ;;
326 esac
327 fi
328 record_status () {
329 if "$@"; then
330 last_status=0
331 else
332 last_status=$?
333 text="$current_section: $* -> $last_status"
334 failure_summary="$failure_summary
335$text"
336 failure_count=$((failure_count + 1))
337 echo "${start_red}^^^^$text^^^^${end_color}"
338 fi
339 }
340 make () {
341 case "$*" in
342 *test|*check)
343 if [ $build_status -eq 0 ]; then
344 record_status command make "$@"
345 else
346 echo "(skipped because the build failed)"
347 fi
348 ;;
349 *)
350 record_status command make "$@"
351 build_status=$last_status
352 ;;
353 esac
354 }
355 final_report () {
356 if [ $failure_count -gt 0 ]; then
357 echo
358 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
359 echo "${start_red}FAILED: $failure_count${end_color}$failure_summary"
360 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Jaeden Amero5113bde2018-07-20 16:42:14 +0100361 exit 1
Gilles Peskine7c652162017-12-11 00:01:40 +0100362 elif [ -z "${1-}" ]; then
363 echo "SUCCESS :)"
364 fi
365 if [ -n "${1-}" ]; then
366 echo "Killed by SIG$1."
367 fi
368 }
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100369}
370
Gilles Peskine7c652162017-12-11 00:01:40 +0100371if_build_succeeded () {
372 if [ $build_status -eq 0 ]; then
373 record_status "$@"
374 fi
375}
376
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100377pre_print_configuration () {
378 msg "info: $0 configuration"
379 echo "MEMORY: $MEMORY"
380 echo "FORCE: $FORCE"
381 echo "SEED: ${SEED-"UNSET"}"
382 echo "OPENSSL: $OPENSSL"
383 echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
384 echo "GNUTLS_CLI: $GNUTLS_CLI"
385 echo "GNUTLS_SERV: $GNUTLS_SERV"
386 echo "GNUTLS_LEGACY_CLI: $GNUTLS_LEGACY_CLI"
387 echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV"
388 echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
389 echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
390}
Andres AG7770ea82016-10-10 15:46:20 +0100391
Andres AGd9eba4b2016-08-26 14:42:14 +0100392# Make sure the tools we need are available.
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100393pre_check_tools () {
394 ARMC5_CC="$ARMC5_BIN_DIR/armcc"
395 ARMC5_AR="$ARMC5_BIN_DIR/armar"
396 ARMC6_CC="$ARMC6_BIN_DIR/armclang"
397 ARMC6_AR="$ARMC6_BIN_DIR/armar"
398
399 # To avoid setting OpenSSL and GnuTLS for each call to compat.sh and ssl-opt.sh
400 # we just export the variables they require
401 export OPENSSL_CMD="$OPENSSL"
402 export GNUTLS_CLI="$GNUTLS_CLI"
403 export GNUTLS_SERV="$GNUTLS_SERV"
404
405 # Avoid passing --seed flag in every call to ssl-opt.sh
406 if [ -n "${SEED-}" ]; then
407 export SEED
408 fi
409
410 check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$GNUTLS_CLI" "$GNUTLS_SERV" \
411 "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV" "doxygen" "dot" \
412 "arm-none-eabi-gcc" "i686-w64-mingw32-gcc"
413 if [ $RUN_ARMCC -ne 0 ]; then
414 check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC6_CC" "$ARMC6_AR"
415 fi
416
417 msg "info: output_env.sh"
418 OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY" GNUTLS_CLI="$GNUTLS_CLI" \
419 GNUTLS_SERV="$GNUTLS_SERV" GNUTLS_LEGACY_CLI="$GNUTLS_LEGACY_CLI" \
420 GNUTLS_LEGACY_SERV="$GNUTLS_LEGACY_SERV" ARMC5_CC="$ARMC5_CC" \
421 ARMC6_CC="$ARMC6_CC" RUN_ARMCC="$RUN_ARMCC" scripts/output_env.sh
422}
Andres AGd9eba4b2016-08-26 14:42:14 +0100423
Gilles Peskine192c72f2017-12-21 15:59:21 +0100424
425
426################################################################
427#### Basic checks
428################################################################
SimonB2e23c822016-04-16 21:54:39 +0100429
430#
431# Test Suites to be executed
432#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200433# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100434# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard61bc57a2014-08-14 11:29:06 +0200435# and/or are more likely to fail than others (eg I use Clang most of the
436# time, so start with a GCC build).
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200437# 2. Minimize total running time, by avoiding useless rebuilds
438#
439# Indicative running times are given for reference.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100440
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100441component_check_recursion () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100442 msg "test: recursion.pl" # < 1s
443 record_status tests/scripts/recursion.pl library/*.c
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100444}
Manuel Pégourié-Gonnardea29d152014-11-20 17:32:33 +0100445
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100446component_check_generated_files () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100447 msg "test: freshness of generated source files" # < 1s
448 record_status tests/scripts/check-generated-files.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100449}
Manuel Pégourié-Gonnardb3b8e432015-02-13 14:52:19 +0000450
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100451component_check_doxy_blocks () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100452 msg "test: doxygen markup outside doxygen blocks" # < 1s
453 record_status tests/scripts/check-doxy-blocks.pl
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100454}
Manuel Pégourié-Gonnardd09a6b52015-04-09 17:19:23 +0200455
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100456component_check_files () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100457 msg "test: check-files.py" # < 1s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100458 record_status tests/scripts/check-files.py
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100459}
Manuel Pégourié-Gonnard77d56bb2015-07-28 15:00:37 +0200460
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100461component_check_names () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100462 msg "test/build: declared and exported names" # < 3s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100463 record_status tests/scripts/check-names.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100464}
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +0200465
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100466component_check_doxygen_warnings () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100467 msg "test: doxygen warnings" # ~ 3s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100468 record_status tests/scripts/doxygen.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100469}
Andres Amaya Garciadd29c2f2017-05-04 11:35:51 +0100470
Simon Butcher948f2642018-07-20 21:27:33 +0100471
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100472################################################################
473#### Build and test many configurations and targets
474################################################################
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100475
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100476component_build_yotta () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100477 if [ $RUN_ARMCC -ne 0 ] && [ $YOTTA -ne 0 ]; then
478 # Note - use of yotta is deprecated, and yotta also requires armcc to be on the
479 # path, and uses whatever version of armcc it finds there.
480 msg "build: create and build yotta module" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100481 record_status tests/scripts/yotta-build.sh
482 fi
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100483}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100484
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100485component_test_default_cmake_gcc_asan () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100486 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100487 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100488 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +0200489
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100490 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100491 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100492
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100493 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
Gilles Peskine7c652162017-12-11 00:01:40 +0100494 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100495
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100496 msg "test: compat.sh (ASan build)" # ~ 6 min
497 if_build_succeeded tests/compat.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100498}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000499
Gilles Peskine3484ed82019-01-08 22:51:19 +0100500component_test_ref_configs () {
501 msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
502 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
503 record_status tests/scripts/test-ref-configs.pl
504}
505
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100506component_test_sslv3 () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100507 msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100508 cp "$CONFIG_H" "$CONFIG_BAK"
509 scripts/config.pl set MBEDTLS_SSL_PROTO_SSL3
510 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
511 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000512
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100513 msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
514 make test
515
516 msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
517 if_build_succeeded tests/compat.sh -m 'tls1 tls1_1 tls1_2 dtls1 dtls1_2'
518 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
519
520 msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
521 if_build_succeeded tests/ssl-opt.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100522}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100523
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100524component_test_no_renegotiation () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100525 msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100526 cp "$CONFIG_H" "$CONFIG_BAK"
527 scripts/config.pl unset MBEDTLS_SSL_RENEGOTIATION
528 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
529 make
530
531 msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
532 make test
533
534 msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
535 if_build_succeeded tests/ssl-opt.sh
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100536}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100537
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100538component_test_rsa_no_crt () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100539 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100540 cp "$CONFIG_H" "$CONFIG_BAK"
541 scripts/config.pl set MBEDTLS_RSA_NO_CRT
542 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
543 make
544
545 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
546 make test
547
548 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
549 if_build_succeeded tests/ssl-opt.sh -f RSA
550
551 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
552 if_build_succeeded tests/compat.sh -t RSA
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100553}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100554
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100555component_test_full_cmake_clang () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100556 msg "build: cmake, full config, clang" # ~ 50s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100557 cp "$CONFIG_H" "$CONFIG_BAK"
558 scripts/config.pl full
559 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
560 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check -D ENABLE_TESTING=On .
561 make
562
563 msg "test: main suites (full config)" # ~ 5s
564 make test
565
566 msg "test: ssl-opt.sh default (full config)" # ~ 1s
567 if_build_succeeded tests/ssl-opt.sh -f Default
568
569 msg "test: compat.sh RC4, DES & NULL (full config)" # ~ 2 min
570 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 +0100571}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100572
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100573component_build_deprecated () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100574 msg "build: make, full config + DEPRECATED_WARNING, gcc -O" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100575 cp "$CONFIG_H" "$CONFIG_BAK"
576 scripts/config.pl full
577 scripts/config.pl set MBEDTLS_DEPRECATED_WARNING
578 # Build with -O -Wextra to catch a maximum of issues.
579 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra' lib programs
580 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
581
582 msg "build: make, full config + DEPRECATED_REMOVED, clang -O" # ~ 30s
583 # No cleanup, just tweak the configuration and rebuild
584 make clean
585 scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
586 scripts/config.pl set MBEDTLS_DEPRECATED_REMOVED
587 # Build with -O -Wextra to catch a maximum of issues.
588 make CC=clang CFLAGS='-O -Werror -Wall -Wextra' lib programs
589 make CC=clang CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100590}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100591
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100592component_test_depends_curves () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100593 msg "test/build: curves.pl (gcc)" # ~ 4 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100594 record_status tests/scripts/curves.pl
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100595}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100596
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100597component_test_depends_hashes () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100598 msg "test/build: depends-hashes.pl (gcc)" # ~ 2 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100599 record_status tests/scripts/depends-hashes.pl
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_depends_pkalgs () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100603 msg "test/build: depends-pkalgs.pl (gcc)" # ~ 2 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100604 record_status tests/scripts/depends-pkalgs.pl
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100605}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100606
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100607component_build_key_exchanges () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100608 msg "test/build: key-exchanges (gcc)" # ~ 1 min
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100609 record_status tests/scripts/key-exchanges.pl
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100610}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100611
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100612component_build_default_make_gcc () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100613 msg "build: Unix make, -Os (gcc)" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100614 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100615}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100616
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100617component_test_no_platform () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100618 # Full configuration build, without platform support, file IO and net sockets.
619 # This should catch missing mbedtls_printf definitions, and by disabling file
620 # IO, it should catch missing '#include <stdio.h>'
621 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100622 cp "$CONFIG_H" "$CONFIG_BAK"
623 scripts/config.pl full
624 scripts/config.pl unset MBEDTLS_PLATFORM_C
625 scripts/config.pl unset MBEDTLS_NET_C
626 scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
627 scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
628 scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
629 scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
630 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
631 scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
632 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
633 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
634 scripts/config.pl unset MBEDTLS_FS_IO
635 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
636 # to re-enable platform integration features otherwise disabled in C99 builds
637 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -O0 -D_DEFAULT_SOURCE' lib programs
638 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0' test
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100639}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100640
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100641component_build_no_std_function () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100642 # catch compile bugs in _uninit functions
643 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100644 cp "$CONFIG_H" "$CONFIG_BAK"
645 scripts/config.pl full
646 scripts/config.pl set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
647 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
648 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100649}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100650
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100651component_build_no_ssl_srv () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100652 msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100653 cp "$CONFIG_H" "$CONFIG_BAK"
654 scripts/config.pl full
655 scripts/config.pl unset MBEDTLS_SSL_SRV_C
656 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100657}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100658
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100659component_build_no_ssl_cli () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100660 msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100661 cp "$CONFIG_H" "$CONFIG_BAK"
662 scripts/config.pl full
663 scripts/config.pl unset MBEDTLS_SSL_CLI_C
664 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100665}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100666
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100667component_build_no_sockets () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100668 # Note, C99 compliance can also be tested with the sockets support disabled,
669 # as that requires a POSIX platform (which isn't the same as C99).
670 msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100671 cp "$CONFIG_H" "$CONFIG_BAK"
672 scripts/config.pl full
673 scripts/config.pl unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
674 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
675 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0 -std=c99 -pedantic' lib
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_no_max_fragment_length () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100679 msg "build: default config except MFL extension (ASan build)" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100680 cp "$CONFIG_H" "$CONFIG_BAK"
681 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
682 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
683 make
684
685 msg "test: ssl-opt.sh, MFL-related tests"
686 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length"
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100687}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100688
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100689component_test_null_entropy () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100690 msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100691 cp "$CONFIG_H" "$CONFIG_BAK"
692 scripts/config.pl set MBEDTLS_TEST_NULL_ENTROPY
693 scripts/config.pl set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
694 scripts/config.pl set MBEDTLS_ENTROPY_C
695 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
696 scripts/config.pl unset MBEDTLS_ENTROPY_HARDWARE_ALT
697 scripts/config.pl unset MBEDTLS_HAVEGE_C
698 CC=gcc cmake -D UNSAFE_BUILD=ON -D CMAKE_C_FLAGS:String="-fsanitize=address -fno-common -O3" .
699 make
700
701 msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)"
702 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100703}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100704
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100705component_test_platform_calloc_macro () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100706 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100707 cp "$CONFIG_H" "$CONFIG_BAK"
708 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
709 scripts/config.pl set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
710 scripts/config.pl set MBEDTLS_PLATFORM_FREE_MACRO free
711 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
712 make
713
714 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
715 make test
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_make_shared () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100719 if uname -a | grep -F Linux >/dev/null; then
720 msg "build/test: make shared" # ~ 40s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100721 make SHARED=1 all check
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100722 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000723
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100724}
725
726component_test_m32_o0 () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100727 if uname -a | grep -F x86_64 >/dev/null; then
728 # Build once with -O0, to compile out the i386 specific inline assembly
729 msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100730 cp "$CONFIG_H" "$CONFIG_BAK"
731 scripts/config.pl full
732 make CC=gcc CFLAGS='-O0 -Werror -Wall -Wextra -m32 -fsanitize=address'
733
734 msg "test: i386, make, gcc -O0 (ASan build)"
735 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100736 fi # x86_64
737}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100738
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100739component_test_m32_o1 () {
740 if uname -a | grep -F x86_64 >/dev/null; then
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100741 # Build again with -O1, to compile in the i386 specific inline assembly
742 msg "build: i386, make, gcc -O1 (ASan build)" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100743 cp "$CONFIG_H" "$CONFIG_BAK"
744 scripts/config.pl full
745 make CC=gcc CFLAGS='-O1 -Werror -Wall -Wextra -m32 -fsanitize=address'
746
747 msg "test: i386, make, gcc -O1 (ASan build)"
748 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100749 fi # x86_64
750}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100751
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100752component_test_mx32 () {
753 if uname -a | grep -F x86_64 >/dev/null; then
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100754 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100755 cp "$CONFIG_H" "$CONFIG_BAK"
756 scripts/config.pl full
757 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32'
758
759 msg "test: 64-bit ILP32, make, gcc"
760 make test
761 fi # x86_64
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100762}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100763
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100764component_test_have_int32 () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100765 msg "build: gcc, force 32-bit bignum limbs"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100766 cp "$CONFIG_H" "$CONFIG_BAK"
767 scripts/config.pl unset MBEDTLS_HAVE_ASM
768 scripts/config.pl unset MBEDTLS_AESNI_C
769 scripts/config.pl unset MBEDTLS_PADLOCK_C
770 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
771
772 msg "test: gcc, force 32-bit bignum limbs"
773 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100774}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100775
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100776component_test_have_int64 () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100777 msg "build: gcc, force 64-bit bignum limbs"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100778 cp "$CONFIG_H" "$CONFIG_BAK"
779 scripts/config.pl unset MBEDTLS_HAVE_ASM
780 scripts/config.pl unset MBEDTLS_AESNI_C
781 scripts/config.pl unset MBEDTLS_PADLOCK_C
782 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
783
784 msg "test: gcc, force 64-bit bignum limbs"
785 make test
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100786}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100787
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100788component_build_arm_none_eabi_gcc () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100789 msg "build: arm-none-eabi-gcc, make" # ~ 10s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100790 cp "$CONFIG_H" "$CONFIG_BAK"
791 scripts/config.pl full
792 scripts/config.pl unset MBEDTLS_NET_C
793 scripts/config.pl unset MBEDTLS_TIMING_C
794 scripts/config.pl unset MBEDTLS_FS_IO
795 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
796 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
797 # following things are not in the default config
798 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
799 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
800 scripts/config.pl unset MBEDTLS_THREADING_C
801 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
802 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
803 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 +0100804}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100805
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100806component_build_arm_none_eabi_gcc_no_udbl_division () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100807 msg "build: arm-none-eabi-gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100808 cp "$CONFIG_H" "$CONFIG_BAK"
809 scripts/config.pl full
810 scripts/config.pl unset MBEDTLS_NET_C
811 scripts/config.pl unset MBEDTLS_TIMING_C
812 scripts/config.pl unset MBEDTLS_FS_IO
813 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
814 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
815 # following things are not in the default config
816 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
817 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
818 scripts/config.pl unset MBEDTLS_THREADING_C
819 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
820 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
821 scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
822 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
823 echo "Checking that software 64-bit division is not required"
824 ! grep __aeabi_uldiv library/*.o
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100825}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100826
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100827component_build_armcc () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100828 msg "build: ARM Compiler 5, make"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100829 cp "$CONFIG_H" "$CONFIG_BAK"
830 scripts/config.pl full
831 scripts/config.pl unset MBEDTLS_NET_C
832 scripts/config.pl unset MBEDTLS_TIMING_C
833 scripts/config.pl unset MBEDTLS_FS_IO
834 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
835 scripts/config.pl unset MBEDTLS_HAVE_TIME
836 scripts/config.pl unset MBEDTLS_HAVE_TIME_DATE
837 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
838 # following things are not in the default config
839 scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
840 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
841 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
842 scripts/config.pl unset MBEDTLS_THREADING_C
843 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
844 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
845 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT # depends on MBEDTLS_HAVE_TIME
846
847 if [ $RUN_ARMCC -ne 0 ]; then
848 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
849 make clean
850
851 # ARM Compiler 6 - Target ARMv7-A
852 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-a"
853
854 # ARM Compiler 6 - Target ARMv7-M
855 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m"
856
857 # ARM Compiler 6 - Target ARMv8-A - AArch32
858 armc6_build_test "--target=arm-arm-none-eabi -march=armv8.2-a"
859
860 # ARM Compiler 6 - Target ARMv8-M
861 armc6_build_test "--target=arm-arm-none-eabi -march=armv8-m.main"
862
863 # ARM Compiler 6 - Target ARMv8-A - AArch64
864 armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a"
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100865 fi
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100866}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000867
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100868component_test_allow_sha1 () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100869 msg "build: allow SHA1 in certificates by default"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100870 cp "$CONFIG_H" "$CONFIG_BAK"
871 scripts/config.pl set MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
872 make CFLAGS='-Werror -Wall -Wextra'
873 msg "test: allow SHA1 in certificates by default"
874 make test
875 if_build_succeeded tests/ssl-opt.sh -f SHA-1
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100876}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000877
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100878component_build_mingw () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100879 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100880 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
881
882 # note Make tests only builds the tests, but doesn't run them
883 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror' WINDOWS_BUILD=1 tests
884 make WINDOWS_BUILD=1 clean
885
886 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
887 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
888 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
889 make WINDOWS_BUILD=1 clean
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100890}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100891
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100892component_test_memsan () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100893 # MemSan currently only available on Linux 64 bits
894 if uname -a | grep 'Linux.*x86_64' >/dev/null; then
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100895 msg "build: MSan (clang)" # ~ 1 min 20s
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100896 cp "$CONFIG_H" "$CONFIG_BAK"
897 scripts/config.pl unset MBEDTLS_AESNI_C # memsan doesn't grok asm
898 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
899 make
900
901 msg "test: main suites (MSan)" # ~ 10s
902 make test
903
904 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
905 if_build_succeeded tests/ssl-opt.sh
906
907 # Optional part(s)
908
909 if [ "$MEMORY" -gt 0 ]; then
910 msg "test: compat.sh (MSan)" # ~ 6 min 20s
911 if_build_succeeded tests/compat.sh
912 fi
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100913 fi
914}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100915
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100916component_test_memcheck () {
917 # Only run if MemSan is not available
918 if ! uname -a | grep 'Linux.*x86_64' >/dev/null; then
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100919 msg "build: Release (clang)"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100920 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
921 make
922
923 msg "test: main suites valgrind (Release)"
924 make memcheck
925
926 # Optional part(s)
927 # Currently broken, programs don't seem to receive signals
928 # under valgrind on OS X
929
930 if [ "$MEMORY" -gt 0 ]; then
931 msg "test: ssl-opt.sh --memcheck (Release)"
932 if_build_succeeded tests/ssl-opt.sh --memcheck
933 fi
934
935 if [ "$MEMORY" -gt 1 ]; then
936 msg "test: compat.sh --memcheck (Release)"
937 if_build_succeeded tests/compat.sh --memcheck
938 fi
939
940 fi # MemSan
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100941}
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100942
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100943component_test_cmake_out_of_source () {
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100944 msg "build: cmake 'out-of-source' build"
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100945 MBEDTLS_ROOT_DIR="$PWD"
946 mkdir "$OUT_OF_SOURCE_DIR"
947 cd "$OUT_OF_SOURCE_DIR"
948 cmake "$MBEDTLS_ROOT_DIR"
949 make
950
951 msg "test: cmake 'out-of-source' build"
952 make test
953 # Test an SSL option that requires an auxiliary script in test/scripts/.
954 # Also ensure that there are no error messages such as
955 # "No such file or directory", which would indicate that some required
956 # file is missing (ssl-opt.sh tolerates the absence of some files so
957 # may exit with status 0 but emit errors).
958 if_build_succeeded ./tests/ssl-opt.sh -f 'Fallback SCSV: beginning of list' 2>ssl-opt.err
959 if [ -s ssl-opt.err ]; then
960 cat ssl-opt.err >&2
961 record_status [ ! -s ssl-opt.err ]
962 rm ssl-opt.err
963 fi
964 cd "$MBEDTLS_ROOT_DIR"
965 rm -rf "$OUT_OF_SOURCE_DIR"
966 unset MBEDTLS_ROOT_DIR
967}
Andres AGdc192212016-08-31 17:33:13 +0100968
Gilles Peskine192c72f2017-12-21 15:59:21 +0100969
970
971################################################################
972#### Termination
973################################################################
974
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100975post_report () {
976 msg "Done, cleaning up"
977 cleanup
978
979 final_report
980}
981
982
983
984################################################################
985#### Run all the things
986################################################################
987
Gilles Peskine1a2ca722019-01-08 22:35:16 +0100988# Run one component and clean up afterwards.
989run_component () {
990 "$@"
991 cleanup
992}
993
Gilles Peskine57db6ff2019-01-08 22:04:31 +0100994# Preliminary setup
995pre_check_environment
996pre_initialize_variables
997pre_parse_command_line "$@"
998
999pre_check_git
1000build_status=0
1001if [ $KEEP_GOING -eq 1 ]; then
1002 pre_setup_keep_going
1003else
1004 record_status () {
1005 "$@"
1006 }
1007fi
1008pre_print_configuration
1009pre_check_tools
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001010cleanup
Gilles Peskine7c652162017-12-11 00:01:40 +01001011
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001012# Run all the test components.
Gilles Peskine91bd8b72019-01-08 23:01:34 +01001013for component in $COMPONENTS; do
Gilles Peskine1a2ca722019-01-08 22:35:16 +01001014 run_component "component_$component"
1015done
Gilles Peskine57db6ff2019-01-08 22:04:31 +01001016
1017# We're done.
1018post_report