• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# ~~~
2# Copyright (c) 2014-2023 Valve Corporation
3# Copyright (c) 2014-2023 LunarG, Inc.
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# ~~~
17enable_language(CXX) # Tests use C++
18
19set(CMAKE_CXX_STANDARD 17)
20set(CMAKE_CXX_STANDARD_REQUIRED ON)
21set(CMAKE_CXX_EXTENSIONS OFF)
22
23# Make sure tests uses the dynamic runtime instead
24set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
25
26if (IS_DIRECTORY "${GOOGLETEST_INSTALL_DIR}/googletest")
27    set(BUILD_GTEST ON)
28    set(BUILD_GMOCK OFF)
29    set(gtest_force_shared_crt ON)
30    set(INSTALL_GTEST OFF)
31    add_subdirectory("${GOOGLETEST_INSTALL_DIR}" ${CMAKE_CURRENT_BINARY_DIR}/gtest)
32else()
33    message(FATAL_ERROR "Could not find googletest directory. See BUILD.md")
34endif()
35
36if (WIN32)
37    if(NOT IS_DIRECTORY ${DETOURS_INSTALL_DIR})
38        message(FATAL_ERROR "Could not find detours! See BUILD.md")
39    endif()
40    add_library(detours STATIC
41        ${DETOURS_INSTALL_DIR}/src/creatwth.cpp
42        ${DETOURS_INSTALL_DIR}/src/detours.cpp
43        ${DETOURS_INSTALL_DIR}/src/detours.h
44        ${DETOURS_INSTALL_DIR}/src/detver.h
45        ${DETOURS_INSTALL_DIR}/src/disasm.cpp
46        ${DETOURS_INSTALL_DIR}/src/disolarm.cpp
47        ${DETOURS_INSTALL_DIR}/src/disolarm64.cpp
48        ${DETOURS_INSTALL_DIR}/src/disolia64.cpp
49        ${DETOURS_INSTALL_DIR}/src/disolx64.cpp
50        ${DETOURS_INSTALL_DIR}/src/disolx86.cpp
51        ${DETOURS_INSTALL_DIR}/src/image.cpp
52        ${DETOURS_INSTALL_DIR}/src/modules.cpp
53    )
54    target_include_directories(detours PUBLIC ${DETOURS_INSTALL_DIR}/src)
55
56    target_compile_definitions(detours PUBLIC WIN32_LEAN_AND_MEAN)
57
58    if(MSVC)
59        target_compile_definitions(detours PUBLIC  "_CRT_SECURE_NO_WARNINGS=1")
60        set_target_properties(detours PROPERTIES COMPILE_FLAGS /EHsc)
61    endif()
62
63    # Silence errors found in clang-cl
64    if(CMAKE_C_COMPILER_ID STREQUAL "Clang" AND "${CMAKE_C_SIMULATE_ID}" MATCHES "MSVC")
65        target_compile_options(detours PRIVATE -Wno-sizeof-pointer-memaccess -Wno-microsoft-goto -Wno-microsoft-cast)
66    endif()
67endif()
68
69option(ENABLE_LIVE_VERIFICATION_TESTS "Enable tests which expect to run on live drivers. Meant for manual verification only" OFF)
70
71include(GoogleTest)
72add_subdirectory(framework)
73
74add_executable(
75    test_regression
76        loader_testing_main.cpp
77        loader_alloc_callback_tests.cpp
78        loader_envvar_tests.cpp
79        loader_get_proc_addr_tests.cpp
80        loader_debug_ext_tests.cpp
81        loader_handle_validation_tests.cpp
82        loader_layer_tests.cpp
83        loader_regression_tests.cpp
84        loader_phys_dev_inst_ext_tests.cpp
85        loader_settings_tests.cpp
86        loader_version_tests.cpp
87        loader_unknown_ext_tests.cpp
88        loader_wsi_tests.cpp)
89target_link_libraries(test_regression PUBLIC testing_dependencies)
90target_compile_definitions(test_regression PUBLIC VK_NO_PROTOTYPES)
91
92add_executable(
93    test_fuzzing
94        loader_testing_main.cpp
95        loader_fuzz_tests.cpp
96)
97target_link_libraries(test_fuzzing PUBLIC testing_dependencies vulkan)
98target_include_directories(test_fuzzing PUBLIC ${CMAKE_SOURCE_DIR}/loader ${CMAKE_SOURCE_DIR}/loader/generated)
99
100# Threading tests live in separate executabe just for threading tests as it'll need support
101# in the test harness to enable in CI, as thread sanitizer doesn't work with address sanitizer enabled.
102add_executable(
103    test_threading
104        loader_testing_main.cpp
105        loader_threading_tests.cpp)
106target_link_libraries(test_threading PUBLIC testing_dependencies)
107target_compile_definitions(test_threading PUBLIC VK_NO_PROTOTYPES)
108
109# executables that are meant for testing against real drivers rather than the mocks
110if (ENABLE_LIVE_VERIFICATION_TESTS)
111    add_subdirectory(live_verification)
112endif()
113
114if(WIN32)
115    # Copy vulkan-1.dll to the test_fuzzing build directory so that the test_fuzzing exe can find it.
116    if(TARGET vulkan)
117        add_custom_command(TARGET test_fuzzing POST_BUILD
118                           COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:vulkan> $<TARGET_FILE_DIR:test_fuzzing>)
119    endif()
120endif()
121
122# https://discourse.cmake.org/t/googletest-crash-when-using-cmake-xcode-arm64/5766
123#
124# TLDR: On macOS arm64, all binaries have to be signed before running.
125# Delay test discovery until test time as a workaround.
126if (XCODE)
127    set(CMAKE_GTEST_DISCOVER_TESTS_DISCOVERY_MODE "PRE_TEST")
128endif()
129
130# must happen after the dll's get copied over
131if(NOT CMAKE_CROSSCOMPILING)
132    gtest_discover_tests(test_regression PROPERTIES DISCOVERY_TIMEOUT 100)
133    gtest_discover_tests(test_fuzzing PROPERTIES DISCOVERY_TIMEOUT 100)
134else()
135    gtest_add_tests(TARGET test_regression)
136    gtest_add_tests(TARGET test_fuzzing)
137endif()
138
139# When APPLE_STATIC_LOADER is ON installation is disabled
140if (APPLE_STATIC_LOADER)
141    return()
142endif()
143
144# Test installation
145set(test_install_dir "${CMAKE_CURRENT_BINARY_DIR}/install")
146add_test(NAME integration.install
147    COMMAND ${CMAKE_COMMAND} --install ${PROJECT_BINARY_DIR} --prefix ${test_install_dir} --config $<CONFIG>
148)
149
150# find_package testing currently doesn't work well under cross-compilation scenarios.
151if (CMAKE_CROSSCOMPILING OR
152    NOT CMAKE_SIZEOF_VOID_P EQUAL 8)
153    return()
154endif()
155
156# Test find_package suppport
157add_test(NAME integration.find_package
158    COMMAND ${CMAKE_CTEST_COMMAND}
159        --build-and-test ${CMAKE_CURRENT_LIST_DIR}/integration
160                        ${CMAKE_CURRENT_BINARY_DIR}/find_package
161        --build-generator ${CMAKE_GENERATOR}
162        --build-options -DCMAKE_PREFIX_PATH=${test_install_dir}
163)
164
165# Installing comes before testing
166set_tests_properties(integration.find_package PROPERTIES DEPENDS integration.install)
167
168if (CODE_COVERAGE)
169    target_code_coverage(test_regression AUTO ALL )
170    target_code_coverage(test_fuzzing AUTO ALL )
171endif()
172