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