blob: 8266ccb76949250205d828bec64a38c67371d496 [file] [log] [blame]
jk-arm957cfea2021-06-18 15:52:12 +05301#/** @file
2# * Copyright (c) 2021, Arm Limited or its affiliates. All rights reserved.
3# * SPDX-License-Identifier : Apache-2.0
4# *
5# * Licensed under the Apache License, Version 2.0 (the "License");
6# * you may not use this file except in compliance with the License.
7# * You may obtain a copy of the License at
8# *
9# * http://www.apache.org/licenses/LICENSE-2.0
10# *
11# * Unless required by applicable law or agreed to in writing, software
12# * distributed under the License is distributed on an "AS IS" BASIS,
13# * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# * See the License for the specific language governing permissions and
15# * limitations under the License.
16
17# Set the minimum required version of CMake for the project
18cmake_minimum_required(VERSION 3.10)
19# cmake_policy
20cmake_policy(SET CMP0057 NEW)
21PROJECT (psa_adac_tests)
22
23# Find python interpreter version 3 or greater
24find_package(PythonInterp 3 REQUIRED)
25
26get_filename_component(PSA_ROOT_DIR . ABSOLUTE)
27include(${PSA_ROOT_DIR}/tools/cmake/common/Utils.cmake)
28
29set(CMAKE_C_STANDARD 99)
30set(CMAKE_C_EXTENSIONS Off)
31set(CMAKE_CXX_STANDARD 14)
32set(CMAKE_CXX_EXTENSIONS Off)
33
34if(NOT DEFINED RDDI_LIB)
35 set(DEPENDS_INC_PATH ${CMAKE_SOURCE_DIR}/platform/native/include)
36else()
37 set(DEPENDS_INC_PATH ${CMAKE_SOURCE_DIR}/platform/rddi/include)
38
39 if(WIN32)
40 set(DEPENDS_LIB_PATH ${CMAKE_SOURCE_DIR}/depends/rddi/win_32-x86_64)
41 else()
42 set(DEPENDS_LIB_PATH ${CMAKE_SOURCE_DIR}/depends/rddi/linux-x86_64)
43 endif()
44endif()
45
46if(NOT DEFINED PSA_ADAC_ROOT)
47 get_filename_component(PSA_ADAC_ROOT ${CMAKE_SOURCE_DIR}/psa-adac ABSOLUTE)
48endif()
49include(${PSA_ADAC_ROOT}/cmake/psa_adac.cmake OPTIONAL)
50
51configure_file(${PSA_ADAC_ROOT}/psa-adac/core/include/psa_adac_config.h.in psa_adac_config.h)
52include_directories (
53 ${DEPENDS_INC_PATH}
54 ${CMAKE_BINARY_DIR}
55 ${PSA_ADAC_ROOT}/psa-adac/core/include
56 ${PSA_ADAC_ROOT}/ports/include
57 )
58
59set(MBEDTLS_CONFIG_FILE "${PSA_ADAC_ROOT}/ports/crypto/manager-crypto-config.h")
60add_compile_options(-DMBEDTLS_CONFIG_FILE="${MBEDTLS_CONFIG_FILE}")
61if (UNIX)
62 add_compile_options(-fPIC -fpic)
63else ()
64 # Silence warning about standard C APIs not being secure.
65 add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
66endif ()
67
68# Generate ADAC LIB
69add_subdirectory(${PSA_ADAC_ROOT}/psa-adac/core adac_core)
70add_subdirectory(${PSA_ADAC_ROOT}/psa-adac/sdm adac_sdm)
71add_subdirectory(${PSA_ADAC_ROOT}/ports/crypto/psa-crypto psa_adac_psa_crypto)
72
73set(ADAC_LIBS psa_adac_sdm psa_adac_core psa_adac_psa_crypto mbedcrypto)
74
75if(NOT DEFINED TFM_PROFILE)
76 message(STATUS "[PSA] : Building Default profile")
77list(APPEND PSA_SUITES #PSA_SUITES
78 "ADAC"
79)
80endif()
81
82# list of VERBOSE options
83list(APPEND PSA_VERBOSE_OPTIONS 1 2 3 4 5)
84
85message(STATUS "[PSA] : ----------Process input arguments- start-------------")
86
87# Check for TARGET command line argument
88_check_arguments("TARGET")
89# Check for SUITE command line argument
90_check_arguments("SUITE")
91
92string(TOLOWER ${SUITE} SUITE_LOWER)
93
94# Check for valid targets
95_get_sub_dir_list(PSA_TARGET_LIST ${PSA_ROOT_DIR}/platform)
96if(NOT ${TARGET} IN_LIST PSA_TARGET_LIST)
97 message(FATAL_ERROR "[PSA] : Error: Unsupported value for -DTARGET=${TARGET}, supported targets are : ${PSA_TARGET_LIST}")
98else()
99 message(STATUS "[PSA] : TARGET is set to ${TARGET}")
100endif()
101
102# Check for the presence of required test suite directories
103if(NOT IS_DIRECTORY ${PSA_ROOT_DIR}/tests)
104 message(STATUS "[PSA] : Error: Could not find architecture test suite directories in psa root path ${PSA_ROOT_DIR}")
105endif()
106
107# Check for valid suite cmake argument passed
108if(NOT ${SUITE} IN_LIST PSA_SUITES)
109 message(FATAL_ERROR "[PSA] : Error: Unsupported value for -DSUITE=${SUITE}, select one from supported suites which are : ${PSA_SUITES}")
110else()
111 message(STATUS "[PSA] : SUITE is set to ${SUITE}")
112endif()
113
114# Project variables
115set(ADAC_HOST_VAL_LIB psa_adac_val)
116set(ADAC_HOST_PAL_LIB psa_adac_pal)
117set(TEST_COMBINE_LIB test_combine)
118set(ADAC_HOST_EXE psa_adac_test)
119
120set(PSA_SUITE_DIR ${PSA_ROOT_DIR}/tests/${SUITE_LOWER})
121set(PSA_TESTLIST_GENERATOR ${PSA_ROOT_DIR}/tools/scripts/gen_tests_list.py)
122set(TESTSUITE_DB ${PSA_SUITE_DIR}/testsuite.db)
123set(PSA_TESTLIST_FILE ${CMAKE_CURRENT_BINARY_DIR}/${SUITE_LOWER}_testlist.txt)
124set(PSA_TEST_ENTRY_LIST_INC ${CMAKE_CURRENT_BINARY_DIR}/test_entry_list.inc)
125set(PSA_TEST_ENTRY_FUN_DECLARE_INC ${CMAKE_CURRENT_BINARY_DIR}/test_entry_fn_declare_list.inc)
126
127# Check for VERBOSE
128if(NOT DEFINED VERBOSE)
129 set(VERBOSE 3 CACHE INTERNAL "Default VERBOSE value" FORCE)
130 message(STATUS "[PSA] : Defaulting VERBOSE to ${VERBOSE}")
131else()
132 if(NOT ${VERBOSE} IN_LIST PSA_VERBOSE_OPTIONS)
133 message(FATAL_ERROR "[PSA] : Error: Unsupported value for -DVERBOSE=${VERBOSE}, supported values are : ${PSA_VERBOSE_OPTIONS}")
134 endif()
135 message(STATUS "[PSA] : VERBOSE is set to ${VERBOSE}")
136endif()
137
138if(NOT DEFINED SUITE_TEST_RANGE)
139 set(SUITE_TEST_RANGE_MIN None)
140 set(SUITE_TEST_RANGE_MAX None)
141else()
142 list(LENGTH SUITE_TEST_RANGE SUITE_TEST_RANGE_LENGTH)
143 if(${SUITE_TEST_RANGE_LENGTH} GREATER "2")
144 message(FATAL_ERROR "[PSA] : -DSUITE_TEST_RANGE=<...> value error! accepts two "
145 " numbers in quotes separated with ';'")
146 endif()
147 if(${SUITE_TEST_RANGE_LENGTH} EQUAL "2")
148 list(GET SUITE_TEST_RANGE 0 SUITE_TEST_RANGE_MIN)
149 list(GET SUITE_TEST_RANGE 1 SUITE_TEST_RANGE_MAX)
150 message(STATUS "[PSA] : Testing (${SUITE_TEST_RANGE_MIN}, ${SUITE_TEST_RANGE_MAX}) of ${SUITE} suite")
151 endif()
152 if(${SUITE_TEST_RANGE_LENGTH} EQUAL "1")
153 set(SUITE_TEST_RANGE_MIN ${SUITE_TEST_RANGE})
154 set(SUITE_TEST_RANGE_MAX ${SUITE_TEST_RANGE})
155 message(STATUS "[PSA] : Testing ${SUITE_TEST_RANGE_MIN} of ${SUITE} suite")
156 endif()
157endif()
158
159message(STATUS "[PSA] : ----------Process input arguments- complete-------------")
160
161# Create PSA clean list
162list(APPEND PSA_CLEAN_LIST
163 ${PSA_TESTLIST_FILE}
164 ${PSA_TEST_ENTRY_LIST_INC}
165 ${PSA_TEST_ENTRY_FUN_DECLARE_INC}
166)
167
168# Process testsuite.db
169message(STATUS "[PSA] : Creating testlist.txt 'available at ${PSA_TESTLIST_FILE}'")
170execute_process(COMMAND ${PYTHON_EXECUTABLE} ${PSA_TESTLIST_GENERATOR}
171 ${SUITE_LOWER}
172 ${TESTSUITE_DB}
173 ${PSA_TESTLIST_FILE}
174 ${PSA_TEST_ENTRY_LIST_INC}
175 ${PSA_TEST_ENTRY_FUN_DECLARE_INC}
176 ${SUITE_TEST_RANGE_MIN}
177 ${SUITE_TEST_RANGE_MAX})
178
179# Creating CMake list variable from file
180file(READ ${PSA_TESTLIST_FILE} PSA_TEST_LIST)
181if(NOT PSA_TEST_LIST)
182 message(FATAL_ERROR "[PSA] : Invalid test number!")
183endif()
184string(REGEX REPLACE "\n" ";" PSA_TEST_LIST "${PSA_TEST_LIST}")
185
186# Global macro to identify the PSA test suite cmake build
187add_definitions(-D${SUITE})
188add_definitions(-DVERBOSE=${VERBOSE})
189add_definitions(-D${TARGET})
190
191# Build PAL LIB
192if(NOT DEFINED RDDI_LIB)
193 add_subdirectory(${CMAKE_SOURCE_DIR}/platform/native)
194 set(ADAC_HOST_PAL_LIB platform_native)
195else()
196 add_subdirectory(${CMAKE_SOURCE_DIR}/platform/csapbcom)
197 set(ADAC_HOST_PAL_LIB csapbcom)
198endif()
199
200# Generate VAL LIB
201include(${CMAKE_SOURCE_DIR}/val/val.cmake)
202
203# Build test
204include(${PSA_SUITE_DIR}/suite.cmake)
205
206#add_dependencies(${TEST_COMBINE_LIB} ${ADAC_HOST_VAL_LIB} ${ADAC_HOST_PAL_LIB} ${ADAC_LIBS})
207add_executable(${ADAC_HOST_EXE} ${SUITE_CC_SOURCE})
208target_include_directories(${ADAC_HOST_EXE} PRIVATE
209 ${CMAKE_SOURCE_DIR}/val/include
210 )
211target_link_libraries (${ADAC_HOST_EXE} ${TEST_COMBINE_LIB}
212 ${ADAC_HOST_VAL_LIB}
213 ${ADAC_HOST_PAL_LIB}
214 ${ADAC_LIBS}
215 )
216
217# Include the files for make clean
218foreach(clean_item ${PSA_CLEAN_LIST})
219 set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${clean_item})
220endforeach()
221