blob: 61b17e102260ed62ef051dd69e4649f6a0493220 [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 Peskinea71d64c2018-03-21 12:16:57 +0100270 if [ -n "${MBEDTLS_ROOT_DIR+set}" ]; then
271 cd "$MBEDTLS_ROOT_DIR"
272 fi
273
Gilles Peskine7c652162017-12-11 00:01:40 +0100274 command make clean
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200275
Gilles Peskine31b07e22018-03-21 12:15:06 +0100276 # Remove CMake artefacts
Jaeden Amero2d0e00f2018-11-07 18:46:41 +0000277 find . -name .git -prune -o \
Gilles Peskine31b07e22018-03-21 12:15:06 +0100278 -iname CMakeFiles -exec rm -rf {} \+ -o \
279 \( -iname cmake_install.cmake -o \
280 -iname CTestTestfile.cmake -o \
Chris Kayd259e342021-03-25 16:03:25 +0000281 -iname CMakeCache.txt \) -exec rm -f {} \+
Gilles Peskine31b07e22018-03-21 12:15:06 +0100282 # Recover files overwritten by in-tree CMake builds
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000283 rm -f include/Makefile include/mbedtls/Makefile programs/*/Makefile
Gilles Peskine636c26a2020-03-04 20:46:15 +0100284 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile
285 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200286
Jaeden Ameroab83fdf2019-06-20 17:38:22 +0100287 # Remove any artifacts from the component_test_cmake_as_subdirectory test.
288 rm -rf programs/test/cmake_subproject/build
289 rm -f programs/test/cmake_subproject/Makefile
290 rm -f programs/test/cmake_subproject/cmake_subproject
291
Chris Kayd259e342021-03-25 16:03:25 +0000292 # Remove any artifacts from the component_test_cmake_as_package test.
293 rm -rf programs/test/cmake_package/build
294 rm -f programs/test/cmake_package/Makefile
295 rm -f programs/test/cmake_package/cmake_package
296
297 # Remove any artifacts from the component_test_cmake_as_installed_package test.
298 rm -rf programs/test/cmake_package_install/build
299 rm -f programs/test/cmake_package_install/Makefile
300 rm -f programs/test/cmake_package_install/cmake_package_install
301
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200302 if [ -f "$CONFIG_BAK" ]; then
303 mv "$CONFIG_BAK" "$CONFIG_H"
304 fi
John Durkopbd069d32020-10-31 22:14:03 -0700305
306 if [ -f "$CRYPTO_CONFIG_BAK" ]; then
307 mv "$CRYPTO_CONFIG_BAK" "$CRYPTO_CONFIG_H"
308 fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100309}
310
Gilles Peskine7c652162017-12-11 00:01:40 +0100311# Executed on exit. May be redefined depending on command line options.
312final_report () {
313 :
314}
315
316fatal_signal () {
317 cleanup
318 final_report $1
319 trap - $1
320 kill -$1 $$
321}
322
323trap 'fatal_signal HUP' HUP
324trap 'fatal_signal INT' INT
325trap 'fatal_signal TERM' TERM
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200326
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100327msg()
328{
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100329 if [ -n "${current_component:-}" ]; then
330 current_section="${current_component#component_}: $1"
331 else
332 current_section="$1"
333 fi
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200334
335 if [ $QUIET -eq 1 ]; then
336 return
337 fi
338
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100339 echo ""
340 echo "******************************************************************"
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100341 echo "* $current_section "
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000342 printf "* "; date
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100343 echo "******************************************************************"
344}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100345
Gilles Peskine8f073122018-11-27 15:58:47 +0100346armc6_build_test()
347{
348 FLAGS="$1"
Andres AGa5cd9732016-10-17 15:23:10 +0100349
Gilles Peskine18487f62020-04-30 23:11:54 +0200350 msg "build: ARM Compiler 6 ($FLAGS)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100351 ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \
352 WARNING_CFLAGS='-xc -std=c99' make lib
Gilles Peskine18487f62020-04-30 23:11:54 +0200353
354 msg "size: ARM Compiler 6 ($FLAGS)"
355 "$ARMC6_FROMELF" -z library/*.o
356
Gilles Peskine8f073122018-11-27 15:58:47 +0100357 make clean
358}
Andres AGa5cd9732016-10-17 15:23:10 +0100359
Andres AGd9eba4b2016-08-26 14:42:14 +0100360err_msg()
361{
362 echo "$1" >&2
363}
364
365check_tools()
366{
367 for TOOL in "$@"; do
Andres AG98393602017-01-31 17:04:45 +0000368 if ! `type "$TOOL" >/dev/null 2>&1`; then
Andres AGd9eba4b2016-08-26 14:42:14 +0100369 err_msg "$TOOL not found!"
370 exit 1
371 fi
372 done
373}
374
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400375check_headers_in_cpp () {
Peter Kolbus1bc1a4c2019-02-01 17:19:08 -0600376 ls include/mbedtls | grep "\.h$" >headers.txt
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400377 <programs/test/cpp_dummy_build.cpp sed -n 's/"$//; s!^#include "mbedtls/!!p' |
378 sort |
379 diff headers.txt -
380 rm headers.txt
381}
382
Gilles Peskine8f073122018-11-27 15:58:47 +0100383pre_parse_command_line () {
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000384 COMMAND_LINE_COMPONENTS=
Gilles Peskinea28db922019-01-10 00:05:18 +0100385 all_except=0
Gilles Peskine5d996822020-03-28 21:09:21 +0100386 error_test=0
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000387 no_armcc=
SimonB2e23c822016-04-16 21:54:39 +0100388
Jaeden Amero9b90f2e2018-11-02 18:34:17 +0000389 # Note that legacy options are ignored instead of being omitted from this
390 # list of options, so invocations that worked with previous version of
391 # all.sh will still run and work properly.
Gilles Peskine8f073122018-11-27 15:58:47 +0100392 while [ $# -gt 0 ]; do
Gilles Peskine55f7c942019-01-09 22:28:21 +0100393 case "$1" in
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200394 --append-outcome) append_outcome=1;;
Gilles Peskine6d061342020-04-30 18:19:32 +0200395 --arm-none-eabi-gcc-prefix) shift; ARM_NONE_EABI_GCC_PREFIX="$1";;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000396 --armcc) no_armcc=;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100397 --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
398 --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
Gilles Peskine5d996822020-03-28 21:09:21 +0100399 --error-test) error_test=$((error_test + 1));;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000400 --except) all_except=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100401 --force|-f) FORCE=1;;
402 --gnutls-cli) shift; GNUTLS_CLI="$1";;
403 --gnutls-legacy-cli) shift; GNUTLS_LEGACY_CLI="$1";;
404 --gnutls-legacy-serv) shift; GNUTLS_LEGACY_SERV="$1";;
405 --gnutls-serv) shift; GNUTLS_SERV="$1";;
406 --help|-h) usage; exit;;
407 --keep-going|-k) KEEP_GOING=1;;
Gilles Peskine878cf602019-01-06 20:50:38 +0000408 --list-all-components) printf '%s\n' $ALL_COMPONENTS; exit;;
409 --list-components) printf '%s\n' $SUPPORTED_COMPONENTS; exit;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100410 --memory|-m) MEMORY=1;;
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200411 --no-append-outcome) append_outcome=0;;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000412 --no-armcc) no_armcc=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100413 --no-force) FORCE=0;;
414 --no-keep-going) KEEP_GOING=0;;
415 --no-memory) MEMORY=0;;
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200416 --no-quiet) QUIET=0;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100417 --openssl) shift; OPENSSL="$1";;
418 --openssl-legacy) shift; OPENSSL_LEGACY="$1";;
419 --openssl-next) shift; OPENSSL_NEXT="$1";;
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200420 --outcome-file) shift; MBEDTLS_TEST_OUTCOME_FILE="$1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100421 --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200422 --quiet|-q) QUIET=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100423 --random-seed) unset SEED;;
Manuel Pégourié-Gonnarde0501912020-06-08 12:59:27 +0200424 --release-test|-r) SEED=$RELEASE_SEED;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100425 --seed|-s) shift; SEED="$1";;
426 -*)
427 echo >&2 "Unknown option: $1"
428 echo >&2 "Run $0 --help for usage."
429 exit 120
430 ;;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000431 *) COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS $1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100432 esac
433 shift
Gilles Peskine8f073122018-11-27 15:58:47 +0100434 done
SimonB2e23c822016-04-16 21:54:39 +0100435
Gilles Peskinea28db922019-01-10 00:05:18 +0100436 # With no list of components, run everything.
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000437 if [ -z "$COMMAND_LINE_COMPONENTS" ]; then
438 all_except=1
Andres AGdc192212016-08-31 17:33:13 +0100439 fi
440
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000441 # --no-armcc is a legacy option. The modern way is --except '*_armcc*'.
442 # Ignore it if components are listed explicitly on the command line.
Gilles Peskinea28db922019-01-10 00:05:18 +0100443 if [ -n "$no_armcc" ] && [ $all_except -eq 1 ]; then
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000444 COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS *_armcc*"
SimonB2e23c822016-04-16 21:54:39 +0100445 fi
SimonB2e23c822016-04-16 21:54:39 +0100446
Gilles Peskineb80f0d22020-03-28 21:37:59 +0100447 if [ $all_except -eq 0 ]; then
448 unsupported=0
449 for component in $COMMAND_LINE_COMPONENTS; do
450 case $component in
451 *[*?\[]*) continue;;
452 esac
453 case " $SUPPORTED_COMPONENTS " in
454 *" $component "*) :;;
455 *)
456 echo >&2 "Component $component was explicitly requested, but is not known or not supported."
457 unsupported=$((unsupported + 1));;
458 esac
459 done
460 if [ $unsupported -ne 0 ]; then
461 exit 2
462 fi
463 fi
464
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000465 # Build the list of components to run.
Gilles Peskinea28db922019-01-10 00:05:18 +0100466 RUN_COMPONENTS=
467 for component in $SUPPORTED_COMPONENTS; do
468 if is_component_included "$component"; [ $? -eq $all_except ]; then
469 RUN_COMPONENTS="$RUN_COMPONENTS $component"
470 fi
471 done
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000472
473 unset all_except
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000474 unset no_armcc
Gilles Peskine8f073122018-11-27 15:58:47 +0100475}
SimonB2e23c822016-04-16 21:54:39 +0100476
Gilles Peskine8f073122018-11-27 15:58:47 +0100477pre_check_git () {
478 if [ $FORCE -eq 1 ]; then
Gilles Peskine53190e62019-01-09 23:17:35 +0100479 rm -rf "$OUT_OF_SOURCE_DIR"
Gilles Peskine8f073122018-11-27 15:58:47 +0100480 git checkout-index -f -q $CONFIG_H
481 cleanup
482 else
SimonB2e23c822016-04-16 21:54:39 +0100483
Gilles Peskine8f073122018-11-27 15:58:47 +0100484 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
485 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
486 echo "You can either delete this directory manually, or force the test by rerunning"
487 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
488 exit 1
489 fi
490
Bence Szépkútibb0cfeb2021-05-28 09:42:25 +0200491 if ! git diff --quiet include/mbedtls/mbedtls_config.h; then
492 err_msg "Warning - the configuration file 'include/mbedtls/mbedtls_config.h' has been edited. "
Gilles Peskine8f073122018-11-27 15:58:47 +0100493 echo "You can either delete or preserve your work, or force the test by rerunning the"
494 echo "script as: $0 --force"
495 exit 1
496 fi
SimonB2e23c822016-04-16 21:54:39 +0100497 fi
Andrzej Kurekeb508712019-02-14 07:18:59 -0500498}
499
Gilles Peskine8f073122018-11-27 15:58:47 +0100500pre_setup_keep_going () {
Gilles Peskinece266c42020-03-28 18:50:43 +0100501 failure_count=0 # Number of failed components
502 last_failure_status=0 # Last failure status in this component
503
Gilles Peskinefec30cb2020-03-28 19:34:23 +0100504 # See err_trap
505 previous_failure_status=0
506 previous_failed_command=
507 previous_failure_funcall_depth=0
Gilles Peskinea681c592020-03-28 21:27:40 +0100508 unset report_failed_command
Gilles Peskinefec30cb2020-03-28 19:34:23 +0100509
Gilles Peskine7c652162017-12-11 00:01:40 +0100510 start_red=
511 end_color=
512 if [ -t 1 ]; then
Gilles Peskine9736b9d2018-01-02 21:54:17 +0100513 case "${TERM:-}" in
Gilles Peskine7c652162017-12-11 00:01:40 +0100514 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
515 start_red=$(printf '\033[31m')
516 end_color=$(printf '\033[0m')
517 ;;
518 esac
519 fi
Gilles Peskinece266c42020-03-28 18:50:43 +0100520
521 # Keep a summary of failures in a file. We'll print it out at the end.
522 failure_summary_file=$PWD/all-sh-failures-$$.log
523 : >"$failure_summary_file"
524
525 # Whether it makes sense to keep a component going after the specified
526 # command fails (test command) or not (configure or build).
527 # This doesn't have to be 100% accurate: all failures are recorded anyway.
528 can_keep_going_after_failure () {
529 case "$1" in
530 "msg "*) false;;
531 *[!A-Za-z]"test"|*[!A-Za-z]"test"[!A-Za-z]*) true;;
532 "tests/"*) true;;
Gilles Peskinea681c592020-03-28 21:27:40 +0100533 "grep "*|"! grep "*) true;;
Gilles Peskinece266c42020-03-28 18:50:43 +0100534 *) false;;
Gilles Peskine7c652162017-12-11 00:01:40 +0100535 esac
536 }
Gilles Peskinece266c42020-03-28 18:50:43 +0100537
538 # This function runs if there is any error in a component.
539 # It must either exit with a nonzero status, or set
540 # last_failure_status to a nonzero value.
541 err_trap () {
542 # Save $? (status of the failing command). This must be the very
543 # first thing, before $? is overridden.
544 last_failure_status=$?
Gilles Peskinea681c592020-03-28 21:27:40 +0100545 failed_command=${report_failed_command-$BASH_COMMAND}
Gilles Peskinece266c42020-03-28 18:50:43 +0100546
Gilles Peskinefec30cb2020-03-28 19:34:23 +0100547 if [[ $last_failure_status -eq $previous_failure_status &&
548 "$failed_command" == "$previous_failed_command" &&
549 ${#FUNCNAME[@]} == $((previous_failure_funcall_depth - 1)) ]]
550 then
551 # The same command failed twice in a row, but this time one level
552 # less deep in the function call stack. This happens when the last
553 # command of a function returns a nonzero status, and the function
554 # returns that same status. Ignore the second failure.
555 previous_failure_funcall_depth=${#FUNCNAME[@]}
556 return
557 fi
558 previous_failure_status=$last_failure_status
559 previous_failed_command=$failed_command
560 previous_failure_funcall_depth=${#FUNCNAME[@]}
561
Gilles Peskinece266c42020-03-28 18:50:43 +0100562 text="$current_section: $failed_command -> $last_failure_status"
563 echo "${start_red}^^^^$text^^^^${end_color}" >&2
564 echo "$text" >>"$failure_summary_file"
565
566 # If the command is fatal (configure or build command), stop this
567 # component. Otherwise (test command) keep the component running
568 # (run more tests from the same build).
569 if ! can_keep_going_after_failure "$failed_command"; then
570 exit $last_failure_status
571 fi
572 }
573
Gilles Peskine7c652162017-12-11 00:01:40 +0100574 final_report () {
575 if [ $failure_count -gt 0 ]; then
576 echo
577 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Gilles Peskinece266c42020-03-28 18:50:43 +0100578 echo "${start_red}FAILED: $failure_count components${end_color}"
579 cat "$failure_summary_file"
Gilles Peskine7c652162017-12-11 00:01:40 +0100580 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
581 elif [ -z "${1-}" ]; then
582 echo "SUCCESS :)"
583 fi
584 if [ -n "${1-}" ]; then
585 echo "Killed by SIG$1."
586 fi
Gilles Peskinece266c42020-03-28 18:50:43 +0100587 rm -f "$failure_summary_file"
588 if [ $failure_count -gt 0 ]; then
589 exit 1
590 fi
Gilles Peskine7c652162017-12-11 00:01:40 +0100591 }
Gilles Peskine8f073122018-11-27 15:58:47 +0100592}
593
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200594# record_status() and if_build_succeeded() are kept temporarily for backward
595# compatibility. Don't use them in new components.
Gilles Peskinece266c42020-03-28 18:50:43 +0100596record_status () {
597 "$@"
Gilles Peskine7c652162017-12-11 00:01:40 +0100598}
Gilles Peskinece266c42020-03-28 18:50:43 +0100599if_build_succeeded () {
600 "$@"
601}
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200602
Gilles Peskinea681c592020-03-28 21:27:40 +0100603# '! true' does not trigger the ERR trap. Arrange to trigger it, with
604# a reasonably informative error message (not just "$@").
605not () {
606 if "$@"; then
607 report_failed_command="! $*"
608 false
609 unset report_failed_command
610 fi
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200611}
612
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200613pre_setup_quiet_redirect () {
614 if [ $QUIET -ne 1 ]; then
615 redirect_out () {
616 "$@"
617 }
Manuel Pégourié-Gonnardf1f180a2020-06-08 10:46:35 +0200618 redirect_err () {
619 "$@"
620 }
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200621 else
622 redirect_out () {
623 "$@" >/dev/null
624 }
Manuel Pégourié-Gonnardf1f180a2020-06-08 10:46:35 +0200625 redirect_err () {
626 "$@" 2>/dev/null
627 }
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200628 fi
629}
630
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200631pre_prepare_outcome_file () {
632 case "$MBEDTLS_TEST_OUTCOME_FILE" in
633 [!/]*) MBEDTLS_TEST_OUTCOME_FILE="$PWD/$MBEDTLS_TEST_OUTCOME_FILE";;
634 esac
635 if [ -n "$MBEDTLS_TEST_OUTCOME_FILE" ] && [ "$append_outcome" -eq 0 ]; then
636 rm -f "$MBEDTLS_TEST_OUTCOME_FILE"
637 fi
638}
639
Gilles Peskine8f073122018-11-27 15:58:47 +0100640pre_print_configuration () {
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200641 if [ $QUIET -eq 1 ]; then
642 return
643 fi
644
Gilles Peskine8f073122018-11-27 15:58:47 +0100645 msg "info: $0 configuration"
646 echo "MEMORY: $MEMORY"
647 echo "FORCE: $FORCE"
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200648 echo "MBEDTLS_TEST_OUTCOME_FILE: ${MBEDTLS_TEST_OUTCOME_FILE:-(none)}"
Gilles Peskine8f073122018-11-27 15:58:47 +0100649 echo "SEED: ${SEED-"UNSET"}"
Gilles Peskine636c26a2020-03-04 20:46:15 +0100650 echo
Gilles Peskine8f073122018-11-27 15:58:47 +0100651 echo "OPENSSL: $OPENSSL"
652 echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
653 echo "OPENSSL_NEXT: $OPENSSL_NEXT"
654 echo "GNUTLS_CLI: $GNUTLS_CLI"
655 echo "GNUTLS_SERV: $GNUTLS_SERV"
656 echo "GNUTLS_LEGACY_CLI: $GNUTLS_LEGACY_CLI"
657 echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV"
658 echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
659 echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
660}
Andres AG7770ea82016-10-10 15:46:20 +0100661
Andres AGd9eba4b2016-08-26 14:42:14 +0100662# Make sure the tools we need are available.
Gilles Peskine8f073122018-11-27 15:58:47 +0100663pre_check_tools () {
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000664 # Build the list of variables to pass to output_env.sh.
665 set env
SimonB2e23c822016-04-16 21:54:39 +0100666
Gilles Peskine87964262019-01-06 22:40:00 +0000667 case " $RUN_COMPONENTS " in
668 # Require OpenSSL and GnuTLS if running any tests (as opposed to
669 # only doing builds). Not all tests run OpenSSL and GnuTLS, but this
670 # is a good enough approximation in practice.
671 *" test_"*)
672 # To avoid setting OpenSSL and GnuTLS for each call to compat.sh
673 # and ssl-opt.sh, we just export the variables they require.
674 export OPENSSL_CMD="$OPENSSL"
675 export GNUTLS_CLI="$GNUTLS_CLI"
676 export GNUTLS_SERV="$GNUTLS_SERV"
677 # Avoid passing --seed flag in every call to ssl-opt.sh
678 if [ -n "${SEED-}" ]; then
679 export SEED
680 fi
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000681 set "$@" OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY"
682 set "$@" GNUTLS_CLI="$GNUTLS_CLI" GNUTLS_SERV="$GNUTLS_SERV"
683 set "$@" GNUTLS_LEGACY_CLI="$GNUTLS_LEGACY_CLI"
684 set "$@" GNUTLS_LEGACY_SERV="$GNUTLS_LEGACY_SERV"
Gilles Peskine87964262019-01-06 22:40:00 +0000685 check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$OPENSSL_NEXT" \
686 "$GNUTLS_CLI" "$GNUTLS_SERV" \
687 "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV"
688 ;;
689 esac
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200690
Gilles Peskine87964262019-01-06 22:40:00 +0000691 case " $RUN_COMPONENTS " in
692 *_doxygen[_\ ]*) check_tools "doxygen" "dot";;
693 esac
Andres AGd9eba4b2016-08-26 14:42:14 +0100694
Gilles Peskine87964262019-01-06 22:40:00 +0000695 case " $RUN_COMPONENTS " in
Gilles Peskine6d061342020-04-30 18:19:32 +0200696 *_arm_none_eabi_gcc[_\ ]*) check_tools "${ARM_NONE_EABI_GCC_PREFIX}gcc";;
Gilles Peskine87964262019-01-06 22:40:00 +0000697 esac
Andres AGd9eba4b2016-08-26 14:42:14 +0100698
Gilles Peskine87964262019-01-06 22:40:00 +0000699 case " $RUN_COMPONENTS " in
700 *_mingw[_\ ]*) check_tools "i686-w64-mingw32-gcc";;
701 esac
702
703 case " $RUN_COMPONENTS " in
704 *" test_zeroize "*) check_tools "gdb";;
705 esac
706
707 case " $RUN_COMPONENTS " in
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000708 *_armcc*)
Gilles Peskine87964262019-01-06 22:40:00 +0000709 ARMC5_CC="$ARMC5_BIN_DIR/armcc"
710 ARMC5_AR="$ARMC5_BIN_DIR/armar"
Gilles Peskine18487f62020-04-30 23:11:54 +0200711 ARMC5_FROMELF="$ARMC5_BIN_DIR/fromelf"
Gilles Peskine87964262019-01-06 22:40:00 +0000712 ARMC6_CC="$ARMC6_BIN_DIR/armclang"
713 ARMC6_AR="$ARMC6_BIN_DIR/armar"
Gilles Peskine18487f62020-04-30 23:11:54 +0200714 ARMC6_FROMELF="$ARMC6_BIN_DIR/fromelf"
715 check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC5_FROMELF" \
716 "$ARMC6_CC" "$ARMC6_AR" "$ARMC6_FROMELF";;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000717 esac
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000718
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200719 # past this point, no call to check_tool, only printing output
720 if [ $QUIET -eq 1 ]; then
721 return
722 fi
723
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000724 msg "info: output_env.sh"
725 case $RUN_COMPONENTS in
726 *_armcc*)
727 set "$@" ARMC5_CC="$ARMC5_CC" ARMC6_CC="$ARMC6_CC" RUN_ARMCC=1;;
728 *) set "$@" RUN_ARMCC=0;;
729 esac
730 "$@" scripts/output_env.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100731}
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100732
Gilles Peskine1570b592021-04-22 01:10:12 +0200733pre_generate_files() {
Manuel Pégourié-Gonnard87db8a22021-06-18 13:30:14 +0200734 # since make doesn't have proper dependencies, remove any possibly outdate
735 # file that might be around before generating fresh ones
736 make neat
Gilles Peskine1570b592021-04-22 01:10:12 +0200737 make generated_files
738}
739
Gilles Peskine192c72f2017-12-21 15:59:21 +0100740
741
742################################################################
743#### Basic checks
744################################################################
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100745
746#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200747# Test Suites to be executed
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100748#
Manuel Pégourié-Gonnard3d404b42015-07-08 21:59:16 +0100749# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200750# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100751# 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 +0200752# time, so start with a GCC build).
753# 2. Minimize total running time, by avoiding useless rebuilds
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100754#
Manuel Pégourié-Gonnard259b08a2016-01-08 16:27:41 +0100755# Indicative running times are given for reference.
756
Gilles Peskine8f073122018-11-27 15:58:47 +0100757component_check_recursion () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200758 msg "Check: recursion.pl" # < 1s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200759 tests/scripts/recursion.pl library/*.c
Gilles Peskine8f073122018-11-27 15:58:47 +0100760}
Janos Follathb72c6782016-07-19 14:54:17 +0100761
Gilles Peskine67debb62021-05-18 16:09:50 +0200762component_check_generated_files () {
763 msg "Check: check-generated-files, files generated with make" # 2s
764 make generated_files
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200765 tests/scripts/check-generated-files.sh
Gilles Peskine67debb62021-05-18 16:09:50 +0200766
767 msg "Check: check-generated-files -u, files present" # 2s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200768 tests/scripts/check-generated-files.sh -u
Gilles Peskine67debb62021-05-18 16:09:50 +0200769 # Check that the generated files are considered up to date.
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200770 tests/scripts/check-generated-files.sh
Gilles Peskine67debb62021-05-18 16:09:50 +0200771
772 msg "Check: check-generated-files -u, files absent" # 2s
773 command make neat
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200774 tests/scripts/check-generated-files.sh -u
Gilles Peskine67debb62021-05-18 16:09:50 +0200775 # Check that the generated files are considered up to date.
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200776 tests/scripts/check-generated-files.sh
Gilles Peskine67debb62021-05-18 16:09:50 +0200777
778 # This component ends with the generated files present in the source tree.
779 # This is necessary for subsequent components!
780}
781
Gilles Peskine8f073122018-11-27 15:58:47 +0100782component_check_doxy_blocks () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200783 msg "Check: doxygen markup outside doxygen blocks" # < 1s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200784 tests/scripts/check-doxy-blocks.pl
Gilles Peskine8f073122018-11-27 15:58:47 +0100785}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200786
Gilles Peskine8f073122018-11-27 15:58:47 +0100787component_check_files () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200788 msg "Check: file sanity checks (permissions, encodings)" # < 1s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200789 tests/scripts/check_files.py
Gilles Peskine8f073122018-11-27 15:58:47 +0100790}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200791
Gilles Peskine30e0bb42020-05-10 17:40:49 +0200792component_check_changelog () {
793 msg "Check: changelog entries" # < 1s
794 rm -f ChangeLog.new
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200795 scripts/assemble_changelog.py -o ChangeLog.new
Gilles Peskine30e0bb42020-05-10 17:40:49 +0200796 if [ -e ChangeLog.new ]; then
797 # Show the diff for information. It isn't an error if the diff is
798 # non-empty.
799 diff -u ChangeLog ChangeLog.new || true
800 rm ChangeLog.new
801 fi
802}
803
Gilles Peskine8f073122018-11-27 15:58:47 +0100804component_check_names () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200805 msg "Check: declared and exported names (builds the library)" # < 3s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200806 tests/scripts/check-names.sh -v
Gilles Peskine8f073122018-11-27 15:58:47 +0100807}
Darryl Greena07039c2018-03-13 16:48:16 +0000808
Gilles Peskine895868b2019-09-19 21:30:05 +0200809component_check_test_cases () {
810 msg "Check: test case descriptions" # < 1s
Manuel Pégourié-Gonnarda9119162020-06-02 11:51:40 +0200811 if [ $QUIET -eq 1 ]; then
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +0200812 opt='--quiet'
Manuel Pégourié-Gonnarda9119162020-06-02 11:51:40 +0200813 else
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +0200814 opt=''
Manuel Pégourié-Gonnarda9119162020-06-02 11:51:40 +0200815 fi
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200816 tests/scripts/check_test_cases.py $opt
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +0200817 unset opt
Gilles Peskine895868b2019-09-19 21:30:05 +0200818}
819
Gilles Peskine8f073122018-11-27 15:58:47 +0100820component_check_doxygen_warnings () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200821 msg "Check: doxygen warnings (builds the documentation)" # ~ 3s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200822 tests/scripts/doxygen.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100823}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200824
Gilles Peskine192c72f2017-12-21 15:59:21 +0100825
Gilles Peskine636c26a2020-03-04 20:46:15 +0100826
Gilles Peskine192c72f2017-12-21 15:59:21 +0100827################################################################
828#### Build and test many configurations and targets
829################################################################
830
Gilles Peskine7832c9f2019-04-08 17:00:15 +0200831component_test_default_out_of_box () {
832 msg "build: make, default config (out-of-box)" # ~1min
833 make
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200834 # Disable fancy stuff
Gilles Peskine717cd762019-09-27 20:21:11 +0200835 SAVE_MBEDTLS_TEST_OUTCOME_FILE="$MBEDTLS_TEST_OUTCOME_FILE"
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200836 unset MBEDTLS_TEST_OUTCOME_FILE
Gilles Peskine7832c9f2019-04-08 17:00:15 +0200837
838 msg "test: main suites make, default config (out-of-box)" # ~10s
839 make test
840
841 msg "selftest: make, default config (out-of-box)" # ~10s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200842 programs/test/selftest
Gilles Peskine717cd762019-09-27 20:21:11 +0200843
844 export MBEDTLS_TEST_OUTCOME_FILE="$SAVE_MBEDTLS_TEST_OUTCOME_FILE"
845 unset SAVE_MBEDTLS_TEST_OUTCOME_FILE
Gilles Peskine7832c9f2019-04-08 17:00:15 +0200846}
847
Gilles Peskine8f073122018-11-27 15:58:47 +0100848component_test_default_cmake_gcc_asan () {
849 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100850 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
851 make
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200852
Gilles Peskine8f073122018-11-27 15:58:47 +0100853 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
854 make test
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200855
Gilles Peskine97bea012020-04-23 23:37:45 +0200856 msg "test: selftest (ASan build)" # ~ 10s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200857 programs/test/selftest
Gilles Peskine97bea012020-04-23 23:37:45 +0200858
Gilles Peskine8f073122018-11-27 15:58:47 +0100859 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200860 tests/ssl-opt.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200861
Gilles Peskine8f073122018-11-27 15:58:47 +0100862 msg "test: compat.sh (ASan build)" # ~ 6 min
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200863 tests/compat.sh
Piotr Nowicki9978e6e2020-04-07 16:07:05 +0200864
865 msg "test: context-info.sh (ASan build)" # ~ 15 sec
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200866 tests/context-info.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100867}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200868
Hanno Becker01635512019-02-26 14:27:09 +0000869component_test_full_cmake_gcc_asan () {
870 msg "build: full config, cmake, gcc, ASan"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200871 scripts/config.py full
Hanno Becker01635512019-02-26 14:27:09 +0000872 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
873 make
874
875 msg "test: main suites (inc. selftests) (full config, ASan build)"
876 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +0100877
Gilles Peskine97bea012020-04-23 23:37:45 +0200878 msg "test: selftest (ASan build)" # ~ 10s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200879 programs/test/selftest
Gilles Peskine97bea012020-04-23 23:37:45 +0200880
Gilles Peskine636c26a2020-03-04 20:46:15 +0100881 msg "test: ssl-opt.sh (full config, ASan build)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200882 tests/ssl-opt.sh
Gilles Peskine636c26a2020-03-04 20:46:15 +0100883
884 msg "test: compat.sh (full config, ASan build)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200885 tests/compat.sh
Piotr Nowicki9978e6e2020-04-07 16:07:05 +0200886
887 msg "test: context-info.sh (full config, ASan build)" # ~ 15 sec
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200888 tests/context-info.sh
Gilles Peskine636c26a2020-03-04 20:46:15 +0100889}
890
Ronald Cronc3623db2020-10-29 10:51:32 +0100891component_test_psa_crypto_key_id_encodes_owner () {
892 msg "build: full config - USE_PSA_CRYPTO + PSA_CRYPTO_KEY_ID_ENCODES_OWNER, cmake, gcc, ASan"
893 scripts/config.py full
894 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
895 scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
896 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
897 make
898
899 msg "test: full config - USE_PSA_CRYPTO + PSA_CRYPTO_KEY_ID_ENCODES_OWNER, cmake, gcc, ASan"
900 make test
901}
902
Gilles Peskinea3548672021-06-17 11:37:52 +0200903# check_renamed_symbols HEADER LIB
904# Check that if HEADER contains '#define MACRO ...' then MACRO is not a symbol
905# name is LIB.
906check_renamed_symbols () {
907 ! nm "$2" | sed 's/.* //' |
908 grep -x -F "$(sed -n 's/^ *# *define *\([A-Z_a-z][0-9A-Z_a-z]*\)..*/\1/p' "$1")"
909}
910
Gilles Peskined1dcfd52021-06-15 18:37:38 +0200911component_build_psa_crypto_spm () {
912 msg "build: full config - USE_PSA_CRYPTO + PSA_CRYPTO_KEY_ID_ENCODES_OWNER + PSA_CRYPTO_SPM, make, gcc"
913 scripts/config.py full
914 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
915 scripts/config.py unset MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS
916 scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
917 scripts/config.py set MBEDTLS_PSA_CRYPTO_SPM
918 # We can only compile, not link, since our test and sample programs
919 # aren't equipped for the modified names used when MBEDTLS_PSA_CRYPTO_SPM
920 # is active.
921 make CC=gcc CFLAGS='-Werror -Wall -Wextra -I../tests/include/spe' lib
Gilles Peskinea3548672021-06-17 11:37:52 +0200922
923 # Check that if a symbol is renamed by crypto_spe.h, the non-renamed
924 # version is not present.
925 echo "Checking for renamed symbols in the library"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200926 check_renamed_symbols tests/include/spe/crypto_spe.h library/libmbedcrypto.a
Gilles Peskined1dcfd52021-06-15 18:37:38 +0200927}
928
Ronald Cron336678b2021-01-28 17:54:24 +0100929component_test_psa_crypto_client () {
930 msg "build: default config - PSA_CRYPTO_C + PSA_CRYPTO_CLIENT, make"
931 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C
932 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
933 scripts/config.py set MBEDTLS_PSA_CRYPTO_CLIENT
934 make
935
936 msg "test: default config - PSA_CRYPTO_C + PSA_CRYPTO_CLIENT, make"
937 make test
938}
939
Jaeden Amero424fa932021-05-14 08:34:32 +0100940component_test_psa_crypto_rsa_no_genprime() {
941 msg "build: default config minus MBEDTLS_GENPRIME"
942 scripts/config.py unset MBEDTLS_GENPRIME
943 make
944
945 msg "test: default config minus MBEDTLS_GENPRIME"
946 make test
947}
948
Gilles Peskine782f4112018-11-27 16:11:09 +0100949component_test_ref_configs () {
950 msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
951 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200952 tests/scripts/test-ref-configs.pl
Gilles Peskine782f4112018-11-27 16:11:09 +0100953}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200954
Gilles Peskine8f073122018-11-27 15:58:47 +0100955component_test_no_renegotiation () {
956 msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200957 scripts/config.py unset MBEDTLS_SSL_RENEGOTIATION
Gilles Peskine8f073122018-11-27 15:58:47 +0100958 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
959 make
Simon Butcher3ea7f522016-03-07 23:22:10 +0000960
Gilles Peskine8f073122018-11-27 15:58:47 +0100961 msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
962 make test
Hanno Becker134c2ab2017-10-12 15:29:50 +0100963
Gilles Peskine8f073122018-11-27 15:58:47 +0100964 msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200965 tests/ssl-opt.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100966}
Hanno Becker134c2ab2017-10-12 15:29:50 +0100967
Gilles Peskine636c26a2020-03-04 20:46:15 +0100968component_test_no_pem_no_fs () {
969 msg "build: Default + !MBEDTLS_PEM_PARSE_C + !MBEDTLS_FS_IO (ASan build)"
970 scripts/config.py unset MBEDTLS_PEM_PARSE_C
971 scripts/config.py unset MBEDTLS_FS_IO
972 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C # requires a filesystem
973 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA ITS
974 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
975 make
976
977 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - main suites (inc. selftests) (ASan build)" # ~ 50s
978 make test
979
980 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - ssl-opt.sh (ASan build)" # ~ 6 min
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200981 tests/ssl-opt.sh
Gilles Peskine636c26a2020-03-04 20:46:15 +0100982}
983
Gilles Peskine8f073122018-11-27 15:58:47 +0100984component_test_rsa_no_crt () {
985 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200986 scripts/config.py set MBEDTLS_RSA_NO_CRT
Gilles Peskine8f073122018-11-27 15:58:47 +0100987 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
988 make
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +0100989
Gilles Peskine8f073122018-11-27 15:58:47 +0100990 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
991 make test
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100992
Gilles Peskine8f073122018-11-27 15:58:47 +0100993 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200994 tests/ssl-opt.sh -f RSA
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100995
Gilles Peskine8f073122018-11-27 15:58:47 +0100996 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200997 tests/compat.sh -t RSA
Piotr Nowicki9978e6e2020-04-07 16:07:05 +0200998
999 msg "test: RSA_NO_CRT - RSA-related part of context-info.sh (ASan build)" # ~ 15 sec
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001000 tests/context-info.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01001001}
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +01001002
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001003component_test_no_ctr_drbg_classic () {
1004 msg "build: Full minus CTR_DRBG, classic crypto in TLS"
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +02001005 scripts/config.py full
1006 scripts/config.py unset MBEDTLS_CTR_DRBG_C
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001007 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +02001008
1009 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1010 make
1011
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001012 msg "test: Full minus CTR_DRBG, classic crypto - main suites"
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +02001013 make test
1014
Gilles Peskineba749042021-01-13 20:02:03 +01001015 # In this configuration, the TLS test programs use HMAC_DRBG.
1016 # The SSL tests are slow, so run a small subset, just enough to get
1017 # confidence that the SSL code copes with HMAC_DRBG.
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001018 msg "test: Full minus CTR_DRBG, classic crypto - ssl-opt.sh (subset)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001019 tests/ssl-opt.sh -f 'Default\|SSL async private.*delay=\|tickets enabled on server'
Gilles Peskineba749042021-01-13 20:02:03 +01001020
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001021 msg "test: Full minus CTR_DRBG, classic crypto - compat.sh (subset)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001022 tests/compat.sh -m tls1_2 -t 'ECDSA PSK' -V NO -p OpenSSL
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +02001023}
1024
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001025component_test_no_ctr_drbg_use_psa () {
1026 msg "build: Full minus CTR_DRBG, PSA crypto in TLS"
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +02001027 scripts/config.py full
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001028 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1029 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +02001030
1031 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1032 make
1033
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001034 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - main suites"
1035 make test
1036
1037 # In this configuration, the TLS test programs use HMAC_DRBG.
1038 # The SSL tests are slow, so run a small subset, just enough to get
1039 # confidence that the SSL code copes with HMAC_DRBG.
1040 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - ssl-opt.sh (subset)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001041 tests/ssl-opt.sh -f 'Default\|SSL async private.*delay=\|tickets enabled on server'
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001042
1043 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - compat.sh (subset)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001044 tests/compat.sh -m tls1_2 -t 'ECDSA PSK' -V NO -p OpenSSL
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001045}
1046
1047component_test_no_hmac_drbg_classic () {
1048 msg "build: Full minus HMAC_DRBG, classic crypto in TLS"
1049 scripts/config.py full
1050 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1051 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1052 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1053
1054 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1055 make
1056
1057 msg "test: Full minus HMAC_DRBG, classic crypto - main suites"
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +02001058 make test
1059
Gilles Peskinea2224342020-11-19 22:14:34 +01001060 # Normally our ECDSA implementation uses deterministic ECDSA. But since
1061 # HMAC_DRBG is disabled in this configuration, randomized ECDSA is used
1062 # instead.
1063 # Test SSL with non-deterministic ECDSA. Only test features that
1064 # might be affected by how ECDSA signature is performed.
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001065 msg "test: Full minus HMAC_DRBG, classic crypto - ssl-opt.sh (subset)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001066 tests/ssl-opt.sh -f 'Default\|SSL async private: sign'
Gilles Peskinea2224342020-11-19 22:14:34 +01001067
1068 # To save time, only test one protocol version, since this part of
1069 # the protocol is identical in (D)TLS up to 1.2.
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001070 msg "test: Full minus HMAC_DRBG, classic crypto - compat.sh (ECDSA)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001071 tests/compat.sh -m tls1_2 -t 'ECDSA'
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +02001072}
1073
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001074component_test_no_hmac_drbg_use_psa () {
1075 msg "build: Full minus HMAC_DRBG, PSA crypto in TLS"
1076 scripts/config.py full
1077 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1078 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1079 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1080
1081 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1082 make
1083
1084 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - main suites"
1085 make test
1086
1087 # Normally our ECDSA implementation uses deterministic ECDSA. But since
1088 # HMAC_DRBG is disabled in this configuration, randomized ECDSA is used
1089 # instead.
1090 # Test SSL with non-deterministic ECDSA. Only test features that
1091 # might be affected by how ECDSA signature is performed.
1092 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - ssl-opt.sh (subset)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001093 tests/ssl-opt.sh -f 'Default\|SSL async private: sign'
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001094
1095 # To save time, only test one protocol version, since this part of
1096 # the protocol is identical in (D)TLS up to 1.2.
1097 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - compat.sh (ECDSA)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001098 tests/compat.sh -m tls1_2 -t 'ECDSA'
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001099}
1100
1101component_test_psa_external_rng_no_drbg_classic () {
1102 msg "build: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto in TLS"
1103 scripts/config.py full
1104 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1105 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
Gilles Peskine38c12fd2021-02-08 21:02:53 +01001106 scripts/config.py unset MBEDTLS_ENTROPY_C
1107 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
1108 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001109 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1110 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1111 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
Gilles Peskine8eb29432021-02-03 20:07:11 +01001112 # When MBEDTLS_USE_PSA_CRYPTO is disabled and there is no DRBG,
1113 # the SSL test programs don't have an RNG and can't work. Explicitly
1114 # make them use the PSA RNG with -DMBEDTLS_TEST_USE_PSA_CRYPTO_RNG.
1115 make CFLAGS="$ASAN_CFLAGS -O2 -DMBEDTLS_TEST_USE_PSA_CRYPTO_RNG" LDFLAGS="$ASAN_CFLAGS"
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001116
1117 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto - main suites"
1118 make test
1119
Gilles Peskine8eb29432021-02-03 20:07:11 +01001120 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto - ssl-opt.sh (subset)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001121 tests/ssl-opt.sh -f 'Default'
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001122}
1123
1124component_test_psa_external_rng_no_drbg_use_psa () {
1125 msg "build: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto in TLS"
Gilles Peskinec109b372020-11-23 17:39:04 +01001126 scripts/config.py full
1127 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
Gilles Peskine38c12fd2021-02-08 21:02:53 +01001128 scripts/config.py unset MBEDTLS_ENTROPY_C
1129 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
1130 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskinec109b372020-11-23 17:39:04 +01001131 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1132 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1133 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
Gilles Peskinec109b372020-11-23 17:39:04 +01001134 make CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
1135
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001136 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto - main suites"
Gilles Peskinec109b372020-11-23 17:39:04 +01001137 make test
1138
Gilles Peskine8eb29432021-02-03 20:07:11 +01001139 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto - ssl-opt.sh (subset)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001140 tests/ssl-opt.sh -f 'Default\|opaque'
Gilles Peskinec109b372020-11-23 17:39:04 +01001141}
1142
1143component_test_psa_external_rng_use_psa_crypto () {
1144 msg "build: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
1145 scripts/config.py full
1146 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
1147 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1148 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1149 make CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
1150
1151 msg "test: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
1152 make test
1153
Gilles Peskineba749042021-01-13 20:02:03 +01001154 msg "test: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001155 tests/ssl-opt.sh -f 'Default\|opaque'
Gilles Peskinec109b372020-11-23 17:39:04 +01001156}
1157
Gilles Peskine636c26a2020-03-04 20:46:15 +01001158component_test_everest () {
1159 msg "build: Everest ECDH context (ASan build)" # ~ 6 min
Gilles Peskine636c26a2020-03-04 20:46:15 +01001160 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
1161 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Asan .
1162 make
1163
1164 msg "test: Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
1165 make test
1166
1167 msg "test: Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001168 tests/ssl-opt.sh -f ECDH
Gilles Peskine636c26a2020-03-04 20:46:15 +01001169
1170 msg "test: Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
1171 # Exclude some symmetric ciphers that are redundant here to gain time.
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001172 tests/compat.sh -f ECDH -V NO -e 'ARIA\|CAMELLIA\|CHACHA\|DES'
Gilles Peskine636c26a2020-03-04 20:46:15 +01001173}
1174
Gilles Peskined3beca92020-07-03 00:15:37 +02001175component_test_everest_curve25519_only () {
1176 msg "build: Everest ECDH context, only Curve25519" # ~ 6 min
Gilles Peskined3beca92020-07-03 00:15:37 +02001177 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
1178 scripts/config.py unset MBEDTLS_ECDSA_C
1179 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
1180 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
TRodziewicz7c1d41d2021-04-23 13:33:44 +02001181 scripts/config.py unset MBEDTLS_ECJPAKE_C
Gilles Peskined3beca92020-07-03 00:15:37 +02001182 # Disable all curves
1183 for c in $(sed -n 's/#define \(MBEDTLS_ECP_DP_[0-9A-Z_a-z]*_ENABLED\).*/\1/p' <"$CONFIG_H"); do
1184 scripts/config.py unset "$c"
1185 done
1186 scripts/config.py set MBEDTLS_ECP_DP_CURVE25519_ENABLED
1187
1188 make CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
1189
1190 msg "test: Everest ECDH context, only Curve25519" # ~ 50s
1191 make test
1192}
1193
Gilles Peskine8f073122018-11-27 15:58:47 +01001194component_test_small_ssl_out_content_len () {
1195 msg "build: small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001196 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 16384
1197 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
Gilles Peskine8f073122018-11-27 15:58:47 +01001198 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1199 make
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +01001200
Gilles Peskine8f073122018-11-27 15:58:47 +01001201 msg "test: small SSL_OUT_CONTENT_LEN - ssl-opt.sh MFL and large packet tests"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001202 tests/ssl-opt.sh -f "Max fragment\|Large packet"
Gilles Peskine8f073122018-11-27 15:58:47 +01001203}
Angus Grattonc4dd0732018-04-11 16:28:39 +10001204
Gilles Peskine8f073122018-11-27 15:58:47 +01001205component_test_small_ssl_in_content_len () {
1206 msg "build: small SSL_IN_CONTENT_LEN (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001207 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 4096
1208 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 16384
Gilles Peskine8f073122018-11-27 15:58:47 +01001209 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1210 make
Angus Grattonc4dd0732018-04-11 16:28:39 +10001211
Gilles Peskine8f073122018-11-27 15:58:47 +01001212 msg "test: small SSL_IN_CONTENT_LEN - ssl-opt.sh MFL tests"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001213 tests/ssl-opt.sh -f "Max fragment"
Gilles Peskine8f073122018-11-27 15:58:47 +01001214}
Angus Grattonc4dd0732018-04-11 16:28:39 +10001215
Gilles Peskine8f073122018-11-27 15:58:47 +01001216component_test_small_ssl_dtls_max_buffering () {
1217 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001218 scripts/config.py set MBEDTLS_SSL_DTLS_MAX_BUFFERING 1000
Gilles Peskine8f073122018-11-27 15:58:47 +01001219 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1220 make
Angus Grattonc4dd0732018-04-11 16:28:39 +10001221
Gilles Peskine8f073122018-11-27 15:58:47 +01001222 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0 - ssl-opt.sh specific reordering test"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001223 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 +01001224}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001225
Gilles Peskine8f073122018-11-27 15:58:47 +01001226component_test_small_mbedtls_ssl_dtls_max_buffering () {
1227 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1"
Gilles Peskine636c26a2020-03-04 20:46:15 +01001228 scripts/config.py set MBEDTLS_SSL_DTLS_MAX_BUFFERING 190
Gilles Peskine8f073122018-11-27 15:58:47 +01001229 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1230 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001231
Gilles Peskine8f073122018-11-27 15:58:47 +01001232 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1 - ssl-opt.sh specific reordering test"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001233 tests/ssl-opt.sh -f "DTLS reordering: Buffer encrypted Finished message, drop for fragmented NewSessionTicket"
Gilles Peskine8f073122018-11-27 15:58:47 +01001234}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001235
Gilles Peskine75cc7712019-09-06 19:47:17 +02001236component_test_psa_collect_statuses () {
1237 msg "build+test: psa_collect_statuses" # ~30s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001238 scripts/config.py full
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001239 tests/scripts/psa_collect_statuses.py
Gilles Peskine75cc7712019-09-06 19:47:17 +02001240 # Check that psa_crypto_init() succeeded at least once
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001241 grep -q '^0:psa_crypto_init:' tests/statuses.log
Gilles Peskine75cc7712019-09-06 19:47:17 +02001242 rm -f tests/statuses.log
1243}
1244
Gilles Peskine8f073122018-11-27 15:58:47 +01001245component_test_full_cmake_clang () {
1246 msg "build: cmake, full config, clang" # ~ 50s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001247 scripts/config.py full
Gilles Peskine8f073122018-11-27 15:58:47 +01001248 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check -D ENABLE_TESTING=On .
1249 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001250
k-stachowiak0291cb72019-06-26 15:52:12 +02001251 msg "test: main suites (full config, clang)" # ~ 5s
Gilles Peskine8f073122018-11-27 15:58:47 +01001252 make test
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +01001253
k-stachowiak0291cb72019-06-26 15:52:12 +02001254 msg "test: psa_constant_names (full config, clang)" # ~ 1s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001255 tests/scripts/test_psa_constant_names.py
Gilles Peskine69e8f7f2020-02-26 19:51:43 +01001256
Gilles Peskine8f073122018-11-27 15:58:47 +01001257 msg "test: ssl-opt.sh default, ECJPAKE, SSL async (full config)" # ~ 1s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001258 tests/ssl-opt.sh -f 'Default\|ECJPAKE\|SSL async private'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +02001259
TRodziewicz10e8cf52021-05-31 17:58:57 +02001260 msg "test: compat.sh DES, 3DES & NULL (full config)" # ~ 2 min
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001261 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 +02001262
Gilles Peskine8f073122018-11-27 15:58:47 +01001263 msg "test: compat.sh ARIA + ChachaPoly"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001264 env OPENSSL_CMD="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
Gilles Peskine8f073122018-11-27 15:58:47 +01001265}
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +02001266
Manuel Pégourié-Gonnard6240def2020-07-10 09:35:54 +02001267component_test_memsan_constant_flow () {
Manuel Pégourié-Gonnard0b2112d2020-07-22 11:09:28 +02001268 # This tests both (1) accesses to undefined memory, and (2) branches or
1269 # memory access depending on secret values. To distinguish between those:
1270 # - unset MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN - does the failure persist?
1271 # - or alternatively, change the build type to MemSanDbg, which enables
1272 # origin tracking and nicer stack traces (which are useful for debugging
1273 # anyway), and check if the origin was TEST_CF_SECRET() or something else.
1274 msg "build: cmake MSan (clang), full config with constant flow testing"
Manuel Pégourié-Gonnard6240def2020-07-10 09:35:54 +02001275 scripts/config.py full
1276 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN
1277 scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm
1278 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
1279 make
1280
Manuel Pégourié-Gonnard0b2112d2020-07-22 11:09:28 +02001281 msg "test: main suites (Msan + constant flow)"
Manuel Pégourié-Gonnard6240def2020-07-10 09:35:54 +02001282 make test
1283}
1284
Manuel Pégourié-Gonnard73afa372020-08-19 10:27:38 +02001285component_test_valgrind_constant_flow () {
1286 # This tests both (1) everything that valgrind's memcheck usually checks
1287 # (heap buffer overflows, use of uninitialized memory, use-after-free,
1288 # etc.) and (2) branches or memory access depending on secret values,
1289 # which will be reported as uninitialized memory. To distinguish between
1290 # secret and actually uninitialized:
1291 # - unset MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND - does the failure persist?
1292 # - or alternatively, build with debug info and manually run the offending
1293 # test suite with valgrind --track-origins=yes, then check if the origin
1294 # was TEST_CF_SECRET() or something else.
1295 msg "build: cmake release GCC, full config with constant flow testing"
1296 scripts/config.py full
1297 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND
1298 cmake -D CMAKE_BUILD_TYPE:String=Release .
1299 make
1300
1301 # this only shows a summary of the results (how many of each type)
1302 # details are left in Testing/<date>/DynamicAnalysis.xml
1303 msg "test: main suites (valgrind + constant flow)"
1304 make memcheck
1305}
1306
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001307component_test_default_no_deprecated () {
Gilles Peskine8386ea22020-04-30 09:07:29 +02001308 # Test that removing the deprecated features from the default
1309 # configuration leaves something consistent.
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001310 msg "build: make, default + MBEDTLS_DEPRECATED_REMOVED" # ~ 30s
1311 scripts/config.py set MBEDTLS_DEPRECATED_REMOVED
1312 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra'
1313
1314 msg "test: make, default + MBEDTLS_DEPRECATED_REMOVED" # ~ 5s
1315 make test
1316}
1317
1318component_test_full_no_deprecated () {
Gilles Peskine30de2e82020-04-20 21:39:22 +02001319 msg "build: make, full_no_deprecated config" # ~ 30s
1320 scripts/config.py full_no_deprecated
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001321 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra'
1322
Gilles Peskine30de2e82020-04-20 21:39:22 +02001323 msg "test: make, full_no_deprecated config" # ~ 5s
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001324 make test
1325}
1326
Gilles Peskine8386ea22020-04-30 09:07:29 +02001327component_test_full_no_deprecated_deprecated_warning () {
1328 # Test that there is nothing deprecated in "full_no_deprecated".
1329 # A deprecated feature would trigger a warning (made fatal) from
1330 # MBEDTLS_DEPRECATED_WARNING.
Gilles Peskine30de2e82020-04-20 21:39:22 +02001331 msg "build: make, full_no_deprecated config, MBEDTLS_DEPRECATED_WARNING" # ~ 30s
1332 scripts/config.py full_no_deprecated
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001333 scripts/config.py unset MBEDTLS_DEPRECATED_REMOVED
1334 scripts/config.py set MBEDTLS_DEPRECATED_WARNING
1335 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra'
1336
Gilles Peskine30de2e82020-04-20 21:39:22 +02001337 msg "test: make, full_no_deprecated config, MBEDTLS_DEPRECATED_WARNING" # ~ 5s
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001338 make test
1339}
1340
Gilles Peskine8386ea22020-04-30 09:07:29 +02001341component_test_full_deprecated_warning () {
1342 # Test that when MBEDTLS_DEPRECATED_WARNING is enabled, the build passes
1343 # with only certain whitelisted types of warnings.
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001344 msg "build: make, full config + MBEDTLS_DEPRECATED_WARNING, expect warnings" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001345 scripts/config.py full
1346 scripts/config.py set MBEDTLS_DEPRECATED_WARNING
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001347 # Expect warnings from '#warning' directives in check_config.h.
1348 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-error=cpp' lib programs
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +01001349
Gilles Peskine8386ea22020-04-30 09:07:29 +02001350 msg "build: make tests, full config + MBEDTLS_DEPRECATED_WARNING, expect warnings" # ~ 30s
1351 # Set MBEDTLS_TEST_DEPRECATED to enable tests for deprecated features.
1352 # By default those are disabled when MBEDTLS_DEPRECATED_WARNING is set.
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001353 # Expect warnings from '#warning' directives in check_config.h and
1354 # from the use of deprecated functions in test suites.
1355 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 +01001356
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001357 msg "test: full config + MBEDTLS_TEST_DEPRECATED" # ~ 30s
1358 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01001359}
Jaeden Ameroed93bdc2018-11-02 16:57:24 +00001360
Gilles Peskineec541fe2020-01-31 14:24:14 +01001361# Check that the specified libraries exist and are empty.
1362are_empty_libraries () {
1363 nm "$@" >/dev/null 2>/dev/null
1364 ! nm "$@" 2>/dev/null | grep -v ':$' | grep .
1365}
1366
1367component_build_crypto_default () {
1368 msg "build: make, crypto only"
1369 scripts/config.py crypto
Gilles Peskine6bb39152020-02-03 11:59:20 +01001370 make CFLAGS='-O1 -Werror'
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001371 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
Gilles Peskineec541fe2020-01-31 14:24:14 +01001372}
1373
1374component_build_crypto_full () {
1375 msg "build: make, crypto only, full config"
1376 scripts/config.py crypto_full
Gilles Peskine6bb39152020-02-03 11:59:20 +01001377 make CFLAGS='-O1 -Werror'
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001378 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
Gilles Peskineec541fe2020-01-31 14:24:14 +01001379}
1380
1381component_build_crypto_baremetal () {
1382 msg "build: make, crypto only, baremetal config"
1383 scripts/config.py crypto_baremetal
Gilles Peskine6bb39152020-02-03 11:59:20 +01001384 make CFLAGS='-O1 -Werror'
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001385 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
Gilles Peskineec541fe2020-01-31 14:24:14 +01001386}
1387
Gilles Peskine8f073122018-11-27 15:58:47 +01001388component_test_depends_curves () {
1389 msg "test/build: curves.pl (gcc)" # ~ 4 min
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001390 tests/scripts/curves.pl
Gilles Peskine8f073122018-11-27 15:58:47 +01001391}
Jaeden Ameroacaabe72018-11-07 11:52:52 +00001392
John Durkopc14be902020-08-20 06:16:41 -07001393component_test_depends_curves_psa () {
1394 msg "test/build: curves.pl with MBEDTLS_USE_PSA_CRYPTO defined (gcc)"
1395 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001396 tests/scripts/curves.pl
John Durkopc14be902020-08-20 06:16:41 -07001397}
1398
Gilles Peskine8f073122018-11-27 15:58:47 +01001399component_test_depends_hashes () {
1400 msg "test/build: depends-hashes.pl (gcc)" # ~ 2 min
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001401 tests/scripts/depends-hashes.pl
Gilles Peskine8f073122018-11-27 15:58:47 +01001402}
Jaeden Ameroacaabe72018-11-07 11:52:52 +00001403
John Durkop2ec2eaa2020-08-24 18:29:15 -07001404component_test_depends_hashes_psa () {
1405 msg "test/build: depends-hashes.pl with MBEDTLS_USE_PSA_CRYPTO defined (gcc)"
1406 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001407 tests/scripts/depends-hashes.pl
John Durkop2ec2eaa2020-08-24 18:29:15 -07001408}
1409
Gilles Peskine8f073122018-11-27 15:58:47 +01001410component_test_depends_pkalgs () {
1411 msg "test/build: depends-pkalgs.pl (gcc)" # ~ 2 min
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001412 tests/scripts/depends-pkalgs.pl
Gilles Peskine8f073122018-11-27 15:58:47 +01001413}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01001414
John Durkop619e09e2020-09-08 22:19:56 -07001415component_test_depends_pkalgs_psa () {
1416 msg "test/build: depends-pkalgs.pl with MBEDTLS_USE_PSA_CRYPTO defined (gcc)"
1417 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001418 tests/scripts/depends-pkalgs.pl
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01001419}
1420
Gilles Peskine8f073122018-11-27 15:58:47 +01001421component_build_key_exchanges () {
1422 msg "test/build: key-exchanges (gcc)" # ~ 1 min
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001423 tests/scripts/key-exchanges.pl
Gilles Peskine8f073122018-11-27 15:58:47 +01001424}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01001425
Gilles Peskine8f073122018-11-27 15:58:47 +01001426component_build_default_make_gcc_and_cxx () {
1427 msg "build: Unix make, -Os (gcc)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +01001428 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01001429
Gilles Peskine8f073122018-11-27 15:58:47 +01001430 msg "test: verify header list in cpp_dummy_build.cpp"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001431 check_headers_in_cpp
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01001432
Gilles Peskine8f073122018-11-27 15:58:47 +01001433 msg "build: Unix make, incremental g++"
1434 make TEST_CPP=1
1435}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01001436
Gilles Peskinecc73cc52021-05-25 09:04:46 +02001437component_build_module_alt () {
1438 msg "build: MBEDTLS_XXX_ALT" # ~30s
1439 scripts/config.py full
1440 # Disable options that are incompatible with some ALT implementations.
1441 # aesni.c and padlock.c reference mbedtls_aes_context fields directly.
1442 scripts/config.py unset MBEDTLS_AESNI_C
1443 scripts/config.py unset MBEDTLS_PADLOCK_C
Gilles Peskinecc73cc52021-05-25 09:04:46 +02001444 # You can only have one threading implementation: alt or pthread, not both.
1445 scripts/config.py unset MBEDTLS_THREADING_PTHREAD
Gilles Peskine5c3f18d2021-05-31 21:21:12 +02001446 # The SpecifiedECDomain parsing code accesses mbedtls_ecp_group fields
1447 # directly and assumes the implementation works with partial groups.
1448 scripts/config.py unset MBEDTLS_PK_PARSE_EC_EXTENDED
Gilles Peskinecc73cc52021-05-25 09:04:46 +02001449 # Enable all MBEDTLS_XXX_ALT for whole modules. Do not enable
1450 # MBEDTLS_XXX_YYY_ALT which are for single functions.
1451 scripts/config.py set-all 'MBEDTLS_([A-Z0-9]*|NIST_KW)_ALT'
Gilles Peskine1628a9c2021-05-31 22:09:58 +02001452 scripts/config.py unset MBEDTLS_DHM_ALT #incompatible with MBEDTLS_DEBUG_C
1453 # We can only compile, not link, since we don't have any implementations
1454 # suitable for testing with the dummy alt headers.
1455 make CC=gcc CFLAGS='-Werror -Wall -Wextra -I../tests/include/alt-dummy' lib
1456}
1457
1458component_build_dhm_alt () {
1459 msg "build: MBEDTLS_DHM_ALT" # ~30s
1460 scripts/config.py full
1461 scripts/config.py set MBEDTLS_DHM_ALT
1462 # debug.c currently references mbedtls_dhm_context fields directly.
1463 scripts/config.py unset MBEDTLS_DEBUG_C
Gilles Peskinecc73cc52021-05-25 09:04:46 +02001464 # We can only compile, not link, since we don't have any implementations
1465 # suitable for testing with the dummy alt headers.
1466 make CC=gcc CFLAGS='-Werror -Wall -Wextra -I../tests/include/alt-dummy' lib
1467}
1468
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001469component_test_no_use_psa_crypto_full_cmake_asan() {
1470 # full minus MBEDTLS_USE_PSA_CRYPTO: run the same set of tests as basic-build-test.sh
Gilles Peskinedc3a1792019-09-03 11:42:04 +02001471 msg "build: cmake, full config minus MBEDTLS_USE_PSA_CRYPTO, ASan"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001472 scripts/config.py full
1473 scripts/config.py set MBEDTLS_ECP_RESTARTABLE # not using PSA, so enable restartable ECC
1474 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C
1475 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1476 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C
Gilles Peskinedc6d8382020-04-12 14:21:55 +02001477 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001478 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
Manuel Pégourié-Gonnardd8167e82019-02-01 11:12:52 +01001479 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Andrzej Kurekde5a0072019-02-01 07:03:03 -05001480 make
Manuel Pégourié-Gonnard43be6cd2017-06-20 09:53:42 +02001481
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001482 msg "test: main suites (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -05001483 make test
Manuel Pégourié-Gonnard503a5ef2015-10-23 09:04:45 +02001484
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001485 msg "test: ssl-opt.sh (full minus MBEDTLS_USE_PSA_CRYPTO)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001486 tests/ssl-opt.sh
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001487
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001488 msg "test: compat.sh default (full minus MBEDTLS_USE_PSA_CRYPTO)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001489 tests/compat.sh
Andrzej Kurek991f9fe2018-07-02 09:08:21 -04001490
TRodziewicz10e8cf52021-05-31 17:58:57 +02001491 msg "test: compat.sh DES & NULL (full minus MBEDTLS_USE_PSA_CRYPTO)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001492 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 -05001493
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001494 msg "test: compat.sh ARIA + ChachaPoly (full minus MBEDTLS_USE_PSA_CRYPTO)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001495 env OPENSSL_CMD="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
Andrzej Kurekde5a0072019-02-01 07:03:03 -05001496}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -05001497
John Durkopd8959392020-09-20 23:09:17 -07001498component_test_psa_crypto_config_basic() {
Ronald Cron067de3b2021-03-11 11:49:03 +01001499 # Test the library excluding all Mbed TLS cryptographic support for which
1500 # we have an accelerator support. Acceleration is faked with the
1501 # transparent test driver.
1502 msg "test: full + MBEDTLS_PSA_CRYPTO_CONFIG + as much acceleration as supported"
John Durkopd8959392020-09-20 23:09:17 -07001503 scripts/config.py full
1504 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1505 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1506 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cron067de3b2021-03-11 11:49:03 +01001507
1508 # There is no intended accelerator support for ALG STREAM_CIPHER and
1509 # ALG_ECB_NO_PADDING. Therefore, asking for them in the build implies the
1510 # inclusion of the Mbed TLS cipher operations. As we want to test here with
1511 # cipher operations solely supported by accelerators, disabled those
1512 # PSA configuration options.
1513 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_STREAM_CIPHER
1514 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_ECB_NO_PADDING
1515
1516 # Don't test DES encryption as:
1517 # 1) It is not an issue if we don't test all cipher types here.
1518 # 2) That way we don't have to modify in psa_crypto.c the compilation
1519 # guards MBEDTLS_PSA_BUILTIN_KEY_TYPE_DES for the code they guard to be
1520 # available to the test driver. Modifications that we would need to
1521 # revert when we move to compile the test driver separately.
1522 # We also disable MBEDTLS_DES_C as the dependencies on DES in PSA test
1523 # suites are still based on MBEDTLS_DES_C and not PSA_WANT_KEY_TYPE_DES.
1524 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_KEY_TYPE_DES
1525 scripts/config.py unset MBEDTLS_DES_C
1526
John Durkopd8959392020-09-20 23:09:17 -07001527 # 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 +01001528 loc_cflags="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST"
Ronald Cron067de3b2021-03-11 11:49:03 +01001529 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_KEY_TYPE_AES"
1530 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_KEY_TYPE_CAMELLIA"
Ronald Cron17b3afc2020-12-10 18:17:09 +01001531 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_KEY_PAIR"
Ronald Cron067de3b2021-03-11 11:49:03 +01001532 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_KEY_PAIR"
1533 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_CBC_NO_PADDING"
1534 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_CBC_PKCS7"
1535 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_CTR"
1536 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_CFB"
Ronald Cron17b3afc2020-12-10 18:17:09 +01001537 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_ECDSA"
1538 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_DETERMINISTIC_ECDSA"
Steven Cooremand50db942021-03-08 17:17:15 +01001539 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_MD5"
Ronald Cron067de3b2021-03-11 11:49:03 +01001540 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_OFB"
Steven Cooremand50db942021-03-08 17:17:15 +01001541 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_RIPEMD160"
Ronald Cron067de3b2021-03-11 11:49:03 +01001542 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_SIGN"
1543 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_RSA_PSS"
Steven Cooremand50db942021-03-08 17:17:15 +01001544 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_SHA_1"
1545 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_SHA_224"
1546 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_SHA_256"
1547 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_SHA_384"
1548 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_SHA_512"
Ronald Cron067de3b2021-03-11 11:49:03 +01001549 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_XTS"
Steven Cooreman7515e752021-03-19 19:36:38 +01001550 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_CMAC"
1551 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_HMAC"
Ronald Cron17b3afc2020-12-10 18:17:09 +01001552 loc_cflags="${loc_cflags} -I../tests/include -O2"
1553
1554 make CC=gcc CFLAGS="$loc_cflags" LDFLAGS="$ASAN_CFLAGS"
1555 unset loc_cflags
John Durkopd8959392020-09-20 23:09:17 -07001556
John Durkop4377bf72020-10-23 01:26:57 -07001557 msg "test: full + MBEDTLS_PSA_CRYPTO_CONFIG"
1558 make test
1559}
1560
1561component_test_psa_crypto_config_no_driver() {
1562 # full plus MBEDTLS_PSA_CRYPTO_CONFIG
1563 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG minus MBEDTLS_PSA_CRYPTO_DRIVERS"
1564 scripts/config.py full
1565 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1566 scripts/config.py unset MBEDTLS_PSA_CRYPTO_DRIVERS
1567 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
John Durkope7012c72020-10-26 09:55:01 -07001568 make CC=gcc CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
John Durkop4377bf72020-10-23 01:26:57 -07001569
1570 msg "test: full + MBEDTLS_PSA_CRYPTO_CONFIG minus MBEDTLS_PSA_CRYPTO_DRIVERS"
John Durkopd8959392020-09-20 23:09:17 -07001571 make test
1572}
1573
John Durkop8ac0b802020-10-23 01:32:15 -07001574# 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 -08001575component_build_psa_accel_alg_ecdsa() {
John Durkopdd544e12020-10-12 21:47:19 -07001576 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_ECDSA
1577 # without MBEDTLS_ECDSA_C
John Durkop28baa1f2020-10-23 00:51:52 -07001578 # PSA_WANT_ALG_ECDSA and PSA_WANT_ALG_DETERMINISTIC_ECDSA are already
1579 # set in include/psa/crypto_config.h
John Durkopdd544e12020-10-12 21:47:19 -07001580 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_ECDSA without MBEDTLS_ECDSA_C"
John Durkopd8959392020-09-20 23:09:17 -07001581 scripts/config.py full
1582 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1583 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1584 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1585 scripts/config.py unset MBEDTLS_ECDSA_C
John Durkop28baa1f2020-10-23 00:51:52 -07001586 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
1587 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
John Durkopd8959392020-09-20 23:09:17 -07001588 # 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 -07001589 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 -07001590}
1591
John Durkopd0321952020-10-29 21:37:36 -07001592# 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 -08001593component_build_psa_accel_alg_ecdh() {
John Durkopd0321952020-10-29 21:37:36 -07001594 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_ECDH
1595 # without MBEDTLS_ECDH_C
1596 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_ECDH without MBEDTLS_ECDH_C"
1597 scripts/config.py full
1598 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1599 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1600 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1601 scripts/config.py unset MBEDTLS_ECDH_C
1602 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
1603 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
1604 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
1605 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
1606 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
1607 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1608 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_ECDH -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
1609}
1610
John Durkopf4c4cb02020-10-28 20:09:55 -07001611# 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 -08001612component_build_psa_accel_key_type_ecc_key_pair() {
John Durkop9814fa22020-11-04 12:28:15 -08001613 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_KEY_TYPE_ECC_KEY_PAIR
1614 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_KEY_TYPE_ECC_KEY_PAIR"
John Durkopf4c4cb02020-10-28 20:09:55 -07001615 scripts/config.py full
1616 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1617 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1618 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
John Durkop9814fa22020-11-04 12:28:15 -08001619 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 -08001620 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 -07001621 # 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 -08001622 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 -07001623}
1624
1625# 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 -08001626component_build_psa_accel_key_type_ecc_public_key() {
John Durkop9814fa22020-11-04 12:28:15 -08001627 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY
1628 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY"
John Durkopf4c4cb02020-10-28 20:09:55 -07001629 scripts/config.py full
1630 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1631 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1632 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
John Durkop9814fa22020-11-04 12:28:15 -08001633 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY 1
1634 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR
John Durkopf4c4cb02020-10-28 20:09:55 -07001635 # 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 -08001636 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 -07001637}
1638
John Durkopd0321952020-10-29 21:37:36 -07001639# 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 -08001640component_build_psa_accel_alg_hmac() {
John Durkopd0321952020-10-29 21:37:36 -07001641 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_HMAC
1642 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_HMAC"
1643 scripts/config.py full
1644 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1645 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1646 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1647 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1648 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_HMAC -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
1649}
1650
1651# 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 -08001652component_build_psa_accel_alg_hkdf() {
John Durkopd0321952020-10-29 21:37:36 -07001653 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_HKDF
1654 # without MBEDTLS_HKDF_C
1655 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_HKDF without MBEDTLS_HKDF_C"
1656 scripts/config.py full
1657 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1658 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1659 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1660 scripts/config.py unset MBEDTLS_HKDF_C
John Durkopbd069d32020-10-31 22:14:03 -07001661 # Make sure to unset TLS1_3_EXPERIMENTAL since it requires HKDF_C and will not build properly without it.
1662 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL
John Durkopd0321952020-10-29 21:37:36 -07001663 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1664 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_HKDF -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
1665}
1666
John Durkop1b7ee052020-11-27 08:51:22 -08001667# This should be renamed to test and updated once the accelerator MD5 code is in place and ready to test.
1668component_build_psa_accel_alg_md5() {
1669 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_MD5 without other hashes
1670 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_MD5 - other hashes"
1671 scripts/config.py full
1672 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1673 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1674 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
John Durkop1b7ee052020-11-27 08:51:22 -08001675 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
1676 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
1677 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
1678 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
1679 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
1680 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
1681 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1682 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_MD5 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
1683}
1684
1685# This should be renamed to test and updated once the accelerator RIPEMD160 code is in place and ready to test.
1686component_build_psa_accel_alg_ripemd160() {
1687 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_RIPEMD160 without other hashes
1688 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_RIPEMD160 - other hashes"
1689 scripts/config.py full
1690 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1691 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1692 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
John Durkop1b7ee052020-11-27 08:51:22 -08001693 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
1694 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
1695 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
1696 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
1697 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
1698 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
1699 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1700 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RIPEMD160 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
1701}
1702
1703# This should be renamed to test and updated once the accelerator SHA1 code is in place and ready to test.
1704component_build_psa_accel_alg_sha1() {
1705 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_SHA_1 without other hashes
1706 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_SHA_1 - other hashes"
1707 scripts/config.py full
1708 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1709 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1710 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
John Durkop1b7ee052020-11-27 08:51:22 -08001711 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
1712 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
1713 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
1714 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
1715 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
1716 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
1717 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1718 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_1 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
1719}
1720
1721# This should be renamed to test and updated once the accelerator SHA224 code is in place and ready to test.
1722component_build_psa_accel_alg_sha224() {
1723 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_SHA_224 without other hashes
1724 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_SHA_224 - other hashes"
1725 scripts/config.py full
1726 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1727 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1728 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
John Durkop1b7ee052020-11-27 08:51:22 -08001729 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
1730 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
1731 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
1732 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
1733 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
1734 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1735 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_224 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
1736}
1737
1738# This should be renamed to test and updated once the accelerator SHA256 code is in place and ready to test.
1739component_build_psa_accel_alg_sha256() {
1740 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_SHA_256 without other hashes
1741 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_SHA_256 - other hashes"
1742 scripts/config.py full
1743 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1744 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1745 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
John Durkop1b7ee052020-11-27 08:51:22 -08001746 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
1747 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
1748 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
1749 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
1750 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
1751 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
1752 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1753 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_256 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
1754}
1755
1756# This should be renamed to test and updated once the accelerator SHA384 code is in place and ready to test.
1757component_build_psa_accel_alg_sha384() {
1758 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_SHA_384 without other hashes
1759 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_SHA_384 - other hashes"
1760 scripts/config.py full
1761 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1762 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1763 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
John Durkop1b7ee052020-11-27 08:51:22 -08001764 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
1765 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
1766 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
1767 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
1768 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
1769 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1770 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_384 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
1771}
1772
1773# This should be renamed to test and updated once the accelerator SHA512 code is in place and ready to test.
1774component_build_psa_accel_alg_sha512() {
1775 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_SHA_512 without other hashes
1776 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_SHA_512 - other hashes"
1777 scripts/config.py full
1778 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1779 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1780 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
John Durkop1b7ee052020-11-27 08:51:22 -08001781 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
1782 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
1783 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
1784 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
1785 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
1786 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
1787 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1788 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_512 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
1789}
1790
John Durkopd0321952020-10-29 21:37:36 -07001791# 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 -08001792component_build_psa_accel_alg_rsa_pkcs1v15_crypt() {
John Durkopbd069d32020-10-31 22:14:03 -07001793 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
1794 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 -07001795 scripts/config.py full
1796 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1797 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1798 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
John Durkopbd069d32020-10-31 22:14:03 -07001799 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_PKCS1V15_CRYPT 1
John Durkop7fc75ea2020-11-03 19:05:36 -08001800 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN
1801 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_OAEP
1802 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PSS
John Durkopd0321952020-10-29 21:37:36 -07001803 # 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 -07001804 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_CRYPT -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
1805}
1806
1807# 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 -08001808component_build_psa_accel_alg_rsa_pkcs1v15_sign() {
John Durkopbd069d32020-10-31 22:14:03 -07001809 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_RSA_PKCS1V15_SIGN and PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY
1810 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_RSA_PKCS1V15_SIGN + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY"
1811 scripts/config.py full
1812 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1813 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1814 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1815 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_PKCS1V15_SIGN 1
John Durkop7fc75ea2020-11-03 19:05:36 -08001816 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
1817 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_OAEP
1818 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PSS
John Durkopbd069d32020-10-31 22:14:03 -07001819 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1820 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_SIGN -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
1821}
1822
1823# 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 -08001824component_build_psa_accel_alg_rsa_oaep() {
John Durkopbd069d32020-10-31 22:14:03 -07001825 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_RSA_OAEP and PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY
1826 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_RSA_OAEP + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY"
1827 scripts/config.py full
1828 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1829 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1830 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1831 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_OAEP 1
John Durkop7fc75ea2020-11-03 19:05:36 -08001832 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
1833 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN
1834 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PSS
John Durkopbd069d32020-10-31 22:14:03 -07001835 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1836 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_OAEP -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
1837}
1838
1839# 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 -08001840component_build_psa_accel_alg_rsa_pss() {
John Durkopbd069d32020-10-31 22:14:03 -07001841 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_RSA_PSS and PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY
1842 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_RSA_PSS + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY"
1843 scripts/config.py full
1844 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1845 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1846 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1847 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_PSS 1
John Durkop7fc75ea2020-11-03 19:05:36 -08001848 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
1849 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN
1850 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_OAEP
John Durkopbd069d32020-10-31 22:14:03 -07001851 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1852 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_PSS -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
1853}
1854
1855# 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 -08001856component_build_psa_accel_key_type_rsa_key_pair() {
John Durkopbd069d32020-10-31 22:14:03 -07001857 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_KEY_TYPE_RSA_KEY_PAIR and PSA_WANT_ALG_RSA_PSS
1858 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_KEY_TYPE_RSA_KEY_PAIR + PSA_WANT_ALG_RSA_PSS"
1859 scripts/config.py full
1860 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1861 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1862 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1863 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_PSS 1
1864 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_KEY_TYPE_RSA_KEY_PAIR 1
1865 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1866 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"
1867}
1868
1869# 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 -08001870component_build_psa_accel_key_type_rsa_public_key() {
John Durkopbd069d32020-10-31 22:14:03 -07001871 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY and PSA_WANT_ALG_RSA_PSS
1872 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY + PSA_WANT_ALG_RSA_PSS"
1873 scripts/config.py full
1874 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1875 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1876 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1877 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_PSS 1
1878 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY 1
1879 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1880 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 -07001881}
1882
Gilles Peskine8f073122018-11-27 15:58:47 +01001883component_test_no_platform () {
1884 # Full configuration build, without platform support, file IO and net sockets.
1885 # This should catch missing mbedtls_printf definitions, and by disabling file
1886 # IO, it should catch missing '#include <stdio.h>'
1887 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001888 scripts/config.py full
1889 scripts/config.py unset MBEDTLS_PLATFORM_C
1890 scripts/config.py unset MBEDTLS_NET_C
1891 scripts/config.py unset MBEDTLS_PLATFORM_MEMORY
1892 scripts/config.py unset MBEDTLS_PLATFORM_PRINTF_ALT
1893 scripts/config.py unset MBEDTLS_PLATFORM_FPRINTF_ALT
1894 scripts/config.py unset MBEDTLS_PLATFORM_SNPRINTF_ALT
1895 scripts/config.py unset MBEDTLS_PLATFORM_TIME_ALT
1896 scripts/config.py unset MBEDTLS_PLATFORM_EXIT_ALT
Gilles Peskine32e889d2020-04-12 23:43:28 +02001897 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001898 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
1899 scripts/config.py unset MBEDTLS_FS_IO
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001900 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001901 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
1902 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C
Gilles Peskine8f073122018-11-27 15:58:47 +01001903 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
1904 # to re-enable platform integration features otherwise disabled in C99 builds
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02001905 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -Os -D_DEFAULT_SOURCE' lib programs
1906 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os' test
Gilles Peskine8f073122018-11-27 15:58:47 +01001907}
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +00001908
Gilles Peskine8f073122018-11-27 15:58:47 +01001909component_build_no_std_function () {
1910 # catch compile bugs in _uninit functions
1911 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001912 scripts/config.py full
1913 scripts/config.py set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
1914 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskine32e889d2020-04-12 23:43:28 +02001915 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02001916 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Gilles Peskine8f073122018-11-27 15:58:47 +01001917}
Manuel Pégourié-Gonnarddccb80b2015-06-03 10:20:33 +01001918
Gilles Peskine8f073122018-11-27 15:58:47 +01001919component_build_no_ssl_srv () {
1920 msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001921 scripts/config.py full
1922 scripts/config.py unset MBEDTLS_SSL_SRV_C
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02001923 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
Gilles Peskine8f073122018-11-27 15:58:47 +01001924}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +02001925
Gilles Peskine8f073122018-11-27 15:58:47 +01001926component_build_no_ssl_cli () {
1927 msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001928 scripts/config.py full
1929 scripts/config.py unset MBEDTLS_SSL_CLI_C
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02001930 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
Gilles Peskine8f073122018-11-27 15:58:47 +01001931}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +02001932
Gilles Peskine8f073122018-11-27 15:58:47 +01001933component_build_no_sockets () {
1934 # Note, C99 compliance can also be tested with the sockets support disabled,
1935 # as that requires a POSIX platform (which isn't the same as C99).
1936 msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001937 scripts/config.py full
1938 scripts/config.py unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
1939 scripts/config.py set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02001940 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1 -std=c99 -pedantic' lib
Gilles Peskine8f073122018-11-27 15:58:47 +01001941}
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +02001942
Andrzej Kurek69f20aa2019-09-05 09:27:47 -04001943component_test_memory_buffer_allocator_backtrace () {
1944 msg "build: default config with memory buffer allocator and backtrace enabled"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001945 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
1946 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
1947 scripts/config.py set MBEDTLS_MEMORY_BACKTRACE
1948 scripts/config.py set MBEDTLS_MEMORY_DEBUG
Andrzej Kurek69f20aa2019-09-05 09:27:47 -04001949 CC=gcc cmake .
1950 make
1951
1952 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C and MBEDTLS_MEMORY_BACKTRACE"
1953 make test
1954}
1955
1956component_test_memory_buffer_allocator () {
1957 msg "build: default config with memory buffer allocator"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001958 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
1959 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
Hanno Becker0fb9ba22019-02-26 14:34:13 +00001960 CC=gcc cmake .
1961 make
1962
1963 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C"
1964 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +01001965
1966 msg "test: ssl-opt.sh, MBEDTLS_MEMORY_BUFFER_ALLOC_C"
1967 # MBEDTLS_MEMORY_BUFFER_ALLOC is slow. Skip tests that tend to time out.
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001968 tests/ssl-opt.sh -e '^DTLS proxy'
Hanno Becker0fb9ba22019-02-26 14:34:13 +00001969}
1970
Gilles Peskine8f073122018-11-27 15:58:47 +01001971component_test_no_max_fragment_length () {
1972 # Run max fragment length tests with MFL disabled
1973 msg "build: default config except MFL extension (ASan build)" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001974 scripts/config.py unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
Gilles Peskine8f073122018-11-27 15:58:47 +01001975 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1976 make
Hanno Becker5175ac62017-09-18 15:36:25 +01001977
Gilles Peskine8f073122018-11-27 15:58:47 +01001978 msg "test: ssl-opt.sh, MFL-related tests"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001979 tests/ssl-opt.sh -f "Max fragment length"
Gilles Peskine8f073122018-11-27 15:58:47 +01001980}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00001981
Hanno Becker545ced42019-02-19 11:10:48 +00001982component_test_asan_remove_peer_certificate () {
1983 msg "build: default config with MBEDTLS_SSL_KEEP_PEER_CERTIFICATE disabled (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001984 scripts/config.py unset MBEDTLS_SSL_KEEP_PEER_CERTIFICATE
Hanno Becker545ced42019-02-19 11:10:48 +00001985 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1986 make
1987
1988 msg "test: !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
1989 make test
1990
1991 msg "test: ssl-opt.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001992 tests/ssl-opt.sh
Hanno Becker545ced42019-02-19 11:10:48 +00001993
1994 msg "test: compat.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001995 tests/compat.sh
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02001996
1997 msg "test: context-info.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001998 tests/context-info.sh
Hanno Becker545ced42019-02-19 11:10:48 +00001999}
2000
Gilles Peskine8f073122018-11-27 15:58:47 +01002001component_test_no_max_fragment_length_small_ssl_out_content_len () {
2002 msg "build: no MFL extension, small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002003 scripts/config.py unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
2004 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 16384
2005 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
Gilles Peskine8f073122018-11-27 15:58:47 +01002006 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2007 make
Angus Grattonc4dd0732018-04-11 16:28:39 +10002008
Gilles Peskine8f073122018-11-27 15:58:47 +01002009 msg "test: MFL tests (disabled MFL extension case) & large packet tests"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002010 tests/ssl-opt.sh -f "Max fragment length\|Large buffer"
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02002011
2012 msg "test: context-info.sh (disabled MFL extension case)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002013 tests/context-info.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01002014}
Angus Grattonc4dd0732018-04-11 16:28:39 +10002015
Darryl Greenaad82f92019-12-02 10:53:11 +00002016component_test_variable_ssl_in_out_buffer_len () {
2017 msg "build: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled (ASan build)"
2018 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
2019 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2020 make
2021
2022 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
2023 make test
2024
2025 msg "test: ssl-opt.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002026 tests/ssl-opt.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00002027
2028 msg "test: compat.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002029 tests/compat.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00002030}
2031
2032component_test_variable_ssl_in_out_buffer_len_CID () {
2033 msg "build: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_DTLS_CONNECTION_ID enabled (ASan build)"
2034 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
2035 scripts/config.py set MBEDTLS_SSL_DTLS_CONNECTION_ID
2036
2037 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2038 make
2039
2040 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_DTLS_CONNECTION_ID"
2041 make test
2042
2043 msg "test: ssl-opt.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_DTLS_CONNECTION_ID enabled"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002044 tests/ssl-opt.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00002045
2046 msg "test: compat.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_DTLS_CONNECTION_ID enabled"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002047 tests/compat.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00002048}
2049
Piotr Nowicki0937ed22019-11-26 16:32:40 +01002050component_test_ssl_alloc_buffer_and_mfl () {
2051 msg "build: default config with memory buffer allocator and MFL extension"
2052 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
2053 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
2054 scripts/config.py set MBEDTLS_MEMORY_DEBUG
2055 scripts/config.py set MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
2056 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
2057 CC=gcc cmake .
2058 make
2059
2060 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH, MBEDTLS_MEMORY_BUFFER_ALLOC_C, MBEDTLS_MEMORY_DEBUG and MBEDTLS_SSL_MAX_FRAGMENT_LENGTH"
2061 make test
2062
2063 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 +02002064 tests/ssl-opt.sh -f "Handshake memory usage"
Piotr Nowicki0937ed22019-11-26 16:32:40 +01002065}
2066
Gilles Peskine636c26a2020-03-04 20:46:15 +01002067component_test_when_no_ciphersuites_have_mac () {
2068 msg "build: when no ciphersuites have MAC"
2069 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
Gilles Peskine636c26a2020-03-04 20:46:15 +01002070 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
TRodziewicz2add5c12021-04-28 16:50:20 +02002071 scripts/config.py unset MBEDTLS_CMAC_C
Gilles Peskine636c26a2020-03-04 20:46:15 +01002072 make
2073
2074 msg "test: !MBEDTLS_SSL_SOME_MODES_USE_MAC"
2075 make test
2076
2077 msg "test ssl-opt.sh: !MBEDTLS_SSL_SOME_MODES_USE_MAC"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002078 tests/ssl-opt.sh -f 'Default\|EtM' -e 'without EtM'
Gilles Peskine636c26a2020-03-04 20:46:15 +01002079}
2080
Raoul Strackxa4e86142020-06-15 17:03:13 +02002081component_test_no_date_time () {
2082 msg "build: default config without MBEDTLS_HAVE_TIME_DATE"
2083 scripts/config.py unset MBEDTLS_HAVE_TIME_DATE
2084 CC=gcc cmake
2085 make
2086
2087 msg "test: !MBEDTLS_HAVE_TIME_DATE - main suites"
2088 make test
2089}
2090
Gilles Peskine8f073122018-11-27 15:58:47 +01002091component_test_platform_calloc_macro () {
2092 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002093 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
2094 scripts/config.py set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
2095 scripts/config.py set MBEDTLS_PLATFORM_FREE_MACRO free
Gilles Peskine8f073122018-11-27 15:58:47 +01002096 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2097 make
Hanno Beckere5fecec2018-10-11 11:02:52 +01002098
Gilles Peskine8f073122018-11-27 15:58:47 +01002099 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
2100 make test
2101}
Hanno Beckere5fecec2018-10-11 11:02:52 +01002102
Gilles Peskinec4ef7a92019-09-17 19:04:38 +02002103component_test_malloc_0_null () {
2104 msg "build: malloc(0) returns NULL (ASan+UBSan build)"
Manuel Pégourié-Gonnard68192fc2020-03-04 10:34:47 +01002105 scripts/config.py full
Gilles Peskine004206c2019-10-21 17:11:33 +02002106 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 +02002107
2108 msg "test: malloc(0) returns NULL (ASan+UBSan build)"
2109 make test
2110
2111 msg "selftest: malloc(0) returns NULL (ASan+UBSan build)"
2112 # Just the calloc selftest. "make test" ran the others as part of the
2113 # test suites.
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002114 programs/test/selftest calloc
Gilles Peskine765d2402020-02-11 18:26:34 +01002115
2116 msg "test ssl-opt.sh: malloc(0) returns NULL (ASan+UBSan build)"
2117 # Run a subset of the tests. The choice is a balance between coverage
2118 # and time (including time indirectly wasted due to flaky tests).
2119 # The current choice is to skip tests whose description includes
2120 # "proxy", which is an approximation of skipping tests that use the
2121 # UDP proxy, which tend to be slower and flakier.
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002122 tests/ssl-opt.sh -e 'proxy'
Gilles Peskinec4ef7a92019-09-17 19:04:38 +02002123}
2124
Gilles Peskine8f073122018-11-27 15:58:47 +01002125component_test_aes_fewer_tables () {
2126 msg "build: default config with AES_FEWER_TABLES enabled"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002127 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
Gilles Peskine8f073122018-11-27 15:58:47 +01002128 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01002129
Gilles Peskine8f073122018-11-27 15:58:47 +01002130 msg "test: AES_FEWER_TABLES"
2131 make test
2132}
Hanno Becker83ebf782017-07-07 12:29:15 +01002133
Gilles Peskine8f073122018-11-27 15:58:47 +01002134component_test_aes_rom_tables () {
2135 msg "build: default config with AES_ROM_TABLES enabled"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002136 scripts/config.py set MBEDTLS_AES_ROM_TABLES
Gilles Peskine8f073122018-11-27 15:58:47 +01002137 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01002138
Gilles Peskine8f073122018-11-27 15:58:47 +01002139 msg "test: AES_ROM_TABLES"
2140 make test
2141}
Hanno Becker83ebf782017-07-07 12:29:15 +01002142
Gilles Peskine8f073122018-11-27 15:58:47 +01002143component_test_aes_fewer_tables_and_rom_tables () {
2144 msg "build: default config with AES_ROM_TABLES and AES_FEWER_TABLES enabled"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002145 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
2146 scripts/config.py set MBEDTLS_AES_ROM_TABLES
Gilles Peskine8f073122018-11-27 15:58:47 +01002147 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01002148
Gilles Peskine8f073122018-11-27 15:58:47 +01002149 msg "test: AES_FEWER_TABLES + AES_ROM_TABLES"
2150 make test
2151}
2152
Gilles Peskine592f5912019-10-07 18:49:32 +02002153component_test_ctr_drbg_aes_256_sha_256 () {
2154 msg "build: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
Gilles Peskine3b46cd32020-02-18 17:56:33 +01002155 scripts/config.py full
2156 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
2157 scripts/config.py set MBEDTLS_ENTROPY_FORCE_SHA256
Gilles Peskine592f5912019-10-07 18:49:32 +02002158 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2159 make
2160
2161 msg "test: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
2162 make test
2163}
2164
2165component_test_ctr_drbg_aes_128_sha_512 () {
2166 msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)"
Gilles Peskine3b46cd32020-02-18 17:56:33 +01002167 scripts/config.py full
2168 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
2169 scripts/config.py set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
Gilles Peskine592f5912019-10-07 18:49:32 +02002170 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2171 make
2172
2173 msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)"
2174 make test
2175}
2176
2177component_test_ctr_drbg_aes_128_sha_256 () {
2178 msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
Gilles Peskine3b46cd32020-02-18 17:56:33 +01002179 scripts/config.py full
2180 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
2181 scripts/config.py set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
2182 scripts/config.py set MBEDTLS_ENTROPY_FORCE_SHA256
Gilles Peskine592f5912019-10-07 18:49:32 +02002183 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2184 make
2185
2186 msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
2187 make test
2188}
2189
Gilles Peskinef96aefe2019-07-24 14:58:38 +02002190component_test_se_default () {
2191 msg "build: default config + MBEDTLS_PSA_CRYPTO_SE_C"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002192 scripts/config.py set MBEDTLS_PSA_CRYPTO_SE_C
Gilles Peskine004206c2019-10-21 17:11:33 +02002193 make CC=clang CFLAGS="$ASAN_CFLAGS -Os" LDFLAGS="$ASAN_CFLAGS"
Gilles Peskinef96aefe2019-07-24 14:58:38 +02002194
2195 msg "test: default config + MBEDTLS_PSA_CRYPTO_SE_C"
2196 make test
2197}
2198
Steven Cooremand57203d2020-07-16 20:28:59 +02002199component_test_psa_crypto_drivers () {
Steven Cooreman55ae2172020-07-17 19:46:15 +02002200 msg "build: MBEDTLS_PSA_CRYPTO_DRIVERS w/ driver hooks"
Steven Cooreman753f9732021-03-15 11:38:44 +01002201 scripts/config.py full
Steven Cooremand57203d2020-07-16 20:28:59 +02002202 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
Steven Cooreman6801f082021-02-19 17:21:22 +01002203 scripts/config.py set MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS
Steven Cooreman1cd39d52020-07-23 16:26:08 +02002204 # 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 +01002205 loc_cflags="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST"
Ronald Crone6f63012021-03-19 14:57:08 +01002206 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_KEY_TYPE_AES"
2207 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_KEY_TYPE_CAMELLIA"
Ronald Cron17b3afc2020-12-10 18:17:09 +01002208 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_KEY_PAIR"
Ronald Crone6f63012021-03-19 14:57:08 +01002209 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_KEY_PAIR"
2210 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_CBC_NO_PADDING"
2211 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_CBC_PKCS7"
2212 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_CTR"
2213 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_CFB"
Ronald Cron17b3afc2020-12-10 18:17:09 +01002214 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_ECDSA"
2215 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_DETERMINISTIC_ECDSA"
Steven Cooremand50db942021-03-08 17:17:15 +01002216 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_MD5"
Ronald Crone6f63012021-03-19 14:57:08 +01002217 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_OFB"
Steven Cooremand50db942021-03-08 17:17:15 +01002218 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_RIPEMD160"
Ronald Crone6f63012021-03-19 14:57:08 +01002219 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_SIGN"
2220 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_RSA_PSS"
Steven Cooremand50db942021-03-08 17:17:15 +01002221 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_SHA_1"
2222 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_SHA_224"
2223 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_SHA_256"
2224 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_SHA_384"
2225 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_SHA_512"
Ronald Crone6f63012021-03-19 14:57:08 +01002226 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_XTS"
Steven Cooreman7515e752021-03-19 19:36:38 +01002227 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_CMAC"
2228 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_HMAC"
Ronald Cron17b3afc2020-12-10 18:17:09 +01002229 loc_cflags="${loc_cflags} -I../tests/include -O2"
2230
2231 make CC=gcc CFLAGS="${loc_cflags}" LDFLAGS="$ASAN_CFLAGS"
2232 unset loc_cflags
Steven Cooremand57203d2020-07-16 20:28:59 +02002233
Steven Cooreman753f9732021-03-15 11:38:44 +01002234 msg "test: full + MBEDTLS_PSA_CRYPTO_DRIVERS"
Steven Cooremand57203d2020-07-16 20:28:59 +02002235 make test
2236}
2237
Gilles Peskine8f073122018-11-27 15:58:47 +01002238component_test_make_shared () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01002239 msg "build/test: make shared" # ~ 40s
Andrzej Kurek232e8f92019-10-03 03:18:01 -04002240 make SHARED=1 all check
Gilles Peskine56c01612019-07-03 20:43:32 +02002241 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskine8f073122018-11-27 15:58:47 +01002242}
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +02002243
Gilles Peskinecf740502019-07-03 20:43:05 +02002244component_test_cmake_shared () {
2245 msg "build/test: cmake shared" # ~ 2min
2246 cmake -DUSE_SHARED_MBEDTLS_LIBRARY=On .
2247 make
Gilles Peskine56c01612019-07-03 20:43:32 +02002248 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskinecf740502019-07-03 20:43:05 +02002249 make test
2250}
2251
Gilles Peskineec10bf12019-09-20 19:56:06 +02002252test_build_opt () {
2253 info=$1 cc=$2; shift 2
2254 for opt in "$@"; do
2255 msg "build/test: $cc $opt, $info" # ~ 30s
Gilles Peskinee094a182020-04-14 20:08:41 +02002256 make CC="$cc" CFLAGS="$opt -std=c99 -pedantic -Wall -Wextra -Werror"
Gilles Peskineec10bf12019-09-20 19:56:06 +02002257 # We're confident enough in compilers to not run _all_ the tests,
2258 # but at least run the unit tests. In particular, runs with
2259 # optimizations use inline assembly whereas runs with -O0
2260 # skip inline assembly.
2261 make test # ~30s
2262 make clean
2263 done
2264}
2265
2266component_test_clang_opt () {
Manuel Pégourié-Gonnard68192fc2020-03-04 10:34:47 +01002267 scripts/config.py full
Gilles Peskineec10bf12019-09-20 19:56:06 +02002268 test_build_opt 'full config' clang -O0 -Os -O2
2269}
2270
2271component_test_gcc_opt () {
Manuel Pégourié-Gonnard68192fc2020-03-04 10:34:47 +01002272 scripts/config.py full
Gilles Peskineec10bf12019-09-20 19:56:06 +02002273 test_build_opt 'full config' gcc -O0 -Os -O2
2274}
2275
Gilles Peskineabf9b4d2019-07-03 20:42:16 +02002276component_build_mbedtls_config_file () {
2277 msg "build: make with MBEDTLS_CONFIG_FILE" # ~40s
2278 # Use the full config so as to catch a maximum of places where
2279 # the check of MBEDTLS_CONFIG_FILE might be missing.
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002280 scripts/config.py full
Gilles Peskineabf9b4d2019-07-03 20:42:16 +02002281 sed 's!"check_config.h"!"mbedtls/check_config.h"!' <"$CONFIG_H" >full_config.h
2282 echo '#error "MBEDTLS_CONFIG_FILE is not working"' >"$CONFIG_H"
2283 make CFLAGS="-I '$PWD' -DMBEDTLS_CONFIG_FILE='\"full_config.h\"'"
2284 rm -f full_config.h
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00002285}
2286
Gilles Peskine8f073122018-11-27 15:58:47 +01002287component_test_m32_o0 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +01002288 # Build once with -O0, to compile out the i386 specific inline assembly
2289 msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002290 scripts/config.py full
Gilles Peskine8fd59422019-10-21 17:11:33 +02002291 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O0" LDFLAGS="-m32 $ASAN_CFLAGS"
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01002292
Simon Butcher8e6a22a2018-07-20 21:27:33 +01002293 msg "test: i386, make, gcc -O0 (ASan build)"
2294 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01002295}
Gilles Peskine878cf602019-01-06 20:50:38 +00002296support_test_m32_o0 () {
2297 case $(uname -m) in
2298 *64*) true;;
2299 *) false;;
2300 esac
2301}
Simon Butcher8e6a22a2018-07-20 21:27:33 +01002302
Gilles Peskine8f073122018-11-27 15:58:47 +01002303component_test_m32_o1 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +01002304 # Build again with -O1, to compile in the i386 specific inline assembly
2305 msg "build: i386, make, gcc -O1 (ASan build)" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002306 scripts/config.py full
Gilles Peskine8fd59422019-10-21 17:11:33 +02002307 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O1" LDFLAGS="-m32 $ASAN_CFLAGS"
Simon Butcher8e6a22a2018-07-20 21:27:33 +01002308
2309 msg "test: i386, make, gcc -O1 (ASan build)"
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01002310 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +01002311
2312 msg "test ssl-opt.sh, i386, make, gcc-O1"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002313 tests/ssl-opt.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01002314}
Gilles Peskine878cf602019-01-06 20:50:38 +00002315support_test_m32_o1 () {
2316 support_test_m32_o0 "$@"
2317}
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01002318
Gilles Peskine0c6b7992019-04-12 20:29:48 +02002319component_test_m32_everest () {
2320 msg "build: i386, Everest ECDH context (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002321 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
Gilles Peskine8fd59422019-10-21 17:11:33 +02002322 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O2" LDFLAGS="-m32 $ASAN_CFLAGS"
Gilles Peskine0c6b7992019-04-12 20:29:48 +02002323
2324 msg "test: i386, Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
2325 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +01002326
2327 msg "test: i386, Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002328 tests/ssl-opt.sh -f ECDH
Gilles Peskine636c26a2020-03-04 20:46:15 +01002329
2330 msg "test: i386, Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
2331 # Exclude some symmetric ciphers that are redundant here to gain time.
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002332 tests/compat.sh -f ECDH -V NO -e 'ARIA\|CAMELLIA\|CHACHA\|DES'
Gilles Peskine0c6b7992019-04-12 20:29:48 +02002333}
2334support_test_m32_everest () {
2335 support_test_m32_o0 "$@"
2336}
2337
Gilles Peskine8f073122018-11-27 15:58:47 +01002338component_test_mx32 () {
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01002339 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002340 scripts/config.py full
Gilles Peskine5d26e7c2019-06-07 14:50:09 +02002341 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32' LDFLAGS='-mx32'
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01002342
2343 msg "test: 64-bit ILP32, make, gcc"
2344 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01002345}
Gilles Peskine878cf602019-01-06 20:50:38 +00002346support_test_mx32 () {
2347 case $(uname -m) in
2348 amd64|x86_64) true;;
2349 *) false;;
2350 esac
2351}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00002352
Peter Kolbus60c6da22018-12-27 06:59:04 -06002353component_test_min_mpi_window_size () {
2354 msg "build: Default + MBEDTLS_MPI_WINDOW_SIZE=1 (ASan build)" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002355 scripts/config.py set MBEDTLS_MPI_WINDOW_SIZE 1
Peter Kolbus60c6da22018-12-27 06:59:04 -06002356 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2357 make
2358
2359 msg "test: MBEDTLS_MPI_WINDOW_SIZE=1 - main suites (inc. selftests) (ASan build)" # ~ 10s
2360 make test
2361}
2362
Gilles Peskine8f073122018-11-27 15:58:47 +01002363component_test_have_int32 () {
2364 msg "build: gcc, force 32-bit bignum limbs"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002365 scripts/config.py unset MBEDTLS_HAVE_ASM
2366 scripts/config.py unset MBEDTLS_AESNI_C
2367 scripts/config.py unset MBEDTLS_PADLOCK_C
Gilles Peskine8f073122018-11-27 15:58:47 +01002368 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01002369
Gilles Peskine8f073122018-11-27 15:58:47 +01002370 msg "test: gcc, force 32-bit bignum limbs"
2371 make test
2372}
Andres Amaya Garciafe843a32017-07-20 13:21:34 +01002373
Gilles Peskine8f073122018-11-27 15:58:47 +01002374component_test_have_int64 () {
2375 msg "build: gcc, force 64-bit bignum limbs"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002376 scripts/config.py unset MBEDTLS_HAVE_ASM
2377 scripts/config.py unset MBEDTLS_AESNI_C
2378 scripts/config.py unset MBEDTLS_PADLOCK_C
Gilles Peskine8f073122018-11-27 15:58:47 +01002379 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
Gilles Peskine14c3c062018-01-29 21:25:12 +01002380
Gilles Peskine8f073122018-11-27 15:58:47 +01002381 msg "test: gcc, force 64-bit bignum limbs"
2382 make test
2383}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00002384
Gilles Peskine8f073122018-11-27 15:58:47 +01002385component_test_no_udbl_division () {
2386 msg "build: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002387 scripts/config.py full
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002388 scripts/config.py set MBEDTLS_NO_UDBL_DIVISION
Gilles Peskine8f073122018-11-27 15:58:47 +01002389 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02002390
Gilles Peskine8f073122018-11-27 15:58:47 +01002391 msg "test: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
2392 make test
2393}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02002394
Gilles Peskine8f073122018-11-27 15:58:47 +01002395component_test_no_64bit_multiplication () {
2396 msg "build: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002397 scripts/config.py full
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002398 scripts/config.py set MBEDTLS_NO_64BIT_MULTIPLICATION
Gilles Peskine8f073122018-11-27 15:58:47 +01002399 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02002400
Gilles Peskine8f073122018-11-27 15:58:47 +01002401 msg "test: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
2402 make test
2403}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02002404
Gilles Peskine3809f5f2020-11-09 15:40:05 +01002405component_test_no_strings () {
2406 msg "build: no strings" # ~10s
2407 scripts/config.py full
2408 # Disable options that activate a large amount of string constants.
2409 scripts/config.py unset MBEDTLS_DEBUG_C
2410 scripts/config.py unset MBEDTLS_ERROR_C
2411 scripts/config.py set MBEDTLS_ERROR_STRERROR_DUMMY
2412 scripts/config.py unset MBEDTLS_VERSION_FEATURES
2413 make CFLAGS='-Werror -Os'
2414
2415 msg "test: no strings" # ~ 10s
2416 make test
2417}
2418
Hanno Beckerc5722d12020-10-09 11:10:42 +01002419component_test_no_x509_info () {
2420 msg "build: full + MBEDTLS_X509_REMOVE_INFO" # ~ 10s
2421 scripts/config.pl full
2422 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
2423 scripts/config.pl set MBEDTLS_X509_REMOVE_INFO
2424 make CFLAGS='-Werror -O1'
2425
2426 msg "test: full + MBEDTLS_X509_REMOVE_INFO" # ~ 10s
2427 make test
2428
2429 msg "test: ssl-opt.sh, full + MBEDTLS_X509_REMOVE_INFO" # ~ 1 min
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002430 tests/ssl-opt.sh
Hanno Beckerc5722d12020-10-09 11:10:42 +01002431}
2432
Gilles Peskine8f073122018-11-27 15:58:47 +01002433component_build_arm_none_eabi_gcc () {
Gilles Peskine18487f62020-04-30 23:11:54 +02002434 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002435 scripts/config.py baremetal
Gilles Peskineaeedd742020-09-02 11:03:04 +02002436 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 +02002437
2438 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1"
2439 ${ARM_NONE_EABI_GCC_PREFIX}size library/*.o
Gilles Peskine8f073122018-11-27 15:58:47 +01002440}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02002441
Gilles Peskine2c897d72019-08-09 16:05:05 +02002442component_build_arm_none_eabi_gcc_arm5vte () {
Gilles Peskine18487f62020-04-30 23:11:54 +02002443 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=arm5vte" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002444 scripts/config.py baremetal
Gilles Peskine2c897d72019-08-09 16:05:05 +02002445 # Build for a target platform that's close to what Debian uses
2446 # for its "armel" distribution (https://wiki.debian.org/ArmEabiPort).
2447 # See https://github.com/ARMmbed/mbedtls/pull/2169 and comments.
2448 # It would be better to build with arm-linux-gnueabi-gcc but
2449 # we don't have that on our CI at this time.
Gilles Peskineaeedd742020-09-02 11:03:04 +02002450 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 +02002451
2452 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=armv5te -O1"
2453 ${ARM_NONE_EABI_GCC_PREFIX}size library/*.o
Gilles Peskine93e4e032019-08-05 11:34:25 +02002454}
2455
Gilles Peskine6e2fb862020-04-30 23:00:53 +02002456component_build_arm_none_eabi_gcc_m0plus () {
2457 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus" # ~ 10s
2458 scripts/config.py baremetal
Gilles Peskineaeedd742020-09-02 11:03:04 +02002459 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 +02002460
2461 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus -Os"
2462 ${ARM_NONE_EABI_GCC_PREFIX}size library/*.o
Gilles Peskine6e2fb862020-04-30 23:00:53 +02002463}
2464
Gilles Peskine8f073122018-11-27 15:58:47 +01002465component_build_arm_none_eabi_gcc_no_udbl_division () {
Gilles Peskine6d061342020-04-30 18:19:32 +02002466 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002467 scripts/config.py baremetal
2468 scripts/config.py set MBEDTLS_NO_UDBL_DIVISION
Gilles Peskineaeedd742020-09-02 11:03:04 +02002469 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 +01002470 echo "Checking that software 64-bit division is not required"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002471 not grep __aeabi_uldiv library/*.o
Gilles Peskine8f073122018-11-27 15:58:47 +01002472}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02002473
Gilles Peskine8f073122018-11-27 15:58:47 +01002474component_build_arm_none_eabi_gcc_no_64bit_multiplication () {
Gilles Peskine6d061342020-04-30 18:19:32 +02002475 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc MBEDTLS_NO_64BIT_MULTIPLICATION, make" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002476 scripts/config.py baremetal
2477 scripts/config.py set MBEDTLS_NO_64BIT_MULTIPLICATION
Gilles Peskineaeedd742020-09-02 11:03:04 +02002478 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 +01002479 echo "Checking that software 64-bit multiplication is not required"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002480 not grep __aeabi_lmul library/*.o
Gilles Peskine8f073122018-11-27 15:58:47 +01002481}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02002482
Gilles Peskine8f073122018-11-27 15:58:47 +01002483component_build_armcc () {
Gilles Peskine18487f62020-04-30 23:11:54 +02002484 msg "build: ARM Compiler 5"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002485 scripts/config.py baremetal
Gilles Peskinebca6ab92017-12-19 18:24:31 +01002486 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
Gilles Peskine18487f62020-04-30 23:11:54 +02002487
2488 msg "size: ARM Compiler 5"
2489 "$ARMC5_FROMELF" -z library/*.o
2490
Gilles Peskinebca6ab92017-12-19 18:24:31 +01002491 make clean
Andres AG87bb5772016-09-27 15:05:15 +01002492
Gilles Peskinebca6ab92017-12-19 18:24:31 +01002493 # ARM Compiler 6 - Target ARMv7-A
2494 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-a"
Simon Butcher940737f2017-07-23 13:42:36 +02002495
Gilles Peskinebca6ab92017-12-19 18:24:31 +01002496 # ARM Compiler 6 - Target ARMv7-M
2497 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m"
Simon Butcher940737f2017-07-23 13:42:36 +02002498
Gilles Peskinebca6ab92017-12-19 18:24:31 +01002499 # ARM Compiler 6 - Target ARMv8-A - AArch32
2500 armc6_build_test "--target=arm-arm-none-eabi -march=armv8.2-a"
Simon Butcher940737f2017-07-23 13:42:36 +02002501
Gilles Peskinebca6ab92017-12-19 18:24:31 +01002502 # ARM Compiler 6 - Target ARMv8-M
2503 armc6_build_test "--target=arm-arm-none-eabi -march=armv8-m.main"
Simon Butcher940737f2017-07-23 13:42:36 +02002504
Gilles Peskinebca6ab92017-12-19 18:24:31 +01002505 # ARM Compiler 6 - Target ARMv8-A - AArch64
2506 armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a"
Gilles Peskine8f073122018-11-27 15:58:47 +01002507}
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +01002508
Hanno Beckera711f6e2020-05-04 12:03:51 +01002509component_test_tls13_experimental () {
2510 msg "build: default config with MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL enabled"
2511 scripts/config.pl set MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL
2512 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2513 make
2514 msg "test: default config with MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL enabled"
2515 make test
2516}
2517
Gilles Peskine8f073122018-11-27 15:58:47 +01002518component_build_mingw () {
2519 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
Andrzej Kurek232e8f92019-10-03 03:18:01 -04002520 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 +00002521
Gilles Peskine8f073122018-11-27 15:58:47 +01002522 # note Make tests only builds the tests, but doesn't run them
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' WINDOWS_BUILD=1 tests
Gilles Peskine8f073122018-11-27 15:58:47 +01002524 make WINDOWS_BUILD=1 clean
Gilles Peskine2a458da2017-05-12 15:26:58 +02002525
Gilles Peskine8f073122018-11-27 15:58:47 +01002526 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
Andrzej Kurek232e8f92019-10-03 03:18:01 -04002527 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
2528 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 +01002529 make WINDOWS_BUILD=1 clean
2530}
Jaeden Amero117b8a42019-04-17 15:19:26 +01002531support_build_mingw() {
2532 case $(i686-w64-mingw32-gcc -dumpversion) in
2533 [0-5]*) false;;
2534 *) true;;
2535 esac
2536}
Simon Butcher91aef332016-11-17 09:20:50 +00002537
Gilles Peskine8f073122018-11-27 15:58:47 +01002538component_test_memsan () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01002539 msg "build: MSan (clang)" # ~ 1 min 20s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002540 scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm
Gilles Peskine7ad603e2017-12-10 23:22:20 +01002541 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
2542 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +02002543
Gilles Peskine7ad603e2017-12-10 23:22:20 +01002544 msg "test: main suites (MSan)" # ~ 10s
2545 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01002546
Gilles Peskine7ad603e2017-12-10 23:22:20 +01002547 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002548 tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01002549
Gilles Peskine7ad603e2017-12-10 23:22:20 +01002550 # Optional part(s)
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01002551
Gilles Peskine7ad603e2017-12-10 23:22:20 +01002552 if [ "$MEMORY" -gt 0 ]; then
2553 msg "test: compat.sh (MSan)" # ~ 6 min 20s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002554 tests/compat.sh
Gilles Peskine7ad603e2017-12-10 23:22:20 +01002555 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01002556}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01002557
Gilles Peskine69f190e2019-01-10 00:11:42 +01002558component_test_valgrind () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01002559 msg "build: Release (clang)"
Gilles Peskine7ad603e2017-12-10 23:22:20 +01002560 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
2561 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00002562
Gilles Peskine7ad603e2017-12-10 23:22:20 +01002563 msg "test: main suites valgrind (Release)"
2564 make memcheck
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00002565
Gilles Peskine636c26a2020-03-04 20:46:15 +01002566 # Optional parts (slow; currently broken on OS X because programs don't
2567 # seem to receive signals under valgrind on OS X).
Gilles Peskine7ad603e2017-12-10 23:22:20 +01002568 if [ "$MEMORY" -gt 0 ]; then
2569 msg "test: ssl-opt.sh --memcheck (Release)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002570 tests/ssl-opt.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01002571 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00002572
Gilles Peskine7ad603e2017-12-10 23:22:20 +01002573 if [ "$MEMORY" -gt 1 ]; then
2574 msg "test: compat.sh --memcheck (Release)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002575 tests/compat.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01002576 fi
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02002577
2578 if [ "$MEMORY" -gt 0 ]; then
2579 msg "test: context-info.sh --memcheck (Release)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002580 tests/context-info.sh --memcheck
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02002581 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01002582}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00002583
Gilles Peskine8f073122018-11-27 15:58:47 +01002584component_test_cmake_out_of_source () {
2585 msg "build: cmake 'out-of-source' build"
Gilles Peskine8f073122018-11-27 15:58:47 +01002586 MBEDTLS_ROOT_DIR="$PWD"
2587 mkdir "$OUT_OF_SOURCE_DIR"
2588 cd "$OUT_OF_SOURCE_DIR"
2589 cmake "$MBEDTLS_ROOT_DIR"
2590 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00002591
Gilles Peskine8f073122018-11-27 15:58:47 +01002592 msg "test: cmake 'out-of-source' build"
2593 make test
2594 # Test an SSL option that requires an auxiliary script in test/scripts/.
2595 # Also ensure that there are no error messages such as
2596 # "No such file or directory", which would indicate that some required
2597 # file is missing (ssl-opt.sh tolerates the absence of some files so
2598 # may exit with status 0 but emit errors).
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002599 ./tests/ssl-opt.sh -f 'Fallback SCSV: beginning of list' 2>ssl-opt.err
Gilles Peskinef7e956c2020-03-28 18:56:09 +01002600 cat ssl-opt.err >&2
2601 # If ssl-opt.err is non-empty, record an error and keep going.
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002602 [ ! -s ssl-opt.err ]
Gilles Peskinef7e956c2020-03-28 18:56:09 +01002603 rm ssl-opt.err
Gilles Peskine8f073122018-11-27 15:58:47 +01002604 cd "$MBEDTLS_ROOT_DIR"
2605 rm -rf "$OUT_OF_SOURCE_DIR"
2606 unset MBEDTLS_ROOT_DIR
2607}
Andres AGdc192212016-08-31 17:33:13 +01002608
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01002609component_test_cmake_as_subdirectory () {
2610 msg "build: cmake 'as-subdirectory' build"
2611 MBEDTLS_ROOT_DIR="$PWD"
2612
2613 cd programs/test/cmake_subproject
2614 cmake .
2615 make
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002616 ./cmake_subproject
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01002617
2618 cd "$MBEDTLS_ROOT_DIR"
2619 unset MBEDTLS_ROOT_DIR
2620}
2621
Chris Kayd259e342021-03-25 16:03:25 +00002622component_test_cmake_as_package () {
2623 msg "build: cmake 'as-package' build"
2624 MBEDTLS_ROOT_DIR="$PWD"
2625
2626 cd programs/test/cmake_package
2627 cmake .
2628 make
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002629 ./cmake_package
Chris Kayd259e342021-03-25 16:03:25 +00002630
2631 cd "$MBEDTLS_ROOT_DIR"
2632 unset MBEDTLS_ROOT_DIR
2633}
2634
2635component_test_cmake_as_package_install () {
2636 msg "build: cmake 'as-installed-package' build"
2637 MBEDTLS_ROOT_DIR="$PWD"
2638
2639 cd programs/test/cmake_package_install
2640 cmake .
2641 make
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002642 ./cmake_package_install
Chris Kayd259e342021-03-25 16:03:25 +00002643
2644 cd "$MBEDTLS_ROOT_DIR"
2645 unset MBEDTLS_ROOT_DIR
2646}
2647
Gilles Peskine8f073122018-11-27 15:58:47 +01002648component_test_zeroize () {
2649 # Test that the function mbedtls_platform_zeroize() is not optimized away by
2650 # different combinations of compilers and optimization flags by using an
2651 # auxiliary GDB script. Unfortunately, GDB does not return error values to the
2652 # system in all cases that the script fails, so we must manually search the
2653 # output to check whether the pass string is present and no failure strings
2654 # were printed.
Andres AGdc192212016-08-31 17:33:13 +01002655
Gilles Peskine4976e822019-01-06 19:52:22 +00002656 # Don't try to disable ASLR. We don't care about ASLR here. We do care
2657 # about a spurious message if Gdb tries and fails, so suppress that.
2658 gdb_disable_aslr=
2659 if [ -z "$(gdb -batch -nw -ex 'set disable-randomization off' 2>&1)" ]; then
2660 gdb_disable_aslr='set disable-randomization off'
2661 fi
2662
Gilles Peskine8f073122018-11-27 15:58:47 +01002663 for optimization_flag in -O2 -O3 -Ofast -Os; do
Gilles Peskine55f7c942019-01-09 22:28:21 +01002664 for compiler in clang gcc; do
2665 msg "test: $compiler $optimization_flag, mbedtls_platform_zeroize()"
2666 make programs CC="$compiler" DEBUG=1 CFLAGS="$optimization_flag"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002667 gdb -ex "$gdb_disable_aslr" -x tests/scripts/test_zeroize.gdb -nw -batch -nx 2>&1 | tee test_zeroize.log
2668 grep "The buffer was correctly zeroized" test_zeroize.log
2669 not grep -i "error" test_zeroize.log
Gilles Peskine55f7c942019-01-09 22:28:21 +01002670 rm -f test_zeroize.log
2671 make clean
2672 done
Andres Amaya Garcia29673812017-10-25 10:35:51 +01002673 done
Andres Amaya Garciad0d7bf62017-10-25 09:01:31 +01002674
Gilles Peskine4976e822019-01-06 19:52:22 +00002675 unset gdb_disable_aslr
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_python_files () {
2679 msg "Lint: Python scripts"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002680 tests/scripts/check-python-files.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01002681}
Gilles Peskine192c72f2017-12-21 15:59:21 +01002682
Gilles Peskine8f073122018-11-27 15:58:47 +01002683component_check_generate_test_code () {
2684 msg "uint test: generate_test_code.py"
Manuel Pégourié-Gonnarddfb114a2020-06-02 11:40:08 +02002685 # unittest writes out mundane stuff like number or tests run on stderr.
2686 # Our convention is to reserve stderr for actual errors, and write
2687 # harmless info on stdout so it can be suppress with --quiet.
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002688 ./tests/scripts/test_generate_test_code.py 2>&1
Gilles Peskine8f073122018-11-27 15:58:47 +01002689}
Gilles Peskine192c72f2017-12-21 15:59:21 +01002690
2691################################################################
2692#### Termination
2693################################################################
2694
Gilles Peskine8f073122018-11-27 15:58:47 +01002695post_report () {
2696 msg "Done, cleaning up"
2697 cleanup
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01002698
Gilles Peskine8f073122018-11-27 15:58:47 +01002699 final_report
2700}
2701
2702
2703
2704################################################################
2705#### Run all the things
2706################################################################
2707
Gilles Peskine5d996822020-03-28 21:09:21 +01002708# Function invoked by --error-test to test error reporting.
2709pseudo_component_error_test () {
2710 msg "Testing error reporting $error_test"
2711 if [ $KEEP_GOING -ne 0 ]; then
2712 echo "Expect three failing commands."
2713 fi
2714 error_test='this should not be used since the component runs in a subshell'
2715 grep non_existent /dev/null
2716 not grep -q . "$0"
2717 make unknown_target
2718 false "this should not be executed"
2719}
2720
Gilles Peskinee48351a2018-11-27 16:06:30 +01002721# Run one component and clean up afterwards.
Gilles Peskine8f073122018-11-27 15:58:47 +01002722run_component () {
Gilles Peskine608953e2019-01-02 18:57:02 +01002723 # Back up the configuration in case the component modifies it.
2724 # The cleanup function will restore it.
2725 cp -p "$CONFIG_H" "$CONFIG_BAK"
John Durkopbd069d32020-10-31 22:14:03 -07002726 cp -p "$CRYPTO_CONFIG_H" "$CRYPTO_CONFIG_BAK"
Gilles Peskineffcdeff2018-12-04 12:49:28 +01002727 current_component="$1"
Gilles Peskine9004a172019-09-16 15:20:36 +02002728 export MBEDTLS_TEST_CONFIGURATION="$current_component"
Gilles Peskine2ef377d2019-10-07 18:44:21 +02002729
2730 # Unconditionally create a seedfile that's sufficiently long.
2731 # Do this before each component, because a previous component may
2732 # have messed it up or shortened it.
Manuel Pégourié-Gonnardf1f180a2020-06-08 10:46:35 +02002733 redirect_err dd if=/dev/urandom of=./tests/seedfile bs=64 count=1
Gilles Peskine2ef377d2019-10-07 18:44:21 +02002734
Gilles Peskinece266c42020-03-28 18:50:43 +01002735 # Run the component in a subshell
2736 if [ $KEEP_GOING -eq 1 ]; then
2737 set +e
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +02002738 fi
Gilles Peskinece266c42020-03-28 18:50:43 +01002739 (
2740 if [ $QUIET -eq 1 ]; then
2741 # msg() will be silenced, so just print the component name here.
2742 echo "${current_component#component_}"
2743 exec >/dev/null
2744 fi
2745 if [ $KEEP_GOING -eq 1 ]; then
2746 # Keep "set -e" off, and run an ERR trap instead to record failures.
2747 set -E
2748 trap err_trap ERR
2749 fi
2750 # The next line is what runs the component
2751 "$@"
2752 if [ $KEEP_GOING -eq 1 ]; then
2753 trap - ERR
2754 exit $last_failure_status
2755 fi
2756 )
2757 component_status=$?
2758 if [ $KEEP_GOING -eq 1 ]; then
2759 set -e
2760 if [ $component_status -ne 0 ]; then
2761 failure_count=$((failure_count + 1))
2762 fi
2763 fi
Gilles Peskine2ef377d2019-10-07 18:44:21 +02002764
2765 # Restore the build tree to a clean state.
Gilles Peskinee48351a2018-11-27 16:06:30 +01002766 cleanup
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +02002767 unset current_component
Gilles Peskine8f073122018-11-27 15:58:47 +01002768}
2769
2770# Preliminary setup
2771pre_check_environment
2772pre_initialize_variables
2773pre_parse_command_line "$@"
Gilles Peskine348fb9a2018-11-27 17:04:29 +01002774
Gilles Peskine878cf602019-01-06 20:50:38 +00002775pre_check_git
Andrzej Kurekeb508712019-02-14 07:18:59 -05002776
Gilles Peskine878cf602019-01-06 20:50:38 +00002777build_status=0
2778if [ $KEEP_GOING -eq 1 ]; then
2779 pre_setup_keep_going
Gilles Peskine8f073122018-11-27 15:58:47 +01002780fi
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +02002781pre_setup_quiet_redirect
Gilles Peskine67ffdaf2019-09-16 15:55:46 +02002782pre_prepare_outcome_file
Gilles Peskine878cf602019-01-06 20:50:38 +00002783pre_print_configuration
2784pre_check_tools
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01002785cleanup
Gilles Peskine1570b592021-04-22 01:10:12 +02002786pre_generate_files
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01002787
Gilles Peskinebeb3a812019-01-06 22:11:25 +00002788# Run the requested tests.
Gilles Peskine5d996822020-03-28 21:09:21 +01002789while [ $error_test -gt 0 ]; do
2790 run_component pseudo_component_error_test
2791 error_test=$((error_test - 1))
2792done
Gilles Peskinebeb3a812019-01-06 22:11:25 +00002793for component in $RUN_COMPONENTS; do
2794 run_component "component_$component"
2795done
Gilles Peskine8f073122018-11-27 15:58:47 +01002796
2797# We're done.
Gilles Peskine878cf602019-01-06 20:50:38 +00002798post_report