@@ -3870,4 +3870,85 @@ TEST(DrmAllocationTest, givenResourceRegistrationNotEnabledWhenRegisteringBindEx
38703870 EXPECT_EQ (Drm::ResourceClass::MaxSize, drm.registeredClass );
38713871}
38723872
3873+ TEST (DrmMemoryManager, givenTrackedAllocationTypeWhenAllocatingThenAllocationIsRegistered) {
3874+ auto executionEnvironment = std::make_unique<MockExecutionEnvironment>();
3875+ executionEnvironment->prepareRootDeviceEnvironments (1u );
3876+ executionEnvironment->rootDeviceEnvironments [0 ]->setHwInfo (defaultHwInfo.get ());
3877+ auto memoryManager = std::make_unique<TestedDrmMemoryManager>(false , false , false , *executionEnvironment);
3878+ auto mockDrm = new DrmMockResources (*executionEnvironment->rootDeviceEnvironments [0 ]);
3879+ executionEnvironment->rootDeviceEnvironments [0 ]->osInterface = std::make_unique<OSInterface>();
3880+ executionEnvironment->rootDeviceEnvironments [0 ]->osInterface ->get ()->setDrm (mockDrm);
3881+
3882+ for (uint32_t i = 3 ; i < 3 + static_cast <uint32_t >(Drm::ResourceClass::MaxSize); i++) {
3883+ mockDrm->classHandles .push_back (i);
3884+ }
3885+
3886+ EXPECT_TRUE (mockDrm->resourceRegistrationEnabled ());
3887+
3888+ NEO::AllocationProperties properties{0 , true , MemoryConstants::pageSize,
3889+ NEO::GraphicsAllocation::AllocationType::DEBUG_SBA_TRACKING_BUFFER,
3890+ false ,
3891+ CommonConstants::allDevicesBitfield};
3892+
3893+ properties.gpuAddress = 0x20000 ;
3894+ auto sbaAllocation = memoryManager->allocateGraphicsMemoryWithProperties (properties);
3895+ EXPECT_EQ (Drm::ResourceClass::SbaTrackingBuffer, mockDrm->registeredClass );
3896+
3897+ EXPECT_EQ (sizeof (uint64_t ), mockDrm->registeredDataSize );
3898+ uint64_t *data = reinterpret_cast <uint64_t *>(mockDrm->registeredData );
3899+ EXPECT_EQ (properties.gpuAddress , *data);
3900+
3901+ memoryManager->freeGraphicsMemory (sbaAllocation);
3902+ }
3903+
3904+ TEST (DrmMemoryManager, givenTrackedAllocationTypeWhenFreeingThenRegisteredHandlesAreUnregistered) {
3905+ auto executionEnvironment = std::make_unique<MockExecutionEnvironment>();
3906+ executionEnvironment->prepareRootDeviceEnvironments (1u );
3907+ executionEnvironment->rootDeviceEnvironments [0 ]->setHwInfo (defaultHwInfo.get ());
3908+ auto memoryManager = std::make_unique<TestedDrmMemoryManager>(false , false , false , *executionEnvironment);
3909+ auto mockDrm = new DrmMockResources (*executionEnvironment->rootDeviceEnvironments [0 ]);
3910+ executionEnvironment->rootDeviceEnvironments [0 ]->osInterface = std::make_unique<OSInterface>();
3911+ executionEnvironment->rootDeviceEnvironments [0 ]->osInterface ->get ()->setDrm (mockDrm);
3912+
3913+ for (uint32_t i = 3 ; i < 3 + static_cast <uint32_t >(Drm::ResourceClass::MaxSize); i++) {
3914+ mockDrm->classHandles .push_back (i);
3915+ }
3916+
3917+ EXPECT_TRUE (mockDrm->resourceRegistrationEnabled ());
3918+
3919+ NEO::AllocationProperties properties{0 , true , MemoryConstants::pageSize,
3920+ NEO::GraphicsAllocation::AllocationType::DEBUG_SBA_TRACKING_BUFFER,
3921+ false ,
3922+ CommonConstants::allDevicesBitfield};
3923+
3924+ properties.gpuAddress = 0x20000 ;
3925+ auto sbaAllocation = memoryManager->allocateGraphicsMemoryWithProperties (properties);
3926+
3927+ EXPECT_EQ (0u , mockDrm->unregisterCalledCount );
3928+
3929+ memoryManager->freeGraphicsMemory (sbaAllocation);
3930+
3931+ EXPECT_EQ (DrmMockResources::registerResourceReturnHandle, mockDrm->unregisteredHandle );
3932+ EXPECT_EQ (1u , mockDrm->unregisterCalledCount );
3933+ }
3934+
3935+ TEST (DrmMemoryManager, givenNullBoWhenRegisteringBindExtHandleThenEarlyReturn) {
3936+ auto executionEnvironment = std::make_unique<MockExecutionEnvironment>();
3937+ executionEnvironment->prepareRootDeviceEnvironments (1u );
3938+ executionEnvironment->rootDeviceEnvironments [0 ]->setHwInfo (defaultHwInfo.get ());
3939+ auto mockDrm = std::make_unique<DrmMockResources>(*executionEnvironment->rootDeviceEnvironments [0 ]);
3940+
3941+ for (uint32_t i = 3 ; i < 3 + static_cast <uint32_t >(Drm::ResourceClass::MaxSize); i++) {
3942+ mockDrm->classHandles .push_back (i);
3943+ }
3944+
3945+ EXPECT_TRUE (mockDrm->resourceRegistrationEnabled ());
3946+
3947+ MockDrmAllocation gfxAllocation (GraphicsAllocation::AllocationType::DEBUG_SBA_TRACKING_BUFFER, MemoryPool::MemoryNull);
3948+
3949+ gfxAllocation.registerBOBindExtHandle (mockDrm.get ());
3950+ EXPECT_EQ (1u , gfxAllocation.registeredBoBindHandles .size ());
3951+ gfxAllocation.freeRegisteredBOBindExtHandles (mockDrm.get ());
3952+ }
3953+
38733954} // namespace NEO
0 commit comments