Skip to content

Commit

Permalink
tests: Add nvofapi tests skeleton
Browse files Browse the repository at this point in the history
  • Loading branch information
jp7677 committed Jan 28, 2025
1 parent 62976ae commit a48bfe2
Show file tree
Hide file tree
Showing 26 changed files with 285 additions and 101 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/build-test-package-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,15 @@ jobs:
./package-release.sh "${{ env.VERSION }}" build --enable-tests
mkdir "${HOME}/tests-prefix"
WINEPREFIX="${HOME}/tests-prefix" WINEDEBUG=-all wine \
"./build/dxvk-nvapi-${{ env.VERSION }}/x64/nvapi64-tests.exe" [@unit-tests] -o tests.log
"./build/dxvk-nvapi-${{ env.VERSION }}/x64/nvapi64-tests.exe" [@unit-tests] -o nvapi64-tests.log
WINEPREFIX="${HOME}/tests-prefix" WINEDEBUG=-all wine \
"./build/dxvk-nvapi-${{ env.VERSION }}/x64/nvofapi64-tests.exe" [@unit-tests] -o nvofapi64-tests.log
- name: Present tests results
if: success() || failure()
run: if [ -e tests.log ]; then cat tests.log; fi
run: |
if [ -e nvapi64-tests.log ]; then cat nvapi64-tests.log; fi
if [ -e nvofapi64-tests.log ]; then cat nvofapi64-tests.log; fi
- name: Create tarball
if: github.ref_type == 'tag'
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/build-test-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ jobs:
shell: pwsh
run: |
& .\build-msvc-x64\tests\nvapi64-tests.exe [@unit-tests]
& .\build-msvc-x64\tests\nvofapi64-tests.exe [@unit-tests]
- name: Build MSVC layer
shell: pwsh
Expand Down
29 changes: 29 additions & 0 deletions tests/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,32 @@ nvapi_exe = executable(target_name, [ nvapi_src, catch2_src, nvapi_tests_src, dx
dependencies : [ lib_dxgi, lib_d3d11, lib_version ],
include_directories : [ nvapi_headers, vk_headers ],
install : true)

nvofapi_src = files([
'../src/util/util_string.cpp',
'../src/util/util_env.cpp',
'../src/util/util_log.cpp',
'../src/shared/resource_factory.cpp',
'../src/shared/vk.cpp',
'../src/nvofapi/nvofapi_image.cpp',
'../src/nvofapi/nvofapi_instance.cpp',
'../src/nvofapi/nvofapi_d3d12_instance.cpp',
'../src/nvofapi/nvofapi_vk_instance.cpp',
'../src/nvofapi_globals.cpp',
'../src/nvofapi.cpp',
'../src/nvofapi_d3d12.cpp',
'../src/nvofapi_vk.cpp',
])

nvofapi_tests_src = files([
'nvofapi/main.cpp',
'nvofapi/nvofapi_d3d12.cpp',
'nvofapi/nvofapi_vk.cpp',
])

target_name = 'nvofapi'+target_suffix+'-tests'
nvofapi_exe = executable(target_name, [ nvofapi_src, catch2_src, nvofapi_tests_src, dxvk_nvapi_version ],
cpp_args : '-DDXVK_NVAPI_TARGET_NAME="'+target_name+'"',
dependencies : [ lib_version ],
include_directories : [ nvapi_headers, vk_headers ],
install : true)
2 changes: 1 addition & 1 deletion tests/nvapi/mock_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "../../src/nvapi/nvapi_resource_factory.h"
#include "nvapi_d3d_mocks.h"
#include "nvapi_sysinfo_mocks.h"
#include "nvapi_vulkan_mocks.h"
#include "../shared/vulkan_mocks.h"

using namespace trompeloeil;

Expand Down
2 changes: 2 additions & 0 deletions tests/nvapi/nvapi_d3d.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "nvapi_tests_private.h"
#include "resource_factory_util.h"
#include "nvapi_d3d_mocks.h"
#include "../shared/dxgi_mocks.h"
#include "../shared/d3d_mocks.h"

using namespace trompeloeil;

Expand Down
6 changes: 4 additions & 2 deletions tests/nvapi/nvapi_d3d11.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#include "nvapi_tests_private.h"
#include "resource_factory_util.h"
#include "nvapi_sysinfo_mocks.h"
#include "nvapi_vulkan_mocks.h"
#include "nvapi_d3d_mocks.h"
#include "nvapi_d3d11_mocks.h"
#include "../shared/vulkan_mocks.h"
#include "../shared/dxgi_mocks.h"
#include "../shared/d3d11_mocks.h"
#include "../shared/d3d_mocks.h"

using namespace trompeloeil;

Expand Down
5 changes: 3 additions & 2 deletions tests/nvapi/nvapi_d3d12.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#include "nvapi_tests_private.h"
#include "resource_factory_util.h"
#include "nvapi_sysinfo_mocks.h"
#include "nvapi_vulkan_mocks.h"
#include "nvapi_d3d12_mocks.h"
#include "nvapi_d3d_mocks.h"
#include "../shared/dxgi_mocks.h"
#include "../shared/d3d12_mocks.h"
#include "../shared/vulkan_mocks.h"

using namespace trompeloeil;

Expand Down
6 changes: 0 additions & 6 deletions tests/nvapi/nvapi_d3d_mocks.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@
#include "../../src/interfaces/shared_interfaces.h"
#include "../../src/nvapi/lfx.h"

class UnknownMock : public trompeloeil::mock_interface<IUnknown> {
MAKE_MOCK2(QueryInterface, HRESULT(REFIID, void**), override);
MAKE_MOCK0(AddRef, ULONG(), override);
MAKE_MOCK0(Release, ULONG(), override);
};

class LfxMock : public trompeloeil::mock_interface<dxvk::Lfx> {
IMPLEMENT_CONST_MOCK0(IsAvailable);
IMPLEMENT_MOCK0(WaitAndBeginFrame);
Expand Down
3 changes: 2 additions & 1 deletion tests/nvapi/nvapi_sysinfo.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#include "nvapi_tests_private.h"
#include "resource_factory_util.h"
#include "nvapi_sysinfo_mocks.h"
#include "nvapi_vulkan_mocks.h"
#include "../shared/dxgi_mocks.h"
#include "../shared/vulkan_mocks.h"

using namespace trompeloeil;
using namespace Catch::Matchers;
Expand Down
3 changes: 2 additions & 1 deletion tests/nvapi/nvapi_sysinfo_hdr.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#include "nvapi_tests_private.h"
#include "resource_factory_util.h"
#include "nvapi_sysinfo_mocks.h"
#include "nvapi_vulkan_mocks.h"
#include "../shared/dxgi_mocks.h"
#include "../shared/vulkan_mocks.h"

using namespace trompeloeil;
using namespace Catch::Matchers;
Expand Down
79 changes: 0 additions & 79 deletions tests/nvapi/nvapi_sysinfo_mocks.h
Original file line number Diff line number Diff line change
@@ -1,87 +1,8 @@
#pragma once

#include "nvapi_tests_private.h"
#include "../../src/interfaces/dxvk_interfaces.h"
#include "../../src/nvapi/nvml.h"

class IDXGIDxvkFactoryMock : public IDXGIFactory1, public IDXGIVkInteropFactory1 {};

class DXGIDxvkFactoryMock final : public trompeloeil::mock_interface<IDXGIDxvkFactoryMock> {
MAKE_MOCK2(QueryInterface, HRESULT(REFIID, void**), override);
MAKE_MOCK0(AddRef, ULONG(), override);
MAKE_MOCK0(Release, ULONG(), override);
IMPLEMENT_MOCK3(GetPrivateData);
IMPLEMENT_MOCK3(SetPrivateData);
IMPLEMENT_MOCK2(SetPrivateDataInterface);
IMPLEMENT_MOCK2(GetParent);
IMPLEMENT_MOCK2(EnumAdapters);
IMPLEMENT_MOCK2(MakeWindowAssociation);
IMPLEMENT_MOCK1(GetWindowAssociation);
IMPLEMENT_MOCK3(CreateSwapChain);
IMPLEMENT_MOCK2(CreateSoftwareAdapter);
IMPLEMENT_MOCK2(EnumAdapters1);
IMPLEMENT_MOCK0(IsCurrent);
IMPLEMENT_MOCK2(GetVulkanInstance);
IMPLEMENT_MOCK2(GetGlobalHDRState);
IMPLEMENT_MOCK2(SetGlobalHDRState);
};

class IDXGIDxvkAdapter : public IDXGIAdapter3, public IDXGIVkInteropAdapter {};

class DXGIDxvkAdapterMock final : public trompeloeil::mock_interface<IDXGIDxvkAdapter> {
MAKE_MOCK2(QueryInterface, HRESULT(REFIID, void**), override);
MAKE_MOCK0(AddRef, ULONG(), override);
MAKE_MOCK0(Release, ULONG(), override);
IMPLEMENT_MOCK3(GetPrivateData);
IMPLEMENT_MOCK3(SetPrivateData);
IMPLEMENT_MOCK2(SetPrivateDataInterface);
IMPLEMENT_MOCK2(GetParent);
IMPLEMENT_MOCK2(EnumOutputs);
IMPLEMENT_MOCK1(GetDesc);
IMPLEMENT_MOCK2(CheckInterfaceSupport);
IMPLEMENT_MOCK1(GetDesc1);
IMPLEMENT_MOCK2(GetVulkanHandles);
IMPLEMENT_MOCK1(GetDesc2);
IMPLEMENT_MOCK2(RegisterHardwareContentProtectionTeardownStatusEvent);
IMPLEMENT_MOCK1(UnregisterHardwareContentProtectionTeardownStatus);
IMPLEMENT_MOCK3(QueryVideoMemoryInfo);
IMPLEMENT_MOCK3(SetVideoMemoryReservation);
IMPLEMENT_MOCK2(RegisterVideoMemoryBudgetChangeNotificationEvent);
IMPLEMENT_MOCK1(UnregisterVideoMemoryBudgetChangeNotification);
};

class DXGIOutput6Mock final : public trompeloeil::mock_interface<IDXGIOutput6> {
MAKE_MOCK2(QueryInterface, HRESULT(REFIID, void**), override);
MAKE_MOCK0(AddRef, ULONG(), override);
MAKE_MOCK0(Release, ULONG(), override);
IMPLEMENT_MOCK3(GetPrivateData);
IMPLEMENT_MOCK3(SetPrivateData);
IMPLEMENT_MOCK2(SetPrivateDataInterface);
IMPLEMENT_MOCK2(GetParent);
IMPLEMENT_MOCK1(GetDesc);
IMPLEMENT_MOCK4(GetDisplayModeList);
IMPLEMENT_MOCK3(FindClosestMatchingMode);
IMPLEMENT_MOCK0(WaitForVBlank);
IMPLEMENT_MOCK2(TakeOwnership);
IMPLEMENT_MOCK0(ReleaseOwnership);
IMPLEMENT_MOCK1(GetGammaControlCapabilities);
IMPLEMENT_MOCK1(SetGammaControl);
IMPLEMENT_MOCK1(GetGammaControl);
IMPLEMENT_MOCK1(SetDisplaySurface);
IMPLEMENT_MOCK1(GetDisplaySurfaceData);
IMPLEMENT_MOCK1(GetFrameStatistics);
IMPLEMENT_MOCK4(GetDisplayModeList1);
IMPLEMENT_MOCK3(FindClosestMatchingMode1);
IMPLEMENT_MOCK1(GetDisplaySurfaceData1);
IMPLEMENT_MOCK2(DuplicateOutput);
IMPLEMENT_MOCK0(SupportsOverlays);
IMPLEMENT_MOCK3(CheckOverlaySupport);
IMPLEMENT_MOCK4(CheckOverlayColorSpaceSupport);
IMPLEMENT_MOCK5(DuplicateOutput1);
IMPLEMENT_MOCK1(GetDesc1);
IMPLEMENT_MOCK1(CheckHardwareCompositionSupport);
};

class NvmlMock final : public trompeloeil::mock_interface<dxvk::Nvml> {
IMPLEMENT_CONST_MOCK0(IsAvailable);
IMPLEMENT_CONST_MOCK1(ErrorString);
Expand Down
3 changes: 2 additions & 1 deletion tests/nvapi/nvapi_sysinfo_nvml.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#include "nvapi_tests_private.h"
#include "resource_factory_util.h"
#include "nvapi_sysinfo_mocks.h"
#include "nvapi_vulkan_mocks.h"
#include "../shared/dxgi_mocks.h"
#include "../shared/vulkan_mocks.h"

using namespace trompeloeil;
using namespace Catch::Matchers;
Expand Down
3 changes: 2 additions & 1 deletion tests/nvapi/nvapi_sysinfo_topo.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#include "nvapi_tests_private.h"
#include "resource_factory_util.h"
#include "nvapi_sysinfo_mocks.h"
#include "nvapi_vulkan_mocks.h"
#include "../shared/dxgi_mocks.h"
#include "../shared/vulkan_mocks.h"

using namespace trompeloeil;
using namespace Catch::Matchers;
Expand Down
3 changes: 2 additions & 1 deletion tests/nvapi/nvapi_vulkan.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "nvapi_tests_private.h"
#include "resource_factory_util.h"
#include "nvapi_vulkan_mocks.h"
#include "../shared/vulkan_mocks.h"
#include "../shared/dxgi_mocks.h"

using namespace trompeloeil;

Expand Down
3 changes: 2 additions & 1 deletion tests/nvapi/resource_factory_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
#include "nvapi_tests_private.h"
#include "nvapi_d3d_mocks.h"
#include "nvapi_sysinfo_mocks.h"
#include "nvapi_vulkan_mocks.h"
#include "../shared/vulkan_mocks.h"
#include "../shared/dxgi_mocks.h"

DXGIDxvkAdapterMock* CreateDXGIDxvkAdapterMock();
DXGIOutput6Mock* CreateDXGIOutput6Mock();
Expand Down
8 changes: 8 additions & 0 deletions tests/nvofapi/main.cpp
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)
21 changes: 21 additions & 0 deletions tests/nvofapi/mock_factory.h
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 "../shared/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;
};
33 changes: 33 additions & 0 deletions tests/nvofapi/nvofapi_d3d12.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include "nvofapi_tests_private.h"
#include "mock_factory.h"
#include "../shared/vulkan_mocks.h"
#include "../shared/d3d12_mocks.h"

using namespace trompeloeil;

TEST_CASE("D3D12 methods succeed", "[.d3d12][!mayfail]") {
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") {
auto vk = std::make_unique<VkMock>();
auto vkDevice = std::make_unique<VkDeviceMock>();

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);
}
}
}
11 changes: 11 additions & 0 deletions tests/nvofapi/nvofapi_tests_private.h
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"
47 changes: 47 additions & 0 deletions tests/nvofapi/nvofapi_vk.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include "nvofapi_tests_private.h"
#include "mock_factory.h"
#include "../shared/vulkan_mocks.h"

using namespace trompeloeil;

TEST_CASE("Vk methods succeed", "[.vk][!mayfail]") {

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);
}
}
}
Loading

0 comments on commit a48bfe2

Please sign in to comment.