2020-03-27 16:35:23 +01:00
|
|
|
#! /usr/bin/env bash
|
2014-03-19 18:29:01 +01:00
|
|
|
|
2016-03-07 23:22:10 +00:00
|
|
|
# all.sh
|
|
|
|
#
|
2020-08-07 13:07:28 +02:00
|
|
|
# Copyright The Mbed TLS Contributors
|
2023-11-02 19:47:20 +00:00
|
|
|
# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
|
2017-12-21 15:59:21 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
################################################################
|
|
|
|
#### Documentation
|
|
|
|
################################################################
|
|
|
|
|
2016-03-07 23:22:10 +00:00
|
|
|
# Purpose
|
2017-12-21 15:59:21 +01:00
|
|
|
# -------
|
2016-03-07 23:22:10 +00:00
|
|
|
#
|
2016-04-16 21:54:39 +01:00
|
|
|
# To run all tests possible or available on the platform.
|
2014-03-19 18:29:01 +01:00
|
|
|
#
|
2017-12-21 15:59:21 +01:00
|
|
|
# Notes for users
|
|
|
|
# ---------------
|
|
|
|
#
|
2016-04-16 21:54:39 +01:00
|
|
|
# Warning: the test is destructive. It includes various build modes and
|
|
|
|
# configurations, and can and will arbitrarily change the current CMake
|
2017-12-21 15:59:21 +01:00
|
|
|
# configuration. The following files must be committed into git:
|
2021-05-28 09:42:25 +02:00
|
|
|
# * include/mbedtls/mbedtls_config.h
|
2020-03-04 20:46:15 +01:00
|
|
|
# * Makefile, library/Makefile, programs/Makefile, tests/Makefile,
|
|
|
|
# programs/fuzz/Makefile
|
2017-12-21 15:59:21 +01:00
|
|
|
# After running this script, the CMake cache will be lost and CMake
|
|
|
|
# will no longer be initialised.
|
|
|
|
#
|
|
|
|
# The script assumes the presence of a number of tools:
|
|
|
|
# * Basic Unix tools (Windows users note: a Unix-style find must be before
|
|
|
|
# the Windows find in the PATH)
|
|
|
|
# * Perl
|
|
|
|
# * GNU Make
|
|
|
|
# * CMake
|
|
|
|
# * GCC and Clang (recent enough for using ASan with gcc and MemSan with clang, or valgrind)
|
2018-06-28 04:41:50 -04:00
|
|
|
# * G++
|
2017-12-21 15:59:21 +01:00
|
|
|
# * arm-gcc and mingw-gcc
|
|
|
|
# * ArmCC 5 and ArmCC 6, unless invoked with --no-armcc
|
2023-08-27 21:39:21 +02:00
|
|
|
# * OpenSSL and GnuTLS command line tools, in suitable versions for the
|
|
|
|
# interoperability tests. The following are the official versions at the
|
|
|
|
# time of writing:
|
|
|
|
# * GNUTLS_{CLI,SERV} = 3.4.10
|
|
|
|
# * GNUTLS_NEXT_{CLI,SERV} = 3.7.2
|
|
|
|
# * OPENSSL = 1.0.2g (without Debian/Ubuntu patches)
|
2024-04-02 14:39:53 +02:00
|
|
|
# * OPENSSL_NEXT = 3.1.2
|
2017-12-21 15:59:21 +01:00
|
|
|
# See the invocation of check_tools below for details.
|
|
|
|
#
|
|
|
|
# This script must be invoked from the toplevel directory of a git
|
|
|
|
# working copy of Mbed TLS.
|
|
|
|
#
|
2020-03-28 18:50:43 +01:00
|
|
|
# The behavior on an error depends on whether --keep-going (alias -k)
|
|
|
|
# is in effect.
|
|
|
|
# * Without --keep-going: the script stops on the first error without
|
|
|
|
# cleaning up. This lets you work in the configuration of the failing
|
|
|
|
# component.
|
|
|
|
# * With --keep-going: the script runs all requested components and
|
|
|
|
# reports failures at the end. In particular the script always cleans
|
|
|
|
# up on exit.
|
|
|
|
#
|
2017-12-21 15:59:21 +01:00
|
|
|
# Note that the output is not saved. You may want to run
|
|
|
|
# script -c tests/scripts/all.sh
|
|
|
|
# or
|
|
|
|
# tests/scripts/all.sh >all.log 2>&1
|
2014-03-27 14:44:04 +01:00
|
|
|
#
|
2017-12-21 15:59:21 +01:00
|
|
|
# Notes for maintainers
|
|
|
|
# ---------------------
|
2014-03-27 14:44:04 +01:00
|
|
|
#
|
2018-11-27 15:58:47 +01:00
|
|
|
# The bulk of the code is organized into functions that follow one of the
|
|
|
|
# following naming conventions:
|
|
|
|
# * pre_XXX: things to do before running the tests, in order.
|
|
|
|
# * component_XXX: independent components. They can be run in any order.
|
2019-01-09 22:29:17 +01:00
|
|
|
# * component_check_XXX: quick tests that aren't worth parallelizing.
|
|
|
|
# * component_build_XXX: build things but don't run them.
|
|
|
|
# * component_test_XXX: build and test.
|
2023-12-15 17:05:15 +01:00
|
|
|
# * component_release_XXX: tests that the CI should skip during PR testing.
|
2019-01-06 20:50:38 +00:00
|
|
|
# * support_XXX: if support_XXX exists and returns false then
|
|
|
|
# component_XXX is not run by default.
|
2018-11-27 15:58:47 +01:00
|
|
|
# * post_XXX: things to do after running the tests.
|
|
|
|
# * other: miscellaneous support functions.
|
|
|
|
#
|
2019-01-09 22:29:17 +01:00
|
|
|
# Each component must start by invoking `msg` with a short informative message.
|
|
|
|
#
|
2020-03-28 21:27:40 +01:00
|
|
|
# Warning: due to the way bash detects errors, the failure of a command
|
|
|
|
# inside 'if' or '!' is not detected. Use the 'not' function instead of '!'.
|
|
|
|
#
|
2020-03-28 18:50:43 +01:00
|
|
|
# Each component is executed in a separate shell process. The component
|
|
|
|
# fails if any command in it returns a non-zero status.
|
|
|
|
#
|
2019-01-09 22:29:17 +01:00
|
|
|
# The framework performs some cleanup tasks after each component. This
|
|
|
|
# means that components can assume that the working directory is in a
|
|
|
|
# cleaned-up state, and don't need to perform the cleanup themselves.
|
|
|
|
# * Run `make clean`.
|
2021-06-28 14:11:11 +01:00
|
|
|
# * Restore `include/mbedtls/mbedtls_config.h` from a backup made before running
|
2019-01-09 22:29:17 +01:00
|
|
|
# the component.
|
2020-03-04 20:46:15 +01:00
|
|
|
# * Check out `Makefile`, `library/Makefile`, `programs/Makefile`,
|
|
|
|
# `tests/Makefile` and `programs/fuzz/Makefile` from git.
|
|
|
|
# This cleans up after an in-tree use of CMake.
|
2019-01-09 22:29:17 +01:00
|
|
|
#
|
2017-12-21 15:59:21 +01:00
|
|
|
# The tests are roughly in order from fastest to slowest. This doesn't
|
|
|
|
# have to be exact, but in general you should add slower tests towards
|
|
|
|
# the end and fast checks near the beginning.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
################################################################
|
|
|
|
#### Initialization and command line parsing
|
|
|
|
################################################################
|
2014-03-19 18:29:01 +01:00
|
|
|
|
2020-03-28 18:50:49 +01:00
|
|
|
# Abort on errors (even on the left-hand side of a pipe).
|
|
|
|
# Treat uninitialised variables as errors.
|
|
|
|
set -e -o pipefail -u
|
2014-03-19 18:29:01 +01:00
|
|
|
|
2022-08-30 21:02:44 +02:00
|
|
|
# Enable ksh/bash extended file matching patterns
|
|
|
|
shopt -s extglob
|
|
|
|
|
2023-08-17 17:32:26 +01:00
|
|
|
in_mbedtls_repo () {
|
2023-08-29 09:53:52 +01:00
|
|
|
test -d include -a -d library -a -d programs -a -d tests
|
|
|
|
}
|
|
|
|
|
2023-10-09 10:25:45 +02:00
|
|
|
in_tf_psa_crypto_repo () {
|
2023-08-29 09:53:52 +01:00
|
|
|
test -d include -a -d core -a -d drivers -a -d programs -a -d tests
|
2023-07-14 12:30:00 +01:00
|
|
|
}
|
|
|
|
|
2018-11-27 15:58:47 +01:00
|
|
|
pre_check_environment () {
|
2023-10-09 10:25:45 +02:00
|
|
|
if in_mbedtls_repo || in_tf_psa_crypto_repo; then :; else
|
|
|
|
echo "Must be run from Mbed TLS / TF-PSA-Crypto root" >&2
|
2018-11-27 15:58:47 +01:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
2014-03-19 18:29:01 +01:00
|
|
|
|
2018-11-27 15:58:47 +01:00
|
|
|
pre_initialize_variables () {
|
2023-08-17 17:32:26 +01:00
|
|
|
if in_mbedtls_repo; then
|
2023-07-14 12:30:00 +01:00
|
|
|
CONFIG_H='include/mbedtls/mbedtls_config.h'
|
2024-07-04 09:25:59 +02:00
|
|
|
if [ -d tf-psa-crypto ]; then
|
|
|
|
CRYPTO_CONFIG_H='tf-psa-crypto/include/psa/crypto_config.h'
|
|
|
|
PSA_CORE_PATH='tf-psa-crypto/core'
|
|
|
|
BUILTIN_SRC_PATH='tf-psa-crypto/drivers/builtin/src'
|
|
|
|
else
|
|
|
|
CRYPTO_CONFIG_H='include/psa/crypto_config.h'
|
|
|
|
fi
|
2023-08-17 17:32:26 +01:00
|
|
|
else
|
|
|
|
CONFIG_H='drivers/builtin/include/mbedtls/mbedtls_config.h'
|
2024-06-10 14:25:46 +02:00
|
|
|
CRYPTO_CONFIG_H='include/psa/crypto_config.h'
|
2024-07-04 09:25:59 +02:00
|
|
|
PSA_CORE_PATH='core'
|
|
|
|
BUILTIN_SRC_PATH='drivers/builtin/src'
|
2023-07-14 12:30:00 +01:00
|
|
|
fi
|
2022-12-27 12:35:11 +01:00
|
|
|
CONFIG_TEST_DRIVER_H='tests/include/test/drivers/config_test_driver.h'
|
2020-03-30 20:11:39 +02:00
|
|
|
|
|
|
|
# Files that are clobbered by some jobs will be backed up. Use a different
|
|
|
|
# suffix from auxiliary scripts so that all.sh and auxiliary scripts can
|
|
|
|
# independently decide when to remove the backup file.
|
|
|
|
backup_suffix='.all.bak'
|
|
|
|
# Files clobbered by config.py
|
2023-07-31 10:57:16 +01:00
|
|
|
files_to_back_up="$CONFIG_H $CRYPTO_CONFIG_H $CONFIG_TEST_DRIVER_H"
|
2023-08-17 17:32:26 +01:00
|
|
|
if in_mbedtls_repo; then
|
2023-07-14 12:30:00 +01:00
|
|
|
# Files clobbered by in-tree cmake
|
|
|
|
files_to_back_up="$files_to_back_up Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile"
|
|
|
|
fi
|
2018-11-27 15:58:47 +01:00
|
|
|
|
2019-09-16 15:55:46 +02:00
|
|
|
append_outcome=0
|
2018-11-27 15:58:47 +01:00
|
|
|
MEMORY=0
|
|
|
|
FORCE=0
|
2020-06-02 11:28:07 +02:00
|
|
|
QUIET=0
|
2018-11-27 15:58:47 +01:00
|
|
|
KEEP_GOING=0
|
|
|
|
|
2020-06-08 12:59:27 +02:00
|
|
|
# Seed value used with the --release-test option.
|
2020-06-22 10:11:47 +02:00
|
|
|
#
|
|
|
|
# See also RELEASE_SEED in basic-build-test.sh. Debugging is easier if
|
|
|
|
# both values are kept in sync. If you change the value here because it
|
|
|
|
# breaks some tests, you'll definitely want to change it in
|
|
|
|
# basic-build-test.sh as well.
|
2020-06-08 12:59:27 +02:00
|
|
|
RELEASE_SEED=1
|
|
|
|
|
2023-11-23 21:29:56 +08:00
|
|
|
# Specify character collation for regular expressions and sorting with C locale
|
|
|
|
export LC_COLLATE=C
|
|
|
|
|
2019-09-16 15:55:46 +02:00
|
|
|
: ${MBEDTLS_TEST_OUTCOME_FILE=}
|
2019-09-16 15:20:36 +02:00
|
|
|
: ${MBEDTLS_TEST_PLATFORM="$(uname -s | tr -c \\n0-9A-Za-z _)-$(uname -m | tr -c \\n0-9A-Za-z _)"}
|
2019-09-16 15:55:46 +02:00
|
|
|
export MBEDTLS_TEST_OUTCOME_FILE
|
2019-09-16 15:20:36 +02:00
|
|
|
export MBEDTLS_TEST_PLATFORM
|
|
|
|
|
2019-01-30 15:35:44 +00:00
|
|
|
# Default commands, can be overridden by the environment
|
2018-11-27 15:58:47 +01:00
|
|
|
: ${OPENSSL:="openssl"}
|
|
|
|
: ${OPENSSL_NEXT:="$OPENSSL"}
|
|
|
|
: ${GNUTLS_CLI:="gnutls-cli"}
|
|
|
|
: ${GNUTLS_SERV:="gnutls-serv"}
|
|
|
|
: ${OUT_OF_SOURCE_DIR:=./mbedtls_out_of_source_build}
|
|
|
|
: ${ARMC5_BIN_DIR:=/usr/bin}
|
|
|
|
: ${ARMC6_BIN_DIR:=/usr/bin}
|
2020-04-30 18:19:32 +02:00
|
|
|
: ${ARM_NONE_EABI_GCC_PREFIX:=arm-none-eabi-}
|
2020-08-18 10:28:51 +02:00
|
|
|
: ${ARM_LINUX_GNUEABI_GCC_PREFIX:=arm-linux-gnueabi-}
|
2023-07-31 16:38:10 +01:00
|
|
|
: ${CLANG_LATEST:="clang-latest"}
|
|
|
|
: ${CLANG_EARLIEST:="clang-earliest"}
|
|
|
|
: ${GCC_LATEST:="gcc-latest"}
|
|
|
|
: ${GCC_EARLIEST:="gcc-earliest"}
|
2018-11-27 15:58:47 +01:00
|
|
|
# if MAKEFLAGS is not set add the -j option to speed up invocations of make
|
2019-01-06 20:15:26 +00:00
|
|
|
if [ -z "${MAKEFLAGS+set}" ]; then
|
2021-09-30 18:24:21 +02:00
|
|
|
export MAKEFLAGS="-j$(all_sh_nproc)"
|
2018-11-27 15:58:47 +01:00
|
|
|
fi
|
2023-12-18 19:53:25 +00:00
|
|
|
# if CC is not set, use clang by default (if present) to improve build times
|
|
|
|
if [ -z "${CC+set}" ] && (type clang > /dev/null 2>&1); then
|
2023-12-19 16:08:19 +00:00
|
|
|
export CC="clang"
|
2023-12-18 18:34:50 +00:00
|
|
|
fi
|
2019-01-06 20:50:38 +00:00
|
|
|
|
2024-04-02 14:39:53 +02:00
|
|
|
if [ -n "${OPENSSL_3+set}" ]; then
|
|
|
|
export OPENSSL_NEXT="$OPENSSL_3"
|
|
|
|
fi
|
|
|
|
|
2021-09-20 18:57:55 +02:00
|
|
|
# Include more verbose output for failing tests run by CMake or make
|
2019-02-07 17:43:39 +00:00
|
|
|
export CTEST_OUTPUT_ON_FAILURE=1
|
|
|
|
|
2019-10-21 17:11:33 +02:00
|
|
|
# CFLAGS and LDFLAGS for Asan builds that don't use CMake
|
2022-11-30 10:42:03 +01:00
|
|
|
# default to -O2, use -Ox _after_ this if you want another level
|
2023-05-31 09:38:21 +02:00
|
|
|
ASAN_CFLAGS='-O2 -Werror -fsanitize=address,undefined -fno-sanitize-recover=all'
|
2023-12-14 16:42:48 +00:00
|
|
|
# Normally, tests should use this compiler for ASAN testing
|
|
|
|
ASAN_CC=clang
|
2019-10-21 17:11:33 +02:00
|
|
|
|
2023-06-27 10:02:09 -04:00
|
|
|
# Platform tests have an allocation that returns null
|
|
|
|
export ASAN_OPTIONS="allocator_may_return_null=1"
|
2023-07-05 08:32:43 -04:00
|
|
|
export MSAN_OPTIONS="allocator_may_return_null=1"
|
2023-06-27 10:02:09 -04:00
|
|
|
|
2019-01-06 20:50:38 +00:00
|
|
|
# Gather the list of available components. These are the functions
|
|
|
|
# defined in this script whose name starts with "component_".
|
2023-07-28 16:41:21 +01:00
|
|
|
ALL_COMPONENTS=$(compgen -A function component_ | sed 's/component_//')
|
2019-01-06 20:50:38 +00:00
|
|
|
|
2024-06-27 07:59:39 +02:00
|
|
|
PSASIM_PATH='tests/psa-client-server/psasim/'
|
|
|
|
|
2024-01-16 17:33:34 +00:00
|
|
|
# Delay determining SUPPORTED_COMPONENTS until the command line options have a chance to override
|
2023-12-15 19:20:31 +01:00
|
|
|
# the commands set by the environment
|
2018-11-27 15:58:47 +01:00
|
|
|
}
|
2016-07-12 16:54:33 +01:00
|
|
|
|
2024-02-26 11:41:19 +00:00
|
|
|
setup_quiet_wrappers()
|
|
|
|
{
|
|
|
|
# Pick up "quiet" wrappers for make and cmake, which don't output very much
|
|
|
|
# unless there is an error. This reduces logging overhead in the CI.
|
|
|
|
#
|
|
|
|
# Note that the cmake wrapper breaks unless we use an absolute path here.
|
2024-02-26 17:27:18 +00:00
|
|
|
if [[ -e ${PWD}/tests/scripts/quiet ]]; then
|
|
|
|
export PATH=${PWD}/tests/scripts/quiet:$PATH
|
2024-02-26 11:41:19 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2019-01-10 00:05:18 +01:00
|
|
|
# Test whether the component $1 is included in the command line patterns.
|
|
|
|
is_component_included()
|
2018-11-27 21:37:53 +01:00
|
|
|
{
|
2021-08-06 11:35:17 +02:00
|
|
|
# Temporarily disable wildcard expansion so that $COMMAND_LINE_COMPONENTS
|
|
|
|
# only does word splitting.
|
2018-11-27 21:37:53 +01:00
|
|
|
set -f
|
2019-01-06 22:11:25 +00:00
|
|
|
for pattern in $COMMAND_LINE_COMPONENTS; do
|
2018-11-27 21:37:53 +01:00
|
|
|
set +f
|
|
|
|
case ${1#component_} in $pattern) return 0;; esac
|
|
|
|
done
|
|
|
|
set +f
|
|
|
|
return 1
|
|
|
|
}
|
2016-07-12 16:54:33 +01:00
|
|
|
|
2016-09-07 00:07:09 +01:00
|
|
|
usage()
|
2016-04-16 21:54:39 +01:00
|
|
|
{
|
2017-12-10 23:43:39 +01:00
|
|
|
cat <<EOF
|
2018-11-27 18:15:35 +01:00
|
|
|
Usage: $0 [OPTION]... [COMPONENT]...
|
2018-11-27 17:04:29 +01:00
|
|
|
Run mbedtls release validation tests.
|
2018-11-27 18:15:35 +01:00
|
|
|
By default, run all tests. With one or more COMPONENT, run only those.
|
2019-01-10 00:05:18 +01:00
|
|
|
COMPONENT can be the name of a component or a shell wildcard pattern.
|
|
|
|
|
|
|
|
Examples:
|
|
|
|
$0 "check_*"
|
|
|
|
Run all sanity checks.
|
|
|
|
$0 --no-armcc --except test_memsan
|
|
|
|
Run everything except builds that require armcc and MemSan.
|
2018-11-27 17:04:29 +01:00
|
|
|
|
|
|
|
Special options:
|
|
|
|
-h|--help Print this help and exit.
|
2019-01-06 20:50:38 +00:00
|
|
|
--list-all-components List all available test components and exit.
|
|
|
|
--list-components List components supported on this platform and exit.
|
2017-12-10 23:43:39 +01:00
|
|
|
|
|
|
|
General options:
|
2020-06-02 11:28:07 +02:00
|
|
|
-q|--quiet Only output component names, and errors if any.
|
2017-12-10 23:43:39 +01:00
|
|
|
-f|--force Force the tests to overwrite any modified files.
|
2017-12-11 00:01:40 +01:00
|
|
|
-k|--keep-going Run all tests and report errors at the end.
|
2017-12-10 23:43:39 +01:00
|
|
|
-m|--memory Additional optional memory tests.
|
2019-09-16 15:55:46 +02:00
|
|
|
--append-outcome Append to the outcome file (if used).
|
2020-04-30 18:19:32 +02:00
|
|
|
--arm-none-eabi-gcc-prefix=<string>
|
|
|
|
Prefix for a cross-compiler for arm-none-eabi
|
|
|
|
(default: "${ARM_NONE_EABI_GCC_PREFIX}")
|
2020-08-18 10:28:51 +02:00
|
|
|
--arm-linux-gnueabi-gcc-prefix=<string>
|
|
|
|
Prefix for a cross-compiler for arm-linux-gnueabi
|
|
|
|
(default: "${ARM_LINUX_GNUEABI_GCC_PREFIX}")
|
2017-12-19 18:24:31 +01:00
|
|
|
--armcc Run ARM Compiler builds (on by default).
|
2021-08-06 11:51:59 +02:00
|
|
|
--restore First clean up the build tree, restoring backed up
|
|
|
|
files. Do not run any components unless they are
|
|
|
|
explicitly specified.
|
2020-03-28 21:09:21 +01:00
|
|
|
--error-test Error test mode: run a failing function in addition
|
2021-08-05 15:11:33 +02:00
|
|
|
to any specified component. May be repeated.
|
2019-01-10 00:05:18 +01:00
|
|
|
--except Exclude the COMPONENTs listed on the command line,
|
|
|
|
instead of running only those.
|
2019-09-16 15:55:46 +02:00
|
|
|
--no-append-outcome Write a new outcome file and analyze it (default).
|
2017-12-19 18:24:31 +01:00
|
|
|
--no-armcc Skip ARM Compiler builds.
|
2018-03-21 08:40:26 +01:00
|
|
|
--no-force Refuse to overwrite modified files (default).
|
|
|
|
--no-keep-going Stop at the first error (default).
|
|
|
|
--no-memory No additional memory tests (default).
|
2021-12-20 21:14:10 -08:00
|
|
|
--no-quiet Print full output from components.
|
2017-12-10 23:43:39 +01:00
|
|
|
--out-of-source-dir=<path> Directory used for CMake out-of-source build tests.
|
2019-09-16 15:55:46 +02:00
|
|
|
--outcome-file=<path> File where test outcomes are written (not done if
|
|
|
|
empty; default: \$MBEDTLS_TEST_OUTCOME_FILE).
|
2018-03-21 08:40:26 +01:00
|
|
|
--random-seed Use a random seed value for randomized tests (default).
|
2020-06-08 12:59:27 +02:00
|
|
|
-r|--release-test Run this script in release mode. This fixes the seed value to ${RELEASE_SEED}.
|
2017-12-10 23:43:39 +01:00
|
|
|
-s|--seed Integer seed value to use for this test run.
|
|
|
|
|
|
|
|
Tool path options:
|
|
|
|
--armc5-bin-dir=<ARMC5_bin_dir_path> ARM Compiler 5 bin directory.
|
|
|
|
--armc6-bin-dir=<ARMC6_bin_dir_path> ARM Compiler 6 bin directory.
|
2023-07-28 17:04:47 +01:00
|
|
|
--clang-earliest=<Clang_earliest_path> Earliest version of clang available
|
|
|
|
--clang-latest=<Clang_latest_path> Latest version of clang available
|
|
|
|
--gcc-earliest=<GCC_earliest_path> Earliest version of GCC available
|
|
|
|
--gcc-latest=<GCC_latest_path> Latest version of GCC available
|
2017-12-10 23:43:39 +01:00
|
|
|
--gnutls-cli=<GnuTLS_cli_path> GnuTLS client executable to use for most tests.
|
|
|
|
--gnutls-serv=<GnuTLS_serv_path> GnuTLS server executable to use for most tests.
|
|
|
|
--openssl=<OpenSSL_path> OpenSSL executable to use for most tests.
|
2018-02-20 12:02:07 +01:00
|
|
|
--openssl-next=<OpenSSL_path> OpenSSL executable to use for recent things like ARIA
|
2017-12-10 23:43:39 +01:00
|
|
|
EOF
|
2016-04-16 21:54:39 +01:00
|
|
|
}
|
2014-03-19 18:29:01 +01:00
|
|
|
|
2021-08-03 13:44:28 +02:00
|
|
|
# Cleanup before/after running a component.
|
|
|
|
# Remove built files as well as the cmake cache/config.
|
|
|
|
# Does not remove generated source files.
|
2014-03-19 18:29:01 +01:00
|
|
|
cleanup()
|
|
|
|
{
|
2023-08-17 17:32:26 +01:00
|
|
|
if in_mbedtls_repo; then
|
2023-07-14 12:30:00 +01:00
|
|
|
command make clean
|
|
|
|
fi
|
2014-07-12 04:00:00 +02:00
|
|
|
|
2018-03-21 12:15:06 +01:00
|
|
|
# Remove CMake artefacts
|
2018-11-07 18:46:41 +00:00
|
|
|
find . -name .git -prune -o \
|
2018-03-21 12:15:06 +01:00
|
|
|
-iname CMakeFiles -exec rm -rf {} \+ -o \
|
|
|
|
\( -iname cmake_install.cmake -o \
|
|
|
|
-iname CTestTestfile.cmake -o \
|
2021-09-09 11:11:44 +02:00
|
|
|
-iname CMakeCache.txt -o \
|
|
|
|
-path './cmake/*.cmake' \) -exec rm -f {} \+
|
2024-06-12 10:04:22 +02:00
|
|
|
# Remove Makefiles generated by in-tree CMake builds
|
2024-07-02 07:36:39 +02:00
|
|
|
rm -f pkgconfig/Makefile framework/Makefile
|
2024-06-12 10:04:22 +02:00
|
|
|
rm -f include/Makefile programs/!(fuzz)/Makefile
|
2024-06-11 14:07:09 +02:00
|
|
|
rm -f tf-psa-crypto/Makefile tf-psa-crypto/include/Makefile
|
2024-07-02 08:40:24 +02:00
|
|
|
rm -f tf-psa-crypto/core/Makefile tf-psa-crypto/drivers/Makefile
|
2024-07-12 14:30:16 +02:00
|
|
|
rm -f tf-psa-crypto/tests/Makefile
|
2024-07-02 07:36:39 +02:00
|
|
|
rm -f tf-psa-crypto/drivers/everest/Makefile
|
|
|
|
rm -f tf-psa-crypto/drivers/p256-m/Makefile
|
2024-07-02 08:40:24 +02:00
|
|
|
rm -f tf-psa-crypto/drivers/builtin/Makefile
|
|
|
|
rm -f tf-psa-crypto/drivers/builtin/src/Makefile
|
2014-07-12 04:00:00 +02:00
|
|
|
|
2019-06-20 17:38:22 +01:00
|
|
|
# Remove any artifacts from the component_test_cmake_as_subdirectory test.
|
|
|
|
rm -rf programs/test/cmake_subproject/build
|
|
|
|
rm -f programs/test/cmake_subproject/Makefile
|
|
|
|
rm -f programs/test/cmake_subproject/cmake_subproject
|
|
|
|
|
2021-03-25 16:03:25 +00:00
|
|
|
# Remove any artifacts from the component_test_cmake_as_package test.
|
|
|
|
rm -rf programs/test/cmake_package/build
|
|
|
|
rm -f programs/test/cmake_package/Makefile
|
|
|
|
rm -f programs/test/cmake_package/cmake_package
|
|
|
|
|
|
|
|
# Remove any artifacts from the component_test_cmake_as_installed_package test.
|
|
|
|
rm -rf programs/test/cmake_package_install/build
|
|
|
|
rm -f programs/test/cmake_package_install/Makefile
|
|
|
|
rm -f programs/test/cmake_package_install/cmake_package_install
|
|
|
|
|
2020-03-30 20:11:39 +02:00
|
|
|
# Restore files that may have been clobbered by the job
|
|
|
|
for x in $files_to_back_up; do
|
2022-08-30 21:02:00 +02:00
|
|
|
if [[ -e "$x$backup_suffix" ]]; then
|
|
|
|
cp -p "$x$backup_suffix" "$x"
|
|
|
|
fi
|
2020-03-30 20:11:39 +02:00
|
|
|
done
|
|
|
|
}
|
2020-10-31 22:14:03 -07:00
|
|
|
|
2024-06-27 07:59:39 +02:00
|
|
|
# This is a helper function to be used in psasim builds. It is meant to clean
|
|
|
|
# up the library's workspace after the server build and before the client
|
|
|
|
# build. Built libraries (mbedcrypto, mbedx509 and mbedtls) are supposed to be
|
|
|
|
# already copied to psasim folder at this point.
|
2024-07-02 12:02:25 +02:00
|
|
|
helper_psasim_cleanup_before_client() {
|
2024-06-27 07:59:39 +02:00
|
|
|
# Clean up library files
|
|
|
|
make -C library clean
|
|
|
|
# Clean up intermediate files that were used to build the server
|
|
|
|
make -C $PSASIM_PATH clean_server_intermediate_files
|
|
|
|
# Restore files that were backup before building library files. This
|
|
|
|
# includes $CONFIG_H and $CRYPTO_CONFIG_H.
|
|
|
|
for x in $files_to_back_up; do
|
|
|
|
if [[ -e "$x$backup_suffix" ]]; then
|
|
|
|
cp -p "$x$backup_suffix" "$x"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2021-08-03 13:44:28 +02:00
|
|
|
# Final cleanup when this script exits (except when exiting on a failure
|
|
|
|
# in non-keep-going mode).
|
2020-03-30 20:11:39 +02:00
|
|
|
final_cleanup () {
|
|
|
|
cleanup
|
|
|
|
|
|
|
|
for x in $files_to_back_up; do
|
|
|
|
rm -f "$x$backup_suffix"
|
|
|
|
done
|
2014-03-19 18:29:01 +01:00
|
|
|
}
|
|
|
|
|
2017-12-11 00:01:40 +01:00
|
|
|
# Executed on exit. May be redefined depending on command line options.
|
|
|
|
final_report () {
|
|
|
|
:
|
|
|
|
}
|
|
|
|
|
|
|
|
fatal_signal () {
|
2020-03-30 20:11:39 +02:00
|
|
|
final_cleanup
|
2017-12-11 00:01:40 +01:00
|
|
|
final_report $1
|
|
|
|
trap - $1
|
|
|
|
kill -$1 $$
|
|
|
|
}
|
|
|
|
|
|
|
|
trap 'fatal_signal HUP' HUP
|
|
|
|
trap 'fatal_signal INT' INT
|
|
|
|
trap 'fatal_signal TERM' TERM
|
2014-07-12 04:00:00 +02:00
|
|
|
|
2021-09-30 18:24:21 +02:00
|
|
|
# Number of processors on this machine. Used as the default setting
|
|
|
|
# for parallel make.
|
|
|
|
all_sh_nproc ()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
nproc || # Linux
|
|
|
|
sysctl -n hw.ncpuonline || # NetBSD, OpenBSD
|
|
|
|
sysctl -n hw.ncpu || # FreeBSD
|
|
|
|
echo 1
|
|
|
|
} 2>/dev/null
|
|
|
|
}
|
|
|
|
|
2014-03-27 14:44:04 +01:00
|
|
|
msg()
|
|
|
|
{
|
2018-12-04 12:49:28 +01:00
|
|
|
if [ -n "${current_component:-}" ]; then
|
|
|
|
current_section="${current_component#component_}: $1"
|
|
|
|
else
|
|
|
|
current_section="$1"
|
|
|
|
fi
|
2020-06-02 11:28:07 +02:00
|
|
|
|
|
|
|
if [ $QUIET -eq 1 ]; then
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2014-03-27 14:44:04 +01:00
|
|
|
echo ""
|
|
|
|
echo "******************************************************************"
|
2018-12-04 12:49:28 +01:00
|
|
|
echo "* $current_section "
|
2015-01-26 14:03:56 +00:00
|
|
|
printf "* "; date
|
2014-03-27 14:44:04 +01:00
|
|
|
echo "******************************************************************"
|
|
|
|
}
|
2014-03-19 18:29:01 +01:00
|
|
|
|
2018-11-27 15:58:47 +01:00
|
|
|
armc6_build_test()
|
|
|
|
{
|
|
|
|
FLAGS="$1"
|
2016-10-17 15:23:10 +01:00
|
|
|
|
2020-04-30 23:11:54 +02:00
|
|
|
msg "build: ARM Compiler 6 ($FLAGS)"
|
2023-09-08 11:20:59 +08:00
|
|
|
make clean
|
2018-11-27 15:58:47 +01:00
|
|
|
ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \
|
2023-03-02 13:39:04 +00:00
|
|
|
WARNING_CFLAGS='-Werror -xc -std=c99' make lib
|
2020-04-30 23:11:54 +02:00
|
|
|
|
|
|
|
msg "size: ARM Compiler 6 ($FLAGS)"
|
|
|
|
"$ARMC6_FROMELF" -z library/*.o
|
2024-07-04 09:25:59 +02:00
|
|
|
if [ -n ${PSA_CORE_PATH} ]; then
|
|
|
|
"$ARMC6_FROMELF" -z ${PSA_CORE_PATH}/*.o
|
|
|
|
fi
|
|
|
|
if [ -n ${BUILTIN_SRC_PATH} ]; then
|
|
|
|
"$ARMC6_FROMELF" -z ${BUILTIN_SRC_PATH}/*.o
|
|
|
|
fi
|
2018-11-27 15:58:47 +01:00
|
|
|
}
|
2016-10-17 15:23:10 +01:00
|
|
|
|
2016-08-26 14:42:14 +01:00
|
|
|
err_msg()
|
|
|
|
{
|
|
|
|
echo "$1" >&2
|
|
|
|
}
|
|
|
|
|
|
|
|
check_tools()
|
|
|
|
{
|
2023-09-28 09:08:04 +02:00
|
|
|
for tool in "$@"; do
|
|
|
|
if ! `type "$tool" >/dev/null 2>&1`; then
|
|
|
|
err_msg "$tool not found!"
|
2016-08-26 14:42:14 +01:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2018-11-27 15:58:47 +01:00
|
|
|
pre_parse_command_line () {
|
2019-01-06 22:11:25 +00:00
|
|
|
COMMAND_LINE_COMPONENTS=
|
2019-01-10 00:05:18 +01:00
|
|
|
all_except=0
|
2020-03-28 21:09:21 +01:00
|
|
|
error_test=0
|
2023-12-15 19:20:31 +01:00
|
|
|
list_components=0
|
2021-08-06 11:51:59 +02:00
|
|
|
restore_first=0
|
2019-01-06 22:23:42 +00:00
|
|
|
no_armcc=
|
2019-01-06 22:11:25 +00:00
|
|
|
|
2018-11-02 18:34:17 +00:00
|
|
|
# Note that legacy options are ignored instead of being omitted from this
|
|
|
|
# list of options, so invocations that worked with previous version of
|
|
|
|
# all.sh will still run and work properly.
|
2018-11-27 15:58:47 +01:00
|
|
|
while [ $# -gt 0 ]; do
|
2019-01-09 22:28:21 +01:00
|
|
|
case "$1" in
|
2019-09-16 15:55:46 +02:00
|
|
|
--append-outcome) append_outcome=1;;
|
2020-04-30 18:19:32 +02:00
|
|
|
--arm-none-eabi-gcc-prefix) shift; ARM_NONE_EABI_GCC_PREFIX="$1";;
|
2020-08-18 10:28:51 +02:00
|
|
|
--arm-linux-gnueabi-gcc-prefix) shift; ARM_LINUX_GNUEABI_GCC_PREFIX="$1";;
|
2019-01-06 22:23:42 +00:00
|
|
|
--armcc) no_armcc=;;
|
2023-12-15 19:20:31 +01:00
|
|
|
--armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
|
|
|
|
--armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
|
2023-07-28 17:04:47 +01:00
|
|
|
--clang-earliest) shift; CLANG_EARLIEST="$1";;
|
|
|
|
--clang-latest) shift; CLANG_LATEST="$1";;
|
2020-03-28 21:09:21 +01:00
|
|
|
--error-test) error_test=$((error_test + 1));;
|
2019-01-06 22:11:25 +00:00
|
|
|
--except) all_except=1;;
|
2019-01-09 22:28:21 +01:00
|
|
|
--force|-f) FORCE=1;;
|
2023-07-28 17:04:47 +01:00
|
|
|
--gcc-earliest) shift; GCC_EARLIEST="$1";;
|
|
|
|
--gcc-latest) shift; GCC_LATEST="$1";;
|
2019-01-09 22:28:21 +01:00
|
|
|
--gnutls-cli) shift; GNUTLS_CLI="$1";;
|
2023-08-27 21:39:21 +02:00
|
|
|
--gnutls-legacy-cli) shift;; # ignored for backward compatibility
|
|
|
|
--gnutls-legacy-serv) shift;; # ignored for backward compatibility
|
2019-01-09 22:28:21 +01:00
|
|
|
--gnutls-serv) shift; GNUTLS_SERV="$1";;
|
|
|
|
--help|-h) usage; exit;;
|
|
|
|
--keep-going|-k) KEEP_GOING=1;;
|
2019-01-06 20:50:38 +00:00
|
|
|
--list-all-components) printf '%s\n' $ALL_COMPONENTS; exit;;
|
2023-12-15 19:20:31 +01:00
|
|
|
--list-components) list_components=1;;
|
2019-01-09 22:28:21 +01:00
|
|
|
--memory|-m) MEMORY=1;;
|
2019-09-16 15:55:46 +02:00
|
|
|
--no-append-outcome) append_outcome=0;;
|
2019-01-06 22:23:42 +00:00
|
|
|
--no-armcc) no_armcc=1;;
|
2019-01-09 22:28:21 +01:00
|
|
|
--no-force) FORCE=0;;
|
|
|
|
--no-keep-going) KEEP_GOING=0;;
|
|
|
|
--no-memory) MEMORY=0;;
|
2020-06-02 11:28:07 +02:00
|
|
|
--no-quiet) QUIET=0;;
|
2019-01-09 22:28:21 +01:00
|
|
|
--openssl) shift; OPENSSL="$1";;
|
|
|
|
--openssl-next) shift; OPENSSL_NEXT="$1";;
|
2019-09-16 15:55:46 +02:00
|
|
|
--outcome-file) shift; MBEDTLS_TEST_OUTCOME_FILE="$1";;
|
2019-01-09 22:28:21 +01:00
|
|
|
--out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
|
2020-06-02 11:28:07 +02:00
|
|
|
--quiet|-q) QUIET=1;;
|
2019-01-09 22:28:21 +01:00
|
|
|
--random-seed) unset SEED;;
|
2020-06-08 12:59:27 +02:00
|
|
|
--release-test|-r) SEED=$RELEASE_SEED;;
|
2021-08-06 11:51:59 +02:00
|
|
|
--restore) restore_first=1;;
|
2019-01-09 22:28:21 +01:00
|
|
|
--seed|-s) shift; SEED="$1";;
|
|
|
|
-*)
|
|
|
|
echo >&2 "Unknown option: $1"
|
|
|
|
echo >&2 "Run $0 --help for usage."
|
|
|
|
exit 120
|
|
|
|
;;
|
2019-01-06 22:11:25 +00:00
|
|
|
*) COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS $1";;
|
2019-01-09 22:28:21 +01:00
|
|
|
esac
|
|
|
|
shift
|
2018-11-27 15:58:47 +01:00
|
|
|
done
|
2016-04-16 21:54:39 +01:00
|
|
|
|
2023-12-15 19:20:31 +01:00
|
|
|
# Exclude components that are not supported on this platform.
|
|
|
|
SUPPORTED_COMPONENTS=
|
|
|
|
for component in $ALL_COMPONENTS; do
|
|
|
|
case $(type "support_$component" 2>&1) in
|
|
|
|
*' function'*)
|
|
|
|
if ! support_$component; then continue; fi;;
|
|
|
|
esac
|
|
|
|
SUPPORTED_COMPONENTS="$SUPPORTED_COMPONENTS $component"
|
|
|
|
done
|
|
|
|
|
|
|
|
if [ $list_components -eq 1 ]; then
|
|
|
|
printf '%s\n' $SUPPORTED_COMPONENTS
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
2019-01-10 00:05:18 +01:00
|
|
|
# With no list of components, run everything.
|
2021-08-06 11:51:59 +02:00
|
|
|
if [ -z "$COMMAND_LINE_COMPONENTS" ] && [ $restore_first -eq 0 ]; then
|
2019-01-06 22:11:25 +00:00
|
|
|
all_except=1
|
|
|
|
fi
|
2016-04-16 21:54:39 +01:00
|
|
|
|
2019-01-06 22:23:42 +00:00
|
|
|
# --no-armcc is a legacy option. The modern way is --except '*_armcc*'.
|
|
|
|
# Ignore it if components are listed explicitly on the command line.
|
2019-01-10 00:05:18 +01:00
|
|
|
if [ -n "$no_armcc" ] && [ $all_except -eq 1 ]; then
|
2019-01-06 22:23:42 +00:00
|
|
|
COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS *_armcc*"
|
2016-08-31 17:33:13 +01:00
|
|
|
fi
|
|
|
|
|
2021-08-03 13:44:28 +02:00
|
|
|
# Error out if an explicitly requested component doesn't exist.
|
2020-03-28 21:37:59 +01:00
|
|
|
if [ $all_except -eq 0 ]; then
|
|
|
|
unsupported=0
|
2021-08-06 11:35:17 +02:00
|
|
|
# Temporarily disable wildcard expansion so that $COMMAND_LINE_COMPONENTS
|
|
|
|
# only does word splitting.
|
2021-08-03 13:43:36 +02:00
|
|
|
set -f
|
2020-03-28 21:37:59 +01:00
|
|
|
for component in $COMMAND_LINE_COMPONENTS; do
|
2021-08-03 13:43:36 +02:00
|
|
|
set +f
|
2021-08-03 13:44:28 +02:00
|
|
|
# If the requested name includes a wildcard character, don't
|
|
|
|
# check it. Accept wildcard patterns that don't match anything.
|
2020-03-28 21:37:59 +01:00
|
|
|
case $component in
|
|
|
|
*[*?\[]*) continue;;
|
|
|
|
esac
|
|
|
|
case " $SUPPORTED_COMPONENTS " in
|
|
|
|
*" $component "*) :;;
|
|
|
|
*)
|
|
|
|
echo >&2 "Component $component was explicitly requested, but is not known or not supported."
|
|
|
|
unsupported=$((unsupported + 1));;
|
|
|
|
esac
|
|
|
|
done
|
2021-08-03 13:43:36 +02:00
|
|
|
set +f
|
2020-03-28 21:37:59 +01:00
|
|
|
if [ $unsupported -ne 0 ]; then
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2019-01-06 22:11:25 +00:00
|
|
|
# Build the list of components to run.
|
2019-01-10 00:05:18 +01:00
|
|
|
RUN_COMPONENTS=
|
|
|
|
for component in $SUPPORTED_COMPONENTS; do
|
|
|
|
if is_component_included "$component"; [ $? -eq $all_except ]; then
|
|
|
|
RUN_COMPONENTS="$RUN_COMPONENTS $component"
|
|
|
|
fi
|
|
|
|
done
|
2019-01-06 22:11:25 +00:00
|
|
|
|
|
|
|
unset all_except
|
2019-01-06 22:23:42 +00:00
|
|
|
unset no_armcc
|
2018-11-27 15:58:47 +01:00
|
|
|
}
|
2016-04-16 21:54:39 +01:00
|
|
|
|
2018-11-27 15:58:47 +01:00
|
|
|
pre_check_git () {
|
|
|
|
if [ $FORCE -eq 1 ]; then
|
2019-01-09 23:17:35 +01:00
|
|
|
rm -rf "$OUT_OF_SOURCE_DIR"
|
2018-11-27 15:58:47 +01:00
|
|
|
git checkout-index -f -q $CONFIG_H
|
|
|
|
cleanup
|
|
|
|
else
|
2016-08-31 17:33:13 +01:00
|
|
|
|
2018-11-27 15:58:47 +01:00
|
|
|
if [ -d "$OUT_OF_SOURCE_DIR" ]; then
|
|
|
|
echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
|
|
|
|
echo "You can either delete this directory manually, or force the test by rerunning"
|
|
|
|
echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2023-07-20 09:49:12 +02:00
|
|
|
if ! git diff --quiet "$CONFIG_H"; then
|
2023-07-14 12:30:00 +01:00
|
|
|
err_msg "Warning - the configuration file '$CONFIG_H' has been edited. "
|
2018-11-27 15:58:47 +01:00
|
|
|
echo "You can either delete or preserve your work, or force the test by rerunning the"
|
|
|
|
echo "script as: $0 --force"
|
|
|
|
exit 1
|
|
|
|
fi
|
2016-04-16 21:54:39 +01:00
|
|
|
fi
|
2019-02-14 07:18:59 -05:00
|
|
|
}
|
|
|
|
|
2021-07-12 18:16:01 +02:00
|
|
|
pre_restore_files () {
|
|
|
|
# If the makefiles have been generated by a framework such as cmake,
|
|
|
|
# restore them from git. If the makefiles look like modifications from
|
|
|
|
# the ones checked into git, take care not to modify them. Whatever
|
|
|
|
# this function leaves behind is what the script will restore before
|
|
|
|
# each component.
|
|
|
|
case "$(head -n1 Makefile)" in
|
|
|
|
*[Gg]enerated*)
|
|
|
|
git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile
|
|
|
|
git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2020-03-30 20:11:39 +02:00
|
|
|
pre_back_up () {
|
|
|
|
for x in $files_to_back_up; do
|
|
|
|
cp -p "$x" "$x$backup_suffix"
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2018-11-27 15:58:47 +01:00
|
|
|
pre_setup_keep_going () {
|
2020-03-28 18:50:43 +01:00
|
|
|
failure_count=0 # Number of failed components
|
|
|
|
last_failure_status=0 # Last failure status in this component
|
|
|
|
|
2020-03-28 19:34:23 +01:00
|
|
|
# See err_trap
|
|
|
|
previous_failure_status=0
|
|
|
|
previous_failed_command=
|
|
|
|
previous_failure_funcall_depth=0
|
2020-03-28 21:27:40 +01:00
|
|
|
unset report_failed_command
|
2020-03-28 19:34:23 +01:00
|
|
|
|
2017-12-11 00:01:40 +01:00
|
|
|
start_red=
|
|
|
|
end_color=
|
|
|
|
if [ -t 1 ]; then
|
2018-01-02 21:54:17 +01:00
|
|
|
case "${TERM:-}" in
|
2017-12-11 00:01:40 +01:00
|
|
|
*color*|cygwin|linux|rxvt*|screen|[Eex]term*)
|
|
|
|
start_red=$(printf '\033[31m')
|
|
|
|
end_color=$(printf '\033[0m')
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
fi
|
2020-03-28 18:50:43 +01:00
|
|
|
|
|
|
|
# Keep a summary of failures in a file. We'll print it out at the end.
|
|
|
|
failure_summary_file=$PWD/all-sh-failures-$$.log
|
|
|
|
: >"$failure_summary_file"
|
|
|
|
|
|
|
|
# Whether it makes sense to keep a component going after the specified
|
|
|
|
# command fails (test command) or not (configure or build).
|
2021-08-06 11:35:17 +02:00
|
|
|
# This function normally receives the failing simple command
|
|
|
|
# ($BASH_COMMAND) as an argument, but if $report_failed_command is set,
|
|
|
|
# this is passed instead.
|
2020-03-28 18:50:43 +01:00
|
|
|
# This doesn't have to be 100% accurate: all failures are recorded anyway.
|
2021-08-02 23:29:53 +02:00
|
|
|
# False positives result in running things that can't be expected to
|
|
|
|
# work. False negatives result in things not running after something else
|
|
|
|
# failed even though they might have given useful feedback.
|
2020-03-28 18:50:43 +01:00
|
|
|
can_keep_going_after_failure () {
|
|
|
|
case "$1" in
|
|
|
|
"msg "*) false;;
|
2021-08-02 23:29:53 +02:00
|
|
|
"cd "*) false;;
|
2023-11-10 09:58:31 +01:00
|
|
|
"diff "*) true;;
|
2021-08-02 23:29:53 +02:00
|
|
|
*make*[\ /]tests*) false;; # make tests, make CFLAGS=-I../tests, ...
|
|
|
|
*test*) true;; # make test, tests/stuff, env V=v tests/stuff, ...
|
|
|
|
*make*check*) true;;
|
|
|
|
"grep "*) true;;
|
|
|
|
"[ "*) true;;
|
|
|
|
"! "*) true;;
|
2020-03-28 18:50:43 +01:00
|
|
|
*) false;;
|
2017-12-11 00:01:40 +01:00
|
|
|
esac
|
|
|
|
}
|
2020-03-28 18:50:43 +01:00
|
|
|
|
|
|
|
# This function runs if there is any error in a component.
|
|
|
|
# It must either exit with a nonzero status, or set
|
|
|
|
# last_failure_status to a nonzero value.
|
|
|
|
err_trap () {
|
|
|
|
# Save $? (status of the failing command). This must be the very
|
|
|
|
# first thing, before $? is overridden.
|
|
|
|
last_failure_status=$?
|
2020-03-28 21:27:40 +01:00
|
|
|
failed_command=${report_failed_command-$BASH_COMMAND}
|
2020-03-28 18:50:43 +01:00
|
|
|
|
2020-03-28 19:34:23 +01:00
|
|
|
if [[ $last_failure_status -eq $previous_failure_status &&
|
|
|
|
"$failed_command" == "$previous_failed_command" &&
|
|
|
|
${#FUNCNAME[@]} == $((previous_failure_funcall_depth - 1)) ]]
|
|
|
|
then
|
|
|
|
# The same command failed twice in a row, but this time one level
|
|
|
|
# less deep in the function call stack. This happens when the last
|
|
|
|
# command of a function returns a nonzero status, and the function
|
|
|
|
# returns that same status. Ignore the second failure.
|
|
|
|
previous_failure_funcall_depth=${#FUNCNAME[@]}
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
previous_failure_status=$last_failure_status
|
|
|
|
previous_failed_command=$failed_command
|
|
|
|
previous_failure_funcall_depth=${#FUNCNAME[@]}
|
|
|
|
|
2020-03-28 18:50:43 +01:00
|
|
|
text="$current_section: $failed_command -> $last_failure_status"
|
|
|
|
echo "${start_red}^^^^$text^^^^${end_color}" >&2
|
|
|
|
echo "$text" >>"$failure_summary_file"
|
|
|
|
|
|
|
|
# If the command is fatal (configure or build command), stop this
|
|
|
|
# component. Otherwise (test command) keep the component running
|
|
|
|
# (run more tests from the same build).
|
|
|
|
if ! can_keep_going_after_failure "$failed_command"; then
|
|
|
|
exit $last_failure_status
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2017-12-11 00:01:40 +01:00
|
|
|
final_report () {
|
|
|
|
if [ $failure_count -gt 0 ]; then
|
|
|
|
echo
|
|
|
|
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
|
2020-03-28 18:50:43 +01:00
|
|
|
echo "${start_red}FAILED: $failure_count components${end_color}"
|
|
|
|
cat "$failure_summary_file"
|
2017-12-11 00:01:40 +01:00
|
|
|
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
|
|
|
|
elif [ -z "${1-}" ]; then
|
|
|
|
echo "SUCCESS :)"
|
|
|
|
fi
|
|
|
|
if [ -n "${1-}" ]; then
|
|
|
|
echo "Killed by SIG$1."
|
|
|
|
fi
|
2020-03-28 18:50:43 +01:00
|
|
|
rm -f "$failure_summary_file"
|
|
|
|
if [ $failure_count -gt 0 ]; then
|
|
|
|
exit 1
|
|
|
|
fi
|
2017-12-11 00:01:40 +01:00
|
|
|
}
|
2018-11-27 15:58:47 +01:00
|
|
|
}
|
|
|
|
|
2021-07-08 18:41:16 +02:00
|
|
|
# record_status() and if_build_succeeded() are kept temporarily for backward
|
|
|
|
# compatibility. Don't use them in new components.
|
2020-03-28 18:50:43 +01:00
|
|
|
record_status () {
|
|
|
|
"$@"
|
2017-12-11 00:01:40 +01:00
|
|
|
}
|
|
|
|
if_build_succeeded () {
|
2020-03-28 18:50:43 +01:00
|
|
|
"$@"
|
2018-06-07 10:51:44 +02:00
|
|
|
}
|
|
|
|
|
2020-03-28 21:27:40 +01:00
|
|
|
# '! true' does not trigger the ERR trap. Arrange to trigger it, with
|
|
|
|
# a reasonably informative error message (not just "$@").
|
|
|
|
not () {
|
|
|
|
if "$@"; then
|
|
|
|
report_failed_command="! $*"
|
|
|
|
false
|
|
|
|
unset report_failed_command
|
2020-06-02 11:28:07 +02:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2019-09-16 15:55:46 +02:00
|
|
|
pre_prepare_outcome_file () {
|
|
|
|
case "$MBEDTLS_TEST_OUTCOME_FILE" in
|
|
|
|
[!/]*) MBEDTLS_TEST_OUTCOME_FILE="$PWD/$MBEDTLS_TEST_OUTCOME_FILE";;
|
|
|
|
esac
|
|
|
|
if [ -n "$MBEDTLS_TEST_OUTCOME_FILE" ] && [ "$append_outcome" -eq 0 ]; then
|
|
|
|
rm -f "$MBEDTLS_TEST_OUTCOME_FILE"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2018-11-27 15:58:47 +01:00
|
|
|
pre_print_configuration () {
|
2020-06-02 11:28:07 +02:00
|
|
|
if [ $QUIET -eq 1 ]; then
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2018-11-27 15:58:47 +01:00
|
|
|
msg "info: $0 configuration"
|
|
|
|
echo "MEMORY: $MEMORY"
|
|
|
|
echo "FORCE: $FORCE"
|
2019-09-16 15:55:46 +02:00
|
|
|
echo "MBEDTLS_TEST_OUTCOME_FILE: ${MBEDTLS_TEST_OUTCOME_FILE:-(none)}"
|
2018-11-27 15:58:47 +01:00
|
|
|
echo "SEED: ${SEED-"UNSET"}"
|
2020-03-04 20:46:15 +01:00
|
|
|
echo
|
2018-11-27 15:58:47 +01:00
|
|
|
echo "OPENSSL: $OPENSSL"
|
|
|
|
echo "OPENSSL_NEXT: $OPENSSL_NEXT"
|
|
|
|
echo "GNUTLS_CLI: $GNUTLS_CLI"
|
|
|
|
echo "GNUTLS_SERV: $GNUTLS_SERV"
|
|
|
|
echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
|
|
|
|
echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
|
|
|
|
}
|
2016-10-10 15:46:20 +01:00
|
|
|
|
2016-08-26 14:42:14 +01:00
|
|
|
# Make sure the tools we need are available.
|
2018-11-27 15:58:47 +01:00
|
|
|
pre_check_tools () {
|
2019-01-06 22:46:21 +00:00
|
|
|
# Build the list of variables to pass to output_env.sh.
|
|
|
|
set env
|
|
|
|
|
2019-01-06 22:40:00 +00:00
|
|
|
case " $RUN_COMPONENTS " in
|
|
|
|
# Require OpenSSL and GnuTLS if running any tests (as opposed to
|
|
|
|
# only doing builds). Not all tests run OpenSSL and GnuTLS, but this
|
|
|
|
# is a good enough approximation in practice.
|
2023-12-15 20:58:15 +01:00
|
|
|
*" test_"* | *" release_test_"*)
|
2019-01-06 22:40:00 +00:00
|
|
|
# To avoid setting OpenSSL and GnuTLS for each call to compat.sh
|
|
|
|
# and ssl-opt.sh, we just export the variables they require.
|
Use OPENSSL everywhere, not OPENSSL_CMD
These variables were both uses to select the default version of OpenSSL
to use for tests:
- when running compat.sh or ssl-opt.sh directly, OPENSSL_CMD was used;
- when running all.sh, OPENSSL was used.
This caused surprising situations if you had one but not the other set
in your environment. For example I used to have OPENSSL_CMD set but not
OPENSSL, so ssl-opt.sh was failing in some all.sh components but passing
when I ran it manually in the same configuration and build, a rather
unpleasant experience.
The natural name would be OPENSSL, and that's what set in the Docker
images used by the CI. However back in the 1.3.x days, that name was
already used in library/Makefile, so it was preferable to pick a
different one, hence OPENSSL_CMD. However the build system has not been
using this name since at least Mbed TLS 2.0.0, so it's now free for use
again (as demonstrated by the fact that it's been set in the CI without
causing any trouble).
So, unify things and use OPENSSL everywhere. Just leave an error message
for the benefit of developers which might have OPENSSL_CMD, not OPENSSL,
set in their environment from the old days.
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2022-12-19 11:42:12 +01:00
|
|
|
export OPENSSL="$OPENSSL"
|
2019-01-06 22:40:00 +00:00
|
|
|
export GNUTLS_CLI="$GNUTLS_CLI"
|
|
|
|
export GNUTLS_SERV="$GNUTLS_SERV"
|
|
|
|
# Avoid passing --seed flag in every call to ssl-opt.sh
|
|
|
|
if [ -n "${SEED-}" ]; then
|
|
|
|
export SEED
|
|
|
|
fi
|
2023-08-27 21:39:21 +02:00
|
|
|
set "$@" OPENSSL="$OPENSSL"
|
2019-01-06 22:46:21 +00:00
|
|
|
set "$@" GNUTLS_CLI="$GNUTLS_CLI" GNUTLS_SERV="$GNUTLS_SERV"
|
2023-08-27 21:39:21 +02:00
|
|
|
check_tools "$OPENSSL" "$OPENSSL_NEXT" \
|
|
|
|
"$GNUTLS_CLI" "$GNUTLS_SERV"
|
2019-01-06 22:40:00 +00:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
case " $RUN_COMPONENTS " in
|
|
|
|
*_doxygen[_\ ]*) check_tools "doxygen" "dot";;
|
|
|
|
esac
|
|
|
|
|
|
|
|
case " $RUN_COMPONENTS " in
|
2020-04-30 18:19:32 +02:00
|
|
|
*_arm_none_eabi_gcc[_\ ]*) check_tools "${ARM_NONE_EABI_GCC_PREFIX}gcc";;
|
2019-01-06 22:40:00 +00:00
|
|
|
esac
|
|
|
|
|
|
|
|
case " $RUN_COMPONENTS " in
|
|
|
|
*_mingw[_\ ]*) check_tools "i686-w64-mingw32-gcc";;
|
|
|
|
esac
|
|
|
|
|
|
|
|
case " $RUN_COMPONENTS " in
|
|
|
|
*" test_zeroize "*) check_tools "gdb";;
|
|
|
|
esac
|
2016-08-26 14:42:14 +01:00
|
|
|
|
2019-01-06 22:40:00 +00:00
|
|
|
case " $RUN_COMPONENTS " in
|
2019-01-06 22:23:42 +00:00
|
|
|
*_armcc*)
|
2019-01-06 22:40:00 +00:00
|
|
|
ARMC5_CC="$ARMC5_BIN_DIR/armcc"
|
|
|
|
ARMC5_AR="$ARMC5_BIN_DIR/armar"
|
2020-04-30 23:11:54 +02:00
|
|
|
ARMC5_FROMELF="$ARMC5_BIN_DIR/fromelf"
|
2019-01-06 22:40:00 +00:00
|
|
|
ARMC6_CC="$ARMC6_BIN_DIR/armclang"
|
|
|
|
ARMC6_AR="$ARMC6_BIN_DIR/armar"
|
2020-04-30 23:11:54 +02:00
|
|
|
ARMC6_FROMELF="$ARMC6_BIN_DIR/fromelf"
|
|
|
|
check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC5_FROMELF" \
|
|
|
|
"$ARMC6_CC" "$ARMC6_AR" "$ARMC6_FROMELF";;
|
2019-01-06 22:23:42 +00:00
|
|
|
esac
|
2016-08-26 14:42:14 +01:00
|
|
|
|
2020-06-02 11:28:07 +02:00
|
|
|
# past this point, no call to check_tool, only printing output
|
|
|
|
if [ $QUIET -eq 1 ]; then
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2019-01-06 22:46:21 +00:00
|
|
|
msg "info: output_env.sh"
|
|
|
|
case $RUN_COMPONENTS in
|
|
|
|
*_armcc*)
|
|
|
|
set "$@" ARMC5_CC="$ARMC5_CC" ARMC6_CC="$ARMC6_CC" RUN_ARMCC=1;;
|
|
|
|
*) set "$@" RUN_ARMCC=0;;
|
|
|
|
esac
|
|
|
|
"$@" scripts/output_env.sh
|
2018-11-27 15:58:47 +01:00
|
|
|
}
|
2016-08-26 14:42:14 +01:00
|
|
|
|
2021-04-22 01:10:12 +02:00
|
|
|
pre_generate_files() {
|
2021-06-18 13:30:14 +02:00
|
|
|
# since make doesn't have proper dependencies, remove any possibly outdate
|
|
|
|
# file that might be around before generating fresh ones
|
|
|
|
make neat
|
2021-07-08 19:07:07 +02:00
|
|
|
if [ $QUIET -eq 1 ]; then
|
2021-08-05 15:10:47 +02:00
|
|
|
make generated_files >/dev/null
|
2021-07-08 19:07:07 +02:00
|
|
|
else
|
|
|
|
make generated_files
|
|
|
|
fi
|
2021-04-22 01:10:12 +02:00
|
|
|
}
|
|
|
|
|
2024-01-30 13:56:38 +00:00
|
|
|
clang_version() {
|
|
|
|
if command -v clang > /dev/null ; then
|
|
|
|
clang --version|grep version|sed -E 's#.*version ([0-9]+).*#\1#'
|
|
|
|
else
|
|
|
|
echo 0 # report version 0 for "no clang"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2023-05-25 09:39:08 +02:00
|
|
|
################################################################
|
|
|
|
#### Helpers for components using libtestdriver1
|
|
|
|
################################################################
|
2017-12-21 15:59:21 +01:00
|
|
|
|
2023-06-06 11:14:57 +02:00
|
|
|
# How to use libtestdriver1
|
|
|
|
# -------------------------
|
|
|
|
#
|
|
|
|
# 1. Define the list algorithms and key types to accelerate,
|
|
|
|
# designated the same way as PSA_WANT_ macros but without PSA_WANT_.
|
|
|
|
# Examples:
|
|
|
|
# - loc_accel_list="ALG_JPAKE"
|
|
|
|
# - loc_accel_list="ALG_FFDH KEY_TYPE_DH_KEY_PAIR KEY_TYPE_DH_PUBLIC_KEY"
|
Group both configuration steps
Compared to the previous scheme, this avoid the problem of having to
warn about adjusting PSA_WANT in the wrong place.
Also, it allows enabling MBEDTLS_PSA_CRYPTO_CONFIG in adjust_config
rather than having to repeat it in every single component.
It also plays more nicely with components that have an associated
reference component and use a common config function. (Some of them were
already using the new order.)
Finally, "configure, build, run the tests" seems more natural than
"configure, build, configure, build, test" (and, coming back to the
initial point, it avoid questions about what to configure when).
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2023-06-12 17:09:38 +02:00
|
|
|
# 2. Make configurations changes for the driver and/or main libraries.
|
|
|
|
# 2a. Call helper_libtestdriver1_adjust_config <base>, where the argument
|
|
|
|
# can be either "default" to start with the default config, or a name
|
|
|
|
# supported by scripts/config.py (for example, "full"). This selects
|
2023-06-12 17:17:54 +02:00
|
|
|
# the base to use, and makes common adjustments.
|
Group both configuration steps
Compared to the previous scheme, this avoid the problem of having to
warn about adjusting PSA_WANT in the wrong place.
Also, it allows enabling MBEDTLS_PSA_CRYPTO_CONFIG in adjust_config
rather than having to repeat it in every single component.
It also plays more nicely with components that have an associated
reference component and use a common config function. (Some of them were
already using the new order.)
Finally, "configure, build, run the tests" seems more natural than
"configure, build, configure, build, test" (and, coming back to the
initial point, it avoid questions about what to configure when).
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2023-06-12 17:09:38 +02:00
|
|
|
# 2b. If desired, adjust the PSA_WANT symbols in psa/crypto_config.h.
|
|
|
|
# These changes affect both the driver and the main libraries.
|
|
|
|
# (Note: they need to have the same set of PSA_WANT symbols, as that
|
|
|
|
# determines the ABI between them.)
|
|
|
|
# 2c. Adjust MBEDTLS_ symbols in mbedtls_config.h. This only affects the
|
|
|
|
# main libraries. Typically, you want to disable the module(s) that are
|
|
|
|
# being accelerated. You may need to also disable modules that depend
|
|
|
|
# on them or options that are not supported with drivers.
|
|
|
|
# 2d. On top of psa/crypto_config.h, the driver library uses its own config
|
|
|
|
# file: tests/include/test/drivers/config_test_driver.h. You usually
|
|
|
|
# don't need to edit it: using loc_extra_list (see below) is preferred.
|
|
|
|
# However, when there's no PSA symbol for what you want to enable,
|
|
|
|
# calling scripts/config.py on this file remains the only option.
|
|
|
|
# 3. Build the driver library, then the main libraries, test, and programs.
|
|
|
|
# 3a. Call helper_libtestdriver1_make_drivers "$loc_accel_list". You may
|
|
|
|
# need to enable more algorithms here, typically hash algorithms when
|
|
|
|
# accelerating some signature algorithms (ECDSA, RSAv2). This is done
|
|
|
|
# by passing a 2nd argument listing the extra algorithms.
|
|
|
|
# Example:
|
|
|
|
# loc_extra_list="ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512"
|
|
|
|
# helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
|
2023-10-11 13:27:25 +08:00
|
|
|
# 3b. Call helper_libtestdriver1_make_main "$loc_accel_list". Any
|
Group both configuration steps
Compared to the previous scheme, this avoid the problem of having to
warn about adjusting PSA_WANT in the wrong place.
Also, it allows enabling MBEDTLS_PSA_CRYPTO_CONFIG in adjust_config
rather than having to repeat it in every single component.
It also plays more nicely with components that have an associated
reference component and use a common config function. (Some of them were
already using the new order.)
Finally, "configure, build, run the tests" seems more natural than
"configure, build, configure, build, test" (and, coming back to the
initial point, it avoid questions about what to configure when).
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2023-06-12 17:09:38 +02:00
|
|
|
# additional arguments will be passed to make: this can be useful if
|
|
|
|
# you don't want to build everything when iterating during development.
|
|
|
|
# Example:
|
|
|
|
# helper_libtestdriver1_make_main "$loc_accel_list" -C tests test_suite_foo
|
|
|
|
# 4. Run the tests you want.
|
2023-06-06 11:14:57 +02:00
|
|
|
|
2023-05-25 09:39:08 +02:00
|
|
|
# Adjust the configuration - for both libtestdriver1 and main library,
|
|
|
|
# as they should have the same PSA_WANT macros.
|
|
|
|
helper_libtestdriver1_adjust_config() {
|
2023-09-28 09:08:04 +02:00
|
|
|
base_config=$1
|
Group both configuration steps
Compared to the previous scheme, this avoid the problem of having to
warn about adjusting PSA_WANT in the wrong place.
Also, it allows enabling MBEDTLS_PSA_CRYPTO_CONFIG in adjust_config
rather than having to repeat it in every single component.
It also plays more nicely with components that have an associated
reference component and use a common config function. (Some of them were
already using the new order.)
Finally, "configure, build, run the tests" seems more natural than
"configure, build, configure, build, test" (and, coming back to the
initial point, it avoid questions about what to configure when).
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2023-06-12 17:09:38 +02:00
|
|
|
# Select the base configuration
|
2023-09-28 09:08:04 +02:00
|
|
|
if [ "$base_config" != "default" ]; then
|
|
|
|
scripts/config.py "$base_config"
|
Group both configuration steps
Compared to the previous scheme, this avoid the problem of having to
warn about adjusting PSA_WANT in the wrong place.
Also, it allows enabling MBEDTLS_PSA_CRYPTO_CONFIG in adjust_config
rather than having to repeat it in every single component.
It also plays more nicely with components that have an associated
reference component and use a common config function. (Some of them were
already using the new order.)
Finally, "configure, build, run the tests" seems more natural than
"configure, build, configure, build, test" (and, coming back to the
initial point, it avoid questions about what to configure when).
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2023-06-12 17:09:38 +02:00
|
|
|
fi
|
2017-12-21 15:59:21 +01:00
|
|
|
|
Group both configuration steps
Compared to the previous scheme, this avoid the problem of having to
warn about adjusting PSA_WANT in the wrong place.
Also, it allows enabling MBEDTLS_PSA_CRYPTO_CONFIG in adjust_config
rather than having to repeat it in every single component.
It also plays more nicely with components that have an associated
reference component and use a common config function. (Some of them were
already using the new order.)
Finally, "configure, build, run the tests" seems more natural than
"configure, build, configure, build, test" (and, coming back to the
initial point, it avoid questions about what to configure when).
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2023-06-12 17:09:38 +02:00
|
|
|
# Enable PSA-based config (necessary to use drivers)
|
|
|
|
scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
|
|
|
|
|
2023-06-12 17:17:54 +02:00
|
|
|
# Dynamic secure element support is a deprecated feature and needs to be disabled here.
|
|
|
|
# This is done to have the same form of psa_key_attributes_s for libdriver and library.
|
|
|
|
scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
|
2024-03-05 11:46:32 +00:00
|
|
|
|
|
|
|
# If threading is enabled on the normal build, then we need to enable it in the drivers as well,
|
|
|
|
# otherwise we will end up running multithreaded tests without mutexes to protect them.
|
|
|
|
if scripts/config.py get MBEDTLS_THREADING_C; then
|
|
|
|
scripts/config.py -f "$CONFIG_TEST_DRIVER_H" set MBEDTLS_THREADING_C
|
|
|
|
fi
|
|
|
|
|
|
|
|
if scripts/config.py get MBEDTLS_THREADING_PTHREAD; then
|
|
|
|
scripts/config.py -f "$CONFIG_TEST_DRIVER_H" set MBEDTLS_THREADING_PTHREAD
|
|
|
|
fi
|
2023-05-25 09:39:08 +02:00
|
|
|
}
|
2017-12-21 15:59:21 +01:00
|
|
|
|
2023-11-15 12:32:17 +01:00
|
|
|
# Build the drivers library libtestdriver1.a (with ASan).
|
|
|
|
#
|
|
|
|
# Parameters:
|
|
|
|
# 1. a space-separated list of things to accelerate;
|
|
|
|
# 2. optional: a space-separate list of things to also support.
|
|
|
|
# Here "things" are PSA_WANT_ symbols but with PSA_WANT_ removed.
|
|
|
|
helper_libtestdriver1_make_drivers() {
|
|
|
|
loc_accel_flags=$( echo "$1 ${2-}" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
|
|
|
|
make CC=$ASAN_CC -C tests libtestdriver1.a CFLAGS=" $ASAN_CFLAGS $loc_accel_flags" LDFLAGS="$ASAN_CFLAGS"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Build the main libraries, programs and tests,
|
|
|
|
# linking to the drivers library (with ASan).
|
|
|
|
#
|
|
|
|
# Parameters:
|
|
|
|
# 1. a space-separated list of things to accelerate;
|
|
|
|
# *. remaining arguments if any are passed directly to make
|
|
|
|
# (examples: lib, -C tests test_suite_xxx, etc.)
|
|
|
|
# Here "things" are PSA_WANT_ symbols but with PSA_WANT_ removed.
|
|
|
|
helper_libtestdriver1_make_main() {
|
|
|
|
loc_accel_list=$1
|
|
|
|
shift
|
|
|
|
|
|
|
|
# we need flags both with and without the LIBTESTDRIVER1_ prefix
|
|
|
|
loc_accel_flags=$( echo "$loc_accel_list" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
|
|
|
|
loc_accel_flags="$loc_accel_flags $( echo "$loc_accel_list" | sed 's/[^ ]* */-DMBEDTLS_PSA_ACCEL_&/g' )"
|
|
|
|
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" "$@"
|
|
|
|
}
|
|
|
|
|
2024-06-27 07:59:39 +02:00
|
|
|
# Set some default values $CONFIG_H in order to build server or client sides
|
|
|
|
# in PSASIM. There is only 1 mandatory parameter:
|
|
|
|
# - $1: target which can be "client" or "server"
|
2024-07-02 12:02:25 +02:00
|
|
|
helper_psasim_config() {
|
2024-05-07 16:00:21 +02:00
|
|
|
TARGET=$1
|
|
|
|
|
|
|
|
if [ "$TARGET" == "client" ]; then
|
|
|
|
scripts/config.py full
|
|
|
|
scripts/config.py unset MBEDTLS_PSA_CRYPTO_C
|
|
|
|
scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
|
|
|
|
# Dynamic secure element support is a deprecated feature and it is not
|
|
|
|
# available when CRYPTO_C and PSA_CRYPTO_STORAGE_C are disabled.
|
|
|
|
scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
|
|
|
|
# Disable potentially problematic features
|
|
|
|
scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
|
|
|
|
scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
|
|
|
|
scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
|
|
|
|
scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
|
|
|
|
scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
|
2024-06-11 17:26:17 +01:00
|
|
|
scripts/config.py unset MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
|
2024-05-07 16:00:21 +02:00
|
|
|
else
|
|
|
|
scripts/config.py crypto_full
|
|
|
|
scripts/config.py unset MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS
|
2024-06-11 17:26:17 +01:00
|
|
|
# We need to match the client with MBEDTLS_PSA_CRYPTO_SE_C
|
|
|
|
scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
|
|
|
|
# Also ensure MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER not set (to match client)
|
|
|
|
scripts/config.py unset MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
|
2024-05-07 16:00:21 +02:00
|
|
|
fi
|
2024-06-27 07:59:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Helper to build the libraries for client/server in PSASIM. If the server is
|
|
|
|
# being built, then it builds also the final executable.
|
|
|
|
# There is only 1 mandatory parameter:
|
|
|
|
# - $1: target which can be "client" or "server"
|
|
|
|
helper_psasim_build() {
|
|
|
|
TARGET=$1
|
|
|
|
shift
|
|
|
|
TARGET_LIB=${TARGET}_libs
|
|
|
|
|
|
|
|
make -C $PSASIM_PATH CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS" $TARGET_LIB "$@"
|
2024-05-07 16:00:21 +02:00
|
|
|
|
2024-06-27 07:59:39 +02:00
|
|
|
# Build also the server application after its libraries have been built.
|
|
|
|
if [ "$TARGET" == "server" ]; then
|
|
|
|
make -C $PSASIM_PATH CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS" test/psa_server
|
|
|
|
fi
|
2024-05-07 16:00:21 +02:00
|
|
|
}
|
|
|
|
|
2023-11-15 12:32:17 +01:00
|
|
|
################################################################
|
|
|
|
#### Configuration helpers
|
|
|
|
################################################################
|
|
|
|
|
2023-08-15 17:10:47 +02:00
|
|
|
# When called with no parameter this function disables all builtin curves.
|
2023-09-04 14:01:41 +02:00
|
|
|
# The function optionally accepts 1 parameter: a space-separated list of the
|
|
|
|
# curves that should be kept enabled.
|
2023-08-15 17:10:47 +02:00
|
|
|
helper_disable_builtin_curves() {
|
|
|
|
allowed_list="${1:-}"
|
|
|
|
scripts/config.py unset-all "MBEDTLS_ECP_DP_[0-9A-Z_a-z]*_ENABLED"
|
|
|
|
|
2023-09-28 09:08:04 +02:00
|
|
|
for curve in $allowed_list; do
|
|
|
|
scripts/config.py set $curve
|
2023-08-15 17:10:47 +02:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
# Helper returning the list of supported elliptic curves from CRYPTO_CONFIG_H,
|
|
|
|
# without the "PSA_WANT_" prefix. This becomes handy for accelerating curves
|
|
|
|
# in the following helpers.
|
|
|
|
helper_get_psa_curve_list () {
|
|
|
|
loc_list=""
|
2023-09-28 09:08:04 +02:00
|
|
|
for item in $(sed -n 's/^#define PSA_WANT_\(ECC_[0-9A-Z_a-z]*\).*/\1/p' <"$CRYPTO_CONFIG_H"); do
|
|
|
|
loc_list="$loc_list $item"
|
2023-08-15 17:10:47 +02:00
|
|
|
done
|
|
|
|
|
|
|
|
echo "$loc_list"
|
|
|
|
}
|
|
|
|
|
2024-01-17 15:53:46 +01:00
|
|
|
# Helper returning the list of supported DH groups from CRYPTO_CONFIG_H,
|
|
|
|
# without the "PSA_WANT_" prefix. This becomes handy for accelerating DH groups
|
|
|
|
# in the following helpers.
|
|
|
|
helper_get_psa_dh_group_list () {
|
|
|
|
loc_list=""
|
|
|
|
for item in $(sed -n 's/^#define PSA_WANT_\(DH_RFC7919_[0-9]*\).*/\1/p' <"$CRYPTO_CONFIG_H"); do
|
|
|
|
loc_list="$loc_list $item"
|
|
|
|
done
|
|
|
|
|
|
|
|
echo "$loc_list"
|
|
|
|
}
|
|
|
|
|
2023-08-15 17:10:47 +02:00
|
|
|
# Get the list of uncommented PSA_WANT_KEY_TYPE_xxx_ from CRYPTO_CONFIG_H. This
|
2023-09-01 09:12:31 +02:00
|
|
|
# is useful to easily get a list of key type symbols to accelerate.
|
2023-08-15 17:10:47 +02:00
|
|
|
# The function accepts a single argument which is the key type: ECC, DH, RSA.
|
2023-09-01 09:12:31 +02:00
|
|
|
helper_get_psa_key_type_list() {
|
2023-09-28 09:08:04 +02:00
|
|
|
key_type="$1"
|
2023-08-15 17:10:47 +02:00
|
|
|
loc_list=""
|
2023-09-28 09:08:04 +02:00
|
|
|
for item in $(sed -n "s/^#define PSA_WANT_\(KEY_TYPE_${key_type}_[0-9A-Z_a-z]*\).*/\1/p" <"$CRYPTO_CONFIG_H"); do
|
2023-08-15 17:10:47 +02:00
|
|
|
# Skip DERIVE for elliptic keys since there is no driver dispatch for
|
|
|
|
# it so it cannot be accelerated.
|
2023-09-28 09:08:04 +02:00
|
|
|
if [ "$item" != "KEY_TYPE_ECC_KEY_PAIR_DERIVE" ]; then
|
|
|
|
loc_list="$loc_list $item"
|
2023-08-15 17:10:47 +02:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
echo "$loc_list"
|
|
|
|
}
|
|
|
|
|
2024-07-25 14:24:37 +01:00
|
|
|
# Include the components from components.sh
|
|
|
|
test_script_dir="${0%/*}"
|
2024-07-26 12:34:19 +01:00
|
|
|
source "$test_script_dir/components-compiler.sh"
|
|
|
|
source "$test_script_dir/components-platform.sh"
|
|
|
|
source "$test_script_dir/components-build-system.sh"
|
|
|
|
source "$test_script_dir/components-configuration.sh"
|
|
|
|
source "$test_script_dir/components-configuration-platform.sh"
|
|
|
|
source "$test_script_dir/components-configuration-tls.sh"
|
|
|
|
source "$test_script_dir/components-configuration-x509.sh"
|
|
|
|
source "$test_script_dir/components-configuration-crypto.sh"
|
|
|
|
source "$test_script_dir/components-basic-checks.sh"
|
|
|
|
source "$test_script_dir/components-sanitizers.sh"
|
|
|
|
source "$test_script_dir/components-compliance.sh"
|
2024-07-26 20:32:04 +01:00
|
|
|
source "$test_script_dir/components-psasim.sh"
|
2024-06-27 07:59:39 +02:00
|
|
|
|
2017-12-21 15:59:21 +01:00
|
|
|
################################################################
|
|
|
|
#### Termination
|
|
|
|
################################################################
|
|
|
|
|
2018-11-27 15:58:47 +01:00
|
|
|
post_report () {
|
|
|
|
msg "Done, cleaning up"
|
2020-03-30 20:11:39 +02:00
|
|
|
final_cleanup
|
2018-11-27 15:58:47 +01:00
|
|
|
|
|
|
|
final_report
|
|
|
|
}
|
|
|
|
|
|
|
|
################################################################
|
|
|
|
#### Run all the things
|
|
|
|
################################################################
|
|
|
|
|
2020-03-28 21:09:21 +01:00
|
|
|
# Function invoked by --error-test to test error reporting.
|
|
|
|
pseudo_component_error_test () {
|
2021-08-02 23:28:00 +02:00
|
|
|
msg "Testing error reporting $error_test_i"
|
2020-03-28 21:09:21 +01:00
|
|
|
if [ $KEEP_GOING -ne 0 ]; then
|
|
|
|
echo "Expect three failing commands."
|
|
|
|
fi
|
2021-08-02 23:28:00 +02:00
|
|
|
# If the component doesn't run in a subshell, changing error_test_i to an
|
|
|
|
# invalid integer will cause an error in the loop that runs this function.
|
|
|
|
error_test_i=this_should_not_be_used_since_the_component_runs_in_a_subshell
|
2021-08-02 23:14:03 +02:00
|
|
|
# Expected error: 'grep non_existent /dev/null -> 1'
|
2020-03-28 21:09:21 +01:00
|
|
|
grep non_existent /dev/null
|
2021-08-02 23:14:03 +02:00
|
|
|
# Expected error: '! grep -q . tests/scripts/all.sh -> 1'
|
2020-03-28 21:09:21 +01:00
|
|
|
not grep -q . "$0"
|
2021-08-02 23:14:03 +02:00
|
|
|
# Expected error: 'make unknown_target -> 2'
|
2020-03-28 21:09:21 +01:00
|
|
|
make unknown_target
|
|
|
|
false "this should not be executed"
|
|
|
|
}
|
|
|
|
|
2018-11-27 16:06:30 +01:00
|
|
|
# Run one component and clean up afterwards.
|
2018-11-27 15:58:47 +01:00
|
|
|
run_component () {
|
2018-12-04 12:49:28 +01:00
|
|
|
current_component="$1"
|
2019-09-16 15:20:36 +02:00
|
|
|
export MBEDTLS_TEST_CONFIGURATION="$current_component"
|
2019-10-07 18:44:21 +02:00
|
|
|
|
|
|
|
# Unconditionally create a seedfile that's sufficiently long.
|
|
|
|
# Do this before each component, because a previous component may
|
|
|
|
# have messed it up or shortened it.
|
2021-07-08 19:03:50 +02:00
|
|
|
local dd_cmd
|
|
|
|
dd_cmd=(dd if=/dev/urandom of=./tests/seedfile bs=64 count=1)
|
|
|
|
case $OSTYPE in
|
2022-03-16 14:11:07 +00:00
|
|
|
linux*|freebsd*|openbsd*) dd_cmd+=(status=none)
|
2021-07-08 19:03:50 +02:00
|
|
|
esac
|
|
|
|
"${dd_cmd[@]}"
|
2019-10-07 18:44:21 +02:00
|
|
|
|
2024-07-12 14:30:16 +02:00
|
|
|
if [ -d tf-psa-crypto ]; then
|
|
|
|
dd_cmd=(dd if=/dev/urandom of=./tf-psa-crypto/tests/seedfile bs=64 count=1)
|
|
|
|
case $OSTYPE in
|
|
|
|
linux*|freebsd*|openbsd*) dd_cmd+=(status=none)
|
|
|
|
esac
|
|
|
|
"${dd_cmd[@]}"
|
|
|
|
fi
|
|
|
|
|
2021-08-02 23:14:03 +02:00
|
|
|
# Run the component in a subshell, with error trapping and output
|
|
|
|
# redirection set up based on the relevant options.
|
2020-03-28 18:50:43 +01:00
|
|
|
if [ $KEEP_GOING -eq 1 ]; then
|
2021-08-02 23:14:03 +02:00
|
|
|
# We want to keep running if the subshell fails, so 'set -e' must
|
|
|
|
# be off when the subshell runs.
|
2020-03-28 18:50:43 +01:00
|
|
|
set +e
|
|
|
|
fi
|
|
|
|
(
|
|
|
|
if [ $QUIET -eq 1 ]; then
|
|
|
|
# msg() will be silenced, so just print the component name here.
|
|
|
|
echo "${current_component#component_}"
|
|
|
|
exec >/dev/null
|
|
|
|
fi
|
|
|
|
if [ $KEEP_GOING -eq 1 ]; then
|
|
|
|
# Keep "set -e" off, and run an ERR trap instead to record failures.
|
|
|
|
set -E
|
|
|
|
trap err_trap ERR
|
|
|
|
fi
|
|
|
|
# The next line is what runs the component
|
|
|
|
"$@"
|
|
|
|
if [ $KEEP_GOING -eq 1 ]; then
|
|
|
|
trap - ERR
|
|
|
|
exit $last_failure_status
|
|
|
|
fi
|
|
|
|
)
|
|
|
|
component_status=$?
|
|
|
|
if [ $KEEP_GOING -eq 1 ]; then
|
|
|
|
set -e
|
|
|
|
if [ $component_status -ne 0 ]; then
|
|
|
|
failure_count=$((failure_count + 1))
|
|
|
|
fi
|
2020-06-02 11:28:07 +02:00
|
|
|
fi
|
2019-10-07 18:44:21 +02:00
|
|
|
|
|
|
|
# Restore the build tree to a clean state.
|
2018-11-27 16:06:30 +01:00
|
|
|
cleanup
|
2020-06-08 10:59:41 +02:00
|
|
|
unset current_component
|
2018-11-27 15:58:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# Preliminary setup
|
|
|
|
pre_check_environment
|
|
|
|
pre_initialize_variables
|
|
|
|
pre_parse_command_line "$@"
|
2018-11-27 17:04:29 +01:00
|
|
|
|
2024-02-26 11:41:19 +00:00
|
|
|
setup_quiet_wrappers
|
2019-01-06 20:50:38 +00:00
|
|
|
pre_check_git
|
2021-07-12 18:16:01 +02:00
|
|
|
pre_restore_files
|
2020-03-30 20:11:39 +02:00
|
|
|
pre_back_up
|
2019-02-14 07:18:59 -05:00
|
|
|
|
2019-01-06 20:50:38 +00:00
|
|
|
build_status=0
|
|
|
|
if [ $KEEP_GOING -eq 1 ]; then
|
|
|
|
pre_setup_keep_going
|
2018-11-27 15:58:47 +01:00
|
|
|
fi
|
2019-09-16 15:55:46 +02:00
|
|
|
pre_prepare_outcome_file
|
2019-01-06 20:50:38 +00:00
|
|
|
pre_print_configuration
|
|
|
|
pre_check_tools
|
2014-03-19 18:29:01 +01:00
|
|
|
cleanup
|
2023-08-17 17:32:26 +01:00
|
|
|
if in_mbedtls_repo; then
|
2023-07-14 12:30:00 +01:00
|
|
|
pre_generate_files
|
|
|
|
fi
|
2014-03-19 18:29:01 +01:00
|
|
|
|
2019-01-06 22:11:25 +00:00
|
|
|
# Run the requested tests.
|
2021-08-02 23:28:00 +02:00
|
|
|
for ((error_test_i=1; error_test_i <= error_test; error_test_i++)); do
|
2020-03-28 21:09:21 +01:00
|
|
|
run_component pseudo_component_error_test
|
|
|
|
done
|
2021-08-02 23:28:00 +02:00
|
|
|
unset error_test_i
|
2019-01-06 22:11:25 +00:00
|
|
|
for component in $RUN_COMPONENTS; do
|
|
|
|
run_component "component_$component"
|
|
|
|
done
|
2014-03-19 18:29:01 +01:00
|
|
|
|
2018-11-27 15:58:47 +01:00
|
|
|
# We're done.
|
2019-01-06 20:50:38 +00:00
|
|
|
post_report
|