blob: 6249977c8262054fbfa66c6b2fe639c85677e63d [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
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400371check_headers_in_cpp () {
Peter Kolbus1bc1a4c2019-02-01 17:19:08 -0600372 ls include/mbedtls | grep "\.h$" >headers.txt
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400373 <programs/test/cpp_dummy_build.cpp sed -n 's/"$//; s!^#include "mbedtls/!!p' |
374 sort |
375 diff headers.txt -
376 rm headers.txt
377}
378
Gilles Peskine8f073122018-11-27 15:58:47 +0100379pre_parse_command_line () {
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000380 COMMAND_LINE_COMPONENTS=
Gilles Peskinea28db922019-01-10 00:05:18 +0100381 all_except=0
Gilles Peskine5d996822020-03-28 21:09:21 +0100382 error_test=0
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000383 no_armcc=
SimonB2e23c822016-04-16 21:54:39 +0100384
Jaeden Amero9b90f2e2018-11-02 18:34:17 +0000385 # Note that legacy options are ignored instead of being omitted from this
386 # list of options, so invocations that worked with previous version of
387 # all.sh will still run and work properly.
Gilles Peskine8f073122018-11-27 15:58:47 +0100388 while [ $# -gt 0 ]; do
Gilles Peskine55f7c942019-01-09 22:28:21 +0100389 case "$1" in
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200390 --append-outcome) append_outcome=1;;
Gilles Peskine6d061342020-04-30 18:19:32 +0200391 --arm-none-eabi-gcc-prefix) shift; ARM_NONE_EABI_GCC_PREFIX="$1";;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000392 --armcc) no_armcc=;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100393 --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
394 --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
Gilles Peskine5d996822020-03-28 21:09:21 +0100395 --error-test) error_test=$((error_test + 1));;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000396 --except) all_except=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100397 --force|-f) FORCE=1;;
398 --gnutls-cli) shift; GNUTLS_CLI="$1";;
399 --gnutls-legacy-cli) shift; GNUTLS_LEGACY_CLI="$1";;
400 --gnutls-legacy-serv) shift; GNUTLS_LEGACY_SERV="$1";;
401 --gnutls-serv) shift; GNUTLS_SERV="$1";;
402 --help|-h) usage; exit;;
403 --keep-going|-k) KEEP_GOING=1;;
Gilles Peskine878cf602019-01-06 20:50:38 +0000404 --list-all-components) printf '%s\n' $ALL_COMPONENTS; exit;;
405 --list-components) printf '%s\n' $SUPPORTED_COMPONENTS; exit;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100406 --memory|-m) MEMORY=1;;
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200407 --no-append-outcome) append_outcome=0;;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000408 --no-armcc) no_armcc=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100409 --no-force) FORCE=0;;
410 --no-keep-going) KEEP_GOING=0;;
411 --no-memory) MEMORY=0;;
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200412 --no-quiet) QUIET=0;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100413 --openssl) shift; OPENSSL="$1";;
414 --openssl-legacy) shift; OPENSSL_LEGACY="$1";;
415 --openssl-next) shift; OPENSSL_NEXT="$1";;
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200416 --outcome-file) shift; MBEDTLS_TEST_OUTCOME_FILE="$1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100417 --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200418 --quiet|-q) QUIET=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100419 --random-seed) unset SEED;;
Manuel Pégourié-Gonnarde0501912020-06-08 12:59:27 +0200420 --release-test|-r) SEED=$RELEASE_SEED;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100421 --seed|-s) shift; SEED="$1";;
422 -*)
423 echo >&2 "Unknown option: $1"
424 echo >&2 "Run $0 --help for usage."
425 exit 120
426 ;;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000427 *) COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS $1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100428 esac
429 shift
Gilles Peskine8f073122018-11-27 15:58:47 +0100430 done
SimonB2e23c822016-04-16 21:54:39 +0100431
Gilles Peskinea28db922019-01-10 00:05:18 +0100432 # With no list of components, run everything.
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000433 if [ -z "$COMMAND_LINE_COMPONENTS" ]; then
434 all_except=1
Andres AGdc192212016-08-31 17:33:13 +0100435 fi
436
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000437 # --no-armcc is a legacy option. The modern way is --except '*_armcc*'.
438 # Ignore it if components are listed explicitly on the command line.
Gilles Peskinea28db922019-01-10 00:05:18 +0100439 if [ -n "$no_armcc" ] && [ $all_except -eq 1 ]; then
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000440 COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS *_armcc*"
SimonB2e23c822016-04-16 21:54:39 +0100441 fi
SimonB2e23c822016-04-16 21:54:39 +0100442
Gilles Peskineb80f0d22020-03-28 21:37:59 +0100443 if [ $all_except -eq 0 ]; then
444 unsupported=0
445 for component in $COMMAND_LINE_COMPONENTS; do
446 case $component in
447 *[*?\[]*) continue;;
448 esac
449 case " $SUPPORTED_COMPONENTS " in
450 *" $component "*) :;;
451 *)
452 echo >&2 "Component $component was explicitly requested, but is not known or not supported."
453 unsupported=$((unsupported + 1));;
454 esac
455 done
456 if [ $unsupported -ne 0 ]; then
457 exit 2
458 fi
459 fi
460
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000461 # Build the list of components to run.
Gilles Peskinea28db922019-01-10 00:05:18 +0100462 RUN_COMPONENTS=
463 for component in $SUPPORTED_COMPONENTS; do
464 if is_component_included "$component"; [ $? -eq $all_except ]; then
465 RUN_COMPONENTS="$RUN_COMPONENTS $component"
466 fi
467 done
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000468
469 unset all_except
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000470 unset no_armcc
Gilles Peskine8f073122018-11-27 15:58:47 +0100471}
SimonB2e23c822016-04-16 21:54:39 +0100472
Gilles Peskine8f073122018-11-27 15:58:47 +0100473pre_check_git () {
474 if [ $FORCE -eq 1 ]; then
Gilles Peskine53190e62019-01-09 23:17:35 +0100475 rm -rf "$OUT_OF_SOURCE_DIR"
Gilles Peskine8f073122018-11-27 15:58:47 +0100476 git checkout-index -f -q $CONFIG_H
477 cleanup
478 else
SimonB2e23c822016-04-16 21:54:39 +0100479
Gilles Peskine8f073122018-11-27 15:58:47 +0100480 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
481 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
482 echo "You can either delete this directory manually, or force the test by rerunning"
483 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
484 exit 1
485 fi
486
Bence Szépkútibb0cfeb2021-05-28 09:42:25 +0200487 if ! git diff --quiet include/mbedtls/mbedtls_config.h; then
488 err_msg "Warning - the configuration file 'include/mbedtls/mbedtls_config.h' has been edited. "
Gilles Peskine8f073122018-11-27 15:58:47 +0100489 echo "You can either delete or preserve your work, or force the test by rerunning the"
490 echo "script as: $0 --force"
491 exit 1
492 fi
SimonB2e23c822016-04-16 21:54:39 +0100493 fi
Andrzej Kurekeb508712019-02-14 07:18:59 -0500494}
495
Gilles Peskine8f073122018-11-27 15:58:47 +0100496pre_setup_keep_going () {
Gilles Peskinece266c42020-03-28 18:50:43 +0100497 failure_count=0 # Number of failed components
498 last_failure_status=0 # Last failure status in this component
499
Gilles Peskinefec30cb2020-03-28 19:34:23 +0100500 # See err_trap
501 previous_failure_status=0
502 previous_failed_command=
503 previous_failure_funcall_depth=0
Gilles Peskinea681c592020-03-28 21:27:40 +0100504 unset report_failed_command
Gilles Peskinefec30cb2020-03-28 19:34:23 +0100505
Gilles Peskine7c652162017-12-11 00:01:40 +0100506 start_red=
507 end_color=
508 if [ -t 1 ]; then
Gilles Peskine9736b9d2018-01-02 21:54:17 +0100509 case "${TERM:-}" in
Gilles Peskine7c652162017-12-11 00:01:40 +0100510 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
511 start_red=$(printf '\033[31m')
512 end_color=$(printf '\033[0m')
513 ;;
514 esac
515 fi
Gilles Peskinece266c42020-03-28 18:50:43 +0100516
517 # Keep a summary of failures in a file. We'll print it out at the end.
518 failure_summary_file=$PWD/all-sh-failures-$$.log
519 : >"$failure_summary_file"
520
521 # Whether it makes sense to keep a component going after the specified
522 # command fails (test command) or not (configure or build).
523 # This doesn't have to be 100% accurate: all failures are recorded anyway.
524 can_keep_going_after_failure () {
525 case "$1" in
526 "msg "*) false;;
527 *[!A-Za-z]"test"|*[!A-Za-z]"test"[!A-Za-z]*) true;;
528 "tests/"*) true;;
Gilles Peskinea681c592020-03-28 21:27:40 +0100529 "grep "*|"! grep "*) true;;
Gilles Peskinece266c42020-03-28 18:50:43 +0100530 *) false;;
Gilles Peskine7c652162017-12-11 00:01:40 +0100531 esac
532 }
Gilles Peskinece266c42020-03-28 18:50:43 +0100533
534 # This function runs if there is any error in a component.
535 # It must either exit with a nonzero status, or set
536 # last_failure_status to a nonzero value.
537 err_trap () {
538 # Save $? (status of the failing command). This must be the very
539 # first thing, before $? is overridden.
540 last_failure_status=$?
Gilles Peskinea681c592020-03-28 21:27:40 +0100541 failed_command=${report_failed_command-$BASH_COMMAND}
Gilles Peskinece266c42020-03-28 18:50:43 +0100542
Gilles Peskinefec30cb2020-03-28 19:34:23 +0100543 if [[ $last_failure_status -eq $previous_failure_status &&
544 "$failed_command" == "$previous_failed_command" &&
545 ${#FUNCNAME[@]} == $((previous_failure_funcall_depth - 1)) ]]
546 then
547 # The same command failed twice in a row, but this time one level
548 # less deep in the function call stack. This happens when the last
549 # command of a function returns a nonzero status, and the function
550 # returns that same status. Ignore the second failure.
551 previous_failure_funcall_depth=${#FUNCNAME[@]}
552 return
553 fi
554 previous_failure_status=$last_failure_status
555 previous_failed_command=$failed_command
556 previous_failure_funcall_depth=${#FUNCNAME[@]}
557
Gilles Peskinece266c42020-03-28 18:50:43 +0100558 text="$current_section: $failed_command -> $last_failure_status"
559 echo "${start_red}^^^^$text^^^^${end_color}" >&2
560 echo "$text" >>"$failure_summary_file"
561
562 # If the command is fatal (configure or build command), stop this
563 # component. Otherwise (test command) keep the component running
564 # (run more tests from the same build).
565 if ! can_keep_going_after_failure "$failed_command"; then
566 exit $last_failure_status
567 fi
568 }
569
Gilles Peskine7c652162017-12-11 00:01:40 +0100570 final_report () {
571 if [ $failure_count -gt 0 ]; then
572 echo
573 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Gilles Peskinece266c42020-03-28 18:50:43 +0100574 echo "${start_red}FAILED: $failure_count components${end_color}"
575 cat "$failure_summary_file"
Gilles Peskine7c652162017-12-11 00:01:40 +0100576 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
577 elif [ -z "${1-}" ]; then
578 echo "SUCCESS :)"
579 fi
580 if [ -n "${1-}" ]; then
581 echo "Killed by SIG$1."
582 fi
Gilles Peskinece266c42020-03-28 18:50:43 +0100583 rm -f "$failure_summary_file"
584 if [ $failure_count -gt 0 ]; then
585 exit 1
586 fi
Gilles Peskine7c652162017-12-11 00:01:40 +0100587 }
Gilles Peskine8f073122018-11-27 15:58:47 +0100588}
589
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200590# record_status() and if_build_succeeded() are kept temporarily for backward
591# compatibility. Don't use them in new components.
Gilles Peskinece266c42020-03-28 18:50:43 +0100592record_status () {
593 "$@"
Gilles Peskine7c652162017-12-11 00:01:40 +0100594}
Gilles Peskinece266c42020-03-28 18:50:43 +0100595if_build_succeeded () {
596 "$@"
597}
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200598
Gilles Peskinea681c592020-03-28 21:27:40 +0100599# '! true' does not trigger the ERR trap. Arrange to trigger it, with
600# a reasonably informative error message (not just "$@").
601not () {
602 if "$@"; then
603 report_failed_command="! $*"
604 false
605 unset report_failed_command
606 fi
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200607}
608
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200609pre_setup_quiet_redirect () {
610 if [ $QUIET -ne 1 ]; then
611 redirect_out () {
612 "$@"
613 }
Manuel Pégourié-Gonnardf1f180a2020-06-08 10:46:35 +0200614 redirect_err () {
615 "$@"
616 }
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200617 else
618 redirect_out () {
619 "$@" >/dev/null
620 }
Manuel Pégourié-Gonnardf1f180a2020-06-08 10:46:35 +0200621 redirect_err () {
622 "$@" 2>/dev/null
623 }
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200624 fi
625}
626
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200627pre_prepare_outcome_file () {
628 case "$MBEDTLS_TEST_OUTCOME_FILE" in
629 [!/]*) MBEDTLS_TEST_OUTCOME_FILE="$PWD/$MBEDTLS_TEST_OUTCOME_FILE";;
630 esac
631 if [ -n "$MBEDTLS_TEST_OUTCOME_FILE" ] && [ "$append_outcome" -eq 0 ]; then
632 rm -f "$MBEDTLS_TEST_OUTCOME_FILE"
633 fi
634}
635
Gilles Peskine8f073122018-11-27 15:58:47 +0100636pre_print_configuration () {
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200637 if [ $QUIET -eq 1 ]; then
638 return
639 fi
640
Gilles Peskine8f073122018-11-27 15:58:47 +0100641 msg "info: $0 configuration"
642 echo "MEMORY: $MEMORY"
643 echo "FORCE: $FORCE"
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200644 echo "MBEDTLS_TEST_OUTCOME_FILE: ${MBEDTLS_TEST_OUTCOME_FILE:-(none)}"
Gilles Peskine8f073122018-11-27 15:58:47 +0100645 echo "SEED: ${SEED-"UNSET"}"
Gilles Peskine636c26a2020-03-04 20:46:15 +0100646 echo
Gilles Peskine8f073122018-11-27 15:58:47 +0100647 echo "OPENSSL: $OPENSSL"
648 echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
649 echo "OPENSSL_NEXT: $OPENSSL_NEXT"
650 echo "GNUTLS_CLI: $GNUTLS_CLI"
651 echo "GNUTLS_SERV: $GNUTLS_SERV"
652 echo "GNUTLS_LEGACY_CLI: $GNUTLS_LEGACY_CLI"
653 echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV"
654 echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
655 echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
656}
Andres AG7770ea82016-10-10 15:46:20 +0100657
Andres AGd9eba4b2016-08-26 14:42:14 +0100658# Make sure the tools we need are available.
Gilles Peskine8f073122018-11-27 15:58:47 +0100659pre_check_tools () {
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000660 # Build the list of variables to pass to output_env.sh.
661 set env
SimonB2e23c822016-04-16 21:54:39 +0100662
Gilles Peskine87964262019-01-06 22:40:00 +0000663 case " $RUN_COMPONENTS " in
664 # Require OpenSSL and GnuTLS if running any tests (as opposed to
665 # only doing builds). Not all tests run OpenSSL and GnuTLS, but this
666 # is a good enough approximation in practice.
667 *" test_"*)
668 # To avoid setting OpenSSL and GnuTLS for each call to compat.sh
669 # and ssl-opt.sh, we just export the variables they require.
670 export OPENSSL_CMD="$OPENSSL"
671 export GNUTLS_CLI="$GNUTLS_CLI"
672 export GNUTLS_SERV="$GNUTLS_SERV"
673 # Avoid passing --seed flag in every call to ssl-opt.sh
674 if [ -n "${SEED-}" ]; then
675 export SEED
676 fi
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000677 set "$@" OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY"
678 set "$@" GNUTLS_CLI="$GNUTLS_CLI" GNUTLS_SERV="$GNUTLS_SERV"
679 set "$@" GNUTLS_LEGACY_CLI="$GNUTLS_LEGACY_CLI"
680 set "$@" GNUTLS_LEGACY_SERV="$GNUTLS_LEGACY_SERV"
Gilles Peskine87964262019-01-06 22:40:00 +0000681 check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$OPENSSL_NEXT" \
682 "$GNUTLS_CLI" "$GNUTLS_SERV" \
683 "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV"
684 ;;
685 esac
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200686
Gilles Peskine87964262019-01-06 22:40:00 +0000687 case " $RUN_COMPONENTS " in
688 *_doxygen[_\ ]*) check_tools "doxygen" "dot";;
689 esac
Andres AGd9eba4b2016-08-26 14:42:14 +0100690
Gilles Peskine87964262019-01-06 22:40:00 +0000691 case " $RUN_COMPONENTS " in
Gilles Peskine6d061342020-04-30 18:19:32 +0200692 *_arm_none_eabi_gcc[_\ ]*) check_tools "${ARM_NONE_EABI_GCC_PREFIX}gcc";;
Gilles Peskine87964262019-01-06 22:40:00 +0000693 esac
Andres AGd9eba4b2016-08-26 14:42:14 +0100694
Gilles Peskine87964262019-01-06 22:40:00 +0000695 case " $RUN_COMPONENTS " in
696 *_mingw[_\ ]*) check_tools "i686-w64-mingw32-gcc";;
697 esac
698
699 case " $RUN_COMPONENTS " in
700 *" test_zeroize "*) check_tools "gdb";;
701 esac
702
703 case " $RUN_COMPONENTS " in
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000704 *_armcc*)
Gilles Peskine87964262019-01-06 22:40:00 +0000705 ARMC5_CC="$ARMC5_BIN_DIR/armcc"
706 ARMC5_AR="$ARMC5_BIN_DIR/armar"
Gilles Peskine18487f62020-04-30 23:11:54 +0200707 ARMC5_FROMELF="$ARMC5_BIN_DIR/fromelf"
Gilles Peskine87964262019-01-06 22:40:00 +0000708 ARMC6_CC="$ARMC6_BIN_DIR/armclang"
709 ARMC6_AR="$ARMC6_BIN_DIR/armar"
Gilles Peskine18487f62020-04-30 23:11:54 +0200710 ARMC6_FROMELF="$ARMC6_BIN_DIR/fromelf"
711 check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC5_FROMELF" \
712 "$ARMC6_CC" "$ARMC6_AR" "$ARMC6_FROMELF";;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000713 esac
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000714
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200715 # past this point, no call to check_tool, only printing output
716 if [ $QUIET -eq 1 ]; then
717 return
718 fi
719
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000720 msg "info: output_env.sh"
721 case $RUN_COMPONENTS in
722 *_armcc*)
723 set "$@" ARMC5_CC="$ARMC5_CC" ARMC6_CC="$ARMC6_CC" RUN_ARMCC=1;;
724 *) set "$@" RUN_ARMCC=0;;
725 esac
726 "$@" scripts/output_env.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100727}
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100728
Gilles Peskine1570b592021-04-22 01:10:12 +0200729pre_generate_files() {
Manuel Pégourié-Gonnard87db8a22021-06-18 13:30:14 +0200730 # since make doesn't have proper dependencies, remove any possibly outdate
731 # file that might be around before generating fresh ones
732 make neat
Gilles Peskine1570b592021-04-22 01:10:12 +0200733 make generated_files
734}
735
Gilles Peskine192c72f2017-12-21 15:59:21 +0100736
737
738################################################################
739#### Basic checks
740################################################################
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100741
742#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200743# Test Suites to be executed
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100744#
Manuel Pégourié-Gonnard3d404b42015-07-08 21:59:16 +0100745# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200746# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100747# 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 +0200748# time, so start with a GCC build).
749# 2. Minimize total running time, by avoiding useless rebuilds
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100750#
Manuel Pégourié-Gonnard259b08a2016-01-08 16:27:41 +0100751# Indicative running times are given for reference.
752
Gilles Peskine8f073122018-11-27 15:58:47 +0100753component_check_recursion () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200754 msg "Check: recursion.pl" # < 1s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200755 tests/scripts/recursion.pl library/*.c
Gilles Peskine8f073122018-11-27 15:58:47 +0100756}
Janos Follathb72c6782016-07-19 14:54:17 +0100757
Gilles Peskine67debb62021-05-18 16:09:50 +0200758component_check_generated_files () {
759 msg "Check: check-generated-files, files generated with make" # 2s
760 make generated_files
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200761 tests/scripts/check-generated-files.sh
Gilles Peskine67debb62021-05-18 16:09:50 +0200762
763 msg "Check: check-generated-files -u, files present" # 2s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200764 tests/scripts/check-generated-files.sh -u
Gilles Peskine67debb62021-05-18 16:09:50 +0200765 # Check that the generated files are considered up to date.
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200766 tests/scripts/check-generated-files.sh
Gilles Peskine67debb62021-05-18 16:09:50 +0200767
768 msg "Check: check-generated-files -u, files absent" # 2s
769 command make neat
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200770 tests/scripts/check-generated-files.sh -u
Gilles Peskine67debb62021-05-18 16:09:50 +0200771 # Check that the generated files are considered up to date.
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200772 tests/scripts/check-generated-files.sh
Gilles Peskine67debb62021-05-18 16:09:50 +0200773
774 # This component ends with the generated files present in the source tree.
775 # This is necessary for subsequent components!
776}
777
Gilles Peskine8f073122018-11-27 15:58:47 +0100778component_check_doxy_blocks () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200779 msg "Check: doxygen markup outside doxygen blocks" # < 1s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200780 tests/scripts/check-doxy-blocks.pl
Gilles Peskine8f073122018-11-27 15:58:47 +0100781}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200782
Gilles Peskine8f073122018-11-27 15:58:47 +0100783component_check_files () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200784 msg "Check: file sanity checks (permissions, encodings)" # < 1s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200785 tests/scripts/check_files.py
Gilles Peskine8f073122018-11-27 15:58:47 +0100786}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200787
Gilles Peskine30e0bb42020-05-10 17:40:49 +0200788component_check_changelog () {
789 msg "Check: changelog entries" # < 1s
790 rm -f ChangeLog.new
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200791 scripts/assemble_changelog.py -o ChangeLog.new
Gilles Peskine30e0bb42020-05-10 17:40:49 +0200792 if [ -e ChangeLog.new ]; then
793 # Show the diff for information. It isn't an error if the diff is
794 # non-empty.
795 diff -u ChangeLog ChangeLog.new || true
796 rm ChangeLog.new
797 fi
798}
799
Gilles Peskine8f073122018-11-27 15:58:47 +0100800component_check_names () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200801 msg "Check: declared and exported names (builds the library)" # < 3s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200802 tests/scripts/check-names.sh -v
Gilles Peskine8f073122018-11-27 15:58:47 +0100803}
Darryl Greena07039c2018-03-13 16:48:16 +0000804
Gilles Peskine895868b2019-09-19 21:30:05 +0200805component_check_test_cases () {
806 msg "Check: test case descriptions" # < 1s
Manuel Pégourié-Gonnarda9119162020-06-02 11:51:40 +0200807 if [ $QUIET -eq 1 ]; then
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +0200808 opt='--quiet'
Manuel Pégourié-Gonnarda9119162020-06-02 11:51:40 +0200809 else
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +0200810 opt=''
Manuel Pégourié-Gonnarda9119162020-06-02 11:51:40 +0200811 fi
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200812 tests/scripts/check_test_cases.py $opt
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +0200813 unset opt
Gilles Peskine895868b2019-09-19 21:30:05 +0200814}
815
Gilles Peskine8f073122018-11-27 15:58:47 +0100816component_check_doxygen_warnings () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200817 msg "Check: doxygen warnings (builds the documentation)" # ~ 3s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200818 tests/scripts/doxygen.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100819}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200820
Gilles Peskine192c72f2017-12-21 15:59:21 +0100821
Gilles Peskine636c26a2020-03-04 20:46:15 +0100822
Gilles Peskine192c72f2017-12-21 15:59:21 +0100823################################################################
824#### Build and test many configurations and targets
825################################################################
826
Gilles Peskine7832c9f2019-04-08 17:00:15 +0200827component_test_default_out_of_box () {
828 msg "build: make, default config (out-of-box)" # ~1min
829 make
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200830 # Disable fancy stuff
Gilles Peskine717cd762019-09-27 20:21:11 +0200831 SAVE_MBEDTLS_TEST_OUTCOME_FILE="$MBEDTLS_TEST_OUTCOME_FILE"
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200832 unset MBEDTLS_TEST_OUTCOME_FILE
Gilles Peskine7832c9f2019-04-08 17:00:15 +0200833
834 msg "test: main suites make, default config (out-of-box)" # ~10s
835 make test
836
837 msg "selftest: make, default config (out-of-box)" # ~10s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200838 programs/test/selftest
Gilles Peskine717cd762019-09-27 20:21:11 +0200839
840 export MBEDTLS_TEST_OUTCOME_FILE="$SAVE_MBEDTLS_TEST_OUTCOME_FILE"
841 unset SAVE_MBEDTLS_TEST_OUTCOME_FILE
Gilles Peskine7832c9f2019-04-08 17:00:15 +0200842}
843
Gilles Peskine8f073122018-11-27 15:58:47 +0100844component_test_default_cmake_gcc_asan () {
845 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100846 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
847 make
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200848
Gilles Peskine8f073122018-11-27 15:58:47 +0100849 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
850 make test
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200851
Gilles Peskine97bea012020-04-23 23:37:45 +0200852 msg "test: selftest (ASan build)" # ~ 10s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200853 programs/test/selftest
Gilles Peskine97bea012020-04-23 23:37:45 +0200854
Gilles Peskine8f073122018-11-27 15:58:47 +0100855 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200856 tests/ssl-opt.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200857
Gilles Peskine8f073122018-11-27 15:58:47 +0100858 msg "test: compat.sh (ASan build)" # ~ 6 min
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200859 tests/compat.sh
Piotr Nowicki9978e6e2020-04-07 16:07:05 +0200860
861 msg "test: context-info.sh (ASan build)" # ~ 15 sec
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200862 tests/context-info.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100863}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200864
Hanno Becker01635512019-02-26 14:27:09 +0000865component_test_full_cmake_gcc_asan () {
866 msg "build: full config, cmake, gcc, ASan"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200867 scripts/config.py full
Hanno Becker01635512019-02-26 14:27:09 +0000868 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
869 make
870
871 msg "test: main suites (inc. selftests) (full config, ASan build)"
872 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +0100873
Gilles Peskine97bea012020-04-23 23:37:45 +0200874 msg "test: selftest (ASan build)" # ~ 10s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200875 programs/test/selftest
Gilles Peskine97bea012020-04-23 23:37:45 +0200876
Gilles Peskine636c26a2020-03-04 20:46:15 +0100877 msg "test: ssl-opt.sh (full config, ASan build)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200878 tests/ssl-opt.sh
Gilles Peskine636c26a2020-03-04 20:46:15 +0100879
880 msg "test: compat.sh (full config, ASan build)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200881 tests/compat.sh
Piotr Nowicki9978e6e2020-04-07 16:07:05 +0200882
883 msg "test: context-info.sh (full config, ASan build)" # ~ 15 sec
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200884 tests/context-info.sh
Gilles Peskine636c26a2020-03-04 20:46:15 +0100885}
886
Ronald Cronc3623db2020-10-29 10:51:32 +0100887component_test_psa_crypto_key_id_encodes_owner () {
888 msg "build: full config - USE_PSA_CRYPTO + PSA_CRYPTO_KEY_ID_ENCODES_OWNER, cmake, gcc, ASan"
889 scripts/config.py full
890 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
891 scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
892 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
893 make
894
895 msg "test: full config - USE_PSA_CRYPTO + PSA_CRYPTO_KEY_ID_ENCODES_OWNER, cmake, gcc, ASan"
896 make test
897}
898
Gilles Peskinea3548672021-06-17 11:37:52 +0200899# check_renamed_symbols HEADER LIB
900# Check that if HEADER contains '#define MACRO ...' then MACRO is not a symbol
901# name is LIB.
902check_renamed_symbols () {
903 ! nm "$2" | sed 's/.* //' |
904 grep -x -F "$(sed -n 's/^ *# *define *\([A-Z_a-z][0-9A-Z_a-z]*\)..*/\1/p' "$1")"
905}
906
Gilles Peskined1dcfd52021-06-15 18:37:38 +0200907component_build_psa_crypto_spm () {
908 msg "build: full config - USE_PSA_CRYPTO + PSA_CRYPTO_KEY_ID_ENCODES_OWNER + PSA_CRYPTO_SPM, make, gcc"
909 scripts/config.py full
910 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
911 scripts/config.py unset MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS
912 scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
913 scripts/config.py set MBEDTLS_PSA_CRYPTO_SPM
914 # We can only compile, not link, since our test and sample programs
915 # aren't equipped for the modified names used when MBEDTLS_PSA_CRYPTO_SPM
916 # is active.
917 make CC=gcc CFLAGS='-Werror -Wall -Wextra -I../tests/include/spe' lib
Gilles Peskinea3548672021-06-17 11:37:52 +0200918
919 # Check that if a symbol is renamed by crypto_spe.h, the non-renamed
920 # version is not present.
921 echo "Checking for renamed symbols in the library"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200922 check_renamed_symbols tests/include/spe/crypto_spe.h library/libmbedcrypto.a
Gilles Peskined1dcfd52021-06-15 18:37:38 +0200923}
924
Ronald Cron336678b2021-01-28 17:54:24 +0100925component_test_psa_crypto_client () {
926 msg "build: default config - PSA_CRYPTO_C + PSA_CRYPTO_CLIENT, make"
927 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C
928 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
929 scripts/config.py set MBEDTLS_PSA_CRYPTO_CLIENT
930 make
931
932 msg "test: default config - PSA_CRYPTO_C + PSA_CRYPTO_CLIENT, make"
933 make test
934}
935
Jaeden Amero424fa932021-05-14 08:34:32 +0100936component_test_psa_crypto_rsa_no_genprime() {
937 msg "build: default config minus MBEDTLS_GENPRIME"
938 scripts/config.py unset MBEDTLS_GENPRIME
939 make
940
941 msg "test: default config minus MBEDTLS_GENPRIME"
942 make test
943}
944
Gilles Peskine782f4112018-11-27 16:11:09 +0100945component_test_ref_configs () {
946 msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
947 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200948 tests/scripts/test-ref-configs.pl
Gilles Peskine782f4112018-11-27 16:11:09 +0100949}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200950
Gilles Peskine8f073122018-11-27 15:58:47 +0100951component_test_no_renegotiation () {
952 msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200953 scripts/config.py unset MBEDTLS_SSL_RENEGOTIATION
Gilles Peskine8f073122018-11-27 15:58:47 +0100954 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
955 make
Simon Butcher3ea7f522016-03-07 23:22:10 +0000956
Gilles Peskine8f073122018-11-27 15:58:47 +0100957 msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
958 make test
Hanno Becker134c2ab2017-10-12 15:29:50 +0100959
Gilles Peskine8f073122018-11-27 15:58:47 +0100960 msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200961 tests/ssl-opt.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100962}
Hanno Becker134c2ab2017-10-12 15:29:50 +0100963
Gilles Peskine636c26a2020-03-04 20:46:15 +0100964component_test_no_pem_no_fs () {
965 msg "build: Default + !MBEDTLS_PEM_PARSE_C + !MBEDTLS_FS_IO (ASan build)"
966 scripts/config.py unset MBEDTLS_PEM_PARSE_C
967 scripts/config.py unset MBEDTLS_FS_IO
968 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C # requires a filesystem
969 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA ITS
970 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
971 make
972
973 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - main suites (inc. selftests) (ASan build)" # ~ 50s
974 make test
975
976 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - ssl-opt.sh (ASan build)" # ~ 6 min
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200977 tests/ssl-opt.sh
Gilles Peskine636c26a2020-03-04 20:46:15 +0100978}
979
Gilles Peskine8f073122018-11-27 15:58:47 +0100980component_test_rsa_no_crt () {
981 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200982 scripts/config.py set MBEDTLS_RSA_NO_CRT
Gilles Peskine8f073122018-11-27 15:58:47 +0100983 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
984 make
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +0100985
Gilles Peskine8f073122018-11-27 15:58:47 +0100986 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
987 make test
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100988
Gilles Peskine8f073122018-11-27 15:58:47 +0100989 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200990 tests/ssl-opt.sh -f RSA
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100991
Gilles Peskine8f073122018-11-27 15:58:47 +0100992 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200993 tests/compat.sh -t RSA
Piotr Nowicki9978e6e2020-04-07 16:07:05 +0200994
995 msg "test: RSA_NO_CRT - RSA-related part of context-info.sh (ASan build)" # ~ 15 sec
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200996 tests/context-info.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100997}
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100998
Gilles Peskine2747d7d2021-02-03 14:56:51 +0100999component_test_no_ctr_drbg_classic () {
1000 msg "build: Full minus CTR_DRBG, classic crypto in TLS"
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +02001001 scripts/config.py full
1002 scripts/config.py unset MBEDTLS_CTR_DRBG_C
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001003 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +02001004
1005 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1006 make
1007
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001008 msg "test: Full minus CTR_DRBG, classic crypto - main suites"
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +02001009 make test
1010
Gilles Peskineba749042021-01-13 20:02:03 +01001011 # In this configuration, the TLS test programs use HMAC_DRBG.
1012 # The SSL tests are slow, so run a small subset, just enough to get
1013 # confidence that the SSL code copes with HMAC_DRBG.
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001014 msg "test: Full minus CTR_DRBG, classic crypto - ssl-opt.sh (subset)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001015 tests/ssl-opt.sh -f 'Default\|SSL async private.*delay=\|tickets enabled on server'
Gilles Peskineba749042021-01-13 20:02:03 +01001016
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001017 msg "test: Full minus CTR_DRBG, classic crypto - compat.sh (subset)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001018 tests/compat.sh -m tls1_2 -t 'ECDSA PSK' -V NO -p OpenSSL
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +02001019}
1020
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001021component_test_no_ctr_drbg_use_psa () {
1022 msg "build: Full minus CTR_DRBG, PSA crypto in TLS"
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +02001023 scripts/config.py full
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001024 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1025 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +02001026
1027 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1028 make
1029
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001030 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - main suites"
1031 make test
1032
1033 # In this configuration, the TLS test programs use HMAC_DRBG.
1034 # The SSL tests are slow, so run a small subset, just enough to get
1035 # confidence that the SSL code copes with HMAC_DRBG.
1036 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - ssl-opt.sh (subset)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001037 tests/ssl-opt.sh -f 'Default\|SSL async private.*delay=\|tickets enabled on server'
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001038
1039 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - compat.sh (subset)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001040 tests/compat.sh -m tls1_2 -t 'ECDSA PSK' -V NO -p OpenSSL
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001041}
1042
1043component_test_no_hmac_drbg_classic () {
1044 msg "build: Full minus HMAC_DRBG, classic crypto in TLS"
1045 scripts/config.py full
1046 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1047 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1048 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1049
1050 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1051 make
1052
1053 msg "test: Full minus HMAC_DRBG, classic crypto - main suites"
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +02001054 make test
1055
Gilles Peskinea2224342020-11-19 22:14:34 +01001056 # Normally our ECDSA implementation uses deterministic ECDSA. But since
1057 # HMAC_DRBG is disabled in this configuration, randomized ECDSA is used
1058 # instead.
1059 # Test SSL with non-deterministic ECDSA. Only test features that
1060 # might be affected by how ECDSA signature is performed.
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001061 msg "test: Full minus HMAC_DRBG, classic crypto - ssl-opt.sh (subset)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001062 tests/ssl-opt.sh -f 'Default\|SSL async private: sign'
Gilles Peskinea2224342020-11-19 22:14:34 +01001063
1064 # To save time, only test one protocol version, since this part of
1065 # the protocol is identical in (D)TLS up to 1.2.
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001066 msg "test: Full minus HMAC_DRBG, classic crypto - compat.sh (ECDSA)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001067 tests/compat.sh -m tls1_2 -t 'ECDSA'
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +02001068}
1069
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001070component_test_no_hmac_drbg_use_psa () {
1071 msg "build: Full minus HMAC_DRBG, PSA crypto in TLS"
1072 scripts/config.py full
1073 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1074 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1075 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1076
1077 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1078 make
1079
1080 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - main suites"
1081 make test
1082
1083 # Normally our ECDSA implementation uses deterministic ECDSA. But since
1084 # HMAC_DRBG is disabled in this configuration, randomized ECDSA is used
1085 # instead.
1086 # Test SSL with non-deterministic ECDSA. Only test features that
1087 # might be affected by how ECDSA signature is performed.
1088 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - ssl-opt.sh (subset)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001089 tests/ssl-opt.sh -f 'Default\|SSL async private: sign'
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001090
1091 # To save time, only test one protocol version, since this part of
1092 # the protocol is identical in (D)TLS up to 1.2.
1093 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - compat.sh (ECDSA)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001094 tests/compat.sh -m tls1_2 -t 'ECDSA'
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001095}
1096
1097component_test_psa_external_rng_no_drbg_classic () {
1098 msg "build: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto in TLS"
1099 scripts/config.py full
1100 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1101 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
Gilles Peskine38c12fd2021-02-08 21:02:53 +01001102 scripts/config.py unset MBEDTLS_ENTROPY_C
1103 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
1104 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001105 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1106 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1107 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
Gilles Peskine8eb29432021-02-03 20:07:11 +01001108 # When MBEDTLS_USE_PSA_CRYPTO is disabled and there is no DRBG,
1109 # the SSL test programs don't have an RNG and can't work. Explicitly
1110 # make them use the PSA RNG with -DMBEDTLS_TEST_USE_PSA_CRYPTO_RNG.
1111 make CFLAGS="$ASAN_CFLAGS -O2 -DMBEDTLS_TEST_USE_PSA_CRYPTO_RNG" LDFLAGS="$ASAN_CFLAGS"
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001112
1113 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto - main suites"
1114 make test
1115
Gilles Peskine8eb29432021-02-03 20:07:11 +01001116 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto - ssl-opt.sh (subset)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001117 tests/ssl-opt.sh -f 'Default'
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001118}
1119
1120component_test_psa_external_rng_no_drbg_use_psa () {
1121 msg "build: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto in TLS"
Gilles Peskinec109b372020-11-23 17:39:04 +01001122 scripts/config.py full
1123 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
Gilles Peskine38c12fd2021-02-08 21:02:53 +01001124 scripts/config.py unset MBEDTLS_ENTROPY_C
1125 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
1126 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskinec109b372020-11-23 17:39:04 +01001127 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1128 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1129 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
Gilles Peskinec109b372020-11-23 17:39:04 +01001130 make CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
1131
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001132 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto - main suites"
Gilles Peskinec109b372020-11-23 17:39:04 +01001133 make test
1134
Gilles Peskine8eb29432021-02-03 20:07:11 +01001135 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto - ssl-opt.sh (subset)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001136 tests/ssl-opt.sh -f 'Default\|opaque'
Gilles Peskinec109b372020-11-23 17:39:04 +01001137}
1138
1139component_test_psa_external_rng_use_psa_crypto () {
1140 msg "build: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
1141 scripts/config.py full
1142 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
1143 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1144 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1145 make CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
1146
1147 msg "test: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
1148 make test
1149
Gilles Peskineba749042021-01-13 20:02:03 +01001150 msg "test: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001151 tests/ssl-opt.sh -f 'Default\|opaque'
Gilles Peskinec109b372020-11-23 17:39:04 +01001152}
1153
Gilles Peskine636c26a2020-03-04 20:46:15 +01001154component_test_everest () {
1155 msg "build: Everest ECDH context (ASan build)" # ~ 6 min
Gilles Peskine636c26a2020-03-04 20:46:15 +01001156 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
1157 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Asan .
1158 make
1159
1160 msg "test: Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
1161 make test
1162
1163 msg "test: Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001164 tests/ssl-opt.sh -f ECDH
Gilles Peskine636c26a2020-03-04 20:46:15 +01001165
1166 msg "test: Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
1167 # Exclude some symmetric ciphers that are redundant here to gain time.
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001168 tests/compat.sh -f ECDH -V NO -e 'ARIA\|CAMELLIA\|CHACHA\|DES'
Gilles Peskine636c26a2020-03-04 20:46:15 +01001169}
1170
Gilles Peskined3beca92020-07-03 00:15:37 +02001171component_test_everest_curve25519_only () {
1172 msg "build: Everest ECDH context, only Curve25519" # ~ 6 min
Gilles Peskined3beca92020-07-03 00:15:37 +02001173 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
1174 scripts/config.py unset MBEDTLS_ECDSA_C
1175 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
1176 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
TRodziewicz7c1d41d2021-04-23 13:33:44 +02001177 scripts/config.py unset MBEDTLS_ECJPAKE_C
Gilles Peskined3beca92020-07-03 00:15:37 +02001178 # Disable all curves
1179 for c in $(sed -n 's/#define \(MBEDTLS_ECP_DP_[0-9A-Z_a-z]*_ENABLED\).*/\1/p' <"$CONFIG_H"); do
1180 scripts/config.py unset "$c"
1181 done
1182 scripts/config.py set MBEDTLS_ECP_DP_CURVE25519_ENABLED
1183
1184 make CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
1185
1186 msg "test: Everest ECDH context, only Curve25519" # ~ 50s
1187 make test
1188}
1189
Gilles Peskine8f073122018-11-27 15:58:47 +01001190component_test_small_ssl_out_content_len () {
1191 msg "build: small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001192 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 16384
1193 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
Gilles Peskine8f073122018-11-27 15:58:47 +01001194 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1195 make
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +01001196
Gilles Peskine8f073122018-11-27 15:58:47 +01001197 msg "test: small SSL_OUT_CONTENT_LEN - ssl-opt.sh MFL and large packet tests"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001198 tests/ssl-opt.sh -f "Max fragment\|Large packet"
Gilles Peskine8f073122018-11-27 15:58:47 +01001199}
Angus Grattonc4dd0732018-04-11 16:28:39 +10001200
Gilles Peskine8f073122018-11-27 15:58:47 +01001201component_test_small_ssl_in_content_len () {
1202 msg "build: small SSL_IN_CONTENT_LEN (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001203 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 4096
1204 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 16384
Gilles Peskine8f073122018-11-27 15:58:47 +01001205 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1206 make
Angus Grattonc4dd0732018-04-11 16:28:39 +10001207
Gilles Peskine8f073122018-11-27 15:58:47 +01001208 msg "test: small SSL_IN_CONTENT_LEN - ssl-opt.sh MFL tests"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001209 tests/ssl-opt.sh -f "Max fragment"
Gilles Peskine8f073122018-11-27 15:58:47 +01001210}
Angus Grattonc4dd0732018-04-11 16:28:39 +10001211
Gilles Peskine8f073122018-11-27 15:58:47 +01001212component_test_small_ssl_dtls_max_buffering () {
1213 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001214 scripts/config.py set MBEDTLS_SSL_DTLS_MAX_BUFFERING 1000
Gilles Peskine8f073122018-11-27 15:58:47 +01001215 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1216 make
Angus Grattonc4dd0732018-04-11 16:28:39 +10001217
Gilles Peskine8f073122018-11-27 15:58:47 +01001218 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0 - ssl-opt.sh specific reordering test"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001219 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 +01001220}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001221
Gilles Peskine8f073122018-11-27 15:58:47 +01001222component_test_small_mbedtls_ssl_dtls_max_buffering () {
1223 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1"
Gilles Peskine636c26a2020-03-04 20:46:15 +01001224 scripts/config.py set MBEDTLS_SSL_DTLS_MAX_BUFFERING 190
Gilles Peskine8f073122018-11-27 15:58:47 +01001225 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1226 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001227
Gilles Peskine8f073122018-11-27 15:58:47 +01001228 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1 - ssl-opt.sh specific reordering test"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001229 tests/ssl-opt.sh -f "DTLS reordering: Buffer encrypted Finished message, drop for fragmented NewSessionTicket"
Gilles Peskine8f073122018-11-27 15:58:47 +01001230}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001231
Gilles Peskine75cc7712019-09-06 19:47:17 +02001232component_test_psa_collect_statuses () {
1233 msg "build+test: psa_collect_statuses" # ~30s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001234 scripts/config.py full
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001235 tests/scripts/psa_collect_statuses.py
Gilles Peskine75cc7712019-09-06 19:47:17 +02001236 # Check that psa_crypto_init() succeeded at least once
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001237 grep -q '^0:psa_crypto_init:' tests/statuses.log
Gilles Peskine75cc7712019-09-06 19:47:17 +02001238 rm -f tests/statuses.log
1239}
1240
Gilles Peskine8f073122018-11-27 15:58:47 +01001241component_test_full_cmake_clang () {
1242 msg "build: cmake, full config, clang" # ~ 50s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001243 scripts/config.py full
Gilles Peskine8f073122018-11-27 15:58:47 +01001244 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check -D ENABLE_TESTING=On .
1245 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001246
k-stachowiak0291cb72019-06-26 15:52:12 +02001247 msg "test: main suites (full config, clang)" # ~ 5s
Gilles Peskine8f073122018-11-27 15:58:47 +01001248 make test
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +01001249
k-stachowiak0291cb72019-06-26 15:52:12 +02001250 msg "test: psa_constant_names (full config, clang)" # ~ 1s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001251 tests/scripts/test_psa_constant_names.py
Gilles Peskine69e8f7f2020-02-26 19:51:43 +01001252
Gilles Peskine8f073122018-11-27 15:58:47 +01001253 msg "test: ssl-opt.sh default, ECJPAKE, SSL async (full config)" # ~ 1s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001254 tests/ssl-opt.sh -f 'Default\|ECJPAKE\|SSL async private'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +02001255
TRodziewicz10e8cf52021-05-31 17:58:57 +02001256 msg "test: compat.sh DES, 3DES & NULL (full config)" # ~ 2 min
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001257 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 +02001258
Gilles Peskine8f073122018-11-27 15:58:47 +01001259 msg "test: compat.sh ARIA + ChachaPoly"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001260 env OPENSSL_CMD="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
Gilles Peskine8f073122018-11-27 15:58:47 +01001261}
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +02001262
Manuel Pégourié-Gonnard6240def2020-07-10 09:35:54 +02001263component_test_memsan_constant_flow () {
Manuel Pégourié-Gonnard0b2112d2020-07-22 11:09:28 +02001264 # This tests both (1) accesses to undefined memory, and (2) branches or
1265 # memory access depending on secret values. To distinguish between those:
1266 # - unset MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN - does the failure persist?
1267 # - or alternatively, change the build type to MemSanDbg, which enables
1268 # origin tracking and nicer stack traces (which are useful for debugging
1269 # anyway), and check if the origin was TEST_CF_SECRET() or something else.
1270 msg "build: cmake MSan (clang), full config with constant flow testing"
Manuel Pégourié-Gonnard6240def2020-07-10 09:35:54 +02001271 scripts/config.py full
1272 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN
1273 scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm
1274 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
1275 make
1276
Manuel Pégourié-Gonnard0b2112d2020-07-22 11:09:28 +02001277 msg "test: main suites (Msan + constant flow)"
Manuel Pégourié-Gonnard6240def2020-07-10 09:35:54 +02001278 make test
1279}
1280
Manuel Pégourié-Gonnard73afa372020-08-19 10:27:38 +02001281component_test_valgrind_constant_flow () {
1282 # This tests both (1) everything that valgrind's memcheck usually checks
1283 # (heap buffer overflows, use of uninitialized memory, use-after-free,
1284 # etc.) and (2) branches or memory access depending on secret values,
1285 # which will be reported as uninitialized memory. To distinguish between
1286 # secret and actually uninitialized:
1287 # - unset MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND - does the failure persist?
1288 # - or alternatively, build with debug info and manually run the offending
1289 # test suite with valgrind --track-origins=yes, then check if the origin
1290 # was TEST_CF_SECRET() or something else.
1291 msg "build: cmake release GCC, full config with constant flow testing"
1292 scripts/config.py full
1293 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND
1294 cmake -D CMAKE_BUILD_TYPE:String=Release .
1295 make
1296
1297 # this only shows a summary of the results (how many of each type)
1298 # details are left in Testing/<date>/DynamicAnalysis.xml
1299 msg "test: main suites (valgrind + constant flow)"
1300 make memcheck
1301}
1302
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001303component_test_default_no_deprecated () {
Gilles Peskine8386ea22020-04-30 09:07:29 +02001304 # Test that removing the deprecated features from the default
1305 # configuration leaves something consistent.
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001306 msg "build: make, default + MBEDTLS_DEPRECATED_REMOVED" # ~ 30s
1307 scripts/config.py set MBEDTLS_DEPRECATED_REMOVED
1308 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra'
1309
1310 msg "test: make, default + MBEDTLS_DEPRECATED_REMOVED" # ~ 5s
1311 make test
1312}
1313
1314component_test_full_no_deprecated () {
Gilles Peskine30de2e82020-04-20 21:39:22 +02001315 msg "build: make, full_no_deprecated config" # ~ 30s
1316 scripts/config.py full_no_deprecated
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001317 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra'
1318
Gilles Peskine30de2e82020-04-20 21:39:22 +02001319 msg "test: make, full_no_deprecated config" # ~ 5s
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001320 make test
1321}
1322
Gilles Peskine8386ea22020-04-30 09:07:29 +02001323component_test_full_no_deprecated_deprecated_warning () {
1324 # Test that there is nothing deprecated in "full_no_deprecated".
1325 # A deprecated feature would trigger a warning (made fatal) from
1326 # MBEDTLS_DEPRECATED_WARNING.
Gilles Peskine30de2e82020-04-20 21:39:22 +02001327 msg "build: make, full_no_deprecated config, MBEDTLS_DEPRECATED_WARNING" # ~ 30s
1328 scripts/config.py full_no_deprecated
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001329 scripts/config.py unset MBEDTLS_DEPRECATED_REMOVED
1330 scripts/config.py set MBEDTLS_DEPRECATED_WARNING
1331 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra'
1332
Gilles Peskine30de2e82020-04-20 21:39:22 +02001333 msg "test: make, full_no_deprecated config, MBEDTLS_DEPRECATED_WARNING" # ~ 5s
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001334 make test
1335}
1336
Gilles Peskine8386ea22020-04-30 09:07:29 +02001337component_test_full_deprecated_warning () {
1338 # Test that when MBEDTLS_DEPRECATED_WARNING is enabled, the build passes
1339 # with only certain whitelisted types of warnings.
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001340 msg "build: make, full config + MBEDTLS_DEPRECATED_WARNING, expect warnings" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001341 scripts/config.py full
1342 scripts/config.py set MBEDTLS_DEPRECATED_WARNING
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001343 # Expect warnings from '#warning' directives in check_config.h.
1344 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-error=cpp' lib programs
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +01001345
Gilles Peskine8386ea22020-04-30 09:07:29 +02001346 msg "build: make tests, full config + MBEDTLS_DEPRECATED_WARNING, expect warnings" # ~ 30s
1347 # Set MBEDTLS_TEST_DEPRECATED to enable tests for deprecated features.
1348 # By default those are disabled when MBEDTLS_DEPRECATED_WARNING is set.
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001349 # Expect warnings from '#warning' directives in check_config.h and
1350 # from the use of deprecated functions in test suites.
1351 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 +01001352
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001353 msg "test: full config + MBEDTLS_TEST_DEPRECATED" # ~ 30s
1354 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01001355}
Jaeden Ameroed93bdc2018-11-02 16:57:24 +00001356
Gilles Peskineec541fe2020-01-31 14:24:14 +01001357# Check that the specified libraries exist and are empty.
1358are_empty_libraries () {
1359 nm "$@" >/dev/null 2>/dev/null
1360 ! nm "$@" 2>/dev/null | grep -v ':$' | grep .
1361}
1362
1363component_build_crypto_default () {
1364 msg "build: make, crypto only"
1365 scripts/config.py crypto
Gilles Peskine6bb39152020-02-03 11:59:20 +01001366 make CFLAGS='-O1 -Werror'
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001367 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
Gilles Peskineec541fe2020-01-31 14:24:14 +01001368}
1369
1370component_build_crypto_full () {
1371 msg "build: make, crypto only, full config"
1372 scripts/config.py crypto_full
Gilles Peskine6bb39152020-02-03 11:59:20 +01001373 make CFLAGS='-O1 -Werror'
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001374 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
Gilles Peskineec541fe2020-01-31 14:24:14 +01001375}
1376
1377component_build_crypto_baremetal () {
1378 msg "build: make, crypto only, baremetal config"
1379 scripts/config.py crypto_baremetal
Gilles Peskine6bb39152020-02-03 11:59:20 +01001380 make CFLAGS='-O1 -Werror'
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001381 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
Gilles Peskineec541fe2020-01-31 14:24:14 +01001382}
1383
Gilles Peskine8f073122018-11-27 15:58:47 +01001384component_test_depends_curves () {
1385 msg "test/build: curves.pl (gcc)" # ~ 4 min
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001386 tests/scripts/curves.pl
Gilles Peskine8f073122018-11-27 15:58:47 +01001387}
Jaeden Ameroacaabe72018-11-07 11:52:52 +00001388
John Durkopc14be902020-08-20 06:16:41 -07001389component_test_depends_curves_psa () {
1390 msg "test/build: curves.pl with MBEDTLS_USE_PSA_CRYPTO defined (gcc)"
1391 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001392 tests/scripts/curves.pl
John Durkopc14be902020-08-20 06:16:41 -07001393}
1394
Gilles Peskine8f073122018-11-27 15:58:47 +01001395component_test_depends_hashes () {
1396 msg "test/build: depends-hashes.pl (gcc)" # ~ 2 min
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001397 tests/scripts/depends-hashes.pl
Gilles Peskine8f073122018-11-27 15:58:47 +01001398}
Jaeden Ameroacaabe72018-11-07 11:52:52 +00001399
John Durkop2ec2eaa2020-08-24 18:29:15 -07001400component_test_depends_hashes_psa () {
1401 msg "test/build: depends-hashes.pl with MBEDTLS_USE_PSA_CRYPTO defined (gcc)"
1402 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001403 tests/scripts/depends-hashes.pl
John Durkop2ec2eaa2020-08-24 18:29:15 -07001404}
1405
Gilles Peskine8f073122018-11-27 15:58:47 +01001406component_test_depends_pkalgs () {
1407 msg "test/build: depends-pkalgs.pl (gcc)" # ~ 2 min
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001408 tests/scripts/depends-pkalgs.pl
Gilles Peskine8f073122018-11-27 15:58:47 +01001409}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01001410
John Durkop619e09e2020-09-08 22:19:56 -07001411component_test_depends_pkalgs_psa () {
1412 msg "test/build: depends-pkalgs.pl with MBEDTLS_USE_PSA_CRYPTO defined (gcc)"
1413 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001414 tests/scripts/depends-pkalgs.pl
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01001415}
1416
Gilles Peskine8f073122018-11-27 15:58:47 +01001417component_build_key_exchanges () {
1418 msg "test/build: key-exchanges (gcc)" # ~ 1 min
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001419 tests/scripts/key-exchanges.pl
Gilles Peskine8f073122018-11-27 15:58:47 +01001420}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01001421
Gilles Peskine8f073122018-11-27 15:58:47 +01001422component_build_default_make_gcc_and_cxx () {
1423 msg "build: Unix make, -Os (gcc)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +01001424 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01001425
Gilles Peskine8f073122018-11-27 15:58:47 +01001426 msg "test: verify header list in cpp_dummy_build.cpp"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001427 check_headers_in_cpp
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01001428
Gilles Peskine8f073122018-11-27 15:58:47 +01001429 msg "build: Unix make, incremental g++"
1430 make TEST_CPP=1
1431}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01001432
Gilles Peskinecc73cc52021-05-25 09:04:46 +02001433component_build_module_alt () {
1434 msg "build: MBEDTLS_XXX_ALT" # ~30s
1435 scripts/config.py full
1436 # Disable options that are incompatible with some ALT implementations.
1437 # aesni.c and padlock.c reference mbedtls_aes_context fields directly.
1438 scripts/config.py unset MBEDTLS_AESNI_C
1439 scripts/config.py unset MBEDTLS_PADLOCK_C
Gilles Peskinecc73cc52021-05-25 09:04:46 +02001440 # You can only have one threading implementation: alt or pthread, not both.
1441 scripts/config.py unset MBEDTLS_THREADING_PTHREAD
Gilles Peskine5c3f18d2021-05-31 21:21:12 +02001442 # The SpecifiedECDomain parsing code accesses mbedtls_ecp_group fields
1443 # directly and assumes the implementation works with partial groups.
1444 scripts/config.py unset MBEDTLS_PK_PARSE_EC_EXTENDED
Gilles Peskinecc73cc52021-05-25 09:04:46 +02001445 # Enable all MBEDTLS_XXX_ALT for whole modules. Do not enable
1446 # MBEDTLS_XXX_YYY_ALT which are for single functions.
1447 scripts/config.py set-all 'MBEDTLS_([A-Z0-9]*|NIST_KW)_ALT'
Gilles Peskine1628a9c2021-05-31 22:09:58 +02001448 scripts/config.py unset MBEDTLS_DHM_ALT #incompatible with MBEDTLS_DEBUG_C
1449 # We can only compile, not link, since we don't have any implementations
1450 # suitable for testing with the dummy alt headers.
1451 make CC=gcc CFLAGS='-Werror -Wall -Wextra -I../tests/include/alt-dummy' lib
1452}
1453
1454component_build_dhm_alt () {
1455 msg "build: MBEDTLS_DHM_ALT" # ~30s
1456 scripts/config.py full
1457 scripts/config.py set MBEDTLS_DHM_ALT
1458 # debug.c currently references mbedtls_dhm_context fields directly.
1459 scripts/config.py unset MBEDTLS_DEBUG_C
Gilles Peskinecc73cc52021-05-25 09:04:46 +02001460 # We can only compile, not link, since we don't have any implementations
1461 # suitable for testing with the dummy alt headers.
1462 make CC=gcc CFLAGS='-Werror -Wall -Wextra -I../tests/include/alt-dummy' lib
1463}
1464
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001465component_test_no_use_psa_crypto_full_cmake_asan() {
1466 # full minus MBEDTLS_USE_PSA_CRYPTO: run the same set of tests as basic-build-test.sh
Gilles Peskinedc3a1792019-09-03 11:42:04 +02001467 msg "build: cmake, full config minus MBEDTLS_USE_PSA_CRYPTO, ASan"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001468 scripts/config.py full
1469 scripts/config.py set MBEDTLS_ECP_RESTARTABLE # not using PSA, so enable restartable ECC
1470 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C
1471 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1472 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C
Gilles Peskinedc6d8382020-04-12 14:21:55 +02001473 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001474 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
Manuel Pégourié-Gonnardd8167e82019-02-01 11:12:52 +01001475 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Andrzej Kurekde5a0072019-02-01 07:03:03 -05001476 make
Manuel Pégourié-Gonnard43be6cd2017-06-20 09:53:42 +02001477
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001478 msg "test: main suites (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -05001479 make test
Manuel Pégourié-Gonnard503a5ef2015-10-23 09:04:45 +02001480
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001481 msg "test: ssl-opt.sh (full minus MBEDTLS_USE_PSA_CRYPTO)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001482 tests/ssl-opt.sh
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001483
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001484 msg "test: compat.sh default (full minus MBEDTLS_USE_PSA_CRYPTO)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001485 tests/compat.sh
Andrzej Kurek991f9fe2018-07-02 09:08:21 -04001486
TRodziewicz10e8cf52021-05-31 17:58:57 +02001487 msg "test: compat.sh DES & NULL (full minus MBEDTLS_USE_PSA_CRYPTO)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001488 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 -05001489
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001490 msg "test: compat.sh ARIA + ChachaPoly (full minus MBEDTLS_USE_PSA_CRYPTO)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001491 env OPENSSL_CMD="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
Andrzej Kurekde5a0072019-02-01 07:03:03 -05001492}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -05001493
John Durkopd8959392020-09-20 23:09:17 -07001494component_test_psa_crypto_config_basic() {
Ronald Cron067de3b2021-03-11 11:49:03 +01001495 # Test the library excluding all Mbed TLS cryptographic support for which
1496 # we have an accelerator support. Acceleration is faked with the
1497 # transparent test driver.
1498 msg "test: full + MBEDTLS_PSA_CRYPTO_CONFIG + as much acceleration as supported"
John Durkopd8959392020-09-20 23:09:17 -07001499 scripts/config.py full
1500 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1501 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1502 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cron067de3b2021-03-11 11:49:03 +01001503
1504 # There is no intended accelerator support for ALG STREAM_CIPHER and
1505 # ALG_ECB_NO_PADDING. Therefore, asking for them in the build implies the
1506 # inclusion of the Mbed TLS cipher operations. As we want to test here with
1507 # cipher operations solely supported by accelerators, disabled those
1508 # PSA configuration options.
1509 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_STREAM_CIPHER
1510 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_ECB_NO_PADDING
1511
1512 # Don't test DES encryption as:
1513 # 1) It is not an issue if we don't test all cipher types here.
1514 # 2) That way we don't have to modify in psa_crypto.c the compilation
1515 # guards MBEDTLS_PSA_BUILTIN_KEY_TYPE_DES for the code they guard to be
1516 # available to the test driver. Modifications that we would need to
1517 # revert when we move to compile the test driver separately.
1518 # We also disable MBEDTLS_DES_C as the dependencies on DES in PSA test
1519 # suites are still based on MBEDTLS_DES_C and not PSA_WANT_KEY_TYPE_DES.
1520 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_KEY_TYPE_DES
1521 scripts/config.py unset MBEDTLS_DES_C
1522
John Durkopd8959392020-09-20 23:09:17 -07001523 # 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 +01001524 loc_cflags="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST"
Ronald Cron067de3b2021-03-11 11:49:03 +01001525 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_KEY_TYPE_AES"
1526 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_KEY_TYPE_CAMELLIA"
Ronald Cron17b3afc2020-12-10 18:17:09 +01001527 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_KEY_PAIR"
Ronald Cron067de3b2021-03-11 11:49:03 +01001528 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_KEY_PAIR"
1529 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_CBC_NO_PADDING"
1530 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_CBC_PKCS7"
1531 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_CTR"
1532 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_CFB"
Ronald Cron17b3afc2020-12-10 18:17:09 +01001533 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_ECDSA"
1534 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_DETERMINISTIC_ECDSA"
Steven Cooremand50db942021-03-08 17:17:15 +01001535 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_MD5"
Ronald Cron067de3b2021-03-11 11:49:03 +01001536 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_OFB"
Steven Cooremand50db942021-03-08 17:17:15 +01001537 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_RIPEMD160"
Ronald Cron067de3b2021-03-11 11:49:03 +01001538 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_SIGN"
1539 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_RSA_PSS"
Steven Cooremand50db942021-03-08 17:17:15 +01001540 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_SHA_1"
1541 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_SHA_224"
1542 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_SHA_256"
1543 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_SHA_384"
1544 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_SHA_512"
Ronald Cron067de3b2021-03-11 11:49:03 +01001545 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_XTS"
Steven Cooreman7515e752021-03-19 19:36:38 +01001546 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_CMAC"
1547 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_HMAC"
Ronald Cron17b3afc2020-12-10 18:17:09 +01001548 loc_cflags="${loc_cflags} -I../tests/include -O2"
1549
1550 make CC=gcc CFLAGS="$loc_cflags" LDFLAGS="$ASAN_CFLAGS"
1551 unset loc_cflags
John Durkopd8959392020-09-20 23:09:17 -07001552
John Durkop4377bf72020-10-23 01:26:57 -07001553 msg "test: full + MBEDTLS_PSA_CRYPTO_CONFIG"
1554 make test
1555}
1556
1557component_test_psa_crypto_config_no_driver() {
1558 # full plus MBEDTLS_PSA_CRYPTO_CONFIG
1559 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG minus MBEDTLS_PSA_CRYPTO_DRIVERS"
1560 scripts/config.py full
1561 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1562 scripts/config.py unset MBEDTLS_PSA_CRYPTO_DRIVERS
1563 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
John Durkope7012c72020-10-26 09:55:01 -07001564 make CC=gcc CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
John Durkop4377bf72020-10-23 01:26:57 -07001565
1566 msg "test: full + MBEDTLS_PSA_CRYPTO_CONFIG minus MBEDTLS_PSA_CRYPTO_DRIVERS"
John Durkopd8959392020-09-20 23:09:17 -07001567 make test
1568}
1569
John Durkop8ac0b802020-10-23 01:32:15 -07001570# 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 -08001571component_build_psa_accel_alg_ecdsa() {
John Durkopdd544e12020-10-12 21:47:19 -07001572 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_ECDSA
1573 # without MBEDTLS_ECDSA_C
John Durkop28baa1f2020-10-23 00:51:52 -07001574 # PSA_WANT_ALG_ECDSA and PSA_WANT_ALG_DETERMINISTIC_ECDSA are already
1575 # set in include/psa/crypto_config.h
John Durkopdd544e12020-10-12 21:47:19 -07001576 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_ECDSA without MBEDTLS_ECDSA_C"
John Durkopd8959392020-09-20 23:09:17 -07001577 scripts/config.py full
1578 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1579 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1580 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1581 scripts/config.py unset MBEDTLS_ECDSA_C
John Durkop28baa1f2020-10-23 00:51:52 -07001582 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
1583 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
John Durkopd8959392020-09-20 23:09:17 -07001584 # 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 -07001585 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 -07001586}
1587
John Durkopd0321952020-10-29 21:37:36 -07001588# 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 -08001589component_build_psa_accel_alg_ecdh() {
John Durkopd0321952020-10-29 21:37:36 -07001590 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_ECDH
1591 # without MBEDTLS_ECDH_C
1592 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_ECDH without MBEDTLS_ECDH_C"
1593 scripts/config.py full
1594 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1595 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1596 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1597 scripts/config.py unset MBEDTLS_ECDH_C
1598 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
1599 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
1600 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
1601 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
1602 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
1603 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1604 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_ECDH -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
1605}
1606
John Durkopf4c4cb02020-10-28 20:09:55 -07001607# 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 -08001608component_build_psa_accel_key_type_ecc_key_pair() {
John Durkop9814fa22020-11-04 12:28:15 -08001609 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_KEY_TYPE_ECC_KEY_PAIR
1610 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_KEY_TYPE_ECC_KEY_PAIR"
John Durkopf4c4cb02020-10-28 20:09:55 -07001611 scripts/config.py full
1612 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1613 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1614 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
John Durkop9814fa22020-11-04 12:28:15 -08001615 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 -08001616 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 -07001617 # 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 -08001618 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 -07001619}
1620
1621# 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 -08001622component_build_psa_accel_key_type_ecc_public_key() {
John Durkop9814fa22020-11-04 12:28:15 -08001623 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY
1624 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY"
John Durkopf4c4cb02020-10-28 20:09:55 -07001625 scripts/config.py full
1626 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1627 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1628 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
John Durkop9814fa22020-11-04 12:28:15 -08001629 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY 1
1630 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR
John Durkopf4c4cb02020-10-28 20:09:55 -07001631 # 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 -08001632 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 -07001633}
1634
John Durkopd0321952020-10-29 21:37:36 -07001635# 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 -08001636component_build_psa_accel_alg_hmac() {
John Durkopd0321952020-10-29 21:37:36 -07001637 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_HMAC
1638 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_HMAC"
1639 scripts/config.py full
1640 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1641 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1642 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1643 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1644 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_HMAC -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
1645}
1646
1647# 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 -08001648component_build_psa_accel_alg_hkdf() {
John Durkopd0321952020-10-29 21:37:36 -07001649 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_HKDF
1650 # without MBEDTLS_HKDF_C
1651 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_HKDF without MBEDTLS_HKDF_C"
1652 scripts/config.py full
1653 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1654 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1655 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1656 scripts/config.py unset MBEDTLS_HKDF_C
John Durkopbd069d32020-10-31 22:14:03 -07001657 # Make sure to unset TLS1_3_EXPERIMENTAL since it requires HKDF_C and will not build properly without it.
1658 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL
John Durkopd0321952020-10-29 21:37:36 -07001659 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1660 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_HKDF -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
1661}
1662
John Durkop1b7ee052020-11-27 08:51:22 -08001663# This should be renamed to test and updated once the accelerator MD5 code is in place and ready to test.
1664component_build_psa_accel_alg_md5() {
1665 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_MD5 without other hashes
1666 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_MD5 - other hashes"
1667 scripts/config.py full
1668 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1669 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1670 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
John Durkop1b7ee052020-11-27 08:51:22 -08001671 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
1672 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
1673 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
1674 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
1675 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
1676 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
1677 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1678 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_MD5 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
1679}
1680
1681# This should be renamed to test and updated once the accelerator RIPEMD160 code is in place and ready to test.
1682component_build_psa_accel_alg_ripemd160() {
1683 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_RIPEMD160 without other hashes
1684 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_RIPEMD160 - other hashes"
1685 scripts/config.py full
1686 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1687 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1688 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
John Durkop1b7ee052020-11-27 08:51:22 -08001689 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
1690 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
1691 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
1692 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
1693 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
1694 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
1695 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1696 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RIPEMD160 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
1697}
1698
1699# This should be renamed to test and updated once the accelerator SHA1 code is in place and ready to test.
1700component_build_psa_accel_alg_sha1() {
1701 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_SHA_1 without other hashes
1702 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_SHA_1 - other hashes"
1703 scripts/config.py full
1704 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1705 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1706 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
John Durkop1b7ee052020-11-27 08:51:22 -08001707 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
1708 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
1709 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
1710 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
1711 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
1712 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
1713 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1714 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_1 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
1715}
1716
1717# This should be renamed to test and updated once the accelerator SHA224 code is in place and ready to test.
1718component_build_psa_accel_alg_sha224() {
1719 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_SHA_224 without other hashes
1720 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_SHA_224 - other hashes"
1721 scripts/config.py full
1722 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1723 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1724 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
John Durkop1b7ee052020-11-27 08:51:22 -08001725 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
1726 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
1727 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
1728 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
1729 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
1730 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1731 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_224 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
1732}
1733
1734# This should be renamed to test and updated once the accelerator SHA256 code is in place and ready to test.
1735component_build_psa_accel_alg_sha256() {
1736 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_SHA_256 without other hashes
1737 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_SHA_256 - other hashes"
1738 scripts/config.py full
1739 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1740 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1741 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
John Durkop1b7ee052020-11-27 08:51:22 -08001742 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
1743 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
1744 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
1745 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
1746 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
1747 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
1748 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1749 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_256 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
1750}
1751
1752# This should be renamed to test and updated once the accelerator SHA384 code is in place and ready to test.
1753component_build_psa_accel_alg_sha384() {
1754 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_SHA_384 without other hashes
1755 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_SHA_384 - other hashes"
1756 scripts/config.py full
1757 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1758 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1759 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
John Durkop1b7ee052020-11-27 08:51:22 -08001760 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
1761 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
1762 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
1763 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
1764 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
1765 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1766 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_384 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
1767}
1768
1769# This should be renamed to test and updated once the accelerator SHA512 code is in place and ready to test.
1770component_build_psa_accel_alg_sha512() {
1771 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_SHA_512 without other hashes
1772 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_SHA_512 - other hashes"
1773 scripts/config.py full
1774 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1775 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1776 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
John Durkop1b7ee052020-11-27 08:51:22 -08001777 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
1778 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
1779 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
1780 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
1781 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
1782 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
1783 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1784 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_512 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
1785}
1786
John Durkopd0321952020-10-29 21:37:36 -07001787# 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 -08001788component_build_psa_accel_alg_rsa_pkcs1v15_crypt() {
John Durkopbd069d32020-10-31 22:14:03 -07001789 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
1790 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 -07001791 scripts/config.py full
1792 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1793 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1794 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
John Durkopbd069d32020-10-31 22:14:03 -07001795 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_PKCS1V15_CRYPT 1
John Durkop7fc75ea2020-11-03 19:05:36 -08001796 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN
1797 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_OAEP
1798 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PSS
John Durkopd0321952020-10-29 21:37:36 -07001799 # 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 -07001800 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_CRYPT -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
1801}
1802
1803# 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 -08001804component_build_psa_accel_alg_rsa_pkcs1v15_sign() {
John Durkopbd069d32020-10-31 22:14:03 -07001805 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_RSA_PKCS1V15_SIGN and PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY
1806 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_RSA_PKCS1V15_SIGN + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY"
1807 scripts/config.py full
1808 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1809 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1810 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1811 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_PKCS1V15_SIGN 1
John Durkop7fc75ea2020-11-03 19:05:36 -08001812 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
1813 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_OAEP
1814 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PSS
John Durkopbd069d32020-10-31 22:14:03 -07001815 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1816 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_SIGN -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
1817}
1818
1819# 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 -08001820component_build_psa_accel_alg_rsa_oaep() {
John Durkopbd069d32020-10-31 22:14:03 -07001821 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_RSA_OAEP and PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY
1822 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_RSA_OAEP + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY"
1823 scripts/config.py full
1824 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1825 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1826 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1827 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_OAEP 1
John Durkop7fc75ea2020-11-03 19:05:36 -08001828 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
1829 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN
1830 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PSS
John Durkopbd069d32020-10-31 22:14:03 -07001831 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1832 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_OAEP -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
1833}
1834
1835# 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 -08001836component_build_psa_accel_alg_rsa_pss() {
John Durkopbd069d32020-10-31 22:14:03 -07001837 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_RSA_PSS and PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY
1838 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_RSA_PSS + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY"
1839 scripts/config.py full
1840 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1841 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1842 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1843 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_PSS 1
John Durkop7fc75ea2020-11-03 19:05:36 -08001844 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
1845 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN
1846 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_OAEP
John Durkopbd069d32020-10-31 22:14:03 -07001847 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1848 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_PSS -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
1849}
1850
1851# 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 -08001852component_build_psa_accel_key_type_rsa_key_pair() {
John Durkopbd069d32020-10-31 22:14:03 -07001853 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_KEY_TYPE_RSA_KEY_PAIR and PSA_WANT_ALG_RSA_PSS
1854 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_KEY_TYPE_RSA_KEY_PAIR + PSA_WANT_ALG_RSA_PSS"
1855 scripts/config.py full
1856 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1857 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1858 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1859 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_PSS 1
1860 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_KEY_TYPE_RSA_KEY_PAIR 1
1861 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1862 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"
1863}
1864
1865# 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 -08001866component_build_psa_accel_key_type_rsa_public_key() {
John Durkopbd069d32020-10-31 22:14:03 -07001867 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY and PSA_WANT_ALG_RSA_PSS
1868 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY + PSA_WANT_ALG_RSA_PSS"
1869 scripts/config.py full
1870 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1871 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1872 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1873 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_PSS 1
1874 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY 1
1875 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1876 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 -07001877}
1878
Gilles Peskine8f073122018-11-27 15:58:47 +01001879component_test_no_platform () {
1880 # Full configuration build, without platform support, file IO and net sockets.
1881 # This should catch missing mbedtls_printf definitions, and by disabling file
1882 # IO, it should catch missing '#include <stdio.h>'
1883 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001884 scripts/config.py full
1885 scripts/config.py unset MBEDTLS_PLATFORM_C
1886 scripts/config.py unset MBEDTLS_NET_C
1887 scripts/config.py unset MBEDTLS_PLATFORM_MEMORY
1888 scripts/config.py unset MBEDTLS_PLATFORM_PRINTF_ALT
1889 scripts/config.py unset MBEDTLS_PLATFORM_FPRINTF_ALT
1890 scripts/config.py unset MBEDTLS_PLATFORM_SNPRINTF_ALT
1891 scripts/config.py unset MBEDTLS_PLATFORM_TIME_ALT
1892 scripts/config.py unset MBEDTLS_PLATFORM_EXIT_ALT
Gilles Peskine32e889d2020-04-12 23:43:28 +02001893 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001894 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
1895 scripts/config.py unset MBEDTLS_FS_IO
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001896 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001897 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
1898 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C
Gilles Peskine8f073122018-11-27 15:58:47 +01001899 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
1900 # to re-enable platform integration features otherwise disabled in C99 builds
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02001901 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -Os -D_DEFAULT_SOURCE' lib programs
1902 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os' test
Gilles Peskine8f073122018-11-27 15:58:47 +01001903}
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +00001904
Gilles Peskine8f073122018-11-27 15:58:47 +01001905component_build_no_std_function () {
1906 # catch compile bugs in _uninit functions
1907 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001908 scripts/config.py full
1909 scripts/config.py set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
1910 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskine32e889d2020-04-12 23:43:28 +02001911 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02001912 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Gilles Peskine8f073122018-11-27 15:58:47 +01001913}
Manuel Pégourié-Gonnarddccb80b2015-06-03 10:20:33 +01001914
Gilles Peskine8f073122018-11-27 15:58:47 +01001915component_build_no_ssl_srv () {
1916 msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001917 scripts/config.py full
1918 scripts/config.py unset MBEDTLS_SSL_SRV_C
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02001919 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
Gilles Peskine8f073122018-11-27 15:58:47 +01001920}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +02001921
Gilles Peskine8f073122018-11-27 15:58:47 +01001922component_build_no_ssl_cli () {
1923 msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001924 scripts/config.py full
1925 scripts/config.py unset MBEDTLS_SSL_CLI_C
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02001926 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
Gilles Peskine8f073122018-11-27 15:58:47 +01001927}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +02001928
Gilles Peskine8f073122018-11-27 15:58:47 +01001929component_build_no_sockets () {
1930 # Note, C99 compliance can also be tested with the sockets support disabled,
1931 # as that requires a POSIX platform (which isn't the same as C99).
1932 msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001933 scripts/config.py full
1934 scripts/config.py unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
1935 scripts/config.py set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02001936 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1 -std=c99 -pedantic' lib
Gilles Peskine8f073122018-11-27 15:58:47 +01001937}
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +02001938
Andrzej Kurek69f20aa2019-09-05 09:27:47 -04001939component_test_memory_buffer_allocator_backtrace () {
1940 msg "build: default config with memory buffer allocator and backtrace enabled"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001941 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
1942 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
1943 scripts/config.py set MBEDTLS_MEMORY_BACKTRACE
1944 scripts/config.py set MBEDTLS_MEMORY_DEBUG
Andrzej Kurek69f20aa2019-09-05 09:27:47 -04001945 CC=gcc cmake .
1946 make
1947
1948 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C and MBEDTLS_MEMORY_BACKTRACE"
1949 make test
1950}
1951
1952component_test_memory_buffer_allocator () {
1953 msg "build: default config with memory buffer allocator"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001954 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
1955 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
Hanno Becker0fb9ba22019-02-26 14:34:13 +00001956 CC=gcc cmake .
1957 make
1958
1959 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C"
1960 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +01001961
1962 msg "test: ssl-opt.sh, MBEDTLS_MEMORY_BUFFER_ALLOC_C"
1963 # MBEDTLS_MEMORY_BUFFER_ALLOC is slow. Skip tests that tend to time out.
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001964 tests/ssl-opt.sh -e '^DTLS proxy'
Hanno Becker0fb9ba22019-02-26 14:34:13 +00001965}
1966
Gilles Peskine8f073122018-11-27 15:58:47 +01001967component_test_no_max_fragment_length () {
1968 # Run max fragment length tests with MFL disabled
1969 msg "build: default config except MFL extension (ASan build)" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001970 scripts/config.py unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
Gilles Peskine8f073122018-11-27 15:58:47 +01001971 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1972 make
Hanno Becker5175ac62017-09-18 15:36:25 +01001973
Gilles Peskine8f073122018-11-27 15:58:47 +01001974 msg "test: ssl-opt.sh, MFL-related tests"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001975 tests/ssl-opt.sh -f "Max fragment length"
Gilles Peskine8f073122018-11-27 15:58:47 +01001976}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001977
Hanno Becker545ced42019-02-19 11:10:48 +00001978component_test_asan_remove_peer_certificate () {
1979 msg "build: default config with MBEDTLS_SSL_KEEP_PEER_CERTIFICATE disabled (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001980 scripts/config.py unset MBEDTLS_SSL_KEEP_PEER_CERTIFICATE
Hanno Becker545ced42019-02-19 11:10:48 +00001981 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1982 make
1983
1984 msg "test: !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
1985 make test
1986
1987 msg "test: ssl-opt.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001988 tests/ssl-opt.sh
Hanno Becker545ced42019-02-19 11:10:48 +00001989
1990 msg "test: compat.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001991 tests/compat.sh
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02001992
1993 msg "test: context-info.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001994 tests/context-info.sh
Hanno Becker545ced42019-02-19 11:10:48 +00001995}
1996
Gilles Peskine8f073122018-11-27 15:58:47 +01001997component_test_no_max_fragment_length_small_ssl_out_content_len () {
1998 msg "build: no MFL extension, small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001999 scripts/config.py unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
2000 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 16384
2001 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
Gilles Peskine8f073122018-11-27 15:58:47 +01002002 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2003 make
Angus Grattonc4dd0732018-04-11 16:28:39 +10002004
Gilles Peskine8f073122018-11-27 15:58:47 +01002005 msg "test: MFL tests (disabled MFL extension case) & large packet tests"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002006 tests/ssl-opt.sh -f "Max fragment length\|Large buffer"
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02002007
2008 msg "test: context-info.sh (disabled MFL extension case)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002009 tests/context-info.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01002010}
Angus Grattonc4dd0732018-04-11 16:28:39 +10002011
Darryl Greenaad82f92019-12-02 10:53:11 +00002012component_test_variable_ssl_in_out_buffer_len () {
2013 msg "build: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled (ASan build)"
2014 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
2015 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2016 make
2017
2018 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
2019 make test
2020
2021 msg "test: ssl-opt.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002022 tests/ssl-opt.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00002023
2024 msg "test: compat.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002025 tests/compat.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00002026}
2027
2028component_test_variable_ssl_in_out_buffer_len_CID () {
2029 msg "build: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_DTLS_CONNECTION_ID enabled (ASan build)"
2030 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
2031 scripts/config.py set MBEDTLS_SSL_DTLS_CONNECTION_ID
2032
2033 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2034 make
2035
2036 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_DTLS_CONNECTION_ID"
2037 make test
2038
2039 msg "test: ssl-opt.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_DTLS_CONNECTION_ID enabled"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002040 tests/ssl-opt.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00002041
2042 msg "test: compat.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_DTLS_CONNECTION_ID enabled"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002043 tests/compat.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00002044}
2045
Piotr Nowicki0937ed22019-11-26 16:32:40 +01002046component_test_ssl_alloc_buffer_and_mfl () {
2047 msg "build: default config with memory buffer allocator and MFL extension"
2048 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
2049 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
2050 scripts/config.py set MBEDTLS_MEMORY_DEBUG
2051 scripts/config.py set MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
2052 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
2053 CC=gcc cmake .
2054 make
2055
2056 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH, MBEDTLS_MEMORY_BUFFER_ALLOC_C, MBEDTLS_MEMORY_DEBUG and MBEDTLS_SSL_MAX_FRAGMENT_LENGTH"
2057 make test
2058
2059 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 +02002060 tests/ssl-opt.sh -f "Handshake memory usage"
Piotr Nowicki0937ed22019-11-26 16:32:40 +01002061}
2062
Gilles Peskine636c26a2020-03-04 20:46:15 +01002063component_test_when_no_ciphersuites_have_mac () {
2064 msg "build: when no ciphersuites have MAC"
2065 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
Gilles Peskine636c26a2020-03-04 20:46:15 +01002066 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
TRodziewicz2add5c12021-04-28 16:50:20 +02002067 scripts/config.py unset MBEDTLS_CMAC_C
Gilles Peskine636c26a2020-03-04 20:46:15 +01002068 make
2069
2070 msg "test: !MBEDTLS_SSL_SOME_MODES_USE_MAC"
2071 make test
2072
2073 msg "test ssl-opt.sh: !MBEDTLS_SSL_SOME_MODES_USE_MAC"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002074 tests/ssl-opt.sh -f 'Default\|EtM' -e 'without EtM'
Gilles Peskine636c26a2020-03-04 20:46:15 +01002075}
2076
Raoul Strackxa4e86142020-06-15 17:03:13 +02002077component_test_no_date_time () {
2078 msg "build: default config without MBEDTLS_HAVE_TIME_DATE"
2079 scripts/config.py unset MBEDTLS_HAVE_TIME_DATE
2080 CC=gcc cmake
2081 make
2082
2083 msg "test: !MBEDTLS_HAVE_TIME_DATE - main suites"
2084 make test
2085}
2086
Gilles Peskine8f073122018-11-27 15:58:47 +01002087component_test_platform_calloc_macro () {
2088 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002089 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
2090 scripts/config.py set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
2091 scripts/config.py set MBEDTLS_PLATFORM_FREE_MACRO free
Gilles Peskine8f073122018-11-27 15:58:47 +01002092 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2093 make
Hanno Beckere5fecec2018-10-11 11:02:52 +01002094
Gilles Peskine8f073122018-11-27 15:58:47 +01002095 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
2096 make test
2097}
Hanno Beckere5fecec2018-10-11 11:02:52 +01002098
Gilles Peskinec4ef7a92019-09-17 19:04:38 +02002099component_test_malloc_0_null () {
2100 msg "build: malloc(0) returns NULL (ASan+UBSan build)"
Manuel Pégourié-Gonnard68192fc2020-03-04 10:34:47 +01002101 scripts/config.py full
Gilles Peskine004206c2019-10-21 17:11:33 +02002102 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 +02002103
2104 msg "test: malloc(0) returns NULL (ASan+UBSan build)"
2105 make test
2106
2107 msg "selftest: malloc(0) returns NULL (ASan+UBSan build)"
2108 # Just the calloc selftest. "make test" ran the others as part of the
2109 # test suites.
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002110 programs/test/selftest calloc
Gilles Peskine765d2402020-02-11 18:26:34 +01002111
2112 msg "test ssl-opt.sh: malloc(0) returns NULL (ASan+UBSan build)"
2113 # Run a subset of the tests. The choice is a balance between coverage
2114 # and time (including time indirectly wasted due to flaky tests).
2115 # The current choice is to skip tests whose description includes
2116 # "proxy", which is an approximation of skipping tests that use the
2117 # UDP proxy, which tend to be slower and flakier.
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002118 tests/ssl-opt.sh -e 'proxy'
Gilles Peskinec4ef7a92019-09-17 19:04:38 +02002119}
2120
Gilles Peskine8f073122018-11-27 15:58:47 +01002121component_test_aes_fewer_tables () {
2122 msg "build: default config with AES_FEWER_TABLES enabled"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002123 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
Gilles Peskine8f073122018-11-27 15:58:47 +01002124 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01002125
Gilles Peskine8f073122018-11-27 15:58:47 +01002126 msg "test: AES_FEWER_TABLES"
2127 make test
2128}
Hanno Becker83ebf782017-07-07 12:29:15 +01002129
Gilles Peskine8f073122018-11-27 15:58:47 +01002130component_test_aes_rom_tables () {
2131 msg "build: default config with AES_ROM_TABLES enabled"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002132 scripts/config.py set MBEDTLS_AES_ROM_TABLES
Gilles Peskine8f073122018-11-27 15:58:47 +01002133 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01002134
Gilles Peskine8f073122018-11-27 15:58:47 +01002135 msg "test: AES_ROM_TABLES"
2136 make test
2137}
Hanno Becker83ebf782017-07-07 12:29:15 +01002138
Gilles Peskine8f073122018-11-27 15:58:47 +01002139component_test_aes_fewer_tables_and_rom_tables () {
2140 msg "build: default config with AES_ROM_TABLES and AES_FEWER_TABLES enabled"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002141 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
2142 scripts/config.py set MBEDTLS_AES_ROM_TABLES
Gilles Peskine8f073122018-11-27 15:58:47 +01002143 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01002144
Gilles Peskine8f073122018-11-27 15:58:47 +01002145 msg "test: AES_FEWER_TABLES + AES_ROM_TABLES"
2146 make test
2147}
2148
Gilles Peskine592f5912019-10-07 18:49:32 +02002149component_test_ctr_drbg_aes_256_sha_256 () {
2150 msg "build: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
Gilles Peskine3b46cd32020-02-18 17:56:33 +01002151 scripts/config.py full
2152 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
2153 scripts/config.py set MBEDTLS_ENTROPY_FORCE_SHA256
Gilles Peskine592f5912019-10-07 18:49:32 +02002154 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2155 make
2156
2157 msg "test: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
2158 make test
2159}
2160
2161component_test_ctr_drbg_aes_128_sha_512 () {
2162 msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)"
Gilles Peskine3b46cd32020-02-18 17:56:33 +01002163 scripts/config.py full
2164 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
2165 scripts/config.py set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
Gilles Peskine592f5912019-10-07 18:49:32 +02002166 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2167 make
2168
2169 msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)"
2170 make test
2171}
2172
2173component_test_ctr_drbg_aes_128_sha_256 () {
2174 msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
Gilles Peskine3b46cd32020-02-18 17:56:33 +01002175 scripts/config.py full
2176 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
2177 scripts/config.py set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
2178 scripts/config.py set MBEDTLS_ENTROPY_FORCE_SHA256
Gilles Peskine592f5912019-10-07 18:49:32 +02002179 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2180 make
2181
2182 msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
2183 make test
2184}
2185
Gilles Peskinef96aefe2019-07-24 14:58:38 +02002186component_test_se_default () {
2187 msg "build: default config + MBEDTLS_PSA_CRYPTO_SE_C"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002188 scripts/config.py set MBEDTLS_PSA_CRYPTO_SE_C
Gilles Peskine004206c2019-10-21 17:11:33 +02002189 make CC=clang CFLAGS="$ASAN_CFLAGS -Os" LDFLAGS="$ASAN_CFLAGS"
Gilles Peskinef96aefe2019-07-24 14:58:38 +02002190
2191 msg "test: default config + MBEDTLS_PSA_CRYPTO_SE_C"
2192 make test
2193}
2194
Steven Cooremand57203d2020-07-16 20:28:59 +02002195component_test_psa_crypto_drivers () {
Steven Cooreman55ae2172020-07-17 19:46:15 +02002196 msg "build: MBEDTLS_PSA_CRYPTO_DRIVERS w/ driver hooks"
Steven Cooreman753f9732021-03-15 11:38:44 +01002197 scripts/config.py full
Steven Cooremand57203d2020-07-16 20:28:59 +02002198 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
Steven Cooreman6801f082021-02-19 17:21:22 +01002199 scripts/config.py set MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS
Steven Cooreman1cd39d52020-07-23 16:26:08 +02002200 # 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 +01002201 loc_cflags="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST"
Ronald Crone6f63012021-03-19 14:57:08 +01002202 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_KEY_TYPE_AES"
2203 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_KEY_TYPE_CAMELLIA"
Ronald Cron17b3afc2020-12-10 18:17:09 +01002204 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_KEY_PAIR"
Ronald Crone6f63012021-03-19 14:57:08 +01002205 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_KEY_PAIR"
2206 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_CBC_NO_PADDING"
2207 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_CBC_PKCS7"
2208 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_CTR"
2209 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_CFB"
Ronald Cron17b3afc2020-12-10 18:17:09 +01002210 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_ECDSA"
2211 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_DETERMINISTIC_ECDSA"
Steven Cooremand50db942021-03-08 17:17:15 +01002212 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_MD5"
Ronald Crone6f63012021-03-19 14:57:08 +01002213 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_OFB"
Steven Cooremand50db942021-03-08 17:17:15 +01002214 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_RIPEMD160"
Ronald Crone6f63012021-03-19 14:57:08 +01002215 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_SIGN"
2216 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_RSA_PSS"
Steven Cooremand50db942021-03-08 17:17:15 +01002217 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_SHA_1"
2218 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_SHA_224"
2219 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_SHA_256"
2220 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_SHA_384"
2221 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_SHA_512"
Ronald Crone6f63012021-03-19 14:57:08 +01002222 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_XTS"
Steven Cooreman7515e752021-03-19 19:36:38 +01002223 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_CMAC"
2224 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_HMAC"
Ronald Cron17b3afc2020-12-10 18:17:09 +01002225 loc_cflags="${loc_cflags} -I../tests/include -O2"
2226
2227 make CC=gcc CFLAGS="${loc_cflags}" LDFLAGS="$ASAN_CFLAGS"
2228 unset loc_cflags
Steven Cooremand57203d2020-07-16 20:28:59 +02002229
Steven Cooreman753f9732021-03-15 11:38:44 +01002230 msg "test: full + MBEDTLS_PSA_CRYPTO_DRIVERS"
Steven Cooremand57203d2020-07-16 20:28:59 +02002231 make test
2232}
2233
Gilles Peskine8f073122018-11-27 15:58:47 +01002234component_test_make_shared () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01002235 msg "build/test: make shared" # ~ 40s
Andrzej Kurek232e8f92019-10-03 03:18:01 -04002236 make SHARED=1 all check
Gilles Peskine56c01612019-07-03 20:43:32 +02002237 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskine8f073122018-11-27 15:58:47 +01002238}
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +02002239
Gilles Peskinecf740502019-07-03 20:43:05 +02002240component_test_cmake_shared () {
2241 msg "build/test: cmake shared" # ~ 2min
2242 cmake -DUSE_SHARED_MBEDTLS_LIBRARY=On .
2243 make
Gilles Peskine56c01612019-07-03 20:43:32 +02002244 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskinecf740502019-07-03 20:43:05 +02002245 make test
2246}
2247
Gilles Peskineec10bf12019-09-20 19:56:06 +02002248test_build_opt () {
2249 info=$1 cc=$2; shift 2
2250 for opt in "$@"; do
2251 msg "build/test: $cc $opt, $info" # ~ 30s
Gilles Peskinee094a182020-04-14 20:08:41 +02002252 make CC="$cc" CFLAGS="$opt -std=c99 -pedantic -Wall -Wextra -Werror"
Gilles Peskineec10bf12019-09-20 19:56:06 +02002253 # We're confident enough in compilers to not run _all_ the tests,
2254 # but at least run the unit tests. In particular, runs with
2255 # optimizations use inline assembly whereas runs with -O0
2256 # skip inline assembly.
2257 make test # ~30s
2258 make clean
2259 done
2260}
2261
2262component_test_clang_opt () {
Manuel Pégourié-Gonnard68192fc2020-03-04 10:34:47 +01002263 scripts/config.py full
Gilles Peskineec10bf12019-09-20 19:56:06 +02002264 test_build_opt 'full config' clang -O0 -Os -O2
2265}
2266
2267component_test_gcc_opt () {
Manuel Pégourié-Gonnard68192fc2020-03-04 10:34:47 +01002268 scripts/config.py full
Gilles Peskineec10bf12019-09-20 19:56:06 +02002269 test_build_opt 'full config' gcc -O0 -Os -O2
2270}
2271
Gilles Peskineabf9b4d2019-07-03 20:42:16 +02002272component_build_mbedtls_config_file () {
2273 msg "build: make with MBEDTLS_CONFIG_FILE" # ~40s
2274 # Use the full config so as to catch a maximum of places where
2275 # the check of MBEDTLS_CONFIG_FILE might be missing.
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002276 scripts/config.py full
Gilles Peskineabf9b4d2019-07-03 20:42:16 +02002277 sed 's!"check_config.h"!"mbedtls/check_config.h"!' <"$CONFIG_H" >full_config.h
2278 echo '#error "MBEDTLS_CONFIG_FILE is not working"' >"$CONFIG_H"
2279 make CFLAGS="-I '$PWD' -DMBEDTLS_CONFIG_FILE='\"full_config.h\"'"
2280 rm -f full_config.h
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00002281}
2282
Gilles Peskine8f073122018-11-27 15:58:47 +01002283component_test_m32_o0 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +01002284 # Build once with -O0, to compile out the i386 specific inline assembly
2285 msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002286 scripts/config.py full
Gilles Peskine8fd59422019-10-21 17:11:33 +02002287 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O0" LDFLAGS="-m32 $ASAN_CFLAGS"
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01002288
Simon Butcher8e6a22a2018-07-20 21:27:33 +01002289 msg "test: i386, make, gcc -O0 (ASan build)"
2290 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01002291}
Gilles Peskine878cf602019-01-06 20:50:38 +00002292support_test_m32_o0 () {
2293 case $(uname -m) in
2294 *64*) true;;
2295 *) false;;
2296 esac
2297}
Simon Butcher8e6a22a2018-07-20 21:27:33 +01002298
Gilles Peskine8f073122018-11-27 15:58:47 +01002299component_test_m32_o1 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +01002300 # Build again with -O1, to compile in the i386 specific inline assembly
2301 msg "build: i386, make, gcc -O1 (ASan build)" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002302 scripts/config.py full
Gilles Peskine8fd59422019-10-21 17:11:33 +02002303 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O1" LDFLAGS="-m32 $ASAN_CFLAGS"
Simon Butcher8e6a22a2018-07-20 21:27:33 +01002304
2305 msg "test: i386, make, gcc -O1 (ASan build)"
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01002306 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +01002307
2308 msg "test ssl-opt.sh, i386, make, gcc-O1"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002309 tests/ssl-opt.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01002310}
Gilles Peskine878cf602019-01-06 20:50:38 +00002311support_test_m32_o1 () {
2312 support_test_m32_o0 "$@"
2313}
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01002314
Gilles Peskine0c6b7992019-04-12 20:29:48 +02002315component_test_m32_everest () {
2316 msg "build: i386, Everest ECDH context (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002317 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
Gilles Peskine8fd59422019-10-21 17:11:33 +02002318 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O2" LDFLAGS="-m32 $ASAN_CFLAGS"
Gilles Peskine0c6b7992019-04-12 20:29:48 +02002319
2320 msg "test: i386, Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
2321 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +01002322
2323 msg "test: i386, Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002324 tests/ssl-opt.sh -f ECDH
Gilles Peskine636c26a2020-03-04 20:46:15 +01002325
2326 msg "test: i386, Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
2327 # Exclude some symmetric ciphers that are redundant here to gain time.
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002328 tests/compat.sh -f ECDH -V NO -e 'ARIA\|CAMELLIA\|CHACHA\|DES'
Gilles Peskine0c6b7992019-04-12 20:29:48 +02002329}
2330support_test_m32_everest () {
2331 support_test_m32_o0 "$@"
2332}
2333
Gilles Peskine8f073122018-11-27 15:58:47 +01002334component_test_mx32 () {
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01002335 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002336 scripts/config.py full
Gilles Peskine5d26e7c2019-06-07 14:50:09 +02002337 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32' LDFLAGS='-mx32'
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01002338
2339 msg "test: 64-bit ILP32, make, gcc"
2340 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01002341}
Gilles Peskine878cf602019-01-06 20:50:38 +00002342support_test_mx32 () {
2343 case $(uname -m) in
2344 amd64|x86_64) true;;
2345 *) false;;
2346 esac
2347}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00002348
Peter Kolbus60c6da22018-12-27 06:59:04 -06002349component_test_min_mpi_window_size () {
2350 msg "build: Default + MBEDTLS_MPI_WINDOW_SIZE=1 (ASan build)" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002351 scripts/config.py set MBEDTLS_MPI_WINDOW_SIZE 1
Peter Kolbus60c6da22018-12-27 06:59:04 -06002352 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2353 make
2354
2355 msg "test: MBEDTLS_MPI_WINDOW_SIZE=1 - main suites (inc. selftests) (ASan build)" # ~ 10s
2356 make test
2357}
2358
Gilles Peskine8f073122018-11-27 15:58:47 +01002359component_test_have_int32 () {
2360 msg "build: gcc, force 32-bit bignum limbs"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002361 scripts/config.py unset MBEDTLS_HAVE_ASM
2362 scripts/config.py unset MBEDTLS_AESNI_C
2363 scripts/config.py unset MBEDTLS_PADLOCK_C
Gilles Peskine8f073122018-11-27 15:58:47 +01002364 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01002365
Gilles Peskine8f073122018-11-27 15:58:47 +01002366 msg "test: gcc, force 32-bit bignum limbs"
2367 make test
2368}
Andres Amaya Garciafe843a32017-07-20 13:21:34 +01002369
Gilles Peskine8f073122018-11-27 15:58:47 +01002370component_test_have_int64 () {
2371 msg "build: gcc, force 64-bit bignum limbs"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002372 scripts/config.py unset MBEDTLS_HAVE_ASM
2373 scripts/config.py unset MBEDTLS_AESNI_C
2374 scripts/config.py unset MBEDTLS_PADLOCK_C
Gilles Peskine8f073122018-11-27 15:58:47 +01002375 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
Gilles Peskine14c3c062018-01-29 21:25:12 +01002376
Gilles Peskine8f073122018-11-27 15:58:47 +01002377 msg "test: gcc, force 64-bit bignum limbs"
2378 make test
2379}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00002380
Gilles Peskine8f073122018-11-27 15:58:47 +01002381component_test_no_udbl_division () {
2382 msg "build: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002383 scripts/config.py full
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002384 scripts/config.py set MBEDTLS_NO_UDBL_DIVISION
Gilles Peskine8f073122018-11-27 15:58:47 +01002385 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02002386
Gilles Peskine8f073122018-11-27 15:58:47 +01002387 msg "test: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
2388 make test
2389}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02002390
Gilles Peskine8f073122018-11-27 15:58:47 +01002391component_test_no_64bit_multiplication () {
2392 msg "build: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002393 scripts/config.py full
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002394 scripts/config.py set MBEDTLS_NO_64BIT_MULTIPLICATION
Gilles Peskine8f073122018-11-27 15:58:47 +01002395 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02002396
Gilles Peskine8f073122018-11-27 15:58:47 +01002397 msg "test: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
2398 make test
2399}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02002400
Gilles Peskine3809f5f2020-11-09 15:40:05 +01002401component_test_no_strings () {
2402 msg "build: no strings" # ~10s
2403 scripts/config.py full
2404 # Disable options that activate a large amount of string constants.
2405 scripts/config.py unset MBEDTLS_DEBUG_C
2406 scripts/config.py unset MBEDTLS_ERROR_C
2407 scripts/config.py set MBEDTLS_ERROR_STRERROR_DUMMY
2408 scripts/config.py unset MBEDTLS_VERSION_FEATURES
2409 make CFLAGS='-Werror -Os'
2410
2411 msg "test: no strings" # ~ 10s
2412 make test
2413}
2414
Hanno Beckerc5722d12020-10-09 11:10:42 +01002415component_test_no_x509_info () {
2416 msg "build: full + MBEDTLS_X509_REMOVE_INFO" # ~ 10s
2417 scripts/config.pl full
2418 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
2419 scripts/config.pl set MBEDTLS_X509_REMOVE_INFO
2420 make CFLAGS='-Werror -O1'
2421
2422 msg "test: full + MBEDTLS_X509_REMOVE_INFO" # ~ 10s
2423 make test
2424
2425 msg "test: ssl-opt.sh, full + MBEDTLS_X509_REMOVE_INFO" # ~ 1 min
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002426 tests/ssl-opt.sh
Hanno Beckerc5722d12020-10-09 11:10:42 +01002427}
2428
Gilles Peskine8f073122018-11-27 15:58:47 +01002429component_build_arm_none_eabi_gcc () {
Gilles Peskine18487f62020-04-30 23:11:54 +02002430 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002431 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 -O1' lib
Gilles Peskine18487f62020-04-30 23:11:54 +02002433
2434 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1"
2435 ${ARM_NONE_EABI_GCC_PREFIX}size library/*.o
Gilles Peskine8f073122018-11-27 15:58:47 +01002436}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02002437
Gilles Peskine2c897d72019-08-09 16:05:05 +02002438component_build_arm_none_eabi_gcc_arm5vte () {
Gilles Peskine18487f62020-04-30 23:11:54 +02002439 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=arm5vte" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002440 scripts/config.py baremetal
Gilles Peskine2c897d72019-08-09 16:05:05 +02002441 # Build for a target platform that's close to what Debian uses
2442 # for its "armel" distribution (https://wiki.debian.org/ArmEabiPort).
2443 # See https://github.com/ARMmbed/mbedtls/pull/2169 and comments.
2444 # It would be better to build with arm-linux-gnueabi-gcc but
2445 # we don't have that on our CI at this time.
Gilles Peskineaeedd742020-09-02 11:03:04 +02002446 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 +02002447
2448 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=armv5te -O1"
2449 ${ARM_NONE_EABI_GCC_PREFIX}size library/*.o
Gilles Peskine93e4e032019-08-05 11:34:25 +02002450}
2451
Gilles Peskine6e2fb862020-04-30 23:00:53 +02002452component_build_arm_none_eabi_gcc_m0plus () {
2453 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus" # ~ 10s
2454 scripts/config.py baremetal
Gilles Peskineaeedd742020-09-02 11:03:04 +02002455 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 +02002456
2457 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus -Os"
2458 ${ARM_NONE_EABI_GCC_PREFIX}size library/*.o
Gilles Peskine6e2fb862020-04-30 23:00:53 +02002459}
2460
Gilles Peskine8f073122018-11-27 15:58:47 +01002461component_build_arm_none_eabi_gcc_no_udbl_division () {
Gilles Peskine6d061342020-04-30 18:19:32 +02002462 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002463 scripts/config.py baremetal
2464 scripts/config.py set MBEDTLS_NO_UDBL_DIVISION
Gilles Peskineaeedd742020-09-02 11:03:04 +02002465 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 +01002466 echo "Checking that software 64-bit division is not required"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002467 not grep __aeabi_uldiv library/*.o
Gilles Peskine8f073122018-11-27 15:58:47 +01002468}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02002469
Gilles Peskine8f073122018-11-27 15:58:47 +01002470component_build_arm_none_eabi_gcc_no_64bit_multiplication () {
Gilles Peskine6d061342020-04-30 18:19:32 +02002471 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc MBEDTLS_NO_64BIT_MULTIPLICATION, make" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002472 scripts/config.py baremetal
2473 scripts/config.py set MBEDTLS_NO_64BIT_MULTIPLICATION
Gilles Peskineaeedd742020-09-02 11:03:04 +02002474 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 +01002475 echo "Checking that software 64-bit multiplication is not required"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002476 not grep __aeabi_lmul library/*.o
Gilles Peskine8f073122018-11-27 15:58:47 +01002477}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02002478
Gilles Peskine8f073122018-11-27 15:58:47 +01002479component_build_armcc () {
Gilles Peskine18487f62020-04-30 23:11:54 +02002480 msg "build: ARM Compiler 5"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002481 scripts/config.py baremetal
Gilles Peskinebca6ab92017-12-19 18:24:31 +01002482 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
Gilles Peskine18487f62020-04-30 23:11:54 +02002483
2484 msg "size: ARM Compiler 5"
2485 "$ARMC5_FROMELF" -z library/*.o
2486
Gilles Peskinebca6ab92017-12-19 18:24:31 +01002487 make clean
Andres AG87bb5772016-09-27 15:05:15 +01002488
Gilles Peskinebca6ab92017-12-19 18:24:31 +01002489 # ARM Compiler 6 - Target ARMv7-A
2490 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-a"
Simon Butcher940737f2017-07-23 13:42:36 +02002491
Gilles Peskinebca6ab92017-12-19 18:24:31 +01002492 # ARM Compiler 6 - Target ARMv7-M
2493 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m"
Simon Butcher940737f2017-07-23 13:42:36 +02002494
Gilles Peskinebca6ab92017-12-19 18:24:31 +01002495 # ARM Compiler 6 - Target ARMv8-A - AArch32
2496 armc6_build_test "--target=arm-arm-none-eabi -march=armv8.2-a"
Simon Butcher940737f2017-07-23 13:42:36 +02002497
Gilles Peskinebca6ab92017-12-19 18:24:31 +01002498 # ARM Compiler 6 - Target ARMv8-M
2499 armc6_build_test "--target=arm-arm-none-eabi -march=armv8-m.main"
Simon Butcher940737f2017-07-23 13:42:36 +02002500
Gilles Peskinebca6ab92017-12-19 18:24:31 +01002501 # ARM Compiler 6 - Target ARMv8-A - AArch64
2502 armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a"
Gilles Peskine8f073122018-11-27 15:58:47 +01002503}
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +01002504
Hanno Beckera711f6e2020-05-04 12:03:51 +01002505component_test_tls13_experimental () {
2506 msg "build: default config with MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL enabled"
2507 scripts/config.pl set MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL
2508 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2509 make
2510 msg "test: default config with MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL enabled"
2511 make test
2512}
2513
Gilles Peskine8f073122018-11-27 15:58:47 +01002514component_build_mingw () {
2515 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
Andrzej Kurek232e8f92019-10-03 03:18:01 -04002516 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 +00002517
Gilles Peskine8f073122018-11-27 15:58:47 +01002518 # note Make tests only builds the tests, but doesn't run them
Andrzej Kurek232e8f92019-10-03 03:18:01 -04002519 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 +01002520 make WINDOWS_BUILD=1 clean
Gilles Peskine2a458da2017-05-12 15:26:58 +02002521
Gilles Peskine8f073122018-11-27 15:58:47 +01002522 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
Andrzej Kurek232e8f92019-10-03 03:18:01 -04002523 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
2524 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 +01002525 make WINDOWS_BUILD=1 clean
2526}
Jaeden Amero117b8a42019-04-17 15:19:26 +01002527support_build_mingw() {
2528 case $(i686-w64-mingw32-gcc -dumpversion) in
2529 [0-5]*) false;;
2530 *) true;;
2531 esac
2532}
Simon Butcher91aef332016-11-17 09:20:50 +00002533
Gilles Peskine8f073122018-11-27 15:58:47 +01002534component_test_memsan () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01002535 msg "build: MSan (clang)" # ~ 1 min 20s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002536 scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm
Gilles Peskine7ad603e2017-12-10 23:22:20 +01002537 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
2538 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +02002539
Gilles Peskine7ad603e2017-12-10 23:22:20 +01002540 msg "test: main suites (MSan)" # ~ 10s
2541 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01002542
Gilles Peskine7ad603e2017-12-10 23:22:20 +01002543 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002544 tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01002545
Gilles Peskine7ad603e2017-12-10 23:22:20 +01002546 # Optional part(s)
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01002547
Gilles Peskine7ad603e2017-12-10 23:22:20 +01002548 if [ "$MEMORY" -gt 0 ]; then
2549 msg "test: compat.sh (MSan)" # ~ 6 min 20s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002550 tests/compat.sh
Gilles Peskine7ad603e2017-12-10 23:22:20 +01002551 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01002552}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01002553
Gilles Peskine69f190e2019-01-10 00:11:42 +01002554component_test_valgrind () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01002555 msg "build: Release (clang)"
Gilles Peskine7ad603e2017-12-10 23:22:20 +01002556 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
2557 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00002558
Gilles Peskine7ad603e2017-12-10 23:22:20 +01002559 msg "test: main suites valgrind (Release)"
2560 make memcheck
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00002561
Gilles Peskine636c26a2020-03-04 20:46:15 +01002562 # Optional parts (slow; currently broken on OS X because programs don't
2563 # seem to receive signals under valgrind on OS X).
Gilles Peskine7ad603e2017-12-10 23:22:20 +01002564 if [ "$MEMORY" -gt 0 ]; then
2565 msg "test: ssl-opt.sh --memcheck (Release)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002566 tests/ssl-opt.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01002567 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00002568
Gilles Peskine7ad603e2017-12-10 23:22:20 +01002569 if [ "$MEMORY" -gt 1 ]; then
2570 msg "test: compat.sh --memcheck (Release)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002571 tests/compat.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01002572 fi
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02002573
2574 if [ "$MEMORY" -gt 0 ]; then
2575 msg "test: context-info.sh --memcheck (Release)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002576 tests/context-info.sh --memcheck
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02002577 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01002578}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00002579
Gilles Peskine8f073122018-11-27 15:58:47 +01002580component_test_cmake_out_of_source () {
2581 msg "build: cmake 'out-of-source' build"
Gilles Peskine8f073122018-11-27 15:58:47 +01002582 MBEDTLS_ROOT_DIR="$PWD"
2583 mkdir "$OUT_OF_SOURCE_DIR"
2584 cd "$OUT_OF_SOURCE_DIR"
2585 cmake "$MBEDTLS_ROOT_DIR"
2586 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00002587
Gilles Peskine8f073122018-11-27 15:58:47 +01002588 msg "test: cmake 'out-of-source' build"
2589 make test
2590 # Test an SSL option that requires an auxiliary script in test/scripts/.
2591 # Also ensure that there are no error messages such as
2592 # "No such file or directory", which would indicate that some required
2593 # file is missing (ssl-opt.sh tolerates the absence of some files so
2594 # may exit with status 0 but emit errors).
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002595 ./tests/ssl-opt.sh -f 'Fallback SCSV: beginning of list' 2>ssl-opt.err
Gilles Peskinef7e956c2020-03-28 18:56:09 +01002596 cat ssl-opt.err >&2
2597 # If ssl-opt.err is non-empty, record an error and keep going.
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002598 [ ! -s ssl-opt.err ]
Gilles Peskinef7e956c2020-03-28 18:56:09 +01002599 rm ssl-opt.err
Gilles Peskine8f073122018-11-27 15:58:47 +01002600 cd "$MBEDTLS_ROOT_DIR"
2601 rm -rf "$OUT_OF_SOURCE_DIR"
Gilles Peskine8f073122018-11-27 15:58:47 +01002602}
Andres AGdc192212016-08-31 17:33:13 +01002603
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01002604component_test_cmake_as_subdirectory () {
2605 msg "build: cmake 'as-subdirectory' build"
2606 MBEDTLS_ROOT_DIR="$PWD"
2607
2608 cd programs/test/cmake_subproject
2609 cmake .
2610 make
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002611 ./cmake_subproject
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01002612
2613 cd "$MBEDTLS_ROOT_DIR"
2614 unset MBEDTLS_ROOT_DIR
2615}
2616
Chris Kayd259e342021-03-25 16:03:25 +00002617component_test_cmake_as_package () {
2618 msg "build: cmake 'as-package' build"
2619 MBEDTLS_ROOT_DIR="$PWD"
2620
2621 cd programs/test/cmake_package
2622 cmake .
2623 make
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002624 ./cmake_package
Chris Kayd259e342021-03-25 16:03:25 +00002625
2626 cd "$MBEDTLS_ROOT_DIR"
2627 unset MBEDTLS_ROOT_DIR
2628}
2629
2630component_test_cmake_as_package_install () {
2631 msg "build: cmake 'as-installed-package' build"
2632 MBEDTLS_ROOT_DIR="$PWD"
2633
2634 cd programs/test/cmake_package_install
2635 cmake .
2636 make
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002637 ./cmake_package_install
Chris Kayd259e342021-03-25 16:03:25 +00002638
2639 cd "$MBEDTLS_ROOT_DIR"
2640 unset MBEDTLS_ROOT_DIR
2641}
2642
Gilles Peskine8f073122018-11-27 15:58:47 +01002643component_test_zeroize () {
2644 # Test that the function mbedtls_platform_zeroize() is not optimized away by
2645 # different combinations of compilers and optimization flags by using an
2646 # auxiliary GDB script. Unfortunately, GDB does not return error values to the
2647 # system in all cases that the script fails, so we must manually search the
2648 # output to check whether the pass string is present and no failure strings
2649 # were printed.
Andres AGdc192212016-08-31 17:33:13 +01002650
Gilles Peskine4976e822019-01-06 19:52:22 +00002651 # Don't try to disable ASLR. We don't care about ASLR here. We do care
2652 # about a spurious message if Gdb tries and fails, so suppress that.
2653 gdb_disable_aslr=
2654 if [ -z "$(gdb -batch -nw -ex 'set disable-randomization off' 2>&1)" ]; then
2655 gdb_disable_aslr='set disable-randomization off'
2656 fi
2657
Gilles Peskine8f073122018-11-27 15:58:47 +01002658 for optimization_flag in -O2 -O3 -Ofast -Os; do
Gilles Peskine55f7c942019-01-09 22:28:21 +01002659 for compiler in clang gcc; do
2660 msg "test: $compiler $optimization_flag, mbedtls_platform_zeroize()"
2661 make programs CC="$compiler" DEBUG=1 CFLAGS="$optimization_flag"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002662 gdb -ex "$gdb_disable_aslr" -x tests/scripts/test_zeroize.gdb -nw -batch -nx 2>&1 | tee test_zeroize.log
2663 grep "The buffer was correctly zeroized" test_zeroize.log
2664 not grep -i "error" test_zeroize.log
Gilles Peskine55f7c942019-01-09 22:28:21 +01002665 rm -f test_zeroize.log
2666 make clean
2667 done
Andres Amaya Garcia29673812017-10-25 10:35:51 +01002668 done
Andres Amaya Garciad0d7bf62017-10-25 09:01:31 +01002669
Gilles Peskine4976e822019-01-06 19:52:22 +00002670 unset gdb_disable_aslr
Gilles Peskine8f073122018-11-27 15:58:47 +01002671}
Gilles Peskine192c72f2017-12-21 15:59:21 +01002672
Gilles Peskine8f073122018-11-27 15:58:47 +01002673component_check_python_files () {
2674 msg "Lint: Python scripts"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002675 tests/scripts/check-python-files.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01002676}
Gilles Peskine192c72f2017-12-21 15:59:21 +01002677
Gilles Peskine8f073122018-11-27 15:58:47 +01002678component_check_generate_test_code () {
2679 msg "uint test: generate_test_code.py"
Manuel Pégourié-Gonnarddfb114a2020-06-02 11:40:08 +02002680 # unittest writes out mundane stuff like number or tests run on stderr.
2681 # Our convention is to reserve stderr for actual errors, and write
2682 # harmless info on stdout so it can be suppress with --quiet.
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002683 ./tests/scripts/test_generate_test_code.py 2>&1
Gilles Peskine8f073122018-11-27 15:58:47 +01002684}
Gilles Peskine192c72f2017-12-21 15:59:21 +01002685
2686################################################################
2687#### Termination
2688################################################################
2689
Gilles Peskine8f073122018-11-27 15:58:47 +01002690post_report () {
2691 msg "Done, cleaning up"
2692 cleanup
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01002693
Gilles Peskine8f073122018-11-27 15:58:47 +01002694 final_report
2695}
2696
2697
2698
2699################################################################
2700#### Run all the things
2701################################################################
2702
Gilles Peskine5d996822020-03-28 21:09:21 +01002703# Function invoked by --error-test to test error reporting.
2704pseudo_component_error_test () {
2705 msg "Testing error reporting $error_test"
2706 if [ $KEEP_GOING -ne 0 ]; then
2707 echo "Expect three failing commands."
2708 fi
2709 error_test='this should not be used since the component runs in a subshell'
2710 grep non_existent /dev/null
2711 not grep -q . "$0"
2712 make unknown_target
2713 false "this should not be executed"
2714}
2715
Gilles Peskinee48351a2018-11-27 16:06:30 +01002716# Run one component and clean up afterwards.
Gilles Peskine8f073122018-11-27 15:58:47 +01002717run_component () {
Gilles Peskine608953e2019-01-02 18:57:02 +01002718 # Back up the configuration in case the component modifies it.
2719 # The cleanup function will restore it.
2720 cp -p "$CONFIG_H" "$CONFIG_BAK"
John Durkopbd069d32020-10-31 22:14:03 -07002721 cp -p "$CRYPTO_CONFIG_H" "$CRYPTO_CONFIG_BAK"
Gilles Peskineffcdeff2018-12-04 12:49:28 +01002722 current_component="$1"
Gilles Peskine9004a172019-09-16 15:20:36 +02002723 export MBEDTLS_TEST_CONFIGURATION="$current_component"
Gilles Peskine2ef377d2019-10-07 18:44:21 +02002724
2725 # Unconditionally create a seedfile that's sufficiently long.
2726 # Do this before each component, because a previous component may
2727 # have messed it up or shortened it.
Manuel Pégourié-Gonnardf1f180a2020-06-08 10:46:35 +02002728 redirect_err dd if=/dev/urandom of=./tests/seedfile bs=64 count=1
Gilles Peskine2ef377d2019-10-07 18:44:21 +02002729
Gilles Peskinece266c42020-03-28 18:50:43 +01002730 # Run the component in a subshell
2731 if [ $KEEP_GOING -eq 1 ]; then
2732 set +e
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +02002733 fi
Gilles Peskinece266c42020-03-28 18:50:43 +01002734 (
2735 if [ $QUIET -eq 1 ]; then
2736 # msg() will be silenced, so just print the component name here.
2737 echo "${current_component#component_}"
2738 exec >/dev/null
2739 fi
2740 if [ $KEEP_GOING -eq 1 ]; then
2741 # Keep "set -e" off, and run an ERR trap instead to record failures.
2742 set -E
2743 trap err_trap ERR
2744 fi
2745 # The next line is what runs the component
2746 "$@"
2747 if [ $KEEP_GOING -eq 1 ]; then
2748 trap - ERR
2749 exit $last_failure_status
2750 fi
2751 )
2752 component_status=$?
2753 if [ $KEEP_GOING -eq 1 ]; then
2754 set -e
2755 if [ $component_status -ne 0 ]; then
2756 failure_count=$((failure_count + 1))
2757 fi
2758 fi
Gilles Peskine2ef377d2019-10-07 18:44:21 +02002759
2760 # Restore the build tree to a clean state.
Gilles Peskinee48351a2018-11-27 16:06:30 +01002761 cleanup
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +02002762 unset current_component
Gilles Peskine8f073122018-11-27 15:58:47 +01002763}
2764
2765# Preliminary setup
2766pre_check_environment
2767pre_initialize_variables
2768pre_parse_command_line "$@"
Gilles Peskine348fb9a2018-11-27 17:04:29 +01002769
Gilles Peskine878cf602019-01-06 20:50:38 +00002770pre_check_git
Andrzej Kurekeb508712019-02-14 07:18:59 -05002771
Gilles Peskine878cf602019-01-06 20:50:38 +00002772build_status=0
2773if [ $KEEP_GOING -eq 1 ]; then
2774 pre_setup_keep_going
Gilles Peskine8f073122018-11-27 15:58:47 +01002775fi
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +02002776pre_setup_quiet_redirect
Gilles Peskine67ffdaf2019-09-16 15:55:46 +02002777pre_prepare_outcome_file
Gilles Peskine878cf602019-01-06 20:50:38 +00002778pre_print_configuration
2779pre_check_tools
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01002780cleanup
Gilles Peskine1570b592021-04-22 01:10:12 +02002781pre_generate_files
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01002782
Gilles Peskinebeb3a812019-01-06 22:11:25 +00002783# Run the requested tests.
Gilles Peskine5d996822020-03-28 21:09:21 +01002784while [ $error_test -gt 0 ]; do
2785 run_component pseudo_component_error_test
2786 error_test=$((error_test - 1))
2787done
Gilles Peskinebeb3a812019-01-06 22:11:25 +00002788for component in $RUN_COMPONENTS; do
2789 run_component "component_$component"
2790done
Gilles Peskine8f073122018-11-27 15:58:47 +01002791
2792# We're done.
Gilles Peskine878cf602019-01-06 20:50:38 +00002793post_report