Remove GMock from GMockMemoryManagerFailFirstAllocation, GMockMemoryManager...

Removed GMock from
- GMockMemoryManagerFailFirstAllocation
- GMockMemoryManager
- TestEventCsr
- MockKmdNotifyCsr
- MockMemoryOperationsHandlerTests
- GmockGmmMemory
- MockMemoryManagerCommandQueueSBA
- TestCmdQueueCsr

Renamed:
- GMockMemoryManagerFailFirstAllocation -> MockMemoryManagerFailFirstAllocation

Moved class body:
- GMockMemoryManager to MockMemoryManager
- GmockGmmMemory to MockGmmMemoryBase

Related-To: NEO-4914
Signed-off-by: Fabian Zwolinski <fabian.zwolinski@intel.com>
This commit is contained in:
Fabian Zwolinski
2022-01-13 13:03:40 +00:00
committed by Compute-Runtime-Automation
parent fbc0666d1b
commit d9bf1886c2
19 changed files with 378 additions and 310 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020-2021 Intel Corporation
* Copyright (C) 2020-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -53,6 +53,9 @@ void CommandQueueHw<gfxCoreFamily>::programStateBaseAddress(uint64_t gsba, bool
globalHeapsBase = neoDevice->getBindlessHeapsHelper()->getGlobalHeapsBase();
}
auto indirectObjectHeapBaseAddress = neoDevice->getMemoryManager()->getInternalHeapBaseAddress(device->getRootDeviceIndex(), useLocalMemoryForIndirectHeap);
auto instructionHeapBaseAddress = neoDevice->getMemoryManager()->getInternalHeapBaseAddress(device->getRootDeviceIndex(), neoDevice->getMemoryManager()->isLocalMemoryUsedForIsa(neoDevice->getRootDeviceIndex()));
NEO::StateBaseAddressHelper<GfxFamily>::programStateBaseAddress(&sbaCmd,
nullptr,
nullptr,
@@ -60,8 +63,8 @@ void CommandQueueHw<gfxCoreFamily>::programStateBaseAddress(uint64_t gsba, bool
gsba,
true,
(device->getMOCS(cachedMOCSAllowed, false) >> 1),
neoDevice->getMemoryManager()->getInternalHeapBaseAddress(device->getRootDeviceIndex(), useLocalMemoryForIndirectHeap),
neoDevice->getMemoryManager()->getInternalHeapBaseAddress(device->getRootDeviceIndex(), neoDevice->getMemoryManager()->isLocalMemoryUsedForIsa(neoDevice->getRootDeviceIndex())),
indirectObjectHeapBaseAddress,
instructionHeapBaseAddress,
globalHeapsBase,
true,
useGlobalSshAndDsh,

View File

@@ -386,7 +386,21 @@ using CommandQueueSBASupport = IsWithinProducts<IGFX_SKYLAKE, IGFX_TIGERLAKE_LP>
struct MockMemoryManagerCommandQueueSBA : public MemoryManagerMock {
MockMemoryManagerCommandQueueSBA(NEO::ExecutionEnvironment &executionEnvironment) : MemoryManagerMock(const_cast<NEO::ExecutionEnvironment &>(executionEnvironment)) {}
MOCK_METHOD2(getInternalHeapBaseAddress, uint64_t(uint32_t rootDeviceIndex, bool useLocalMemory));
uint64_t getInternalHeapBaseAddress(uint32_t rootDeviceIndex, bool useLocalMemory) override {
getInternalHeapBaseAddressCalled++;
getInternalHeapBaseAddressParamsPassed.push_back({rootDeviceIndex, useLocalMemory});
return getInternalHeapBaseAddressResult;
}
struct GetInternalHeapBaseAddressParams {
uint32_t rootDeviceIndex{};
bool useLocalMemory{};
};
uint32_t getInternalHeapBaseAddressCalled = 0u;
uint64_t getInternalHeapBaseAddressResult = 0u;
StackVec<GetInternalHeapBaseAddressParams, 4> getInternalHeapBaseAddressParamsPassed{};
};
struct CommandQueueProgramSBATest : public ::testing::Test {
@@ -397,7 +411,7 @@ struct CommandQueueProgramSBATest : public ::testing::Test {
executionEnvironment->rootDeviceEnvironments[i]->setHwInfo(NEO::defaultHwInfo.get());
}
memoryManager = new ::testing::NiceMock<MockMemoryManagerCommandQueueSBA>(*executionEnvironment);
memoryManager = new MockMemoryManagerCommandQueueSBA(*executionEnvironment);
executionEnvironment->memoryManager.reset(memoryManager);
neoDevice = NEO::MockDevice::create<NEO::MockDevice>(executionEnvironment, rootDeviceIndex);
@@ -432,40 +446,36 @@ HWTEST2_F(CommandQueueProgramSBATest, whenCreatingCommandQueueThenItIsInitialize
NEO::LinearStream child(commandQueue->commandStream->getSpace(alignedSize), alignedSize);
auto &hwHelper = HwHelper::get(neoDevice->getHardwareInfo().platform.eRenderCoreFamily);
bool isaInLocalMemory = !hwHelper.useSystemMemoryPlacementForISA(neoDevice->getHardwareInfo());
if (isaInLocalMemory) {
EXPECT_CALL(*memoryManager, getInternalHeapBaseAddress(rootDeviceIndex, true))
.Times(2);
EXPECT_CALL(*memoryManager, getInternalHeapBaseAddress(rootDeviceIndex, false))
.Times(0);
} else {
EXPECT_CALL(*memoryManager, getInternalHeapBaseAddress(rootDeviceIndex, true))
.Times(1); // IOH
EXPECT_CALL(*memoryManager, getInternalHeapBaseAddress(rootDeviceIndex, false))
.Times(1); // instruction heap
}
const bool isaInLocalMemory = !hwHelper.useSystemMemoryPlacementForISA(neoDevice->getHardwareInfo());
commandQueue->programStateBaseAddress(0u, true, child, true);
EXPECT_EQ(2u, memoryManager->getInternalHeapBaseAddressCalled);
EXPECT_EQ(rootDeviceIndex, memoryManager->getInternalHeapBaseAddressParamsPassed[0].rootDeviceIndex);
EXPECT_EQ(rootDeviceIndex, memoryManager->getInternalHeapBaseAddressParamsPassed[1].rootDeviceIndex);
if (isaInLocalMemory) {
EXPECT_CALL(*memoryManager, getInternalHeapBaseAddress(rootDeviceIndex, false))
.Times(1); // IOH
EXPECT_CALL(*memoryManager, getInternalHeapBaseAddress(rootDeviceIndex, true))
.Times(1); // instruction heap
EXPECT_TRUE(memoryManager->getInternalHeapBaseAddressParamsPassed[0].useLocalMemory);
EXPECT_TRUE(memoryManager->getInternalHeapBaseAddressParamsPassed[1].useLocalMemory);
} else {
EXPECT_CALL(*memoryManager, getInternalHeapBaseAddress(rootDeviceIndex, true))
.Times(0);
EXPECT_CALL(*memoryManager, getInternalHeapBaseAddress(rootDeviceIndex, false))
.Times(2);
EXPECT_TRUE(memoryManager->getInternalHeapBaseAddressParamsPassed[0].useLocalMemory);
EXPECT_FALSE(memoryManager->getInternalHeapBaseAddressParamsPassed[1].useLocalMemory);
}
commandQueue->programStateBaseAddress(0u, false, child, true);
EXPECT_EQ(4u, memoryManager->getInternalHeapBaseAddressCalled);
EXPECT_EQ(rootDeviceIndex, memoryManager->getInternalHeapBaseAddressParamsPassed[2].rootDeviceIndex);
EXPECT_EQ(rootDeviceIndex, memoryManager->getInternalHeapBaseAddressParamsPassed[3].rootDeviceIndex);
if (isaInLocalMemory) {
EXPECT_TRUE(memoryManager->getInternalHeapBaseAddressParamsPassed[2].useLocalMemory);
EXPECT_FALSE(memoryManager->getInternalHeapBaseAddressParamsPassed[3].useLocalMemory);
} else {
EXPECT_FALSE(memoryManager->getInternalHeapBaseAddressParamsPassed[2].useLocalMemory);
EXPECT_FALSE(memoryManager->getInternalHeapBaseAddressParamsPassed[3].useLocalMemory);
}
commandQueue->destroy();
}

View File

@@ -12,6 +12,7 @@
#include "shared/test/common/mocks/mock_memory_manager.h"
#include "shared/test/common/mocks/mock_memory_operations_handler.h"
#include "shared/test/common/mocks/ult_device_factory.h"
#include "shared/test/common/test_macros/mock_method_macros.h"
#include "shared/test/common/test_macros/test.h"
#include "level_zero/core/test/unit_tests/fixtures/aub_csr_fixture.h"
@@ -348,7 +349,7 @@ struct TestCmdQueueCsr : public NEO::UltCommandStreamReceiver<GfxFamily> {
TestCmdQueueCsr(const NEO::ExecutionEnvironment &executionEnvironment, const DeviceBitfield deviceBitfield)
: NEO::UltCommandStreamReceiver<GfxFamily>(const_cast<NEO::ExecutionEnvironment &>(executionEnvironment), 0, deviceBitfield) {
}
MOCK_METHOD3(waitForCompletionWithTimeout, bool(bool enableTimeout, int64_t timeoutMs, uint32_t taskCountToWait));
ADDMETHOD_NOBASE(waitForCompletionWithTimeout, bool, false, (bool enableTimeout, int64_t timeoutMs, uint32_t taskCountToWait));
};
HWTEST_F(CommandQueueSynchronizeTest, givenSinglePartitionCountWhenWaitFunctionFailsThenReturnNotReady) {
@@ -368,17 +369,12 @@ HWTEST_F(CommandQueueSynchronizeTest, givenSinglePartitionCountWhenWaitFunctionF
EXPECT_EQ(returnValue, ZE_RESULT_SUCCESS);
ASSERT_NE(nullptr, commandQueue);
EXPECT_CALL(*csr, waitForCompletionWithTimeout(::testing::_,
::testing::_,
::testing::_))
.Times(1)
.WillOnce(::testing::Return(false));
uint64_t timeout = std::numeric_limits<uint64_t>::max();
returnValue = commandQueue->synchronize(timeout);
EXPECT_EQ(returnValue, ZE_RESULT_NOT_READY);
commandQueue->destroy();
EXPECT_EQ(1u, csr->waitForCompletionWithTimeoutCalled);
}
using CommandQueuePowerHintTest = Test<ContextFixture>;

View File

@@ -351,13 +351,12 @@ TEST_F(ContextMakeMemoryResidentTests,
&ptr);
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
EXPECT_CALL(*mockMemoryInterface, makeResident)
.WillRepeatedly(testing::Return(NEO::MemoryOperationsStatus::SUCCESS));
mockMemoryInterface->makeResidentResult = NEO::MemoryOperationsStatus::SUCCESS;
res = context->makeMemoryResident(device, ptr, size);
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
EXPECT_CALL(*mockMemoryInterface, evict)
.WillRepeatedly(testing::Return(NEO::MemoryOperationsStatus::SUCCESS));
mockMemoryInterface->evictResult = NEO::MemoryOperationsStatus::SUCCESS;
res = context->evictMemory(device, ptr, size);
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
@@ -381,16 +380,14 @@ TEST_F(ContextMakeMemoryResidentTests,
DriverHandleImp *driverHandleImp = static_cast<DriverHandleImp *>(hostDriverHandle.get());
size_t previousSize = driverHandleImp->sharedMakeResidentAllocations.size();
EXPECT_CALL(*mockMemoryInterface, makeResident)
.WillRepeatedly(testing::Return(NEO::MemoryOperationsStatus::SUCCESS));
mockMemoryInterface->makeResidentResult = NEO::MemoryOperationsStatus::SUCCESS;
res = context->makeMemoryResident(device, ptr, size);
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
size_t currentSize = driverHandleImp->sharedMakeResidentAllocations.size();
EXPECT_EQ(previousSize + 1, currentSize);
EXPECT_CALL(*mockMemoryInterface, evict)
.WillRepeatedly(testing::Return(NEO::MemoryOperationsStatus::SUCCESS));
mockMemoryInterface->evictResult = NEO::MemoryOperationsStatus::SUCCESS;
res = context->evictMemory(device, ptr, size);
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
@@ -415,16 +412,14 @@ TEST_F(ContextMakeMemoryResidentTests,
DriverHandleImp *driverHandleImp = static_cast<DriverHandleImp *>(hostDriverHandle.get());
size_t previousSize = driverHandleImp->sharedMakeResidentAllocations.size();
EXPECT_CALL(*mockMemoryInterface, makeResident)
.WillRepeatedly(testing::Return(NEO::MemoryOperationsStatus::SUCCESS));
mockMemoryInterface->makeResidentResult = NEO::MemoryOperationsStatus::SUCCESS;
res = context->makeMemoryResident(device, ptr, size);
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
size_t currentSize = driverHandleImp->sharedMakeResidentAllocations.size();
EXPECT_EQ(previousSize, currentSize);
EXPECT_CALL(*mockMemoryInterface, evict)
.WillRepeatedly(testing::Return(NEO::MemoryOperationsStatus::SUCCESS));
mockMemoryInterface->evictResult = NEO::MemoryOperationsStatus::SUCCESS;
res = context->evictMemory(device, ptr, size);
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
@@ -448,8 +443,8 @@ TEST_F(ContextMakeMemoryResidentTests,
DriverHandleImp *driverHandleImp = static_cast<DriverHandleImp *>(hostDriverHandle.get());
size_t previousSize = driverHandleImp->sharedMakeResidentAllocations.size();
EXPECT_CALL(*mockMemoryInterface, makeResident)
.WillRepeatedly(testing::Return(NEO::MemoryOperationsStatus::FAILED));
mockMemoryInterface->makeResidentResult = NEO::MemoryOperationsStatus::FAILED;
res = context->makeMemoryResident(device, ptr, size);
EXPECT_EQ(ZE_RESULT_ERROR_DEVICE_LOST, res);
@@ -509,8 +504,8 @@ HWTEST_F(ContextMakeMemoryResidentAndMigrationTests,
DriverHandleImp *driverHandleImp = static_cast<DriverHandleImp *>(hostDriverHandle.get());
size_t previousSize = driverHandleImp->sharedMakeResidentAllocations.size();
EXPECT_CALL(*mockMemoryInterface, makeResident)
.WillRepeatedly(testing::Return(NEO::MemoryOperationsStatus::SUCCESS));
mockMemoryInterface->makeResidentResult = NEO::MemoryOperationsStatus::SUCCESS;
ze_result_t res = context->makeMemoryResident(device, ptr, size);
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
@@ -546,8 +541,7 @@ HWTEST_F(ContextMakeMemoryResidentAndMigrationTests,
EXPECT_EQ(mockPageFaultManager->moveAllocationToGpuDomainCalledTimes, 1u);
EXPECT_EQ(mockPageFaultManager->migratedAddress, ptr);
EXPECT_CALL(*mockMemoryInterface, evict)
.WillRepeatedly(testing::Return(NEO::MemoryOperationsStatus::SUCCESS));
mockMemoryInterface->evictResult = NEO::MemoryOperationsStatus::SUCCESS;
res = context->evictMemory(device, ptr, size);
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
@@ -560,8 +554,8 @@ HWTEST_F(ContextMakeMemoryResidentAndMigrationTests,
DriverHandleImp *driverHandleImp = static_cast<DriverHandleImp *>(hostDriverHandle.get());
size_t previousSize = driverHandleImp->sharedMakeResidentAllocations.size();
EXPECT_CALL(*mockMemoryInterface, makeResident)
.WillRepeatedly(testing::Return(NEO::MemoryOperationsStatus::SUCCESS));
mockMemoryInterface->makeResidentResult = NEO::MemoryOperationsStatus::SUCCESS;
ze_result_t res = context->makeMemoryResident(device, ptr, size);
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
@@ -597,8 +591,7 @@ HWTEST_F(ContextMakeMemoryResidentAndMigrationTests,
EXPECT_EQ(mockPageFaultManager->moveAllocationToGpuDomainCalledTimes, 0u);
EXPECT_EQ(mockPageFaultManager->migratedAddress, nullptr);
EXPECT_CALL(*mockMemoryInterface, evict)
.WillRepeatedly(testing::Return(NEO::MemoryOperationsStatus::SUCCESS));
mockMemoryInterface->evictResult = NEO::MemoryOperationsStatus::SUCCESS;
res = context->evictMemory(device, ptr, size);
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
@@ -611,8 +604,8 @@ HWTEST_F(ContextMakeMemoryResidentAndMigrationTests,
DriverHandleImp *driverHandleImp = static_cast<DriverHandleImp *>(hostDriverHandle.get());
size_t previousSize = driverHandleImp->sharedMakeResidentAllocations.size();
EXPECT_CALL(*mockMemoryInterface, makeResident)
.WillRepeatedly(testing::Return(NEO::MemoryOperationsStatus::SUCCESS));
mockMemoryInterface->makeResidentResult = NEO::MemoryOperationsStatus::SUCCESS;
ze_result_t res = context->makeMemoryResident(device, ptr, size);
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
@@ -651,8 +644,7 @@ HWTEST_F(ContextMakeMemoryResidentAndMigrationTests,
EXPECT_EQ(mockPageFaultManager->moveAllocationToGpuDomainCalledTimes, 1u);
EXPECT_EQ(mockPageFaultManager->migratedAddress, ptr);
EXPECT_CALL(*mockMemoryInterface, evict)
.WillRepeatedly(testing::Return(NEO::MemoryOperationsStatus::SUCCESS));
mockMemoryInterface->evictResult = NEO::MemoryOperationsStatus::SUCCESS;
res = context->evictMemory(device, ptr, size);
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
@@ -665,8 +657,8 @@ HWTEST_F(ContextMakeMemoryResidentAndMigrationTests,
DriverHandleImp *driverHandleImp = static_cast<DriverHandleImp *>(hostDriverHandle.get());
size_t previousSize = driverHandleImp->sharedMakeResidentAllocations.size();
EXPECT_CALL(*mockMemoryInterface, makeResident)
.WillRepeatedly(testing::Return(NEO::MemoryOperationsStatus::SUCCESS));
mockMemoryInterface->makeResidentResult = NEO::MemoryOperationsStatus::SUCCESS;
ze_result_t res = context->makeMemoryResident(device, ptr, size);
EXPECT_EQ(ZE_RESULT_SUCCESS, res);

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020-2021 Intel Corporation
* Copyright (C) 2020-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -390,12 +390,8 @@ TEST_F(HostPointerManagerTest, givenNoPointerRegisteredWhenAllocationCreationFai
TEST_F(HostPointerManagerTest, givenHostAllocationImportedWhenMakingResidentAddressThenAllocationMadeResident) {
void *testPtr = heapPointer;
EXPECT_CALL(*mockMemoryInterface, makeResident(_, _))
.Times(1)
.WillRepeatedly(::testing::Return(NEO::MemoryOperationsStatus::SUCCESS));
EXPECT_CALL(*mockMemoryInterface, evict(_, _))
.Times(1)
.WillRepeatedly(::testing::Return(NEO::MemoryOperationsStatus::SUCCESS));
mockMemoryInterface->makeResidentResult = NEO::MemoryOperationsStatus::SUCCESS;
mockMemoryInterface->evictResult = NEO::MemoryOperationsStatus::SUCCESS;
auto result = context->makeMemoryResident(device, testPtr, MemoryConstants::pageSize);
EXPECT_EQ(ZE_RESULT_ERROR_INVALID_ARGUMENT, result);
@@ -414,6 +410,9 @@ TEST_F(HostPointerManagerTest, givenHostAllocationImportedWhenMakingResidentAddr
result = context->evictMemory(device, testPtr, MemoryConstants::pageSize);
EXPECT_EQ(ZE_RESULT_ERROR_INVALID_ARGUMENT, result);
EXPECT_EQ(1u, mockMemoryInterface->makeResidentCalled);
EXPECT_EQ(1u, mockMemoryInterface->evictCalled);
}
TEST_F(HostPointerManagerTest, givenMisalignedPointerRegisteredWhenGettingRelativeOffsetAddressThenRetrieveMisalignedPointerAsBaseAddress) {