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