blob: 8c75c9f052bc83427205d13e662620393fb48240 [file] [log] [blame]
Gilles Peskine62cf2e82020-03-27 16:35:23 +01001#! /usr/bin/env bash
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:
Bence Szépkútibb0cfeb2021-05-28 09:42:25 +020037# * include/mbedtls/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
Mateusz Starzykf5c53512021-04-15 13:28:52 +020054# interoperability tests. If they don't support old features which we want
55# to test, then a legacy version of these tools must be present as well
56# (search for LEGACY below).
Gilles Peskine192c72f2017-12-21 15:59:21 +010057# 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#
Gilles Peskinece266c42020-03-28 18:50:43 +010062# The behavior on an error depends on whether --keep-going (alias -k)
63# is in effect.
64# * Without --keep-going: the script stops on the first error without
65# cleaning up. This lets you work in the configuration of the failing
66# component.
67# * With --keep-going: the script runs all requested components and
68# reports failures at the end. In particular the script always cleans
69# up on exit.
70#
Gilles Peskine192c72f2017-12-21 15:59:21 +010071# Note that the output is not saved. You may want to run
72# script -c tests/scripts/all.sh
73# or
74# tests/scripts/all.sh >all.log 2>&1
75#
76# Notes for maintainers
77# ---------------------
78#
Gilles Peskine8f073122018-11-27 15:58:47 +010079# The bulk of the code is organized into functions that follow one of the
80# following naming conventions:
81# * pre_XXX: things to do before running the tests, in order.
82# * component_XXX: independent components. They can be run in any order.
Gilles Peskinec70637a2019-01-09 22:29:17 +010083# * component_check_XXX: quick tests that aren't worth parallelizing.
84# * component_build_XXX: build things but don't run them.
85# * component_test_XXX: build and test.
Gilles Peskine878cf602019-01-06 20:50:38 +000086# * support_XXX: if support_XXX exists and returns false then
87# component_XXX is not run by default.
Gilles Peskine8f073122018-11-27 15:58:47 +010088# * post_XXX: things to do after running the tests.
89# * other: miscellaneous support functions.
90#
Gilles Peskinec70637a2019-01-09 22:29:17 +010091# Each component must start by invoking `msg` with a short informative message.
92#
Gilles Peskinea681c592020-03-28 21:27:40 +010093# Warning: due to the way bash detects errors, the failure of a command
94# inside 'if' or '!' is not detected. Use the 'not' function instead of '!'.
95#
Gilles Peskinece266c42020-03-28 18:50:43 +010096# Each component is executed in a separate shell process. The component
97# fails if any command in it returns a non-zero status.
98#
Gilles Peskinec70637a2019-01-09 22:29:17 +010099# The framework performs some cleanup tasks after each component. This
100# means that components can assume that the working directory is in a
101# cleaned-up state, and don't need to perform the cleanup themselves.
102# * Run `make clean`.
Bence Szépkúti414d6bd2021-06-28 14:11:11 +0100103# * Restore `include/mbedtls/mbedtls_config.h` from a backup made before running
Gilles Peskinec70637a2019-01-09 22:29:17 +0100104# the component.
Gilles Peskine636c26a2020-03-04 20:46:15 +0100105# * Check out `Makefile`, `library/Makefile`, `programs/Makefile`,
106# `tests/Makefile` and `programs/fuzz/Makefile` from git.
107# This cleans up after an in-tree use of CMake.
Gilles Peskinec70637a2019-01-09 22:29:17 +0100108#
Gilles Peskine192c72f2017-12-21 15:59:21 +0100109# The tests are roughly in order from fastest to slowest. This doesn't
110# have to be exact, but in general you should add slower tests towards
111# the end and fast checks near the beginning.
Gilles Peskine192c72f2017-12-21 15:59:21 +0100112
113
114
115################################################################
116#### Initialization and command line parsing
117################################################################
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100118
Gilles Peskine36647802020-03-28 18:50:49 +0100119# Abort on errors (even on the left-hand side of a pipe).
120# Treat uninitialised variables as errors.
121set -e -o pipefail -u
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100122
Gilles Peskine8f073122018-11-27 15:58:47 +0100123pre_check_environment () {
Gilles Peskinea16c2b12019-01-06 19:58:02 +0000124 if [ -d library -a -d include -a -d tests ]; then :; else
Gilles Peskine8f073122018-11-27 15:58:47 +0100125 echo "Must be run from mbed TLS root" >&2
126 exit 1
127 fi
128}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100129
Gilles Peskine8f073122018-11-27 15:58:47 +0100130pre_initialize_variables () {
Bence Szépkútibb0cfeb2021-05-28 09:42:25 +0200131 CONFIG_H='include/mbedtls/mbedtls_config.h'
Gilles Peskine8f073122018-11-27 15:58:47 +0100132 CONFIG_BAK="$CONFIG_H.bak"
John Durkopbd069d32020-10-31 22:14:03 -0700133 CRYPTO_CONFIG_H='include/psa/crypto_config.h'
134 CRYPTO_CONFIG_BAK="$CRYPTO_CONFIG_H.bak"
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200135
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200136 append_outcome=0
Gilles Peskine8f073122018-11-27 15:58:47 +0100137 MEMORY=0
138 FORCE=0
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200139 QUIET=0
Gilles Peskine8f073122018-11-27 15:58:47 +0100140 KEEP_GOING=0
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100141
Manuel Pégourié-Gonnarde0501912020-06-08 12:59:27 +0200142 # Seed value used with the --release-test option.
Manuel Pégourié-Gonnard54304472020-06-22 10:11:47 +0200143 #
144 # See also RELEASE_SEED in basic-build-test.sh. Debugging is easier if
145 # both values are kept in sync. If you change the value here because it
146 # breaks some tests, you'll definitely want to change it in
147 # basic-build-test.sh as well.
Manuel Pégourié-Gonnarde0501912020-06-08 12:59:27 +0200148 RELEASE_SEED=1
149
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200150 : ${MBEDTLS_TEST_OUTCOME_FILE=}
Gilles Peskine9004a172019-09-16 15:20:36 +0200151 : ${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 +0200152 export MBEDTLS_TEST_OUTCOME_FILE
Gilles Peskine9004a172019-09-16 15:20:36 +0200153 export MBEDTLS_TEST_PLATFORM
154
Jaeden Ameroc4cc2512019-01-30 15:35:44 +0000155 # Default commands, can be overridden by the environment
Gilles Peskine8f073122018-11-27 15:58:47 +0100156 : ${OPENSSL:="openssl"}
157 : ${OPENSSL_LEGACY:="$OPENSSL"}
158 : ${OPENSSL_NEXT:="$OPENSSL"}
159 : ${GNUTLS_CLI:="gnutls-cli"}
160 : ${GNUTLS_SERV:="gnutls-serv"}
161 : ${GNUTLS_LEGACY_CLI:="$GNUTLS_CLI"}
162 : ${GNUTLS_LEGACY_SERV:="$GNUTLS_SERV"}
163 : ${OUT_OF_SOURCE_DIR:=./mbedtls_out_of_source_build}
164 : ${ARMC5_BIN_DIR:=/usr/bin}
165 : ${ARMC6_BIN_DIR:=/usr/bin}
Gilles Peskine6d061342020-04-30 18:19:32 +0200166 : ${ARM_NONE_EABI_GCC_PREFIX:=arm-none-eabi-}
Andres AGdc192212016-08-31 17:33:13 +0100167
Gilles Peskine8f073122018-11-27 15:58:47 +0100168 # if MAKEFLAGS is not set add the -j option to speed up invocations of make
Gilles Peskinea1fc4b52019-01-06 20:15:26 +0000169 if [ -z "${MAKEFLAGS+set}" ]; then
Gilles Peskine8f073122018-11-27 15:58:47 +0100170 export MAKEFLAGS="-j"
171 fi
Gilles Peskine878cf602019-01-06 20:50:38 +0000172
Jaeden Amerod48e9c72019-02-07 17:43:39 +0000173 # Include more verbose output for failing tests run by CMake
174 export CTEST_OUTPUT_ON_FAILURE=1
175
Gilles Peskine8fd59422019-10-21 17:11:33 +0200176 # CFLAGS and LDFLAGS for Asan builds that don't use CMake
Gilles Peskine5ca393f2019-10-21 19:06:33 +0200177 ASAN_CFLAGS='-Werror -Wall -Wextra -fsanitize=address,undefined -fno-sanitize-recover=all'
Gilles Peskine8fd59422019-10-21 17:11:33 +0200178
Gilles Peskine878cf602019-01-06 20:50:38 +0000179 # Gather the list of available components. These are the functions
180 # defined in this script whose name starts with "component_".
Gilles Peskine62cf2e82020-03-27 16:35:23 +0100181 # Parse the script with sed. This way we get the functions in the order
182 # they are defined.
Gilles Peskine878cf602019-01-06 20:50:38 +0000183 ALL_COMPONENTS=$(sed -n 's/^ *component_\([0-9A-Z_a-z]*\) *().*/\1/p' <"$0")
184
185 # Exclude components that are not supported on this platform.
186 SUPPORTED_COMPONENTS=
187 for component in $ALL_COMPONENTS; do
188 case $(type "support_$component" 2>&1) in
189 *' function'*)
190 if ! support_$component; then continue; fi;;
191 esac
192 SUPPORTED_COMPONENTS="$SUPPORTED_COMPONENTS $component"
193 done
Gilles Peskine8f073122018-11-27 15:58:47 +0100194}
Andres AG38495a32016-07-12 16:54:33 +0100195
Gilles Peskinea28db922019-01-10 00:05:18 +0100196# Test whether the component $1 is included in the command line patterns.
197is_component_included()
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100198{
199 set -f
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000200 for pattern in $COMMAND_LINE_COMPONENTS; do
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100201 set +f
202 case ${1#component_} in $pattern) return 0;; esac
203 done
204 set +f
205 return 1
206}
Andres AG7770ea82016-10-10 15:46:20 +0100207
Simon Butcher41eeccf2016-09-07 00:07:09 +0100208usage()
Andres AGd9eba4b2016-08-26 14:42:14 +0100209{
Gilles Peskine709346a2017-12-10 23:43:39 +0100210 cat <<EOF
Gilles Peskine92525112018-11-27 18:15:35 +0100211Usage: $0 [OPTION]... [COMPONENT]...
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100212Run mbedtls release validation tests.
Gilles Peskine92525112018-11-27 18:15:35 +0100213By default, run all tests. With one or more COMPONENT, run only those.
Gilles Peskinea28db922019-01-10 00:05:18 +0100214COMPONENT can be the name of a component or a shell wildcard pattern.
215
216Examples:
217 $0 "check_*"
218 Run all sanity checks.
219 $0 --no-armcc --except test_memsan
220 Run everything except builds that require armcc and MemSan.
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100221
222Special options:
223 -h|--help Print this help and exit.
Gilles Peskine878cf602019-01-06 20:50:38 +0000224 --list-all-components List all available test components and exit.
225 --list-components List components supported on this platform and exit.
Gilles Peskine709346a2017-12-10 23:43:39 +0100226
227General options:
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200228 -q|--quiet Only output component names, and errors if any.
Gilles Peskine709346a2017-12-10 23:43:39 +0100229 -f|--force Force the tests to overwrite any modified files.
Gilles Peskine7c652162017-12-11 00:01:40 +0100230 -k|--keep-going Run all tests and report errors at the end.
Gilles Peskine709346a2017-12-10 23:43:39 +0100231 -m|--memory Additional optional memory tests.
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200232 --append-outcome Append to the outcome file (if used).
Gilles Peskine6d061342020-04-30 18:19:32 +0200233 --arm-none-eabi-gcc-prefix=<string>
234 Prefix for a cross-compiler for arm-none-eabi
235 (default: "${ARM_NONE_EABI_GCC_PREFIX}")
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100236 --armcc Run ARM Compiler builds (on by default).
Gilles Peskine5d996822020-03-28 21:09:21 +0100237 --error-test Error test mode: run a failing function in addition
238 to any specified component.
Gilles Peskinea28db922019-01-10 00:05:18 +0100239 --except Exclude the COMPONENTs listed on the command line,
240 instead of running only those.
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200241 --no-append-outcome Write a new outcome file and analyze it (default).
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100242 --no-armcc Skip ARM Compiler builds.
Gilles Peskine38d81652018-03-21 08:40:26 +0100243 --no-force Refuse to overwrite modified files (default).
244 --no-keep-going Stop at the first error (default).
245 --no-memory No additional memory tests (default).
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200246 --no-quiet Print full ouput from components.
Gilles Peskine709346a2017-12-10 23:43:39 +0100247 --out-of-source-dir=<path> Directory used for CMake out-of-source build tests.
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200248 --outcome-file=<path> File where test outcomes are written (not done if
249 empty; default: \$MBEDTLS_TEST_OUTCOME_FILE).
Gilles Peskine38d81652018-03-21 08:40:26 +0100250 --random-seed Use a random seed value for randomized tests (default).
Manuel Pégourié-Gonnarde0501912020-06-08 12:59:27 +0200251 -r|--release-test Run this script in release mode. This fixes the seed value to ${RELEASE_SEED}.
Gilles Peskine709346a2017-12-10 23:43:39 +0100252 -s|--seed Integer seed value to use for this test run.
253
254Tool path options:
255 --armc5-bin-dir=<ARMC5_bin_dir_path> ARM Compiler 5 bin directory.
256 --armc6-bin-dir=<ARMC6_bin_dir_path> ARM Compiler 6 bin directory.
257 --gnutls-cli=<GnuTLS_cli_path> GnuTLS client executable to use for most tests.
258 --gnutls-serv=<GnuTLS_serv_path> GnuTLS server executable to use for most tests.
259 --gnutls-legacy-cli=<GnuTLS_cli_path> GnuTLS client executable to use for legacy tests.
260 --gnutls-legacy-serv=<GnuTLS_serv_path> GnuTLS server executable to use for legacy tests.
261 --openssl=<OpenSSL_path> OpenSSL executable to use for most tests.
Mateusz Starzyk06b07fb2021-02-18 13:55:21 +0100262 --openssl-legacy=<OpenSSL_path> OpenSSL executable to use for legacy tests..
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100263 --openssl-next=<OpenSSL_path> OpenSSL executable to use for recent things like ARIA
Gilles Peskine709346a2017-12-10 23:43:39 +0100264EOF
SimonB2e23c822016-04-16 21:54:39 +0100265}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100266
267# remove built files as well as the cmake cache/config
268cleanup()
269{
Gilles Peskine7c652162017-12-11 00:01:40 +0100270 command make clean
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200271
Gilles Peskine31b07e22018-03-21 12:15:06 +0100272 # Remove CMake artefacts
Jaeden Amero2d0e00f2018-11-07 18:46:41 +0000273 find . -name .git -prune -o \
Gilles Peskine31b07e22018-03-21 12:15:06 +0100274 -iname CMakeFiles -exec rm -rf {} \+ -o \
275 \( -iname cmake_install.cmake -o \
276 -iname CTestTestfile.cmake -o \
Chris Kayd259e342021-03-25 16:03:25 +0000277 -iname CMakeCache.txt \) -exec rm -f {} \+
Gilles Peskine31b07e22018-03-21 12:15:06 +0100278 # Recover files overwritten by in-tree CMake builds
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000279 rm -f include/Makefile include/mbedtls/Makefile programs/*/Makefile
Gilles Peskine636c26a2020-03-04 20:46:15 +0100280 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile
281 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200282
Jaeden Ameroab83fdf2019-06-20 17:38:22 +0100283 # Remove any artifacts from the component_test_cmake_as_subdirectory test.
284 rm -rf programs/test/cmake_subproject/build
285 rm -f programs/test/cmake_subproject/Makefile
286 rm -f programs/test/cmake_subproject/cmake_subproject
287
Chris Kayd259e342021-03-25 16:03:25 +0000288 # Remove any artifacts from the component_test_cmake_as_package test.
289 rm -rf programs/test/cmake_package/build
290 rm -f programs/test/cmake_package/Makefile
291 rm -f programs/test/cmake_package/cmake_package
292
293 # Remove any artifacts from the component_test_cmake_as_installed_package test.
294 rm -rf programs/test/cmake_package_install/build
295 rm -f programs/test/cmake_package_install/Makefile
296 rm -f programs/test/cmake_package_install/cmake_package_install
297
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200298 if [ -f "$CONFIG_BAK" ]; then
299 mv "$CONFIG_BAK" "$CONFIG_H"
300 fi
John Durkopbd069d32020-10-31 22:14:03 -0700301
302 if [ -f "$CRYPTO_CONFIG_BAK" ]; then
303 mv "$CRYPTO_CONFIG_BAK" "$CRYPTO_CONFIG_H"
304 fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100305}
306
Gilles Peskine7c652162017-12-11 00:01:40 +0100307# Executed on exit. May be redefined depending on command line options.
308final_report () {
309 :
310}
311
312fatal_signal () {
313 cleanup
314 final_report $1
315 trap - $1
316 kill -$1 $$
317}
318
319trap 'fatal_signal HUP' HUP
320trap 'fatal_signal INT' INT
321trap 'fatal_signal TERM' TERM
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200322
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100323msg()
324{
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100325 if [ -n "${current_component:-}" ]; then
326 current_section="${current_component#component_}: $1"
327 else
328 current_section="$1"
329 fi
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200330
331 if [ $QUIET -eq 1 ]; then
332 return
333 fi
334
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100335 echo ""
336 echo "******************************************************************"
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100337 echo "* $current_section "
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000338 printf "* "; date
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100339 echo "******************************************************************"
340}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100341
Gilles Peskine8f073122018-11-27 15:58:47 +0100342armc6_build_test()
343{
344 FLAGS="$1"
Andres AGa5cd9732016-10-17 15:23:10 +0100345
Gilles Peskine18487f62020-04-30 23:11:54 +0200346 msg "build: ARM Compiler 6 ($FLAGS)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100347 ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \
348 WARNING_CFLAGS='-xc -std=c99' make lib
Gilles Peskine18487f62020-04-30 23:11:54 +0200349
350 msg "size: ARM Compiler 6 ($FLAGS)"
351 "$ARMC6_FROMELF" -z library/*.o
352
Gilles Peskine8f073122018-11-27 15:58:47 +0100353 make clean
354}
Andres AGa5cd9732016-10-17 15:23:10 +0100355
Andres AGd9eba4b2016-08-26 14:42:14 +0100356err_msg()
357{
358 echo "$1" >&2
359}
360
361check_tools()
362{
363 for TOOL in "$@"; do
Andres AG98393602017-01-31 17:04:45 +0000364 if ! `type "$TOOL" >/dev/null 2>&1`; then
Andres AGd9eba4b2016-08-26 14:42:14 +0100365 err_msg "$TOOL not found!"
366 exit 1
367 fi
368 done
369}
370
Gilles Peskine8f073122018-11-27 15:58:47 +0100371pre_parse_command_line () {
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000372 COMMAND_LINE_COMPONENTS=
Gilles Peskinea28db922019-01-10 00:05:18 +0100373 all_except=0
Gilles Peskine5d996822020-03-28 21:09:21 +0100374 error_test=0
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000375 no_armcc=
SimonB2e23c822016-04-16 21:54:39 +0100376
Jaeden Amero9b90f2e2018-11-02 18:34:17 +0000377 # Note that legacy options are ignored instead of being omitted from this
378 # list of options, so invocations that worked with previous version of
379 # all.sh will still run and work properly.
Gilles Peskine8f073122018-11-27 15:58:47 +0100380 while [ $# -gt 0 ]; do
Gilles Peskine55f7c942019-01-09 22:28:21 +0100381 case "$1" in
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200382 --append-outcome) append_outcome=1;;
Gilles Peskine6d061342020-04-30 18:19:32 +0200383 --arm-none-eabi-gcc-prefix) shift; ARM_NONE_EABI_GCC_PREFIX="$1";;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000384 --armcc) no_armcc=;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100385 --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
386 --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
Gilles Peskine5d996822020-03-28 21:09:21 +0100387 --error-test) error_test=$((error_test + 1));;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000388 --except) all_except=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100389 --force|-f) FORCE=1;;
390 --gnutls-cli) shift; GNUTLS_CLI="$1";;
391 --gnutls-legacy-cli) shift; GNUTLS_LEGACY_CLI="$1";;
392 --gnutls-legacy-serv) shift; GNUTLS_LEGACY_SERV="$1";;
393 --gnutls-serv) shift; GNUTLS_SERV="$1";;
394 --help|-h) usage; exit;;
395 --keep-going|-k) KEEP_GOING=1;;
Gilles Peskine878cf602019-01-06 20:50:38 +0000396 --list-all-components) printf '%s\n' $ALL_COMPONENTS; exit;;
397 --list-components) printf '%s\n' $SUPPORTED_COMPONENTS; exit;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100398 --memory|-m) MEMORY=1;;
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200399 --no-append-outcome) append_outcome=0;;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000400 --no-armcc) no_armcc=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100401 --no-force) FORCE=0;;
402 --no-keep-going) KEEP_GOING=0;;
403 --no-memory) MEMORY=0;;
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200404 --no-quiet) QUIET=0;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100405 --openssl) shift; OPENSSL="$1";;
406 --openssl-legacy) shift; OPENSSL_LEGACY="$1";;
407 --openssl-next) shift; OPENSSL_NEXT="$1";;
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200408 --outcome-file) shift; MBEDTLS_TEST_OUTCOME_FILE="$1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100409 --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200410 --quiet|-q) QUIET=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100411 --random-seed) unset SEED;;
Manuel Pégourié-Gonnarde0501912020-06-08 12:59:27 +0200412 --release-test|-r) SEED=$RELEASE_SEED;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100413 --seed|-s) shift; SEED="$1";;
414 -*)
415 echo >&2 "Unknown option: $1"
416 echo >&2 "Run $0 --help for usage."
417 exit 120
418 ;;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000419 *) COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS $1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100420 esac
421 shift
Gilles Peskine8f073122018-11-27 15:58:47 +0100422 done
SimonB2e23c822016-04-16 21:54:39 +0100423
Gilles Peskinea28db922019-01-10 00:05:18 +0100424 # With no list of components, run everything.
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000425 if [ -z "$COMMAND_LINE_COMPONENTS" ]; then
426 all_except=1
Andres AGdc192212016-08-31 17:33:13 +0100427 fi
428
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000429 # --no-armcc is a legacy option. The modern way is --except '*_armcc*'.
430 # Ignore it if components are listed explicitly on the command line.
Gilles Peskinea28db922019-01-10 00:05:18 +0100431 if [ -n "$no_armcc" ] && [ $all_except -eq 1 ]; then
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000432 COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS *_armcc*"
SimonB2e23c822016-04-16 21:54:39 +0100433 fi
SimonB2e23c822016-04-16 21:54:39 +0100434
Gilles Peskineb80f0d22020-03-28 21:37:59 +0100435 if [ $all_except -eq 0 ]; then
436 unsupported=0
437 for component in $COMMAND_LINE_COMPONENTS; do
438 case $component in
439 *[*?\[]*) continue;;
440 esac
441 case " $SUPPORTED_COMPONENTS " in
442 *" $component "*) :;;
443 *)
444 echo >&2 "Component $component was explicitly requested, but is not known or not supported."
445 unsupported=$((unsupported + 1));;
446 esac
447 done
448 if [ $unsupported -ne 0 ]; then
449 exit 2
450 fi
451 fi
452
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000453 # Build the list of components to run.
Gilles Peskinea28db922019-01-10 00:05:18 +0100454 RUN_COMPONENTS=
455 for component in $SUPPORTED_COMPONENTS; do
456 if is_component_included "$component"; [ $? -eq $all_except ]; then
457 RUN_COMPONENTS="$RUN_COMPONENTS $component"
458 fi
459 done
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000460
461 unset all_except
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000462 unset no_armcc
Gilles Peskine8f073122018-11-27 15:58:47 +0100463}
SimonB2e23c822016-04-16 21:54:39 +0100464
Gilles Peskine8f073122018-11-27 15:58:47 +0100465pre_check_git () {
466 if [ $FORCE -eq 1 ]; then
Gilles Peskine53190e62019-01-09 23:17:35 +0100467 rm -rf "$OUT_OF_SOURCE_DIR"
Gilles Peskine8f073122018-11-27 15:58:47 +0100468 git checkout-index -f -q $CONFIG_H
469 cleanup
470 else
SimonB2e23c822016-04-16 21:54:39 +0100471
Gilles Peskine8f073122018-11-27 15:58:47 +0100472 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
473 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
474 echo "You can either delete this directory manually, or force the test by rerunning"
475 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
476 exit 1
477 fi
478
Bence Szépkútibb0cfeb2021-05-28 09:42:25 +0200479 if ! git diff --quiet include/mbedtls/mbedtls_config.h; then
480 err_msg "Warning - the configuration file 'include/mbedtls/mbedtls_config.h' has been edited. "
Gilles Peskine8f073122018-11-27 15:58:47 +0100481 echo "You can either delete or preserve your work, or force the test by rerunning the"
482 echo "script as: $0 --force"
483 exit 1
484 fi
SimonB2e23c822016-04-16 21:54:39 +0100485 fi
Andrzej Kurekeb508712019-02-14 07:18:59 -0500486}
487
Gilles Peskine8f073122018-11-27 15:58:47 +0100488pre_setup_keep_going () {
Gilles Peskinece266c42020-03-28 18:50:43 +0100489 failure_count=0 # Number of failed components
490 last_failure_status=0 # Last failure status in this component
491
Gilles Peskinefec30cb2020-03-28 19:34:23 +0100492 # See err_trap
493 previous_failure_status=0
494 previous_failed_command=
495 previous_failure_funcall_depth=0
Gilles Peskinea681c592020-03-28 21:27:40 +0100496 unset report_failed_command
Gilles Peskinefec30cb2020-03-28 19:34:23 +0100497
Gilles Peskine7c652162017-12-11 00:01:40 +0100498 start_red=
499 end_color=
500 if [ -t 1 ]; then
Gilles Peskine9736b9d2018-01-02 21:54:17 +0100501 case "${TERM:-}" in
Gilles Peskine7c652162017-12-11 00:01:40 +0100502 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
503 start_red=$(printf '\033[31m')
504 end_color=$(printf '\033[0m')
505 ;;
506 esac
507 fi
Gilles Peskinece266c42020-03-28 18:50:43 +0100508
509 # Keep a summary of failures in a file. We'll print it out at the end.
510 failure_summary_file=$PWD/all-sh-failures-$$.log
511 : >"$failure_summary_file"
512
513 # Whether it makes sense to keep a component going after the specified
514 # command fails (test command) or not (configure or build).
515 # This doesn't have to be 100% accurate: all failures are recorded anyway.
516 can_keep_going_after_failure () {
517 case "$1" in
518 "msg "*) false;;
519 *[!A-Za-z]"test"|*[!A-Za-z]"test"[!A-Za-z]*) true;;
520 "tests/"*) true;;
Gilles Peskinea681c592020-03-28 21:27:40 +0100521 "grep "*|"! grep "*) true;;
Gilles Peskineaca0b322020-04-20 13:21:27 +0200522 "test "*|"[ "*) true;;
Gilles Peskinece266c42020-03-28 18:50:43 +0100523 *) false;;
Gilles Peskine7c652162017-12-11 00:01:40 +0100524 esac
525 }
Gilles Peskinece266c42020-03-28 18:50:43 +0100526
527 # This function runs if there is any error in a component.
528 # It must either exit with a nonzero status, or set
529 # last_failure_status to a nonzero value.
530 err_trap () {
531 # Save $? (status of the failing command). This must be the very
532 # first thing, before $? is overridden.
533 last_failure_status=$?
Gilles Peskinea681c592020-03-28 21:27:40 +0100534 failed_command=${report_failed_command-$BASH_COMMAND}
Gilles Peskinece266c42020-03-28 18:50:43 +0100535
Gilles Peskinefec30cb2020-03-28 19:34:23 +0100536 if [[ $last_failure_status -eq $previous_failure_status &&
537 "$failed_command" == "$previous_failed_command" &&
538 ${#FUNCNAME[@]} == $((previous_failure_funcall_depth - 1)) ]]
539 then
540 # The same command failed twice in a row, but this time one level
541 # less deep in the function call stack. This happens when the last
542 # command of a function returns a nonzero status, and the function
543 # returns that same status. Ignore the second failure.
544 previous_failure_funcall_depth=${#FUNCNAME[@]}
545 return
546 fi
547 previous_failure_status=$last_failure_status
548 previous_failed_command=$failed_command
549 previous_failure_funcall_depth=${#FUNCNAME[@]}
550
Gilles Peskinece266c42020-03-28 18:50:43 +0100551 text="$current_section: $failed_command -> $last_failure_status"
552 echo "${start_red}^^^^$text^^^^${end_color}" >&2
553 echo "$text" >>"$failure_summary_file"
554
555 # If the command is fatal (configure or build command), stop this
556 # component. Otherwise (test command) keep the component running
557 # (run more tests from the same build).
558 if ! can_keep_going_after_failure "$failed_command"; then
559 exit $last_failure_status
560 fi
561 }
562
Gilles Peskine7c652162017-12-11 00:01:40 +0100563 final_report () {
564 if [ $failure_count -gt 0 ]; then
565 echo
566 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Gilles Peskinece266c42020-03-28 18:50:43 +0100567 echo "${start_red}FAILED: $failure_count components${end_color}"
568 cat "$failure_summary_file"
Gilles Peskine7c652162017-12-11 00:01:40 +0100569 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
570 elif [ -z "${1-}" ]; then
571 echo "SUCCESS :)"
572 fi
573 if [ -n "${1-}" ]; then
574 echo "Killed by SIG$1."
575 fi
Gilles Peskinece266c42020-03-28 18:50:43 +0100576 rm -f "$failure_summary_file"
577 if [ $failure_count -gt 0 ]; then
578 exit 1
579 fi
Gilles Peskine7c652162017-12-11 00:01:40 +0100580 }
Gilles Peskine8f073122018-11-27 15:58:47 +0100581}
582
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200583# record_status() and if_build_succeeded() are kept temporarily for backward
584# compatibility. Don't use them in new components.
Gilles Peskinece266c42020-03-28 18:50:43 +0100585record_status () {
586 "$@"
Gilles Peskine7c652162017-12-11 00:01:40 +0100587}
Gilles Peskinece266c42020-03-28 18:50:43 +0100588if_build_succeeded () {
589 "$@"
590}
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200591
Gilles Peskinea681c592020-03-28 21:27:40 +0100592# '! true' does not trigger the ERR trap. Arrange to trigger it, with
593# a reasonably informative error message (not just "$@").
594not () {
595 if "$@"; then
596 report_failed_command="! $*"
597 false
598 unset report_failed_command
599 fi
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200600}
601
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200602pre_prepare_outcome_file () {
603 case "$MBEDTLS_TEST_OUTCOME_FILE" in
604 [!/]*) MBEDTLS_TEST_OUTCOME_FILE="$PWD/$MBEDTLS_TEST_OUTCOME_FILE";;
605 esac
606 if [ -n "$MBEDTLS_TEST_OUTCOME_FILE" ] && [ "$append_outcome" -eq 0 ]; then
607 rm -f "$MBEDTLS_TEST_OUTCOME_FILE"
608 fi
609}
610
Gilles Peskine8f073122018-11-27 15:58:47 +0100611pre_print_configuration () {
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200612 if [ $QUIET -eq 1 ]; then
613 return
614 fi
615
Gilles Peskine8f073122018-11-27 15:58:47 +0100616 msg "info: $0 configuration"
617 echo "MEMORY: $MEMORY"
618 echo "FORCE: $FORCE"
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200619 echo "MBEDTLS_TEST_OUTCOME_FILE: ${MBEDTLS_TEST_OUTCOME_FILE:-(none)}"
Gilles Peskine8f073122018-11-27 15:58:47 +0100620 echo "SEED: ${SEED-"UNSET"}"
Gilles Peskine636c26a2020-03-04 20:46:15 +0100621 echo
Gilles Peskine8f073122018-11-27 15:58:47 +0100622 echo "OPENSSL: $OPENSSL"
623 echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
624 echo "OPENSSL_NEXT: $OPENSSL_NEXT"
625 echo "GNUTLS_CLI: $GNUTLS_CLI"
626 echo "GNUTLS_SERV: $GNUTLS_SERV"
627 echo "GNUTLS_LEGACY_CLI: $GNUTLS_LEGACY_CLI"
628 echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV"
629 echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
630 echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
631}
Andres AG7770ea82016-10-10 15:46:20 +0100632
Andres AGd9eba4b2016-08-26 14:42:14 +0100633# Make sure the tools we need are available.
Gilles Peskine8f073122018-11-27 15:58:47 +0100634pre_check_tools () {
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000635 # Build the list of variables to pass to output_env.sh.
636 set env
SimonB2e23c822016-04-16 21:54:39 +0100637
Gilles Peskine87964262019-01-06 22:40:00 +0000638 case " $RUN_COMPONENTS " in
639 # Require OpenSSL and GnuTLS if running any tests (as opposed to
640 # only doing builds). Not all tests run OpenSSL and GnuTLS, but this
641 # is a good enough approximation in practice.
642 *" test_"*)
643 # To avoid setting OpenSSL and GnuTLS for each call to compat.sh
644 # and ssl-opt.sh, we just export the variables they require.
645 export OPENSSL_CMD="$OPENSSL"
646 export GNUTLS_CLI="$GNUTLS_CLI"
647 export GNUTLS_SERV="$GNUTLS_SERV"
648 # Avoid passing --seed flag in every call to ssl-opt.sh
649 if [ -n "${SEED-}" ]; then
650 export SEED
651 fi
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000652 set "$@" OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY"
653 set "$@" GNUTLS_CLI="$GNUTLS_CLI" GNUTLS_SERV="$GNUTLS_SERV"
654 set "$@" GNUTLS_LEGACY_CLI="$GNUTLS_LEGACY_CLI"
655 set "$@" GNUTLS_LEGACY_SERV="$GNUTLS_LEGACY_SERV"
Gilles Peskine87964262019-01-06 22:40:00 +0000656 check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$OPENSSL_NEXT" \
657 "$GNUTLS_CLI" "$GNUTLS_SERV" \
658 "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV"
659 ;;
660 esac
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200661
Gilles Peskine87964262019-01-06 22:40:00 +0000662 case " $RUN_COMPONENTS " in
663 *_doxygen[_\ ]*) check_tools "doxygen" "dot";;
664 esac
Andres AGd9eba4b2016-08-26 14:42:14 +0100665
Gilles Peskine87964262019-01-06 22:40:00 +0000666 case " $RUN_COMPONENTS " in
Gilles Peskine6d061342020-04-30 18:19:32 +0200667 *_arm_none_eabi_gcc[_\ ]*) check_tools "${ARM_NONE_EABI_GCC_PREFIX}gcc";;
Gilles Peskine87964262019-01-06 22:40:00 +0000668 esac
Andres AGd9eba4b2016-08-26 14:42:14 +0100669
Gilles Peskine87964262019-01-06 22:40:00 +0000670 case " $RUN_COMPONENTS " in
671 *_mingw[_\ ]*) check_tools "i686-w64-mingw32-gcc";;
672 esac
673
674 case " $RUN_COMPONENTS " in
675 *" test_zeroize "*) check_tools "gdb";;
676 esac
677
678 case " $RUN_COMPONENTS " in
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000679 *_armcc*)
Gilles Peskine87964262019-01-06 22:40:00 +0000680 ARMC5_CC="$ARMC5_BIN_DIR/armcc"
681 ARMC5_AR="$ARMC5_BIN_DIR/armar"
Gilles Peskine18487f62020-04-30 23:11:54 +0200682 ARMC5_FROMELF="$ARMC5_BIN_DIR/fromelf"
Gilles Peskine87964262019-01-06 22:40:00 +0000683 ARMC6_CC="$ARMC6_BIN_DIR/armclang"
684 ARMC6_AR="$ARMC6_BIN_DIR/armar"
Gilles Peskine18487f62020-04-30 23:11:54 +0200685 ARMC6_FROMELF="$ARMC6_BIN_DIR/fromelf"
686 check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC5_FROMELF" \
687 "$ARMC6_CC" "$ARMC6_AR" "$ARMC6_FROMELF";;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000688 esac
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000689
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200690 # past this point, no call to check_tool, only printing output
691 if [ $QUIET -eq 1 ]; then
692 return
693 fi
694
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000695 msg "info: output_env.sh"
696 case $RUN_COMPONENTS in
697 *_armcc*)
698 set "$@" ARMC5_CC="$ARMC5_CC" ARMC6_CC="$ARMC6_CC" RUN_ARMCC=1;;
699 *) set "$@" RUN_ARMCC=0;;
700 esac
701 "$@" scripts/output_env.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100702}
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100703
Gilles Peskine1570b592021-04-22 01:10:12 +0200704pre_generate_files() {
Manuel Pégourié-Gonnard87db8a22021-06-18 13:30:14 +0200705 # since make doesn't have proper dependencies, remove any possibly outdate
706 # file that might be around before generating fresh ones
707 make neat
Gilles Peskine72385032021-07-08 19:07:07 +0200708 if [ $QUIET -eq 1 ]; then
709 make -s generated_files
710 else
711 make generated_files
712 fi
Gilles Peskine1570b592021-04-22 01:10:12 +0200713}
714
Gilles Peskine192c72f2017-12-21 15:59:21 +0100715
716
717################################################################
718#### Basic checks
719################################################################
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100720
721#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200722# Test Suites to be executed
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100723#
Manuel Pégourié-Gonnard3d404b42015-07-08 21:59:16 +0100724# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200725# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100726# 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 +0200727# time, so start with a GCC build).
728# 2. Minimize total running time, by avoiding useless rebuilds
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100729#
Manuel Pégourié-Gonnard259b08a2016-01-08 16:27:41 +0100730# Indicative running times are given for reference.
731
Gilles Peskine8f073122018-11-27 15:58:47 +0100732component_check_recursion () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200733 msg "Check: recursion.pl" # < 1s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200734 tests/scripts/recursion.pl library/*.c
Gilles Peskine8f073122018-11-27 15:58:47 +0100735}
Janos Follathb72c6782016-07-19 14:54:17 +0100736
Gilles Peskine67debb62021-05-18 16:09:50 +0200737component_check_generated_files () {
738 msg "Check: check-generated-files, files generated with make" # 2s
739 make generated_files
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200740 tests/scripts/check-generated-files.sh
Gilles Peskine67debb62021-05-18 16:09:50 +0200741
742 msg "Check: check-generated-files -u, files present" # 2s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200743 tests/scripts/check-generated-files.sh -u
Gilles Peskine67debb62021-05-18 16:09:50 +0200744 # Check that the generated files are considered up to date.
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200745 tests/scripts/check-generated-files.sh
Gilles Peskine67debb62021-05-18 16:09:50 +0200746
747 msg "Check: check-generated-files -u, files absent" # 2s
748 command make neat
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200749 tests/scripts/check-generated-files.sh -u
Gilles Peskine67debb62021-05-18 16:09:50 +0200750 # Check that the generated files are considered up to date.
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200751 tests/scripts/check-generated-files.sh
Gilles Peskine67debb62021-05-18 16:09:50 +0200752
753 # This component ends with the generated files present in the source tree.
754 # This is necessary for subsequent components!
755}
756
Gilles Peskine8f073122018-11-27 15:58:47 +0100757component_check_doxy_blocks () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200758 msg "Check: doxygen markup outside doxygen blocks" # < 1s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200759 tests/scripts/check-doxy-blocks.pl
Gilles Peskine8f073122018-11-27 15:58:47 +0100760}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200761
Gilles Peskine8f073122018-11-27 15:58:47 +0100762component_check_files () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200763 msg "Check: file sanity checks (permissions, encodings)" # < 1s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200764 tests/scripts/check_files.py
Gilles Peskine8f073122018-11-27 15:58:47 +0100765}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200766
Gilles Peskine30e0bb42020-05-10 17:40:49 +0200767component_check_changelog () {
768 msg "Check: changelog entries" # < 1s
769 rm -f ChangeLog.new
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200770 scripts/assemble_changelog.py -o ChangeLog.new
Gilles Peskine30e0bb42020-05-10 17:40:49 +0200771 if [ -e ChangeLog.new ]; then
772 # Show the diff for information. It isn't an error if the diff is
773 # non-empty.
774 diff -u ChangeLog ChangeLog.new || true
775 rm ChangeLog.new
776 fi
777}
778
Gilles Peskine8f073122018-11-27 15:58:47 +0100779component_check_names () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200780 msg "Check: declared and exported names (builds the library)" # < 3s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200781 tests/scripts/check-names.sh -v
Gilles Peskine8f073122018-11-27 15:58:47 +0100782}
Darryl Greena07039c2018-03-13 16:48:16 +0000783
Gilles Peskine895868b2019-09-19 21:30:05 +0200784component_check_test_cases () {
785 msg "Check: test case descriptions" # < 1s
Manuel Pégourié-Gonnarda9119162020-06-02 11:51:40 +0200786 if [ $QUIET -eq 1 ]; then
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +0200787 opt='--quiet'
Manuel Pégourié-Gonnarda9119162020-06-02 11:51:40 +0200788 else
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +0200789 opt=''
Manuel Pégourié-Gonnarda9119162020-06-02 11:51:40 +0200790 fi
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200791 tests/scripts/check_test_cases.py $opt
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +0200792 unset opt
Gilles Peskine895868b2019-09-19 21:30:05 +0200793}
794
Gilles Peskine8f073122018-11-27 15:58:47 +0100795component_check_doxygen_warnings () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200796 msg "Check: doxygen warnings (builds the documentation)" # ~ 3s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200797 tests/scripts/doxygen.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100798}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200799
Gilles Peskine192c72f2017-12-21 15:59:21 +0100800
Gilles Peskine636c26a2020-03-04 20:46:15 +0100801
Gilles Peskine192c72f2017-12-21 15:59:21 +0100802################################################################
803#### Build and test many configurations and targets
804################################################################
805
Gilles Peskine7832c9f2019-04-08 17:00:15 +0200806component_test_default_out_of_box () {
807 msg "build: make, default config (out-of-box)" # ~1min
808 make
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200809 # Disable fancy stuff
Gilles Peskine717cd762019-09-27 20:21:11 +0200810 SAVE_MBEDTLS_TEST_OUTCOME_FILE="$MBEDTLS_TEST_OUTCOME_FILE"
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200811 unset MBEDTLS_TEST_OUTCOME_FILE
Gilles Peskine7832c9f2019-04-08 17:00:15 +0200812
813 msg "test: main suites make, default config (out-of-box)" # ~10s
814 make test
815
816 msg "selftest: make, default config (out-of-box)" # ~10s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200817 programs/test/selftest
Gilles Peskine717cd762019-09-27 20:21:11 +0200818
819 export MBEDTLS_TEST_OUTCOME_FILE="$SAVE_MBEDTLS_TEST_OUTCOME_FILE"
820 unset SAVE_MBEDTLS_TEST_OUTCOME_FILE
Gilles Peskine7832c9f2019-04-08 17:00:15 +0200821}
822
Gilles Peskine8f073122018-11-27 15:58:47 +0100823component_test_default_cmake_gcc_asan () {
824 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100825 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
826 make
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200827
Gilles Peskine8f073122018-11-27 15:58:47 +0100828 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
829 make test
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200830
Gilles Peskine97bea012020-04-23 23:37:45 +0200831 msg "test: selftest (ASan build)" # ~ 10s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200832 programs/test/selftest
Gilles Peskine97bea012020-04-23 23:37:45 +0200833
Gilles Peskine8f073122018-11-27 15:58:47 +0100834 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200835 tests/ssl-opt.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200836
Gilles Peskine8f073122018-11-27 15:58:47 +0100837 msg "test: compat.sh (ASan build)" # ~ 6 min
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200838 tests/compat.sh
Piotr Nowicki9978e6e2020-04-07 16:07:05 +0200839
840 msg "test: context-info.sh (ASan build)" # ~ 15 sec
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200841 tests/context-info.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100842}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200843
Hanno Becker01635512019-02-26 14:27:09 +0000844component_test_full_cmake_gcc_asan () {
845 msg "build: full config, cmake, gcc, ASan"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200846 scripts/config.py full
Hanno Becker01635512019-02-26 14:27:09 +0000847 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
848 make
849
850 msg "test: main suites (inc. selftests) (full config, ASan build)"
851 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +0100852
Gilles Peskine97bea012020-04-23 23:37:45 +0200853 msg "test: selftest (ASan build)" # ~ 10s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200854 programs/test/selftest
Gilles Peskine97bea012020-04-23 23:37:45 +0200855
Gilles Peskine636c26a2020-03-04 20:46:15 +0100856 msg "test: ssl-opt.sh (full config, ASan build)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200857 tests/ssl-opt.sh
Gilles Peskine636c26a2020-03-04 20:46:15 +0100858
859 msg "test: compat.sh (full config, ASan build)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200860 tests/compat.sh
Piotr Nowicki9978e6e2020-04-07 16:07:05 +0200861
862 msg "test: context-info.sh (full config, ASan build)" # ~ 15 sec
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200863 tests/context-info.sh
Gilles Peskine636c26a2020-03-04 20:46:15 +0100864}
865
Ronald Cronc3623db2020-10-29 10:51:32 +0100866component_test_psa_crypto_key_id_encodes_owner () {
867 msg "build: full config - USE_PSA_CRYPTO + PSA_CRYPTO_KEY_ID_ENCODES_OWNER, cmake, gcc, ASan"
868 scripts/config.py full
869 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
870 scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
871 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
872 make
873
874 msg "test: full config - USE_PSA_CRYPTO + PSA_CRYPTO_KEY_ID_ENCODES_OWNER, cmake, gcc, ASan"
875 make test
876}
877
Gilles Peskinea3548672021-06-17 11:37:52 +0200878# check_renamed_symbols HEADER LIB
879# Check that if HEADER contains '#define MACRO ...' then MACRO is not a symbol
880# name is LIB.
881check_renamed_symbols () {
882 ! nm "$2" | sed 's/.* //' |
883 grep -x -F "$(sed -n 's/^ *# *define *\([A-Z_a-z][0-9A-Z_a-z]*\)..*/\1/p' "$1")"
884}
885
Gilles Peskined1dcfd52021-06-15 18:37:38 +0200886component_build_psa_crypto_spm () {
887 msg "build: full config - USE_PSA_CRYPTO + PSA_CRYPTO_KEY_ID_ENCODES_OWNER + PSA_CRYPTO_SPM, make, gcc"
888 scripts/config.py full
889 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
890 scripts/config.py unset MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS
891 scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
892 scripts/config.py set MBEDTLS_PSA_CRYPTO_SPM
893 # We can only compile, not link, since our test and sample programs
894 # aren't equipped for the modified names used when MBEDTLS_PSA_CRYPTO_SPM
895 # is active.
896 make CC=gcc CFLAGS='-Werror -Wall -Wextra -I../tests/include/spe' lib
Gilles Peskinea3548672021-06-17 11:37:52 +0200897
898 # Check that if a symbol is renamed by crypto_spe.h, the non-renamed
899 # version is not present.
900 echo "Checking for renamed symbols in the library"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200901 check_renamed_symbols tests/include/spe/crypto_spe.h library/libmbedcrypto.a
Gilles Peskined1dcfd52021-06-15 18:37:38 +0200902}
903
Ronald Cron336678b2021-01-28 17:54:24 +0100904component_test_psa_crypto_client () {
905 msg "build: default config - PSA_CRYPTO_C + PSA_CRYPTO_CLIENT, make"
906 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C
907 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
908 scripts/config.py set MBEDTLS_PSA_CRYPTO_CLIENT
909 make
910
911 msg "test: default config - PSA_CRYPTO_C + PSA_CRYPTO_CLIENT, make"
912 make test
913}
914
Jaeden Amero424fa932021-05-14 08:34:32 +0100915component_test_psa_crypto_rsa_no_genprime() {
916 msg "build: default config minus MBEDTLS_GENPRIME"
917 scripts/config.py unset MBEDTLS_GENPRIME
918 make
919
920 msg "test: default config minus MBEDTLS_GENPRIME"
921 make test
922}
923
Gilles Peskine782f4112018-11-27 16:11:09 +0100924component_test_ref_configs () {
925 msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
926 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200927 tests/scripts/test-ref-configs.pl
Gilles Peskine782f4112018-11-27 16:11:09 +0100928}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200929
Gilles Peskine8f073122018-11-27 15:58:47 +0100930component_test_no_renegotiation () {
931 msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200932 scripts/config.py unset MBEDTLS_SSL_RENEGOTIATION
Gilles Peskine8f073122018-11-27 15:58:47 +0100933 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
934 make
Simon Butcher3ea7f522016-03-07 23:22:10 +0000935
Gilles Peskine8f073122018-11-27 15:58:47 +0100936 msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
937 make test
Hanno Becker134c2ab2017-10-12 15:29:50 +0100938
Gilles Peskine8f073122018-11-27 15:58:47 +0100939 msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200940 tests/ssl-opt.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100941}
Hanno Becker134c2ab2017-10-12 15:29:50 +0100942
Gilles Peskine636c26a2020-03-04 20:46:15 +0100943component_test_no_pem_no_fs () {
944 msg "build: Default + !MBEDTLS_PEM_PARSE_C + !MBEDTLS_FS_IO (ASan build)"
945 scripts/config.py unset MBEDTLS_PEM_PARSE_C
946 scripts/config.py unset MBEDTLS_FS_IO
947 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C # requires a filesystem
948 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA ITS
949 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
950 make
951
952 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - main suites (inc. selftests) (ASan build)" # ~ 50s
953 make test
954
955 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - ssl-opt.sh (ASan build)" # ~ 6 min
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200956 tests/ssl-opt.sh
Gilles Peskine636c26a2020-03-04 20:46:15 +0100957}
958
Gilles Peskine8f073122018-11-27 15:58:47 +0100959component_test_rsa_no_crt () {
960 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200961 scripts/config.py set MBEDTLS_RSA_NO_CRT
Gilles Peskine8f073122018-11-27 15:58:47 +0100962 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
963 make
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +0100964
Gilles Peskine8f073122018-11-27 15:58:47 +0100965 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
966 make test
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100967
Gilles Peskine8f073122018-11-27 15:58:47 +0100968 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200969 tests/ssl-opt.sh -f RSA
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100970
Gilles Peskine8f073122018-11-27 15:58:47 +0100971 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200972 tests/compat.sh -t RSA
Piotr Nowicki9978e6e2020-04-07 16:07:05 +0200973
974 msg "test: RSA_NO_CRT - RSA-related part of context-info.sh (ASan build)" # ~ 15 sec
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200975 tests/context-info.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100976}
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100977
Gilles Peskine2747d7d2021-02-03 14:56:51 +0100978component_test_no_ctr_drbg_classic () {
979 msg "build: Full minus CTR_DRBG, classic crypto in TLS"
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +0200980 scripts/config.py full
981 scripts/config.py unset MBEDTLS_CTR_DRBG_C
Gilles Peskine2747d7d2021-02-03 14:56:51 +0100982 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +0200983
984 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
985 make
986
Gilles Peskine2747d7d2021-02-03 14:56:51 +0100987 msg "test: Full minus CTR_DRBG, classic crypto - main suites"
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +0200988 make test
989
Gilles Peskineba749042021-01-13 20:02:03 +0100990 # In this configuration, the TLS test programs use HMAC_DRBG.
991 # The SSL tests are slow, so run a small subset, just enough to get
992 # confidence that the SSL code copes with HMAC_DRBG.
Gilles Peskine2747d7d2021-02-03 14:56:51 +0100993 msg "test: Full minus CTR_DRBG, classic crypto - ssl-opt.sh (subset)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200994 tests/ssl-opt.sh -f 'Default\|SSL async private.*delay=\|tickets enabled on server'
Gilles Peskineba749042021-01-13 20:02:03 +0100995
Gilles Peskine2747d7d2021-02-03 14:56:51 +0100996 msg "test: Full minus CTR_DRBG, classic crypto - compat.sh (subset)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200997 tests/compat.sh -m tls1_2 -t 'ECDSA PSK' -V NO -p OpenSSL
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +0200998}
999
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001000component_test_no_ctr_drbg_use_psa () {
1001 msg "build: Full minus CTR_DRBG, PSA crypto in TLS"
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +02001002 scripts/config.py full
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001003 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1004 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +02001005
1006 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1007 make
1008
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001009 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - main suites"
1010 make test
1011
1012 # In this configuration, the TLS test programs use HMAC_DRBG.
1013 # The SSL tests are slow, so run a small subset, just enough to get
1014 # confidence that the SSL code copes with HMAC_DRBG.
1015 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - ssl-opt.sh (subset)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001016 tests/ssl-opt.sh -f 'Default\|SSL async private.*delay=\|tickets enabled on server'
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001017
1018 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - compat.sh (subset)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001019 tests/compat.sh -m tls1_2 -t 'ECDSA PSK' -V NO -p OpenSSL
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001020}
1021
1022component_test_no_hmac_drbg_classic () {
1023 msg "build: Full minus HMAC_DRBG, classic crypto in TLS"
1024 scripts/config.py full
1025 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1026 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1027 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1028
1029 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1030 make
1031
1032 msg "test: Full minus HMAC_DRBG, classic crypto - main suites"
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +02001033 make test
1034
Gilles Peskinea2224342020-11-19 22:14:34 +01001035 # Normally our ECDSA implementation uses deterministic ECDSA. But since
1036 # HMAC_DRBG is disabled in this configuration, randomized ECDSA is used
1037 # instead.
1038 # Test SSL with non-deterministic ECDSA. Only test features that
1039 # might be affected by how ECDSA signature is performed.
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001040 msg "test: Full minus HMAC_DRBG, classic crypto - ssl-opt.sh (subset)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001041 tests/ssl-opt.sh -f 'Default\|SSL async private: sign'
Gilles Peskinea2224342020-11-19 22:14:34 +01001042
1043 # To save time, only test one protocol version, since this part of
1044 # the protocol is identical in (D)TLS up to 1.2.
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001045 msg "test: Full minus HMAC_DRBG, classic crypto - compat.sh (ECDSA)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001046 tests/compat.sh -m tls1_2 -t 'ECDSA'
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +02001047}
1048
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001049component_test_no_hmac_drbg_use_psa () {
1050 msg "build: Full minus HMAC_DRBG, PSA crypto in TLS"
1051 scripts/config.py full
1052 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1053 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1054 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1055
1056 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1057 make
1058
1059 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - main suites"
1060 make test
1061
1062 # Normally our ECDSA implementation uses deterministic ECDSA. But since
1063 # HMAC_DRBG is disabled in this configuration, randomized ECDSA is used
1064 # instead.
1065 # Test SSL with non-deterministic ECDSA. Only test features that
1066 # might be affected by how ECDSA signature is performed.
1067 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - ssl-opt.sh (subset)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001068 tests/ssl-opt.sh -f 'Default\|SSL async private: sign'
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001069
1070 # To save time, only test one protocol version, since this part of
1071 # the protocol is identical in (D)TLS up to 1.2.
1072 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - compat.sh (ECDSA)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001073 tests/compat.sh -m tls1_2 -t 'ECDSA'
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001074}
1075
1076component_test_psa_external_rng_no_drbg_classic () {
1077 msg "build: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto in TLS"
1078 scripts/config.py full
1079 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1080 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
Gilles Peskine38c12fd2021-02-08 21:02:53 +01001081 scripts/config.py unset MBEDTLS_ENTROPY_C
1082 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
1083 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001084 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1085 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1086 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
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)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001096 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
Gilles Peskinec109b372020-11-23 17:39:04 +01001109 make CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
1110
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001111 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto - main suites"
Gilles Peskinec109b372020-11-23 17:39:04 +01001112 make test
1113
Gilles Peskine8eb29432021-02-03 20:07:11 +01001114 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto - ssl-opt.sh (subset)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001115 tests/ssl-opt.sh -f 'Default\|opaque'
Gilles Peskinec109b372020-11-23 17:39:04 +01001116}
1117
1118component_test_psa_external_rng_use_psa_crypto () {
1119 msg "build: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
1120 scripts/config.py full
1121 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
1122 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1123 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1124 make CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
1125
1126 msg "test: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
1127 make test
1128
Gilles Peskineba749042021-01-13 20:02:03 +01001129 msg "test: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001130 tests/ssl-opt.sh -f 'Default\|opaque'
Gilles Peskinec109b372020-11-23 17:39:04 +01001131}
1132
Gilles Peskine636c26a2020-03-04 20:46:15 +01001133component_test_everest () {
1134 msg "build: Everest ECDH context (ASan build)" # ~ 6 min
Gilles Peskine636c26a2020-03-04 20:46:15 +01001135 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
1136 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Asan .
1137 make
1138
1139 msg "test: Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
1140 make test
1141
1142 msg "test: Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001143 tests/ssl-opt.sh -f ECDH
Gilles Peskine636c26a2020-03-04 20:46:15 +01001144
1145 msg "test: Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
1146 # Exclude some symmetric ciphers that are redundant here to gain time.
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001147 tests/compat.sh -f ECDH -V NO -e 'ARIA\|CAMELLIA\|CHACHA\|DES'
Gilles Peskine636c26a2020-03-04 20:46:15 +01001148}
1149
Gilles Peskined3beca92020-07-03 00:15:37 +02001150component_test_everest_curve25519_only () {
1151 msg "build: Everest ECDH context, only Curve25519" # ~ 6 min
Gilles Peskined3beca92020-07-03 00:15:37 +02001152 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
1153 scripts/config.py unset MBEDTLS_ECDSA_C
1154 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
1155 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
TRodziewicz7c1d41d2021-04-23 13:33:44 +02001156 scripts/config.py unset MBEDTLS_ECJPAKE_C
Gilles Peskined3beca92020-07-03 00:15:37 +02001157 # Disable all curves
1158 for c in $(sed -n 's/#define \(MBEDTLS_ECP_DP_[0-9A-Z_a-z]*_ENABLED\).*/\1/p' <"$CONFIG_H"); do
1159 scripts/config.py unset "$c"
1160 done
1161 scripts/config.py set MBEDTLS_ECP_DP_CURVE25519_ENABLED
1162
1163 make CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
1164
1165 msg "test: Everest ECDH context, only Curve25519" # ~ 50s
1166 make test
1167}
1168
Gilles Peskine8f073122018-11-27 15:58:47 +01001169component_test_small_ssl_out_content_len () {
1170 msg "build: small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001171 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 16384
1172 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
Gilles Peskine8f073122018-11-27 15:58:47 +01001173 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1174 make
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +01001175
Gilles Peskine8f073122018-11-27 15:58:47 +01001176 msg "test: small SSL_OUT_CONTENT_LEN - ssl-opt.sh MFL and large packet tests"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001177 tests/ssl-opt.sh -f "Max fragment\|Large packet"
Gilles Peskine8f073122018-11-27 15:58:47 +01001178}
Angus Grattonc4dd0732018-04-11 16:28:39 +10001179
Gilles Peskine8f073122018-11-27 15:58:47 +01001180component_test_small_ssl_in_content_len () {
1181 msg "build: small SSL_IN_CONTENT_LEN (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001182 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 4096
1183 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 16384
Gilles Peskine8f073122018-11-27 15:58:47 +01001184 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1185 make
Angus Grattonc4dd0732018-04-11 16:28:39 +10001186
Gilles Peskine8f073122018-11-27 15:58:47 +01001187 msg "test: small SSL_IN_CONTENT_LEN - ssl-opt.sh MFL tests"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001188 tests/ssl-opt.sh -f "Max fragment"
Gilles Peskine8f073122018-11-27 15:58:47 +01001189}
Angus Grattonc4dd0732018-04-11 16:28:39 +10001190
Gilles Peskine8f073122018-11-27 15:58:47 +01001191component_test_small_ssl_dtls_max_buffering () {
1192 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001193 scripts/config.py set MBEDTLS_SSL_DTLS_MAX_BUFFERING 1000
Gilles Peskine8f073122018-11-27 15:58:47 +01001194 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1195 make
Angus Grattonc4dd0732018-04-11 16:28:39 +10001196
Gilles Peskine8f073122018-11-27 15:58:47 +01001197 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0 - ssl-opt.sh specific reordering test"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001198 tests/ssl-opt.sh -f "DTLS reordering: Buffer out-of-order hs msg before reassembling next, free buffered msg"
Gilles Peskine8f073122018-11-27 15:58:47 +01001199}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001200
Gilles Peskine8f073122018-11-27 15:58:47 +01001201component_test_small_mbedtls_ssl_dtls_max_buffering () {
1202 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1"
Gilles Peskine636c26a2020-03-04 20:46:15 +01001203 scripts/config.py set MBEDTLS_SSL_DTLS_MAX_BUFFERING 190
Gilles Peskine8f073122018-11-27 15:58:47 +01001204 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1205 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001206
Gilles Peskine8f073122018-11-27 15:58:47 +01001207 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1 - ssl-opt.sh specific reordering test"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001208 tests/ssl-opt.sh -f "DTLS reordering: Buffer encrypted Finished message, drop for fragmented NewSessionTicket"
Gilles Peskine8f073122018-11-27 15:58:47 +01001209}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001210
Gilles Peskine75cc7712019-09-06 19:47:17 +02001211component_test_psa_collect_statuses () {
1212 msg "build+test: psa_collect_statuses" # ~30s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001213 scripts/config.py full
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001214 tests/scripts/psa_collect_statuses.py
Gilles Peskine75cc7712019-09-06 19:47:17 +02001215 # Check that psa_crypto_init() succeeded at least once
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001216 grep -q '^0:psa_crypto_init:' tests/statuses.log
Gilles Peskine75cc7712019-09-06 19:47:17 +02001217 rm -f tests/statuses.log
1218}
1219
Gilles Peskine8f073122018-11-27 15:58:47 +01001220component_test_full_cmake_clang () {
1221 msg "build: cmake, full config, clang" # ~ 50s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001222 scripts/config.py full
Gilles Peskine8f073122018-11-27 15:58:47 +01001223 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check -D ENABLE_TESTING=On .
1224 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001225
k-stachowiak0291cb72019-06-26 15:52:12 +02001226 msg "test: main suites (full config, clang)" # ~ 5s
Gilles Peskine8f073122018-11-27 15:58:47 +01001227 make test
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +01001228
k-stachowiak0291cb72019-06-26 15:52:12 +02001229 msg "test: psa_constant_names (full config, clang)" # ~ 1s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001230 tests/scripts/test_psa_constant_names.py
Gilles Peskine69e8f7f2020-02-26 19:51:43 +01001231
Gilles Peskine8f073122018-11-27 15:58:47 +01001232 msg "test: ssl-opt.sh default, ECJPAKE, SSL async (full config)" # ~ 1s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001233 tests/ssl-opt.sh -f 'Default\|ECJPAKE\|SSL async private'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +02001234
TRodziewicz10e8cf52021-05-31 17:58:57 +02001235 msg "test: compat.sh DES, 3DES & NULL (full config)" # ~ 2 min
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001236 env OPENSSL_CMD="$OPENSSL_LEGACY" GNUTLS_CLI="$GNUTLS_LEGACY_CLI" GNUTLS_SERV="$GNUTLS_LEGACY_SERV" tests/compat.sh -e '^$' -f 'NULL\|DES'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +02001237
Gilles Peskine8f073122018-11-27 15:58:47 +01001238 msg "test: compat.sh ARIA + ChachaPoly"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001239 env OPENSSL_CMD="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
Gilles Peskine8f073122018-11-27 15:58:47 +01001240}
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +02001241
Manuel Pégourié-Gonnard6240def2020-07-10 09:35:54 +02001242component_test_memsan_constant_flow () {
Manuel Pégourié-Gonnard0b2112d2020-07-22 11:09:28 +02001243 # This tests both (1) accesses to undefined memory, and (2) branches or
1244 # memory access depending on secret values. To distinguish between those:
1245 # - unset MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN - does the failure persist?
1246 # - or alternatively, change the build type to MemSanDbg, which enables
1247 # origin tracking and nicer stack traces (which are useful for debugging
1248 # anyway), and check if the origin was TEST_CF_SECRET() or something else.
1249 msg "build: cmake MSan (clang), full config with constant flow testing"
Manuel Pégourié-Gonnard6240def2020-07-10 09:35:54 +02001250 scripts/config.py full
1251 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN
1252 scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm
1253 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
1254 make
1255
Manuel Pégourié-Gonnard0b2112d2020-07-22 11:09:28 +02001256 msg "test: main suites (Msan + constant flow)"
Manuel Pégourié-Gonnard6240def2020-07-10 09:35:54 +02001257 make test
1258}
1259
Manuel Pégourié-Gonnard73afa372020-08-19 10:27:38 +02001260component_test_valgrind_constant_flow () {
1261 # This tests both (1) everything that valgrind's memcheck usually checks
1262 # (heap buffer overflows, use of uninitialized memory, use-after-free,
1263 # etc.) and (2) branches or memory access depending on secret values,
1264 # which will be reported as uninitialized memory. To distinguish between
1265 # secret and actually uninitialized:
1266 # - unset MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND - does the failure persist?
1267 # - or alternatively, build with debug info and manually run the offending
1268 # test suite with valgrind --track-origins=yes, then check if the origin
1269 # was TEST_CF_SECRET() or something else.
1270 msg "build: cmake release GCC, full config with constant flow testing"
1271 scripts/config.py full
1272 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND
1273 cmake -D CMAKE_BUILD_TYPE:String=Release .
1274 make
1275
1276 # this only shows a summary of the results (how many of each type)
1277 # details are left in Testing/<date>/DynamicAnalysis.xml
1278 msg "test: main suites (valgrind + constant flow)"
1279 make memcheck
1280}
1281
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001282component_test_default_no_deprecated () {
Gilles Peskine8386ea22020-04-30 09:07:29 +02001283 # Test that removing the deprecated features from the default
1284 # configuration leaves something consistent.
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001285 msg "build: make, default + MBEDTLS_DEPRECATED_REMOVED" # ~ 30s
1286 scripts/config.py set MBEDTLS_DEPRECATED_REMOVED
1287 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra'
1288
1289 msg "test: make, default + MBEDTLS_DEPRECATED_REMOVED" # ~ 5s
1290 make test
1291}
1292
1293component_test_full_no_deprecated () {
Gilles Peskine30de2e82020-04-20 21:39:22 +02001294 msg "build: make, full_no_deprecated config" # ~ 30s
1295 scripts/config.py full_no_deprecated
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001296 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra'
1297
Gilles Peskine30de2e82020-04-20 21:39:22 +02001298 msg "test: make, full_no_deprecated config" # ~ 5s
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001299 make test
1300}
1301
Gilles Peskine8386ea22020-04-30 09:07:29 +02001302component_test_full_no_deprecated_deprecated_warning () {
1303 # Test that there is nothing deprecated in "full_no_deprecated".
1304 # A deprecated feature would trigger a warning (made fatal) from
1305 # MBEDTLS_DEPRECATED_WARNING.
Gilles Peskine30de2e82020-04-20 21:39:22 +02001306 msg "build: make, full_no_deprecated config, MBEDTLS_DEPRECATED_WARNING" # ~ 30s
1307 scripts/config.py full_no_deprecated
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001308 scripts/config.py unset MBEDTLS_DEPRECATED_REMOVED
1309 scripts/config.py set MBEDTLS_DEPRECATED_WARNING
1310 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra'
1311
Gilles Peskine30de2e82020-04-20 21:39:22 +02001312 msg "test: make, full_no_deprecated config, MBEDTLS_DEPRECATED_WARNING" # ~ 5s
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001313 make test
1314}
1315
Gilles Peskine8386ea22020-04-30 09:07:29 +02001316component_test_full_deprecated_warning () {
1317 # Test that when MBEDTLS_DEPRECATED_WARNING is enabled, the build passes
1318 # with only certain whitelisted types of warnings.
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001319 msg "build: make, full config + MBEDTLS_DEPRECATED_WARNING, expect warnings" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001320 scripts/config.py full
1321 scripts/config.py set MBEDTLS_DEPRECATED_WARNING
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001322 # Expect warnings from '#warning' directives in check_config.h.
1323 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-error=cpp' lib programs
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +01001324
Gilles Peskine8386ea22020-04-30 09:07:29 +02001325 msg "build: make tests, full config + MBEDTLS_DEPRECATED_WARNING, expect warnings" # ~ 30s
1326 # Set MBEDTLS_TEST_DEPRECATED to enable tests for deprecated features.
1327 # By default those are disabled when MBEDTLS_DEPRECATED_WARNING is set.
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001328 # Expect warnings from '#warning' directives in check_config.h and
1329 # from the use of deprecated functions in test suites.
1330 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 +01001331
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001332 msg "test: full config + MBEDTLS_TEST_DEPRECATED" # ~ 30s
1333 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01001334}
Jaeden Ameroed93bdc2018-11-02 16:57:24 +00001335
Gilles Peskineec541fe2020-01-31 14:24:14 +01001336# Check that the specified libraries exist and are empty.
1337are_empty_libraries () {
1338 nm "$@" >/dev/null 2>/dev/null
1339 ! nm "$@" 2>/dev/null | grep -v ':$' | grep .
1340}
1341
1342component_build_crypto_default () {
1343 msg "build: make, crypto only"
1344 scripts/config.py crypto
Gilles Peskine6bb39152020-02-03 11:59:20 +01001345 make CFLAGS='-O1 -Werror'
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001346 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
Gilles Peskineec541fe2020-01-31 14:24:14 +01001347}
1348
1349component_build_crypto_full () {
1350 msg "build: make, crypto only, full config"
1351 scripts/config.py crypto_full
Gilles Peskine6bb39152020-02-03 11:59:20 +01001352 make CFLAGS='-O1 -Werror'
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001353 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
Gilles Peskineec541fe2020-01-31 14:24:14 +01001354}
1355
1356component_build_crypto_baremetal () {
1357 msg "build: make, crypto only, baremetal config"
1358 scripts/config.py crypto_baremetal
Gilles Peskine6bb39152020-02-03 11:59:20 +01001359 make CFLAGS='-O1 -Werror'
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001360 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
Gilles Peskineec541fe2020-01-31 14:24:14 +01001361}
1362
Gilles Peskine8f073122018-11-27 15:58:47 +01001363component_test_depends_curves () {
1364 msg "test/build: curves.pl (gcc)" # ~ 4 min
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001365 tests/scripts/curves.pl
Gilles Peskine8f073122018-11-27 15:58:47 +01001366}
Jaeden Ameroacaabe72018-11-07 11:52:52 +00001367
John Durkopc14be902020-08-20 06:16:41 -07001368component_test_depends_curves_psa () {
1369 msg "test/build: curves.pl with MBEDTLS_USE_PSA_CRYPTO defined (gcc)"
1370 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001371 tests/scripts/curves.pl
John Durkopc14be902020-08-20 06:16:41 -07001372}
1373
Gilles Peskine8f073122018-11-27 15:58:47 +01001374component_test_depends_hashes () {
1375 msg "test/build: depends-hashes.pl (gcc)" # ~ 2 min
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001376 tests/scripts/depends-hashes.pl
Gilles Peskine8f073122018-11-27 15:58:47 +01001377}
Jaeden Ameroacaabe72018-11-07 11:52:52 +00001378
John Durkop2ec2eaa2020-08-24 18:29:15 -07001379component_test_depends_hashes_psa () {
1380 msg "test/build: depends-hashes.pl with MBEDTLS_USE_PSA_CRYPTO defined (gcc)"
1381 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001382 tests/scripts/depends-hashes.pl
John Durkop2ec2eaa2020-08-24 18:29:15 -07001383}
1384
Gilles Peskine8f073122018-11-27 15:58:47 +01001385component_test_depends_pkalgs () {
1386 msg "test/build: depends-pkalgs.pl (gcc)" # ~ 2 min
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001387 tests/scripts/depends-pkalgs.pl
Gilles Peskine8f073122018-11-27 15:58:47 +01001388}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01001389
John Durkop619e09e2020-09-08 22:19:56 -07001390component_test_depends_pkalgs_psa () {
1391 msg "test/build: depends-pkalgs.pl with MBEDTLS_USE_PSA_CRYPTO defined (gcc)"
1392 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001393 tests/scripts/depends-pkalgs.pl
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01001394}
1395
Gilles Peskine8f073122018-11-27 15:58:47 +01001396component_build_key_exchanges () {
1397 msg "test/build: key-exchanges (gcc)" # ~ 1 min
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001398 tests/scripts/key-exchanges.pl
Gilles Peskine8f073122018-11-27 15:58:47 +01001399}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01001400
Gilles Peskine03ab5442021-07-09 15:19:28 +02001401component_test_make_cxx () {
1402 msg "build: Unix make, full, gcc + g++"
1403 scripts/config.py full
1404 make TEST_CPP=1 lib programs
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01001405
Gilles Peskine03ab5442021-07-09 15:19:28 +02001406 msg "test: cpp_dummy_build"
1407 programs/test/cpp_dummy_build
Gilles Peskine8f073122018-11-27 15:58:47 +01001408}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01001409
Gilles Peskinecc73cc52021-05-25 09:04:46 +02001410component_build_module_alt () {
1411 msg "build: MBEDTLS_XXX_ALT" # ~30s
1412 scripts/config.py full
1413 # Disable options that are incompatible with some ALT implementations.
1414 # aesni.c and padlock.c reference mbedtls_aes_context fields directly.
1415 scripts/config.py unset MBEDTLS_AESNI_C
1416 scripts/config.py unset MBEDTLS_PADLOCK_C
Gilles Peskinecc73cc52021-05-25 09:04:46 +02001417 # You can only have one threading implementation: alt or pthread, not both.
1418 scripts/config.py unset MBEDTLS_THREADING_PTHREAD
Gilles Peskine5c3f18d2021-05-31 21:21:12 +02001419 # The SpecifiedECDomain parsing code accesses mbedtls_ecp_group fields
1420 # directly and assumes the implementation works with partial groups.
1421 scripts/config.py unset MBEDTLS_PK_PARSE_EC_EXTENDED
Gilles Peskinecc73cc52021-05-25 09:04:46 +02001422 # Enable all MBEDTLS_XXX_ALT for whole modules. Do not enable
1423 # MBEDTLS_XXX_YYY_ALT which are for single functions.
1424 scripts/config.py set-all 'MBEDTLS_([A-Z0-9]*|NIST_KW)_ALT'
Gilles Peskine1628a9c2021-05-31 22:09:58 +02001425 scripts/config.py unset MBEDTLS_DHM_ALT #incompatible with MBEDTLS_DEBUG_C
1426 # We can only compile, not link, since we don't have any implementations
1427 # suitable for testing with the dummy alt headers.
1428 make CC=gcc CFLAGS='-Werror -Wall -Wextra -I../tests/include/alt-dummy' lib
1429}
1430
1431component_build_dhm_alt () {
1432 msg "build: MBEDTLS_DHM_ALT" # ~30s
1433 scripts/config.py full
1434 scripts/config.py set MBEDTLS_DHM_ALT
1435 # debug.c currently references mbedtls_dhm_context fields directly.
1436 scripts/config.py unset MBEDTLS_DEBUG_C
Gilles Peskinecc73cc52021-05-25 09:04:46 +02001437 # We can only compile, not link, since we don't have any implementations
1438 # suitable for testing with the dummy alt headers.
1439 make CC=gcc CFLAGS='-Werror -Wall -Wextra -I../tests/include/alt-dummy' lib
1440}
1441
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001442component_test_no_use_psa_crypto_full_cmake_asan() {
1443 # full minus MBEDTLS_USE_PSA_CRYPTO: run the same set of tests as basic-build-test.sh
Gilles Peskinedc3a1792019-09-03 11:42:04 +02001444 msg "build: cmake, full config minus MBEDTLS_USE_PSA_CRYPTO, ASan"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001445 scripts/config.py full
1446 scripts/config.py set MBEDTLS_ECP_RESTARTABLE # not using PSA, so enable restartable ECC
1447 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C
1448 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1449 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C
Gilles Peskinedc6d8382020-04-12 14:21:55 +02001450 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001451 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
Manuel Pégourié-Gonnardd8167e82019-02-01 11:12:52 +01001452 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Andrzej Kurekde5a0072019-02-01 07:03:03 -05001453 make
Manuel Pégourié-Gonnard43be6cd2017-06-20 09:53:42 +02001454
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001455 msg "test: main suites (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -05001456 make test
Manuel Pégourié-Gonnard503a5ef2015-10-23 09:04:45 +02001457
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001458 msg "test: ssl-opt.sh (full minus MBEDTLS_USE_PSA_CRYPTO)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001459 tests/ssl-opt.sh
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001460
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001461 msg "test: compat.sh default (full minus MBEDTLS_USE_PSA_CRYPTO)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001462 tests/compat.sh
Andrzej Kurek991f9fe2018-07-02 09:08:21 -04001463
TRodziewicz10e8cf52021-05-31 17:58:57 +02001464 msg "test: compat.sh DES & NULL (full minus MBEDTLS_USE_PSA_CRYPTO)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001465 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'
Andrzej Kurekc470b6b2019-01-31 08:20:20 -05001466
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001467 msg "test: compat.sh ARIA + ChachaPoly (full minus MBEDTLS_USE_PSA_CRYPTO)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001468 env OPENSSL_CMD="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
Andrzej Kurekde5a0072019-02-01 07:03:03 -05001469}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -05001470
John Durkopd8959392020-09-20 23:09:17 -07001471component_test_psa_crypto_config_basic() {
Ronald Cron067de3b2021-03-11 11:49:03 +01001472 # Test the library excluding all Mbed TLS cryptographic support for which
1473 # we have an accelerator support. Acceleration is faked with the
1474 # transparent test driver.
1475 msg "test: full + MBEDTLS_PSA_CRYPTO_CONFIG + as much acceleration as supported"
John Durkopd8959392020-09-20 23:09:17 -07001476 scripts/config.py full
1477 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1478 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1479 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cron067de3b2021-03-11 11:49:03 +01001480
1481 # There is no intended accelerator support for ALG STREAM_CIPHER and
1482 # ALG_ECB_NO_PADDING. Therefore, asking for them in the build implies the
1483 # inclusion of the Mbed TLS cipher operations. As we want to test here with
1484 # cipher operations solely supported by accelerators, disabled those
1485 # PSA configuration options.
1486 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_STREAM_CIPHER
1487 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_ECB_NO_PADDING
1488
1489 # Don't test DES encryption as:
1490 # 1) It is not an issue if we don't test all cipher types here.
1491 # 2) That way we don't have to modify in psa_crypto.c the compilation
1492 # guards MBEDTLS_PSA_BUILTIN_KEY_TYPE_DES for the code they guard to be
1493 # available to the test driver. Modifications that we would need to
1494 # revert when we move to compile the test driver separately.
1495 # We also disable MBEDTLS_DES_C as the dependencies on DES in PSA test
1496 # suites are still based on MBEDTLS_DES_C and not PSA_WANT_KEY_TYPE_DES.
1497 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_KEY_TYPE_DES
1498 scripts/config.py unset MBEDTLS_DES_C
1499
John Durkopd8959392020-09-20 23:09:17 -07001500 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
Ronald Cron17b3afc2020-12-10 18:17:09 +01001501 loc_cflags="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST"
Ronald Cron067de3b2021-03-11 11:49:03 +01001502 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_KEY_TYPE_AES"
1503 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_KEY_TYPE_CAMELLIA"
Ronald Cron17b3afc2020-12-10 18:17:09 +01001504 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_KEY_PAIR"
Ronald Cron067de3b2021-03-11 11:49:03 +01001505 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_KEY_PAIR"
1506 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_CBC_NO_PADDING"
1507 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_CBC_PKCS7"
1508 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_CTR"
1509 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_CFB"
Ronald Cron17b3afc2020-12-10 18:17:09 +01001510 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_ECDSA"
1511 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_DETERMINISTIC_ECDSA"
Steven Cooremand50db942021-03-08 17:17:15 +01001512 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_MD5"
Ronald Cron067de3b2021-03-11 11:49:03 +01001513 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_OFB"
Steven Cooremand50db942021-03-08 17:17:15 +01001514 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_RIPEMD160"
Ronald Cron067de3b2021-03-11 11:49:03 +01001515 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_SIGN"
1516 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_RSA_PSS"
Steven Cooremand50db942021-03-08 17:17:15 +01001517 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_SHA_1"
1518 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_SHA_224"
1519 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_SHA_256"
1520 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_SHA_384"
1521 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_SHA_512"
Ronald Cron067de3b2021-03-11 11:49:03 +01001522 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_XTS"
Steven Cooreman7515e752021-03-19 19:36:38 +01001523 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_CMAC"
1524 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_HMAC"
Ronald Cron17b3afc2020-12-10 18:17:09 +01001525 loc_cflags="${loc_cflags} -I../tests/include -O2"
1526
1527 make CC=gcc CFLAGS="$loc_cflags" LDFLAGS="$ASAN_CFLAGS"
1528 unset loc_cflags
John Durkopd8959392020-09-20 23:09:17 -07001529
John Durkop4377bf72020-10-23 01:26:57 -07001530 msg "test: full + MBEDTLS_PSA_CRYPTO_CONFIG"
1531 make test
1532}
1533
1534component_test_psa_crypto_config_no_driver() {
1535 # full plus MBEDTLS_PSA_CRYPTO_CONFIG
1536 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG minus MBEDTLS_PSA_CRYPTO_DRIVERS"
1537 scripts/config.py full
1538 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1539 scripts/config.py unset MBEDTLS_PSA_CRYPTO_DRIVERS
1540 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
John Durkope7012c72020-10-26 09:55:01 -07001541 make CC=gcc CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
John Durkop4377bf72020-10-23 01:26:57 -07001542
1543 msg "test: full + MBEDTLS_PSA_CRYPTO_CONFIG minus MBEDTLS_PSA_CRYPTO_DRIVERS"
John Durkopd8959392020-09-20 23:09:17 -07001544 make test
1545}
1546
John Durkop8ac0b802020-10-23 01:32:15 -07001547# 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 -08001548component_build_psa_accel_alg_ecdsa() {
John Durkopdd544e12020-10-12 21:47:19 -07001549 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_ECDSA
1550 # without MBEDTLS_ECDSA_C
John Durkop28baa1f2020-10-23 00:51:52 -07001551 # PSA_WANT_ALG_ECDSA and PSA_WANT_ALG_DETERMINISTIC_ECDSA are already
1552 # set in include/psa/crypto_config.h
John Durkopdd544e12020-10-12 21:47:19 -07001553 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_ECDSA without MBEDTLS_ECDSA_C"
John Durkopd8959392020-09-20 23:09:17 -07001554 scripts/config.py full
1555 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1556 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1557 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1558 scripts/config.py unset MBEDTLS_ECDSA_C
John Durkop28baa1f2020-10-23 00:51:52 -07001559 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
1560 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
John Durkopd8959392020-09-20 23:09:17 -07001561 # 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 -07001562 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 -07001563}
1564
John Durkopd0321952020-10-29 21:37:36 -07001565# 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 -08001566component_build_psa_accel_alg_ecdh() {
John Durkopd0321952020-10-29 21:37:36 -07001567 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_ECDH
1568 # without MBEDTLS_ECDH_C
1569 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_ECDH without MBEDTLS_ECDH_C"
1570 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_ECDH_C
1575 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
1576 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
1577 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
1578 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
1579 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
1580 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1581 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_ECDH -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
1582}
1583
John Durkopf4c4cb02020-10-28 20:09:55 -07001584# 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 -08001585component_build_psa_accel_key_type_ecc_key_pair() {
John Durkop9814fa22020-11-04 12:28:15 -08001586 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_KEY_TYPE_ECC_KEY_PAIR
1587 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_KEY_TYPE_ECC_KEY_PAIR"
John Durkopf4c4cb02020-10-28 20:09:55 -07001588 scripts/config.py full
1589 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1590 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1591 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
John Durkop9814fa22020-11-04 12:28:15 -08001592 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 -08001593 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 -07001594 # 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 -08001595 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 -07001596}
1597
1598# 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 -08001599component_build_psa_accel_key_type_ecc_public_key() {
John Durkop9814fa22020-11-04 12:28:15 -08001600 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY
1601 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY"
John Durkopf4c4cb02020-10-28 20:09:55 -07001602 scripts/config.py full
1603 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1604 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1605 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
John Durkop9814fa22020-11-04 12:28:15 -08001606 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY 1
1607 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR
John Durkopf4c4cb02020-10-28 20:09:55 -07001608 # 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 -08001609 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 -07001610}
1611
John Durkopd0321952020-10-29 21:37:36 -07001612# 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 -08001613component_build_psa_accel_alg_hmac() {
John Durkopd0321952020-10-29 21:37:36 -07001614 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_HMAC
1615 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_HMAC"
1616 scripts/config.py full
1617 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1618 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1619 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1620 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1621 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_HMAC -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
1622}
1623
1624# 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 -08001625component_build_psa_accel_alg_hkdf() {
John Durkopd0321952020-10-29 21:37:36 -07001626 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_HKDF
1627 # without MBEDTLS_HKDF_C
1628 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_HKDF without MBEDTLS_HKDF_C"
1629 scripts/config.py full
1630 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1631 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1632 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1633 scripts/config.py unset MBEDTLS_HKDF_C
John Durkopbd069d32020-10-31 22:14:03 -07001634 # Make sure to unset TLS1_3_EXPERIMENTAL since it requires HKDF_C and will not build properly without it.
1635 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL
John Durkopd0321952020-10-29 21:37:36 -07001636 # 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_HKDF -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
1638}
1639
John Durkop1b7ee052020-11-27 08:51:22 -08001640# This should be renamed to test and updated once the accelerator MD5 code is in place and ready to test.
1641component_build_psa_accel_alg_md5() {
1642 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_MD5 without other hashes
1643 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_MD5 - other hashes"
1644 scripts/config.py full
1645 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1646 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1647 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
John Durkop1b7ee052020-11-27 08:51:22 -08001648 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
1649 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
1650 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
1651 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
1652 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
1653 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
1654 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1655 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_MD5 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
1656}
1657
1658# This should be renamed to test and updated once the accelerator RIPEMD160 code is in place and ready to test.
1659component_build_psa_accel_alg_ripemd160() {
1660 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_RIPEMD160 without other hashes
1661 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_RIPEMD160 - other hashes"
1662 scripts/config.py full
1663 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1664 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1665 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
John Durkop1b7ee052020-11-27 08:51:22 -08001666 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
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_RIPEMD160 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
1674}
1675
1676# This should be renamed to test and updated once the accelerator SHA1 code is in place and ready to test.
1677component_build_psa_accel_alg_sha1() {
1678 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_SHA_1 without other hashes
1679 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_SHA_1 - 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
John Durkop1b7ee052020-11-27 08:51:22 -08001684 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
1685 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
1686 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
1687 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
1688 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
1689 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
1690 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1691 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_1 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
1692}
1693
1694# This should be renamed to test and updated once the accelerator SHA224 code is in place and ready to test.
1695component_build_psa_accel_alg_sha224() {
1696 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_SHA_224 without other hashes
1697 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_SHA_224 - other hashes"
1698 scripts/config.py full
1699 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1700 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1701 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
John Durkop1b7ee052020-11-27 08:51:22 -08001702 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
1703 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
1704 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
1705 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
1706 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
1707 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1708 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_224 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
1709}
1710
1711# This should be renamed to test and updated once the accelerator SHA256 code is in place and ready to test.
1712component_build_psa_accel_alg_sha256() {
1713 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_SHA_256 without other hashes
1714 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_SHA_256 - other hashes"
1715 scripts/config.py full
1716 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1717 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1718 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
John Durkop1b7ee052020-11-27 08:51:22 -08001719 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
1720 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
1721 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
1722 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
1723 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
1724 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
1725 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1726 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_256 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
1727}
1728
1729# This should be renamed to test and updated once the accelerator SHA384 code is in place and ready to test.
1730component_build_psa_accel_alg_sha384() {
1731 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_SHA_384 without other hashes
1732 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_SHA_384 - other hashes"
1733 scripts/config.py full
1734 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1735 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1736 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
John Durkop1b7ee052020-11-27 08:51:22 -08001737 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
1738 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
1739 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
1740 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
1741 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
1742 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1743 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_384 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
1744}
1745
1746# This should be renamed to test and updated once the accelerator SHA512 code is in place and ready to test.
1747component_build_psa_accel_alg_sha512() {
1748 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_SHA_512 without other hashes
1749 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_SHA_512 - other hashes"
1750 scripts/config.py full
1751 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1752 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1753 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
John Durkop1b7ee052020-11-27 08:51:22 -08001754 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
1755 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
1756 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
1757 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
1758 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
1759 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
1760 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1761 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_512 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
1762}
1763
John Durkopd0321952020-10-29 21:37:36 -07001764# 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 -08001765component_build_psa_accel_alg_rsa_pkcs1v15_crypt() {
John Durkopbd069d32020-10-31 22:14:03 -07001766 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
1767 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 -07001768 scripts/config.py full
1769 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1770 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1771 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
John Durkopbd069d32020-10-31 22:14:03 -07001772 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_PKCS1V15_CRYPT 1
John Durkop7fc75ea2020-11-03 19:05:36 -08001773 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN
1774 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_OAEP
1775 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PSS
John Durkopd0321952020-10-29 21:37:36 -07001776 # 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 -07001777 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_CRYPT -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
1778}
1779
1780# 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 -08001781component_build_psa_accel_alg_rsa_pkcs1v15_sign() {
John Durkopbd069d32020-10-31 22:14:03 -07001782 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_RSA_PKCS1V15_SIGN and PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY
1783 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_RSA_PKCS1V15_SIGN + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY"
1784 scripts/config.py full
1785 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1786 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1787 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1788 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_PKCS1V15_SIGN 1
John Durkop7fc75ea2020-11-03 19:05:36 -08001789 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
1790 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_OAEP
1791 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PSS
John Durkopbd069d32020-10-31 22:14:03 -07001792 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1793 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_SIGN -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
1794}
1795
1796# 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 -08001797component_build_psa_accel_alg_rsa_oaep() {
John Durkopbd069d32020-10-31 22:14:03 -07001798 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_RSA_OAEP and PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY
1799 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_RSA_OAEP + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY"
1800 scripts/config.py full
1801 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1802 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1803 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1804 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_OAEP 1
John Durkop7fc75ea2020-11-03 19:05:36 -08001805 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
1806 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN
1807 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PSS
John Durkopbd069d32020-10-31 22:14:03 -07001808 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1809 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_OAEP -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
1810}
1811
1812# 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 -08001813component_build_psa_accel_alg_rsa_pss() {
John Durkopbd069d32020-10-31 22:14:03 -07001814 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_RSA_PSS and PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY
1815 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_RSA_PSS + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY"
1816 scripts/config.py full
1817 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1818 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1819 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1820 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_PSS 1
John Durkop7fc75ea2020-11-03 19:05:36 -08001821 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
1822 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN
1823 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_OAEP
John Durkopbd069d32020-10-31 22:14:03 -07001824 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1825 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_PSS -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
1826}
1827
1828# 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 -08001829component_build_psa_accel_key_type_rsa_key_pair() {
John Durkopbd069d32020-10-31 22:14:03 -07001830 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_KEY_TYPE_RSA_KEY_PAIR and PSA_WANT_ALG_RSA_PSS
1831 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_KEY_TYPE_RSA_KEY_PAIR + PSA_WANT_ALG_RSA_PSS"
1832 scripts/config.py full
1833 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1834 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1835 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1836 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_PSS 1
1837 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_KEY_TYPE_RSA_KEY_PAIR 1
1838 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1839 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"
1840}
1841
1842# 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 -08001843component_build_psa_accel_key_type_rsa_public_key() {
John Durkopbd069d32020-10-31 22:14:03 -07001844 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY and PSA_WANT_ALG_RSA_PSS
1845 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY + PSA_WANT_ALG_RSA_PSS"
1846 scripts/config.py full
1847 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1848 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1849 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1850 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_PSS 1
1851 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY 1
1852 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1853 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 -07001854}
1855
Gilles Peskine8f073122018-11-27 15:58:47 +01001856component_test_no_platform () {
1857 # Full configuration build, without platform support, file IO and net sockets.
1858 # This should catch missing mbedtls_printf definitions, and by disabling file
1859 # IO, it should catch missing '#include <stdio.h>'
1860 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001861 scripts/config.py full
1862 scripts/config.py unset MBEDTLS_PLATFORM_C
1863 scripts/config.py unset MBEDTLS_NET_C
1864 scripts/config.py unset MBEDTLS_PLATFORM_MEMORY
1865 scripts/config.py unset MBEDTLS_PLATFORM_PRINTF_ALT
1866 scripts/config.py unset MBEDTLS_PLATFORM_FPRINTF_ALT
1867 scripts/config.py unset MBEDTLS_PLATFORM_SNPRINTF_ALT
1868 scripts/config.py unset MBEDTLS_PLATFORM_TIME_ALT
1869 scripts/config.py unset MBEDTLS_PLATFORM_EXIT_ALT
Gilles Peskine32e889d2020-04-12 23:43:28 +02001870 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001871 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
1872 scripts/config.py unset MBEDTLS_FS_IO
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001873 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001874 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
1875 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C
Gilles Peskine8f073122018-11-27 15:58:47 +01001876 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
1877 # to re-enable platform integration features otherwise disabled in C99 builds
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02001878 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -Os -D_DEFAULT_SOURCE' lib programs
1879 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os' test
Gilles Peskine8f073122018-11-27 15:58:47 +01001880}
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +00001881
Gilles Peskine8f073122018-11-27 15:58:47 +01001882component_build_no_std_function () {
1883 # catch compile bugs in _uninit functions
1884 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001885 scripts/config.py full
1886 scripts/config.py set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
1887 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskine32e889d2020-04-12 23:43:28 +02001888 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02001889 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Gilles Peskine8f073122018-11-27 15:58:47 +01001890}
Manuel Pégourié-Gonnarddccb80b2015-06-03 10:20:33 +01001891
Gilles Peskine8f073122018-11-27 15:58:47 +01001892component_build_no_ssl_srv () {
1893 msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001894 scripts/config.py full
1895 scripts/config.py unset MBEDTLS_SSL_SRV_C
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02001896 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
Gilles Peskine8f073122018-11-27 15:58:47 +01001897}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +02001898
Gilles Peskine8f073122018-11-27 15:58:47 +01001899component_build_no_ssl_cli () {
1900 msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001901 scripts/config.py full
1902 scripts/config.py unset MBEDTLS_SSL_CLI_C
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02001903 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
Gilles Peskine8f073122018-11-27 15:58:47 +01001904}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +02001905
Gilles Peskine8f073122018-11-27 15:58:47 +01001906component_build_no_sockets () {
1907 # Note, C99 compliance can also be tested with the sockets support disabled,
1908 # as that requires a POSIX platform (which isn't the same as C99).
1909 msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001910 scripts/config.py full
1911 scripts/config.py unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
1912 scripts/config.py set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02001913 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1 -std=c99 -pedantic' lib
Gilles Peskine8f073122018-11-27 15:58:47 +01001914}
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +02001915
Andrzej Kurek69f20aa2019-09-05 09:27:47 -04001916component_test_memory_buffer_allocator_backtrace () {
1917 msg "build: default config with memory buffer allocator and backtrace enabled"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001918 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
1919 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
1920 scripts/config.py set MBEDTLS_MEMORY_BACKTRACE
1921 scripts/config.py set MBEDTLS_MEMORY_DEBUG
Andrzej Kurek69f20aa2019-09-05 09:27:47 -04001922 CC=gcc cmake .
1923 make
1924
1925 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C and MBEDTLS_MEMORY_BACKTRACE"
1926 make test
1927}
1928
1929component_test_memory_buffer_allocator () {
1930 msg "build: default config with memory buffer allocator"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001931 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
1932 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
Hanno Becker0fb9ba22019-02-26 14:34:13 +00001933 CC=gcc cmake .
1934 make
1935
1936 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C"
1937 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +01001938
1939 msg "test: ssl-opt.sh, MBEDTLS_MEMORY_BUFFER_ALLOC_C"
1940 # MBEDTLS_MEMORY_BUFFER_ALLOC is slow. Skip tests that tend to time out.
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001941 tests/ssl-opt.sh -e '^DTLS proxy'
Hanno Becker0fb9ba22019-02-26 14:34:13 +00001942}
1943
Gilles Peskine8f073122018-11-27 15:58:47 +01001944component_test_no_max_fragment_length () {
1945 # Run max fragment length tests with MFL disabled
1946 msg "build: default config except MFL extension (ASan build)" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001947 scripts/config.py unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
Gilles Peskine8f073122018-11-27 15:58:47 +01001948 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1949 make
Hanno Becker5175ac62017-09-18 15:36:25 +01001950
Gilles Peskine8f073122018-11-27 15:58:47 +01001951 msg "test: ssl-opt.sh, MFL-related tests"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001952 tests/ssl-opt.sh -f "Max fragment length"
Gilles Peskine8f073122018-11-27 15:58:47 +01001953}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001954
Hanno Becker545ced42019-02-19 11:10:48 +00001955component_test_asan_remove_peer_certificate () {
1956 msg "build: default config with MBEDTLS_SSL_KEEP_PEER_CERTIFICATE disabled (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001957 scripts/config.py unset MBEDTLS_SSL_KEEP_PEER_CERTIFICATE
Hanno Becker545ced42019-02-19 11:10:48 +00001958 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1959 make
1960
1961 msg "test: !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
1962 make test
1963
1964 msg "test: ssl-opt.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001965 tests/ssl-opt.sh
Hanno Becker545ced42019-02-19 11:10:48 +00001966
1967 msg "test: compat.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001968 tests/compat.sh
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02001969
1970 msg "test: context-info.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001971 tests/context-info.sh
Hanno Becker545ced42019-02-19 11:10:48 +00001972}
1973
Gilles Peskine8f073122018-11-27 15:58:47 +01001974component_test_no_max_fragment_length_small_ssl_out_content_len () {
1975 msg "build: no MFL extension, small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001976 scripts/config.py unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
1977 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 16384
1978 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
Gilles Peskine8f073122018-11-27 15:58:47 +01001979 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1980 make
Angus Grattonc4dd0732018-04-11 16:28:39 +10001981
Gilles Peskine8f073122018-11-27 15:58:47 +01001982 msg "test: MFL tests (disabled MFL extension case) & large packet tests"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001983 tests/ssl-opt.sh -f "Max fragment length\|Large buffer"
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02001984
1985 msg "test: context-info.sh (disabled MFL extension case)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001986 tests/context-info.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01001987}
Angus Grattonc4dd0732018-04-11 16:28:39 +10001988
Darryl Greenaad82f92019-12-02 10:53:11 +00001989component_test_variable_ssl_in_out_buffer_len () {
1990 msg "build: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled (ASan build)"
1991 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
1992 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1993 make
1994
1995 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
1996 make test
1997
1998 msg "test: ssl-opt.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001999 tests/ssl-opt.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00002000
2001 msg "test: compat.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002002 tests/compat.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00002003}
2004
2005component_test_variable_ssl_in_out_buffer_len_CID () {
2006 msg "build: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_DTLS_CONNECTION_ID enabled (ASan build)"
2007 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
2008 scripts/config.py set MBEDTLS_SSL_DTLS_CONNECTION_ID
2009
2010 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2011 make
2012
2013 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_DTLS_CONNECTION_ID"
2014 make test
2015
2016 msg "test: ssl-opt.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_DTLS_CONNECTION_ID enabled"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002017 tests/ssl-opt.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00002018
2019 msg "test: compat.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_DTLS_CONNECTION_ID enabled"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002020 tests/compat.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00002021}
2022
Piotr Nowicki0937ed22019-11-26 16:32:40 +01002023component_test_ssl_alloc_buffer_and_mfl () {
2024 msg "build: default config with memory buffer allocator and MFL extension"
2025 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
2026 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
2027 scripts/config.py set MBEDTLS_MEMORY_DEBUG
2028 scripts/config.py set MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
2029 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
2030 CC=gcc cmake .
2031 make
2032
2033 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH, MBEDTLS_MEMORY_BUFFER_ALLOC_C, MBEDTLS_MEMORY_DEBUG and MBEDTLS_SSL_MAX_FRAGMENT_LENGTH"
2034 make test
2035
2036 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH, MBEDTLS_MEMORY_BUFFER_ALLOC_C, MBEDTLS_MEMORY_DEBUG and MBEDTLS_SSL_MAX_FRAGMENT_LENGTH"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002037 tests/ssl-opt.sh -f "Handshake memory usage"
Piotr Nowicki0937ed22019-11-26 16:32:40 +01002038}
2039
Gilles Peskine636c26a2020-03-04 20:46:15 +01002040component_test_when_no_ciphersuites_have_mac () {
2041 msg "build: when no ciphersuites have MAC"
2042 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
Gilles Peskine636c26a2020-03-04 20:46:15 +01002043 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
TRodziewicz2add5c12021-04-28 16:50:20 +02002044 scripts/config.py unset MBEDTLS_CMAC_C
Gilles Peskine636c26a2020-03-04 20:46:15 +01002045 make
2046
2047 msg "test: !MBEDTLS_SSL_SOME_MODES_USE_MAC"
2048 make test
2049
2050 msg "test ssl-opt.sh: !MBEDTLS_SSL_SOME_MODES_USE_MAC"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002051 tests/ssl-opt.sh -f 'Default\|EtM' -e 'without EtM'
Gilles Peskine636c26a2020-03-04 20:46:15 +01002052}
2053
Raoul Strackxa4e86142020-06-15 17:03:13 +02002054component_test_no_date_time () {
2055 msg "build: default config without MBEDTLS_HAVE_TIME_DATE"
2056 scripts/config.py unset MBEDTLS_HAVE_TIME_DATE
2057 CC=gcc cmake
2058 make
2059
2060 msg "test: !MBEDTLS_HAVE_TIME_DATE - main suites"
2061 make test
2062}
2063
Gilles Peskine8f073122018-11-27 15:58:47 +01002064component_test_platform_calloc_macro () {
2065 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002066 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
2067 scripts/config.py set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
2068 scripts/config.py set MBEDTLS_PLATFORM_FREE_MACRO free
Gilles Peskine8f073122018-11-27 15:58:47 +01002069 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2070 make
Hanno Beckere5fecec2018-10-11 11:02:52 +01002071
Gilles Peskine8f073122018-11-27 15:58:47 +01002072 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
2073 make test
2074}
Hanno Beckere5fecec2018-10-11 11:02:52 +01002075
Gilles Peskinec4ef7a92019-09-17 19:04:38 +02002076component_test_malloc_0_null () {
2077 msg "build: malloc(0) returns NULL (ASan+UBSan build)"
Manuel Pégourié-Gonnard68192fc2020-03-04 10:34:47 +01002078 scripts/config.py full
Gilles Peskine004206c2019-10-21 17:11:33 +02002079 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 +02002080
2081 msg "test: malloc(0) returns NULL (ASan+UBSan build)"
2082 make test
2083
2084 msg "selftest: malloc(0) returns NULL (ASan+UBSan build)"
2085 # Just the calloc selftest. "make test" ran the others as part of the
2086 # test suites.
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002087 programs/test/selftest calloc
Gilles Peskine765d2402020-02-11 18:26:34 +01002088
2089 msg "test ssl-opt.sh: malloc(0) returns NULL (ASan+UBSan build)"
2090 # Run a subset of the tests. The choice is a balance between coverage
2091 # and time (including time indirectly wasted due to flaky tests).
2092 # The current choice is to skip tests whose description includes
2093 # "proxy", which is an approximation of skipping tests that use the
2094 # UDP proxy, which tend to be slower and flakier.
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002095 tests/ssl-opt.sh -e 'proxy'
Gilles Peskinec4ef7a92019-09-17 19:04:38 +02002096}
2097
Gilles Peskine8f073122018-11-27 15:58:47 +01002098component_test_aes_fewer_tables () {
2099 msg "build: default config with AES_FEWER_TABLES enabled"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002100 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
Gilles Peskine8f073122018-11-27 15:58:47 +01002101 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01002102
Gilles Peskine8f073122018-11-27 15:58:47 +01002103 msg "test: AES_FEWER_TABLES"
2104 make test
2105}
Hanno Becker83ebf782017-07-07 12:29:15 +01002106
Gilles Peskine8f073122018-11-27 15:58:47 +01002107component_test_aes_rom_tables () {
2108 msg "build: default config with AES_ROM_TABLES enabled"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002109 scripts/config.py set MBEDTLS_AES_ROM_TABLES
Gilles Peskine8f073122018-11-27 15:58:47 +01002110 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01002111
Gilles Peskine8f073122018-11-27 15:58:47 +01002112 msg "test: AES_ROM_TABLES"
2113 make test
2114}
Hanno Becker83ebf782017-07-07 12:29:15 +01002115
Gilles Peskine8f073122018-11-27 15:58:47 +01002116component_test_aes_fewer_tables_and_rom_tables () {
2117 msg "build: default config with AES_ROM_TABLES and AES_FEWER_TABLES enabled"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002118 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
2119 scripts/config.py set MBEDTLS_AES_ROM_TABLES
Gilles Peskine8f073122018-11-27 15:58:47 +01002120 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01002121
Gilles Peskine8f073122018-11-27 15:58:47 +01002122 msg "test: AES_FEWER_TABLES + AES_ROM_TABLES"
2123 make test
2124}
2125
Gilles Peskine592f5912019-10-07 18:49:32 +02002126component_test_ctr_drbg_aes_256_sha_256 () {
2127 msg "build: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
Gilles Peskine3b46cd32020-02-18 17:56:33 +01002128 scripts/config.py full
2129 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
2130 scripts/config.py set MBEDTLS_ENTROPY_FORCE_SHA256
Gilles Peskine592f5912019-10-07 18:49:32 +02002131 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2132 make
2133
2134 msg "test: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
2135 make test
2136}
2137
2138component_test_ctr_drbg_aes_128_sha_512 () {
2139 msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)"
Gilles Peskine3b46cd32020-02-18 17:56:33 +01002140 scripts/config.py full
2141 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
2142 scripts/config.py set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
Gilles Peskine592f5912019-10-07 18:49:32 +02002143 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2144 make
2145
2146 msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)"
2147 make test
2148}
2149
2150component_test_ctr_drbg_aes_128_sha_256 () {
2151 msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
Gilles Peskine3b46cd32020-02-18 17:56:33 +01002152 scripts/config.py full
2153 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
2154 scripts/config.py set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
2155 scripts/config.py set MBEDTLS_ENTROPY_FORCE_SHA256
Gilles Peskine592f5912019-10-07 18:49:32 +02002156 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2157 make
2158
2159 msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
2160 make test
2161}
2162
Gilles Peskinef96aefe2019-07-24 14:58:38 +02002163component_test_se_default () {
2164 msg "build: default config + MBEDTLS_PSA_CRYPTO_SE_C"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002165 scripts/config.py set MBEDTLS_PSA_CRYPTO_SE_C
Gilles Peskine004206c2019-10-21 17:11:33 +02002166 make CC=clang CFLAGS="$ASAN_CFLAGS -Os" LDFLAGS="$ASAN_CFLAGS"
Gilles Peskinef96aefe2019-07-24 14:58:38 +02002167
2168 msg "test: default config + MBEDTLS_PSA_CRYPTO_SE_C"
2169 make test
2170}
2171
Steven Cooremand57203d2020-07-16 20:28:59 +02002172component_test_psa_crypto_drivers () {
Steven Cooreman55ae2172020-07-17 19:46:15 +02002173 msg "build: MBEDTLS_PSA_CRYPTO_DRIVERS w/ driver hooks"
Steven Cooreman753f9732021-03-15 11:38:44 +01002174 scripts/config.py full
Steven Cooremand57203d2020-07-16 20:28:59 +02002175 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
Steven Cooreman6801f082021-02-19 17:21:22 +01002176 scripts/config.py set MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS
Steven Cooreman1cd39d52020-07-23 16:26:08 +02002177 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
Ronald Cron17b3afc2020-12-10 18:17:09 +01002178 loc_cflags="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST"
Ronald Crone6f63012021-03-19 14:57:08 +01002179 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_KEY_TYPE_AES"
2180 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_KEY_TYPE_CAMELLIA"
Ronald Cron17b3afc2020-12-10 18:17:09 +01002181 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_KEY_PAIR"
Ronald Crone6f63012021-03-19 14:57:08 +01002182 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_KEY_PAIR"
2183 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_CBC_NO_PADDING"
2184 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_CBC_PKCS7"
2185 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_CTR"
2186 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_CFB"
Ronald Cron17b3afc2020-12-10 18:17:09 +01002187 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_ECDSA"
2188 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_DETERMINISTIC_ECDSA"
Steven Cooremand50db942021-03-08 17:17:15 +01002189 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_MD5"
Ronald Crone6f63012021-03-19 14:57:08 +01002190 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_OFB"
Steven Cooremand50db942021-03-08 17:17:15 +01002191 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_RIPEMD160"
Ronald Crone6f63012021-03-19 14:57:08 +01002192 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_SIGN"
2193 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_RSA_PSS"
Steven Cooremand50db942021-03-08 17:17:15 +01002194 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_SHA_1"
2195 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_SHA_224"
2196 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_SHA_256"
2197 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_SHA_384"
2198 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_SHA_512"
Ronald Crone6f63012021-03-19 14:57:08 +01002199 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_XTS"
Steven Cooreman7515e752021-03-19 19:36:38 +01002200 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_CMAC"
2201 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_HMAC"
Ronald Cron17b3afc2020-12-10 18:17:09 +01002202 loc_cflags="${loc_cflags} -I../tests/include -O2"
2203
2204 make CC=gcc CFLAGS="${loc_cflags}" LDFLAGS="$ASAN_CFLAGS"
2205 unset loc_cflags
Steven Cooremand57203d2020-07-16 20:28:59 +02002206
Steven Cooreman753f9732021-03-15 11:38:44 +01002207 msg "test: full + MBEDTLS_PSA_CRYPTO_DRIVERS"
Steven Cooremand57203d2020-07-16 20:28:59 +02002208 make test
2209}
2210
Gilles Peskine8f073122018-11-27 15:58:47 +01002211component_test_make_shared () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01002212 msg "build/test: make shared" # ~ 40s
Andrzej Kurek232e8f92019-10-03 03:18:01 -04002213 make SHARED=1 all check
Gilles Peskine56c01612019-07-03 20:43:32 +02002214 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskine8f073122018-11-27 15:58:47 +01002215}
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +02002216
Gilles Peskinecf740502019-07-03 20:43:05 +02002217component_test_cmake_shared () {
2218 msg "build/test: cmake shared" # ~ 2min
2219 cmake -DUSE_SHARED_MBEDTLS_LIBRARY=On .
2220 make
Gilles Peskine56c01612019-07-03 20:43:32 +02002221 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskinecf740502019-07-03 20:43:05 +02002222 make test
2223}
2224
Gilles Peskineec10bf12019-09-20 19:56:06 +02002225test_build_opt () {
2226 info=$1 cc=$2; shift 2
2227 for opt in "$@"; do
2228 msg "build/test: $cc $opt, $info" # ~ 30s
Gilles Peskinee094a182020-04-14 20:08:41 +02002229 make CC="$cc" CFLAGS="$opt -std=c99 -pedantic -Wall -Wextra -Werror"
Gilles Peskineec10bf12019-09-20 19:56:06 +02002230 # We're confident enough in compilers to not run _all_ the tests,
2231 # but at least run the unit tests. In particular, runs with
2232 # optimizations use inline assembly whereas runs with -O0
2233 # skip inline assembly.
2234 make test # ~30s
2235 make clean
2236 done
2237}
2238
2239component_test_clang_opt () {
Manuel Pégourié-Gonnard68192fc2020-03-04 10:34:47 +01002240 scripts/config.py full
Gilles Peskineec10bf12019-09-20 19:56:06 +02002241 test_build_opt 'full config' clang -O0 -Os -O2
2242}
2243
2244component_test_gcc_opt () {
Manuel Pégourié-Gonnard68192fc2020-03-04 10:34:47 +01002245 scripts/config.py full
Gilles Peskineec10bf12019-09-20 19:56:06 +02002246 test_build_opt 'full config' gcc -O0 -Os -O2
2247}
2248
Gilles Peskineabf9b4d2019-07-03 20:42:16 +02002249component_build_mbedtls_config_file () {
2250 msg "build: make with MBEDTLS_CONFIG_FILE" # ~40s
2251 # Use the full config so as to catch a maximum of places where
2252 # the check of MBEDTLS_CONFIG_FILE might be missing.
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002253 scripts/config.py full
Gilles Peskineabf9b4d2019-07-03 20:42:16 +02002254 sed 's!"check_config.h"!"mbedtls/check_config.h"!' <"$CONFIG_H" >full_config.h
2255 echo '#error "MBEDTLS_CONFIG_FILE is not working"' >"$CONFIG_H"
2256 make CFLAGS="-I '$PWD' -DMBEDTLS_CONFIG_FILE='\"full_config.h\"'"
2257 rm -f full_config.h
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00002258}
2259
Gilles Peskine8f073122018-11-27 15:58:47 +01002260component_test_m32_o0 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +01002261 # Build once with -O0, to compile out the i386 specific inline assembly
2262 msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002263 scripts/config.py full
Gilles Peskine8fd59422019-10-21 17:11:33 +02002264 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O0" LDFLAGS="-m32 $ASAN_CFLAGS"
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01002265
Simon Butcher8e6a22a2018-07-20 21:27:33 +01002266 msg "test: i386, make, gcc -O0 (ASan build)"
2267 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01002268}
Gilles Peskine878cf602019-01-06 20:50:38 +00002269support_test_m32_o0 () {
2270 case $(uname -m) in
2271 *64*) true;;
2272 *) false;;
2273 esac
2274}
Simon Butcher8e6a22a2018-07-20 21:27:33 +01002275
Gilles Peskine8f073122018-11-27 15:58:47 +01002276component_test_m32_o1 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +01002277 # Build again with -O1, to compile in the i386 specific inline assembly
2278 msg "build: i386, make, gcc -O1 (ASan build)" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002279 scripts/config.py full
Gilles Peskine8fd59422019-10-21 17:11:33 +02002280 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O1" LDFLAGS="-m32 $ASAN_CFLAGS"
Simon Butcher8e6a22a2018-07-20 21:27:33 +01002281
2282 msg "test: i386, make, gcc -O1 (ASan build)"
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01002283 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +01002284
2285 msg "test ssl-opt.sh, i386, make, gcc-O1"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002286 tests/ssl-opt.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01002287}
Gilles Peskine878cf602019-01-06 20:50:38 +00002288support_test_m32_o1 () {
2289 support_test_m32_o0 "$@"
2290}
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01002291
Gilles Peskine0c6b7992019-04-12 20:29:48 +02002292component_test_m32_everest () {
2293 msg "build: i386, Everest ECDH context (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002294 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
Gilles Peskine8fd59422019-10-21 17:11:33 +02002295 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O2" LDFLAGS="-m32 $ASAN_CFLAGS"
Gilles Peskine0c6b7992019-04-12 20:29:48 +02002296
2297 msg "test: i386, Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
2298 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +01002299
2300 msg "test: i386, Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002301 tests/ssl-opt.sh -f ECDH
Gilles Peskine636c26a2020-03-04 20:46:15 +01002302
2303 msg "test: i386, Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
2304 # Exclude some symmetric ciphers that are redundant here to gain time.
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002305 tests/compat.sh -f ECDH -V NO -e 'ARIA\|CAMELLIA\|CHACHA\|DES'
Gilles Peskine0c6b7992019-04-12 20:29:48 +02002306}
2307support_test_m32_everest () {
2308 support_test_m32_o0 "$@"
2309}
2310
Gilles Peskine8f073122018-11-27 15:58:47 +01002311component_test_mx32 () {
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01002312 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002313 scripts/config.py full
Gilles Peskine5d26e7c2019-06-07 14:50:09 +02002314 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32' LDFLAGS='-mx32'
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01002315
2316 msg "test: 64-bit ILP32, make, gcc"
2317 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01002318}
Gilles Peskine878cf602019-01-06 20:50:38 +00002319support_test_mx32 () {
2320 case $(uname -m) in
2321 amd64|x86_64) true;;
2322 *) false;;
2323 esac
2324}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00002325
Peter Kolbus60c6da22018-12-27 06:59:04 -06002326component_test_min_mpi_window_size () {
2327 msg "build: Default + MBEDTLS_MPI_WINDOW_SIZE=1 (ASan build)" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002328 scripts/config.py set MBEDTLS_MPI_WINDOW_SIZE 1
Peter Kolbus60c6da22018-12-27 06:59:04 -06002329 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2330 make
2331
2332 msg "test: MBEDTLS_MPI_WINDOW_SIZE=1 - main suites (inc. selftests) (ASan build)" # ~ 10s
2333 make test
2334}
2335
Gilles Peskine8f073122018-11-27 15:58:47 +01002336component_test_have_int32 () {
2337 msg "build: gcc, force 32-bit bignum limbs"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002338 scripts/config.py unset MBEDTLS_HAVE_ASM
2339 scripts/config.py unset MBEDTLS_AESNI_C
2340 scripts/config.py unset MBEDTLS_PADLOCK_C
Gilles Peskine8f073122018-11-27 15:58:47 +01002341 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01002342
Gilles Peskine8f073122018-11-27 15:58:47 +01002343 msg "test: gcc, force 32-bit bignum limbs"
2344 make test
2345}
Andres Amaya Garciafe843a32017-07-20 13:21:34 +01002346
Gilles Peskine8f073122018-11-27 15:58:47 +01002347component_test_have_int64 () {
2348 msg "build: gcc, force 64-bit bignum limbs"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002349 scripts/config.py unset MBEDTLS_HAVE_ASM
2350 scripts/config.py unset MBEDTLS_AESNI_C
2351 scripts/config.py unset MBEDTLS_PADLOCK_C
Gilles Peskine8f073122018-11-27 15:58:47 +01002352 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
Gilles Peskine14c3c062018-01-29 21:25:12 +01002353
Gilles Peskine8f073122018-11-27 15:58:47 +01002354 msg "test: gcc, force 64-bit bignum limbs"
2355 make test
2356}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00002357
Gilles Peskine8f073122018-11-27 15:58:47 +01002358component_test_no_udbl_division () {
2359 msg "build: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002360 scripts/config.py full
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002361 scripts/config.py set MBEDTLS_NO_UDBL_DIVISION
Gilles Peskine8f073122018-11-27 15:58:47 +01002362 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02002363
Gilles Peskine8f073122018-11-27 15:58:47 +01002364 msg "test: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
2365 make test
2366}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02002367
Gilles Peskine8f073122018-11-27 15:58:47 +01002368component_test_no_64bit_multiplication () {
2369 msg "build: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002370 scripts/config.py full
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002371 scripts/config.py set MBEDTLS_NO_64BIT_MULTIPLICATION
Gilles Peskine8f073122018-11-27 15:58:47 +01002372 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02002373
Gilles Peskine8f073122018-11-27 15:58:47 +01002374 msg "test: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
2375 make test
2376}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02002377
Gilles Peskine3809f5f2020-11-09 15:40:05 +01002378component_test_no_strings () {
2379 msg "build: no strings" # ~10s
2380 scripts/config.py full
2381 # Disable options that activate a large amount of string constants.
2382 scripts/config.py unset MBEDTLS_DEBUG_C
2383 scripts/config.py unset MBEDTLS_ERROR_C
2384 scripts/config.py set MBEDTLS_ERROR_STRERROR_DUMMY
2385 scripts/config.py unset MBEDTLS_VERSION_FEATURES
2386 make CFLAGS='-Werror -Os'
2387
2388 msg "test: no strings" # ~ 10s
2389 make test
2390}
2391
Hanno Beckerc5722d12020-10-09 11:10:42 +01002392component_test_no_x509_info () {
2393 msg "build: full + MBEDTLS_X509_REMOVE_INFO" # ~ 10s
2394 scripts/config.pl full
2395 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
2396 scripts/config.pl set MBEDTLS_X509_REMOVE_INFO
2397 make CFLAGS='-Werror -O1'
2398
2399 msg "test: full + MBEDTLS_X509_REMOVE_INFO" # ~ 10s
2400 make test
2401
2402 msg "test: ssl-opt.sh, full + MBEDTLS_X509_REMOVE_INFO" # ~ 1 min
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002403 tests/ssl-opt.sh
Hanno Beckerc5722d12020-10-09 11:10:42 +01002404}
2405
Gilles Peskine8f073122018-11-27 15:58:47 +01002406component_build_arm_none_eabi_gcc () {
Gilles Peskine18487f62020-04-30 23:11:54 +02002407 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002408 scripts/config.py baremetal
Gilles Peskineaeedd742020-09-02 11:03:04 +02002409 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 +02002410
2411 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1"
2412 ${ARM_NONE_EABI_GCC_PREFIX}size library/*.o
Gilles Peskine8f073122018-11-27 15:58:47 +01002413}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02002414
Gilles Peskine2c897d72019-08-09 16:05:05 +02002415component_build_arm_none_eabi_gcc_arm5vte () {
Gilles Peskine18487f62020-04-30 23:11:54 +02002416 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=arm5vte" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002417 scripts/config.py baremetal
Gilles Peskine2c897d72019-08-09 16:05:05 +02002418 # Build for a target platform that's close to what Debian uses
2419 # for its "armel" distribution (https://wiki.debian.org/ArmEabiPort).
2420 # See https://github.com/ARMmbed/mbedtls/pull/2169 and comments.
2421 # It would be better to build with arm-linux-gnueabi-gcc but
2422 # we don't have that on our CI at this time.
Gilles Peskineaeedd742020-09-02 11:03:04 +02002423 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 +02002424
2425 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=armv5te -O1"
2426 ${ARM_NONE_EABI_GCC_PREFIX}size library/*.o
Gilles Peskine93e4e032019-08-05 11:34:25 +02002427}
2428
Gilles Peskine6e2fb862020-04-30 23:00:53 +02002429component_build_arm_none_eabi_gcc_m0plus () {
2430 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus" # ~ 10s
2431 scripts/config.py baremetal
Gilles Peskineaeedd742020-09-02 11:03:04 +02002432 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 +02002433
2434 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus -Os"
2435 ${ARM_NONE_EABI_GCC_PREFIX}size library/*.o
Gilles Peskine6e2fb862020-04-30 23:00:53 +02002436}
2437
Gilles Peskine8f073122018-11-27 15:58:47 +01002438component_build_arm_none_eabi_gcc_no_udbl_division () {
Gilles Peskine6d061342020-04-30 18:19:32 +02002439 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002440 scripts/config.py baremetal
2441 scripts/config.py set MBEDTLS_NO_UDBL_DIVISION
Gilles Peskineaeedd742020-09-02 11:03:04 +02002442 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 +01002443 echo "Checking that software 64-bit division is not required"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002444 not grep __aeabi_uldiv library/*.o
Gilles Peskine8f073122018-11-27 15:58:47 +01002445}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02002446
Gilles Peskine8f073122018-11-27 15:58:47 +01002447component_build_arm_none_eabi_gcc_no_64bit_multiplication () {
Gilles Peskine6d061342020-04-30 18:19:32 +02002448 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc MBEDTLS_NO_64BIT_MULTIPLICATION, make" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002449 scripts/config.py baremetal
2450 scripts/config.py set MBEDTLS_NO_64BIT_MULTIPLICATION
Gilles Peskineaeedd742020-09-02 11:03:04 +02002451 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 +01002452 echo "Checking that software 64-bit multiplication is not required"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002453 not grep __aeabi_lmul library/*.o
Gilles Peskine8f073122018-11-27 15:58:47 +01002454}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02002455
Gilles Peskine8f073122018-11-27 15:58:47 +01002456component_build_armcc () {
Gilles Peskine18487f62020-04-30 23:11:54 +02002457 msg "build: ARM Compiler 5"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002458 scripts/config.py baremetal
Gilles Peskinebca6ab92017-12-19 18:24:31 +01002459 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
Gilles Peskine18487f62020-04-30 23:11:54 +02002460
2461 msg "size: ARM Compiler 5"
2462 "$ARMC5_FROMELF" -z library/*.o
2463
Gilles Peskinebca6ab92017-12-19 18:24:31 +01002464 make clean
Andres AG87bb5772016-09-27 15:05:15 +01002465
Gilles Peskinebca6ab92017-12-19 18:24:31 +01002466 # ARM Compiler 6 - Target ARMv7-A
2467 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-a"
Simon Butcher940737f2017-07-23 13:42:36 +02002468
Gilles Peskinebca6ab92017-12-19 18:24:31 +01002469 # ARM Compiler 6 - Target ARMv7-M
2470 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m"
Simon Butcher940737f2017-07-23 13:42:36 +02002471
Gilles Peskinebca6ab92017-12-19 18:24:31 +01002472 # ARM Compiler 6 - Target ARMv8-A - AArch32
2473 armc6_build_test "--target=arm-arm-none-eabi -march=armv8.2-a"
Simon Butcher940737f2017-07-23 13:42:36 +02002474
Gilles Peskinebca6ab92017-12-19 18:24:31 +01002475 # ARM Compiler 6 - Target ARMv8-M
2476 armc6_build_test "--target=arm-arm-none-eabi -march=armv8-m.main"
Simon Butcher940737f2017-07-23 13:42:36 +02002477
Gilles Peskinebca6ab92017-12-19 18:24:31 +01002478 # ARM Compiler 6 - Target ARMv8-A - AArch64
2479 armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a"
Gilles Peskine8f073122018-11-27 15:58:47 +01002480}
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +01002481
Hanno Beckera711f6e2020-05-04 12:03:51 +01002482component_test_tls13_experimental () {
2483 msg "build: default config with MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL enabled"
2484 scripts/config.pl set MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL
2485 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2486 make
2487 msg "test: default config with MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL enabled"
2488 make test
2489}
2490
Gilles Peskine8f073122018-11-27 15:58:47 +01002491component_build_mingw () {
2492 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
Andrzej Kurek232e8f92019-10-03 03:18:01 -04002493 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 +00002494
Gilles Peskine8f073122018-11-27 15:58:47 +01002495 # note Make tests only builds the tests, but doesn't run them
Andrzej Kurek232e8f92019-10-03 03:18:01 -04002496 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 +01002497 make WINDOWS_BUILD=1 clean
Gilles Peskine2a458da2017-05-12 15:26:58 +02002498
Gilles Peskine8f073122018-11-27 15:58:47 +01002499 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
Andrzej Kurek232e8f92019-10-03 03:18:01 -04002500 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
2501 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 +01002502 make WINDOWS_BUILD=1 clean
2503}
Jaeden Amero117b8a42019-04-17 15:19:26 +01002504support_build_mingw() {
2505 case $(i686-w64-mingw32-gcc -dumpversion) in
2506 [0-5]*) false;;
2507 *) true;;
2508 esac
2509}
Simon Butcher91aef332016-11-17 09:20:50 +00002510
Gilles Peskine8f073122018-11-27 15:58:47 +01002511component_test_memsan () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01002512 msg "build: MSan (clang)" # ~ 1 min 20s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002513 scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm
Gilles Peskine7ad603e2017-12-10 23:22:20 +01002514 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
2515 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +02002516
Gilles Peskine7ad603e2017-12-10 23:22:20 +01002517 msg "test: main suites (MSan)" # ~ 10s
2518 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01002519
Gilles Peskine7ad603e2017-12-10 23:22:20 +01002520 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002521 tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01002522
Gilles Peskine7ad603e2017-12-10 23:22:20 +01002523 # Optional part(s)
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01002524
Gilles Peskine7ad603e2017-12-10 23:22:20 +01002525 if [ "$MEMORY" -gt 0 ]; then
2526 msg "test: compat.sh (MSan)" # ~ 6 min 20s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002527 tests/compat.sh
Gilles Peskine7ad603e2017-12-10 23:22:20 +01002528 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01002529}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01002530
Gilles Peskine69f190e2019-01-10 00:11:42 +01002531component_test_valgrind () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01002532 msg "build: Release (clang)"
Gilles Peskine7ad603e2017-12-10 23:22:20 +01002533 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
2534 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00002535
Gilles Peskine7ad603e2017-12-10 23:22:20 +01002536 msg "test: main suites valgrind (Release)"
2537 make memcheck
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00002538
Gilles Peskine636c26a2020-03-04 20:46:15 +01002539 # Optional parts (slow; currently broken on OS X because programs don't
2540 # seem to receive signals under valgrind on OS X).
Gilles Peskine7ad603e2017-12-10 23:22:20 +01002541 if [ "$MEMORY" -gt 0 ]; then
2542 msg "test: ssl-opt.sh --memcheck (Release)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002543 tests/ssl-opt.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01002544 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00002545
Gilles Peskine7ad603e2017-12-10 23:22:20 +01002546 if [ "$MEMORY" -gt 1 ]; then
2547 msg "test: compat.sh --memcheck (Release)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002548 tests/compat.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01002549 fi
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02002550
2551 if [ "$MEMORY" -gt 0 ]; then
2552 msg "test: context-info.sh --memcheck (Release)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002553 tests/context-info.sh --memcheck
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02002554 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01002555}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00002556
Gilles Peskine8f073122018-11-27 15:58:47 +01002557component_test_cmake_out_of_source () {
2558 msg "build: cmake 'out-of-source' build"
Gilles Peskine8f073122018-11-27 15:58:47 +01002559 MBEDTLS_ROOT_DIR="$PWD"
2560 mkdir "$OUT_OF_SOURCE_DIR"
2561 cd "$OUT_OF_SOURCE_DIR"
2562 cmake "$MBEDTLS_ROOT_DIR"
2563 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00002564
Gilles Peskine8f073122018-11-27 15:58:47 +01002565 msg "test: cmake 'out-of-source' build"
2566 make test
2567 # Test an SSL option that requires an auxiliary script in test/scripts/.
2568 # Also ensure that there are no error messages such as
2569 # "No such file or directory", which would indicate that some required
2570 # file is missing (ssl-opt.sh tolerates the absence of some files so
2571 # may exit with status 0 but emit errors).
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002572 ./tests/ssl-opt.sh -f 'Fallback SCSV: beginning of list' 2>ssl-opt.err
Gilles Peskinef7e956c2020-03-28 18:56:09 +01002573 cat ssl-opt.err >&2
2574 # If ssl-opt.err is non-empty, record an error and keep going.
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002575 [ ! -s ssl-opt.err ]
Gilles Peskinef7e956c2020-03-28 18:56:09 +01002576 rm ssl-opt.err
Gilles Peskine8f073122018-11-27 15:58:47 +01002577 cd "$MBEDTLS_ROOT_DIR"
2578 rm -rf "$OUT_OF_SOURCE_DIR"
Gilles Peskine8f073122018-11-27 15:58:47 +01002579}
Andres AGdc192212016-08-31 17:33:13 +01002580
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01002581component_test_cmake_as_subdirectory () {
2582 msg "build: cmake 'as-subdirectory' build"
2583 MBEDTLS_ROOT_DIR="$PWD"
2584
2585 cd programs/test/cmake_subproject
2586 cmake .
2587 make
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002588 ./cmake_subproject
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01002589
2590 cd "$MBEDTLS_ROOT_DIR"
2591 unset MBEDTLS_ROOT_DIR
2592}
2593
Chris Kayd259e342021-03-25 16:03:25 +00002594component_test_cmake_as_package () {
2595 msg "build: cmake 'as-package' build"
2596 MBEDTLS_ROOT_DIR="$PWD"
2597
2598 cd programs/test/cmake_package
2599 cmake .
2600 make
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002601 ./cmake_package
Chris Kayd259e342021-03-25 16:03:25 +00002602
2603 cd "$MBEDTLS_ROOT_DIR"
2604 unset MBEDTLS_ROOT_DIR
2605}
2606
2607component_test_cmake_as_package_install () {
2608 msg "build: cmake 'as-installed-package' build"
2609 MBEDTLS_ROOT_DIR="$PWD"
2610
2611 cd programs/test/cmake_package_install
2612 cmake .
2613 make
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002614 ./cmake_package_install
Chris Kayd259e342021-03-25 16:03:25 +00002615
2616 cd "$MBEDTLS_ROOT_DIR"
2617 unset MBEDTLS_ROOT_DIR
2618}
2619
Gilles Peskine8f073122018-11-27 15:58:47 +01002620component_test_zeroize () {
2621 # Test that the function mbedtls_platform_zeroize() is not optimized away by
2622 # different combinations of compilers and optimization flags by using an
2623 # auxiliary GDB script. Unfortunately, GDB does not return error values to the
2624 # system in all cases that the script fails, so we must manually search the
2625 # output to check whether the pass string is present and no failure strings
2626 # were printed.
Andres AGdc192212016-08-31 17:33:13 +01002627
Gilles Peskine4976e822019-01-06 19:52:22 +00002628 # Don't try to disable ASLR. We don't care about ASLR here. We do care
2629 # about a spurious message if Gdb tries and fails, so suppress that.
2630 gdb_disable_aslr=
2631 if [ -z "$(gdb -batch -nw -ex 'set disable-randomization off' 2>&1)" ]; then
2632 gdb_disable_aslr='set disable-randomization off'
2633 fi
2634
Gilles Peskine8f073122018-11-27 15:58:47 +01002635 for optimization_flag in -O2 -O3 -Ofast -Os; do
Gilles Peskine55f7c942019-01-09 22:28:21 +01002636 for compiler in clang gcc; do
2637 msg "test: $compiler $optimization_flag, mbedtls_platform_zeroize()"
2638 make programs CC="$compiler" DEBUG=1 CFLAGS="$optimization_flag"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002639 gdb -ex "$gdb_disable_aslr" -x tests/scripts/test_zeroize.gdb -nw -batch -nx 2>&1 | tee test_zeroize.log
2640 grep "The buffer was correctly zeroized" test_zeroize.log
2641 not grep -i "error" test_zeroize.log
Gilles Peskine55f7c942019-01-09 22:28:21 +01002642 rm -f test_zeroize.log
2643 make clean
2644 done
Andres Amaya Garcia29673812017-10-25 10:35:51 +01002645 done
Andres Amaya Garciad0d7bf62017-10-25 09:01:31 +01002646
Gilles Peskine4976e822019-01-06 19:52:22 +00002647 unset gdb_disable_aslr
Gilles Peskine8f073122018-11-27 15:58:47 +01002648}
Gilles Peskine192c72f2017-12-21 15:59:21 +01002649
Gilles Peskine8f073122018-11-27 15:58:47 +01002650component_check_python_files () {
2651 msg "Lint: Python scripts"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002652 tests/scripts/check-python-files.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01002653}
Gilles Peskine192c72f2017-12-21 15:59:21 +01002654
Gilles Peskine8f073122018-11-27 15:58:47 +01002655component_check_generate_test_code () {
2656 msg "uint test: generate_test_code.py"
Manuel Pégourié-Gonnarddfb114a2020-06-02 11:40:08 +02002657 # unittest writes out mundane stuff like number or tests run on stderr.
2658 # Our convention is to reserve stderr for actual errors, and write
2659 # harmless info on stdout so it can be suppress with --quiet.
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002660 ./tests/scripts/test_generate_test_code.py 2>&1
Gilles Peskine8f073122018-11-27 15:58:47 +01002661}
Gilles Peskine192c72f2017-12-21 15:59:21 +01002662
2663################################################################
2664#### Termination
2665################################################################
2666
Gilles Peskine8f073122018-11-27 15:58:47 +01002667post_report () {
2668 msg "Done, cleaning up"
2669 cleanup
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01002670
Gilles Peskine8f073122018-11-27 15:58:47 +01002671 final_report
2672}
2673
2674
2675
2676################################################################
2677#### Run all the things
2678################################################################
2679
Gilles Peskine5d996822020-03-28 21:09:21 +01002680# Function invoked by --error-test to test error reporting.
2681pseudo_component_error_test () {
2682 msg "Testing error reporting $error_test"
2683 if [ $KEEP_GOING -ne 0 ]; then
2684 echo "Expect three failing commands."
2685 fi
2686 error_test='this should not be used since the component runs in a subshell'
2687 grep non_existent /dev/null
2688 not grep -q . "$0"
2689 make unknown_target
2690 false "this should not be executed"
2691}
2692
Gilles Peskinee48351a2018-11-27 16:06:30 +01002693# Run one component and clean up afterwards.
Gilles Peskine8f073122018-11-27 15:58:47 +01002694run_component () {
Gilles Peskine608953e2019-01-02 18:57:02 +01002695 # Back up the configuration in case the component modifies it.
2696 # The cleanup function will restore it.
2697 cp -p "$CONFIG_H" "$CONFIG_BAK"
John Durkopbd069d32020-10-31 22:14:03 -07002698 cp -p "$CRYPTO_CONFIG_H" "$CRYPTO_CONFIG_BAK"
Gilles Peskineffcdeff2018-12-04 12:49:28 +01002699 current_component="$1"
Gilles Peskine9004a172019-09-16 15:20:36 +02002700 export MBEDTLS_TEST_CONFIGURATION="$current_component"
Gilles Peskine2ef377d2019-10-07 18:44:21 +02002701
2702 # Unconditionally create a seedfile that's sufficiently long.
2703 # Do this before each component, because a previous component may
2704 # have messed it up or shortened it.
Gilles Peskine88a07452021-07-08 19:03:50 +02002705 local dd_cmd
2706 dd_cmd=(dd if=/dev/urandom of=./tests/seedfile bs=64 count=1)
2707 case $OSTYPE in
2708 linux*|freebsd*|openbsd*|darwin*) dd_cmd+=(status=none)
2709 esac
2710 "${dd_cmd[@]}"
Gilles Peskine2ef377d2019-10-07 18:44:21 +02002711
Gilles Peskinece266c42020-03-28 18:50:43 +01002712 # Run the component in a subshell
2713 if [ $KEEP_GOING -eq 1 ]; then
2714 set +e
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +02002715 fi
Gilles Peskinece266c42020-03-28 18:50:43 +01002716 (
2717 if [ $QUIET -eq 1 ]; then
2718 # msg() will be silenced, so just print the component name here.
2719 echo "${current_component#component_}"
2720 exec >/dev/null
2721 fi
2722 if [ $KEEP_GOING -eq 1 ]; then
2723 # Keep "set -e" off, and run an ERR trap instead to record failures.
2724 set -E
2725 trap err_trap ERR
2726 fi
2727 # The next line is what runs the component
2728 "$@"
2729 if [ $KEEP_GOING -eq 1 ]; then
2730 trap - ERR
2731 exit $last_failure_status
2732 fi
2733 )
2734 component_status=$?
2735 if [ $KEEP_GOING -eq 1 ]; then
2736 set -e
2737 if [ $component_status -ne 0 ]; then
2738 failure_count=$((failure_count + 1))
2739 fi
2740 fi
Gilles Peskine2ef377d2019-10-07 18:44:21 +02002741
2742 # Restore the build tree to a clean state.
Gilles Peskinee48351a2018-11-27 16:06:30 +01002743 cleanup
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +02002744 unset current_component
Gilles Peskine8f073122018-11-27 15:58:47 +01002745}
2746
2747# Preliminary setup
2748pre_check_environment
2749pre_initialize_variables
2750pre_parse_command_line "$@"
Gilles Peskine348fb9a2018-11-27 17:04:29 +01002751
Gilles Peskine878cf602019-01-06 20:50:38 +00002752pre_check_git
Andrzej Kurekeb508712019-02-14 07:18:59 -05002753
Gilles Peskine878cf602019-01-06 20:50:38 +00002754build_status=0
2755if [ $KEEP_GOING -eq 1 ]; then
2756 pre_setup_keep_going
Gilles Peskine8f073122018-11-27 15:58:47 +01002757fi
Gilles Peskine67ffdaf2019-09-16 15:55:46 +02002758pre_prepare_outcome_file
Gilles Peskine878cf602019-01-06 20:50:38 +00002759pre_print_configuration
2760pre_check_tools
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01002761cleanup
Gilles Peskine1570b592021-04-22 01:10:12 +02002762pre_generate_files
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01002763
Gilles Peskinebeb3a812019-01-06 22:11:25 +00002764# Run the requested tests.
Gilles Peskine5d996822020-03-28 21:09:21 +01002765while [ $error_test -gt 0 ]; do
2766 run_component pseudo_component_error_test
2767 error_test=$((error_test - 1))
2768done
Gilles Peskinebeb3a812019-01-06 22:11:25 +00002769for component in $RUN_COMPONENTS; do
2770 run_component "component_$component"
2771done
Gilles Peskine8f073122018-11-27 15:58:47 +01002772
2773# We're done.
Gilles Peskine878cf602019-01-06 20:50:38 +00002774post_report