Move MockWddm body to WddmMock

This commit cleans the code after previously removed GMock from the
MockWddm(GmockWddm) class by merging MockWddm class into WddmMock.

Signed-off-by: Fabian Zwolinski <fabian.zwolinski@intel.com>
This commit is contained in:
Fabian Zwolinski 2022-01-11 10:00:36 +01:00 committed by Compute-Runtime-Automation
parent 37c78b9ef7
commit 44ebe800df
9 changed files with 131 additions and 162 deletions

View File

@ -801,6 +801,7 @@ TEST_F(WddmCommandStreamMockGdiTest, WhenFlushingThenWddmMakeResidentIsCalledFor
ASSERT_NE(nullptr, commandBuffer);
LinearStream cs(commandBuffer);
wddm->callBaseMakeResident = true;
csr->makeResident(*commandBuffer);
EXPECT_EQ(1u, csr->getResidencyAllocations().size());
@ -1137,6 +1138,7 @@ TEST_F(WddmCommandStreamTest, givenResidencyLoggingAvailableWhenFlushingCommandB
NEO::IoFunctions::mockFcloseCalled = 0u;
wddm->createPagingFenceLogger();
wddm->callBaseMakeResident = true;
EXPECT_EQ(1u, NEO::IoFunctions::mockFopenCalled);
EXPECT_EQ(1u, NEO::IoFunctions::mockVfptrinfCalled);

View File

@ -683,6 +683,7 @@ TEST_F(Wddm20Tests, GivenMultipleHandlesWhenMakingResidentThenAllocationListIsCo
D3DKMT_HANDLE handles[2] = {ALLOCATION_HANDLE, ALLOCATION_HANDLE};
gdi->getMakeResidentArg().NumAllocations = 0;
gdi->getMakeResidentArg().AllocationList = nullptr;
wddm->callBaseMakeResident = true;
bool error = wddm->makeResident(handles, 2, false, nullptr, 0x1000);
EXPECT_TRUE(error);
@ -697,6 +698,7 @@ TEST_F(Wddm20Tests, GivenMultipleHandlesWhenMakingResidentThenBytesToTrimIsCorre
gdi->getMakeResidentArg().NumAllocations = 0;
gdi->getMakeResidentArg().AllocationList = nullptr;
gdi->getMakeResidentArg().NumBytesToTrim = 30;
wddm->callBaseMakeResident = true;
uint64_t bytesToTrim = 0;
bool success = wddm->makeResident(handles, 2, false, &bytesToTrim, 0x1000);
@ -713,6 +715,7 @@ TEST_F(Wddm20Tests, WhenMakingNonResidentThenEvictIsCalled) {
gdi->getEvictArg().hDevice = 0;
gdi->getEvictArg().NumAllocations = 0;
gdi->getEvictArg().NumBytesToTrim = 20;
wddm->callBaseEvict = true;
uint64_t sizeToTrim = 10;
wddm->evict(&handle, 1, sizeToTrim);
@ -918,7 +921,7 @@ TEST_F(WddmLockWithMakeResidentTests, givenAllocationThatDoesntNeedMakeResidentB
TEST_F(WddmLockWithMakeResidentTests, givenAllocationThatNeedsMakeResidentBeforeLockWhenLockThenCallBlockingMakeResident) {
wddm->lockResource(ALLOCATION_HANDLE, true, 0x1000);
EXPECT_EQ(1u, mockTemporaryResources->makeResidentResult.called);
EXPECT_EQ(1u, wddm->makeResidentResult.called);
}
TEST_F(WddmLockWithMakeResidentTests, givenAllocationWhenApplyBlockingMakeResidentThenAcquireUniqueLock) {
@ -934,6 +937,7 @@ TEST_F(WddmLockWithMakeResidentTests, givenAllocationWhenApplyBlockingMakeReside
}
TEST_F(WddmLockWithMakeResidentTests, givenAllocationWhenApplyBlockingMakeResidentThenWaitForCurrentPagingFenceValue) {
wddm->callBaseMakeResident = true;
wddm->mockPagingFence = 0u;
wddm->temporaryResources->makeResidentResource(ALLOCATION_HANDLE, 0x1000);
UINT64 expectedCallNumber = NEO::wddmResidencyLoggingAvailable ? MockGdi::pagingFenceReturnValue + 1 : 0ull;
@ -945,48 +949,48 @@ TEST_F(WddmLockWithMakeResidentTests, givenAllocationWhenApplyBlockingMakeReside
TEST_F(WddmLockWithMakeResidentTests, givenAllocationWhenApplyBlockingMakeResidentAndMakeResidentCallFailsThenEvictTemporaryResourcesAndRetry) {
MockWddmAllocation allocation(rootDeviceEnvironment->getGmmClientContext());
allocation.handle = 0x3;
MockWddm mockWddm(*executionEnvironment->rootDeviceEnvironments[0]);
mockWddm.makeResidentResult = false;
WddmMock mockWddm(*executionEnvironment->rootDeviceEnvironments[0]);
mockWddm.makeResidentStatus = false;
auto mockTemporaryResources = static_cast<MockWddmResidentAllocationsContainer *>(mockWddm.temporaryResources.get());
mockWddm.temporaryResources->makeResidentResource(allocation.handle, 0x1000);
EXPECT_EQ(1u, mockTemporaryResources->evictAllResourcesResult.called);
EXPECT_EQ(allocation.handle, mockWddm.makeResidentParamsPassed[0].handles[0]);
EXPECT_EQ(2u, mockWddm.makeResidentCalled);
EXPECT_EQ(allocation.handle, mockWddm.makeResidentResult.handlePack[0]);
EXPECT_EQ(2u, mockWddm.makeResidentResult.called);
}
TEST_F(WddmLockWithMakeResidentTests, whenApplyBlockingMakeResidentAndTemporaryResourcesAreEvictedSuccessfullyThenCallMakeResidentOneMoreTime) {
MockWddmAllocation allocation(rootDeviceEnvironment->getGmmClientContext());
allocation.handle = 0x3;
MockWddm mockWddm(*executionEnvironment->rootDeviceEnvironments[0]);
mockWddm.makeResidentResult = false;
WddmMock mockWddm(*executionEnvironment->rootDeviceEnvironments[0]);
mockWddm.makeResidentStatus = false;
auto mockTemporaryResources = static_cast<MockWddmResidentAllocationsContainer *>(mockWddm.temporaryResources.get());
mockTemporaryResources->resourceHandles.push_back(allocation.handle);
mockWddm.temporaryResources->makeResidentResource(allocation.handle, 0x1000);
EXPECT_EQ(2u, mockTemporaryResources->evictAllResourcesResult.called);
EXPECT_EQ(1u, mockWddm.evictCalled);
EXPECT_EQ(allocation.handle, mockWddm.makeResidentParamsPassed[0].handles[0]);
EXPECT_EQ(3u, mockWddm.makeResidentCalled);
EXPECT_EQ(1u, mockWddm.evictResult.called);
EXPECT_EQ(allocation.handle, mockWddm.makeResidentResult.handlePack[0]);
EXPECT_EQ(3u, mockWddm.makeResidentResult.called);
}
TEST_F(WddmLockWithMakeResidentTests, whenApplyBlockingMakeResidentAndMakeResidentStillFailsThenDontStoreTemporaryResource) {
MockWddmAllocation allocation(rootDeviceEnvironment->getGmmClientContext());
allocation.handle = 0x2;
MockWddm mockWddm(*executionEnvironment->rootDeviceEnvironments[0]);
mockWddm.makeResidentResult = false;
WddmMock mockWddm(*executionEnvironment->rootDeviceEnvironments[0]);
mockWddm.makeResidentStatus = false;
auto mockTemporaryResources = static_cast<MockWddmResidentAllocationsContainer *>(mockWddm.temporaryResources.get());
mockTemporaryResources->resourceHandles.push_back(0x1);
EXPECT_EQ(1u, mockTemporaryResources->resourceHandles.size());
mockWddm.temporaryResources->makeResidentResource(allocation.handle, 0x1000);
EXPECT_EQ(0u, mockTemporaryResources->resourceHandles.size());
EXPECT_EQ(1u, mockWddm.evictCalled);
EXPECT_EQ(allocation.handle, mockWddm.makeResidentParamsPassed[0].handles[0]);
EXPECT_EQ(3u, mockWddm.makeResidentCalled);
EXPECT_EQ(1u, mockWddm.evictResult.called);
EXPECT_EQ(allocation.handle, mockWddm.makeResidentResult.handlePack[0]);
EXPECT_EQ(3u, mockWddm.makeResidentResult.called);
}
TEST_F(WddmLockWithMakeResidentTests, whenApplyBlockingMakeResidentAndMakeResidentPassesAfterEvictThenStoreTemporaryResource) {
MockWddmAllocation allocation(rootDeviceEnvironment->getGmmClientContext());
allocation.handle = 0x2;
MockWddm mockWddm(*executionEnvironment->rootDeviceEnvironments[0]);
WddmMock mockWddm(*executionEnvironment->rootDeviceEnvironments[0]);
mockWddm.makeResidentResults = {false, true};
auto mockTemporaryResources = static_cast<MockWddmResidentAllocationsContainer *>(mockWddm.temporaryResources.get());
mockTemporaryResources->resourceHandles.push_back(0x1);
@ -994,22 +998,22 @@ TEST_F(WddmLockWithMakeResidentTests, whenApplyBlockingMakeResidentAndMakeReside
mockWddm.temporaryResources->makeResidentResource(allocation.handle, 0x1000);
EXPECT_EQ(1u, mockTemporaryResources->resourceHandles.size());
EXPECT_EQ(0x2, mockTemporaryResources->resourceHandles.back());
EXPECT_EQ(1u, mockWddm.evictCalled);
EXPECT_EQ(allocation.handle, mockWddm.makeResidentParamsPassed[0].handles[0]);
EXPECT_EQ(2u, mockWddm.makeResidentCalled);
EXPECT_EQ(1u, mockWddm.evictResult.called);
EXPECT_EQ(allocation.handle, mockWddm.makeResidentResult.handlePack[0]);
EXPECT_EQ(2u, mockWddm.makeResidentResult.called);
}
TEST_F(WddmLockWithMakeResidentTests, whenApplyBlockingMakeResidentAndMakeResidentPassesThenStoreTemporaryResource) {
MockWddmAllocation allocation(rootDeviceEnvironment->getGmmClientContext());
allocation.handle = 0x2;
MockWddm mockWddm(*executionEnvironment->rootDeviceEnvironments[0]);
WddmMock mockWddm(*executionEnvironment->rootDeviceEnvironments[0]);
auto mockTemporaryResources = static_cast<MockWddmResidentAllocationsContainer *>(mockWddm.temporaryResources.get());
mockTemporaryResources->resourceHandles.push_back(0x1);
mockWddm.temporaryResources->makeResidentResource(allocation.handle, 0x1000);
EXPECT_EQ(2u, mockTemporaryResources->resourceHandles.size());
EXPECT_EQ(0x2, mockTemporaryResources->resourceHandles.back());
EXPECT_EQ(allocation.handle, mockWddm.makeResidentParamsPassed[0].handles[0]);
EXPECT_EQ(1u, mockWddm.makeResidentCalled);
EXPECT_EQ(allocation.handle, mockWddm.makeResidentResult.handlePack[0]);
EXPECT_EQ(1u, mockWddm.makeResidentResult.called);
}
TEST_F(WddmLockWithMakeResidentTests, givenNoTemporaryResourcesWhenEvictingAllTemporaryResourcesThenEvictionIsNotApplied) {
@ -1025,17 +1029,17 @@ TEST_F(WddmLockWithMakeResidentTests, whenEvictingAllTemporaryResourcesThenAcqui
TEST_F(WddmLockWithMakeResidentTests, whenEvictingAllTemporaryResourcesAndAllEvictionsSucceedThenReturnSuccess) {
MockWddmAllocation allocation(rootDeviceEnvironment->getGmmClientContext());
MockWddm mockWddm(*executionEnvironment->rootDeviceEnvironments[0]);
WddmMock mockWddm(*executionEnvironment->rootDeviceEnvironments[0]);
auto mockTemporaryResources = static_cast<MockWddmResidentAllocationsContainer *>(mockWddm.temporaryResources.get());
mockTemporaryResources->resourceHandles.push_back(allocation.handle);
mockWddm.getTemporaryResourcesContainer()->evictAllResources();
EXPECT_EQ(1u, mockTemporaryResources->evictAllResourcesResult.called);
EXPECT_EQ(MemoryOperationsStatus::SUCCESS, mockTemporaryResources->evictAllResourcesResult.operationSuccess);
EXPECT_EQ(1u, mockWddm.evictCalled);
EXPECT_EQ(1u, mockWddm.evictResult.called);
}
TEST_F(WddmLockWithMakeResidentTests, givenThreeAllocationsWhenEvictingAllTemporaryResourcesThenCallEvictForEachAllocationAndCleanList) {
MockWddm mockWddm(*executionEnvironment->rootDeviceEnvironments[0]);
WddmMock mockWddm(*executionEnvironment->rootDeviceEnvironments[0]);
auto mockTemporaryResources = static_cast<MockWddmResidentAllocationsContainer *>(mockWddm.temporaryResources.get());
constexpr uint32_t numAllocations = 3u;
for (auto i = 0u; i < numAllocations; i++) {
@ -1043,12 +1047,12 @@ TEST_F(WddmLockWithMakeResidentTests, givenThreeAllocationsWhenEvictingAllTempor
}
mockWddm.getTemporaryResourcesContainer()->evictAllResources();
EXPECT_TRUE(mockTemporaryResources->resourceHandles.empty());
EXPECT_EQ(1u, mockWddm.evictCalled);
EXPECT_EQ(1u, mockWddm.evictResult.called);
}
TEST_F(WddmLockWithMakeResidentTests, givenThreeAllocationsWhenEvictingAllTemporaryResourcesAndOneOfThemFailsThenReturnFail) {
MockWddm mockWddm(*executionEnvironment->rootDeviceEnvironments[0].get());
mockWddm.evictResult = false;
WddmMock mockWddm(*executionEnvironment->rootDeviceEnvironments[0].get());
mockWddm.evictStatus = false;
auto mockTemporaryResources = static_cast<MockWddmResidentAllocationsContainer *>(mockWddm.temporaryResources.get());
constexpr uint32_t numAllocations = 3u;
for (auto i = 0u; i < numAllocations; i++) {
@ -1056,7 +1060,7 @@ TEST_F(WddmLockWithMakeResidentTests, givenThreeAllocationsWhenEvictingAllTempor
}
mockWddm.getTemporaryResourcesContainer()->evictAllResources();
EXPECT_EQ(MemoryOperationsStatus::FAILED, mockTemporaryResources->evictAllResourcesResult.operationSuccess);
EXPECT_EQ(1u, mockWddm.evictCalled);
EXPECT_EQ(1u, mockWddm.evictResult.called);
}
TEST_F(WddmLockWithMakeResidentTests, givenNoTemporaryResourcesWhenEvictingTemporaryResourceThenEvictionIsNotApplied) {
@ -1079,24 +1083,24 @@ TEST_F(WddmLockWithMakeResidentTests, whenEvictingNonExistingTemporaryResourceTh
}
TEST_F(WddmLockWithMakeResidentTests, whenEvictingTemporaryResourceAndEvictFailsThenReturnFail) {
MockWddm mockWddm(*executionEnvironment->rootDeviceEnvironments[0]);
mockWddm.evictResult = false;
WddmMock mockWddm(*executionEnvironment->rootDeviceEnvironments[0]);
mockWddm.evictStatus = false;
auto mockTemporaryResources = static_cast<MockWddmResidentAllocationsContainer *>(mockWddm.temporaryResources.get());
mockTemporaryResources->resourceHandles.push_back(ALLOCATION_HANDLE);
mockWddm.getTemporaryResourcesContainer()->evictResource(ALLOCATION_HANDLE);
EXPECT_TRUE(mockTemporaryResources->resourceHandles.empty());
EXPECT_EQ(MemoryOperationsStatus::FAILED, mockTemporaryResources->evictResourceResult.operationSuccess);
EXPECT_EQ(1u, mockWddm.evictCalled);
EXPECT_EQ(1u, mockWddm.evictResult.called);
}
TEST_F(WddmLockWithMakeResidentTests, whenEvictingTemporaryResourceAndEvictSucceedThenReturnSuccess) {
MockWddm mockWddm(*executionEnvironment->rootDeviceEnvironments[0]);
WddmMock mockWddm(*executionEnvironment->rootDeviceEnvironments[0]);
auto mockTemporaryResources = static_cast<MockWddmResidentAllocationsContainer *>(mockWddm.temporaryResources.get());
mockTemporaryResources->resourceHandles.push_back(ALLOCATION_HANDLE);
mockWddm.getTemporaryResourcesContainer()->evictResource(ALLOCATION_HANDLE);
EXPECT_TRUE(mockTemporaryResources->resourceHandles.empty());
EXPECT_EQ(MemoryOperationsStatus::SUCCESS, mockTemporaryResources->evictResourceResult.operationSuccess);
EXPECT_EQ(1u, mockWddm.evictCalled);
EXPECT_EQ(1u, mockWddm.evictResult.called);
}
TEST_F(WddmLockWithMakeResidentTests, whenEvictingTemporaryResourceThenOtherResourcesRemainOnTheList) {
@ -1428,6 +1432,7 @@ TEST_F(WddmTest, GivenResidencyLoggingEnabledWhenMakeResidentSuccessThenExpectSi
DebugManagerStateRestore dbgRestore;
DebugManager.flags.WddmResidencyLogger.set(true);
wddm->callBaseCreatePagingLogger = false;
wddm->callBaseMakeResident = true;
wddm->createPagingFenceLogger();
EXPECT_NE(nullptr, wddm->residencyLogger.get());
@ -1454,6 +1459,7 @@ TEST_F(WddmTest, GivenResidencyLoggingEnabledWhenMakeResidentFailThenExpectTrimR
DebugManagerStateRestore dbgRestore;
DebugManager.flags.WddmResidencyLogger.set(true);
wddm->callBaseCreatePagingLogger = false;
wddm->callBaseMakeResident = true;
wddm->createPagingFenceLogger();
EXPECT_NE(nullptr, wddm->residencyLogger.get());
@ -1499,6 +1505,7 @@ TEST_F(WddmTest, GivenResidencyLoggingEnabledWhenMakeResidentAndWaitPagingThenEx
DebugManagerStateRestore dbgRestore;
DebugManager.flags.WddmResidencyLogger.set(true);
wddm->callBaseCreatePagingLogger = false;
wddm->callBaseMakeResident = true;
wddm->createPagingFenceLogger();
EXPECT_NE(nullptr, wddm->residencyLogger.get());

View File

@ -2116,7 +2116,8 @@ TEST_F(WddmMemoryManagerTest2, givenReadOnlyMemoryWhenCreateAllocationFailsThenP
handleStorage.fragmentStorageData[0].fragmentSize = 0x1000;
handleStorage.fragmentStorageData[0].freeTheFragment = false;
wddm->createAllocationsAndMapGpuVaResult = STATUS_GRAPHICS_NO_VIDEO_MEMORY;
wddm->callBaseCreateAllocationsAndMapGpuVa = false;
wddm->createAllocationsAndMapGpuVaStatus = STATUS_GRAPHICS_NO_VIDEO_MEMORY;
auto result = memoryManager->populateOsHandles(handleStorage, 0);
@ -2136,7 +2137,8 @@ TEST_F(WddmMemoryManagerTest2, givenReadOnlyMemoryPassedToPopulateOsHandlesWhenC
handleStorage.fragmentStorageData[1].cpuPtr = reinterpret_cast<void *>(0x2000);
handleStorage.fragmentStorageData[1].fragmentSize = 0x6000;
wddm->createAllocationsAndMapGpuVaResult = STATUS_GRAPHICS_NO_VIDEO_MEMORY;
wddm->callBaseCreateAllocationsAndMapGpuVa = false;
wddm->createAllocationsAndMapGpuVaStatus = STATUS_GRAPHICS_NO_VIDEO_MEMORY;
auto result = memoryManager->populateOsHandles(handleStorage, mockRootDeviceIndex);
auto hostPtrManager = static_cast<MockHostPtrManager *>(memoryManager->getHostPtrManager());

View File

@ -107,7 +107,7 @@ class WddmMemoryManagerFixtureWithGmockWddm : public ExecutionEnvironmentFixture
void SetUp() override {
// wddm is deleted by memory manager
wddm = new MockWddm(*executionEnvironment->rootDeviceEnvironments[0].get());
wddm = new WddmMock(*executionEnvironment->rootDeviceEnvironments[0].get());
ASSERT_NE(nullptr, wddm);
auto preemptionMode = PreemptionHelper::getDefaultPreemptionMode(*defaultHwInfo);
wddm->init();
@ -128,7 +128,7 @@ class WddmMemoryManagerFixtureWithGmockWddm : public ExecutionEnvironmentFixture
osContext->decRefInternal();
}
MockWddm *wddm = nullptr;
WddmMock *wddm = nullptr;
std::unique_ptr<CommandStreamReceiver> csr;
OSInterface *osInterface;
OsContext *osContext;

View File

@ -119,7 +119,7 @@ struct WddmResidencyControllerWithMockWddmTest : public WddmResidencyControllerT
void SetUp() {
executionEnvironment = platform()->peekExecutionEnvironment();
wddm = new MockWddm(*executionEnvironment->rootDeviceEnvironments[0].get());
wddm = new WddmMock(*executionEnvironment->rootDeviceEnvironments[0].get());
wddm->resetGdi(new MockGdi());
auto preemptionMode = PreemptionHelper::getDefaultPreemptionMode(*defaultHwInfo);
wddm->init();
@ -147,7 +147,7 @@ struct WddmResidencyControllerWithMockWddmTest : public WddmResidencyControllerT
ExecutionEnvironment *executionEnvironment;
std::unique_ptr<MockWddmMemoryManager> memoryManager;
std::unique_ptr<CommandStreamReceiver> csr;
MockWddm *wddm = nullptr;
WddmMock *wddm = nullptr;
OsContext *osContext;
WddmResidencyController *residencyController;
GmmClientContext *gmmClientContext = nullptr;
@ -515,7 +515,7 @@ TEST_F(WddmResidencyControllerWithGdiTest, givenNotUsedAllocationsFromPreviousPe
// Set current fence value to greater value
residencyController->getMonitoredFence().currentFenceValue = 20;
wddm->makeNonResidentResult.called = 0;
wddm->evictResult.called = 0;
residencyController->addToTrimCandidateList(&allocation1);
residencyController->addToTrimCandidateList(&allocation2);
@ -523,7 +523,7 @@ TEST_F(WddmResidencyControllerWithGdiTest, givenNotUsedAllocationsFromPreviousPe
residencyController->trimResidency(trimNotification.Flags, trimNotification.NumBytesToTrim);
// 2 allocations evicted
EXPECT_EQ(2u, wddm->makeNonResidentResult.called);
EXPECT_EQ(2u, wddm->evictResult.called);
// removed from trim candidate list
EXPECT_EQ(0u, residencyController->peekTrimCandidateList().size());
// marked nonresident
@ -550,7 +550,7 @@ TEST_F(WddmResidencyControllerWithGdiTest, givenOneUsedAllocationFromPreviousPer
// Set current fence value to greater value
residencyController->getMonitoredFence().currentFenceValue = 20;
wddm->makeNonResidentResult.called = 0;
wddm->evictResult.called = 0;
residencyController->addToTrimCandidateList(&allocation1);
residencyController->addToTrimCandidateList(&allocation2);
@ -558,7 +558,7 @@ TEST_F(WddmResidencyControllerWithGdiTest, givenOneUsedAllocationFromPreviousPer
residencyController->trimResidency(trimNotification.Flags, trimNotification.NumBytesToTrim);
// 1 allocation evicted
EXPECT_EQ(1u, wddm->makeNonResidentResult.called);
EXPECT_EQ(1u, wddm->evictResult.called);
// removed from trim candidate list
EXPECT_EQ(trimListUnusedPosition, allocation1.getTrimCandidateListPosition(osContextId));
@ -600,14 +600,14 @@ TEST_F(WddmResidencyControllerWithGdiAndMemoryManagerTest, givenTripleAllocation
// Set current fence value to greater value
residencyController->getMonitoredFence().currentFenceValue = 20;
wddm->makeNonResidentResult.called = 0;
wddm->evictResult.called = 0;
residencyController->addToTrimCandidateList(allocationTriple);
residencyController->trimResidency(trimNotification.Flags, trimNotification.NumBytesToTrim);
// 2 fragments evicted with one call
EXPECT_EQ(1u, wddm->makeNonResidentResult.called);
EXPECT_EQ(1u, wddm->evictResult.called);
// marked nonresident
EXPECT_FALSE(allocationTriple->fragmentsStorage.fragmentStorageData[0].residency->resident[osContextId]);
EXPECT_FALSE(allocationTriple->fragmentsStorage.fragmentStorageData[2].residency->resident[osContextId]);
@ -671,7 +671,7 @@ TEST_F(WddmResidencyControllerWithGdiTest, WhenTrimmingToBudgetThenAllDoneAlloca
residencyController->getMonitoredFence().lastSubmittedFence = 1;
residencyController->getMonitoredFence().currentFenceValue = 1;
wddm->makeNonResidentResult.called = 0;
wddm->evictResult.called = 0;
residencyController->addToTrimCandidateList(&allocation1);
residencyController->addToTrimCandidateList(&allocation2);
@ -679,7 +679,7 @@ TEST_F(WddmResidencyControllerWithGdiTest, WhenTrimmingToBudgetThenAllDoneAlloca
residencyController->trimResidencyToBudget(3 * 4096);
EXPECT_EQ(2u, wddm->makeNonResidentResult.called);
EXPECT_EQ(2u, wddm->evictResult.called);
EXPECT_EQ(1u, residencyController->peekTrimCandidatesCount());
residencyController->compactTrimCandidateList();
@ -701,13 +701,13 @@ TEST_F(WddmResidencyControllerWithGdiTest, GivenNumBytesToTrimIsNotZeroWhenTrimm
*residencyController->getMonitoredFence().cpuAddress = 1;
residencyController->getMonitoredFence().lastSubmittedFence = 1;
wddm->makeNonResidentResult.called = 0;
wddm->evictResult.called = 0;
residencyController->addToTrimCandidateList(&allocation1);
bool status = residencyController->trimResidencyToBudget(3 * 4096);
EXPECT_EQ(1u, wddm->makeNonResidentResult.called);
EXPECT_EQ(1u, wddm->evictResult.called);
EXPECT_EQ(0u, residencyController->peekTrimCandidateList().size());
EXPECT_FALSE(status);
@ -731,7 +731,7 @@ TEST_F(WddmResidencyControllerWithGdiTest, GivenNumBytesToTrimIsZeroWhenTrimming
residencyController->getMonitoredFence().lastSubmittedFence = 1;
residencyController->getMonitoredFence().currentFenceValue = 1;
wddm->makeNonResidentResult.called = 0;
wddm->evictResult.called = 0;
residencyController->addToTrimCandidateList(&allocation1);
residencyController->addToTrimCandidateList(&allocation2);
@ -740,7 +740,7 @@ TEST_F(WddmResidencyControllerWithGdiTest, GivenNumBytesToTrimIsZeroWhenTrimming
bool status = residencyController->trimResidencyToBudget(3 * 4096);
EXPECT_TRUE(status);
EXPECT_EQ(2u, wddm->makeNonResidentResult.called);
EXPECT_EQ(2u, wddm->evictResult.called);
EXPECT_EQ(1u, residencyController->peekTrimCandidateList().size());
EXPECT_EQ(trimListUnusedPosition, allocation1.getTrimCandidateListPosition(osContextId));
@ -768,7 +768,7 @@ TEST_F(WddmResidencyControllerWithGdiTest, WhenTrimmingToBudgetThenEvictedAlloca
residencyController->getMonitoredFence().lastSubmittedFence = 1;
residencyController->getMonitoredFence().currentFenceValue = 1;
wddm->makeNonResidentResult.called = 0;
wddm->evictResult.called = 0;
residencyController->addToTrimCandidateList(&allocation1);
residencyController->addToTrimCandidateList(&allocation2);
@ -793,7 +793,7 @@ TEST_F(WddmResidencyControllerWithGdiTest, GivenLastFenceIsGreaterThanMonitoredW
residencyController->getMonitoredFence().lastSubmittedFence = 2;
residencyController->getMonitoredFence().currentFenceValue = 3;
wddm->makeNonResidentResult.called = 0;
wddm->evictResult.called = 0;
wddm->waitFromCpuResult.called = 0;
residencyController->addToTrimCandidateList(&allocation1);
@ -802,7 +802,7 @@ TEST_F(WddmResidencyControllerWithGdiTest, GivenLastFenceIsGreaterThanMonitoredW
residencyController->trimResidencyToBudget(3 * 4096);
EXPECT_EQ(1u, wddm->makeNonResidentResult.called);
EXPECT_EQ(1u, wddm->evictResult.called);
EXPECT_FALSE(allocation1.getResidencyData().resident[osContextId]);
EXPECT_EQ(wddm->getDeviceHandle(), gdi->getWaitFromCpuArg().hDevice);
@ -847,11 +847,11 @@ TEST_F(WddmResidencyControllerWithGdiAndMemoryManagerTest, WhenTrimmingToBudgetT
residencyController->getMonitoredFence().lastSubmittedFence = 1;
residencyController->getMonitoredFence().currentFenceValue = 2;
wddm->makeNonResidentResult.called = 0;
wddm->evictResult.called = 0;
residencyController->trimResidencyToBudget(3 * 4096);
EXPECT_EQ(2u, wddm->makeNonResidentResult.called);
EXPECT_EQ(2u, wddm->evictResult.called);
EXPECT_FALSE(allocationTriple->fragmentsStorage.fragmentStorageData[0].residency->resident[osContextId]);
EXPECT_TRUE(allocationTriple->fragmentsStorage.fragmentStorageData[1].residency->resident[osContextId]);
@ -890,7 +890,7 @@ TEST_F(WddmResidencyControllerWithGdiTest, givenThreeAllocationsAlignedSizeBigge
residencyController->getMonitoredFence().lastSubmittedFence = 1;
residencyController->getMonitoredFence().currentFenceValue = 1;
wddm->makeNonResidentResult.called = 0;
wddm->evictResult.called = 0;
residencyController->addToTrimCandidateList(&allocation1);
residencyController->addToTrimCandidateList(&allocation2);
@ -973,6 +973,7 @@ TEST_F(WddmResidencyControllerWithGdiAndMemoryManagerTest, GivenTripleAllocation
MockWddmAllocation allocation1(gmmClientContext);
MockWddmAllocation allocation2(gmmClientContext);
void *ptr = reinterpret_cast<void *>(wddm->virtualAllocAddress + 0x1500);
wddm->callBaseMakeResident = true;
WddmAllocation *allocationTriple = (WddmAllocation *)memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), false, 2 * MemoryConstants::pageSize}, ptr);
ResidencyContainer residencyPack{&allocation1, allocationTriple, &allocation2};
@ -1013,7 +1014,7 @@ TEST_F(WddmResidencyControllerWithMockWddmTest, givenMakeResidentFailsWhenCallin
MockWddmAllocation allocation4(gmmClientContext);
wddm->makeResidentNumberOfBytesToTrim = 4 * 4096;
wddm->makeResidentResult = false;
wddm->makeResidentStatus = false;
ResidencyContainer residencyPack{&allocation1, &allocation2, &allocation3, &allocation4};
bool result = residencyController->makeResidentResidencyAllocations(residencyPack);
@ -1024,19 +1025,19 @@ TEST_F(WddmResidencyControllerWithMockWddmTest, givenMakeResidentFailsWhenCallin
EXPECT_FALSE(allocation2.getResidencyData().resident[osContextId]);
EXPECT_FALSE(allocation3.getResidencyData().resident[osContextId]);
EXPECT_FALSE(allocation4.getResidencyData().resident[osContextId]);
EXPECT_EQ(2u, wddm->makeResidentCalled);
EXPECT_EQ(2u, wddm->makeResidentResult.called);
}
TEST_F(WddmResidencyControllerWithMockWddmTest, givenMakeResidentFailsWhenCallingMakeResidentResidencyAllocationsThenDontMarkTripleAllocationsAsResident) {
MockWddmAllocation allocation1(gmmClientContext);
MockWddmAllocation allocation2(gmmClientContext);
wddm->callBaseCreateAllocationAndMapGpuVa = true;
wddm->callBaseCreateAllocationsAndMapGpuVa = true;
void *ptr = reinterpret_cast<void *>(wddm->getWddmMinAddress() + 0x1500);
WddmAllocation *allocationTriple = static_cast<WddmAllocation *>(memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), false, 2 * MemoryConstants::pageSize}, ptr));
ASSERT_NE(nullptr, allocationTriple);
wddm->makeResidentNumberOfBytesToTrim = 4 * 4096;
wddm->makeResidentResult = false;
wddm->makeResidentStatus = false;
ResidencyContainer residencyPack{&allocation1, allocationTriple, &allocation2};
bool result = residencyController->makeResidentResidencyAllocations(residencyPack);
@ -1048,21 +1049,21 @@ TEST_F(WddmResidencyControllerWithMockWddmTest, givenMakeResidentFailsWhenCallin
}
memoryManager->freeGraphicsMemory(allocationTriple);
EXPECT_EQ(2u, wddm->makeResidentCalled);
EXPECT_EQ(2u, wddm->makeResidentResult.called);
}
TEST_F(WddmResidencyControllerWithMockWddmTest, givenMakeResidentFailsWhenCallingMakeResidentResidencyAllocationsThenCallItAgainWithCantTrimFurtherSetToTrue) {
MockWddmAllocation allocation1(gmmClientContext);
wddm->makeResidentNumberOfBytesToTrim = 4 * 4096;
wddm->makeResidentResult = false;
wddm->makeResidentStatus = false;
ResidencyContainer residencyPack{&allocation1};
bool result = residencyController->makeResidentResidencyAllocations(residencyPack);
EXPECT_FALSE(result);
EXPECT_NE(wddm->makeResidentParamsPassed[0].cantTrimFurther, wddm->makeResidentParamsPassed[1].cantTrimFurther);
EXPECT_EQ(2u, wddm->makeResidentCalled);
EXPECT_EQ(2u, wddm->makeResidentResult.called);
}
TEST_F(WddmResidencyControllerWithMockWddmTest, givenAllocationPackPassedWhenCallingMakeResidentResidencyAllocationsThenItIsUsed) {
@ -1074,11 +1075,11 @@ TEST_F(WddmResidencyControllerWithMockWddmTest, givenAllocationPackPassedWhenCal
bool result = residencyController->makeResidentResidencyAllocations(residencyPack);
EXPECT_TRUE(result);
EXPECT_EQ(2 * EngineLimits::maxHandleCount, wddm->makeResidentParamsPassed[0].handles.size());
EXPECT_EQ(false, wddm->makeResidentParamsPassed[0].cantTrimFurther);
EXPECT_EQ(1, wddm->makeResidentParamsPassed[0].handles[0 * EngineLimits::maxHandleCount]);
EXPECT_EQ(2, wddm->makeResidentParamsPassed[0].handles[1 * EngineLimits::maxHandleCount]);
EXPECT_EQ(1u, wddm->makeResidentCalled);
EXPECT_EQ(2 * EngineLimits::maxHandleCount, wddm->makeResidentResult.handleCount);
EXPECT_EQ(false, wddm->makeResidentResult.cantTrimFurther);
EXPECT_EQ(1, wddm->makeResidentResult.handlePack[0 * EngineLimits::maxHandleCount]);
EXPECT_EQ(2, wddm->makeResidentResult.handlePack[1 * EngineLimits::maxHandleCount]);
EXPECT_EQ(1u, wddm->makeResidentResult.called);
}
TEST_F(WddmResidencyControllerWithMockWddmTest, givenMakeResidentFailsAndTrimToBudgetSuceedsWhenCallingMakeResidentResidencyAllocationsThenSucceed) {
@ -1100,7 +1101,7 @@ TEST_F(WddmResidencyControllerWithMockWddmTest, givenMakeResidentFailsAndTrimToB
EXPECT_TRUE(result);
EXPECT_TRUE(allocation1.getResidencyData().resident[osContextId]);
EXPECT_EQ(2u, wddm->makeResidentCalled);
EXPECT_EQ(2u, wddm->makeResidentResult.called);
}
TEST_F(WddmResidencyControllerWithMockWddmTest, givenMakeResidentFailsWhenCallingMakeResidentResidencyAllocationsThenMemoryBudgetExhaustedIsSetToTrue) {
@ -1111,5 +1112,5 @@ TEST_F(WddmResidencyControllerWithMockWddmTest, givenMakeResidentFailsWhenCallin
residencyController->makeResidentResidencyAllocations(residencyPack);
EXPECT_TRUE(residencyController->isMemoryBudgetExhausted());
EXPECT_EQ(2u, wddm->makeResidentCalled);
EXPECT_EQ(2u, wddm->makeResidentResult.called);
}

View File

@ -40,20 +40,38 @@ WddmMock::~WddmMock() {
bool WddmMock::makeResident(const D3DKMT_HANDLE *handles, uint32_t count, bool cantTrimFurther, uint64_t *numberOfBytesToTrim, size_t totalSize) {
makeResidentResult.called++;
makeResidentResult.handleCount = count;
for (auto i = 0u; i < count; i++) {
makeResidentResult.handlePack.push_back(handles[i]);
makeResidentResult.cantTrimFurther = cantTrimFurther;
makeResidentResult.totalSize = totalSize;
if (handles) {
for (size_t i = 0; i < count; i++) {
makeResidentResult.handlePack.push_back(handles[i]);
}
}
makeResidentParamsPassed.push_back(makeResidentResult);
if (callBaseMakeResident) {
return makeResidentResult.success = Wddm::makeResident(handles, count, cantTrimFurther, numberOfBytesToTrim, totalSize);
} else {
makeResidentResult.success = makeResidentStatus;
return makeResidentStatus;
return Wddm::makeResident(handles, count, cantTrimFurther, numberOfBytesToTrim, totalSize);
}
if (numberOfBytesToTrim != nullptr) {
*numberOfBytesToTrim = makeResidentNumberOfBytesToTrim;
}
if (makeResidentResult.called <= makeResidentResults.size()) {
return makeResidentResults[makeResidentResult.called - 1];
}
return makeResidentStatus;
}
bool WddmMock::evict(const D3DKMT_HANDLE *handles, uint32_t num, uint64_t &sizeToTrim) {
makeNonResidentResult.called++;
return makeNonResidentResult.success = Wddm::evict(handles, num, sizeToTrim);
evictResult.called++;
if (callBaseEvict) {
evictStatus = Wddm::evict(handles, num, sizeToTrim);
}
return evictStatus;
}
NTSTATUS WddmMock::createAllocationsAndMapGpuVa(OsHandleStorage &osHandles) {
createAllocationsAndMapGpuVaResult.called++;
if (callBaseCreateAllocationsAndMapGpuVa) {
createAllocationsAndMapGpuVaStatus = Wddm::createAllocationsAndMapGpuVa(osHandles);
}
return createAllocationsAndMapGpuVaStatus;
}
bool WddmMock::mapGpuVirtualAddress(WddmAllocation *allocation) {
D3DGPU_VIRTUAL_ADDRESS minimumAddress = gfxPartition.Standard.Base;
@ -308,16 +326,4 @@ bool WddmMock::setAllocationPriority(const D3DKMT_HANDLE *handles, uint32_t allo
return status;
}
return setAllocationPriorityResult.success;
}
void *MockWddm::virtualAllocWrapper(void *inPtr, size_t size, uint32_t flags, uint32_t type) {
void *tmp = reinterpret_cast<void *>(virtualAllocAddress);
size += MemoryConstants::pageSize;
size -= size % MemoryConstants::pageSize;
virtualAllocAddress += size;
return tmp;
}
MockWddm::MockWddm(RootDeviceEnvironment &rootDeviceEnvironment) : WddmMock(rootDeviceEnvironment) {
virtualAllocAddress = NEO::windowsMinAddress;
}
}

View File

@ -52,8 +52,6 @@ class WddmMock : public Wddm {
WddmMock(RootDeviceEnvironment &rootDeviceEnvironment);
~WddmMock();
bool makeResident(const D3DKMT_HANDLE *handles, uint32_t count, bool cantTrimFurther, uint64_t *numberOfBytesToTrim, size_t totalSize) override;
bool evict(const D3DKMT_HANDLE *handles, uint32_t num, uint64_t &sizeToTrim) override;
bool mapGpuVirtualAddress(Gmm *gmm, D3DKMT_HANDLE handle, D3DGPU_VIRTUAL_ADDRESS minimumAddress, D3DGPU_VIRTUAL_ADDRESS maximumAddress, D3DGPU_VIRTUAL_ADDRESS preferredAddress, D3DGPU_VIRTUAL_ADDRESS &gpuPtr) override;
bool mapGpuVirtualAddress(WddmAllocation *allocation);
bool freeGpuVirtualAddress(D3DGPU_VIRTUAL_ADDRESS &gpuPtr, uint64_t size) override;
@ -124,9 +122,13 @@ class WddmMock : public Wddm {
};
void resetGdi(Gdi *gdi);
bool makeResident(const D3DKMT_HANDLE *handles, uint32_t count, bool cantTrimFurther, uint64_t *numberOfBytesToTrim, size_t totalSize) override;
bool evict(const D3DKMT_HANDLE *handles, uint32_t num, uint64_t &sizeToTrim) override;
NTSTATUS createAllocationsAndMapGpuVa(OsHandleStorage &osHandles) override;
WddmMockHelpers::MakeResidentCall makeResidentResult;
WddmMockHelpers::CallResult makeNonResidentResult;
WddmMockHelpers::CallResult evictResult;
WddmMockHelpers::CallResult createAllocationsAndMapGpuVaResult;
WddmMockHelpers::CallResult mapGpuVirtualAddressResult;
WddmMockHelpers::FreeGpuVirtualAddressCall freeGpuVirtualAddressResult;
WddmMockHelpers::CallResult createAllocationResult;
@ -150,6 +152,15 @@ class WddmMock : public Wddm {
WddmMockHelpers::CallResult waitOnPagingFenceFromCpuResult;
WddmMockHelpers::CallResult setAllocationPriorityResult;
StackVec<WddmMockHelpers::MakeResidentCall, 2> makeResidentParamsPassed{};
bool makeResidentStatus = true;
bool callBaseMakeResident = false;
std::vector<bool> makeResidentResults = {};
uint64_t makeResidentNumberOfBytesToTrim = 0;
bool callBaseEvict = false;
bool evictStatus = true;
bool callBaseCreateAllocationsAndMapGpuVa = true;
NTSTATUS createAllocationsAndMapGpuVaStatus = STATUS_UNSUCCESSFUL;
NTSTATUS createAllocationStatus = STATUS_SUCCESS;
bool verifyAdapterLuidReturnValue = true;
bool callBaseVerifyAdapterLuid = false;
@ -161,71 +172,8 @@ class WddmMock : public Wddm {
uintptr_t virtualAllocAddress = NEO::windowsMinAddress;
bool kmDafEnabled = false;
uint64_t mockPagingFence = 0u;
bool makeResidentStatus = true;
bool callBaseMakeResident = true;
bool callBaseCreatePagingLogger = true;
bool shutdownStatus = false;
bool callBaseSetAllocationPriority = true;
};
struct MockWddm : WddmMock {
MockWddm(RootDeviceEnvironment &rootDeviceEnvironment);
~MockWddm() = default;
bool virtualFreeWrapper(void *ptr, size_t size, uint32_t flags) {
return true;
}
void *virtualAllocWrapper(void *inPtr, size_t size, uint32_t flags, uint32_t type);
uintptr_t virtualAllocAddress;
bool makeResident(const D3DKMT_HANDLE *handles, uint32_t count, bool cantTrimFurther, uint64_t *numberOfBytesToTrim, size_t totalSize) override {
makeResidentCalled++;
MakeResidentParams params{};
params.cantTrimFurther = cantTrimFurther;
params.totalSize = totalSize;
if (handles) {
for (size_t i = 0; i < count; i++) {
params.handles.push_back(handles[i]);
}
}
if (numberOfBytesToTrim != nullptr) {
*numberOfBytesToTrim = makeResidentNumberOfBytesToTrim;
}
makeResidentParamsPassed.push_back(params);
if (makeResidentCalled <= makeResidentResults.size()) {
return makeResidentResults[makeResidentCalled - 1];
}
return makeResidentResult;
}
struct MakeResidentParams {
StackVec<D3DKMT_HANDLE, 2> handles;
bool cantTrimFurther{};
size_t totalSize{};
};
StackVec<MakeResidentParams, 2> makeResidentParamsPassed{};
uint32_t makeResidentCalled = 0u;
bool makeResidentResult = true;
std::vector<bool> makeResidentResults = {};
uint64_t makeResidentNumberOfBytesToTrim = 0;
ADDMETHOD_NOBASE(evict, bool, true, (const D3DKMT_HANDLE *handles, uint32_t num, uint64_t &sizeToTrim));
NTSTATUS createAllocationsAndMapGpuVa(OsHandleStorage &osHandles) override {
createAllocationsAndMapGpuVaCalled++;
if (callBaseCreateAllocationAndMapGpuVa) {
createAllocationsAndMapGpuVaResult = baseCreateAllocationAndMapGpuVa(osHandles);
}
return createAllocationsAndMapGpuVaResult;
}
uint32_t createAllocationsAndMapGpuVaCalled = 0u;
bool callBaseCreateAllocationAndMapGpuVa = false;
NTSTATUS createAllocationsAndMapGpuVaResult = STATUS_UNSUCCESSFUL;
NTSTATUS baseCreateAllocationAndMapGpuVa(OsHandleStorage &osHandles) {
return Wddm::createAllocationsAndMapGpuVa(osHandles);
}
};
} // namespace NEO

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2019-2021 Intel Corporation
* Copyright (C) 2019-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -25,6 +25,8 @@ struct CallResult {
struct MakeResidentCall : CallResult {
std::vector<D3DKMT_HANDLE> handlePack;
uint32_t handleCount = 0;
bool cantTrimFurther{};
size_t totalSize{};
};
struct KmDafLockCall : CallResult {
std::vector<D3DKMT_HANDLE> lockedAllocations;

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2020-2021 Intel Corporation
* Copyright (C) 2020-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -376,6 +376,7 @@ HWTEST_F(WddmDirectSubmissionTest, givenWddmResidencyEnabledWhenAllocatingResour
MockWddmDirectSubmission<FamilyType, Dispatcher> wddmDirectSubmission(*device.get(),
*osContext.get());
wddm->callBaseMakeResident = true;
wddm->createPagingFenceLogger();
EXPECT_EQ(1u, NEO::IoFunctions::mockFopenCalled);