jk-arm | 957cfea | 2021-06-18 15:52:12 +0530 | [diff] [blame] | 1 | #/** @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 |
| 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) |
| 30 | set(CMAKE_C_EXTENSIONS Off) |
| 31 | set(CMAKE_CXX_STANDARD 14) |
| 32 | set(CMAKE_CXX_EXTENSIONS Off) |
| 33 | |
| 34 | if(NOT DEFINED RDDI_LIB) |
| 35 | set(DEPENDS_INC_PATH ${CMAKE_SOURCE_DIR}/platform/native/include) |
| 36 | else() |
| 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() |
| 44 | endif() |
| 45 | |
| 46 | if(NOT DEFINED PSA_ADAC_ROOT) |
| 47 | get_filename_component(PSA_ADAC_ROOT ${CMAKE_SOURCE_DIR}/psa-adac ABSOLUTE) |
| 48 | endif() |
| 49 | include(${PSA_ADAC_ROOT}/cmake/psa_adac.cmake OPTIONAL) |
| 50 | |
| 51 | configure_file(${PSA_ADAC_ROOT}/psa-adac/core/include/psa_adac_config.h.in psa_adac_config.h) |
| 52 | include_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 | |
| 59 | set(MBEDTLS_CONFIG_FILE "${PSA_ADAC_ROOT}/ports/crypto/manager-crypto-config.h") |
| 60 | add_compile_options(-DMBEDTLS_CONFIG_FILE="${MBEDTLS_CONFIG_FILE}") |
| 61 | if (UNIX) |
| 62 | add_compile_options(-fPIC -fpic) |
| 63 | else () |
| 64 | # Silence warning about standard C APIs not being secure. |
| 65 | add_compile_definitions(_CRT_SECURE_NO_WARNINGS) |
| 66 | endif () |
| 67 | |
| 68 | # Generate ADAC LIB |
| 69 | add_subdirectory(${PSA_ADAC_ROOT}/psa-adac/core adac_core) |
| 70 | add_subdirectory(${PSA_ADAC_ROOT}/psa-adac/sdm adac_sdm) |
| 71 | add_subdirectory(${PSA_ADAC_ROOT}/ports/crypto/psa-crypto psa_adac_psa_crypto) |
| 72 | |
| 73 | set(ADAC_LIBS psa_adac_sdm psa_adac_core psa_adac_psa_crypto mbedcrypto) |
| 74 | |
| 75 | if(NOT DEFINED TFM_PROFILE) |
| 76 | message(STATUS "[PSA] : Building Default profile") |
| 77 | list(APPEND PSA_SUITES #PSA_SUITES |
| 78 | "ADAC" |
| 79 | ) |
| 80 | endif() |
| 81 | |
| 82 | # list of VERBOSE options |
| 83 | list(APPEND PSA_VERBOSE_OPTIONS 1 2 3 4 5) |
| 84 | |
| 85 | message(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 | |
| 92 | string(TOLOWER ${SUITE} SUITE_LOWER) |
| 93 | |
| 94 | # Check for valid targets |
| 95 | _get_sub_dir_list(PSA_TARGET_LIST ${PSA_ROOT_DIR}/platform) |
| 96 | if(NOT ${TARGET} IN_LIST PSA_TARGET_LIST) |
| 97 | message(FATAL_ERROR "[PSA] : Error: Unsupported value for -DTARGET=${TARGET}, supported targets are : ${PSA_TARGET_LIST}") |
| 98 | else() |
| 99 | message(STATUS "[PSA] : TARGET is set to ${TARGET}") |
| 100 | endif() |
| 101 | |
| 102 | # Check for the presence of required test suite directories |
| 103 | if(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}") |
| 105 | endif() |
| 106 | |
| 107 | # Check for valid suite cmake argument passed |
| 108 | if(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}") |
| 110 | else() |
| 111 | message(STATUS "[PSA] : SUITE is set to ${SUITE}") |
| 112 | endif() |
| 113 | |
| 114 | # Project variables |
| 115 | set(ADAC_HOST_VAL_LIB psa_adac_val) |
| 116 | set(ADAC_HOST_PAL_LIB psa_adac_pal) |
| 117 | set(TEST_COMBINE_LIB test_combine) |
| 118 | set(ADAC_HOST_EXE psa_adac_test) |
| 119 | |
| 120 | set(PSA_SUITE_DIR ${PSA_ROOT_DIR}/tests/${SUITE_LOWER}) |
| 121 | set(PSA_TESTLIST_GENERATOR ${PSA_ROOT_DIR}/tools/scripts/gen_tests_list.py) |
| 122 | set(TESTSUITE_DB ${PSA_SUITE_DIR}/testsuite.db) |
| 123 | set(PSA_TESTLIST_FILE ${CMAKE_CURRENT_BINARY_DIR}/${SUITE_LOWER}_testlist.txt) |
| 124 | set(PSA_TEST_ENTRY_LIST_INC ${CMAKE_CURRENT_BINARY_DIR}/test_entry_list.inc) |
| 125 | set(PSA_TEST_ENTRY_FUN_DECLARE_INC ${CMAKE_CURRENT_BINARY_DIR}/test_entry_fn_declare_list.inc) |
| 126 | |
| 127 | # Check for VERBOSE |
| 128 | if(NOT DEFINED VERBOSE) |
| 129 | set(VERBOSE 3 CACHE INTERNAL "Default VERBOSE value" FORCE) |
| 130 | message(STATUS "[PSA] : Defaulting VERBOSE to ${VERBOSE}") |
| 131 | else() |
| 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}") |
| 136 | endif() |
| 137 | |
| 138 | if(NOT DEFINED SUITE_TEST_RANGE) |
| 139 | set(SUITE_TEST_RANGE_MIN None) |
| 140 | set(SUITE_TEST_RANGE_MAX None) |
| 141 | else() |
| 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() |
| 157 | endif() |
| 158 | |
| 159 | message(STATUS "[PSA] : ----------Process input arguments- complete-------------") |
| 160 | |
| 161 | # Create PSA clean list |
| 162 | list(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 |
| 169 | message(STATUS "[PSA] : Creating testlist.txt 'available at ${PSA_TESTLIST_FILE}'") |
| 170 | execute_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 |
| 180 | file(READ ${PSA_TESTLIST_FILE} PSA_TEST_LIST) |
| 181 | if(NOT PSA_TEST_LIST) |
| 182 | message(FATAL_ERROR "[PSA] : Invalid test number!") |
| 183 | endif() |
| 184 | string(REGEX REPLACE "\n" ";" PSA_TEST_LIST "${PSA_TEST_LIST}") |
| 185 | |
| 186 | # Global macro to identify the PSA test suite cmake build |
| 187 | add_definitions(-D${SUITE}) |
| 188 | add_definitions(-DVERBOSE=${VERBOSE}) |
| 189 | add_definitions(-D${TARGET}) |
| 190 | |
| 191 | # Build PAL LIB |
| 192 | if(NOT DEFINED RDDI_LIB) |
| 193 | add_subdirectory(${CMAKE_SOURCE_DIR}/platform/native) |
| 194 | set(ADAC_HOST_PAL_LIB platform_native) |
| 195 | else() |
| 196 | add_subdirectory(${CMAKE_SOURCE_DIR}/platform/csapbcom) |
| 197 | set(ADAC_HOST_PAL_LIB csapbcom) |
| 198 | endif() |
| 199 | |
| 200 | # Generate VAL LIB |
| 201 | include(${CMAKE_SOURCE_DIR}/val/val.cmake) |
| 202 | |
| 203 | # Build test |
| 204 | include(${PSA_SUITE_DIR}/suite.cmake) |
| 205 | |
| 206 | #add_dependencies(${TEST_COMBINE_LIB} ${ADAC_HOST_VAL_LIB} ${ADAC_HOST_PAL_LIB} ${ADAC_LIBS}) |
| 207 | add_executable(${ADAC_HOST_EXE} ${SUITE_CC_SOURCE}) |
| 208 | target_include_directories(${ADAC_HOST_EXE} PRIVATE |
| 209 | ${CMAKE_SOURCE_DIR}/val/include |
| 210 | ) |
| 211 | target_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 |
| 218 | foreach(clean_item ${PSA_CLEAN_LIST}) |
| 219 | set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${clean_item}) |
| 220 | endforeach() |
| 221 | |