|
13 | 13 | #include "shared/source/memory_manager/memory_banks.h" |
14 | 14 | #include "shared/source/memory_manager/unified_memory_manager.h" |
15 | 15 | #include "shared/source/os_interface/linux/allocator_helper.h" |
| 16 | +#include "shared/source/os_interface/linux/drm_memory_operations_handler_bind.h" |
16 | 17 | #include "shared/source/utilities/heap_allocator.h" |
17 | 18 | #include "shared/test/common/helpers/batch_buffer_helper.h" |
18 | 19 | #include "shared/test/common/helpers/stream_capture.h" |
@@ -3735,3 +3736,57 @@ TEST_F(DrmMemoryManagerLocalMemoryPrelimTest, givenCreateMultiHostDebugSurfaceAl |
3735 | 3736 |
|
3736 | 3737 | memoryManager->freeGraphicsMemory(allocation); |
3737 | 3738 | } |
| 3739 | + |
| 3740 | +TEST_F(DrmMemoryManagerLocalMemoryPrelimTest, givenDrmMemoryManagerAndResidentNeededbeforeLockWhenCreateAllocWithAlignmentIsCalledThenverifyAllocationIsResident) { |
| 3741 | + auto mockIoctlHelper = new MockIoctlHelper(*mock); |
| 3742 | + mockIoctlHelper->makeResidentBeforeLockNeededResult = true; |
| 3743 | + |
| 3744 | + auto &drm = static_cast<DrmMockCustom &>(memoryManager->getDrm(rootDeviceIndex)); |
| 3745 | + drm.ioctlHelper.reset(mockIoctlHelper); |
| 3746 | + |
| 3747 | + auto memoryClassSystem = mockIoctlHelper->getDrmParamValue(DrmParam::memoryClassSystem); |
| 3748 | + auto memoryClassDevice = mockIoctlHelper->getDrmParamValue(DrmParam::memoryClassDevice); |
| 3749 | + |
| 3750 | + std::vector<MemoryRegion> regionInfo(2); |
| 3751 | + regionInfo[0].region = {static_cast<uint16_t>(memoryClassSystem), 0}; |
| 3752 | + regionInfo[1].region = {static_cast<uint16_t>(memoryClassDevice), DrmMockHelper::getEngineOrMemoryInstanceValue(0, 0)}; |
| 3753 | + |
| 3754 | + mock->memoryInfo.reset(new MockedMemoryInfo(regionInfo, *mock)); |
| 3755 | + mock->engineInfoQueried = false; |
| 3756 | + mock->queryEngineInfo(); |
| 3757 | + |
| 3758 | + memoryManager->mmapFunction = [](void *addr, size_t len, int prot, |
| 3759 | + int flags, int fd, off_t offset) throw() { |
| 3760 | + if (addr == 0) { |
| 3761 | + return reinterpret_cast<void *>(0x10000000); |
| 3762 | + } else { |
| 3763 | + return addr; |
| 3764 | + } |
| 3765 | + }; |
| 3766 | + |
| 3767 | + memoryManager->munmapFunction = [](void *addr, size_t len) throw() { |
| 3768 | + return 0; |
| 3769 | + }; |
| 3770 | + |
| 3771 | + executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->memoryOperationsInterface.reset(new DrmMemoryOperationsHandlerBind(*executionEnvironment->rootDeviceEnvironments[rootDeviceIndex].get(), 0)); |
| 3772 | + |
| 3773 | + AllocationData allocationData; |
| 3774 | + allocationData.size = MemoryConstants::pageSize64k; |
| 3775 | + allocationData.rootDeviceIndex = 0u; |
| 3776 | + allocationData.type = AllocationType::buffer; |
| 3777 | + |
| 3778 | + auto allocation = memoryManager->createAllocWithAlignment(allocationData, |
| 3779 | + MemoryConstants::pageSize, |
| 3780 | + MemoryConstants::pageSize64k, |
| 3781 | + MemoryConstants::pageSize64k, |
| 3782 | + 0u); |
| 3783 | + ASSERT_NE(nullptr, allocation); |
| 3784 | + |
| 3785 | + auto osContext = device->getDefaultEngine().osContext; |
| 3786 | + EXPECT_TRUE(allocation->isAlwaysResident(osContext->getContextId())); |
| 3787 | + |
| 3788 | + memoryManager->freeGraphicsMemory(allocation); |
| 3789 | + |
| 3790 | + memoryManager->mmapFunction = SysCalls::mmap; |
| 3791 | + memoryManager->munmapFunction = SysCalls::munmap; |
| 3792 | +} |
0 commit comments