1# 2# Copyright (c) 2021 Nordic Semiconductor ASA 3# 4# SPDX-License-Identifier: Apache-2.0 5# 6 7cmake_minimum_required(VERSION 3.20.0) 8 9find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) 10 11project(tfm_psa_arch_test) 12 13target_sources(app PRIVATE src/main.c) 14 15get_target_property(TFM_BINARY_DIR tfm TFM_BINARY_DIR) 16get_target_property(TFM_NS_BIN_FILE tfm TFM_NS_BIN_FILE) 17get_target_property(TFM_NS_HEX_FILE tfm TFM_NS_HEX_FILE) 18get_target_property(TFM_NS_SIGNED_BIN_FILE tfm TFM_NS_SIGNED_BIN_FILE) 19 20get_target_property(TFM_TOOLCHAIN_PATH tfm TFM_TOOLCHAIN_PATH) 21get_target_property(TFM_TOOLCHAIN_PREFIX tfm TFM_TOOLCHAIN_PREFIX) 22get_target_property(TFM_TOOLCHAIN_NS_FILE tfm TFM_TOOLCHAIN_NS_FILE) 23 24set(TFM_TEST_REPO_PATH ${ZEPHYR_TRUSTED_FIRMWARE_M_MODULE_DIR}/../tf-m-tests) 25set(PSA_ARCH_TESTS_PATH ${ZEPHYR_TRUSTED_FIRMWARE_M_MODULE_DIR}/../psa-arch-tests) 26 27set(TFM_TEST_DIR "${TFM_TEST_REPO_PATH}/tests_psa_arch/spe/partitions") 28set(PSA_ARCH_TESTS_CONFIG_FILE "${TFM_TEST_REPO_PATH}/tests_psa_arch/spe/config/config_test_psa_api.cmake") 29if (CONFIG_TFM_PSA_TEST_CRYPTO) 30set(TFM_PSA_TEST_SUITE CRYPTO) 31elseif (CONFIG_TFM_PSA_TEST_PROTECTED_STORAGE) 32set(TFM_PSA_TEST_SUITE PROTECTED_STORAGE) 33elseif (CONFIG_TFM_PSA_TEST_INTERNAL_TRUSTED_STORAGE) 34set(TFM_PSA_TEST_SUITE INTERNAL_TRUSTED_STORAGE) 35elseif (CONFIG_TFM_PSA_TEST_STORAGE) 36set(TFM_PSA_TEST_SUITE STORAGE) 37elseif (CONFIG_TFM_PSA_TEST_INITIAL_ATTESTATION) 38set(TFM_PSA_TEST_SUITE INITIAL_ATTESTATION) 39endif() 40 41if (NOT DEFINED TFM_PSA_TEST_SUITE) 42 message(FATAL_ERROR "Please define a test suite to run. Refer to the README to see the available test suites.") 43endif() 44set(TEST_PSA_API "${TFM_PSA_TEST_SUITE}") 45 46set_property(TARGET zephyr_property_target 47 APPEND PROPERTY TFM_CMAKE_OPTIONS 48 -DPSA_ARCH_TESTS_PATH=${PSA_ARCH_TESTS_PATH} 49) 50 51set_property(TARGET zephyr_property_target 52 APPEND PROPERTY TFM_CMAKE_OPTIONS 53 -DCONFIG_TFM_TEST_DIR=${TFM_TEST_DIR} 54) 55 56set_property(TARGET zephyr_property_target 57 APPEND PROPERTY TFM_CMAKE_OPTIONS 58 -DCONFIG_PSA_ARCH_TESTS_CONFIG_FILE=${PSA_ARCH_TESTS_CONFIG_FILE} 59) 60 61set_property(TARGET zephyr_property_target 62 APPEND PROPERTY TFM_CMAKE_OPTIONS 63 -DTEST_PSA_API=${TEST_PSA_API} 64) 65 66include(ExternalProject) 67 68ExternalProject_Add(tfm_psa_arch_test_app 69 SOURCE_DIR ${TFM_TEST_REPO_PATH}/tests_psa_arch 70 BINARY_DIR ${PROJECT_BINARY_DIR}/tfm_ns 71 CONFIGURE_COMMAND 72 ${CMAKE_COMMAND} 73 -G ${CMAKE_GENERATOR} 74 -S ${TFM_TEST_REPO_PATH}/tests_psa_arch 75 -B ${PROJECT_BINARY_DIR}/tfm_ns 76 -DCROSS_COMPILE=${TFM_TOOLCHAIN_PATH}/${TFM_TOOLCHAIN_PREFIX} 77 -DPSA_TOOLCHAIN_FILE=${TFM_BINARY_DIR}/api_ns/cmake/${TFM_TOOLCHAIN_NS_FILE} 78 -DCONFIG_SPE_PATH=${TFM_BINARY_DIR}/api_ns 79 -DTFM_TOOLCHAIN_FILE=cmake/${TFM_TOOLCHAIN_NS_FILE} 80 -DQCBOR_PATH${QCBOR_PATH_TYPE}=${CONFIG_TFM_QCBOR_PATH} 81 -DCMAKE_BUILD_TYPE=RelWithDebInfo 82 -DTEST_PSA_API=${TEST_PSA_API} 83 BUILD_COMMAND ${CMAKE_COMMAND} --build . 84 INSTALL_COMMAND "" 85 BUILD_ALWAYS True 86 USES_TERMINAL_BUILD True 87 WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/tfm_ns 88 DEPENDS tfm 89 BUILD_BYPRODUCTS 90 ${TFM_NS_HEX_FILE} 91 ${TFM_NS_BIN_FILE} 92 ${TFM_NS_SIGNED_BIN_FILE} 93) 94 95add_dependencies(app tfm_psa_arch_test_app) 96