Wddm interface [1/n]: Wddm fixture cleanup

Change-Id: I9ef300ba6f0abe7659683ee96730621a9b57ea85
This commit is contained in:
Dunajski, Bartosz
2018-05-07 20:42:00 +02:00
committed by sys_ocldev
parent 2298b5db25
commit d33866b027
10 changed files with 364 additions and 548 deletions

View File

@@ -27,7 +27,6 @@ set(IGDRCL_SRCS_tests_fixtures
${CMAKE_CURRENT_SOURCE_DIR}/enqueue_handler_fixture.h ${CMAKE_CURRENT_SOURCE_DIR}/enqueue_handler_fixture.h
${CMAKE_CURRENT_SOURCE_DIR}/execution_model_fixture.h ${CMAKE_CURRENT_SOURCE_DIR}/execution_model_fixture.h
${CMAKE_CURRENT_SOURCE_DIR}/execution_model_kernel_fixture.h ${CMAKE_CURRENT_SOURCE_DIR}/execution_model_kernel_fixture.h
${CMAKE_CURRENT_SOURCE_DIR}/gmm_fixture.h
${CMAKE_CURRENT_SOURCE_DIR}/hello_world_fixture.h ${CMAKE_CURRENT_SOURCE_DIR}/hello_world_fixture.h
${CMAKE_CURRENT_SOURCE_DIR}/hello_world_kernel_fixture.h ${CMAKE_CURRENT_SOURCE_DIR}/hello_world_kernel_fixture.h
${CMAKE_CURRENT_SOURCE_DIR}/image_fixture.cpp ${CMAKE_CURRENT_SOURCE_DIR}/image_fixture.cpp

View File

@@ -1,76 +0,0 @@
/*
* Copyright (c) 2017, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include "gtest/gtest.h"
#include "runtime/helpers/aligned_memory.h"
#include "runtime/gmm_helper/gmm_helper.h"
#include "unit_tests/mocks/mock_gmm_resource_info.h"
using namespace OCLRT;
class GmmFixture {
public:
virtual void SetUp() {
}
virtual void TearDown() {
}
Gmm *getGmm(void *ptr, size_t size) {
size_t alignedSize = alignSizeWholePage(ptr, size);
void *alignedPtr = alignUp(ptr, 4096);
Gmm *gmm;
gmm = new Gmm;
EXPECT_NE(gmm, nullptr);
gmm->resourceParams.Type = RESOURCE_BUFFER;
gmm->resourceParams.Format = GMM_FORMAT_GENERIC_8BIT;
gmm->resourceParams.BaseWidth = (uint32_t)alignedSize;
gmm->resourceParams.BaseHeight = 1;
gmm->resourceParams.Depth = 1;
gmm->resourceParams.Usage = GMM_RESOURCE_USAGE_OCL_BUFFER;
gmm->resourceParams.pExistingSysMem = reinterpret_cast<GMM_VOIDPTR64>(alignedPtr);
gmm->resourceParams.ExistingSysMemSize = alignedSize;
gmm->resourceParams.BaseAlignment = 0;
gmm->resourceParams.Flags.Info.ExistingSysMem = 1;
gmm->resourceParams.Flags.Info.Linear = 1;
gmm->resourceParams.Flags.Info.Cacheable = 1;
gmm->resourceParams.Flags.Gpu.Texture = 1;
gmm->create();
EXPECT_NE(gmm->gmmResourceInfo.get(), nullptr);
return gmm;
}
void releaseGmm(Gmm *gmm) {
delete gmm;
}
};

View File

@@ -24,6 +24,7 @@ set(IGDRCL_SRCS_tests_os_interface_windows
${CMAKE_CURRENT_SOURCE_DIR}/device_command_stream_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/device_command_stream_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/device_os_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/device_os_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/driver_info_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/driver_info_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/gdi_dll_fixture.h
${CMAKE_CURRENT_SOURCE_DIR}/gdi_interface_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/gdi_interface_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/hw_info_config_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/hw_info_config_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/hw_info_config_tests.h ${CMAKE_CURRENT_SOURCE_DIR}/hw_info_config_tests.h

View File

@@ -54,16 +54,17 @@
using namespace OCLRT; using namespace OCLRT;
using namespace ::testing; using namespace ::testing;
class WddmCommandStreamFixture : public WddmFixtureMock { class WddmCommandStreamFixture {
public: public:
DeviceCommandStreamReceiver<DEFAULT_TEST_FAMILY_NAME> *csr = nullptr; DeviceCommandStreamReceiver<DEFAULT_TEST_FAMILY_NAME> *csr = nullptr;
MemoryManager *memManager = nullptr; MemoryManager *memManager = nullptr;
MockDevice *device = nullptr; MockDevice *device = nullptr;
MockWddmMemoryManager *mockWddmMM = nullptr; MockWddmMemoryManager *mockWddmMM = nullptr;
WddmMock *wddm = nullptr;
DebugManagerStateRestore stateRestore; DebugManagerStateRestore stateRestore;
void SetUp() { virtual void SetUp() {
WddmFixtureMock::SetUp(); wddm = static_cast<WddmMock *>(Wddm::createWddm());
ASSERT_NE(wddm, nullptr); ASSERT_NE(wddm, nullptr);
DebugManager.flags.CsrDispatchMode.set(static_cast<uint32_t>(DispatchMode::ImmediateDispatch)); DebugManager.flags.CsrDispatchMode.set(static_cast<uint32_t>(DispatchMode::ImmediateDispatch));
@@ -82,28 +83,28 @@ class WddmCommandStreamFixture : public WddmFixtureMock {
ASSERT_NE(nullptr, memManager); ASSERT_NE(nullptr, memManager);
} }
void TearDown() { virtual void TearDown() {
mockWddmMM = nullptr; mockWddmMM = nullptr;
delete csr->getTagAddress(); delete csr->getTagAddress();
delete csr; delete csr;
delete memManager; delete memManager;
delete device; delete device;
WddmFixtureMock::TearDown();
} }
}; };
class WddmCommandStreamWithMockGdiFixture : public WddmFixture { class WddmCommandStreamWithMockGdiFixture {
public: public:
DeviceCommandStreamReceiver<DEFAULT_TEST_FAMILY_NAME> *csr = nullptr; DeviceCommandStreamReceiver<DEFAULT_TEST_FAMILY_NAME> *csr = nullptr;
MemoryManager *memManager = nullptr; MemoryManager *memManager = nullptr;
MockDevice *device = nullptr; MockDevice *device = nullptr;
WddmMock *wddm = nullptr;
MockGdi gdi; MockGdi gdi;
DebugManagerStateRestore stateRestore; DebugManagerStateRestore stateRestore;
GraphicsAllocation *tagAllocation; GraphicsAllocation *tagAllocation;
GraphicsAllocation *preemptionAllocation = nullptr; GraphicsAllocation *preemptionAllocation = nullptr;
void SetUp() { virtual void SetUp() {
WddmFixture::SetUp(&gdi); wddm = static_cast<WddmMock *>(Wddm::createWddm(&gdi));
ASSERT_NE(wddm, nullptr); ASSERT_NE(wddm, nullptr);
DebugManager.flags.CsrDispatchMode.set(static_cast<uint32_t>(DispatchMode::ImmediateDispatch)); DebugManager.flags.CsrDispatchMode.set(static_cast<uint32_t>(DispatchMode::ImmediateDispatch));
csr = new WddmCommandStreamReceiver<DEFAULT_TEST_FAMILY_NAME>(*platformDevices[0], wddm); csr = new WddmCommandStreamReceiver<DEFAULT_TEST_FAMILY_NAME>(*platformDevices[0], wddm);
@@ -124,7 +125,7 @@ class WddmCommandStreamWithMockGdiFixture : public WddmFixture {
tagBuffer[0] = initialHardwareTag; tagBuffer[0] = initialHardwareTag;
} }
void TearDown() { virtual void TearDown() {
memManager->freeGraphicsMemory(tagAllocation); memManager->freeGraphicsMemory(tagAllocation);
if (preemptionAllocation) { if (preemptionAllocation) {
memManager->freeGraphicsMemory(preemptionAllocation); memManager->freeGraphicsMemory(preemptionAllocation);
@@ -134,7 +135,6 @@ class WddmCommandStreamWithMockGdiFixture : public WddmFixture {
delete memManager; delete memManager;
wddm = nullptr; wddm = nullptr;
delete device; delete device;
WddmFixture::TearDown();
} }
}; };
@@ -706,11 +706,11 @@ HWTEST_F(WddmCommandStreamMockGdiTest, givenRecordedCommandBufferWhenItIsSubmitt
//preemption allocation //preemption allocation
size_t csrSurfaceCount = (device->getPreemptionMode() == PreemptionMode::MidThread) ? 1 : 0; size_t csrSurfaceCount = (device->getPreemptionMode() == PreemptionMode::MidThread) ? 1 : 0;
EXPECT_EQ(1u, mockWddm->submitResult.called); EXPECT_EQ(1u, wddm->submitResult.called);
auto csrCommandStream = mockCsr->commandStream.getGraphicsAllocation(); auto csrCommandStream = mockCsr->commandStream.getGraphicsAllocation();
EXPECT_EQ(reinterpret_cast<uint64_t>(csrCommandStream->getUnderlyingBuffer()), mockWddm->submitResult.commandBufferSubmitted); EXPECT_EQ(reinterpret_cast<uint64_t>(csrCommandStream->getUnderlyingBuffer()), wddm->submitResult.commandBufferSubmitted);
EXPECT_TRUE(((COMMAND_BUFFER_HEADER *)mockWddm->submitResult.commandHeaderSubmitted)->RequiresCoherency); EXPECT_TRUE(((COMMAND_BUFFER_HEADER *)wddm->submitResult.commandHeaderSubmitted)->RequiresCoherency);
EXPECT_EQ(6u + csrSurfaceCount, mockWddm->makeResidentResult.handleCount); EXPECT_EQ(6u + csrSurfaceCount, wddm->makeResidentResult.handleCount);
std::vector<D3DKMT_HANDLE> expectedHandles; std::vector<D3DKMT_HANDLE> expectedHandles;
expectedHandles.push_back(((WddmAllocation *)tagAllocation)->handle); expectedHandles.push_back(((WddmAllocation *)tagAllocation)->handle);
@@ -720,8 +720,8 @@ HWTEST_F(WddmCommandStreamMockGdiTest, givenRecordedCommandBufferWhenItIsSubmitt
expectedHandles.push_back(((WddmAllocation *)sshAlloc)->handle); expectedHandles.push_back(((WddmAllocation *)sshAlloc)->handle);
expectedHandles.push_back(((WddmAllocation *)csrCommandStream)->handle); expectedHandles.push_back(((WddmAllocation *)csrCommandStream)->handle);
for (auto i = 0u; i < mockWddm->makeResidentResult.handleCount; i++) { for (auto i = 0u; i < wddm->makeResidentResult.handleCount; i++) {
auto handle = mockWddm->makeResidentResult.handlePack[i]; auto handle = wddm->makeResidentResult.handlePack[i];
auto found = false; auto found = false;
for (auto &expectedHandle : expectedHandles) { for (auto &expectedHandle : expectedHandles) {
if (expectedHandle == handle) { if (expectedHandle == handle) {

View File

@@ -0,0 +1,74 @@
/*
* Copyright (c) 2018, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include "runtime/helpers/hw_info.h"
#include "runtime/helpers/options.h"
#include "runtime/os_interface/os_library.h"
#include "unit_tests/mock_gdi/mock_gdi.h"
using namespace OCLRT;
OsLibrary *setAdapterInfo(const PLATFORM *platform, const GT_SYSTEM_INFO *gtSystemInfo);
struct GdiDllFixture {
virtual void SetUp() {
const HardwareInfo hwInfo = *platformDevices[0];
mockGdiDll.reset(setAdapterInfo(hwInfo.pPlatform, hwInfo.pSysInfo));
setSizesFcn = reinterpret_cast<decltype(&MockSetSizes)>(mockGdiDll->getProcAddress("MockSetSizes"));
getSizesFcn = reinterpret_cast<decltype(&GetMockSizes)>(mockGdiDll->getProcAddress("GetMockSizes"));
getMockLastDestroyedResHandleFcn =
reinterpret_cast<decltype(&GetMockLastDestroyedResHandle)>(mockGdiDll->getProcAddress("GetMockLastDestroyedResHandle"));
setMockLastDestroyedResHandleFcn =
reinterpret_cast<decltype(&SetMockLastDestroyedResHandle)>(mockGdiDll->getProcAddress("SetMockLastDestroyedResHandle"));
getMockCreateDeviceParamsFcn =
reinterpret_cast<decltype(&GetMockCreateDeviceParams)>(mockGdiDll->getProcAddress("GetMockCreateDeviceParams"));
setMockCreateDeviceParamsFcn =
reinterpret_cast<decltype(&SetMockCreateDeviceParams)>(mockGdiDll->getProcAddress("SetMockCreateDeviceParams"));
getMockAllocationFcn = reinterpret_cast<decltype(&getMockAllocation)>(mockGdiDll->getProcAddress("getMockAllocation"));
getAdapterInfoAddressFcn = reinterpret_cast<decltype(&getAdapterInfoAddress)>(mockGdiDll->getProcAddress("getAdapterInfoAddress"));
getLastCallMapGpuVaArgFcn = reinterpret_cast<decltype(&getLastCallMapGpuVaArg)>(mockGdiDll->getProcAddress("getLastCallMapGpuVaArg"));
setMapGpuVaFailConfigFcn = reinterpret_cast<decltype(&setMapGpuVaFailConfig)>(mockGdiDll->getProcAddress("setMapGpuVaFailConfig"));
setMapGpuVaFailConfigFcn(0, 0);
getCreateContextDataFcn = reinterpret_cast<decltype(&getCreateContextData)>(mockGdiDll->getProcAddress("getCreateContextData"));
setMockLastDestroyedResHandleFcn((D3DKMT_HANDLE)0);
}
virtual void TearDown() {
setMapGpuVaFailConfigFcn(0, 0);
}
std::unique_ptr<OsLibrary> mockGdiDll;
decltype(&MockSetSizes) setSizesFcn = nullptr;
decltype(&GetMockSizes) getSizesFcn = nullptr;
decltype(&GetMockLastDestroyedResHandle) getMockLastDestroyedResHandleFcn = nullptr;
decltype(&SetMockLastDestroyedResHandle) setMockLastDestroyedResHandleFcn = nullptr;
decltype(&GetMockCreateDeviceParams) getMockCreateDeviceParamsFcn = nullptr;
decltype(&SetMockCreateDeviceParams) setMockCreateDeviceParamsFcn = nullptr;
decltype(&getMockAllocation) getMockAllocationFcn = nullptr;
decltype(&getAdapterInfoAddress) getAdapterInfoAddressFcn = nullptr;
decltype(&getLastCallMapGpuVaArg) getLastCallMapGpuVaArgFcn = nullptr;
decltype(&setMapGpuVaFailConfig) setMapGpuVaFailConfigFcn = nullptr;
decltype(&getCreateContextData) getCreateContextDataFcn = nullptr;
};

View File

@@ -21,7 +21,6 @@
*/ */
#pragma once #pragma once
#if defined(_WIN32)
#include "runtime/helpers/aligned_memory.h" #include "runtime/helpers/aligned_memory.h"
#include "runtime/helpers/hw_info.h" #include "runtime/helpers/hw_info.h"
#include "runtime/helpers/options.h" #include "runtime/helpers/options.h"
@@ -30,10 +29,10 @@
#include "runtime/os_interface/windows/wddm.h" #include "runtime/os_interface/windows/wddm.h"
#include "runtime/os_interface/windows/wddm_allocation.h" #include "runtime/os_interface/windows/wddm_allocation.h"
#include "unit_tests/helpers/debug_manager_state_restore.h" #include "unit_tests/helpers/debug_manager_state_restore.h"
#include "unit_tests/fixtures/gmm_fixture.h"
#include "unit_tests/mock_gdi/mock_gdi.h" #include "unit_tests/mock_gdi/mock_gdi.h"
#include "mock_gmm_memory.h" #include "mock_gmm_memory.h"
#include "unit_tests//os_interface/windows/mock_gdi_interface.h" #include "unit_tests/os_interface/windows/mock_gdi_interface.h"
#include "unit_tests/os_interface/windows/gdi_dll_fixture.h"
#pragma warning(push) #pragma warning(push)
#pragma warning(disable : 4005) #pragma warning(disable : 4005)
#include <ntstatus.h> #include <ntstatus.h>
@@ -114,6 +113,10 @@ class WddmMock : public Wddm {
virtualAllocAddress = OCLRT::windowsMinAddress; virtualAllocAddress = OCLRT::windowsMinAddress;
} }
~WddmMock() {
EXPECT_EQ(0, reservedAddresses.size());
}
bool makeResident(D3DKMT_HANDLE *handles, uint32_t count, bool cantTrimFurther, uint64_t *numberOfBytesToTrim) override { bool makeResident(D3DKMT_HANDLE *handles, uint32_t count, bool cantTrimFurther, uint64_t *numberOfBytesToTrim) override {
makeResidentResult.called++; makeResidentResult.called++;
makeResidentResult.handleCount = count; makeResidentResult.handleCount = count;
@@ -396,113 +399,40 @@ class WddmMockReserveAddress : public WddmMock {
uint32_t returnNullIter; uint32_t returnNullIter;
}; };
class WddmFixture { struct WddmFixture {
protected:
Wddm *wddm;
WddmMock *mockWddm = nullptr;
OsLibrary *mockGdiDll;
decltype(&MockSetSizes) setSizesFunction;
decltype(&GetMockSizes) getSizesFunction;
decltype(&GetMockLastDestroyedResHandle) getMockLastDestroyedResHandleFcn;
decltype(&SetMockLastDestroyedResHandle) setMockLastDestroyedResHandleFcn;
decltype(&GetMockCreateDeviceParams) getMockCreateDeviceParamsFcn;
decltype(&SetMockCreateDeviceParams) setMockCreateDeviceParamsFcn;
decltype(&getMockAllocation) getMockAllocationFcn;
decltype(&getAdapterInfoAddress) getAdapterInfoAddressFcn;
decltype(&getLastCallMapGpuVaArg) getLastCallMapGpuVaArgFcn;
decltype(&setMapGpuVaFailConfig) setMapGpuVaFailConfigFcn = nullptr;
decltype(&getCreateContextData) getCreateContextDataFcn;
public:
virtual void SetUp() { virtual void SetUp() {
const HardwareInfo hwInfo = *platformDevices[0]; wddm.reset(static_cast<WddmMock *>(Wddm::createWddm(&gdi)));
mockGdiDll = setAdapterInfo(hwInfo.pPlatform, hwInfo.pSysInfo);
setSizesFunction = reinterpret_cast<decltype(&MockSetSizes)>(mockGdiDll->getProcAddress("MockSetSizes"));
getSizesFunction = reinterpret_cast<decltype(&GetMockSizes)>(mockGdiDll->getProcAddress("GetMockSizes"));
getMockLastDestroyedResHandleFcn =
reinterpret_cast<decltype(&GetMockLastDestroyedResHandle)>(mockGdiDll->getProcAddress("GetMockLastDestroyedResHandle"));
setMockLastDestroyedResHandleFcn =
reinterpret_cast<decltype(&SetMockLastDestroyedResHandle)>(mockGdiDll->getProcAddress("SetMockLastDestroyedResHandle"));
getMockCreateDeviceParamsFcn =
reinterpret_cast<decltype(&GetMockCreateDeviceParams)>(mockGdiDll->getProcAddress("GetMockCreateDeviceParams"));
setMockCreateDeviceParamsFcn =
reinterpret_cast<decltype(&SetMockCreateDeviceParams)>(mockGdiDll->getProcAddress("SetMockCreateDeviceParams"));
getMockAllocationFcn = reinterpret_cast<decltype(&getMockAllocation)>(mockGdiDll->getProcAddress("getMockAllocation"));
getAdapterInfoAddressFcn = reinterpret_cast<decltype(&getAdapterInfoAddress)>(mockGdiDll->getProcAddress("getAdapterInfoAddress"));
getLastCallMapGpuVaArgFcn = reinterpret_cast<decltype(&getLastCallMapGpuVaArg)>(mockGdiDll->getProcAddress("getLastCallMapGpuVaArg"));
setMapGpuVaFailConfigFcn = reinterpret_cast<decltype(&setMapGpuVaFailConfig)>(mockGdiDll->getProcAddress("setMapGpuVaFailConfig"));
setMapGpuVaFailConfigFcn(0, 0);
getCreateContextDataFcn = reinterpret_cast<decltype(&getCreateContextData)>(mockGdiDll->getProcAddress("getCreateContextData"));
wddm = Wddm::createWddm();
mockWddm = static_cast<WddmMock *>(wddm);
wddm->registryReader.reset(new RegistryReaderMock());
setMockLastDestroyedResHandleFcn((D3DKMT_HANDLE)0);
} }
virtual void SetUp(Gdi *gdi) { virtual void TearDown(){};
mockGdiDll = nullptr;
wddm = Wddm::createWddm(gdi);
mockWddm = static_cast<WddmMock *>(wddm);
wddm->registryReader.reset(new RegistryReaderMock());
}
virtual void TearDown() { std::unique_ptr<WddmMock> wddm;
if (wddm != nullptr) { MockGdi gdi;
EXPECT_EQ(0, mockWddm->reservedAddresses.size());
delete wddm;
}
if (mockGdiDll != nullptr) {
if (setMapGpuVaFailConfigFcn != nullptr) {
setMapGpuVaFailConfigFcn(0, 0);
}
delete mockGdiDll;
}
}
}; };
class WddmFixtureMock { struct WddmFixtureWithMockGdiDll : public GdiDllFixture {
protected: void SetUp() override {
WddmMock *wddm; GdiDllFixture::SetUp();
OsLibrary *mockGdiDll; wddm.reset(static_cast<WddmMock *>(Wddm::createWddm()));
public:
virtual void SetUp() {
const HardwareInfo hwInfo = *platformDevices[0];
mockGdiDll = setAdapterInfo(hwInfo.pPlatform, hwInfo.pSysInfo);
wddm = new WddmMock();
} }
virtual void TearDown() { void TearDown() override {
delete mockGdiDll; GdiDllFixture::TearDown();
} }
std::unique_ptr<WddmMock> wddm;
}; };
class WddmGmmFixture : public GmmFixture, public WddmFixture { struct WddmInstrumentationGmmFixture {
public:
virtual void SetUp() {
GmmFixture::SetUp();
WddmFixture::SetUp();
}
virtual void TearDown() {
WddmFixture::TearDown();
GmmFixture::TearDown();
}
};
class WddmInstrumentationGmmFixture : public WddmGmmFixture {
public:
virtual void SetUp() { virtual void SetUp() {
MockGmmMemory::MockGmmMemoryFlag = MockGmmMemory::MockType::MockInstrumentation; MockGmmMemory::MockGmmMemoryFlag = MockGmmMemory::MockType::MockInstrumentation;
WddmGmmFixture::SetUp(); wddm.reset(static_cast<WddmMock *>(Wddm::createWddm()));
gmmMem = static_cast<GmockGmmMemory *>(wddm->getGmmMemory());
} }
virtual void TearDown() { virtual void TearDown() {
WddmGmmFixture::TearDown();
MockGmmMemory::MockGmmMemoryFlag = MockGmmMemory::MockType::MockDummy; MockGmmMemory::MockGmmMemoryFlag = MockGmmMemory::MockType::MockDummy;
} }
std::unique_ptr<WddmMock> wddm;
GmockGmmMemory *gmmMem = nullptr;
}; };
typedef ::testing::Test WddmDummyFixture;
#endif

View File

@@ -33,7 +33,8 @@ using namespace OCLRT;
using namespace ::testing; using namespace ::testing;
void WddmMemoryManagerFixture::SetUp() { void WddmMemoryManagerFixture::SetUp() {
WddmFixture::SetUp(); GdiDllFixture::SetUp();
wddm = static_cast<WddmMock *>(Wddm::createWddm());
ASSERT_NE(nullptr, wddm); ASSERT_NE(nullptr, wddm);
if (platformDevices[0]->capabilityTable.ftrCompression) { if (platformDevices[0]->capabilityTable.ftrCompression) {
GMM_DEVICE_CALLBACKS dummyDeviceCallbacks = {}; GMM_DEVICE_CALLBACKS dummyDeviceCallbacks = {};
@@ -110,7 +111,7 @@ HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenCreateFromSharedHandle
void *pSysMem = reinterpret_cast<void *>(0x1000); void *pSysMem = reinterpret_cast<void *>(0x1000);
std::unique_ptr<Gmm> gmm(Gmm::create(pSysMem, 4096u, false)); std::unique_ptr<Gmm> gmm(Gmm::create(pSysMem, 4096u, false));
auto status = setSizesFunction(gmm->gmmResourceInfo.get(), 1u, 1024u, 1u); auto status = setSizesFcn(gmm->gmmResourceInfo.get(), 1u, 1024u, 1u);
auto *gpuAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, false); auto *gpuAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, false);
auto wddmAlloc = static_cast<WddmAllocation *>(gpuAllocation); auto wddmAlloc = static_cast<WddmAllocation *>(gpuAllocation);
@@ -127,7 +128,7 @@ HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenCreateFromNTHandleIsCa
void *pSysMem = reinterpret_cast<void *>(0x1000); void *pSysMem = reinterpret_cast<void *>(0x1000);
std::unique_ptr<Gmm> gmm(Gmm::create(pSysMem, 4096u, false)); std::unique_ptr<Gmm> gmm(Gmm::create(pSysMem, 4096u, false));
auto status = setSizesFunction(gmm->gmmResourceInfo.get(), 1u, 1024u, 1u); auto status = setSizesFcn(gmm->gmmResourceInfo.get(), 1u, 1024u, 1u);
auto *gpuAllocation = memoryManager->createGraphicsAllocationFromNTHandle(reinterpret_cast<void *>(1)); auto *gpuAllocation = memoryManager->createGraphicsAllocationFromNTHandle(reinterpret_cast<void *>(1));
auto wddmAlloc = static_cast<WddmAllocation *>(gpuAllocation); auto wddmAlloc = static_cast<WddmAllocation *>(gpuAllocation);
@@ -144,12 +145,12 @@ HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenLockUnlockIsCalledThen
auto ptr = memoryManager->lockResource(alloc); auto ptr = memoryManager->lockResource(alloc);
EXPECT_NE(nullptr, ptr); EXPECT_NE(nullptr, ptr);
EXPECT_EQ(1u, mockWddm->lockResult.called); EXPECT_EQ(1u, wddm->lockResult.called);
EXPECT_TRUE(mockWddm->lockResult.success); EXPECT_TRUE(wddm->lockResult.success);
memoryManager->unlockResource(alloc); memoryManager->unlockResource(alloc);
EXPECT_EQ(1u, mockWddm->unlockResult.called); EXPECT_EQ(1u, wddm->unlockResult.called);
EXPECT_TRUE(mockWddm->unlockResult.success); EXPECT_TRUE(wddm->unlockResult.success);
memoryManager->freeGraphicsMemory(alloc); memoryManager->freeGraphicsMemory(alloc);
} }
@@ -161,7 +162,7 @@ HWTEST_F(WddmMemoryManagerTest, createAllocationFromSharedHandleReturns32BitAllo
void *pSysMem = reinterpret_cast<void *>(0x1000); void *pSysMem = reinterpret_cast<void *>(0x1000);
std::unique_ptr<Gmm> gmm(Gmm::create(pSysMem, 4096u, false)); std::unique_ptr<Gmm> gmm(Gmm::create(pSysMem, 4096u, false));
auto status = setSizesFunction(gmm->gmmResourceInfo.get(), 1u, 1024u, 1u); auto status = setSizesFcn(gmm->gmmResourceInfo.get(), 1u, 1024u, 1u);
memoryManager->setForce32BitAllocations(true); memoryManager->setForce32BitAllocations(true);
@@ -184,7 +185,7 @@ HWTEST_F(WddmMemoryManagerTest, createAllocationFromSharedHandleDoesNotReturn32B
void *pSysMem = reinterpret_cast<void *>(0x1000); void *pSysMem = reinterpret_cast<void *>(0x1000);
std::unique_ptr<Gmm> gmm(Gmm::create(pSysMem, 4096u, false)); std::unique_ptr<Gmm> gmm(Gmm::create(pSysMem, 4096u, false));
auto status = setSizesFunction(gmm->gmmResourceInfo.get(), 1u, 1024u, 1u); auto status = setSizesFcn(gmm->gmmResourceInfo.get(), 1u, 1024u, 1u);
memoryManager->setForce32BitAllocations(true); memoryManager->setForce32BitAllocations(true);
@@ -207,7 +208,7 @@ HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenFreeAllocFromSharedHan
void *pSysMem = reinterpret_cast<void *>(0x1000); void *pSysMem = reinterpret_cast<void *>(0x1000);
std::unique_ptr<Gmm> gmm(Gmm::create(pSysMem, 4096u, false)); std::unique_ptr<Gmm> gmm(Gmm::create(pSysMem, 4096u, false));
auto status = setSizesFunction(gmm->gmmResourceInfo.get(), 1u, 1024u, 1u); auto status = setSizesFcn(gmm->gmmResourceInfo.get(), 1u, 1024u, 1u);
auto gpuAllocation = (WddmAllocation *)memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, false); auto gpuAllocation = (WddmAllocation *)memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, false);
EXPECT_NE(nullptr, gpuAllocation); EXPECT_NE(nullptr, gpuAllocation);
@@ -229,7 +230,7 @@ HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerSizeZeroWhenCreateFromShar
void *pSysMem = reinterpret_cast<void *>(0x1000); void *pSysMem = reinterpret_cast<void *>(0x1000);
std::unique_ptr<Gmm> gmm(Gmm::create(pSysMem, size, false)); std::unique_ptr<Gmm> gmm(Gmm::create(pSysMem, size, false));
auto status = setSizesFunction(gmm->gmmResourceInfo.get(), 1u, 1024u, 1u); auto status = setSizesFcn(gmm->gmmResourceInfo.get(), 1u, 1024u, 1u);
auto *gpuAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, false); auto *gpuAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, false);
ASSERT_NE(nullptr, gpuAllocation); ASSERT_NE(nullptr, gpuAllocation);
@@ -244,9 +245,9 @@ HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenCreateFromSharedHandle
void *pSysMem = reinterpret_cast<void *>(0x1000); void *pSysMem = reinterpret_cast<void *>(0x1000);
std::unique_ptr<Gmm> gmm(Gmm::create(pSysMem, size, false)); std::unique_ptr<Gmm> gmm(Gmm::create(pSysMem, size, false));
auto status = setSizesFunction(gmm->gmmResourceInfo.get(), 1u, 1024u, 1u); auto status = setSizesFcn(gmm->gmmResourceInfo.get(), 1u, 1024u, 1u);
mockWddm->failOpenSharedHandle = true; wddm->failOpenSharedHandle = true;
auto *gpuAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, false); auto *gpuAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, false);
EXPECT_EQ(nullptr, gpuAllocation); EXPECT_EQ(nullptr, gpuAllocation);
@@ -255,7 +256,7 @@ HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenCreateFromSharedHandle
HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenTiledImageWithMipCountZeroIsBeingCreatedThenallocateGraphicsMemoryForImageIsUsed) { HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenTiledImageWithMipCountZeroIsBeingCreatedThenallocateGraphicsMemoryForImageIsUsed) {
SetUpMm<FamilyType>(); SetUpMm<FamilyType>();
MockContext context; MockContext context;
context.setMemoryManager(memoryManager); context.setMemoryManager(memoryManager.get());
cl_image_format imageFormat; cl_image_format imageFormat;
imageFormat.image_channel_data_type = CL_UNORM_INT8; imageFormat.image_channel_data_type = CL_UNORM_INT8;
@@ -283,7 +284,7 @@ HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenTiledImageWithMipCount
HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenTiledImageWithMipCountNonZeroIsBeingCreatedThenallocateGraphicsMemoryForImageIsUsed) { HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenTiledImageWithMipCountNonZeroIsBeingCreatedThenallocateGraphicsMemoryForImageIsUsed) {
SetUpMm<FamilyType>(); SetUpMm<FamilyType>();
MockContext context; MockContext context;
context.setMemoryManager(memoryManager); context.setMemoryManager(memoryManager.get());
cl_image_format imageFormat; cl_image_format imageFormat;
imageFormat.image_channel_data_type = CL_UNORM_INT8; imageFormat.image_channel_data_type = CL_UNORM_INT8;
@@ -313,7 +314,7 @@ HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenTiledImageWithMipCount
HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenTiledImageIsBeingCreatedFromHostPtrThenallocateGraphicsMemoryForImageIsUsed) { HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenTiledImageIsBeingCreatedFromHostPtrThenallocateGraphicsMemoryForImageIsUsed) {
SetUpMm<FamilyType>(); SetUpMm<FamilyType>();
MockContext context; MockContext context;
context.setMemoryManager(memoryManager); context.setMemoryManager(memoryManager.get());
cl_image_format imageFormat; cl_image_format imageFormat;
imageFormat.image_channel_data_type = CL_UNORM_INT8; imageFormat.image_channel_data_type = CL_UNORM_INT8;
@@ -343,7 +344,7 @@ HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenTiledImageIsBeingCreat
HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenNonTiledImgWithMipCountZeroisBeingCreatedThenAllocateGraphicsMemoryIsUsed) { HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenNonTiledImgWithMipCountZeroisBeingCreatedThenAllocateGraphicsMemoryIsUsed) {
SetUpMm<FamilyType>(); SetUpMm<FamilyType>();
MockContext context; MockContext context;
context.setMemoryManager(memoryManager); context.setMemoryManager(memoryManager.get());
cl_image_format imageFormat; cl_image_format imageFormat;
imageFormat.image_channel_data_type = CL_UNORM_INT8; imageFormat.image_channel_data_type = CL_UNORM_INT8;
@@ -372,7 +373,7 @@ HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenNonTiledImgWithMipCoun
HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenNonTiledImgWithMipCountNonZeroisBeingCreatedThenAllocateGraphicsMemoryForImageIsUsed) { HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenNonTiledImgWithMipCountNonZeroisBeingCreatedThenAllocateGraphicsMemoryForImageIsUsed) {
SetUpMm<FamilyType>(); SetUpMm<FamilyType>();
MockContext context; MockContext context;
context.setMemoryManager(memoryManager); context.setMemoryManager(memoryManager.get());
cl_image_format imageFormat; cl_image_format imageFormat;
imageFormat.image_channel_data_type = CL_UNORM_INT8; imageFormat.image_channel_data_type = CL_UNORM_INT8;
@@ -591,7 +592,7 @@ HWTEST_F(WddmMemoryManagerTest, GivenThreeOsHandlesWhenAskedForDestroyAllocation
auto destroyWithResourceHandleCalled = 0u; auto destroyWithResourceHandleCalled = 0u;
D3DKMT_DESTROYALLOCATION2 *ptrToDestroyAlloc2 = nullptr; D3DKMT_DESTROYALLOCATION2 *ptrToDestroyAlloc2 = nullptr;
getSizesFunction(destroyWithResourceHandleCalled, ptrToDestroyAlloc2); getSizesFcn(destroyWithResourceHandleCalled, ptrToDestroyAlloc2);
EXPECT_EQ(0u, ptrToDestroyAlloc2->Flags.SynchronousDestroy); EXPECT_EQ(0u, ptrToDestroyAlloc2->Flags.SynchronousDestroy);
EXPECT_EQ(1u, ptrToDestroyAlloc2->Flags.AssumeNotInUse); EXPECT_EQ(1u, ptrToDestroyAlloc2->Flags.AssumeNotInUse);
@@ -616,13 +617,12 @@ HWTEST_F(WddmMemoryManagerTest, givenDefaultWddmMemoryManagerWhenAskedForAligned
HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenCpuMemNotMeetRestrictionsThenReserveMemRangeForMap) { HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenCpuMemNotMeetRestrictionsThenReserveMemRangeForMap) {
SetUpMm<FamilyType>(); SetUpMm<FamilyType>();
WddmMock *mockWddm = static_cast<WddmMock *>(wddm);
void *cpuPtr = reinterpret_cast<void *>(memoryManager->getAlignedMallocRestrictions()->minAddress - 0x1000); void *cpuPtr = reinterpret_cast<void *>(memoryManager->getAlignedMallocRestrictions()->minAddress - 0x1000);
size_t size = 0x1000; size_t size = 0x1000;
WddmAllocation *allocation = static_cast<WddmAllocation *>(memoryManager->allocateGraphicsMemory(size, cpuPtr)); WddmAllocation *allocation = static_cast<WddmAllocation *>(memoryManager->allocateGraphicsMemory(size, cpuPtr));
void *expectReserve = reinterpret_cast<void *>(mockWddm->virtualAllocAddress); void *expectReserve = reinterpret_cast<void *>(wddm->virtualAllocAddress);
ASSERT_NE(nullptr, allocation); ASSERT_NE(nullptr, allocation);
EXPECT_EQ(expectReserve, allocation->getReservedAddress()); EXPECT_EQ(expectReserve, allocation->getReservedAddress());
@@ -636,17 +636,12 @@ HWTEST_F(WddmMemoryManagerTest, givenManagerWithDisabledDeferredDeleterWhenMapGp
size_t size = 0x1000; size_t size = 0x1000;
std::unique_ptr<Gmm> gmm(Gmm::create(ptr, size, false)); std::unique_ptr<Gmm> gmm(Gmm::create(ptr, size, false));
WddmMock *mockedWddm = new WddmMock; memoryManager->setDeferredDeleter(nullptr);
EXPECT_TRUE(mockedWddm->init<FamilyType>());
MockWddmMemoryManager mockMemoryManager(mockedWddm);
mockMemoryManager.setDeferredDeleter(nullptr);
setMapGpuVaFailConfigFcn(0, 1); setMapGpuVaFailConfigFcn(0, 1);
WddmAllocation allocation(ptr, size, nullptr); WddmAllocation allocation(ptr, size, nullptr);
allocation.gmm = gmm.get(); allocation.gmm = gmm.get();
bool ret = mockMemoryManager.createWddmAllocation(&allocation, MemoryType::EXTERNAL_ALLOCATION); bool ret = memoryManager->createWddmAllocation(&allocation, MemoryType::EXTERNAL_ALLOCATION);
EXPECT_FALSE(ret); EXPECT_FALSE(ret);
} }
@@ -656,18 +651,14 @@ HWTEST_F(WddmMemoryManagerTest, givenManagerWithEnabledDeferredDeleterWhenFirstM
size_t size = 0x1000; size_t size = 0x1000;
std::unique_ptr<Gmm> gmm(Gmm::create(ptr, size, false)); std::unique_ptr<Gmm> gmm(Gmm::create(ptr, size, false));
WddmMock *mockedWddm = new WddmMock;
EXPECT_TRUE(mockedWddm->init<FamilyType>());
MockDeferredDeleter *deleter = new MockDeferredDeleter; MockDeferredDeleter *deleter = new MockDeferredDeleter;
MockWddmMemoryManager mockMemoryManager(mockedWddm); memoryManager->setDeferredDeleter(deleter);
mockMemoryManager.setDeferredDeleter(deleter);
setMapGpuVaFailConfigFcn(0, 1); setMapGpuVaFailConfigFcn(0, 1);
WddmAllocation allocation(ptr, size, nullptr); WddmAllocation allocation(ptr, size, nullptr);
allocation.gmm = gmm.get(); allocation.gmm = gmm.get();
bool ret = mockMemoryManager.createWddmAllocation(&allocation, MemoryType::EXTERNAL_ALLOCATION); bool ret = memoryManager->createWddmAllocation(&allocation, MemoryType::EXTERNAL_ALLOCATION);
EXPECT_TRUE(ret); EXPECT_TRUE(ret);
EXPECT_EQ(reinterpret_cast<uint64_t>(ptr), allocation.getGpuAddress()); EXPECT_EQ(reinterpret_cast<uint64_t>(ptr), allocation.getGpuAddress());
} }
@@ -678,18 +669,14 @@ HWTEST_F(WddmMemoryManagerTest, givenManagerWithEnabledDeferredDeleterWhenFirstA
size_t size = 0x1000; size_t size = 0x1000;
std::unique_ptr<Gmm> gmm(Gmm::create(ptr, size, false)); std::unique_ptr<Gmm> gmm(Gmm::create(ptr, size, false));
WddmMock *mockedWddm = new WddmMock;
EXPECT_TRUE(mockedWddm->init<FamilyType>());
MockDeferredDeleter *deleter = new MockDeferredDeleter; MockDeferredDeleter *deleter = new MockDeferredDeleter;
MockWddmMemoryManager mockMemoryManager(mockedWddm); memoryManager->setDeferredDeleter(deleter);
mockMemoryManager.setDeferredDeleter(deleter);
setMapGpuVaFailConfigFcn(0, 2); setMapGpuVaFailConfigFcn(0, 2);
WddmAllocation allocation(ptr, size, nullptr); WddmAllocation allocation(ptr, size, nullptr);
allocation.gmm = gmm.get(); allocation.gmm = gmm.get();
bool ret = mockMemoryManager.createWddmAllocation(&allocation, MemoryType::EXTERNAL_ALLOCATION); bool ret = memoryManager->createWddmAllocation(&allocation, MemoryType::EXTERNAL_ALLOCATION);
EXPECT_FALSE(ret); EXPECT_FALSE(ret);
} }
@@ -955,9 +942,8 @@ HWTEST_F(WddmMemoryManagerResidencyTest, makeResidentResidencyAllocationsUpdates
HWTEST_F(WddmMemoryManagerResidencyTest, makeResidentResidencyAllocationsMarksTripleAllocationsResident) { HWTEST_F(WddmMemoryManagerResidencyTest, makeResidentResidencyAllocationsMarksTripleAllocationsResident) {
SetUpMm<FamilyType>(); SetUpMm<FamilyType>();
WddmMock *mockWddm = static_cast<WddmMock *>(wddm);
WddmAllocation allocation1, allocation2; WddmAllocation allocation1, allocation2;
void *ptr = reinterpret_cast<void *>(mockWddm->virtualAllocAddress + 0x1500); void *ptr = reinterpret_cast<void *>(wddm->virtualAllocAddress + 0x1500);
WddmAllocation *allocationTriple = (WddmAllocation *)memoryManager->allocateGraphicsMemory(8196, ptr); WddmAllocation *allocationTriple = (WddmAllocation *)memoryManager->allocateGraphicsMemory(8196, ptr);
@@ -1000,7 +986,7 @@ HWTEST_F(WddmMemoryManagerResidencyTest, makeResidentResidencyAllocationsSetsLas
HWTEST_F(WddmMemoryManagerResidencyTest, trimCallbackIsRegisteredInWddmMemoryManagerCtor) { HWTEST_F(WddmMemoryManagerResidencyTest, trimCallbackIsRegisteredInWddmMemoryManagerCtor) {
SetUpMm<FamilyType>(); SetUpMm<FamilyType>();
EXPECT_EQ((PFND3DKMT_TRIMNOTIFICATIONCALLBACK)memoryManager->trimCallback, gdi.getRegisterTrimNotificationArg().Callback); EXPECT_EQ((PFND3DKMT_TRIMNOTIFICATIONCALLBACK)memoryManager->trimCallback, gdi.getRegisterTrimNotificationArg().Callback);
EXPECT_EQ(reinterpret_cast<void *>(memoryManager), gdi.getRegisterTrimNotificationArg().Context); EXPECT_EQ(reinterpret_cast<void *>(memoryManager.get()), gdi.getRegisterTrimNotificationArg().Context);
EXPECT_EQ(wddm->getDevice(), gdi.getRegisterTrimNotificationArg().hDevice); EXPECT_EQ(wddm->getDevice(), gdi.getRegisterTrimNotificationArg().hDevice);
} }
@@ -1020,7 +1006,7 @@ HWTEST_F(WddmMemoryManagerResidencyTest, givenNotUsedAllocationsFromPreviousPeri
// Set current fence value to greater value // Set current fence value to greater value
wddm->getMonitoredFence().currentFenceValue = 20; wddm->getMonitoredFence().currentFenceValue = 20;
mockWddm->makeNonResidentResult.called = 0; wddm->makeNonResidentResult.called = 0;
memoryManager->trimCandidateList.resize(0); memoryManager->trimCandidateList.resize(0);
@@ -1030,7 +1016,7 @@ HWTEST_F(WddmMemoryManagerResidencyTest, givenNotUsedAllocationsFromPreviousPeri
memoryManager->trimResidency(trimNotification.Flags, trimNotification.NumBytesToTrim); memoryManager->trimResidency(trimNotification.Flags, trimNotification.NumBytesToTrim);
// 2 allocations evicted // 2 allocations evicted
EXPECT_EQ(2u, mockWddm->makeNonResidentResult.called); EXPECT_EQ(2u, wddm->makeNonResidentResult.called);
// removed from trim candidate list // removed from trim candidate list
EXPECT_EQ(0u, memoryManager->trimCandidateList.size()); EXPECT_EQ(0u, memoryManager->trimCandidateList.size());
// marked nonresident // marked nonresident
@@ -1056,7 +1042,7 @@ HWTEST_F(WddmMemoryManagerResidencyTest, givenOneUsedAllocationFromPreviousPerio
// Set current fence value to greater value // Set current fence value to greater value
wddm->getMonitoredFence().currentFenceValue = 20; wddm->getMonitoredFence().currentFenceValue = 20;
mockWddm->makeNonResidentResult.called = 0; wddm->makeNonResidentResult.called = 0;
memoryManager->trimCandidateList.resize(0); memoryManager->trimCandidateList.resize(0);
@@ -1066,7 +1052,7 @@ HWTEST_F(WddmMemoryManagerResidencyTest, givenOneUsedAllocationFromPreviousPerio
memoryManager->trimResidency(trimNotification.Flags, trimNotification.NumBytesToTrim); memoryManager->trimResidency(trimNotification.Flags, trimNotification.NumBytesToTrim);
// 1 allocation evicted // 1 allocation evicted
EXPECT_EQ(1u, mockWddm->makeNonResidentResult.called); EXPECT_EQ(1u, wddm->makeNonResidentResult.called);
// removed from trim candidate list // removed from trim candidate list
EXPECT_EQ(trimListUnusedPosition, allocation1.getTrimCandidateListPosition()); EXPECT_EQ(trimListUnusedPosition, allocation1.getTrimCandidateListPosition());
@@ -1078,11 +1064,10 @@ HWTEST_F(WddmMemoryManagerResidencyTest, givenOneUsedAllocationFromPreviousPerio
HWTEST_F(WddmMemoryManagerResidencyTest, givenTripleAllocationWithUsedAndUnusedFragmentsSincePreviousTrimWhenTrimResidencyPeriodicTrimIsCalledThenProperFragmentsAreEvictedAndMarked) { HWTEST_F(WddmMemoryManagerResidencyTest, givenTripleAllocationWithUsedAndUnusedFragmentsSincePreviousTrimWhenTrimResidencyPeriodicTrimIsCalledThenProperFragmentsAreEvictedAndMarked) {
SetUpMm<FamilyType>(); SetUpMm<FamilyType>();
WddmMock *mockWddm = static_cast<WddmMock *>(wddm);
D3DKMT_TRIMNOTIFICATION trimNotification = {0}; D3DKMT_TRIMNOTIFICATION trimNotification = {0};
trimNotification.Flags.PeriodicTrim = 1; trimNotification.Flags.PeriodicTrim = 1;
trimNotification.NumBytesToTrim = 0; trimNotification.NumBytesToTrim = 0;
void *ptr = reinterpret_cast<void *>(mockWddm->virtualAllocAddress + 0x1500); void *ptr = reinterpret_cast<void *>(wddm->virtualAllocAddress + 0x1500);
// 3-fragment Allocation // 3-fragment Allocation
WddmAllocation *allocationTriple = (WddmAllocation *)memoryManager->allocateGraphicsMemory(8196, ptr); WddmAllocation *allocationTriple = (WddmAllocation *)memoryManager->allocateGraphicsMemory(8196, ptr);
// whole allocation unused since previous trim // whole allocation unused since previous trim
@@ -1103,7 +1088,7 @@ HWTEST_F(WddmMemoryManagerResidencyTest, givenTripleAllocationWithUsedAndUnusedF
// Set current fence value to greater value // Set current fence value to greater value
wddm->getMonitoredFence().currentFenceValue = 20; wddm->getMonitoredFence().currentFenceValue = 20;
mockWddm->makeNonResidentResult.called = 0; wddm->makeNonResidentResult.called = 0;
memoryManager->trimCandidateList.resize(0); memoryManager->trimCandidateList.resize(0);
@@ -1112,7 +1097,7 @@ HWTEST_F(WddmMemoryManagerResidencyTest, givenTripleAllocationWithUsedAndUnusedF
memoryManager->trimResidency(trimNotification.Flags, trimNotification.NumBytesToTrim); memoryManager->trimResidency(trimNotification.Flags, trimNotification.NumBytesToTrim);
// 2 fragments evicted with one call // 2 fragments evicted with one call
EXPECT_EQ(1u, mockWddm->makeNonResidentResult.called); EXPECT_EQ(1u, wddm->makeNonResidentResult.called);
// marked nonresident // marked nonresident
EXPECT_FALSE(allocationTriple->fragmentsStorage.fragmentStorageData[0].residency->resident); EXPECT_FALSE(allocationTriple->fragmentsStorage.fragmentStorageData[0].residency->resident);
EXPECT_FALSE(allocationTriple->fragmentsStorage.fragmentStorageData[2].residency->resident); EXPECT_FALSE(allocationTriple->fragmentsStorage.fragmentStorageData[2].residency->resident);
@@ -1179,7 +1164,7 @@ HWTEST_F(WddmMemoryManagerResidencyTest, trimToBudgetAllDoneAllocations) {
wddm->getMonitoredFence().lastSubmittedFence = 1; wddm->getMonitoredFence().lastSubmittedFence = 1;
wddm->getMonitoredFence().currentFenceValue = 1; wddm->getMonitoredFence().currentFenceValue = 1;
mockWddm->makeNonResidentResult.called = 0; wddm->makeNonResidentResult.called = 0;
memoryManager->trimCandidateList.resize(0); memoryManager->trimCandidateList.resize(0);
@@ -1189,7 +1174,7 @@ HWTEST_F(WddmMemoryManagerResidencyTest, trimToBudgetAllDoneAllocations) {
memoryManager->trimResidencyToBudget(3 * 4096); memoryManager->trimResidencyToBudget(3 * 4096);
EXPECT_EQ(2u, mockWddm->makeNonResidentResult.called); EXPECT_EQ(2u, wddm->makeNonResidentResult.called);
EXPECT_EQ(1u, memoryManager->trimCandidatesCount); EXPECT_EQ(1u, memoryManager->trimCandidatesCount);
memoryManager->compactTrimCandidateList(); memoryManager->compactTrimCandidateList();
@@ -1211,14 +1196,14 @@ HWTEST_F(WddmMemoryManagerResidencyTest, trimToBudgetReturnsFalseWhenNumBytesToT
*wddm->getMonitoredFence().cpuAddress = 1; *wddm->getMonitoredFence().cpuAddress = 1;
wddm->getMonitoredFence().lastSubmittedFence = 1; wddm->getMonitoredFence().lastSubmittedFence = 1;
mockWddm->makeNonResidentResult.called = 0; wddm->makeNonResidentResult.called = 0;
memoryManager->trimCandidateList.resize(0); memoryManager->trimCandidateList.resize(0);
memoryManager->addToTrimCandidateList(&allocation1); memoryManager->addToTrimCandidateList(&allocation1);
bool status = memoryManager->trimResidencyToBudget(3 * 4096); bool status = memoryManager->trimResidencyToBudget(3 * 4096);
EXPECT_EQ(1u, mockWddm->makeNonResidentResult.called); EXPECT_EQ(1u, wddm->makeNonResidentResult.called);
EXPECT_EQ(0u, memoryManager->trimCandidateList.size()); EXPECT_EQ(0u, memoryManager->trimCandidateList.size());
EXPECT_FALSE(status); EXPECT_FALSE(status);
@@ -1243,7 +1228,7 @@ HWTEST_F(WddmMemoryManagerResidencyTest, trimToBudgetStopsEvictingWhenNumBytesTo
wddm->getMonitoredFence().lastSubmittedFence = 1; wddm->getMonitoredFence().lastSubmittedFence = 1;
wddm->getMonitoredFence().currentFenceValue = 1; wddm->getMonitoredFence().currentFenceValue = 1;
mockWddm->makeNonResidentResult.called = 0; wddm->makeNonResidentResult.called = 0;
memoryManager->trimCandidateList.resize(0); memoryManager->trimCandidateList.resize(0);
@@ -1254,7 +1239,7 @@ HWTEST_F(WddmMemoryManagerResidencyTest, trimToBudgetStopsEvictingWhenNumBytesTo
bool status = memoryManager->trimResidencyToBudget(3 * 4096); bool status = memoryManager->trimResidencyToBudget(3 * 4096);
EXPECT_TRUE(status); EXPECT_TRUE(status);
EXPECT_EQ(2u, mockWddm->makeNonResidentResult.called); EXPECT_EQ(2u, wddm->makeNonResidentResult.called);
EXPECT_EQ(1u, memoryManager->trimCandidateList.size()); EXPECT_EQ(1u, memoryManager->trimCandidateList.size());
EXPECT_EQ(trimListUnusedPosition, allocation1.getTrimCandidateListPosition()); EXPECT_EQ(trimListUnusedPosition, allocation1.getTrimCandidateListPosition());
@@ -1280,7 +1265,7 @@ HWTEST_F(WddmMemoryManagerResidencyTest, trimToBudgetMarksEvictedAllocationNonRe
wddm->getMonitoredFence().lastSubmittedFence = 1; wddm->getMonitoredFence().lastSubmittedFence = 1;
wddm->getMonitoredFence().currentFenceValue = 1; wddm->getMonitoredFence().currentFenceValue = 1;
mockWddm->makeNonResidentResult.called = 0; wddm->makeNonResidentResult.called = 0;
memoryManager->trimCandidateList.resize(0); memoryManager->trimCandidateList.resize(0);
@@ -1307,8 +1292,8 @@ HWTEST_F(WddmMemoryManagerResidencyTest, trimToBudgetWaitsFromCpuWhenLastFenceIs
wddm->getMonitoredFence().lastSubmittedFence = 2; wddm->getMonitoredFence().lastSubmittedFence = 2;
wddm->getMonitoredFence().currentFenceValue = 3; wddm->getMonitoredFence().currentFenceValue = 3;
mockWddm->makeNonResidentResult.called = 0; wddm->makeNonResidentResult.called = 0;
mockWddm->waitFromCpuResult.called = 0; wddm->waitFromCpuResult.called = 0;
memoryManager->trimCandidateList.resize(0); memoryManager->trimCandidateList.resize(0);
@@ -1318,17 +1303,16 @@ HWTEST_F(WddmMemoryManagerResidencyTest, trimToBudgetWaitsFromCpuWhenLastFenceIs
bool status = memoryManager->trimResidencyToBudget(3 * 4096); bool status = memoryManager->trimResidencyToBudget(3 * 4096);
EXPECT_EQ(1u, mockWddm->makeNonResidentResult.called); EXPECT_EQ(1u, wddm->makeNonResidentResult.called);
EXPECT_FALSE(allocation1.getResidencyData().resident); EXPECT_FALSE(allocation1.getResidencyData().resident);
EXPECT_EQ(mockWddm->getDevice(), gdi.getWaitFromCpuArg().hDevice); EXPECT_EQ(wddm->getDevice(), gdi.getWaitFromCpuArg().hDevice);
} }
HWTEST_F(WddmMemoryManagerResidencyTest, trimToBudgetEvictsDoneFragmentsOnly) { HWTEST_F(WddmMemoryManagerResidencyTest, trimToBudgetEvictsDoneFragmentsOnly) {
SetUpMm<FamilyType>(); SetUpMm<FamilyType>();
WddmMock *mockWddm = static_cast<WddmMock *>(wddm);
gdi.setNonZeroNumBytesToTrimInEvict(); gdi.setNonZeroNumBytesToTrimInEvict();
void *ptr = reinterpret_cast<void *>(mockWddm->virtualAllocAddress + 0x1000); void *ptr = reinterpret_cast<void *>(wddm->virtualAllocAddress + 0x1000);
WddmAllocation allocation1(ptr, 0x1000, ptr, 0x1000, nullptr); WddmAllocation allocation1(ptr, 0x1000, ptr, 0x1000, nullptr);
WddmAllocation allocation2(ptr, 0x1000, ptr, 0x1000, nullptr); WddmAllocation allocation2(ptr, 0x1000, ptr, 0x1000, nullptr);
allocation1.getResidencyData().resident = true; allocation1.getResidencyData().resident = true;
@@ -1363,11 +1347,11 @@ HWTEST_F(WddmMemoryManagerResidencyTest, trimToBudgetEvictsDoneFragmentsOnly) {
wddm->getMonitoredFence().lastSubmittedFence = 1; wddm->getMonitoredFence().lastSubmittedFence = 1;
wddm->getMonitoredFence().currentFenceValue = 2; wddm->getMonitoredFence().currentFenceValue = 2;
mockWddm->makeNonResidentResult.called = 0; wddm->makeNonResidentResult.called = 0;
bool status = memoryManager->trimResidencyToBudget(3 * 4096); bool status = memoryManager->trimResidencyToBudget(3 * 4096);
EXPECT_EQ(2u, mockWddm->makeNonResidentResult.called); EXPECT_EQ(2u, wddm->makeNonResidentResult.called);
EXPECT_FALSE(allocationTriple->fragmentsStorage.fragmentStorageData[0].residency->resident); EXPECT_FALSE(allocationTriple->fragmentsStorage.fragmentStorageData[0].residency->resident);
EXPECT_TRUE(allocationTriple->fragmentsStorage.fragmentStorageData[1].residency->resident); EXPECT_TRUE(allocationTriple->fragmentsStorage.fragmentStorageData[1].residency->resident);
@@ -1402,7 +1386,6 @@ HWTEST_F(WddmMemoryManagerResidencyTest, checkTrimCandidateListCompaction) {
HWTEST_F(WddmMemoryManagerResidencyTest, givenThreeAllocationsAlignedSizeBiggerThanAllocSizeWhenBudgetEqualTwoAlignedAllocationThenEvictOnlyTwo) { HWTEST_F(WddmMemoryManagerResidencyTest, givenThreeAllocationsAlignedSizeBiggerThanAllocSizeWhenBudgetEqualTwoAlignedAllocationThenEvictOnlyTwo) {
SetUpMm<FamilyType>(); SetUpMm<FamilyType>();
WddmMock *mockWddm = static_cast<WddmMock *>(wddm);
gdi.setNonZeroNumBytesToTrimInEvict(); gdi.setNonZeroNumBytesToTrimInEvict();
size_t underlyingSize = 0xF00; size_t underlyingSize = 0xF00;
size_t alignedSize = 0x1000; size_t alignedSize = 0x1000;
@@ -1411,9 +1394,9 @@ HWTEST_F(WddmMemoryManagerResidencyTest, givenThreeAllocationsAlignedSizeBiggerT
//trim budget should consider aligned size, not underlying, so if function considers underlying, it should evict three, not two //trim budget should consider aligned size, not underlying, so if function considers underlying, it should evict three, not two
EXPECT_GT((3 * underlyingSize), budget); EXPECT_GT((3 * underlyingSize), budget);
EXPECT_LT((2 * underlyingSize), budget); EXPECT_LT((2 * underlyingSize), budget);
void *ptr1 = reinterpret_cast<void *>(mockWddm->virtualAllocAddress + 0x1000); void *ptr1 = reinterpret_cast<void *>(wddm->virtualAllocAddress + 0x1000);
void *ptr2 = reinterpret_cast<void *>(mockWddm->virtualAllocAddress + 0x3000); void *ptr2 = reinterpret_cast<void *>(wddm->virtualAllocAddress + 0x3000);
void *ptr3 = reinterpret_cast<void *>(mockWddm->virtualAllocAddress + 0x5000); void *ptr3 = reinterpret_cast<void *>(wddm->virtualAllocAddress + 0x5000);
WddmAllocation allocation1(ptr1, underlyingSize, ptr1, alignedSize, nullptr); WddmAllocation allocation1(ptr1, underlyingSize, ptr1, alignedSize, nullptr);
WddmAllocation allocation2(ptr2, underlyingSize, ptr2, alignedSize, nullptr); WddmAllocation allocation2(ptr2, underlyingSize, ptr2, alignedSize, nullptr);
@@ -1432,7 +1415,7 @@ HWTEST_F(WddmMemoryManagerResidencyTest, givenThreeAllocationsAlignedSizeBiggerT
wddm->getMonitoredFence().lastSubmittedFence = 1; wddm->getMonitoredFence().lastSubmittedFence = 1;
wddm->getMonitoredFence().currentFenceValue = 1; wddm->getMonitoredFence().currentFenceValue = 1;
mockWddm->makeNonResidentResult.called = 0; wddm->makeNonResidentResult.called = 0;
memoryManager->trimCandidateList.resize(0); memoryManager->trimCandidateList.resize(0);
@@ -1489,8 +1472,7 @@ HWTEST_F(BufferWithWddmMemory, NullOsHandleStorageAskedForPopulationReturnsFille
HWTEST_F(BufferWithWddmMemory, GivenMisalignedHostPtrAndMultiplePagesSizeWhenAskedForGraphicsAllcoationThenItContainsAllFragmentsWithProperGpuAdrresses) { HWTEST_F(BufferWithWddmMemory, GivenMisalignedHostPtrAndMultiplePagesSizeWhenAskedForGraphicsAllcoationThenItContainsAllFragmentsWithProperGpuAdrresses) {
SetUpMm<FamilyType>(); SetUpMm<FamilyType>();
WddmMock *mockWddm = static_cast<WddmMock *>(wddm); auto ptr = reinterpret_cast<void *>(wddm->virtualAllocAddress + 0x1001);
auto ptr = reinterpret_cast<void *>(mockWddm->virtualAllocAddress + 0x1001);
auto size = MemoryConstants::pageSize * 10; auto size = MemoryConstants::pageSize * 10;
auto graphicsAllocation = memoryManager->allocateGraphicsMemory(size, ptr); auto graphicsAllocation = memoryManager->allocateGraphicsMemory(size, ptr);
@@ -1519,11 +1501,10 @@ HWTEST_F(BufferWithWddmMemory, GivenMisalignedHostPtrAndMultiplePagesSizeWhenAsk
HWTEST_F(BufferWithWddmMemory, GivenPointerAndSizeWhenAskedToCreateGrahicsAllocationThenGraphicsAllocationIsCreated) { HWTEST_F(BufferWithWddmMemory, GivenPointerAndSizeWhenAskedToCreateGrahicsAllocationThenGraphicsAllocationIsCreated) {
SetUpMm<FamilyType>(); SetUpMm<FamilyType>();
WddmMock *mockWddm = static_cast<WddmMock *>(wddm);
OsHandleStorage handleStorage; OsHandleStorage handleStorage;
auto ptr = reinterpret_cast<void *>(mockWddm->virtualAllocAddress + 0x1000); auto ptr = reinterpret_cast<void *>(wddm->virtualAllocAddress + 0x1000);
auto ptr2 = reinterpret_cast<void *>(mockWddm->virtualAllocAddress + 0x1001); auto ptr2 = reinterpret_cast<void *>(wddm->virtualAllocAddress + 0x1001);
auto size = MemoryConstants::pageSize; auto size = MemoryConstants::pageSize;
handleStorage.fragmentStorageData[0].cpuPtr = ptr; handleStorage.fragmentStorageData[0].cpuPtr = ptr;

View File

@@ -36,67 +36,51 @@
using namespace OCLRT; using namespace OCLRT;
using namespace ::testing; using namespace ::testing;
class WddmMemoryManagerFixture : public WddmFixture { class WddmMemoryManagerFixture : public GdiDllFixture {
public: public:
WddmMemoryManager *memoryManager = nullptr; void SetUp() override;
virtual void SetUp();
template <typename FamiltyType> template <typename FamiltyType>
void SetUpMm() { void SetUpMm() {
WddmMock *mockWddm = static_cast<WddmMock *>(wddm);
EXPECT_TRUE(wddm->init<FamiltyType>()); EXPECT_TRUE(wddm->init<FamiltyType>());
uint64_t heap32Base = (uint64_t)(0x800000000000); uint64_t heap32Base = (uint64_t)(0x800000000000);
if (sizeof(uintptr_t) == 4) { if (sizeof(uintptr_t) == 4) {
heap32Base = 0x1000; heap32Base = 0x1000;
} }
mockWddm->setHeap32(heap32Base, 1000 * MemoryConstants::pageSize - 1); wddm->setHeap32(heap32Base, 1000 * MemoryConstants::pageSize - 1);
memoryManager = new (std::nothrow) WddmMemoryManager(false, wddm); memoryManager.reset(new (std::nothrow) MockWddmMemoryManager(wddm));
//assert we have memory manager //assert we have memory manager
ASSERT_NE(nullptr, memoryManager); ASSERT_NE(nullptr, memoryManager);
} }
virtual void TearDown() { std::unique_ptr<MockWddmMemoryManager> memoryManager;
WddmMock *mockWddm = static_cast<WddmMock *>(this->wddm); WddmMock *wddm = nullptr;
EXPECT_EQ(0, mockWddm->reservedAddresses.size());
delete memoryManager;
this->wddm = nullptr;
WddmFixture::TearDown();
}
}; };
typedef ::Test<WddmMemoryManagerFixture> WddmMemoryManagerTest; typedef ::Test<WddmMemoryManagerFixture> WddmMemoryManagerTest;
class MockWddmMemoryManagerFixture : public WddmFixture { class MockWddmMemoryManagerFixture {
public: public:
MockWddmMemoryManager *memoryManager = nullptr; void SetUp() {
wddm = static_cast<WddmMock *>(Wddm::createWddm(&gdi));
virtual void SetUp() {
WddmFixture::SetUp(&gdi);
ASSERT_NE(nullptr, wddm);
} }
template <typename FamiltyType> template <typename FamiltyType>
void SetUpMm() { void SetUpMm() {
WddmMock *mockWddm = static_cast<WddmMock *>(wddm);
EXPECT_TRUE(wddm->init<FamiltyType>()); EXPECT_TRUE(wddm->init<FamiltyType>());
uint64_t heap32Base = (uint64_t)(0x800000000000); uint64_t heap32Base = (uint64_t)(0x800000000000);
if (sizeof(uintptr_t) == 4) { if (sizeof(uintptr_t) == 4) {
heap32Base = 0x1000; heap32Base = 0x1000;
} }
mockWddm->setHeap32(heap32Base, 1000 * MemoryConstants::pageSize - 1); wddm->setHeap32(heap32Base, 1000 * MemoryConstants::pageSize - 1);
memoryManager = new (std::nothrow) MockWddmMemoryManager(wddm); memoryManager.reset(new (std::nothrow) MockWddmMemoryManager(wddm));
//assert we have memory manager //assert we have memory manager
ASSERT_NE(nullptr, memoryManager); ASSERT_NE(nullptr, memoryManager);
} }
virtual void TearDown() { virtual void TearDown() {}
WddmMock *mockWddm = static_cast<WddmMock *>(this->wddm); std::unique_ptr<MockWddmMemoryManager> memoryManager;
EXPECT_EQ(0, mockWddm->reservedAddresses.size()); WddmMock *wddm = nullptr;
delete memoryManager;
this->wddm = nullptr;
WddmFixture::TearDown();
}
MockGdi gdi; MockGdi gdi;
}; };
@@ -171,17 +155,16 @@ class BufferWithWddmMemory : public ::testing::Test,
template <typename FamiltyType> template <typename FamiltyType>
void SetUpMm() { void SetUpMm() {
WddmMock *mockWddm = static_cast<WddmMock *>(wddm);
EXPECT_TRUE(wddm->init<FamiltyType>()); EXPECT_TRUE(wddm->init<FamiltyType>());
uint64_t heap32Base = (uint64_t)(0x800000000000); uint64_t heap32Base = (uint64_t)(0x800000000000);
if (sizeof(uintptr_t) == 4) { if (sizeof(uintptr_t) == 4) {
heap32Base = 0x1000; heap32Base = 0x1000;
} }
mockWddm->setHeap32(heap32Base, 1000 * MemoryConstants::pageSize - 1); wddm->setHeap32(heap32Base, 1000 * MemoryConstants::pageSize - 1);
memoryManager = new (std::nothrow) WddmMemoryManager(false, wddm); memoryManager.reset(new (std::nothrow) MockWddmMemoryManager(wddm));
//assert we have memory manager //assert we have memory manager
ASSERT_NE(nullptr, memoryManager); ASSERT_NE(nullptr, memoryManager);
context.setMemoryManager(memoryManager); context.setMemoryManager(memoryManager.get());
flags = 0; flags = 0;
} }

View File

@@ -32,6 +32,7 @@
#include "runtime/os_interface/windows/wddm_memory_manager.h" #include "runtime/os_interface/windows/wddm_memory_manager.h"
#include "unit_tests/helpers/debug_manager_state_restore.h" #include "unit_tests/helpers/debug_manager_state_restore.h"
#include "unit_tests/mocks/mock_gmm_resource_info.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "runtime/os_interface/os_time.h" #include "runtime/os_interface/os_time.h"
@@ -41,10 +42,39 @@
using namespace OCLRT; using namespace OCLRT;
HWTEST_F(WddmTestSingle, givenMinWindowsAddressWhenWddmIsInitializedThenWddmUseThisAddress) { namespace GmmHelperFunctions {
Gmm *getGmm(void *ptr, size_t size) {
size_t alignedSize = alignSizeWholePage(ptr, size);
void *alignedPtr = alignUp(ptr, 4096);
Gmm *gmm = new Gmm;
gmm->resourceParams.Type = RESOURCE_BUFFER;
gmm->resourceParams.Format = GMM_FORMAT_GENERIC_8BIT;
gmm->resourceParams.BaseWidth = (uint32_t)alignedSize;
gmm->resourceParams.BaseHeight = 1;
gmm->resourceParams.Depth = 1;
gmm->resourceParams.Usage = GMM_RESOURCE_USAGE_OCL_BUFFER;
gmm->resourceParams.pExistingSysMem = reinterpret_cast<GMM_VOIDPTR64>(alignedPtr);
gmm->resourceParams.ExistingSysMemSize = alignedSize;
gmm->resourceParams.BaseAlignment = 0;
gmm->resourceParams.Flags.Info.ExistingSysMem = 1;
gmm->resourceParams.Flags.Info.Linear = 1;
gmm->resourceParams.Flags.Info.Cacheable = 1;
gmm->resourceParams.Flags.Gpu.Texture = 1;
gmm->create();
EXPECT_NE(gmm->gmmResourceInfo.get(), nullptr);
return gmm;
}
} // namespace GmmHelperFunctions
HWTEST_F(WddmTest, givenMinWindowsAddressWhenWddmIsInitializedThenWddmUseThisAddress) {
uintptr_t expectedAddress = 0x200000; uintptr_t expectedAddress = 0x200000;
EXPECT_EQ(expectedAddress, OCLRT::windowsMinAddress); EXPECT_EQ(expectedAddress, OCLRT::windowsMinAddress);
std::unique_ptr<Wddm> wddm(Wddm::createWddm());
bool status = wddm->init<FamilyType>(); bool status = wddm->init<FamilyType>();
EXPECT_TRUE(status); EXPECT_TRUE(status);
@@ -52,40 +82,31 @@ HWTEST_F(WddmTestSingle, givenMinWindowsAddressWhenWddmIsInitializedThenWddmUseT
EXPECT_EQ(expectedAddress, wddm->getWddmMinAddress()); EXPECT_EQ(expectedAddress, wddm->getWddmMinAddress());
} }
HWTEST_F(WddmTestSingle, creation) { HWTEST_F(WddmTest, creation) {
Wddm *wddm = Wddm::createWddm();
bool error = wddm->init<FamilyType>(); bool error = wddm->init<FamilyType>();
EXPECT_TRUE(error); EXPECT_TRUE(error);
EXPECT_TRUE(wddm->isInitialized()); EXPECT_TRUE(wddm->isInitialized());
delete wddm;
} }
HWTEST_F(WddmTest, doubleCreation) { HWTEST_F(WddmTest, doubleCreation) {
auto wddmMock(new WddmMock()); bool error = wddm->init<FamilyType>();
EXPECT_EQ(1u, wddm->createContextResult.called);
bool error = wddmMock->init<FamilyType>(); error |= wddm->init<FamilyType>();
EXPECT_EQ(1u, wddmMock->createContextResult.called); EXPECT_EQ(1u, wddm->createContextResult.called);
error |= wddmMock->init<FamilyType>();
EXPECT_EQ(1u, wddmMock->createContextResult.called);
EXPECT_TRUE(error); EXPECT_TRUE(error);
EXPECT_TRUE(wddmMock->isInitialized()); EXPECT_TRUE(wddm->isInitialized());
delete wddmMock;
} }
TEST_F(WddmTest, givenNullPageTableManagerWhenUpdateAuxTableCalledThenReturnFalse) { TEST_F(WddmTest, givenNullPageTableManagerWhenUpdateAuxTableCalledThenReturnFalse) {
auto wddmMock = std::make_unique<WddmMock>(); wddm->resetPageTableManager(nullptr);
EXPECT_EQ(nullptr, wddm->getPageTableManager());
wddmMock->resetPageTableManager(nullptr);
EXPECT_EQ(nullptr, wddmMock->getPageTableManager());
auto gmm = std::unique_ptr<Gmm>(Gmm::create(nullptr, 1, false)); auto gmm = std::unique_ptr<Gmm>(Gmm::create(nullptr, 1, false));
auto mockGmmRes = reinterpret_cast<MockGmmResourceInfo *>(gmm->gmmResourceInfo.get()); auto mockGmmRes = reinterpret_cast<MockGmmResourceInfo *>(gmm->gmmResourceInfo.get());
mockGmmRes->setUnifiedAuxTranslationCapable(); mockGmmRes->setUnifiedAuxTranslationCapable();
EXPECT_FALSE(wddmMock->updateAuxTable(1234u, gmm.get(), true)); EXPECT_FALSE(wddm->updateAuxTable(1234u, gmm.get(), true));
} }
TEST(WddmTestEnumAdapters, expectTrue) { TEST(WddmTestEnumAdapters, expectTrue) {
@@ -189,10 +210,7 @@ HWTEST_F(WddmTest, allocation) {
ASSERT_TRUE(wddm->isInitialized()); ASSERT_TRUE(wddm->isInitialized());
OsAgnosticMemoryManager mm(false); OsAgnosticMemoryManager mm(false);
WddmAllocation allocation(mm.allocateSystemMemory(100, 0), 100, nullptr); WddmAllocation allocation(mm.allocateSystemMemory(100, 0), 100, nullptr);
Gmm *gmm; Gmm *gmm = GmmHelperFunctions::getGmm(allocation.getUnderlyingBuffer(), allocation.getUnderlyingBufferSize());
gmm = getGmm(allocation.getUnderlyingBuffer(), allocation.getUnderlyingBufferSize());
ASSERT_NE(gmm, nullptr);
allocation.gmm = gmm; allocation.gmm = gmm;
auto status = wddm->createAllocation(&allocation); auto status = wddm->createAllocation(&allocation);
@@ -200,18 +218,18 @@ HWTEST_F(WddmTest, allocation) {
EXPECT_EQ(STATUS_SUCCESS, status); EXPECT_EQ(STATUS_SUCCESS, status);
EXPECT_TRUE(allocation.handle != 0); EXPECT_TRUE(allocation.handle != 0);
auto error = mockWddm->destroyAllocation(&allocation); auto error = wddm->destroyAllocation(&allocation);
EXPECT_TRUE(error); EXPECT_TRUE(error);
releaseGmm(gmm); delete gmm;
mm.freeSystemMemory(allocation.getUnderlyingBuffer()); mm.freeSystemMemory(allocation.getUnderlyingBuffer());
} }
HWTEST_F(WddmTest, givenAllocationSmallerUnderlyingThanAlignedSizeWhenCreatedThenWddmUseAligned) { HWTEST_F(WddmTestWithMockGdiDll, givenAllocationSmallerUnderlyingThanAlignedSizeWhenCreatedThenWddmUseAligned) {
wddm->init<FamilyType>(); wddm->init<FamilyType>();
ASSERT_TRUE(wddm->isInitialized()); ASSERT_TRUE(wddm->isInitialized());
void *ptr = reinterpret_cast<void *>(mockWddm->virtualAllocAddress + 0x1000); void *ptr = reinterpret_cast<void *>(wddm->virtualAllocAddress + 0x1000);
size_t underlyingSize = 0x2100; size_t underlyingSize = 0x2100;
size_t alignedSize = 0x3000; size_t alignedSize = 0x3000;
@@ -219,8 +237,7 @@ HWTEST_F(WddmTest, givenAllocationSmallerUnderlyingThanAlignedSizeWhenCreatedThe
size_t alignedPages = alignedSize / MemoryConstants::pageSize; size_t alignedPages = alignedSize / MemoryConstants::pageSize;
WddmAllocation allocation(ptr, 0x2100, ptr, 0x3000, nullptr); WddmAllocation allocation(ptr, 0x2100, ptr, 0x3000, nullptr);
Gmm *gmm = getGmm(allocation.getAlignedCpuPtr(), allocation.getAlignedSize()); Gmm *gmm = GmmHelperFunctions::getGmm(allocation.getAlignedCpuPtr(), allocation.getAlignedSize());
ASSERT_NE(nullptr, gmm);
allocation.gmm = gmm; allocation.gmm = gmm;
auto status = wddm->createAllocation(&allocation); auto status = wddm->createAllocation(&allocation);
@@ -234,30 +251,25 @@ HWTEST_F(WddmTest, givenAllocationSmallerUnderlyingThanAlignedSizeWhenCreatedThe
EXPECT_EQ(alignedPages, getLastCallMapGpuVaArgFcn()->SizeInPages); EXPECT_EQ(alignedPages, getLastCallMapGpuVaArgFcn()->SizeInPages);
EXPECT_NE(underlyingPages, getLastCallMapGpuVaArgFcn()->SizeInPages); EXPECT_NE(underlyingPages, getLastCallMapGpuVaArgFcn()->SizeInPages);
ret = mockWddm->destroyAllocation(&allocation); ret = wddm->destroyAllocation(&allocation);
EXPECT_TRUE(ret); EXPECT_TRUE(ret);
releaseGmm(gmm); delete gmm;
} }
HWTEST_F(WddmTest, createAllocation32bit) { HWTEST_F(WddmTest, createAllocation32bit) {
wddm->init<FamilyType>(); wddm->init<FamilyType>();
ASSERT_TRUE(wddm->isInitialized()); ASSERT_TRUE(wddm->isInitialized());
WddmMock *wddmMock = (WddmMock *)wddm;
uint64_t heap32baseAddress = 0x40000; uint64_t heap32baseAddress = 0x40000;
uint64_t heap32Size = 0x40000; uint64_t heap32Size = 0x40000;
wddmMock->setHeap32(heap32baseAddress, heap32Size); wddm->setHeap32(heap32baseAddress, heap32Size);
void *alignedPtr = (void *)0x12000; void *alignedPtr = (void *)0x12000;
size_t alignedSize = 0x2000; size_t alignedSize = 0x2000;
WddmAllocation allocation(alignedPtr, alignedSize, nullptr); WddmAllocation allocation(alignedPtr, alignedSize, nullptr);
Gmm *gmm; Gmm *gmm = GmmHelperFunctions::getGmm(allocation.getUnderlyingBuffer(), allocation.getUnderlyingBufferSize());
gmm = getGmm(allocation.getUnderlyingBuffer(), allocation.getUnderlyingBufferSize());
ASSERT_NE(gmm, nullptr);
allocation.gmm = gmm; allocation.gmm = gmm;
allocation.is32BitAllocation = true; // mark 32 bit allocation allocation.is32BitAllocation = true; // mark 32 bit allocation
@@ -270,15 +282,15 @@ HWTEST_F(WddmTest, createAllocation32bit) {
bool ret = wddm->mapGpuVirtualAddress(&allocation, allocation.getAlignedCpuPtr(), allocation.getAlignedSize(), allocation.is32BitAllocation, false, false); bool ret = wddm->mapGpuVirtualAddress(&allocation, allocation.getAlignedCpuPtr(), allocation.getAlignedSize(), allocation.is32BitAllocation, false, false);
EXPECT_TRUE(ret); EXPECT_TRUE(ret);
EXPECT_EQ(1u, wddmMock->mapGpuVirtualAddressResult.called); EXPECT_EQ(1u, wddm->mapGpuVirtualAddressResult.called);
EXPECT_LE(heap32baseAddress, allocation.gpuPtr); EXPECT_LE(heap32baseAddress, allocation.gpuPtr);
EXPECT_GT(heap32baseAddress + heap32Size, allocation.gpuPtr); EXPECT_GT(heap32baseAddress + heap32Size, allocation.gpuPtr);
auto success = mockWddm->destroyAllocation(&allocation); auto success = wddm->destroyAllocation(&allocation);
EXPECT_TRUE(success); EXPECT_TRUE(success);
releaseGmm(gmm); delete gmm;
} }
HWTEST_F(WddmTest, givenGraphicsAllocationWhenItIsMappedInHeap1ThenItHasGpuAddressWithingHeap1Limits) { HWTEST_F(WddmTest, givenGraphicsAllocationWhenItIsMappedInHeap1ThenItHasGpuAddressWithingHeap1Limits) {
@@ -288,7 +300,7 @@ HWTEST_F(WddmTest, givenGraphicsAllocationWhenItIsMappedInHeap1ThenItHasGpuAddre
WddmAllocation allocation(alignedPtr, alignedSize, nullptr); WddmAllocation allocation(alignedPtr, alignedSize, nullptr);
allocation.handle = ALLOCATION_HANDLE; allocation.handle = ALLOCATION_HANDLE;
allocation.gmm = getGmm(allocation.getUnderlyingBuffer(), allocation.getUnderlyingBufferSize()); allocation.gmm = GmmHelperFunctions::getGmm(allocation.getUnderlyingBuffer(), allocation.getUnderlyingBufferSize());
bool ret = wddm->mapGpuVirtualAddress(&allocation, allocation.getAlignedCpuPtr(), allocation.getAlignedSize(), false, false, true); bool ret = wddm->mapGpuVirtualAddress(&allocation, allocation.getAlignedCpuPtr(), allocation.getAlignedSize(), false, false, true);
EXPECT_TRUE(ret); EXPECT_TRUE(ret);
@@ -298,10 +310,10 @@ HWTEST_F(WddmTest, givenGraphicsAllocationWhenItIsMappedInHeap1ThenItHasGpuAddre
EXPECT_GE(allocation.gpuPtr, cannonizedHeapBase); EXPECT_GE(allocation.gpuPtr, cannonizedHeapBase);
EXPECT_LE(allocation.gpuPtr, cannonizedHeapEnd); EXPECT_LE(allocation.gpuPtr, cannonizedHeapEnd);
releaseGmm(allocation.gmm); delete allocation.gmm;
} }
HWTEST_F(WddmTest, GivenThreeOsHandlesWhenAskedForDestroyAllocationsThenAllMarkedAllocationsAreDestroyed) { HWTEST_F(WddmTestWithMockGdiDll, GivenThreeOsHandlesWhenAskedForDestroyAllocationsThenAllMarkedAllocationsAreDestroyed) {
EXPECT_TRUE(wddm->init<FamilyType>()); EXPECT_TRUE(wddm->init<FamilyType>());
OsHandleStorage storage; OsHandleStorage storage;
OsHandle osHandle1 = {0}; OsHandle osHandle1 = {0};
@@ -328,7 +340,7 @@ HWTEST_F(WddmTest, GivenThreeOsHandlesWhenAskedForDestroyAllocationsThenAllMarke
auto destroyWithResourceHandleCalled = 0u; auto destroyWithResourceHandleCalled = 0u;
D3DKMT_DESTROYALLOCATION2 *ptrToDestroyAlloc2 = nullptr; D3DKMT_DESTROYALLOCATION2 *ptrToDestroyAlloc2 = nullptr;
getSizesFunction(destroyWithResourceHandleCalled, ptrToDestroyAlloc2); getSizesFcn(destroyWithResourceHandleCalled, ptrToDestroyAlloc2);
EXPECT_EQ(0u, ptrToDestroyAlloc2->Flags.SynchronousDestroy); EXPECT_EQ(0u, ptrToDestroyAlloc2->Flags.SynchronousDestroy);
EXPECT_EQ(1u, ptrToDestroyAlloc2->Flags.AssumeNotInUse); EXPECT_EQ(1u, ptrToDestroyAlloc2->Flags.AssumeNotInUse);
@@ -340,10 +352,7 @@ HWTEST_F(WddmTest, mapAndFreeGpuVa) {
OsAgnosticMemoryManager mm(false); OsAgnosticMemoryManager mm(false);
WddmAllocation allocation(mm.allocateSystemMemory(100, 0), 100, nullptr); WddmAllocation allocation(mm.allocateSystemMemory(100, 0), 100, nullptr);
Gmm *gmm; Gmm *gmm = GmmHelperFunctions::getGmm(allocation.getUnderlyingBuffer(), allocation.getUnderlyingBufferSize());
gmm = getGmm(allocation.getUnderlyingBuffer(), allocation.getUnderlyingBufferSize());
ASSERT_NE(gmm, nullptr);
allocation.gmm = gmm; allocation.gmm = gmm;
auto status = wddm->createAllocation(&allocation); auto status = wddm->createAllocation(&allocation);
@@ -359,9 +368,9 @@ HWTEST_F(WddmTest, mapAndFreeGpuVa) {
EXPECT_TRUE(error); EXPECT_TRUE(error);
EXPECT_TRUE(allocation.gpuPtr == 0); EXPECT_TRUE(allocation.gpuPtr == 0);
error = mockWddm->destroyAllocation(&allocation); error = wddm->destroyAllocation(&allocation);
EXPECT_TRUE(error); EXPECT_TRUE(error);
releaseGmm(gmm); delete gmm;
mm.freeSystemMemory(allocation.getUnderlyingBuffer()); mm.freeSystemMemory(allocation.getUnderlyingBuffer());
} }
@@ -371,10 +380,7 @@ HWTEST_F(WddmTest, givenNullAllocationWhenCreateThenAllocateAndMap) {
OsAgnosticMemoryManager mm(false); OsAgnosticMemoryManager mm(false);
WddmAllocation allocation(nullptr, 100, nullptr); WddmAllocation allocation(nullptr, 100, nullptr);
Gmm *gmm; Gmm *gmm = GmmHelperFunctions::getGmm(allocation.getUnderlyingBuffer(), allocation.getUnderlyingBufferSize());
gmm = getGmm(allocation.getUnderlyingBuffer(), allocation.getUnderlyingBufferSize());
ASSERT_NE(gmm, nullptr);
allocation.gmm = gmm; allocation.gmm = gmm;
auto status = wddm->createAllocation(&allocation); auto status = wddm->createAllocation(&allocation);
@@ -386,7 +392,7 @@ HWTEST_F(WddmTest, givenNullAllocationWhenCreateThenAllocateAndMap) {
EXPECT_NE(0u, allocation.gpuPtr); EXPECT_NE(0u, allocation.gpuPtr);
EXPECT_EQ(allocation.gpuPtr, Gmm::canonize(allocation.gpuPtr)); EXPECT_EQ(allocation.gpuPtr, Gmm::canonize(allocation.gpuPtr));
releaseGmm(gmm); delete gmm;
mm.freeSystemMemory(allocation.getUnderlyingBuffer()); mm.freeSystemMemory(allocation.getUnderlyingBuffer());
} }
@@ -396,10 +402,7 @@ HWTEST_F(WddmTest, makeResidentNonResident) {
OsAgnosticMemoryManager mm(false); OsAgnosticMemoryManager mm(false);
WddmAllocation allocation(mm.allocateSystemMemory(100, 0), 100, nullptr); WddmAllocation allocation(mm.allocateSystemMemory(100, 0), 100, nullptr);
Gmm *gmm; Gmm *gmm = GmmHelperFunctions::getGmm(allocation.getUnderlyingBuffer(), allocation.getUnderlyingBufferSize());
gmm = getGmm(allocation.getUnderlyingBuffer(), allocation.getUnderlyingBufferSize());
ASSERT_NE(gmm, nullptr);
allocation.gmm = gmm; allocation.gmm = gmm;
auto status = wddm->createAllocation(&allocation); auto status = wddm->createAllocation(&allocation);
@@ -423,10 +426,10 @@ HWTEST_F(WddmTest, makeResidentNonResident) {
monitoredFence.cpuAddress = &fenceValue; monitoredFence.cpuAddress = &fenceValue;
monitoredFence.currentFenceValue = 101; monitoredFence.currentFenceValue = 101;
error = mockWddm->destroyAllocation(&allocation); error = wddm->destroyAllocation(&allocation);
EXPECT_TRUE(error); EXPECT_TRUE(error);
releaseGmm(gmm); delete gmm;
mm.freeSystemMemory(allocation.getUnderlyingBuffer()); mm.freeSystemMemory(allocation.getUnderlyingBuffer());
} }
@@ -451,7 +454,7 @@ TEST_F(WddmTest, GetCpuGpuTime) {
TimeStampData CPUGPUTime01 = {0}; TimeStampData CPUGPUTime01 = {0};
TimeStampData CPUGPUTime02 = {0}; TimeStampData CPUGPUTime02 = {0};
std::unique_ptr<OSInterface> osInterface(new OSInterface()); std::unique_ptr<OSInterface> osInterface(new OSInterface());
osInterface->get()->setWddm(wddm); osInterface->get()->setWddm(wddm.get());
std::unique_ptr<OSTime> osTime(OSTime::create(osInterface.get()).release()); std::unique_ptr<OSTime> osTime(OSTime::create(osInterface.get()).release());
auto success = osTime->getCpuGpuTime(&CPUGPUTime01); auto success = osTime->getCpuGpuTime(&CPUGPUTime01);
EXPECT_TRUE(success); EXPECT_TRUE(success);
@@ -465,15 +468,14 @@ TEST_F(WddmTest, GetCpuGpuTime) {
EXPECT_GT(CPUGPUTime02.CPUTimeinNS, CPUGPUTime01.CPUTimeinNS); EXPECT_GT(CPUGPUTime02.CPUTimeinNS, CPUGPUTime01.CPUTimeinNS);
} }
HWTEST_F(WddmTest, givenSharedHandleWhenCreateGraphicsAllocationFromSharedHandleIsCalledThenGraphicsAllocationWithSharedPropertiesIsCreated) { HWTEST_F(WddmTestWithMockGdiDll, givenSharedHandleWhenCreateGraphicsAllocationFromSharedHandleIsCalledThenGraphicsAllocationWithSharedPropertiesIsCreated) {
void *pSysMem = (void *)0x1000; void *pSysMem = (void *)0x1000;
std::unique_ptr<Gmm> gmm(Gmm::create(pSysMem, 4096u, false)); std::unique_ptr<Gmm> gmm(Gmm::create(pSysMem, 4096u, false));
auto status = setSizesFunction(gmm->gmmResourceInfo.get(), 1u, 1024u, 1u); auto status = setSizesFcn(gmm->gmmResourceInfo.get(), 1u, 1024u, 1u);
EXPECT_EQ(0u, status); EXPECT_EQ(0u, status);
std::unique_ptr<WddmMock> mockWddm(new WddmMock()); wddm->init<FamilyType>();
mockWddm->init<FamilyType>(); WddmMemoryManager mm(false, wddm.release());
WddmMemoryManager mm(false, mockWddm.release());
auto graphicsAllocation = mm.createGraphicsAllocationFromSharedHandle(ALLOCATION_HANDLE, false); auto graphicsAllocation = mm.createGraphicsAllocationFromSharedHandle(ALLOCATION_HANDLE, false);
auto wddmAllocation = (WddmAllocation *)graphicsAllocation; auto wddmAllocation = (WddmAllocation *)graphicsAllocation;
@@ -495,7 +497,7 @@ HWTEST_F(WddmTest, givenSharedHandleWhenCreateGraphicsAllocationFromSharedHandle
auto destroyWithResourceHandleCalled = 0u; auto destroyWithResourceHandleCalled = 0u;
D3DKMT_DESTROYALLOCATION2 *ptrToDestroyAlloc2 = nullptr; D3DKMT_DESTROYALLOCATION2 *ptrToDestroyAlloc2 = nullptr;
status = getSizesFunction(destroyWithResourceHandleCalled, ptrToDestroyAlloc2); status = getSizesFcn(destroyWithResourceHandleCalled, ptrToDestroyAlloc2);
EXPECT_EQ(0u, ptrToDestroyAlloc2->Flags.SynchronousDestroy); EXPECT_EQ(0u, ptrToDestroyAlloc2->Flags.SynchronousDestroy);
EXPECT_EQ(1u, ptrToDestroyAlloc2->Flags.AssumeNotInUse); EXPECT_EQ(1u, ptrToDestroyAlloc2->Flags.AssumeNotInUse);
@@ -504,14 +506,13 @@ HWTEST_F(WddmTest, givenSharedHandleWhenCreateGraphicsAllocationFromSharedHandle
EXPECT_EQ(1u, destroyWithResourceHandleCalled); EXPECT_EQ(1u, destroyWithResourceHandleCalled);
} }
HWTEST_F(WddmTest, givenSharedHandleWhenCreateGraphicsAllocationFromSharedHandleIsCalledThenMapGpuVaWithCpuPtrDepensOnBitness) { HWTEST_F(WddmTestWithMockGdiDll, givenSharedHandleWhenCreateGraphicsAllocationFromSharedHandleIsCalledThenMapGpuVaWithCpuPtrDepensOnBitness) {
void *pSysMem = (void *)0x1000; void *pSysMem = (void *)0x1000;
std::unique_ptr<Gmm> gmm(Gmm::create(pSysMem, 4096u, false)); std::unique_ptr<Gmm> gmm(Gmm::create(pSysMem, 4096u, false));
auto status = setSizesFunction(gmm->gmmResourceInfo.get(), 1u, 1024u, 1u); auto status = setSizesFcn(gmm->gmmResourceInfo.get(), 1u, 1024u, 1u);
EXPECT_EQ(0u, status); EXPECT_EQ(0u, status);
auto mockWddm(new WddmMock()); auto mockWddm = wddm.release();
mockWddm->init<FamilyType>(); mockWddm->init<FamilyType>();
WddmMemoryManager mm(false, mockWddm); WddmMemoryManager mm(false, mockWddm);
@@ -529,30 +530,22 @@ HWTEST_F(WddmTest, givenSharedHandleWhenCreateGraphicsAllocationFromSharedHandle
} }
HWTEST_F(WddmTest, givenWddmCreatedWhenNotInitedThenMinAddressZero) { HWTEST_F(WddmTest, givenWddmCreatedWhenNotInitedThenMinAddressZero) {
Wddm *wddm = Wddm::createWddm();
uintptr_t expected = 0; uintptr_t expected = 0;
uintptr_t actual = wddm->getWddmMinAddress(); uintptr_t actual = wddm->getWddmMinAddress();
EXPECT_EQ(expected, actual); EXPECT_EQ(expected, actual);
delete wddm;
} }
HWTEST_F(WddmTest, givenWddmCreatedWhenInitedThenMinAddressValid) { HWTEST_F(WddmTest, givenWddmCreatedWhenInitedThenMinAddressValid) {
Wddm *wddm = Wddm::createWddm();
bool ret = wddm->init<FamilyType>(); bool ret = wddm->init<FamilyType>();
EXPECT_TRUE(ret); EXPECT_TRUE(ret);
uintptr_t expected = windowsMinAddress; uintptr_t expected = windowsMinAddress;
uintptr_t actual = wddm->getWddmMinAddress(); uintptr_t actual = wddm->getWddmMinAddress();
EXPECT_EQ(expected, actual); EXPECT_EQ(expected, actual);
delete wddm;
} }
HWTEST_F(WddmInstrumentationTest, configureDeviceAddressSpaceOnInit) { HWTEST_F(WddmInstrumentationTest, configureDeviceAddressSpaceOnInit) {
SYSTEM_INFO sysInfo = {}; SYSTEM_INFO sysInfo = {};
auto mockWddm(new WddmMock());
auto gmmMem = static_cast<GmockGmmMemory *>(mockWddm->getGmmMemory());
WddmMock::getSystemInfo(&sysInfo); WddmMock::getSystemInfo(&sysInfo);
uintptr_t maxAddr = reinterpret_cast<uintptr_t>(sysInfo.lpMaximumApplicationAddress) + 1; uintptr_t maxAddr = reinterpret_cast<uintptr_t>(sysInfo.lpMaximumApplicationAddress) + 1;
@@ -563,7 +556,7 @@ HWTEST_F(WddmInstrumentationTest, configureDeviceAddressSpaceOnInit) {
EXPECT_CALL(*gmmMem, configureDeviceAddressSpace(adapterHandle, EXPECT_CALL(*gmmMem, configureDeviceAddressSpace(adapterHandle,
deviceHandle, deviceHandle,
mockWddm->gdi->escape.mFunc, wddm->gdi->escape.mFunc,
maxAddr, maxAddr,
0, 0,
0, 0,
@@ -572,17 +565,13 @@ HWTEST_F(WddmInstrumentationTest, configureDeviceAddressSpaceOnInit) {
0)) 0))
.Times(1) .Times(1)
.WillRepeatedly(::testing::Return(true)); .WillRepeatedly(::testing::Return(true));
mockWddm->init<FamilyType>(); wddm->init<FamilyType>();
EXPECT_TRUE(mockWddm->isInitialized()); EXPECT_TRUE(wddm->isInitialized());
delete mockWddm;
} }
HWTEST_F(WddmInstrumentationTest, configureDeviceAddressSpaceNoAdapter) { HWTEST_F(WddmInstrumentationTest, configureDeviceAddressSpaceNoAdapter) {
auto mockWddm(new WddmMock()); wddm->adapter = static_cast<D3DKMT_HANDLE>(0);
auto gmmMem = static_cast<GmockGmmMemory *>(mockWddm->getGmmMemory());
mockWddm->adapter = static_cast<D3DKMT_HANDLE>(0);
EXPECT_CALL(*gmmMem, configureDeviceAddressSpace(static_cast<D3DKMT_HANDLE>(0), EXPECT_CALL(*gmmMem, configureDeviceAddressSpace(static_cast<D3DKMT_HANDLE>(0),
::testing::_, ::testing::_,
::testing::_, ::testing::_,
@@ -594,17 +583,13 @@ HWTEST_F(WddmInstrumentationTest, configureDeviceAddressSpaceNoAdapter) {
::testing::_)) ::testing::_))
.Times(1) .Times(1)
.WillRepeatedly(::testing::Return(false)); .WillRepeatedly(::testing::Return(false));
auto ret = mockWddm->configureDeviceAddressSpace<FamilyType>(); auto ret = wddm->configureDeviceAddressSpace<FamilyType>();
EXPECT_FALSE(ret); EXPECT_FALSE(ret);
delete mockWddm;
} }
HWTEST_F(WddmInstrumentationTest, configureDeviceAddressSpaceNoDevice) { HWTEST_F(WddmInstrumentationTest, configureDeviceAddressSpaceNoDevice) {
auto mockWddm(new WddmMock()); wddm->device = static_cast<D3DKMT_HANDLE>(0);
auto gmmMem = static_cast<GmockGmmMemory *>(mockWddm->getGmmMemory());
mockWddm->device = static_cast<D3DKMT_HANDLE>(0);
EXPECT_CALL(*gmmMem, configureDeviceAddressSpace(::testing::_, EXPECT_CALL(*gmmMem, configureDeviceAddressSpace(::testing::_,
static_cast<D3DKMT_HANDLE>(0), static_cast<D3DKMT_HANDLE>(0),
::testing::_, ::testing::_,
@@ -616,17 +601,13 @@ HWTEST_F(WddmInstrumentationTest, configureDeviceAddressSpaceNoDevice) {
::testing::_)) ::testing::_))
.Times(1) .Times(1)
.WillRepeatedly(::testing::Return(false)); .WillRepeatedly(::testing::Return(false));
auto ret = mockWddm->configureDeviceAddressSpace<FamilyType>(); auto ret = wddm->configureDeviceAddressSpace<FamilyType>();
EXPECT_FALSE(ret); EXPECT_FALSE(ret);
delete mockWddm;
} }
HWTEST_F(WddmInstrumentationTest, configureDeviceAddressSpaceNoEscFunc) { HWTEST_F(WddmInstrumentationTest, configureDeviceAddressSpaceNoEscFunc) {
auto mockWddm(new WddmMock()); wddm->gdi->escape = static_cast<PFND3DKMT_ESCAPE>(nullptr);
auto gmmMem = static_cast<GmockGmmMemory *>(mockWddm->getGmmMemory());
mockWddm->gdi->escape = static_cast<PFND3DKMT_ESCAPE>(nullptr);
EXPECT_CALL(*gmmMem, configureDeviceAddressSpace(::testing::_, EXPECT_CALL(*gmmMem, configureDeviceAddressSpace(::testing::_,
::testing::_, ::testing::_,
static_cast<PFND3DKMT_ESCAPE>(nullptr), static_cast<PFND3DKMT_ESCAPE>(nullptr),
@@ -638,56 +619,46 @@ HWTEST_F(WddmInstrumentationTest, configureDeviceAddressSpaceNoEscFunc) {
::testing::_)) ::testing::_))
.Times(1) .Times(1)
.WillRepeatedly(::testing::Return(false)); .WillRepeatedly(::testing::Return(false));
auto ret = mockWddm->configureDeviceAddressSpace<FamilyType>(); auto ret = wddm->configureDeviceAddressSpace<FamilyType>();
EXPECT_FALSE(ret); EXPECT_FALSE(ret);
delete mockWddm;
} }
HWTEST_F(WddmTest, getMaxApplicationAddress) { HWTEST_F(WddmTest, getMaxApplicationAddress) {
auto mockWddm(new WddmMock()); wddm->init<FamilyType>();
EXPECT_TRUE(wddm->isInitialized());
mockWddm->init<FamilyType>(); uint64_t maxAddr = wddm->getMaxApplicationAddress();
EXPECT_TRUE(mockWddm->isInitialized());
uint64_t maxAddr = mockWddm->getMaxApplicationAddress();
if (is32bit) { if (is32bit) {
EXPECT_EQ(maxAddr, MemoryConstants::max32BitAppAddress); EXPECT_EQ(maxAddr, MemoryConstants::max32BitAppAddress);
} else { } else {
EXPECT_EQ(maxAddr, MemoryConstants::max64BitAppAddress); EXPECT_EQ(maxAddr, MemoryConstants::max64BitAppAddress);
} }
delete mockWddm;
} }
HWTEST_F(WddmTest, dontCallCreateContextBeforeConfigureDeviceAddressSpace) { HWTEST_F(WddmTest, dontCallCreateContextBeforeConfigureDeviceAddressSpace) {
auto mockWddm(new WddmMock()); wddm->createContext();
mockWddm->createContext(); EXPECT_EQ(1u, wddm->createContextResult.called); // dont care about the result
EXPECT_EQ(1u, mockWddm->createContextResult.called); // dont care about the result
mockWddm->configureDeviceAddressSpace<FamilyType>(); wddm->configureDeviceAddressSpace<FamilyType>();
EXPECT_EQ(1u, mockWddm->configureDeviceAddressSpaceResult.called); EXPECT_EQ(1u, wddm->configureDeviceAddressSpaceResult.called);
EXPECT_FALSE(mockWddm->configureDeviceAddressSpaceResult.success); EXPECT_FALSE(wddm->configureDeviceAddressSpaceResult.success);
delete mockWddm;
} }
HWTEST_F(WddmTest, givenUseNoRingFlushesKmdModeDebugFlagToFalseWhenCreateContextIsCalledThenNoRingFlushesKmdModeIsSetToFalse) { HWTEST_F(WddmTestWithMockGdiDll, givenUseNoRingFlushesKmdModeDebugFlagToFalseWhenCreateContextIsCalledThenNoRingFlushesKmdModeIsSetToFalse) {
DebugManagerStateRestore dbgRestore; DebugManagerStateRestore dbgRestore;
DebugManager.flags.UseNoRingFlushesKmdMode.set(false); DebugManager.flags.UseNoRingFlushesKmdMode.set(false);
std::unique_ptr<WddmMock> mockWddm(new WddmMock()); wddm->init<FamilyType>();
mockWddm->init<FamilyType>();
auto createContextParams = this->getCreateContextDataFcn(); auto createContextParams = this->getCreateContextDataFcn();
auto privateData = (CREATECONTEXT_PVTDATA *)createContextParams->pPrivateDriverData; auto privateData = (CREATECONTEXT_PVTDATA *)createContextParams->pPrivateDriverData;
EXPECT_FALSE(!!privateData->NoRingFlushes); EXPECT_FALSE(!!privateData->NoRingFlushes);
} }
HWTEST_F(WddmTest, givenUseNoRingFlushesKmdModeDebugFlagToTrueWhenCreateContextIsCalledThenNoRingFlushesKmdModeIsSetToTrue) { HWTEST_F(WddmTestWithMockGdiDll, givenUseNoRingFlushesKmdModeDebugFlagToTrueWhenCreateContextIsCalledThenNoRingFlushesKmdModeIsSetToTrue) {
DebugManagerStateRestore dbgRestore; DebugManagerStateRestore dbgRestore;
DebugManager.flags.UseNoRingFlushesKmdMode.set(true); DebugManager.flags.UseNoRingFlushesKmdMode.set(true);
std::unique_ptr<WddmMock> mockWddm(new WddmMock()); wddm->init<FamilyType>();
mockWddm->init<FamilyType>();
auto createContextParams = this->getCreateContextDataFcn(); auto createContextParams = this->getCreateContextDataFcn();
auto privateData = (CREATECONTEXT_PVTDATA *)createContextParams->pPrivateDriverData; auto privateData = (CREATECONTEXT_PVTDATA *)createContextParams->pPrivateDriverData;
EXPECT_TRUE(!!privateData->NoRingFlushes); EXPECT_TRUE(!!privateData->NoRingFlushes);
@@ -751,7 +722,7 @@ HWTEST_F(WddmPreemptionTests, givenDevicePreemptionDisabledDebugFlagForcePreempt
EXPECT_EQ(expectedVal, getCreateContextDataFcn()->Flags.DisableGpuTimeout); EXPECT_EQ(expectedVal, getCreateContextDataFcn()->Flags.DisableGpuTimeout);
} }
HWTEST_F(WddmWithMockGdiTest, makeResidentMultipleHandles) { HWTEST_F(WddmTest, makeResidentMultipleHandles) {
wddm->init<FamilyType>(); wddm->init<FamilyType>();
ASSERT_TRUE(wddm->isInitialized()); ASSERT_TRUE(wddm->isInitialized());
@@ -776,7 +747,7 @@ HWTEST_F(WddmWithMockGdiTest, makeResidentMultipleHandles) {
mm.freeSystemMemory(allocation.getUnderlyingBuffer()); mm.freeSystemMemory(allocation.getUnderlyingBuffer());
} }
HWTEST_F(WddmWithMockGdiTest, makeResidentMultipleHandlesWithReturnBytesToTrim) { HWTEST_F(WddmTest, makeResidentMultipleHandlesWithReturnBytesToTrim) {
wddm->init<FamilyType>(); wddm->init<FamilyType>();
ASSERT_TRUE(wddm->isInitialized()); ASSERT_TRUE(wddm->isInitialized());
@@ -802,11 +773,8 @@ HWTEST_F(WddmWithMockGdiTest, makeResidentMultipleHandlesWithReturnBytesToTrim)
mm.freeSystemMemory(allocation.getUnderlyingBuffer()); mm.freeSystemMemory(allocation.getUnderlyingBuffer());
} }
HWTEST_F(WddmWithMockGdiTest, makeNonResidentCallsEvict) { HWTEST_F(WddmTest, makeNonResidentCallsEvict) {
MockGdi gdi; wddm->init<FamilyType>();
WddmMock wddm(&gdi);
wddm.init<FamilyType>();
D3DKMT_HANDLE handle = (D3DKMT_HANDLE)0x1234; D3DKMT_HANDLE handle = (D3DKMT_HANDLE)0x1234;
@@ -817,25 +785,22 @@ HWTEST_F(WddmWithMockGdiTest, makeNonResidentCallsEvict) {
gdi.getEvictArg().NumBytesToTrim = 20; gdi.getEvictArg().NumBytesToTrim = 20;
uint64_t sizeToTrim = 10; uint64_t sizeToTrim = 10;
wddm.evict(&handle, 1, sizeToTrim); wddm->evict(&handle, 1, sizeToTrim);
EXPECT_EQ(1u, gdi.getEvictArg().NumAllocations); EXPECT_EQ(1u, gdi.getEvictArg().NumAllocations);
EXPECT_EQ(&handle, gdi.getEvictArg().AllocationList); EXPECT_EQ(&handle, gdi.getEvictArg().AllocationList);
EXPECT_EQ(wddm.getDevice(), gdi.getEvictArg().hDevice); EXPECT_EQ(wddm->getDevice(), gdi.getEvictArg().hDevice);
EXPECT_EQ(0u, gdi.getEvictArg().NumBytesToTrim); EXPECT_EQ(0u, gdi.getEvictArg().NumBytesToTrim);
} }
HWTEST_F(WddmWithMockGdiTest, destroyAllocationWithLastFenceValueGreaterThanCurrentValueCallsWaitFromCpu) { HWTEST_F(WddmTest, destroyAllocationWithLastFenceValueGreaterThanCurrentValueCallsWaitFromCpu) {
MockGdi gdi; wddm->init<FamilyType>();
WddmMock wddm(&gdi);
wddm.init<FamilyType>();
WddmAllocation allocation((void *)0x23000, 0x1000, nullptr); WddmAllocation allocation((void *)0x23000, 0x1000, nullptr);
allocation.getResidencyData().lastFence = 20; allocation.getResidencyData().lastFence = 20;
allocation.handle = ALLOCATION_HANDLE; allocation.handle = ALLOCATION_HANDLE;
*wddm.getMonitoredFence().cpuAddress = 10; *wddm->getMonitoredFence().cpuAddress = 10;
D3DKMT_HANDLE handle = (D3DKMT_HANDLE)0x1234; D3DKMT_HANDLE handle = (D3DKMT_HANDLE)0x1234;
@@ -851,29 +816,26 @@ HWTEST_F(WddmWithMockGdiTest, destroyAllocationWithLastFenceValueGreaterThanCurr
gdi.getDestroyArg().hResource = (D3DKMT_HANDLE)0; gdi.getDestroyArg().hResource = (D3DKMT_HANDLE)0;
gdi.getDestroyArg().phAllocationList = nullptr; gdi.getDestroyArg().phAllocationList = nullptr;
wddm.destroyAllocation(&allocation); wddm->destroyAllocation(&allocation);
EXPECT_NE(nullptr, gdi.getWaitFromCpuArg().FenceValueArray); EXPECT_NE(nullptr, gdi.getWaitFromCpuArg().FenceValueArray);
EXPECT_EQ(wddm.getDevice(), gdi.getWaitFromCpuArg().hDevice); EXPECT_EQ(wddm->getDevice(), gdi.getWaitFromCpuArg().hDevice);
EXPECT_EQ(1u, gdi.getWaitFromCpuArg().ObjectCount); EXPECT_EQ(1u, gdi.getWaitFromCpuArg().ObjectCount);
EXPECT_EQ(&wddm.getMonitoredFence().fenceHandle, gdi.getWaitFromCpuArg().ObjectHandleArray); EXPECT_EQ(&wddm->getMonitoredFence().fenceHandle, gdi.getWaitFromCpuArg().ObjectHandleArray);
EXPECT_EQ(wddm.getDevice(), gdi.getDestroyArg().hDevice); EXPECT_EQ(wddm->getDevice(), gdi.getDestroyArg().hDevice);
EXPECT_EQ(1u, gdi.getDestroyArg().AllocationCount); EXPECT_EQ(1u, gdi.getDestroyArg().AllocationCount);
EXPECT_NE(nullptr, gdi.getDestroyArg().phAllocationList); EXPECT_NE(nullptr, gdi.getDestroyArg().phAllocationList);
} }
HWTEST_F(WddmWithMockGdiTest, destroyAllocationWithLastFenceValueLessEqualToCurrentValueDoesNotCallWaitFromCpu) { HWTEST_F(WddmTest, destroyAllocationWithLastFenceValueLessEqualToCurrentValueDoesNotCallWaitFromCpu) {
MockGdi gdi; wddm->init<FamilyType>();
WddmMock wddm(&gdi);
wddm.init<FamilyType>();
WddmAllocation allocation((void *)0x23000, 0x1000, nullptr); WddmAllocation allocation((void *)0x23000, 0x1000, nullptr);
allocation.getResidencyData().lastFence = 10; allocation.getResidencyData().lastFence = 10;
allocation.handle = ALLOCATION_HANDLE; allocation.handle = ALLOCATION_HANDLE;
*wddm.getMonitoredFence().cpuAddress = 10; *wddm->getMonitoredFence().cpuAddress = 10;
D3DKMT_HANDLE handle = (D3DKMT_HANDLE)0x1234; D3DKMT_HANDLE handle = (D3DKMT_HANDLE)0x1234;
@@ -889,29 +851,26 @@ HWTEST_F(WddmWithMockGdiTest, destroyAllocationWithLastFenceValueLessEqualToCurr
gdi.getDestroyArg().hResource = (D3DKMT_HANDLE)0; gdi.getDestroyArg().hResource = (D3DKMT_HANDLE)0;
gdi.getDestroyArg().phAllocationList = nullptr; gdi.getDestroyArg().phAllocationList = nullptr;
wddm.destroyAllocation(&allocation); wddm->destroyAllocation(&allocation);
EXPECT_EQ(nullptr, gdi.getWaitFromCpuArg().FenceValueArray); EXPECT_EQ(nullptr, gdi.getWaitFromCpuArg().FenceValueArray);
EXPECT_EQ((D3DKMT_HANDLE)0, gdi.getWaitFromCpuArg().hDevice); EXPECT_EQ((D3DKMT_HANDLE)0, gdi.getWaitFromCpuArg().hDevice);
EXPECT_EQ(0u, gdi.getWaitFromCpuArg().ObjectCount); EXPECT_EQ(0u, gdi.getWaitFromCpuArg().ObjectCount);
EXPECT_EQ(nullptr, gdi.getWaitFromCpuArg().ObjectHandleArray); EXPECT_EQ(nullptr, gdi.getWaitFromCpuArg().ObjectHandleArray);
EXPECT_EQ(wddm.getDevice(), gdi.getDestroyArg().hDevice); EXPECT_EQ(wddm->getDevice(), gdi.getDestroyArg().hDevice);
EXPECT_EQ(1u, gdi.getDestroyArg().AllocationCount); EXPECT_EQ(1u, gdi.getDestroyArg().AllocationCount);
EXPECT_NE(nullptr, gdi.getDestroyArg().phAllocationList); EXPECT_NE(nullptr, gdi.getDestroyArg().phAllocationList);
} }
HWTEST_F(WddmWithMockGdiTest, WhenLastFenceLessEqualThanMonitoredThenWaitFromCpuIsNotCalled) { HWTEST_F(WddmTest, WhenLastFenceLessEqualThanMonitoredThenWaitFromCpuIsNotCalled) {
MockGdi gdi; wddm->init<FamilyType>();
WddmMock wddm(&gdi);
wddm.init<FamilyType>();
WddmAllocation allocation((void *)0x23000, 0x1000, nullptr); WddmAllocation allocation((void *)0x23000, 0x1000, nullptr);
allocation.getResidencyData().lastFence = 10; allocation.getResidencyData().lastFence = 10;
allocation.handle = ALLOCATION_HANDLE; allocation.handle = ALLOCATION_HANDLE;
*wddm.getMonitoredFence().cpuAddress = 10; *wddm->getMonitoredFence().cpuAddress = 10;
gdi.getWaitFromCpuArg().FenceValueArray = nullptr; gdi.getWaitFromCpuArg().FenceValueArray = nullptr;
gdi.getWaitFromCpuArg().Flags.Value = 0; gdi.getWaitFromCpuArg().Flags.Value = 0;
@@ -919,7 +878,7 @@ HWTEST_F(WddmWithMockGdiTest, WhenLastFenceLessEqualThanMonitoredThenWaitFromCpu
gdi.getWaitFromCpuArg().ObjectCount = 0; gdi.getWaitFromCpuArg().ObjectCount = 0;
gdi.getWaitFromCpuArg().ObjectHandleArray = nullptr; gdi.getWaitFromCpuArg().ObjectHandleArray = nullptr;
auto status = wddm.waitFromCpu(10); auto status = wddm->waitFromCpu(10);
EXPECT_TRUE(status); EXPECT_TRUE(status);
@@ -929,17 +888,14 @@ HWTEST_F(WddmWithMockGdiTest, WhenLastFenceLessEqualThanMonitoredThenWaitFromCpu
EXPECT_EQ(nullptr, gdi.getWaitFromCpuArg().ObjectHandleArray); EXPECT_EQ(nullptr, gdi.getWaitFromCpuArg().ObjectHandleArray);
} }
HWTEST_F(WddmWithMockGdiTest, WhenLastFenceGreaterThanMonitoredThenWaitFromCpuIsCalled) { HWTEST_F(WddmTest, WhenLastFenceGreaterThanMonitoredThenWaitFromCpuIsCalled) {
MockGdi gdi; wddm->init<FamilyType>();
WddmMock wddm(&gdi);
wddm.init<FamilyType>();
WddmAllocation allocation((void *)0x23000, 0x1000, nullptr); WddmAllocation allocation((void *)0x23000, 0x1000, nullptr);
allocation.getResidencyData().lastFence = 10; allocation.getResidencyData().lastFence = 10;
allocation.handle = ALLOCATION_HANDLE; allocation.handle = ALLOCATION_HANDLE;
*wddm.getMonitoredFence().cpuAddress = 10; *wddm->getMonitoredFence().cpuAddress = 10;
gdi.getWaitFromCpuArg().FenceValueArray = nullptr; gdi.getWaitFromCpuArg().FenceValueArray = nullptr;
gdi.getWaitFromCpuArg().Flags.Value = 0; gdi.getWaitFromCpuArg().Flags.Value = 0;
@@ -947,30 +903,27 @@ HWTEST_F(WddmWithMockGdiTest, WhenLastFenceGreaterThanMonitoredThenWaitFromCpuIs
gdi.getWaitFromCpuArg().ObjectCount = 0; gdi.getWaitFromCpuArg().ObjectCount = 0;
gdi.getWaitFromCpuArg().ObjectHandleArray = nullptr; gdi.getWaitFromCpuArg().ObjectHandleArray = nullptr;
auto status = wddm.waitFromCpu(20); auto status = wddm->waitFromCpu(20);
EXPECT_TRUE(status); EXPECT_TRUE(status);
EXPECT_NE(nullptr, gdi.getWaitFromCpuArg().FenceValueArray); EXPECT_NE(nullptr, gdi.getWaitFromCpuArg().FenceValueArray);
EXPECT_EQ((D3DKMT_HANDLE)wddm.getDevice(), gdi.getWaitFromCpuArg().hDevice); EXPECT_EQ((D3DKMT_HANDLE)wddm->getDevice(), gdi.getWaitFromCpuArg().hDevice);
EXPECT_EQ(1u, gdi.getWaitFromCpuArg().ObjectCount); EXPECT_EQ(1u, gdi.getWaitFromCpuArg().ObjectCount);
EXPECT_NE(nullptr, gdi.getWaitFromCpuArg().ObjectHandleArray); EXPECT_NE(nullptr, gdi.getWaitFromCpuArg().ObjectHandleArray);
} }
HWTEST_F(WddmWithMockGdiTest, createMonitoredFenceIsInitializedWithFenceValueZeroAndCurrentFenceValueIsSetToOne) { HWTEST_F(WddmTest, createMonitoredFenceIsInitializedWithFenceValueZeroAndCurrentFenceValueIsSetToOne) {
MockGdi gdi; wddm->init<FamilyType>();
WddmMock wddm(&gdi);
wddm.init<FamilyType>();
gdi.createSynchronizationObject2 = gdi.createSynchronizationObject2Mock; gdi.createSynchronizationObject2 = gdi.createSynchronizationObject2Mock;
gdi.getCreateSynchronizationObject2Arg().Info.MonitoredFence.InitialFenceValue = 300; gdi.getCreateSynchronizationObject2Arg().Info.MonitoredFence.InitialFenceValue = 300;
wddm.createMonitoredFence(); wddm->createMonitoredFence();
EXPECT_EQ(0u, gdi.getCreateSynchronizationObject2Arg().Info.MonitoredFence.InitialFenceValue); EXPECT_EQ(0u, gdi.getCreateSynchronizationObject2Arg().Info.MonitoredFence.InitialFenceValue);
EXPECT_EQ(1u, wddm.getMonitoredFence().currentFenceValue); EXPECT_EQ(1u, wddm->getMonitoredFence().currentFenceValue);
} }
NTSTATUS APIENTRY queryResourceInfoMock(D3DKMT_QUERYRESOURCEINFO *pData) { NTSTATUS APIENTRY queryResourceInfoMock(D3DKMT_QUERYRESOURCEINFO *pData) {
@@ -978,118 +931,109 @@ NTSTATUS APIENTRY queryResourceInfoMock(D3DKMT_QUERYRESOURCEINFO *pData) {
return 0; return 0;
} }
HWTEST_F(WddmWithMockGdiTest, givenOpenSharedHandleWhenZeroAllocationsThenReturnNull) { HWTEST_F(WddmTest, givenOpenSharedHandleWhenZeroAllocationsThenReturnNull) {
MockGdi gdi; wddm->init<FamilyType>();
WddmMock wddm(&gdi);
wddm.init<FamilyType>();
D3DKMT_HANDLE handle = 0; D3DKMT_HANDLE handle = 0;
WddmAllocation *alloc = nullptr; WddmAllocation *alloc = nullptr;
gdi.queryResourceInfo = reinterpret_cast<PFND3DKMT_QUERYRESOURCEINFO>(queryResourceInfoMock); gdi.queryResourceInfo = reinterpret_cast<PFND3DKMT_QUERYRESOURCEINFO>(queryResourceInfoMock);
auto ret = wddm.openSharedHandle(handle, alloc); auto ret = wddm->openSharedHandle(handle, alloc);
EXPECT_EQ(false, ret); EXPECT_EQ(false, ret);
} }
using WddmReserveAddressTest = WddmTest; using WddmReserveAddressTest = WddmTestSingle;
HWTEST_F(WddmReserveAddressTest, givenWddmWhenFirstIsSuccessfulThenReturnReserveAddress) { HWTEST_F(WddmReserveAddressTest, givenWddmWhenFirstIsSuccessfulThenReturnReserveAddress) {
std::unique_ptr<WddmMockReserveAddress> wddmMockPtr(new WddmMockReserveAddress()); std::unique_ptr<WddmMockReserveAddress> wddm(new WddmMockReserveAddress());
WddmMockReserveAddress *wddmMock = wddmMockPtr.get();
size_t size = 0x1000; size_t size = 0x1000;
void *reserve = nullptr; void *reserve = nullptr;
bool ret = wddmMock->init<FamilyType>(); bool ret = wddm->init<FamilyType>();
EXPECT_TRUE(ret); EXPECT_TRUE(ret);
wddmMock->returnGood = 1; wddm->returnGood = 1;
ret = wddmMock->reserveValidAddressRange(size, reserve); ret = wddm->reserveValidAddressRange(size, reserve);
uintptr_t expectedReserve = wddmMock->virtualAllocAddress; uintptr_t expectedReserve = wddm->virtualAllocAddress;
EXPECT_TRUE(ret); EXPECT_TRUE(ret);
EXPECT_EQ(expectedReserve, reinterpret_cast<uintptr_t>(reserve)); EXPECT_EQ(expectedReserve, reinterpret_cast<uintptr_t>(reserve));
wddmMock->releaseReservedAddress(reserve); wddm->releaseReservedAddress(reserve);
} }
HWTEST_F(WddmReserveAddressTest, givenWddmWhenFirstIsNullThenReturnNull) { HWTEST_F(WddmReserveAddressTest, givenWddmWhenFirstIsNullThenReturnNull) {
std::unique_ptr<WddmMockReserveAddress> wddmMockPtr(new WddmMockReserveAddress()); std::unique_ptr<WddmMockReserveAddress> wddm(new WddmMockReserveAddress());
WddmMockReserveAddress *wddmMock = wddmMockPtr.get();
size_t size = 0x1000; size_t size = 0x1000;
void *reserve = nullptr; void *reserve = nullptr;
bool ret = wddmMock->init<FamilyType>(); bool ret = wddm->init<FamilyType>();
EXPECT_TRUE(ret); EXPECT_TRUE(ret);
uintptr_t expectedReserve = 0; uintptr_t expectedReserve = 0;
ret = wddmMock->reserveValidAddressRange(size, reserve); ret = wddm->reserveValidAddressRange(size, reserve);
EXPECT_FALSE(ret); EXPECT_FALSE(ret);
EXPECT_EQ(expectedReserve, reinterpret_cast<uintptr_t>(reserve)); EXPECT_EQ(expectedReserve, reinterpret_cast<uintptr_t>(reserve));
} }
HWTEST_F(WddmReserveAddressTest, givenWddmWhenFirstIsInvalidSecondSuccessfulThenReturnSecond) { HWTEST_F(WddmReserveAddressTest, givenWddmWhenFirstIsInvalidSecondSuccessfulThenReturnSecond) {
std::unique_ptr<WddmMockReserveAddress> wddmMockPtr(new WddmMockReserveAddress()); std::unique_ptr<WddmMockReserveAddress> wddm(new WddmMockReserveAddress());
WddmMockReserveAddress *wddmMock = wddmMockPtr.get();
size_t size = 0x1000; size_t size = 0x1000;
void *reserve = nullptr; void *reserve = nullptr;
bool ret = wddmMock->init<FamilyType>(); bool ret = wddm->init<FamilyType>();
EXPECT_TRUE(ret); EXPECT_TRUE(ret);
wddmMock->returnInvalidCount = 1; wddm->returnInvalidCount = 1;
ret = wddmMock->reserveValidAddressRange(size, reserve); ret = wddm->reserveValidAddressRange(size, reserve);
uintptr_t expectedReserve = wddmMock->virtualAllocAddress; uintptr_t expectedReserve = wddm->virtualAllocAddress;
EXPECT_TRUE(ret); EXPECT_TRUE(ret);
EXPECT_EQ(expectedReserve, reinterpret_cast<uintptr_t>(reserve)); EXPECT_EQ(expectedReserve, reinterpret_cast<uintptr_t>(reserve));
wddmMock->releaseReservedAddress(reserve); wddm->releaseReservedAddress(reserve);
} }
HWTEST_F(WddmReserveAddressTest, givenWddmWhenSecondIsInvalidThirdSuccessfulThenReturnThird) { HWTEST_F(WddmReserveAddressTest, givenWddmWhenSecondIsInvalidThirdSuccessfulThenReturnThird) {
std::unique_ptr<WddmMockReserveAddress> wddmMockPtr(new WddmMockReserveAddress()); std::unique_ptr<WddmMockReserveAddress> wddm(new WddmMockReserveAddress());
WddmMockReserveAddress *wddmMock = wddmMockPtr.get();
size_t size = 0x1000; size_t size = 0x1000;
void *reserve = nullptr; void *reserve = nullptr;
bool ret = wddmMock->init<FamilyType>(); bool ret = wddm->init<FamilyType>();
EXPECT_TRUE(ret); EXPECT_TRUE(ret);
wddmMock->returnInvalidCount = 2; wddm->returnInvalidCount = 2;
ret = wddmMock->reserveValidAddressRange(size, reserve); ret = wddm->reserveValidAddressRange(size, reserve);
uintptr_t expectedReserve = wddmMock->virtualAllocAddress; uintptr_t expectedReserve = wddm->virtualAllocAddress;
EXPECT_TRUE(ret); EXPECT_TRUE(ret);
EXPECT_EQ(expectedReserve, reinterpret_cast<uintptr_t>(reserve)); EXPECT_EQ(expectedReserve, reinterpret_cast<uintptr_t>(reserve));
wddmMock->releaseReservedAddress(reserve); wddm->releaseReservedAddress(reserve);
} }
HWTEST_F(WddmReserveAddressTest, givenWddmWhenFirstIsInvalidSecondNullThenReturnSecondNull) { HWTEST_F(WddmReserveAddressTest, givenWddmWhenFirstIsInvalidSecondNullThenReturnSecondNull) {
std::unique_ptr<WddmMockReserveAddress> wddmMockPtr(new WddmMockReserveAddress()); std::unique_ptr<WddmMockReserveAddress> wddm(new WddmMockReserveAddress());
WddmMockReserveAddress *wddmMock = wddmMockPtr.get();
size_t size = 0x1000; size_t size = 0x1000;
void *reserve = nullptr; void *reserve = nullptr;
bool ret = wddmMock->init<FamilyType>(); bool ret = wddm->init<FamilyType>();
EXPECT_TRUE(ret); EXPECT_TRUE(ret);
wddmMock->returnInvalidCount = 2; wddm->returnInvalidCount = 2;
wddmMock->returnNullCount = 1; wddm->returnNullCount = 1;
uintptr_t expectedReserve = 0; uintptr_t expectedReserve = 0;
ret = wddmMock->reserveValidAddressRange(size, reserve); ret = wddm->reserveValidAddressRange(size, reserve);
EXPECT_FALSE(ret); EXPECT_FALSE(ret);
EXPECT_EQ(expectedReserve, reinterpret_cast<uintptr_t>(reserve)); EXPECT_EQ(expectedReserve, reinterpret_cast<uintptr_t>(reserve));
} }
HWTEST_F(WddmWithMockGdiTest, givenReadOnlyMemoryWhenCreateAllocationFailsWithNoVideoMemoryThenCorrectStatusIsReturned) { HWTEST_F(WddmTest, givenReadOnlyMemoryWhenCreateAllocationFailsWithNoVideoMemoryThenCorrectStatusIsReturned) {
class MockCreateAllocation { class MockCreateAllocation {
public: public:
static NTSTATUS APIENTRY mockCreateAllocation(D3DKMT_CREATEALLOCATION *param) { static NTSTATUS APIENTRY mockCreateAllocation(D3DKMT_CREATEALLOCATION *param) {
return STATUS_GRAPHICS_NO_VIDEO_MEMORY; return STATUS_GRAPHICS_NO_VIDEO_MEMORY;
}; };
}; };
Gdi *gdi = wddm->getGdi(); gdi.createAllocation = MockCreateAllocation::mockCreateAllocation;
gdi->createAllocation = MockCreateAllocation::mockCreateAllocation;
wddm->init<FamilyType>(); wddm->init<FamilyType>();
OsHandleStorage handleStorage; OsHandleStorage handleStorage;
@@ -1102,18 +1046,17 @@ HWTEST_F(WddmWithMockGdiTest, givenReadOnlyMemoryWhenCreateAllocationFailsWithNo
handleStorage.fragmentStorageData[0].freeTheFragment = false; handleStorage.fragmentStorageData[0].freeTheFragment = false;
handleStorage.fragmentStorageData[0].osHandleStorage = &handle; handleStorage.fragmentStorageData[0].osHandleStorage = &handle;
handleStorage.fragmentStorageData[0].residency = &residency; handleStorage.fragmentStorageData[0].residency = &residency;
handleStorage.fragmentStorageData[0].osHandleStorage->gmm = getGmm(nullptr, 0); handleStorage.fragmentStorageData[0].osHandleStorage->gmm = GmmHelperFunctions::getGmm(nullptr, 0);
NTSTATUS result = wddm->createAllocationsAndMapGpuVa(handleStorage); NTSTATUS result = wddm->createAllocationsAndMapGpuVa(handleStorage);
EXPECT_EQ(STATUS_GRAPHICS_NO_VIDEO_MEMORY, result); EXPECT_EQ(STATUS_GRAPHICS_NO_VIDEO_MEMORY, result);
releaseGmm(handleStorage.fragmentStorageData[0].osHandleStorage->gmm); delete handleStorage.fragmentStorageData[0].osHandleStorage->gmm;
} }
HWTEST_F(WddmTest, whenGetOsDeviceContextIsCalledThenWddmOsDeviceContextIsReturned) { HWTEST_F(WddmTest, whenGetOsDeviceContextIsCalledThenWddmOsDeviceContextIsReturned) {
std::unique_ptr<WddmMock> wddmMock(new WddmMock());
D3DKMT_HANDLE ctx = 0xc1; D3DKMT_HANDLE ctx = 0xc1;
wddmMock->context = ctx; wddm->context = ctx;
EXPECT_EQ(ctx, wddmMock->getOsDeviceContext()); EXPECT_EQ(ctx, wddm->getOsDeviceContext());
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2017, Intel Corporation * Copyright (c) 2017 - 2018, Intel Corporation
* *
* Permission is hereby granted, free of charge, to any person obtaining a * Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"), * copy of this software and associated documentation files (the "Software"),
@@ -31,57 +31,38 @@ using namespace OCLRT;
OsLibrary *setAdapterInfo(const PLATFORM *platform, const GT_SYSTEM_INFO *gtSystemInfo); OsLibrary *setAdapterInfo(const PLATFORM *platform, const GT_SYSTEM_INFO *gtSystemInfo);
typedef Test<WddmGmmFixture> WddmTest; typedef Test<WddmFixture> WddmTest;
typedef Test<WddmFixtureWithMockGdiDll> WddmTestWithMockGdiDll;
typedef Test<WddmInstrumentationGmmFixture> WddmInstrumentationTest; typedef Test<WddmInstrumentationGmmFixture> WddmInstrumentationTest;
typedef WddmDummyFixture WddmTestSingle; typedef ::testing::Test WddmTestSingle;
class WddmPreemptionTests : public WddmTest { class WddmPreemptionTests : public WddmTestWithMockGdiDll {
public: public:
void SetUp() override { void SetUp() override {
WddmTest::SetUp(); WddmTestWithMockGdiDll::SetUp();
const HardwareInfo hwInfo = *platformDevices[0]; const HardwareInfo hwInfo = *platformDevices[0];
memcpy(&hwInfoTest, &hwInfo, sizeof(hwInfoTest)); memcpy(&hwInfoTest, &hwInfo, sizeof(hwInfoTest));
dbgRestorer = new DebugManagerStateRestore(); dbgRestorer = new DebugManagerStateRestore();
} }
void TearDown() override { void TearDown() override {
if (mockWddm) {
delete mockWddm;
}
delete dbgRestorer; delete dbgRestorer;
WddmTest::TearDown(); WddmTestWithMockGdiDll::TearDown();
} }
template <typename GfxFamily> template <typename GfxFamily>
void createAndInitWddm(unsigned int forceReturnPreemptionRegKeyValue) { void createAndInitWddm(unsigned int forceReturnPreemptionRegKeyValue) {
mockWddm = new WddmMock(); wddm.reset(static_cast<WddmMock *>(Wddm::createWddm()));
auto regReader = new RegistryReaderMock(); auto regReader = new RegistryReaderMock();
mockWddm->registryReader.reset(regReader); wddm->registryReader.reset(regReader);
regReader->forceRetValue = forceReturnPreemptionRegKeyValue; regReader->forceRetValue = forceReturnPreemptionRegKeyValue;
PreemptionMode preemptionMode = PreemptionHelper::getDefaultPreemptionMode(hwInfoTest); PreemptionMode preemptionMode = PreemptionHelper::getDefaultPreemptionMode(hwInfoTest);
mockWddm->setPreemptionMode(preemptionMode); wddm->setPreemptionMode(preemptionMode);
mockWddm->init<GfxFamily>(); wddm->init<GfxFamily>();
} }
WddmMock *mockWddm = nullptr;
DebugManagerStateRestore *dbgRestorer = nullptr; DebugManagerStateRestore *dbgRestorer = nullptr;
HardwareInfo hwInfoTest; HardwareInfo hwInfoTest;
}; };
class WddmGmmMockGdiFixture : public GmmFixture, public WddmFixture {
public:
virtual void SetUp() {
GmmFixture::SetUp();
WddmFixture::SetUp(&gdi);
}
virtual void TearDown() {
WddmFixture::TearDown();
GmmFixture::TearDown();
}
MockGdi gdi;
};
typedef Test<WddmGmmMockGdiFixture> WddmWithMockGdiTest;