-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
207 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#define CATCH_CONFIG_MAIN | ||
#include "../../inc/catch_amalgamated.hpp" | ||
#include "section_listener.h" | ||
|
||
CATCH_REGISTER_TAG_ALIAS("[@unit-tests]", "[d3d12],[vk]") | ||
CATCH_REGISTER_TAG_ALIAS("[@all]", "[d3d12],[vk]") | ||
|
||
CATCH_REGISTER_LISTENER(SectionListener) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#pragma once | ||
|
||
#include "nvofapi_tests_private.h" | ||
#include "../../src/shared/resource_factory.h" | ||
#include "nvofapi_vulkan_mocks.h" | ||
|
||
using namespace trompeloeil; | ||
|
||
class MockFactory final : public dxvk::ResourceFactory { | ||
|
||
public: | ||
MockFactory(std::unique_ptr<VkMock> vkMock) | ||
: m_vkMock(std::move(vkMock)) {}; | ||
|
||
std::unique_ptr<dxvk::Vk> CreateVulkan(const char*) override { | ||
return std::move(m_vkMock); | ||
} | ||
|
||
private: | ||
std::unique_ptr<VkMock> m_vkMock; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#include "nvofapi_tests_private.h" | ||
#include "nvofapi_vulkan_mocks.h" | ||
#include "mock_factory.h" | ||
|
||
using namespace trompeloeil; | ||
|
||
TEST_CASE("D3D12 methods succeed", "[.d3d12]") { | ||
auto vk = std::make_unique<VkMock>(); | ||
auto vkDevice = std::make_unique<VkDeviceMock>(); | ||
|
||
SECTION("CreateInstanceD3D12 fails to initialize with major version other than 5") { | ||
NV_OF_D3D12_API_FUNCTION_LIST functionList{}; | ||
REQUIRE(NvOFAPICreateInstanceD3D12(0, &functionList) == NV_OF_ERR_INVALID_VERSION); | ||
} | ||
|
||
SECTION("CreateInstanceD3D12 initializes") { | ||
NV_OF_D3D12_API_FUNCTION_LIST functionList{}; | ||
REQUIRE(NvOFAPICreateInstanceD3D12(80, &functionList) == NV_OF_SUCCESS); | ||
|
||
SECTION("CreateInstanceVk fails to initialize when Vulkan is not available") { | ||
ALLOW_CALL(*vk, IsAvailable()).RETURN(false); | ||
FORBID_CALL(*vk, GetInstanceProcAddr(_, _)); | ||
FORBID_CALL(*vk, GetDeviceProcAddr(_, _)); | ||
|
||
resourceFactory = std::make_unique<MockFactory>(std::move(vk)); | ||
|
||
// D3D12Vkd3dDeviceMock device; | ||
// NvOFHandle hOFInstance; | ||
// REQUIRE(functionList.nvCreateOpticalFlowD3D12(static_cast<ID3D12Device*>(&device), &hOFInstance) == NV_OF_ERR_GENERIC); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#pragma once | ||
|
||
#if defined(__GNUC__) || defined(__clang__) | ||
#pragma GCC diagnostic ignored "-Wnon-virtual-dtor" | ||
#endif // defined(__GNUC__) || defined(__clang__) | ||
|
||
#include "../../src/nvofapi_private.h" | ||
#include "../../src/nvofapi_globals.h" | ||
|
||
#include "../../inc/catch_amalgamated.hpp" | ||
#include "../../inc/catch2/trompeloeil.hpp" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#include "nvofapi_tests_private.h" | ||
#include "nvofapi_vulkan_mocks.h" | ||
#include "mock_factory.h" | ||
|
||
using namespace trompeloeil; | ||
|
||
TEST_CASE("Vk methods succeed", "[.vk]") { | ||
|
||
|
||
SECTION("CreateInstanceVk fails to initialize with major version other than 5") { | ||
NV_OF_VK_API_FUNCTION_LIST functionList{}; | ||
REQUIRE(NvOFAPICreateInstanceVk(0, &functionList) == NV_OF_ERR_INVALID_VERSION); | ||
} | ||
|
||
SECTION("CreateInstanceVk initializes") { | ||
auto vk = std::make_unique<VkMock>(); | ||
auto vkDevice = std::make_unique<VkDeviceMock>(); | ||
|
||
NV_OF_VK_API_FUNCTION_LIST functionList{}; | ||
REQUIRE(NvOFAPICreateInstanceVk(80, &functionList) == NV_OF_SUCCESS); | ||
|
||
SECTION("CreateInstanceVk fails to initialize when Vulkan is not available") { | ||
ALLOW_CALL(*vk, IsAvailable()).RETURN(false); | ||
FORBID_CALL(*vk, GetInstanceProcAddr(_, _)); | ||
FORBID_CALL(*vk, GetDeviceProcAddr(_, _)); | ||
|
||
resourceFactory = std::make_unique<MockFactory>(std::move(vk)); | ||
|
||
VkInstance vkInstance{}; | ||
VkPhysicalDevice vkPhysicalDevice{}; | ||
NvOFHandle hOFInstance; | ||
REQUIRE(functionList.nvCreateOpticalFlowVk(vkInstance, vkPhysicalDevice, reinterpret_cast<VkDevice>(vkDevice.get()), &hOFInstance) == NV_OF_ERR_GENERIC); | ||
} | ||
|
||
SECTION("CreateInstanceVk returns success") { | ||
ALLOW_CALL(*vk, IsAvailable()).RETURN(true); | ||
FORBID_CALL(*vk, GetInstanceProcAddr(_, _)); | ||
FORBID_CALL(*vk, GetDeviceProcAddr(_, _)); | ||
|
||
resourceFactory = std::make_unique<MockFactory>(std::move(vk)); | ||
|
||
VkInstance vkInstance{}; | ||
VkPhysicalDevice vkPhysicalDevice{}; | ||
NvOFHandle hOFInstance; | ||
REQUIRE(functionList.nvCreateOpticalFlowVk(vkInstance, vkPhysicalDevice, reinterpret_cast<VkDevice>(vkDevice.get()), &hOFInstance) == NV_OF_SUCCESS); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#pragma once | ||
|
||
#include "nvofapi_tests_private.h" | ||
#include "../../src/shared/vk.h" | ||
|
||
using namespace trompeloeil; | ||
|
||
class VkDeviceMock { | ||
MAKE_MOCK4(vkCreateSemaphore, VkResult(VkDevice, const VkSemaphoreCreateInfo*, const VkAllocationCallbacks*, VkSemaphore*)); | ||
MAKE_MOCK3(vkDestroySemaphore, void(VkDevice, VkSemaphore, const VkAllocationCallbacks*)); | ||
|
||
static VkResult CreateSemaphore(VkDevice device, const VkSemaphoreCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSemaphore* pSemaphore) { | ||
return reinterpret_cast<VkDeviceMock*>(device)->vkCreateSemaphore(device, pCreateInfo, pAllocator, pSemaphore); | ||
} | ||
static void DestroySemaphore(VkDevice device, VkSemaphore semaphore, const VkAllocationCallbacks* pAllocator) { | ||
reinterpret_cast<VkDeviceMock*>(device)->vkDestroySemaphore(device, semaphore, pAllocator); | ||
} | ||
}; | ||
|
||
class VkQueueMock { | ||
|
||
}; | ||
|
||
class VkMock final : public mock_interface<dxvk::Vk> { | ||
IMPLEMENT_CONST_MOCK0(IsAvailable); | ||
IMPLEMENT_CONST_MOCK2(GetInstanceProcAddr); | ||
IMPLEMENT_CONST_MOCK2(GetDeviceProcAddr); | ||
IMPLEMENT_CONST_MOCK2(GetDeviceExtensions); | ||
IMPLEMENT_CONST_MOCK3(GetPhysicalDeviceProperties2); | ||
|
||
[[nodiscard]] static std::array<std::unique_ptr<expectation>, 2> ConfigureDefaultPFN(VkMock& mock) { | ||
return { | ||
NAMED_ALLOW_CALL(mock, GetDeviceProcAddr(_, eq(std::string_view("vkCreateSemaphore")))) | ||
.RETURN(reinterpret_cast<PFN_vkVoidFunction>(VkDeviceMock::CreateSemaphore)), | ||
NAMED_ALLOW_CALL(mock, GetDeviceProcAddr(_, eq(std::string_view("vkDestroySemaphore")))) | ||
.RETURN(reinterpret_cast<PFN_vkVoidFunction>(VkDeviceMock::DestroySemaphore))}; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#pragma once | ||
|
||
#include "nvofapi_tests_private.h" | ||
|
||
class SectionListener : public Catch::EventListenerBase { | ||
|
||
public: | ||
using Catch::EventListenerBase::EventListenerBase; | ||
|
||
void sectionEnded(Catch::SectionStats const&) override { | ||
resourceFactory.reset(); | ||
} | ||
}; |