15db71995Sopenharmony_ci# ~~~ 25db71995Sopenharmony_ci# Copyright (c) 2014-2023 Valve Corporation 35db71995Sopenharmony_ci# Copyright (c) 2014-2023 LunarG, Inc. 45db71995Sopenharmony_ci# 55db71995Sopenharmony_ci# Licensed under the Apache License, Version 2.0 (the "License"); 65db71995Sopenharmony_ci# you may not use this file except in compliance with the License. 75db71995Sopenharmony_ci# You may obtain a copy of the License at 85db71995Sopenharmony_ci# 95db71995Sopenharmony_ci# http://www.apache.org/licenses/LICENSE-2.0 105db71995Sopenharmony_ci# 115db71995Sopenharmony_ci# Unless required by applicable law or agreed to in writing, software 125db71995Sopenharmony_ci# distributed under the License is distributed on an "AS IS" BASIS, 135db71995Sopenharmony_ci# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 145db71995Sopenharmony_ci# See the License for the specific language governing permissions and 155db71995Sopenharmony_ci# limitations under the License. 165db71995Sopenharmony_ci# ~~~ 175db71995Sopenharmony_cienable_language(CXX) # Tests use C++ 185db71995Sopenharmony_ci 195db71995Sopenharmony_ciset(CMAKE_CXX_STANDARD 17) 205db71995Sopenharmony_ciset(CMAKE_CXX_STANDARD_REQUIRED ON) 215db71995Sopenharmony_ciset(CMAKE_CXX_EXTENSIONS OFF) 225db71995Sopenharmony_ci 235db71995Sopenharmony_ci# Make sure tests uses the dynamic runtime instead 245db71995Sopenharmony_ciset(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL") 255db71995Sopenharmony_ci 265db71995Sopenharmony_ci# For MSVC/Windows, replace /GR with an empty string, this prevents warnings of /GR being overriden by /GR- 275db71995Sopenharmony_ci# Newer CMake versions (3.20) have better solutions for this through policy - using the old 285db71995Sopenharmony_ci# way while waiting for when updating can occur 295db71995Sopenharmony_cistring(REPLACE "/GR" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") 305db71995Sopenharmony_ci 315db71995Sopenharmony_ciif (IS_DIRECTORY "${GOOGLETEST_INSTALL_DIR}/googletest") 325db71995Sopenharmony_ci set(BUILD_GTEST ON) 335db71995Sopenharmony_ci set(BUILD_GMOCK OFF) 345db71995Sopenharmony_ci set(gtest_force_shared_crt ON) 355db71995Sopenharmony_ci set(BUILD_SHARED_LIBS ON) 365db71995Sopenharmony_ci set(INSTALL_GTEST OFF) 375db71995Sopenharmony_ci add_subdirectory("${GOOGLETEST_INSTALL_DIR}" ${CMAKE_CURRENT_BINARY_DIR}/gtest) 385db71995Sopenharmony_cielse() 395db71995Sopenharmony_ci message(FATAL_ERROR "Could not find googletest directory. See BUILD.md") 405db71995Sopenharmony_ciendif() 415db71995Sopenharmony_ci 425db71995Sopenharmony_ciif (WIN32) 435db71995Sopenharmony_ci if(NOT IS_DIRECTORY ${DETOURS_INSTALL_DIR}) 445db71995Sopenharmony_ci message(FATAL_ERROR "Could not find detours! See BUILD.md") 455db71995Sopenharmony_ci endif() 465db71995Sopenharmony_ci add_library(detours STATIC 475db71995Sopenharmony_ci ${DETOURS_INSTALL_DIR}/src/creatwth.cpp 485db71995Sopenharmony_ci ${DETOURS_INSTALL_DIR}/src/detours.cpp 495db71995Sopenharmony_ci ${DETOURS_INSTALL_DIR}/src/detours.h 505db71995Sopenharmony_ci ${DETOURS_INSTALL_DIR}/src/detver.h 515db71995Sopenharmony_ci ${DETOURS_INSTALL_DIR}/src/disasm.cpp 525db71995Sopenharmony_ci ${DETOURS_INSTALL_DIR}/src/disolarm.cpp 535db71995Sopenharmony_ci ${DETOURS_INSTALL_DIR}/src/disolarm64.cpp 545db71995Sopenharmony_ci ${DETOURS_INSTALL_DIR}/src/disolia64.cpp 555db71995Sopenharmony_ci ${DETOURS_INSTALL_DIR}/src/disolx64.cpp 565db71995Sopenharmony_ci ${DETOURS_INSTALL_DIR}/src/disolx86.cpp 575db71995Sopenharmony_ci ${DETOURS_INSTALL_DIR}/src/image.cpp 585db71995Sopenharmony_ci ${DETOURS_INSTALL_DIR}/src/modules.cpp 595db71995Sopenharmony_ci ) 605db71995Sopenharmony_ci target_include_directories(detours PUBLIC ${DETOURS_INSTALL_DIR}/src) 615db71995Sopenharmony_ci 625db71995Sopenharmony_ci target_compile_definitions(detours PUBLIC WIN32_LEAN_AND_MEAN) 635db71995Sopenharmony_ci 645db71995Sopenharmony_ci if(MSVC) 655db71995Sopenharmony_ci target_compile_definitions(detours PUBLIC "_CRT_SECURE_NO_WARNINGS=1") 665db71995Sopenharmony_ci set_target_properties(detours PROPERTIES COMPILE_FLAGS /EHsc) 675db71995Sopenharmony_ci endif() 685db71995Sopenharmony_ci 695db71995Sopenharmony_ci # Silence errors found in clang-cl 705db71995Sopenharmony_ci if(CMAKE_C_COMPILER_ID STREQUAL "Clang" AND "${CMAKE_C_SIMULATE_ID}" MATCHES "MSVC") 715db71995Sopenharmony_ci target_compile_options(detours PRIVATE -Wno-sizeof-pointer-memaccess -Wno-microsoft-goto -Wno-microsoft-cast) 725db71995Sopenharmony_ci endif() 735db71995Sopenharmony_ciendif() 745db71995Sopenharmony_ci 755db71995Sopenharmony_cioption(ENABLE_LIVE_VERIFICATION_TESTS "Enable tests which expect to run on live drivers. Meant for manual verification only" OFF) 765db71995Sopenharmony_ci 775db71995Sopenharmony_ciinclude(GoogleTest) 785db71995Sopenharmony_ciadd_subdirectory(framework) 795db71995Sopenharmony_ci 805db71995Sopenharmony_ciadd_executable( 815db71995Sopenharmony_ci test_regression 825db71995Sopenharmony_ci loader_testing_main.cpp 835db71995Sopenharmony_ci loader_alloc_callback_tests.cpp 845db71995Sopenharmony_ci loader_envvar_tests.cpp 855db71995Sopenharmony_ci loader_get_proc_addr_tests.cpp 865db71995Sopenharmony_ci loader_debug_ext_tests.cpp 875db71995Sopenharmony_ci loader_handle_validation_tests.cpp 885db71995Sopenharmony_ci loader_layer_tests.cpp 895db71995Sopenharmony_ci loader_regression_tests.cpp 905db71995Sopenharmony_ci loader_phys_dev_inst_ext_tests.cpp 915db71995Sopenharmony_ci loader_settings_tests.cpp 925db71995Sopenharmony_ci loader_version_tests.cpp 935db71995Sopenharmony_ci loader_unknown_ext_tests.cpp 945db71995Sopenharmony_ci loader_wsi_tests.cpp) 955db71995Sopenharmony_citarget_link_libraries(test_regression PUBLIC testing_dependencies) 965db71995Sopenharmony_citarget_compile_definitions(test_regression PUBLIC VK_NO_PROTOTYPES) 975db71995Sopenharmony_ci 985db71995Sopenharmony_ci# Threading tests live in separate executabe just for threading tests as it'll need support 995db71995Sopenharmony_ci# in the test harness to enable in CI, as thread sanitizer doesn't work with address sanitizer enabled. 1005db71995Sopenharmony_ciadd_executable( 1015db71995Sopenharmony_ci test_threading 1025db71995Sopenharmony_ci loader_testing_main.cpp 1035db71995Sopenharmony_ci loader_threading_tests.cpp) 1045db71995Sopenharmony_citarget_link_libraries(test_threading PUBLIC testing_dependencies) 1055db71995Sopenharmony_citarget_compile_definitions(test_threading PUBLIC VK_NO_PROTOTYPES) 1065db71995Sopenharmony_ci 1075db71995Sopenharmony_ci# executables that are meant for testing against real drivers rather than the mocks 1085db71995Sopenharmony_ciif (ENABLE_LIVE_VERIFICATION_TESTS) 1095db71995Sopenharmony_ci add_subdirectory(live_verification) 1105db71995Sopenharmony_ciendif() 1115db71995Sopenharmony_ci 1125db71995Sopenharmony_ciif(WIN32) 1135db71995Sopenharmony_ci # Copy loader and googletest (gtest) libs to test dir so the test executable can find them. 1145db71995Sopenharmony_ci add_custom_command(TARGET test_regression POST_BUILD 1155db71995Sopenharmony_ci COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:gtest> $<TARGET_FILE_DIR:test_regression>) 1165db71995Sopenharmony_ci # Copy the loader shared lib (if built) to the test application directory so the test app finds it. 1175db71995Sopenharmony_ci if(TARGET vulkan) 1185db71995Sopenharmony_ci add_custom_command(TARGET test_regression POST_BUILD 1195db71995Sopenharmony_ci COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:vulkan> $<TARGET_FILE_DIR:test_regression>) 1205db71995Sopenharmony_ci endif() 1215db71995Sopenharmony_ci 1225db71995Sopenharmony_ci # Copy the gtest shared lib (if built) to the live verification tests directory so the tests finds it. 1235db71995Sopenharmony_ci if(ENABLE_LIVE_VERIFICATION_TESTS) 1245db71995Sopenharmony_ci add_custom_command(TARGET test_regression POST_BUILD 1255db71995Sopenharmony_ci COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:gtest> $<TARGET_FILE_DIR:dynamic_rendering_get_proc_addr>) 1265db71995Sopenharmony_ci endif() 1275db71995Sopenharmony_ciendif() 1285db71995Sopenharmony_ci 1295db71995Sopenharmony_ci# https://discourse.cmake.org/t/googletest-crash-when-using-cmake-xcode-arm64/5766 1305db71995Sopenharmony_ci# 1315db71995Sopenharmony_ci# TLDR: On macOS arm64, all binaries have to be signed before running. 1325db71995Sopenharmony_ci# Delay test discovery until test time as a workaround. 1335db71995Sopenharmony_ciif (XCODE) 1345db71995Sopenharmony_ci set(CMAKE_GTEST_DISCOVER_TESTS_DISCOVERY_MODE "PRE_TEST") 1355db71995Sopenharmony_ciendif() 1365db71995Sopenharmony_ci 1375db71995Sopenharmony_ci# must happen after the dll's get copied over 1385db71995Sopenharmony_ciif(NOT CMAKE_CROSSCOMPILING) 1395db71995Sopenharmony_ci gtest_discover_tests(test_regression PROPERTIES DISCOVERY_TIMEOUT 100) 1405db71995Sopenharmony_cielse() 1415db71995Sopenharmony_ci gtest_add_tests(TARGET test_regression) 1425db71995Sopenharmony_ciendif() 1435db71995Sopenharmony_ci 1445db71995Sopenharmony_ci# When APPLE_STATIC_LOADER is ON installation is disabled 1455db71995Sopenharmony_ciif (APPLE_STATIC_LOADER) 1465db71995Sopenharmony_ci return() 1475db71995Sopenharmony_ciendif() 1485db71995Sopenharmony_ci 1495db71995Sopenharmony_ci# Test installation 1505db71995Sopenharmony_ciset(test_install_dir "${CMAKE_CURRENT_BINARY_DIR}/install") 1515db71995Sopenharmony_ciadd_test(NAME integration.install 1525db71995Sopenharmony_ci COMMAND ${CMAKE_COMMAND} --install ${PROJECT_BINARY_DIR} --prefix ${test_install_dir} --config $<CONFIG> 1535db71995Sopenharmony_ci) 1545db71995Sopenharmony_ci 1555db71995Sopenharmony_ci# find_package testing currently doesn't work well under cross-compilation scenarios. 1565db71995Sopenharmony_ciif (CMAKE_CROSSCOMPILING OR 1575db71995Sopenharmony_ci NOT CMAKE_SIZEOF_VOID_P EQUAL 8) 1585db71995Sopenharmony_ci return() 1595db71995Sopenharmony_ciendif() 1605db71995Sopenharmony_ci 1615db71995Sopenharmony_ci# Test find_package suppport 1625db71995Sopenharmony_ciadd_test(NAME integration.find_package 1635db71995Sopenharmony_ci COMMAND ${CMAKE_CTEST_COMMAND} 1645db71995Sopenharmony_ci --build-and-test ${CMAKE_CURRENT_LIST_DIR}/integration 1655db71995Sopenharmony_ci ${CMAKE_CURRENT_BINARY_DIR}/find_package 1665db71995Sopenharmony_ci --build-generator ${CMAKE_GENERATOR} 1675db71995Sopenharmony_ci --build-options -DCMAKE_PREFIX_PATH=${test_install_dir} 1685db71995Sopenharmony_ci) 1695db71995Sopenharmony_ci 1705db71995Sopenharmony_ci# Installing comes before testing 1715db71995Sopenharmony_ciset_tests_properties(integration.find_package PROPERTIES DEPENDS integration.install) 172