blob: 5dd2acf99400dc6cd5f6dca6e395a3b1f977a559 [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
65# * post_XXX: things to do after running the tests.
66# * other: miscellaneous support functions.
67#
Gilles Peskine192c72f2017-12-21 15:59:21 +010068# The tests are roughly in order from fastest to slowest. This doesn't
69# have to be exact, but in general you should add slower tests towards
70# the end and fast checks near the beginning.
71#
72# Sanity checks have the following form:
73# 1. msg "short description of what is about to be done"
74# 2. run sanity check (failure stops the script)
75#
76# Build or build-and-test steps have the following form:
77# 1. msg "short description of what is about to be done"
78# 2. cleanup
79# 3. preparation (config.pl, cmake, ...) (failure stops the script)
80# 4. make
81# 5. Run tests if relevant. All tests must be prefixed with
82# if_build_successful for the sake of --keep-going.
83
84
85
86################################################################
87#### Initialization and command line parsing
88################################################################
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010089
SimonB2e23c822016-04-16 21:54:39 +010090# Abort on errors (and uninitialised variables)
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010091set -eu
92
Gilles Peskine8f073122018-11-27 15:58:47 +010093pre_check_environment () {
94 if [ "$( uname )" != "Linux" ]; then
95 echo "This script only works in Linux" >&2
96 exit 1
97 elif [ -d library -a -d include -a -d tests ]; then :; else
98 echo "Must be run from mbed TLS root" >&2
99 exit 1
100 fi
101}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100102
Gilles Peskine8f073122018-11-27 15:58:47 +0100103pre_initialize_variables () {
104 CONFIG_H='include/mbedtls/config.h'
105 CONFIG_BAK="$CONFIG_H.bak"
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200106
Gilles Peskine92525112018-11-27 18:15:35 +0100107 COMPONENTS=
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100108 ALL_EXCEPT=0
Gilles Peskine8f073122018-11-27 15:58:47 +0100109 MEMORY=0
110 FORCE=0
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100111 INTROSPECTION_MODE=
Gilles Peskine8f073122018-11-27 15:58:47 +0100112 KEEP_GOING=0
113 RUN_ARMCC=1
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100114
Gilles Peskine8f073122018-11-27 15:58:47 +0100115 # Default commands, can be overriden by the environment
116 : ${OPENSSL:="openssl"}
117 : ${OPENSSL_LEGACY:="$OPENSSL"}
118 : ${OPENSSL_NEXT:="$OPENSSL"}
119 : ${GNUTLS_CLI:="gnutls-cli"}
120 : ${GNUTLS_SERV:="gnutls-serv"}
121 : ${GNUTLS_LEGACY_CLI:="$GNUTLS_CLI"}
122 : ${GNUTLS_LEGACY_SERV:="$GNUTLS_SERV"}
123 : ${OUT_OF_SOURCE_DIR:=./mbedtls_out_of_source_build}
124 : ${ARMC5_BIN_DIR:=/usr/bin}
125 : ${ARMC6_BIN_DIR:=/usr/bin}
Andres AGdc192212016-08-31 17:33:13 +0100126
Gilles Peskine8f073122018-11-27 15:58:47 +0100127 # if MAKEFLAGS is not set add the -j option to speed up invocations of make
128 if [ -n "${MAKEFLAGS+set}" ]; then
129 export MAKEFLAGS="-j"
130 fi
131}
Andres AG38495a32016-07-12 16:54:33 +0100132
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100133# Test whether $1 is excluded via $COMPONENTS (a space-separated list of
134# wildcard patterns).
135component_is_excluded()
136{
137 set -f
138 for pattern in $COMPONENTS; do
139 set +f
140 case ${1#component_} in $pattern) return 0;; esac
141 done
142 set +f
143 return 1
144}
145
Simon Butcher41eeccf2016-09-07 00:07:09 +0100146usage()
SimonB2e23c822016-04-16 21:54:39 +0100147{
Gilles Peskine709346a2017-12-10 23:43:39 +0100148 cat <<EOF
Gilles Peskine92525112018-11-27 18:15:35 +0100149Usage: $0 [OPTION]... [COMPONENT]...
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100150Run mbedtls release validation tests.
Gilles Peskine92525112018-11-27 18:15:35 +0100151By default, run all tests. With one or more COMPONENT, run only those.
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100152
153Special options:
154 -h|--help Print this help and exit.
155 --list-components List available test components and exit.
Gilles Peskine709346a2017-12-10 23:43:39 +0100156
157General options:
158 -f|--force Force the tests to overwrite any modified files.
Gilles Peskine7c652162017-12-11 00:01:40 +0100159 -k|--keep-going Run all tests and report errors at the end.
Gilles Peskine709346a2017-12-10 23:43:39 +0100160 -m|--memory Additional optional memory tests.
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100161 --armcc Run ARM Compiler builds (on by default).
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100162 --except If some components are passed on the command line,
163 run all the tests except for these components. In
164 this mode, you can pass shell wildcard patterns as
165 component names, e.g. "$0 --except 'test_*'" to
166 exclude all components that run tests.
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100167 --no-armcc Skip ARM Compiler builds.
Gilles Peskine38d81652018-03-21 08:40:26 +0100168 --no-force Refuse to overwrite modified files (default).
169 --no-keep-going Stop at the first error (default).
170 --no-memory No additional memory tests (default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100171 --out-of-source-dir=<path> Directory used for CMake out-of-source build tests.
Gilles Peskine38d81652018-03-21 08:40:26 +0100172 --random-seed Use a random seed value for randomized tests (default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100173 -r|--release-test Run this script in release mode. This fixes the seed value to 1.
174 -s|--seed Integer seed value to use for this test run.
175
176Tool path options:
177 --armc5-bin-dir=<ARMC5_bin_dir_path> ARM Compiler 5 bin directory.
178 --armc6-bin-dir=<ARMC6_bin_dir_path> ARM Compiler 6 bin directory.
179 --gnutls-cli=<GnuTLS_cli_path> GnuTLS client executable to use for most tests.
180 --gnutls-serv=<GnuTLS_serv_path> GnuTLS server executable to use for most tests.
181 --gnutls-legacy-cli=<GnuTLS_cli_path> GnuTLS client executable to use for legacy tests.
182 --gnutls-legacy-serv=<GnuTLS_serv_path> GnuTLS server executable to use for legacy tests.
183 --openssl=<OpenSSL_path> OpenSSL executable to use for most tests.
184 --openssl-legacy=<OpenSSL_path> OpenSSL executable to use for legacy tests e.g. SSLv3.
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100185 --openssl-next=<OpenSSL_path> OpenSSL executable to use for recent things like ARIA
Gilles Peskine709346a2017-12-10 23:43:39 +0100186EOF
SimonB2e23c822016-04-16 21:54:39 +0100187}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100188
189# remove built files as well as the cmake cache/config
190cleanup()
191{
Gilles Peskinea71d64c2018-03-21 12:16:57 +0100192 if [ -n "${MBEDTLS_ROOT_DIR+set}" ]; then
193 cd "$MBEDTLS_ROOT_DIR"
194 fi
195
Gilles Peskine7c652162017-12-11 00:01:40 +0100196 command make clean
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200197
Gilles Peskine31b07e22018-03-21 12:15:06 +0100198 # Remove CMake artefacts
Simon Butcher3ad2efd2018-05-02 14:49:38 +0100199 find . -name .git -prune \
Gilles Peskine31b07e22018-03-21 12:15:06 +0100200 -iname CMakeFiles -exec rm -rf {} \+ -o \
201 \( -iname cmake_install.cmake -o \
202 -iname CTestTestfile.cmake -o \
203 -iname CMakeCache.txt \) -exec rm {} \+
204 # Recover files overwritten by in-tree CMake builds
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000205 rm -f include/Makefile include/mbedtls/Makefile programs/*/Makefile
Paul Bakkerfe0984d2014-06-13 00:13:45 +0200206 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile
207 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200208
209 if [ -f "$CONFIG_BAK" ]; then
210 mv "$CONFIG_BAK" "$CONFIG_H"
211 fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100212}
213
Gilles Peskine7c652162017-12-11 00:01:40 +0100214# Executed on exit. May be redefined depending on command line options.
215final_report () {
216 :
217}
218
219fatal_signal () {
220 cleanup
221 final_report $1
222 trap - $1
223 kill -$1 $$
224}
225
226trap 'fatal_signal HUP' HUP
227trap 'fatal_signal INT' INT
228trap 'fatal_signal TERM' TERM
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200229
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100230msg()
231{
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100232 if [ -n "${current_component:-}" ]; then
233 current_section="${current_component#component_}: $1"
234 else
235 current_section="$1"
236 fi
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100237 echo ""
238 echo "******************************************************************"
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100239 echo "* $current_section "
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000240 printf "* "; date
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100241 echo "******************************************************************"
242}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100243
Gilles Peskine8f073122018-11-27 15:58:47 +0100244armc6_build_test()
245{
246 FLAGS="$1"
Andres AGa5cd9732016-10-17 15:23:10 +0100247
Gilles Peskine8f073122018-11-27 15:58:47 +0100248 msg "build: ARM Compiler 6 ($FLAGS), make"
249 ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \
250 WARNING_CFLAGS='-xc -std=c99' make lib
251 make clean
252}
Andres AGa5cd9732016-10-17 15:23:10 +0100253
Andres AGd9eba4b2016-08-26 14:42:14 +0100254err_msg()
255{
256 echo "$1" >&2
257}
258
259check_tools()
260{
261 for TOOL in "$@"; do
Andres AG98393602017-01-31 17:04:45 +0000262 if ! `type "$TOOL" >/dev/null 2>&1`; then
Andres AGd9eba4b2016-08-26 14:42:14 +0100263 err_msg "$TOOL not found!"
264 exit 1
265 fi
266 done
267}
268
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400269check_headers_in_cpp () {
270 ls include/mbedtls >headers.txt
271 <programs/test/cpp_dummy_build.cpp sed -n 's/"$//; s!^#include "mbedtls/!!p' |
272 sort |
273 diff headers.txt -
274 rm headers.txt
275}
276
Gilles Peskine8f073122018-11-27 15:58:47 +0100277pre_parse_command_line () {
278 while [ $# -gt 0 ]; do
279 case "$1" in
280 --armcc) RUN_ARMCC=1;;
281 --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
282 --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100283 --except) ALL_EXCEPT=1;;
Gilles Peskine8f073122018-11-27 15:58:47 +0100284 --force|-f) FORCE=1;;
285 --gnutls-cli) shift; GNUTLS_CLI="$1";;
286 --gnutls-legacy-cli) shift; GNUTLS_LEGACY_CLI="$1";;
287 --gnutls-legacy-serv) shift; GNUTLS_LEGACY_SERV="$1";;
288 --gnutls-serv) shift; GNUTLS_SERV="$1";;
289 --help|-h) usage; exit;;
290 --keep-going|-k) KEEP_GOING=1;;
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100291 --list-components) INTROSPECTION_MODE=list_components;;
Gilles Peskine8f073122018-11-27 15:58:47 +0100292 --memory|-m) MEMORY=1;;
293 --no-armcc) RUN_ARMCC=0;;
294 --no-force) FORCE=0;;
295 --no-keep-going) KEEP_GOING=0;;
296 --no-memory) MEMORY=0;;
297 --openssl) shift; OPENSSL="$1";;
298 --openssl-legacy) shift; OPENSSL_LEGACY="$1";;
299 --openssl-next) shift; OPENSSL_NEXT="$1";;
300 --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
301 --random-seed) unset SEED;;
302 --release-test|-r) SEED=1;;
303 --seed|-s) shift; SEED="$1";;
Gilles Peskine92525112018-11-27 18:15:35 +0100304 -*)
Gilles Peskine8f073122018-11-27 15:58:47 +0100305 echo >&2 "Unknown option: $1"
306 echo >&2 "Run $0 --help for usage."
307 exit 120
308 ;;
Gilles Peskine92525112018-11-27 18:15:35 +0100309 *)
310 COMPONENTS="$COMPONENTS $1";;
Gilles Peskine8f073122018-11-27 15:58:47 +0100311 esac
312 shift
313 done
314}
SimonB2e23c822016-04-16 21:54:39 +0100315
Gilles Peskine8f073122018-11-27 15:58:47 +0100316pre_check_git () {
317 if [ $FORCE -eq 1 ]; then
318 git checkout-index -f -q $CONFIG_H
319 cleanup
320 else
SimonB2e23c822016-04-16 21:54:39 +0100321
Gilles Peskine8f073122018-11-27 15:58:47 +0100322 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
323 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
324 echo "You can either delete this directory manually, or force the test by rerunning"
325 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
326 exit 1
327 fi
328
329 if ! git diff-files --quiet include/mbedtls/config.h; then
330 err_msg "Warning - the configuration file 'include/mbedtls/config.h' has been edited. "
331 echo "You can either delete or preserve your work, or force the test by rerunning the"
332 echo "script as: $0 --force"
333 exit 1
334 fi
Andres AGdc192212016-08-31 17:33:13 +0100335 fi
Gilles Peskine8f073122018-11-27 15:58:47 +0100336}
Andres AGdc192212016-08-31 17:33:13 +0100337
Gilles Peskine8f073122018-11-27 15:58:47 +0100338pre_setup_keep_going () {
Gilles Peskine7c652162017-12-11 00:01:40 +0100339 failure_summary=
340 failure_count=0
341 start_red=
342 end_color=
343 if [ -t 1 ]; then
Gilles Peskine9736b9d2018-01-02 21:54:17 +0100344 case "${TERM:-}" in
Gilles Peskine7c652162017-12-11 00:01:40 +0100345 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
346 start_red=$(printf '\033[31m')
347 end_color=$(printf '\033[0m')
348 ;;
349 esac
350 fi
351 record_status () {
352 if "$@"; then
353 last_status=0
354 else
355 last_status=$?
356 text="$current_section: $* -> $last_status"
357 failure_summary="$failure_summary
358$text"
359 failure_count=$((failure_count + 1))
360 echo "${start_red}^^^^$text^^^^${end_color}"
361 fi
362 }
363 make () {
364 case "$*" in
365 *test|*check)
366 if [ $build_status -eq 0 ]; then
367 record_status command make "$@"
368 else
369 echo "(skipped because the build failed)"
370 fi
371 ;;
372 *)
373 record_status command make "$@"
374 build_status=$last_status
375 ;;
376 esac
377 }
378 final_report () {
379 if [ $failure_count -gt 0 ]; then
380 echo
381 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
382 echo "${start_red}FAILED: $failure_count${end_color}$failure_summary"
383 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Jaeden Amero7c1258d2018-07-20 16:42:14 +0100384 exit 1
Gilles Peskine7c652162017-12-11 00:01:40 +0100385 elif [ -z "${1-}" ]; then
386 echo "SUCCESS :)"
387 fi
388 if [ -n "${1-}" ]; then
389 echo "Killed by SIG$1."
390 fi
391 }
Gilles Peskine8f073122018-11-27 15:58:47 +0100392}
393
Gilles Peskine7c652162017-12-11 00:01:40 +0100394if_build_succeeded () {
395 if [ $build_status -eq 0 ]; then
396 record_status "$@"
397 fi
398}
399
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200400# to be used instead of ! for commands run with
401# record_status or if_build_succeeded
402not() {
403 ! "$@"
404}
405
Gilles Peskine8f073122018-11-27 15:58:47 +0100406pre_print_configuration () {
407 msg "info: $0 configuration"
408 echo "MEMORY: $MEMORY"
409 echo "FORCE: $FORCE"
410 echo "SEED: ${SEED-"UNSET"}"
411 echo "OPENSSL: $OPENSSL"
412 echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
413 echo "OPENSSL_NEXT: $OPENSSL_NEXT"
414 echo "GNUTLS_CLI: $GNUTLS_CLI"
415 echo "GNUTLS_SERV: $GNUTLS_SERV"
416 echo "GNUTLS_LEGACY_CLI: $GNUTLS_LEGACY_CLI"
417 echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV"
418 echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
419 echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
420}
Andres AG87bb5772016-09-27 15:05:15 +0100421
Gilles Peskine8f073122018-11-27 15:58:47 +0100422pre_check_tools () {
423 ARMC5_CC="$ARMC5_BIN_DIR/armcc"
424 ARMC5_AR="$ARMC5_BIN_DIR/armar"
425 ARMC6_CC="$ARMC6_BIN_DIR/armclang"
426 ARMC6_AR="$ARMC6_BIN_DIR/armar"
Andres AGd9eba4b2016-08-26 14:42:14 +0100427
Gilles Peskine8f073122018-11-27 15:58:47 +0100428 # To avoid setting OpenSSL and GnuTLS for each call to compat.sh and ssl-opt.sh
429 # we just export the variables they require
430 export OPENSSL_CMD="$OPENSSL"
431 export GNUTLS_CLI="$GNUTLS_CLI"
432 export GNUTLS_SERV="$GNUTLS_SERV"
Andres AGb2fdd042016-09-22 14:17:46 +0100433
Gilles Peskine8f073122018-11-27 15:58:47 +0100434 # Avoid passing --seed flag in every call to ssl-opt.sh
435 if [ -n "${SEED-}" ]; then
436 export SEED
437 fi
Andres AG7770ea82016-10-10 15:46:20 +0100438
Gilles Peskine8f073122018-11-27 15:58:47 +0100439 # Make sure the tools we need are available.
440 check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$OPENSSL_NEXT" \
441 "$GNUTLS_CLI" "$GNUTLS_SERV" \
442 "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV" "doxygen" "dot" \
443 "arm-none-eabi-gcc" "i686-w64-mingw32-gcc" "gdb"
444 if [ $RUN_ARMCC -ne 0 ]; then
445 check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC6_CC" "$ARMC6_AR"
446 fi
447}
Gilles Peskine192c72f2017-12-21 15:59:21 +0100448
449
450################################################################
451#### Basic checks
452################################################################
Andres AGd9eba4b2016-08-26 14:42:14 +0100453
SimonB2e23c822016-04-16 21:54:39 +0100454#
455# Test Suites to be executed
456#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200457# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100458# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard61bc57a2014-08-14 11:29:06 +0200459# and/or are more likely to fail than others (eg I use Clang most of the
460# time, so start with a GCC build).
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200461# 2. Minimize total running time, by avoiding useless rebuilds
462#
463# Indicative running times are given for reference.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100464
Gilles Peskine8f073122018-11-27 15:58:47 +0100465pre_print_tools () {
466 msg "info: output_env.sh"
467 OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY" GNUTLS_CLI="$GNUTLS_CLI" \
468 GNUTLS_SERV="$GNUTLS_SERV" GNUTLS_LEGACY_CLI="$GNUTLS_LEGACY_CLI" \
469 GNUTLS_LEGACY_SERV="$GNUTLS_LEGACY_SERV" ARMC5_CC="$ARMC5_CC" \
470 ARMC6_CC="$ARMC6_CC" RUN_ARMCC="$RUN_ARMCC" scripts/output_env.sh
471}
Janos Follathb72c6782016-07-19 14:54:17 +0100472
Gilles Peskine8f073122018-11-27 15:58:47 +0100473component_check_recursion () {
474 msg "test: recursion.pl" # < 1s
475 record_status tests/scripts/recursion.pl library/*.c
476}
Manuel Pégourié-Gonnardea29d152014-11-20 17:32:33 +0100477
Gilles Peskine8f073122018-11-27 15:58:47 +0100478component_check_generated_files () {
479 msg "test: freshness of generated source files" # < 1s
480 record_status tests/scripts/check-generated-files.sh
481}
Manuel Pégourié-Gonnardb3b8e432015-02-13 14:52:19 +0000482
Gilles Peskine8f073122018-11-27 15:58:47 +0100483component_check_doxy_blocks () {
484 msg "test: doxygen markup outside doxygen blocks" # < 1s
485 record_status tests/scripts/check-doxy-blocks.pl
486}
Manuel Pégourié-Gonnardd09a6b52015-04-09 17:19:23 +0200487
Gilles Peskine8f073122018-11-27 15:58:47 +0100488component_check_files () {
489 msg "test: check-files.py" # < 1s
Gilles Peskine8f073122018-11-27 15:58:47 +0100490 record_status tests/scripts/check-files.py
491}
Darryl Greena07039c2018-03-13 16:48:16 +0000492
Gilles Peskine8f073122018-11-27 15:58:47 +0100493component_check_names () {
494 msg "test/build: declared and exported names" # < 3s
Gilles Peskine8f073122018-11-27 15:58:47 +0100495 record_status tests/scripts/check-names.sh
496}
Manuel Pégourié-Gonnarda687baf2015-04-09 11:09:03 +0200497
Gilles Peskine8f073122018-11-27 15:58:47 +0100498component_check_doxygen_warnings () {
499 msg "test: doxygen warnings" # ~ 3s
Gilles Peskine8f073122018-11-27 15:58:47 +0100500 record_status tests/scripts/doxygen.sh
501}
Manuel Pégourié-Gonnard1d552e72016-01-04 16:49:09 +0100502
Gilles Peskine192c72f2017-12-21 15:59:21 +0100503
504
505################################################################
506#### Build and test many configurations and targets
507################################################################
508
Gilles Peskine8f073122018-11-27 15:58:47 +0100509component_test_default_cmake_gcc_asan () {
510 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100511 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
512 make
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100513
Gilles Peskine8f073122018-11-27 15:58:47 +0100514 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
515 make test
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200516
Gilles Peskine8f073122018-11-27 15:58:47 +0100517 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
518 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200519
Gilles Peskine8f073122018-11-27 15:58:47 +0100520 msg "test: compat.sh (ASan build)" # ~ 6 min
521 if_build_succeeded tests/compat.sh
522}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200523
Gilles Peskine782f4112018-11-27 16:11:09 +0100524component_test_ref_configs () {
525 msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
526 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
527 record_status tests/scripts/test-ref-configs.pl
528}
529
Gilles Peskine8f073122018-11-27 15:58:47 +0100530component_test_sslv3 () {
531 msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100532 cp "$CONFIG_H" "$CONFIG_BAK"
533 scripts/config.pl set MBEDTLS_SSL_PROTO_SSL3
534 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
535 make
Simon Butcher3ea7f522016-03-07 23:22:10 +0000536
Gilles Peskine8f073122018-11-27 15:58:47 +0100537 msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
538 make test
Simon Butcher3ea7f522016-03-07 23:22:10 +0000539
Gilles Peskine8f073122018-11-27 15:58:47 +0100540 msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
541 if_build_succeeded tests/compat.sh -m 'tls1 tls1_1 tls1_2 dtls1 dtls1_2'
542 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
Simon Butcher3ea7f522016-03-07 23:22:10 +0000543
Gilles Peskine8f073122018-11-27 15:58:47 +0100544 msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
545 if_build_succeeded tests/ssl-opt.sh
546}
Simon Butcher3ea7f522016-03-07 23:22:10 +0000547
Gilles Peskine8f073122018-11-27 15:58:47 +0100548component_test_no_renegotiation () {
549 msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100550 cp "$CONFIG_H" "$CONFIG_BAK"
551 scripts/config.pl unset MBEDTLS_SSL_RENEGOTIATION
552 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
553 make
Hanno Becker134c2ab2017-10-12 15:29:50 +0100554
Gilles Peskine8f073122018-11-27 15:58:47 +0100555 msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
556 make test
Hanno Becker134c2ab2017-10-12 15:29:50 +0100557
Gilles Peskine8f073122018-11-27 15:58:47 +0100558 msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
559 if_build_succeeded tests/ssl-opt.sh
560}
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +0100561
Gilles Peskine8f073122018-11-27 15:58:47 +0100562component_test_rsa_no_crt () {
563 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100564 cp "$CONFIG_H" "$CONFIG_BAK"
565 scripts/config.pl set MBEDTLS_RSA_NO_CRT
566 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
567 make
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100568
Gilles Peskine8f073122018-11-27 15:58:47 +0100569 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
570 make test
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100571
Gilles Peskine8f073122018-11-27 15:58:47 +0100572 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
573 if_build_succeeded tests/ssl-opt.sh -f RSA
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100574
Gilles Peskine8f073122018-11-27 15:58:47 +0100575 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
576 if_build_succeeded tests/compat.sh -t RSA
577}
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100578
Gilles Peskine8f073122018-11-27 15:58:47 +0100579component_test_small_ssl_out_content_len () {
580 msg "build: small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100581 cp "$CONFIG_H" "$CONFIG_BAK"
582 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 16384
583 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
584 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
585 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000586
Gilles Peskine8f073122018-11-27 15:58:47 +0100587 msg "test: small SSL_OUT_CONTENT_LEN - ssl-opt.sh MFL and large packet tests"
588 if_build_succeeded tests/ssl-opt.sh -f "Max fragment\|Large packet"
589}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000590
Gilles Peskine8f073122018-11-27 15:58:47 +0100591component_test_small_ssl_in_content_len () {
592 msg "build: small SSL_IN_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100593 cp "$CONFIG_H" "$CONFIG_BAK"
594 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 4096
595 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 16384
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_IN_CONTENT_LEN - ssl-opt.sh MFL tests"
600 if_build_succeeded tests/ssl-opt.sh -f "Max fragment"
601}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000602
Gilles Peskine8f073122018-11-27 15:58:47 +0100603component_test_small_ssl_dtls_max_buffering () {
604 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0"
Gilles Peskine8f073122018-11-27 15:58:47 +0100605 cp "$CONFIG_H" "$CONFIG_BAK"
606 scripts/config.pl set MBEDTLS_SSL_DTLS_MAX_BUFFERING 1000
607 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
608 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100609
Gilles Peskine8f073122018-11-27 15:58:47 +0100610 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0 - ssl-opt.sh specific reordering test"
611 if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer out-of-order hs msg before reassembling next, free buffered msg"
612}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100613
Gilles Peskine8f073122018-11-27 15:58:47 +0100614component_test_small_mbedtls_ssl_dtls_max_buffering () {
615 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1"
Gilles Peskine8f073122018-11-27 15:58:47 +0100616 cp "$CONFIG_H" "$CONFIG_BAK"
617 scripts/config.pl set MBEDTLS_SSL_DTLS_MAX_BUFFERING 240
618 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
619 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100620
Gilles Peskine8f073122018-11-27 15:58:47 +0100621 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1 - ssl-opt.sh specific reordering test"
622 if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer encrypted Finished message, drop for fragmented NewSessionTicket"
623}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100624
Gilles Peskine8f073122018-11-27 15:58:47 +0100625component_test_full_cmake_clang () {
626 msg "build: cmake, full config, clang" # ~ 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100627 cp "$CONFIG_H" "$CONFIG_BAK"
628 scripts/config.pl full
629 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
630 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check -D ENABLE_TESTING=On .
631 make
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100632
Gilles Peskine8f073122018-11-27 15:58:47 +0100633 msg "test: main suites (full config)" # ~ 5s
634 make test
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200635
Gilles Peskine8f073122018-11-27 15:58:47 +0100636 msg "test: ssl-opt.sh default, ECJPAKE, SSL async (full config)" # ~ 1s
637 if_build_succeeded tests/ssl-opt.sh -f 'Default\|ECJPAKE\|SSL async private'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200638
Gilles Peskine8f073122018-11-27 15:58:47 +0100639 msg "test: compat.sh RC4, DES & NULL (full config)" # ~ 2 min
640 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 +0200641
Gilles Peskine8f073122018-11-27 15:58:47 +0100642 msg "test: compat.sh ARIA + ChachaPoly"
643 if_build_succeeded env OPENSSL_CMD="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
644}
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100645
Gilles Peskine8f073122018-11-27 15:58:47 +0100646component_build_deprecated () {
647 msg "build: make, full config + DEPRECATED_WARNING, gcc -O" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100648 cp "$CONFIG_H" "$CONFIG_BAK"
649 scripts/config.pl full
650 scripts/config.pl set MBEDTLS_DEPRECATED_WARNING
651 # Build with -O -Wextra to catch a maximum of issues.
652 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra' lib programs
653 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
Gilles Peskineb4ef45b2018-03-01 22:23:50 +0100654
Gilles Peskine8f073122018-11-27 15:58:47 +0100655 msg "build: make, full config + DEPRECATED_REMOVED, clang -O" # ~ 30s
656 # No cleanup, just tweak the configuration and rebuild
657 make clean
658 scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
659 scripts/config.pl set MBEDTLS_DEPRECATED_REMOVED
660 # Build with -O -Wextra to catch a maximum of issues.
661 make CC=clang CFLAGS='-O -Werror -Wall -Wextra' lib programs
662 make CC=clang CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
663}
Gilles Peskine0afe6242018-02-21 19:28:12 +0100664
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200665
Gilles Peskine8f073122018-11-27 15:58:47 +0100666component_test_depends_curves () {
667 msg "test/build: curves.pl (gcc)" # ~ 4 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100668 record_status tests/scripts/curves.pl
669}
Manuel Pégourié-Gonnard1fe6bb92017-06-06 11:36:16 +0200670
Gilles Peskine8f073122018-11-27 15:58:47 +0100671component_test_depends_hashes () {
672 msg "test/build: depends-hashes.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100673 record_status tests/scripts/depends-hashes.pl
674}
Manuel Pégourié-Gonnard43be6cd2017-06-20 09:53:42 +0200675
Gilles Peskine8f073122018-11-27 15:58:47 +0100676component_test_depends_pkalgs () {
677 msg "test/build: depends-pkalgs.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100678 record_status tests/scripts/depends-pkalgs.pl
679}
Manuel Pégourié-Gonnard503a5ef2015-10-23 09:04:45 +0200680
Gilles Peskine8f073122018-11-27 15:58:47 +0100681component_build_key_exchanges () {
682 msg "test/build: key-exchanges (gcc)" # ~ 1 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100683 record_status tests/scripts/key-exchanges.pl
684}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100685
Gilles Peskine8f073122018-11-27 15:58:47 +0100686component_build_default_make_gcc_and_cxx () {
687 msg "build: Unix make, -Os (gcc)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100688 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400689
Gilles Peskine8f073122018-11-27 15:58:47 +0100690 msg "test: verify header list in cpp_dummy_build.cpp"
691 record_status check_headers_in_cpp
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400692
Gilles Peskine8f073122018-11-27 15:58:47 +0100693 msg "build: Unix make, incremental g++"
694 make TEST_CPP=1
695}
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +0000696
Gilles Peskine8f073122018-11-27 15:58:47 +0100697component_test_no_platform () {
698 # Full configuration build, without platform support, file IO and net sockets.
699 # This should catch missing mbedtls_printf definitions, and by disabling file
700 # IO, it should catch missing '#include <stdio.h>'
701 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100702 cp "$CONFIG_H" "$CONFIG_BAK"
703 scripts/config.pl full
704 scripts/config.pl unset MBEDTLS_PLATFORM_C
705 scripts/config.pl unset MBEDTLS_NET_C
706 scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
707 scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
708 scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
709 scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
710 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
711 scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
712 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
713 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
714 scripts/config.pl unset MBEDTLS_FS_IO
715 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
716 # to re-enable platform integration features otherwise disabled in C99 builds
717 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -O0 -D_DEFAULT_SOURCE' lib programs
718 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0' test
719}
Manuel Pégourié-Gonnarddccb80b2015-06-03 10:20:33 +0100720
Gilles Peskine8f073122018-11-27 15:58:47 +0100721component_build_no_std_function () {
722 # catch compile bugs in _uninit functions
723 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100724 cp "$CONFIG_H" "$CONFIG_BAK"
725 scripts/config.pl full
726 scripts/config.pl set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
727 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
728 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
729}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200730
Gilles Peskine8f073122018-11-27 15:58:47 +0100731component_build_no_ssl_srv () {
732 msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100733 cp "$CONFIG_H" "$CONFIG_BAK"
734 scripts/config.pl full
735 scripts/config.pl unset MBEDTLS_SSL_SRV_C
736 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
737}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200738
Gilles Peskine8f073122018-11-27 15:58:47 +0100739component_build_no_ssl_cli () {
740 msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100741 cp "$CONFIG_H" "$CONFIG_BAK"
742 scripts/config.pl full
743 scripts/config.pl unset MBEDTLS_SSL_CLI_C
744 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
745}
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +0200746
Gilles Peskine8f073122018-11-27 15:58:47 +0100747component_build_no_sockets () {
748 # Note, C99 compliance can also be tested with the sockets support disabled,
749 # as that requires a POSIX platform (which isn't the same as C99).
750 msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100751 cp "$CONFIG_H" "$CONFIG_BAK"
752 scripts/config.pl full
753 scripts/config.pl unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
754 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
755 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0 -std=c99 -pedantic' lib
756}
Hanno Becker5175ac62017-09-18 15:36:25 +0100757
Gilles Peskine8f073122018-11-27 15:58:47 +0100758component_test_no_max_fragment_length () {
759 # Run max fragment length tests with MFL disabled
760 msg "build: default config except MFL extension (ASan build)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100761 cp "$CONFIG_H" "$CONFIG_BAK"
762 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
763 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
764 make
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000765
Gilles Peskine8f073122018-11-27 15:58:47 +0100766 msg "test: ssl-opt.sh, MFL-related tests"
767 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length"
768}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000769
Gilles Peskine8f073122018-11-27 15:58:47 +0100770component_test_no_max_fragment_length_small_ssl_out_content_len () {
771 msg "build: no MFL extension, small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100772 cp "$CONFIG_H" "$CONFIG_BAK"
773 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
774 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 16384
775 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
776 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
777 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000778
Gilles Peskine8f073122018-11-27 15:58:47 +0100779 msg "test: MFL tests (disabled MFL extension case) & large packet tests"
780 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length\|Large buffer"
781}
Janos Follath06c54002016-06-09 13:57:40 +0100782
Gilles Peskine8f073122018-11-27 15:58:47 +0100783component_test_null_entropy () {
784 msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100785 cp "$CONFIG_H" "$CONFIG_BAK"
786 scripts/config.pl set MBEDTLS_TEST_NULL_ENTROPY
787 scripts/config.pl set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
788 scripts/config.pl set MBEDTLS_ENTROPY_C
789 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
790 scripts/config.pl unset MBEDTLS_ENTROPY_HARDWARE_ALT
791 scripts/config.pl unset MBEDTLS_HAVEGE_C
792 CC=gcc cmake -D UNSAFE_BUILD=ON -D CMAKE_C_FLAGS:String="-fsanitize=address -fno-common -O3" .
793 make
Janos Follath06c54002016-06-09 13:57:40 +0100794
Gilles Peskine8f073122018-11-27 15:58:47 +0100795 msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)"
796 make test
797}
Hanno Beckere5fecec2018-10-11 11:02:52 +0100798
Gilles Peskine8f073122018-11-27 15:58:47 +0100799component_test_platform_calloc_macro () {
800 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100801 cp "$CONFIG_H" "$CONFIG_BAK"
802 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 cp "$CONFIG_H" "$CONFIG_BAK"
815 scripts/config.pl set MBEDTLS_AES_FEWER_TABLES
816 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +0100817
Gilles Peskine8f073122018-11-27 15:58:47 +0100818 msg "test: AES_FEWER_TABLES"
819 make test
820}
Hanno Becker83ebf782017-07-07 12:29:15 +0100821
Gilles Peskine8f073122018-11-27 15:58:47 +0100822component_test_aes_rom_tables () {
823 msg "build: default config with AES_ROM_TABLES enabled"
Gilles Peskine8f073122018-11-27 15:58:47 +0100824 cp "$CONFIG_H" "$CONFIG_BAK"
825 scripts/config.pl set MBEDTLS_AES_ROM_TABLES
826 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +0100827
Gilles Peskine8f073122018-11-27 15:58:47 +0100828 msg "test: AES_ROM_TABLES"
829 make test
830}
Hanno Becker83ebf782017-07-07 12:29:15 +0100831
Gilles Peskine8f073122018-11-27 15:58:47 +0100832component_test_aes_fewer_tables_and_rom_tables () {
833 msg "build: default config with AES_ROM_TABLES and AES_FEWER_TABLES enabled"
Gilles Peskine8f073122018-11-27 15:58:47 +0100834 cp "$CONFIG_H" "$CONFIG_BAK"
835 scripts/config.pl set MBEDTLS_AES_FEWER_TABLES
836 scripts/config.pl set MBEDTLS_AES_ROM_TABLES
837 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +0100838
Gilles Peskine8f073122018-11-27 15:58:47 +0100839 msg "test: AES_FEWER_TABLES + AES_ROM_TABLES"
840 make test
841}
842
843component_test_make_shared () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100844 msg "build/test: make shared" # ~ 40s
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100845 make SHARED=1 all check
Gilles Peskine8f073122018-11-27 15:58:47 +0100846}
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +0200847
Gilles Peskine8f073122018-11-27 15:58:47 +0100848component_test_m32_o0 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100849 # Build once with -O0, to compile out the i386 specific inline assembly
850 msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
Simon Butcher7a6da6e2018-06-27 21:52:54 +0100851 cp "$CONFIG_H" "$CONFIG_BAK"
852 scripts/config.pl full
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100853 make CC=gcc CFLAGS='-O0 -Werror -Wall -Wextra -m32 -fsanitize=address'
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +0100854
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100855 msg "test: i386, make, gcc -O0 (ASan build)"
856 make test
Gilles Peskine8f073122018-11-27 15:58:47 +0100857}
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100858
Gilles Peskine8f073122018-11-27 15:58:47 +0100859component_test_m32_o1 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100860 # Build again with -O1, to compile in the i386 specific inline assembly
861 msg "build: i386, make, gcc -O1 (ASan build)" # ~ 30s
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100862 cp "$CONFIG_H" "$CONFIG_BAK"
863 scripts/config.pl full
864 make CC=gcc CFLAGS='-O1 -Werror -Wall -Wextra -m32 -fsanitize=address'
865
866 msg "test: i386, make, gcc -O1 (ASan build)"
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +0100867 make test
Gilles Peskine8f073122018-11-27 15:58:47 +0100868}
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +0100869
Gilles Peskine8f073122018-11-27 15:58:47 +0100870component_test_mx32 () {
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +0100871 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
Simon Butcher7a6da6e2018-06-27 21:52:54 +0100872 cp "$CONFIG_H" "$CONFIG_BAK"
873 scripts/config.pl full
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +0100874 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32'
875
876 msg "test: 64-bit ILP32, make, gcc"
877 make test
Gilles Peskine8f073122018-11-27 15:58:47 +0100878}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000879
Gilles Peskine8f073122018-11-27 15:58:47 +0100880component_test_have_int32 () {
881 msg "build: gcc, force 32-bit bignum limbs"
Gilles Peskine8f073122018-11-27 15:58:47 +0100882 cp "$CONFIG_H" "$CONFIG_BAK"
883 scripts/config.pl unset MBEDTLS_HAVE_ASM
884 scripts/config.pl unset MBEDTLS_AESNI_C
885 scripts/config.pl unset MBEDTLS_PADLOCK_C
886 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +0100887
Gilles Peskine8f073122018-11-27 15:58:47 +0100888 msg "test: gcc, force 32-bit bignum limbs"
889 make test
890}
Andres Amaya Garciafe843a32017-07-20 13:21:34 +0100891
Gilles Peskine8f073122018-11-27 15:58:47 +0100892component_test_have_int64 () {
893 msg "build: gcc, force 64-bit bignum limbs"
Gilles Peskine8f073122018-11-27 15:58:47 +0100894 cp "$CONFIG_H" "$CONFIG_BAK"
895 scripts/config.pl unset MBEDTLS_HAVE_ASM
896 scripts/config.pl unset MBEDTLS_AESNI_C
897 scripts/config.pl unset MBEDTLS_PADLOCK_C
898 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
Gilles Peskine14c3c062018-01-29 21:25:12 +0100899
Gilles Peskine8f073122018-11-27 15:58:47 +0100900 msg "test: gcc, force 64-bit bignum limbs"
901 make test
902}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000903
Gilles Peskine8f073122018-11-27 15:58:47 +0100904component_test_no_udbl_division () {
905 msg "build: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +0100906 cp "$CONFIG_H" "$CONFIG_BAK"
907 scripts/config.pl full
908 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
909 scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
910 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200911
Gilles Peskine8f073122018-11-27 15:58:47 +0100912 msg "test: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
913 make test
914}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200915
Gilles Peskine8f073122018-11-27 15:58:47 +0100916component_test_no_64bit_multiplication () {
917 msg "build: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +0100918 cp "$CONFIG_H" "$CONFIG_BAK"
919 scripts/config.pl full
920 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
921 scripts/config.pl set MBEDTLS_NO_64BIT_MULTIPLICATION
922 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200923
Gilles Peskine8f073122018-11-27 15:58:47 +0100924 msg "test: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
925 make test
926}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200927
Gilles Peskine8f073122018-11-27 15:58:47 +0100928component_build_arm_none_eabi_gcc () {
929 msg "build: arm-none-eabi-gcc, make" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +0100930 cp "$CONFIG_H" "$CONFIG_BAK"
931 scripts/config.pl full
932 scripts/config.pl unset MBEDTLS_NET_C
933 scripts/config.pl unset MBEDTLS_TIMING_C
934 scripts/config.pl unset MBEDTLS_FS_IO
935 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
936 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
937 # following things are not in the default config
938 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
939 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
940 scripts/config.pl unset MBEDTLS_THREADING_C
941 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
942 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
943 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
944}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200945
Gilles Peskine8f073122018-11-27 15:58:47 +0100946component_build_arm_none_eabi_gcc_no_udbl_division () {
947 msg "build: arm-none-eabi-gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +0100948 cp "$CONFIG_H" "$CONFIG_BAK"
949 scripts/config.pl full
950 scripts/config.pl unset MBEDTLS_NET_C
951 scripts/config.pl unset MBEDTLS_TIMING_C
952 scripts/config.pl unset MBEDTLS_FS_IO
953 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
954 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
955 # following things are not in the default config
956 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
957 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
958 scripts/config.pl unset MBEDTLS_THREADING_C
959 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
960 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
961 scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
962 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
963 echo "Checking that software 64-bit division is not required"
964 if_build_succeeded not grep __aeabi_uldiv library/*.o
965}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200966
Gilles Peskine8f073122018-11-27 15:58:47 +0100967component_build_arm_none_eabi_gcc_no_64bit_multiplication () {
968 msg "build: arm-none-eabi-gcc MBEDTLS_NO_64BIT_MULTIPLICATION, make" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +0100969 cp "$CONFIG_H" "$CONFIG_BAK"
970 scripts/config.pl full
971 scripts/config.pl unset MBEDTLS_NET_C
972 scripts/config.pl unset MBEDTLS_TIMING_C
973 scripts/config.pl unset MBEDTLS_FS_IO
974 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
975 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
976 # following things are not in the default config
977 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
978 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
979 scripts/config.pl unset MBEDTLS_THREADING_C
980 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
981 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
982 scripts/config.pl set MBEDTLS_NO_64BIT_MULTIPLICATION
983 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -O1 -march=armv6-m -mthumb' lib
984 echo "Checking that software 64-bit multiplication is not required"
985 if_build_succeeded not grep __aeabi_lmul library/*.o
986}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200987
Gilles Peskine8f073122018-11-27 15:58:47 +0100988component_build_armcc () {
989 msg "build: ARM Compiler 5, make"
Gilles Peskine8f073122018-11-27 15:58:47 +0100990 cp "$CONFIG_H" "$CONFIG_BAK"
991 scripts/config.pl full
992 scripts/config.pl unset MBEDTLS_NET_C
993 scripts/config.pl unset MBEDTLS_TIMING_C
994 scripts/config.pl unset MBEDTLS_FS_IO
995 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
996 scripts/config.pl unset MBEDTLS_HAVE_TIME
997 scripts/config.pl unset MBEDTLS_HAVE_TIME_DATE
998 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
999 # following things are not in the default config
1000 scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
1001 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
1002 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
1003 scripts/config.pl unset MBEDTLS_THREADING_C
1004 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
1005 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
1006 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT # depends on MBEDTLS_HAVE_TIME
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001007
Gilles Peskine8f073122018-11-27 15:58:47 +01001008 if [ $RUN_ARMCC -ne 0 ]; then
1009 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
1010 make clean
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001011
Gilles Peskine8f073122018-11-27 15:58:47 +01001012 # ARM Compiler 6 - Target ARMv7-A
1013 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-a"
Gilles Peskineed942f82017-06-08 15:19:20 +02001014
Gilles Peskine8f073122018-11-27 15:58:47 +01001015 # ARM Compiler 6 - Target ARMv7-M
1016 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m"
Andres AG87bb5772016-09-27 15:05:15 +01001017
Gilles Peskine8f073122018-11-27 15:58:47 +01001018 # ARM Compiler 6 - Target ARMv8-A - AArch32
1019 armc6_build_test "--target=arm-arm-none-eabi -march=armv8.2-a"
Andres AG87bb5772016-09-27 15:05:15 +01001020
Gilles Peskine8f073122018-11-27 15:58:47 +01001021 # ARM Compiler 6 - Target ARMv8-M
1022 armc6_build_test "--target=arm-arm-none-eabi -march=armv8-m.main"
Simon Butcher940737f2017-07-23 13:42:36 +02001023
Gilles Peskine8f073122018-11-27 15:58:47 +01001024 # ARM Compiler 6 - Target ARMv8-A - AArch64
1025 armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a"
1026 fi
1027}
Simon Butcher940737f2017-07-23 13:42:36 +02001028
Gilles Peskine8f073122018-11-27 15:58:47 +01001029component_test_allow_sha1 () {
1030 msg "build: allow SHA1 in certificates by default"
Gilles Peskine8f073122018-11-27 15:58:47 +01001031 cp "$CONFIG_H" "$CONFIG_BAK"
1032 scripts/config.pl set MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
1033 make CFLAGS='-Werror -Wall -Wextra'
1034 msg "test: allow SHA1 in certificates by default"
1035 make test
1036 if_build_succeeded tests/ssl-opt.sh -f SHA-1
1037}
Simon Butcher940737f2017-07-23 13:42:36 +02001038
Gilles Peskine8f073122018-11-27 15:58:47 +01001039component_build_mingw () {
1040 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +01001041 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 +02001042
Gilles Peskine8f073122018-11-27 15:58:47 +01001043 # note Make tests only builds the tests, but doesn't run them
1044 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror' WINDOWS_BUILD=1 tests
1045 make WINDOWS_BUILD=1 clean
Hanno Beckere963efa2018-01-03 10:03:43 +00001046
Gilles Peskine8f073122018-11-27 15:58:47 +01001047 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
1048 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
1049 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
1050 make WINDOWS_BUILD=1 clean
1051}
Simon Butcher002bc622016-11-17 09:27:45 +00001052
Gilles Peskine8f073122018-11-27 15:58:47 +01001053component_test_memsan () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001054 msg "build: MSan (clang)" # ~ 1 min 20s
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001055 cp "$CONFIG_H" "$CONFIG_BAK"
1056 scripts/config.pl unset MBEDTLS_AESNI_C # memsan doesn't grok asm
1057 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
1058 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +02001059
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001060 msg "test: main suites (MSan)" # ~ 10s
1061 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001062
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001063 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
Gilles Peskine7c652162017-12-11 00:01:40 +01001064 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001065
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001066 # Optional part(s)
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001067
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001068 if [ "$MEMORY" -gt 0 ]; then
1069 msg "test: compat.sh (MSan)" # ~ 6 min 20s
Gilles Peskine7c652162017-12-11 00:01:40 +01001070 if_build_succeeded tests/compat.sh
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001071 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001072}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001073
Gilles Peskine8f073122018-11-27 15:58:47 +01001074component_test_memcheck () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001075 msg "build: Release (clang)"
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001076 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
1077 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001078
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001079 msg "test: main suites valgrind (Release)"
1080 make memcheck
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001081
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001082 # Optional part(s)
1083 # Currently broken, programs don't seem to receive signals
1084 # under valgrind on OS X
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001085
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001086 if [ "$MEMORY" -gt 0 ]; then
1087 msg "test: ssl-opt.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +01001088 if_build_succeeded tests/ssl-opt.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001089 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001090
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001091 if [ "$MEMORY" -gt 1 ]; then
1092 msg "test: compat.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +01001093 if_build_succeeded tests/compat.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001094 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001095}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001096
Gilles Peskine8f073122018-11-27 15:58:47 +01001097component_test_cmake_out_of_source () {
1098 msg "build: cmake 'out-of-source' build"
Gilles Peskine8f073122018-11-27 15:58:47 +01001099 MBEDTLS_ROOT_DIR="$PWD"
1100 mkdir "$OUT_OF_SOURCE_DIR"
1101 cd "$OUT_OF_SOURCE_DIR"
1102 cmake "$MBEDTLS_ROOT_DIR"
1103 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001104
Gilles Peskine8f073122018-11-27 15:58:47 +01001105 msg "test: cmake 'out-of-source' build"
1106 make test
1107 # Test an SSL option that requires an auxiliary script in test/scripts/.
1108 # Also ensure that there are no error messages such as
1109 # "No such file or directory", which would indicate that some required
1110 # file is missing (ssl-opt.sh tolerates the absence of some files so
1111 # may exit with status 0 but emit errors).
1112 if_build_succeeded ./tests/ssl-opt.sh -f 'Fallback SCSV: beginning of list' 2>ssl-opt.err
1113 if [ -s ssl-opt.err ]; then
1114 cat ssl-opt.err >&2
1115 record_status [ ! -s ssl-opt.err ]
1116 rm ssl-opt.err
1117 fi
1118 cd "$MBEDTLS_ROOT_DIR"
1119 rm -rf "$OUT_OF_SOURCE_DIR"
1120 unset MBEDTLS_ROOT_DIR
1121}
Andres AGdc192212016-08-31 17:33:13 +01001122
Gilles Peskine8f073122018-11-27 15:58:47 +01001123component_test_zeroize () {
1124 # Test that the function mbedtls_platform_zeroize() is not optimized away by
1125 # different combinations of compilers and optimization flags by using an
1126 # auxiliary GDB script. Unfortunately, GDB does not return error values to the
1127 # system in all cases that the script fails, so we must manually search the
1128 # output to check whether the pass string is present and no failure strings
1129 # were printed.
1130 for optimization_flag in -O2 -O3 -Ofast -Os; do
1131 for compiler in clang gcc; do
1132 msg "test: $compiler $optimization_flag, mbedtls_platform_zeroize()"
Gilles Peskine8f073122018-11-27 15:58:47 +01001133 make programs CC="$compiler" DEBUG=1 CFLAGS="$optimization_flag"
1134 if_build_succeeded gdb -x tests/scripts/test_zeroize.gdb -nw -batch -nx 2>&1 | tee test_zeroize.log
1135 if_build_succeeded grep "The buffer was correctly zeroized" test_zeroize.log
1136 if_build_succeeded not grep -i "error" test_zeroize.log
1137 rm -f test_zeroize.log
Gilles Peskinee48351a2018-11-27 16:06:30 +01001138 make clean
Gilles Peskine8f073122018-11-27 15:58:47 +01001139 done
Andres Amaya Garcia29673812017-10-25 10:35:51 +01001140 done
Gilles Peskine8f073122018-11-27 15:58:47 +01001141}
Andres Amaya Garciad0d7bf62017-10-25 09:01:31 +01001142
Gilles Peskine8f073122018-11-27 15:58:47 +01001143component_check_python_files () {
1144 msg "Lint: Python scripts"
1145 record_status tests/scripts/check-python-files.sh
1146}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001147
Gilles Peskine8f073122018-11-27 15:58:47 +01001148component_check_generate_test_code () {
1149 msg "uint test: generate_test_code.py"
1150 record_status ./tests/scripts/test_generate_test_code.py
1151}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001152
1153################################################################
1154#### Termination
1155################################################################
1156
Gilles Peskine8f073122018-11-27 15:58:47 +01001157post_report () {
1158 msg "Done, cleaning up"
1159 cleanup
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001160
Gilles Peskine8f073122018-11-27 15:58:47 +01001161 final_report
1162}
1163
1164
1165
1166################################################################
1167#### Run all the things
1168################################################################
1169
Gilles Peskine92525112018-11-27 18:15:35 +01001170run_all_components () {
1171 # Small things
1172 run_component component_check_recursion
1173 run_component component_check_generated_files
1174 run_component component_check_doxy_blocks
1175 run_component component_check_files
1176 run_component component_check_names
1177 run_component component_check_doxygen_warnings
1178
1179 # Test many different configurations
1180 run_component component_test_default_cmake_gcc_asan
1181 run_component component_test_ref_configs
1182 run_component component_test_sslv3
1183 run_component component_test_no_renegotiation
1184 run_component component_test_rsa_no_crt
1185 run_component component_test_small_ssl_out_content_len
1186 run_component component_test_small_ssl_in_content_len
1187 run_component component_test_small_ssl_dtls_max_buffering
1188 run_component component_test_small_mbedtls_ssl_dtls_max_buffering
1189 run_component component_test_full_cmake_clang
1190 run_component component_build_deprecated
1191 run_component component_test_depends_curves
1192 run_component component_test_depends_hashes
1193 run_component component_test_depends_pkalgs
1194 run_component component_build_key_exchanges
1195 run_component component_build_default_make_gcc_and_cxx
1196 run_component component_test_no_platform
1197 run_component component_build_no_std_function
1198 run_component component_build_no_ssl_srv
1199 run_component component_build_no_ssl_cli
1200 run_component component_build_no_sockets
1201 run_component component_test_no_max_fragment_length
1202 run_component component_test_no_max_fragment_length_small_ssl_out_content_len
1203 run_component component_test_null_entropy
1204 run_component component_test_platform_calloc_macro
1205 run_component component_test_aes_fewer_tables
1206 run_component component_test_aes_rom_tables
1207 run_component component_test_aes_fewer_tables_and_rom_tables
1208 if uname -a | grep -F Linux >/dev/null; then
1209 run_component component_test_make_shared
1210 fi
1211 if uname -a | grep -F x86_64 >/dev/null; then
1212 run_component component_test_m32_o0
1213 run_component component_test_m32_o1
1214 run_component component_test_mx32
1215 fi
1216 run_component component_test_have_int32
1217 run_component component_test_have_int64
1218 run_component component_test_no_udbl_division
1219 run_component component_test_no_64bit_multiplication
1220 run_component component_build_arm_none_eabi_gcc
1221 run_component component_build_arm_none_eabi_gcc_no_udbl_division
1222 run_component component_build_arm_none_eabi_gcc_no_64bit_multiplication
1223 run_component component_build_armcc
1224 run_component component_test_allow_sha1
1225 run_component component_build_mingw
1226 # MemSan currently only available on Linux 64 bits
1227 if uname -a | grep 'Linux.*x86_64' >/dev/null; then
1228 run_component component_test_memsan
1229 else # no MemSan
1230 run_component component_test_memcheck
1231 fi
1232 run_component component_test_cmake_out_of_source
1233
1234 # More small things
1235 run_component component_test_zeroize
1236 run_component component_check_python_files
1237 run_component component_check_generate_test_code
1238}
1239
Gilles Peskinee48351a2018-11-27 16:06:30 +01001240# Run one component and clean up afterwards.
Gilles Peskine8f073122018-11-27 15:58:47 +01001241run_component () {
Gilles Peskine81b96ed2018-11-27 21:37:53 +01001242 if [ $ALL_EXCEPT -ne 0 ] && component_is_excluded "$1"; then
1243 return
1244 fi
Gilles Peskineffcdeff2018-12-04 12:49:28 +01001245 current_component="$1"
Gilles Peskine8f073122018-11-27 15:58:47 +01001246 "$@"
Gilles Peskinee48351a2018-11-27 16:06:30 +01001247 cleanup
Gilles Peskine8f073122018-11-27 15:58:47 +01001248}
1249
1250# Preliminary setup
1251pre_check_environment
1252pre_initialize_variables
1253pre_parse_command_line "$@"
Gilles Peskine348fb9a2018-11-27 17:04:29 +01001254
1255case "$INTROSPECTION_MODE" in
1256 list_components)
1257 components=
1258 newline='
1259'
1260 run_component () {
Gilles Peskine92525112018-11-27 18:15:35 +01001261 components="${components}${newline}${1#component_}"
Gilles Peskine348fb9a2018-11-27 17:04:29 +01001262 }
1263 ;;
1264
1265 *)
1266 pre_check_git
1267 build_status=0
1268 if [ $KEEP_GOING -eq 1 ]; then
1269 pre_setup_keep_going
1270 else
1271 record_status () {
1272 "$@"
1273 }
1274 fi
1275 pre_print_configuration
1276 pre_check_tools
1277 pre_print_tools
1278 cleanup
1279 ;;
1280esac
Gilles Peskine8f073122018-11-27 15:58:47 +01001281
Gilles Peskine81b96ed2018-11-27 21:37:53 +01001282if [ -n "$COMPONENTS" ] && [ $ALL_EXCEPT -eq 0 ]; then
Gilles Peskine92525112018-11-27 18:15:35 +01001283 for component in $COMPONENTS; do
1284 run_component "component_$component"
1285 done
1286else
1287 run_all_components
Gilles Peskine8f073122018-11-27 15:58:47 +01001288fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001289
1290# We're done.
Gilles Peskine348fb9a2018-11-27 17:04:29 +01001291case "$INTROSPECTION_MODE" in
1292 list_components)
1293 echo "$components" | sort
1294 ;;
1295 *)
1296 post_report
1297 ;;
1298esac