blob: 364c8bf3ff83882af2d2df1f76e6f31d21aa31ee [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
Philippe Antoine1c582c32019-06-25 21:55:21 +020027# * Makefile, library/Makefile, programs/Makefile, tests/Makefile,
Philippe Antoine5dece6d2019-06-27 16:55:07 +020028# programs/fuzz/Makefile
Gilles Peskine192c72f2017-12-21 15:59:21 +010029# After running this script, the CMake cache will be lost and CMake
30# will no longer be initialised.
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +010031#
Gilles Peskine192c72f2017-12-21 15:59:21 +010032# The script assumes the presence of a number of tools:
33# * Basic Unix tools (Windows users note: a Unix-style find must be before
34# the Windows find in the PATH)
35# * Perl
36# * GNU Make
37# * CMake
38# * GCC and Clang (recent enough for using ASan with gcc and MemSan with clang, or valgrind)
Andrzej Kurek05be06c2018-06-28 04:41:50 -040039# * G++
Gilles Peskine192c72f2017-12-21 15:59:21 +010040# * arm-gcc and mingw-gcc
41# * ArmCC 5 and ArmCC 6, unless invoked with --no-armcc
Gilles Peskine192c72f2017-12-21 15:59:21 +010042# * OpenSSL and GnuTLS command line tools, recent enough for the
43# interoperability tests. If they don't support SSLv3 then a legacy
44# version of these tools must be present as well (search for LEGACY
45# below).
46# See the invocation of check_tools below for details.
47#
48# This script must be invoked from the toplevel directory of a git
49# working copy of Mbed TLS.
50#
51# Note that the output is not saved. You may want to run
52# script -c tests/scripts/all.sh
53# or
54# tests/scripts/all.sh >all.log 2>&1
55#
56# Notes for maintainers
57# ---------------------
58#
Gilles Peskine8f073122018-11-27 15:58:47 +010059# The bulk of the code is organized into functions that follow one of the
60# following naming conventions:
61# * pre_XXX: things to do before running the tests, in order.
62# * component_XXX: independent components. They can be run in any order.
Gilles Peskinec70637a2019-01-09 22:29:17 +010063# * component_check_XXX: quick tests that aren't worth parallelizing.
64# * component_build_XXX: build things but don't run them.
65# * component_test_XXX: build and test.
Gilles Peskine878cf602019-01-06 20:50:38 +000066# * support_XXX: if support_XXX exists and returns false then
67# component_XXX is not run by default.
Gilles Peskine8f073122018-11-27 15:58:47 +010068# * post_XXX: things to do after running the tests.
69# * other: miscellaneous support functions.
70#
Gilles Peskinec70637a2019-01-09 22:29:17 +010071# Each component must start by invoking `msg` with a short informative message.
72#
73# The framework performs some cleanup tasks after each component. This
74# means that components can assume that the working directory is in a
75# cleaned-up state, and don't need to perform the cleanup themselves.
76# * Run `make clean`.
77# * Restore `include/mbedtks/config.h` from a backup made before running
78# the component.
Philippe Antoine1c582c32019-06-25 21:55:21 +020079# * Check out `Makefile`, `library/Makefile`, `programs/Makefile`,
Philippe Antoine5dece6d2019-06-27 16:55:07 +020080# `tests/Makefile` and `programs/fuzz/Makefile` from git.
Philippe Antoine1c582c32019-06-25 21:55:21 +020081# This cleans up after an in-tree use of CMake.
Gilles Peskinec70637a2019-01-09 22:29:17 +010082#
83# Any command that is expected to fail must be protected so that the
84# script keeps running in --keep-going mode despite `set -e`. In keep-going
85# mode, if a protected command fails, this is logged as a failure and the
86# script will exit with a failure status once it has run all components.
87# Commands can be protected in any of the following ways:
88# * `make` is a function which runs the `make` command with protection.
89# Note that you must write `make VAR=value`, not `VAR=value make`,
90# because the `VAR=value make` syntax doesn't work with functions.
91# * Put `report_status` before the command to protect it.
92# * Put `if_build_successful` before a command. This protects it, and
93# additionally skips it if a prior invocation of `make` in the same
94# component failed.
95#
Gilles Peskine192c72f2017-12-21 15:59:21 +010096# The tests are roughly in order from fastest to slowest. This doesn't
97# have to be exact, but in general you should add slower tests towards
98# the end and fast checks near the beginning.
Gilles Peskine192c72f2017-12-21 15:59:21 +010099
100
101
102################################################################
103#### Initialization and command line parsing
104################################################################
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100105
SimonB2e23c822016-04-16 21:54:39 +0100106# Abort on errors (and uninitialised variables)
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100107set -eu
108
Gilles Peskine8f073122018-11-27 15:58:47 +0100109pre_check_environment () {
Gilles Peskinea16c2b12019-01-06 19:58:02 +0000110 if [ -d library -a -d include -a -d tests ]; then :; else
Gilles Peskine8f073122018-11-27 15:58:47 +0100111 echo "Must be run from mbed TLS root" >&2
112 exit 1
113 fi
114}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100115
Gilles Peskine8f073122018-11-27 15:58:47 +0100116pre_initialize_variables () {
117 CONFIG_H='include/mbedtls/config.h'
118 CONFIG_BAK="$CONFIG_H.bak"
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200119
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200120 append_outcome=0
Gilles Peskine8f073122018-11-27 15:58:47 +0100121 MEMORY=0
122 FORCE=0
123 KEEP_GOING=0
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100124
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200125 : ${MBEDTLS_TEST_OUTCOME_FILE=}
Gilles Peskine9004a172019-09-16 15:20:36 +0200126 : ${MBEDTLS_TEST_PLATFORM="$(uname -s | tr -c \\n0-9A-Za-z _)-$(uname -m | tr -c \\n0-9A-Za-z _)"}
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200127 export MBEDTLS_TEST_OUTCOME_FILE
Gilles Peskine9004a172019-09-16 15:20:36 +0200128 export MBEDTLS_TEST_PLATFORM
129
Jaeden Ameroc4cc2512019-01-30 15:35:44 +0000130 # Default commands, can be overridden by the environment
Gilles Peskine8f073122018-11-27 15:58:47 +0100131 : ${OPENSSL:="openssl"}
132 : ${OPENSSL_LEGACY:="$OPENSSL"}
133 : ${OPENSSL_NEXT:="$OPENSSL"}
134 : ${GNUTLS_CLI:="gnutls-cli"}
135 : ${GNUTLS_SERV:="gnutls-serv"}
136 : ${GNUTLS_LEGACY_CLI:="$GNUTLS_CLI"}
137 : ${GNUTLS_LEGACY_SERV:="$GNUTLS_SERV"}
138 : ${OUT_OF_SOURCE_DIR:=./mbedtls_out_of_source_build}
139 : ${ARMC5_BIN_DIR:=/usr/bin}
140 : ${ARMC6_BIN_DIR:=/usr/bin}
Andres AGdc192212016-08-31 17:33:13 +0100141
Gilles Peskine8f073122018-11-27 15:58:47 +0100142 # if MAKEFLAGS is not set add the -j option to speed up invocations of make
Gilles Peskinea1fc4b52019-01-06 20:15:26 +0000143 if [ -z "${MAKEFLAGS+set}" ]; then
Gilles Peskine8f073122018-11-27 15:58:47 +0100144 export MAKEFLAGS="-j"
145 fi
Gilles Peskine878cf602019-01-06 20:50:38 +0000146
147 # Gather the list of available components. These are the functions
148 # defined in this script whose name starts with "component_".
149 # Parse the script with sed, because in sh there is no way to list
150 # defined functions.
151 ALL_COMPONENTS=$(sed -n 's/^ *component_\([0-9A-Z_a-z]*\) *().*/\1/p' <"$0")
152
153 # Exclude components that are not supported on this platform.
154 SUPPORTED_COMPONENTS=
155 for component in $ALL_COMPONENTS; do
156 case $(type "support_$component" 2>&1) in
157 *' function'*)
158 if ! support_$component; then continue; fi;;
159 esac
160 SUPPORTED_COMPONENTS="$SUPPORTED_COMPONENTS $component"
161 done
Gilles Peskine8f073122018-11-27 15:58:47 +0100162}
Andres AG38495a32016-07-12 16:54:33 +0100163
Gilles Peskinea28db922019-01-10 00:05:18 +0100164# Test whether the component $1 is included in the command line patterns.
165is_component_included()
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100166{
167 set -f
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000168 for pattern in $COMMAND_LINE_COMPONENTS; do
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100169 set +f
170 case ${1#component_} in $pattern) return 0;; esac
171 done
172 set +f
173 return 1
174}
Andres AG7770ea82016-10-10 15:46:20 +0100175
Simon Butcher41eeccf2016-09-07 00:07:09 +0100176usage()
Andres AGd9eba4b2016-08-26 14:42:14 +0100177{
Gilles Peskine709346a2017-12-10 23:43:39 +0100178 cat <<EOF
Gilles Peskine92525112018-11-27 18:15:35 +0100179Usage: $0 [OPTION]... [COMPONENT]...
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100180Run mbedtls release validation tests.
Gilles Peskine92525112018-11-27 18:15:35 +0100181By default, run all tests. With one or more COMPONENT, run only those.
Gilles Peskinea28db922019-01-10 00:05:18 +0100182COMPONENT can be the name of a component or a shell wildcard pattern.
183
184Examples:
185 $0 "check_*"
186 Run all sanity checks.
187 $0 --no-armcc --except test_memsan
188 Run everything except builds that require armcc and MemSan.
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100189
190Special options:
191 -h|--help Print this help and exit.
Gilles Peskine878cf602019-01-06 20:50:38 +0000192 --list-all-components List all available test components and exit.
193 --list-components List components supported on this platform and exit.
Gilles Peskine709346a2017-12-10 23:43:39 +0100194
195General options:
196 -f|--force Force the tests to overwrite any modified files.
Gilles Peskine7c652162017-12-11 00:01:40 +0100197 -k|--keep-going Run all tests and report errors at the end.
Gilles Peskine709346a2017-12-10 23:43:39 +0100198 -m|--memory Additional optional memory tests.
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200199 --append-outcome Append to the outcome file (if used).
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100200 --armcc Run ARM Compiler builds (on by default).
Gilles Peskinea28db922019-01-10 00:05:18 +0100201 --except Exclude the COMPONENTs listed on the command line,
202 instead of running only those.
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200203 --no-append-outcome Write a new outcome file and analyze it (default).
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100204 --no-armcc Skip ARM Compiler builds.
Gilles Peskine38d81652018-03-21 08:40:26 +0100205 --no-force Refuse to overwrite modified files (default).
206 --no-keep-going Stop at the first error (default).
207 --no-memory No additional memory tests (default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100208 --out-of-source-dir=<path> Directory used for CMake out-of-source build tests.
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200209 --outcome-file=<path> File where test outcomes are written (not done if
210 empty; default: \$MBEDTLS_TEST_OUTCOME_FILE).
Gilles Peskine38d81652018-03-21 08:40:26 +0100211 --random-seed Use a random seed value for randomized tests (default).
Gilles Peskine709346a2017-12-10 23:43:39 +0100212 -r|--release-test Run this script in release mode. This fixes the seed value to 1.
213 -s|--seed Integer seed value to use for this test run.
214
215Tool path options:
216 --armc5-bin-dir=<ARMC5_bin_dir_path> ARM Compiler 5 bin directory.
217 --armc6-bin-dir=<ARMC6_bin_dir_path> ARM Compiler 6 bin directory.
218 --gnutls-cli=<GnuTLS_cli_path> GnuTLS client executable to use for most tests.
219 --gnutls-serv=<GnuTLS_serv_path> GnuTLS server executable to use for most tests.
220 --gnutls-legacy-cli=<GnuTLS_cli_path> GnuTLS client executable to use for legacy tests.
221 --gnutls-legacy-serv=<GnuTLS_serv_path> GnuTLS server executable to use for legacy tests.
222 --openssl=<OpenSSL_path> OpenSSL executable to use for most tests.
223 --openssl-legacy=<OpenSSL_path> OpenSSL executable to use for legacy tests e.g. SSLv3.
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100224 --openssl-next=<OpenSSL_path> OpenSSL executable to use for recent things like ARIA
Gilles Peskine709346a2017-12-10 23:43:39 +0100225EOF
SimonB2e23c822016-04-16 21:54:39 +0100226}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100227
228# remove built files as well as the cmake cache/config
229cleanup()
230{
Gilles Peskinea71d64c2018-03-21 12:16:57 +0100231 if [ -n "${MBEDTLS_ROOT_DIR+set}" ]; then
232 cd "$MBEDTLS_ROOT_DIR"
233 fi
234
Gilles Peskine7c652162017-12-11 00:01:40 +0100235 command make clean
Jaeden Ameroed93bdc2018-11-02 16:57:24 +0000236 cd crypto
237 command make clean
238 cd ..
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200239
Gilles Peskine31b07e22018-03-21 12:15:06 +0100240 # Remove CMake artefacts
Jaeden Amero2d0e00f2018-11-07 18:46:41 +0000241 find . -name .git -prune -o \
Gilles Peskine31b07e22018-03-21 12:15:06 +0100242 -iname CMakeFiles -exec rm -rf {} \+ -o \
243 \( -iname cmake_install.cmake -o \
244 -iname CTestTestfile.cmake -o \
245 -iname CMakeCache.txt \) -exec rm {} \+
246 # Recover files overwritten by in-tree CMake builds
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000247 rm -f include/Makefile include/mbedtls/Makefile programs/*/Makefile
Philippe Antoine5dece6d2019-06-27 16:55:07 +0200248 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile
249 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile
Jaeden Ameroed93bdc2018-11-02 16:57:24 +0000250 cd crypto
251 rm -f include/Makefile include/mbedtls/Makefile programs/*/Makefile
252 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile
253 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile
254 cd ..
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200255
Jaeden Ameroab83fdf2019-06-20 17:38:22 +0100256 # Remove any artifacts from the component_test_cmake_as_subdirectory test.
257 rm -rf programs/test/cmake_subproject/build
258 rm -f programs/test/cmake_subproject/Makefile
259 rm -f programs/test/cmake_subproject/cmake_subproject
260
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200261 if [ -f "$CONFIG_BAK" ]; then
262 mv "$CONFIG_BAK" "$CONFIG_H"
263 fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100264}
265
Gilles Peskine7c652162017-12-11 00:01:40 +0100266# Executed on exit. May be redefined depending on command line options.
267final_report () {
268 :
269}
270
271fatal_signal () {
272 cleanup
273 final_report $1
274 trap - $1
275 kill -$1 $$
276}
277
278trap 'fatal_signal HUP' HUP
279trap 'fatal_signal INT' INT
280trap 'fatal_signal TERM' TERM
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200281
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100282msg()
283{
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100284 if [ -n "${current_component:-}" ]; then
285 current_section="${current_component#component_}: $1"
286 else
287 current_section="$1"
288 fi
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100289 echo ""
290 echo "******************************************************************"
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100291 echo "* $current_section "
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000292 printf "* "; date
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100293 echo "******************************************************************"
294}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100295
Gilles Peskine8f073122018-11-27 15:58:47 +0100296armc6_build_test()
297{
298 FLAGS="$1"
Andres AGa5cd9732016-10-17 15:23:10 +0100299
Gilles Peskine8f073122018-11-27 15:58:47 +0100300 msg "build: ARM Compiler 6 ($FLAGS), make"
301 ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \
302 WARNING_CFLAGS='-xc -std=c99' make lib
303 make clean
304}
Andres AGa5cd9732016-10-17 15:23:10 +0100305
Andres AGd9eba4b2016-08-26 14:42:14 +0100306err_msg()
307{
308 echo "$1" >&2
309}
310
311check_tools()
312{
313 for TOOL in "$@"; do
Andres AG98393602017-01-31 17:04:45 +0000314 if ! `type "$TOOL" >/dev/null 2>&1`; then
Andres AGd9eba4b2016-08-26 14:42:14 +0100315 err_msg "$TOOL not found!"
316 exit 1
317 fi
318 done
319}
320
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400321check_headers_in_cpp () {
Peter Kolbus1bc1a4c2019-02-01 17:19:08 -0600322 ls include/mbedtls | grep "\.h$" >headers.txt
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400323 <programs/test/cpp_dummy_build.cpp sed -n 's/"$//; s!^#include "mbedtls/!!p' |
324 sort |
325 diff headers.txt -
326 rm headers.txt
327}
328
Gilles Peskine8f073122018-11-27 15:58:47 +0100329pre_parse_command_line () {
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000330 COMMAND_LINE_COMPONENTS=
Gilles Peskinea28db922019-01-10 00:05:18 +0100331 all_except=0
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000332 no_armcc=
SimonB2e23c822016-04-16 21:54:39 +0100333
Gilles Peskine8f073122018-11-27 15:58:47 +0100334 while [ $# -gt 0 ]; do
Gilles Peskine55f7c942019-01-09 22:28:21 +0100335 case "$1" in
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200336 --append-outcome) append_outcome=1;;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000337 --armcc) no_armcc=;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100338 --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
339 --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000340 --except) all_except=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100341 --force|-f) FORCE=1;;
342 --gnutls-cli) shift; GNUTLS_CLI="$1";;
343 --gnutls-legacy-cli) shift; GNUTLS_LEGACY_CLI="$1";;
344 --gnutls-legacy-serv) shift; GNUTLS_LEGACY_SERV="$1";;
345 --gnutls-serv) shift; GNUTLS_SERV="$1";;
346 --help|-h) usage; exit;;
347 --keep-going|-k) KEEP_GOING=1;;
Gilles Peskine878cf602019-01-06 20:50:38 +0000348 --list-all-components) printf '%s\n' $ALL_COMPONENTS; exit;;
349 --list-components) printf '%s\n' $SUPPORTED_COMPONENTS; exit;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100350 --memory|-m) MEMORY=1;;
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200351 --no-append-outcome) append_outcome=0;;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000352 --no-armcc) no_armcc=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100353 --no-force) FORCE=0;;
354 --no-keep-going) KEEP_GOING=0;;
355 --no-memory) MEMORY=0;;
356 --openssl) shift; OPENSSL="$1";;
357 --openssl-legacy) shift; OPENSSL_LEGACY="$1";;
358 --openssl-next) shift; OPENSSL_NEXT="$1";;
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200359 --outcome-file) shift; MBEDTLS_TEST_OUTCOME_FILE="$1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100360 --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
361 --random-seed) unset SEED;;
362 --release-test|-r) SEED=1;;
363 --seed|-s) shift; SEED="$1";;
364 -*)
365 echo >&2 "Unknown option: $1"
366 echo >&2 "Run $0 --help for usage."
367 exit 120
368 ;;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000369 *) COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS $1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100370 esac
371 shift
Gilles Peskine8f073122018-11-27 15:58:47 +0100372 done
SimonB2e23c822016-04-16 21:54:39 +0100373
Gilles Peskinea28db922019-01-10 00:05:18 +0100374 # With no list of components, run everything.
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000375 if [ -z "$COMMAND_LINE_COMPONENTS" ]; then
376 all_except=1
Andres AGdc192212016-08-31 17:33:13 +0100377 fi
378
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000379 # --no-armcc is a legacy option. The modern way is --except '*_armcc*'.
380 # Ignore it if components are listed explicitly on the command line.
Gilles Peskinea28db922019-01-10 00:05:18 +0100381 if [ -n "$no_armcc" ] && [ $all_except -eq 1 ]; then
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000382 COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS *_armcc*"
SimonB2e23c822016-04-16 21:54:39 +0100383 fi
SimonB2e23c822016-04-16 21:54:39 +0100384
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000385 # Build the list of components to run.
Gilles Peskinea28db922019-01-10 00:05:18 +0100386 RUN_COMPONENTS=
387 for component in $SUPPORTED_COMPONENTS; do
388 if is_component_included "$component"; [ $? -eq $all_except ]; then
389 RUN_COMPONENTS="$RUN_COMPONENTS $component"
390 fi
391 done
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000392
393 unset all_except
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000394 unset no_armcc
Gilles Peskine8f073122018-11-27 15:58:47 +0100395}
SimonB2e23c822016-04-16 21:54:39 +0100396
Gilles Peskine8f073122018-11-27 15:58:47 +0100397pre_check_git () {
398 if [ $FORCE -eq 1 ]; then
Gilles Peskine53190e62019-01-09 23:17:35 +0100399 rm -rf "$OUT_OF_SOURCE_DIR"
Gilles Peskine8f073122018-11-27 15:58:47 +0100400 git checkout-index -f -q $CONFIG_H
401 cleanup
402 else
SimonB2e23c822016-04-16 21:54:39 +0100403
Gilles Peskine8f073122018-11-27 15:58:47 +0100404 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
405 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
406 echo "You can either delete this directory manually, or force the test by rerunning"
407 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
408 exit 1
409 fi
410
Gilles Peskined1174cf2019-01-09 22:30:01 +0100411 if ! git diff --quiet include/mbedtls/config.h; then
Gilles Peskine8f073122018-11-27 15:58:47 +0100412 err_msg "Warning - the configuration file 'include/mbedtls/config.h' has been edited. "
413 echo "You can either delete or preserve your work, or force the test by rerunning the"
414 echo "script as: $0 --force"
415 exit 1
416 fi
SimonB2e23c822016-04-16 21:54:39 +0100417 fi
Andrzej Kureke9c3b812019-02-05 05:34:21 -0500418 if ! [ -f crypto/Makefile ]; then
419 echo "Please initialize the crypto submodule" >&2
420 exit 1
421 fi
Gilles Peskine8f073122018-11-27 15:58:47 +0100422}
SimonB2e23c822016-04-16 21:54:39 +0100423
Andrzej Kurekeb508712019-02-14 07:18:59 -0500424pre_check_seedfile () {
425 if [ ! -f "./tests/seedfile" ]; then
426 dd if=/dev/urandom of=./tests/seedfile bs=32 count=1
427 fi
Jaeden Amero97145102019-03-18 16:31:21 +0000428 if [ ! -f "./crypto/tests/seedfile" ]; then
429 dd if=/dev/urandom of=./crypto/tests/seedfile bs=32 count=1
430 fi
Andrzej Kurekeb508712019-02-14 07:18:59 -0500431}
432
Gilles Peskine8f073122018-11-27 15:58:47 +0100433pre_setup_keep_going () {
Gilles Peskine7c652162017-12-11 00:01:40 +0100434 failure_summary=
435 failure_count=0
436 start_red=
437 end_color=
438 if [ -t 1 ]; then
Gilles Peskine9736b9d2018-01-02 21:54:17 +0100439 case "${TERM:-}" in
Gilles Peskine7c652162017-12-11 00:01:40 +0100440 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
441 start_red=$(printf '\033[31m')
442 end_color=$(printf '\033[0m')
443 ;;
444 esac
445 fi
446 record_status () {
447 if "$@"; then
448 last_status=0
449 else
450 last_status=$?
451 text="$current_section: $* -> $last_status"
452 failure_summary="$failure_summary
453$text"
454 failure_count=$((failure_count + 1))
455 echo "${start_red}^^^^$text^^^^${end_color}"
456 fi
457 }
458 make () {
459 case "$*" in
460 *test|*check)
461 if [ $build_status -eq 0 ]; then
462 record_status command make "$@"
463 else
464 echo "(skipped because the build failed)"
465 fi
466 ;;
467 *)
468 record_status command make "$@"
469 build_status=$last_status
470 ;;
471 esac
472 }
473 final_report () {
474 if [ $failure_count -gt 0 ]; then
475 echo
476 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
477 echo "${start_red}FAILED: $failure_count${end_color}$failure_summary"
478 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Jaeden Amero7c1258d2018-07-20 16:42:14 +0100479 exit 1
Gilles Peskine7c652162017-12-11 00:01:40 +0100480 elif [ -z "${1-}" ]; then
481 echo "SUCCESS :)"
482 fi
483 if [ -n "${1-}" ]; then
484 echo "Killed by SIG$1."
485 fi
486 }
Gilles Peskine8f073122018-11-27 15:58:47 +0100487}
488
Gilles Peskine7c652162017-12-11 00:01:40 +0100489if_build_succeeded () {
490 if [ $build_status -eq 0 ]; then
491 record_status "$@"
492 fi
493}
494
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200495# to be used instead of ! for commands run with
496# record_status or if_build_succeeded
497not() {
498 ! "$@"
499}
500
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200501pre_prepare_outcome_file () {
502 case "$MBEDTLS_TEST_OUTCOME_FILE" in
503 [!/]*) MBEDTLS_TEST_OUTCOME_FILE="$PWD/$MBEDTLS_TEST_OUTCOME_FILE";;
504 esac
505 if [ -n "$MBEDTLS_TEST_OUTCOME_FILE" ] && [ "$append_outcome" -eq 0 ]; then
506 rm -f "$MBEDTLS_TEST_OUTCOME_FILE"
507 fi
508}
509
Gilles Peskine8f073122018-11-27 15:58:47 +0100510pre_print_configuration () {
511 msg "info: $0 configuration"
512 echo "MEMORY: $MEMORY"
513 echo "FORCE: $FORCE"
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200514 echo "MBEDTLS_TEST_OUTCOME_FILE: ${MBEDTLS_TEST_OUTCOME_FILE:-(none)}"
Gilles Peskine8f073122018-11-27 15:58:47 +0100515 echo "SEED: ${SEED-"UNSET"}"
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200516 echo
Gilles Peskine8f073122018-11-27 15:58:47 +0100517 echo "OPENSSL: $OPENSSL"
518 echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
519 echo "OPENSSL_NEXT: $OPENSSL_NEXT"
520 echo "GNUTLS_CLI: $GNUTLS_CLI"
521 echo "GNUTLS_SERV: $GNUTLS_SERV"
522 echo "GNUTLS_LEGACY_CLI: $GNUTLS_LEGACY_CLI"
523 echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV"
524 echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
525 echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
526}
Andres AG7770ea82016-10-10 15:46:20 +0100527
Andres AGd9eba4b2016-08-26 14:42:14 +0100528# Make sure the tools we need are available.
Gilles Peskine8f073122018-11-27 15:58:47 +0100529pre_check_tools () {
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000530 # Build the list of variables to pass to output_env.sh.
531 set env
SimonB2e23c822016-04-16 21:54:39 +0100532
Gilles Peskine87964262019-01-06 22:40:00 +0000533 case " $RUN_COMPONENTS " in
534 # Require OpenSSL and GnuTLS if running any tests (as opposed to
535 # only doing builds). Not all tests run OpenSSL and GnuTLS, but this
536 # is a good enough approximation in practice.
537 *" test_"*)
538 # To avoid setting OpenSSL and GnuTLS for each call to compat.sh
539 # and ssl-opt.sh, we just export the variables they require.
540 export OPENSSL_CMD="$OPENSSL"
541 export GNUTLS_CLI="$GNUTLS_CLI"
542 export GNUTLS_SERV="$GNUTLS_SERV"
543 # Avoid passing --seed flag in every call to ssl-opt.sh
544 if [ -n "${SEED-}" ]; then
545 export SEED
546 fi
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000547 set "$@" OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY"
548 set "$@" GNUTLS_CLI="$GNUTLS_CLI" GNUTLS_SERV="$GNUTLS_SERV"
549 set "$@" GNUTLS_LEGACY_CLI="$GNUTLS_LEGACY_CLI"
550 set "$@" GNUTLS_LEGACY_SERV="$GNUTLS_LEGACY_SERV"
Gilles Peskine87964262019-01-06 22:40:00 +0000551 check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$OPENSSL_NEXT" \
552 "$GNUTLS_CLI" "$GNUTLS_SERV" \
553 "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV"
554 ;;
555 esac
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200556
Gilles Peskine87964262019-01-06 22:40:00 +0000557 case " $RUN_COMPONENTS " in
558 *_doxygen[_\ ]*) check_tools "doxygen" "dot";;
559 esac
Andres AGd9eba4b2016-08-26 14:42:14 +0100560
Gilles Peskine87964262019-01-06 22:40:00 +0000561 case " $RUN_COMPONENTS " in
562 *_arm_none_eabi_gcc[_\ ]*) check_tools "arm-none-eabi-gcc";;
563 esac
Andres AGd9eba4b2016-08-26 14:42:14 +0100564
Gilles Peskine87964262019-01-06 22:40:00 +0000565 case " $RUN_COMPONENTS " in
566 *_mingw[_\ ]*) check_tools "i686-w64-mingw32-gcc";;
567 esac
568
569 case " $RUN_COMPONENTS " in
570 *" test_zeroize "*) check_tools "gdb";;
571 esac
572
573 case " $RUN_COMPONENTS " in
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000574 *_armcc*)
Gilles Peskine87964262019-01-06 22:40:00 +0000575 ARMC5_CC="$ARMC5_BIN_DIR/armcc"
576 ARMC5_AR="$ARMC5_BIN_DIR/armar"
577 ARMC6_CC="$ARMC6_BIN_DIR/armclang"
578 ARMC6_AR="$ARMC6_BIN_DIR/armar"
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000579 check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC6_CC" "$ARMC6_AR";;
580 esac
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000581
582 msg "info: output_env.sh"
583 case $RUN_COMPONENTS in
584 *_armcc*)
585 set "$@" ARMC5_CC="$ARMC5_CC" ARMC6_CC="$ARMC6_CC" RUN_ARMCC=1;;
586 *) set "$@" RUN_ARMCC=0;;
587 esac
588 "$@" scripts/output_env.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100589}
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100590
Gilles Peskine192c72f2017-12-21 15:59:21 +0100591
592
593################################################################
594#### Basic checks
595################################################################
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100596
597#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200598# Test Suites to be executed
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100599#
Manuel Pégourié-Gonnard3d404b42015-07-08 21:59:16 +0100600# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200601# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100602# and/or are more likely to fail than others (eg I use Clang most of the
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200603# time, so start with a GCC build).
604# 2. Minimize total running time, by avoiding useless rebuilds
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100605#
Manuel Pégourié-Gonnard259b08a2016-01-08 16:27:41 +0100606# Indicative running times are given for reference.
607
Gilles Peskine8f073122018-11-27 15:58:47 +0100608component_check_recursion () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200609 msg "Check: recursion.pl" # < 1s
Gilles Peskine8f073122018-11-27 15:58:47 +0100610 record_status tests/scripts/recursion.pl library/*.c
611}
Janos Follathb72c6782016-07-19 14:54:17 +0100612
Gilles Peskine8f073122018-11-27 15:58:47 +0100613component_check_generated_files () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200614 msg "Check: freshness of generated source files" # < 1s
Gilles Peskine8f073122018-11-27 15:58:47 +0100615 record_status tests/scripts/check-generated-files.sh
616}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200617
Gilles Peskine8f073122018-11-27 15:58:47 +0100618component_check_doxy_blocks () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200619 msg "Check: doxygen markup outside doxygen blocks" # < 1s
Gilles Peskine8f073122018-11-27 15:58:47 +0100620 record_status tests/scripts/check-doxy-blocks.pl
621}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200622
Gilles Peskine8f073122018-11-27 15:58:47 +0100623component_check_files () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200624 msg "Check: file sanity checks (permissions, encodings)" # < 1s
Gilles Peskine8f073122018-11-27 15:58:47 +0100625 record_status tests/scripts/check-files.py
626}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200627
Gilles Peskine8f073122018-11-27 15:58:47 +0100628component_check_names () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200629 msg "Check: declared and exported names (builds the library)" # < 3s
Gilles Peskine13f97dc2019-05-15 17:52:22 +0200630 record_status tests/scripts/check-names.sh -v
Gilles Peskine8f073122018-11-27 15:58:47 +0100631}
Darryl Greena07039c2018-03-13 16:48:16 +0000632
Gilles Peskine895868b2019-09-19 21:30:05 +0200633component_check_test_cases () {
634 msg "Check: test case descriptions" # < 1s
635 record_status tests/scripts/check-test-cases.py
636}
637
Gilles Peskine8f073122018-11-27 15:58:47 +0100638component_check_doxygen_warnings () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200639 msg "Check: doxygen warnings (builds the documentation)" # ~ 3s
Gilles Peskine8f073122018-11-27 15:58:47 +0100640 record_status tests/scripts/doxygen.sh
641}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200642
Gilles Peskine192c72f2017-12-21 15:59:21 +0100643
644
645################################################################
646#### Build and test many configurations and targets
647################################################################
648
k-stachowiakc1955552019-06-10 11:46:18 +0200649component_test_large_ecdsa_key_signature () {
650
651 SMALL_MPI_MAX_SIZE=136 # Small enough to interfere with the EC signatures
652
653 msg "build: cmake + MBEDTLS_MPI_MAX_SIZE=${SMALL_MPI_MAX_SIZE}, gcc, ASan" # ~ 1 min 50s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200654 scripts/config.py set MBEDTLS_MPI_MAX_SIZE $SMALL_MPI_MAX_SIZE
k-stachowiakc1955552019-06-10 11:46:18 +0200655 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
656 make
657
658 INEVITABLY_PRESENT_FILE=Makefile
659 SIGNATURE_FILE="${INEVITABLY_PRESENT_FILE}.sig" # Warning, this is rm -f'ed below
660
661 msg "test: pk_sign secp521r1_prv.der for MBEDTLS_MPI_MAX_SIZE=${SMALL_MPI_MAX_SIZE} (ASan build)" # ~ 5s
662 if_build_succeeded programs/pkey/pk_sign tests/data_files/secp521r1_prv.der $INEVITABLY_PRESENT_FILE
663 rm -f $SIGNATURE_FILE
664}
665
Gilles Peskine7832c9f2019-04-08 17:00:15 +0200666component_test_default_out_of_box () {
667 msg "build: make, default config (out-of-box)" # ~1min
668 make
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200669 # Disable fancy stuff
Gilles Peskine717cd762019-09-27 20:21:11 +0200670 SAVE_MBEDTLS_TEST_OUTCOME_FILE="$MBEDTLS_TEST_OUTCOME_FILE"
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200671 unset MBEDTLS_TEST_OUTCOME_FILE
Gilles Peskine7832c9f2019-04-08 17:00:15 +0200672
673 msg "test: main suites make, default config (out-of-box)" # ~10s
674 make test
675
676 msg "selftest: make, default config (out-of-box)" # ~10s
677 programs/test/selftest
Gilles Peskine717cd762019-09-27 20:21:11 +0200678
679 export MBEDTLS_TEST_OUTCOME_FILE="$SAVE_MBEDTLS_TEST_OUTCOME_FILE"
680 unset SAVE_MBEDTLS_TEST_OUTCOME_FILE
Gilles Peskine7832c9f2019-04-08 17:00:15 +0200681}
682
Gilles Peskine8f073122018-11-27 15:58:47 +0100683component_test_default_cmake_gcc_asan () {
684 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100685 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
686 make
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200687
Gilles Peskine8f073122018-11-27 15:58:47 +0100688 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
689 make test
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200690
Gilles Peskine8f073122018-11-27 15:58:47 +0100691 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
692 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200693
Gilles Peskine8f073122018-11-27 15:58:47 +0100694 msg "test: compat.sh (ASan build)" # ~ 6 min
695 if_build_succeeded tests/compat.sh
696}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200697
Hanno Becker01635512019-02-26 14:27:09 +0000698component_test_full_cmake_gcc_asan () {
699 msg "build: full config, cmake, gcc, ASan"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200700 scripts/config.py full
Hanno Becker01635512019-02-26 14:27:09 +0000701 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
702 make
703
704 msg "test: main suites (inc. selftests) (full config, ASan build)"
705 make test
706
707 msg "test: ssl-opt.sh (full config, ASan build)"
708 if_build_succeeded tests/ssl-opt.sh
709
710 msg "test: compat.sh (full config, ASan build)"
711 if_build_succeeded tests/compat.sh
712}
713
Gilles Peskine782f4112018-11-27 16:11:09 +0100714component_test_ref_configs () {
715 msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
716 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
717 record_status tests/scripts/test-ref-configs.pl
718}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200719
Gilles Peskine8f073122018-11-27 15:58:47 +0100720component_test_sslv3 () {
721 msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200722 scripts/config.py set MBEDTLS_SSL_PROTO_SSL3
Gilles Peskine8f073122018-11-27 15:58:47 +0100723 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
724 make
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200725
Gilles Peskine8f073122018-11-27 15:58:47 +0100726 msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
727 make test
Simon Butcher3ea7f522016-03-07 23:22:10 +0000728
Gilles Peskine8f073122018-11-27 15:58:47 +0100729 msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
730 if_build_succeeded tests/compat.sh -m 'tls1 tls1_1 tls1_2 dtls1 dtls1_2'
731 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
Simon Butcher3ea7f522016-03-07 23:22:10 +0000732
Gilles Peskine8f073122018-11-27 15:58:47 +0100733 msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
734 if_build_succeeded tests/ssl-opt.sh
735}
Simon Butcher3ea7f522016-03-07 23:22:10 +0000736
Gilles Peskine8f073122018-11-27 15:58:47 +0100737component_test_no_renegotiation () {
738 msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200739 scripts/config.py unset MBEDTLS_SSL_RENEGOTIATION
Gilles Peskine8f073122018-11-27 15:58:47 +0100740 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
741 make
Simon Butcher3ea7f522016-03-07 23:22:10 +0000742
Gilles Peskine8f073122018-11-27 15:58:47 +0100743 msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
744 make test
Hanno Becker134c2ab2017-10-12 15:29:50 +0100745
Gilles Peskine8f073122018-11-27 15:58:47 +0100746 msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
747 if_build_succeeded tests/ssl-opt.sh
748}
Hanno Becker134c2ab2017-10-12 15:29:50 +0100749
Hanno Beckera545be22019-05-10 14:45:37 +0100750component_test_no_pem_no_fs () {
751 msg "build: Default + !MBEDTLS_PEM_PARSE_C + !MBEDTLS_FS_IO (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200752 scripts/config.py unset MBEDTLS_PEM_PARSE_C
753 scripts/config.py unset MBEDTLS_FS_IO
Hanno Beckera545be22019-05-10 14:45:37 +0100754 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
755 make
756
757 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - main suites (inc. selftests) (ASan build)" # ~ 50s
758 make test
759
760 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - ssl-opt.sh (ASan build)" # ~ 6 min
761 if_build_succeeded tests/ssl-opt.sh
762}
763
Gilles Peskine8f073122018-11-27 15:58:47 +0100764component_test_rsa_no_crt () {
765 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200766 scripts/config.py set MBEDTLS_RSA_NO_CRT
Gilles Peskine8f073122018-11-27 15:58:47 +0100767 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
768 make
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +0100769
Gilles Peskine8f073122018-11-27 15:58:47 +0100770 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
771 make test
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100772
Gilles Peskine8f073122018-11-27 15:58:47 +0100773 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
774 if_build_succeeded tests/ssl-opt.sh -f RSA
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100775
Gilles Peskine8f073122018-11-27 15:58:47 +0100776 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
777 if_build_succeeded tests/compat.sh -t RSA
778}
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100779
Gilles Peskine0c6b7992019-04-12 20:29:48 +0200780component_test_everest () {
781 msg "build: Everest ECDH context (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200782 scripts/config.py unset MBEDTLS_ECDH_LEGACY_CONTEXT
783 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
Gilles Peskine0c6b7992019-04-12 20:29:48 +0200784 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Asan .
785 make
786
787 msg "test: Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
788 make test
789
790 msg "test: Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
791 if_build_succeeded tests/ssl-opt.sh -f ECDH
792
793 msg "test: Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
794 # Exclude some symmetric ciphers that are redundant here to gain time.
795 if_build_succeeded tests/compat.sh -f ECDH -V NO -e 'ARCFOUR\|ARIA\|CAMELLIA\|CHACHA\|DES\|RC4'
796}
797
Gilles Peskine8f073122018-11-27 15:58:47 +0100798component_test_small_ssl_out_content_len () {
799 msg "build: small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200800 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 16384
801 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
Gilles Peskine8f073122018-11-27 15:58:47 +0100802 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
803 make
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100804
Gilles Peskine8f073122018-11-27 15:58:47 +0100805 msg "test: small SSL_OUT_CONTENT_LEN - ssl-opt.sh MFL and large packet tests"
806 if_build_succeeded tests/ssl-opt.sh -f "Max fragment\|Large packet"
807}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000808
Gilles Peskine8f073122018-11-27 15:58:47 +0100809component_test_small_ssl_in_content_len () {
810 msg "build: small SSL_IN_CONTENT_LEN (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200811 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 4096
812 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 16384
Gilles Peskine8f073122018-11-27 15:58:47 +0100813 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
814 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000815
Gilles Peskine8f073122018-11-27 15:58:47 +0100816 msg "test: small SSL_IN_CONTENT_LEN - ssl-opt.sh MFL tests"
817 if_build_succeeded tests/ssl-opt.sh -f "Max fragment"
818}
Angus Grattonc4dd0732018-04-11 16:28:39 +1000819
Gilles Peskine8f073122018-11-27 15:58:47 +0100820component_test_small_ssl_dtls_max_buffering () {
821 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200822 scripts/config.py set MBEDTLS_SSL_DTLS_MAX_BUFFERING 1000
Gilles Peskine8f073122018-11-27 15:58:47 +0100823 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
824 make
Angus Grattonc4dd0732018-04-11 16:28:39 +1000825
Gilles Peskine8f073122018-11-27 15:58:47 +0100826 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0 - ssl-opt.sh specific reordering test"
827 if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer out-of-order hs msg before reassembling next, free buffered msg"
828}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100829
Gilles Peskine8f073122018-11-27 15:58:47 +0100830component_test_small_mbedtls_ssl_dtls_max_buffering () {
831 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200832 scripts/config.py set MBEDTLS_SSL_DTLS_MAX_BUFFERING 190
Gilles Peskine8f073122018-11-27 15:58:47 +0100833 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
834 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100835
Gilles Peskine8f073122018-11-27 15:58:47 +0100836 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1 - ssl-opt.sh specific reordering test"
837 if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer encrypted Finished message, drop for fragmented NewSessionTicket"
838}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100839
Gilles Peskine8f073122018-11-27 15:58:47 +0100840component_test_full_cmake_clang () {
841 msg "build: cmake, full config, clang" # ~ 50s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200842 scripts/config.py full
Gilles Peskine8f073122018-11-27 15:58:47 +0100843 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check -D ENABLE_TESTING=On .
844 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +0100845
Gilles Peskine8f073122018-11-27 15:58:47 +0100846 msg "test: main suites (full config)" # ~ 5s
847 make test
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100848
Gilles Peskine8f073122018-11-27 15:58:47 +0100849 msg "test: ssl-opt.sh default, ECJPAKE, SSL async (full config)" # ~ 1s
850 if_build_succeeded tests/ssl-opt.sh -f 'Default\|ECJPAKE\|SSL async private'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200851
Andres Amaya Garcia2dadab72019-01-08 21:42:27 +0000852 msg "test: compat.sh RC4, DES, 3DES & NULL (full config)" # ~ 2 min
Andres Amaya Garcia419bd002019-02-19 20:20:57 +0000853 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" GNUTLS_CLI="$GNUTLS_LEGACY_CLI" GNUTLS_SERV="$GNUTLS_LEGACY_SERV" tests/compat.sh -e '^$' -f 'NULL\|DES\|RC4\|ARCFOUR'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200854
Gilles Peskine8f073122018-11-27 15:58:47 +0100855 msg "test: compat.sh ARIA + ChachaPoly"
856 if_build_succeeded env OPENSSL_CMD="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
857}
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200858
Gilles Peskine8f073122018-11-27 15:58:47 +0100859component_build_deprecated () {
860 msg "build: make, full config + DEPRECATED_WARNING, gcc -O" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200861 scripts/config.py full
862 scripts/config.py set MBEDTLS_DEPRECATED_WARNING
Gilles Peskine8f073122018-11-27 15:58:47 +0100863 # Build with -O -Wextra to catch a maximum of issues.
864 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra' lib programs
865 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100866
Gilles Peskine8f073122018-11-27 15:58:47 +0100867 msg "build: make, full config + DEPRECATED_REMOVED, clang -O" # ~ 30s
868 # No cleanup, just tweak the configuration and rebuild
869 make clean
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200870 scripts/config.py unset MBEDTLS_DEPRECATED_WARNING
871 scripts/config.py set MBEDTLS_DEPRECATED_REMOVED
Gilles Peskine8f073122018-11-27 15:58:47 +0100872 # Build with -O -Wextra to catch a maximum of issues.
873 make CC=clang CFLAGS='-O -Werror -Wall -Wextra' lib programs
874 make CC=clang CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests
875}
Jaeden Ameroed93bdc2018-11-02 16:57:24 +0000876
Gilles Peskine8f073122018-11-27 15:58:47 +0100877component_test_depends_curves () {
878 msg "test/build: curves.pl (gcc)" # ~ 4 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100879 record_status tests/scripts/curves.pl
880}
Jaeden Ameroacaabe72018-11-07 11:52:52 +0000881
Gilles Peskine8f073122018-11-27 15:58:47 +0100882component_test_depends_hashes () {
883 msg "test/build: depends-hashes.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100884 record_status tests/scripts/depends-hashes.pl
885}
Jaeden Ameroacaabe72018-11-07 11:52:52 +0000886
Gilles Peskine8f073122018-11-27 15:58:47 +0100887component_test_depends_pkalgs () {
888 msg "test/build: depends-pkalgs.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100889 record_status tests/scripts/depends-pkalgs.pl
890}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100891
Gilles Peskine8f073122018-11-27 15:58:47 +0100892component_build_key_exchanges () {
893 msg "test/build: key-exchanges (gcc)" # ~ 1 min
Gilles Peskine8f073122018-11-27 15:58:47 +0100894 record_status tests/scripts/key-exchanges.pl
895}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100896
Gilles Peskine8f073122018-11-27 15:58:47 +0100897component_build_default_make_gcc_and_cxx () {
898 msg "build: Unix make, -Os (gcc)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +0100899 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100900
Gilles Peskine8f073122018-11-27 15:58:47 +0100901 msg "test: verify header list in cpp_dummy_build.cpp"
902 record_status check_headers_in_cpp
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100903
Gilles Peskine8f073122018-11-27 15:58:47 +0100904 msg "build: Unix make, incremental g++"
905 make TEST_CPP=1
906}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +0100907
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100908component_test_no_use_psa_crypto_full_cmake_asan() {
909 # full minus MBEDTLS_USE_PSA_CRYPTO: run the same set of tests as basic-build-test.sh
Gilles Peskinedc3a1792019-09-03 11:42:04 +0200910 msg "build: cmake, full config minus MBEDTLS_USE_PSA_CRYPTO, ASan"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200911 scripts/config.py full
912 scripts/config.py set MBEDTLS_ECP_RESTARTABLE # not using PSA, so enable restartable ECC
913 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C
914 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
915 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C
916 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
Manuel Pégourié-Gonnardd8167e82019-02-01 11:12:52 +0100917 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500918 make
Manuel Pégourié-Gonnard43be6cd2017-06-20 09:53:42 +0200919
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100920 msg "test: main suites (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500921 make test
Manuel Pégourié-Gonnard503a5ef2015-10-23 09:04:45 +0200922
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100923 msg "test: ssl-opt.sh (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500924 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100925
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100926 msg "test: compat.sh default (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500927 if_build_succeeded tests/compat.sh
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400928
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100929 msg "test: compat.sh ssl3 (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500930 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400931
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100932 msg "test: compat.sh RC4, DES & NULL (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500933 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'
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500934
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +0100935 msg "test: compat.sh ARIA + ChachaPoly (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -0500936 if_build_succeeded env OPENSSL_CMD="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
937}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500938
Gilles Peskineadcde5e2019-06-12 16:05:50 +0200939component_test_check_params_functionality () {
940 msg "build+test: MBEDTLS_CHECK_PARAMS functionality"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200941 scripts/config.py full # includes CHECK_PARAMS
Gilles Peskineadcde5e2019-06-12 16:05:50 +0200942 # Make MBEDTLS_PARAM_FAILED call mbedtls_param_failed().
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200943 scripts/config.py unset MBEDTLS_CHECK_PARAMS_ASSERT
Gilles Peskineadcde5e2019-06-12 16:05:50 +0200944 # Only build and run tests. Do not build sample programs, because
945 # they don't have a mbedtls_param_failed() function.
946 make CC=gcc CFLAGS='-Werror -O1' lib test
947}
948
Gilles Peskineb28636b2019-01-02 19:06:24 +0100949component_test_check_params_without_platform () {
950 msg "build+test: MBEDTLS_CHECK_PARAMS without MBEDTLS_PLATFORM_C"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200951 scripts/config.py full # includes CHECK_PARAMS
Gilles Peskineadcde5e2019-06-12 16:05:50 +0200952 # Keep MBEDTLS_PARAM_FAILED as assert.
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200953 scripts/config.py unset MBEDTLS_PLATFORM_EXIT_ALT
954 scripts/config.py unset MBEDTLS_PLATFORM_TIME_ALT
955 scripts/config.py unset MBEDTLS_PLATFORM_FPRINTF_ALT
956 scripts/config.py unset MBEDTLS_PLATFORM_MEMORY
957 scripts/config.py unset MBEDTLS_PLATFORM_PRINTF_ALT
958 scripts/config.py unset MBEDTLS_PLATFORM_SNPRINTF_ALT
959 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
960 scripts/config.py unset MBEDTLS_PLATFORM_C
Gilles Peskineb28636b2019-01-02 19:06:24 +0100961 make CC=gcc CFLAGS='-Werror -O1' all test
962}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500963
Gilles Peskineb28636b2019-01-02 19:06:24 +0100964component_test_check_params_silent () {
965 msg "build+test: MBEDTLS_CHECK_PARAMS with alternative MBEDTLS_PARAM_FAILED()"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200966 scripts/config.py full # includes CHECK_PARAMS
Gilles Peskineadcde5e2019-06-12 16:05:50 +0200967 # Set MBEDTLS_PARAM_FAILED to nothing.
Gilles Peskineb28636b2019-01-02 19:06:24 +0100968 sed -i 's/.*\(#define MBEDTLS_PARAM_FAILED( cond )\).*/\1/' "$CONFIG_H"
969 make CC=gcc CFLAGS='-Werror -O1' all test
970}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500971
Gilles Peskine8f073122018-11-27 15:58:47 +0100972component_test_no_platform () {
973 # Full configuration build, without platform support, file IO and net sockets.
974 # This should catch missing mbedtls_printf definitions, and by disabling file
975 # IO, it should catch missing '#include <stdio.h>'
976 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200977 scripts/config.py full
978 scripts/config.py unset MBEDTLS_PLATFORM_C
979 scripts/config.py unset MBEDTLS_NET_C
980 scripts/config.py unset MBEDTLS_PLATFORM_MEMORY
981 scripts/config.py unset MBEDTLS_PLATFORM_PRINTF_ALT
982 scripts/config.py unset MBEDTLS_PLATFORM_FPRINTF_ALT
983 scripts/config.py unset MBEDTLS_PLATFORM_SNPRINTF_ALT
984 scripts/config.py unset MBEDTLS_PLATFORM_TIME_ALT
985 scripts/config.py unset MBEDTLS_PLATFORM_EXIT_ALT
986 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
987 scripts/config.py unset MBEDTLS_FS_IO
988 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
989 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C
Gilles Peskine8f073122018-11-27 15:58:47 +0100990 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
991 # to re-enable platform integration features otherwise disabled in C99 builds
992 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -O0 -D_DEFAULT_SOURCE' lib programs
993 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0' test
994}
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +0000995
Gilles Peskine8f073122018-11-27 15:58:47 +0100996component_build_no_std_function () {
997 # catch compile bugs in _uninit functions
998 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200999 scripts/config.py full
1000 scripts/config.py set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
1001 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskine8f073122018-11-27 15:58:47 +01001002 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
1003}
Manuel Pégourié-Gonnarddccb80b2015-06-03 10:20:33 +01001004
Gilles Peskine8f073122018-11-27 15:58:47 +01001005component_build_no_ssl_srv () {
1006 msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001007 scripts/config.py full
1008 scripts/config.py unset MBEDTLS_SSL_SRV_C
Gilles Peskine8f073122018-11-27 15:58:47 +01001009 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
1010}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +02001011
Gilles Peskine8f073122018-11-27 15:58:47 +01001012component_build_no_ssl_cli () {
1013 msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001014 scripts/config.py full
1015 scripts/config.py unset MBEDTLS_SSL_CLI_C
Gilles Peskine8f073122018-11-27 15:58:47 +01001016 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0'
1017}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +02001018
Gilles Peskine8f073122018-11-27 15:58:47 +01001019component_build_no_sockets () {
1020 # Note, C99 compliance can also be tested with the sockets support disabled,
1021 # as that requires a POSIX platform (which isn't the same as C99).
1022 msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001023 scripts/config.py full
1024 scripts/config.py unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
1025 scripts/config.py set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
Gilles Peskine8f073122018-11-27 15:58:47 +01001026 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0 -std=c99 -pedantic' lib
1027}
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +02001028
Andrzej Kurek69f20aa2019-09-05 09:27:47 -04001029component_test_memory_buffer_allocator_backtrace () {
1030 msg "build: default config with memory buffer allocator and backtrace enabled"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001031 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
1032 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
1033 scripts/config.py set MBEDTLS_MEMORY_BACKTRACE
1034 scripts/config.py set MBEDTLS_MEMORY_DEBUG
Andrzej Kurek69f20aa2019-09-05 09:27:47 -04001035 CC=gcc cmake .
1036 make
1037
1038 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C and MBEDTLS_MEMORY_BACKTRACE"
1039 make test
1040}
1041
1042component_test_memory_buffer_allocator () {
1043 msg "build: default config with memory buffer allocator"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001044 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
1045 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
Hanno Becker0fb9ba22019-02-26 14:34:13 +00001046 CC=gcc cmake .
1047 make
1048
1049 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C"
1050 make test
1051
1052 msg "test: ssl-opt.sh, MBEDTLS_MEMORY_BUFFER_ALLOC_C"
Andrzej Kurek1e56d2c2019-09-05 10:09:37 -04001053 # MBEDTLS_MEMORY_BUFFER_ALLOC is slow. Skip tests that tend to time out.
1054 if_build_succeeded tests/ssl-opt.sh -e '^DTLS proxy'
Hanno Becker0fb9ba22019-02-26 14:34:13 +00001055}
1056
Gilles Peskine8f073122018-11-27 15:58:47 +01001057component_test_no_max_fragment_length () {
1058 # Run max fragment length tests with MFL disabled
1059 msg "build: default config except MFL extension (ASan build)" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001060 scripts/config.py unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
Gilles Peskine8f073122018-11-27 15:58:47 +01001061 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1062 make
Hanno Becker5175ac62017-09-18 15:36:25 +01001063
Gilles Peskine8f073122018-11-27 15:58:47 +01001064 msg "test: ssl-opt.sh, MFL-related tests"
1065 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length"
1066}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001067
Hanno Becker545ced42019-02-19 11:10:48 +00001068component_test_asan_remove_peer_certificate () {
1069 msg "build: default config with MBEDTLS_SSL_KEEP_PEER_CERTIFICATE disabled (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001070 scripts/config.py unset MBEDTLS_SSL_KEEP_PEER_CERTIFICATE
Hanno Becker545ced42019-02-19 11:10:48 +00001071 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1072 make
1073
1074 msg "test: !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
1075 make test
1076
1077 msg "test: ssl-opt.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
1078 if_build_succeeded tests/ssl-opt.sh
1079
1080 msg "test: compat.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
1081 if_build_succeeded tests/compat.sh
1082}
1083
Gilles Peskine8f073122018-11-27 15:58:47 +01001084component_test_no_max_fragment_length_small_ssl_out_content_len () {
1085 msg "build: no MFL extension, small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001086 scripts/config.py unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
1087 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 16384
1088 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
Gilles Peskine8f073122018-11-27 15:58:47 +01001089 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1090 make
Angus Grattonc4dd0732018-04-11 16:28:39 +10001091
Gilles Peskine8f073122018-11-27 15:58:47 +01001092 msg "test: MFL tests (disabled MFL extension case) & large packet tests"
1093 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length\|Large buffer"
1094}
Angus Grattonc4dd0732018-04-11 16:28:39 +10001095
Jaeden Amero2de07f12019-06-05 13:32:08 +01001096component_test_when_no_ciphersuites_have_mac () {
1097 msg "build: when no ciphersuites have MAC"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001098 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
1099 scripts/config.py unset MBEDTLS_ARC4_C
1100 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
Jaeden Amero2de07f12019-06-05 13:32:08 +01001101 make
1102
1103 msg "test: !MBEDTLS_SSL_SOME_MODES_USE_MAC"
1104 make test
1105
1106 msg "test ssl-opt.sh: !MBEDTLS_SSL_SOME_MODES_USE_MAC"
Jaeden Amero6b1683d2019-06-05 14:42:50 +01001107 if_build_succeeded tests/ssl-opt.sh -f 'Default\|EtM' -e 'without EtM'
Jaeden Amero2de07f12019-06-05 13:32:08 +01001108}
1109
Gilles Peskine8f073122018-11-27 15:58:47 +01001110component_test_null_entropy () {
1111 msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001112 scripts/config.py set MBEDTLS_TEST_NULL_ENTROPY
1113 scripts/config.py set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
1114 scripts/config.py set MBEDTLS_ENTROPY_C
1115 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
1116 scripts/config.py unset MBEDTLS_ENTROPY_HARDWARE_ALT
1117 scripts/config.py unset MBEDTLS_HAVEGE_C
Gilles Peskine5fa32a72019-01-06 19:48:30 +00001118 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan -D UNSAFE_BUILD=ON .
Gilles Peskine8f073122018-11-27 15:58:47 +01001119 make
Janos Follath06c54002016-06-09 13:57:40 +01001120
Gilles Peskine8f073122018-11-27 15:58:47 +01001121 msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)"
1122 make test
1123}
Janos Follath06c54002016-06-09 13:57:40 +01001124
Gilles Peskine8f073122018-11-27 15:58:47 +01001125component_test_platform_calloc_macro () {
1126 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001127 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
1128 scripts/config.py set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
1129 scripts/config.py set MBEDTLS_PLATFORM_FREE_MACRO free
Gilles Peskine8f073122018-11-27 15:58:47 +01001130 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1131 make
Hanno Beckere5fecec2018-10-11 11:02:52 +01001132
Gilles Peskine8f073122018-11-27 15:58:47 +01001133 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
1134 make test
1135}
Hanno Beckere5fecec2018-10-11 11:02:52 +01001136
Gilles Peskine8f073122018-11-27 15:58:47 +01001137component_test_make_shared () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001138 msg "build/test: make shared" # ~ 40s
Andrzej Kurek232e8f92019-10-03 03:18:01 -04001139 make SHARED=1 all check
Gilles Peskine56c01612019-07-03 20:43:32 +02001140 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskine8f073122018-11-27 15:58:47 +01001141}
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +02001142
Gilles Peskinecf740502019-07-03 20:43:05 +02001143component_test_cmake_shared () {
1144 msg "build/test: cmake shared" # ~ 2min
1145 cmake -DUSE_SHARED_MBEDTLS_LIBRARY=On .
1146 make
Gilles Peskine56c01612019-07-03 20:43:32 +02001147 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskinecf740502019-07-03 20:43:05 +02001148 make test
1149}
1150
Gilles Peskineabf9b4d2019-07-03 20:42:16 +02001151component_build_mbedtls_config_file () {
1152 msg "build: make with MBEDTLS_CONFIG_FILE" # ~40s
1153 # Use the full config so as to catch a maximum of places where
1154 # the check of MBEDTLS_CONFIG_FILE might be missing.
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001155 scripts/config.py full
Gilles Peskineabf9b4d2019-07-03 20:42:16 +02001156 sed 's!"check_config.h"!"mbedtls/check_config.h"!' <"$CONFIG_H" >full_config.h
1157 echo '#error "MBEDTLS_CONFIG_FILE is not working"' >"$CONFIG_H"
1158 make CFLAGS="-I '$PWD' -DMBEDTLS_CONFIG_FILE='\"full_config.h\"'"
1159 rm -f full_config.h
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001160}
1161
Gilles Peskine8f073122018-11-27 15:58:47 +01001162component_test_m32_o0 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001163 # Build once with -O0, to compile out the i386 specific inline assembly
1164 msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001165 scripts/config.py full
Philippe Antoinecd2c1272019-06-25 21:50:07 +02001166 make CC=gcc CFLAGS='-O0 -Werror -Wall -Wextra -m32 -fsanitize=address' LDFLAGS='-m32 -fsanitize=address'
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01001167
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001168 msg "test: i386, make, gcc -O0 (ASan build)"
1169 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01001170}
Gilles Peskine878cf602019-01-06 20:50:38 +00001171support_test_m32_o0 () {
1172 case $(uname -m) in
1173 *64*) true;;
1174 *) false;;
1175 esac
1176}
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001177
Gilles Peskine8f073122018-11-27 15:58:47 +01001178component_test_m32_o1 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001179 # Build again with -O1, to compile in the i386 specific inline assembly
1180 msg "build: i386, make, gcc -O1 (ASan build)" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001181 scripts/config.py full
Philippe Antoinecd2c1272019-06-25 21:50:07 +02001182 make CC=gcc CFLAGS='-O1 -Werror -Wall -Wextra -m32 -fsanitize=address' LDFLAGS='-m32 -fsanitize=address'
Simon Butcher8e6a22a2018-07-20 21:27:33 +01001183
1184 msg "test: i386, make, gcc -O1 (ASan build)"
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001185 make test
Gilles Peskine4b317612019-04-08 16:58:02 +02001186
1187 msg "test ssl-opt.sh, i386, make, gcc-O1"
1188 if_build_succeeded tests/ssl-opt.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01001189}
Gilles Peskine878cf602019-01-06 20:50:38 +00001190support_test_m32_o1 () {
1191 support_test_m32_o0 "$@"
1192}
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001193
Gilles Peskine0c6b7992019-04-12 20:29:48 +02001194component_test_m32_everest () {
1195 msg "build: i386, Everest ECDH context (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001196 scripts/config.py unset MBEDTLS_ECDH_LEGACY_CONTEXT
1197 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
Gilles Peskine0c6b7992019-04-12 20:29:48 +02001198 make CC=gcc CFLAGS='-O2 -Werror -Wall -Wextra -m32 -fsanitize=address' LDFLAGS='-m32 -fsanitize=address'
1199
1200 msg "test: i386, Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
1201 make test
1202
1203 msg "test: i386, Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
1204 if_build_succeeded tests/ssl-opt.sh -f ECDH
1205
1206 msg "test: i386, Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
1207 # Exclude some symmetric ciphers that are redundant here to gain time.
1208 if_build_succeeded tests/compat.sh -f ECDH -V NO -e 'ARCFOUR\|ARIA\|CAMELLIA\|CHACHA\|DES\|RC4'
1209}
1210support_test_m32_everest () {
1211 support_test_m32_o0 "$@"
1212}
1213
Gilles Peskine8f073122018-11-27 15:58:47 +01001214component_test_mx32 () {
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001215 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001216 scripts/config.py full
Gilles Peskine5d26e7c2019-06-07 14:50:09 +02001217 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32' LDFLAGS='-mx32'
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01001218
1219 msg "test: 64-bit ILP32, make, gcc"
1220 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01001221}
Gilles Peskine878cf602019-01-06 20:50:38 +00001222support_test_mx32 () {
1223 case $(uname -m) in
1224 amd64|x86_64) true;;
1225 *) false;;
1226 esac
1227}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001228
Gilles Peskine8f073122018-11-27 15:58:47 +01001229component_build_arm_none_eabi_gcc () {
1230 msg "build: arm-none-eabi-gcc, make" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001231 scripts/config.py baremetal
Gilles Peskine8f073122018-11-27 15:58:47 +01001232 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
1233}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001234
Gilles Peskine2c897d72019-08-09 16:05:05 +02001235component_build_arm_none_eabi_gcc_arm5vte () {
Gilles Peskine8a52af92019-08-08 16:09:02 +02001236 msg "build: arm-none-eabi-gcc -march=arm5vte, make" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001237 scripts/config.py baremetal
Gilles Peskine2c897d72019-08-09 16:05:05 +02001238 # Build for a target platform that's close to what Debian uses
1239 # for its "armel" distribution (https://wiki.debian.org/ArmEabiPort).
1240 # See https://github.com/ARMmbed/mbedtls/pull/2169 and comments.
1241 # It would be better to build with arm-linux-gnueabi-gcc but
1242 # we don't have that on our CI at this time.
Gilles Peskine8a52af92019-08-08 16:09:02 +02001243 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar CFLAGS='-Werror -Wall -Wextra -march=armv5te -O1' LDFLAGS='-march=armv5te' SHELL='sh -x' lib
Gilles Peskine93e4e032019-08-05 11:34:25 +02001244}
1245
Gilles Peskine8f073122018-11-27 15:58:47 +01001246component_build_arm_none_eabi_gcc_no_udbl_division () {
1247 msg "build: arm-none-eabi-gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001248 scripts/config.py baremetal
1249 scripts/config.py set MBEDTLS_NO_UDBL_DIVISION
Gilles Peskine8f073122018-11-27 15:58:47 +01001250 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib
1251 echo "Checking that software 64-bit division is not required"
1252 if_build_succeeded not grep __aeabi_uldiv library/*.o
1253}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001254
Gilles Peskine8f073122018-11-27 15:58:47 +01001255component_build_arm_none_eabi_gcc_no_64bit_multiplication () {
1256 msg "build: arm-none-eabi-gcc MBEDTLS_NO_64BIT_MULTIPLICATION, make" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001257 scripts/config.py baremetal
1258 scripts/config.py set MBEDTLS_NO_64BIT_MULTIPLICATION
Gilles Peskine8f073122018-11-27 15:58:47 +01001259 make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -O1 -march=armv6-m -mthumb' lib
1260 echo "Checking that software 64-bit multiplication is not required"
1261 if_build_succeeded not grep __aeabi_lmul library/*.o
1262}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02001263
Gilles Peskine8f073122018-11-27 15:58:47 +01001264component_build_armcc () {
1265 msg "build: ARM Compiler 5, make"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001266 scripts/config.py baremetal
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001267
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001268 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
1269 make clean
Andres AG87bb5772016-09-27 15:05:15 +01001270
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001271 # ARM Compiler 6 - Target ARMv7-A
1272 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-a"
Simon Butcher940737f2017-07-23 13:42:36 +02001273
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001274 # ARM Compiler 6 - Target ARMv7-M
1275 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m"
Simon Butcher940737f2017-07-23 13:42:36 +02001276
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001277 # ARM Compiler 6 - Target ARMv8-A - AArch32
1278 armc6_build_test "--target=arm-arm-none-eabi -march=armv8.2-a"
Simon Butcher940737f2017-07-23 13:42:36 +02001279
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001280 # ARM Compiler 6 - Target ARMv8-M
1281 armc6_build_test "--target=arm-arm-none-eabi -march=armv8-m.main"
Simon Butcher940737f2017-07-23 13:42:36 +02001282
Gilles Peskinebca6ab92017-12-19 18:24:31 +01001283 # ARM Compiler 6 - Target ARMv8-A - AArch64
1284 armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a"
Gilles Peskine8f073122018-11-27 15:58:47 +01001285}
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +01001286
Gilles Peskine8f073122018-11-27 15:58:47 +01001287component_test_allow_sha1 () {
1288 msg "build: allow SHA1 in certificates by default"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001289 scripts/config.py set MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
Gilles Peskine8f073122018-11-27 15:58:47 +01001290 make CFLAGS='-Werror -Wall -Wextra'
1291 msg "test: allow SHA1 in certificates by default"
1292 make test
1293 if_build_succeeded tests/ssl-opt.sh -f SHA-1
1294}
Gilles Peskine2a458da2017-05-12 15:26:58 +02001295
Gilles Peskine8f073122018-11-27 15:58:47 +01001296component_build_mingw () {
1297 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
Andrzej Kurek232e8f92019-10-03 03:18:01 -04001298 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
Hanno Beckere963efa2018-01-03 10:03:43 +00001299
Gilles Peskine8f073122018-11-27 15:58:47 +01001300 # note Make tests only builds the tests, but doesn't run them
Andrzej Kurek232e8f92019-10-03 03:18:01 -04001301 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror' WINDOWS_BUILD=1 tests
Gilles Peskine8f073122018-11-27 15:58:47 +01001302 make WINDOWS_BUILD=1 clean
Simon Butcher002bc622016-11-17 09:27:45 +00001303
Gilles Peskine8f073122018-11-27 15:58:47 +01001304 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
Andrzej Kurek232e8f92019-10-03 03:18:01 -04001305 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
1306 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
Gilles Peskine8f073122018-11-27 15:58:47 +01001307 make WINDOWS_BUILD=1 clean
1308}
Jaeden Amero117b8a42019-04-17 15:19:26 +01001309support_build_mingw() {
1310 case $(i686-w64-mingw32-gcc -dumpversion) in
1311 [0-5]*) false;;
1312 *) true;;
1313 esac
1314}
Manuel Pégourié-Gonnard6448bce2015-02-16 17:18:36 +01001315
Gilles Peskine8f073122018-11-27 15:58:47 +01001316component_test_memsan () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001317 msg "build: MSan (clang)" # ~ 1 min 20s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001318 scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001319 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
1320 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +02001321
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001322 msg "test: main suites (MSan)" # ~ 10s
1323 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001324
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001325 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
Gilles Peskine7c652162017-12-11 00:01:40 +01001326 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001327
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001328 # Optional part(s)
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001329
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001330 if [ "$MEMORY" -gt 0 ]; then
1331 msg "test: compat.sh (MSan)" # ~ 6 min 20s
Gilles Peskine7c652162017-12-11 00:01:40 +01001332 if_build_succeeded tests/compat.sh
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001333 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001334}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001335
Gilles Peskine69f190e2019-01-10 00:11:42 +01001336component_test_valgrind () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001337 msg "build: Release (clang)"
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001338 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
1339 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001340
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001341 msg "test: main suites valgrind (Release)"
1342 make memcheck
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001343
Gilles Peskinef1349e42019-04-08 17:00:56 +02001344 # Optional parts (slow; currently broken on OS X because programs don't
1345 # seem to receive signals under valgrind on OS X).
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001346 if [ "$MEMORY" -gt 0 ]; then
1347 msg "test: ssl-opt.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +01001348 if_build_succeeded tests/ssl-opt.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001349 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001350
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001351 if [ "$MEMORY" -gt 1 ]; then
1352 msg "test: compat.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +01001353 if_build_succeeded tests/compat.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01001354 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01001355}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001356
Gilles Peskine8f073122018-11-27 15:58:47 +01001357component_test_cmake_out_of_source () {
1358 msg "build: cmake 'out-of-source' build"
Gilles Peskine8f073122018-11-27 15:58:47 +01001359 MBEDTLS_ROOT_DIR="$PWD"
1360 mkdir "$OUT_OF_SOURCE_DIR"
1361 cd "$OUT_OF_SOURCE_DIR"
1362 cmake "$MBEDTLS_ROOT_DIR"
1363 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00001364
Gilles Peskine8f073122018-11-27 15:58:47 +01001365 msg "test: cmake 'out-of-source' build"
1366 make test
1367 # Test an SSL option that requires an auxiliary script in test/scripts/.
1368 # Also ensure that there are no error messages such as
1369 # "No such file or directory", which would indicate that some required
1370 # file is missing (ssl-opt.sh tolerates the absence of some files so
1371 # may exit with status 0 but emit errors).
1372 if_build_succeeded ./tests/ssl-opt.sh -f 'Fallback SCSV: beginning of list' 2>ssl-opt.err
1373 if [ -s ssl-opt.err ]; then
1374 cat ssl-opt.err >&2
1375 record_status [ ! -s ssl-opt.err ]
1376 rm ssl-opt.err
1377 fi
1378 cd "$MBEDTLS_ROOT_DIR"
1379 rm -rf "$OUT_OF_SOURCE_DIR"
1380 unset MBEDTLS_ROOT_DIR
1381}
Andres AGdc192212016-08-31 17:33:13 +01001382
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01001383component_test_cmake_as_subdirectory () {
1384 msg "build: cmake 'as-subdirectory' build"
1385 MBEDTLS_ROOT_DIR="$PWD"
1386
1387 cd programs/test/cmake_subproject
1388 cmake .
1389 make
1390 if_build_succeeded ./cmake_subproject
1391
1392 cd "$MBEDTLS_ROOT_DIR"
1393 unset MBEDTLS_ROOT_DIR
1394}
1395
Gilles Peskine8f073122018-11-27 15:58:47 +01001396component_test_zeroize () {
1397 # Test that the function mbedtls_platform_zeroize() is not optimized away by
1398 # different combinations of compilers and optimization flags by using an
1399 # auxiliary GDB script. Unfortunately, GDB does not return error values to the
1400 # system in all cases that the script fails, so we must manually search the
1401 # output to check whether the pass string is present and no failure strings
1402 # were printed.
Andres AGdc192212016-08-31 17:33:13 +01001403
Gilles Peskine4976e822019-01-06 19:52:22 +00001404 # Don't try to disable ASLR. We don't care about ASLR here. We do care
1405 # about a spurious message if Gdb tries and fails, so suppress that.
1406 gdb_disable_aslr=
1407 if [ -z "$(gdb -batch -nw -ex 'set disable-randomization off' 2>&1)" ]; then
1408 gdb_disable_aslr='set disable-randomization off'
1409 fi
1410
Gilles Peskine8f073122018-11-27 15:58:47 +01001411 for optimization_flag in -O2 -O3 -Ofast -Os; do
Gilles Peskine55f7c942019-01-09 22:28:21 +01001412 for compiler in clang gcc; do
1413 msg "test: $compiler $optimization_flag, mbedtls_platform_zeroize()"
1414 make programs CC="$compiler" DEBUG=1 CFLAGS="$optimization_flag"
Gilles Peskine4976e822019-01-06 19:52:22 +00001415 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 +01001416 if_build_succeeded grep "The buffer was correctly zeroized" test_zeroize.log
1417 if_build_succeeded not grep -i "error" test_zeroize.log
1418 rm -f test_zeroize.log
1419 make clean
1420 done
Andres Amaya Garcia29673812017-10-25 10:35:51 +01001421 done
Andres Amaya Garciad0d7bf62017-10-25 09:01:31 +01001422
Gilles Peskine4976e822019-01-06 19:52:22 +00001423 unset gdb_disable_aslr
Gilles Peskine8f073122018-11-27 15:58:47 +01001424}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001425
Gilles Peskineaad2ebd2019-02-25 20:26:06 +01001426support_check_python_files () {
1427 type pylint3 >/dev/null 2>/dev/null
1428}
Gilles Peskine8f073122018-11-27 15:58:47 +01001429component_check_python_files () {
1430 msg "Lint: Python scripts"
1431 record_status tests/scripts/check-python-files.sh
1432}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001433
Gilles Peskine8f073122018-11-27 15:58:47 +01001434component_check_generate_test_code () {
1435 msg "uint test: generate_test_code.py"
1436 record_status ./tests/scripts/test_generate_test_code.py
1437}
Gilles Peskine192c72f2017-12-21 15:59:21 +01001438
1439################################################################
1440#### Termination
1441################################################################
1442
Gilles Peskine8f073122018-11-27 15:58:47 +01001443post_report () {
1444 msg "Done, cleaning up"
1445 cleanup
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001446
Gilles Peskine8f073122018-11-27 15:58:47 +01001447 final_report
1448}
1449
1450
1451
1452################################################################
1453#### Run all the things
1454################################################################
1455
Gilles Peskinee48351a2018-11-27 16:06:30 +01001456# Run one component and clean up afterwards.
Gilles Peskine8f073122018-11-27 15:58:47 +01001457run_component () {
Gilles Peskine608953e2019-01-02 18:57:02 +01001458 # Back up the configuration in case the component modifies it.
1459 # The cleanup function will restore it.
1460 cp -p "$CONFIG_H" "$CONFIG_BAK"
Gilles Peskineffcdeff2018-12-04 12:49:28 +01001461 current_component="$1"
Gilles Peskine9004a172019-09-16 15:20:36 +02001462 export MBEDTLS_TEST_CONFIGURATION="$current_component"
Gilles Peskine8f073122018-11-27 15:58:47 +01001463 "$@"
Gilles Peskinee48351a2018-11-27 16:06:30 +01001464 cleanup
Gilles Peskine8f073122018-11-27 15:58:47 +01001465}
1466
1467# Preliminary setup
1468pre_check_environment
1469pre_initialize_variables
1470pre_parse_command_line "$@"
Gilles Peskine348fb9a2018-11-27 17:04:29 +01001471
Gilles Peskine878cf602019-01-06 20:50:38 +00001472pre_check_git
Andrzej Kurekeb508712019-02-14 07:18:59 -05001473pre_check_seedfile
1474
Gilles Peskine878cf602019-01-06 20:50:38 +00001475build_status=0
1476if [ $KEEP_GOING -eq 1 ]; then
1477 pre_setup_keep_going
Gilles Peskine92525112018-11-27 18:15:35 +01001478else
Gilles Peskine878cf602019-01-06 20:50:38 +00001479 record_status () {
1480 "$@"
1481 }
Gilles Peskine8f073122018-11-27 15:58:47 +01001482fi
Gilles Peskine67ffdaf2019-09-16 15:55:46 +02001483pre_prepare_outcome_file
Gilles Peskine878cf602019-01-06 20:50:38 +00001484pre_print_configuration
1485pre_check_tools
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001486cleanup
1487
Gilles Peskinebeb3a812019-01-06 22:11:25 +00001488# Run the requested tests.
1489for component in $RUN_COMPONENTS; do
1490 run_component "component_$component"
1491done
Gilles Peskine8f073122018-11-27 15:58:47 +01001492
1493# We're done.
Gilles Peskine878cf602019-01-06 20:50:38 +00001494post_report