alexander | 31ae9f0 | 2022-02-10 16:15:54 +0000 | [diff] [blame] | 1 | #---------------------------------------------------------------------------- |
| 2 | # Copyright (c) 2022 Arm Limited. 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 | |
alexander | 31ae9f0 | 2022-02-10 16:15:54 +0000 | [diff] [blame] | 18 | function(set_platform_global_defaults) |
| 19 | message(STATUS "Platform: Native (Linux based x86_64/aarch64 system)") |
| 20 | if (NOT DEFINED CMAKE_TOOLCHAIN_FILE) |
| 21 | set(CMAKE_TOOLCHAIN_FILE ${CMAKE_TOOLCHAIN_DIR}/native-gcc.cmake |
| 22 | CACHE FILEPATH "Toolchain file") |
| 23 | endif() |
| 24 | |
Kshitij Sisodia | a1256e3 | 2022-02-23 14:40:45 +0000 | [diff] [blame] | 25 | set(PLATFORM_DRIVERS_DIR "${HAL_PLATFORM_DIR}/native" PARENT_SCOPE) |
alexander | cb8a987 | 2022-02-11 13:23:22 +0000 | [diff] [blame] | 26 | set(TEST_TPIP ${DOWNLOAD_DEP_DIR}/test) |
| 27 | |
| 28 | file(MAKE_DIRECTORY ${TEST_TPIP}) |
| 29 | set(TEST_TPIP_INCLUDE ${TEST_TPIP}/include) |
| 30 | file(MAKE_DIRECTORY ${TEST_TPIP_INCLUDE}) |
| 31 | |
| 32 | ExternalProject_Add(catch2-headers |
| 33 | URL https://github.com/catchorg/Catch2/releases/download/v2.11.1/catch.hpp |
| 34 | DOWNLOAD_NO_EXTRACT 1 |
| 35 | CONFIGURE_COMMAND "" |
| 36 | BUILD_COMMAND ${CMAKE_COMMAND} -E copy <DOWNLOAD_DIR>/catch.hpp ${TEST_TPIP_INCLUDE} |
| 37 | INSTALL_COMMAND "") |
| 38 | |
| 39 | add_library(catch2 INTERFACE) |
| 40 | target_include_directories(catch2 |
| 41 | INTERFACE |
| 42 | ${TEST_TPIP_INCLUDE}) |
Kshitij Sisodia | e2da7ee | 2022-02-14 11:22:58 +0000 | [diff] [blame] | 43 | add_dependencies(catch2 catch2-headers) |
alexander | cb8a987 | 2022-02-11 13:23:22 +0000 | [diff] [blame] | 44 | |
alexander | 31ae9f0 | 2022-02-10 16:15:54 +0000 | [diff] [blame] | 45 | endfunction() |
| 46 | |
| 47 | function(platform_custom_post_build) |
| 48 | set(oneValueArgs TARGET_NAME) |
| 49 | cmake_parse_arguments(PARSED "" "${oneValueArgs}" "" ${ARGN} ) |
| 50 | |
| 51 | |
| 52 | # If native build tests |
| 53 | set(TEST_SRC_USE_CASE "") |
| 54 | foreach(USE_CASES_TESTS_SEARCH_DIR ${USE_CASES_TESTS_SEARCH_DIR_LIST}) |
| 55 | |
| 56 | if (EXISTS ${USE_CASES_TESTS_SEARCH_DIR}/${use_case}) |
| 57 | message(STATUS "Found tests for use-case ${use_case} at ${USE_CASES_TESTS_SEARCH_DIR}/${use_case}.") |
| 58 | set(TEST_SRC_USE_CASE ${USE_CASES_TESTS_SEARCH_DIR}) |
| 59 | break() |
| 60 | endif () |
| 61 | endforeach() |
| 62 | |
| 63 | # Add tests only if they exists for the usecase |
| 64 | if (NOT ${TEST_SRC_USE_CASE} STREQUAL "") |
| 65 | |
| 66 | set(TEST_RESOURCES_INCLUDE |
| 67 | "${TEST_SRCS}/utils/" |
| 68 | "${TEST_SRC_USE_CASE}/${use_case}/include/" |
| 69 | ) |
| 70 | |
| 71 | # Define Test sources and new target to run unit tests |
| 72 | file(GLOB_RECURSE TEST_SOURCES |
| 73 | "${TEST_SRCS}/common/*.cpp" |
| 74 | "${TEST_SRCS}/common/*.cc" |
| 75 | "${TEST_SRCS}/utils/*.cc" |
| 76 | "${TEST_SRCS}/utils/*.cpp" |
| 77 | "${TEST_SRC_USE_CASE}/${use_case}/*.cpp" |
| 78 | "${TEST_SRC_USE_CASE}/${use_case}/*.cc" |
| 79 | "${TEST_SRC_USE_CASE}/${use_case}/*.c" |
| 80 | "${TEST_SRC_USE_CASE}/${use_case}/**/*.cpp" |
| 81 | "${TEST_SRC_USE_CASE}/${use_case}/**/*.cc" |
| 82 | "${TEST_SRC_USE_CASE}/${use_case}/**/*.c" |
| 83 | ) |
| 84 | |
| 85 | set(TEST_SRC_GEN_DIR ${CMAKE_BINARY_DIR}/generated/${use_case}/tests/src) |
| 86 | set(TEST_INC_GEN_DIR ${CMAKE_BINARY_DIR}/generated/${use_case}/tests/include) |
| 87 | file(MAKE_DIRECTORY ${TEST_SRC_GEN_DIR} ${TEST_INC_GEN_DIR}) |
| 88 | |
| 89 | set(${use_case}_DEFAULT_TEST_DATA_DIR ${DEFAULT_TEST_DATA_DIR} CACHE PATH "") |
| 90 | # Generate test data files to be included in x86 tests |
| 91 | generate_test_data_code( |
| 92 | INPUT_DIR "${${use_case}_DEFAULT_TEST_DATA_DIR}" |
| 93 | DESTINATION_SRC ${TEST_SRC_GEN_DIR} |
| 94 | DESTINATION_HDR ${TEST_INC_GEN_DIR} |
| 95 | NAMESPACE "test" |
| 96 | ) |
| 97 | |
| 98 | file(GLOB_RECURSE TEST_SOURCES_GEN |
| 99 | "${TEST_SRC_GEN_DIR}/*.cc" |
| 100 | "${TEST_SRC_GEN_DIR}/**/*.cc" |
| 101 | ) |
| 102 | message(STATUS "Adding ${TEST_SOURCES_GEN} to test sources") |
| 103 | list(APPEND TEST_SOURCES ${TEST_SOURCES_GEN}) |
| 104 | list(APPEND TEST_RESOURCES_INCLUDE ${TEST_INC_GEN_DIR}) |
| 105 | |
Eanna O Cathain | 19c91fe | 2022-06-08 15:05:22 +0100 | [diff] [blame] | 106 | set(TEST_TARGET_NAME "${use_case}_tests") |
alexander | 31ae9f0 | 2022-02-10 16:15:54 +0000 | [diff] [blame] | 107 | add_executable(${TEST_TARGET_NAME} ${TEST_SOURCES}) |
alexander | cb8a987 | 2022-02-11 13:23:22 +0000 | [diff] [blame] | 108 | target_include_directories(${TEST_TARGET_NAME} PRIVATE ${TEST_RESOURCES_INCLUDE}) |
| 109 | target_link_libraries(${TEST_TARGET_NAME} PRIVATE ${UC_LIB_NAME} catch2) |
alexander | 31ae9f0 | 2022-02-10 16:15:54 +0000 | [diff] [blame] | 110 | target_compile_definitions(${TEST_TARGET_NAME} PRIVATE |
| 111 | "ACTIVATION_BUF_SZ=${${use_case}_ACTIVATION_BUF_SZ}" |
| 112 | TESTS) |
Eanna O Cathain | 19c91fe | 2022-06-08 15:05:22 +0100 | [diff] [blame] | 113 | add_test(NAME "${use_case}-tests" COMMAND ${TEST_TARGET_NAME} -r junit -o ${TEST_TARGET_NAME}.xml) |
alexander | 31ae9f0 | 2022-02-10 16:15:54 +0000 | [diff] [blame] | 114 | endif () |
| 115 | endfunction() |