Merge pull request #141 from valeriosetti/issue138-framework

[framework] Add test_tf_psa_crypto_cmake_shared to components-build-system.sh
This commit is contained in:
Ronald Cron
2025-04-04 10:01:09 +02:00
committed by GitHub
3 changed files with 122 additions and 22 deletions
+43 -11
View File
@@ -16,18 +16,43 @@
set -e -u set -e -u
## $root_dir is the root directory of the Mbed TLS source tree. DEMO_COMMON_NEED_QUERY_COMPILE_TIME_CONFIG=${DEMO_COMMON_NEED_QUERY_COMPILE_TIME_CONFIG:-1}
need_query_compile_time_config () {
if [ $DEMO_COMMON_NEED_QUERY_COMPILE_TIME_CONFIG -eq 1 ]; then
return 0;
else
return 1;
fi
}
## At the end of the while loop below $root_dir will point to the root directory
## of the Mbed TLS or TF-PSA-Crypto source tree.
root_dir="${0%/*}" root_dir="${0%/*}"
# Find a nice path to the root directory, avoiding unnecessary "../". ## Find a nice path to the root directory, avoiding unnecessary "../".
# The code supports demo scripts nested up to 4 levels deep. ##
# The code works no matter where the demo script is relative to the current ## The code supports demo scripts nested up to 4 levels deep.
# directory, even if it is called with a relative path. ##
n=4 # limit the search depth ## The code works no matter where the demo script is relative to the current
while ! [ -d "$root_dir/programs" ] || ! [ -d "$root_dir/library" ]; do ## directory, even if it is called with a relative path.
n=5
while true; do
# If we went up too many folders, then give up and return a failure.
if [ $n -eq 0 ]; then if [ $n -eq 0 ]; then
echo >&2 "This doesn't seem to be an Mbed TLS source tree." echo >&2 "This doesn't seem to be an Mbed TLS source tree."
exit 125 exit 125
fi fi
# If we reached the Mbed TLS root folder then we're done.
if is_mbedtls_root "$root_dir"; then
break;
fi
# If we reached the TF-PSA-Crypto root folder and the script that sourced
# this file does not need query_compile_time_config (which is only available
# in Mbed TLS repo) then we're done.
if is_tf_psa_crypto_root "$root_dir" && ! need_query_compile_time_config; then
break;
fi
n=$((n - 1)) n=$((n - 1))
case $root_dir in case $root_dir in
.) root_dir="..";; .) root_dir="..";;
@@ -38,10 +63,6 @@ while ! [ -d "$root_dir/programs" ] || ! [ -d "$root_dir/library" ]; do
esac esac
done done
## $programs_dir is the directory containing the sample programs.
# Assume an in-tree build.
programs_dir="$root_dir/programs"
## msg LINE... ## msg LINE...
## msg <TEXT_ORIGIN ## msg <TEXT_ORIGIN
## Display an informational message. ## Display an informational message.
@@ -80,9 +101,20 @@ run_bad () {
not "$@" not "$@"
} }
## $programs_dir is the directory containing the sample programs.
## Assume an in-tree build.
programs_dir="$root_dir/programs"
## config_has SYMBOL... ## config_has SYMBOL...
## Succeeds if the library configuration has all SYMBOLs set. ## Succeeds if the library configuration has all SYMBOLs set.
##
## Note: "query_compile_time_config" is only available when in Mbed TLS project,
## so "config_has" is not available in TF-PSA-Crypto one. If this function is
## called from the latter we fail immediately.
config_has () { config_has () {
if ! is_mbedtls_root "$root_dir"; then
return 1;
fi
for x in "$@"; do for x in "$@"; do
"$programs_dir/test/query_compile_time_config" "$x" "$programs_dir/test/query_compile_time_config" "$x"
done done
+61 -7
View File
@@ -9,25 +9,79 @@
# help detect which project (Mbed TLS, TF-PSA-Crypto) # help detect which project (Mbed TLS, TF-PSA-Crypto)
# or which Mbed TLS branch they are in. # or which Mbed TLS branch they are in.
# Project detection # Project detection.
#
# Both Mbed TLS and TF-PSA-Cryto repos have a "scripts/project_name.txt" file
# which contains the name of the project. They are used in scripts to know in
# which project/folder we're in.
# This function accepts 2 parameters:
# - $1: boolean value which defines the behavior in case
# "scripts/project_name.txt" is not found:
# - 1: exit with error message
# - 0: simply return an error
# - $2: mandatory value which defined the root folder where to look for
# "scripts/project_name.txt".
read_project_name_file () { read_project_name_file () {
SCRIPT_DIR=$(pwd) EXIT_IF_NOT_FOUND=$1
ROOT_PATH=$2
PROJECT_NAME_FILE="scripts/project_name.txt" PROJECT_NAME_FILE="scripts/project_name.txt"
if read -r PROJECT_NAME < "$PROJECT_NAME_FILE"; then :; else # Check if file exists.
echo "$PROJECT_NAME_FILE does not exist... Exiting..." >&2 if [ ! -f "$ROOT_PATH/$PROJECT_NAME_FILE" ]; then
exit 1 if $EXIT_IF_NOT_FOUND ; then
echo "$ROOT_PATH/$PROJECT_NAME_FILE does not exist... Exiting..." >&2
exit 1
fi
# Simply return a failure in case we were asked not to fail in case of
# missing file.
return 1
fi
if read -r PROJECT_NAME < "$ROOT_PATH/$PROJECT_NAME_FILE"; then :; else
return 1
fi fi
} }
# Check if the current folder is the Mbed TLS root one.
#
# Warning: if this is not run from Mbed TLS/TF-PSA-Crypto root folder, the
# script is terminated with a failure.
in_mbedtls_repo () { in_mbedtls_repo () {
read_project_name_file read_project_name_file true .
test "$PROJECT_NAME" = "Mbed TLS" test "$PROJECT_NAME" = "Mbed TLS"
} }
# Check if the current folder is the TF-PSA-Crypto root one.
#
# Warning: if this is not run from Mbed TLS/TF-PSA-Crypto root folder, the
# script is terminated with a failure.
in_tf_psa_crypto_repo () { in_tf_psa_crypto_repo () {
read_project_name_file read_project_name_file true .
test "$PROJECT_NAME" = "TF-PSA-Crypto"
}
# Check if $1 is an Mbed TLS root folder.
#
# Differently from in_mbedtls_repo() above, this can be run on any folder
# without causing the script to exit.
is_mbedtls_root() {
if ! read_project_name_file false $1 ; then
return 1
fi
test "$PROJECT_NAME" = "Mbed TLS"
}
# Check if $1 is a TF-PSA-Crypto root folder.
#
# Differently from in_tf_psa_crypto_repo() above, this can be run on any folder
# without causing the script to exit.
is_tf_psa_crypto_root() {
if ! read_project_name_file false $1 ; then
return 1
fi
test "$PROJECT_NAME" = "TF-PSA-Crypto" test "$PROJECT_NAME" = "TF-PSA-Crypto"
} }
+18 -4
View File
@@ -6,17 +6,31 @@
# Copyright The Mbed TLS Contributors # Copyright The Mbed TLS Contributors
# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later # SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
. "${0%/*}/../../scripts/demo_common.sh" DEMO_COMMON_NEED_QUERY_COMPILE_TIME_CONFIG=0
SCRIPT_DIR=$(dirname "$0")
. "${SCRIPT_DIR}/../../scripts/project_detection.sh"
. "${SCRIPT_DIR}/../../scripts/demo_common.sh"
msg "Test the dynamic loading of libmbed*" msg "Test the dynamic loading of libmbed*"
program="$programs_dir/test/dlopen" # Once demo_common.sh is sourced we'll have the following variables set:
library_dir="$root_dir/library" # - $root_dir points to the root path of Mbed TLS or TF-PSA-Crypto;
# - $programs_dir points to "$root_dir/programs" folder.
if is_mbedtls_root $root_dir; then
msg "Running in Mbed TLS repo"
program="$programs_dir/test/dlopen"
library_dir="$root_dir/library"
else
msg "Running in TF-PSA-Crypto repo"
program="$root_dir/programs/test/tfpsacrypto_dlopen"
library_dir="$root_dir/core"
fi
# Skip this test if we don't have a shared library build. Detect this # Skip this test if we don't have a shared library build. Detect this
# through the absence of the demo program. # through the absence of the demo program.
if [ ! -e "$program" ]; then if [ ! -e "$program" ]; then
msg "$0: this demo requires a shared library build." msg "Error: demo program $program not found."
# Exit with a success status so that this counts as a pass for run_demos.py. # Exit with a success status so that this counts as a pass for run_demos.py.
exit exit
fi fi