Gilles Peskine | 62cf2e8 | 2020-03-27 16:35:23 +0100 | [diff] [blame] | 1 | #! /usr/bin/env bash |
Manuel Pégourié-Gonnard | 80955ee | 2014-03-19 18:29:01 +0100 | [diff] [blame] | 2 | |
Simon Butcher | 3ea7f52 | 2016-03-07 23:22:10 +0000 | [diff] [blame] | 3 | # all.sh |
| 4 | # |
Bence Szépkúti | 1e14827 | 2020-08-07 13:07:28 +0200 | [diff] [blame] | 5 | # Copyright The Mbed TLS Contributors |
Dave Rodgman | 16799db | 2023-11-02 19:47:20 +0000 | [diff] [blame] | 6 | # SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later |
Gilles Peskine | 192c72f | 2017-12-21 15:59:21 +0100 | [diff] [blame] | 7 | |
| 8 | |
| 9 | |
| 10 | ################################################################ |
| 11 | #### Documentation |
| 12 | ################################################################ |
| 13 | |
Simon Butcher | 3ea7f52 | 2016-03-07 23:22:10 +0000 | [diff] [blame] | 14 | # Purpose |
Gilles Peskine | 192c72f | 2017-12-21 15:59:21 +0100 | [diff] [blame] | 15 | # ------- |
Simon Butcher | 3ea7f52 | 2016-03-07 23:22:10 +0000 | [diff] [blame] | 16 | # |
SimonB | 2e23c82 | 2016-04-16 21:54:39 +0100 | [diff] [blame] | 17 | # To run all tests possible or available on the platform. |
Manuel Pégourié-Gonnard | 80955ee | 2014-03-19 18:29:01 +0100 | [diff] [blame] | 18 | # |
Gilles Peskine | 192c72f | 2017-12-21 15:59:21 +0100 | [diff] [blame] | 19 | # Notes for users |
| 20 | # --------------- |
| 21 | # |
SimonB | 2e23c82 | 2016-04-16 21:54:39 +0100 | [diff] [blame] | 22 | # Warning: the test is destructive. It includes various build modes and |
| 23 | # configurations, and can and will arbitrarily change the current CMake |
Gilles Peskine | 192c72f | 2017-12-21 15:59:21 +0100 | [diff] [blame] | 24 | # configuration. The following files must be committed into git: |
Bence Szépkúti | bb0cfeb | 2021-05-28 09:42:25 +0200 | [diff] [blame] | 25 | # * include/mbedtls/mbedtls_config.h |
Gilles Peskine | 636c26a | 2020-03-04 20:46:15 +0100 | [diff] [blame] | 26 | # * Makefile, library/Makefile, programs/Makefile, tests/Makefile, |
| 27 | # programs/fuzz/Makefile |
Gilles Peskine | 192c72f | 2017-12-21 15:59:21 +0100 | [diff] [blame] | 28 | # After running this script, the CMake cache will be lost and CMake |
| 29 | # will no longer be initialised. |
Manuel Pégourié-Gonnard | 3895f5a | 2014-03-27 14:44:04 +0100 | [diff] [blame] | 30 | # |
Gilles Peskine | 192c72f | 2017-12-21 15:59:21 +0100 | [diff] [blame] | 31 | # The script assumes the presence of a number of tools: |
| 32 | # * Basic Unix tools (Windows users note: a Unix-style find must be before |
| 33 | # the Windows find in the PATH) |
| 34 | # * Perl |
| 35 | # * GNU Make |
| 36 | # * CMake |
| 37 | # * GCC and Clang (recent enough for using ASan with gcc and MemSan with clang, or valgrind) |
Andrzej Kurek | 05be06c | 2018-06-28 04:41:50 -0400 | [diff] [blame] | 38 | # * G++ |
Gilles Peskine | 192c72f | 2017-12-21 15:59:21 +0100 | [diff] [blame] | 39 | # * arm-gcc and mingw-gcc |
| 40 | # * ArmCC 5 and ArmCC 6, unless invoked with --no-armcc |
Gilles Peskine | 7be571a | 2023-08-27 21:39:21 +0200 | [diff] [blame] | 41 | # * OpenSSL and GnuTLS command line tools, in suitable versions for the |
| 42 | # interoperability tests. The following are the official versions at the |
| 43 | # time of writing: |
| 44 | # * GNUTLS_{CLI,SERV} = 3.4.10 |
| 45 | # * GNUTLS_NEXT_{CLI,SERV} = 3.7.2 |
| 46 | # * OPENSSL = 1.0.2g (without Debian/Ubuntu patches) |
Ronald Cron | 561181c | 2024-04-02 14:39:53 +0200 | [diff] [blame] | 47 | # * OPENSSL_NEXT = 3.1.2 |
Gilles Peskine | 192c72f | 2017-12-21 15:59:21 +0100 | [diff] [blame] | 48 | # See the invocation of check_tools below for details. |
| 49 | # |
| 50 | # This script must be invoked from the toplevel directory of a git |
| 51 | # working copy of Mbed TLS. |
| 52 | # |
Gilles Peskine | ce266c4 | 2020-03-28 18:50:43 +0100 | [diff] [blame] | 53 | # The behavior on an error depends on whether --keep-going (alias -k) |
| 54 | # is in effect. |
| 55 | # * Without --keep-going: the script stops on the first error without |
| 56 | # cleaning up. This lets you work in the configuration of the failing |
| 57 | # component. |
| 58 | # * With --keep-going: the script runs all requested components and |
| 59 | # reports failures at the end. In particular the script always cleans |
| 60 | # up on exit. |
| 61 | # |
Gilles Peskine | 192c72f | 2017-12-21 15:59:21 +0100 | [diff] [blame] | 62 | # Note that the output is not saved. You may want to run |
| 63 | # script -c tests/scripts/all.sh |
| 64 | # or |
| 65 | # tests/scripts/all.sh >all.log 2>&1 |
| 66 | # |
| 67 | # Notes for maintainers |
| 68 | # --------------------- |
| 69 | # |
Gilles Peskine | 8f07312 | 2018-11-27 15:58:47 +0100 | [diff] [blame] | 70 | # The bulk of the code is organized into functions that follow one of the |
| 71 | # following naming conventions: |
| 72 | # * pre_XXX: things to do before running the tests, in order. |
| 73 | # * component_XXX: independent components. They can be run in any order. |
Gilles Peskine | c70637a | 2019-01-09 22:29:17 +0100 | [diff] [blame] | 74 | # * component_check_XXX: quick tests that aren't worth parallelizing. |
| 75 | # * component_build_XXX: build things but don't run them. |
| 76 | # * component_test_XXX: build and test. |
Bence Szépkúti | 89dd5c0 | 2023-12-15 17:05:15 +0100 | [diff] [blame] | 77 | # * component_release_XXX: tests that the CI should skip during PR testing. |
Gilles Peskine | 878cf60 | 2019-01-06 20:50:38 +0000 | [diff] [blame] | 78 | # * support_XXX: if support_XXX exists and returns false then |
| 79 | # component_XXX is not run by default. |
Gilles Peskine | 8f07312 | 2018-11-27 15:58:47 +0100 | [diff] [blame] | 80 | # * post_XXX: things to do after running the tests. |
| 81 | # * other: miscellaneous support functions. |
| 82 | # |
Gilles Peskine | c70637a | 2019-01-09 22:29:17 +0100 | [diff] [blame] | 83 | # Each component must start by invoking `msg` with a short informative message. |
| 84 | # |
Gilles Peskine | a681c59 | 2020-03-28 21:27:40 +0100 | [diff] [blame] | 85 | # Warning: due to the way bash detects errors, the failure of a command |
| 86 | # inside 'if' or '!' is not detected. Use the 'not' function instead of '!'. |
| 87 | # |
Gilles Peskine | ce266c4 | 2020-03-28 18:50:43 +0100 | [diff] [blame] | 88 | # Each component is executed in a separate shell process. The component |
| 89 | # fails if any command in it returns a non-zero status. |
| 90 | # |
Gilles Peskine | c70637a | 2019-01-09 22:29:17 +0100 | [diff] [blame] | 91 | # The framework performs some cleanup tasks after each component. This |
| 92 | # means that components can assume that the working directory is in a |
| 93 | # cleaned-up state, and don't need to perform the cleanup themselves. |
| 94 | # * Run `make clean`. |
Bence Szépkúti | 414d6bd | 2021-06-28 14:11:11 +0100 | [diff] [blame] | 95 | # * Restore `include/mbedtls/mbedtls_config.h` from a backup made before running |
Gilles Peskine | c70637a | 2019-01-09 22:29:17 +0100 | [diff] [blame] | 96 | # the component. |
Gilles Peskine | 636c26a | 2020-03-04 20:46:15 +0100 | [diff] [blame] | 97 | # * Check out `Makefile`, `library/Makefile`, `programs/Makefile`, |
| 98 | # `tests/Makefile` and `programs/fuzz/Makefile` from git. |
| 99 | # This cleans up after an in-tree use of CMake. |
Gilles Peskine | c70637a | 2019-01-09 22:29:17 +0100 | [diff] [blame] | 100 | # |
Gilles Peskine | 192c72f | 2017-12-21 15:59:21 +0100 | [diff] [blame] | 101 | # The tests are roughly in order from fastest to slowest. This doesn't |
| 102 | # have to be exact, but in general you should add slower tests towards |
| 103 | # the end and fast checks near the beginning. |
Gilles Peskine | 192c72f | 2017-12-21 15:59:21 +0100 | [diff] [blame] | 104 | |
| 105 | |
| 106 | |
| 107 | ################################################################ |
| 108 | #### Initialization and command line parsing |
| 109 | ################################################################ |
Manuel Pégourié-Gonnard | 80955ee | 2014-03-19 18:29:01 +0100 | [diff] [blame] | 110 | |
Manuel Pégourié-Gonnard | 2c3a624 | 2024-10-01 11:54:34 +0200 | [diff] [blame] | 111 | # Enable ksh/bash extended file matching patterns. |
| 112 | # Must come before function definitions or some of them wouldn't parse. |
Gilles Peskine | 076f725 | 2022-08-30 21:02:44 +0200 | [diff] [blame] | 113 | shopt -s extglob |
| 114 | |
Manuel Pégourié-Gonnard | 2c3a624 | 2024-10-01 11:54:34 +0200 | [diff] [blame] | 115 | pre_set_shell_options () { |
| 116 | # Abort on errors (even on the left-hand side of a pipe). |
| 117 | # Treat uninitialised variables as errors. |
| 118 | set -e -o pipefail -u |
| 119 | } |
| 120 | |
Thomas Daubney | 2f55640 | 2024-07-30 15:52:58 +0100 | [diff] [blame] | 121 | # For project detection |
David Horstmann | 76a7738 | 2023-08-17 17:32:26 +0100 | [diff] [blame] | 122 | in_mbedtls_repo () { |
Thomas Daubney | 2f55640 | 2024-07-30 15:52:58 +0100 | [diff] [blame] | 123 | test "$PROJECT_NAME" = "Mbed TLS" |
David Horstmann | d02b5f8 | 2023-08-29 09:53:52 +0100 | [diff] [blame] | 124 | } |
| 125 | |
Ronald Cron | 070e865 | 2023-10-09 10:25:45 +0200 | [diff] [blame] | 126 | in_tf_psa_crypto_repo () { |
Thomas Daubney | 2f55640 | 2024-07-30 15:52:58 +0100 | [diff] [blame] | 127 | test "$PROJECT_NAME" = "TF-PSA-Crypto" |
David Horstmann | 9a6c45b | 2023-07-14 12:30:00 +0100 | [diff] [blame] | 128 | } |
| 129 | |
Gilles Peskine | 8f07312 | 2018-11-27 15:58:47 +0100 | [diff] [blame] | 130 | pre_check_environment () { |
Thomas Daubney | 5f0b64a | 2024-08-06 17:38:19 +0100 | [diff] [blame] | 131 | # For project detection |
| 132 | PROJECT_NAME_FILE='./scripts/project_name.txt' |
| 133 | if read -r PROJECT_NAME < "$PROJECT_NAME_FILE"; then :; else |
| 134 | echo "$PROJECT_NAME_FILE does not exist... Exiting..." >&2 |
| 135 | exit 1 |
| 136 | fi |
| 137 | |
Ronald Cron | 070e865 | 2023-10-09 10:25:45 +0200 | [diff] [blame] | 138 | if in_mbedtls_repo || in_tf_psa_crypto_repo; then :; else |
| 139 | echo "Must be run from Mbed TLS / TF-PSA-Crypto root" >&2 |
Gilles Peskine | 8f07312 | 2018-11-27 15:58:47 +0100 | [diff] [blame] | 140 | exit 1 |
| 141 | fi |
| 142 | } |
Manuel Pégourié-Gonnard | 80955ee | 2014-03-19 18:29:01 +0100 | [diff] [blame] | 143 | |
Gilles Peskine | 8f07312 | 2018-11-27 15:58:47 +0100 | [diff] [blame] | 144 | pre_initialize_variables () { |
David Horstmann | 76a7738 | 2023-08-17 17:32:26 +0100 | [diff] [blame] | 145 | if in_mbedtls_repo; then |
David Horstmann | 9a6c45b | 2023-07-14 12:30:00 +0100 | [diff] [blame] | 146 | CONFIG_H='include/mbedtls/mbedtls_config.h' |
Manuel Pégourié-Gonnard | 6c0c0f2 | 2024-10-16 10:12:00 +0200 | [diff] [blame] | 147 | if [ -d tf-psa-crypto ]; then |
| 148 | CRYPTO_CONFIG_H='tf-psa-crypto/include/psa/crypto_config.h' |
| 149 | PSA_CORE_PATH='tf-psa-crypto/core' |
| 150 | BUILTIN_SRC_PATH='tf-psa-crypto/drivers/builtin/src' |
| 151 | else |
| 152 | CRYPTO_CONFIG_H='include/psa/crypto_config.h' |
| 153 | fi |
David Horstmann | 76a7738 | 2023-08-17 17:32:26 +0100 | [diff] [blame] | 154 | else |
| 155 | CONFIG_H='drivers/builtin/include/mbedtls/mbedtls_config.h' |
Manuel Pégourié-Gonnard | 6c0c0f2 | 2024-10-16 10:12:00 +0200 | [diff] [blame] | 156 | CRYPTO_CONFIG_H='include/psa/crypto_config.h' |
| 157 | PSA_CORE_PATH='core' |
| 158 | BUILTIN_SRC_PATH='drivers/builtin/src' |
David Horstmann | 9a6c45b | 2023-07-14 12:30:00 +0100 | [diff] [blame] | 159 | fi |
Manuel Pégourié-Gonnard | 462e3a9 | 2022-12-27 12:35:11 +0100 | [diff] [blame] | 160 | CONFIG_TEST_DRIVER_H='tests/include/test/drivers/config_test_driver.h' |
Gilles Peskine | f83eb82 | 2020-03-30 20:11:39 +0200 | [diff] [blame] | 161 | |
| 162 | # Files that are clobbered by some jobs will be backed up. Use a different |
| 163 | # suffix from auxiliary scripts so that all.sh and auxiliary scripts can |
| 164 | # independently decide when to remove the backup file. |
| 165 | backup_suffix='.all.bak' |
| 166 | # Files clobbered by config.py |
Janos Follath | 2f04582 | 2023-07-31 10:57:16 +0100 | [diff] [blame] | 167 | files_to_back_up="$CONFIG_H $CRYPTO_CONFIG_H $CONFIG_TEST_DRIVER_H" |
David Horstmann | 76a7738 | 2023-08-17 17:32:26 +0100 | [diff] [blame] | 168 | if in_mbedtls_repo; then |
David Horstmann | 9a6c45b | 2023-07-14 12:30:00 +0100 | [diff] [blame] | 169 | # Files clobbered by in-tree cmake |
| 170 | files_to_back_up="$files_to_back_up Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile" |
| 171 | fi |
Manuel Pégourié-Gonnard | e73b263 | 2014-07-12 04:00:00 +0200 | [diff] [blame] | 172 | |
Gilles Peskine | 67ffdaf | 2019-09-16 15:55:46 +0200 | [diff] [blame] | 173 | append_outcome=0 |
Gilles Peskine | 8f07312 | 2018-11-27 15:58:47 +0100 | [diff] [blame] | 174 | MEMORY=0 |
| 175 | FORCE=0 |
Manuel Pégourié-Gonnard | 2b2bdaa | 2020-06-02 11:28:07 +0200 | [diff] [blame] | 176 | QUIET=0 |
Gilles Peskine | 8f07312 | 2018-11-27 15:58:47 +0100 | [diff] [blame] | 177 | KEEP_GOING=0 |
Manuel Pégourié-Gonnard | 80955ee | 2014-03-19 18:29:01 +0100 | [diff] [blame] | 178 | |
Manuel Pégourié-Gonnard | e050191 | 2020-06-08 12:59:27 +0200 | [diff] [blame] | 179 | # Seed value used with the --release-test option. |
Manuel Pégourié-Gonnard | 5430447 | 2020-06-22 10:11:47 +0200 | [diff] [blame] | 180 | # |
| 181 | # See also RELEASE_SEED in basic-build-test.sh. Debugging is easier if |
| 182 | # both values are kept in sync. If you change the value here because it |
| 183 | # breaks some tests, you'll definitely want to change it in |
| 184 | # basic-build-test.sh as well. |
Manuel Pégourié-Gonnard | e050191 | 2020-06-08 12:59:27 +0200 | [diff] [blame] | 185 | RELEASE_SEED=1 |
| 186 | |
Yanray Wang | 18040ed | 2023-11-23 21:29:56 +0800 | [diff] [blame] | 187 | # Specify character collation for regular expressions and sorting with C locale |
| 188 | export LC_COLLATE=C |
| 189 | |
Gilles Peskine | 67ffdaf | 2019-09-16 15:55:46 +0200 | [diff] [blame] | 190 | : ${MBEDTLS_TEST_OUTCOME_FILE=} |
Gilles Peskine | 9004a17 | 2019-09-16 15:20:36 +0200 | [diff] [blame] | 191 | : ${MBEDTLS_TEST_PLATFORM="$(uname -s | tr -c \\n0-9A-Za-z _)-$(uname -m | tr -c \\n0-9A-Za-z _)"} |
Gilles Peskine | 67ffdaf | 2019-09-16 15:55:46 +0200 | [diff] [blame] | 192 | export MBEDTLS_TEST_OUTCOME_FILE |
Gilles Peskine | 9004a17 | 2019-09-16 15:20:36 +0200 | [diff] [blame] | 193 | export MBEDTLS_TEST_PLATFORM |
| 194 | |
Jaeden Amero | c4cc251 | 2019-01-30 15:35:44 +0000 | [diff] [blame] | 195 | # Default commands, can be overridden by the environment |
Gilles Peskine | 8f07312 | 2018-11-27 15:58:47 +0100 | [diff] [blame] | 196 | : ${OPENSSL:="openssl"} |
Gilles Peskine | 8f07312 | 2018-11-27 15:58:47 +0100 | [diff] [blame] | 197 | : ${OPENSSL_NEXT:="$OPENSSL"} |
| 198 | : ${GNUTLS_CLI:="gnutls-cli"} |
| 199 | : ${GNUTLS_SERV:="gnutls-serv"} |
Gilles Peskine | 8f07312 | 2018-11-27 15:58:47 +0100 | [diff] [blame] | 200 | : ${OUT_OF_SOURCE_DIR:=./mbedtls_out_of_source_build} |
| 201 | : ${ARMC5_BIN_DIR:=/usr/bin} |
| 202 | : ${ARMC6_BIN_DIR:=/usr/bin} |
Gilles Peskine | 6d06134 | 2020-04-30 18:19:32 +0200 | [diff] [blame] | 203 | : ${ARM_NONE_EABI_GCC_PREFIX:=arm-none-eabi-} |
Manuel Pégourié-Gonnard | 3a6c769 | 2020-08-18 10:28:51 +0200 | [diff] [blame] | 204 | : ${ARM_LINUX_GNUEABI_GCC_PREFIX:=arm-linux-gnueabi-} |
Gowtham Suresh Kumar | 9da40b8 | 2023-07-31 16:38:10 +0100 | [diff] [blame] | 205 | : ${CLANG_LATEST:="clang-latest"} |
| 206 | : ${CLANG_EARLIEST:="clang-earliest"} |
| 207 | : ${GCC_LATEST:="gcc-latest"} |
| 208 | : ${GCC_EARLIEST:="gcc-earliest"} |
Gilles Peskine | 8f07312 | 2018-11-27 15:58:47 +0100 | [diff] [blame] | 209 | # if MAKEFLAGS is not set add the -j option to speed up invocations of make |
Gilles Peskine | a1fc4b5 | 2019-01-06 20:15:26 +0000 | [diff] [blame] | 210 | if [ -z "${MAKEFLAGS+set}" ]; then |
Gilles Peskine | 050d2fc | 2021-09-30 18:24:21 +0200 | [diff] [blame] | 211 | export MAKEFLAGS="-j$(all_sh_nproc)" |
Gilles Peskine | 8f07312 | 2018-11-27 15:58:47 +0100 | [diff] [blame] | 212 | fi |
Dave Rodgman | 0c5bfe8 | 2023-12-18 19:53:25 +0000 | [diff] [blame] | 213 | # if CC is not set, use clang by default (if present) to improve build times |
| 214 | if [ -z "${CC+set}" ] && (type clang > /dev/null 2>&1); then |
Dave Rodgman | fc5b955 | 2023-12-19 16:08:19 +0000 | [diff] [blame] | 215 | export CC="clang" |
Dave Rodgman | 66cbc83 | 2023-12-18 18:34:50 +0000 | [diff] [blame] | 216 | fi |
Gilles Peskine | 878cf60 | 2019-01-06 20:50:38 +0000 | [diff] [blame] | 217 | |
Ronald Cron | 561181c | 2024-04-02 14:39:53 +0200 | [diff] [blame] | 218 | if [ -n "${OPENSSL_3+set}" ]; then |
| 219 | export OPENSSL_NEXT="$OPENSSL_3" |
| 220 | fi |
| 221 | |
Gilles Peskine | 396853a | 2021-09-20 18:57:55 +0200 | [diff] [blame] | 222 | # Include more verbose output for failing tests run by CMake or make |
Jaeden Amero | d48e9c7 | 2019-02-07 17:43:39 +0000 | [diff] [blame] | 223 | export CTEST_OUTPUT_ON_FAILURE=1 |
| 224 | |
Gilles Peskine | 8fd5942 | 2019-10-21 17:11:33 +0200 | [diff] [blame] | 225 | # CFLAGS and LDFLAGS for Asan builds that don't use CMake |
Manuel Pégourié-Gonnard | fe549a7 | 2022-11-30 10:42:03 +0100 | [diff] [blame] | 226 | # default to -O2, use -Ox _after_ this if you want another level |
Przemek Stekiel | 6efa608 | 2023-05-31 09:38:21 +0200 | [diff] [blame] | 227 | ASAN_CFLAGS='-O2 -Werror -fsanitize=address,undefined -fno-sanitize-recover=all' |
Dave Rodgman | 17127e9 | 2023-12-14 16:42:48 +0000 | [diff] [blame] | 228 | # Normally, tests should use this compiler for ASAN testing |
| 229 | ASAN_CC=clang |
Gilles Peskine | 8fd5942 | 2019-10-21 17:11:33 +0200 | [diff] [blame] | 230 | |
Andrzej Kurek | 04bfe57 | 2023-06-27 10:02:09 -0400 | [diff] [blame] | 231 | # Platform tests have an allocation that returns null |
| 232 | export ASAN_OPTIONS="allocator_may_return_null=1" |
Andrzej Kurek | 026235c | 2023-07-05 08:32:43 -0400 | [diff] [blame] | 233 | export MSAN_OPTIONS="allocator_may_return_null=1" |
Andrzej Kurek | 04bfe57 | 2023-06-27 10:02:09 -0400 | [diff] [blame] | 234 | |
Gilles Peskine | 878cf60 | 2019-01-06 20:50:38 +0000 | [diff] [blame] | 235 | # Gather the list of available components. These are the functions |
| 236 | # defined in this script whose name starts with "component_". |
Gowtham Suresh Kumar | 1e829a4 | 2023-07-28 16:41:21 +0100 | [diff] [blame] | 237 | ALL_COMPONENTS=$(compgen -A function component_ | sed 's/component_//') |
Gilles Peskine | 878cf60 | 2019-01-06 20:50:38 +0000 | [diff] [blame] | 238 | |
Manuel Pégourié-Gonnard | 8535f4c | 2024-10-16 10:14:49 +0200 | [diff] [blame] | 239 | PSASIM_PATH='tests/psa-client-server/psasim/' |
| 240 | |
Dave Rodgman | 5f8e2a2 | 2024-01-16 17:33:34 +0000 | [diff] [blame] | 241 | # Delay determining SUPPORTED_COMPONENTS until the command line options have a chance to override |
Bence Szépkúti | 71c71eb | 2023-12-15 19:20:31 +0100 | [diff] [blame] | 242 | # the commands set by the environment |
Gilles Peskine | 8f07312 | 2018-11-27 15:58:47 +0100 | [diff] [blame] | 243 | } |
Andres AG | 38495a3 | 2016-07-12 16:54:33 +0100 | [diff] [blame] | 244 | |
Dave Rodgman | 2190063 | 2024-02-26 11:41:19 +0000 | [diff] [blame] | 245 | setup_quiet_wrappers() |
| 246 | { |
| 247 | # Pick up "quiet" wrappers for make and cmake, which don't output very much |
| 248 | # unless there is an error. This reduces logging overhead in the CI. |
| 249 | # |
| 250 | # Note that the cmake wrapper breaks unless we use an absolute path here. |
Dave Rodgman | a9e8dbe | 2024-02-26 17:27:18 +0000 | [diff] [blame] | 251 | if [[ -e ${PWD}/tests/scripts/quiet ]]; then |
| 252 | export PATH=${PWD}/tests/scripts/quiet:$PATH |
Dave Rodgman | 2190063 | 2024-02-26 11:41:19 +0000 | [diff] [blame] | 253 | fi |
| 254 | } |
| 255 | |
Gilles Peskine | a28db92 | 2019-01-10 00:05:18 +0100 | [diff] [blame] | 256 | # Test whether the component $1 is included in the command line patterns. |
| 257 | is_component_included() |
Gilles Peskine | 81b96ed | 2018-11-27 21:37:53 +0100 | [diff] [blame] | 258 | { |
Gilles Peskine | 03af678 | 2021-08-06 11:35:17 +0200 | [diff] [blame] | 259 | # Temporarily disable wildcard expansion so that $COMMAND_LINE_COMPONENTS |
| 260 | # only does word splitting. |
Gilles Peskine | 81b96ed | 2018-11-27 21:37:53 +0100 | [diff] [blame] | 261 | set -f |
Gilles Peskine | beb3a81 | 2019-01-06 22:11:25 +0000 | [diff] [blame] | 262 | for pattern in $COMMAND_LINE_COMPONENTS; do |
Gilles Peskine | 81b96ed | 2018-11-27 21:37:53 +0100 | [diff] [blame] | 263 | set +f |
| 264 | case ${1#component_} in $pattern) return 0;; esac |
| 265 | done |
| 266 | set +f |
| 267 | return 1 |
| 268 | } |
Andres AG | 7770ea8 | 2016-10-10 15:46:20 +0100 | [diff] [blame] | 269 | |
Simon Butcher | 41eeccf | 2016-09-07 00:07:09 +0100 | [diff] [blame] | 270 | usage() |
Andres AG | d9eba4b | 2016-08-26 14:42:14 +0100 | [diff] [blame] | 271 | { |
Gilles Peskine | 709346a | 2017-12-10 23:43:39 +0100 | [diff] [blame] | 272 | cat <<EOF |
Gilles Peskine | 9252511 | 2018-11-27 18:15:35 +0100 | [diff] [blame] | 273 | Usage: $0 [OPTION]... [COMPONENT]... |
Gilles Peskine | 348fb9a | 2018-11-27 17:04:29 +0100 | [diff] [blame] | 274 | Run mbedtls release validation tests. |
Gilles Peskine | 9252511 | 2018-11-27 18:15:35 +0100 | [diff] [blame] | 275 | By default, run all tests. With one or more COMPONENT, run only those. |
Gilles Peskine | a28db92 | 2019-01-10 00:05:18 +0100 | [diff] [blame] | 276 | COMPONENT can be the name of a component or a shell wildcard pattern. |
| 277 | |
| 278 | Examples: |
| 279 | $0 "check_*" |
| 280 | Run all sanity checks. |
| 281 | $0 --no-armcc --except test_memsan |
| 282 | Run everything except builds that require armcc and MemSan. |
Gilles Peskine | 348fb9a | 2018-11-27 17:04:29 +0100 | [diff] [blame] | 283 | |
| 284 | Special options: |
| 285 | -h|--help Print this help and exit. |
Gilles Peskine | 878cf60 | 2019-01-06 20:50:38 +0000 | [diff] [blame] | 286 | --list-all-components List all available test components and exit. |
| 287 | --list-components List components supported on this platform and exit. |
Gilles Peskine | 709346a | 2017-12-10 23:43:39 +0100 | [diff] [blame] | 288 | |
| 289 | General options: |
Manuel Pégourié-Gonnard | 2b2bdaa | 2020-06-02 11:28:07 +0200 | [diff] [blame] | 290 | -q|--quiet Only output component names, and errors if any. |
Gilles Peskine | 709346a | 2017-12-10 23:43:39 +0100 | [diff] [blame] | 291 | -f|--force Force the tests to overwrite any modified files. |
Gilles Peskine | 7c65216 | 2017-12-11 00:01:40 +0100 | [diff] [blame] | 292 | -k|--keep-going Run all tests and report errors at the end. |
Gilles Peskine | 709346a | 2017-12-10 23:43:39 +0100 | [diff] [blame] | 293 | -m|--memory Additional optional memory tests. |
Gilles Peskine | 67ffdaf | 2019-09-16 15:55:46 +0200 | [diff] [blame] | 294 | --append-outcome Append to the outcome file (if used). |
Gilles Peskine | 6d06134 | 2020-04-30 18:19:32 +0200 | [diff] [blame] | 295 | --arm-none-eabi-gcc-prefix=<string> |
| 296 | Prefix for a cross-compiler for arm-none-eabi |
| 297 | (default: "${ARM_NONE_EABI_GCC_PREFIX}") |
Manuel Pégourié-Gonnard | 3a6c769 | 2020-08-18 10:28:51 +0200 | [diff] [blame] | 298 | --arm-linux-gnueabi-gcc-prefix=<string> |
| 299 | Prefix for a cross-compiler for arm-linux-gnueabi |
| 300 | (default: "${ARM_LINUX_GNUEABI_GCC_PREFIX}") |
Gilles Peskine | bca6ab9 | 2017-12-19 18:24:31 +0100 | [diff] [blame] | 301 | --armcc Run ARM Compiler builds (on by default). |
Gilles Peskine | 80ddb99 | 2021-08-06 11:51:59 +0200 | [diff] [blame] | 302 | --restore First clean up the build tree, restoring backed up |
| 303 | files. Do not run any components unless they are |
| 304 | explicitly specified. |
Gilles Peskine | 5d99682 | 2020-03-28 21:09:21 +0100 | [diff] [blame] | 305 | --error-test Error test mode: run a failing function in addition |
Gilles Peskine | 86f6129 | 2021-08-05 15:11:33 +0200 | [diff] [blame] | 306 | to any specified component. May be repeated. |
Gilles Peskine | a28db92 | 2019-01-10 00:05:18 +0100 | [diff] [blame] | 307 | --except Exclude the COMPONENTs listed on the command line, |
| 308 | instead of running only those. |
Gilles Peskine | 67ffdaf | 2019-09-16 15:55:46 +0200 | [diff] [blame] | 309 | --no-append-outcome Write a new outcome file and analyze it (default). |
Gilles Peskine | bca6ab9 | 2017-12-19 18:24:31 +0100 | [diff] [blame] | 310 | --no-armcc Skip ARM Compiler builds. |
Gilles Peskine | 38d8165 | 2018-03-21 08:40:26 +0100 | [diff] [blame] | 311 | --no-force Refuse to overwrite modified files (default). |
| 312 | --no-keep-going Stop at the first error (default). |
| 313 | --no-memory No additional memory tests (default). |
Shaun Case | 8b0ecbc | 2021-12-20 21:14:10 -0800 | [diff] [blame] | 314 | --no-quiet Print full output from components. |
Gilles Peskine | 709346a | 2017-12-10 23:43:39 +0100 | [diff] [blame] | 315 | --out-of-source-dir=<path> Directory used for CMake out-of-source build tests. |
Gilles Peskine | 67ffdaf | 2019-09-16 15:55:46 +0200 | [diff] [blame] | 316 | --outcome-file=<path> File where test outcomes are written (not done if |
| 317 | empty; default: \$MBEDTLS_TEST_OUTCOME_FILE). |
Gilles Peskine | 38d8165 | 2018-03-21 08:40:26 +0100 | [diff] [blame] | 318 | --random-seed Use a random seed value for randomized tests (default). |
Manuel Pégourié-Gonnard | e050191 | 2020-06-08 12:59:27 +0200 | [diff] [blame] | 319 | -r|--release-test Run this script in release mode. This fixes the seed value to ${RELEASE_SEED}. |
Gilles Peskine | 709346a | 2017-12-10 23:43:39 +0100 | [diff] [blame] | 320 | -s|--seed Integer seed value to use for this test run. |
| 321 | |
| 322 | Tool path options: |
| 323 | --armc5-bin-dir=<ARMC5_bin_dir_path> ARM Compiler 5 bin directory. |
| 324 | --armc6-bin-dir=<ARMC6_bin_dir_path> ARM Compiler 6 bin directory. |
Gowtham Suresh Kumar | 6f1977b | 2023-07-28 17:04:47 +0100 | [diff] [blame] | 325 | --clang-earliest=<Clang_earliest_path> Earliest version of clang available |
| 326 | --clang-latest=<Clang_latest_path> Latest version of clang available |
| 327 | --gcc-earliest=<GCC_earliest_path> Earliest version of GCC available |
| 328 | --gcc-latest=<GCC_latest_path> Latest version of GCC available |
Gilles Peskine | 709346a | 2017-12-10 23:43:39 +0100 | [diff] [blame] | 329 | --gnutls-cli=<GnuTLS_cli_path> GnuTLS client executable to use for most tests. |
| 330 | --gnutls-serv=<GnuTLS_serv_path> GnuTLS server executable to use for most tests. |
Gilles Peskine | 709346a | 2017-12-10 23:43:39 +0100 | [diff] [blame] | 331 | --openssl=<OpenSSL_path> OpenSSL executable to use for most tests. |
Manuel Pégourié-Gonnard | 6b36892 | 2018-02-20 12:02:07 +0100 | [diff] [blame] | 332 | --openssl-next=<OpenSSL_path> OpenSSL executable to use for recent things like ARIA |
Gilles Peskine | 709346a | 2017-12-10 23:43:39 +0100 | [diff] [blame] | 333 | EOF |
SimonB | 2e23c82 | 2016-04-16 21:54:39 +0100 | [diff] [blame] | 334 | } |
Manuel Pégourié-Gonnard | 80955ee | 2014-03-19 18:29:01 +0100 | [diff] [blame] | 335 | |
Gilles Peskine | bf66e2c | 2021-08-03 13:44:28 +0200 | [diff] [blame] | 336 | # Cleanup before/after running a component. |
| 337 | # Remove built files as well as the cmake cache/config. |
| 338 | # Does not remove generated source files. |
Manuel Pégourié-Gonnard | 80955ee | 2014-03-19 18:29:01 +0100 | [diff] [blame] | 339 | cleanup() |
| 340 | { |
David Horstmann | 76a7738 | 2023-08-17 17:32:26 +0100 | [diff] [blame] | 341 | if in_mbedtls_repo; then |
David Horstmann | 9a6c45b | 2023-07-14 12:30:00 +0100 | [diff] [blame] | 342 | command make clean |
| 343 | fi |
Manuel Pégourié-Gonnard | e73b263 | 2014-07-12 04:00:00 +0200 | [diff] [blame] | 344 | |
Gilles Peskine | 31b07e2 | 2018-03-21 12:15:06 +0100 | [diff] [blame] | 345 | # Remove CMake artefacts |
Jaeden Amero | 2d0e00f | 2018-11-07 18:46:41 +0000 | [diff] [blame] | 346 | find . -name .git -prune -o \ |
Gilles Peskine | 31b07e2 | 2018-03-21 12:15:06 +0100 | [diff] [blame] | 347 | -iname CMakeFiles -exec rm -rf {} \+ -o \ |
| 348 | \( -iname cmake_install.cmake -o \ |
| 349 | -iname CTestTestfile.cmake -o \ |
Manuel Pégourié-Gonnard | bfe54d7 | 2021-09-09 11:11:44 +0200 | [diff] [blame] | 350 | -iname CMakeCache.txt -o \ |
| 351 | -path './cmake/*.cmake' \) -exec rm -f {} \+ |
Ronald Cron | da22402 | 2024-06-12 10:04:22 +0200 | [diff] [blame] | 352 | # Remove Makefiles generated by in-tree CMake builds |
Manuel Pégourié-Gonnard | 86c4838 | 2024-10-16 10:23:41 +0200 | [diff] [blame] | 353 | rm -f pkgconfig/Makefile framework/Makefile |
Ronald Cron | da22402 | 2024-06-12 10:04:22 +0200 | [diff] [blame] | 354 | rm -f include/Makefile programs/!(fuzz)/Makefile |
Manuel Pégourié-Gonnard | 6c0c0f2 | 2024-10-16 10:12:00 +0200 | [diff] [blame] | 355 | rm -f tf-psa-crypto/Makefile tf-psa-crypto/include/Makefile |
| 356 | rm -f tf-psa-crypto/core/Makefile tf-psa-crypto/drivers/Makefile |
| 357 | rm -f tf-psa-crypto/tests/Makefile |
| 358 | rm -f tf-psa-crypto/drivers/everest/Makefile |
| 359 | rm -f tf-psa-crypto/drivers/p256-m/Makefile |
| 360 | rm -f tf-psa-crypto/drivers/builtin/Makefile |
| 361 | rm -f tf-psa-crypto/drivers/builtin/src/Makefile |
Manuel Pégourié-Gonnard | e73b263 | 2014-07-12 04:00:00 +0200 | [diff] [blame] | 362 | |
Jaeden Amero | ab83fdf | 2019-06-20 17:38:22 +0100 | [diff] [blame] | 363 | # Remove any artifacts from the component_test_cmake_as_subdirectory test. |
| 364 | rm -rf programs/test/cmake_subproject/build |
| 365 | rm -f programs/test/cmake_subproject/Makefile |
| 366 | rm -f programs/test/cmake_subproject/cmake_subproject |
| 367 | |
Chris Kay | d259e34 | 2021-03-25 16:03:25 +0000 | [diff] [blame] | 368 | # Remove any artifacts from the component_test_cmake_as_package test. |
| 369 | rm -rf programs/test/cmake_package/build |
| 370 | rm -f programs/test/cmake_package/Makefile |
| 371 | rm -f programs/test/cmake_package/cmake_package |
| 372 | |
| 373 | # Remove any artifacts from the component_test_cmake_as_installed_package test. |
| 374 | rm -rf programs/test/cmake_package_install/build |
| 375 | rm -f programs/test/cmake_package_install/Makefile |
| 376 | rm -f programs/test/cmake_package_install/cmake_package_install |
| 377 | |
Gilles Peskine | f83eb82 | 2020-03-30 20:11:39 +0200 | [diff] [blame] | 378 | # Restore files that may have been clobbered by the job |
| 379 | for x in $files_to_back_up; do |
Gilles Peskine | dd06efb | 2022-08-30 21:02:00 +0200 | [diff] [blame] | 380 | if [[ -e "$x$backup_suffix" ]]; then |
| 381 | cp -p "$x$backup_suffix" "$x" |
| 382 | fi |
Gilles Peskine | f83eb82 | 2020-03-30 20:11:39 +0200 | [diff] [blame] | 383 | done |
| 384 | } |
John Durkop | bd069d3 | 2020-10-31 22:14:03 -0700 | [diff] [blame] | 385 | |
Manuel Pégourié-Gonnard | 8535f4c | 2024-10-16 10:14:49 +0200 | [diff] [blame] | 386 | # This is a helper function to be used in psasim builds. It is meant to clean |
| 387 | # up the library's workspace after the server build and before the client |
| 388 | # build. Built libraries (mbedcrypto, mbedx509 and mbedtls) are supposed to be |
| 389 | # already copied to psasim folder at this point. |
| 390 | helper_psasim_cleanup_before_client() { |
| 391 | # Clean up library files |
| 392 | make -C library clean |
| 393 | |
| 394 | # Restore files that were backup before building library files. This |
| 395 | # includes $CONFIG_H and $CRYPTO_CONFIG_H. |
| 396 | for x in $files_to_back_up; do |
| 397 | if [[ -e "$x$backup_suffix" ]]; then |
| 398 | cp -p "$x$backup_suffix" "$x" |
| 399 | fi |
| 400 | done |
| 401 | } |
| 402 | |
Gilles Peskine | bf66e2c | 2021-08-03 13:44:28 +0200 | [diff] [blame] | 403 | # Final cleanup when this script exits (except when exiting on a failure |
| 404 | # in non-keep-going mode). |
Gilles Peskine | f83eb82 | 2020-03-30 20:11:39 +0200 | [diff] [blame] | 405 | final_cleanup () { |
| 406 | cleanup |
| 407 | |
| 408 | for x in $files_to_back_up; do |
| 409 | rm -f "$x$backup_suffix" |
| 410 | done |
Manuel Pégourié-Gonnard | 80955ee | 2014-03-19 18:29:01 +0100 | [diff] [blame] | 411 | } |
| 412 | |
Gilles Peskine | 7c65216 | 2017-12-11 00:01:40 +0100 | [diff] [blame] | 413 | # Executed on exit. May be redefined depending on command line options. |
| 414 | final_report () { |
| 415 | : |
| 416 | } |
| 417 | |
| 418 | fatal_signal () { |
Gilles Peskine | f83eb82 | 2020-03-30 20:11:39 +0200 | [diff] [blame] | 419 | final_cleanup |
Gilles Peskine | 7c65216 | 2017-12-11 00:01:40 +0100 | [diff] [blame] | 420 | final_report $1 |
| 421 | trap - $1 |
| 422 | kill -$1 $$ |
| 423 | } |
| 424 | |
| 425 | trap 'fatal_signal HUP' HUP |
| 426 | trap 'fatal_signal INT' INT |
| 427 | trap 'fatal_signal TERM' TERM |
Manuel Pégourié-Gonnard | e73b263 | 2014-07-12 04:00:00 +0200 | [diff] [blame] | 428 | |
Gilles Peskine | 050d2fc | 2021-09-30 18:24:21 +0200 | [diff] [blame] | 429 | # Number of processors on this machine. Used as the default setting |
| 430 | # for parallel make. |
| 431 | all_sh_nproc () |
| 432 | { |
| 433 | { |
| 434 | nproc || # Linux |
| 435 | sysctl -n hw.ncpuonline || # NetBSD, OpenBSD |
| 436 | sysctl -n hw.ncpu || # FreeBSD |
| 437 | echo 1 |
| 438 | } 2>/dev/null |
| 439 | } |
| 440 | |
Manuel Pégourié-Gonnard | 3895f5a | 2014-03-27 14:44:04 +0100 | [diff] [blame] | 441 | msg() |
| 442 | { |
Gilles Peskine | ffcdeff | 2018-12-04 12:49:28 +0100 | [diff] [blame] | 443 | if [ -n "${current_component:-}" ]; then |
| 444 | current_section="${current_component#component_}: $1" |
| 445 | else |
| 446 | current_section="$1" |
| 447 | fi |
Manuel Pégourié-Gonnard | 2b2bdaa | 2020-06-02 11:28:07 +0200 | [diff] [blame] | 448 | |
| 449 | if [ $QUIET -eq 1 ]; then |
| 450 | return |
| 451 | fi |
| 452 | |
Manuel Pégourié-Gonnard | 3895f5a | 2014-03-27 14:44:04 +0100 | [diff] [blame] | 453 | echo "" |
| 454 | echo "******************************************************************" |
Gilles Peskine | ffcdeff | 2018-12-04 12:49:28 +0100 | [diff] [blame] | 455 | echo "* $current_section " |
Manuel Pégourié-Gonnard | 392d3dd | 2015-01-26 14:03:56 +0000 | [diff] [blame] | 456 | printf "* "; date |
Manuel Pégourié-Gonnard | 3895f5a | 2014-03-27 14:44:04 +0100 | [diff] [blame] | 457 | echo "******************************************************************" |
| 458 | } |
Manuel Pégourié-Gonnard | 80955ee | 2014-03-19 18:29:01 +0100 | [diff] [blame] | 459 | |
Gilles Peskine | 8f07312 | 2018-11-27 15:58:47 +0100 | [diff] [blame] | 460 | armc6_build_test() |
| 461 | { |
| 462 | FLAGS="$1" |
Andres AG | a5cd973 | 2016-10-17 15:23:10 +0100 | [diff] [blame] | 463 | |
Gilles Peskine | 18487f6 | 2020-04-30 23:11:54 +0200 | [diff] [blame] | 464 | msg "build: ARM Compiler 6 ($FLAGS)" |
Yanray Wang | bc7716c | 2023-09-08 11:20:59 +0800 | [diff] [blame] | 465 | make clean |
Gilles Peskine | 8f07312 | 2018-11-27 15:58:47 +0100 | [diff] [blame] | 466 | ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \ |
Dave Rodgman | 1c232a8 | 2023-03-02 13:39:04 +0000 | [diff] [blame] | 467 | WARNING_CFLAGS='-Werror -xc -std=c99' make lib |
Gilles Peskine | 18487f6 | 2020-04-30 23:11:54 +0200 | [diff] [blame] | 468 | |
| 469 | msg "size: ARM Compiler 6 ($FLAGS)" |
| 470 | "$ARMC6_FROMELF" -z library/*.o |
Manuel Pégourié-Gonnard | 6c0c0f2 | 2024-10-16 10:12:00 +0200 | [diff] [blame] | 471 | if [ -n ${PSA_CORE_PATH} ]; then |
| 472 | "$ARMC6_FROMELF" -z ${PSA_CORE_PATH}/*.o |
| 473 | fi |
| 474 | if [ -n ${BUILTIN_SRC_PATH} ]; then |
| 475 | "$ARMC6_FROMELF" -z ${BUILTIN_SRC_PATH}/*.o |
| 476 | fi |
Gilles Peskine | 8f07312 | 2018-11-27 15:58:47 +0100 | [diff] [blame] | 477 | } |
Andres AG | a5cd973 | 2016-10-17 15:23:10 +0100 | [diff] [blame] | 478 | |
Andres AG | d9eba4b | 2016-08-26 14:42:14 +0100 | [diff] [blame] | 479 | err_msg() |
| 480 | { |
| 481 | echo "$1" >&2 |
| 482 | } |
| 483 | |
| 484 | check_tools() |
| 485 | { |
Manuel Pégourié-Gonnard | 6be64f7 | 2023-09-28 09:08:04 +0200 | [diff] [blame] | 486 | for tool in "$@"; do |
| 487 | if ! `type "$tool" >/dev/null 2>&1`; then |
| 488 | err_msg "$tool not found!" |
Andres AG | d9eba4b | 2016-08-26 14:42:14 +0100 | [diff] [blame] | 489 | exit 1 |
| 490 | fi |
| 491 | done |
| 492 | } |
| 493 | |
Gilles Peskine | 8f07312 | 2018-11-27 15:58:47 +0100 | [diff] [blame] | 494 | pre_parse_command_line () { |
Gilles Peskine | beb3a81 | 2019-01-06 22:11:25 +0000 | [diff] [blame] | 495 | COMMAND_LINE_COMPONENTS= |
Gilles Peskine | a28db92 | 2019-01-10 00:05:18 +0100 | [diff] [blame] | 496 | all_except=0 |
Gilles Peskine | 5d99682 | 2020-03-28 21:09:21 +0100 | [diff] [blame] | 497 | error_test=0 |
Bence Szépkúti | 71c71eb | 2023-12-15 19:20:31 +0100 | [diff] [blame] | 498 | list_components=0 |
Gilles Peskine | 80ddb99 | 2021-08-06 11:51:59 +0200 | [diff] [blame] | 499 | restore_first=0 |
Gilles Peskine | 5331c6e | 2019-01-06 22:23:42 +0000 | [diff] [blame] | 500 | no_armcc= |
SimonB | 2e23c82 | 2016-04-16 21:54:39 +0100 | [diff] [blame] | 501 | |
Jaeden Amero | 9b90f2e | 2018-11-02 18:34:17 +0000 | [diff] [blame] | 502 | # Note that legacy options are ignored instead of being omitted from this |
| 503 | # list of options, so invocations that worked with previous version of |
| 504 | # all.sh will still run and work properly. |
Gilles Peskine | 8f07312 | 2018-11-27 15:58:47 +0100 | [diff] [blame] | 505 | while [ $# -gt 0 ]; do |
Gilles Peskine | 55f7c94 | 2019-01-09 22:28:21 +0100 | [diff] [blame] | 506 | case "$1" in |
Gilles Peskine | 67ffdaf | 2019-09-16 15:55:46 +0200 | [diff] [blame] | 507 | --append-outcome) append_outcome=1;; |
Gilles Peskine | 6d06134 | 2020-04-30 18:19:32 +0200 | [diff] [blame] | 508 | --arm-none-eabi-gcc-prefix) shift; ARM_NONE_EABI_GCC_PREFIX="$1";; |
Manuel Pégourié-Gonnard | 3a6c769 | 2020-08-18 10:28:51 +0200 | [diff] [blame] | 509 | --arm-linux-gnueabi-gcc-prefix) shift; ARM_LINUX_GNUEABI_GCC_PREFIX="$1";; |
Gilles Peskine | 5331c6e | 2019-01-06 22:23:42 +0000 | [diff] [blame] | 510 | --armcc) no_armcc=;; |
Bence Szépkúti | 71c71eb | 2023-12-15 19:20:31 +0100 | [diff] [blame] | 511 | --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";; |
| 512 | --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";; |
Gowtham Suresh Kumar | 6f1977b | 2023-07-28 17:04:47 +0100 | [diff] [blame] | 513 | --clang-earliest) shift; CLANG_EARLIEST="$1";; |
| 514 | --clang-latest) shift; CLANG_LATEST="$1";; |
Gilles Peskine | 5d99682 | 2020-03-28 21:09:21 +0100 | [diff] [blame] | 515 | --error-test) error_test=$((error_test + 1));; |
Gilles Peskine | beb3a81 | 2019-01-06 22:11:25 +0000 | [diff] [blame] | 516 | --except) all_except=1;; |
Gilles Peskine | 55f7c94 | 2019-01-09 22:28:21 +0100 | [diff] [blame] | 517 | --force|-f) FORCE=1;; |
Gowtham Suresh Kumar | 6f1977b | 2023-07-28 17:04:47 +0100 | [diff] [blame] | 518 | --gcc-earliest) shift; GCC_EARLIEST="$1";; |
| 519 | --gcc-latest) shift; GCC_LATEST="$1";; |
Gilles Peskine | 55f7c94 | 2019-01-09 22:28:21 +0100 | [diff] [blame] | 520 | --gnutls-cli) shift; GNUTLS_CLI="$1";; |
Gilles Peskine | 7be571a | 2023-08-27 21:39:21 +0200 | [diff] [blame] | 521 | --gnutls-legacy-cli) shift;; # ignored for backward compatibility |
| 522 | --gnutls-legacy-serv) shift;; # ignored for backward compatibility |
Gilles Peskine | 55f7c94 | 2019-01-09 22:28:21 +0100 | [diff] [blame] | 523 | --gnutls-serv) shift; GNUTLS_SERV="$1";; |
| 524 | --help|-h) usage; exit;; |
| 525 | --keep-going|-k) KEEP_GOING=1;; |
Gilles Peskine | 878cf60 | 2019-01-06 20:50:38 +0000 | [diff] [blame] | 526 | --list-all-components) printf '%s\n' $ALL_COMPONENTS; exit;; |
Bence Szépkúti | 71c71eb | 2023-12-15 19:20:31 +0100 | [diff] [blame] | 527 | --list-components) list_components=1;; |
Gilles Peskine | 55f7c94 | 2019-01-09 22:28:21 +0100 | [diff] [blame] | 528 | --memory|-m) MEMORY=1;; |
Gilles Peskine | 67ffdaf | 2019-09-16 15:55:46 +0200 | [diff] [blame] | 529 | --no-append-outcome) append_outcome=0;; |
Gilles Peskine | 5331c6e | 2019-01-06 22:23:42 +0000 | [diff] [blame] | 530 | --no-armcc) no_armcc=1;; |
Gilles Peskine | 55f7c94 | 2019-01-09 22:28:21 +0100 | [diff] [blame] | 531 | --no-force) FORCE=0;; |
| 532 | --no-keep-going) KEEP_GOING=0;; |
| 533 | --no-memory) MEMORY=0;; |
Manuel Pégourié-Gonnard | 2b2bdaa | 2020-06-02 11:28:07 +0200 | [diff] [blame] | 534 | --no-quiet) QUIET=0;; |
Gilles Peskine | 55f7c94 | 2019-01-09 22:28:21 +0100 | [diff] [blame] | 535 | --openssl) shift; OPENSSL="$1";; |
Gilles Peskine | 55f7c94 | 2019-01-09 22:28:21 +0100 | [diff] [blame] | 536 | --openssl-next) shift; OPENSSL_NEXT="$1";; |
Gilles Peskine | 67ffdaf | 2019-09-16 15:55:46 +0200 | [diff] [blame] | 537 | --outcome-file) shift; MBEDTLS_TEST_OUTCOME_FILE="$1";; |
Gilles Peskine | 55f7c94 | 2019-01-09 22:28:21 +0100 | [diff] [blame] | 538 | --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";; |
Manuel Pégourié-Gonnard | 2b2bdaa | 2020-06-02 11:28:07 +0200 | [diff] [blame] | 539 | --quiet|-q) QUIET=1;; |
Gilles Peskine | 55f7c94 | 2019-01-09 22:28:21 +0100 | [diff] [blame] | 540 | --random-seed) unset SEED;; |
Manuel Pégourié-Gonnard | e050191 | 2020-06-08 12:59:27 +0200 | [diff] [blame] | 541 | --release-test|-r) SEED=$RELEASE_SEED;; |
Gilles Peskine | 80ddb99 | 2021-08-06 11:51:59 +0200 | [diff] [blame] | 542 | --restore) restore_first=1;; |
Gilles Peskine | 55f7c94 | 2019-01-09 22:28:21 +0100 | [diff] [blame] | 543 | --seed|-s) shift; SEED="$1";; |
| 544 | -*) |
| 545 | echo >&2 "Unknown option: $1" |
| 546 | echo >&2 "Run $0 --help for usage." |
| 547 | exit 120 |
| 548 | ;; |
Gilles Peskine | beb3a81 | 2019-01-06 22:11:25 +0000 | [diff] [blame] | 549 | *) COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS $1";; |
Gilles Peskine | 55f7c94 | 2019-01-09 22:28:21 +0100 | [diff] [blame] | 550 | esac |
| 551 | shift |
Gilles Peskine | 8f07312 | 2018-11-27 15:58:47 +0100 | [diff] [blame] | 552 | done |
SimonB | 2e23c82 | 2016-04-16 21:54:39 +0100 | [diff] [blame] | 553 | |
Bence Szépkúti | 71c71eb | 2023-12-15 19:20:31 +0100 | [diff] [blame] | 554 | # Exclude components that are not supported on this platform. |
| 555 | SUPPORTED_COMPONENTS= |
| 556 | for component in $ALL_COMPONENTS; do |
| 557 | case $(type "support_$component" 2>&1) in |
| 558 | *' function'*) |
| 559 | if ! support_$component; then continue; fi;; |
| 560 | esac |
| 561 | SUPPORTED_COMPONENTS="$SUPPORTED_COMPONENTS $component" |
| 562 | done |
| 563 | |
| 564 | if [ $list_components -eq 1 ]; then |
| 565 | printf '%s\n' $SUPPORTED_COMPONENTS |
| 566 | exit |
| 567 | fi |
| 568 | |
Gilles Peskine | a28db92 | 2019-01-10 00:05:18 +0100 | [diff] [blame] | 569 | # With no list of components, run everything. |
Gilles Peskine | 80ddb99 | 2021-08-06 11:51:59 +0200 | [diff] [blame] | 570 | if [ -z "$COMMAND_LINE_COMPONENTS" ] && [ $restore_first -eq 0 ]; then |
Gilles Peskine | beb3a81 | 2019-01-06 22:11:25 +0000 | [diff] [blame] | 571 | all_except=1 |
Andres AG | dc19221 | 2016-08-31 17:33:13 +0100 | [diff] [blame] | 572 | fi |
| 573 | |
Gilles Peskine | 5331c6e | 2019-01-06 22:23:42 +0000 | [diff] [blame] | 574 | # --no-armcc is a legacy option. The modern way is --except '*_armcc*'. |
| 575 | # Ignore it if components are listed explicitly on the command line. |
Gilles Peskine | a28db92 | 2019-01-10 00:05:18 +0100 | [diff] [blame] | 576 | if [ -n "$no_armcc" ] && [ $all_except -eq 1 ]; then |
Gilles Peskine | 5331c6e | 2019-01-06 22:23:42 +0000 | [diff] [blame] | 577 | COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS *_armcc*" |
SimonB | 2e23c82 | 2016-04-16 21:54:39 +0100 | [diff] [blame] | 578 | fi |
SimonB | 2e23c82 | 2016-04-16 21:54:39 +0100 | [diff] [blame] | 579 | |
Gilles Peskine | bf66e2c | 2021-08-03 13:44:28 +0200 | [diff] [blame] | 580 | # Error out if an explicitly requested component doesn't exist. |
Gilles Peskine | b80f0d2 | 2020-03-28 21:37:59 +0100 | [diff] [blame] | 581 | if [ $all_except -eq 0 ]; then |
| 582 | unsupported=0 |
Gilles Peskine | 03af678 | 2021-08-06 11:35:17 +0200 | [diff] [blame] | 583 | # Temporarily disable wildcard expansion so that $COMMAND_LINE_COMPONENTS |
| 584 | # only does word splitting. |
Gilles Peskine | 1d475b6 | 2021-08-03 13:43:36 +0200 | [diff] [blame] | 585 | set -f |
Gilles Peskine | b80f0d2 | 2020-03-28 21:37:59 +0100 | [diff] [blame] | 586 | for component in $COMMAND_LINE_COMPONENTS; do |
Gilles Peskine | 1d475b6 | 2021-08-03 13:43:36 +0200 | [diff] [blame] | 587 | set +f |
Gilles Peskine | bf66e2c | 2021-08-03 13:44:28 +0200 | [diff] [blame] | 588 | # If the requested name includes a wildcard character, don't |
| 589 | # check it. Accept wildcard patterns that don't match anything. |
Gilles Peskine | b80f0d2 | 2020-03-28 21:37:59 +0100 | [diff] [blame] | 590 | case $component in |
| 591 | *[*?\[]*) continue;; |
| 592 | esac |
| 593 | case " $SUPPORTED_COMPONENTS " in |
| 594 | *" $component "*) :;; |
| 595 | *) |
| 596 | echo >&2 "Component $component was explicitly requested, but is not known or not supported." |
| 597 | unsupported=$((unsupported + 1));; |
| 598 | esac |
| 599 | done |
Gilles Peskine | 1d475b6 | 2021-08-03 13:43:36 +0200 | [diff] [blame] | 600 | set +f |
Gilles Peskine | b80f0d2 | 2020-03-28 21:37:59 +0100 | [diff] [blame] | 601 | if [ $unsupported -ne 0 ]; then |
| 602 | exit 2 |
| 603 | fi |
| 604 | fi |
| 605 | |
Gilles Peskine | beb3a81 | 2019-01-06 22:11:25 +0000 | [diff] [blame] | 606 | # Build the list of components to run. |
Gilles Peskine | a28db92 | 2019-01-10 00:05:18 +0100 | [diff] [blame] | 607 | RUN_COMPONENTS= |
| 608 | for component in $SUPPORTED_COMPONENTS; do |
| 609 | if is_component_included "$component"; [ $? -eq $all_except ]; then |
| 610 | RUN_COMPONENTS="$RUN_COMPONENTS $component" |
| 611 | fi |
| 612 | done |
Gilles Peskine | beb3a81 | 2019-01-06 22:11:25 +0000 | [diff] [blame] | 613 | |
| 614 | unset all_except |
Gilles Peskine | 5331c6e | 2019-01-06 22:23:42 +0000 | [diff] [blame] | 615 | unset no_armcc |
Gilles Peskine | 8f07312 | 2018-11-27 15:58:47 +0100 | [diff] [blame] | 616 | } |
SimonB | 2e23c82 | 2016-04-16 21:54:39 +0100 | [diff] [blame] | 617 | |
Gilles Peskine | 8f07312 | 2018-11-27 15:58:47 +0100 | [diff] [blame] | 618 | pre_check_git () { |
| 619 | if [ $FORCE -eq 1 ]; then |
Gilles Peskine | 53190e6 | 2019-01-09 23:17:35 +0100 | [diff] [blame] | 620 | rm -rf "$OUT_OF_SOURCE_DIR" |
Gilles Peskine | 8f07312 | 2018-11-27 15:58:47 +0100 | [diff] [blame] | 621 | git checkout-index -f -q $CONFIG_H |
| 622 | cleanup |
| 623 | else |
SimonB | 2e23c82 | 2016-04-16 21:54:39 +0100 | [diff] [blame] | 624 | |
Gilles Peskine | 8f07312 | 2018-11-27 15:58:47 +0100 | [diff] [blame] | 625 | if [ -d "$OUT_OF_SOURCE_DIR" ]; then |
| 626 | echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2 |
| 627 | echo "You can either delete this directory manually, or force the test by rerunning" |
| 628 | echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR" |
| 629 | exit 1 |
| 630 | fi |
| 631 | |
Ronald Cron | 7a93ac5 | 2023-07-20 09:49:12 +0200 | [diff] [blame] | 632 | if ! git diff --quiet "$CONFIG_H"; then |
David Horstmann | 9a6c45b | 2023-07-14 12:30:00 +0100 | [diff] [blame] | 633 | err_msg "Warning - the configuration file '$CONFIG_H' has been edited. " |
Gilles Peskine | 8f07312 | 2018-11-27 15:58:47 +0100 | [diff] [blame] | 634 | echo "You can either delete or preserve your work, or force the test by rerunning the" |
| 635 | echo "script as: $0 --force" |
| 636 | exit 1 |
| 637 | fi |
SimonB | 2e23c82 | 2016-04-16 21:54:39 +0100 | [diff] [blame] | 638 | fi |
Andrzej Kurek | eb50871 | 2019-02-14 07:18:59 -0500 | [diff] [blame] | 639 | } |
| 640 | |
Gilles Peskine | 568f53a | 2021-07-12 18:16:01 +0200 | [diff] [blame] | 641 | pre_restore_files () { |
| 642 | # If the makefiles have been generated by a framework such as cmake, |
| 643 | # restore them from git. If the makefiles look like modifications from |
| 644 | # the ones checked into git, take care not to modify them. Whatever |
| 645 | # this function leaves behind is what the script will restore before |
| 646 | # each component. |
| 647 | case "$(head -n1 Makefile)" in |
| 648 | *[Gg]enerated*) |
| 649 | git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile |
| 650 | git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile |
| 651 | ;; |
| 652 | esac |
| 653 | } |
| 654 | |
Gilles Peskine | f83eb82 | 2020-03-30 20:11:39 +0200 | [diff] [blame] | 655 | pre_back_up () { |
| 656 | for x in $files_to_back_up; do |
| 657 | cp -p "$x" "$x$backup_suffix" |
| 658 | done |
| 659 | } |
| 660 | |
Gilles Peskine | 8f07312 | 2018-11-27 15:58:47 +0100 | [diff] [blame] | 661 | pre_setup_keep_going () { |
Gilles Peskine | ce266c4 | 2020-03-28 18:50:43 +0100 | [diff] [blame] | 662 | failure_count=0 # Number of failed components |
| 663 | last_failure_status=0 # Last failure status in this component |
| 664 | |
Gilles Peskine | fec30cb | 2020-03-28 19:34:23 +0100 | [diff] [blame] | 665 | # See err_trap |
| 666 | previous_failure_status=0 |
| 667 | previous_failed_command= |
| 668 | previous_failure_funcall_depth=0 |
Gilles Peskine | a681c59 | 2020-03-28 21:27:40 +0100 | [diff] [blame] | 669 | unset report_failed_command |
Gilles Peskine | fec30cb | 2020-03-28 19:34:23 +0100 | [diff] [blame] | 670 | |
Gilles Peskine | 7c65216 | 2017-12-11 00:01:40 +0100 | [diff] [blame] | 671 | start_red= |
| 672 | end_color= |
| 673 | if [ -t 1 ]; then |
Gilles Peskine | 9736b9d | 2018-01-02 21:54:17 +0100 | [diff] [blame] | 674 | case "${TERM:-}" in |
Gilles Peskine | 7c65216 | 2017-12-11 00:01:40 +0100 | [diff] [blame] | 675 | *color*|cygwin|linux|rxvt*|screen|[Eex]term*) |
| 676 | start_red=$(printf '\033[31m') |
| 677 | end_color=$(printf '\033[0m') |
| 678 | ;; |
| 679 | esac |
| 680 | fi |
Gilles Peskine | ce266c4 | 2020-03-28 18:50:43 +0100 | [diff] [blame] | 681 | |
| 682 | # Keep a summary of failures in a file. We'll print it out at the end. |
| 683 | failure_summary_file=$PWD/all-sh-failures-$$.log |
| 684 | : >"$failure_summary_file" |
| 685 | |
| 686 | # Whether it makes sense to keep a component going after the specified |
| 687 | # command fails (test command) or not (configure or build). |
Gilles Peskine | 03af678 | 2021-08-06 11:35:17 +0200 | [diff] [blame] | 688 | # This function normally receives the failing simple command |
| 689 | # ($BASH_COMMAND) as an argument, but if $report_failed_command is set, |
| 690 | # this is passed instead. |
Gilles Peskine | ce266c4 | 2020-03-28 18:50:43 +0100 | [diff] [blame] | 691 | # This doesn't have to be 100% accurate: all failures are recorded anyway. |
Gilles Peskine | c111e24 | 2021-08-02 23:29:53 +0200 | [diff] [blame] | 692 | # False positives result in running things that can't be expected to |
| 693 | # work. False negatives result in things not running after something else |
| 694 | # failed even though they might have given useful feedback. |
Gilles Peskine | ce266c4 | 2020-03-28 18:50:43 +0100 | [diff] [blame] | 695 | can_keep_going_after_failure () { |
| 696 | case "$1" in |
| 697 | "msg "*) false;; |
Gilles Peskine | c111e24 | 2021-08-02 23:29:53 +0200 | [diff] [blame] | 698 | "cd "*) false;; |
Manuel Pégourié-Gonnard | a742337 | 2023-11-10 09:58:31 +0100 | [diff] [blame] | 699 | "diff "*) true;; |
Gilles Peskine | c111e24 | 2021-08-02 23:29:53 +0200 | [diff] [blame] | 700 | *make*[\ /]tests*) false;; # make tests, make CFLAGS=-I../tests, ... |
| 701 | *test*) true;; # make test, tests/stuff, env V=v tests/stuff, ... |
| 702 | *make*check*) true;; |
| 703 | "grep "*) true;; |
| 704 | "[ "*) true;; |
| 705 | "! "*) true;; |
Gilles Peskine | ce266c4 | 2020-03-28 18:50:43 +0100 | [diff] [blame] | 706 | *) false;; |
Gilles Peskine | 7c65216 | 2017-12-11 00:01:40 +0100 | [diff] [blame] | 707 | esac |
| 708 | } |
Gilles Peskine | ce266c4 | 2020-03-28 18:50:43 +0100 | [diff] [blame] | 709 | |
| 710 | # This function runs if there is any error in a component. |
| 711 | # It must either exit with a nonzero status, or set |
| 712 | # last_failure_status to a nonzero value. |
| 713 | err_trap () { |
| 714 | # Save $? (status of the failing command). This must be the very |
| 715 | # first thing, before $? is overridden. |
| 716 | last_failure_status=$? |
Gilles Peskine | a681c59 | 2020-03-28 21:27:40 +0100 | [diff] [blame] | 717 | failed_command=${report_failed_command-$BASH_COMMAND} |
Gilles Peskine | ce266c4 | 2020-03-28 18:50:43 +0100 | [diff] [blame] | 718 | |
Gilles Peskine | fec30cb | 2020-03-28 19:34:23 +0100 | [diff] [blame] | 719 | if [[ $last_failure_status -eq $previous_failure_status && |
| 720 | "$failed_command" == "$previous_failed_command" && |
| 721 | ${#FUNCNAME[@]} == $((previous_failure_funcall_depth - 1)) ]] |
| 722 | then |
| 723 | # The same command failed twice in a row, but this time one level |
| 724 | # less deep in the function call stack. This happens when the last |
| 725 | # command of a function returns a nonzero status, and the function |
| 726 | # returns that same status. Ignore the second failure. |
| 727 | previous_failure_funcall_depth=${#FUNCNAME[@]} |
| 728 | return |
| 729 | fi |
| 730 | previous_failure_status=$last_failure_status |
| 731 | previous_failed_command=$failed_command |
| 732 | previous_failure_funcall_depth=${#FUNCNAME[@]} |
| 733 | |
Gilles Peskine | ce266c4 | 2020-03-28 18:50:43 +0100 | [diff] [blame] | 734 | text="$current_section: $failed_command -> $last_failure_status" |
| 735 | echo "${start_red}^^^^$text^^^^${end_color}" >&2 |
| 736 | echo "$text" >>"$failure_summary_file" |
| 737 | |
| 738 | # If the command is fatal (configure or build command), stop this |
| 739 | # component. Otherwise (test command) keep the component running |
| 740 | # (run more tests from the same build). |
| 741 | if ! can_keep_going_after_failure "$failed_command"; then |
| 742 | exit $last_failure_status |
| 743 | fi |
| 744 | } |
| 745 | |
Gilles Peskine | 7c65216 | 2017-12-11 00:01:40 +0100 | [diff] [blame] | 746 | final_report () { |
| 747 | if [ $failure_count -gt 0 ]; then |
| 748 | echo |
| 749 | echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" |
Gilles Peskine | ce266c4 | 2020-03-28 18:50:43 +0100 | [diff] [blame] | 750 | echo "${start_red}FAILED: $failure_count components${end_color}" |
| 751 | cat "$failure_summary_file" |
Gilles Peskine | 7c65216 | 2017-12-11 00:01:40 +0100 | [diff] [blame] | 752 | echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" |
| 753 | elif [ -z "${1-}" ]; then |
| 754 | echo "SUCCESS :)" |
| 755 | fi |
| 756 | if [ -n "${1-}" ]; then |
| 757 | echo "Killed by SIG$1." |
| 758 | fi |
Gilles Peskine | ce266c4 | 2020-03-28 18:50:43 +0100 | [diff] [blame] | 759 | rm -f "$failure_summary_file" |
| 760 | if [ $failure_count -gt 0 ]; then |
| 761 | exit 1 |
| 762 | fi |
Gilles Peskine | 7c65216 | 2017-12-11 00:01:40 +0100 | [diff] [blame] | 763 | } |
Gilles Peskine | 8f07312 | 2018-11-27 15:58:47 +0100 | [diff] [blame] | 764 | } |
| 765 | |
Gilles Peskine | a681c59 | 2020-03-28 21:27:40 +0100 | [diff] [blame] | 766 | # '! true' does not trigger the ERR trap. Arrange to trigger it, with |
| 767 | # a reasonably informative error message (not just "$@"). |
| 768 | not () { |
| 769 | if "$@"; then |
| 770 | report_failed_command="! $*" |
| 771 | false |
| 772 | unset report_failed_command |
Manuel Pégourié-Gonnard | 2b2bdaa | 2020-06-02 11:28:07 +0200 | [diff] [blame] | 773 | fi |
| 774 | } |
| 775 | |
Gilles Peskine | 67ffdaf | 2019-09-16 15:55:46 +0200 | [diff] [blame] | 776 | pre_prepare_outcome_file () { |
| 777 | case "$MBEDTLS_TEST_OUTCOME_FILE" in |
| 778 | [!/]*) MBEDTLS_TEST_OUTCOME_FILE="$PWD/$MBEDTLS_TEST_OUTCOME_FILE";; |
| 779 | esac |
| 780 | if [ -n "$MBEDTLS_TEST_OUTCOME_FILE" ] && [ "$append_outcome" -eq 0 ]; then |
| 781 | rm -f "$MBEDTLS_TEST_OUTCOME_FILE" |
| 782 | fi |
| 783 | } |
| 784 | |
Gilles Peskine | 8f07312 | 2018-11-27 15:58:47 +0100 | [diff] [blame] | 785 | pre_print_configuration () { |
Manuel Pégourié-Gonnard | 2b2bdaa | 2020-06-02 11:28:07 +0200 | [diff] [blame] | 786 | if [ $QUIET -eq 1 ]; then |
| 787 | return |
| 788 | fi |
| 789 | |
Gilles Peskine | 8f07312 | 2018-11-27 15:58:47 +0100 | [diff] [blame] | 790 | msg "info: $0 configuration" |
| 791 | echo "MEMORY: $MEMORY" |
| 792 | echo "FORCE: $FORCE" |
Gilles Peskine | 67ffdaf | 2019-09-16 15:55:46 +0200 | [diff] [blame] | 793 | echo "MBEDTLS_TEST_OUTCOME_FILE: ${MBEDTLS_TEST_OUTCOME_FILE:-(none)}" |
Gilles Peskine | 8f07312 | 2018-11-27 15:58:47 +0100 | [diff] [blame] | 794 | echo "SEED: ${SEED-"UNSET"}" |
Gilles Peskine | 636c26a | 2020-03-04 20:46:15 +0100 | [diff] [blame] | 795 | echo |
Gilles Peskine | 8f07312 | 2018-11-27 15:58:47 +0100 | [diff] [blame] | 796 | echo "OPENSSL: $OPENSSL" |
Gilles Peskine | 8f07312 | 2018-11-27 15:58:47 +0100 | [diff] [blame] | 797 | echo "OPENSSL_NEXT: $OPENSSL_NEXT" |
| 798 | echo "GNUTLS_CLI: $GNUTLS_CLI" |
| 799 | echo "GNUTLS_SERV: $GNUTLS_SERV" |
Gilles Peskine | 8f07312 | 2018-11-27 15:58:47 +0100 | [diff] [blame] | 800 | echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR" |
| 801 | echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR" |
| 802 | } |
Andres AG | 7770ea8 | 2016-10-10 15:46:20 +0100 | [diff] [blame] | 803 | |
Andres AG | d9eba4b | 2016-08-26 14:42:14 +0100 | [diff] [blame] | 804 | # Make sure the tools we need are available. |
Gilles Peskine | 8f07312 | 2018-11-27 15:58:47 +0100 | [diff] [blame] | 805 | pre_check_tools () { |
Gilles Peskine | cc9f0b9 | 2019-01-06 22:46:21 +0000 | [diff] [blame] | 806 | # Build the list of variables to pass to output_env.sh. |
| 807 | set env |
SimonB | 2e23c82 | 2016-04-16 21:54:39 +0100 | [diff] [blame] | 808 | |
Gilles Peskine | 8796426 | 2019-01-06 22:40:00 +0000 | [diff] [blame] | 809 | case " $RUN_COMPONENTS " in |
| 810 | # Require OpenSSL and GnuTLS if running any tests (as opposed to |
| 811 | # only doing builds). Not all tests run OpenSSL and GnuTLS, but this |
| 812 | # is a good enough approximation in practice. |
Bence Szépkúti | bbb5af9 | 2023-12-15 20:58:15 +0100 | [diff] [blame] | 813 | *" test_"* | *" release_test_"*) |
Gilles Peskine | 8796426 | 2019-01-06 22:40:00 +0000 | [diff] [blame] | 814 | # To avoid setting OpenSSL and GnuTLS for each call to compat.sh |
| 815 | # and ssl-opt.sh, we just export the variables they require. |
Manuel Pégourié-Gonnard | c572246 | 2022-12-19 11:42:12 +0100 | [diff] [blame] | 816 | export OPENSSL="$OPENSSL" |
Gilles Peskine | 8796426 | 2019-01-06 22:40:00 +0000 | [diff] [blame] | 817 | export GNUTLS_CLI="$GNUTLS_CLI" |
| 818 | export GNUTLS_SERV="$GNUTLS_SERV" |
| 819 | # Avoid passing --seed flag in every call to ssl-opt.sh |
| 820 | if [ -n "${SEED-}" ]; then |
| 821 | export SEED |
| 822 | fi |
Gilles Peskine | 7be571a | 2023-08-27 21:39:21 +0200 | [diff] [blame] | 823 | set "$@" OPENSSL="$OPENSSL" |
Gilles Peskine | cc9f0b9 | 2019-01-06 22:46:21 +0000 | [diff] [blame] | 824 | set "$@" GNUTLS_CLI="$GNUTLS_CLI" GNUTLS_SERV="$GNUTLS_SERV" |
Gilles Peskine | 7be571a | 2023-08-27 21:39:21 +0200 | [diff] [blame] | 825 | check_tools "$OPENSSL" "$OPENSSL_NEXT" \ |
| 826 | "$GNUTLS_CLI" "$GNUTLS_SERV" |
Gilles Peskine | 8796426 | 2019-01-06 22:40:00 +0000 | [diff] [blame] | 827 | ;; |
| 828 | esac |
Manuel Pégourié-Gonnard | 57255b1 | 2014-06-09 11:21:49 +0200 | [diff] [blame] | 829 | |
Gilles Peskine | 8796426 | 2019-01-06 22:40:00 +0000 | [diff] [blame] | 830 | case " $RUN_COMPONENTS " in |
| 831 | *_doxygen[_\ ]*) check_tools "doxygen" "dot";; |
| 832 | esac |
Andres AG | d9eba4b | 2016-08-26 14:42:14 +0100 | [diff] [blame] | 833 | |
Gilles Peskine | 8796426 | 2019-01-06 22:40:00 +0000 | [diff] [blame] | 834 | case " $RUN_COMPONENTS " in |
Gilles Peskine | 6d06134 | 2020-04-30 18:19:32 +0200 | [diff] [blame] | 835 | *_arm_none_eabi_gcc[_\ ]*) check_tools "${ARM_NONE_EABI_GCC_PREFIX}gcc";; |
Gilles Peskine | 8796426 | 2019-01-06 22:40:00 +0000 | [diff] [blame] | 836 | esac |
Andres AG | d9eba4b | 2016-08-26 14:42:14 +0100 | [diff] [blame] | 837 | |
Gilles Peskine | 8796426 | 2019-01-06 22:40:00 +0000 | [diff] [blame] | 838 | case " $RUN_COMPONENTS " in |
| 839 | *_mingw[_\ ]*) check_tools "i686-w64-mingw32-gcc";; |
| 840 | esac |
| 841 | |
| 842 | case " $RUN_COMPONENTS " in |
| 843 | *" test_zeroize "*) check_tools "gdb";; |
| 844 | esac |
| 845 | |
| 846 | case " $RUN_COMPONENTS " in |
Gilles Peskine | 5331c6e | 2019-01-06 22:23:42 +0000 | [diff] [blame] | 847 | *_armcc*) |
Gilles Peskine | 8796426 | 2019-01-06 22:40:00 +0000 | [diff] [blame] | 848 | ARMC5_CC="$ARMC5_BIN_DIR/armcc" |
| 849 | ARMC5_AR="$ARMC5_BIN_DIR/armar" |
Gilles Peskine | 18487f6 | 2020-04-30 23:11:54 +0200 | [diff] [blame] | 850 | ARMC5_FROMELF="$ARMC5_BIN_DIR/fromelf" |
Gilles Peskine | 8796426 | 2019-01-06 22:40:00 +0000 | [diff] [blame] | 851 | ARMC6_CC="$ARMC6_BIN_DIR/armclang" |
| 852 | ARMC6_AR="$ARMC6_BIN_DIR/armar" |
Gilles Peskine | 18487f6 | 2020-04-30 23:11:54 +0200 | [diff] [blame] | 853 | ARMC6_FROMELF="$ARMC6_BIN_DIR/fromelf" |
| 854 | check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC5_FROMELF" \ |
| 855 | "$ARMC6_CC" "$ARMC6_AR" "$ARMC6_FROMELF";; |
Gilles Peskine | 5331c6e | 2019-01-06 22:23:42 +0000 | [diff] [blame] | 856 | esac |
Gilles Peskine | cc9f0b9 | 2019-01-06 22:46:21 +0000 | [diff] [blame] | 857 | |
Manuel Pégourié-Gonnard | 2b2bdaa | 2020-06-02 11:28:07 +0200 | [diff] [blame] | 858 | # past this point, no call to check_tool, only printing output |
| 859 | if [ $QUIET -eq 1 ]; then |
| 860 | return |
| 861 | fi |
| 862 | |
Gilles Peskine | cc9f0b9 | 2019-01-06 22:46:21 +0000 | [diff] [blame] | 863 | msg "info: output_env.sh" |
| 864 | case $RUN_COMPONENTS in |
| 865 | *_armcc*) |
| 866 | set "$@" ARMC5_CC="$ARMC5_CC" ARMC6_CC="$ARMC6_CC" RUN_ARMCC=1;; |
| 867 | *) set "$@" RUN_ARMCC=0;; |
| 868 | esac |
| 869 | "$@" scripts/output_env.sh |
Gilles Peskine | 8f07312 | 2018-11-27 15:58:47 +0100 | [diff] [blame] | 870 | } |
Manuel Pégourié-Gonnard | 9bda9b3 | 2014-11-20 13:10:22 +0100 | [diff] [blame] | 871 | |
Manuel Pégourié-Gonnard | c974134 | 2024-10-16 10:06:15 +0200 | [diff] [blame] | 872 | pre_generate_files() { |
Manuel Pégourié-Gonnard | 87db8a2 | 2021-06-18 13:30:14 +0200 | [diff] [blame] | 873 | # since make doesn't have proper dependencies, remove any possibly outdate |
| 874 | # file that might be around before generating fresh ones |
| 875 | make neat |
Gilles Peskine | 7238503 | 2021-07-08 19:07:07 +0200 | [diff] [blame] | 876 | if [ $QUIET -eq 1 ]; then |
Gilles Peskine | 7530163 | 2021-08-05 15:10:47 +0200 | [diff] [blame] | 877 | make generated_files >/dev/null |
Gilles Peskine | 7238503 | 2021-07-08 19:07:07 +0200 | [diff] [blame] | 878 | else |
| 879 | make generated_files |
| 880 | fi |
Gilles Peskine | 1570b59 | 2021-04-22 01:10:12 +0200 | [diff] [blame] | 881 | } |
| 882 | |
Manuel Pégourié-Gonnard | c974134 | 2024-10-16 10:06:15 +0200 | [diff] [blame] | 883 | clang_version() { |
Tom Cosgrove | d4c373a | 2024-01-30 13:56:38 +0000 | [diff] [blame] | 884 | if command -v clang > /dev/null ; then |
| 885 | clang --version|grep version|sed -E 's#.*version ([0-9]+).*#\1#' |
| 886 | else |
| 887 | echo 0 # report version 0 for "no clang" |
| 888 | fi |
| 889 | } |
| 890 | |
Manuel Pégourié-Gonnard | 27e1767 | 2023-05-25 09:39:08 +0200 | [diff] [blame] | 891 | ################################################################ |
| 892 | #### Helpers for components using libtestdriver1 |
| 893 | ################################################################ |
Gilles Peskine | 192c72f | 2017-12-21 15:59:21 +0100 | [diff] [blame] | 894 | |
Manuel Pégourié-Gonnard | f5c5d97 | 2023-06-06 11:14:57 +0200 | [diff] [blame] | 895 | # How to use libtestdriver1 |
| 896 | # ------------------------- |
| 897 | # |
| 898 | # 1. Define the list algorithms and key types to accelerate, |
| 899 | # designated the same way as PSA_WANT_ macros but without PSA_WANT_. |
| 900 | # Examples: |
| 901 | # - loc_accel_list="ALG_JPAKE" |
| 902 | # - loc_accel_list="ALG_FFDH KEY_TYPE_DH_KEY_PAIR KEY_TYPE_DH_PUBLIC_KEY" |
Manuel Pégourié-Gonnard | 8df87bf | 2023-06-12 17:09:38 +0200 | [diff] [blame] | 903 | # 2. Make configurations changes for the driver and/or main libraries. |
| 904 | # 2a. Call helper_libtestdriver1_adjust_config <base>, where the argument |
| 905 | # can be either "default" to start with the default config, or a name |
| 906 | # supported by scripts/config.py (for example, "full"). This selects |
Manuel Pégourié-Gonnard | 2336c8e | 2023-06-12 17:17:54 +0200 | [diff] [blame] | 907 | # the base to use, and makes common adjustments. |
Manuel Pégourié-Gonnard | 8df87bf | 2023-06-12 17:09:38 +0200 | [diff] [blame] | 908 | # 2b. If desired, adjust the PSA_WANT symbols in psa/crypto_config.h. |
| 909 | # These changes affect both the driver and the main libraries. |
| 910 | # (Note: they need to have the same set of PSA_WANT symbols, as that |
| 911 | # determines the ABI between them.) |
| 912 | # 2c. Adjust MBEDTLS_ symbols in mbedtls_config.h. This only affects the |
| 913 | # main libraries. Typically, you want to disable the module(s) that are |
| 914 | # being accelerated. You may need to also disable modules that depend |
| 915 | # on them or options that are not supported with drivers. |
| 916 | # 2d. On top of psa/crypto_config.h, the driver library uses its own config |
| 917 | # file: tests/include/test/drivers/config_test_driver.h. You usually |
| 918 | # don't need to edit it: using loc_extra_list (see below) is preferred. |
| 919 | # However, when there's no PSA symbol for what you want to enable, |
| 920 | # calling scripts/config.py on this file remains the only option. |
| 921 | # 3. Build the driver library, then the main libraries, test, and programs. |
| 922 | # 3a. Call helper_libtestdriver1_make_drivers "$loc_accel_list". You may |
| 923 | # need to enable more algorithms here, typically hash algorithms when |
| 924 | # accelerating some signature algorithms (ECDSA, RSAv2). This is done |
| 925 | # by passing a 2nd argument listing the extra algorithms. |
| 926 | # Example: |
| 927 | # loc_extra_list="ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512" |
| 928 | # helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list" |
Yanray Wang | 0df6d96 | 2023-10-11 13:27:25 +0800 | [diff] [blame] | 929 | # 3b. Call helper_libtestdriver1_make_main "$loc_accel_list". Any |
Manuel Pégourié-Gonnard | 8df87bf | 2023-06-12 17:09:38 +0200 | [diff] [blame] | 930 | # additional arguments will be passed to make: this can be useful if |
| 931 | # you don't want to build everything when iterating during development. |
| 932 | # Example: |
| 933 | # helper_libtestdriver1_make_main "$loc_accel_list" -C tests test_suite_foo |
| 934 | # 4. Run the tests you want. |
Manuel Pégourié-Gonnard | f5c5d97 | 2023-06-06 11:14:57 +0200 | [diff] [blame] | 935 | |
Manuel Pégourié-Gonnard | 27e1767 | 2023-05-25 09:39:08 +0200 | [diff] [blame] | 936 | # Adjust the configuration - for both libtestdriver1 and main library, |
| 937 | # as they should have the same PSA_WANT macros. |
Manuel Pégourié-Gonnard | c974134 | 2024-10-16 10:06:15 +0200 | [diff] [blame] | 938 | helper_libtestdriver1_adjust_config() { |
Manuel Pégourié-Gonnard | 6be64f7 | 2023-09-28 09:08:04 +0200 | [diff] [blame] | 939 | base_config=$1 |
Manuel Pégourié-Gonnard | 8df87bf | 2023-06-12 17:09:38 +0200 | [diff] [blame] | 940 | # Select the base configuration |
Manuel Pégourié-Gonnard | 6be64f7 | 2023-09-28 09:08:04 +0200 | [diff] [blame] | 941 | if [ "$base_config" != "default" ]; then |
| 942 | scripts/config.py "$base_config" |
Manuel Pégourié-Gonnard | 8df87bf | 2023-06-12 17:09:38 +0200 | [diff] [blame] | 943 | fi |
| 944 | |
| 945 | # Enable PSA-based config (necessary to use drivers) |
| 946 | scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG |
| 947 | |
Manuel Pégourié-Gonnard | 2336c8e | 2023-06-12 17:17:54 +0200 | [diff] [blame] | 948 | # Dynamic secure element support is a deprecated feature and needs to be disabled here. |
| 949 | # This is done to have the same form of psa_key_attributes_s for libdriver and library. |
| 950 | scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C |
Paul Elliott | 053b788 | 2024-03-05 11:46:32 +0000 | [diff] [blame] | 951 | |
| 952 | # If threading is enabled on the normal build, then we need to enable it in the drivers as well, |
| 953 | # otherwise we will end up running multithreaded tests without mutexes to protect them. |
| 954 | if scripts/config.py get MBEDTLS_THREADING_C; then |
| 955 | scripts/config.py -f "$CONFIG_TEST_DRIVER_H" set MBEDTLS_THREADING_C |
| 956 | fi |
| 957 | |
| 958 | if scripts/config.py get MBEDTLS_THREADING_PTHREAD; then |
| 959 | scripts/config.py -f "$CONFIG_TEST_DRIVER_H" set MBEDTLS_THREADING_PTHREAD |
| 960 | fi |
Manuel Pégourié-Gonnard | 27e1767 | 2023-05-25 09:39:08 +0200 | [diff] [blame] | 961 | } |
Gilles Peskine | 192c72f | 2017-12-21 15:59:21 +0100 | [diff] [blame] | 962 | |
Manuel Pégourié-Gonnard | 7955091 | 2024-10-16 10:09:08 +0200 | [diff] [blame] | 963 | # Build the drivers library libtestdriver1.a (with ASan). |
| 964 | # |
| 965 | # Parameters: |
| 966 | # 1. a space-separated list of things to accelerate; |
| 967 | # 2. optional: a space-separate list of things to also support. |
| 968 | # Here "things" are PSA_WANT_ symbols but with PSA_WANT_ removed. |
| 969 | helper_libtestdriver1_make_drivers() { |
| 970 | loc_accel_flags=$( echo "$1 ${2-}" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' ) |
| 971 | make CC=$ASAN_CC -C tests libtestdriver1.a CFLAGS=" $ASAN_CFLAGS $loc_accel_flags" LDFLAGS="$ASAN_CFLAGS" |
| 972 | } |
| 973 | |
| 974 | # Build the main libraries, programs and tests, |
| 975 | # linking to the drivers library (with ASan). |
| 976 | # |
| 977 | # Parameters: |
| 978 | # 1. a space-separated list of things to accelerate; |
| 979 | # *. remaining arguments if any are passed directly to make |
| 980 | # (examples: lib, -C tests test_suite_xxx, etc.) |
| 981 | # Here "things" are PSA_WANT_ symbols but with PSA_WANT_ removed. |
| 982 | helper_libtestdriver1_make_main() { |
| 983 | loc_accel_list=$1 |
| 984 | shift |
| 985 | |
| 986 | # we need flags both with and without the LIBTESTDRIVER1_ prefix |
| 987 | loc_accel_flags=$( echo "$loc_accel_list" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' ) |
| 988 | loc_accel_flags="$loc_accel_flags $( echo "$loc_accel_list" | sed 's/[^ ]* */-DMBEDTLS_PSA_ACCEL_&/g' )" |
| 989 | make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -I../tests/include -I../tests -I../../tests -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_TEST_LIBTESTDRIVER1 $loc_accel_flags" LDFLAGS="-ltestdriver1 $ASAN_CFLAGS" "$@" |
| 990 | } |
| 991 | |
Manuel Pégourié-Gonnard | 8535f4c | 2024-10-16 10:14:49 +0200 | [diff] [blame] | 992 | # Set some default values $CONFIG_H in order to build server or client sides |
| 993 | # in PSASIM. There is only 1 mandatory parameter: |
| 994 | # - $1: target which can be "client" or "server" |
| 995 | helper_psasim_config() { |
| 996 | TARGET=$1 |
| 997 | |
| 998 | if [ "$TARGET" == "client" ]; then |
| 999 | scripts/config.py full |
| 1000 | scripts/config.py unset MBEDTLS_PSA_CRYPTO_C |
| 1001 | scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C |
| 1002 | # Dynamic secure element support is a deprecated feature and it is not |
| 1003 | # available when CRYPTO_C and PSA_CRYPTO_STORAGE_C are disabled. |
| 1004 | scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C |
| 1005 | # Disable potentially problematic features |
| 1006 | scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT |
| 1007 | scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED |
| 1008 | scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED |
| 1009 | scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED |
| 1010 | scripts/config.py unset MBEDTLS_ECP_RESTARTABLE |
| 1011 | scripts/config.py unset MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER |
| 1012 | else |
| 1013 | scripts/config.py crypto_full |
| 1014 | scripts/config.py unset MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS |
| 1015 | # We need to match the client with MBEDTLS_PSA_CRYPTO_SE_C |
| 1016 | scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C |
| 1017 | # Also ensure MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER not set (to match client) |
| 1018 | scripts/config.py unset MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER |
| 1019 | fi |
| 1020 | } |
| 1021 | |
| 1022 | # Helper to build the libraries for client/server in PSASIM. If the server is |
| 1023 | # being built, then it builds also the final executable. |
| 1024 | # There is only 1 mandatory parameter: |
| 1025 | # - $1: target which can be "client" or "server" |
| 1026 | helper_psasim_build() { |
| 1027 | TARGET=$1 |
| 1028 | shift |
| 1029 | TARGET_LIB=${TARGET}_libs |
| 1030 | |
| 1031 | make -C $PSASIM_PATH CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS" $TARGET_LIB "$@" |
| 1032 | |
| 1033 | # Build also the server application after its libraries have been built. |
| 1034 | if [ "$TARGET" == "server" ]; then |
| 1035 | make -C $PSASIM_PATH CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS" test/psa_server |
| 1036 | fi |
| 1037 | } |
| 1038 | |
| 1039 | ################################################################ |
| 1040 | #### Configuration helpers |
| 1041 | ################################################################ |
| 1042 | |
Valerio Setti | b2fd673 | 2023-08-15 17:10:47 +0200 | [diff] [blame] | 1043 | # When called with no parameter this function disables all builtin curves. |
Valerio Setti | 4ca250b | 2023-09-04 14:01:41 +0200 | [diff] [blame] | 1044 | # The function optionally accepts 1 parameter: a space-separated list of the |
| 1045 | # curves that should be kept enabled. |
Manuel Pégourié-Gonnard | c974134 | 2024-10-16 10:06:15 +0200 | [diff] [blame] | 1046 | helper_disable_builtin_curves() { |
Valerio Setti | b2fd673 | 2023-08-15 17:10:47 +0200 | [diff] [blame] | 1047 | allowed_list="${1:-}" |
| 1048 | scripts/config.py unset-all "MBEDTLS_ECP_DP_[0-9A-Z_a-z]*_ENABLED" |
| 1049 | |
Manuel Pégourié-Gonnard | 6be64f7 | 2023-09-28 09:08:04 +0200 | [diff] [blame] | 1050 | for curve in $allowed_list; do |
| 1051 | scripts/config.py set $curve |
Valerio Setti | b2fd673 | 2023-08-15 17:10:47 +0200 | [diff] [blame] | 1052 | done |
| 1053 | } |
| 1054 | |
| 1055 | # Helper returning the list of supported elliptic curves from CRYPTO_CONFIG_H, |
| 1056 | # without the "PSA_WANT_" prefix. This becomes handy for accelerating curves |
| 1057 | # in the following helpers. |
| 1058 | helper_get_psa_curve_list () { |
| 1059 | loc_list="" |
Manuel Pégourié-Gonnard | 6be64f7 | 2023-09-28 09:08:04 +0200 | [diff] [blame] | 1060 | for item in $(sed -n 's/^#define PSA_WANT_\(ECC_[0-9A-Z_a-z]*\).*/\1/p' <"$CRYPTO_CONFIG_H"); do |
| 1061 | loc_list="$loc_list $item" |
Valerio Setti | b2fd673 | 2023-08-15 17:10:47 +0200 | [diff] [blame] | 1062 | done |
| 1063 | |
| 1064 | echo "$loc_list" |
| 1065 | } |
| 1066 | |
Valerio Setti | 78aa0bc | 2024-01-17 15:53:46 +0100 | [diff] [blame] | 1067 | # Helper returning the list of supported DH groups from CRYPTO_CONFIG_H, |
| 1068 | # without the "PSA_WANT_" prefix. This becomes handy for accelerating DH groups |
| 1069 | # in the following helpers. |
| 1070 | helper_get_psa_dh_group_list () { |
| 1071 | loc_list="" |
| 1072 | for item in $(sed -n 's/^#define PSA_WANT_\(DH_RFC7919_[0-9]*\).*/\1/p' <"$CRYPTO_CONFIG_H"); do |
| 1073 | loc_list="$loc_list $item" |
| 1074 | done |
| 1075 | |
| 1076 | echo "$loc_list" |
| 1077 | } |
| 1078 | |
Valerio Setti | b2fd673 | 2023-08-15 17:10:47 +0200 | [diff] [blame] | 1079 | # Get the list of uncommented PSA_WANT_KEY_TYPE_xxx_ from CRYPTO_CONFIG_H. This |
Valerio Setti | 0a342c9 | 2023-09-01 09:12:31 +0200 | [diff] [blame] | 1080 | # is useful to easily get a list of key type symbols to accelerate. |
Valerio Setti | b2fd673 | 2023-08-15 17:10:47 +0200 | [diff] [blame] | 1081 | # The function accepts a single argument which is the key type: ECC, DH, RSA. |
Manuel Pégourié-Gonnard | c974134 | 2024-10-16 10:06:15 +0200 | [diff] [blame] | 1082 | helper_get_psa_key_type_list() { |
Manuel Pégourié-Gonnard | 6be64f7 | 2023-09-28 09:08:04 +0200 | [diff] [blame] | 1083 | key_type="$1" |
Valerio Setti | b2fd673 | 2023-08-15 17:10:47 +0200 | [diff] [blame] | 1084 | loc_list="" |
Manuel Pégourié-Gonnard | 6be64f7 | 2023-09-28 09:08:04 +0200 | [diff] [blame] | 1085 | for item in $(sed -n "s/^#define PSA_WANT_\(KEY_TYPE_${key_type}_[0-9A-Z_a-z]*\).*/\1/p" <"$CRYPTO_CONFIG_H"); do |
Valerio Setti | b2fd673 | 2023-08-15 17:10:47 +0200 | [diff] [blame] | 1086 | # Skip DERIVE for elliptic keys since there is no driver dispatch for |
| 1087 | # it so it cannot be accelerated. |
Manuel Pégourié-Gonnard | 6be64f7 | 2023-09-28 09:08:04 +0200 | [diff] [blame] | 1088 | if [ "$item" != "KEY_TYPE_ECC_KEY_PAIR_DERIVE" ]; then |
| 1089 | loc_list="$loc_list $item" |
Valerio Setti | b2fd673 | 2023-08-15 17:10:47 +0200 | [diff] [blame] | 1090 | fi |
| 1091 | done |
| 1092 | |
| 1093 | echo "$loc_list" |
| 1094 | } |
| 1095 | |
Manuel Pégourié-Gonnard | 2c3a624 | 2024-10-01 11:54:34 +0200 | [diff] [blame] | 1096 | # Must be called before pre_initialize_variables which sets ALL_COMPONENTS. |
| 1097 | pre_load_components () { |
| 1098 | # Include the components from components.sh |
| 1099 | test_script_dir="${0%/*}" |
| 1100 | for file in "$test_script_dir"/components*.sh; do |
| 1101 | source $file |
| 1102 | done |
| 1103 | } |
Jerry Yu | d767cc4 | 2023-03-31 15:03:55 +0800 | [diff] [blame] | 1104 | |
Manuel Pégourié-Gonnard | c974134 | 2024-10-16 10:06:15 +0200 | [diff] [blame] | 1105 | |
Gilles Peskine | 192c72f | 2017-12-21 15:59:21 +0100 | [diff] [blame] | 1106 | ################################################################ |
| 1107 | #### Termination |
| 1108 | ################################################################ |
| 1109 | |
Gilles Peskine | 8f07312 | 2018-11-27 15:58:47 +0100 | [diff] [blame] | 1110 | post_report () { |
| 1111 | msg "Done, cleaning up" |
Gilles Peskine | f83eb82 | 2020-03-30 20:11:39 +0200 | [diff] [blame] | 1112 | final_cleanup |
Manuel Pégourié-Gonnard | 80955ee | 2014-03-19 18:29:01 +0100 | [diff] [blame] | 1113 | |
Gilles Peskine | 8f07312 | 2018-11-27 15:58:47 +0100 | [diff] [blame] | 1114 | final_report |
| 1115 | } |
| 1116 | |
Gilles Peskine | 8f07312 | 2018-11-27 15:58:47 +0100 | [diff] [blame] | 1117 | ################################################################ |
| 1118 | #### Run all the things |
| 1119 | ################################################################ |
| 1120 | |
Gilles Peskine | 5d99682 | 2020-03-28 21:09:21 +0100 | [diff] [blame] | 1121 | # Function invoked by --error-test to test error reporting. |
| 1122 | pseudo_component_error_test () { |
Gilles Peskine | 88a7c2b | 2021-08-02 23:28:00 +0200 | [diff] [blame] | 1123 | msg "Testing error reporting $error_test_i" |
Gilles Peskine | 5d99682 | 2020-03-28 21:09:21 +0100 | [diff] [blame] | 1124 | if [ $KEEP_GOING -ne 0 ]; then |
| 1125 | echo "Expect three failing commands." |
| 1126 | fi |
Gilles Peskine | 88a7c2b | 2021-08-02 23:28:00 +0200 | [diff] [blame] | 1127 | # If the component doesn't run in a subshell, changing error_test_i to an |
| 1128 | # invalid integer will cause an error in the loop that runs this function. |
| 1129 | error_test_i=this_should_not_be_used_since_the_component_runs_in_a_subshell |
Gilles Peskine | ec13554 | 2021-08-02 23:14:03 +0200 | [diff] [blame] | 1130 | # Expected error: 'grep non_existent /dev/null -> 1' |
Gilles Peskine | 5d99682 | 2020-03-28 21:09:21 +0100 | [diff] [blame] | 1131 | grep non_existent /dev/null |
Gilles Peskine | ec13554 | 2021-08-02 23:14:03 +0200 | [diff] [blame] | 1132 | # Expected error: '! grep -q . tests/scripts/all.sh -> 1' |
Gilles Peskine | 5d99682 | 2020-03-28 21:09:21 +0100 | [diff] [blame] | 1133 | not grep -q . "$0" |
Gilles Peskine | ec13554 | 2021-08-02 23:14:03 +0200 | [diff] [blame] | 1134 | # Expected error: 'make unknown_target -> 2' |
Gilles Peskine | 5d99682 | 2020-03-28 21:09:21 +0100 | [diff] [blame] | 1135 | make unknown_target |
| 1136 | false "this should not be executed" |
| 1137 | } |
| 1138 | |
Gilles Peskine | e48351a | 2018-11-27 16:06:30 +0100 | [diff] [blame] | 1139 | # Run one component and clean up afterwards. |
Gilles Peskine | 8f07312 | 2018-11-27 15:58:47 +0100 | [diff] [blame] | 1140 | run_component () { |
Gilles Peskine | ffcdeff | 2018-12-04 12:49:28 +0100 | [diff] [blame] | 1141 | current_component="$1" |
Gilles Peskine | 9004a17 | 2019-09-16 15:20:36 +0200 | [diff] [blame] | 1142 | export MBEDTLS_TEST_CONFIGURATION="$current_component" |
Gilles Peskine | 2ef377d | 2019-10-07 18:44:21 +0200 | [diff] [blame] | 1143 | |
| 1144 | # Unconditionally create a seedfile that's sufficiently long. |
| 1145 | # Do this before each component, because a previous component may |
| 1146 | # have messed it up or shortened it. |
Gilles Peskine | 88a0745 | 2021-07-08 19:03:50 +0200 | [diff] [blame] | 1147 | local dd_cmd |
| 1148 | dd_cmd=(dd if=/dev/urandom of=./tests/seedfile bs=64 count=1) |
| 1149 | case $OSTYPE in |
Tom Cosgrove | 226aca1 | 2022-03-16 14:11:07 +0000 | [diff] [blame] | 1150 | linux*|freebsd*|openbsd*) dd_cmd+=(status=none) |
Gilles Peskine | 88a0745 | 2021-07-08 19:03:50 +0200 | [diff] [blame] | 1151 | esac |
| 1152 | "${dd_cmd[@]}" |
Gilles Peskine | 2ef377d | 2019-10-07 18:44:21 +0200 | [diff] [blame] | 1153 | |
Manuel Pégourié-Gonnard | 6c0c0f2 | 2024-10-16 10:12:00 +0200 | [diff] [blame] | 1154 | if [ -d tf-psa-crypto ]; then |
| 1155 | dd_cmd=(dd if=/dev/urandom of=./tf-psa-crypto/tests/seedfile bs=64 count=1) |
| 1156 | case $OSTYPE in |
| 1157 | linux*|freebsd*|openbsd*) dd_cmd+=(status=none) |
| 1158 | esac |
| 1159 | "${dd_cmd[@]}" |
| 1160 | fi |
| 1161 | |
Gilles Peskine | ec13554 | 2021-08-02 23:14:03 +0200 | [diff] [blame] | 1162 | # Run the component in a subshell, with error trapping and output |
| 1163 | # redirection set up based on the relevant options. |
Gilles Peskine | ce266c4 | 2020-03-28 18:50:43 +0100 | [diff] [blame] | 1164 | if [ $KEEP_GOING -eq 1 ]; then |
Gilles Peskine | ec13554 | 2021-08-02 23:14:03 +0200 | [diff] [blame] | 1165 | # We want to keep running if the subshell fails, so 'set -e' must |
| 1166 | # be off when the subshell runs. |
Gilles Peskine | ce266c4 | 2020-03-28 18:50:43 +0100 | [diff] [blame] | 1167 | set +e |
Manuel Pégourié-Gonnard | 2b2bdaa | 2020-06-02 11:28:07 +0200 | [diff] [blame] | 1168 | fi |
Gilles Peskine | ce266c4 | 2020-03-28 18:50:43 +0100 | [diff] [blame] | 1169 | ( |
| 1170 | if [ $QUIET -eq 1 ]; then |
| 1171 | # msg() will be silenced, so just print the component name here. |
| 1172 | echo "${current_component#component_}" |
| 1173 | exec >/dev/null |
| 1174 | fi |
| 1175 | if [ $KEEP_GOING -eq 1 ]; then |
| 1176 | # Keep "set -e" off, and run an ERR trap instead to record failures. |
| 1177 | set -E |
| 1178 | trap err_trap ERR |
| 1179 | fi |
| 1180 | # The next line is what runs the component |
| 1181 | "$@" |
| 1182 | if [ $KEEP_GOING -eq 1 ]; then |
| 1183 | trap - ERR |
| 1184 | exit $last_failure_status |
| 1185 | fi |
| 1186 | ) |
| 1187 | component_status=$? |
| 1188 | if [ $KEEP_GOING -eq 1 ]; then |
| 1189 | set -e |
| 1190 | if [ $component_status -ne 0 ]; then |
| 1191 | failure_count=$((failure_count + 1)) |
| 1192 | fi |
| 1193 | fi |
Gilles Peskine | 2ef377d | 2019-10-07 18:44:21 +0200 | [diff] [blame] | 1194 | |
| 1195 | # Restore the build tree to a clean state. |
Gilles Peskine | e48351a | 2018-11-27 16:06:30 +0100 | [diff] [blame] | 1196 | cleanup |
Manuel Pégourié-Gonnard | 304b099 | 2020-06-08 10:59:41 +0200 | [diff] [blame] | 1197 | unset current_component |
Gilles Peskine | 8f07312 | 2018-11-27 15:58:47 +0100 | [diff] [blame] | 1198 | } |
| 1199 | |
Manuel Pégourié-Gonnard | 2c3a624 | 2024-10-01 11:54:34 +0200 | [diff] [blame] | 1200 | ################################################################ |
| 1201 | #### Main (only function definitions above) |
| 1202 | ################################################################ |
| 1203 | |
| 1204 | |
Gilles Peskine | 8f07312 | 2018-11-27 15:58:47 +0100 | [diff] [blame] | 1205 | # Preliminary setup |
Manuel Pégourié-Gonnard | 2c3a624 | 2024-10-01 11:54:34 +0200 | [diff] [blame] | 1206 | pre_set_shell_options |
Gilles Peskine | 8f07312 | 2018-11-27 15:58:47 +0100 | [diff] [blame] | 1207 | pre_check_environment |
Manuel Pégourié-Gonnard | 2c3a624 | 2024-10-01 11:54:34 +0200 | [diff] [blame] | 1208 | pre_load_components |
Gilles Peskine | 8f07312 | 2018-11-27 15:58:47 +0100 | [diff] [blame] | 1209 | pre_initialize_variables |
| 1210 | pre_parse_command_line "$@" |
Gilles Peskine | 348fb9a | 2018-11-27 17:04:29 +0100 | [diff] [blame] | 1211 | |
Dave Rodgman | 2190063 | 2024-02-26 11:41:19 +0000 | [diff] [blame] | 1212 | setup_quiet_wrappers |
Gilles Peskine | 878cf60 | 2019-01-06 20:50:38 +0000 | [diff] [blame] | 1213 | pre_check_git |
Gilles Peskine | 568f53a | 2021-07-12 18:16:01 +0200 | [diff] [blame] | 1214 | pre_restore_files |
Gilles Peskine | f83eb82 | 2020-03-30 20:11:39 +0200 | [diff] [blame] | 1215 | pre_back_up |
Andrzej Kurek | eb50871 | 2019-02-14 07:18:59 -0500 | [diff] [blame] | 1216 | |
Gilles Peskine | 878cf60 | 2019-01-06 20:50:38 +0000 | [diff] [blame] | 1217 | build_status=0 |
| 1218 | if [ $KEEP_GOING -eq 1 ]; then |
| 1219 | pre_setup_keep_going |
Gilles Peskine | 8f07312 | 2018-11-27 15:58:47 +0100 | [diff] [blame] | 1220 | fi |
Gilles Peskine | 67ffdaf | 2019-09-16 15:55:46 +0200 | [diff] [blame] | 1221 | pre_prepare_outcome_file |
Gilles Peskine | 878cf60 | 2019-01-06 20:50:38 +0000 | [diff] [blame] | 1222 | pre_print_configuration |
| 1223 | pre_check_tools |
Manuel Pégourié-Gonnard | 80955ee | 2014-03-19 18:29:01 +0100 | [diff] [blame] | 1224 | cleanup |
David Horstmann | 76a7738 | 2023-08-17 17:32:26 +0100 | [diff] [blame] | 1225 | if in_mbedtls_repo; then |
David Horstmann | 9a6c45b | 2023-07-14 12:30:00 +0100 | [diff] [blame] | 1226 | pre_generate_files |
| 1227 | fi |
Manuel Pégourié-Gonnard | 80955ee | 2014-03-19 18:29:01 +0100 | [diff] [blame] | 1228 | |
Gilles Peskine | beb3a81 | 2019-01-06 22:11:25 +0000 | [diff] [blame] | 1229 | # Run the requested tests. |
Gilles Peskine | 88a7c2b | 2021-08-02 23:28:00 +0200 | [diff] [blame] | 1230 | for ((error_test_i=1; error_test_i <= error_test; error_test_i++)); do |
Gilles Peskine | 5d99682 | 2020-03-28 21:09:21 +0100 | [diff] [blame] | 1231 | run_component pseudo_component_error_test |
Gilles Peskine | 5d99682 | 2020-03-28 21:09:21 +0100 | [diff] [blame] | 1232 | done |
Gilles Peskine | 88a7c2b | 2021-08-02 23:28:00 +0200 | [diff] [blame] | 1233 | unset error_test_i |
Gilles Peskine | beb3a81 | 2019-01-06 22:11:25 +0000 | [diff] [blame] | 1234 | for component in $RUN_COMPONENTS; do |
| 1235 | run_component "component_$component" |
| 1236 | done |
Gilles Peskine | 8f07312 | 2018-11-27 15:58:47 +0100 | [diff] [blame] | 1237 | |
| 1238 | # We're done. |
Gilles Peskine | 878cf60 | 2019-01-06 20:50:38 +0000 | [diff] [blame] | 1239 | post_report |