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