Kevin Peng | 62a8711 | 2020-07-07 15:07:46 +0800 | [diff] [blame^] | 1 | #------------------------------------------------------------------------------- |
| 2 | # Copyright (c) 2017-2020, Arm Limited. All rights reserved. |
| 3 | # |
| 4 | # SPDX-License-Identifier: BSD-3-Clause |
| 5 | # |
| 6 | #------------------------------------------------------------------------------- |
| 7 | |
| 8 | cmake_minimum_required(VERSION 3.7) |
| 9 | |
| 10 | #Tell cmake where our modules can be found |
| 11 | list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/../cmake) |
| 12 | |
| 13 | #Tell TFM Root before calling sub cmake |
| 14 | get_filename_component(TFM_ROOT_DIR "${CMAKE_CURRENT_LIST_DIR}/.." ABSOLUTE) |
| 15 | |
| 16 | #Include common stuff to control cmake. |
| 17 | include("Common/BuildSys") |
| 18 | |
| 19 | #Start an embedded project. |
| 20 | embedded_project_start(CONFIG "${TFM_ROOT_DIR}/configs/ConfigDefault.cmake") |
| 21 | project(tfm_tests LANGUAGES ASM C) |
| 22 | embedded_project_fixup() |
| 23 | |
| 24 | #Check incoming configuration options |
| 25 | if (NOT DEFINED SERVICES_TEST_ENABLED) |
| 26 | message(FATAL_ERROR "Incomplete build configuration: SERVICES_TEST_ENABLED is undefined. ") |
| 27 | endif() |
| 28 | |
| 29 | if (NOT DEFINED CORE_TEST_INTERACTIVE) |
| 30 | message(FATAL_ERROR "Incomplete build configuration: CORE_TEST_INTERACTIVE is undefined. ") |
| 31 | endif() |
| 32 | |
| 33 | if (NOT DEFINED CORE_TEST_POSITIVE) |
| 34 | message(FATAL_ERROR "Incomplete build configuration: CORE_TEST_POSITIVE is undefined. ") |
| 35 | endif() |
| 36 | |
| 37 | if (NOT DEFINED TFM_LVL) |
| 38 | message(FATAL_ERROR "Incomplete build configuration: TFM_LVL is undefined. ") |
| 39 | endif() |
| 40 | |
| 41 | if (NOT DEFINED TFM_PARTITION_AUDIT_LOG) |
| 42 | message(FATAL_ERROR "Incomplete build configuration: TFM_PARTITION_AUDIT_LOG is undefined.") |
| 43 | endif() |
| 44 | |
| 45 | if (NOT DEFINED TFM_PARTITION_PROTECTED_STORAGE) |
| 46 | message(FATAL_ERROR "Incomplete build configuration: TFM_PARTITION_PROTECTED_STORAGE is undefined.") |
| 47 | endif() |
| 48 | |
| 49 | if (NOT DEFINED TFM_PARTITION_INTERNAL_TRUSTED_STORAGE) |
| 50 | message(FATAL_ERROR "Incomplete build configuration: TFM_PARTITION_INTERNAL_TRUSTED_STORAGE is undefined.") |
| 51 | endif() |
| 52 | |
| 53 | if (NOT DEFINED TFM_PARTITION_CRYPTO) |
| 54 | message(FATAL_ERROR "Incomplete build configuration: TFM_PARTITION_CRYPTO is undefined.") |
| 55 | endif() |
| 56 | |
| 57 | if (NOT DEFINED TFM_PARTITION_INITIAL_ATTESTATION) |
| 58 | message(FATAL_ERROR "Incomplete build configuration: TFM_PARTITION_INITIAL_ATTESTATION is undefined.") |
| 59 | endif() |
| 60 | |
| 61 | if (NOT DEFINED TFM_ENABLE_IRQ_TEST) |
| 62 | message(FATAL_ERROR "Incomplete build configuration: TFM_ENABLE_IRQ_TEST is undefined.") |
| 63 | endif() |
| 64 | |
| 65 | #Configure our options as needed. |
| 66 | if (CORE_TEST_INTERACTIVE OR CORE_TEST_POSITIVE) |
| 67 | set(ENABLE_CORE_TESTS True) |
| 68 | set(ENABLE_CORE_TESTS_2 True) |
| 69 | else() |
| 70 | set(ENABLE_CORE_TESTS False) |
| 71 | set(ENABLE_CORE_TESTS_2 False) |
| 72 | endif() |
| 73 | |
| 74 | if (TFM_ENABLE_IRQ_TEST) |
| 75 | set(ENABLE_IRQ_TEST_SERVICES ON) |
| 76 | else() |
| 77 | set(ENABLE_IRQ_TEST_SERVICES OFF) |
| 78 | endif() |
| 79 | |
| 80 | if (ENABLE_CORE_TESTS) |
| 81 | # If the platform doesn't specify whether the peripheral test is enabled |
| 82 | # or not, select it by default. |
| 83 | if (NOT DEFINED TFM_ENABLE_PERIPH_ACCESS_TEST) |
| 84 | set(TFM_ENABLE_PERIPH_ACCESS_TEST TRUE) |
| 85 | endif() |
| 86 | |
| 87 | if (TFM_ENABLE_PERIPH_ACCESS_TEST) |
| 88 | add_definitions(-DTFM_ENABLE_PERIPH_ACCESS_TEST) |
| 89 | endif() |
| 90 | else() |
| 91 | set(TFM_ENABLE_PERIPH_ACCESS_TEST FALSE) |
| 92 | endif() |
| 93 | |
| 94 | include(${CMAKE_CURRENT_LIST_DIR}/TestConfig.cmake) |
| 95 | include(${CMAKE_CURRENT_LIST_DIR}/CMakeLists.inc) |
| 96 | |
| 97 | if (ENABLE_PROTECTED_STORAGE_SERVICE_TESTS) |
| 98 | embedded_set_target_compile_defines(TARGET tfm_secure_tests LANGUAGE C DEFINES ENABLE_PROTECTED_STORAGE_SERVICE_TESTS APPEND) |
| 99 | embedded_set_target_compile_defines(TARGET tfm_non_secure_tests LANGUAGE C DEFINES ENABLE_PROTECTED_STORAGE_SERVICE_TESTS APPEND) |
| 100 | endif() |
| 101 | |
| 102 | if (ENABLE_INTERNAL_TRUSTED_STORAGE_SERVICE_TESTS) |
| 103 | embedded_set_target_compile_defines(TARGET tfm_secure_tests LANGUAGE C DEFINES ENABLE_INTERNAL_TRUSTED_STORAGE_SERVICE_TESTS APPEND) |
| 104 | embedded_set_target_compile_defines(TARGET tfm_non_secure_tests LANGUAGE C DEFINES ENABLE_INTERNAL_TRUSTED_STORAGE_SERVICE_TESTS APPEND) |
| 105 | endif() |
| 106 | |
| 107 | if (ENABLE_CRYPTO_SERVICE_TESTS) |
| 108 | embedded_set_target_compile_defines(TARGET tfm_secure_tests LANGUAGE C DEFINES ENABLE_CRYPTO_SERVICE_TESTS APPEND) |
| 109 | embedded_set_target_compile_defines(TARGET tfm_non_secure_tests LANGUAGE C DEFINES ENABLE_CRYPTO_SERVICE_TESTS APPEND) |
| 110 | endif() |
| 111 | |
| 112 | if (ENABLE_ATTESTATION_SERVICE_TESTS) |
| 113 | embedded_set_target_compile_defines(TARGET tfm_secure_tests LANGUAGE C DEFINES ENABLE_ATTESTATION_SERVICE_TESTS APPEND) |
| 114 | embedded_set_target_compile_defines(TARGET tfm_non_secure_tests LANGUAGE C DEFINES ENABLE_ATTESTATION_SERVICE_TESTS APPEND) |
| 115 | endif() |
| 116 | |
| 117 | if (ENABLE_PLATFORM_SERVICE_TESTS) |
| 118 | embedded_set_target_compile_defines(TARGET tfm_secure_tests LANGUAGE C DEFINES ENABLE_PLATFORM_SERVICE_TESTS APPEND) |
| 119 | embedded_set_target_compile_defines(TARGET tfm_non_secure_tests LANGUAGE C DEFINES ENABLE_PLATFORM_SERVICE_TESTS APPEND) |
| 120 | endif() |
| 121 | |
| 122 | if (ENABLE_QCBOR_TESTS) |
| 123 | embedded_set_target_compile_defines(TARGET tfm_secure_tests LANGUAGE C DEFINES ENABLE_QCBOR_TESTS APPEND) |
| 124 | embedded_set_target_compile_defines(TARGET tfm_non_secure_tests LANGUAGE C DEFINES ENABLE_QCBOR_TESTS APPEND) |
| 125 | endif() |
| 126 | |
| 127 | if (ENABLE_T_COSE_TESTS) |
| 128 | embedded_set_target_compile_defines(TARGET tfm_non_secure_tests LANGUAGE C DEFINES ENABLE_T_COSE_TESTS APPEND) |
| 129 | endif() |
| 130 | |
| 131 | if (ENABLE_AUDIT_LOGGING_SERVICE_TESTS) |
| 132 | embedded_set_target_compile_defines(TARGET tfm_secure_tests LANGUAGE C DEFINES ENABLE_AUDIT_LOGGING_SERVICE_TESTS APPEND) |
| 133 | embedded_set_target_compile_defines(TARGET tfm_non_secure_tests LANGUAGE C DEFINES ENABLE_AUDIT_LOGGING_SERVICE_TESTS APPEND) |
| 134 | endif() |
| 135 | |
| 136 | if (TFM_MULTI_CORE_TEST) |
| 137 | embedded_set_target_compile_defines(TARGET tfm_non_secure_tests LANGUAGE C DEFINES TFM_MULTI_CORE_TEST APPEND) |
| 138 | endif() |
| 139 | |
| 140 | if (NOT DEFINED TFM_BUILD_IN_SPE) |
| 141 | message(FATAL_ERROR "TFM_BUILD_IN_SPE is not set. Cannot specify current building status") |
| 142 | endif() |
| 143 | |
| 144 | if (NOT TARGET tfm_t_cose_verify AND (ENABLE_ATTESTATION_SERVICE_TESTS OR ENABLE_T_COSE_TESTS)) |
| 145 | add_subdirectory(${TFM_ROOT_DIR}/lib/ext/t_cose ${CMAKE_CURRENT_BINARY_DIR}/t_cose) |
| 146 | endif() |
| 147 | |
| 148 | if ((NOT TARGET tfm_qcbor_encode OR NOT TARGET tfm_qcbor_decode) AND (ENABLE_ATTESTATION_SERVICE_TESTS OR ENABLE_QCBOR_TESTS OR ENABLE_T_COSE_TESTS)) |
| 149 | add_subdirectory(${TFM_ROOT_DIR}/lib/ext/qcbor ${CMAKE_CURRENT_BINARY_DIR}/qcbor) |
| 150 | endif() |
| 151 | |
| 152 | if (TFM_BUILD_IN_SPE) |
| 153 | #Build the secure library. Even though secure tests files depend on |
| 154 | #tfm_qcbor, this is not expressed here as the tfm_attest library is expected |
| 155 | #to hold the compiled tfm_qcbor files. |
| 156 | add_library(tfm_secure_tests STATIC ${ALL_SRC_C} ${ALL_SRC_C_S}) |
| 157 | if (ENABLE_ATTESTATION_SERVICE_TESTS) |
| 158 | target_sources(tfm_secure_tests PRIVATE $<TARGET_OBJECTS:tfm_t_cose_verify> $<TARGET_OBJECTS:tfm_qcbor_decode>) |
| 159 | endif() |
| 160 | |
| 161 | #Set common compiler and linker flags |
| 162 | if (DEFINED CMSE_FLAGS) |
| 163 | embedded_set_target_compile_flags(TARGET tfm_secure_tests LANGUAGE C APPEND FLAGS ${CMSE_FLAGS}) |
| 164 | endif() |
| 165 | config_setting_shared_compiler_flags(tfm_secure_tests) |
| 166 | config_setting_shared_linker_flags(tfm_secure_tests) |
| 167 | |
| 168 | embedded_set_target_compile_defines(TARGET tfm_secure_tests LANGUAGE C DEFINES __thumb2__ TFM_LVL=${TFM_LVL} APPEND) |
| 169 | |
| 170 | if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) |
| 171 | set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" CACHE |
| 172 | PATH "Default install location for tfm_storage." |
| 173 | FORCE) |
| 174 | endif() |
| 175 | |
| 176 | install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/framework/test_framework_integ_test.h |
| 177 | ${CMAKE_CURRENT_SOURCE_DIR}/test_services/tfm_secure_client_service/tfm_secure_client_service_api.h |
| 178 | DESTINATION export/tfm/test/inc) |
| 179 | |
| 180 | embedded_project_end(tfm_secure_tests) |
| 181 | else () |
| 182 | #Build the non-secure library |
| 183 | set(CMAKE_STATIC_LIBRARY_PREFIX_C "lib") |
| 184 | add_library(tfm_non_secure_tests STATIC ${ALL_SRC_C} ${ALL_SRC_C_NS}) |
| 185 | |
| 186 | embedded_target_include_directories(TARGET tfm_non_secure_tests PATH ${CMSIS_DIR}/RTOS2/Include ABSOLUTE APPEND) |
| 187 | |
| 188 | if (ENABLE_ATTESTATION_SERVICE_TESTS OR ENABLE_T_COSE_TESTS) |
| 189 | target_sources(tfm_non_secure_tests PRIVATE $<TARGET_OBJECTS:tfm_t_cose_verify> PRIVATE $<TARGET_OBJECTS:tfm_t_cose_sign>) |
| 190 | endif() |
| 191 | if (ENABLE_ATTESTATION_SERVICE_TESTS OR ENABLE_QCBOR_TESTS OR ENABLE_T_COSE_TESTS) |
| 192 | target_sources(tfm_non_secure_tests PRIVATE $<TARGET_OBJECTS:tfm_qcbor_decode> PRIVATE $<TARGET_OBJECTS:tfm_qcbor_encode>) |
| 193 | endif() |
| 194 | |
| 195 | #Set common compiler and linker flags |
| 196 | config_setting_shared_compiler_flags(tfm_non_secure_tests) |
| 197 | config_setting_shared_linker_flags(tfm_non_secure_tests) |
| 198 | |
| 199 | #Set macro definitions |
| 200 | set(TARGET_COMPILE_DEFINITIONS __thumb2__ __DOMAIN_NS=1 DOMAIN_NS=__DOMAIN_NS TFM_LVL=${TFM_LVL}) |
| 201 | embedded_set_target_compile_defines(TARGET tfm_non_secure_tests LANGUAGE C DEFINES ${TARGET_COMPILE_DEFINITIONS} APPEND) |
| 202 | |
| 203 | if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) |
| 204 | set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" CACHE |
| 205 | PATH "Default install location for tfm_storage." |
| 206 | FORCE) |
| 207 | endif() |
| 208 | |
| 209 | install(TARGETS tfm_non_secure_tests |
| 210 | DESTINATION export/tfm/test/lib |
| 211 | PUBLIC_HEADER DESTINATION export/tfm/test/inc) |
| 212 | |
| 213 | if(ENABLE_PROTECTED_STORAGE_SERVICE_TESTS) |
| 214 | #only PS tests are using semaphore and thread APIs |
| 215 | install(FILES ${TFM_ROOT_DIR}/interface/include/os_wrapper/semaphore.h |
| 216 | ${TFM_ROOT_DIR}/interface/include/os_wrapper/thread.h |
| 217 | DESTINATION export/tfm/include/os_wrapper) |
| 218 | endif() |
| 219 | |
| 220 | embedded_project_end(tfm_non_secure_tests) |
| 221 | endif() |