From 0b07d334f91e05c13631adf8a7b20e206da667bb Mon Sep 17 00:00:00 2001 From: Devaraj Ranganna Date: Wed, 31 Mar 2021 12:51:48 +0100 Subject: [PATCH] Add TF-M regression tests on AN524 TF-M regression tests config option `TFM_REGRESSION` is documented in `Arm/MPS3_AN524/app/config.cmake` and is disabled by default. To run TF-M NS regression tests set the config option to `ON` and rebuild the application. Then run it either on QEMU or hardware. Signed-off-by: Devaraj Ranganna --- Arm/MPS3_AN524/app/CMakeLists.txt | 5 ++ Arm/MPS3_AN524/app/config.cmake | 2 +- Arm/MPS3_AN524/app/main.c | 15 ++++++ Arm/MPS3_AN524/lib/tf-m/CMakeLists.txt | 68 ++++++++++++++++++++++---- Arm/MPS3_AN524/readme.md | 6 +++ 5 files changed, 86 insertions(+), 10 deletions(-) diff --git a/Arm/MPS3_AN524/app/CMakeLists.txt b/Arm/MPS3_AN524/app/CMakeLists.txt index d38be874f..118cedbea 100644 --- a/Arm/MPS3_AN524/app/CMakeLists.txt +++ b/Arm/MPS3_AN524/app/CMakeLists.txt @@ -18,6 +18,11 @@ set(SOURCES add_executable(${PROJECT_NAME} ${SOURCES}) +target_compile_definitions(${PROJECT_NAME} + PRIVATE + $<$:TFM_REGRESSION> +) + target_link_libraries(${PROJECT_NAME} PUBLIC azrtos::threadx diff --git a/Arm/MPS3_AN524/app/config.cmake b/Arm/MPS3_AN524/app/config.cmake index 09cee0a3c..f53095d9d 100644 --- a/Arm/MPS3_AN524/app/config.cmake +++ b/Arm/MPS3_AN524/app/config.cmake @@ -138,7 +138,7 @@ cmake_dependent_option(TFM_IPC cmake_dependent_option(TFM_REGRESSION "When enabled, this option signifies that the TF-M build includes the Secure and the Non-Secure regression tests." - ON + OFF BUILD_WITH_TFM OFF ) diff --git a/Arm/MPS3_AN524/app/main.c b/Arm/MPS3_AN524/app/main.c index c5b7d3fe7..5db7c19ce 100644 --- a/Arm/MPS3_AN524/app/main.c +++ b/Arm/MPS3_AN524/app/main.c @@ -13,9 +13,18 @@ #include "psa_manifest/sid.h" #endif +#ifdef TFM_REGRESSION +#include "test_framework_integ_test.h" +#endif + #define AZURE_THREAD_STACK_SIZE 4096 #define AZURE_THREAD_PRIORITY 4 +int tfm_log_printf(const char *fmt, ...) +{ + printf(fmt); +} + static __inline void systick_interval_set(uint32_t ticks) { // 1. Disable the counter @@ -62,6 +71,8 @@ void azure_thread_entry(ULONG parameter) printf("The version of the PSA Framework API is not valid!\n"); return; } + +#ifdef TFM_REGRESSION psa_handle_t handle; handle = psa_connect(IPC_SERVICE_TEST_BASIC_SID, @@ -73,6 +84,10 @@ void azure_thread_entry(ULONG parameter) return; } psa_close(handle); + + /* Start TF-M NS regression tests */ + tfm_non_secure_client_run_tests(); +#endif } void tx_application_define(void* first_unused_memory) diff --git a/Arm/MPS3_AN524/lib/tf-m/CMakeLists.txt b/Arm/MPS3_AN524/lib/tf-m/CMakeLists.txt index deb7b2167..4e1c2482d 100644 --- a/Arm/MPS3_AN524/lib/tf-m/CMakeLists.txt +++ b/Arm/MPS3_AN524/lib/tf-m/CMakeLists.txt @@ -86,8 +86,6 @@ function(trusted_firmware_build) set(MCUBOOT_IMAGE_NUM_ARG -DMCUBOOT_IMAGE_NUMBER=${TFM_MCUBOOT_IMAGE_NUMBER}) endif() - set(VENEERS_FILE ${TFM_BINARY_DIR}/install/interface/lib/s_veneers.o) - set(PSA_API_NS_PATH ${TFM_BINARY_DIR}/app/libtfm_api_ns.a) set(TFM_GENERATED_INCLUDES ${TFM_BINARY_DIR}/generated/interface/include) if(TFM_BL2) @@ -102,9 +100,45 @@ function(trusted_firmware_build) set(TFM_NS_SIGNED_BIN_FILE ${TFM_BINARY_DIR}/bin/tfm_ns_signed.bin) set(TFM_S_NS_SIGNED_BIN_FILE ${TFM_BINARY_DIR}/bin/tfm_s_ns_signed.bin) + set(VENEERS_FILE ${TFM_BINARY_DIR}/install/interface/lib/s_veneers.o) + + set(PSA_API_NS_PATH ${TFM_BINARY_DIR}/app/libtfm_api_ns.a) + if (TFM_REGRESSION) + set(PSA_QCBOR_NS_REGRESSION_TEST_PATH ${TFM_BINARY_DIR}/test/suites/qcbor/libtfm_test_suite_qcbor_ns.a) + set(PSA_NS_CORE_TEST_PATH ${TFM_BINARY_DIR}/test/suites/core/libtfm_test_suite_core_ns.a) + set(PSA_NS_IPC_TEST_PATH ${TFM_BINARY_DIR}/test/suites/ipc/libtfm_test_suite_ipc_ns.a) + set(PSA_ATTESTATION_NS_REGRESSION_TEST_PATH ${TFM_BINARY_DIR}/test/suites/attestation/libtfm_test_suite_attestation_ns.a) + set(PSA_CRYPTO_NS_REGRESSION_TEST_PATH ${TFM_BINARY_DIR}/test/suites/crypto/libtfm_test_suite_crypto_ns.a) + set(PSA_PLATFORM_NS_REGRESSION_TEST_PATH ${TFM_BINARY_DIR}/test/suites/platform/libtfm_test_suite_platform_ns.a) + set(PSA_PS_NS_REGRESSION_TEST_PATH ${TFM_BINARY_DIR}/test/suites/ps/libtfm_test_suite_ps_ns.a) + set(PSA_ITS_NS_REGRESSION_TEST_PATH ${TFM_BINARY_DIR}/test/suites/its/libtfm_test_suite_its_ns.a) + set(PSA_T_COSE_NS_REGRESSION_TEST_PATH ${TFM_BINARY_DIR}/test/suites/t_cose/libtfm_test_suite_t_cose_ns.a) + set(PSA_NS_REGRESSION_TEST_PATH ${TFM_BINARY_DIR}/app/libtfm_ns_integration_test.a) + set(PSA_QCBOR_TEST_PATH ${TFM_BINARY_DIR}/lib/ext/qcbor/libtfm_qcbor_test.a) + set(PSA_T_COSE_TEST_PATH ${TFM_BINARY_DIR}/lib/ext/t_cose/libtfm_t_cose_test.a) + set(PSA_PLATFORM_NS_PATH ${TFM_BINARY_DIR}/platform/libplatform_ns.a) + set(PSA_QCBOR_PATH ${TFM_BINARY_DIR}/lib/ext/qcbor/libtfm_qcbor.a) + set(PSA_T_COSE_PATH ${TFM_BINARY_DIR}/lib/ext/t_cose/libtfm_t_cose.a) + endif() + set(BUILD_BYPRODUCTS ${VENEERS_FILE} ${PSA_API_NS_PATH} + ${PSA_QCBOR_NS_REGRESSION_TEST_PATH} + ${PSA_NS_CORE_TEST_PATH} + ${PSA_NS_IPC_TEST_PATH} + ${PSA_ATTESTATION_NS_REGRESSION_TEST_PATH} + ${PSA_CRYPTO_NS_REGRESSION_TEST_PATH} + ${PSA_PLATFORM_NS_REGRESSION_TEST_PATH} + ${PSA_PS_NS_REGRESSION_TEST_PATH} + ${PSA_ITS_NS_REGRESSION_TEST_PATH} + ${PSA_T_COSE_NS_REGRESSION_TEST_PATH} + ${PSA_NS_REGRESSION_TEST_PATH} + ${PSA_QCBOR_TEST_PATH} + ${PSA_T_COSE_TEST_PATH} + ${PSA_PLATFORM_NS_PATH} + ${PSA_QCBOR_PATH} + ${PSA_T_COSE_PATH} ${TFM_GENERATED_INCLUDES}/psa_manifest/sid.h ${BL2_BIN_FILE} ${BL2_HEX_FILE} @@ -170,24 +204,40 @@ function(trusted_firmware_build) TFM_S_NS_SIGNED_BIN_FILE ${TFM_S_NS_SIGNED_BIN_FILE} # Merged TFM Secure/Nonsecure FW (signed) ) - add_library(tfm_api - ${TX_TFM_TESTS_DIR}/app/os_wrapper_cmsis_rtos_v2.c + add_library(tfm_api INTERFACE + # ${TX_TFM_TESTS_DIR}/app/os_wrapper_cmsis_rtos_v2.c ) target_include_directories(tfm_api - PRIVATE - ${TX_TFM_TESTS_DIR}/CMSIS/RTOS2/Include - PUBLIC - ${TX_TFM_BASE_DIR}/interface/include + # PRIVATE + # ${TX_TFM_TESTS_DIR}/CMSIS/RTOS2/Include INTERFACE + ${TX_TFM_BASE_DIR}/interface/include + ${TX_TFM_BASE_DIR}/../tf-m-tests/test/framework + # INTERFACE ${TFM_GENERATED_INCLUDES} ) target_link_libraries(tfm_api INTERFACE + ${PSA_NS_CORE_TEST_PATH} + ${PSA_ATTESTATION_NS_REGRESSION_TEST_PATH} + ${PSA_CRYPTO_NS_REGRESSION_TEST_PATH} + ${PSA_NS_IPC_TEST_PATH} + ${PSA_ITS_NS_REGRESSION_TEST_PATH} + ${PSA_PLATFORM_NS_REGRESSION_TEST_PATH} + ${PSA_PS_NS_REGRESSION_TEST_PATH} + ${PSA_QCBOR_NS_REGRESSION_TEST_PATH} + ${PSA_T_COSE_NS_REGRESSION_TEST_PATH} + ${PSA_QCBOR_TEST_PATH} + ${PSA_T_COSE_TEST_PATH} + ${PSA_PLATFORM_NS_PATH} ${PSA_API_NS_PATH} + ${PSA_NS_REGRESSION_TEST_PATH} + ${PSA_QCBOR_PATH} + ${PSA_T_COSE_PATH} ${VENEERS_FILE} - $ + # $ ) add_dependencies(tfm_api tfm) diff --git a/Arm/MPS3_AN524/readme.md b/Arm/MPS3_AN524/readme.md index 05c214b54..821747a82 100644 --- a/Arm/MPS3_AN524/readme.md +++ b/Arm/MPS3_AN524/readme.md @@ -101,6 +101,12 @@ and semaphores. The size of these allocations may also be configured. Configuration options for these are defined and documented in `Arm/MPS3_AN524/lib/threadx/CMmakeLists.txt`. +### Running TF-M NS regression tests +TF-M NS regression tests config option `TFM_REGRESSION` is documented in +`Arm/MPS3_AN524/app/config.cmake` and is disabled by default. To run TF-M NS +regression tests set the config option to `ON` and rebuild the application. +Then run it either on [QEMU](#using-qemu) or [hardware](#updating-application-image) + ## Updating application image > This has only been tested on OS X, some modifications might be needed to make `Arm/MPS3_AN524/tools/flash.py` to work in Windows/Linux environments.