mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-11 16:45:25 +08:00
Move free function to DrmMemoryManager
Signed-off-by: Szymon Morek <szymon.morek@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
263becc3f8
commit
e368e6c20b
@@ -39,14 +39,6 @@ class DrmMockCustomImpl : public DrmMockCustom {
|
||||
__u32 createExtHandle = 0;
|
||||
__u64 createExtExtensions = 0;
|
||||
|
||||
//DRM_IOCTL_I915_GEM_MMAP_OFFSET
|
||||
__u32 mmapOffsetHandle = 0;
|
||||
__u32 mmapOffsetPad = 0;
|
||||
__u64 mmapOffsetOffset = 0;
|
||||
__u64 mmapOffsetFlags = 0;
|
||||
|
||||
bool failOnMmapOffset = false;
|
||||
|
||||
int ioctlExtra(unsigned long request, void *arg) override {
|
||||
switch (request) {
|
||||
case DRM_IOCTL_I915_GEM_CREATE_EXT: {
|
||||
@@ -56,17 +48,6 @@ class DrmMockCustomImpl : public DrmMockCustom {
|
||||
createExtExtensions = createExtParams->extensions;
|
||||
ioctlImpl_cnt.gemCreateExt++;
|
||||
} break;
|
||||
case DRM_IOCTL_I915_GEM_MMAP_OFFSET: {
|
||||
auto mmapOffsetParams = reinterpret_cast<drm_i915_gem_mmap_offset *>(arg);
|
||||
mmapOffsetHandle = mmapOffsetParams->handle;
|
||||
mmapOffsetPad = mmapOffsetParams->pad;
|
||||
mmapOffsetOffset = mmapOffsetParams->offset;
|
||||
mmapOffsetFlags = mmapOffsetParams->flags;
|
||||
ioctlImpl_cnt.gemMmapOffset++;
|
||||
if (failOnMmapOffset == true) {
|
||||
return -1;
|
||||
}
|
||||
} break;
|
||||
default: {
|
||||
std::cout << "unexpected IOCTL: " << std::hex << request << std::endl;
|
||||
UNRECOVERABLE_IF(true);
|
||||
|
||||
@@ -88,48 +88,6 @@ class DrmMemoryManagerLocalMemoryWithCustomMockTest : public ::testing::Test {
|
||||
std::unique_ptr<TestedDrmMemoryManager> memoryManager;
|
||||
};
|
||||
|
||||
extern bool retrieveMmapOffsetForBufferObject(Drm &drm, BufferObject &bo, uint64_t flags, uint64_t &offset);
|
||||
|
||||
TEST_F(DrmMemoryManagerLocalMemoryTest, givenDrmWhenRetrieveMmapOffsetForBufferObjectSucceedsThenReturnTrueAndCorrectOffset) {
|
||||
BufferObject bo(mock, 1, 1024, 0);
|
||||
mock->offset = 21;
|
||||
|
||||
uint64_t offset = 0;
|
||||
auto ret = retrieveMmapOffsetForBufferObject(*mock, bo, 0, offset);
|
||||
|
||||
EXPECT_TRUE(ret);
|
||||
EXPECT_EQ(21u, offset);
|
||||
}
|
||||
|
||||
TEST_F(DrmMemoryManagerLocalMemoryTest, givenDrmWhenRetrieveMmapOffsetForBufferObjectFailsThenReturnFalse) {
|
||||
BufferObject bo(mock, 1, 1024, 0);
|
||||
mock->mmapOffsetRetVal = -1;
|
||||
|
||||
uint64_t offset = 0;
|
||||
auto ret = retrieveMmapOffsetForBufferObject(*mock, bo, 0, offset);
|
||||
|
||||
EXPECT_FALSE(ret);
|
||||
}
|
||||
|
||||
TEST_F(DrmMemoryManagerLocalMemoryTest, givenDrmWhenRetrieveMmapOffsetForBufferObjectIsCalledThenApplyCorrectFlags) {
|
||||
BufferObject bo(mock, 1, 1024, 0);
|
||||
|
||||
uint64_t offset = 0;
|
||||
auto ret = retrieveMmapOffsetForBufferObject(*mock, bo, 0, offset);
|
||||
|
||||
EXPECT_TRUE(ret);
|
||||
EXPECT_EQ(4u, mock->mmapOffsetFlagsReceived);
|
||||
|
||||
mock->mmapOffsetRetVal = -1;
|
||||
|
||||
for (uint64_t flags : {I915_MMAP_OFFSET_WC, I915_MMAP_OFFSET_WB}) {
|
||||
ret = retrieveMmapOffsetForBufferObject(*mock, bo, flags, offset);
|
||||
|
||||
EXPECT_FALSE(ret);
|
||||
EXPECT_EQ(flags, mock->mmapOffsetFlagsReceived);
|
||||
}
|
||||
}
|
||||
|
||||
HWTEST2_F(DrmMemoryManagerLocalMemoryTest, givenDrmMemoryManagerWhenCreateBufferObjectInMemoryRegionIsCalledThenBufferObjectWithAGivenGpuAddressAndSizeIsCreatedAndAllocatedInASpecifiedMemoryRegion, NonDefaultIoctlsSupported) {
|
||||
DebugManagerStateRestore restorer;
|
||||
DebugManager.flags.EnableLocalMemory.set(1);
|
||||
@@ -822,7 +780,7 @@ HWTEST2_F(DrmMemoryManagerTestImpl, givenDrmMemoryManagerWhenLockUnlockIsCalledO
|
||||
mockExp->ioctlImpl_expected.gemCreateExt = 1;
|
||||
mockExp->ioctl_expected.gemWait = 1;
|
||||
mockExp->ioctl_expected.gemClose = 1;
|
||||
mockExp->ioctlImpl_expected.gemMmapOffset = 1;
|
||||
mockExp->ioctl_expected.gemMmapOffset = 1;
|
||||
mockExp->memoryInfo.reset(new MockMemoryInfo());
|
||||
|
||||
AllocationData allocData;
|
||||
@@ -845,7 +803,7 @@ HWTEST2_F(DrmMemoryManagerTestImpl, givenDrmMemoryManagerWhenLockUnlockIsCalledO
|
||||
|
||||
EXPECT_EQ(static_cast<uint32_t>(drmAllocation->getBO()->peekHandle()), mockExp->mmapOffsetHandle);
|
||||
EXPECT_EQ(0u, mockExp->mmapOffsetPad);
|
||||
EXPECT_EQ(0u, mockExp->mmapOffsetOffset);
|
||||
EXPECT_EQ(0u, mockExp->mmapOffsetExpected);
|
||||
EXPECT_EQ(4u, mockExp->mmapOffsetFlags);
|
||||
|
||||
memoryManager->unlockResource(allocation);
|
||||
@@ -855,7 +813,7 @@ HWTEST2_F(DrmMemoryManagerTestImpl, givenDrmMemoryManagerWhenLockUnlockIsCalledO
|
||||
}
|
||||
|
||||
TEST_F(DrmMemoryManagerTestImpl, givenDrmMemoryManagerWhenLockUnlockIsCalledOnAllocationInLocalMemoryButFailsOnMmapThenReturnNullPtr) {
|
||||
mockExp->ioctlImpl_expected.gemMmapOffset = 2;
|
||||
mockExp->ioctl_expected.gemMmapOffset = 2;
|
||||
this->ioctlResExt = {mockExp->ioctl_cnt.total, -1};
|
||||
mockExp->ioctl_res_ext = &ioctlResExt;
|
||||
|
||||
@@ -871,7 +829,7 @@ TEST_F(DrmMemoryManagerTestImpl, givenDrmMemoryManagerWhenLockUnlockIsCalledOnAl
|
||||
}
|
||||
|
||||
TEST_F(DrmMemoryManagerTestImpl, givenDrmMemoryManagerWhenLockUnlockIsCalledOnAllocationInLocalMemoryButFailsOnIoctlMmapFunctionOffsetThenReturnNullPtr) {
|
||||
mockExp->ioctlImpl_expected.gemMmapOffset = 2;
|
||||
mockExp->ioctl_expected.gemMmapOffset = 2;
|
||||
mockExp->returnIoctlExtraErrorValue = true;
|
||||
mockExp->failOnMmapOffset = true;
|
||||
|
||||
|
||||
@@ -5543,4 +5543,72 @@ TEST(DrmMemoryManagerCopyMemoryToAllocationBanksTest, givenDrmMemoryManagerWhenC
|
||||
delete mockAllocation.bufferObjects[index];
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(DrmMemoryManagerWithLocalMemoryTest, givenDrmWhenRetrieveMmapOffsetForBufferObjectSucceedsThenReturnTrueAndCorrectOffset) {
|
||||
mock->ioctl_expected.gemMmapOffset = 1;
|
||||
BufferObject bo(mock, 1, 1024, 0);
|
||||
mock->mmapOffsetExpected = 21;
|
||||
|
||||
uint64_t offset = 0;
|
||||
auto ret = memoryManager->retrieveMmapOffsetForBufferObject(rootDeviceIndex, bo, 0, offset);
|
||||
|
||||
EXPECT_TRUE(ret);
|
||||
EXPECT_EQ(21u, offset);
|
||||
}
|
||||
|
||||
TEST_F(DrmMemoryManagerWithLocalMemoryTest, givenDrmWhenRetrieveMmapOffsetForBufferObjectFailsThenReturnFalse) {
|
||||
mock->ioctl_expected.gemMmapOffset = 2;
|
||||
BufferObject bo(mock, 1, 1024, 0);
|
||||
mock->failOnMmapOffset = true;
|
||||
|
||||
uint64_t offset = 0;
|
||||
auto ret = memoryManager->retrieveMmapOffsetForBufferObject(rootDeviceIndex, bo, 0, offset);
|
||||
|
||||
EXPECT_FALSE(ret);
|
||||
}
|
||||
|
||||
TEST_F(DrmMemoryManagerWithLocalMemoryTest, givenDrmWhenRetrieveMmapOffsetForBufferObjectIsCalledForLocalMemoryThenApplyCorrectFlags) {
|
||||
mock->ioctl_expected.gemMmapOffset = 5;
|
||||
BufferObject bo(mock, 1, 1024, 0);
|
||||
|
||||
uint64_t offset = 0;
|
||||
auto ret = memoryManager->retrieveMmapOffsetForBufferObject(rootDeviceIndex, bo, 0, offset);
|
||||
|
||||
EXPECT_TRUE(ret);
|
||||
EXPECT_EQ(4u, mock->mmapOffsetFlags);
|
||||
|
||||
mock->failOnMmapOffset = true;
|
||||
|
||||
for (uint64_t flags : {I915_MMAP_OFFSET_WC, I915_MMAP_OFFSET_WB}) {
|
||||
ret = memoryManager->retrieveMmapOffsetForBufferObject(rootDeviceIndex, bo, flags, offset);
|
||||
|
||||
EXPECT_FALSE(ret);
|
||||
EXPECT_EQ(flags, mock->mmapOffsetFlags);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(DrmMemoryManagerTest, givenDrmWhenRetrieveMmapOffsetForBufferObjectIsCalledForSystemMemoryThenApplyCorrectFlags) {
|
||||
mock->ioctl_expected.gemMmapOffset = 4;
|
||||
BufferObject bo(mock, 1, 1024, 0);
|
||||
|
||||
uint64_t offset = 0;
|
||||
bool ret = false;
|
||||
|
||||
for (uint64_t flags : {I915_MMAP_OFFSET_WC, I915_MMAP_OFFSET_WB}) {
|
||||
ret = memoryManager->retrieveMmapOffsetForBufferObject(rootDeviceIndex, bo, flags, offset);
|
||||
|
||||
EXPECT_TRUE(ret);
|
||||
EXPECT_EQ(flags, mock->mmapOffsetFlags);
|
||||
}
|
||||
|
||||
mock->failOnMmapOffset = true;
|
||||
|
||||
for (uint64_t flags : {I915_MMAP_OFFSET_WC, I915_MMAP_OFFSET_WB}) {
|
||||
ret = memoryManager->retrieveMmapOffsetForBufferObject(rootDeviceIndex, bo, flags, offset);
|
||||
|
||||
EXPECT_FALSE(ret);
|
||||
EXPECT_EQ(flags, mock->mmapOffsetFlags);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace NEO
|
||||
|
||||
Reference in New Issue
Block a user