@@ -170,6 +170,48 @@ class DrmMemoryManagerLocalMemoryWithCustomMockTest : public ::testing::Test {
170170 std::unique_ptr<TestedDrmMemoryManager> memoryManager;
171171};
172172
173+ extern bool retrieveMmapOffsetForBufferObject (Drm &drm, BufferObject &bo, uint64_t flags, uint64_t &offset);
174+
175+ TEST_F (DrmMemoryManagerLocalMemoryTest, givenDrmWhenRetrieveMmapOffsetForBufferObjectSucceedsThenReturnTrueAndCorrectOffset) {
176+ BufferObject bo (mock, 1 , 1024 , 0 );
177+ mock->offset = 21 ;
178+
179+ uint64_t offset = 0 ;
180+ auto ret = retrieveMmapOffsetForBufferObject (*mock, bo, 0 , offset);
181+
182+ EXPECT_TRUE (ret);
183+ EXPECT_EQ (21u , offset);
184+ }
185+
186+ TEST_F (DrmMemoryManagerLocalMemoryTest, givenDrmWhenRetrieveMmapOffsetForBufferObjectFailsThenReturnFalse) {
187+ BufferObject bo (mock, 1 , 1024 , 0 );
188+ mock->mmapOffsetRetVal = -1 ;
189+
190+ uint64_t offset = 0 ;
191+ auto ret = retrieveMmapOffsetForBufferObject (*mock, bo, 0 , offset);
192+
193+ EXPECT_FALSE (ret);
194+ }
195+
196+ TEST_F (DrmMemoryManagerLocalMemoryTest, givenDrmWhenRetrieveMmapOffsetForBufferObjectIsCalledThenApplyCorrectFlags) {
197+ BufferObject bo (mock, 1 , 1024 , 0 );
198+
199+ uint64_t offset = 0 ;
200+ auto ret = retrieveMmapOffsetForBufferObject (*mock, bo, 0 , offset);
201+
202+ EXPECT_TRUE (ret);
203+ EXPECT_EQ (4u , mock->mmapOffsetFlagsReceived );
204+
205+ mock->mmapOffsetRetVal = -1 ;
206+
207+ for (uint64_t flags : {I915_MMAP_OFFSET_WC, I915_MMAP_OFFSET_WB}) {
208+ ret = retrieveMmapOffsetForBufferObject (*mock, bo, flags, offset);
209+
210+ EXPECT_FALSE (ret);
211+ EXPECT_EQ (flags, mock->mmapOffsetFlagsReceived );
212+ }
213+ }
214+
173215TEST_F (DrmMemoryManagerLocalMemoryTest, givenDrmMemoryManagerWhenCreateBufferObjectInMemoryRegionIsCalledThenBufferObjectWithAGivenGpuAddressAndSizeIsCreatedAndAllocatedInASpecifiedMemoryRegion) {
174216 DebugManagerStateRestore restorer;
175217 DebugManager.flags .EnableLocalMemory .set (1 );
@@ -1433,16 +1475,16 @@ TEST_F(DrmMemoryManagerTestDg1, givenDrmMemoryManagerWhenLockUnlockIsCalledOnAll
14331475 EXPECT_EQ (static_cast <uint32_t >(drmAllocation->getBO ()->peekHandle ()), mockDg1->mmapOffsetHandle );
14341476 EXPECT_EQ (0u , mockDg1->mmapOffsetPad );
14351477 EXPECT_EQ (0u , mockDg1->mmapOffsetOffset );
1436- EXPECT_EQ (( uint64_t )I915_MMAP_OFFSET_WC , mockDg1->mmapOffsetFlags );
1478+ EXPECT_EQ (4u , mockDg1->mmapOffsetFlags );
14371479
14381480 memoryManager->unlockResource (allocation);
14391481 EXPECT_EQ (nullptr , drmAllocation->getBO ()->peekLockedAddress ());
14401482
14411483 memoryManager->freeGraphicsMemory (allocation);
14421484}
14431485
1444- TEST_F (DrmMemoryManagerTestDg1, givenDrmMemoryManagerWhenLockUnlockIsCalledOnAllocationInLocalMemoryButFailsOnIoctlMmapOffsetThenReturnNullPtr ) {
1445- mockDg1->ioctlDg1_expected .gemMmapOffset = 1 ;
1486+ TEST_F (DrmMemoryManagerTestDg1, givenDrmMemoryManagerWhenLockUnlockIsCalledOnAllocationInLocalMemoryButFailsOnMmapThenReturnNullPtr ) {
1487+ mockDg1->ioctlDg1_expected .gemMmapOffset = 2 ;
14461488 this ->ioctlResExt = {mockDg1->ioctl_cnt .total , -1 };
14471489 mockDg1->ioctl_res_ext = &ioctlResExt;
14481490
@@ -1457,6 +1499,22 @@ TEST_F(DrmMemoryManagerTestDg1, givenDrmMemoryManagerWhenLockUnlockIsCalledOnAll
14571499 mockDg1->ioctl_res_ext = &mockDg1->NONE ;
14581500}
14591501
1502+ TEST_F (DrmMemoryManagerTestDg1, givenDrmMemoryManagerWhenLockUnlockIsCalledOnAllocationInLocalMemoryButFailsOnIoctlMmapFunctionOffsetThenReturnNullPtr) {
1503+ mockDg1->ioctlDg1_expected .gemMmapOffset = 2 ;
1504+ mockDg1->returnIoctlExtraErrorValue = true ;
1505+ mockDg1->failOnMmapOffset = true ;
1506+
1507+ BufferObject bo (mockDg1, 1 , 0 , 0 );
1508+ DrmAllocation drmAllocation (0 , GraphicsAllocation::AllocationType::UNKNOWN, &bo, nullptr , 0u , 0u , MemoryPool::LocalMemory);
1509+ EXPECT_NE (nullptr , drmAllocation.getBO ());
1510+
1511+ auto ptr = memoryManager->lockResource (&drmAllocation);
1512+ EXPECT_EQ (nullptr , ptr);
1513+
1514+ memoryManager->unlockResource (&drmAllocation);
1515+ mockDg1->ioctl_res_ext = &mockDg1->NONE ;
1516+ }
1517+
14601518TEST_F (DrmMemoryManagerTestDg1, givenDrmMemoryManagerWhenLockUnlockIsCalledOnAllocationInLocalMemoryButBufferObjectIsNullThenReturnNullPtr) {
14611519 DrmAllocation drmAllocation (0 , GraphicsAllocation::AllocationType::UNKNOWN, nullptr , nullptr , 0u , 0u , MemoryPool::LocalMemory);
14621520
0 commit comments