blob: bf6f980e432760c9ef281c6cfa13e0bdd390eeb8 [file] [log] [blame]
alexander31ae9f02022-02-10 16:15:54 +00001#----------------------------------------------------------------------------
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
alexander31ae9f02022-02-10 16:15:54 +000018function(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
alexandercb8a9872022-02-11 13:23:22 +000025 set(TEST_TPIP ${DOWNLOAD_DEP_DIR}/test)
26
27 file(MAKE_DIRECTORY ${TEST_TPIP})
28 set(TEST_TPIP_INCLUDE ${TEST_TPIP}/include)
29 file(MAKE_DIRECTORY ${TEST_TPIP_INCLUDE})
30
31 ExternalProject_Add(catch2-headers
32 URL https://github.com/catchorg/Catch2/releases/download/v2.11.1/catch.hpp
33 DOWNLOAD_NO_EXTRACT 1
34 CONFIGURE_COMMAND ""
35 BUILD_COMMAND ${CMAKE_COMMAND} -E copy <DOWNLOAD_DIR>/catch.hpp ${TEST_TPIP_INCLUDE}
36 INSTALL_COMMAND "")
37
38 add_library(catch2 INTERFACE)
39 target_include_directories(catch2
40 INTERFACE
41 ${TEST_TPIP_INCLUDE})
42
alexander31ae9f02022-02-10 16:15:54 +000043endfunction()
44
45function(platform_custom_post_build)
46 set(oneValueArgs TARGET_NAME)
47 cmake_parse_arguments(PARSED "" "${oneValueArgs}" "" ${ARGN} )
48
49
50 # If native build tests
51 set(TEST_SRC_USE_CASE "")
52 foreach(USE_CASES_TESTS_SEARCH_DIR ${USE_CASES_TESTS_SEARCH_DIR_LIST})
53
54 if (EXISTS ${USE_CASES_TESTS_SEARCH_DIR}/${use_case})
55 message(STATUS "Found tests for use-case ${use_case} at ${USE_CASES_TESTS_SEARCH_DIR}/${use_case}.")
56 set(TEST_SRC_USE_CASE ${USE_CASES_TESTS_SEARCH_DIR})
57 break()
58 endif ()
59 endforeach()
60
61 # Add tests only if they exists for the usecase
62 if (NOT ${TEST_SRC_USE_CASE} STREQUAL "")
63
64 set(TEST_RESOURCES_INCLUDE
65 "${TEST_SRCS}/utils/"
66 "${TEST_SRC_USE_CASE}/${use_case}/include/"
67 )
68
69 # Define Test sources and new target to run unit tests
70 file(GLOB_RECURSE TEST_SOURCES
71 "${TEST_SRCS}/common/*.cpp"
72 "${TEST_SRCS}/common/*.cc"
73 "${TEST_SRCS}/utils/*.cc"
74 "${TEST_SRCS}/utils/*.cpp"
75 "${TEST_SRC_USE_CASE}/${use_case}/*.cpp"
76 "${TEST_SRC_USE_CASE}/${use_case}/*.cc"
77 "${TEST_SRC_USE_CASE}/${use_case}/*.c"
78 "${TEST_SRC_USE_CASE}/${use_case}/**/*.cpp"
79 "${TEST_SRC_USE_CASE}/${use_case}/**/*.cc"
80 "${TEST_SRC_USE_CASE}/${use_case}/**/*.c"
81 )
82
83 set(TEST_SRC_GEN_DIR ${CMAKE_BINARY_DIR}/generated/${use_case}/tests/src)
84 set(TEST_INC_GEN_DIR ${CMAKE_BINARY_DIR}/generated/${use_case}/tests/include)
85 file(MAKE_DIRECTORY ${TEST_SRC_GEN_DIR} ${TEST_INC_GEN_DIR})
86
87 set(${use_case}_DEFAULT_TEST_DATA_DIR ${DEFAULT_TEST_DATA_DIR} CACHE PATH "")
88 # Generate test data files to be included in x86 tests
89 generate_test_data_code(
90 INPUT_DIR "${${use_case}_DEFAULT_TEST_DATA_DIR}"
91 DESTINATION_SRC ${TEST_SRC_GEN_DIR}
92 DESTINATION_HDR ${TEST_INC_GEN_DIR}
93 NAMESPACE "test"
94 )
95
96 file(GLOB_RECURSE TEST_SOURCES_GEN
97 "${TEST_SRC_GEN_DIR}/*.cc"
98 "${TEST_SRC_GEN_DIR}/**/*.cc"
99 )
100 message(STATUS "Adding ${TEST_SOURCES_GEN} to test sources")
101 list(APPEND TEST_SOURCES ${TEST_SOURCES_GEN})
102 list(APPEND TEST_RESOURCES_INCLUDE ${TEST_INC_GEN_DIR})
103
104 set(TEST_TARGET_NAME "${CMAKE_PROJECT_NAME}-${use_case}-tests")
105 add_executable(${TEST_TARGET_NAME} ${TEST_SOURCES})
alexandercb8a9872022-02-11 13:23:22 +0000106 target_include_directories(${TEST_TARGET_NAME} PRIVATE ${TEST_RESOURCES_INCLUDE})
107 target_link_libraries(${TEST_TARGET_NAME} PRIVATE ${UC_LIB_NAME} catch2)
alexander31ae9f02022-02-10 16:15:54 +0000108 target_compile_definitions(${TEST_TARGET_NAME} PRIVATE
109 "ACTIVATION_BUF_SZ=${${use_case}_ACTIVATION_BUF_SZ}"
110 TESTS)
alexander31ae9f02022-02-10 16:15:54 +0000111 endif ()
112endfunction()