Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Alternating Interrupt/Resume Test #86

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions conformance_tests/tools/debug/src/test_debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1440,6 +1440,7 @@ void zetDebugThreadControlTest::SetUpThreadControl(ze_device_handle_t &device,
smaller_thread_functor());
}

#define INTERRUPT_TEST_SLEEP std::chrono::seconds(2)
void zetDebugThreadControlTest::run_alternate_stop_resume_test(
std::vector<ze_device_handle_t> &devices, bool use_sub_devices) {
for (auto &device : devices) {
Expand Down Expand Up @@ -1467,7 +1468,7 @@ void zetDebugThreadControlTest::run_alternate_stop_resume_test(
}
i++;
}
std::this_thread::sleep_for(std::chrono::seconds(2));
std::this_thread::sleep_for(INTERRUPT_TEST_SLEEP);

LOG_INFO
<< "[Debugger] ######### Interrupting Odd AND resumming Even threads "
Expand All @@ -1494,7 +1495,7 @@ void zetDebugThreadControlTest::run_alternate_stop_resume_test(
}
i++;
}
std::this_thread::sleep_for(std::chrono::seconds(2));
std::this_thread::sleep_for(INTERRUPT_TEST_SLEEP);

LOG_INFO
<< "[Debugger] ######### Interrupting Even threads AND resumming Odd "
Expand All @@ -1521,7 +1522,7 @@ void zetDebugThreadControlTest::run_alternate_stop_resume_test(
}
i++;
}
std::this_thread::sleep_for(std::chrono::seconds(2));
std::this_thread::sleep_for(INTERRUPT_TEST_SLEEP);

LOG_INFO << "[Debugger] ######### Interrupting Odd threads ##########";
threadsToCheck.clear();
Expand Down Expand Up @@ -1559,7 +1560,7 @@ void zetDebugThreadControlTest::run_alternate_stop_resume_test(
i++;
}

std::this_thread::sleep_for(std::chrono::seconds(2));
std::this_thread::sleep_for(INTERRUPT_TEST_SLEEP);
EXPECT_EQ(debugHelper.running(), true);

LOG_INFO << "[Debugger] ######### Ressuming Odd threads ##########";
Expand All @@ -1573,7 +1574,7 @@ void zetDebugThreadControlTest::run_alternate_stop_resume_test(
}

LOG_INFO << "[Debugger] ######### Checking ALL threads are running ######";
std::this_thread::sleep_for(std::chrono::seconds(2));
std::this_thread::sleep_for(INTERRUPT_TEST_SLEEP);
stoppedThreadsCheck.clear();
stoppedThreadsCheck = get_stopped_threads(debugSession, device);
EXPECT_EQ(stoppedThreadsCheck.size(), 0);
Expand Down Expand Up @@ -1608,7 +1609,7 @@ void zetDebugThreadControlTest::run_alternate_stop_resume_test(

LOG_INFO
<< "[Debugger] ######### Checking ALL threads are running ##########";
std::this_thread::sleep_for(std::chrono::seconds(2));
std::this_thread::sleep_for(INTERRUPT_TEST_SLEEP);
stoppedThreadsCheck.clear();
stoppedThreadsCheck = get_stopped_threads(debugSession, device);
EXPECT_EQ(stoppedThreadsCheck.size(), 0);
Expand Down
45 changes: 44 additions & 1 deletion conformance_tests/tools/debug/src/test_debug_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -577,18 +577,25 @@ bool find_multi_event_stopped_threads(
uint8_t attempts = 0;
uint16_t numEventsReceived = 0;
uint16_t numEventsExpected = threadsToCheck.size();
uint8_t retryAttempts = 0;

zet_debug_event_t debugEvent = {};
stoppedThreadsFound.clear();
bool foundAll = true;

std::vector<ze_device_thread_t> stoppedThreadsFromEvent;
LOG_DEBUG << "[Debugger] Expecting " << threadsToCheck.size() << " events.";
for (auto threadToCheck : threadsToCheck) {
auto sleepTime = 30;
int numEvents = 0;
int numEventsExpectedDuringRetry = numEventsExpected;
std::vector<ze_device_thread_t> threadsToRetry;
while ((numEventsReceived < numEventsExpected) && (retryAttempts <= 5)) {
do {
lzt::debug_read_event(debugSession, debugEvent, eventsTimeoutMS / 10,
true);
LOG_INFO << "[Debugger] received event: "
<< lzt::debuggerEventTypeString[debugEvent.type];
numEvents++;

if (debugEvent.type == ZET_DEBUG_EVENT_TYPE_THREAD_STOPPED) {
print_thread("[Debugger] Stopped thread event for ",
Expand All @@ -598,11 +605,47 @@ bool find_multi_event_stopped_threads(
EXPECT_TRUE(is_thread_in_vector(debugEvent.info.thread.thread,
threadsToCheck));
}
stoppedThreadsFromEvent.push_back(debugEvent.info.thread.thread);
numEventsReceived++;
break;
} else if (debugEvent.type == ZET_DEBUG_EVENT_TYPE_THREAD_UNAVAILABLE) {
// there is a thread we need to retry interrupting
print_thread("[Debugger] Thread unavailable event for ",
debugEvent.info.thread.thread, DEBUG);

} else {
LOG_WARNING << "[Debugger] Unexpected event received: "
<< lzt::debuggerEventTypeString[debugEvent.type];
}
attempts++;
} while (attempts < 5);
attempts = 0;

if (numEvents >= numEventsExpectedDuringRetry && retryAttempts < 5) {
numEvents = 0;
for (auto &thread : threadsToCheck) {
if (is_thread_in_vector(thread, stoppedThreadsFromEvent))
continue;
threadsToRetry.push_back(thread);
}
if (threadsToRetry.empty()) {
break;
}
numEventsExpectedDuringRetry = threadsToRetry.size();
LOG_INFO << "[Debugger] Sleeping for " << sleepTime
<< " seconds before retrying to interrupt threads";
std::this_thread::sleep_for(std::chrono::seconds(sleepTime));
LOG_INFO << "[Debugger] Trying to interrupt threads again";
for (auto &thread : threadsToRetry) {
print_thread("[Debugger] \t\tThread to interrupt: ", thread, INFO);
}
for (auto &thread : threadsToRetry) {
lzt::debug_interrupt(debugSession, thread, true);
}
retryAttempts++;
sleepTime += 10;
threadsToRetry.clear();
}
}

EXPECT_EQ(numEventsReceived, numEventsExpected);
Expand Down
7 changes: 4 additions & 3 deletions utils/test_harness/tools/include/test_harness_debug.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,15 @@ void debug_ack_event(const zet_debug_session_handle_t &debug_session,
const zet_debug_event_t *debug_event);

void debug_interrupt(const zet_debug_session_handle_t &debug_session,
const ze_device_thread_t &device_thread);
const ze_device_thread_t &device_thread,
bool retry = false);

void debug_resume(const zet_debug_session_handle_t &debug_session,
const ze_device_thread_t &device_thread);

void clear_exceptions(const ze_device_handle_t &device,
const zet_debug_session_handle_t &debug_session,
const ze_device_thread_t &device_thread);
const zet_debug_session_handle_t &debug_session,
const ze_device_thread_t &device_thread);

void debug_read_memory(const zet_debug_session_handle_t &debug_session,
const ze_device_thread_t &device_thread,
Expand Down
20 changes: 16 additions & 4 deletions utils/test_harness/tools/src/test_harness_debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,21 @@ void debug_ack_event(const zet_debug_session_handle_t &debug_session,
}

void debug_interrupt(const zet_debug_session_handle_t &debug_session,
const ze_device_thread_t &device_thread) {
const ze_device_thread_t &device_thread, bool retry) {

EXPECT_EQ(ZE_RESULT_SUCCESS, zetDebugInterrupt(debug_session, device_thread));
if (!retry) {
EXPECT_EQ(ZE_RESULT_SUCCESS,
zetDebugInterrupt(debug_session, device_thread));
} else {
auto result = zetDebugInterrupt(debug_session, device_thread);
if (result != ZE_RESULT_SUCCESS) {
LOG_WARNING << "[Debugger] Interrupt failed: " << result
<< " SLICE:" << device_thread.slice
<< " SUBSLICE: " << device_thread.subslice
<< " EU: " << device_thread.eu
<< " THREAD: " << device_thread.thread;
}
}
}

void debug_resume(const zet_debug_session_handle_t &debug_session,
Expand Down Expand Up @@ -181,8 +193,8 @@ bool get_register_set_props(ze_device_handle_t device,
}

void clear_exceptions(const ze_device_handle_t &device,
const zet_debug_session_handle_t &debug_session,
const ze_device_thread_t &device_thread) {
const zet_debug_session_handle_t &debug_session,
const ze_device_thread_t &device_thread) {
size_t reg_size_in_bytes = 0;

zet_debug_regset_properties_t cr_reg_prop;
Expand Down
Loading