Skip to content

Commit e248de5

Browse files
authored
Merge pull request #9720 from mpg/all.sh-tf-psa-crypto-dev
All.sh add support for tf-psa-crypto components
2 parents fc140d0 + dea700d commit e248de5

File tree

6 files changed

+193
-47
lines changed

6 files changed

+193
-47
lines changed

tests/scripts/all-core.sh

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,12 @@
109109
# means that components can assume that the working directory is in a
110110
# cleaned-up state, and don't need to perform the cleanup themselves.
111111
# * Run `make clean`.
112-
# * Restore `include/mbedtls/mbedtls_config.h` from a backup made before running
113-
# the component.
114-
# * Check out `Makefile`, `library/Makefile`, `programs/Makefile`,
115-
# `tests/Makefile` and `programs/fuzz/Makefile` from git.
116-
# This cleans up after an in-tree use of CMake.
112+
# * Restore the various config files (potentially modified by config.py) from
113+
# a backup made when starting the script.
114+
# * If in Mbed TLS, restore the various `Makefile`s (potentially modified by
115+
# in-tree use of CMake) from a backup made when starting the script. (Note:
116+
# if the files look generated when starting the script, they will be
117+
# restored from the git index before making the backup.)
117118

118119

119120
################################################################
@@ -156,15 +157,16 @@ pre_check_environment () {
156157
# Must be called before pre_initialize_variables which sets ALL_COMPONENTS.
157158
pre_load_components () {
158159
# Include the components from components.sh
159-
test_script_dir="${0%/*}"
160-
for file in "$test_script_dir"/components-*.sh; do
160+
# Use a path relative to the current directory, aka project's root.
161+
for file in tests/scripts/components-*.sh; do
161162
source $file
162163
done
163164
}
164165

165166
pre_initialize_variables () {
166167
if in_mbedtls_repo; then
167168
CONFIG_H='include/mbedtls/mbedtls_config.h'
169+
CONFIG_TEST_DRIVER_H='tests/include/test/drivers/config_test_driver.h'
168170
if [ -d tf-psa-crypto ]; then
169171
CRYPTO_CONFIG_H='tf-psa-crypto/include/psa/crypto_config.h'
170172
PSA_CORE_PATH='tf-psa-crypto/core'
@@ -176,20 +178,21 @@ pre_initialize_variables () {
176178
PSA_CORE_PATH=''
177179
BUILTIN_SRC_PATH=''
178180
fi
181+
config_files="$CONFIG_H $CRYPTO_CONFIG_H $CONFIG_TEST_DRIVER_H"
179182
else
180-
CONFIG_H='drivers/builtin/include/mbedtls/mbedtls_config.h'
181183
CRYPTO_CONFIG_H='include/psa/crypto_config.h'
182184
PSA_CORE_PATH='core'
183185
BUILTIN_SRC_PATH='drivers/builtin/src'
186+
187+
config_files="$CRYPTO_CONFIG_H"
184188
fi
185-
CONFIG_TEST_DRIVER_H='tests/include/test/drivers/config_test_driver.h'
186189

187190
# Files that are clobbered by some jobs will be backed up. Use a different
188191
# suffix from auxiliary scripts so that all.sh and auxiliary scripts can
189192
# independently decide when to remove the backup file.
190193
backup_suffix='.all.bak'
191194
# Files clobbered by config.py
192-
files_to_back_up="$CONFIG_H $CRYPTO_CONFIG_H $CONFIG_TEST_DRIVER_H"
195+
files_to_back_up="$config_files"
193196
if in_mbedtls_repo; then
194197
# Files clobbered by in-tree cmake
195198
files_to_back_up="$files_to_back_up Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile"
@@ -623,7 +626,7 @@ pre_parse_command_line () {
623626
pre_check_git () {
624627
if [ $FORCE -eq 1 ]; then
625628
rm -rf "$OUT_OF_SOURCE_DIR"
626-
git checkout-index -f -q $CONFIG_H
629+
git checkout-index -f -q $config_files
627630
cleanup
628631
else
629632
@@ -634,12 +637,14 @@ pre_check_git () {
634637
exit 1
635638
fi
636639
637-
if ! git diff --quiet "$CONFIG_H"; then
638-
err_msg "Warning - the configuration file '$CONFIG_H' has been edited. "
639-
echo "You can either delete or preserve your work, or force the test by rerunning the"
640-
echo "script as: $0 --force"
641-
exit 1
642-
fi
640+
for config in $config_files; do
641+
if ! git diff --quiet "$config"; then
642+
err_msg "Warning - the configuration file '$config' has been edited. "
643+
echo "You can either delete or preserve your work, or force the test by rerunning the"
644+
echo "script as: $0 --force"
645+
exit 1
646+
fi
647+
done
643648
fi
644649
}
645650
@@ -866,7 +871,8 @@ pre_check_tools () {
866871
set "$@" ARMC6_CC="$ARMC6_CC" RUN_ARMCC=1;;
867872
*) set "$@" RUN_ARMCC=0;;
868873
esac
869-
"$@" scripts/output_env.sh
874+
# Use a path relative to the currently-sourced file.
875+
"$@" "${BASH_SOURCE%/*}"/../../scripts/output_env.sh
870876
}
871877
872878
pre_generate_files() {
@@ -881,8 +887,8 @@ pre_generate_files() {
881887
}
882888
883889
pre_load_helpers () {
884-
# The path is going to change when this is moved to the framework
885-
test_script_dir="${0%/*}"
890+
# Use a path relative to the currently-sourced file.
891+
test_script_dir="${BASH_SOURCE%/*}"
886892
source "$test_script_dir"/all-helpers.sh
887893
}
888894

tests/scripts/all.sh

Lines changed: 104 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,112 @@
11
#! /usr/bin/env bash
22

3-
# all.sh
3+
# all.sh (transitional wrapper)
44
#
55
# Copyright The Mbed TLS Contributors
66
# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
77

8-
# This file is executable; it is the entry point for users and the CI.
9-
# See "Files structure" in all-core.sh for other files used.
8+
# This is a transitional wrapper that's only meant for the CI.
9+
# Developers should directly invoke on or two of:
10+
# - tests/scripts/mbedtls-all.sh ...
11+
# - (cd tf-psa-crypto && tests/scripts/all.sh ...)
12+
#
13+
# During the transition, it's illegal for a tf-psa-crypto component to have
14+
# the same name as an mbedtls components; since this wrapper handles both
15+
# sides at once, component names need to be globally unique. Once the
16+
# transition period is over, unicity on each side will be enough.
17+
#
18+
# For context, here are the steps of the transition:
19+
# 1. We have an all.sh in tf-psa-crypto but for now we don't invoke it directly
20+
# on the CI, only through this transitional wrapper in mbedtls. (tf-psa-crypto
21+
# doesn't have its own CI initially and runs Mbed TLS's instead.)
22+
# 2. We move all relevant components to tf-psa-crypto so that it gets the level of
23+
# coverage we want. We need to make sure the new names are unique.
24+
# 3. We change the CI job on tf-psa-crypto to stop checking out mbedtls and running
25+
# its all.sh - instead we do the normal thing of checking out tf-psa-crypto and
26+
# running its all.sh. (In two steps: (a) add the new job, (b) remove the old
27+
# one.)
28+
# 4. We remove the transitional wrapper in mbedtls and we're now free to rename
29+
# tf-psa-crypto components as we want. If we followed a consistent naming
30+
# pattern, this can be as simple as s/_tf_psa_crypto// in components-*.sh.
31+
32+
# This script must be invoked from the project's root.
33+
34+
# There are exactly 4 ways this is invoked in the CI:
35+
# 1. tests/scripts/all.sh --help
36+
# 2. tests/scripts/all.sh --list-all-components
37+
# 3. tests/scripts/all.sh --list-components
38+
# 4. tests/scripts/all.sh --seed 4 --keep-going single_component_name
39+
# This wrapper does not support other invocations.
40+
41+
set -eu
42+
43+
# Cases 1-3
44+
if [ "$#" -eq 1 ]; then
45+
if [ "$1" = '--help' ]; then
46+
# It doesn't matter which one we use, they're the same
47+
tests/scripts/mbedtls-all.sh "$1"
48+
exit 0
49+
fi
50+
if [ "$1" = '--list-all-components' -o "$1" = '--list-components' ]; then
51+
# Invoke both
52+
tests/scripts/mbedtls-all.sh "$1"
53+
(cd tf-psa-crypto && tests/scripts/all.sh "$1")
54+
exit 0
55+
fi
56+
fi
57+
58+
if [ "$#" -ne 4 -o "${1:-unset}" != '--seed' -o "${3:-unset}" != '--keep-going' ]; then
59+
echo "This invocation is not supported by the transitional wrapper." >&2
60+
echo "See the comments at the top of $0." >&2
61+
exit 1
62+
fi
63+
64+
# Case 4: invoke the right all.sh for this component
65+
comp_name=$4
66+
67+
# Get the list of components available on each side.
68+
COMP_MBEDTLS=$(tests/scripts/mbedtls-all.sh --list-all-components | tr '\n' ' ')
69+
COMP_CRYPTO=$(cd tf-psa-crypto && tests/scripts/all.sh --list-all-components | tr '\n' ' ')
70+
71+
# tell if $1 is in space-separated list $2
72+
is_in() {
73+
needle=$1
74+
haystack=$2
75+
case " $haystack " in
76+
*" $needle "*) echo 1;;
77+
*) echo 0;;
78+
esac
79+
}
80+
81+
is_crypto=$(is_in "$comp_name" "$COMP_CRYPTO")
82+
is_mbedtls=$(is_in "$comp_name" "$COMP_MBEDTLS")
83+
84+
# Component should be on exactly one side (see comment near the top).
85+
if [ "$is_crypto" -eq 1 -a "$is_mbedtls" -eq 1 ]; then
86+
echo "Component '$comp_name' is both in crypto and Mbed TLS". >&2
87+
echo "See the comments at the top of $0." >&2
88+
exit 1
89+
fi
90+
if [ "$is_crypto" -eq 0 -a "$is_mbedtls" -eq 0 ]; then
91+
echo "Component '$comp_name' is neither in crypto nor in Mbed TLS". >&2
92+
echo "See the comments at the top of $0." >&2
93+
exit 1
94+
fi
1095

11-
# The path is going to change when this is moved to the framework
12-
test_script_dir="${0%/*}"
13-
source "$test_script_dir"/all-core.sh
1496

15-
main "$@"
97+
# Invoke the real thing
98+
if [ "$is_crypto" -eq 1 ]; then
99+
# Make sure the path to the outcomes file is absolute. This is done by
100+
# pre_prepare_outcome_file() however by the time it runs we've already
101+
# changed the working directory, so do it now.
102+
if [ -n "${MBEDTLS_TEST_OUTCOME_FILE+set}" ]; then
103+
case "$MBEDTLS_TEST_OUTCOME_FILE" in
104+
[!/]*) MBEDTLS_TEST_OUTCOME_FILE="$PWD/$MBEDTLS_TEST_OUTCOME_FILE";;
105+
esac
106+
export MBEDTLS_TEST_OUTCOME_FILE
107+
fi
108+
cd tf-psa-crypto
109+
exec tests/scripts/all.sh "$@"
110+
else
111+
exec tests/scripts/mbedtls-all.sh "$@"
112+
fi

tests/scripts/components-build-system.sh

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -85,26 +85,6 @@ component_test_cmake_out_of_source () {
8585
rm -rf "$OUT_OF_SOURCE_DIR"
8686
}
8787

88-
component_test_cmake_tf_psa_crypto_out_of_source () {
89-
# Remove existing generated files so that we use the ones cmake
90-
# generates
91-
make neat
92-
msg "build: cmake tf-psa-crypto 'out-of-source' build"
93-
MBEDTLS_ROOT_DIR="$PWD"
94-
cd tf-psa-crypto
95-
TF_PSA_CRYPTO_ROOT_DIR="$PWD"
96-
mkdir "$OUT_OF_SOURCE_DIR"
97-
cd "$OUT_OF_SOURCE_DIR"
98-
# Note: Explicitly generate files as these are turned off in releases
99-
cmake -D CMAKE_BUILD_TYPE:String=Check -D GEN_FILES=ON "$TF_PSA_CRYPTO_ROOT_DIR"
100-
make
101-
msg "test: cmake tf-psa-crypto 'out-of-source' build"
102-
make test
103-
cd "$TF_PSA_CRYPTO_ROOT_DIR"
104-
rm -rf "$OUT_OF_SOURCE_DIR"
105-
cd "$MBEDTLS_ROOT_DIR"
106-
}
107-
10888
component_test_cmake_as_subdirectory () {
10989
# Remove existing generated files so that we use the ones CMake
11090
# generates

tests/scripts/mbedtls-all.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#! /usr/bin/env bash
2+
3+
# all.sh (mbedtls part)
4+
#
5+
# Copyright The Mbed TLS Contributors
6+
# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
7+
8+
# This file is executable; it is the entry point for users and the CI.
9+
# See "Files structure" in all-core.sh for other files used.
10+
11+
# This script must be invoked from the project's root.
12+
13+
# The path is going to change when this is moved to the framework
14+
source tests/scripts/all-core.sh
15+
16+
main "$@"

tf-psa-crypto/tests/scripts/all.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#! /usr/bin/env bash
2+
3+
# all.sh
4+
#
5+
# Copyright The Mbed TLS Contributors
6+
# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
7+
8+
# This file is executable; it is the entry point for users and the CI.
9+
# See "Files structure" in all-core.sh for other files used.
10+
11+
# This script must be invoked from the project's root.
12+
13+
# Prevent silly mistakes when people would invoke this from mbedtls
14+
if [ -d tf-psa-crypto -a -d library ]; then
15+
echo "When invoking this script from an mbedtls checkout," >&2
16+
echo "you must change the working directory to tf-psa-crypto." >&2
17+
exit 255
18+
fi
19+
20+
# The path is going to change when this is moved to the framework
21+
source ../tests/scripts/all-core.sh
22+
23+
main "$@"
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# components-build-system.sh
2+
#
3+
# Copyright The Mbed TLS Contributors
4+
# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
5+
6+
# This file contains test components that are executed by all.sh
7+
8+
################################################################
9+
#### Build System Testing
10+
################################################################
11+
12+
component_test_cmake_tf_psa_crypto_out_of_source () {
13+
msg "build: cmake tf-psa-crypto 'out-of-source' build"
14+
TF_PSA_CRYPTO_ROOT_DIR="$PWD"
15+
mkdir "$OUT_OF_SOURCE_DIR"
16+
cd "$OUT_OF_SOURCE_DIR"
17+
# Note: Explicitly generate files as these are turned off in releases
18+
cmake -D CMAKE_BUILD_TYPE:String=Check -D GEN_FILES=ON "$TF_PSA_CRYPTO_ROOT_DIR"
19+
make
20+
msg "test: cmake tf-psa-crypto 'out-of-source' build"
21+
make test
22+
cd "$TF_PSA_CRYPTO_ROOT_DIR"
23+
rm -rf "$OUT_OF_SOURCE_DIR"
24+
}

0 commit comments

Comments
 (0)