diff --git a/level_zero/tools/source/debug/debug_session_imp.cpp b/level_zero/tools/source/debug/debug_session_imp.cpp index 69ec7f22d4..4c0a92e15a 100644 --- a/level_zero/tools/source/debug/debug_session_imp.cpp +++ b/level_zero/tools/source/debug/debug_session_imp.cpp @@ -698,7 +698,10 @@ void DebugSessionImp::markPendingInterruptsOrAddToNewlyStoppedFromRaisedAttentio auto isInterrupted = checkSingleThreadWithinDeviceThread(apiThread, request.first); if (isInterrupted) { - request.second = true; + // mark pending interrupt as completed successfully only when new thread has been stopped + if (!wasStopped) { + request.second = true; + } threadWasInterrupted = true; } } diff --git a/level_zero/tools/test/unit_tests/sources/debug/debug_session_tests.cpp b/level_zero/tools/test/unit_tests/sources/debug/debug_session_tests.cpp index 4a894d4470..3eebe68c4c 100644 --- a/level_zero/tools/test/unit_tests/sources/debug/debug_session_tests.cpp +++ b/level_zero/tools/test/unit_tests/sources/debug/debug_session_tests.cpp @@ -182,7 +182,7 @@ TEST(DebugSessionTest, givenInterruptRequestWhenInterruptImpFailsInSendInterrupt EXPECT_EQ(0u, sessionMock->pendingInterrupts.size()); } -TEST(DebugSessionTest, givenPendingInteruptWhenHadnlingThreadWithAttentionThenPendingInterruptIsMarkedComplete) { +TEST(DebugSessionTest, givenPendingInteruptWhenHandlingThreadWithAttentionThenPendingInterruptIsMarkedComplete) { zet_debug_config_t config = {}; config.pid = 0x1234; auto hwInfo = *NEO::defaultHwInfo.get(); @@ -207,6 +207,44 @@ TEST(DebugSessionTest, givenPendingInteruptWhenHadnlingThreadWithAttentionThenPe EXPECT_EQ(0u, sessionMock->newlyStoppedThreads.size()); } +TEST(DebugSessionTest, givenPreviouslyStoppedThreadAndPendingInterruptWhenHandlingThreadWithAttentionThenPendingInterruptIsNotMarkedCompleteAndInterruptGeneratesUnavailableEvent) { + zet_debug_config_t config = {}; + config.pid = 0x1234; + auto hwInfo = *NEO::defaultHwInfo.get(); + + NEO::MockDevice *neoDevice(NEO::MockDevice::createWithNewExecutionEnvironment(&hwInfo, 0)); + Mock deviceImp(neoDevice, neoDevice->getExecutionEnvironment()); + + auto sessionMock = std::make_unique(config, &deviceImp); + + ze_device_thread_t apiThread = {0, 0, 0, 0}; + EuThread::ThreadId thread(0, 0, 0, 0, 0); + + auto result = sessionMock->interrupt(apiThread); + EXPECT_EQ(ZE_RESULT_SUCCESS, result); + + sessionMock->sendInterrupts(); + + // stop thread for a reason different than interrupt exception (forceException) + sessionMock->onlyForceException = false; + sessionMock->allThreads[thread]->stopThread(1u); + + sessionMock->markPendingInterruptsOrAddToNewlyStoppedFromRaisedAttention(thread, 1u); + + EXPECT_TRUE(sessionMock->allThreads[thread]->isStopped()); + + EXPECT_FALSE(sessionMock->pendingInterrupts[0].second); + EXPECT_EQ(0u, sessionMock->newlyStoppedThreads.size()); + + sessionMock->expectedAttentionEvents = 0; + sessionMock->checkTriggerEventsForAttention(); + sessionMock->generateEventsAndResumeStoppedThreads(); + + EXPECT_EQ(1u, sessionMock->events.size()); + EXPECT_EQ(ZET_DEBUG_EVENT_TYPE_THREAD_UNAVAILABLE, sessionMock->events[0].type); + EXPECT_TRUE(DebugSession::areThreadsEqual(apiThread, sessionMock->events[0].info.thread.thread)); +} + TEST(DebugSessionTest, givenStoppedThreadWhenAddingNewlyStoppedThenThreadIsNotAdded) { zet_debug_config_t config = {}; config.pid = 0x1234;