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