blob: 46ca5d5f4d6393d74aa8de5a19e38e025766132b [file] [log] [blame]
Andres AG31f9b5b2016-10-04 17:14:38 +01001#! /usr/bin/env sh
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01002
Simon Butcher3ea7f522016-03-07 23:22:10 +00003# all.sh
4#
SimonB2e23c822016-04-16 21:54:39 +01005# This file is part of mbed TLS (https://tls.mbed.org)
6#
Gilles Peskine192c72f2017-12-21 15:59:21 +01007# Copyright (c) 2014-2017, ARM Limited, All Rights Reserved
8
9
10
11################################################################
12#### Documentation
13################################################################
14
Simon Butcher3ea7f522016-03-07 23:22:10 +000015# Purpose
Gilles Peskine192c72f2017-12-21 15:59:21 +010016# -------
Simon Butcher3ea7f522016-03-07 23:22:10 +000017#
SimonB2e23c822016-04-16 21:54:39 +010018# To run all tests possible or available on the platform.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010019#
Gilles Peskine192c72f2017-12-21 15:59:21 +010020# Notes for users
21# ---------------
22#
SimonB2e23c822016-04-16 21:54:39 +010023# Warning: the test is destructive. It includes various build modes and
24# configurations, and can and will arbitrarily change the current CMake
Gilles Peskine192c72f2017-12-21 15:59:21 +010025# configuration. The following files must be committed into git:
26# * include/mbedtls/config.h
27# * Makefile, library/Makefile, programs/Makefile, tests/Makefile
28# After running this script, the CMake cache will be lost and CMake
29# will no longer be initialised.
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +010030#
Gilles Peskine192c72f2017-12-21 15:59:21 +010031# The script assumes the presence of a number of tools:
32# * Basic Unix tools (Windows users note: a Unix-style find must be before
33# the Windows find in the PATH)
34# * Perl
35# * GNU Make
36# * CMake
37# * GCC and Clang (recent enough for using ASan with gcc and MemSan with clang, or valgrind)
Andrzej Kurek05be06c2018-06-28 04:41:50 -040038# * G++
Gilles Peskine192c72f2017-12-21 15:59:21 +010039# * arm-gcc and mingw-gcc
40# * ArmCC 5 and ArmCC 6, unless invoked with --no-armcc
Gilles Peskine192c72f2017-12-21 15:59:21 +010041# * OpenSSL and GnuTLS command line tools, recent enough for the
42# interoperability tests. If they don't support SSLv3 then a legacy
43# version of these tools must be present as well (search for LEGACY
44# below).
45# See the invocation of check_tools below for details.
46#
47# This script must be invoked from the toplevel directory of a git
48# working copy of Mbed TLS.
49#
50# Note that the output is not saved. You may want to run
51# script -c tests/scripts/all.sh
52# or
53# tests/scripts/all.sh >all.log 2>&1
54#
55# Notes for maintainers
56# ---------------------
57#
Gilles Peskine8f073122018-11-27 15:58:47 +010058# The bulk of the code is organized into functions that follow one of the
59# following naming conventions:
60# * pre_XXX: things to do before running the tests, in order.
61# * component_XXX: independent components. They can be run in any order.
62# * component_check_XXX: quick tests that aren't worth parallelizing
63# * component_build_XXX: build things but don't run them
64# * component_test_XXX: build and test
Gilles Peskine10726102019-01-06 20:50:38 +000065# * support_XXX: if support_XXX exists and returns false then
66# component_XXX is not run by default.
Gilles Peskine8f073122018-11-27 15:58:47 +010067# * post_XXX: things to do after running the tests.
68# * other: miscellaneous support functions.
69#
Gilles Peskine192c72f2017-12-21 15:59:21 +010070# The tests are roughly in order from fastest to slowest. This doesn't
71# have to be exact, but in general you should add slower tests towards
72# the end and fast checks near the beginning.
73#
74# Sanity checks have the following form:
75# 1. msg "short description of what is about to be done"
76# 2. run sanity check (failure stops the script)
77#
78# Build or build-and-test steps have the following form:
79# 1. msg "short description of what is about to be done"
80# 2. cleanup
81# 3. preparation (config.pl, cmake, ...) (failure stops the script)
82# 4. make
83# 5. Run tests if relevant. All tests must be prefixed with
84# if_build_successful for the sake of --keep-going.
85
86
87
88################################################################
89#### Initialization and command line parsing
90################################################################
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010091
SimonB2e23c822016-04-16 21:54:39 +010092# Abort on errors (and uninitialised variables)
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010093set -eu
94
Gilles Peskine8f073122018-11-27 15:58:47 +010095pre_check_environment () {
Gilles Peskinebdf3f522019-01-06 19:58:02 +000096 if [ -d library -a -d include -a -d tests ]; then :; else
Gilles Peskine8f073122018-11-27 15:58:47 +010097 echo "Must be run from mbed TLS root" >&2
98 exit 1
99 fi
100}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100101
Gilles Peskine8f073122018-11-27 15:58:47 +0100102pre_initialize_variables () {
103 CONFIG_H='include/mbedtls/config.h'
104 CONFIG_BAK="$CONFIG_H.bak"
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200105
Gilles 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 Peskine55ae1622019-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 Peskine10726102019-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 Peskine10726102019-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 Peskine10726102019-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 Peskine1bcb1c82019-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 Peskine10726102019-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 Peskine1bcb1c82019-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 Peskine06b385f2019-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 Peskine1bcb1c82019-01-06 22:11:25 +0000300 --except) all_except=1;;
Gilles Peskine06b385f2019-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 Peskine10726102019-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 Peskine06b385f2019-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 Peskine1bcb1c82019-01-06 22:11:25 +0000327 *) COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS $1";;
Gilles Peskine06b385f2019-01-09 22:28:21 +0100328 esac
329 shift
Gilles Peskine8f073122018-11-27 15:58:47 +0100330 done
Gilles Peskine1bcb1c82019-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
Gilles Peskine192c72f2017-12-21 15:59:21 +0100539################################################################
540#### Build and test many configurations and targets
541################################################################
542
Gilles Peskine8f073122018-11-27 15:58:47 +0100543component_test_default_cmake_gcc_asan () {
544 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100545 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
546 make
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100547
Gilles Peskine8f073122018-11-27 15:58:47 +0100548 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
549 make test
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200550
Gilles Peskine8f073122018-11-27 15:58:47 +0100551 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
552 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200553
Gilles Peskine8f073122018-11-27 15:58:47 +0100554 msg "test: compat.sh (ASan build)" # ~ 6 min
555 if_build_succeeded tests/compat.sh
556}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200557
Gilles Peskine782f4112018-11-27 16:11:09 +0100558component_test_ref_configs () {
559 msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
560 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
561 record_status tests/scripts/test-ref-configs.pl
562}
563
Gilles Peskine8f073122018-11-27 15:58:47 +0100564component_test_sslv3 () {
565 msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100566 scripts/config.pl set MBEDTLS_SSL_PROTO_SSL3
567 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
568 make
Simon Butcher3ea7f522016-03-07 23:22:10 +0000569
Gilles Peskine8f073122018-11-27 15:58:47 +0100570 msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
571 make test
Simon Butcher3ea7f522016-03-07 23:22:10 +0000572
Gilles Peskine8f073122018-11-27 15:58:47 +0100573 msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
574 if_build_succeeded tests/compat.sh -m 'tls1 tls1_1 tls1_2 dtls1 dtls1_2'
575 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
Simon Butcher3ea7f522016-03-07 23:22:10 +0000576
Gilles Peskine8f073122018-11-27 15:58:47 +0100577 msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
578 if_build_succeeded tests/ssl-opt.sh
579}
Simon Butcher3ea7f522016-03-07 23:22:10 +0000580
Gilles Peskine8f073122018-11-27 15:58:47 +0100581component_test_no_renegotiation () {
582 msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100583 scripts/config.pl unset MBEDTLS_SSL_RENEGOTIATION
584 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
585 make
Hanno Becker134c2ab2017-10-12 15:29:50 +0100586
Gilles Peskine8f073122018-11-27 15:58:47 +0100587 msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
588 make test
Hanno Becker134c2ab2017-10-12 15:29:50 +0100589
Gilles Peskine8f073122018-11-27 15:58:47 +0100590 msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
591 if_build_succeeded tests/ssl-opt.sh
592}
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +0100593
Gilles Peskine8f073122018-11-27 15:58:47 +0100594component_test_rsa_no_crt () {
595 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100596 scripts/config.pl set MBEDTLS_RSA_NO_CRT
597 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
598 make
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100599
Gilles Peskine8f073122018-11-27 15:58:47 +0100600 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
601 make test
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100602
Gilles Peskine8f073122018-11-27 15:58:47 +0100603 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
604 if_build_succeeded tests/ssl-opt.sh -f RSA
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100605
Gilles Peskine8f073122018-11-27 15:58:47 +0100606 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
607 if_build_succeeded tests/compat.sh -t RSA
608}
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100609
Gilles Peskine8f073122018-11-27 15:58:47 +0100610component_test_small_ssl_out_content_len () {
611 msg "build: small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100612 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 16384
613 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
614 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
615 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000616
Gilles Peskine8f073122018-11-27 15:58:47 +0100617 msg "test: small SSL_OUT_CONTENT_LEN - ssl-opt.sh MFL and large packet tests"
618 if_build_succeeded tests/ssl-opt.sh -f "Max fragment\|Large packet"
619}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000620
Gilles Peskine8f073122018-11-27 15:58:47 +0100621component_test_small_ssl_in_content_len () {
622 msg "build: small SSL_IN_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100623 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 4096
624 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 16384
625 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
626 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000627
Gilles Peskine8f073122018-11-27 15:58:47 +0100628 msg "test: small SSL_IN_CONTENT_LEN - ssl-opt.sh MFL tests"
629 if_build_succeeded tests/ssl-opt.sh -f "Max fragment"
630}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000631
Gilles Peskine8f073122018-11-27 15:58:47 +0100632component_test_small_ssl_dtls_max_buffering () {
633 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0"
Gilles Peskine8f073122018-11-27 15:58:47 +0100634 scripts/config.pl set MBEDTLS_SSL_DTLS_MAX_BUFFERING 1000
635 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
636 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100637
Gilles Peskine8f073122018-11-27 15:58:47 +0100638 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0 - ssl-opt.sh specific reordering test"
639 if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer out-of-order hs msg before reassembling next, free buffered msg"
640}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100641
Gilles Peskine8f073122018-11-27 15:58:47 +0100642component_test_small_mbedtls_ssl_dtls_max_buffering () {
643 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1"
Gilles Peskine8f073122018-11-27 15:58:47 +0100644 scripts/config.pl set MBEDTLS_SSL_DTLS_MAX_BUFFERING 240
645 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
646 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100647
Gilles Peskine8f073122018-11-27 15:58:47 +0100648 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1 - ssl-opt.sh specific reordering test"
649 if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer encrypted Finished message, drop for fragmented NewSessionTicket"
650}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100651
Gilles Peskine8f073122018-11-27 15:58:47 +0100652component_test_full_cmake_clang () {
653 msg "build: cmake, full config, clang" # ~ 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100654 scripts/config.pl full
655 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
656 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check -D ENABLE_TESTING=On .
657 make
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100658
Gilles Peskine8f073122018-11-27 15:58:47 +0100659 msg "test: main suites (full config)" # ~ 5s
660 make test
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200661
Gilles Peskine8f073122018-11-27 15:58:47 +0100662 msg "test: ssl-opt.sh default, ECJPAKE, SSL async (full config)" # ~ 1s
663 if_build_succeeded tests/ssl-opt.sh -f 'Default\|ECJPAKE\|SSL async private'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200664
Gilles Peskine8f073122018-11-27 15:58:47 +0100665 msg "test: compat.sh RC4, DES & NULL (full config)" # ~ 2 min
666 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 +0200667
Gilles Peskine8f073122018-11-27 15:58:47 +0100668 msg "test: compat.sh ARIA + ChachaPoly"
669 if_build_succeeded env OPENSSL_CMD="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
670}
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100671
Gilles Peskine8f073122018-11-27 15:58:47 +0100672component_build_deprecated () {
673 msg "build: make, full config + DEPRECATED_WARNING, gcc -O" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100674 scripts/config.pl full
675 scripts/config.pl set MBEDTLS_DEPRECATED_WARNING
676 # Build with -O -Wextra to catch a maximum of issues.
677 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra' lib programs
678 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
Gilles Peskineb4ef45b2018-03-01 22:23:50 +0100679
Gilles Peskine8f073122018-11-27 15:58:47 +0100680 msg "build: make, full config + DEPRECATED_REMOVED, clang -O" # ~ 30s
681 # No cleanup, just tweak the configuration and rebuild
682 make clean
683 scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
684 scripts/config.pl set MBEDTLS_DEPRECATED_REMOVED
685 # Build with -O -Wextra to catch a maximum of issues.
686 make CC=clang CFLAGS='-O -Werror -Wall -Wextra' lib programs
687 make CC=clang CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
688}
Gilles Peskine0afe6242018-02-21 19:28:12 +0100689
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200690
Gilles Peskine8f073122018-11-27 15:58:47 +0100691component_test_depends_curves () {
692 msg "test/build: curves.pl (gcc)" # ~ 4 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100693 record_status tests/scripts/curves.pl
694}
Manuel Pégourié-Gonnard1fe6bb92017-06-06 11:36:16 +0200695
Gilles Peskine8f073122018-11-27 15:58:47 +0100696component_test_depends_hashes () {
697 msg "test/build: depends-hashes.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100698 record_status tests/scripts/depends-hashes.pl
699}
Manuel Pégourié-Gonnard43be6cd2017-06-20 09:53:42 +0200700
Gilles Peskine8f073122018-11-27 15:58:47 +0100701component_test_depends_pkalgs () {
702 msg "test/build: depends-pkalgs.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100703 record_status tests/scripts/depends-pkalgs.pl
704}
Manuel Pégourié-Gonnard503a5ef2015-10-23 09:04:45 +0200705
Gilles Peskine8f073122018-11-27 15:58:47 +0100706component_build_key_exchanges () {
707 msg "test/build: key-exchanges (gcc)" # ~ 1 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100708 record_status tests/scripts/key-exchanges.pl
709}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100710
Gilles Peskine8f073122018-11-27 15:58:47 +0100711component_build_default_make_gcc_and_cxx () {
712 msg "build: Unix make, -Os (gcc)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100713 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400714
Gilles Peskine8f073122018-11-27 15:58:47 +0100715 msg "test: verify header list in cpp_dummy_build.cpp"
716 record_status check_headers_in_cpp
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400717
Gilles Peskine8f073122018-11-27 15:58:47 +0100718 msg "build: Unix make, incremental g++"
719 make TEST_CPP=1
720}
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +0000721
Gilles Peskine8f073122018-11-27 15:58:47 +0100722component_test_no_platform () {
723 # Full configuration build, without platform support, file IO and net sockets.
724 # This should catch missing mbedtls_printf definitions, and by disabling file
725 # IO, it should catch missing '#include <stdio.h>'
726 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100727 scripts/config.pl full
728 scripts/config.pl unset MBEDTLS_PLATFORM_C
729 scripts/config.pl unset MBEDTLS_NET_C
730 scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
731 scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
732 scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
733 scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
734 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
735 scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
736 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
737 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
738 scripts/config.pl unset MBEDTLS_FS_IO
Gilles Peskine51585382019-01-05 10:27:47 +0100739 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_FILE_C
740 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_C
Gilles Peskine8f073122018-11-27 15:58:47 +0100741 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
742 # to re-enable platform integration features otherwise disabled in C99 builds
743 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -O0 -D_DEFAULT_SOURCE' lib programs
744 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0' test
745}
Manuel Pégourié-Gonnarddccb80b2015-06-03 10:20:33 +0100746
Gilles Peskine8f073122018-11-27 15:58:47 +0100747component_build_no_std_function () {
748 # catch compile bugs in _uninit functions
749 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100750 scripts/config.pl full
751 scripts/config.pl set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
752 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
753 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
754}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200755
Gilles Peskine8f073122018-11-27 15:58:47 +0100756component_build_no_ssl_srv () {
757 msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100758 scripts/config.pl full
759 scripts/config.pl unset MBEDTLS_SSL_SRV_C
760 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
761}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +0200762
Gilles Peskine8f073122018-11-27 15:58:47 +0100763component_build_no_ssl_cli () {
764 msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100765 scripts/config.pl full
766 scripts/config.pl unset MBEDTLS_SSL_CLI_C
767 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
768}
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +0200769
Gilles Peskine8f073122018-11-27 15:58:47 +0100770component_build_no_sockets () {
771 # Note, C99 compliance can also be tested with the sockets support disabled,
772 # as that requires a POSIX platform (which isn't the same as C99).
773 msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100774 scripts/config.pl full
775 scripts/config.pl unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
776 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
777 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0 -std=c99 -pedantic' lib
778}
Hanno Becker5175ac62017-09-18 15:36:25 +0100779
Gilles Peskine8f073122018-11-27 15:58:47 +0100780component_test_no_max_fragment_length () {
781 # Run max fragment length tests with MFL disabled
782 msg "build: default config except MFL extension (ASan build)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100783 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
784 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
785 make
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000786
Gilles Peskine8f073122018-11-27 15:58:47 +0100787 msg "test: ssl-opt.sh, MFL-related tests"
788 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length"
789}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000790
Gilles Peskine8f073122018-11-27 15:58:47 +0100791component_test_no_max_fragment_length_small_ssl_out_content_len () {
792 msg "build: no MFL extension, small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100793 scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
794 scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 16384
795 scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
796 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
797 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000798
Gilles Peskine8f073122018-11-27 15:58:47 +0100799 msg "test: MFL tests (disabled MFL extension case) & large packet tests"
800 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length\|Large buffer"
801}
Janos Follath06c54002016-06-09 13:57:40 +0100802
Gilles Peskine8f073122018-11-27 15:58:47 +0100803component_test_null_entropy () {
804 msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100805 scripts/config.pl set MBEDTLS_TEST_NULL_ENTROPY
806 scripts/config.pl set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
807 scripts/config.pl set MBEDTLS_ENTROPY_C
808 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
809 scripts/config.pl unset MBEDTLS_ENTROPY_HARDWARE_ALT
810 scripts/config.pl unset MBEDTLS_HAVEGE_C
Gilles Peskine19275652019-01-06 19:48:30 +0000811 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan -D UNSAFE_BUILD=ON .
Gilles Peskine8f073122018-11-27 15:58:47 +0100812 make
Janos Follath06c54002016-06-09 13:57:40 +0100813
Gilles Peskine8f073122018-11-27 15:58:47 +0100814 msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)"
815 make test
816}
Hanno Beckere5fecec2018-10-11 11:02:52 +0100817
Gilles Peskine8f073122018-11-27 15:58:47 +0100818component_test_platform_calloc_macro () {
819 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100820 scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
821 scripts/config.pl set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
822 scripts/config.pl set MBEDTLS_PLATFORM_FREE_MACRO free
823 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
824 make
Hanno Beckere5fecec2018-10-11 11:02:52 +0100825
Gilles Peskine8f073122018-11-27 15:58:47 +0100826 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
827 make test
828}
Hanno Becker83ebf782017-07-07 12:29:15 +0100829
Gilles Peskine8f073122018-11-27 15:58:47 +0100830component_test_aes_fewer_tables () {
831 msg "build: default config with AES_FEWER_TABLES enabled"
Gilles Peskine8f073122018-11-27 15:58:47 +0100832 scripts/config.pl set MBEDTLS_AES_FEWER_TABLES
833 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +0100834
Gilles Peskine8f073122018-11-27 15:58:47 +0100835 msg "test: AES_FEWER_TABLES"
836 make test
837}
Hanno Becker83ebf782017-07-07 12:29:15 +0100838
Gilles Peskine8f073122018-11-27 15:58:47 +0100839component_test_aes_rom_tables () {
840 msg "build: default config with AES_ROM_TABLES enabled"
Gilles Peskine8f073122018-11-27 15:58:47 +0100841 scripts/config.pl set MBEDTLS_AES_ROM_TABLES
842 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +0100843
Gilles Peskine8f073122018-11-27 15:58:47 +0100844 msg "test: AES_ROM_TABLES"
845 make test
846}
Hanno Becker83ebf782017-07-07 12:29:15 +0100847
Gilles Peskine8f073122018-11-27 15:58:47 +0100848component_test_aes_fewer_tables_and_rom_tables () {
849 msg "build: default config with AES_ROM_TABLES and AES_FEWER_TABLES enabled"
Gilles Peskine8f073122018-11-27 15:58:47 +0100850 scripts/config.pl set MBEDTLS_AES_FEWER_TABLES
851 scripts/config.pl set MBEDTLS_AES_ROM_TABLES
852 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +0100853
Gilles Peskine8f073122018-11-27 15:58:47 +0100854 msg "test: AES_FEWER_TABLES + AES_ROM_TABLES"
855 make test
856}
857
858component_test_make_shared () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100859 msg "build/test: make shared" # ~ 40s
Gilles Peskine7ad603e2017-12-10 23:22:20 +0100860 make SHARED=1 all check
Gilles Peskine8f073122018-11-27 15:58:47 +0100861}
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +0200862
Gilles Peskine8f073122018-11-27 15:58:47 +0100863component_test_m32_o0 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100864 # Build once with -O0, to compile out the i386 specific inline assembly
865 msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
Simon Butcher7a6da6e2018-06-27 21:52:54 +0100866 scripts/config.pl full
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100867 make CC=gcc CFLAGS='-O0 -Werror -Wall -Wextra -m32 -fsanitize=address'
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +0100868
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100869 msg "test: i386, make, gcc -O0 (ASan build)"
870 make test
Gilles Peskine8f073122018-11-27 15:58:47 +0100871}
Gilles Peskine10726102019-01-06 20:50:38 +0000872support_test_m32_o0 () {
873 case $(uname -m) in
874 *64*) true;;
875 *) false;;
876 esac
877}
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100878
Gilles Peskine8f073122018-11-27 15:58:47 +0100879component_test_m32_o1 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100880 # Build again with -O1, to compile in the i386 specific inline assembly
881 msg "build: i386, make, gcc -O1 (ASan build)" # ~ 30s
Simon Butcher8e6a22a2018-07-20 21:27:33 +0100882 scripts/config.pl full
883 make CC=gcc CFLAGS='-O1 -Werror -Wall -Wextra -m32 -fsanitize=address'
884
885 msg "test: i386, make, gcc -O1 (ASan build)"
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +0100886 make test
Gilles Peskine8f073122018-11-27 15:58:47 +0100887}
Gilles Peskine10726102019-01-06 20:50:38 +0000888support_test_m32_o1 () {
889 support_test_m32_o0 "$@"
890}
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +0100891
Gilles Peskine8f073122018-11-27 15:58:47 +0100892component_test_mx32 () {
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +0100893 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
Simon Butcher7a6da6e2018-06-27 21:52:54 +0100894 scripts/config.pl full
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +0100895 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32'
896
897 msg "test: 64-bit ILP32, make, gcc"
898 make test
Gilles Peskine8f073122018-11-27 15:58:47 +0100899}
Gilles Peskine10726102019-01-06 20:50:38 +0000900support_test_mx32 () {
901 case $(uname -m) in
902 amd64|x86_64) true;;
903 *) false;;
904 esac
905}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000906
Gilles Peskine8f073122018-11-27 15:58:47 +0100907component_test_have_int32 () {
908 msg "build: gcc, force 32-bit bignum limbs"
Gilles Peskine8f073122018-11-27 15:58:47 +0100909 scripts/config.pl unset MBEDTLS_HAVE_ASM
910 scripts/config.pl unset MBEDTLS_AESNI_C
911 scripts/config.pl unset MBEDTLS_PADLOCK_C
912 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +0100913
Gilles Peskine8f073122018-11-27 15:58:47 +0100914 msg "test: gcc, force 32-bit bignum limbs"
915 make test
916}
Andres Amaya Garciafe843a32017-07-20 13:21:34 +0100917
Gilles Peskine8f073122018-11-27 15:58:47 +0100918component_test_have_int64 () {
919 msg "build: gcc, force 64-bit bignum limbs"
Gilles Peskine8f073122018-11-27 15:58:47 +0100920 scripts/config.pl unset MBEDTLS_HAVE_ASM
921 scripts/config.pl unset MBEDTLS_AESNI_C
922 scripts/config.pl unset MBEDTLS_PADLOCK_C
923 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
Gilles Peskine14c3c062018-01-29 21:25:12 +0100924
Gilles Peskine8f073122018-11-27 15:58:47 +0100925 msg "test: gcc, force 64-bit bignum limbs"
926 make test
927}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +0000928
Gilles Peskine8f073122018-11-27 15:58:47 +0100929component_test_no_udbl_division () {
930 msg "build: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +0100931 scripts/config.pl full
932 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
933 scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
934 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200935
Gilles Peskine8f073122018-11-27 15:58:47 +0100936 msg "test: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
937 make test
938}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200939
Gilles Peskine8f073122018-11-27 15:58:47 +0100940component_test_no_64bit_multiplication () {
941 msg "build: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +0100942 scripts/config.pl full
943 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
944 scripts/config.pl set MBEDTLS_NO_64BIT_MULTIPLICATION
945 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200946
Gilles Peskine8f073122018-11-27 15:58:47 +0100947 msg "test: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
948 make test
949}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200950
Gilles Peskine8f073122018-11-27 15:58:47 +0100951component_build_arm_none_eabi_gcc () {
952 msg "build: arm-none-eabi-gcc, make" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +0100953 scripts/config.pl full
954 scripts/config.pl unset MBEDTLS_NET_C
955 scripts/config.pl unset MBEDTLS_TIMING_C
956 scripts/config.pl unset MBEDTLS_FS_IO
Gilles Peskine51585382019-01-05 10:27:47 +0100957 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_FILE_C
958 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_C
Gilles Peskine8f073122018-11-27 15:58:47 +0100959 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
960 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
961 # following things are not in the default config
962 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
963 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
964 scripts/config.pl unset MBEDTLS_THREADING_C
965 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
966 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
967 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
968}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200969
Gilles Peskine8f073122018-11-27 15:58:47 +0100970component_build_arm_none_eabi_gcc_no_udbl_division () {
971 msg "build: arm-none-eabi-gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +0100972 scripts/config.pl full
973 scripts/config.pl unset MBEDTLS_NET_C
974 scripts/config.pl unset MBEDTLS_TIMING_C
975 scripts/config.pl unset MBEDTLS_FS_IO
Gilles Peskine51585382019-01-05 10:27:47 +0100976 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_FILE_C
977 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_C
Gilles Peskine8f073122018-11-27 15:58:47 +0100978 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
979 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
980 # following things are not in the default config
981 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
982 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
983 scripts/config.pl unset MBEDTLS_THREADING_C
984 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
985 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
986 scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
987 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
988 echo "Checking that software 64-bit division is not required"
989 if_build_succeeded not grep __aeabi_uldiv library/*.o
990}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200991
Gilles Peskine8f073122018-11-27 15:58:47 +0100992component_build_arm_none_eabi_gcc_no_64bit_multiplication () {
993 msg "build: arm-none-eabi-gcc MBEDTLS_NO_64BIT_MULTIPLICATION, make" # ~ 10s
Gilles Peskine8f073122018-11-27 15:58:47 +0100994 scripts/config.pl full
995 scripts/config.pl unset MBEDTLS_NET_C
996 scripts/config.pl unset MBEDTLS_TIMING_C
997 scripts/config.pl unset MBEDTLS_FS_IO
Gilles Peskine51585382019-01-05 10:27:47 +0100998 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_FILE_C
999 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_C
Gilles Peskine8f073122018-11-27 15:58:47 +01001000 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
1001 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
1002 # following things are not in the default config
1003 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
1004 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
1005 scripts/config.pl unset MBEDTLS_THREADING_C
1006 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
1007 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
1008 scripts/config.pl set MBEDTLS_NO_64BIT_MULTIPLICATION
1009 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -O1 -march=armv6-m -mthumb' lib
1010 echo "Checking that software 64-bit multiplication is not required"
1011 if_build_succeeded not grep __aeabi_lmul library/*.o
1012}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001013
Gilles Peskine8f073122018-11-27 15:58:47 +01001014component_build_armcc () {
1015 msg "build: ARM Compiler 5, make"
Gilles Peskine8f073122018-11-27 15:58:47 +01001016 scripts/config.pl full
1017 scripts/config.pl unset MBEDTLS_NET_C
1018 scripts/config.pl unset MBEDTLS_TIMING_C
1019 scripts/config.pl unset MBEDTLS_FS_IO
Gilles Peskine51585382019-01-05 10:27:47 +01001020 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_FILE_C
1021 scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_C
Gilles Peskine8f073122018-11-27 15:58:47 +01001022 scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
1023 scripts/config.pl unset MBEDTLS_HAVE_TIME
1024 scripts/config.pl unset MBEDTLS_HAVE_TIME_DATE
1025 scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY
1026 # following things are not in the default config
1027 scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING
1028 scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c
1029 scripts/config.pl unset MBEDTLS_THREADING_PTHREAD
1030 scripts/config.pl unset MBEDTLS_THREADING_C
1031 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h
1032 scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit
1033 scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT # depends on MBEDTLS_HAVE_TIME
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001034
Gilles Peskine8f073122018-11-27 15:58:47 +01001035 if [ $RUN_ARMCC -ne 0 ]; then
1036 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
1037 make clean
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001038
Gilles Peskine8f073122018-11-27 15:58:47 +01001039 # ARM Compiler 6 - Target ARMv7-A
1040 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-a"
Gilles Peskineed942f82017-06-08 15:19:20 +02001041
Gilles Peskine8f073122018-11-27 15:58:47 +01001042 # ARM Compiler 6 - Target ARMv7-M
1043 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m"
Andres AG87bb5772016-09-27 15:05:15 +01001044
Gilles Peskine8f073122018-11-27 15:58:47 +01001045 # ARM Compiler 6 - Target ARMv8-A - AArch32
1046 armc6_build_test "--target=arm-arm-none-eabi -march=armv8.2-a"
Andres AG87bb5772016-09-27 15:05:15 +01001047
Gilles Peskine8f073122018-11-27 15:58:47 +01001048 # ARM Compiler 6 - Target ARMv8-M
1049 armc6_build_test "--target=arm-arm-none-eabi -march=armv8-m.main"
Simon Butcher940737f2017-07-23 13:42:36 +02001050
Gilles Peskine8f073122018-11-27 15:58:47 +01001051 # ARM Compiler 6 - Target ARMv8-A - AArch64
1052 armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a"
1053 fi
1054}
Simon Butcher940737f2017-07-23 13:42:36 +02001055
Gilles Peskine8f073122018-11-27 15:58:47 +01001056component_test_allow_sha1 () {
1057 msg "build: allow SHA1 in certificates by default"
Gilles Peskine8f073122018-11-27 15:58:47 +01001058 scripts/config.pl set MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
1059 make CFLAGS='-Werror -Wall -Wextra'
1060 msg "test: allow SHA1 in certificates by default"
1061 make test
1062 if_build_succeeded tests/ssl-opt.sh -f SHA-1
1063}
Simon Butcher940737f2017-07-23 13:42:36 +02001064
Gilles Peskine8f073122018-11-27 15:58:47 +01001065component_build_mingw () {
1066 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +01001067 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 +02001068
Gilles Peskine8f073122018-11-27 15:58:47 +01001069 # note Make tests only builds the tests, but doesn't run them
1070 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror' WINDOWS_BUILD=1 tests
1071 make WINDOWS_BUILD=1 clean
Hanno Beckere963efa2018-01-03 10:03:43 +00001072
Gilles Peskine8f073122018-11-27 15:58:47 +01001073 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
1074 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
1075 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
1076 make WINDOWS_BUILD=1 clean
1077}
Simon Butcher002bc622016-11-17 09:27:45 +00001078
Gilles Peskine8f073122018-11-27 15:58:47 +01001079component_test_memsan () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001080 msg "build: MSan (clang)" # ~ 1 min 20s
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001081 scripts/config.pl unset MBEDTLS_AESNI_C # memsan doesn't grok asm
1082 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
1083 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +02001084
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001085 msg "test: main suites (MSan)" # ~ 10s
1086 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001087
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001088 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
Gilles Peskine7c652162017-12-11 00:01:40 +01001089 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001090
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001091 # Optional part(s)
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001092
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001093 if [ "$MEMORY" -gt 0 ]; then
1094 msg "test: compat.sh (MSan)" # ~ 6 min 20s
Gilles Peskine7c652162017-12-11 00:01:40 +01001095 if_build_succeeded tests/compat.sh
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001096 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001097}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001098
Gilles Peskine8f073122018-11-27 15:58:47 +01001099component_test_memcheck () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001100 msg "build: Release (clang)"
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001101 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
1102 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001103
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001104 msg "test: main suites valgrind (Release)"
1105 make memcheck
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001106
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001107 # Optional part(s)
1108 # Currently broken, programs don't seem to receive signals
1109 # under valgrind on OS X
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001110
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001111 if [ "$MEMORY" -gt 0 ]; then
1112 msg "test: ssl-opt.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +01001113 if_build_succeeded tests/ssl-opt.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001114 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001115
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001116 if [ "$MEMORY" -gt 1 ]; then
1117 msg "test: compat.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +01001118 if_build_succeeded tests/compat.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001119 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001120}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001121
Gilles Peskine8f073122018-11-27 15:58:47 +01001122component_test_cmake_out_of_source () {
1123 msg "build: cmake 'out-of-source' build"
Gilles Peskine8f073122018-11-27 15:58:47 +01001124 MBEDTLS_ROOT_DIR="$PWD"
1125 mkdir "$OUT_OF_SOURCE_DIR"
1126 cd "$OUT_OF_SOURCE_DIR"
1127 cmake "$MBEDTLS_ROOT_DIR"
1128 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001129
Gilles Peskine8f073122018-11-27 15:58:47 +01001130 msg "test: cmake 'out-of-source' build"
1131 make test
1132 # Test an SSL option that requires an auxiliary script in test/scripts/.
1133 # Also ensure that there are no error messages such as
1134 # "No such file or directory", which would indicate that some required
1135 # file is missing (ssl-opt.sh tolerates the absence of some files so
1136 # may exit with status 0 but emit errors).
1137 if_build_succeeded ./tests/ssl-opt.sh -f 'Fallback SCSV: beginning of list' 2>ssl-opt.err
1138 if [ -s ssl-opt.err ]; then
1139 cat ssl-opt.err >&2
1140 record_status [ ! -s ssl-opt.err ]
1141 rm ssl-opt.err
1142 fi
1143 cd "$MBEDTLS_ROOT_DIR"
1144 rm -rf "$OUT_OF_SOURCE_DIR"
1145 unset MBEDTLS_ROOT_DIR
1146}
Andres AGdc192212016-08-31 17:33:13 +01001147
Gilles Peskine8f073122018-11-27 15:58:47 +01001148component_test_zeroize () {
1149 # Test that the function mbedtls_platform_zeroize() is not optimized away by
1150 # different combinations of compilers and optimization flags by using an
1151 # auxiliary GDB script. Unfortunately, GDB does not return error values to the
1152 # system in all cases that the script fails, so we must manually search the
1153 # output to check whether the pass string is present and no failure strings
1154 # were printed.
Gilles Peskine74851d82019-01-06 19:52:22 +00001155
1156 # Don't try to disable ASLR. We don't care about ASLR here. We do care
1157 # about a spurious message if Gdb tries and fails, so suppress that.
1158 gdb_disable_aslr=
1159 if [ -z "$(gdb -batch -nw -ex 'set disable-randomization off' 2>&1)" ]; then
1160 gdb_disable_aslr='set disable-randomization off'
1161 fi
1162
Gilles Peskine8f073122018-11-27 15:58:47 +01001163 for optimization_flag in -O2 -O3 -Ofast -Os; do
Gilles Peskine06b385f2019-01-09 22:28:21 +01001164 for compiler in clang gcc; do
1165 msg "test: $compiler $optimization_flag, mbedtls_platform_zeroize()"
1166 make programs CC="$compiler" DEBUG=1 CFLAGS="$optimization_flag"
Gilles Peskine74851d82019-01-06 19:52:22 +00001167 if_build_succeeded gdb -ex "$gdb_disable_aslr" -x tests/scripts/test_zeroize.gdb -nw -batch -nx 2>&1 | tee test_zeroize.log
Gilles Peskine06b385f2019-01-09 22:28:21 +01001168 if_build_succeeded grep "The buffer was correctly zeroized" test_zeroize.log
1169 if_build_succeeded not grep -i "error" test_zeroize.log
1170 rm -f test_zeroize.log
1171 make clean
1172 done
Andres Amaya Garcia29673812017-10-25 10:35:51 +01001173 done
Gilles Peskine74851d82019-01-06 19:52:22 +00001174
1175 unset gdb_disable_aslr
Gilles Peskine8f073122018-11-27 15:58:47 +01001176}
Andres Amaya Garciad0d7bf62017-10-25 09:01:31 +01001177
Gilles Peskine8f073122018-11-27 15:58:47 +01001178component_check_python_files () {
1179 msg "Lint: Python scripts"
1180 record_status tests/scripts/check-python-files.sh
1181}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001182
Gilles Peskine8f073122018-11-27 15:58:47 +01001183component_check_generate_test_code () {
1184 msg "uint test: generate_test_code.py"
1185 record_status ./tests/scripts/test_generate_test_code.py
1186}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001187
1188################################################################
1189#### Termination
1190################################################################
1191
Gilles Peskine8f073122018-11-27 15:58:47 +01001192post_report () {
1193 msg "Done, cleaning up"
1194 cleanup
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001195
Gilles Peskine8f073122018-11-27 15:58:47 +01001196 final_report
1197}
1198
1199
1200
1201################################################################
1202#### Run all the things
1203################################################################
1204
Gilles Peskinee48351a2018-11-27 16:06:30 +01001205# Run one component and clean up afterwards.
Gilles Peskine8f073122018-11-27 15:58:47 +01001206run_component () {
Gilles Peskine8ae15dd2019-01-02 18:57:02 +01001207 # Back up the configuration in case the component modifies it.
1208 # The cleanup function will restore it.
1209 cp -p "$CONFIG_H" "$CONFIG_BAK"
Gilles Peskineffcdeff2018-12-04 12:49:28 +01001210 current_component="$1"
Gilles Peskine8f073122018-11-27 15:58:47 +01001211 "$@"
Gilles Peskinee48351a2018-11-27 16:06:30 +01001212 cleanup
Gilles Peskine8f073122018-11-27 15:58:47 +01001213}
1214
1215# Preliminary setup
1216pre_check_environment
1217pre_initialize_variables
1218pre_parse_command_line "$@"
Gilles Peskine348fb9a2018-11-27 17:04:29 +01001219
Gilles Peskine10726102019-01-06 20:50:38 +00001220pre_check_git
1221build_status=0
1222if [ $KEEP_GOING -eq 1 ]; then
1223 pre_setup_keep_going
1224else
1225 record_status () {
1226 "$@"
1227 }
1228fi
1229pre_print_configuration
1230pre_check_tools
1231pre_print_tools
1232cleanup
Gilles Peskine8f073122018-11-27 15:58:47 +01001233
Gilles Peskine1bcb1c82019-01-06 22:11:25 +00001234# Run the requested tests.
1235for component in $RUN_COMPONENTS; do
1236 run_component "component_$component"
1237done
Gilles Peskine8f073122018-11-27 15:58:47 +01001238
1239# We're done.
Gilles Peskine10726102019-01-06 20:50:38 +00001240post_report