From 7910567a763a62bd0134bc241c518bec678a96db Mon Sep 17 00:00:00 2001 From: Mateusz Jablonski Date: Fri, 1 Apr 2022 09:40:06 +0000 Subject: [PATCH] Handle missing tag address in getting completion address rename test fixture to comply one definition rule Related-To: NEO-6643 Signed-off-by: Mateusz Jablonski --- ...rm_command_stream_xehp_and_later_tests.cpp | 5 ---- .../linux/drm_memory_manager_tests.cpp | 23 +++++++++++++++++++ .../os_interface/linux/drm_command_stream.inl | 3 +++ .../linux/drm_command_stream_tests.cpp | 15 ++++++++---- 4 files changed, 37 insertions(+), 9 deletions(-) diff --git a/opencl/test/unit_test/os_interface/linux/drm_command_stream_xehp_and_later_tests.cpp b/opencl/test/unit_test/os_interface/linux/drm_command_stream_xehp_and_later_tests.cpp index 7934258b4a..e90840c128 100644 --- a/opencl/test/unit_test/os_interface/linux/drm_command_stream_xehp_and_later_tests.cpp +++ b/opencl/test/unit_test/os_interface/linux/drm_command_stream_xehp_and_later_tests.cpp @@ -72,14 +72,9 @@ struct DrmCommandStreamMultiTileMemExecFixture { using DrmCommandStreamMultiTileMemExecTest = Test; HWCMDTEST_F(IGFX_XE_HP_CORE, DrmCommandStreamMultiTileMemExecTest, GivenDrmSupportsCompletionFenceAndVmBindWhenCallingCsrExecThenMultipleTagAllocationIsPassed) { - auto osContext = std::make_unique(*mock, 0u, EngineDescriptorHelper::getDefaultDescriptor(device->getDeviceBitfield())); - osContext->ensureContextInitialized(); - auto *testCsr = new TestedDrmCommandStreamReceiver(*executionEnvironment, 0, device->getDeviceBitfield()); - auto device = std::unique_ptr(MockDevice::create(executionEnvironment, 0)); device->resetCommandStreamReceiver(testCsr); EXPECT_EQ(2u, testCsr->activePartitions); - testCsr->setupContext(*osContext.get()); mock->completionFenceSupported = true; mock->isVmBindAvailableCall.callParent = false; 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 093b30408b..6c15e10a40 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 @@ -5920,4 +5920,27 @@ TEST_F(DrmMemoryManagerTest, givenCompletionFenceEnabledWhenHandlingCompletionOf memoryManager->freeGraphicsMemory(allocation); } +HWTEST_F(DrmMemoryManagerTest, givenCompletionFenceEnabledWhenHandlingCompletionAndTagAddressIsNullThenDoNotCallWaitUserFence) { + mock->ioctl_expected.total = -1; + + VariableBackup backupFenceSupported{&mock->completionFenceSupported, true}; + VariableBackup backupVmBindCallParent{&mock->isVmBindAvailableCall.callParent, false}; + VariableBackup backupVmBindReturnValue{&mock->isVmBindAvailableCall.returnValue, true}; + + auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{rootDeviceIndex, 1024, AllocationType::COMMAND_BUFFER}); + auto engine = memoryManager->getRegisteredEngines()[0]; + allocation->updateTaskCount(2, engine.osContext->getContextId()); + + auto testCsr = static_cast *>(engine.commandStreamReceiver); + auto backupTagAddress = testCsr->tagAddress; + testCsr->tagAddress = nullptr; + + memoryManager->handleFenceCompletion(allocation); + EXPECT_EQ(0u, mock->waitUserFenceCall.called); + + testCsr->tagAddress = backupTagAddress; + + memoryManager->freeGraphicsMemory(allocation); +} + } // namespace NEO diff --git a/shared/source/os_interface/linux/drm_command_stream.inl b/shared/source/os_interface/linux/drm_command_stream.inl index a24fe6f057..2b66a013f0 100644 --- a/shared/source/os_interface/linux/drm_command_stream.inl +++ b/shared/source/os_interface/linux/drm_command_stream.inl @@ -319,6 +319,9 @@ inline bool DrmCommandStreamReceiver::isUserFenceWaitActive() { template uint64_t DrmCommandStreamReceiver::getCompletionAddress() { uint64_t completionFenceAddress = castToUint64(const_cast(getTagAddress())); + if (completionFenceAddress == 0) { + return 0; + } completionFenceAddress += Drm::completionFenceOffset; return completionFenceAddress; } diff --git a/shared/test/unit_test/os_interface/linux/drm_command_stream_tests.cpp b/shared/test/unit_test/os_interface/linux/drm_command_stream_tests.cpp index 6c5fadfb79..3b95bcad46 100644 --- a/shared/test/unit_test/os_interface/linux/drm_command_stream_tests.cpp +++ b/shared/test/unit_test/os_interface/linux/drm_command_stream_tests.cpp @@ -29,7 +29,7 @@ extern ApiSpecificConfig::ApiType apiTypeForUlts; } //namespace NEO using namespace NEO; -class DrmCommandStreamTest : public ::testing::Test { +class DrmCommandStreamTest2 : public ::testing::Test { public: template void SetUpT() { @@ -95,21 +95,28 @@ struct MockDrmCsr : public DrmCommandStreamReceiver { using DrmCommandStreamReceiver::dispatchMode; }; -HWTEST_TEMPLATED_F(DrmCommandStreamTest, givenL0ApiConfigWhenCreatingDrmCsrThenEnableImmediateDispatch) { +HWTEST_TEMPLATED_F(DrmCommandStreamTest2, givenL0ApiConfigWhenCreatingDrmCsrThenEnableImmediateDispatch) { VariableBackup backup(&apiTypeForUlts, ApiSpecificConfig::L0); MockDrmCsr csr(executionEnvironment, 0, 1, gemCloseWorkerMode::gemCloseWorkerInactive); EXPECT_EQ(DispatchMode::ImmediateDispatch, csr.dispatchMode); } -HWTEST_TEMPLATED_F(DrmCommandStreamTest, whenGettingCompletionValueThenTaskCountOfAllocationIsReturned) { +HWTEST_TEMPLATED_F(DrmCommandStreamTest2, whenGettingCompletionValueThenTaskCountOfAllocationIsReturned) { MockGraphicsAllocation allocation{}; uint32_t expectedValue = 0x1234; allocation.updateTaskCount(expectedValue, osContext->getContextId()); EXPECT_EQ(expectedValue, csr->getCompletionValue(allocation)); } -HWTEST_TEMPLATED_F(DrmCommandStreamTest, whenGettingCompletionAddressThenOffsettedTagAddressIsReturned) { +HWTEST_TEMPLATED_F(DrmCommandStreamTest2, whenGettingCompletionAddressThenOffsettedTagAddressIsReturned) { + csr->initializeTagAllocation(); + EXPECT_NE(nullptr, csr->getTagAddress()); uint64_t tagAddress = castToUint64(const_cast(csr->getTagAddress())); auto expectedAddress = tagAddress + Drm::completionFenceOffset; EXPECT_EQ(expectedAddress, csr->getCompletionAddress()); } + +HWTEST_TEMPLATED_F(DrmCommandStreamTest2, givenNoTagAddressWhenGettingCompletionAddressThenZeroIsReturned) { + EXPECT_EQ(nullptr, csr->getTagAddress()); + EXPECT_EQ(0u, csr->getCompletionAddress()); +}