Fix registering and unregistering module debug handle

- do not unregister module handle if not registered before

Signed-off-by: Mateusz Hoppe <mateusz.hoppe@intel.com>
This commit is contained in:
Mateusz Hoppe
2022-02-17 17:05:15 +00:00
committed by Compute-Runtime-Automation
parent b62675290f
commit be7c45bab0
4 changed files with 51 additions and 2 deletions

View File

@@ -50,7 +50,7 @@ bool DebuggerL0::attachZebinModuleToSegmentAllocations(const StackVec<NEO::Graph
}
bool DebuggerL0::removeZebinModule(uint32_t moduleHandle) {
if (device->getRootDeviceEnvironment().osInterface == nullptr) {
if (device->getRootDeviceEnvironment().osInterface == nullptr || moduleHandle == 0) {
return false;
}
auto drm = device->getRootDeviceEnvironment().osInterface->getDriverModel()->as<NEO::Drm>();

View File

@@ -88,7 +88,7 @@ struct ModuleImp : public Module {
auto tempHandle = debugModuleHandle;
auto tempDevice = device;
delete this;
if (tempDevice->getL0Debugger()) {
if (tempDevice->getL0Debugger() && tempHandle != 0) {
tempDevice->getL0Debugger()->removeZebinModule(tempHandle);
}
return ZE_RESULT_SUCCESS;

View File

@@ -220,6 +220,13 @@ TEST_F(L0DebuggerLinuxTest, givenModuleHandleWhenRemoveZebinModuleIsCalledThenHa
EXPECT_EQ(20u, drmMock->unregisteredHandle);
}
TEST_F(L0DebuggerLinuxTest, givenModuleHandleZeroWhenRemoveZebinModuleIsCalledThenDrmUnregisterIsNotCalled) {
uint32_t handle = 0;
EXPECT_FALSE(device->getL0Debugger()->removeZebinModule(handle));
EXPECT_EQ(0u, drmMock->unregisterCalledCount);
}
HWTEST_F(L0DebuggerLinuxTest, givenDebuggingEnabledAndCommandQueuesAreCreatedAndDestroyedThanDebuggerL0IsNotified) {
auto debuggerL0Hw = static_cast<MockDebuggerL0Hw<FamilyType> *>(device->getL0Debugger());

View File

@@ -644,6 +644,48 @@ HWTEST_F(ModuleWithZebinAndL0DebuggerTest, GivenZebinWhenModuleIsInitializedAndD
EXPECT_EQ(6u, getMockDebuggerL0Hw<FamilyType>()->removedZebinModuleHandle);
}
HWTEST_F(ModuleWithZebinAndL0DebuggerTest, GivenModuleDebugHandleZeroWhenInitializingAndDestoryingModuleThenHandleIsNotPassedToDebugger) {
NEO::MockCompilerEnableGuard mock(true);
auto cip = new NEO::MockCompilerInterfaceCaptureBuildOptions();
neoDevice->getExecutionEnvironment()->rootDeviceEnvironments[neoDevice->getRootDeviceIndex()]->compilerInterface.reset(cip);
uint8_t binary[10];
ze_module_desc_t moduleDesc = {};
moduleDesc.format = ZE_MODULE_FORMAT_IL_SPIRV;
moduleDesc.pInputModule = binary;
moduleDesc.inputSize = 10;
uint32_t kernelHeap = 0;
auto kernelInfo = std::make_unique<KernelInfo>();
kernelInfo->heapInfo.KernelHeapSize = 1;
kernelInfo->heapInfo.pKernelHeap = &kernelHeap;
auto kernelImmutableData = ::std::make_unique<KernelImmutableData>(device);
kernelImmutableData->initialize(kernelInfo.get(), device, 0, nullptr, nullptr, false);
std::unique_ptr<MockModule> moduleMock = std::make_unique<MockModule>(device, nullptr, ModuleType::User);
moduleMock->translationUnit = std::make_unique<MockModuleTranslationUnit>(device);
moduleMock->kernelImmDatas.push_back(std::move(kernelImmutableData));
auto zebin = ZebinTestData::ValidEmptyProgram();
moduleMock->translationUnit = std::make_unique<MockModuleTranslationUnit>(device);
moduleMock->translationUnit->unpackedDeviceBinarySize = zebin.storage.size();
moduleMock->translationUnit->unpackedDeviceBinary.reset(new char[zebin.storage.size()]);
memcpy_s(moduleMock->translationUnit->unpackedDeviceBinary.get(), moduleMock->translationUnit->unpackedDeviceBinarySize,
zebin.storage.data(), zebin.storage.size());
getMockDebuggerL0Hw<FamilyType>()->moduleHandleToReturn = 0u;
EXPECT_TRUE(moduleMock->initialize(&moduleDesc, neoDevice));
EXPECT_EQ(1u, getMockDebuggerL0Hw<FamilyType>()->segmentCountWithAttachedModuleHandle);
EXPECT_EQ(getMockDebuggerL0Hw<FamilyType>()->moduleHandleToReturn, moduleMock->debugModuleHandle);
getMockDebuggerL0Hw<FamilyType>()->removedZebinModuleHandle = std::numeric_limits<uint32_t>::max();
moduleMock->destroy();
moduleMock.release();
EXPECT_EQ(std::numeric_limits<uint32_t>::max(), getMockDebuggerL0Hw<FamilyType>()->removedZebinModuleHandle);
}
using NotifyModuleLoadTest = Test<ModuleFixture>;
HWTEST_F(NotifyModuleLoadTest, givenDebuggingEnabledWhenModuleIsCreatedAndFullyLinkedThenIsaAllocationsAreCopiedAndResident) {