Test: Build TF-M SPE alone with NS test flags selected
Some usage scenarios, such as multi-core platforms, require to build
non-secure side and secure side separately. TF-M currently supports to
build TF-M secure side with secure tests only.
However, some non-secure tests also require secure test services.
Therefore, NS test flags shall be selected even during TF-M secure build
alone.
But if NS tests flags are selected while building TF-M secure side only,
the TF-M build with current tf-m-tests will fail since the tf-m-tests is
not decoupled well.
This commit supports to build TF-M secure side only with NS test flags
selected, to include secure test services to support NS tests.
If NS is not selected, skip NS test framework and test suites build by
temporarily unsetting corresponding flags.
Signed-off-by: David Hu <david.hu@arm.com>
Change-Id: I2ae1caab9d5b63f43bb17453a3392cb22963f85d
diff --git a/test/secure_tests.cmake b/test/secure_tests.cmake
new file mode 100644
index 0000000..e1111ab
--- /dev/null
+++ b/test/secure_tests.cmake
@@ -0,0 +1,79 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2021, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+
+# Since the main test directory is a NS dir, this subdir is specifically made a
+# secure directory as it build the secure side tests and services
+if (TFM_MULTI_CORE_TOPOLOGY)
+ include(${CMAKE_SOURCE_DIR}/platform/ext/target/${TFM_PLATFORM}/preload.cmake)
+ tfm_toolchain_reload_compiler()
+endif()
+
+# Test services are also required by some NS regression tests.
+# Include test services at first no matter whether secure tests are enabled.
+add_subdirectory(test_services)
+
+if (NOT TEST_FRAMEWORK_S)
+ return()
+endif()
+
+add_library(tfm_test_framework_s INTERFACE)
+add_library(tfm_s_tests INTERFACE)
+
+target_link_libraries(tfm_test_framework_s
+ INTERFACE
+ psa_interface
+ tfm_test_framework_common
+ tfm_sp_log_raw
+)
+
+target_sources(tfm_s_tests
+ INTERFACE
+ ${CMAKE_CURRENT_SOURCE_DIR}/framework/secure_suites.c
+)
+
+target_link_libraries(tfm_s_tests
+ INTERFACE
+ tfm_test_framework_s
+ tfm_partition_defs
+ tfm_spm
+)
+
+target_compile_definitions(tfm_s_tests
+ INTERFACE
+ $<$<BOOL:${PS_TEST_NV_COUNTERS}>:PS_TEST_NV_COUNTERS>
+)
+
+############################# Secure tests #####################################
+
+# Add secure test library targets here to inherit secure side configurations
+if (TEST_S_CRYPTO)
+ add_library(tfm_test_suite_crypto_s STATIC EXCLUDE_FROM_ALL)
+endif()
+if (TEST_S_ATTESTATION)
+ add_library(tfm_test_suite_attestation_s STATIC EXCLUDE_FROM_ALL)
+endif()
+if (TEST_S_ITS)
+ add_library(tfm_test_suite_its_s STATIC EXCLUDE_FROM_ALL)
+endif()
+if (TEST_S_PS)
+ add_library(tfm_test_suite_ps_s STATIC EXCLUDE_FROM_ALL)
+endif()
+if (TEST_S_AUDIT)
+ add_library(tfm_test_suite_audit_s STATIC EXCLUDE_FROM_ALL)
+endif()
+if (TEST_S_PLATFORM)
+ add_library(tfm_test_suite_platform_s STATIC EXCLUDE_FROM_ALL)
+endif()
+if (TEST_S_IPC)
+ add_library(tfm_test_suite_ipc_s STATIC EXCLUDE_FROM_ALL)
+endif()
+if (TEST_S_FWU)
+ add_library(tfm_test_suite_fwu_s STATIC EXCLUDE_FROM_ALL)
+endif()
+if (EXTRA_S_TEST_SUITES_PATHS)
+ add_library(tfm_test_suite_extra_s STATIC EXCLUDE_FROM_ALL)
+endif()