blob: 98950c06a6b79848aa5192e92563120e93fc5a35 [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#
Bence Szépkúti1e148272020-08-07 13:07:28 +02005# Copyright The Mbed TLS Contributors
Bence Szépkútic7da1fe2020-05-26 01:54:15 +02006# SPDX-License-Identifier: Apache-2.0
7#
8# Licensed under the Apache License, Version 2.0 (the "License"); you may
9# not use this file except in compliance with the License.
10# You may obtain a copy of the License at
11#
12# http://www.apache.org/licenses/LICENSE-2.0
13#
14# Unless required by applicable law or agreed to in writing, software
15# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17# See the License for the specific language governing permissions and
18# limitations under the License.
Gilles Peskine192c72f2017-12-21 15:59:21 +010019
20
21
22################################################################
23#### Documentation
24################################################################
25
Simon Butcher3ea7f522016-03-07 23:22:10 +000026# Purpose
Gilles Peskine192c72f2017-12-21 15:59:21 +010027# -------
Simon Butcher3ea7f522016-03-07 23:22:10 +000028#
SimonB2e23c822016-04-16 21:54:39 +010029# To run all tests possible or available on the platform.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010030#
Gilles Peskine192c72f2017-12-21 15:59:21 +010031# Notes for users
32# ---------------
33#
SimonB2e23c822016-04-16 21:54:39 +010034# Warning: the test is destructive. It includes various build modes and
35# configurations, and can and will arbitrarily change the current CMake
Gilles Peskine192c72f2017-12-21 15:59:21 +010036# configuration. The following files must be committed into git:
37# * include/mbedtls/config.h
Gilles Peskine636c26a2020-03-04 20:46:15 +010038# * Makefile, library/Makefile, programs/Makefile, tests/Makefile,
39# programs/fuzz/Makefile
Gilles Peskine192c72f2017-12-21 15:59:21 +010040# After running this script, the CMake cache will be lost and CMake
41# will no longer be initialised.
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +010042#
Gilles Peskine192c72f2017-12-21 15:59:21 +010043# The script assumes the presence of a number of tools:
44# * Basic Unix tools (Windows users note: a Unix-style find must be before
45# the Windows find in the PATH)
46# * Perl
47# * GNU Make
48# * CMake
49# * GCC and Clang (recent enough for using ASan with gcc and MemSan with clang, or valgrind)
Andrzej Kurek05be06c2018-06-28 04:41:50 -040050# * G++
Gilles Peskine192c72f2017-12-21 15:59:21 +010051# * arm-gcc and mingw-gcc
52# * ArmCC 5 and ArmCC 6, unless invoked with --no-armcc
Gilles Peskine192c72f2017-12-21 15:59:21 +010053# * OpenSSL and GnuTLS command line tools, recent enough for the
54# interoperability tests. If they don't support SSLv3 then a legacy
55# version of these tools must be present as well (search for LEGACY
56# below).
57# See the invocation of check_tools below for details.
58#
59# This script must be invoked from the toplevel directory of a git
60# working copy of Mbed TLS.
61#
62# Note that the output is not saved. You may want to run
63# script -c tests/scripts/all.sh
64# or
65# tests/scripts/all.sh >all.log 2>&1
66#
67# Notes for maintainers
68# ---------------------
69#
Gilles Peskine8f073122018-11-27 15:58:47 +010070# The bulk of the code is organized into functions that follow one of the
71# following naming conventions:
72# * pre_XXX: things to do before running the tests, in order.
73# * component_XXX: independent components. They can be run in any order.
Gilles Peskinec70637a2019-01-09 22:29:17 +010074# * component_check_XXX: quick tests that aren't worth parallelizing.
75# * component_build_XXX: build things but don't run them.
76# * component_test_XXX: build and test.
Gilles Peskine878cf602019-01-06 20:50:38 +000077# * support_XXX: if support_XXX exists and returns false then
78# component_XXX is not run by default.
Gilles Peskine8f073122018-11-27 15:58:47 +010079# * post_XXX: things to do after running the tests.
80# * other: miscellaneous support functions.
81#
Gilles Peskinec70637a2019-01-09 22:29:17 +010082# Each component must start by invoking `msg` with a short informative message.
83#
84# The framework performs some cleanup tasks after each component. This
85# means that components can assume that the working directory is in a
86# cleaned-up state, and don't need to perform the cleanup themselves.
87# * Run `make clean`.
88# * Restore `include/mbedtks/config.h` from a backup made before running
89# the component.
Gilles Peskine636c26a2020-03-04 20:46:15 +010090# * Check out `Makefile`, `library/Makefile`, `programs/Makefile`,
91# `tests/Makefile` and `programs/fuzz/Makefile` from git.
92# This cleans up after an in-tree use of CMake.
Gilles Peskinec70637a2019-01-09 22:29:17 +010093#
94# Any command that is expected to fail must be protected so that the
95# script keeps running in --keep-going mode despite `set -e`. In keep-going
96# mode, if a protected command fails, this is logged as a failure and the
97# script will exit with a failure status once it has run all components.
98# Commands can be protected in any of the following ways:
99# * `make` is a function which runs the `make` command with protection.
100# Note that you must write `make VAR=value`, not `VAR=value make`,
101# because the `VAR=value make` syntax doesn't work with functions.
102# * Put `report_status` before the command to protect it.
103# * Put `if_build_successful` before a command. This protects it, and
104# additionally skips it if a prior invocation of `make` in the same
105# component failed.
106#
Gilles Peskine192c72f2017-12-21 15:59:21 +0100107# The tests are roughly in order from fastest to slowest. This doesn't
108# have to be exact, but in general you should add slower tests towards
109# the end and fast checks near the beginning.
Gilles Peskine192c72f2017-12-21 15:59:21 +0100110
111
112
113################################################################
114#### Initialization and command line parsing
115################################################################
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100116
SimonB2e23c822016-04-16 21:54:39 +0100117# Abort on errors (and uninitialised variables)
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100118set -eu
119
Gilles Peskine8f073122018-11-27 15:58:47 +0100120pre_check_environment () {
Gilles Peskinea16c2b12019-01-06 19:58:02 +0000121 if [ -d library -a -d include -a -d tests ]; then :; else
Gilles Peskine8f073122018-11-27 15:58:47 +0100122 echo "Must be run from mbed TLS root" >&2
123 exit 1
124 fi
125}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100126
Gilles Peskine8f073122018-11-27 15:58:47 +0100127pre_initialize_variables () {
128 CONFIG_H='include/mbedtls/config.h'
129 CONFIG_BAK="$CONFIG_H.bak"
John Durkopbd069d32020-10-31 22:14:03 -0700130 CRYPTO_CONFIG_H='include/psa/crypto_config.h'
131 CRYPTO_CONFIG_BAK="$CRYPTO_CONFIG_H.bak"
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200132
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200133 append_outcome=0
Gilles Peskine8f073122018-11-27 15:58:47 +0100134 MEMORY=0
135 FORCE=0
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200136 QUIET=0
Gilles Peskine8f073122018-11-27 15:58:47 +0100137 KEEP_GOING=0
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100138
Manuel Pégourié-Gonnarde0501912020-06-08 12:59:27 +0200139 # Seed value used with the --release-test option.
Manuel Pégourié-Gonnard54304472020-06-22 10:11:47 +0200140 #
141 # See also RELEASE_SEED in basic-build-test.sh. Debugging is easier if
142 # both values are kept in sync. If you change the value here because it
143 # breaks some tests, you'll definitely want to change it in
144 # basic-build-test.sh as well.
Manuel Pégourié-Gonnarde0501912020-06-08 12:59:27 +0200145 RELEASE_SEED=1
146
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200147 : ${MBEDTLS_TEST_OUTCOME_FILE=}
Gilles Peskine9004a172019-09-16 15:20:36 +0200148 : ${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 +0200149 export MBEDTLS_TEST_OUTCOME_FILE
Gilles Peskine9004a172019-09-16 15:20:36 +0200150 export MBEDTLS_TEST_PLATFORM
151
Jaeden Ameroc4cc2512019-01-30 15:35:44 +0000152 # Default commands, can be overridden by the environment
Gilles Peskine8f073122018-11-27 15:58:47 +0100153 : ${OPENSSL:="openssl"}
154 : ${OPENSSL_LEGACY:="$OPENSSL"}
155 : ${OPENSSL_NEXT:="$OPENSSL"}
156 : ${GNUTLS_CLI:="gnutls-cli"}
157 : ${GNUTLS_SERV:="gnutls-serv"}
158 : ${GNUTLS_LEGACY_CLI:="$GNUTLS_CLI"}
159 : ${GNUTLS_LEGACY_SERV:="$GNUTLS_SERV"}
160 : ${OUT_OF_SOURCE_DIR:=./mbedtls_out_of_source_build}
161 : ${ARMC5_BIN_DIR:=/usr/bin}
162 : ${ARMC6_BIN_DIR:=/usr/bin}
Gilles Peskine6d061342020-04-30 18:19:32 +0200163 : ${ARM_NONE_EABI_GCC_PREFIX:=arm-none-eabi-}
Manuel Pégourié-Gonnard71930162020-08-18 10:28:51 +0200164 : ${ARM_LINUX_GNUEABI_GCC_PREFIX:=arm-linux-gnueabi-}
Andres AGdc192212016-08-31 17:33:13 +0100165
Gilles Peskine8f073122018-11-27 15:58:47 +0100166 # if MAKEFLAGS is not set add the -j option to speed up invocations of make
Gilles Peskinea1fc4b52019-01-06 20:15:26 +0000167 if [ -z "${MAKEFLAGS+set}" ]; then
Gilles Peskine85229ac2021-09-30 18:24:21 +0200168 export MAKEFLAGS="-j$(all_sh_nproc)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100169 fi
Gilles Peskine878cf602019-01-06 20:50:38 +0000170
Gilles Peskinec761d8f2021-09-20 18:57:55 +0200171 # Include more verbose output for failing tests run by CMake or make
Jaeden Amerod48e9c72019-02-07 17:43:39 +0000172 export CTEST_OUTPUT_ON_FAILURE=1
173
Gilles Peskine8fd59422019-10-21 17:11:33 +0200174 # CFLAGS and LDFLAGS for Asan builds that don't use CMake
Gilles Peskine5ca393f2019-10-21 19:06:33 +0200175 ASAN_CFLAGS='-Werror -Wall -Wextra -fsanitize=address,undefined -fno-sanitize-recover=all'
Gilles Peskine8fd59422019-10-21 17:11:33 +0200176
Gilles Peskine878cf602019-01-06 20:50:38 +0000177 # Gather the list of available components. These are the functions
178 # defined in this script whose name starts with "component_".
179 # Parse the script with sed, because in sh there is no way to list
180 # defined functions.
181 ALL_COMPONENTS=$(sed -n 's/^ *component_\([0-9A-Z_a-z]*\) *().*/\1/p' <"$0")
182
183 # Exclude components that are not supported on this platform.
184 SUPPORTED_COMPONENTS=
185 for component in $ALL_COMPONENTS; do
186 case $(type "support_$component" 2>&1) in
187 *' function'*)
188 if ! support_$component; then continue; fi;;
189 esac
190 SUPPORTED_COMPONENTS="$SUPPORTED_COMPONENTS $component"
191 done
Gilles Peskine8f073122018-11-27 15:58:47 +0100192}
Andres AG38495a32016-07-12 16:54:33 +0100193
Gilles Peskinea28db922019-01-10 00:05:18 +0100194# Test whether the component $1 is included in the command line patterns.
195is_component_included()
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100196{
197 set -f
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000198 for pattern in $COMMAND_LINE_COMPONENTS; do
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100199 set +f
200 case ${1#component_} in $pattern) return 0;; esac
201 done
202 set +f
203 return 1
204}
Andres AG7770ea82016-10-10 15:46:20 +0100205
Simon Butcher41eeccf2016-09-07 00:07:09 +0100206usage()
Andres AGd9eba4b2016-08-26 14:42:14 +0100207{
Gilles Peskine709346a2017-12-10 23:43:39 +0100208 cat <<EOF
Gilles Peskine92525112018-11-27 18:15:35 +0100209Usage: $0 [OPTION]... [COMPONENT]...
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100210Run mbedtls release validation tests.
Gilles Peskine92525112018-11-27 18:15:35 +0100211By default, run all tests. With one or more COMPONENT, run only those.
Gilles Peskinea28db922019-01-10 00:05:18 +0100212COMPONENT can be the name of a component or a shell wildcard pattern.
213
214Examples:
215 $0 "check_*"
216 Run all sanity checks.
217 $0 --no-armcc --except test_memsan
218 Run everything except builds that require armcc and MemSan.
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100219
220Special options:
221 -h|--help Print this help and exit.
Gilles Peskine878cf602019-01-06 20:50:38 +0000222 --list-all-components List all available test components and exit.
223 --list-components List components supported on this platform and exit.
Gilles Peskine709346a2017-12-10 23:43:39 +0100224
225General options:
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200226 -q|--quiet Only output component names, and errors if any.
Gilles Peskine709346a2017-12-10 23:43:39 +0100227 -f|--force Force the tests to overwrite any modified files.
Gilles Peskine7c652162017-12-11 00:01:40 +0100228 -k|--keep-going Run all tests and report errors at the end.
Gilles Peskine709346a2017-12-10 23:43:39 +0100229 -m|--memory Additional optional memory tests.
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200230 --append-outcome Append to the outcome file (if used).
Gilles Peskine6d061342020-04-30 18:19:32 +0200231 --arm-none-eabi-gcc-prefix=<string>
232 Prefix for a cross-compiler for arm-none-eabi
233 (default: "${ARM_NONE_EABI_GCC_PREFIX}")
Manuel Pégourié-Gonnard71930162020-08-18 10:28:51 +0200234 --arm-linux-gnueabi-gcc-prefix=<string>
235 Prefix for a cross-compiler for arm-linux-gnueabi
236 (default: "${ARM_LINUX_GNUEABI_GCC_PREFIX}")
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100237 --armcc Run ARM Compiler builds (on by default).
Gilles Peskinea28db922019-01-10 00:05:18 +0100238 --except Exclude the COMPONENTs listed on the command line,
239 instead of running only those.
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200240 --no-append-outcome Write a new outcome file and analyze it (default).
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100241 --no-armcc Skip ARM Compiler builds.
Gilles Peskine38d81652018-03-21 08:40:26 +0100242 --no-force Refuse to overwrite modified files (default).
243 --no-keep-going Stop at the first error (default).
244 --no-memory No additional memory tests (default).
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200245 --no-quiet Print full ouput from components.
Gilles Peskine709346a2017-12-10 23:43:39 +0100246 --out-of-source-dir=<path> Directory used for CMake out-of-source build tests.
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200247 --outcome-file=<path> File where test outcomes are written (not done if
248 empty; default: \$MBEDTLS_TEST_OUTCOME_FILE).
Gilles Peskine38d81652018-03-21 08:40:26 +0100249 --random-seed Use a random seed value for randomized tests (default).
Manuel Pégourié-Gonnarde0501912020-06-08 12:59:27 +0200250 -r|--release-test Run this script in release mode. This fixes the seed value to ${RELEASE_SEED}.
Gilles Peskine709346a2017-12-10 23:43:39 +0100251 -s|--seed Integer seed value to use for this test run.
252
253Tool path options:
254 --armc5-bin-dir=<ARMC5_bin_dir_path> ARM Compiler 5 bin directory.
255 --armc6-bin-dir=<ARMC6_bin_dir_path> ARM Compiler 6 bin directory.
256 --gnutls-cli=<GnuTLS_cli_path> GnuTLS client executable to use for most tests.
257 --gnutls-serv=<GnuTLS_serv_path> GnuTLS server executable to use for most tests.
258 --gnutls-legacy-cli=<GnuTLS_cli_path> GnuTLS client executable to use for legacy tests.
259 --gnutls-legacy-serv=<GnuTLS_serv_path> GnuTLS server executable to use for legacy tests.
260 --openssl=<OpenSSL_path> OpenSSL executable to use for most tests.
261 --openssl-legacy=<OpenSSL_path> OpenSSL executable to use for legacy tests e.g. SSLv3.
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100262 --openssl-next=<OpenSSL_path> OpenSSL executable to use for recent things like ARIA
Gilles Peskine709346a2017-12-10 23:43:39 +0100263EOF
SimonB2e23c822016-04-16 21:54:39 +0100264}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100265
266# remove built files as well as the cmake cache/config
267cleanup()
268{
Gilles Peskinea71d64c2018-03-21 12:16:57 +0100269 if [ -n "${MBEDTLS_ROOT_DIR+set}" ]; then
270 cd "$MBEDTLS_ROOT_DIR"
271 fi
272
Gilles Peskine7c652162017-12-11 00:01:40 +0100273 command make clean
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200274
Gilles Peskine31b07e22018-03-21 12:15:06 +0100275 # Remove CMake artefacts
Jaeden Amero2d0e00f2018-11-07 18:46:41 +0000276 find . -name .git -prune -o \
Gilles Peskine31b07e22018-03-21 12:15:06 +0100277 -iname CMakeFiles -exec rm -rf {} \+ -o \
278 \( -iname cmake_install.cmake -o \
279 -iname CTestTestfile.cmake -o \
280 -iname CMakeCache.txt \) -exec rm {} \+
281 # Recover files overwritten by in-tree CMake builds
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000282 rm -f include/Makefile include/mbedtls/Makefile programs/*/Makefile
Gilles Peskine636c26a2020-03-04 20:46:15 +0100283 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile
284 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200285
Jaeden Ameroab83fdf2019-06-20 17:38:22 +0100286 # Remove any artifacts from the component_test_cmake_as_subdirectory test.
287 rm -rf programs/test/cmake_subproject/build
288 rm -f programs/test/cmake_subproject/Makefile
289 rm -f programs/test/cmake_subproject/cmake_subproject
290
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200291 if [ -f "$CONFIG_BAK" ]; then
292 mv "$CONFIG_BAK" "$CONFIG_H"
293 fi
John Durkopbd069d32020-10-31 22:14:03 -0700294
295 if [ -f "$CRYPTO_CONFIG_BAK" ]; then
296 mv "$CRYPTO_CONFIG_BAK" "$CRYPTO_CONFIG_H"
297 fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100298}
299
Gilles Peskine7c652162017-12-11 00:01:40 +0100300# Executed on exit. May be redefined depending on command line options.
301final_report () {
302 :
303}
304
305fatal_signal () {
306 cleanup
307 final_report $1
308 trap - $1
309 kill -$1 $$
310}
311
312trap 'fatal_signal HUP' HUP
313trap 'fatal_signal INT' INT
314trap 'fatal_signal TERM' TERM
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200315
Gilles Peskine85229ac2021-09-30 18:24:21 +0200316# Number of processors on this machine. Used as the default setting
317# for parallel make.
318all_sh_nproc ()
319{
320 {
321 nproc || # Linux
322 sysctl -n hw.ncpuonline || # NetBSD, OpenBSD
323 sysctl -n hw.ncpu || # FreeBSD
324 echo 1
325 } 2>/dev/null
326}
327
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100328msg()
329{
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100330 if [ -n "${current_component:-}" ]; then
331 current_section="${current_component#component_}: $1"
332 else
333 current_section="$1"
334 fi
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200335
336 if [ $QUIET -eq 1 ]; then
337 return
338 fi
339
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100340 echo ""
341 echo "******************************************************************"
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100342 echo "* $current_section "
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000343 printf "* "; date
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100344 echo "******************************************************************"
345}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100346
Gilles Peskine8f073122018-11-27 15:58:47 +0100347armc6_build_test()
348{
349 FLAGS="$1"
Andres AGa5cd9732016-10-17 15:23:10 +0100350
Gilles Peskine18487f62020-04-30 23:11:54 +0200351 msg "build: ARM Compiler 6 ($FLAGS)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100352 ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \
353 WARNING_CFLAGS='-xc -std=c99' make lib
Gilles Peskine18487f62020-04-30 23:11:54 +0200354
355 msg "size: ARM Compiler 6 ($FLAGS)"
356 "$ARMC6_FROMELF" -z library/*.o
357
Gilles Peskine8f073122018-11-27 15:58:47 +0100358 make clean
359}
Andres AGa5cd9732016-10-17 15:23:10 +0100360
Andres AGd9eba4b2016-08-26 14:42:14 +0100361err_msg()
362{
363 echo "$1" >&2
364}
365
366check_tools()
367{
368 for TOOL in "$@"; do
Andres AG98393602017-01-31 17:04:45 +0000369 if ! `type "$TOOL" >/dev/null 2>&1`; then
Andres AGd9eba4b2016-08-26 14:42:14 +0100370 err_msg "$TOOL not found!"
371 exit 1
372 fi
373 done
374}
375
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400376check_headers_in_cpp () {
Peter Kolbus1bc1a4c2019-02-01 17:19:08 -0600377 ls include/mbedtls | grep "\.h$" >headers.txt
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400378 <programs/test/cpp_dummy_build.cpp sed -n 's/"$//; s!^#include "mbedtls/!!p' |
379 sort |
380 diff headers.txt -
381 rm headers.txt
382}
383
Gilles Peskine8f073122018-11-27 15:58:47 +0100384pre_parse_command_line () {
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000385 COMMAND_LINE_COMPONENTS=
Gilles Peskinea28db922019-01-10 00:05:18 +0100386 all_except=0
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000387 no_armcc=
SimonB2e23c822016-04-16 21:54:39 +0100388
Jaeden Amero9b90f2e2018-11-02 18:34:17 +0000389 # Note that legacy options are ignored instead of being omitted from this
390 # list of options, so invocations that worked with previous version of
391 # all.sh will still run and work properly.
Gilles Peskine8f073122018-11-27 15:58:47 +0100392 while [ $# -gt 0 ]; do
Gilles Peskine55f7c942019-01-09 22:28:21 +0100393 case "$1" in
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200394 --append-outcome) append_outcome=1;;
Gilles Peskine6d061342020-04-30 18:19:32 +0200395 --arm-none-eabi-gcc-prefix) shift; ARM_NONE_EABI_GCC_PREFIX="$1";;
Manuel Pégourié-Gonnard71930162020-08-18 10:28:51 +0200396 --arm-linux-gnueabi-gcc-prefix) shift; ARM_LINUX_GNUEABI_GCC_PREFIX="$1";;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000397 --armcc) no_armcc=;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100398 --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
399 --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000400 --except) all_except=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100401 --force|-f) FORCE=1;;
402 --gnutls-cli) shift; GNUTLS_CLI="$1";;
403 --gnutls-legacy-cli) shift; GNUTLS_LEGACY_CLI="$1";;
404 --gnutls-legacy-serv) shift; GNUTLS_LEGACY_SERV="$1";;
405 --gnutls-serv) shift; GNUTLS_SERV="$1";;
406 --help|-h) usage; exit;;
407 --keep-going|-k) KEEP_GOING=1;;
Gilles Peskine878cf602019-01-06 20:50:38 +0000408 --list-all-components) printf '%s\n' $ALL_COMPONENTS; exit;;
409 --list-components) printf '%s\n' $SUPPORTED_COMPONENTS; exit;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100410 --memory|-m) MEMORY=1;;
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200411 --no-append-outcome) append_outcome=0;;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000412 --no-armcc) no_armcc=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100413 --no-force) FORCE=0;;
414 --no-keep-going) KEEP_GOING=0;;
415 --no-memory) MEMORY=0;;
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200416 --no-quiet) QUIET=0;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100417 --openssl) shift; OPENSSL="$1";;
418 --openssl-legacy) shift; OPENSSL_LEGACY="$1";;
419 --openssl-next) shift; OPENSSL_NEXT="$1";;
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200420 --outcome-file) shift; MBEDTLS_TEST_OUTCOME_FILE="$1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100421 --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200422 --quiet|-q) QUIET=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100423 --random-seed) unset SEED;;
Manuel Pégourié-Gonnarde0501912020-06-08 12:59:27 +0200424 --release-test|-r) SEED=$RELEASE_SEED;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100425 --seed|-s) shift; SEED="$1";;
426 -*)
427 echo >&2 "Unknown option: $1"
428 echo >&2 "Run $0 --help for usage."
429 exit 120
430 ;;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000431 *) COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS $1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100432 esac
433 shift
Gilles Peskine8f073122018-11-27 15:58:47 +0100434 done
SimonB2e23c822016-04-16 21:54:39 +0100435
Gilles Peskinea28db922019-01-10 00:05:18 +0100436 # With no list of components, run everything.
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000437 if [ -z "$COMMAND_LINE_COMPONENTS" ]; then
438 all_except=1
Andres AGdc192212016-08-31 17:33:13 +0100439 fi
440
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000441 # --no-armcc is a legacy option. The modern way is --except '*_armcc*'.
442 # Ignore it if components are listed explicitly on the command line.
Gilles Peskinea28db922019-01-10 00:05:18 +0100443 if [ -n "$no_armcc" ] && [ $all_except -eq 1 ]; then
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000444 COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS *_armcc*"
SimonB2e23c822016-04-16 21:54:39 +0100445 fi
SimonB2e23c822016-04-16 21:54:39 +0100446
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000447 # Build the list of components to run.
Gilles Peskinea28db922019-01-10 00:05:18 +0100448 RUN_COMPONENTS=
449 for component in $SUPPORTED_COMPONENTS; do
450 if is_component_included "$component"; [ $? -eq $all_except ]; then
451 RUN_COMPONENTS="$RUN_COMPONENTS $component"
452 fi
453 done
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000454
455 unset all_except
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000456 unset no_armcc
Gilles Peskine8f073122018-11-27 15:58:47 +0100457}
SimonB2e23c822016-04-16 21:54:39 +0100458
Gilles Peskine8f073122018-11-27 15:58:47 +0100459pre_check_git () {
460 if [ $FORCE -eq 1 ]; then
Gilles Peskine53190e62019-01-09 23:17:35 +0100461 rm -rf "$OUT_OF_SOURCE_DIR"
Gilles Peskine8f073122018-11-27 15:58:47 +0100462 git checkout-index -f -q $CONFIG_H
463 cleanup
464 else
SimonB2e23c822016-04-16 21:54:39 +0100465
Gilles Peskine8f073122018-11-27 15:58:47 +0100466 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
467 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
468 echo "You can either delete this directory manually, or force the test by rerunning"
469 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
470 exit 1
471 fi
472
Gilles Peskined1174cf2019-01-09 22:30:01 +0100473 if ! git diff --quiet include/mbedtls/config.h; then
Gilles Peskine8f073122018-11-27 15:58:47 +0100474 err_msg "Warning - the configuration file 'include/mbedtls/config.h' has been edited. "
475 echo "You can either delete or preserve your work, or force the test by rerunning the"
476 echo "script as: $0 --force"
477 exit 1
478 fi
SimonB2e23c822016-04-16 21:54:39 +0100479 fi
Andrzej Kurekeb508712019-02-14 07:18:59 -0500480}
481
Gilles Peskine8f073122018-11-27 15:58:47 +0100482pre_setup_keep_going () {
Gilles Peskine7c652162017-12-11 00:01:40 +0100483 failure_summary=
484 failure_count=0
485 start_red=
486 end_color=
487 if [ -t 1 ]; then
Gilles Peskine9736b9d2018-01-02 21:54:17 +0100488 case "${TERM:-}" in
Gilles Peskine7c652162017-12-11 00:01:40 +0100489 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
490 start_red=$(printf '\033[31m')
491 end_color=$(printf '\033[0m')
492 ;;
493 esac
494 fi
495 record_status () {
496 if "$@"; then
497 last_status=0
498 else
499 last_status=$?
500 text="$current_section: $* -> $last_status"
501 failure_summary="$failure_summary
502$text"
503 failure_count=$((failure_count + 1))
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200504 echo "${start_red}^^^^$text^^^^${end_color}" >&2
Gilles Peskine7c652162017-12-11 00:01:40 +0100505 fi
506 }
507 make () {
508 case "$*" in
509 *test|*check)
510 if [ $build_status -eq 0 ]; then
511 record_status command make "$@"
512 else
513 echo "(skipped because the build failed)"
514 fi
515 ;;
516 *)
517 record_status command make "$@"
518 build_status=$last_status
519 ;;
520 esac
521 }
522 final_report () {
523 if [ $failure_count -gt 0 ]; then
524 echo
525 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
526 echo "${start_red}FAILED: $failure_count${end_color}$failure_summary"
527 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Jaeden Amero7c1258d2018-07-20 16:42:14 +0100528 exit 1
Gilles Peskine7c652162017-12-11 00:01:40 +0100529 elif [ -z "${1-}" ]; then
530 echo "SUCCESS :)"
531 fi
532 if [ -n "${1-}" ]; then
533 echo "Killed by SIG$1."
534 fi
535 }
Gilles Peskine8f073122018-11-27 15:58:47 +0100536}
537
Gilles Peskine7c652162017-12-11 00:01:40 +0100538if_build_succeeded () {
539 if [ $build_status -eq 0 ]; then
540 record_status "$@"
541 fi
542}
543
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200544# to be used instead of ! for commands run with
545# record_status or if_build_succeeded
546not() {
547 ! "$@"
548}
549
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200550pre_setup_quiet_redirect () {
551 if [ $QUIET -ne 1 ]; then
552 redirect_out () {
553 "$@"
554 }
Manuel Pégourié-Gonnardf1f180a2020-06-08 10:46:35 +0200555 redirect_err () {
556 "$@"
557 }
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200558 else
559 redirect_out () {
560 "$@" >/dev/null
561 }
Manuel Pégourié-Gonnardf1f180a2020-06-08 10:46:35 +0200562 redirect_err () {
563 "$@" 2>/dev/null
564 }
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200565 fi
566}
567
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200568pre_prepare_outcome_file () {
569 case "$MBEDTLS_TEST_OUTCOME_FILE" in
570 [!/]*) MBEDTLS_TEST_OUTCOME_FILE="$PWD/$MBEDTLS_TEST_OUTCOME_FILE";;
571 esac
572 if [ -n "$MBEDTLS_TEST_OUTCOME_FILE" ] && [ "$append_outcome" -eq 0 ]; then
573 rm -f "$MBEDTLS_TEST_OUTCOME_FILE"
574 fi
575}
576
Gilles Peskine8f073122018-11-27 15:58:47 +0100577pre_print_configuration () {
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200578 if [ $QUIET -eq 1 ]; then
579 return
580 fi
581
Gilles Peskine8f073122018-11-27 15:58:47 +0100582 msg "info: $0 configuration"
583 echo "MEMORY: $MEMORY"
584 echo "FORCE: $FORCE"
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200585 echo "MBEDTLS_TEST_OUTCOME_FILE: ${MBEDTLS_TEST_OUTCOME_FILE:-(none)}"
Gilles Peskine8f073122018-11-27 15:58:47 +0100586 echo "SEED: ${SEED-"UNSET"}"
Gilles Peskine636c26a2020-03-04 20:46:15 +0100587 echo
Gilles Peskine8f073122018-11-27 15:58:47 +0100588 echo "OPENSSL: $OPENSSL"
589 echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
590 echo "OPENSSL_NEXT: $OPENSSL_NEXT"
591 echo "GNUTLS_CLI: $GNUTLS_CLI"
592 echo "GNUTLS_SERV: $GNUTLS_SERV"
593 echo "GNUTLS_LEGACY_CLI: $GNUTLS_LEGACY_CLI"
594 echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV"
595 echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
596 echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
597}
Andres AG7770ea82016-10-10 15:46:20 +0100598
Andres AGd9eba4b2016-08-26 14:42:14 +0100599# Make sure the tools we need are available.
Gilles Peskine8f073122018-11-27 15:58:47 +0100600pre_check_tools () {
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000601 # Build the list of variables to pass to output_env.sh.
602 set env
SimonB2e23c822016-04-16 21:54:39 +0100603
Gilles Peskine87964262019-01-06 22:40:00 +0000604 case " $RUN_COMPONENTS " in
605 # Require OpenSSL and GnuTLS if running any tests (as opposed to
606 # only doing builds). Not all tests run OpenSSL and GnuTLS, but this
607 # is a good enough approximation in practice.
608 *" test_"*)
609 # To avoid setting OpenSSL and GnuTLS for each call to compat.sh
610 # and ssl-opt.sh, we just export the variables they require.
611 export OPENSSL_CMD="$OPENSSL"
612 export GNUTLS_CLI="$GNUTLS_CLI"
613 export GNUTLS_SERV="$GNUTLS_SERV"
614 # Avoid passing --seed flag in every call to ssl-opt.sh
615 if [ -n "${SEED-}" ]; then
616 export SEED
617 fi
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000618 set "$@" OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY"
619 set "$@" GNUTLS_CLI="$GNUTLS_CLI" GNUTLS_SERV="$GNUTLS_SERV"
620 set "$@" GNUTLS_LEGACY_CLI="$GNUTLS_LEGACY_CLI"
621 set "$@" GNUTLS_LEGACY_SERV="$GNUTLS_LEGACY_SERV"
Gilles Peskine87964262019-01-06 22:40:00 +0000622 check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$OPENSSL_NEXT" \
623 "$GNUTLS_CLI" "$GNUTLS_SERV" \
624 "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV"
625 ;;
626 esac
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200627
Gilles Peskine87964262019-01-06 22:40:00 +0000628 case " $RUN_COMPONENTS " in
629 *_doxygen[_\ ]*) check_tools "doxygen" "dot";;
630 esac
Andres AGd9eba4b2016-08-26 14:42:14 +0100631
Gilles Peskine87964262019-01-06 22:40:00 +0000632 case " $RUN_COMPONENTS " in
Gilles Peskine6d061342020-04-30 18:19:32 +0200633 *_arm_none_eabi_gcc[_\ ]*) check_tools "${ARM_NONE_EABI_GCC_PREFIX}gcc";;
Gilles Peskine87964262019-01-06 22:40:00 +0000634 esac
Andres AGd9eba4b2016-08-26 14:42:14 +0100635
Gilles Peskine87964262019-01-06 22:40:00 +0000636 case " $RUN_COMPONENTS " in
637 *_mingw[_\ ]*) check_tools "i686-w64-mingw32-gcc";;
638 esac
639
640 case " $RUN_COMPONENTS " in
641 *" test_zeroize "*) check_tools "gdb";;
642 esac
643
644 case " $RUN_COMPONENTS " in
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000645 *_armcc*)
Gilles Peskine87964262019-01-06 22:40:00 +0000646 ARMC5_CC="$ARMC5_BIN_DIR/armcc"
647 ARMC5_AR="$ARMC5_BIN_DIR/armar"
Gilles Peskine18487f62020-04-30 23:11:54 +0200648 ARMC5_FROMELF="$ARMC5_BIN_DIR/fromelf"
Gilles Peskine87964262019-01-06 22:40:00 +0000649 ARMC6_CC="$ARMC6_BIN_DIR/armclang"
650 ARMC6_AR="$ARMC6_BIN_DIR/armar"
Gilles Peskine18487f62020-04-30 23:11:54 +0200651 ARMC6_FROMELF="$ARMC6_BIN_DIR/fromelf"
652 check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC5_FROMELF" \
653 "$ARMC6_CC" "$ARMC6_AR" "$ARMC6_FROMELF";;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000654 esac
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000655
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200656 # past this point, no call to check_tool, only printing output
657 if [ $QUIET -eq 1 ]; then
658 return
659 fi
660
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000661 msg "info: output_env.sh"
662 case $RUN_COMPONENTS in
663 *_armcc*)
664 set "$@" ARMC5_CC="$ARMC5_CC" ARMC6_CC="$ARMC6_CC" RUN_ARMCC=1;;
665 *) set "$@" RUN_ARMCC=0;;
666 esac
667 "$@" scripts/output_env.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100668}
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100669
Gilles Peskine192c72f2017-12-21 15:59:21 +0100670
671
672################################################################
673#### Basic checks
674################################################################
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100675
676#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200677# Test Suites to be executed
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100678#
Manuel Pégourié-Gonnard3d404b42015-07-08 21:59:16 +0100679# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200680# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100681# 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 +0200682# time, so start with a GCC build).
683# 2. Minimize total running time, by avoiding useless rebuilds
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100684#
Manuel Pégourié-Gonnard259b08a2016-01-08 16:27:41 +0100685# Indicative running times are given for reference.
686
Gilles Peskine8f073122018-11-27 15:58:47 +0100687component_check_recursion () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200688 msg "Check: recursion.pl" # < 1s
Gilles Peskine8f073122018-11-27 15:58:47 +0100689 record_status tests/scripts/recursion.pl library/*.c
690}
Janos Follathb72c6782016-07-19 14:54:17 +0100691
Gilles Peskine8f073122018-11-27 15:58:47 +0100692component_check_generated_files () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200693 msg "Check: freshness of generated source files" # < 1s
Gilles Peskine8f073122018-11-27 15:58:47 +0100694 record_status tests/scripts/check-generated-files.sh
695}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200696
Gilles Peskine8f073122018-11-27 15:58:47 +0100697component_check_doxy_blocks () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200698 msg "Check: doxygen markup outside doxygen blocks" # < 1s
Gilles Peskine8f073122018-11-27 15:58:47 +0100699 record_status tests/scripts/check-doxy-blocks.pl
700}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200701
Gilles Peskine8f073122018-11-27 15:58:47 +0100702component_check_files () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200703 msg "Check: file sanity checks (permissions, encodings)" # < 1s
Gilles Peskinefb4f9332020-06-25 14:18:34 +0200704 record_status tests/scripts/check_files.py
Gilles Peskine8f073122018-11-27 15:58:47 +0100705}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200706
Gilles Peskine30e0bb42020-05-10 17:40:49 +0200707component_check_changelog () {
708 msg "Check: changelog entries" # < 1s
709 rm -f ChangeLog.new
710 record_status scripts/assemble_changelog.py -o ChangeLog.new
711 if [ -e ChangeLog.new ]; then
712 # Show the diff for information. It isn't an error if the diff is
713 # non-empty.
714 diff -u ChangeLog ChangeLog.new || true
715 rm ChangeLog.new
716 fi
717}
718
Gilles Peskine8f073122018-11-27 15:58:47 +0100719component_check_names () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200720 msg "Check: declared and exported names (builds the library)" # < 3s
Gilles Peskine31da67b2021-09-27 20:13:00 +0200721 record_status tests/scripts/check_names.py -v
Gilles Peskine8f073122018-11-27 15:58:47 +0100722}
Darryl Greena07039c2018-03-13 16:48:16 +0000723
Gilles Peskine895868b2019-09-19 21:30:05 +0200724component_check_test_cases () {
725 msg "Check: test case descriptions" # < 1s
Manuel Pégourié-Gonnarda9119162020-06-02 11:51:40 +0200726 if [ $QUIET -eq 1 ]; then
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +0200727 opt='--quiet'
Manuel Pégourié-Gonnarda9119162020-06-02 11:51:40 +0200728 else
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +0200729 opt=''
Manuel Pégourié-Gonnarda9119162020-06-02 11:51:40 +0200730 fi
Gilles Peskinefb4f9332020-06-25 14:18:34 +0200731 record_status tests/scripts/check_test_cases.py $opt
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +0200732 unset opt
Gilles Peskine895868b2019-09-19 21:30:05 +0200733}
734
Gilles Peskine8f073122018-11-27 15:58:47 +0100735component_check_doxygen_warnings () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200736 msg "Check: doxygen warnings (builds the documentation)" # ~ 3s
Gilles Peskine8f073122018-11-27 15:58:47 +0100737 record_status tests/scripts/doxygen.sh
738}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200739
Gilles Peskine192c72f2017-12-21 15:59:21 +0100740
Gilles Peskine636c26a2020-03-04 20:46:15 +0100741
Gilles Peskine192c72f2017-12-21 15:59:21 +0100742################################################################
743#### Build and test many configurations and targets
744################################################################
745
Gilles Peskine7832c9f2019-04-08 17:00:15 +0200746component_test_default_out_of_box () {
747 msg "build: make, default config (out-of-box)" # ~1min
748 make
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200749 # Disable fancy stuff
Gilles Peskine717cd762019-09-27 20:21:11 +0200750 SAVE_MBEDTLS_TEST_OUTCOME_FILE="$MBEDTLS_TEST_OUTCOME_FILE"
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200751 unset MBEDTLS_TEST_OUTCOME_FILE
Gilles Peskine7832c9f2019-04-08 17:00:15 +0200752
753 msg "test: main suites make, default config (out-of-box)" # ~10s
754 make test
755
756 msg "selftest: make, default config (out-of-box)" # ~10s
Gilles Peskine97bea012020-04-23 23:37:45 +0200757 if_build_succeeded programs/test/selftest
Gilles Peskine717cd762019-09-27 20:21:11 +0200758
759 export MBEDTLS_TEST_OUTCOME_FILE="$SAVE_MBEDTLS_TEST_OUTCOME_FILE"
760 unset SAVE_MBEDTLS_TEST_OUTCOME_FILE
Gilles Peskine7832c9f2019-04-08 17:00:15 +0200761}
762
Gilles Peskine8f073122018-11-27 15:58:47 +0100763component_test_default_cmake_gcc_asan () {
764 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100765 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
766 make
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200767
Gilles Peskine8f073122018-11-27 15:58:47 +0100768 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
769 make test
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200770
Gilles Peskine97bea012020-04-23 23:37:45 +0200771 msg "test: selftest (ASan build)" # ~ 10s
772 if_build_succeeded programs/test/selftest
773
Gilles Peskine8f073122018-11-27 15:58:47 +0100774 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
775 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200776
Gilles Peskine8f073122018-11-27 15:58:47 +0100777 msg "test: compat.sh (ASan build)" # ~ 6 min
778 if_build_succeeded tests/compat.sh
Piotr Nowicki9978e6e2020-04-07 16:07:05 +0200779
780 msg "test: context-info.sh (ASan build)" # ~ 15 sec
781 if_build_succeeded tests/context-info.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100782}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200783
Hanno Becker01635512019-02-26 14:27:09 +0000784component_test_full_cmake_gcc_asan () {
785 msg "build: full config, cmake, gcc, ASan"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200786 scripts/config.py full
Hanno Becker01635512019-02-26 14:27:09 +0000787 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
788 make
789
790 msg "test: main suites (inc. selftests) (full config, ASan build)"
791 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +0100792
Gilles Peskine97bea012020-04-23 23:37:45 +0200793 msg "test: selftest (ASan build)" # ~ 10s
794 if_build_succeeded programs/test/selftest
795
Gilles Peskine636c26a2020-03-04 20:46:15 +0100796 msg "test: ssl-opt.sh (full config, ASan build)"
797 if_build_succeeded tests/ssl-opt.sh
798
799 msg "test: compat.sh (full config, ASan build)"
800 if_build_succeeded tests/compat.sh
Piotr Nowicki9978e6e2020-04-07 16:07:05 +0200801
802 msg "test: context-info.sh (full config, ASan build)" # ~ 15 sec
803 if_build_succeeded tests/context-info.sh
Gilles Peskine636c26a2020-03-04 20:46:15 +0100804}
805
Ronald Cronc3623db2020-10-29 10:51:32 +0100806component_test_psa_crypto_key_id_encodes_owner () {
807 msg "build: full config - USE_PSA_CRYPTO + PSA_CRYPTO_KEY_ID_ENCODES_OWNER, cmake, gcc, ASan"
808 scripts/config.py full
809 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
810 scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
811 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
812 make
813
814 msg "test: full config - USE_PSA_CRYPTO + PSA_CRYPTO_KEY_ID_ENCODES_OWNER, cmake, gcc, ASan"
815 make test
816}
817
Gilles Peskine99a34622021-06-17 11:37:52 +0200818# check_renamed_symbols HEADER LIB
819# Check that if HEADER contains '#define MACRO ...' then MACRO is not a symbol
820# name is LIB.
821check_renamed_symbols () {
822 ! nm "$2" | sed 's/.* //' |
823 grep -x -F "$(sed -n 's/^ *# *define *\([A-Z_a-z][0-9A-Z_a-z]*\)..*/\1/p' "$1")"
824}
825
Gilles Peskine984c19f2021-06-15 18:37:38 +0200826component_build_psa_crypto_spm () {
827 msg "build: full config - USE_PSA_CRYPTO + PSA_CRYPTO_KEY_ID_ENCODES_OWNER + PSA_CRYPTO_SPM, make, gcc"
828 scripts/config.py full
829 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
830 scripts/config.py unset MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS
831 scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
832 scripts/config.py set MBEDTLS_PSA_CRYPTO_SPM
833 # We can only compile, not link, since our test and sample programs
834 # aren't equipped for the modified names used when MBEDTLS_PSA_CRYPTO_SPM
835 # is active.
836 make CC=gcc CFLAGS='-Werror -Wall -Wextra -I../tests/include/spe' lib
Gilles Peskine99a34622021-06-17 11:37:52 +0200837
838 # Check that if a symbol is renamed by crypto_spe.h, the non-renamed
839 # version is not present.
840 echo "Checking for renamed symbols in the library"
841 if_build_succeeded check_renamed_symbols tests/include/spe/crypto_spe.h library/libmbedcrypto.a
Gilles Peskine984c19f2021-06-15 18:37:38 +0200842}
843
Ronald Cron336678b2021-01-28 17:54:24 +0100844component_test_psa_crypto_client () {
845 msg "build: default config - PSA_CRYPTO_C + PSA_CRYPTO_CLIENT, make"
846 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C
847 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
848 scripts/config.py set MBEDTLS_PSA_CRYPTO_CLIENT
849 make
850
851 msg "test: default config - PSA_CRYPTO_C + PSA_CRYPTO_CLIENT, make"
852 make test
853}
854
Gilles Peskine636c26a2020-03-04 20:46:15 +0100855component_test_zlib_make() {
856 msg "build: zlib enabled, make"
857 scripts/config.py set MBEDTLS_ZLIB_SUPPORT
858 make ZLIB=1 CFLAGS='-Werror -O1'
859
860 msg "test: main suites (zlib, make)"
861 make test
862
863 msg "test: ssl-opt.sh (zlib, make)"
864 if_build_succeeded tests/ssl-opt.sh
865}
866support_test_zlib_make () {
867 base=support_test_zlib_$$
868 cat <<'EOF' > ${base}.c
869#include "zlib.h"
870int main(void) { return 0; }
871EOF
872 gcc -o ${base}.exe ${base}.c -lz 2>/dev/null
873 ret=$?
874 rm -f ${base}.*
875 return $ret
876}
877
878component_test_zlib_cmake() {
879 msg "build: zlib enabled, cmake"
880 scripts/config.py set MBEDTLS_ZLIB_SUPPORT
881 cmake -D ENABLE_ZLIB_SUPPORT=On -D CMAKE_BUILD_TYPE:String=Check .
882 make
883
884 msg "test: main suites (zlib, cmake)"
885 make test
886
887 msg "test: ssl-opt.sh (zlib, cmake)"
888 if_build_succeeded tests/ssl-opt.sh
889}
890support_test_zlib_cmake () {
891 support_test_zlib_make "$@"
Manuel Pégourié-Gonnardf2e29022020-01-24 10:17:20 +0100892}
Manuel Pégourié-Gonnard95e04492020-01-02 11:45:12 +0100893
Jaeden Ameroc17f2932021-05-14 08:34:32 +0100894component_test_psa_crypto_rsa_no_genprime() {
895 msg "build: default config minus MBEDTLS_GENPRIME"
896 scripts/config.py unset MBEDTLS_GENPRIME
897 make
898
899 msg "test: default config minus MBEDTLS_GENPRIME"
900 make test
901}
902
Gilles Peskine782f4112018-11-27 16:11:09 +0100903component_test_ref_configs () {
904 msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
905 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
906 record_status tests/scripts/test-ref-configs.pl
907}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200908
Gilles Peskine8f073122018-11-27 15:58:47 +0100909component_test_sslv3 () {
910 msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200911 scripts/config.py set MBEDTLS_SSL_PROTO_SSL3
Gilles Peskine8f073122018-11-27 15:58:47 +0100912 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
913 make
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200914
Gilles Peskine8f073122018-11-27 15:58:47 +0100915 msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
916 make test
Simon Butcher3ea7f522016-03-07 23:22:10 +0000917
Gilles Peskine8f073122018-11-27 15:58:47 +0100918 msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
919 if_build_succeeded tests/compat.sh -m 'tls1 tls1_1 tls1_2 dtls1 dtls1_2'
920 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
Simon Butcher3ea7f522016-03-07 23:22:10 +0000921
Gilles Peskine8f073122018-11-27 15:58:47 +0100922 msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
923 if_build_succeeded tests/ssl-opt.sh
Piotr Nowicki9978e6e2020-04-07 16:07:05 +0200924
925 msg "build: SSLv3 - context-info.sh (ASan build)" # ~ 15 sec
926 if_build_succeeded tests/context-info.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100927}
Simon Butcher3ea7f522016-03-07 23:22:10 +0000928
Gilles Peskine8f073122018-11-27 15:58:47 +0100929component_test_no_renegotiation () {
930 msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200931 scripts/config.py unset MBEDTLS_SSL_RENEGOTIATION
Gilles Peskine8f073122018-11-27 15:58:47 +0100932 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
933 make
Simon Butcher3ea7f522016-03-07 23:22:10 +0000934
Gilles Peskine8f073122018-11-27 15:58:47 +0100935 msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
936 make test
Hanno Becker134c2ab2017-10-12 15:29:50 +0100937
Gilles Peskine8f073122018-11-27 15:58:47 +0100938 msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
939 if_build_succeeded tests/ssl-opt.sh
940}
Hanno Becker134c2ab2017-10-12 15:29:50 +0100941
Gilles Peskine636c26a2020-03-04 20:46:15 +0100942component_test_no_pem_no_fs () {
943 msg "build: Default + !MBEDTLS_PEM_PARSE_C + !MBEDTLS_FS_IO (ASan build)"
944 scripts/config.py unset MBEDTLS_PEM_PARSE_C
945 scripts/config.py unset MBEDTLS_FS_IO
946 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C # requires a filesystem
947 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA ITS
948 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
949 make
950
951 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - main suites (inc. selftests) (ASan build)" # ~ 50s
952 make test
953
954 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - ssl-opt.sh (ASan build)" # ~ 6 min
955 if_build_succeeded tests/ssl-opt.sh
956}
957
Gilles Peskine8f073122018-11-27 15:58:47 +0100958component_test_rsa_no_crt () {
959 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200960 scripts/config.py set MBEDTLS_RSA_NO_CRT
Gilles Peskine8f073122018-11-27 15:58:47 +0100961 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
962 make
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +0100963
Gilles Peskine8f073122018-11-27 15:58:47 +0100964 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
965 make test
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100966
Gilles Peskine8f073122018-11-27 15:58:47 +0100967 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
968 if_build_succeeded tests/ssl-opt.sh -f RSA
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100969
Gilles Peskine8f073122018-11-27 15:58:47 +0100970 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
971 if_build_succeeded tests/compat.sh -t RSA
Piotr Nowicki9978e6e2020-04-07 16:07:05 +0200972
973 msg "test: RSA_NO_CRT - RSA-related part of context-info.sh (ASan build)" # ~ 15 sec
974 if_build_succeeded tests/context-info.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100975}
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100976
Gilles Peskine2747d7d2021-02-03 14:56:51 +0100977component_test_no_ctr_drbg_classic () {
978 msg "build: Full minus CTR_DRBG, classic crypto in TLS"
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +0200979 scripts/config.py full
980 scripts/config.py unset MBEDTLS_CTR_DRBG_C
Gilles Peskine2747d7d2021-02-03 14:56:51 +0100981 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +0200982
983 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
984 make
985
Gilles Peskine2747d7d2021-02-03 14:56:51 +0100986 msg "test: Full minus CTR_DRBG, classic crypto - main suites"
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +0200987 make test
988
Gilles Peskineba749042021-01-13 20:02:03 +0100989 # In this configuration, the TLS test programs use HMAC_DRBG.
990 # The SSL tests are slow, so run a small subset, just enough to get
991 # confidence that the SSL code copes with HMAC_DRBG.
Gilles Peskine2747d7d2021-02-03 14:56:51 +0100992 msg "test: Full minus CTR_DRBG, classic crypto - ssl-opt.sh (subset)"
Gilles Peskineba749042021-01-13 20:02:03 +0100993 if_build_succeeded tests/ssl-opt.sh -f 'Default\|SSL async private.*delay=\|tickets enabled on server'
994
Gilles Peskine2747d7d2021-02-03 14:56:51 +0100995 msg "test: Full minus CTR_DRBG, classic crypto - compat.sh (subset)"
Gilles Peskineba749042021-01-13 20:02:03 +0100996 if_build_succeeded tests/compat.sh -m tls1_2 -t 'ECDSA PSK' -V NO -p OpenSSL
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +0200997}
998
Gilles Peskine2747d7d2021-02-03 14:56:51 +0100999component_test_no_ctr_drbg_use_psa () {
1000 msg "build: Full minus CTR_DRBG, PSA crypto in TLS"
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +02001001 scripts/config.py full
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001002 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1003 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +02001004
1005 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1006 make
1007
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001008 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - main suites"
1009 make test
1010
1011 # In this configuration, the TLS test programs use HMAC_DRBG.
1012 # The SSL tests are slow, so run a small subset, just enough to get
1013 # confidence that the SSL code copes with HMAC_DRBG.
1014 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - ssl-opt.sh (subset)"
1015 if_build_succeeded tests/ssl-opt.sh -f 'Default\|SSL async private.*delay=\|tickets enabled on server'
1016
1017 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - compat.sh (subset)"
1018 if_build_succeeded tests/compat.sh -m tls1_2 -t 'ECDSA PSK' -V NO -p OpenSSL
1019}
1020
1021component_test_no_hmac_drbg_classic () {
1022 msg "build: Full minus HMAC_DRBG, classic crypto in TLS"
1023 scripts/config.py full
1024 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1025 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1026 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1027
1028 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1029 make
1030
1031 msg "test: Full minus HMAC_DRBG, classic crypto - main suites"
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +02001032 make test
1033
Gilles Peskinea2224342020-11-19 22:14:34 +01001034 # Normally our ECDSA implementation uses deterministic ECDSA. But since
1035 # HMAC_DRBG is disabled in this configuration, randomized ECDSA is used
1036 # instead.
1037 # Test SSL with non-deterministic ECDSA. Only test features that
1038 # might be affected by how ECDSA signature is performed.
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001039 msg "test: Full minus HMAC_DRBG, classic crypto - ssl-opt.sh (subset)"
Gilles Peskinea2224342020-11-19 22:14:34 +01001040 if_build_succeeded tests/ssl-opt.sh -f 'Default\|SSL async private: sign'
1041
1042 # To save time, only test one protocol version, since this part of
1043 # the protocol is identical in (D)TLS up to 1.2.
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001044 msg "test: Full minus HMAC_DRBG, classic crypto - compat.sh (ECDSA)"
Gilles Peskinea2224342020-11-19 22:14:34 +01001045 if_build_succeeded tests/compat.sh -m tls1_2 -t 'ECDSA'
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +02001046}
1047
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001048component_test_no_hmac_drbg_use_psa () {
1049 msg "build: Full minus HMAC_DRBG, PSA crypto in TLS"
1050 scripts/config.py full
1051 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1052 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1053 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1054
1055 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1056 make
1057
1058 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - main suites"
1059 make test
1060
1061 # Normally our ECDSA implementation uses deterministic ECDSA. But since
1062 # HMAC_DRBG is disabled in this configuration, randomized ECDSA is used
1063 # instead.
1064 # Test SSL with non-deterministic ECDSA. Only test features that
1065 # might be affected by how ECDSA signature is performed.
1066 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - ssl-opt.sh (subset)"
1067 if_build_succeeded tests/ssl-opt.sh -f 'Default\|SSL async private: sign'
1068
1069 # To save time, only test one protocol version, since this part of
1070 # the protocol is identical in (D)TLS up to 1.2.
1071 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - compat.sh (ECDSA)"
1072 if_build_succeeded tests/compat.sh -m tls1_2 -t 'ECDSA'
1073}
1074
1075component_test_psa_external_rng_no_drbg_classic () {
1076 msg "build: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto in TLS"
1077 scripts/config.py full
1078 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1079 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
Gilles Peskine38c12fd2021-02-08 21:02:53 +01001080 scripts/config.py unset MBEDTLS_ENTROPY_C
1081 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
1082 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001083 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1084 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1085 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1086 scripts/config.py set MBEDTLS_ECP_NO_INTERNAL_RNG
Gilles Peskine8eb29432021-02-03 20:07:11 +01001087 # When MBEDTLS_USE_PSA_CRYPTO is disabled and there is no DRBG,
1088 # the SSL test programs don't have an RNG and can't work. Explicitly
1089 # make them use the PSA RNG with -DMBEDTLS_TEST_USE_PSA_CRYPTO_RNG.
1090 make CFLAGS="$ASAN_CFLAGS -O2 -DMBEDTLS_TEST_USE_PSA_CRYPTO_RNG" LDFLAGS="$ASAN_CFLAGS"
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001091
1092 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto - main suites"
1093 make test
1094
Gilles Peskine8eb29432021-02-03 20:07:11 +01001095 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto - ssl-opt.sh (subset)"
1096 if_build_succeeded tests/ssl-opt.sh -f 'Default'
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001097}
1098
1099component_test_psa_external_rng_no_drbg_use_psa () {
1100 msg "build: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto in TLS"
Gilles Peskinec109b372020-11-23 17:39:04 +01001101 scripts/config.py full
1102 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
Gilles Peskine38c12fd2021-02-08 21:02:53 +01001103 scripts/config.py unset MBEDTLS_ENTROPY_C
1104 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
1105 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskinec109b372020-11-23 17:39:04 +01001106 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1107 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1108 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1109 scripts/config.py set MBEDTLS_ECP_NO_INTERNAL_RNG
1110 make CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
1111
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001112 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto - main suites"
Gilles Peskinec109b372020-11-23 17:39:04 +01001113 make test
1114
Gilles Peskine8eb29432021-02-03 20:07:11 +01001115 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto - ssl-opt.sh (subset)"
1116 if_build_succeeded tests/ssl-opt.sh -f 'Default\|opaque'
Gilles Peskinec109b372020-11-23 17:39:04 +01001117}
1118
1119component_test_psa_external_rng_use_psa_crypto () {
1120 msg "build: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
1121 scripts/config.py full
1122 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
1123 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1124 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1125 make CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
1126
1127 msg "test: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
1128 make test
1129
Gilles Peskineba749042021-01-13 20:02:03 +01001130 msg "test: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
1131 if_build_succeeded tests/ssl-opt.sh -f 'Default\|opaque'
Gilles Peskinec109b372020-11-23 17:39:04 +01001132}
1133
Manuel Pégourié-Gonnard1a3f9ed2020-05-19 12:38:31 +02001134component_test_ecp_no_internal_rng () {
1135 msg "build: Default plus ECP_NO_INTERNAL_RNG minus DRBG modules"
1136 scripts/config.py set MBEDTLS_ECP_NO_INTERNAL_RNG
1137 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1138 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1139 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1140 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C # requires a DRBG
1141 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA Crypto
1142
1143 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1144 make
1145
1146 msg "test: ECP_NO_INTERNAL_RNG, no DRBG module"
1147 make test
1148
1149 # no SSL tests as they all depend on having a DRBG
1150}
1151
Manuel Pégourié-Gonnard53fb66d2020-06-04 09:43:14 +02001152component_test_ecp_restartable_no_internal_rng () {
1153 msg "build: Default plus ECP_RESTARTABLE and ECP_NO_INTERNAL_RNG, no DRBG"
1154 scripts/config.py set MBEDTLS_ECP_NO_INTERNAL_RNG
1155 scripts/config.py set MBEDTLS_ECP_RESTARTABLE
1156 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1157 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1158 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1159 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C # requires CTR_DRBG
1160 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA Crypto
1161
1162 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1163 make
1164
1165 msg "test: ECP_RESTARTABLE and ECP_NO_INTERNAL_RNG, no DRBG module"
1166 make test
1167
1168 # no SSL tests as they all depend on having a DRBG
1169}
1170
Gilles Peskine636c26a2020-03-04 20:46:15 +01001171component_test_new_ecdh_context () {
1172 msg "build: new ECDH context (ASan build)" # ~ 6 min
1173 scripts/config.py unset MBEDTLS_ECDH_LEGACY_CONTEXT
1174 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1175 make
1176
1177 msg "test: new ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
1178 make test
1179
1180 msg "test: new ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
1181 if_build_succeeded tests/ssl-opt.sh -f ECDH
1182
1183 msg "test: new ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
1184 # Exclude some symmetric ciphers that are redundant here to gain time.
1185 if_build_succeeded tests/compat.sh -f ECDH -V NO -e 'ARCFOUR\|ARIA\|CAMELLIA\|CHACHA\|DES\|RC4'
1186}
1187
1188component_test_everest () {
1189 msg "build: Everest ECDH context (ASan build)" # ~ 6 min
1190 scripts/config.py unset MBEDTLS_ECDH_LEGACY_CONTEXT
1191 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
1192 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Asan .
1193 make
1194
1195 msg "test: Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
1196 make test
1197
1198 msg "test: Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
1199 if_build_succeeded tests/ssl-opt.sh -f ECDH
1200
1201 msg "test: Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
1202 # Exclude some symmetric ciphers that are redundant here to gain time.
1203 if_build_succeeded tests/compat.sh -f ECDH -V NO -e 'ARCFOUR\|ARIA\|CAMELLIA\|CHACHA\|DES\|RC4'
1204}
1205
Gilles Peskined3beca92020-07-03 00:15:37 +02001206component_test_everest_curve25519_only () {
1207 msg "build: Everest ECDH context, only Curve25519" # ~ 6 min
1208 scripts/config.py unset MBEDTLS_ECDH_LEGACY_CONTEXT
1209 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
1210 scripts/config.py unset MBEDTLS_ECDSA_C
1211 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
1212 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
1213 # Disable all curves
1214 for c in $(sed -n 's/#define \(MBEDTLS_ECP_DP_[0-9A-Z_a-z]*_ENABLED\).*/\1/p' <"$CONFIG_H"); do
1215 scripts/config.py unset "$c"
1216 done
1217 scripts/config.py set MBEDTLS_ECP_DP_CURVE25519_ENABLED
1218
1219 make CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
1220
1221 msg "test: Everest ECDH context, only Curve25519" # ~ 50s
1222 make test
1223}
1224
Gilles Peskine8f073122018-11-27 15:58:47 +01001225component_test_small_ssl_out_content_len () {
1226 msg "build: small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001227 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 16384
1228 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
Gilles Peskine8f073122018-11-27 15:58:47 +01001229 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1230 make
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +01001231
Gilles Peskine8f073122018-11-27 15:58:47 +01001232 msg "test: small SSL_OUT_CONTENT_LEN - ssl-opt.sh MFL and large packet tests"
1233 if_build_succeeded tests/ssl-opt.sh -f "Max fragment\|Large packet"
1234}
Angus Grattonc4dd0732018-04-11 16:28:39 +10001235
Gilles Peskine8f073122018-11-27 15:58:47 +01001236component_test_small_ssl_in_content_len () {
1237 msg "build: small SSL_IN_CONTENT_LEN (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001238 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 4096
1239 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 16384
Gilles Peskine8f073122018-11-27 15:58:47 +01001240 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1241 make
Angus Grattonc4dd0732018-04-11 16:28:39 +10001242
Gilles Peskine8f073122018-11-27 15:58:47 +01001243 msg "test: small SSL_IN_CONTENT_LEN - ssl-opt.sh MFL tests"
1244 if_build_succeeded tests/ssl-opt.sh -f "Max fragment"
1245}
Angus Grattonc4dd0732018-04-11 16:28:39 +10001246
Gilles Peskine8f073122018-11-27 15:58:47 +01001247component_test_small_ssl_dtls_max_buffering () {
1248 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001249 scripts/config.py set MBEDTLS_SSL_DTLS_MAX_BUFFERING 1000
Gilles Peskine8f073122018-11-27 15:58:47 +01001250 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1251 make
Angus Grattonc4dd0732018-04-11 16:28:39 +10001252
Gilles Peskine8f073122018-11-27 15:58:47 +01001253 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0 - ssl-opt.sh specific reordering test"
1254 if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer out-of-order hs msg before reassembling next, free buffered msg"
1255}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001256
Gilles Peskine8f073122018-11-27 15:58:47 +01001257component_test_small_mbedtls_ssl_dtls_max_buffering () {
1258 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1"
Gilles Peskine636c26a2020-03-04 20:46:15 +01001259 scripts/config.py set MBEDTLS_SSL_DTLS_MAX_BUFFERING 190
Gilles Peskine8f073122018-11-27 15:58:47 +01001260 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1261 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001262
Gilles Peskine8f073122018-11-27 15:58:47 +01001263 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1 - ssl-opt.sh specific reordering test"
1264 if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer encrypted Finished message, drop for fragmented NewSessionTicket"
1265}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001266
Gilles Peskine75cc7712019-09-06 19:47:17 +02001267component_test_psa_collect_statuses () {
1268 msg "build+test: psa_collect_statuses" # ~30s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001269 scripts/config.py full
Gilles Peskine75cc7712019-09-06 19:47:17 +02001270 record_status tests/scripts/psa_collect_statuses.py
1271 # Check that psa_crypto_init() succeeded at least once
1272 record_status grep -q '^0:psa_crypto_init:' tests/statuses.log
1273 rm -f tests/statuses.log
1274}
1275
Gilles Peskine8f073122018-11-27 15:58:47 +01001276component_test_full_cmake_clang () {
1277 msg "build: cmake, full config, clang" # ~ 50s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001278 scripts/config.py full
Gilles Peskine8f073122018-11-27 15:58:47 +01001279 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check -D ENABLE_TESTING=On .
1280 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001281
k-stachowiak0291cb72019-06-26 15:52:12 +02001282 msg "test: main suites (full config, clang)" # ~ 5s
Gilles Peskine8f073122018-11-27 15:58:47 +01001283 make test
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +01001284
k-stachowiak0291cb72019-06-26 15:52:12 +02001285 msg "test: psa_constant_names (full config, clang)" # ~ 1s
Darryl Green45010a32019-02-06 13:43:58 +00001286 record_status tests/scripts/test_psa_constant_names.py
Gilles Peskine69e8f7f2020-02-26 19:51:43 +01001287
Gilles Peskine8f073122018-11-27 15:58:47 +01001288 msg "test: ssl-opt.sh default, ECJPAKE, SSL async (full config)" # ~ 1s
1289 if_build_succeeded tests/ssl-opt.sh -f 'Default\|ECJPAKE\|SSL async private'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +02001290
Andres Amaya Garcia2dadab72019-01-08 21:42:27 +00001291 msg "test: compat.sh RC4, DES, 3DES & NULL (full config)" # ~ 2 min
Andres Amaya Garcia419bd002019-02-19 20:20:57 +00001292 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 +02001293
Gilles Peskine8f073122018-11-27 15:58:47 +01001294 msg "test: compat.sh ARIA + ChachaPoly"
1295 if_build_succeeded env OPENSSL_CMD="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
1296}
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +02001297
Manuel Pégourié-Gonnard6240def2020-07-10 09:35:54 +02001298component_test_memsan_constant_flow () {
Manuel Pégourié-Gonnard0b2112d2020-07-22 11:09:28 +02001299 # This tests both (1) accesses to undefined memory, and (2) branches or
1300 # memory access depending on secret values. To distinguish between those:
1301 # - unset MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN - does the failure persist?
1302 # - or alternatively, change the build type to MemSanDbg, which enables
1303 # origin tracking and nicer stack traces (which are useful for debugging
1304 # anyway), and check if the origin was TEST_CF_SECRET() or something else.
1305 msg "build: cmake MSan (clang), full config with constant flow testing"
Manuel Pégourié-Gonnard6240def2020-07-10 09:35:54 +02001306 scripts/config.py full
1307 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN
1308 scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm
1309 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
1310 make
1311
Manuel Pégourié-Gonnard0b2112d2020-07-22 11:09:28 +02001312 msg "test: main suites (Msan + constant flow)"
Manuel Pégourié-Gonnard6240def2020-07-10 09:35:54 +02001313 make test
1314}
1315
Manuel Pégourié-Gonnard73afa372020-08-19 10:27:38 +02001316component_test_valgrind_constant_flow () {
1317 # This tests both (1) everything that valgrind's memcheck usually checks
1318 # (heap buffer overflows, use of uninitialized memory, use-after-free,
1319 # etc.) and (2) branches or memory access depending on secret values,
1320 # which will be reported as uninitialized memory. To distinguish between
1321 # secret and actually uninitialized:
1322 # - unset MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND - does the failure persist?
1323 # - or alternatively, build with debug info and manually run the offending
1324 # test suite with valgrind --track-origins=yes, then check if the origin
1325 # was TEST_CF_SECRET() or something else.
1326 msg "build: cmake release GCC, full config with constant flow testing"
1327 scripts/config.py full
1328 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND
1329 cmake -D CMAKE_BUILD_TYPE:String=Release .
1330 make
1331
1332 # this only shows a summary of the results (how many of each type)
1333 # details are left in Testing/<date>/DynamicAnalysis.xml
1334 msg "test: main suites (valgrind + constant flow)"
1335 make memcheck
1336}
1337
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001338component_test_default_no_deprecated () {
Gilles Peskine8386ea22020-04-30 09:07:29 +02001339 # Test that removing the deprecated features from the default
1340 # configuration leaves something consistent.
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001341 msg "build: make, default + MBEDTLS_DEPRECATED_REMOVED" # ~ 30s
1342 scripts/config.py set MBEDTLS_DEPRECATED_REMOVED
1343 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra'
1344
1345 msg "test: make, default + MBEDTLS_DEPRECATED_REMOVED" # ~ 5s
1346 make test
1347}
1348
1349component_test_full_no_deprecated () {
Gilles Peskine30de2e82020-04-20 21:39:22 +02001350 msg "build: make, full_no_deprecated config" # ~ 30s
1351 scripts/config.py full_no_deprecated
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001352 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra'
1353
Gilles Peskine30de2e82020-04-20 21:39:22 +02001354 msg "test: make, full_no_deprecated config" # ~ 5s
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001355 make test
1356}
1357
Gilles Peskine8386ea22020-04-30 09:07:29 +02001358component_test_full_no_deprecated_deprecated_warning () {
1359 # Test that there is nothing deprecated in "full_no_deprecated".
1360 # A deprecated feature would trigger a warning (made fatal) from
1361 # MBEDTLS_DEPRECATED_WARNING.
Gilles Peskine30de2e82020-04-20 21:39:22 +02001362 msg "build: make, full_no_deprecated config, MBEDTLS_DEPRECATED_WARNING" # ~ 30s
1363 scripts/config.py full_no_deprecated
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001364 scripts/config.py unset MBEDTLS_DEPRECATED_REMOVED
1365 scripts/config.py set MBEDTLS_DEPRECATED_WARNING
1366 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra'
1367
Gilles Peskine30de2e82020-04-20 21:39:22 +02001368 msg "test: make, full_no_deprecated config, MBEDTLS_DEPRECATED_WARNING" # ~ 5s
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001369 make test
1370}
1371
Gilles Peskine8386ea22020-04-30 09:07:29 +02001372component_test_full_deprecated_warning () {
1373 # Test that when MBEDTLS_DEPRECATED_WARNING is enabled, the build passes
1374 # with only certain whitelisted types of warnings.
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001375 msg "build: make, full config + MBEDTLS_DEPRECATED_WARNING, expect warnings" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001376 scripts/config.py full
1377 scripts/config.py set MBEDTLS_DEPRECATED_WARNING
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001378 # Expect warnings from '#warning' directives in check_config.h.
1379 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-error=cpp' lib programs
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +01001380
Gilles Peskine8386ea22020-04-30 09:07:29 +02001381 msg "build: make tests, full config + MBEDTLS_DEPRECATED_WARNING, expect warnings" # ~ 30s
1382 # Set MBEDTLS_TEST_DEPRECATED to enable tests for deprecated features.
1383 # By default those are disabled when MBEDTLS_DEPRECATED_WARNING is set.
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001384 # Expect warnings from '#warning' directives in check_config.h and
1385 # from the use of deprecated functions in test suites.
1386 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-error=deprecated-declarations -Wno-error=cpp -DMBEDTLS_TEST_DEPRECATED' tests
Gilles Peskine841b14b2019-11-26 17:37:37 +01001387
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001388 msg "test: full config + MBEDTLS_TEST_DEPRECATED" # ~ 30s
1389 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01001390}
Jaeden Ameroed93bdc2018-11-02 16:57:24 +00001391
Gilles Peskineec541fe2020-01-31 14:24:14 +01001392# Check that the specified libraries exist and are empty.
1393are_empty_libraries () {
1394 nm "$@" >/dev/null 2>/dev/null
1395 ! nm "$@" 2>/dev/null | grep -v ':$' | grep .
1396}
1397
1398component_build_crypto_default () {
1399 msg "build: make, crypto only"
1400 scripts/config.py crypto
Gilles Peskine6bb39152020-02-03 11:59:20 +01001401 make CFLAGS='-O1 -Werror'
Gilles Peskineec541fe2020-01-31 14:24:14 +01001402 if_build_succeeded are_empty_libraries library/libmbedx509.* library/libmbedtls.*
1403}
1404
1405component_build_crypto_full () {
1406 msg "build: make, crypto only, full config"
1407 scripts/config.py crypto_full
Gilles Peskine6bb39152020-02-03 11:59:20 +01001408 make CFLAGS='-O1 -Werror'
Gilles Peskineec541fe2020-01-31 14:24:14 +01001409 if_build_succeeded are_empty_libraries library/libmbedx509.* library/libmbedtls.*
1410}
1411
1412component_build_crypto_baremetal () {
1413 msg "build: make, crypto only, baremetal config"
1414 scripts/config.py crypto_baremetal
Gilles Peskine6bb39152020-02-03 11:59:20 +01001415 make CFLAGS='-O1 -Werror'
Gilles Peskineec541fe2020-01-31 14:24:14 +01001416 if_build_succeeded are_empty_libraries library/libmbedx509.* library/libmbedtls.*
1417}
1418
Gilles Peskine8f073122018-11-27 15:58:47 +01001419component_test_depends_curves () {
1420 msg "test/build: curves.pl (gcc)" # ~ 4 min
Gilles Peskine8f073122018-11-27 15:58:47 +01001421 record_status tests/scripts/curves.pl
1422}
Jaeden Ameroacaabe72018-11-07 11:52:52 +00001423
John Durkopc14be902020-08-20 06:16:41 -07001424component_test_depends_curves_psa () {
1425 msg "test/build: curves.pl with MBEDTLS_USE_PSA_CRYPTO defined (gcc)"
1426 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1427 record_status tests/scripts/curves.pl
1428}
1429
Gilles Peskine8f073122018-11-27 15:58:47 +01001430component_test_depends_hashes () {
1431 msg "test/build: depends-hashes.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +01001432 record_status tests/scripts/depends-hashes.pl
1433}
Jaeden Ameroacaabe72018-11-07 11:52:52 +00001434
John Durkop2ec2eaa2020-08-24 18:29:15 -07001435component_test_depends_hashes_psa () {
1436 msg "test/build: depends-hashes.pl with MBEDTLS_USE_PSA_CRYPTO defined (gcc)"
1437 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1438 record_status tests/scripts/depends-hashes.pl
1439}
1440
Gilles Peskine8f073122018-11-27 15:58:47 +01001441component_test_depends_pkalgs () {
1442 msg "test/build: depends-pkalgs.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +01001443 record_status tests/scripts/depends-pkalgs.pl
1444}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01001445
John Durkop619e09e2020-09-08 22:19:56 -07001446component_test_depends_pkalgs_psa () {
1447 msg "test/build: depends-pkalgs.pl with MBEDTLS_USE_PSA_CRYPTO defined (gcc)"
1448 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01001449 record_status tests/scripts/depends-pkalgs.pl
1450}
1451
Gilles Peskine8f073122018-11-27 15:58:47 +01001452component_build_key_exchanges () {
1453 msg "test/build: key-exchanges (gcc)" # ~ 1 min
Gilles Peskine8f073122018-11-27 15:58:47 +01001454 record_status tests/scripts/key-exchanges.pl
1455}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01001456
Gilles Peskine8f073122018-11-27 15:58:47 +01001457component_build_default_make_gcc_and_cxx () {
1458 msg "build: Unix make, -Os (gcc)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +01001459 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01001460
Gilles Peskine8f073122018-11-27 15:58:47 +01001461 msg "test: verify header list in cpp_dummy_build.cpp"
1462 record_status check_headers_in_cpp
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01001463
Gilles Peskine8f073122018-11-27 15:58:47 +01001464 msg "build: Unix make, incremental g++"
1465 make TEST_CPP=1
1466}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01001467
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001468component_test_no_use_psa_crypto_full_cmake_asan() {
1469 # full minus MBEDTLS_USE_PSA_CRYPTO: run the same set of tests as basic-build-test.sh
Gilles Peskinedc3a1792019-09-03 11:42:04 +02001470 msg "build: cmake, full config minus MBEDTLS_USE_PSA_CRYPTO, ASan"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001471 scripts/config.py full
1472 scripts/config.py set MBEDTLS_ECP_RESTARTABLE # not using PSA, so enable restartable ECC
1473 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C
1474 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1475 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C
Gilles Peskinedc6d8382020-04-12 14:21:55 +02001476 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001477 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
Manuel Pégourié-Gonnardd8167e82019-02-01 11:12:52 +01001478 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Andrzej Kurekde5a0072019-02-01 07:03:03 -05001479 make
Manuel Pégourié-Gonnard43be6cd2017-06-20 09:53:42 +02001480
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001481 msg "test: main suites (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -05001482 make test
Manuel Pégourié-Gonnard503a5ef2015-10-23 09:04:45 +02001483
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001484 msg "test: ssl-opt.sh (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -05001485 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001486
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001487 msg "test: compat.sh default (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -05001488 if_build_succeeded tests/compat.sh
Andrzej Kurek991f9fe2018-07-02 09:08:21 -04001489
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001490 msg "test: compat.sh RC4, DES & NULL (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -05001491 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 -05001492
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001493 msg "test: compat.sh ARIA + ChachaPoly (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -05001494 if_build_succeeded env OPENSSL_CMD="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
1495}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -05001496
John Durkopd8959392020-09-20 23:09:17 -07001497component_test_psa_crypto_config_basic() {
Ronald Cron067de3b2021-03-11 11:49:03 +01001498 # Test the library excluding all Mbed TLS cryptographic support for which
1499 # we have an accelerator support. Acceleration is faked with the
1500 # transparent test driver.
1501 msg "test: full + MBEDTLS_PSA_CRYPTO_CONFIG + as much acceleration as supported"
John Durkopd8959392020-09-20 23:09:17 -07001502 scripts/config.py full
1503 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1504 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1505 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cron067de3b2021-03-11 11:49:03 +01001506
1507 # There is no intended accelerator support for ALG STREAM_CIPHER and
1508 # ALG_ECB_NO_PADDING. Therefore, asking for them in the build implies the
1509 # inclusion of the Mbed TLS cipher operations. As we want to test here with
1510 # cipher operations solely supported by accelerators, disabled those
1511 # PSA configuration options.
1512 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_STREAM_CIPHER
1513 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_ECB_NO_PADDING
1514
1515 # Don't test DES encryption as:
1516 # 1) It is not an issue if we don't test all cipher types here.
1517 # 2) That way we don't have to modify in psa_crypto.c the compilation
1518 # guards MBEDTLS_PSA_BUILTIN_KEY_TYPE_DES for the code they guard to be
1519 # available to the test driver. Modifications that we would need to
1520 # revert when we move to compile the test driver separately.
1521 # We also disable MBEDTLS_DES_C as the dependencies on DES in PSA test
1522 # suites are still based on MBEDTLS_DES_C and not PSA_WANT_KEY_TYPE_DES.
1523 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_KEY_TYPE_DES
1524 scripts/config.py unset MBEDTLS_DES_C
1525
Gilles Peskinefe0acc62021-09-20 19:20:04 +02001526 loc_cflags="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST_ALL"
1527 loc_cflags="${loc_cflags} '-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/user-config-for-test.h\"'"
Ronald Cron17b3afc2020-12-10 18:17:09 +01001528 loc_cflags="${loc_cflags} -I../tests/include -O2"
1529
1530 make CC=gcc CFLAGS="$loc_cflags" LDFLAGS="$ASAN_CFLAGS"
1531 unset loc_cflags
John Durkopd8959392020-09-20 23:09:17 -07001532
John Durkop4377bf72020-10-23 01:26:57 -07001533 msg "test: full + MBEDTLS_PSA_CRYPTO_CONFIG"
1534 make test
1535}
1536
1537component_test_psa_crypto_config_no_driver() {
1538 # full plus MBEDTLS_PSA_CRYPTO_CONFIG
1539 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG minus MBEDTLS_PSA_CRYPTO_DRIVERS"
1540 scripts/config.py full
1541 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1542 scripts/config.py unset MBEDTLS_PSA_CRYPTO_DRIVERS
1543 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
John Durkope7012c72020-10-26 09:55:01 -07001544 make CC=gcc CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
John Durkop4377bf72020-10-23 01:26:57 -07001545
1546 msg "test: full + MBEDTLS_PSA_CRYPTO_CONFIG minus MBEDTLS_PSA_CRYPTO_DRIVERS"
John Durkopd8959392020-09-20 23:09:17 -07001547 make test
1548}
1549
Przemyslaw Stekiel7ce979a2021-10-13 11:09:44 +02001550component_test_psa_crypto_config_chachapoly_disabled() {
1551 # full minus MBEDTLS_CHACHAPOLY_C without PSA_WANT_ALG_GCM and PSA_WANT_ALG_CHACHA20_POLY1305
1552 msg "build: full minus MBEDTLS_CHACHAPOLY_C without PSA_WANT_ALG_GCM and PSA_WANT_ALG_CHACHA20_POLY1305"
1553 scripts/config.py full
1554 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
1555 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_GCM
1556 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_CHACHA20_POLY1305
1557 make CC=gcc CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
1558
1559 msg "test: full minus MBEDTLS_CHACHAPOLY_C without PSA_WANT_ALG_GCM and PSA_WANT_ALG_CHACHA20_POLY1305"
1560 make test
1561}
1562
John Durkop8ac0b802020-10-23 01:32:15 -07001563# This should be renamed to test and updated once the accelerator ECDSA code is in place and ready to test.
John Durkop6ba40d12020-11-10 08:50:04 -08001564component_build_psa_accel_alg_ecdsa() {
John Durkopdd544e12020-10-12 21:47:19 -07001565 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_ECDSA
1566 # without MBEDTLS_ECDSA_C
John Durkop28baa1f2020-10-23 00:51:52 -07001567 # PSA_WANT_ALG_ECDSA and PSA_WANT_ALG_DETERMINISTIC_ECDSA are already
1568 # set in include/psa/crypto_config.h
John Durkopdd544e12020-10-12 21:47:19 -07001569 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_ECDSA without MBEDTLS_ECDSA_C"
John Durkopd8959392020-09-20 23:09:17 -07001570 scripts/config.py full
1571 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1572 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1573 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1574 scripts/config.py unset MBEDTLS_ECDSA_C
John Durkop28baa1f2020-10-23 00:51:52 -07001575 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
1576 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
John Durkopd8959392020-09-20 23:09:17 -07001577 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
John Durkop28baa1f2020-10-23 00:51:52 -07001578 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_ECDSA -DMBEDTLS_PSA_ACCEL_ALG_DETERMINISTIC_ECDSA -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
John Durkopd8959392020-09-20 23:09:17 -07001579}
1580
John Durkopd0321952020-10-29 21:37:36 -07001581# This should be renamed to test and updated once the accelerator ECDH code is in place and ready to test.
John Durkop6ba40d12020-11-10 08:50:04 -08001582component_build_psa_accel_alg_ecdh() {
John Durkopd0321952020-10-29 21:37:36 -07001583 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_ECDH
1584 # without MBEDTLS_ECDH_C
1585 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_ECDH without MBEDTLS_ECDH_C"
1586 scripts/config.py full
1587 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1588 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1589 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1590 scripts/config.py unset MBEDTLS_ECDH_C
1591 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
1592 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
1593 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
1594 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
1595 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
1596 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1597 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_ECDH -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
1598}
1599
John Durkopf4c4cb02020-10-28 20:09:55 -07001600# This should be renamed to test and updated once the accelerator ECC key pair code is in place and ready to test.
John Durkop6ba40d12020-11-10 08:50:04 -08001601component_build_psa_accel_key_type_ecc_key_pair() {
John Durkop9814fa22020-11-04 12:28:15 -08001602 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_KEY_TYPE_ECC_KEY_PAIR
1603 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_KEY_TYPE_ECC_KEY_PAIR"
John Durkopf4c4cb02020-10-28 20:09:55 -07001604 scripts/config.py full
1605 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1606 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1607 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
John Durkop9814fa22020-11-04 12:28:15 -08001608 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_KEY_TYPE_ECC_KEY_PAIR 1
John Durkop07cc04a2020-11-16 22:08:34 -08001609 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY 1
John Durkopf4c4cb02020-10-28 20:09:55 -07001610 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
John Durkop9814fa22020-11-04 12:28:15 -08001611 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_KEY_PAIR -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
John Durkopf4c4cb02020-10-28 20:09:55 -07001612}
1613
1614# This should be renamed to test and updated once the accelerator ECC public key code is in place and ready to test.
John Durkop6ba40d12020-11-10 08:50:04 -08001615component_build_psa_accel_key_type_ecc_public_key() {
John Durkop9814fa22020-11-04 12:28:15 -08001616 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY
1617 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY"
John Durkopf4c4cb02020-10-28 20:09:55 -07001618 scripts/config.py full
1619 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1620 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1621 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
John Durkop9814fa22020-11-04 12:28:15 -08001622 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY 1
1623 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR
John Durkopf4c4cb02020-10-28 20:09:55 -07001624 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
John Durkop9814fa22020-11-04 12:28:15 -08001625 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_PUBLIC_KEY -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
John Durkopf4c4cb02020-10-28 20:09:55 -07001626}
1627
John Durkopd0321952020-10-29 21:37:36 -07001628# This should be renamed to test and updated once the accelerator HMAC code is in place and ready to test.
John Durkop6ba40d12020-11-10 08:50:04 -08001629component_build_psa_accel_alg_hmac() {
John Durkopd0321952020-10-29 21:37:36 -07001630 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_HMAC
1631 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_HMAC"
1632 scripts/config.py full
1633 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1634 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1635 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1636 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1637 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_HMAC -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
1638}
1639
1640# This should be renamed to test and updated once the accelerator HKDF code is in place and ready to test.
John Durkop6ba40d12020-11-10 08:50:04 -08001641component_build_psa_accel_alg_hkdf() {
John Durkopd0321952020-10-29 21:37:36 -07001642 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_HKDF
1643 # without MBEDTLS_HKDF_C
1644 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_HKDF without MBEDTLS_HKDF_C"
1645 scripts/config.py full
1646 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1647 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1648 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1649 scripts/config.py unset MBEDTLS_HKDF_C
John Durkopbd069d32020-10-31 22:14:03 -07001650 # Make sure to unset TLS1_3_EXPERIMENTAL since it requires HKDF_C and will not build properly without it.
1651 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL
John Durkopd0321952020-10-29 21:37:36 -07001652 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1653 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_HKDF -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
1654}
1655
John Durkop1b7ee052020-11-27 08:51:22 -08001656# This should be renamed to test and updated once the accelerator MD2 code is in place and ready to test.
1657component_build_psa_accel_alg_md2() {
1658 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_MD2 without other hashes
1659 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_MD2 - other hashes"
1660 scripts/config.py full
1661 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1662 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1663 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1664 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
1665 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
1666 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
1667 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
1668 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
1669 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
1670 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
1671 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
1672 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1673 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_MD2 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
1674}
1675
1676# This should be renamed to test and updated once the accelerator MD4 code is in place and ready to test.
1677component_build_psa_accel_alg_md4() {
1678 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_MD4 without other hashes
1679 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_MD4 - other hashes"
1680 scripts/config.py full
1681 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1682 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1683 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1684 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
1685 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
1686 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
1687 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
1688 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
1689 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
1690 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
1691 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
1692 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1693 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_MD4 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
1694}
1695
1696# This should be renamed to test and updated once the accelerator MD5 code is in place and ready to test.
1697component_build_psa_accel_alg_md5() {
1698 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_MD5 without other hashes
1699 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_MD5 - other hashes"
1700 scripts/config.py full
1701 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1702 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1703 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1704 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
1705 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
1706 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
1707 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
1708 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
1709 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
1710 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
1711 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
1712 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1713 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_MD5 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
1714}
1715
1716# This should be renamed to test and updated once the accelerator RIPEMD160 code is in place and ready to test.
1717component_build_psa_accel_alg_ripemd160() {
1718 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_RIPEMD160 without other hashes
1719 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_RIPEMD160 - other hashes"
1720 scripts/config.py full
1721 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1722 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1723 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1724 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
1725 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
1726 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
1727 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
1728 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
1729 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
1730 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
1731 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
1732 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1733 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RIPEMD160 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
1734}
1735
1736# This should be renamed to test and updated once the accelerator SHA1 code is in place and ready to test.
1737component_build_psa_accel_alg_sha1() {
1738 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_SHA_1 without other hashes
1739 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_SHA_1 - other hashes"
1740 scripts/config.py full
1741 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1742 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1743 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1744 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
1745 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
1746 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
1747 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
1748 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
1749 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
1750 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
1751 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
1752 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1753 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_1 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
1754}
1755
1756# This should be renamed to test and updated once the accelerator SHA224 code is in place and ready to test.
1757component_build_psa_accel_alg_sha224() {
1758 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_SHA_224 without other hashes
1759 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_SHA_224 - other hashes"
1760 scripts/config.py full
1761 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1762 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1763 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1764 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
1765 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
1766 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
1767 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
1768 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
1769 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
1770 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
1771 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1772 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_224 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
1773}
1774
1775# This should be renamed to test and updated once the accelerator SHA256 code is in place and ready to test.
1776component_build_psa_accel_alg_sha256() {
1777 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_SHA_256 without other hashes
1778 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_SHA_256 - other hashes"
1779 scripts/config.py full
1780 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1781 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1782 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1783 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
1784 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
1785 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
1786 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
1787 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
1788 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
1789 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
1790 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
1791 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1792 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_256 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
1793}
1794
1795# This should be renamed to test and updated once the accelerator SHA384 code is in place and ready to test.
1796component_build_psa_accel_alg_sha384() {
1797 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_SHA_384 without other hashes
1798 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_SHA_384 - other hashes"
1799 scripts/config.py full
1800 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1801 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1802 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1803 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
1804 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
1805 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
1806 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
1807 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
1808 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
1809 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
1810 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1811 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_384 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
1812}
1813
1814# This should be renamed to test and updated once the accelerator SHA512 code is in place and ready to test.
1815component_build_psa_accel_alg_sha512() {
1816 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_SHA_512 without other hashes
1817 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_SHA_512 - other hashes"
1818 scripts/config.py full
1819 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1820 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1821 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1822 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
1823 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
1824 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
1825 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
1826 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
1827 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
1828 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
1829 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
1830 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1831 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_512 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
1832}
1833
John Durkopd0321952020-10-29 21:37:36 -07001834# This should be renamed to test and updated once the accelerator RSA code is in place and ready to test.
John Durkop6ba40d12020-11-10 08:50:04 -08001835component_build_psa_accel_alg_rsa_pkcs1v15_crypt() {
John Durkopbd069d32020-10-31 22:14:03 -07001836 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
1837 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_RSA_PKCS1V15_CRYPT + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY"
John Durkopd0321952020-10-29 21:37:36 -07001838 scripts/config.py full
1839 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1840 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1841 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
John Durkopbd069d32020-10-31 22:14:03 -07001842 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_PKCS1V15_CRYPT 1
John Durkop7fc75ea2020-11-03 19:05:36 -08001843 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN
1844 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_OAEP
1845 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PSS
John Durkopd0321952020-10-29 21:37:36 -07001846 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
John Durkopbd069d32020-10-31 22:14:03 -07001847 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_CRYPT -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
1848}
1849
1850# This should be renamed to test and updated once the accelerator RSA code is in place and ready to test.
John Durkop6ba40d12020-11-10 08:50:04 -08001851component_build_psa_accel_alg_rsa_pkcs1v15_sign() {
John Durkopbd069d32020-10-31 22:14:03 -07001852 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_RSA_PKCS1V15_SIGN and PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY
1853 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_RSA_PKCS1V15_SIGN + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY"
1854 scripts/config.py full
1855 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1856 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1857 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1858 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_PKCS1V15_SIGN 1
John Durkop7fc75ea2020-11-03 19:05:36 -08001859 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
1860 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_OAEP
1861 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PSS
John Durkopbd069d32020-10-31 22:14:03 -07001862 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1863 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_SIGN -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
1864}
1865
1866# This should be renamed to test and updated once the accelerator RSA code is in place and ready to test.
John Durkop6ba40d12020-11-10 08:50:04 -08001867component_build_psa_accel_alg_rsa_oaep() {
John Durkopbd069d32020-10-31 22:14:03 -07001868 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_RSA_OAEP and PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY
1869 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_RSA_OAEP + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY"
1870 scripts/config.py full
1871 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1872 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1873 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1874 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_OAEP 1
John Durkop7fc75ea2020-11-03 19:05:36 -08001875 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
1876 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN
1877 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PSS
John Durkopbd069d32020-10-31 22:14:03 -07001878 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1879 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_OAEP -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
1880}
1881
1882# This should be renamed to test and updated once the accelerator RSA code is in place and ready to test.
John Durkop6ba40d12020-11-10 08:50:04 -08001883component_build_psa_accel_alg_rsa_pss() {
John Durkopbd069d32020-10-31 22:14:03 -07001884 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_RSA_PSS and PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY
1885 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_RSA_PSS + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY"
1886 scripts/config.py full
1887 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1888 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1889 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1890 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_PSS 1
John Durkop7fc75ea2020-11-03 19:05:36 -08001891 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
1892 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN
1893 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_OAEP
John Durkopbd069d32020-10-31 22:14:03 -07001894 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1895 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_PSS -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
1896}
1897
1898# This should be renamed to test and updated once the accelerator RSA code is in place and ready to test.
John Durkop6ba40d12020-11-10 08:50:04 -08001899component_build_psa_accel_key_type_rsa_key_pair() {
John Durkopbd069d32020-10-31 22:14:03 -07001900 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_KEY_TYPE_RSA_KEY_PAIR and PSA_WANT_ALG_RSA_PSS
1901 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_KEY_TYPE_RSA_KEY_PAIR + PSA_WANT_ALG_RSA_PSS"
1902 scripts/config.py full
1903 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1904 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1905 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1906 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_PSS 1
1907 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_KEY_TYPE_RSA_KEY_PAIR 1
1908 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1909 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_KEY_PAIR -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
1910}
1911
1912# This should be renamed to test and updated once the accelerator RSA code is in place and ready to test.
John Durkop6ba40d12020-11-10 08:50:04 -08001913component_build_psa_accel_key_type_rsa_public_key() {
John Durkopbd069d32020-10-31 22:14:03 -07001914 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY and PSA_WANT_ALG_RSA_PSS
1915 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY + PSA_WANT_ALG_RSA_PSS"
1916 scripts/config.py full
1917 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1918 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1919 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1920 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_PSS 1
1921 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY 1
1922 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1923 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_PUBLIC_KEY -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
John Durkopd0321952020-10-29 21:37:36 -07001924}
1925
Gilles Peskineadcde5e2019-06-12 16:05:50 +02001926component_test_check_params_functionality () {
1927 msg "build+test: MBEDTLS_CHECK_PARAMS functionality"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001928 scripts/config.py full # includes CHECK_PARAMS
Gilles Peskineadcde5e2019-06-12 16:05:50 +02001929 # Make MBEDTLS_PARAM_FAILED call mbedtls_param_failed().
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001930 scripts/config.py unset MBEDTLS_CHECK_PARAMS_ASSERT
Ronald Crona1236142020-07-01 16:01:21 +02001931 make CC=gcc CFLAGS='-Werror -O1' all test
Gilles Peskineadcde5e2019-06-12 16:05:50 +02001932}
1933
Gilles Peskineb28636b2019-01-02 19:06:24 +01001934component_test_check_params_without_platform () {
1935 msg "build+test: MBEDTLS_CHECK_PARAMS without MBEDTLS_PLATFORM_C"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001936 scripts/config.py full # includes CHECK_PARAMS
Gilles Peskineadcde5e2019-06-12 16:05:50 +02001937 # Keep MBEDTLS_PARAM_FAILED as assert.
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001938 scripts/config.py unset MBEDTLS_PLATFORM_EXIT_ALT
1939 scripts/config.py unset MBEDTLS_PLATFORM_TIME_ALT
1940 scripts/config.py unset MBEDTLS_PLATFORM_FPRINTF_ALT
1941 scripts/config.py unset MBEDTLS_PLATFORM_MEMORY
Gilles Peskine32e889d2020-04-12 23:43:28 +02001942 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001943 scripts/config.py unset MBEDTLS_PLATFORM_PRINTF_ALT
1944 scripts/config.py unset MBEDTLS_PLATFORM_SNPRINTF_ALT
1945 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
1946 scripts/config.py unset MBEDTLS_PLATFORM_C
Gilles Peskineb28636b2019-01-02 19:06:24 +01001947 make CC=gcc CFLAGS='-Werror -O1' all test
1948}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -05001949
Gilles Peskineb28636b2019-01-02 19:06:24 +01001950component_test_check_params_silent () {
1951 msg "build+test: MBEDTLS_CHECK_PARAMS with alternative MBEDTLS_PARAM_FAILED()"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001952 scripts/config.py full # includes CHECK_PARAMS
Gilles Peskineadcde5e2019-06-12 16:05:50 +02001953 # Set MBEDTLS_PARAM_FAILED to nothing.
Gilles Peskineb28636b2019-01-02 19:06:24 +01001954 sed -i 's/.*\(#define MBEDTLS_PARAM_FAILED( cond )\).*/\1/' "$CONFIG_H"
1955 make CC=gcc CFLAGS='-Werror -O1' all test
1956}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -05001957
Gilles Peskine8f073122018-11-27 15:58:47 +01001958component_test_no_platform () {
1959 # Full configuration build, without platform support, file IO and net sockets.
1960 # This should catch missing mbedtls_printf definitions, and by disabling file
1961 # IO, it should catch missing '#include <stdio.h>'
1962 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001963 scripts/config.py full
1964 scripts/config.py unset MBEDTLS_PLATFORM_C
1965 scripts/config.py unset MBEDTLS_NET_C
1966 scripts/config.py unset MBEDTLS_PLATFORM_MEMORY
1967 scripts/config.py unset MBEDTLS_PLATFORM_PRINTF_ALT
1968 scripts/config.py unset MBEDTLS_PLATFORM_FPRINTF_ALT
1969 scripts/config.py unset MBEDTLS_PLATFORM_SNPRINTF_ALT
1970 scripts/config.py unset MBEDTLS_PLATFORM_TIME_ALT
1971 scripts/config.py unset MBEDTLS_PLATFORM_EXIT_ALT
Gilles Peskine32e889d2020-04-12 23:43:28 +02001972 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001973 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
1974 scripts/config.py unset MBEDTLS_FS_IO
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001975 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001976 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
1977 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C
Gilles Peskine8f073122018-11-27 15:58:47 +01001978 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
1979 # to re-enable platform integration features otherwise disabled in C99 builds
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02001980 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -Os -D_DEFAULT_SOURCE' lib programs
1981 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os' test
Gilles Peskine8f073122018-11-27 15:58:47 +01001982}
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +00001983
Gilles Peskine8f073122018-11-27 15:58:47 +01001984component_build_no_std_function () {
1985 # catch compile bugs in _uninit functions
1986 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001987 scripts/config.py full
1988 scripts/config.py set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
1989 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskine32e889d2020-04-12 23:43:28 +02001990 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02001991 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Gilles Peskine8f073122018-11-27 15:58:47 +01001992}
Manuel Pégourié-Gonnarddccb80b2015-06-03 10:20:33 +01001993
Gilles Peskine8f073122018-11-27 15:58:47 +01001994component_build_no_ssl_srv () {
1995 msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001996 scripts/config.py full
1997 scripts/config.py unset MBEDTLS_SSL_SRV_C
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02001998 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
Gilles Peskine8f073122018-11-27 15:58:47 +01001999}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +02002000
Gilles Peskine8f073122018-11-27 15:58:47 +01002001component_build_no_ssl_cli () {
2002 msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002003 scripts/config.py full
2004 scripts/config.py unset MBEDTLS_SSL_CLI_C
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02002005 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
Gilles Peskine8f073122018-11-27 15:58:47 +01002006}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +02002007
Gilles Peskine8f073122018-11-27 15:58:47 +01002008component_build_no_sockets () {
2009 # Note, C99 compliance can also be tested with the sockets support disabled,
2010 # as that requires a POSIX platform (which isn't the same as C99).
2011 msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002012 scripts/config.py full
2013 scripts/config.py unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
2014 scripts/config.py set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02002015 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1 -std=c99 -pedantic' lib
Gilles Peskine8f073122018-11-27 15:58:47 +01002016}
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +02002017
Andrzej Kurek69f20aa2019-09-05 09:27:47 -04002018component_test_memory_buffer_allocator_backtrace () {
2019 msg "build: default config with memory buffer allocator and backtrace enabled"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002020 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
2021 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
2022 scripts/config.py set MBEDTLS_MEMORY_BACKTRACE
2023 scripts/config.py set MBEDTLS_MEMORY_DEBUG
Andrzej Kurek69f20aa2019-09-05 09:27:47 -04002024 CC=gcc cmake .
2025 make
2026
2027 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C and MBEDTLS_MEMORY_BACKTRACE"
2028 make test
2029}
2030
2031component_test_memory_buffer_allocator () {
2032 msg "build: default config with memory buffer allocator"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002033 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
2034 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
Hanno Becker0fb9ba22019-02-26 14:34:13 +00002035 CC=gcc cmake .
2036 make
2037
2038 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C"
2039 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +01002040
2041 msg "test: ssl-opt.sh, MBEDTLS_MEMORY_BUFFER_ALLOC_C"
2042 # MBEDTLS_MEMORY_BUFFER_ALLOC is slow. Skip tests that tend to time out.
2043 if_build_succeeded tests/ssl-opt.sh -e '^DTLS proxy'
Hanno Becker0fb9ba22019-02-26 14:34:13 +00002044}
2045
Gilles Peskine8f073122018-11-27 15:58:47 +01002046component_test_no_max_fragment_length () {
2047 # Run max fragment length tests with MFL disabled
2048 msg "build: default config except MFL extension (ASan build)" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002049 scripts/config.py unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
Gilles Peskine8f073122018-11-27 15:58:47 +01002050 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2051 make
Hanno Becker5175ac62017-09-18 15:36:25 +01002052
Gilles Peskine8f073122018-11-27 15:58:47 +01002053 msg "test: ssl-opt.sh, MFL-related tests"
2054 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length"
2055}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00002056
Hanno Becker545ced42019-02-19 11:10:48 +00002057component_test_asan_remove_peer_certificate () {
2058 msg "build: default config with MBEDTLS_SSL_KEEP_PEER_CERTIFICATE disabled (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002059 scripts/config.py unset MBEDTLS_SSL_KEEP_PEER_CERTIFICATE
Hanno Becker545ced42019-02-19 11:10:48 +00002060 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2061 make
2062
2063 msg "test: !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
2064 make test
2065
2066 msg "test: ssl-opt.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
2067 if_build_succeeded tests/ssl-opt.sh
2068
2069 msg "test: compat.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
2070 if_build_succeeded tests/compat.sh
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02002071
2072 msg "test: context-info.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
2073 if_build_succeeded tests/context-info.sh
Hanno Becker545ced42019-02-19 11:10:48 +00002074}
2075
Gilles Peskine8f073122018-11-27 15:58:47 +01002076component_test_no_max_fragment_length_small_ssl_out_content_len () {
2077 msg "build: no MFL extension, small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002078 scripts/config.py unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
2079 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 16384
2080 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
Gilles Peskine8f073122018-11-27 15:58:47 +01002081 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2082 make
Angus Grattonc4dd0732018-04-11 16:28:39 +10002083
Gilles Peskine8f073122018-11-27 15:58:47 +01002084 msg "test: MFL tests (disabled MFL extension case) & large packet tests"
2085 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length\|Large buffer"
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02002086
2087 msg "test: context-info.sh (disabled MFL extension case)"
2088 if_build_succeeded tests/context-info.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01002089}
Angus Grattonc4dd0732018-04-11 16:28:39 +10002090
Darryl Greenaad82f92019-12-02 10:53:11 +00002091component_test_variable_ssl_in_out_buffer_len () {
2092 msg "build: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled (ASan build)"
2093 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
2094 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2095 make
2096
2097 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
2098 make test
2099
2100 msg "test: ssl-opt.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
2101 if_build_succeeded tests/ssl-opt.sh
2102
2103 msg "test: compat.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
2104 if_build_succeeded tests/compat.sh
2105}
2106
2107component_test_variable_ssl_in_out_buffer_len_CID () {
2108 msg "build: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_DTLS_CONNECTION_ID enabled (ASan build)"
2109 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
2110 scripts/config.py set MBEDTLS_SSL_DTLS_CONNECTION_ID
2111
2112 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2113 make
2114
2115 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_DTLS_CONNECTION_ID"
2116 make test
2117
2118 msg "test: ssl-opt.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_DTLS_CONNECTION_ID enabled"
2119 if_build_succeeded tests/ssl-opt.sh
2120
2121 msg "test: compat.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_DTLS_CONNECTION_ID enabled"
2122 if_build_succeeded tests/compat.sh
2123}
2124
2125component_test_variable_ssl_in_out_buffer_len_record_splitting () {
2126 msg "build: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_CBC_RECORD_SPLITTING enabled (ASan build)"
2127 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
2128 scripts/config.py set MBEDTLS_SSL_CBC_RECORD_SPLITTING
2129
2130 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2131 make
2132
2133 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_CBC_RECORD_SPLITTING"
2134 make test
2135
2136 msg "test: ssl-opt.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_CBC_RECORD_SPLITTING enabled"
2137 if_build_succeeded tests/ssl-opt.sh
2138
2139 msg "test: compat.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_CBC_RECORD_SPLITTING enabled"
2140 if_build_succeeded tests/compat.sh
2141}
2142
Piotr Nowicki0937ed22019-11-26 16:32:40 +01002143component_test_ssl_alloc_buffer_and_mfl () {
2144 msg "build: default config with memory buffer allocator and MFL extension"
2145 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
2146 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
2147 scripts/config.py set MBEDTLS_MEMORY_DEBUG
2148 scripts/config.py set MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
2149 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
2150 CC=gcc cmake .
2151 make
2152
2153 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH, MBEDTLS_MEMORY_BUFFER_ALLOC_C, MBEDTLS_MEMORY_DEBUG and MBEDTLS_SSL_MAX_FRAGMENT_LENGTH"
2154 make test
2155
2156 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH, MBEDTLS_MEMORY_BUFFER_ALLOC_C, MBEDTLS_MEMORY_DEBUG and MBEDTLS_SSL_MAX_FRAGMENT_LENGTH"
2157 if_build_succeeded tests/ssl-opt.sh -f "Handshake memory usage"
2158}
2159
Gilles Peskine636c26a2020-03-04 20:46:15 +01002160component_test_when_no_ciphersuites_have_mac () {
2161 msg "build: when no ciphersuites have MAC"
2162 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
2163 scripts/config.py unset MBEDTLS_ARC4_C
2164 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
2165 make
2166
2167 msg "test: !MBEDTLS_SSL_SOME_MODES_USE_MAC"
2168 make test
2169
2170 msg "test ssl-opt.sh: !MBEDTLS_SSL_SOME_MODES_USE_MAC"
2171 if_build_succeeded tests/ssl-opt.sh -f 'Default\|EtM' -e 'without EtM'
2172}
2173
Gilles Peskine8f073122018-11-27 15:58:47 +01002174component_test_null_entropy () {
2175 msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002176 scripts/config.py set MBEDTLS_TEST_NULL_ENTROPY
2177 scripts/config.py set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
2178 scripts/config.py set MBEDTLS_ENTROPY_C
2179 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskine32e889d2020-04-12 23:43:28 +02002180 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002181 scripts/config.py unset MBEDTLS_ENTROPY_HARDWARE_ALT
2182 scripts/config.py unset MBEDTLS_HAVEGE_C
Gilles Peskine5fa32a72019-01-06 19:48:30 +00002183 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan -D UNSAFE_BUILD=ON .
Gilles Peskine8f073122018-11-27 15:58:47 +01002184 make
Janos Follath06c54002016-06-09 13:57:40 +01002185
Gilles Peskine8f073122018-11-27 15:58:47 +01002186 msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)"
2187 make test
2188}
Janos Follath06c54002016-06-09 13:57:40 +01002189
Raoul Strackxa4e86142020-06-15 17:03:13 +02002190component_test_no_date_time () {
2191 msg "build: default config without MBEDTLS_HAVE_TIME_DATE"
2192 scripts/config.py unset MBEDTLS_HAVE_TIME_DATE
2193 CC=gcc cmake
2194 make
2195
2196 msg "test: !MBEDTLS_HAVE_TIME_DATE - main suites"
2197 make test
2198}
2199
Gilles Peskine8f073122018-11-27 15:58:47 +01002200component_test_platform_calloc_macro () {
2201 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002202 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
2203 scripts/config.py set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
2204 scripts/config.py set MBEDTLS_PLATFORM_FREE_MACRO free
Gilles Peskine8f073122018-11-27 15:58:47 +01002205 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2206 make
Hanno Beckere5fecec2018-10-11 11:02:52 +01002207
Gilles Peskine8f073122018-11-27 15:58:47 +01002208 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
2209 make test
2210}
Hanno Beckere5fecec2018-10-11 11:02:52 +01002211
Gilles Peskinec4ef7a92019-09-17 19:04:38 +02002212component_test_malloc_0_null () {
2213 msg "build: malloc(0) returns NULL (ASan+UBSan build)"
Manuel Pégourié-Gonnard68192fc2020-03-04 10:34:47 +01002214 scripts/config.py full
Gilles Peskine004206c2019-10-21 17:11:33 +02002215 make CC=gcc CFLAGS="'-DMBEDTLS_CONFIG_FILE=\"$PWD/tests/configs/config-wrapper-malloc-0-null.h\"' $ASAN_CFLAGS -O" LDFLAGS="$ASAN_CFLAGS"
Gilles Peskinec4ef7a92019-09-17 19:04:38 +02002216
2217 msg "test: malloc(0) returns NULL (ASan+UBSan build)"
2218 make test
2219
2220 msg "selftest: malloc(0) returns NULL (ASan+UBSan build)"
2221 # Just the calloc selftest. "make test" ran the others as part of the
2222 # test suites.
2223 if_build_succeeded programs/test/selftest calloc
Gilles Peskine765d2402020-02-11 18:26:34 +01002224
2225 msg "test ssl-opt.sh: malloc(0) returns NULL (ASan+UBSan build)"
2226 # Run a subset of the tests. The choice is a balance between coverage
2227 # and time (including time indirectly wasted due to flaky tests).
2228 # The current choice is to skip tests whose description includes
2229 # "proxy", which is an approximation of skipping tests that use the
2230 # UDP proxy, which tend to be slower and flakier.
2231 if_build_succeeded tests/ssl-opt.sh -e 'proxy'
Gilles Peskinec4ef7a92019-09-17 19:04:38 +02002232}
2233
Gilles Peskine8f073122018-11-27 15:58:47 +01002234component_test_aes_fewer_tables () {
2235 msg "build: default config with AES_FEWER_TABLES enabled"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002236 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
Gilles Peskine8f073122018-11-27 15:58:47 +01002237 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01002238
Gilles Peskine8f073122018-11-27 15:58:47 +01002239 msg "test: AES_FEWER_TABLES"
2240 make test
2241}
Hanno Becker83ebf782017-07-07 12:29:15 +01002242
Gilles Peskine8f073122018-11-27 15:58:47 +01002243component_test_aes_rom_tables () {
2244 msg "build: default config with AES_ROM_TABLES enabled"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002245 scripts/config.py set MBEDTLS_AES_ROM_TABLES
Gilles Peskine8f073122018-11-27 15:58:47 +01002246 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01002247
Gilles Peskine8f073122018-11-27 15:58:47 +01002248 msg "test: AES_ROM_TABLES"
2249 make test
2250}
Hanno Becker83ebf782017-07-07 12:29:15 +01002251
Gilles Peskine8f073122018-11-27 15:58:47 +01002252component_test_aes_fewer_tables_and_rom_tables () {
2253 msg "build: default config with AES_ROM_TABLES and AES_FEWER_TABLES enabled"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002254 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
2255 scripts/config.py set MBEDTLS_AES_ROM_TABLES
Gilles Peskine8f073122018-11-27 15:58:47 +01002256 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01002257
Gilles Peskine8f073122018-11-27 15:58:47 +01002258 msg "test: AES_FEWER_TABLES + AES_ROM_TABLES"
2259 make test
2260}
2261
Gilles Peskine592f5912019-10-07 18:49:32 +02002262component_test_ctr_drbg_aes_256_sha_256 () {
2263 msg "build: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
Gilles Peskine3b46cd32020-02-18 17:56:33 +01002264 scripts/config.py full
2265 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
2266 scripts/config.py set MBEDTLS_ENTROPY_FORCE_SHA256
Gilles Peskine592f5912019-10-07 18:49:32 +02002267 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2268 make
2269
2270 msg "test: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
2271 make test
2272}
2273
2274component_test_ctr_drbg_aes_128_sha_512 () {
2275 msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)"
Gilles Peskine3b46cd32020-02-18 17:56:33 +01002276 scripts/config.py full
2277 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
2278 scripts/config.py set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
Gilles Peskine592f5912019-10-07 18:49:32 +02002279 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2280 make
2281
2282 msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)"
2283 make test
2284}
2285
2286component_test_ctr_drbg_aes_128_sha_256 () {
2287 msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
Gilles Peskine3b46cd32020-02-18 17:56:33 +01002288 scripts/config.py full
2289 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
2290 scripts/config.py set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
2291 scripts/config.py set MBEDTLS_ENTROPY_FORCE_SHA256
Gilles Peskine592f5912019-10-07 18:49:32 +02002292 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2293 make
2294
2295 msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
2296 make test
2297}
2298
Gilles Peskinef96aefe2019-07-24 14:58:38 +02002299component_test_se_default () {
2300 msg "build: default config + MBEDTLS_PSA_CRYPTO_SE_C"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002301 scripts/config.py set MBEDTLS_PSA_CRYPTO_SE_C
Gilles Peskine004206c2019-10-21 17:11:33 +02002302 make CC=clang CFLAGS="$ASAN_CFLAGS -Os" LDFLAGS="$ASAN_CFLAGS"
Gilles Peskinef96aefe2019-07-24 14:58:38 +02002303
2304 msg "test: default config + MBEDTLS_PSA_CRYPTO_SE_C"
2305 make test
2306}
2307
Steven Cooremand57203d2020-07-16 20:28:59 +02002308component_test_psa_crypto_drivers () {
Steven Cooreman55ae2172020-07-17 19:46:15 +02002309 msg "build: MBEDTLS_PSA_CRYPTO_DRIVERS w/ driver hooks"
Steven Cooreman753f9732021-03-15 11:38:44 +01002310 scripts/config.py full
Steven Cooremand57203d2020-07-16 20:28:59 +02002311 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
Steven Cooreman6801f082021-02-19 17:21:22 +01002312 scripts/config.py set MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS
Gilles Peskinefe0acc62021-09-20 19:20:04 +02002313 loc_cflags="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST_ALL"
2314 loc_cflags="${loc_cflags} '-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/user-config-for-test.h\"'"
Ronald Cron17b3afc2020-12-10 18:17:09 +01002315 loc_cflags="${loc_cflags} -I../tests/include -O2"
2316
2317 make CC=gcc CFLAGS="${loc_cflags}" LDFLAGS="$ASAN_CFLAGS"
2318 unset loc_cflags
Steven Cooremand57203d2020-07-16 20:28:59 +02002319
Steven Cooreman753f9732021-03-15 11:38:44 +01002320 msg "test: full + MBEDTLS_PSA_CRYPTO_DRIVERS"
Steven Cooremand57203d2020-07-16 20:28:59 +02002321 make test
2322}
2323
Gilles Peskine8f073122018-11-27 15:58:47 +01002324component_test_make_shared () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01002325 msg "build/test: make shared" # ~ 40s
Andrzej Kurek232e8f92019-10-03 03:18:01 -04002326 make SHARED=1 all check
Gilles Peskine56c01612019-07-03 20:43:32 +02002327 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskine8f073122018-11-27 15:58:47 +01002328}
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +02002329
Gilles Peskinecf740502019-07-03 20:43:05 +02002330component_test_cmake_shared () {
2331 msg "build/test: cmake shared" # ~ 2min
2332 cmake -DUSE_SHARED_MBEDTLS_LIBRARY=On .
2333 make
Gilles Peskine56c01612019-07-03 20:43:32 +02002334 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskinecf740502019-07-03 20:43:05 +02002335 make test
2336}
2337
Gilles Peskineec10bf12019-09-20 19:56:06 +02002338test_build_opt () {
2339 info=$1 cc=$2; shift 2
2340 for opt in "$@"; do
2341 msg "build/test: $cc $opt, $info" # ~ 30s
Gilles Peskinee094a182020-04-14 20:08:41 +02002342 make CC="$cc" CFLAGS="$opt -std=c99 -pedantic -Wall -Wextra -Werror"
Gilles Peskineec10bf12019-09-20 19:56:06 +02002343 # We're confident enough in compilers to not run _all_ the tests,
2344 # but at least run the unit tests. In particular, runs with
2345 # optimizations use inline assembly whereas runs with -O0
2346 # skip inline assembly.
2347 make test # ~30s
2348 make clean
2349 done
2350}
2351
2352component_test_clang_opt () {
Manuel Pégourié-Gonnard68192fc2020-03-04 10:34:47 +01002353 scripts/config.py full
Gilles Peskineec10bf12019-09-20 19:56:06 +02002354 test_build_opt 'full config' clang -O0 -Os -O2
2355}
2356
2357component_test_gcc_opt () {
Manuel Pégourié-Gonnard68192fc2020-03-04 10:34:47 +01002358 scripts/config.py full
Gilles Peskineec10bf12019-09-20 19:56:06 +02002359 test_build_opt 'full config' gcc -O0 -Os -O2
2360}
2361
Gilles Peskineabf9b4d2019-07-03 20:42:16 +02002362component_build_mbedtls_config_file () {
2363 msg "build: make with MBEDTLS_CONFIG_FILE" # ~40s
2364 # Use the full config so as to catch a maximum of places where
2365 # the check of MBEDTLS_CONFIG_FILE might be missing.
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002366 scripts/config.py full
Gilles Peskineabf9b4d2019-07-03 20:42:16 +02002367 sed 's!"check_config.h"!"mbedtls/check_config.h"!' <"$CONFIG_H" >full_config.h
2368 echo '#error "MBEDTLS_CONFIG_FILE is not working"' >"$CONFIG_H"
2369 make CFLAGS="-I '$PWD' -DMBEDTLS_CONFIG_FILE='\"full_config.h\"'"
2370 rm -f full_config.h
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00002371}
2372
Gilles Peskine8f073122018-11-27 15:58:47 +01002373component_test_m32_o0 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +01002374 # Build once with -O0, to compile out the i386 specific inline assembly
2375 msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002376 scripts/config.py full
Gilles Peskine8fd59422019-10-21 17:11:33 +02002377 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O0" LDFLAGS="-m32 $ASAN_CFLAGS"
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01002378
Simon Butcher8e6a22a2018-07-20 21:27:33 +01002379 msg "test: i386, make, gcc -O0 (ASan build)"
2380 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01002381}
Gilles Peskine878cf602019-01-06 20:50:38 +00002382support_test_m32_o0 () {
2383 case $(uname -m) in
2384 *64*) true;;
2385 *) false;;
2386 esac
2387}
Simon Butcher8e6a22a2018-07-20 21:27:33 +01002388
Gilles Peskine8f073122018-11-27 15:58:47 +01002389component_test_m32_o1 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +01002390 # Build again with -O1, to compile in the i386 specific inline assembly
2391 msg "build: i386, make, gcc -O1 (ASan build)" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002392 scripts/config.py full
Gilles Peskine8fd59422019-10-21 17:11:33 +02002393 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O1" LDFLAGS="-m32 $ASAN_CFLAGS"
Simon Butcher8e6a22a2018-07-20 21:27:33 +01002394
2395 msg "test: i386, make, gcc -O1 (ASan build)"
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01002396 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +01002397
2398 msg "test ssl-opt.sh, i386, make, gcc-O1"
2399 if_build_succeeded tests/ssl-opt.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01002400}
Gilles Peskine878cf602019-01-06 20:50:38 +00002401support_test_m32_o1 () {
2402 support_test_m32_o0 "$@"
2403}
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01002404
Gilles Peskine0c6b7992019-04-12 20:29:48 +02002405component_test_m32_everest () {
2406 msg "build: i386, Everest ECDH context (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002407 scripts/config.py unset MBEDTLS_ECDH_LEGACY_CONTEXT
2408 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
Gilles Peskine8fd59422019-10-21 17:11:33 +02002409 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O2" LDFLAGS="-m32 $ASAN_CFLAGS"
Gilles Peskine0c6b7992019-04-12 20:29:48 +02002410
2411 msg "test: i386, Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
2412 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +01002413
2414 msg "test: i386, Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
2415 if_build_succeeded tests/ssl-opt.sh -f ECDH
2416
2417 msg "test: i386, Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
2418 # Exclude some symmetric ciphers that are redundant here to gain time.
2419 if_build_succeeded tests/compat.sh -f ECDH -V NO -e 'ARCFOUR\|ARIA\|CAMELLIA\|CHACHA\|DES\|RC4'
Gilles Peskine0c6b7992019-04-12 20:29:48 +02002420}
2421support_test_m32_everest () {
2422 support_test_m32_o0 "$@"
2423}
2424
Gilles Peskine8f073122018-11-27 15:58:47 +01002425component_test_mx32 () {
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01002426 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002427 scripts/config.py full
Gilles Peskine5d26e7c2019-06-07 14:50:09 +02002428 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32' LDFLAGS='-mx32'
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01002429
2430 msg "test: 64-bit ILP32, make, gcc"
2431 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01002432}
Gilles Peskine878cf602019-01-06 20:50:38 +00002433support_test_mx32 () {
2434 case $(uname -m) in
2435 amd64|x86_64) true;;
2436 *) false;;
2437 esac
2438}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00002439
Peter Kolbus60c6da22018-12-27 06:59:04 -06002440component_test_min_mpi_window_size () {
2441 msg "build: Default + MBEDTLS_MPI_WINDOW_SIZE=1 (ASan build)" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002442 scripts/config.py set MBEDTLS_MPI_WINDOW_SIZE 1
Peter Kolbus60c6da22018-12-27 06:59:04 -06002443 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2444 make
2445
2446 msg "test: MBEDTLS_MPI_WINDOW_SIZE=1 - main suites (inc. selftests) (ASan build)" # ~ 10s
2447 make test
2448}
2449
Gilles Peskine8f073122018-11-27 15:58:47 +01002450component_test_have_int32 () {
2451 msg "build: gcc, force 32-bit bignum limbs"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002452 scripts/config.py unset MBEDTLS_HAVE_ASM
2453 scripts/config.py unset MBEDTLS_AESNI_C
2454 scripts/config.py unset MBEDTLS_PADLOCK_C
Gilles Peskine8f073122018-11-27 15:58:47 +01002455 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01002456
Gilles Peskine8f073122018-11-27 15:58:47 +01002457 msg "test: gcc, force 32-bit bignum limbs"
2458 make test
2459}
Andres Amaya Garciafe843a32017-07-20 13:21:34 +01002460
Gilles Peskine8f073122018-11-27 15:58:47 +01002461component_test_have_int64 () {
2462 msg "build: gcc, force 64-bit bignum limbs"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002463 scripts/config.py unset MBEDTLS_HAVE_ASM
2464 scripts/config.py unset MBEDTLS_AESNI_C
2465 scripts/config.py unset MBEDTLS_PADLOCK_C
Gilles Peskine8f073122018-11-27 15:58:47 +01002466 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
Gilles Peskine14c3c062018-01-29 21:25:12 +01002467
Gilles Peskine8f073122018-11-27 15:58:47 +01002468 msg "test: gcc, force 64-bit bignum limbs"
2469 make test
2470}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00002471
Gilles Peskine8f073122018-11-27 15:58:47 +01002472component_test_no_udbl_division () {
2473 msg "build: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002474 scripts/config.py full
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002475 scripts/config.py set MBEDTLS_NO_UDBL_DIVISION
Gilles Peskine8f073122018-11-27 15:58:47 +01002476 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02002477
Gilles Peskine8f073122018-11-27 15:58:47 +01002478 msg "test: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
2479 make test
2480}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02002481
Gilles Peskine8f073122018-11-27 15:58:47 +01002482component_test_no_64bit_multiplication () {
2483 msg "build: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002484 scripts/config.py full
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002485 scripts/config.py set MBEDTLS_NO_64BIT_MULTIPLICATION
Gilles Peskine8f073122018-11-27 15:58:47 +01002486 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02002487
Gilles Peskine8f073122018-11-27 15:58:47 +01002488 msg "test: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
2489 make test
2490}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02002491
Gilles Peskine3809f5f2020-11-09 15:40:05 +01002492component_test_no_strings () {
2493 msg "build: no strings" # ~10s
2494 scripts/config.py full
2495 # Disable options that activate a large amount of string constants.
2496 scripts/config.py unset MBEDTLS_DEBUG_C
2497 scripts/config.py unset MBEDTLS_ERROR_C
2498 scripts/config.py set MBEDTLS_ERROR_STRERROR_DUMMY
2499 scripts/config.py unset MBEDTLS_VERSION_FEATURES
2500 make CFLAGS='-Werror -Os'
2501
2502 msg "test: no strings" # ~ 10s
2503 make test
2504}
2505
Gilles Peskine8f073122018-11-27 15:58:47 +01002506component_build_arm_none_eabi_gcc () {
Gilles Peskine18487f62020-04-30 23:11:54 +02002507 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002508 scripts/config.py baremetal
Gilles Peskineaeedd742020-09-02 11:03:04 +02002509 make CC="${ARM_NONE_EABI_GCC_PREFIX}gcc" AR="${ARM_NONE_EABI_GCC_PREFIX}ar" LD="${ARM_NONE_EABI_GCC_PREFIX}ld" CFLAGS='-std=c99 -Werror -Wall -Wextra -O1' lib
Gilles Peskine18487f62020-04-30 23:11:54 +02002510
2511 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1"
2512 ${ARM_NONE_EABI_GCC_PREFIX}size library/*.o
Gilles Peskine8f073122018-11-27 15:58:47 +01002513}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02002514
Manuel Pégourié-Gonnard71930162020-08-18 10:28:51 +02002515component_build_arm_linux_gnueabi_gcc_arm5vte () {
2516 msg "build: ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc -march=arm5vte" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002517 scripts/config.py baremetal
Gilles Peskine2c897d72019-08-09 16:05:05 +02002518 # Build for a target platform that's close to what Debian uses
2519 # for its "armel" distribution (https://wiki.debian.org/ArmEabiPort).
2520 # See https://github.com/ARMmbed/mbedtls/pull/2169 and comments.
Manuel Pégourié-Gonnard71930162020-08-18 10:28:51 +02002521 # Build everything including programs, see for example
2522 # https://github.com/ARMmbed/mbedtls/pull/3449#issuecomment-675313720
2523 make CC="${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc" AR="${ARM_LINUX_GNUEABI_GCC_PREFIX}ar" CFLAGS='-Werror -Wall -Wextra -march=armv5te -O1' LDFLAGS='-march=armv5te'
2524
2525 msg "size: ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc -march=armv5te -O1"
2526 ${ARM_LINUX_GNUEABI_GCC_PREFIX}size library/*.o
2527}
2528support_build_arm_linux_gnueabi_gcc_arm5vte () {
2529 type ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc >/dev/null 2>&1
2530}
2531
2532component_build_arm_none_eabi_gcc_arm5vte () {
2533 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=arm5vte" # ~ 10s
2534 scripts/config.py baremetal
2535 # This is an imperfect substitute for
2536 # component_build_arm_linux_gnueabi_gcc_arm5vte
Manuel Pégourié-Gonnard9a260a62021-07-06 09:44:59 +02002537 # in case the gcc-arm-linux-gnueabi toolchain is not available
Gilles Peskineaeedd742020-09-02 11:03:04 +02002538 make CC="${ARM_NONE_EABI_GCC_PREFIX}gcc" AR="${ARM_NONE_EABI_GCC_PREFIX}ar" CFLAGS='-std=c99 -Werror -Wall -Wextra -march=armv5te -O1' LDFLAGS='-march=armv5te' SHELL='sh -x' lib
Gilles Peskine18487f62020-04-30 23:11:54 +02002539
2540 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=armv5te -O1"
2541 ${ARM_NONE_EABI_GCC_PREFIX}size library/*.o
Gilles Peskine93e4e032019-08-05 11:34:25 +02002542}
2543
Gilles Peskine6e2fb862020-04-30 23:00:53 +02002544component_build_arm_none_eabi_gcc_m0plus () {
2545 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus" # ~ 10s
2546 scripts/config.py baremetal
Gilles Peskineaeedd742020-09-02 11:03:04 +02002547 make CC="${ARM_NONE_EABI_GCC_PREFIX}gcc" AR="${ARM_NONE_EABI_GCC_PREFIX}ar" LD="${ARM_NONE_EABI_GCC_PREFIX}ld" CFLAGS='-std=c99 -Werror -Wall -Wextra -mthumb -mcpu=cortex-m0plus -Os' lib
Gilles Peskine18487f62020-04-30 23:11:54 +02002548
2549 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus -Os"
2550 ${ARM_NONE_EABI_GCC_PREFIX}size library/*.o
Gilles Peskine6e2fb862020-04-30 23:00:53 +02002551}
2552
Gilles Peskine8f073122018-11-27 15:58:47 +01002553component_build_arm_none_eabi_gcc_no_udbl_division () {
Gilles Peskine6d061342020-04-30 18:19:32 +02002554 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002555 scripts/config.py baremetal
2556 scripts/config.py set MBEDTLS_NO_UDBL_DIVISION
Gilles Peskineaeedd742020-09-02 11:03:04 +02002557 make CC="${ARM_NONE_EABI_GCC_PREFIX}gcc" AR="${ARM_NONE_EABI_GCC_PREFIX}ar" LD="${ARM_NONE_EABI_GCC_PREFIX}ld" CFLAGS='-std=c99 -Werror -Wall -Wextra' lib
Gilles Peskine8f073122018-11-27 15:58:47 +01002558 echo "Checking that software 64-bit division is not required"
2559 if_build_succeeded not grep __aeabi_uldiv library/*.o
2560}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02002561
Gilles Peskine8f073122018-11-27 15:58:47 +01002562component_build_arm_none_eabi_gcc_no_64bit_multiplication () {
Gilles Peskine6d061342020-04-30 18:19:32 +02002563 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc MBEDTLS_NO_64BIT_MULTIPLICATION, make" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002564 scripts/config.py baremetal
2565 scripts/config.py set MBEDTLS_NO_64BIT_MULTIPLICATION
Gilles Peskineaeedd742020-09-02 11:03:04 +02002566 make CC="${ARM_NONE_EABI_GCC_PREFIX}gcc" AR="${ARM_NONE_EABI_GCC_PREFIX}ar" LD="${ARM_NONE_EABI_GCC_PREFIX}ld" CFLAGS='-std=c99 -Werror -O1 -march=armv6-m -mthumb' lib
Gilles Peskine8f073122018-11-27 15:58:47 +01002567 echo "Checking that software 64-bit multiplication is not required"
2568 if_build_succeeded not grep __aeabi_lmul library/*.o
2569}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02002570
Gilles Peskine8f073122018-11-27 15:58:47 +01002571component_build_armcc () {
Gilles Peskine18487f62020-04-30 23:11:54 +02002572 msg "build: ARM Compiler 5"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002573 scripts/config.py baremetal
Gilles Peskinebca6ab92017-12-19 18:24:31 +01002574 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
Gilles Peskine18487f62020-04-30 23:11:54 +02002575
2576 msg "size: ARM Compiler 5"
2577 "$ARMC5_FROMELF" -z library/*.o
2578
Gilles Peskinebca6ab92017-12-19 18:24:31 +01002579 make clean
Andres AG87bb5772016-09-27 15:05:15 +01002580
Gilles Peskinebca6ab92017-12-19 18:24:31 +01002581 # ARM Compiler 6 - Target ARMv7-A
2582 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-a"
Simon Butcher940737f2017-07-23 13:42:36 +02002583
Gilles Peskinebca6ab92017-12-19 18:24:31 +01002584 # ARM Compiler 6 - Target ARMv7-M
2585 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m"
Simon Butcher940737f2017-07-23 13:42:36 +02002586
Gilles Peskinebca6ab92017-12-19 18:24:31 +01002587 # ARM Compiler 6 - Target ARMv8-A - AArch32
2588 armc6_build_test "--target=arm-arm-none-eabi -march=armv8.2-a"
Simon Butcher940737f2017-07-23 13:42:36 +02002589
Gilles Peskinebca6ab92017-12-19 18:24:31 +01002590 # ARM Compiler 6 - Target ARMv8-M
2591 armc6_build_test "--target=arm-arm-none-eabi -march=armv8-m.main"
Simon Butcher940737f2017-07-23 13:42:36 +02002592
Gilles Peskinebca6ab92017-12-19 18:24:31 +01002593 # ARM Compiler 6 - Target ARMv8-A - AArch64
2594 armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a"
Gilles Peskine8f073122018-11-27 15:58:47 +01002595}
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +01002596
Manuel Pégourié-Gonnarddd8807f2020-02-26 09:56:27 +01002597component_build_ssl_hw_record_accel() {
2598 msg "build: default config with MBEDTLS_SSL_HW_RECORD_ACCEL enabled"
2599 scripts/config.pl set MBEDTLS_SSL_HW_RECORD_ACCEL
2600 make CFLAGS='-Werror -O1'
2601}
2602
Hanno Beckera711f6e2020-05-04 12:03:51 +01002603component_test_tls13_experimental () {
2604 msg "build: default config with MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL enabled"
2605 scripts/config.pl set MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL
2606 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2607 make
2608 msg "test: default config with MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL enabled"
2609 make test
2610}
2611
Gilles Peskine8f073122018-11-27 15:58:47 +01002612component_build_mingw () {
2613 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
Andrzej Kurek232e8f92019-10-03 03:18:01 -04002614 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 +00002615
Gilles Peskine8f073122018-11-27 15:58:47 +01002616 # note Make tests only builds the tests, but doesn't run them
Andrzej Kurek232e8f92019-10-03 03:18:01 -04002617 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 +01002618 make WINDOWS_BUILD=1 clean
Gilles Peskine2a458da2017-05-12 15:26:58 +02002619
Gilles Peskine8f073122018-11-27 15:58:47 +01002620 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
Andrzej Kurek232e8f92019-10-03 03:18:01 -04002621 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
2622 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 +01002623 make WINDOWS_BUILD=1 clean
2624}
Jaeden Amero117b8a42019-04-17 15:19:26 +01002625support_build_mingw() {
2626 case $(i686-w64-mingw32-gcc -dumpversion) in
2627 [0-5]*) false;;
2628 *) true;;
2629 esac
2630}
Simon Butcher91aef332016-11-17 09:20:50 +00002631
Gilles Peskine8f073122018-11-27 15:58:47 +01002632component_test_memsan () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01002633 msg "build: MSan (clang)" # ~ 1 min 20s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002634 scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm
Gilles Peskine7ad603e2017-12-10 23:22:20 +01002635 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
2636 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +02002637
Gilles Peskine7ad603e2017-12-10 23:22:20 +01002638 msg "test: main suites (MSan)" # ~ 10s
2639 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01002640
Gilles Peskine7ad603e2017-12-10 23:22:20 +01002641 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
Gilles Peskine7c652162017-12-11 00:01:40 +01002642 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01002643
Gilles Peskine7ad603e2017-12-10 23:22:20 +01002644 # Optional part(s)
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01002645
Gilles Peskine7ad603e2017-12-10 23:22:20 +01002646 if [ "$MEMORY" -gt 0 ]; then
2647 msg "test: compat.sh (MSan)" # ~ 6 min 20s
Gilles Peskine7c652162017-12-11 00:01:40 +01002648 if_build_succeeded tests/compat.sh
Gilles Peskine7ad603e2017-12-10 23:22:20 +01002649 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01002650}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01002651
Gilles Peskine69f190e2019-01-10 00:11:42 +01002652component_test_valgrind () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01002653 msg "build: Release (clang)"
Gilles Peskine7ad603e2017-12-10 23:22:20 +01002654 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
2655 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00002656
Gilles Peskine7ad603e2017-12-10 23:22:20 +01002657 msg "test: main suites valgrind (Release)"
2658 make memcheck
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00002659
Gilles Peskine636c26a2020-03-04 20:46:15 +01002660 # Optional parts (slow; currently broken on OS X because programs don't
2661 # seem to receive signals under valgrind on OS X).
Gilles Peskine7ad603e2017-12-10 23:22:20 +01002662 if [ "$MEMORY" -gt 0 ]; then
2663 msg "test: ssl-opt.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +01002664 if_build_succeeded tests/ssl-opt.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01002665 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00002666
Gilles Peskine7ad603e2017-12-10 23:22:20 +01002667 if [ "$MEMORY" -gt 1 ]; then
2668 msg "test: compat.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +01002669 if_build_succeeded tests/compat.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01002670 fi
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02002671
2672 if [ "$MEMORY" -gt 0 ]; then
2673 msg "test: context-info.sh --memcheck (Release)"
2674 if_build_succeeded tests/context-info.sh --memcheck
2675 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01002676}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00002677
Gilles Peskine8f073122018-11-27 15:58:47 +01002678component_test_cmake_out_of_source () {
2679 msg "build: cmake 'out-of-source' build"
Gilles Peskine8f073122018-11-27 15:58:47 +01002680 MBEDTLS_ROOT_DIR="$PWD"
2681 mkdir "$OUT_OF_SOURCE_DIR"
2682 cd "$OUT_OF_SOURCE_DIR"
2683 cmake "$MBEDTLS_ROOT_DIR"
2684 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00002685
Gilles Peskine8f073122018-11-27 15:58:47 +01002686 msg "test: cmake 'out-of-source' build"
2687 make test
2688 # Test an SSL option that requires an auxiliary script in test/scripts/.
2689 # Also ensure that there are no error messages such as
2690 # "No such file or directory", which would indicate that some required
2691 # file is missing (ssl-opt.sh tolerates the absence of some files so
2692 # may exit with status 0 but emit errors).
2693 if_build_succeeded ./tests/ssl-opt.sh -f 'Fallback SCSV: beginning of list' 2>ssl-opt.err
2694 if [ -s ssl-opt.err ]; then
2695 cat ssl-opt.err >&2
2696 record_status [ ! -s ssl-opt.err ]
2697 rm ssl-opt.err
2698 fi
2699 cd "$MBEDTLS_ROOT_DIR"
2700 rm -rf "$OUT_OF_SOURCE_DIR"
2701 unset MBEDTLS_ROOT_DIR
2702}
Andres AGdc192212016-08-31 17:33:13 +01002703
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01002704component_test_cmake_as_subdirectory () {
2705 msg "build: cmake 'as-subdirectory' build"
2706 MBEDTLS_ROOT_DIR="$PWD"
2707
2708 cd programs/test/cmake_subproject
2709 cmake .
2710 make
2711 if_build_succeeded ./cmake_subproject
2712
2713 cd "$MBEDTLS_ROOT_DIR"
2714 unset MBEDTLS_ROOT_DIR
2715}
2716
Gilles Peskine8f073122018-11-27 15:58:47 +01002717component_test_zeroize () {
2718 # Test that the function mbedtls_platform_zeroize() is not optimized away by
2719 # different combinations of compilers and optimization flags by using an
2720 # auxiliary GDB script. Unfortunately, GDB does not return error values to the
2721 # system in all cases that the script fails, so we must manually search the
2722 # output to check whether the pass string is present and no failure strings
2723 # were printed.
Andres AGdc192212016-08-31 17:33:13 +01002724
Gilles Peskine4976e822019-01-06 19:52:22 +00002725 # Don't try to disable ASLR. We don't care about ASLR here. We do care
2726 # about a spurious message if Gdb tries and fails, so suppress that.
2727 gdb_disable_aslr=
2728 if [ -z "$(gdb -batch -nw -ex 'set disable-randomization off' 2>&1)" ]; then
2729 gdb_disable_aslr='set disable-randomization off'
2730 fi
2731
Gilles Peskine8f073122018-11-27 15:58:47 +01002732 for optimization_flag in -O2 -O3 -Ofast -Os; do
Gilles Peskine55f7c942019-01-09 22:28:21 +01002733 for compiler in clang gcc; do
2734 msg "test: $compiler $optimization_flag, mbedtls_platform_zeroize()"
2735 make programs CC="$compiler" DEBUG=1 CFLAGS="$optimization_flag"
Gilles Peskine4976e822019-01-06 19:52:22 +00002736 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 +01002737 if_build_succeeded grep "The buffer was correctly zeroized" test_zeroize.log
2738 if_build_succeeded not grep -i "error" test_zeroize.log
2739 rm -f test_zeroize.log
2740 make clean
2741 done
Andres Amaya Garcia29673812017-10-25 10:35:51 +01002742 done
Andres Amaya Garciad0d7bf62017-10-25 09:01:31 +01002743
Gilles Peskine4976e822019-01-06 19:52:22 +00002744 unset gdb_disable_aslr
Gilles Peskine8f073122018-11-27 15:58:47 +01002745}
Gilles Peskine192c72f2017-12-21 15:59:21 +01002746
Gilles Peskine8f073122018-11-27 15:58:47 +01002747component_check_python_files () {
2748 msg "Lint: Python scripts"
2749 record_status tests/scripts/check-python-files.sh
2750}
Gilles Peskine192c72f2017-12-21 15:59:21 +01002751
Gilles Peskine8f073122018-11-27 15:58:47 +01002752component_check_generate_test_code () {
2753 msg "uint test: generate_test_code.py"
Manuel Pégourié-Gonnarddfb114a2020-06-02 11:40:08 +02002754 # unittest writes out mundane stuff like number or tests run on stderr.
2755 # Our convention is to reserve stderr for actual errors, and write
2756 # harmless info on stdout so it can be suppress with --quiet.
2757 record_status ./tests/scripts/test_generate_test_code.py 2>&1
Gilles Peskine8f073122018-11-27 15:58:47 +01002758}
Gilles Peskine192c72f2017-12-21 15:59:21 +01002759
2760################################################################
2761#### Termination
2762################################################################
2763
Gilles Peskine8f073122018-11-27 15:58:47 +01002764post_report () {
2765 msg "Done, cleaning up"
2766 cleanup
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01002767
Gilles Peskine8f073122018-11-27 15:58:47 +01002768 final_report
2769}
2770
2771
2772
2773################################################################
2774#### Run all the things
2775################################################################
2776
Gilles Peskinee48351a2018-11-27 16:06:30 +01002777# Run one component and clean up afterwards.
Gilles Peskine8f073122018-11-27 15:58:47 +01002778run_component () {
Gilles Peskine608953e2019-01-02 18:57:02 +01002779 # Back up the configuration in case the component modifies it.
2780 # The cleanup function will restore it.
2781 cp -p "$CONFIG_H" "$CONFIG_BAK"
John Durkopbd069d32020-10-31 22:14:03 -07002782 cp -p "$CRYPTO_CONFIG_H" "$CRYPTO_CONFIG_BAK"
Gilles Peskineffcdeff2018-12-04 12:49:28 +01002783 current_component="$1"
Gilles Peskine9004a172019-09-16 15:20:36 +02002784 export MBEDTLS_TEST_CONFIGURATION="$current_component"
Gilles Peskine2ef377d2019-10-07 18:44:21 +02002785
2786 # Unconditionally create a seedfile that's sufficiently long.
2787 # Do this before each component, because a previous component may
2788 # have messed it up or shortened it.
Manuel Pégourié-Gonnardf1f180a2020-06-08 10:46:35 +02002789 redirect_err dd if=/dev/urandom of=./tests/seedfile bs=64 count=1
Gilles Peskine2ef377d2019-10-07 18:44:21 +02002790
2791 # Run the component code.
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +02002792 if [ $QUIET -eq 1 ]; then
2793 # msg() is silenced, so just print the component name here
2794 echo "${current_component#component_}"
2795 fi
2796 redirect_out "$@"
Gilles Peskine2ef377d2019-10-07 18:44:21 +02002797
2798 # Restore the build tree to a clean state.
Gilles Peskinee48351a2018-11-27 16:06:30 +01002799 cleanup
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +02002800 unset current_component
Gilles Peskine8f073122018-11-27 15:58:47 +01002801}
2802
2803# Preliminary setup
2804pre_check_environment
2805pre_initialize_variables
2806pre_parse_command_line "$@"
Gilles Peskine348fb9a2018-11-27 17:04:29 +01002807
Gilles Peskine878cf602019-01-06 20:50:38 +00002808pre_check_git
Andrzej Kurekeb508712019-02-14 07:18:59 -05002809
Gilles Peskine878cf602019-01-06 20:50:38 +00002810build_status=0
2811if [ $KEEP_GOING -eq 1 ]; then
2812 pre_setup_keep_going
Gilles Peskine92525112018-11-27 18:15:35 +01002813else
Gilles Peskine878cf602019-01-06 20:50:38 +00002814 record_status () {
2815 "$@"
2816 }
Gilles Peskine8f073122018-11-27 15:58:47 +01002817fi
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +02002818pre_setup_quiet_redirect
Gilles Peskine67ffdaf2019-09-16 15:55:46 +02002819pre_prepare_outcome_file
Gilles Peskine878cf602019-01-06 20:50:38 +00002820pre_print_configuration
2821pre_check_tools
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01002822cleanup
2823
Gilles Peskinebeb3a812019-01-06 22:11:25 +00002824# Run the requested tests.
2825for component in $RUN_COMPONENTS; do
2826 run_component "component_$component"
2827done
Gilles Peskine8f073122018-11-27 15:58:47 +01002828
2829# We're done.
Gilles Peskine878cf602019-01-06 20:50:38 +00002830post_report