blob: a9ac3be663a6e65bdfa3b3d6ba1d5a91ace5e299 [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 Peskine878cf602019-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 Peskinea16c2b12019-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 Peskine8f073122018-11-27 15:58:47 +0100106 MEMORY=0
107 FORCE=0
108 KEEP_GOING=0
109 RUN_ARMCC=1
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100110
Gilles Peskine8f073122018-11-27 15:58:47 +0100111 # Default commands, can be overriden by the environment
112 : ${OPENSSL:="openssl"}
113 : ${OPENSSL_LEGACY:="$OPENSSL"}
114 : ${OPENSSL_NEXT:="$OPENSSL"}
115 : ${GNUTLS_CLI:="gnutls-cli"}
116 : ${GNUTLS_SERV:="gnutls-serv"}
117 : ${GNUTLS_LEGACY_CLI:="$GNUTLS_CLI"}
118 : ${GNUTLS_LEGACY_SERV:="$GNUTLS_SERV"}
119 : ${OUT_OF_SOURCE_DIR:=./mbedtls_out_of_source_build}
120 : ${ARMC5_BIN_DIR:=/usr/bin}
121 : ${ARMC6_BIN_DIR:=/usr/bin}
Andres AGdc192212016-08-31 17:33:13 +0100122
Gilles Peskine8f073122018-11-27 15:58:47 +0100123 # if MAKEFLAGS is not set add the -j option to speed up invocations of make
Gilles Peskinea1fc4b52019-01-06 20:15:26 +0000124 if [ -z "${MAKEFLAGS+set}" ]; then
Gilles Peskine8f073122018-11-27 15:58:47 +0100125 export MAKEFLAGS="-j"
126 fi
Gilles Peskine878cf602019-01-06 20:50:38 +0000127
128 # Gather the list of available components. These are the functions
129 # defined in this script whose name starts with "component_".
130 # Parse the script with sed, because in sh there is no way to list
131 # defined functions.
132 ALL_COMPONENTS=$(sed -n 's/^ *component_\([0-9A-Z_a-z]*\) *().*/\1/p' <"$0")
133
134 # Exclude components that are not supported on this platform.
135 SUPPORTED_COMPONENTS=
136 for component in $ALL_COMPONENTS; do
137 case $(type "support_$component" 2>&1) in
138 *' function'*)
139 if ! support_$component; then continue; fi;;
140 esac
141 SUPPORTED_COMPONENTS="$SUPPORTED_COMPONENTS $component"
142 done
Gilles Peskine8f073122018-11-27 15:58:47 +0100143}
Andres AG38495a32016-07-12 16:54:33 +0100144
Gilles Peskine878cf602019-01-06 20:50:38 +0000145# Test whether $1 is excluded via the command line.
146is_component_excluded()
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100147{
Gilles Peskine878cf602019-01-06 20:50:38 +0000148 # Is $1 excluded via $COMPONENTS (a space-separated list of wildcard
149 # patterns)?
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100150 set -f
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000151 for pattern in $COMMAND_LINE_COMPONENTS; do
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100152 set +f
153 case ${1#component_} in $pattern) return 0;; esac
154 done
155 set +f
156 return 1
157}
158
Simon Butcher41eeccf2016-09-07 00:07:09 +0100159usage()
SimonB2e23c822016-04-16 21:54:39 +0100160{
Gilles Peskine709346a2017-12-10 23:43:39 +0100161 cat <<EOF
Gilles Peskine92525112018-11-27 18:15:35 +0100162Usage: $0 [OPTION]... [COMPONENT]...
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100163Run mbedtls release validation tests.
Gilles Peskine92525112018-11-27 18:15:35 +0100164By default, run all tests. With one or more COMPONENT, run only those.
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100165
166Special options:
167 -h|--help Print this help and exit.
Gilles Peskine878cf602019-01-06 20:50:38 +0000168 --list-all-components List all available test components and exit.
169 --list-components List components supported on this platform and exit.
Gilles Peskine709346a2017-12-10 23:43:39 +0100170
171General options:
172 -f|--force Force the tests to overwrite any modified files.
Gilles Peskine7c652162017-12-11 00:01:40 +0100173 -k|--keep-going Run all tests and report errors at the end.
Gilles Peskine709346a2017-12-10 23:43:39 +0100174 -m|--memory Additional optional memory tests.
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100175 --armcc Run ARM Compiler builds (on by default).
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100176 --except If some components are passed on the command line,
177 run all the tests except for these components. In
178 this mode, you can pass shell wildcard patterns as
179 component names, e.g. "$0 --except 'test_*'" to
180 exclude all components that run tests.
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100181 --no-armcc Skip ARM Compiler builds.
Gilles Peskine38d81652018-03-21 08:40:26 +0100182 --no-force Refuse to overwrite modified files (default).
183 --no-keep-going Stop at the first error (default).
184 --no-memory No additional memory tests (default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100185 --out-of-source-dir=<path> Directory used for CMake out-of-source build tests.
Gilles Peskine38d81652018-03-21 08:40:26 +0100186 --random-seed Use a random seed value for randomized tests (default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100187 -r|--release-test Run this script in release mode. This fixes the seed value to 1.
188 -s|--seed Integer seed value to use for this test run.
189
190Tool path options:
191 --armc5-bin-dir=<ARMC5_bin_dir_path> ARM Compiler 5 bin directory.
192 --armc6-bin-dir=<ARMC6_bin_dir_path> ARM Compiler 6 bin directory.
193 --gnutls-cli=<GnuTLS_cli_path> GnuTLS client executable to use for most tests.
194 --gnutls-serv=<GnuTLS_serv_path> GnuTLS server executable to use for most tests.
195 --gnutls-legacy-cli=<GnuTLS_cli_path> GnuTLS client executable to use for legacy tests.
196 --gnutls-legacy-serv=<GnuTLS_serv_path> GnuTLS server executable to use for legacy tests.
197 --openssl=<OpenSSL_path> OpenSSL executable to use for most tests.
198 --openssl-legacy=<OpenSSL_path> OpenSSL executable to use for legacy tests e.g. SSLv3.
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100199 --openssl-next=<OpenSSL_path> OpenSSL executable to use for recent things like ARIA
Gilles Peskine709346a2017-12-10 23:43:39 +0100200EOF
SimonB2e23c822016-04-16 21:54:39 +0100201}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100202
203# remove built files as well as the cmake cache/config
204cleanup()
205{
Gilles Peskinea71d64c2018-03-21 12:16:57 +0100206 if [ -n "${MBEDTLS_ROOT_DIR+set}" ]; then
207 cd "$MBEDTLS_ROOT_DIR"
208 fi
209
Gilles Peskine7c652162017-12-11 00:01:40 +0100210 command make clean
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200211
Gilles Peskine31b07e22018-03-21 12:15:06 +0100212 # Remove CMake artefacts
Simon Butcher3ad2efd2018-05-02 14:49:38 +0100213 find . -name .git -prune \
Gilles Peskine31b07e22018-03-21 12:15:06 +0100214 -iname CMakeFiles -exec rm -rf {} \+ -o \
215 \( -iname cmake_install.cmake -o \
216 -iname CTestTestfile.cmake -o \
217 -iname CMakeCache.txt \) -exec rm {} \+
218 # Recover files overwritten by in-tree CMake builds
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000219 rm -f include/Makefile include/mbedtls/Makefile programs/*/Makefile
Paul Bakkerfe0984d2014-06-13 00:13:45 +0200220 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile
221 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200222
223 if [ -f "$CONFIG_BAK" ]; then
224 mv "$CONFIG_BAK" "$CONFIG_H"
225 fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100226}
227
Gilles Peskine7c652162017-12-11 00:01:40 +0100228# Executed on exit. May be redefined depending on command line options.
229final_report () {
230 :
231}
232
233fatal_signal () {
234 cleanup
235 final_report $1
236 trap - $1
237 kill -$1 $$
238}
239
240trap 'fatal_signal HUP' HUP
241trap 'fatal_signal INT' INT
242trap 'fatal_signal TERM' TERM
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200243
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100244msg()
245{
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100246 if [ -n "${current_component:-}" ]; then
247 current_section="${current_component#component_}: $1"
248 else
249 current_section="$1"
250 fi
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100251 echo ""
252 echo "******************************************************************"
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100253 echo "* $current_section "
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000254 printf "* "; date
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100255 echo "******************************************************************"
256}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100257
Gilles Peskine8f073122018-11-27 15:58:47 +0100258armc6_build_test()
259{
260 FLAGS="$1"
Andres AGa5cd9732016-10-17 15:23:10 +0100261
Gilles Peskine8f073122018-11-27 15:58:47 +0100262 msg "build: ARM Compiler 6 ($FLAGS), make"
263 ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \
264 WARNING_CFLAGS='-xc -std=c99' make lib
265 make clean
266}
Andres AGa5cd9732016-10-17 15:23:10 +0100267
Andres AGd9eba4b2016-08-26 14:42:14 +0100268err_msg()
269{
270 echo "$1" >&2
271}
272
273check_tools()
274{
275 for TOOL in "$@"; do
Andres AG98393602017-01-31 17:04:45 +0000276 if ! `type "$TOOL" >/dev/null 2>&1`; then
Andres AGd9eba4b2016-08-26 14:42:14 +0100277 err_msg "$TOOL not found!"
278 exit 1
279 fi
280 done
281}
282
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400283check_headers_in_cpp () {
284 ls include/mbedtls >headers.txt
285 <programs/test/cpp_dummy_build.cpp sed -n 's/"$//; s!^#include "mbedtls/!!p' |
286 sort |
287 diff headers.txt -
288 rm headers.txt
289}
290
Gilles Peskine8f073122018-11-27 15:58:47 +0100291pre_parse_command_line () {
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000292 COMMAND_LINE_COMPONENTS=
293 all_except=
294
Gilles Peskine8f073122018-11-27 15:58:47 +0100295 while [ $# -gt 0 ]; do
Gilles Peskine55f7c942019-01-09 22:28:21 +0100296 case "$1" in
297 --armcc) RUN_ARMCC=1;;
298 --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
299 --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000300 --except) all_except=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100301 --force|-f) FORCE=1;;
302 --gnutls-cli) shift; GNUTLS_CLI="$1";;
303 --gnutls-legacy-cli) shift; GNUTLS_LEGACY_CLI="$1";;
304 --gnutls-legacy-serv) shift; GNUTLS_LEGACY_SERV="$1";;
305 --gnutls-serv) shift; GNUTLS_SERV="$1";;
306 --help|-h) usage; exit;;
307 --keep-going|-k) KEEP_GOING=1;;
Gilles Peskine878cf602019-01-06 20:50:38 +0000308 --list-all-components) printf '%s\n' $ALL_COMPONENTS; exit;;
309 --list-components) printf '%s\n' $SUPPORTED_COMPONENTS; exit;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100310 --memory|-m) MEMORY=1;;
311 --no-armcc) RUN_ARMCC=0;;
312 --no-force) FORCE=0;;
313 --no-keep-going) KEEP_GOING=0;;
314 --no-memory) MEMORY=0;;
315 --openssl) shift; OPENSSL="$1";;
316 --openssl-legacy) shift; OPENSSL_LEGACY="$1";;
317 --openssl-next) shift; OPENSSL_NEXT="$1";;
318 --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
319 --random-seed) unset SEED;;
320 --release-test|-r) SEED=1;;
321 --seed|-s) shift; SEED="$1";;
322 -*)
323 echo >&2 "Unknown option: $1"
324 echo >&2 "Run $0 --help for usage."
325 exit 120
326 ;;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000327 *) COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS $1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100328 esac
329 shift
Gilles Peskine8f073122018-11-27 15:58:47 +0100330 done
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000331
332 if [ -z "$COMMAND_LINE_COMPONENTS" ]; then
333 all_except=1
334 fi
335
336 # Build the list of components to run.
337 if [ -n "$all_except" ]; then
338 RUN_COMPONENTS=
339 for component in $SUPPORTED_COMPONENTS; do
340 if ! is_component_excluded "$component"; then
341 RUN_COMPONENTS="$RUN_COMPONENTS $component"
342 fi
343 done
344 else
345 RUN_COMPONENTS="$COMMAND_LINE_COMPONENTS"
346 fi
347
348 unset all_except
Gilles Peskine8f073122018-11-27 15:58:47 +0100349}
SimonB2e23c822016-04-16 21:54:39 +0100350
Gilles Peskine8f073122018-11-27 15:58:47 +0100351pre_check_git () {
352 if [ $FORCE -eq 1 ]; then
353 git checkout-index -f -q $CONFIG_H
354 cleanup
355 else
SimonB2e23c822016-04-16 21:54:39 +0100356
Gilles Peskine8f073122018-11-27 15:58:47 +0100357 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
358 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
359 echo "You can either delete this directory manually, or force the test by rerunning"
360 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
361 exit 1
362 fi
363
364 if ! git diff-files --quiet include/mbedtls/config.h; then
365 err_msg "Warning - the configuration file 'include/mbedtls/config.h' has been edited. "
366 echo "You can either delete or preserve your work, or force the test by rerunning the"
367 echo "script as: $0 --force"
368 exit 1
369 fi
Andres AGdc192212016-08-31 17:33:13 +0100370 fi
Gilles Peskine8f073122018-11-27 15:58:47 +0100371}
Andres AGdc192212016-08-31 17:33:13 +0100372
Gilles Peskine8f073122018-11-27 15:58:47 +0100373pre_setup_keep_going () {
Gilles Peskine7c652162017-12-11 00:01:40 +0100374 failure_summary=
375 failure_count=0
376 start_red=
377 end_color=
378 if [ -t 1 ]; then
Gilles Peskine9736b9d2018-01-02 21:54:17 +0100379 case "${TERM:-}" in
Gilles Peskine7c652162017-12-11 00:01:40 +0100380 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
381 start_red=$(printf '\033[31m')
382 end_color=$(printf '\033[0m')
383 ;;
384 esac
385 fi
386 record_status () {
387 if "$@"; then
388 last_status=0
389 else
390 last_status=$?
391 text="$current_section: $* -> $last_status"
392 failure_summary="$failure_summary
393$text"
394 failure_count=$((failure_count + 1))
395 echo "${start_red}^^^^$text^^^^${end_color}"
396 fi
397 }
398 make () {
399 case "$*" in
400 *test|*check)
401 if [ $build_status -eq 0 ]; then
402 record_status command make "$@"
403 else
404 echo "(skipped because the build failed)"
405 fi
406 ;;
407 *)
408 record_status command make "$@"
409 build_status=$last_status
410 ;;
411 esac
412 }
413 final_report () {
414 if [ $failure_count -gt 0 ]; then
415 echo
416 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
417 echo "${start_red}FAILED: $failure_count${end_color}$failure_summary"
418 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Jaeden Amero7c1258d2018-07-20 16:42:14 +0100419 exit 1
Gilles Peskine7c652162017-12-11 00:01:40 +0100420 elif [ -z "${1-}" ]; then
421 echo "SUCCESS :)"
422 fi
423 if [ -n "${1-}" ]; then
424 echo "Killed by SIG$1."
425 fi
426 }
Gilles Peskine8f073122018-11-27 15:58:47 +0100427}
428
Gilles Peskine7c652162017-12-11 00:01:40 +0100429if_build_succeeded () {
430 if [ $build_status -eq 0 ]; then
431 record_status "$@"
432 fi
433}
434
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200435# to be used instead of ! for commands run with
436# record_status or if_build_succeeded
437not() {
438 ! "$@"
439}
440
Gilles Peskine8f073122018-11-27 15:58:47 +0100441pre_print_configuration () {
442 msg "info: $0 configuration"
443 echo "MEMORY: $MEMORY"
444 echo "FORCE: $FORCE"
445 echo "SEED: ${SEED-"UNSET"}"
446 echo "OPENSSL: $OPENSSL"
447 echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
448 echo "OPENSSL_NEXT: $OPENSSL_NEXT"
449 echo "GNUTLS_CLI: $GNUTLS_CLI"
450 echo "GNUTLS_SERV: $GNUTLS_SERV"
451 echo "GNUTLS_LEGACY_CLI: $GNUTLS_LEGACY_CLI"
452 echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV"
453 echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
454 echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
455}
Andres AG87bb5772016-09-27 15:05:15 +0100456
Gilles Peskine8f073122018-11-27 15:58:47 +0100457pre_check_tools () {
458 ARMC5_CC="$ARMC5_BIN_DIR/armcc"
459 ARMC5_AR="$ARMC5_BIN_DIR/armar"
460 ARMC6_CC="$ARMC6_BIN_DIR/armclang"
461 ARMC6_AR="$ARMC6_BIN_DIR/armar"
Andres AGd9eba4b2016-08-26 14:42:14 +0100462
Gilles Peskine8f073122018-11-27 15:58:47 +0100463 # To avoid setting OpenSSL and GnuTLS for each call to compat.sh and ssl-opt.sh
464 # we just export the variables they require
465 export OPENSSL_CMD="$OPENSSL"
466 export GNUTLS_CLI="$GNUTLS_CLI"
467 export GNUTLS_SERV="$GNUTLS_SERV"
Andres AGb2fdd042016-09-22 14:17:46 +0100468
Gilles Peskine8f073122018-11-27 15:58:47 +0100469 # Avoid passing --seed flag in every call to ssl-opt.sh
470 if [ -n "${SEED-}" ]; then
471 export SEED
472 fi
Andres AG7770ea82016-10-10 15:46:20 +0100473
Gilles Peskine8f073122018-11-27 15:58:47 +0100474 # Make sure the tools we need are available.
475 check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$OPENSSL_NEXT" \
476 "$GNUTLS_CLI" "$GNUTLS_SERV" \
477 "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV" "doxygen" "dot" \
478 "arm-none-eabi-gcc" "i686-w64-mingw32-gcc" "gdb"
479 if [ $RUN_ARMCC -ne 0 ]; then
480 check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC6_CC" "$ARMC6_AR"
481 fi
482}
Gilles Peskine192c72f2017-12-21 15:59:21 +0100483
484
485################################################################
486#### Basic checks
487################################################################
Andres AGd9eba4b2016-08-26 14:42:14 +0100488
SimonB2e23c822016-04-16 21:54:39 +0100489#
490# Test Suites to be executed
491#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200492# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100493# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard61bc57a2014-08-14 11:29:06 +0200494# and/or are more likely to fail than others (eg I use Clang most of the
495# time, so start with a GCC build).
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200496# 2. Minimize total running time, by avoiding useless rebuilds
497#
498# Indicative running times are given for reference.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100499
Gilles Peskine8f073122018-11-27 15:58:47 +0100500pre_print_tools () {
501 msg "info: output_env.sh"
502 OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY" GNUTLS_CLI="$GNUTLS_CLI" \
503 GNUTLS_SERV="$GNUTLS_SERV" GNUTLS_LEGACY_CLI="$GNUTLS_LEGACY_CLI" \
504 GNUTLS_LEGACY_SERV="$GNUTLS_LEGACY_SERV" ARMC5_CC="$ARMC5_CC" \
505 ARMC6_CC="$ARMC6_CC" RUN_ARMCC="$RUN_ARMCC" scripts/output_env.sh
506}
Janos Follathb72c6782016-07-19 14:54:17 +0100507
Gilles Peskine8f073122018-11-27 15:58:47 +0100508component_check_recursion () {
509 msg "test: recursion.pl" # < 1s
510 record_status tests/scripts/recursion.pl library/*.c
511}
Manuel Pégourié-Gonnardea29d152014-11-20 17:32:33 +0100512
Gilles Peskine8f073122018-11-27 15:58:47 +0100513component_check_generated_files () {
514 msg "test: freshness of generated source files" # < 1s
515 record_status tests/scripts/check-generated-files.sh
516}
Manuel Pégourié-Gonnardb3b8e432015-02-13 14:52:19 +0000517
Gilles Peskine8f073122018-11-27 15:58:47 +0100518component_check_doxy_blocks () {
519 msg "test: doxygen markup outside doxygen blocks" # < 1s
520 record_status tests/scripts/check-doxy-blocks.pl
521}
Manuel Pégourié-Gonnardd09a6b52015-04-09 17:19:23 +0200522
Gilles Peskine8f073122018-11-27 15:58:47 +0100523component_check_files () {
524 msg "test: check-files.py" # < 1s
Gilles Peskine8f073122018-11-27 15:58:47 +0100525 record_status tests/scripts/check-files.py
526}
Darryl Greena07039c2018-03-13 16:48:16 +0000527
Gilles Peskine8f073122018-11-27 15:58:47 +0100528component_check_names () {
529 msg "test/build: declared and exported names" # < 3s
Gilles Peskine8f073122018-11-27 15:58:47 +0100530 record_status tests/scripts/check-names.sh
531}
Manuel Pégourié-Gonnarda687baf2015-04-09 11:09:03 +0200532
Gilles Peskine8f073122018-11-27 15:58:47 +0100533component_check_doxygen_warnings () {
534 msg "test: doxygen warnings" # ~ 3s
Gilles Peskine8f073122018-11-27 15:58:47 +0100535 record_status tests/scripts/doxygen.sh
536}
Manuel Pégourié-Gonnard1d552e72016-01-04 16:49:09 +0100537
Gilles Peskine192c72f2017-12-21 15:59:21 +0100538
539
540################################################################
541#### Build and test many configurations and targets
542################################################################
543
Gilles Peskine8f073122018-11-27 15:58:47 +0100544component_test_default_cmake_gcc_asan () {
545 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100546 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
547 make
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100548
Gilles Peskine8f073122018-11-27 15:58:47 +0100549 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
550 make test
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200551
Gilles Peskine8f073122018-11-27 15:58:47 +0100552 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
553 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200554
Gilles Peskine8f073122018-11-27 15:58:47 +0100555 msg "test: compat.sh (ASan build)" # ~ 6 min
556 if_build_succeeded tests/compat.sh
557}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200558
Gilles Peskine782f4112018-11-27 16:11:09 +0100559component_test_ref_configs () {
560 msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
561 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
562 record_status tests/scripts/test-ref-configs.pl
563}
564
Gilles Peskine8f073122018-11-27 15:58:47 +0100565component_test_sslv3 () {
566 msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100567 scripts/config.pl set MBEDTLS_SSL_PROTO_SSL3
568 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
569 make
Simon Butcher3ea7f522016-03-07 23:22:10 +0000570
Gilles Peskine8f073122018-11-27 15:58:47 +0100571 msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
572 make test
Simon Butcher3ea7f522016-03-07 23:22:10 +0000573
Gilles Peskine8f073122018-11-27 15:58:47 +0100574 msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
575 if_build_succeeded tests/compat.sh -m 'tls1 tls1_1 tls1_2 dtls1 dtls1_2'
576 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
Simon Butcher3ea7f522016-03-07 23:22:10 +0000577
Gilles Peskine8f073122018-11-27 15:58:47 +0100578 msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
579 if_build_succeeded tests/ssl-opt.sh
580}
Simon Butcher3ea7f522016-03-07 23:22:10 +0000581
Gilles Peskine8f073122018-11-27 15:58:47 +0100582component_test_no_renegotiation () {
583 msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100584 scripts/config.pl unset MBEDTLS_SSL_RENEGOTIATION
585 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
586 make
Hanno Becker134c2ab2017-10-12 15:29:50 +0100587
Gilles Peskine8f073122018-11-27 15:58:47 +0100588 msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
589 make test
Hanno Becker134c2ab2017-10-12 15:29:50 +0100590
Gilles Peskine8f073122018-11-27 15:58:47 +0100591 msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
592 if_build_succeeded tests/ssl-opt.sh
593}
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +0100594
Gilles Peskine8f073122018-11-27 15:58:47 +0100595component_test_rsa_no_crt () {
596 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100597 scripts/config.pl set MBEDTLS_RSA_NO_CRT
598 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
599 make
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100600
Gilles Peskine8f073122018-11-27 15:58:47 +0100601 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
602 make test
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100603
Gilles Peskine8f073122018-11-27 15:58:47 +0100604 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
605 if_build_succeeded tests/ssl-opt.sh -f RSA
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100606
Gilles Peskine8f073122018-11-27 15:58:47 +0100607 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
608 if_build_succeeded tests/compat.sh -t RSA
609}
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100610
Gilles Peskine8f073122018-11-27 15:58:47 +0100611component_test_small_ssl_out_content_len () {
612 msg "build: small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100613 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 16384
614 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
615 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
616 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000617
Gilles Peskine8f073122018-11-27 15:58:47 +0100618 msg "test: small SSL_OUT_CONTENT_LEN - ssl-opt.sh MFL and large packet tests"
619 if_build_succeeded tests/ssl-opt.sh -f "Max fragment\|Large packet"
620}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000621
Gilles Peskine8f073122018-11-27 15:58:47 +0100622component_test_small_ssl_in_content_len () {
623 msg "build: small SSL_IN_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100624 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 4096
625 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 16384
626 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
627 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000628
Gilles Peskine8f073122018-11-27 15:58:47 +0100629 msg "test: small SSL_IN_CONTENT_LEN - ssl-opt.sh MFL tests"
630 if_build_succeeded tests/ssl-opt.sh -f "Max fragment"
631}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000632
Gilles Peskine8f073122018-11-27 15:58:47 +0100633component_test_small_ssl_dtls_max_buffering () {
634 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0"
Gilles Peskine8f073122018-11-27 15:58:47 +0100635 scripts/config.pl set MBEDTLS_SSL_DTLS_MAX_BUFFERING 1000
636 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
637 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100638
Gilles Peskine8f073122018-11-27 15:58:47 +0100639 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0 - ssl-opt.sh specific reordering test"
640 if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer out-of-order hs msg before reassembling next, free buffered msg"
641}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100642
Gilles Peskine8f073122018-11-27 15:58:47 +0100643component_test_small_mbedtls_ssl_dtls_max_buffering () {
644 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1"
Gilles Peskine8f073122018-11-27 15:58:47 +0100645 scripts/config.pl set MBEDTLS_SSL_DTLS_MAX_BUFFERING 240
646 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
647 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100648
Gilles Peskine8f073122018-11-27 15:58:47 +0100649 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1 - ssl-opt.sh specific reordering test"
650 if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer encrypted Finished message, drop for fragmented NewSessionTicket"
651}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100652
Gilles Peskine8f073122018-11-27 15:58:47 +0100653component_test_full_cmake_clang () {
654 msg "build: cmake, full config, clang" # ~ 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100655 scripts/config.pl full
656 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
657 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check -D ENABLE_TESTING=On .
658 make
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100659
Gilles Peskine8f073122018-11-27 15:58:47 +0100660 msg "test: main suites (full config)" # ~ 5s
661 make test
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200662
Gilles Peskine8f073122018-11-27 15:58:47 +0100663 msg "test: ssl-opt.sh default, ECJPAKE, SSL async (full config)" # ~ 1s
664 if_build_succeeded tests/ssl-opt.sh -f 'Default\|ECJPAKE\|SSL async private'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200665
Gilles Peskine8f073122018-11-27 15:58:47 +0100666 msg "test: compat.sh RC4, DES & NULL (full config)" # ~ 2 min
667 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 +0200668
Gilles Peskine8f073122018-11-27 15:58:47 +0100669 msg "test: compat.sh ARIA + ChachaPoly"
670 if_build_succeeded env OPENSSL_CMD="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
671}
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100672
Gilles Peskine8f073122018-11-27 15:58:47 +0100673component_build_deprecated () {
674 msg "build: make, full config + DEPRECATED_WARNING, gcc -O" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100675 scripts/config.pl full
676 scripts/config.pl set MBEDTLS_DEPRECATED_WARNING
677 # Build with -O -Wextra to catch a maximum of issues.
678 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra' lib programs
679 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
Gilles Peskineb4ef45b2018-03-01 22:23:50 +0100680
Gilles Peskine8f073122018-11-27 15:58:47 +0100681 msg "build: make, full config + DEPRECATED_REMOVED, clang -O" # ~ 30s
682 # No cleanup, just tweak the configuration and rebuild
683 make clean
684 scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
685 scripts/config.pl set MBEDTLS_DEPRECATED_REMOVED
686 # Build with -O -Wextra to catch a maximum of issues.
687 make CC=clang CFLAGS='-O -Werror -Wall -Wextra' lib programs
688 make CC=clang CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
689}
Gilles Peskine0afe6242018-02-21 19:28:12 +0100690
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200691
Gilles Peskine8f073122018-11-27 15:58:47 +0100692component_test_depends_curves () {
693 msg "test/build: curves.pl (gcc)" # ~ 4 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100694 record_status tests/scripts/curves.pl
695}
Manuel Pégourié-Gonnard1fe6bb92017-06-06 11:36:16 +0200696
Gilles Peskine8f073122018-11-27 15:58:47 +0100697component_test_depends_hashes () {
698 msg "test/build: depends-hashes.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100699 record_status tests/scripts/depends-hashes.pl
700}
Manuel Pégourié-Gonnard43be6cd2017-06-20 09:53:42 +0200701
Gilles Peskine8f073122018-11-27 15:58:47 +0100702component_test_depends_pkalgs () {
703 msg "test/build: depends-pkalgs.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100704 record_status tests/scripts/depends-pkalgs.pl
705}
Manuel Pégourié-Gonnard503a5ef2015-10-23 09:04:45 +0200706
Gilles Peskine8f073122018-11-27 15:58:47 +0100707component_build_key_exchanges () {
708 msg "test/build: key-exchanges (gcc)" # ~ 1 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100709 record_status tests/scripts/key-exchanges.pl
710}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100711
Gilles Peskine8f073122018-11-27 15:58:47 +0100712component_build_default_make_gcc_and_cxx () {
713 msg "build: Unix make, -Os (gcc)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100714 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400715
Gilles Peskine8f073122018-11-27 15:58:47 +0100716 msg "test: verify header list in cpp_dummy_build.cpp"
717 record_status check_headers_in_cpp
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400718
Gilles Peskine8f073122018-11-27 15:58:47 +0100719 msg "build: Unix make, incremental g++"
720 make TEST_CPP=1
721}
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +0000722
Gilles Peskineb28636b2019-01-02 19:06:24 +0100723component_test_check_params_without_platform () {
724 msg "build+test: MBEDTLS_CHECK_PARAMS without MBEDTLS_PLATFORM_C"
725 scripts/config.pl full # includes CHECK_PARAMS
726 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
727 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
728 scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
729 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
730 scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
731 scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
732 scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
733 scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
734 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
735 scripts/config.pl unset MBEDTLS_PLATFORM_C
736 make CC=gcc CFLAGS='-Werror -O1' all test
737}
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +0200738
Gilles Peskineb28636b2019-01-02 19:06:24 +0100739component_test_check_params_silent () {
740 msg "build+test: MBEDTLS_CHECK_PARAMS with alternative MBEDTLS_PARAM_FAILED()"
741 scripts/config.pl full # includes CHECK_PARAMS
742 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
743 sed -i 's/.*\(#define MBEDTLS_PARAM_FAILED( cond )\).*/\1/' "$CONFIG_H"
744 make CC=gcc CFLAGS='-Werror -O1' all test
745}
Hanno Becker5175ac62017-09-18 15:36:25 +0100746
Gilles Peskine8f073122018-11-27 15:58:47 +0100747component_test_no_platform () {
748 # Full configuration build, without platform support, file IO and net sockets.
749 # This should catch missing mbedtls_printf definitions, and by disabling file
750 # IO, it should catch missing '#include <stdio.h>'
751 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100752 scripts/config.pl full
753 scripts/config.pl unset MBEDTLS_PLATFORM_C
754 scripts/config.pl unset MBEDTLS_NET_C
755 scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
756 scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
757 scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
758 scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
759 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
760 scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
761 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
762 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
763 scripts/config.pl unset MBEDTLS_FS_IO
764 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
765 # to re-enable platform integration features otherwise disabled in C99 builds
766 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -O0 -D_DEFAULT_SOURCE' lib programs
767 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0' test
768}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200769
Gilles Peskine8f073122018-11-27 15:58:47 +0100770component_build_no_std_function () {
771 # catch compile bugs in _uninit functions
772 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100773 scripts/config.pl full
774 scripts/config.pl set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
775 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
776 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
777}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200778
Gilles Peskine8f073122018-11-27 15:58:47 +0100779component_build_no_ssl_srv () {
780 msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100781 scripts/config.pl full
782 scripts/config.pl unset MBEDTLS_SSL_SRV_C
783 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
784}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200785
Gilles Peskine8f073122018-11-27 15:58:47 +0100786component_build_no_ssl_cli () {
787 msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100788 scripts/config.pl full
789 scripts/config.pl unset MBEDTLS_SSL_CLI_C
790 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
791}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000792
Gilles Peskine8f073122018-11-27 15:58:47 +0100793component_build_no_sockets () {
794 # Note, C99 compliance can also be tested with the sockets support disabled,
795 # as that requires a POSIX platform (which isn't the same as C99).
796 msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100797 scripts/config.pl full
798 scripts/config.pl unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
799 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
800 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0 -std=c99 -pedantic' lib
801}
Hanno Becker5175ac62017-09-18 15:36:25 +0100802
Gilles Peskine8f073122018-11-27 15:58:47 +0100803component_test_no_max_fragment_length () {
804 # Run max fragment length tests with MFL disabled
805 msg "build: default config except MFL extension (ASan build)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100806 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
807 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
808 make
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000809
Gilles Peskine8f073122018-11-27 15:58:47 +0100810 msg "test: ssl-opt.sh, MFL-related tests"
811 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length"
812}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000813
Gilles Peskine8f073122018-11-27 15:58:47 +0100814component_test_no_max_fragment_length_small_ssl_out_content_len () {
815 msg "build: no MFL extension, small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100816 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
817 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 16384
818 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
819 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
820 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000821
Gilles Peskine8f073122018-11-27 15:58:47 +0100822 msg "test: MFL tests (disabled MFL extension case) & large packet tests"
823 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length\|Large buffer"
824}
Janos Follath06c54002016-06-09 13:57:40 +0100825
Gilles Peskine8f073122018-11-27 15:58:47 +0100826component_test_null_entropy () {
827 msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100828 scripts/config.pl set MBEDTLS_TEST_NULL_ENTROPY
829 scripts/config.pl set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
830 scripts/config.pl set MBEDTLS_ENTROPY_C
831 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
832 scripts/config.pl unset MBEDTLS_ENTROPY_HARDWARE_ALT
833 scripts/config.pl unset MBEDTLS_HAVEGE_C
Gilles Peskine5fa32a72019-01-06 19:48:30 +0000834 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan -D UNSAFE_BUILD=ON .
Gilles Peskine8f073122018-11-27 15:58:47 +0100835 make
Janos Follath06c54002016-06-09 13:57:40 +0100836
Gilles Peskine8f073122018-11-27 15:58:47 +0100837 msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)"
838 make test
839}
Hanno Beckere5fecec2018-10-11 11:02:52 +0100840
Gilles Peskine8f073122018-11-27 15:58:47 +0100841component_test_platform_calloc_macro () {
842 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100843 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
844 scripts/config.pl set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
845 scripts/config.pl set MBEDTLS_PLATFORM_FREE_MACRO free
846 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
847 make
Hanno Beckere5fecec2018-10-11 11:02:52 +0100848
Gilles Peskine8f073122018-11-27 15:58:47 +0100849 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
850 make test
851}
Hanno Becker83ebf782017-07-07 12:29:15 +0100852
Gilles Peskine8f073122018-11-27 15:58:47 +0100853component_test_aes_fewer_tables () {
854 msg "build: default config with AES_FEWER_TABLES enabled"
Gilles Peskine8f073122018-11-27 15:58:47 +0100855 scripts/config.pl set MBEDTLS_AES_FEWER_TABLES
856 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +0100857
Gilles Peskine8f073122018-11-27 15:58:47 +0100858 msg "test: AES_FEWER_TABLES"
859 make test
860}
Hanno Becker83ebf782017-07-07 12:29:15 +0100861
Gilles Peskine8f073122018-11-27 15:58:47 +0100862component_test_aes_rom_tables () {
863 msg "build: default config with AES_ROM_TABLES enabled"
Gilles Peskine8f073122018-11-27 15:58:47 +0100864 scripts/config.pl set MBEDTLS_AES_ROM_TABLES
865 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +0100866
Gilles Peskine8f073122018-11-27 15:58:47 +0100867 msg "test: AES_ROM_TABLES"
868 make test
869}
Hanno Becker83ebf782017-07-07 12:29:15 +0100870
Gilles Peskine8f073122018-11-27 15:58:47 +0100871component_test_aes_fewer_tables_and_rom_tables () {
872 msg "build: default config with AES_ROM_TABLES and AES_FEWER_TABLES enabled"
Gilles Peskine8f073122018-11-27 15:58:47 +0100873 scripts/config.pl set MBEDTLS_AES_FEWER_TABLES
874 scripts/config.pl set MBEDTLS_AES_ROM_TABLES
875 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +0100876
Gilles Peskine8f073122018-11-27 15:58:47 +0100877 msg "test: AES_FEWER_TABLES + AES_ROM_TABLES"
878 make test
879}
880
881component_test_make_shared () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100882 msg "build/test: make shared" # ~ 40s
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100883 make SHARED=1 all check
Gilles Peskine8f073122018-11-27 15:58:47 +0100884}
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +0200885
Gilles Peskine8f073122018-11-27 15:58:47 +0100886component_test_m32_o0 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100887 # Build once with -O0, to compile out the i386 specific inline assembly
888 msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
Simon Butcher7a6da6e2018-06-27 21:52:54 +0100889 scripts/config.pl full
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100890 make CC=gcc CFLAGS='-O0 -Werror -Wall -Wextra -m32 -fsanitize=address'
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +0100891
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100892 msg "test: i386, make, gcc -O0 (ASan build)"
893 make test
Gilles Peskine8f073122018-11-27 15:58:47 +0100894}
Gilles Peskine878cf602019-01-06 20:50:38 +0000895support_test_m32_o0 () {
896 case $(uname -m) in
897 *64*) true;;
898 *) false;;
899 esac
900}
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100901
Gilles Peskine8f073122018-11-27 15:58:47 +0100902component_test_m32_o1 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100903 # Build again with -O1, to compile in the i386 specific inline assembly
904 msg "build: i386, make, gcc -O1 (ASan build)" # ~ 30s
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100905 scripts/config.pl full
906 make CC=gcc CFLAGS='-O1 -Werror -Wall -Wextra -m32 -fsanitize=address'
907
908 msg "test: i386, make, gcc -O1 (ASan build)"
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +0100909 make test
Gilles Peskine8f073122018-11-27 15:58:47 +0100910}
Gilles Peskine878cf602019-01-06 20:50:38 +0000911support_test_m32_o1 () {
912 support_test_m32_o0 "$@"
913}
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +0100914
Gilles Peskine8f073122018-11-27 15:58:47 +0100915component_test_mx32 () {
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +0100916 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
Simon Butcher7a6da6e2018-06-27 21:52:54 +0100917 scripts/config.pl full
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +0100918 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32'
919
920 msg "test: 64-bit ILP32, make, gcc"
921 make test
Gilles Peskine8f073122018-11-27 15:58:47 +0100922}
Gilles Peskine878cf602019-01-06 20:50:38 +0000923support_test_mx32 () {
924 case $(uname -m) in
925 amd64|x86_64) true;;
926 *) false;;
927 esac
928}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000929
Gilles Peskine8f073122018-11-27 15:58:47 +0100930component_test_have_int32 () {
931 msg "build: gcc, force 32-bit bignum limbs"
Gilles Peskine8f073122018-11-27 15:58:47 +0100932 scripts/config.pl unset MBEDTLS_HAVE_ASM
933 scripts/config.pl unset MBEDTLS_AESNI_C
934 scripts/config.pl unset MBEDTLS_PADLOCK_C
935 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +0100936
Gilles Peskine8f073122018-11-27 15:58:47 +0100937 msg "test: gcc, force 32-bit bignum limbs"
938 make test
939}
Andres Amaya Garciafe843a32017-07-20 13:21:34 +0100940
Gilles Peskine8f073122018-11-27 15:58:47 +0100941component_test_have_int64 () {
942 msg "build: gcc, force 64-bit bignum limbs"
Gilles Peskine8f073122018-11-27 15:58:47 +0100943 scripts/config.pl unset MBEDTLS_HAVE_ASM
944 scripts/config.pl unset MBEDTLS_AESNI_C
945 scripts/config.pl unset MBEDTLS_PADLOCK_C
946 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
Gilles Peskine14c3c062018-01-29 21:25:12 +0100947
Gilles Peskine8f073122018-11-27 15:58:47 +0100948 msg "test: gcc, force 64-bit bignum limbs"
949 make test
950}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000951
Gilles Peskine8f073122018-11-27 15:58:47 +0100952component_test_no_udbl_division () {
953 msg "build: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +0100954 scripts/config.pl full
955 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
956 scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
957 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200958
Gilles Peskine8f073122018-11-27 15:58:47 +0100959 msg "test: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
960 make test
961}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200962
Gilles Peskine8f073122018-11-27 15:58:47 +0100963component_test_no_64bit_multiplication () {
964 msg "build: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +0100965 scripts/config.pl full
966 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
967 scripts/config.pl set MBEDTLS_NO_64BIT_MULTIPLICATION
968 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200969
Gilles Peskine8f073122018-11-27 15:58:47 +0100970 msg "test: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
971 make test
972}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200973
Gilles Peskine8f073122018-11-27 15:58:47 +0100974component_build_arm_none_eabi_gcc () {
975 msg "build: arm-none-eabi-gcc, 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
980 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
981 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
982 # following things are not in the default config
983 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
984 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
985 scripts/config.pl unset MBEDTLS_THREADING_C
986 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
987 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
988 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
989}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200990
Gilles Peskine8f073122018-11-27 15:58:47 +0100991component_build_arm_none_eabi_gcc_no_udbl_division () {
992 msg "build: arm-none-eabi-gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +0100993 scripts/config.pl full
994 scripts/config.pl unset MBEDTLS_NET_C
995 scripts/config.pl unset MBEDTLS_TIMING_C
996 scripts/config.pl unset MBEDTLS_FS_IO
997 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
998 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
999 # following things are not in the default config
1000 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
1001 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
1002 scripts/config.pl unset MBEDTLS_THREADING_C
1003 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
1004 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
1005 scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
1006 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
1007 echo "Checking that software 64-bit division is not required"
1008 if_build_succeeded not grep __aeabi_uldiv library/*.o
1009}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001010
Gilles Peskine8f073122018-11-27 15:58:47 +01001011component_build_arm_none_eabi_gcc_no_64bit_multiplication () {
1012 msg "build: arm-none-eabi-gcc MBEDTLS_NO_64BIT_MULTIPLICATION, make" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +01001013 scripts/config.pl full
1014 scripts/config.pl unset MBEDTLS_NET_C
1015 scripts/config.pl unset MBEDTLS_TIMING_C
1016 scripts/config.pl unset MBEDTLS_FS_IO
1017 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
1018 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
1019 # following things are not in the default config
1020 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
1021 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
1022 scripts/config.pl unset MBEDTLS_THREADING_C
1023 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
1024 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
1025 scripts/config.pl set MBEDTLS_NO_64BIT_MULTIPLICATION
1026 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -O1 -march=armv6-m -mthumb' lib
1027 echo "Checking that software 64-bit multiplication is not required"
1028 if_build_succeeded not grep __aeabi_lmul library/*.o
1029}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001030
Gilles Peskine8f073122018-11-27 15:58:47 +01001031component_build_armcc () {
1032 msg "build: ARM Compiler 5, make"
Gilles Peskine8f073122018-11-27 15:58:47 +01001033 scripts/config.pl full
1034 scripts/config.pl unset MBEDTLS_NET_C
1035 scripts/config.pl unset MBEDTLS_TIMING_C
1036 scripts/config.pl unset MBEDTLS_FS_IO
1037 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
1038 scripts/config.pl unset MBEDTLS_HAVE_TIME
1039 scripts/config.pl unset MBEDTLS_HAVE_TIME_DATE
1040 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
1041 # following things are not in the default config
1042 scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
1043 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
1044 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
1045 scripts/config.pl unset MBEDTLS_THREADING_C
1046 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
1047 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
1048 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT # depends on MBEDTLS_HAVE_TIME
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001049
Gilles Peskine8f073122018-11-27 15:58:47 +01001050 if [ $RUN_ARMCC -ne 0 ]; then
1051 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
1052 make clean
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001053
Gilles Peskine8f073122018-11-27 15:58:47 +01001054 # ARM Compiler 6 - Target ARMv7-A
1055 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-a"
Gilles Peskineed942f82017-06-08 15:19:20 +02001056
Gilles Peskine8f073122018-11-27 15:58:47 +01001057 # ARM Compiler 6 - Target ARMv7-M
1058 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m"
Andres AG87bb5772016-09-27 15:05:15 +01001059
Gilles Peskine8f073122018-11-27 15:58:47 +01001060 # ARM Compiler 6 - Target ARMv8-A - AArch32
1061 armc6_build_test "--target=arm-arm-none-eabi -march=armv8.2-a"
Andres AG87bb5772016-09-27 15:05:15 +01001062
Gilles Peskine8f073122018-11-27 15:58:47 +01001063 # ARM Compiler 6 - Target ARMv8-M
1064 armc6_build_test "--target=arm-arm-none-eabi -march=armv8-m.main"
Simon Butcher940737f2017-07-23 13:42:36 +02001065
Gilles Peskine8f073122018-11-27 15:58:47 +01001066 # ARM Compiler 6 - Target ARMv8-A - AArch64
1067 armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a"
1068 fi
1069}
Simon Butcher940737f2017-07-23 13:42:36 +02001070
Gilles Peskine8f073122018-11-27 15:58:47 +01001071component_test_allow_sha1 () {
1072 msg "build: allow SHA1 in certificates by default"
Gilles Peskine8f073122018-11-27 15:58:47 +01001073 scripts/config.pl set MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
1074 make CFLAGS='-Werror -Wall -Wextra'
1075 msg "test: allow SHA1 in certificates by default"
1076 make test
1077 if_build_succeeded tests/ssl-opt.sh -f SHA-1
1078}
Simon Butcher940737f2017-07-23 13:42:36 +02001079
Gilles Peskine8f073122018-11-27 15:58:47 +01001080component_build_mingw () {
1081 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +01001082 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 +02001083
Gilles Peskine8f073122018-11-27 15:58:47 +01001084 # note Make tests only builds the tests, but doesn't run them
1085 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror' WINDOWS_BUILD=1 tests
1086 make WINDOWS_BUILD=1 clean
Hanno Beckere963efa2018-01-03 10:03:43 +00001087
Gilles Peskine8f073122018-11-27 15:58:47 +01001088 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
1089 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
1090 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
1091 make WINDOWS_BUILD=1 clean
1092}
Simon Butcher002bc622016-11-17 09:27:45 +00001093
Gilles Peskine8f073122018-11-27 15:58:47 +01001094component_test_memsan () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001095 msg "build: MSan (clang)" # ~ 1 min 20s
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001096 scripts/config.pl unset MBEDTLS_AESNI_C # memsan doesn't grok asm
1097 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
1098 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +02001099
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001100 msg "test: main suites (MSan)" # ~ 10s
1101 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001102
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001103 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
Gilles Peskine7c652162017-12-11 00:01:40 +01001104 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001105
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001106 # Optional part(s)
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001107
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001108 if [ "$MEMORY" -gt 0 ]; then
1109 msg "test: compat.sh (MSan)" # ~ 6 min 20s
Gilles Peskine7c652162017-12-11 00:01:40 +01001110 if_build_succeeded tests/compat.sh
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001111 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001112}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001113
Gilles Peskine8f073122018-11-27 15:58:47 +01001114component_test_memcheck () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001115 msg "build: Release (clang)"
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001116 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
1117 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001118
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001119 msg "test: main suites valgrind (Release)"
1120 make memcheck
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001121
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001122 # Optional part(s)
1123 # Currently broken, programs don't seem to receive signals
1124 # under valgrind on OS X
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001125
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001126 if [ "$MEMORY" -gt 0 ]; then
1127 msg "test: ssl-opt.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +01001128 if_build_succeeded tests/ssl-opt.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001129 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001130
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001131 if [ "$MEMORY" -gt 1 ]; then
1132 msg "test: compat.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +01001133 if_build_succeeded tests/compat.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001134 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001135}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001136
Gilles Peskine8f073122018-11-27 15:58:47 +01001137component_test_cmake_out_of_source () {
1138 msg "build: cmake 'out-of-source' build"
Gilles Peskine8f073122018-11-27 15:58:47 +01001139 MBEDTLS_ROOT_DIR="$PWD"
1140 mkdir "$OUT_OF_SOURCE_DIR"
1141 cd "$OUT_OF_SOURCE_DIR"
1142 cmake "$MBEDTLS_ROOT_DIR"
1143 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001144
Gilles Peskine8f073122018-11-27 15:58:47 +01001145 msg "test: cmake 'out-of-source' build"
1146 make test
1147 # Test an SSL option that requires an auxiliary script in test/scripts/.
1148 # Also ensure that there are no error messages such as
1149 # "No such file or directory", which would indicate that some required
1150 # file is missing (ssl-opt.sh tolerates the absence of some files so
1151 # may exit with status 0 but emit errors).
1152 if_build_succeeded ./tests/ssl-opt.sh -f 'Fallback SCSV: beginning of list' 2>ssl-opt.err
1153 if [ -s ssl-opt.err ]; then
1154 cat ssl-opt.err >&2
1155 record_status [ ! -s ssl-opt.err ]
1156 rm ssl-opt.err
1157 fi
1158 cd "$MBEDTLS_ROOT_DIR"
1159 rm -rf "$OUT_OF_SOURCE_DIR"
1160 unset MBEDTLS_ROOT_DIR
1161}
Andres AGdc192212016-08-31 17:33:13 +01001162
Gilles Peskine8f073122018-11-27 15:58:47 +01001163component_test_zeroize () {
1164 # Test that the function mbedtls_platform_zeroize() is not optimized away by
1165 # different combinations of compilers and optimization flags by using an
1166 # auxiliary GDB script. Unfortunately, GDB does not return error values to the
1167 # system in all cases that the script fails, so we must manually search the
1168 # output to check whether the pass string is present and no failure strings
1169 # were printed.
Gilles Peskine4976e822019-01-06 19:52:22 +00001170
1171 # Don't try to disable ASLR. We don't care about ASLR here. We do care
1172 # about a spurious message if Gdb tries and fails, so suppress that.
1173 gdb_disable_aslr=
1174 if [ -z "$(gdb -batch -nw -ex 'set disable-randomization off' 2>&1)" ]; then
1175 gdb_disable_aslr='set disable-randomization off'
1176 fi
1177
Gilles Peskine8f073122018-11-27 15:58:47 +01001178 for optimization_flag in -O2 -O3 -Ofast -Os; do
Gilles Peskine55f7c942019-01-09 22:28:21 +01001179 for compiler in clang gcc; do
1180 msg "test: $compiler $optimization_flag, mbedtls_platform_zeroize()"
1181 make programs CC="$compiler" DEBUG=1 CFLAGS="$optimization_flag"
Gilles Peskine4976e822019-01-06 19:52:22 +00001182 if_build_succeeded gdb -ex "$gdb_disable_aslr" -x tests/scripts/test_zeroize.gdb -nw -batch -nx 2>&1 | tee test_zeroize.log
Gilles Peskine55f7c942019-01-09 22:28:21 +01001183 if_build_succeeded grep "The buffer was correctly zeroized" test_zeroize.log
1184 if_build_succeeded not grep -i "error" test_zeroize.log
1185 rm -f test_zeroize.log
1186 make clean
1187 done
Andres Amaya Garcia29673812017-10-25 10:35:51 +01001188 done
Gilles Peskine4976e822019-01-06 19:52:22 +00001189
1190 unset gdb_disable_aslr
Gilles Peskine8f073122018-11-27 15:58:47 +01001191}
Andres Amaya Garciad0d7bf62017-10-25 09:01:31 +01001192
Gilles Peskine8f073122018-11-27 15:58:47 +01001193component_check_python_files () {
1194 msg "Lint: Python scripts"
1195 record_status tests/scripts/check-python-files.sh
1196}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001197
Gilles Peskine8f073122018-11-27 15:58:47 +01001198component_check_generate_test_code () {
1199 msg "uint test: generate_test_code.py"
1200 record_status ./tests/scripts/test_generate_test_code.py
1201}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001202
1203################################################################
1204#### Termination
1205################################################################
1206
Gilles Peskine8f073122018-11-27 15:58:47 +01001207post_report () {
1208 msg "Done, cleaning up"
1209 cleanup
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001210
Gilles Peskine8f073122018-11-27 15:58:47 +01001211 final_report
1212}
1213
1214
1215
1216################################################################
1217#### Run all the things
1218################################################################
1219
Gilles Peskinee48351a2018-11-27 16:06:30 +01001220# Run one component and clean up afterwards.
Gilles Peskine8f073122018-11-27 15:58:47 +01001221run_component () {
Gilles Peskine608953e2019-01-02 18:57:02 +01001222 # Back up the configuration in case the component modifies it.
1223 # The cleanup function will restore it.
1224 cp -p "$CONFIG_H" "$CONFIG_BAK"
Gilles Peskineffcdeff2018-12-04 12:49:28 +01001225 current_component="$1"
Gilles Peskine8f073122018-11-27 15:58:47 +01001226 "$@"
Gilles Peskinee48351a2018-11-27 16:06:30 +01001227 cleanup
Gilles Peskine8f073122018-11-27 15:58:47 +01001228}
1229
1230# Preliminary setup
1231pre_check_environment
1232pre_initialize_variables
1233pre_parse_command_line "$@"
Gilles Peskine348fb9a2018-11-27 17:04:29 +01001234
Gilles Peskine878cf602019-01-06 20:50:38 +00001235pre_check_git
1236build_status=0
1237if [ $KEEP_GOING -eq 1 ]; then
1238 pre_setup_keep_going
1239else
1240 record_status () {
1241 "$@"
1242 }
1243fi
1244pre_print_configuration
1245pre_check_tools
1246pre_print_tools
1247cleanup
Gilles Peskine8f073122018-11-27 15:58:47 +01001248
Gilles Peskinebeb3a812019-01-06 22:11:25 +00001249# Run the requested tests.
1250for component in $RUN_COMPONENTS; do
1251 run_component "component_$component"
1252done
Gilles Peskine8f073122018-11-27 15:58:47 +01001253
1254# We're done.
Gilles Peskine878cf602019-01-06 20:50:38 +00001255post_report