blob: 50a7b17f7bd47696d55d770a07722771f82a4fa9 [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
10#Tell cmake where our modules can be found
11list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/../cmake)
12
13#Tell TFM Root before calling sub cmake
14get_filename_component(TFM_ROOT_DIR "${CMAKE_CURRENT_LIST_DIR}/.." ABSOLUTE)
15
16#Include common stuff to control cmake.
17include("Common/BuildSys")
18
19#Start an embedded project.
20embedded_project_start(CONFIG "${TFM_ROOT_DIR}/configs/ConfigDefault.cmake")
21project(tfm_tests LANGUAGES ASM C)
22embedded_project_fixup()
23
24#Check incoming configuration options
25if (NOT DEFINED SERVICES_TEST_ENABLED)
26 message(FATAL_ERROR "Incomplete build configuration: SERVICES_TEST_ENABLED is undefined. ")
27endif()
28
29if (NOT DEFINED CORE_TEST_INTERACTIVE)
30 message(FATAL_ERROR "Incomplete build configuration: CORE_TEST_INTERACTIVE is undefined. ")
31endif()
32
33if (NOT DEFINED CORE_TEST_POSITIVE)
34 message(FATAL_ERROR "Incomplete build configuration: CORE_TEST_POSITIVE is undefined. ")
35endif()
36
37if (NOT DEFINED TFM_LVL)
38 message(FATAL_ERROR "Incomplete build configuration: TFM_LVL is undefined. ")
39endif()
40
41if (NOT DEFINED TFM_PARTITION_AUDIT_LOG)
42 message(FATAL_ERROR "Incomplete build configuration: TFM_PARTITION_AUDIT_LOG is undefined.")
43endif()
44
45if (NOT DEFINED TFM_PARTITION_PROTECTED_STORAGE)
46 message(FATAL_ERROR "Incomplete build configuration: TFM_PARTITION_PROTECTED_STORAGE is undefined.")
47endif()
48
49if (NOT DEFINED TFM_PARTITION_INTERNAL_TRUSTED_STORAGE)
50 message(FATAL_ERROR "Incomplete build configuration: TFM_PARTITION_INTERNAL_TRUSTED_STORAGE is undefined.")
51endif()
52
53if (NOT DEFINED TFM_PARTITION_CRYPTO)
54 message(FATAL_ERROR "Incomplete build configuration: TFM_PARTITION_CRYPTO is undefined.")
55endif()
56
57if (NOT DEFINED TFM_PARTITION_INITIAL_ATTESTATION)
58 message(FATAL_ERROR "Incomplete build configuration: TFM_PARTITION_INITIAL_ATTESTATION is undefined.")
59endif()
60
61if (NOT DEFINED TFM_ENABLE_IRQ_TEST)
62 message(FATAL_ERROR "Incomplete build configuration: TFM_ENABLE_IRQ_TEST is undefined.")
63endif()
64
65#Configure our options as needed.
66if (CORE_TEST_INTERACTIVE OR CORE_TEST_POSITIVE)
67 set(ENABLE_CORE_TESTS True)
68 set(ENABLE_CORE_TESTS_2 True)
69else()
70 set(ENABLE_CORE_TESTS False)
71 set(ENABLE_CORE_TESTS_2 False)
72endif()
73
74if (TFM_ENABLE_IRQ_TEST)
75 set(ENABLE_IRQ_TEST_SERVICES ON)
76else()
77 set(ENABLE_IRQ_TEST_SERVICES OFF)
78endif()
79
80if (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()
90else()
91 set(TFM_ENABLE_PERIPH_ACCESS_TEST FALSE)
92endif()
93
94include(${CMAKE_CURRENT_LIST_DIR}/TestConfig.cmake)
95include(${CMAKE_CURRENT_LIST_DIR}/CMakeLists.inc)
96
97if (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)
100endif()
101
102if (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)
105endif()
106
107if (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)
110endif()
111
112if (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)
115endif()
116
117if (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)
120endif()
121
122if (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)
125endif()
126
127if (ENABLE_T_COSE_TESTS)
128 embedded_set_target_compile_defines(TARGET tfm_non_secure_tests LANGUAGE C DEFINES ENABLE_T_COSE_TESTS APPEND)
129endif()
130
131if (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)
134endif()
135
136if (TFM_MULTI_CORE_TEST)
137 embedded_set_target_compile_defines(TARGET tfm_non_secure_tests LANGUAGE C DEFINES TFM_MULTI_CORE_TEST APPEND)
138endif()
139
140if (NOT DEFINED TFM_BUILD_IN_SPE)
141 message(FATAL_ERROR "TFM_BUILD_IN_SPE is not set. Cannot specify current building status")
142endif()
143
144if (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)
146endif()
147
148if ((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)
150endif()
151
152if (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)
181else ()
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)
221endif()