blob: 8faa441fe2772d9bb3a741780681d534af237ca8 [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)
Andrzej Kurek05be06c2018-06-28 04:41:50 -040038# * G++
Gilles Peskine192c72f2017-12-21 15:59:21 +010039# * arm-gcc and mingw-gcc
40# * ArmCC 5 and ArmCC 6, unless invoked with --no-armcc
Gilles Peskine192c72f2017-12-21 15:59:21 +010041# * 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#
Gilles Peskine8f073122018-11-27 15:58:47 +010058# The bulk of the code is organized into functions that follow one of the
59# following naming conventions:
60# * pre_XXX: things to do before running the tests, in order.
61# * component_XXX: independent components. They can be run in any order.
62# * component_check_XXX: quick tests that aren't worth parallelizing
63# * component_build_XXX: build things but don't run them
64# * component_test_XXX: build and test
Gilles Peskine10726102019-01-06 20:50:38 +000065# * support_XXX: if support_XXX exists and returns false then
66# component_XXX is not run by default.
Gilles Peskine8f073122018-11-27 15:58:47 +010067# * post_XXX: things to do after running the tests.
68# * other: miscellaneous support functions.
69#
Gilles Peskine192c72f2017-12-21 15:59:21 +010070# The tests are roughly in order from fastest to slowest. This doesn't
71# have to be exact, but in general you should add slower tests towards
72# the end and fast checks near the beginning.
73#
74# Sanity checks have the following form:
75# 1. msg "short description of what is about to be done"
76# 2. run sanity check (failure stops the script)
77#
78# Build or build-and-test steps have the following form:
79# 1. msg "short description of what is about to be done"
80# 2. cleanup
81# 3. preparation (config.pl, cmake, ...) (failure stops the script)
82# 4. make
83# 5. Run tests if relevant. All tests must be prefixed with
84# if_build_successful for the sake of --keep-going.
85
86
87
88################################################################
89#### Initialization and command line parsing
90################################################################
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010091
SimonB2e23c822016-04-16 21:54:39 +010092# Abort on errors (and uninitialised variables)
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010093set -eu
94
Gilles Peskine8f073122018-11-27 15:58:47 +010095pre_check_environment () {
Gilles Peskinebdf3f522019-01-06 19:58:02 +000096 if [ -d library -a -d include -a -d tests ]; then :; else
Gilles Peskine8f073122018-11-27 15:58:47 +010097 echo "Must be run from mbed TLS root" >&2
98 exit 1
99 fi
100}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100101
Gilles Peskine8f073122018-11-27 15:58:47 +0100102pre_initialize_variables () {
103 CONFIG_H='include/mbedtls/config.h'
104 CONFIG_BAK="$CONFIG_H.bak"
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200105
Gilles Peskine92525112018-11-27 18:15:35 +0100106 COMPONENTS=
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100107 ALL_EXCEPT=0
Gilles Peskine8f073122018-11-27 15:58:47 +0100108 MEMORY=0
109 FORCE=0
110 KEEP_GOING=0
111 RUN_ARMCC=1
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100112
Gilles Peskine8f073122018-11-27 15:58:47 +0100113 # Default commands, can be overriden by the environment
114 : ${OPENSSL:="openssl"}
115 : ${OPENSSL_LEGACY:="$OPENSSL"}
116 : ${OPENSSL_NEXT:="$OPENSSL"}
117 : ${GNUTLS_CLI:="gnutls-cli"}
118 : ${GNUTLS_SERV:="gnutls-serv"}
119 : ${GNUTLS_LEGACY_CLI:="$GNUTLS_CLI"}
120 : ${GNUTLS_LEGACY_SERV:="$GNUTLS_SERV"}
121 : ${OUT_OF_SOURCE_DIR:=./mbedtls_out_of_source_build}
122 : ${ARMC5_BIN_DIR:=/usr/bin}
123 : ${ARMC6_BIN_DIR:=/usr/bin}
Andres AGdc192212016-08-31 17:33:13 +0100124
Gilles Peskine8f073122018-11-27 15:58:47 +0100125 # if MAKEFLAGS is not set add the -j option to speed up invocations of make
Gilles Peskine55ae1622019-01-06 20:15:26 +0000126 if [ -z "${MAKEFLAGS+set}" ]; then
Gilles Peskine8f073122018-11-27 15:58:47 +0100127 export MAKEFLAGS="-j"
128 fi
Gilles Peskine10726102019-01-06 20:50:38 +0000129
130 # Gather the list of available components. These are the functions
131 # defined in this script whose name starts with "component_".
132 # Parse the script with sed, because in sh there is no way to list
133 # defined functions.
134 ALL_COMPONENTS=$(sed -n 's/^ *component_\([0-9A-Z_a-z]*\) *().*/\1/p' <"$0")
135
136 # Exclude components that are not supported on this platform.
137 SUPPORTED_COMPONENTS=
138 for component in $ALL_COMPONENTS; do
139 case $(type "support_$component" 2>&1) in
140 *' function'*)
141 if ! support_$component; then continue; fi;;
142 esac
143 SUPPORTED_COMPONENTS="$SUPPORTED_COMPONENTS $component"
144 done
Gilles Peskine8f073122018-11-27 15:58:47 +0100145}
Andres AG38495a32016-07-12 16:54:33 +0100146
Gilles Peskine10726102019-01-06 20:50:38 +0000147# Test whether $1 is excluded via the command line.
148is_component_excluded()
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100149{
Gilles Peskine10726102019-01-06 20:50:38 +0000150 # Is $1 excluded via $COMPONENTS (a space-separated list of wildcard
151 # patterns)?
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100152 set -f
153 for pattern in $COMPONENTS; do
154 set +f
155 case ${1#component_} in $pattern) return 0;; esac
156 done
157 set +f
158 return 1
159}
160
Simon Butcher41eeccf2016-09-07 00:07:09 +0100161usage()
SimonB2e23c822016-04-16 21:54:39 +0100162{
Gilles Peskine709346a2017-12-10 23:43:39 +0100163 cat <<EOF
Gilles Peskine92525112018-11-27 18:15:35 +0100164Usage: $0 [OPTION]... [COMPONENT]...
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100165Run mbedtls release validation tests.
Gilles Peskine92525112018-11-27 18:15:35 +0100166By default, run all tests. With one or more COMPONENT, run only those.
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100167
168Special options:
169 -h|--help Print this help and exit.
Gilles Peskine10726102019-01-06 20:50:38 +0000170 --list-all-components List all available test components and exit.
171 --list-components List components supported on this platform and exit.
Gilles Peskine709346a2017-12-10 23:43:39 +0100172
173General options:
174 -f|--force Force the tests to overwrite any modified files.
Gilles Peskine7c652162017-12-11 00:01:40 +0100175 -k|--keep-going Run all tests and report errors at the end.
Gilles Peskine709346a2017-12-10 23:43:39 +0100176 -m|--memory Additional optional memory tests.
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100177 --armcc Run ARM Compiler builds (on by default).
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100178 --except If some components are passed on the command line,
179 run all the tests except for these components. In
180 this mode, you can pass shell wildcard patterns as
181 component names, e.g. "$0 --except 'test_*'" to
182 exclude all components that run tests.
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100183 --no-armcc Skip ARM Compiler builds.
Gilles Peskine38d81652018-03-21 08:40:26 +0100184 --no-force Refuse to overwrite modified files (default).
185 --no-keep-going Stop at the first error (default).
186 --no-memory No additional memory tests (default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100187 --out-of-source-dir=<path> Directory used for CMake out-of-source build tests.
Gilles Peskine38d81652018-03-21 08:40:26 +0100188 --random-seed Use a random seed value for randomized tests (default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100189 -r|--release-test Run this script in release mode. This fixes the seed value to 1.
190 -s|--seed Integer seed value to use for this test run.
191
192Tool path options:
193 --armc5-bin-dir=<ARMC5_bin_dir_path> ARM Compiler 5 bin directory.
194 --armc6-bin-dir=<ARMC6_bin_dir_path> ARM Compiler 6 bin directory.
195 --gnutls-cli=<GnuTLS_cli_path> GnuTLS client executable to use for most tests.
196 --gnutls-serv=<GnuTLS_serv_path> GnuTLS server executable to use for most tests.
197 --gnutls-legacy-cli=<GnuTLS_cli_path> GnuTLS client executable to use for legacy tests.
198 --gnutls-legacy-serv=<GnuTLS_serv_path> GnuTLS server executable to use for legacy tests.
199 --openssl=<OpenSSL_path> OpenSSL executable to use for most tests.
200 --openssl-legacy=<OpenSSL_path> OpenSSL executable to use for legacy tests e.g. SSLv3.
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100201 --openssl-next=<OpenSSL_path> OpenSSL executable to use for recent things like ARIA
Gilles Peskine709346a2017-12-10 23:43:39 +0100202EOF
SimonB2e23c822016-04-16 21:54:39 +0100203}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100204
205# remove built files as well as the cmake cache/config
206cleanup()
207{
Gilles Peskinea71d64c2018-03-21 12:16:57 +0100208 if [ -n "${MBEDTLS_ROOT_DIR+set}" ]; then
209 cd "$MBEDTLS_ROOT_DIR"
210 fi
211
Gilles Peskine7c652162017-12-11 00:01:40 +0100212 command make clean
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200213
Gilles Peskine31b07e22018-03-21 12:15:06 +0100214 # Remove CMake artefacts
Simon Butcher3ad2efd2018-05-02 14:49:38 +0100215 find . -name .git -prune \
Gilles Peskine31b07e22018-03-21 12:15:06 +0100216 -iname CMakeFiles -exec rm -rf {} \+ -o \
217 \( -iname cmake_install.cmake -o \
218 -iname CTestTestfile.cmake -o \
219 -iname CMakeCache.txt \) -exec rm {} \+
220 # Recover files overwritten by in-tree CMake builds
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000221 rm -f include/Makefile include/mbedtls/Makefile programs/*/Makefile
Paul Bakkerfe0984d2014-06-13 00:13:45 +0200222 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile
223 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200224
225 if [ -f "$CONFIG_BAK" ]; then
226 mv "$CONFIG_BAK" "$CONFIG_H"
227 fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100228}
229
Gilles Peskine7c652162017-12-11 00:01:40 +0100230# Executed on exit. May be redefined depending on command line options.
231final_report () {
232 :
233}
234
235fatal_signal () {
236 cleanup
237 final_report $1
238 trap - $1
239 kill -$1 $$
240}
241
242trap 'fatal_signal HUP' HUP
243trap 'fatal_signal INT' INT
244trap 'fatal_signal TERM' TERM
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200245
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100246msg()
247{
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100248 if [ -n "${current_component:-}" ]; then
249 current_section="${current_component#component_}: $1"
250 else
251 current_section="$1"
252 fi
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100253 echo ""
254 echo "******************************************************************"
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100255 echo "* $current_section "
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000256 printf "* "; date
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100257 echo "******************************************************************"
258}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100259
Gilles Peskine8f073122018-11-27 15:58:47 +0100260armc6_build_test()
261{
262 FLAGS="$1"
Andres AGa5cd9732016-10-17 15:23:10 +0100263
Gilles Peskine8f073122018-11-27 15:58:47 +0100264 msg "build: ARM Compiler 6 ($FLAGS), make"
265 ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \
266 WARNING_CFLAGS='-xc -std=c99' make lib
267 make clean
268}
Andres AGa5cd9732016-10-17 15:23:10 +0100269
Andres AGd9eba4b2016-08-26 14:42:14 +0100270err_msg()
271{
272 echo "$1" >&2
273}
274
275check_tools()
276{
277 for TOOL in "$@"; do
Andres AG98393602017-01-31 17:04:45 +0000278 if ! `type "$TOOL" >/dev/null 2>&1`; then
Andres AGd9eba4b2016-08-26 14:42:14 +0100279 err_msg "$TOOL not found!"
280 exit 1
281 fi
282 done
283}
284
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400285check_headers_in_cpp () {
286 ls include/mbedtls >headers.txt
287 <programs/test/cpp_dummy_build.cpp sed -n 's/"$//; s!^#include "mbedtls/!!p' |
288 sort |
289 diff headers.txt -
290 rm headers.txt
291}
292
Gilles Peskine8f073122018-11-27 15:58:47 +0100293pre_parse_command_line () {
294 while [ $# -gt 0 ]; do
Gilles Peskine06b385f2019-01-09 22:28:21 +0100295 case "$1" in
296 --armcc) RUN_ARMCC=1;;
297 --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
298 --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
299 --except) ALL_EXCEPT=1;;
300 --force|-f) FORCE=1;;
301 --gnutls-cli) shift; GNUTLS_CLI="$1";;
302 --gnutls-legacy-cli) shift; GNUTLS_LEGACY_CLI="$1";;
303 --gnutls-legacy-serv) shift; GNUTLS_LEGACY_SERV="$1";;
304 --gnutls-serv) shift; GNUTLS_SERV="$1";;
305 --help|-h) usage; exit;;
306 --keep-going|-k) KEEP_GOING=1;;
Gilles Peskine10726102019-01-06 20:50:38 +0000307 --list-all-components) printf '%s\n' $ALL_COMPONENTS; exit;;
308 --list-components) printf '%s\n' $SUPPORTED_COMPONENTS; exit;;
Gilles Peskine06b385f2019-01-09 22:28:21 +0100309 --memory|-m) MEMORY=1;;
310 --no-armcc) RUN_ARMCC=0;;
311 --no-force) FORCE=0;;
312 --no-keep-going) KEEP_GOING=0;;
313 --no-memory) MEMORY=0;;
314 --openssl) shift; OPENSSL="$1";;
315 --openssl-legacy) shift; OPENSSL_LEGACY="$1";;
316 --openssl-next) shift; OPENSSL_NEXT="$1";;
317 --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
318 --random-seed) unset SEED;;
319 --release-test|-r) SEED=1;;
320 --seed|-s) shift; SEED="$1";;
321 -*)
322 echo >&2 "Unknown option: $1"
323 echo >&2 "Run $0 --help for usage."
324 exit 120
325 ;;
326 *)
327 COMPONENTS="$COMPONENTS $1";;
328 esac
329 shift
Gilles Peskine8f073122018-11-27 15:58:47 +0100330 done
331}
SimonB2e23c822016-04-16 21:54:39 +0100332
Gilles Peskine8f073122018-11-27 15:58:47 +0100333pre_check_git () {
334 if [ $FORCE -eq 1 ]; then
335 git checkout-index -f -q $CONFIG_H
336 cleanup
337 else
SimonB2e23c822016-04-16 21:54:39 +0100338
Gilles Peskine8f073122018-11-27 15:58:47 +0100339 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
340 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
341 echo "You can either delete this directory manually, or force the test by rerunning"
342 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
343 exit 1
344 fi
345
346 if ! git diff-files --quiet include/mbedtls/config.h; then
347 err_msg "Warning - the configuration file 'include/mbedtls/config.h' has been edited. "
348 echo "You can either delete or preserve your work, or force the test by rerunning the"
349 echo "script as: $0 --force"
350 exit 1
351 fi
Andres AGdc192212016-08-31 17:33:13 +0100352 fi
Gilles Peskine8f073122018-11-27 15:58:47 +0100353}
Andres AGdc192212016-08-31 17:33:13 +0100354
Gilles Peskine8f073122018-11-27 15:58:47 +0100355pre_setup_keep_going () {
Gilles Peskine7c652162017-12-11 00:01:40 +0100356 failure_summary=
357 failure_count=0
358 start_red=
359 end_color=
360 if [ -t 1 ]; then
Gilles Peskine9736b9d2018-01-02 21:54:17 +0100361 case "${TERM:-}" in
Gilles Peskine7c652162017-12-11 00:01:40 +0100362 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
363 start_red=$(printf '\033[31m')
364 end_color=$(printf '\033[0m')
365 ;;
366 esac
367 fi
368 record_status () {
369 if "$@"; then
370 last_status=0
371 else
372 last_status=$?
373 text="$current_section: $* -> $last_status"
374 failure_summary="$failure_summary
375$text"
376 failure_count=$((failure_count + 1))
377 echo "${start_red}^^^^$text^^^^${end_color}"
378 fi
379 }
380 make () {
381 case "$*" in
382 *test|*check)
383 if [ $build_status -eq 0 ]; then
384 record_status command make "$@"
385 else
386 echo "(skipped because the build failed)"
387 fi
388 ;;
389 *)
390 record_status command make "$@"
391 build_status=$last_status
392 ;;
393 esac
394 }
395 final_report () {
396 if [ $failure_count -gt 0 ]; then
397 echo
398 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
399 echo "${start_red}FAILED: $failure_count${end_color}$failure_summary"
400 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Jaeden Amero7c1258d2018-07-20 16:42:14 +0100401 exit 1
Gilles Peskine7c652162017-12-11 00:01:40 +0100402 elif [ -z "${1-}" ]; then
403 echo "SUCCESS :)"
404 fi
405 if [ -n "${1-}" ]; then
406 echo "Killed by SIG$1."
407 fi
408 }
Gilles Peskine8f073122018-11-27 15:58:47 +0100409}
410
Gilles Peskine7c652162017-12-11 00:01:40 +0100411if_build_succeeded () {
412 if [ $build_status -eq 0 ]; then
413 record_status "$@"
414 fi
415}
416
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200417# to be used instead of ! for commands run with
418# record_status or if_build_succeeded
419not() {
420 ! "$@"
421}
422
Gilles Peskine8f073122018-11-27 15:58:47 +0100423pre_print_configuration () {
424 msg "info: $0 configuration"
425 echo "MEMORY: $MEMORY"
426 echo "FORCE: $FORCE"
427 echo "SEED: ${SEED-"UNSET"}"
428 echo "OPENSSL: $OPENSSL"
429 echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
430 echo "OPENSSL_NEXT: $OPENSSL_NEXT"
431 echo "GNUTLS_CLI: $GNUTLS_CLI"
432 echo "GNUTLS_SERV: $GNUTLS_SERV"
433 echo "GNUTLS_LEGACY_CLI: $GNUTLS_LEGACY_CLI"
434 echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV"
435 echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
436 echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
437}
Andres AG87bb5772016-09-27 15:05:15 +0100438
Gilles Peskine8f073122018-11-27 15:58:47 +0100439pre_check_tools () {
440 ARMC5_CC="$ARMC5_BIN_DIR/armcc"
441 ARMC5_AR="$ARMC5_BIN_DIR/armar"
442 ARMC6_CC="$ARMC6_BIN_DIR/armclang"
443 ARMC6_AR="$ARMC6_BIN_DIR/armar"
Andres AGd9eba4b2016-08-26 14:42:14 +0100444
Gilles Peskine8f073122018-11-27 15:58:47 +0100445 # To avoid setting OpenSSL and GnuTLS for each call to compat.sh and ssl-opt.sh
446 # we just export the variables they require
447 export OPENSSL_CMD="$OPENSSL"
448 export GNUTLS_CLI="$GNUTLS_CLI"
449 export GNUTLS_SERV="$GNUTLS_SERV"
Andres AGb2fdd042016-09-22 14:17:46 +0100450
Gilles Peskine8f073122018-11-27 15:58:47 +0100451 # Avoid passing --seed flag in every call to ssl-opt.sh
452 if [ -n "${SEED-}" ]; then
453 export SEED
454 fi
Andres AG7770ea82016-10-10 15:46:20 +0100455
Gilles Peskine8f073122018-11-27 15:58:47 +0100456 # Make sure the tools we need are available.
457 check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$OPENSSL_NEXT" \
458 "$GNUTLS_CLI" "$GNUTLS_SERV" \
459 "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV" "doxygen" "dot" \
460 "arm-none-eabi-gcc" "i686-w64-mingw32-gcc" "gdb"
461 if [ $RUN_ARMCC -ne 0 ]; then
462 check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC6_CC" "$ARMC6_AR"
463 fi
464}
Gilles Peskine192c72f2017-12-21 15:59:21 +0100465
466
467################################################################
468#### Basic checks
469################################################################
Andres AGd9eba4b2016-08-26 14:42:14 +0100470
SimonB2e23c822016-04-16 21:54:39 +0100471#
472# Test Suites to be executed
473#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200474# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100475# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard61bc57a2014-08-14 11:29:06 +0200476# and/or are more likely to fail than others (eg I use Clang most of the
477# time, so start with a GCC build).
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200478# 2. Minimize total running time, by avoiding useless rebuilds
479#
480# Indicative running times are given for reference.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100481
Gilles Peskine8f073122018-11-27 15:58:47 +0100482pre_print_tools () {
483 msg "info: output_env.sh"
484 OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY" GNUTLS_CLI="$GNUTLS_CLI" \
485 GNUTLS_SERV="$GNUTLS_SERV" GNUTLS_LEGACY_CLI="$GNUTLS_LEGACY_CLI" \
486 GNUTLS_LEGACY_SERV="$GNUTLS_LEGACY_SERV" ARMC5_CC="$ARMC5_CC" \
487 ARMC6_CC="$ARMC6_CC" RUN_ARMCC="$RUN_ARMCC" scripts/output_env.sh
488}
Janos Follathb72c6782016-07-19 14:54:17 +0100489
Gilles Peskine8f073122018-11-27 15:58:47 +0100490component_check_recursion () {
491 msg "test: recursion.pl" # < 1s
492 record_status tests/scripts/recursion.pl library/*.c
493}
Manuel Pégourié-Gonnardea29d152014-11-20 17:32:33 +0100494
Gilles Peskine8f073122018-11-27 15:58:47 +0100495component_check_generated_files () {
496 msg "test: freshness of generated source files" # < 1s
497 record_status tests/scripts/check-generated-files.sh
498}
Manuel Pégourié-Gonnardb3b8e432015-02-13 14:52:19 +0000499
Gilles Peskine8f073122018-11-27 15:58:47 +0100500component_check_doxy_blocks () {
501 msg "test: doxygen markup outside doxygen blocks" # < 1s
502 record_status tests/scripts/check-doxy-blocks.pl
503}
Manuel Pégourié-Gonnardd09a6b52015-04-09 17:19:23 +0200504
Gilles Peskine8f073122018-11-27 15:58:47 +0100505component_check_files () {
506 msg "test: check-files.py" # < 1s
Gilles Peskine8f073122018-11-27 15:58:47 +0100507 record_status tests/scripts/check-files.py
508}
Darryl Greena07039c2018-03-13 16:48:16 +0000509
Gilles Peskine8f073122018-11-27 15:58:47 +0100510component_check_names () {
511 msg "test/build: declared and exported names" # < 3s
Gilles Peskine8f073122018-11-27 15:58:47 +0100512 record_status tests/scripts/check-names.sh
513}
Manuel Pégourié-Gonnarda687baf2015-04-09 11:09:03 +0200514
Gilles Peskine8f073122018-11-27 15:58:47 +0100515component_check_doxygen_warnings () {
516 msg "test: doxygen warnings" # ~ 3s
Gilles Peskine8f073122018-11-27 15:58:47 +0100517 record_status tests/scripts/doxygen.sh
518}
Manuel Pégourié-Gonnard1d552e72016-01-04 16:49:09 +0100519
Gilles Peskine192c72f2017-12-21 15:59:21 +0100520
Gilles Peskine192c72f2017-12-21 15:59:21 +0100521################################################################
522#### Build and test many configurations and targets
523################################################################
524
Gilles Peskine8f073122018-11-27 15:58:47 +0100525component_test_default_cmake_gcc_asan () {
526 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100527 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
528 make
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100529
Gilles Peskine8f073122018-11-27 15:58:47 +0100530 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
531 make test
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200532
Gilles Peskine8f073122018-11-27 15:58:47 +0100533 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
534 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200535
Gilles Peskine8f073122018-11-27 15:58:47 +0100536 msg "test: compat.sh (ASan build)" # ~ 6 min
537 if_build_succeeded tests/compat.sh
538}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200539
Gilles Peskine782f4112018-11-27 16:11:09 +0100540component_test_ref_configs () {
541 msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
542 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
543 record_status tests/scripts/test-ref-configs.pl
544}
545
Gilles Peskine8f073122018-11-27 15:58:47 +0100546component_test_sslv3 () {
547 msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100548 scripts/config.pl set MBEDTLS_SSL_PROTO_SSL3
549 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
550 make
Simon Butcher3ea7f522016-03-07 23:22:10 +0000551
Gilles Peskine8f073122018-11-27 15:58:47 +0100552 msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
553 make test
Simon Butcher3ea7f522016-03-07 23:22:10 +0000554
Gilles Peskine8f073122018-11-27 15:58:47 +0100555 msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
556 if_build_succeeded tests/compat.sh -m 'tls1 tls1_1 tls1_2 dtls1 dtls1_2'
557 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
Simon Butcher3ea7f522016-03-07 23:22:10 +0000558
Gilles Peskine8f073122018-11-27 15:58:47 +0100559 msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
560 if_build_succeeded tests/ssl-opt.sh
561}
Simon Butcher3ea7f522016-03-07 23:22:10 +0000562
Gilles Peskine8f073122018-11-27 15:58:47 +0100563component_test_no_renegotiation () {
564 msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100565 scripts/config.pl unset MBEDTLS_SSL_RENEGOTIATION
566 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
567 make
Hanno Becker134c2ab2017-10-12 15:29:50 +0100568
Gilles Peskine8f073122018-11-27 15:58:47 +0100569 msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
570 make test
Hanno Becker134c2ab2017-10-12 15:29:50 +0100571
Gilles Peskine8f073122018-11-27 15:58:47 +0100572 msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
573 if_build_succeeded tests/ssl-opt.sh
574}
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +0100575
Gilles Peskine8f073122018-11-27 15:58:47 +0100576component_test_rsa_no_crt () {
577 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100578 scripts/config.pl set MBEDTLS_RSA_NO_CRT
579 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
580 make
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100581
Gilles Peskine8f073122018-11-27 15:58:47 +0100582 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
583 make test
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100584
Gilles Peskine8f073122018-11-27 15:58:47 +0100585 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
586 if_build_succeeded tests/ssl-opt.sh -f RSA
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100587
Gilles Peskine8f073122018-11-27 15:58:47 +0100588 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
589 if_build_succeeded tests/compat.sh -t RSA
590}
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100591
Gilles Peskine8f073122018-11-27 15:58:47 +0100592component_test_small_ssl_out_content_len () {
593 msg "build: small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100594 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 16384
595 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
596 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
597 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000598
Gilles Peskine8f073122018-11-27 15:58:47 +0100599 msg "test: small SSL_OUT_CONTENT_LEN - ssl-opt.sh MFL and large packet tests"
600 if_build_succeeded tests/ssl-opt.sh -f "Max fragment\|Large packet"
601}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000602
Gilles Peskine8f073122018-11-27 15:58:47 +0100603component_test_small_ssl_in_content_len () {
604 msg "build: small SSL_IN_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100605 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 4096
606 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 16384
607 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
608 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000609
Gilles Peskine8f073122018-11-27 15:58:47 +0100610 msg "test: small SSL_IN_CONTENT_LEN - ssl-opt.sh MFL tests"
611 if_build_succeeded tests/ssl-opt.sh -f "Max fragment"
612}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000613
Gilles Peskine8f073122018-11-27 15:58:47 +0100614component_test_small_ssl_dtls_max_buffering () {
615 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0"
Gilles Peskine8f073122018-11-27 15:58:47 +0100616 scripts/config.pl set MBEDTLS_SSL_DTLS_MAX_BUFFERING 1000
617 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
618 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100619
Gilles Peskine8f073122018-11-27 15:58:47 +0100620 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0 - ssl-opt.sh specific reordering test"
621 if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer out-of-order hs msg before reassembling next, free buffered msg"
622}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100623
Gilles Peskine8f073122018-11-27 15:58:47 +0100624component_test_small_mbedtls_ssl_dtls_max_buffering () {
625 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1"
Gilles Peskine8f073122018-11-27 15:58:47 +0100626 scripts/config.pl set MBEDTLS_SSL_DTLS_MAX_BUFFERING 240
627 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
628 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100629
Gilles Peskine8f073122018-11-27 15:58:47 +0100630 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1 - ssl-opt.sh specific reordering test"
631 if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer encrypted Finished message, drop for fragmented NewSessionTicket"
632}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100633
Gilles Peskine8f073122018-11-27 15:58:47 +0100634component_test_full_cmake_clang () {
635 msg "build: cmake, full config, clang" # ~ 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100636 scripts/config.pl full
637 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
638 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check -D ENABLE_TESTING=On .
639 make
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100640
Gilles Peskine8f073122018-11-27 15:58:47 +0100641 msg "test: main suites (full config)" # ~ 5s
642 make test
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200643
Gilles Peskine8f073122018-11-27 15:58:47 +0100644 msg "test: ssl-opt.sh default, ECJPAKE, SSL async (full config)" # ~ 1s
645 if_build_succeeded tests/ssl-opt.sh -f 'Default\|ECJPAKE\|SSL async private'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200646
Gilles Peskine8f073122018-11-27 15:58:47 +0100647 msg "test: compat.sh RC4, DES & NULL (full config)" # ~ 2 min
648 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'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200649
Gilles Peskine8f073122018-11-27 15:58:47 +0100650 msg "test: compat.sh ARIA + ChachaPoly"
651 if_build_succeeded env OPENSSL_CMD="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
652}
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100653
Gilles Peskine8f073122018-11-27 15:58:47 +0100654component_build_deprecated () {
655 msg "build: make, full config + DEPRECATED_WARNING, gcc -O" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100656 scripts/config.pl full
657 scripts/config.pl set MBEDTLS_DEPRECATED_WARNING
658 # Build with -O -Wextra to catch a maximum of issues.
659 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra' lib programs
660 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
Gilles Peskineb4ef45b2018-03-01 22:23:50 +0100661
Gilles Peskine8f073122018-11-27 15:58:47 +0100662 msg "build: make, full config + DEPRECATED_REMOVED, clang -O" # ~ 30s
663 # No cleanup, just tweak the configuration and rebuild
664 make clean
665 scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
666 scripts/config.pl set MBEDTLS_DEPRECATED_REMOVED
667 # Build with -O -Wextra to catch a maximum of issues.
668 make CC=clang CFLAGS='-O -Werror -Wall -Wextra' lib programs
669 make CC=clang CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
670}
Gilles Peskine0afe6242018-02-21 19:28:12 +0100671
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200672
Gilles Peskine8f073122018-11-27 15:58:47 +0100673component_test_depends_curves () {
674 msg "test/build: curves.pl (gcc)" # ~ 4 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100675 record_status tests/scripts/curves.pl
676}
Manuel Pégourié-Gonnard1fe6bb92017-06-06 11:36:16 +0200677
Gilles Peskine8f073122018-11-27 15:58:47 +0100678component_test_depends_hashes () {
679 msg "test/build: depends-hashes.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100680 record_status tests/scripts/depends-hashes.pl
681}
Manuel Pégourié-Gonnard43be6cd2017-06-20 09:53:42 +0200682
Gilles Peskine8f073122018-11-27 15:58:47 +0100683component_test_depends_pkalgs () {
684 msg "test/build: depends-pkalgs.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100685 record_status tests/scripts/depends-pkalgs.pl
686}
Manuel Pégourié-Gonnard503a5ef2015-10-23 09:04:45 +0200687
Gilles Peskine8f073122018-11-27 15:58:47 +0100688component_build_key_exchanges () {
689 msg "test/build: key-exchanges (gcc)" # ~ 1 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100690 record_status tests/scripts/key-exchanges.pl
691}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100692
Gilles Peskine8f073122018-11-27 15:58:47 +0100693component_build_default_make_gcc_and_cxx () {
694 msg "build: Unix make, -Os (gcc)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100695 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400696
Gilles Peskine8f073122018-11-27 15:58:47 +0100697 msg "test: verify header list in cpp_dummy_build.cpp"
698 record_status check_headers_in_cpp
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400699
Gilles Peskine8f073122018-11-27 15:58:47 +0100700 msg "build: Unix make, incremental g++"
701 make TEST_CPP=1
702}
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +0000703
Gilles Peskine8f073122018-11-27 15:58:47 +0100704component_test_no_platform () {
705 # Full configuration build, without platform support, file IO and net sockets.
706 # This should catch missing mbedtls_printf definitions, and by disabling file
707 # IO, it should catch missing '#include <stdio.h>'
708 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100709 scripts/config.pl full
710 scripts/config.pl unset MBEDTLS_PLATFORM_C
711 scripts/config.pl unset MBEDTLS_NET_C
712 scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
713 scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
714 scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
715 scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
716 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
717 scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
718 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
719 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
720 scripts/config.pl unset MBEDTLS_FS_IO
Gilles Peskine51585382019-01-05 10:27:47 +0100721 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_FILE_C
722 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_C
Gilles Peskine8f073122018-11-27 15:58:47 +0100723 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
724 # to re-enable platform integration features otherwise disabled in C99 builds
725 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -O0 -D_DEFAULT_SOURCE' lib programs
726 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0' test
727}
Manuel Pégourié-Gonnarddccb80b2015-06-03 10:20:33 +0100728
Gilles Peskine8f073122018-11-27 15:58:47 +0100729component_build_no_std_function () {
730 # catch compile bugs in _uninit functions
731 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100732 scripts/config.pl full
733 scripts/config.pl set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
734 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
735 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
736}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200737
Gilles Peskine8f073122018-11-27 15:58:47 +0100738component_build_no_ssl_srv () {
739 msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100740 scripts/config.pl full
741 scripts/config.pl unset MBEDTLS_SSL_SRV_C
742 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
743}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200744
Gilles Peskine8f073122018-11-27 15:58:47 +0100745component_build_no_ssl_cli () {
746 msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100747 scripts/config.pl full
748 scripts/config.pl unset MBEDTLS_SSL_CLI_C
749 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
750}
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +0200751
Gilles Peskine8f073122018-11-27 15:58:47 +0100752component_build_no_sockets () {
753 # Note, C99 compliance can also be tested with the sockets support disabled,
754 # as that requires a POSIX platform (which isn't the same as C99).
755 msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100756 scripts/config.pl full
757 scripts/config.pl unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
758 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
759 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0 -std=c99 -pedantic' lib
760}
Hanno Becker5175ac62017-09-18 15:36:25 +0100761
Gilles Peskine8f073122018-11-27 15:58:47 +0100762component_test_no_max_fragment_length () {
763 # Run max fragment length tests with MFL disabled
764 msg "build: default config except MFL extension (ASan build)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100765 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
766 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
767 make
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000768
Gilles Peskine8f073122018-11-27 15:58:47 +0100769 msg "test: ssl-opt.sh, MFL-related tests"
770 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length"
771}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000772
Gilles Peskine8f073122018-11-27 15:58:47 +0100773component_test_no_max_fragment_length_small_ssl_out_content_len () {
774 msg "build: no MFL extension, small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100775 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
776 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 16384
777 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
778 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
779 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000780
Gilles Peskine8f073122018-11-27 15:58:47 +0100781 msg "test: MFL tests (disabled MFL extension case) & large packet tests"
782 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length\|Large buffer"
783}
Janos Follath06c54002016-06-09 13:57:40 +0100784
Gilles Peskine8f073122018-11-27 15:58:47 +0100785component_test_null_entropy () {
786 msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100787 scripts/config.pl set MBEDTLS_TEST_NULL_ENTROPY
788 scripts/config.pl set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
789 scripts/config.pl set MBEDTLS_ENTROPY_C
790 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
791 scripts/config.pl unset MBEDTLS_ENTROPY_HARDWARE_ALT
792 scripts/config.pl unset MBEDTLS_HAVEGE_C
Gilles Peskine19275652019-01-06 19:48:30 +0000793 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan -D UNSAFE_BUILD=ON .
Gilles Peskine8f073122018-11-27 15:58:47 +0100794 make
Janos Follath06c54002016-06-09 13:57:40 +0100795
Gilles Peskine8f073122018-11-27 15:58:47 +0100796 msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)"
797 make test
798}
Hanno Beckere5fecec2018-10-11 11:02:52 +0100799
Gilles Peskine8f073122018-11-27 15:58:47 +0100800component_test_platform_calloc_macro () {
801 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100802 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
803 scripts/config.pl set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
804 scripts/config.pl set MBEDTLS_PLATFORM_FREE_MACRO free
805 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
806 make
Hanno Beckere5fecec2018-10-11 11:02:52 +0100807
Gilles Peskine8f073122018-11-27 15:58:47 +0100808 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
809 make test
810}
Hanno Becker83ebf782017-07-07 12:29:15 +0100811
Gilles Peskine8f073122018-11-27 15:58:47 +0100812component_test_aes_fewer_tables () {
813 msg "build: default config with AES_FEWER_TABLES enabled"
Gilles Peskine8f073122018-11-27 15:58:47 +0100814 scripts/config.pl set MBEDTLS_AES_FEWER_TABLES
815 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +0100816
Gilles Peskine8f073122018-11-27 15:58:47 +0100817 msg "test: AES_FEWER_TABLES"
818 make test
819}
Hanno Becker83ebf782017-07-07 12:29:15 +0100820
Gilles Peskine8f073122018-11-27 15:58:47 +0100821component_test_aes_rom_tables () {
822 msg "build: default config with AES_ROM_TABLES enabled"
Gilles Peskine8f073122018-11-27 15:58:47 +0100823 scripts/config.pl set MBEDTLS_AES_ROM_TABLES
824 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +0100825
Gilles Peskine8f073122018-11-27 15:58:47 +0100826 msg "test: AES_ROM_TABLES"
827 make test
828}
Hanno Becker83ebf782017-07-07 12:29:15 +0100829
Gilles Peskine8f073122018-11-27 15:58:47 +0100830component_test_aes_fewer_tables_and_rom_tables () {
831 msg "build: default config with AES_ROM_TABLES and AES_FEWER_TABLES enabled"
Gilles Peskine8f073122018-11-27 15:58:47 +0100832 scripts/config.pl set MBEDTLS_AES_FEWER_TABLES
833 scripts/config.pl set MBEDTLS_AES_ROM_TABLES
834 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +0100835
Gilles Peskine8f073122018-11-27 15:58:47 +0100836 msg "test: AES_FEWER_TABLES + AES_ROM_TABLES"
837 make test
838}
839
840component_test_make_shared () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100841 msg "build/test: make shared" # ~ 40s
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100842 make SHARED=1 all check
Gilles Peskine8f073122018-11-27 15:58:47 +0100843}
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +0200844
Gilles Peskine8f073122018-11-27 15:58:47 +0100845component_test_m32_o0 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100846 # Build once with -O0, to compile out the i386 specific inline assembly
847 msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
Simon Butcher7a6da6e2018-06-27 21:52:54 +0100848 scripts/config.pl full
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100849 make CC=gcc CFLAGS='-O0 -Werror -Wall -Wextra -m32 -fsanitize=address'
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +0100850
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100851 msg "test: i386, make, gcc -O0 (ASan build)"
852 make test
Gilles Peskine8f073122018-11-27 15:58:47 +0100853}
Gilles Peskine10726102019-01-06 20:50:38 +0000854support_test_m32_o0 () {
855 case $(uname -m) in
856 *64*) true;;
857 *) false;;
858 esac
859}
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100860
Gilles Peskine8f073122018-11-27 15:58:47 +0100861component_test_m32_o1 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100862 # Build again with -O1, to compile in the i386 specific inline assembly
863 msg "build: i386, make, gcc -O1 (ASan build)" # ~ 30s
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100864 scripts/config.pl full
865 make CC=gcc CFLAGS='-O1 -Werror -Wall -Wextra -m32 -fsanitize=address'
866
867 msg "test: i386, make, gcc -O1 (ASan build)"
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +0100868 make test
Gilles Peskine8f073122018-11-27 15:58:47 +0100869}
Gilles Peskine10726102019-01-06 20:50:38 +0000870support_test_m32_o1 () {
871 support_test_m32_o0 "$@"
872}
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +0100873
Gilles Peskine8f073122018-11-27 15:58:47 +0100874component_test_mx32 () {
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +0100875 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
Simon Butcher7a6da6e2018-06-27 21:52:54 +0100876 scripts/config.pl full
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +0100877 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32'
878
879 msg "test: 64-bit ILP32, make, gcc"
880 make test
Gilles Peskine8f073122018-11-27 15:58:47 +0100881}
Gilles Peskine10726102019-01-06 20:50:38 +0000882support_test_mx32 () {
883 case $(uname -m) in
884 amd64|x86_64) true;;
885 *) false;;
886 esac
887}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000888
Gilles Peskine8f073122018-11-27 15:58:47 +0100889component_test_have_int32 () {
890 msg "build: gcc, force 32-bit bignum limbs"
Gilles Peskine8f073122018-11-27 15:58:47 +0100891 scripts/config.pl unset MBEDTLS_HAVE_ASM
892 scripts/config.pl unset MBEDTLS_AESNI_C
893 scripts/config.pl unset MBEDTLS_PADLOCK_C
894 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +0100895
Gilles Peskine8f073122018-11-27 15:58:47 +0100896 msg "test: gcc, force 32-bit bignum limbs"
897 make test
898}
Andres Amaya Garciafe843a32017-07-20 13:21:34 +0100899
Gilles Peskine8f073122018-11-27 15:58:47 +0100900component_test_have_int64 () {
901 msg "build: gcc, force 64-bit bignum limbs"
Gilles Peskine8f073122018-11-27 15:58:47 +0100902 scripts/config.pl unset MBEDTLS_HAVE_ASM
903 scripts/config.pl unset MBEDTLS_AESNI_C
904 scripts/config.pl unset MBEDTLS_PADLOCK_C
905 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
Gilles Peskine14c3c062018-01-29 21:25:12 +0100906
Gilles Peskine8f073122018-11-27 15:58:47 +0100907 msg "test: gcc, force 64-bit bignum limbs"
908 make test
909}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000910
Gilles Peskine8f073122018-11-27 15:58:47 +0100911component_test_no_udbl_division () {
912 msg "build: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +0100913 scripts/config.pl full
914 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
915 scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
916 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200917
Gilles Peskine8f073122018-11-27 15:58:47 +0100918 msg "test: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
919 make test
920}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200921
Gilles Peskine8f073122018-11-27 15:58:47 +0100922component_test_no_64bit_multiplication () {
923 msg "build: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +0100924 scripts/config.pl full
925 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
926 scripts/config.pl set MBEDTLS_NO_64BIT_MULTIPLICATION
927 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200928
Gilles Peskine8f073122018-11-27 15:58:47 +0100929 msg "test: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
930 make test
931}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200932
Gilles Peskine8f073122018-11-27 15:58:47 +0100933component_build_arm_none_eabi_gcc () {
934 msg "build: arm-none-eabi-gcc, make" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +0100935 scripts/config.pl full
936 scripts/config.pl unset MBEDTLS_NET_C
937 scripts/config.pl unset MBEDTLS_TIMING_C
938 scripts/config.pl unset MBEDTLS_FS_IO
Gilles Peskine51585382019-01-05 10:27:47 +0100939 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_FILE_C
940 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_C
Gilles Peskine8f073122018-11-27 15:58:47 +0100941 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
942 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
943 # following things are not in the default config
944 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
945 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
946 scripts/config.pl unset MBEDTLS_THREADING_C
947 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
948 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
949 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
950}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200951
Gilles Peskine8f073122018-11-27 15:58:47 +0100952component_build_arm_none_eabi_gcc_no_udbl_division () {
953 msg "build: arm-none-eabi-gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +0100954 scripts/config.pl full
955 scripts/config.pl unset MBEDTLS_NET_C
956 scripts/config.pl unset MBEDTLS_TIMING_C
957 scripts/config.pl unset MBEDTLS_FS_IO
Gilles Peskine51585382019-01-05 10:27:47 +0100958 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_FILE_C
959 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_C
Gilles Peskine8f073122018-11-27 15:58:47 +0100960 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
961 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
962 # following things are not in the default config
963 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
964 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
965 scripts/config.pl unset MBEDTLS_THREADING_C
966 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
967 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
968 scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
969 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
970 echo "Checking that software 64-bit division is not required"
971 if_build_succeeded not grep __aeabi_uldiv library/*.o
972}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200973
Gilles Peskine8f073122018-11-27 15:58:47 +0100974component_build_arm_none_eabi_gcc_no_64bit_multiplication () {
975 msg "build: arm-none-eabi-gcc MBEDTLS_NO_64BIT_MULTIPLICATION, make" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +0100976 scripts/config.pl full
977 scripts/config.pl unset MBEDTLS_NET_C
978 scripts/config.pl unset MBEDTLS_TIMING_C
979 scripts/config.pl unset MBEDTLS_FS_IO
Gilles Peskine51585382019-01-05 10:27:47 +0100980 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_FILE_C
981 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_C
Gilles Peskine8f073122018-11-27 15:58:47 +0100982 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
983 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
984 # following things are not in the default config
985 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
986 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
987 scripts/config.pl unset MBEDTLS_THREADING_C
988 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
989 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
990 scripts/config.pl set MBEDTLS_NO_64BIT_MULTIPLICATION
991 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -O1 -march=armv6-m -mthumb' lib
992 echo "Checking that software 64-bit multiplication is not required"
993 if_build_succeeded not grep __aeabi_lmul library/*.o
994}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200995
Gilles Peskine8f073122018-11-27 15:58:47 +0100996component_build_armcc () {
997 msg "build: ARM Compiler 5, make"
Gilles Peskine8f073122018-11-27 15:58:47 +0100998 scripts/config.pl full
999 scripts/config.pl unset MBEDTLS_NET_C
1000 scripts/config.pl unset MBEDTLS_TIMING_C
1001 scripts/config.pl unset MBEDTLS_FS_IO
Gilles Peskine51585382019-01-05 10:27:47 +01001002 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_FILE_C
1003 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_C
Gilles Peskine8f073122018-11-27 15:58:47 +01001004 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
1005 scripts/config.pl unset MBEDTLS_HAVE_TIME
1006 scripts/config.pl unset MBEDTLS_HAVE_TIME_DATE
1007 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
1008 # following things are not in the default config
1009 scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
1010 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
1011 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
1012 scripts/config.pl unset MBEDTLS_THREADING_C
1013 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
1014 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
1015 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT # depends on MBEDTLS_HAVE_TIME
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001016
Gilles Peskine8f073122018-11-27 15:58:47 +01001017 if [ $RUN_ARMCC -ne 0 ]; then
1018 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
1019 make clean
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001020
Gilles Peskine8f073122018-11-27 15:58:47 +01001021 # ARM Compiler 6 - Target ARMv7-A
1022 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-a"
Gilles Peskineed942f82017-06-08 15:19:20 +02001023
Gilles Peskine8f073122018-11-27 15:58:47 +01001024 # ARM Compiler 6 - Target ARMv7-M
1025 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m"
Andres AG87bb5772016-09-27 15:05:15 +01001026
Gilles Peskine8f073122018-11-27 15:58:47 +01001027 # ARM Compiler 6 - Target ARMv8-A - AArch32
1028 armc6_build_test "--target=arm-arm-none-eabi -march=armv8.2-a"
Andres AG87bb5772016-09-27 15:05:15 +01001029
Gilles Peskine8f073122018-11-27 15:58:47 +01001030 # ARM Compiler 6 - Target ARMv8-M
1031 armc6_build_test "--target=arm-arm-none-eabi -march=armv8-m.main"
Simon Butcher940737f2017-07-23 13:42:36 +02001032
Gilles Peskine8f073122018-11-27 15:58:47 +01001033 # ARM Compiler 6 - Target ARMv8-A - AArch64
1034 armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a"
1035 fi
1036}
Simon Butcher940737f2017-07-23 13:42:36 +02001037
Gilles Peskine8f073122018-11-27 15:58:47 +01001038component_test_allow_sha1 () {
1039 msg "build: allow SHA1 in certificates by default"
Gilles Peskine8f073122018-11-27 15:58:47 +01001040 scripts/config.pl set MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
1041 make CFLAGS='-Werror -Wall -Wextra'
1042 msg "test: allow SHA1 in certificates by default"
1043 make test
1044 if_build_succeeded tests/ssl-opt.sh -f SHA-1
1045}
Simon Butcher940737f2017-07-23 13:42:36 +02001046
Gilles Peskine8f073122018-11-27 15:58:47 +01001047component_build_mingw () {
1048 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +01001049 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
Gilles Peskine2a458da2017-05-12 15:26:58 +02001050
Gilles Peskine8f073122018-11-27 15:58:47 +01001051 # note Make tests only builds the tests, but doesn't run them
1052 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror' WINDOWS_BUILD=1 tests
1053 make WINDOWS_BUILD=1 clean
Hanno Beckere963efa2018-01-03 10:03:43 +00001054
Gilles Peskine8f073122018-11-27 15:58:47 +01001055 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
1056 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
1057 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
1058 make WINDOWS_BUILD=1 clean
1059}
Simon Butcher002bc622016-11-17 09:27:45 +00001060
Gilles Peskine8f073122018-11-27 15:58:47 +01001061component_test_memsan () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001062 msg "build: MSan (clang)" # ~ 1 min 20s
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001063 scripts/config.pl unset MBEDTLS_AESNI_C # memsan doesn't grok asm
1064 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
1065 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +02001066
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001067 msg "test: main suites (MSan)" # ~ 10s
1068 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001069
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001070 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
Gilles Peskine7c652162017-12-11 00:01:40 +01001071 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001072
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001073 # Optional part(s)
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001074
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001075 if [ "$MEMORY" -gt 0 ]; then
1076 msg "test: compat.sh (MSan)" # ~ 6 min 20s
Gilles Peskine7c652162017-12-11 00:01:40 +01001077 if_build_succeeded tests/compat.sh
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001078 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001079}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001080
Gilles Peskine8f073122018-11-27 15:58:47 +01001081component_test_memcheck () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001082 msg "build: Release (clang)"
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001083 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
1084 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001085
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001086 msg "test: main suites valgrind (Release)"
1087 make memcheck
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001088
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001089 # Optional part(s)
1090 # Currently broken, programs don't seem to receive signals
1091 # under valgrind on OS X
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001092
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001093 if [ "$MEMORY" -gt 0 ]; then
1094 msg "test: ssl-opt.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +01001095 if_build_succeeded tests/ssl-opt.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001096 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001097
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001098 if [ "$MEMORY" -gt 1 ]; then
1099 msg "test: compat.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +01001100 if_build_succeeded tests/compat.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001101 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001102}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001103
Gilles Peskine8f073122018-11-27 15:58:47 +01001104component_test_cmake_out_of_source () {
1105 msg "build: cmake 'out-of-source' build"
Gilles Peskine8f073122018-11-27 15:58:47 +01001106 MBEDTLS_ROOT_DIR="$PWD"
1107 mkdir "$OUT_OF_SOURCE_DIR"
1108 cd "$OUT_OF_SOURCE_DIR"
1109 cmake "$MBEDTLS_ROOT_DIR"
1110 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001111
Gilles Peskine8f073122018-11-27 15:58:47 +01001112 msg "test: cmake 'out-of-source' build"
1113 make test
1114 # Test an SSL option that requires an auxiliary script in test/scripts/.
1115 # Also ensure that there are no error messages such as
1116 # "No such file or directory", which would indicate that some required
1117 # file is missing (ssl-opt.sh tolerates the absence of some files so
1118 # may exit with status 0 but emit errors).
1119 if_build_succeeded ./tests/ssl-opt.sh -f 'Fallback SCSV: beginning of list' 2>ssl-opt.err
1120 if [ -s ssl-opt.err ]; then
1121 cat ssl-opt.err >&2
1122 record_status [ ! -s ssl-opt.err ]
1123 rm ssl-opt.err
1124 fi
1125 cd "$MBEDTLS_ROOT_DIR"
1126 rm -rf "$OUT_OF_SOURCE_DIR"
1127 unset MBEDTLS_ROOT_DIR
1128}
Andres AGdc192212016-08-31 17:33:13 +01001129
Gilles Peskine8f073122018-11-27 15:58:47 +01001130component_test_zeroize () {
1131 # Test that the function mbedtls_platform_zeroize() is not optimized away by
1132 # different combinations of compilers and optimization flags by using an
1133 # auxiliary GDB script. Unfortunately, GDB does not return error values to the
1134 # system in all cases that the script fails, so we must manually search the
1135 # output to check whether the pass string is present and no failure strings
1136 # were printed.
Gilles Peskine74851d82019-01-06 19:52:22 +00001137
1138 # Don't try to disable ASLR. We don't care about ASLR here. We do care
1139 # about a spurious message if Gdb tries and fails, so suppress that.
1140 gdb_disable_aslr=
1141 if [ -z "$(gdb -batch -nw -ex 'set disable-randomization off' 2>&1)" ]; then
1142 gdb_disable_aslr='set disable-randomization off'
1143 fi
1144
Gilles Peskine8f073122018-11-27 15:58:47 +01001145 for optimization_flag in -O2 -O3 -Ofast -Os; do
Gilles Peskine06b385f2019-01-09 22:28:21 +01001146 for compiler in clang gcc; do
1147 msg "test: $compiler $optimization_flag, mbedtls_platform_zeroize()"
1148 make programs CC="$compiler" DEBUG=1 CFLAGS="$optimization_flag"
Gilles Peskine74851d82019-01-06 19:52:22 +00001149 if_build_succeeded gdb -ex "$gdb_disable_aslr" -x tests/scripts/test_zeroize.gdb -nw -batch -nx 2>&1 | tee test_zeroize.log
Gilles Peskine06b385f2019-01-09 22:28:21 +01001150 if_build_succeeded grep "The buffer was correctly zeroized" test_zeroize.log
1151 if_build_succeeded not grep -i "error" test_zeroize.log
1152 rm -f test_zeroize.log
1153 make clean
1154 done
Andres Amaya Garcia29673812017-10-25 10:35:51 +01001155 done
Gilles Peskine74851d82019-01-06 19:52:22 +00001156
1157 unset gdb_disable_aslr
Gilles Peskine8f073122018-11-27 15:58:47 +01001158}
Andres Amaya Garciad0d7bf62017-10-25 09:01:31 +01001159
Gilles Peskine8f073122018-11-27 15:58:47 +01001160component_check_python_files () {
1161 msg "Lint: Python scripts"
1162 record_status tests/scripts/check-python-files.sh
1163}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001164
Gilles Peskine8f073122018-11-27 15:58:47 +01001165component_check_generate_test_code () {
1166 msg "uint test: generate_test_code.py"
1167 record_status ./tests/scripts/test_generate_test_code.py
1168}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001169
1170################################################################
1171#### Termination
1172################################################################
1173
Gilles Peskine8f073122018-11-27 15:58:47 +01001174post_report () {
1175 msg "Done, cleaning up"
1176 cleanup
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001177
Gilles Peskine8f073122018-11-27 15:58:47 +01001178 final_report
1179}
1180
1181
1182
1183################################################################
1184#### Run all the things
1185################################################################
1186
Gilles Peskinee48351a2018-11-27 16:06:30 +01001187# Run one component and clean up afterwards.
Gilles Peskine8f073122018-11-27 15:58:47 +01001188run_component () {
Gilles Peskine8ae15dd2019-01-02 18:57:02 +01001189 # Back up the configuration in case the component modifies it.
1190 # The cleanup function will restore it.
1191 cp -p "$CONFIG_H" "$CONFIG_BAK"
Gilles Peskineffcdeff2018-12-04 12:49:28 +01001192 current_component="$1"
Gilles Peskine8f073122018-11-27 15:58:47 +01001193 "$@"
Gilles Peskinee48351a2018-11-27 16:06:30 +01001194 cleanup
Gilles Peskine8f073122018-11-27 15:58:47 +01001195}
1196
1197# Preliminary setup
1198pre_check_environment
1199pre_initialize_variables
1200pre_parse_command_line "$@"
Gilles Peskine348fb9a2018-11-27 17:04:29 +01001201
Gilles Peskine10726102019-01-06 20:50:38 +00001202pre_check_git
1203build_status=0
1204if [ $KEEP_GOING -eq 1 ]; then
1205 pre_setup_keep_going
1206else
1207 record_status () {
1208 "$@"
1209 }
1210fi
1211pre_print_configuration
1212pre_check_tools
1213pre_print_tools
1214cleanup
Gilles Peskine8f073122018-11-27 15:58:47 +01001215
Gilles Peskine81b96ed2018-11-27 21:37:53 +01001216if [ -n "$COMPONENTS" ] && [ $ALL_EXCEPT -eq 0 ]; then
Gilles Peskine10726102019-01-06 20:50:38 +00001217 # Run the components passed on the command line.
Gilles Peskine92525112018-11-27 18:15:35 +01001218 for component in $COMPONENTS; do
Gilles Peskine10726102019-01-06 20:50:38 +00001219 run_component "component_$component"
Gilles Peskine92525112018-11-27 18:15:35 +01001220 done
1221else
Gilles Peskine10726102019-01-06 20:50:38 +00001222 # Run all components except those excluded on the command line.
1223 for component in $SUPPORTED_COMPONENTS; do
1224 if ! is_component_excluded "$component"; then
1225 run_component "component_$component"
1226 fi
1227 done
Gilles Peskine8f073122018-11-27 15:58:47 +01001228fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001229
1230# We're done.
Gilles Peskine10726102019-01-06 20:50:38 +00001231post_report