@@ -4194,6 +4194,17 @@ TEST(DrmAllocationTest, givenResourceRegistrationEnabledWhenIsaIsRegisteredThenC
41944194 EXPECT_EQ (2u , drm.unregisterCalledCount );
41954195}
41964196
4197+ TEST (DrmAllocationTest, givenDrmAllocationWhenSetCacheRegionIsCalledForDefaultRegionThenReturnTrue) {
4198+ auto executionEnvironment = std::make_unique<ExecutionEnvironment>();
4199+ executionEnvironment->prepareRootDeviceEnvironments (1 );
4200+
4201+ DrmMock drm (*executionEnvironment->rootDeviceEnvironments [0 ]);
4202+
4203+ MockDrmAllocation allocation (GraphicsAllocation::AllocationType::BUFFER, MemoryPool::LocalMemory);
4204+
4205+ EXPECT_TRUE (allocation.setCacheRegion (&drm, CacheRegion::Default));
4206+ }
4207+
41974208TEST (DrmAllocationTest, givenDrmAllocationWhenCacheInfoIsNotAvailableThenCacheRegionIsNotSet) {
41984209 auto executionEnvironment = std::make_unique<ExecutionEnvironment>();
41994210 executionEnvironment->prepareRootDeviceEnvironments (1 );
@@ -4202,10 +4213,10 @@ TEST(DrmAllocationTest, givenDrmAllocationWhenCacheInfoIsNotAvailableThenCacheRe
42024213
42034214 MockDrmAllocation allocation (GraphicsAllocation::AllocationType::BUFFER, MemoryPool::LocalMemory);
42044215
4205- EXPECT_FALSE (allocation.setCacheRegion (&drm, CacheRegion::None ));
4216+ EXPECT_FALSE (allocation.setCacheRegion (&drm, CacheRegion::Region1 ));
42064217}
42074218
4208- TEST (DrmAllocationTest, givenDrmAllocationWhenCacheInfoIsAvailableThenCacheRegionIsNotSetForTheDefault ) {
4219+ TEST (DrmAllocationTest, givenDrmAllocationWhenDefaultCacheInfoIsAvailableThenCacheRegionIsNotSet ) {
42094220 auto executionEnvironment = std::make_unique<ExecutionEnvironment>();
42104221 executionEnvironment->prepareRootDeviceEnvironments (1 );
42114222
@@ -4214,7 +4225,7 @@ TEST(DrmAllocationTest, givenDrmAllocationWhenCacheInfoIsAvailableThenCacheRegio
42144225
42154226 MockDrmAllocation allocation (GraphicsAllocation::AllocationType::BUFFER, MemoryPool::LocalMemory);
42164227
4217- EXPECT_FALSE (allocation.setCacheRegion (&drm, CacheRegion::Default ));
4228+ EXPECT_FALSE (allocation.setCacheRegion (&drm, CacheRegion::Region1 ));
42184229}
42194230
42204231TEST (DrmAllocationTest, givenDrmAllocationWhenCacheRegionIsNotSetThenReturnFalse) {
@@ -4260,4 +4271,63 @@ TEST(DrmAllocationTest, givenDrmAllocationWhenCacheRegionIsSetSuccessfullyThenSe
42604271 }
42614272 }
42624273}
4274+
4275+ TEST_F (DrmMemoryManagerTest, givenDrmAllocationWithHostPtrWhenItIsCreatedWithCacheRegionThenSetRegionInBufferObject) {
4276+ mock->ioctl_expected .total = -1 ;
4277+ auto drm = static_cast <DrmMockCustom *>(executionEnvironment->rootDeviceEnvironments [rootDeviceIndex]->osInterface ->get ()->getDrm ());
4278+ drm->cacheInfo .reset (new MockCacheInfo ());
4279+
4280+ auto ptr = reinterpret_cast <void *>(0x1000 );
4281+ auto size = MemoryConstants::pageSize;
4282+
4283+ OsHandleStorage storage;
4284+ storage.fragmentStorageData [0 ].cpuPtr = ptr;
4285+ storage.fragmentStorageData [0 ].fragmentSize = 1 ;
4286+ storage.fragmentCount = 1 ;
4287+
4288+ memoryManager->populateOsHandles (storage, rootDeviceIndex);
4289+
4290+ auto allocation = std::make_unique<DrmAllocation>(rootDeviceIndex, GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY,
4291+ nullptr , ptr, castToUint64 (ptr), size, MemoryPool::System4KBPages);
4292+ allocation->fragmentsStorage = storage;
4293+
4294+ allocation->setCacheAdvice (drm, 1024 , CacheRegion::Region1);
4295+
4296+ for (uint32_t i = 0 ; i < storage.fragmentCount ; i++) {
4297+ auto bo = allocation->fragmentsStorage .fragmentStorageData [i].osHandleStorage ->bo ;
4298+ EXPECT_EQ (CacheRegion::Region1, bo->peekCacheRegion ());
4299+ }
4300+
4301+ storage.fragmentStorageData [0 ].freeTheFragment = true ;
4302+ memoryManager->cleanOsHandles (storage, rootDeviceIndex);
4303+ }
4304+
4305+ TEST_F (DrmMemoryManagerTest, givenDrmAllocationWithHostPtrWhenItIsCreatedWithIncorrectCacheRegionThenReturnNull) {
4306+ mock->ioctl_expected .total = -1 ;
4307+ auto drm = static_cast <DrmMockCustom *>(executionEnvironment->rootDeviceEnvironments [rootDeviceIndex]->osInterface ->get ()->getDrm ());
4308+ drm->setupCacheInfo (*defaultHwInfo.get ());
4309+
4310+ auto ptr = reinterpret_cast <void *>(0x1000 );
4311+ auto size = MemoryConstants::pageSize;
4312+
4313+ allocationData.size = size;
4314+ allocationData.hostPtr = ptr;
4315+ allocationData.cacheRegion = 0xFFFF ;
4316+
4317+ auto allocation = std::unique_ptr<GraphicsAllocation>(memoryManager->allocateGraphicsMemoryWithHostPtr (allocationData));
4318+ EXPECT_EQ (allocation, nullptr );
4319+ }
4320+
4321+ TEST_F (DrmMemoryManagerTest, givenDrmAllocationWithWithAlignmentFromUserptrWhenItIsCreatedWithIncorrectCacheRegionThenReturnNull) {
4322+ mock->ioctl_expected .total = -1 ;
4323+ auto drm = static_cast <DrmMockCustom *>(executionEnvironment->rootDeviceEnvironments [rootDeviceIndex]->osInterface ->get ()->getDrm ());
4324+ drm->setupCacheInfo (*defaultHwInfo.get ());
4325+
4326+ auto size = MemoryConstants::pageSize;
4327+ allocationData.size = size;
4328+ allocationData.cacheRegion = 0xFFFF ;
4329+
4330+ auto allocation = static_cast <DrmAllocation *>(memoryManager->createAllocWithAlignmentFromUserptr (allocationData, size, 0 , 0 , 0x1000 ));
4331+ EXPECT_EQ (allocation, nullptr );
4332+ }
42634333} // namespace NEO
0 commit comments