blob: 02b3bc543cce16823d81a9c512bee374869c59be [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)
Kevin Peng2ff05d52020-08-14 11:17:42 +080011 set(TFM_ROOT_DIR ${CMAKE_SOURCE_DIR})
Kevin Pengae997e42020-07-08 17:06:37 +080012endif()
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
Summer Qin77894232020-08-28 11:24:15 +0800153set(TEST_SRC "${CMAKE_CURRENT_LIST_DIR}/../log/tfm_log_raw.c")
Kevin Peng62a87112020-07-07 15:07:46 +0800154if (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 Qin77894232020-08-28 11:24:15 +0800158 add_library(tfm_secure_tests STATIC ${ALL_SRC_C} ${ALL_SRC_C_S} ${TEST_SRC})
Kevin Peng62a87112020-07-07 15:07:46 +0800159 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)
183else ()
184 #Build the non-secure library
185 set(CMAKE_STATIC_LIBRARY_PREFIX_C "lib")
Summer Qin77894232020-08-28 11:24:15 +0800186 add_library(tfm_non_secure_tests STATIC ${ALL_SRC_C} ${ALL_SRC_C_NS} ${TEST_SRC})
Kevin Peng62a87112020-07-07 15:07:46 +0800187
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)
223endif()