From 1ab85e9e55ef0f94d94fa70abba3d3ce7183f24c Mon Sep 17 00:00:00 2001 From: Charles Giessen Date: Tue, 3 Oct 2023 16:22:02 -0600 Subject: [PATCH] Run tests in CI scripts Make use of CTest to manage running tests, and configure the project to allow Catch2 to work with CTest --- .github/workflows/ci_build.yml | 114 +++++++++++++++------------------ CMakeLists.txt | 1 + tests/CMakeLists.txt | 9 ++- tests/vulkan_mock.cpp | 27 ++++---- tests/vulkan_mock.hpp | 16 +++-- 5 files changed, 85 insertions(+), 82 deletions(-) diff --git a/.github/workflows/ci_build.yml b/.github/workflows/ci_build.yml index aa12f91..3d5fd42 100644 --- a/.github/workflows/ci_build.yml +++ b/.github/workflows/ci_build.yml @@ -21,72 +21,64 @@ name: CI Build on: [push, pull_request, workflow_dispatch] jobs: - linux-build: - name: ${{ matrix.config.name }} - runs-on: ${{ matrix.config.os }} - strategy: - fail-fast: false - matrix: - config: - - { - name: "Ubuntu GCC Debug", - os: ubuntu-latest, - type: "debug", - build_dir: "build", - cc: "gcc", cxx: "g++" - } - - { - name: "Ubuntu Clang Debug", - os: ubuntu-latest, - type: "debug", - build_dir: "build", - cc: "clang", cxx: "clang++" - } - - { - name: "Ubuntu GCC Release", - os: ubuntu-latest, - type: "release", - build_dir: "build", - cc: "gcc", cxx: "g++" - } - - { - name: "Ubuntu Clang Release", - os: ubuntu-latest, - type: "release", - build_dir: "build", - cc: "clang", cxx: "clang++" - } - steps: - - name: Checkout - uses: actions/checkout@v2.0.0 + linux: + name: Linux + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + type: ["Debug", "Release"] + cc: ["gcc", "clang"] + cxx: ["g++", "clang++"] + exclude: + - cc: gcc + cxx: clang++ + - cc: clang + cxx: g++ - - name: Install build dependencies - run: | - sudo apt-get update - sudo apt-get install -y xorg-dev - - name: CMake Configure - run: cmake -Bbuild -DVK_BOOTSTRAP_WERROR=ON -DVK_BOOTSTRAP_TEST=ON -DCMAKE_BUILD_TYPE=${{matrix.config.type}} + steps: + - uses: actions/checkout@v3 + - uses: lukka/get-cmake@latest + with: + cmakeVersion: 3.15 - - name: CMake Build - run: cmake --build build + - name: Install build dependencies + run: | + sudo apt-get update + sudo apt-get install -y xorg-dev - windows: - name: ${{ matrix.config.name }} - runs-on: ${{matrix.os}} + - name: CMake Configure + run: cmake -S. -B build -DCMAKE_BUILD_TYPE=${{matrix.type}} -DVK_BOOTSTRAP_WERROR=ON -DVK_BOOTSTRAP_TEST=ON - strategy: - matrix: - arch: [ Win32, x64 ] - config: [ Debug, Release ] - os: [windows-latest ] + - name: CMake Build + run: cmake --build build - steps: - - name: Checkout - uses: actions/checkout@v2.0.0 + - name: Install + run: cmake --install build --prefix build/install - - name: CMake Configure - run: cmake -Bbuild -DVK_BOOTSTRAP_WERROR=ON -DVK_BOOTSTRAP_TEST=ON -DCMAKE_BUILD_TYPE=${{matrix.config}} + - name: Run tests + working-directory: ./build + run: ctest --output-on-failure -C ${{matrix.type}} - - name: CMake Build - run: cmake --build build + windows: + name: Windows + runs-on: windows-latest + + strategy: + matrix: + arch: [ Win32, x64 ] + config: [ Debug, Release ] + + steps: + - uses: actions/checkout@v3 + + - name: CMake Configure + run: cmake -S. -B build -D CMAKE_BUILD_TYPE=${{matrix.config}} -D VK_BOOTSTRAP_WERROR=ON -D VK_BOOTSTRAP_TEST=ON -A ${{matrix.arch}} + + - name: CMake Build + run: cmake --build build + + - name: Run tests + working-directory: ./build + run: ctest --output-on-failure -C ${{matrix.config}} diff --git a/CMakeLists.txt b/CMakeLists.txt index 1edac0d..7e18c4f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -96,6 +96,7 @@ endif() option(VK_BOOTSTRAP_TEST "Test Vk-Bootstrap with glfw and Catch2" ${VK_BOOTSTRAP_TEST_DEFAULT_VALUE}) if(VK_BOOTSTRAP_TEST) + enable_testing() add_subdirectory(ext) add_subdirectory(tests) add_subdirectory(example) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index b97eeef..e19b0fe 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -29,8 +29,7 @@ target_link_libraries(vk-bootstrap-test Catch2::Catch2WithMain ) -# This should be how to make CTest aware of the tests, but unfortunately it fails to link. The tests run fine on their own, so this is left as a TODO -# list(APPEND CMAKE_MODULE_PATH ${Catch2_SOURCE_DIR}/extras) -# include(CTest) -# include(Catch) -# catch_discover_tests(vk-bootstrap-test) +list(APPEND CMAKE_MODULE_PATH ${Catch2_SOURCE_DIR}/extras) +include(CTest) +include(Catch) +catch_discover_tests(vk-bootstrap-test) diff --git a/tests/vulkan_mock.cpp b/tests/vulkan_mock.cpp index d16c19a..98b92ea 100644 --- a/tests/vulkan_mock.cpp +++ b/tests/vulkan_mock.cpp @@ -3,6 +3,7 @@ #include "vulkan_mock.hpp" #include + #include #if defined(__linux__) || defined(__APPLE__) @@ -14,7 +15,6 @@ return reinterpret_cast(shim_##x); \ } - VulkanMock mock; EXPORT_MACRO VulkanMock& get_vulkan_mock() { @@ -80,7 +80,7 @@ VKAPI_ATTR VkResult VKAPI_CALL shim_vkCreateInstance([[maybe_unused]] const VkIn if (pInstance == nullptr) { return VK_ERROR_INITIALIZATION_FAILED; } - *pInstance = reinterpret_cast(0x0000ABCD); + *pInstance = get_handle(0x0000ABCDU); return VK_SUCCESS; } VKAPI_ATTR void VKAPI_CALL shim_vkDestroyInstance( @@ -93,7 +93,7 @@ VKAPI_ATTR VkResult VKAPI_CALL shim_vkCreateDebugUtilsMessengerEXT([[maybe_unuse if (instance == nullptr) { return VK_ERROR_INITIALIZATION_FAILED; } - *pMessenger = reinterpret_cast(0xDEBE0000DEBE0000); + *pMessenger = get_uint64_handle(0xDEBE0000DEBE0000U); return VK_SUCCESS; } @@ -176,7 +176,7 @@ VKAPI_ATTR VkResult VKAPI_CALL shim_vkCreateDevice(VkPhysicalDevice physicalDevi if (physicalDevice == nullptr) { return VK_ERROR_INITIALIZATION_FAILED; } - *pDevice = reinterpret_cast(0x00FEDC00); + *pDevice = get_handle(0x0000ABCDU); get_physical_device_details(physicalDevice).created_devices.push_back(*pDevice); return VK_SUCCESS; } @@ -197,7 +197,7 @@ VKAPI_ATTR void VKAPI_CALL shim_vkGetDeviceQueue(VkDevice device, uint32_t queue if (it != std::end(physical_devices.created_devices)) { if (queueFamilyIndex < physical_devices.queue_family_properties.size() && queueIndex < physical_devices.queue_family_properties[queueFamilyIndex].queueCount) { - *pQueue = reinterpret_cast(0x0000CCEE); + *pQueue = get_handle(0x0000CCEEU); return; } } @@ -208,7 +208,7 @@ VKAPI_ATTR VkResult VKAPI_CALL shim_vkCreateCommandPool([[maybe_unused]] VkDevic [[maybe_unused]] const VkCommandPoolCreateInfo* pCreateInfo, [[maybe_unused]] const VkAllocationCallbacks* pAllocator, VkCommandPool* pCommandPool) { - *pCommandPool = reinterpret_cast(0x0000ABBB); + *pCommandPool = get_uint64_handle(0x0000ABBBU); return VK_SUCCESS; } @@ -216,7 +216,7 @@ VKAPI_ATTR VkResult VKAPI_CALL shim_vkCreateFence([[maybe_unused]] VkDevice devi [[maybe_unused]] const VkFenceCreateInfo* pCreateInfo, [[maybe_unused]] const VkAllocationCallbacks* pAllocator, VkFence* pFence) { - *pFence = reinterpret_cast(0x0000AAAC); + *pFence = get_uint64_handle(0x0000AAACU); return VK_SUCCESS; } VKAPI_ATTR void VKAPI_CALL shim_vkDestroyFence( @@ -226,15 +226,15 @@ VKAPI_ATTR VkResult VKAPI_CALL shim_vkCreateSwapchainKHR([[maybe_unused]] VkDevi [[maybe_unused]] const VkSwapchainCreateInfoKHR* pCreateInfo, [[maybe_unused]] const VkAllocationCallbacks* pAllocator, VkSwapchainKHR* pSwapchain) { - *pSwapchain = reinterpret_cast(0x0000FFFE); + *pSwapchain = get_uint64_handle(0x0000FFFEU); return VK_SUCCESS; } VKAPI_ATTR VkResult VKAPI_CALL shim_vkGetSwapchainImagesKHR( [[maybe_unused]] VkDevice device, [[maybe_unused]] VkSwapchainKHR swapchain, uint32_t* pSwapchainImageCount, VkImage* pSwapchainImages) { - std::vector images = { reinterpret_cast(0x0000EDD0), - reinterpret_cast(0x0000EDD1), - reinterpret_cast(0x0000EDD1) }; + std::vector images{ get_uint64_handle(0x0000EDD0U), + get_uint64_handle(0x0000EDD1U), + get_uint64_handle(0x0000EDD1U) }; return fill_out_count_pointer_pair(images, pSwapchainImageCount, pSwapchainImages); } @@ -242,7 +242,7 @@ VKAPI_ATTR VkResult VKAPI_CALL shim_vkCreateImageView([[maybe_unused]] VkDevice [[maybe_unused]] const VkImageViewCreateInfo* pCreateInfo, [[maybe_unused]] const VkAllocationCallbacks* pAllocator, VkImageView* pView) { - if (pView) *pView = reinterpret_cast(0x0000CCCE); + if (pView) *pView = get_uint64_handle(0x0000CCCEU); return VK_SUCCESS; } @@ -366,10 +366,13 @@ PFN_vkVoidFunction shim_vkGetInstanceProcAddr([[maybe_unused]] VkInstance instan } extern "C" { +#if defined(WIN32) EXPORT_MACRO VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char* pName) { +#pragma comment(linker, "/EXPORT:" __FUNCTION__ "=" __FUNCDNAME__) return shim_vkGetInstanceProcAddr(instance, pName); } +#endif #if defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__GNU__) #define DLSYM_FUNC_NAME dlsym diff --git a/tests/vulkan_mock.hpp b/tests/vulkan_mock.hpp index 4e8b3ab..558b621 100644 --- a/tests/vulkan_mock.hpp +++ b/tests/vulkan_mock.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include @@ -26,6 +27,14 @@ inline size_t get_pnext_chain_struct_size(VkStructureType type) { return 0; } +template T get_handle(size_t value) { return reinterpret_cast(value); } + +#if INTPTR_MAX == INT32_MAX +template uint64_t get_uint64_handle(uint64_t value) { return static_cast(value); } +#elif INTPTR_MAX == INT64_MAX +template T get_uint64_handle(uint64_t value) { return reinterpret_cast(value); } +#endif + struct VulkanMock { uint32_t api_version = VK_API_VERSION_1_3; std::vector instance_extensions; @@ -51,8 +60,8 @@ struct VulkanMock { std::vector surface_details; VkSurfaceKHR get_new_surface(SurfaceDetails details) { - size_t new_index = 0x123456789AB + surface_handles.size(); - surface_handles.push_back(reinterpret_cast(new_index)); + surface_handles.push_back( + get_uint64_handle(static_cast(0x123456789ABU + surface_handles.size()))); surface_details.push_back(details); return surface_handles.back(); } @@ -78,8 +87,7 @@ struct VulkanMock { std::vector physical_devices_details; void add_physical_device(PhysicalDeviceDetails details) { - size_t new_index = 0x001122334455 + physical_device_handles.size(); - physical_device_handles.push_back(reinterpret_cast(new_index)); + physical_device_handles.push_back(get_handle(0x22334455U + physical_device_handles.size())); physical_devices_details.emplace_back(std::move(details)); } };