diff options
| author | Charles Giessen <charles@lunarg.com> | 2023-08-19 16:45:26 -0600 |
|---|---|---|
| committer | Charles Giessen <46324611+charles-lunarg@users.noreply.github.com> | 2023-08-21 16:44:30 -0600 |
| commit | b441f434a036d6fe463ba944c8d7e0a9cd30faa6 (patch) | |
| tree | cccb28613e907ac2ec8a46ad743ac9a07394990b | |
| parent | 944f91b48811d072654d3a0db4f6d704c04fadbd (diff) | |
| download | usermoji-b441f434a036d6fe463ba944c8d7e0a9cd30faa6.tar.xz | |
test: Make mock ICD tests work on windows
This does not enable testing in CI on windows, due to the loader ignoring
VK_DRIVER_FILES when running in admin mode.
| -rw-r--r-- | tests/CMakeLists.txt | 13 | ||||
| -rw-r--r-- | tests/icd/mock_icd_tests.cpp | 38 | ||||
| -rw-r--r-- | tests/test_common.h | 37 |
3 files changed, 59 insertions, 29 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 66d9adc6..d95b00a9 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -50,19 +50,30 @@ find_package(GTest REQUIRED CONFIG QUIET) add_executable(vulkan_tools_tests) target_sources(vulkan_tools_tests PRIVATE main.cpp + test_common.h icd/mock_icd_tests.cpp ) get_target_property(TEST_SOURCES vulkan_tools_tests SOURCES) source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}" FILES ${TEST_SOURCES}) -target_include_directories(vulkan_tools_tests PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) +target_include_directories(vulkan_tools_tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) target_link_libraries(vulkan_tools_tests GTest::gtest Vulkan::Vulkan) add_dependencies(vulkan_tools_tests generate_binary_locations) +if (WIN32) + target_compile_definitions(vulkan_tools_tests PUBLIC -DVK_USE_PLATFORM_WIN32_KHR -DWIN32_LEAN_AND_MEAN -DNOMINMAX) +endif() +set_target_properties(vulkan_tools_tests PROPERTIES MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL") if (ENABLE_ADDRESS_SANITIZER) target_compile_options(vulkan_tools_tests PUBLIC -fsanitize=address) target_link_options(vulkan_tools_tests PUBLIC -fsanitize=address) endif () +if (WIN32) + # Copy the loader shared lib (if built) to the test application directory so the test app finds it. + add_custom_command(TARGET vulkan_tools_tests POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:Vulkan::Vulkan> $<TARGET_FILE_DIR:vulkan_tools_tests>) +endif() + include(GoogleTest) gtest_discover_tests(vulkan_tools_tests DISCOVERY_TIMEOUT 100) diff --git a/tests/icd/mock_icd_tests.cpp b/tests/icd/mock_icd_tests.cpp index ee1cbcb5..bcae57a9 100644 --- a/tests/icd/mock_icd_tests.cpp +++ b/tests/icd/mock_icd_tests.cpp @@ -17,25 +17,7 @@ * */ -#include <stdlib.h> - -#include <array> -#include <iostream> -#include <vector> - -#include "gtest/gtest.h" -#include "vulkan/vulkan.h" - -// Location of the built binaries in this repo -#include "binary_locations.h" - -#if defined(WIN32) -#define WIN32_LEAN_AND_MEAN -#include <windows.h> -int set_environment_var(const char* name, const char* value) { return SetEnvironmentVariable(name, value); } -#else -int set_environment_var(const char* name, const char* value) { return setenv(name, value, 1); } -#endif +#include "test_common.h" void setup_mock_icd_env_vars() { // Necessary to point the loader at the mock driver @@ -256,7 +238,7 @@ TEST_F(MockICD, vkGetPhysicalDeviceSurfacePresentModesKHR) { VkSurfaceKHR surface{}; res = create_surface(instance, surface); ASSERT_EQ(res, VK_SUCCESS); - ASSERT_NE(surface, nullptr); + ASSERT_NE(surface, VK_NULL_HANDLE); uint32_t count = 0; std::array<VkPresentModeKHR, 6> present_modes{}; res = vkGetPhysicalDeviceSurfacePresentModesKHR(physical_device, surface, &count, nullptr); @@ -278,7 +260,7 @@ TEST_F(MockICD, vkGetPhysicalDeviceSurfaceFormatsKHR) { VkSurfaceKHR surface{}; res = create_surface(instance, surface); ASSERT_EQ(res, VK_SUCCESS); - ASSERT_NE(surface, nullptr); + ASSERT_NE(surface, VK_NULL_HANDLE); uint32_t count = 0; std::array<VkSurfaceFormatKHR, 2> surface_formats{}; res = vkGetPhysicalDeviceSurfaceFormatsKHR(physical_device, surface, &count, nullptr); @@ -298,7 +280,7 @@ TEST_F(MockICD, vkGetPhysicalDeviceSurfaceFormats2KHR) { VkSurfaceKHR surface{}; res = create_surface(instance, surface); ASSERT_EQ(res, VK_SUCCESS); - ASSERT_NE(surface, nullptr); + ASSERT_NE(surface, VK_NULL_HANDLE); uint32_t count = 0; std::array<VkSurfaceFormat2KHR, 2> surface_formats2{}; VkPhysicalDeviceSurfaceInfo2KHR surface_info{}; @@ -322,7 +304,7 @@ TEST_F(MockICD, vkGetPhysicalDeviceSurfaceSupportKHR) { VkSurfaceKHR surface{}; res = create_surface(instance, surface); ASSERT_EQ(res, VK_SUCCESS); - ASSERT_NE(surface, nullptr); + ASSERT_NE(surface, VK_NULL_HANDLE); VkBool32 supported = false; res = vkGetPhysicalDeviceSurfaceSupportKHR(physical_device, 0, surface, &supported); ASSERT_EQ(res, VK_SUCCESS); @@ -335,7 +317,7 @@ TEST_F(MockICD, vkGetPhysicalDeviceSurfaceCapabilitiesKHR) { VkSurfaceKHR surface{}; res = create_surface(instance, surface); ASSERT_EQ(res, VK_SUCCESS); - ASSERT_NE(surface, nullptr); + ASSERT_NE(surface, VK_NULL_HANDLE); VkSurfaceCapabilitiesKHR surface_capabilities{}; res = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(physical_device, surface, &surface_capabilities); ASSERT_EQ(res, VK_SUCCESS); @@ -354,7 +336,7 @@ TEST_F(MockICD, vkGetPhysicalDeviceSurfaceCapabilities2KHR) { VkSurfaceKHR surface{}; res = create_surface(instance, surface); ASSERT_EQ(res, VK_SUCCESS); - ASSERT_NE(surface, nullptr); + ASSERT_NE(surface, VK_NULL_HANDLE); VkSurfaceCapabilities2KHR surface_capabilities2{}; VkPhysicalDeviceSurfaceInfo2KHR surface_info{}; surface_info.surface = surface; @@ -899,7 +881,7 @@ TEST_F(MockICD, SwapchainLifeCycle) { VkSurfaceKHR surface{}; res = create_surface(instance, surface); ASSERT_EQ(res, VK_SUCCESS); - ASSERT_NE(surface, nullptr); + ASSERT_NE(surface, VK_NULL_HANDLE); VkSwapchainCreateInfoKHR swapchain_create_info{}; swapchain_create_info.surface = surface; @@ -907,7 +889,7 @@ TEST_F(MockICD, SwapchainLifeCycle) { VkSwapchainKHR swapchain{}; res = vkCreateSwapchainKHR(device, &swapchain_create_info, nullptr, &swapchain); ASSERT_EQ(res, VK_SUCCESS); - ASSERT_NE(swapchain, nullptr); + ASSERT_NE(swapchain, VK_NULL_HANDLE); uint32_t count = 0; res = vkGetSwapchainImagesKHR(device, swapchain, &count, nullptr); @@ -916,7 +898,7 @@ TEST_F(MockICD, SwapchainLifeCycle) { std::array<VkImage, 1> swapchain_images; res = vkGetSwapchainImagesKHR(device, swapchain, &count, swapchain_images.data()); ASSERT_EQ(res, VK_SUCCESS); - ASSERT_NE(swapchain_images[0], nullptr); + ASSERT_NE(swapchain_images[0], VK_NULL_HANDLE); uint32_t image_index = 10; // arbitrary non zero value res = vkAcquireNextImageKHR(device, swapchain, 0, VK_NULL_HANDLE, VK_NULL_HANDLE, &image_index); diff --git a/tests/test_common.h b/tests/test_common.h new file mode 100644 index 00000000..de06a784 --- /dev/null +++ b/tests/test_common.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2023 The Khronos Group Inc. + * Copyright (c) 2023 Valve Corporation + * Copyright (c) 2023 LunarG, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include <stdlib.h> + +#include <array> +#include <iostream> +#include <vector> + +#include "gtest/gtest.h" +#include "vulkan/vulkan.h" + +// Location of the built binaries in this repo +#include "binary_locations.h" + +#if defined(WIN32) +#include <windows.h> +inline int set_environment_var(const char* name, const char* value) { return SetEnvironmentVariable(name, value); } +#else +inline int set_environment_var(const char* name, const char* value) { return setenv(name, value, 1); } +#endif |
