alexander | 31ae9f0 | 2022-02-10 16:15:54 +0000 | [diff] [blame] | 1 | #---------------------------------------------------------------------------- |
Richard Burton | f32a86a | 2022-11-15 11:46:11 +0000 | [diff] [blame] | 2 | # SPDX-FileCopyrightText: Copyright 2022 Arm Limited and/or its affiliates <open-source-office@arm.com> |
alexander | 31ae9f0 | 2022-02-10 16:15:54 +0000 | [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 | |
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}) |
Kshitij Sisodia | ee82c60 | 2022-12-29 11:53:23 +0000 | [diff] [blame^] | 31 | set(CATCH_HEADER_URL "https://github.com/catchorg/Catch2/releases/download/v2.11.1/catch.hpp") |
| 32 | set(CATCH_HEADER_MD5 dc6bb8ce282ad134476b37275804c44c) |
alexander | cb8a987 | 2022-02-11 13:23:22 +0000 | [diff] [blame] | 33 | |
alexander | cb8a987 | 2022-02-11 13:23:22 +0000 | [diff] [blame] | 34 | |
Kshitij Sisodia | ee82c60 | 2022-12-29 11:53:23 +0000 | [diff] [blame^] | 35 | include(FetchContent) |
| 36 | FetchContent_Declare(catch2-header-download |
| 37 | URL ${CATCH_HEADER_URL} |
| 38 | URL_HASH MD5=${CATCH_HEADER_MD5} |
| 39 | DOWNLOAD_DIR ${TEST_TPIP_INCLUDE} |
| 40 | DOWNLOAD_NO_EXTRACT ON |
| 41 | ) |
| 42 | FetchContent_MakeAvailable(catch2-header-download) |
| 43 | |
| 44 | add_library(mlek-catch2 INTERFACE) |
| 45 | target_include_directories(mlek-catch2 |
alexander | cb8a987 | 2022-02-11 13:23:22 +0000 | [diff] [blame] | 46 | INTERFACE |
| 47 | ${TEST_TPIP_INCLUDE}) |
Kshitij Sisodia | ee82c60 | 2022-12-29 11:53:23 +0000 | [diff] [blame^] | 48 | add_dependencies(mlek-catch2 catch2-header-download) |
| 49 | add_library(mlek::Catch2 ALIAS mlek-catch2) |
alexander | cb8a987 | 2022-02-11 13:23:22 +0000 | [diff] [blame] | 50 | |
alexander | 31ae9f0 | 2022-02-10 16:15:54 +0000 | [diff] [blame] | 51 | endfunction() |
| 52 | |
| 53 | function(platform_custom_post_build) |
| 54 | set(oneValueArgs TARGET_NAME) |
| 55 | cmake_parse_arguments(PARSED "" "${oneValueArgs}" "" ${ARGN} ) |
| 56 | |
| 57 | |
| 58 | # If native build tests |
| 59 | set(TEST_SRC_USE_CASE "") |
| 60 | foreach(USE_CASES_TESTS_SEARCH_DIR ${USE_CASES_TESTS_SEARCH_DIR_LIST}) |
| 61 | |
| 62 | if (EXISTS ${USE_CASES_TESTS_SEARCH_DIR}/${use_case}) |
| 63 | message(STATUS "Found tests for use-case ${use_case} at ${USE_CASES_TESTS_SEARCH_DIR}/${use_case}.") |
| 64 | set(TEST_SRC_USE_CASE ${USE_CASES_TESTS_SEARCH_DIR}) |
| 65 | break() |
| 66 | endif () |
| 67 | endforeach() |
| 68 | |
| 69 | # Add tests only if they exists for the usecase |
| 70 | if (NOT ${TEST_SRC_USE_CASE} STREQUAL "") |
| 71 | |
| 72 | set(TEST_RESOURCES_INCLUDE |
| 73 | "${TEST_SRCS}/utils/" |
| 74 | "${TEST_SRC_USE_CASE}/${use_case}/include/" |
| 75 | ) |
| 76 | |
| 77 | # Define Test sources and new target to run unit tests |
| 78 | file(GLOB_RECURSE TEST_SOURCES |
| 79 | "${TEST_SRCS}/common/*.cpp" |
| 80 | "${TEST_SRCS}/common/*.cc" |
| 81 | "${TEST_SRCS}/utils/*.cc" |
| 82 | "${TEST_SRCS}/utils/*.cpp" |
| 83 | "${TEST_SRC_USE_CASE}/${use_case}/*.cpp" |
| 84 | "${TEST_SRC_USE_CASE}/${use_case}/*.cc" |
| 85 | "${TEST_SRC_USE_CASE}/${use_case}/*.c" |
| 86 | "${TEST_SRC_USE_CASE}/${use_case}/**/*.cpp" |
| 87 | "${TEST_SRC_USE_CASE}/${use_case}/**/*.cc" |
| 88 | "${TEST_SRC_USE_CASE}/${use_case}/**/*.c" |
| 89 | ) |
| 90 | |
| 91 | set(TEST_SRC_GEN_DIR ${CMAKE_BINARY_DIR}/generated/${use_case}/tests/src) |
| 92 | set(TEST_INC_GEN_DIR ${CMAKE_BINARY_DIR}/generated/${use_case}/tests/include) |
| 93 | file(MAKE_DIRECTORY ${TEST_SRC_GEN_DIR} ${TEST_INC_GEN_DIR}) |
| 94 | |
| 95 | set(${use_case}_DEFAULT_TEST_DATA_DIR ${DEFAULT_TEST_DATA_DIR} CACHE PATH "") |
| 96 | # Generate test data files to be included in x86 tests |
| 97 | generate_test_data_code( |
| 98 | INPUT_DIR "${${use_case}_DEFAULT_TEST_DATA_DIR}" |
| 99 | DESTINATION_SRC ${TEST_SRC_GEN_DIR} |
| 100 | DESTINATION_HDR ${TEST_INC_GEN_DIR} |
| 101 | NAMESPACE "test" |
| 102 | ) |
| 103 | |
| 104 | file(GLOB_RECURSE TEST_SOURCES_GEN |
| 105 | "${TEST_SRC_GEN_DIR}/*.cc" |
| 106 | "${TEST_SRC_GEN_DIR}/**/*.cc" |
| 107 | ) |
| 108 | message(STATUS "Adding ${TEST_SOURCES_GEN} to test sources") |
| 109 | list(APPEND TEST_SOURCES ${TEST_SOURCES_GEN}) |
| 110 | list(APPEND TEST_RESOURCES_INCLUDE ${TEST_INC_GEN_DIR}) |
| 111 | |
Eanna O Cathain | 19c91fe | 2022-06-08 15:05:22 +0100 | [diff] [blame] | 112 | set(TEST_TARGET_NAME "${use_case}_tests") |
alexander | 31ae9f0 | 2022-02-10 16:15:54 +0000 | [diff] [blame] | 113 | add_executable(${TEST_TARGET_NAME} ${TEST_SOURCES}) |
alexander | cb8a987 | 2022-02-11 13:23:22 +0000 | [diff] [blame] | 114 | target_include_directories(${TEST_TARGET_NAME} PRIVATE ${TEST_RESOURCES_INCLUDE}) |
Kshitij Sisodia | ee82c60 | 2022-12-29 11:53:23 +0000 | [diff] [blame^] | 115 | target_link_libraries(${TEST_TARGET_NAME} PRIVATE ${UC_LIB_NAME} mlek::Catch2) |
alexander | 31ae9f0 | 2022-02-10 16:15:54 +0000 | [diff] [blame] | 116 | target_compile_definitions(${TEST_TARGET_NAME} PRIVATE |
| 117 | "ACTIVATION_BUF_SZ=${${use_case}_ACTIVATION_BUF_SZ}" |
| 118 | TESTS) |
Eanna O Cathain | 19c91fe | 2022-06-08 15:05:22 +0100 | [diff] [blame] | 119 | 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] | 120 | endif () |
| 121 | endfunction() |