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}/execution_model_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_kernel_fixture.h
${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_os_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}/hw_info_config_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/hw_info_config_tests.h

View File

@@ -54,16 +54,17 @@
using namespace OCLRT;
using namespace ::testing;
class WddmCommandStreamFixture : public WddmFixtureMock {
class WddmCommandStreamFixture {
public:
DeviceCommandStreamReceiver<DEFAULT_TEST_FAMILY_NAME> *csr = nullptr;
MemoryManager *memManager = nullptr;
MockDevice *device = nullptr;
MockWddmMemoryManager *mockWddmMM = nullptr;
WddmMock *wddm = nullptr;
DebugManagerStateRestore stateRestore;
void SetUp() {
WddmFixtureMock::SetUp();
virtual void SetUp() {
wddm = static_cast<WddmMock *>(Wddm::createWddm());
ASSERT_NE(wddm, nullptr);
DebugManager.flags.CsrDispatchMode.set(static_cast<uint32_t>(DispatchMode::ImmediateDispatch));
@@ -82,28 +83,28 @@ class WddmCommandStreamFixture : public WddmFixtureMock {
ASSERT_NE(nullptr, memManager);
}
void TearDown() {
virtual void TearDown() {
mockWddmMM = nullptr;
delete csr->getTagAddress();
delete csr;
delete memManager;
delete device;
WddmFixtureMock::TearDown();
}
};
class WddmCommandStreamWithMockGdiFixture : public WddmFixture {
class WddmCommandStreamWithMockGdiFixture {
public:
DeviceCommandStreamReceiver<DEFAULT_TEST_FAMILY_NAME> *csr = nullptr;
MemoryManager *memManager = nullptr;
MockDevice *device = nullptr;
WddmMock *wddm = nullptr;
MockGdi gdi;
DebugManagerStateRestore stateRestore;
GraphicsAllocation *tagAllocation;
GraphicsAllocation *preemptionAllocation = nullptr;
void SetUp() {
WddmFixture::SetUp(&gdi);
virtual void SetUp() {
wddm = static_cast<WddmMock *>(Wddm::createWddm(&gdi));
ASSERT_NE(wddm, nullptr);
DebugManager.flags.CsrDispatchMode.set(static_cast<uint32_t>(DispatchMode::ImmediateDispatch));
csr = new WddmCommandStreamReceiver<DEFAULT_TEST_FAMILY_NAME>(*platformDevices[0], wddm);
@@ -124,7 +125,7 @@ class WddmCommandStreamWithMockGdiFixture : public WddmFixture {
tagBuffer[0] = initialHardwareTag;
}
void TearDown() {
virtual void TearDown() {
memManager->freeGraphicsMemory(tagAllocation);
if (preemptionAllocation) {
memManager->freeGraphicsMemory(preemptionAllocation);
@@ -134,7 +135,6 @@ class WddmCommandStreamWithMockGdiFixture : public WddmFixture {
delete memManager;
wddm = nullptr;
delete device;
WddmFixture::TearDown();
}
};
@@ -706,11 +706,11 @@ HWTEST_F(WddmCommandStreamMockGdiTest, givenRecordedCommandBufferWhenItIsSubmitt
//preemption allocation
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();
EXPECT_EQ(reinterpret_cast<uint64_t>(csrCommandStream->getUnderlyingBuffer()), mockWddm->submitResult.commandBufferSubmitted);
EXPECT_TRUE(((COMMAND_BUFFER_HEADER *)mockWddm->submitResult.commandHeaderSubmitted)->RequiresCoherency);
EXPECT_EQ(6u + csrSurfaceCount, mockWddm->makeResidentResult.handleCount);
EXPECT_EQ(reinterpret_cast<uint64_t>(csrCommandStream->getUnderlyingBuffer()), wddm->submitResult.commandBufferSubmitted);
EXPECT_TRUE(((COMMAND_BUFFER_HEADER *)wddm->submitResult.commandHeaderSubmitted)->RequiresCoherency);
EXPECT_EQ(6u + csrSurfaceCount, wddm->makeResidentResult.handleCount);
std::vector<D3DKMT_HANDLE> expectedHandles;
expectedHandles.push_back(((WddmAllocation *)tagAllocation)->handle);
@@ -720,8 +720,8 @@ HWTEST_F(WddmCommandStreamMockGdiTest, givenRecordedCommandBufferWhenItIsSubmitt
expectedHandles.push_back(((WddmAllocation *)sshAlloc)->handle);
expectedHandles.push_back(((WddmAllocation *)csrCommandStream)->handle);
for (auto i = 0u; i < mockWddm->makeResidentResult.handleCount; i++) {
auto handle = mockWddm->makeResidentResult.handlePack[i];
for (auto i = 0u; i < wddm->makeResidentResult.handleCount; i++) {
auto handle = wddm->makeResidentResult.handlePack[i];
auto found = false;
for (auto &expectedHandle : expectedHandles) {
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
#if defined(_WIN32)
#include "runtime/helpers/aligned_memory.h"
#include "runtime/helpers/hw_info.h"
#include "runtime/helpers/options.h"
@@ -30,10 +29,10 @@
#include "runtime/os_interface/windows/wddm.h"
#include "runtime/os_interface/windows/wddm_allocation.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 "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(disable : 4005)
#include <ntstatus.h>
@@ -114,6 +113,10 @@ class WddmMock : public Wddm {
virtualAllocAddress = OCLRT::windowsMinAddress;
}
~WddmMock() {
EXPECT_EQ(0, reservedAddresses.size());
}
bool makeResident(D3DKMT_HANDLE *handles, uint32_t count, bool cantTrimFurther, uint64_t *numberOfBytesToTrim) override {
makeResidentResult.called++;
makeResidentResult.handleCount = count;
@@ -396,113 +399,40 @@ class WddmMockReserveAddress : public WddmMock {
uint32_t returnNullIter;
};
class 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:
struct WddmFixture {
virtual void SetUp() {
const HardwareInfo hwInfo = *platformDevices[0];
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);
wddm.reset(static_cast<WddmMock *>(Wddm::createWddm(&gdi)));
}
virtual void SetUp(Gdi *gdi) {
mockGdiDll = nullptr;
wddm = Wddm::createWddm(gdi);
mockWddm = static_cast<WddmMock *>(wddm);
wddm->registryReader.reset(new RegistryReaderMock());
}
virtual void TearDown(){};
virtual void TearDown() {
if (wddm != nullptr) {
EXPECT_EQ(0, mockWddm->reservedAddresses.size());
delete wddm;
}
if (mockGdiDll != nullptr) {
if (setMapGpuVaFailConfigFcn != nullptr) {
setMapGpuVaFailConfigFcn(0, 0);
}
delete mockGdiDll;
}
}
std::unique_ptr<WddmMock> wddm;
MockGdi gdi;
};
class WddmFixtureMock {
protected:
WddmMock *wddm;
OsLibrary *mockGdiDll;
public:
virtual void SetUp() {
const HardwareInfo hwInfo = *platformDevices[0];
mockGdiDll = setAdapterInfo(hwInfo.pPlatform, hwInfo.pSysInfo);
wddm = new WddmMock();
struct WddmFixtureWithMockGdiDll : public GdiDllFixture {
void SetUp() override {
GdiDllFixture::SetUp();
wddm.reset(static_cast<WddmMock *>(Wddm::createWddm()));
}
virtual void TearDown() {
delete mockGdiDll;
void TearDown() override {
GdiDllFixture::TearDown();
}
std::unique_ptr<WddmMock> wddm;
};
class WddmGmmFixture : public GmmFixture, public WddmFixture {
public:
virtual void SetUp() {
GmmFixture::SetUp();
WddmFixture::SetUp();
}
virtual void TearDown() {
WddmFixture::TearDown();
GmmFixture::TearDown();
}
};
class WddmInstrumentationGmmFixture : public WddmGmmFixture {
public:
struct WddmInstrumentationGmmFixture {
virtual void SetUp() {
MockGmmMemory::MockGmmMemoryFlag = MockGmmMemory::MockType::MockInstrumentation;
WddmGmmFixture::SetUp();
wddm.reset(static_cast<WddmMock *>(Wddm::createWddm()));
gmmMem = static_cast<GmockGmmMemory *>(wddm->getGmmMemory());
}
virtual void TearDown() {
WddmGmmFixture::TearDown();
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;
void WddmMemoryManagerFixture::SetUp() {
WddmFixture::SetUp();
GdiDllFixture::SetUp();
wddm = static_cast<WddmMock *>(Wddm::createWddm());
ASSERT_NE(nullptr, wddm);
if (platformDevices[0]->capabilityTable.ftrCompression) {
GMM_DEVICE_CALLBACKS dummyDeviceCallbacks = {};
@@ -110,7 +111,7 @@ HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenCreateFromSharedHandle
void *pSysMem = reinterpret_cast<void *>(0x1000);
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 wddmAlloc = static_cast<WddmAllocation *>(gpuAllocation);
@@ -127,7 +128,7 @@ HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenCreateFromNTHandleIsCa
void *pSysMem = reinterpret_cast<void *>(0x1000);
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 wddmAlloc = static_cast<WddmAllocation *>(gpuAllocation);
@@ -144,12 +145,12 @@ HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenLockUnlockIsCalledThen
auto ptr = memoryManager->lockResource(alloc);
EXPECT_NE(nullptr, ptr);
EXPECT_EQ(1u, mockWddm->lockResult.called);
EXPECT_TRUE(mockWddm->lockResult.success);
EXPECT_EQ(1u, wddm->lockResult.called);
EXPECT_TRUE(wddm->lockResult.success);
memoryManager->unlockResource(alloc);
EXPECT_EQ(1u, mockWddm->unlockResult.called);
EXPECT_TRUE(mockWddm->unlockResult.success);
EXPECT_EQ(1u, wddm->unlockResult.called);
EXPECT_TRUE(wddm->unlockResult.success);
memoryManager->freeGraphicsMemory(alloc);
}
@@ -161,7 +162,7 @@ HWTEST_F(WddmMemoryManagerTest, createAllocationFromSharedHandleReturns32BitAllo
void *pSysMem = reinterpret_cast<void *>(0x1000);
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);
@@ -184,7 +185,7 @@ HWTEST_F(WddmMemoryManagerTest, createAllocationFromSharedHandleDoesNotReturn32B
void *pSysMem = reinterpret_cast<void *>(0x1000);
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);
@@ -207,7 +208,7 @@ HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenFreeAllocFromSharedHan
void *pSysMem = reinterpret_cast<void *>(0x1000);
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);
EXPECT_NE(nullptr, gpuAllocation);
@@ -229,7 +230,7 @@ HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerSizeZeroWhenCreateFromShar
void *pSysMem = reinterpret_cast<void *>(0x1000);
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);
ASSERT_NE(nullptr, gpuAllocation);
@@ -244,9 +245,9 @@ HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenCreateFromSharedHandle
void *pSysMem = reinterpret_cast<void *>(0x1000);
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);
EXPECT_EQ(nullptr, gpuAllocation);
@@ -255,7 +256,7 @@ HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenCreateFromSharedHandle
HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenTiledImageWithMipCountZeroIsBeingCreatedThenallocateGraphicsMemoryForImageIsUsed) {
SetUpMm<FamilyType>();
MockContext context;
context.setMemoryManager(memoryManager);
context.setMemoryManager(memoryManager.get());
cl_image_format imageFormat;
imageFormat.image_channel_data_type = CL_UNORM_INT8;
@@ -283,7 +284,7 @@ HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenTiledImageWithMipCount
HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenTiledImageWithMipCountNonZeroIsBeingCreatedThenallocateGraphicsMemoryForImageIsUsed) {
SetUpMm<FamilyType>();
MockContext context;
context.setMemoryManager(memoryManager);
context.setMemoryManager(memoryManager.get());
cl_image_format imageFormat;
imageFormat.image_channel_data_type = CL_UNORM_INT8;
@@ -313,7 +314,7 @@ HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenTiledImageWithMipCount
HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenTiledImageIsBeingCreatedFromHostPtrThenallocateGraphicsMemoryForImageIsUsed) {
SetUpMm<FamilyType>();
MockContext context;
context.setMemoryManager(memoryManager);
context.setMemoryManager(memoryManager.get());
cl_image_format imageFormat;
imageFormat.image_channel_data_type = CL_UNORM_INT8;
@@ -343,7 +344,7 @@ HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenTiledImageIsBeingCreat
HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenNonTiledImgWithMipCountZeroisBeingCreatedThenAllocateGraphicsMemoryIsUsed) {
SetUpMm<FamilyType>();
MockContext context;
context.setMemoryManager(memoryManager);
context.setMemoryManager(memoryManager.get());
cl_image_format imageFormat;
imageFormat.image_channel_data_type = CL_UNORM_INT8;
@@ -372,7 +373,7 @@ HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenNonTiledImgWithMipCoun
HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenNonTiledImgWithMipCountNonZeroisBeingCreatedThenAllocateGraphicsMemoryForImageIsUsed) {
SetUpMm<FamilyType>();
MockContext context;
context.setMemoryManager(memoryManager);
context.setMemoryManager(memoryManager.get());
cl_image_format imageFormat;
imageFormat.image_channel_data_type = CL_UNORM_INT8;
@@ -591,7 +592,7 @@ HWTEST_F(WddmMemoryManagerTest, GivenThreeOsHandlesWhenAskedForDestroyAllocation
auto destroyWithResourceHandleCalled = 0u;
D3DKMT_DESTROYALLOCATION2 *ptrToDestroyAlloc2 = nullptr;
getSizesFunction(destroyWithResourceHandleCalled, ptrToDestroyAlloc2);
getSizesFcn(destroyWithResourceHandleCalled, ptrToDestroyAlloc2);
EXPECT_EQ(0u, ptrToDestroyAlloc2->Flags.SynchronousDestroy);
EXPECT_EQ(1u, ptrToDestroyAlloc2->Flags.AssumeNotInUse);
@@ -616,13 +617,12 @@ HWTEST_F(WddmMemoryManagerTest, givenDefaultWddmMemoryManagerWhenAskedForAligned
HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenCpuMemNotMeetRestrictionsThenReserveMemRangeForMap) {
SetUpMm<FamilyType>();
WddmMock *mockWddm = static_cast<WddmMock *>(wddm);
void *cpuPtr = reinterpret_cast<void *>(memoryManager->getAlignedMallocRestrictions()->minAddress - 0x1000);
size_t size = 0x1000;
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);
EXPECT_EQ(expectReserve, allocation->getReservedAddress());
@@ -636,17 +636,12 @@ HWTEST_F(WddmMemoryManagerTest, givenManagerWithDisabledDeferredDeleterWhenMapGp
size_t size = 0x1000;
std::unique_ptr<Gmm> gmm(Gmm::create(ptr, size, false));
WddmMock *mockedWddm = new WddmMock;
EXPECT_TRUE(mockedWddm->init<FamilyType>());
MockWddmMemoryManager mockMemoryManager(mockedWddm);
mockMemoryManager.setDeferredDeleter(nullptr);
memoryManager->setDeferredDeleter(nullptr);
setMapGpuVaFailConfigFcn(0, 1);
WddmAllocation allocation(ptr, size, nullptr);
allocation.gmm = gmm.get();
bool ret = mockMemoryManager.createWddmAllocation(&allocation, MemoryType::EXTERNAL_ALLOCATION);
bool ret = memoryManager->createWddmAllocation(&allocation, MemoryType::EXTERNAL_ALLOCATION);
EXPECT_FALSE(ret);
}
@@ -656,18 +651,14 @@ HWTEST_F(WddmMemoryManagerTest, givenManagerWithEnabledDeferredDeleterWhenFirstM
size_t size = 0x1000;
std::unique_ptr<Gmm> gmm(Gmm::create(ptr, size, false));
WddmMock *mockedWddm = new WddmMock;
EXPECT_TRUE(mockedWddm->init<FamilyType>());
MockDeferredDeleter *deleter = new MockDeferredDeleter;
MockWddmMemoryManager mockMemoryManager(mockedWddm);
mockMemoryManager.setDeferredDeleter(deleter);
memoryManager->setDeferredDeleter(deleter);
setMapGpuVaFailConfigFcn(0, 1);
WddmAllocation allocation(ptr, size, nullptr);
allocation.gmm = gmm.get();
bool ret = mockMemoryManager.createWddmAllocation(&allocation, MemoryType::EXTERNAL_ALLOCATION);
bool ret = memoryManager->createWddmAllocation(&allocation, MemoryType::EXTERNAL_ALLOCATION);
EXPECT_TRUE(ret);
EXPECT_EQ(reinterpret_cast<uint64_t>(ptr), allocation.getGpuAddress());
}
@@ -678,18 +669,14 @@ HWTEST_F(WddmMemoryManagerTest, givenManagerWithEnabledDeferredDeleterWhenFirstA
size_t size = 0x1000;
std::unique_ptr<Gmm> gmm(Gmm::create(ptr, size, false));
WddmMock *mockedWddm = new WddmMock;
EXPECT_TRUE(mockedWddm->init<FamilyType>());
MockDeferredDeleter *deleter = new MockDeferredDeleter;
MockWddmMemoryManager mockMemoryManager(mockedWddm);
mockMemoryManager.setDeferredDeleter(deleter);
memoryManager->setDeferredDeleter(deleter);
setMapGpuVaFailConfigFcn(0, 2);
WddmAllocation allocation(ptr, size, nullptr);
allocation.gmm = gmm.get();
bool ret = mockMemoryManager.createWddmAllocation(&allocation, MemoryType::EXTERNAL_ALLOCATION);
bool ret = memoryManager->createWddmAllocation(&allocation, MemoryType::EXTERNAL_ALLOCATION);
EXPECT_FALSE(ret);
}
@@ -955,9 +942,8 @@ HWTEST_F(WddmMemoryManagerResidencyTest, makeResidentResidencyAllocationsUpdates
HWTEST_F(WddmMemoryManagerResidencyTest, makeResidentResidencyAllocationsMarksTripleAllocationsResident) {
SetUpMm<FamilyType>();
WddmMock *mockWddm = static_cast<WddmMock *>(wddm);
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);
@@ -1000,7 +986,7 @@ HWTEST_F(WddmMemoryManagerResidencyTest, makeResidentResidencyAllocationsSetsLas
HWTEST_F(WddmMemoryManagerResidencyTest, trimCallbackIsRegisteredInWddmMemoryManagerCtor) {
SetUpMm<FamilyType>();
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);
}
@@ -1020,7 +1006,7 @@ HWTEST_F(WddmMemoryManagerResidencyTest, givenNotUsedAllocationsFromPreviousPeri
// Set current fence value to greater value
wddm->getMonitoredFence().currentFenceValue = 20;
mockWddm->makeNonResidentResult.called = 0;
wddm->makeNonResidentResult.called = 0;
memoryManager->trimCandidateList.resize(0);
@@ -1030,7 +1016,7 @@ HWTEST_F(WddmMemoryManagerResidencyTest, givenNotUsedAllocationsFromPreviousPeri
memoryManager->trimResidency(trimNotification.Flags, trimNotification.NumBytesToTrim);
// 2 allocations evicted
EXPECT_EQ(2u, mockWddm->makeNonResidentResult.called);
EXPECT_EQ(2u, wddm->makeNonResidentResult.called);
// removed from trim candidate list
EXPECT_EQ(0u, memoryManager->trimCandidateList.size());
// marked nonresident
@@ -1056,7 +1042,7 @@ HWTEST_F(WddmMemoryManagerResidencyTest, givenOneUsedAllocationFromPreviousPerio
// Set current fence value to greater value
wddm->getMonitoredFence().currentFenceValue = 20;
mockWddm->makeNonResidentResult.called = 0;
wddm->makeNonResidentResult.called = 0;
memoryManager->trimCandidateList.resize(0);
@@ -1066,7 +1052,7 @@ HWTEST_F(WddmMemoryManagerResidencyTest, givenOneUsedAllocationFromPreviousPerio
memoryManager->trimResidency(trimNotification.Flags, trimNotification.NumBytesToTrim);
// 1 allocation evicted
EXPECT_EQ(1u, mockWddm->makeNonResidentResult.called);
EXPECT_EQ(1u, wddm->makeNonResidentResult.called);
// removed from trim candidate list
EXPECT_EQ(trimListUnusedPosition, allocation1.getTrimCandidateListPosition());
@@ -1078,11 +1064,10 @@ HWTEST_F(WddmMemoryManagerResidencyTest, givenOneUsedAllocationFromPreviousPerio
HWTEST_F(WddmMemoryManagerResidencyTest, givenTripleAllocationWithUsedAndUnusedFragmentsSincePreviousTrimWhenTrimResidencyPeriodicTrimIsCalledThenProperFragmentsAreEvictedAndMarked) {
SetUpMm<FamilyType>();
WddmMock *mockWddm = static_cast<WddmMock *>(wddm);
D3DKMT_TRIMNOTIFICATION trimNotification = {0};
trimNotification.Flags.PeriodicTrim = 1;
trimNotification.NumBytesToTrim = 0;
void *ptr = reinterpret_cast<void *>(mockWddm->virtualAllocAddress + 0x1500);
void *ptr = reinterpret_cast<void *>(wddm->virtualAllocAddress + 0x1500);
// 3-fragment Allocation
WddmAllocation *allocationTriple = (WddmAllocation *)memoryManager->allocateGraphicsMemory(8196, ptr);
// whole allocation unused since previous trim
@@ -1103,7 +1088,7 @@ HWTEST_F(WddmMemoryManagerResidencyTest, givenTripleAllocationWithUsedAndUnusedF
// Set current fence value to greater value
wddm->getMonitoredFence().currentFenceValue = 20;
mockWddm->makeNonResidentResult.called = 0;
wddm->makeNonResidentResult.called = 0;
memoryManager->trimCandidateList.resize(0);
@@ -1112,7 +1097,7 @@ HWTEST_F(WddmMemoryManagerResidencyTest, givenTripleAllocationWithUsedAndUnusedF
memoryManager->trimResidency(trimNotification.Flags, trimNotification.NumBytesToTrim);
// 2 fragments evicted with one call
EXPECT_EQ(1u, mockWddm->makeNonResidentResult.called);
EXPECT_EQ(1u, wddm->makeNonResidentResult.called);
// marked nonresident
EXPECT_FALSE(allocationTriple->fragmentsStorage.fragmentStorageData[0].residency->resident);
EXPECT_FALSE(allocationTriple->fragmentsStorage.fragmentStorageData[2].residency->resident);
@@ -1179,7 +1164,7 @@ HWTEST_F(WddmMemoryManagerResidencyTest, trimToBudgetAllDoneAllocations) {
wddm->getMonitoredFence().lastSubmittedFence = 1;
wddm->getMonitoredFence().currentFenceValue = 1;
mockWddm->makeNonResidentResult.called = 0;
wddm->makeNonResidentResult.called = 0;
memoryManager->trimCandidateList.resize(0);
@@ -1189,7 +1174,7 @@ HWTEST_F(WddmMemoryManagerResidencyTest, trimToBudgetAllDoneAllocations) {
memoryManager->trimResidencyToBudget(3 * 4096);
EXPECT_EQ(2u, mockWddm->makeNonResidentResult.called);
EXPECT_EQ(2u, wddm->makeNonResidentResult.called);
EXPECT_EQ(1u, memoryManager->trimCandidatesCount);
memoryManager->compactTrimCandidateList();
@@ -1211,14 +1196,14 @@ HWTEST_F(WddmMemoryManagerResidencyTest, trimToBudgetReturnsFalseWhenNumBytesToT
*wddm->getMonitoredFence().cpuAddress = 1;
wddm->getMonitoredFence().lastSubmittedFence = 1;
mockWddm->makeNonResidentResult.called = 0;
wddm->makeNonResidentResult.called = 0;
memoryManager->trimCandidateList.resize(0);
memoryManager->addToTrimCandidateList(&allocation1);
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_FALSE(status);
@@ -1243,7 +1228,7 @@ HWTEST_F(WddmMemoryManagerResidencyTest, trimToBudgetStopsEvictingWhenNumBytesTo
wddm->getMonitoredFence().lastSubmittedFence = 1;
wddm->getMonitoredFence().currentFenceValue = 1;
mockWddm->makeNonResidentResult.called = 0;
wddm->makeNonResidentResult.called = 0;
memoryManager->trimCandidateList.resize(0);
@@ -1254,7 +1239,7 @@ HWTEST_F(WddmMemoryManagerResidencyTest, trimToBudgetStopsEvictingWhenNumBytesTo
bool status = memoryManager->trimResidencyToBudget(3 * 4096);
EXPECT_TRUE(status);
EXPECT_EQ(2u, mockWddm->makeNonResidentResult.called);
EXPECT_EQ(2u, wddm->makeNonResidentResult.called);
EXPECT_EQ(1u, memoryManager->trimCandidateList.size());
EXPECT_EQ(trimListUnusedPosition, allocation1.getTrimCandidateListPosition());
@@ -1280,7 +1265,7 @@ HWTEST_F(WddmMemoryManagerResidencyTest, trimToBudgetMarksEvictedAllocationNonRe
wddm->getMonitoredFence().lastSubmittedFence = 1;
wddm->getMonitoredFence().currentFenceValue = 1;
mockWddm->makeNonResidentResult.called = 0;
wddm->makeNonResidentResult.called = 0;
memoryManager->trimCandidateList.resize(0);
@@ -1307,8 +1292,8 @@ HWTEST_F(WddmMemoryManagerResidencyTest, trimToBudgetWaitsFromCpuWhenLastFenceIs
wddm->getMonitoredFence().lastSubmittedFence = 2;
wddm->getMonitoredFence().currentFenceValue = 3;
mockWddm->makeNonResidentResult.called = 0;
mockWddm->waitFromCpuResult.called = 0;
wddm->makeNonResidentResult.called = 0;
wddm->waitFromCpuResult.called = 0;
memoryManager->trimCandidateList.resize(0);
@@ -1318,17 +1303,16 @@ HWTEST_F(WddmMemoryManagerResidencyTest, trimToBudgetWaitsFromCpuWhenLastFenceIs
bool status = memoryManager->trimResidencyToBudget(3 * 4096);
EXPECT_EQ(1u, mockWddm->makeNonResidentResult.called);
EXPECT_EQ(1u, wddm->makeNonResidentResult.called);
EXPECT_FALSE(allocation1.getResidencyData().resident);
EXPECT_EQ(mockWddm->getDevice(), gdi.getWaitFromCpuArg().hDevice);
EXPECT_EQ(wddm->getDevice(), gdi.getWaitFromCpuArg().hDevice);
}
HWTEST_F(WddmMemoryManagerResidencyTest, trimToBudgetEvictsDoneFragmentsOnly) {
SetUpMm<FamilyType>();
WddmMock *mockWddm = static_cast<WddmMock *>(wddm);
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 allocation2(ptr, 0x1000, ptr, 0x1000, nullptr);
allocation1.getResidencyData().resident = true;
@@ -1363,11 +1347,11 @@ HWTEST_F(WddmMemoryManagerResidencyTest, trimToBudgetEvictsDoneFragmentsOnly) {
wddm->getMonitoredFence().lastSubmittedFence = 1;
wddm->getMonitoredFence().currentFenceValue = 2;
mockWddm->makeNonResidentResult.called = 0;
wddm->makeNonResidentResult.called = 0;
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_TRUE(allocationTriple->fragmentsStorage.fragmentStorageData[1].residency->resident);
@@ -1402,7 +1386,6 @@ HWTEST_F(WddmMemoryManagerResidencyTest, checkTrimCandidateListCompaction) {
HWTEST_F(WddmMemoryManagerResidencyTest, givenThreeAllocationsAlignedSizeBiggerThanAllocSizeWhenBudgetEqualTwoAlignedAllocationThenEvictOnlyTwo) {
SetUpMm<FamilyType>();
WddmMock *mockWddm = static_cast<WddmMock *>(wddm);
gdi.setNonZeroNumBytesToTrimInEvict();
size_t underlyingSize = 0xF00;
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
EXPECT_GT((3 * underlyingSize), budget);
EXPECT_LT((2 * underlyingSize), budget);
void *ptr1 = reinterpret_cast<void *>(mockWddm->virtualAllocAddress + 0x1000);
void *ptr2 = reinterpret_cast<void *>(mockWddm->virtualAllocAddress + 0x3000);
void *ptr3 = reinterpret_cast<void *>(mockWddm->virtualAllocAddress + 0x5000);
void *ptr1 = reinterpret_cast<void *>(wddm->virtualAllocAddress + 0x1000);
void *ptr2 = reinterpret_cast<void *>(wddm->virtualAllocAddress + 0x3000);
void *ptr3 = reinterpret_cast<void *>(wddm->virtualAllocAddress + 0x5000);
WddmAllocation allocation1(ptr1, underlyingSize, ptr1, alignedSize, nullptr);
WddmAllocation allocation2(ptr2, underlyingSize, ptr2, alignedSize, nullptr);
@@ -1432,7 +1415,7 @@ HWTEST_F(WddmMemoryManagerResidencyTest, givenThreeAllocationsAlignedSizeBiggerT
wddm->getMonitoredFence().lastSubmittedFence = 1;
wddm->getMonitoredFence().currentFenceValue = 1;
mockWddm->makeNonResidentResult.called = 0;
wddm->makeNonResidentResult.called = 0;
memoryManager->trimCandidateList.resize(0);
@@ -1489,8 +1472,7 @@ HWTEST_F(BufferWithWddmMemory, NullOsHandleStorageAskedForPopulationReturnsFille
HWTEST_F(BufferWithWddmMemory, GivenMisalignedHostPtrAndMultiplePagesSizeWhenAskedForGraphicsAllcoationThenItContainsAllFragmentsWithProperGpuAdrresses) {
SetUpMm<FamilyType>();
WddmMock *mockWddm = static_cast<WddmMock *>(wddm);
auto ptr = reinterpret_cast<void *>(mockWddm->virtualAllocAddress + 0x1001);
auto ptr = reinterpret_cast<void *>(wddm->virtualAllocAddress + 0x1001);
auto size = MemoryConstants::pageSize * 10;
auto graphicsAllocation = memoryManager->allocateGraphicsMemory(size, ptr);
@@ -1519,11 +1501,10 @@ HWTEST_F(BufferWithWddmMemory, GivenMisalignedHostPtrAndMultiplePagesSizeWhenAsk
HWTEST_F(BufferWithWddmMemory, GivenPointerAndSizeWhenAskedToCreateGrahicsAllocationThenGraphicsAllocationIsCreated) {
SetUpMm<FamilyType>();
WddmMock *mockWddm = static_cast<WddmMock *>(wddm);
OsHandleStorage handleStorage;
auto ptr = reinterpret_cast<void *>(mockWddm->virtualAllocAddress + 0x1000);
auto ptr2 = reinterpret_cast<void *>(mockWddm->virtualAllocAddress + 0x1001);
auto ptr = reinterpret_cast<void *>(wddm->virtualAllocAddress + 0x1000);
auto ptr2 = reinterpret_cast<void *>(wddm->virtualAllocAddress + 0x1001);
auto size = MemoryConstants::pageSize;
handleStorage.fragmentStorageData[0].cpuPtr = ptr;

View File

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

View File

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