diff --git a/opencl/test/unit_test/mocks/linux/mock_drm_command_stream_receiver.h b/opencl/test/unit_test/mocks/linux/mock_drm_command_stream_receiver.h index 176437611c..1769dc4655 100644 --- a/opencl/test/unit_test/mocks/linux/mock_drm_command_stream_receiver.h +++ b/opencl/test/unit_test/mocks/linux/mock_drm_command_stream_receiver.h @@ -22,8 +22,8 @@ class TestedDrmCommandStreamReceiver : public DrmCommandStreamReceiver(executionEnvironment, 0, mode) { } - TestedDrmCommandStreamReceiver(ExecutionEnvironment &executionEnvironment) - : DrmCommandStreamReceiver(executionEnvironment, 0, gemCloseWorkerMode::gemCloseWorkerInactive) { + TestedDrmCommandStreamReceiver(ExecutionEnvironment &executionEnvironment, uint32_t rootDeviceIndex) + : DrmCommandStreamReceiver(executionEnvironment, rootDeviceIndex, gemCloseWorkerMode::gemCloseWorkerInactive) { } void overrideDispatchPolicy(DispatchMode overrideValue) { diff --git a/opencl/test/unit_test/mocks/linux/mock_drm_memory_manager.cpp b/opencl/test/unit_test/mocks/linux/mock_drm_memory_manager.cpp index 7fd20d4642..af8208f51e 100644 --- a/opencl/test/unit_test/mocks/linux/mock_drm_memory_manager.cpp +++ b/opencl/test/unit_test/mocks/linux/mock_drm_memory_manager.cpp @@ -53,7 +53,11 @@ void TestedDrmMemoryManager::injectPinBB(BufferObject *newPinBB) { } DrmGemCloseWorker *TestedDrmMemoryManager::getgemCloseWorker() { return this->gemCloseWorker.get(); } -void TestedDrmMemoryManager::forceLimitedRangeAllocator(uint64_t range) { getGfxPartition(0)->init(range, getSizeToReserve(), 0, 1); } +void TestedDrmMemoryManager::forceLimitedRangeAllocator(uint64_t range) { + for (auto &gfxPartition : gfxPartitions) { + gfxPartition->init(range, getSizeToReserve(), 0, 1); + } +} void TestedDrmMemoryManager::overrideGfxPartition(GfxPartition *newGfxPartition) { gfxPartitions[0].reset(newGfxPartition); } DrmAllocation *TestedDrmMemoryManager::allocate32BitGraphicsMemory(uint32_t rootDeviceIndex, size_t size, const void *ptr, GraphicsAllocation::AllocationType allocationType) { diff --git a/opencl/test/unit_test/os_interface/linux/drm_command_stream_fixture.h b/opencl/test/unit_test/os_interface/linux/drm_command_stream_fixture.h index cf4d2f85e7..993eaa4dcc 100644 --- a/opencl/test/unit_test/os_interface/linux/drm_command_stream_fixture.h +++ b/opencl/test/unit_test/os_interface/linux/drm_command_stream_fixture.h @@ -85,6 +85,7 @@ class DrmCommandStreamEnhancedTest : public ::testing::Test { MockExecutionEnvironment *executionEnvironment; DrmMockCustom *mock; CommandStreamReceiver *csr = nullptr; + const uint32_t rootDeviceIndex = 0u; DrmMemoryManager *mm = nullptr; std::unique_ptr device; @@ -99,10 +100,10 @@ class DrmCommandStreamEnhancedTest : public ::testing::Test { DebugManager.flags.EnableForcePin.set(false); mock = new DrmMockCustom(); - executionEnvironment->rootDeviceEnvironments[0]->osInterface = std::make_unique(); - executionEnvironment->rootDeviceEnvironments[0]->osInterface->get()->setDrm(mock); + executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->osInterface = std::make_unique(); + executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->osInterface->get()->setDrm(mock); - csr = new TestedDrmCommandStreamReceiver(*executionEnvironment); + csr = new TestedDrmCommandStreamReceiver(*executionEnvironment, rootDeviceIndex); ASSERT_NE(nullptr, csr); mm = new DrmMemoryManager(gemCloseWorkerMode::gemCloseWorkerInactive, DebugManager.flags.EnableForcePin.get(), @@ -110,7 +111,7 @@ class DrmCommandStreamEnhancedTest : public ::testing::Test { *executionEnvironment); ASSERT_NE(nullptr, mm); executionEnvironment->memoryManager.reset(mm); - device.reset(MockDevice::create(executionEnvironment, 0u)); + device.reset(MockDevice::create(executionEnvironment, rootDeviceIndex)); device->resetCommandStreamReceiver(csr); ASSERT_NE(nullptr, device); } diff --git a/opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp b/opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp index 3da6262b9b..b55cc4d38d 100644 --- a/opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp +++ b/opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp @@ -593,23 +593,19 @@ TEST_F(DrmMemoryManagerTest, BoWaitFailure) { } TEST_F(DrmMemoryManagerTest, NullOsHandleStorageAskedForPopulationReturnsFilledPointer) { - mock->ioctl_expected.gemUserptr = 0; - mock->ioctl_expected.gemWait = 0; - mock->ioctl_expected.gemClose = 0; - - nonDefaultDrm->ioctl_expected.gemUserptr = 1; - nonDefaultDrm->ioctl_expected.gemWait = 1; - nonDefaultDrm->ioctl_expected.gemClose = 1; + mock->ioctl_expected.gemUserptr = 1; + mock->ioctl_expected.gemWait = 1; + mock->ioctl_expected.gemClose = 1; OsHandleStorage storage; storage.fragmentStorageData[0].cpuPtr = reinterpret_cast(0x1000); storage.fragmentStorageData[0].fragmentSize = 1; - memoryManager->populateOsHandles(storage, nonDefaultRootDeviceIndex); + memoryManager->populateOsHandles(storage, rootDeviceIndex); EXPECT_NE(nullptr, storage.fragmentStorageData[0].osHandleStorage); EXPECT_EQ(nullptr, storage.fragmentStorageData[1].osHandleStorage); EXPECT_EQ(nullptr, storage.fragmentStorageData[2].osHandleStorage); storage.fragmentStorageData[0].freeTheFragment = true; - memoryManager->cleanOsHandles(storage, nonDefaultRootDeviceIndex); + memoryManager->cleanOsHandles(storage, rootDeviceIndex); } TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenEnabledHostMemoryValidationWhenReadOnlyPointerCausesPinningFailWithEfaultThenPopulateOsHandlesReturnsInvalidHostPointerError) { @@ -2054,7 +2050,7 @@ TEST_F(DrmMemoryManagerTest, givenSharedHandleWhenAllocationIsCreatedAndIoctlPri } TEST_F(DrmMemoryManagerTest, givenTwoGraphicsAllocationsThatShareTheSameBufferObjectWhenTheyAreMadeResidentThenOnlyOneBoIsPassedToExec) { - auto testedCsr = new TestedDrmCommandStreamReceiver(*executionEnvironment); + auto testedCsr = new TestedDrmCommandStreamReceiver(*executionEnvironment, rootDeviceIndex); device->resetCommandStreamReceiver(testedCsr); mock->reset(); @@ -2090,7 +2086,7 @@ TEST_F(DrmMemoryManagerTest, givenTwoGraphicsAllocationsThatDoesnShareTheSameBuf mock->testIoctls(); - auto testedCsr = new TestedDrmCommandStreamReceiver(*executionEnvironment); + auto testedCsr = new TestedDrmCommandStreamReceiver(*executionEnvironment, rootDeviceIndex); device->resetCommandStreamReceiver(testedCsr); mock->reset(); diff --git a/opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.h b/opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.h index 3a31d555d5..39c6bf8e4c 100644 --- a/opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.h +++ b/opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.h @@ -24,22 +24,24 @@ using AllocationData = TestedDrmMemoryManager::AllocationData; class DrmMemoryManagerBasic : public ::testing::Test { public: - DrmMemoryManagerBasic() : executionEnvironment(defaultHwInfo.get()){}; + DrmMemoryManagerBasic() : executionEnvironment(defaultHwInfo.get(), false, numRootDevices){}; void SetUp() override { - executionEnvironment.rootDeviceEnvironments[0]->osInterface = std::make_unique(); - executionEnvironment.rootDeviceEnvironments[0]->osInterface->get()->setDrm(Drm::create(nullptr, *executionEnvironment.rootDeviceEnvironments[0])); - executionEnvironment.rootDeviceEnvironments[0]->memoryOperationsInterface = std::make_unique(); + for (auto i = 0u; i < numRootDevices; i++) { + executionEnvironment.rootDeviceEnvironments[i]->osInterface = std::make_unique(); + executionEnvironment.rootDeviceEnvironments[i]->osInterface->get()->setDrm(Drm::create(nullptr, *executionEnvironment.rootDeviceEnvironments[i])); + executionEnvironment.rootDeviceEnvironments[i]->memoryOperationsInterface = std::make_unique(); + } } - const uint32_t rootDeviceIndex = 0u; + const uint32_t rootDeviceIndex = 1u; + const uint32_t numRootDevices = 2u; MockExecutionEnvironment executionEnvironment; }; class DrmMemoryManagerFixture : public MemoryManagementFixture { public: - DrmMockCustom *mock; - DrmMockCustom *nonDefaultDrm = nullptr; - const uint32_t nonDefaultRootDeviceIndex = 1u; - const uint32_t rootDeviceIndex = 0u; + DrmMockCustom *mock = nullptr; + const uint32_t rootDeviceIndex = 1u; + const uint32_t numRootDevices = 2u; TestedDrmMemoryManager *memoryManager = nullptr; MockClDevice *device = nullptr; @@ -51,16 +53,16 @@ class DrmMemoryManagerFixture : public MemoryManagementFixture { void SetUp(DrmMockCustom *mock, bool localMemoryEnabled) { allocationData.rootDeviceIndex = rootDeviceIndex; this->mock = mock; - executionEnvironment = new MockExecutionEnvironment(defaultHwInfo.get(), false, nonDefaultRootDeviceIndex + 1); + executionEnvironment = new MockExecutionEnvironment(defaultHwInfo.get(), false, numRootDevices); executionEnvironment->incRefInternal(); - rootDeviceEnvironment = executionEnvironment->rootDeviceEnvironments[0].get(); - rootDeviceEnvironment->osInterface = std::make_unique(); - rootDeviceEnvironment->osInterface->get()->setDrm(mock); + for (auto i = 0u; i < numRootDevices; i++) { + auto rootDeviceEnvironment = executionEnvironment->rootDeviceEnvironments[i].get(); + rootDeviceEnvironment->osInterface = std::make_unique(); + rootDeviceEnvironment->osInterface->get()->setDrm(new DrmMockCustom()); + } - nonDefaultDrm = new DrmMockCustom(); - auto nonDefaultRootDeviceEnvironment = executionEnvironment->rootDeviceEnvironments[nonDefaultRootDeviceIndex].get(); - nonDefaultRootDeviceEnvironment->osInterface = std::make_unique(); - nonDefaultRootDeviceEnvironment->osInterface->get()->setDrm(nonDefaultDrm); + rootDeviceEnvironment = executionEnvironment->rootDeviceEnvironments[rootDeviceIndex].get(); + rootDeviceEnvironment->osInterface->get()->setDrm(mock); memoryManager = new (std::nothrow) TestedDrmMemoryManager(localMemoryEnabled, false, false, *executionEnvironment); executionEnvironment->memoryManager.reset(memoryManager); @@ -69,7 +71,7 @@ class DrmMemoryManagerFixture : public MemoryManagementFixture { if (memoryManager->getgemCloseWorker()) { memoryManager->getgemCloseWorker()->close(true); } - device = new MockClDevice{MockDevice::create(executionEnvironment, 0)}; + device = new MockClDevice{MockDevice::create(executionEnvironment, rootDeviceIndex)}; mock->reset(); } diff --git a/opencl/test/unit_test/os_interface/linux/linux_create_command_queue_with_properties_tests.cpp b/opencl/test/unit_test/os_interface/linux/linux_create_command_queue_with_properties_tests.cpp index 3645cb5166..5c8f593746 100644 --- a/opencl/test/unit_test/os_interface/linux/linux_create_command_queue_with_properties_tests.cpp +++ b/opencl/test/unit_test/os_interface/linux/linux_create_command_queue_with_properties_tests.cpp @@ -24,9 +24,9 @@ struct clCreateCommandQueueWithPropertiesLinux : public UltCommandStreamReceiver executionEnvironment->prepareRootDeviceEnvironments(1); auto osInterface = new OSInterface(); osInterface->get()->setDrm(drm); - executionEnvironment->rootDeviceEnvironments[0]->osInterface.reset(osInterface); + executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->osInterface.reset(osInterface); executionEnvironment->memoryManager.reset(new TestedDrmMemoryManager(*executionEnvironment)); - mdevice = std::make_unique(MockDevice::create(executionEnvironment, 0u)); + mdevice = std::make_unique(MockDevice::create(executionEnvironment, rootDeviceIndex)); clDevice = mdevice.get(); retVal = CL_SUCCESS; @@ -38,8 +38,9 @@ struct clCreateCommandQueueWithPropertiesLinux : public UltCommandStreamReceiver DrmMock *drm = new DrmMock(); std::unique_ptr mdevice = nullptr; std::unique_ptr context; - cl_device_id clDevice; - cl_int retVal; + cl_device_id clDevice = nullptr; + cl_int retVal = 0; + const uint32_t rootDeviceIndex = 0u; }; namespace ULT { @@ -110,7 +111,7 @@ HWTEST_F(clCreateCommandQueueWithPropertiesLinux, givenPropertiesWithClQueueSlic cl_queue_properties properties[] = {CL_QUEUE_SLICE_COUNT_INTEL, newSliceCount, 0}; - auto mockCsr = new TestedDrmCommandStreamReceiver(*mdevice->executionEnvironment); + auto mockCsr = new TestedDrmCommandStreamReceiver(*mdevice->executionEnvironment, rootDeviceIndex); mdevice->resetCommandStreamReceiver(mockCsr); cl_command_queue cmdQ = clCreateCommandQueueWithProperties(context.get(), clDevice, properties, &retVal); @@ -154,7 +155,7 @@ HWTEST_F(clCreateCommandQueueWithPropertiesLinux, givenSameSliceCountAsRecentlyS cl_queue_properties properties[] = {CL_QUEUE_SLICE_COUNT_INTEL, newSliceCount, 0}; - auto mockCsr = new TestedDrmCommandStreamReceiver(*mdevice->executionEnvironment); + auto mockCsr = new TestedDrmCommandStreamReceiver(*mdevice->executionEnvironment, rootDeviceIndex); mdevice->resetCommandStreamReceiver(mockCsr); cl_command_queue cmdQ = clCreateCommandQueueWithProperties(context.get(), clDevice, properties, &retVal); @@ -197,7 +198,7 @@ HWTEST_F(clCreateCommandQueueWithPropertiesLinux, givenPropertiesWithClQueueSlic cl_queue_properties properties[] = {CL_QUEUE_SLICE_COUNT_INTEL, newSliceCount, 0}; - auto mockCsr = new TestedDrmCommandStreamReceiver(*mdevice->executionEnvironment); + auto mockCsr = new TestedDrmCommandStreamReceiver(*mdevice->executionEnvironment, rootDeviceIndex); mdevice->resetCommandStreamReceiver(mockCsr); cl_command_queue cmdQ = clCreateCommandQueueWithProperties(context.get(), clDevice, properties, &retVal);