Skip to contentSkip to conversation

arm/trusted-firmware-m: Enable regression test build

PATCH New Gergely Kovacs 1 participant 1 message May 11

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 arm/trusted-firmware-m: Enable regression test build

From: David Hu <[email protected]>

TF-M build system has introduced a ground-breaking change since v2.0.0. Enable TF-M regression test build, following build instructions in TF-M document [1].

Add the BUILD_REGRESSION_TESTS variable to enable regression test builds. Individual regression test suites can be selected by passing the appropriate TF-M CMake options through EXTRA_OECMAKE. If regression test is enabled, build TF-M and tests from tf-m-tests directory.

The build files for Normal World build will be installed.

[1]: https://trustedfirmware-m.readthedocs.io/en/latest/building/tests_build_instruction.html

---
 .../trusted-firmware-m/trusted-firmware-m.inc | 32 +++++++++++++++----
 1 file changed, 25 insertions(+), 7 deletions(-)
meta-arm/recipes-bsp/trusted-firmware-m/trusted-firmware-m.inc +25 -7
index 4e3c5912..3b6dce22 100644
@@ -43,6 +43,11 @@ DEPENDS += "cmake-native \
 
 B = "${WORKDIR}/build"
 
+# Build TF-M regression tests instead of the default firmware.
+# When enabled, the desired test suite options should be appended to
+# EXTRA_OECMAKE (e.g. -DTEST_S=ON).
+BUILD_REGRESSION_TESTS ?= "0"
+
 # Build for debug (set TFM_DEBUG to 1 to activate)
 TFM_DEBUG ?= "${FIRMWARE_DEBUG_BUILD}"
 
@@ -53,11 +58,6 @@ python() {
         raise bb.parse.SkipRecipe("TFM_PLATFORM needs to be set")
 }
 
-PACKAGECONFIG ??= ""
-# Whether to integrate the test suite
-PACKAGECONFIG[test-secure] = "-DTEST_S=ON,-DTEST_S=OFF"
-PACKAGECONFIG[test-nonsecure] = "-DTEST_NS=ON,-DTEST_NS=OFF"
-
 # Currently we only support using the Arm binary GCC
 EXTRA_OECMAKE += "-DTFM_TOOLCHAIN_FILE=${S}/toolchain_GNUARM.cmake"
 
@@ -77,9 +77,12 @@ EXTRA_OECMAKE += "\
     -DQCBOR_PATH=${S}/external/qcbor \
     -DT_COSE_PATH=${S}/external/t_cose \
     -DTFM_EXTRAS_REPO_PATH=${S}/external/tfm-extras \
-    -DTFM_TEST_REPO_PATH=${S}/external/tf-m-tests \
     "
 
+# tf-m-tests directory
+# The directory can be overridden by local tf-m-tests folder path.
+TFM_TESTS_DIR ?= "${S}/external/tf-m-tests"
+
 export CMAKE_BUILD_PARALLEL_LEVEL = "${@oe.utils.parallel_make(d, False)}"
 
 AS[unexport] = "1"
@@ -92,7 +95,13 @@ export OPENSSL_MODULES = "${STAGING_LIBDIR_NATIVE}/ossl-modules"
 
 do_configure[cleandirs] = "${B}"
 do_configure() {
-    cmake -GNinja -S ${S} -B ${B} ${EXTRA_OECMAKE} ${PACKAGECONFIG_CONFARGS}
+    # When regression tests are enabled, TF-M is built under regression test
+    # directory.
+    if [ "${BUILD_REGRESSION_TESTS}" = "1" ]; then
+        cmake -GNinja -S ${TFM_TESTS_DIR}/tests_reg/spe -B ${B} -DCONFIG_TFM_SOURCE_PATH=${S} ${EXTRA_OECMAKE}
+    else
+        cmake -GNinja -S ${S} -B ${B} ${EXTRA_OECMAKE}
+    fi
 }
 
 # Invoke install here as there's no point in splitting compile from install: the
@@ -110,6 +119,15 @@ do_install() {
     find ${B}/bin \( -name '*.bin' -o -name '*.elf' \) -type f | while read -r file; do
         install -m 0644 "$file" "${D}${FIRMWARE_DIR}"
     done
+
+    # Install for NS build
+    if [ -d "${B}/api_ns" ]; then
+        install -d -m 0755 ${D}/sysroot-only/api_ns
+
+        cd ${B}/api_ns
+        find . -type d -exec install -d -m 0755 ${D}/sysroot-only/api_ns/{} \;
+        find . -type f -exec install -m 0644 {} ${D}/sysroot-only/api_ns/{} \;
+    fi
 }
 
 # Build paths are currently embedded because it's impossible to pass -fdebug-prefix-map