Skip to content

Commit dbc40b3

Browse files
authoredFeb 14, 2024
[lldb] Fix the flakey Concurrent tests on macOS (#81710)
The concurrent tests all do a pthread_join at the end, and concurrent_base.py stops after that pthread_join and sanity checks that only 1 thread is running. On macOS, after pthread_join() has completed, there can be an extra thread still running which is completing the details of that task asynchronously; this causes testsuite failures. When this happens, we see the second thread is in ``` frame #0: 0x0000000180ce7700 libsystem_kernel.dylib`__ulock_wake + 8 frame #1: 0x0000000180d25ad4 libsystem_pthread.dylib`_pthread_joiner_wake + 52 frame #2: 0x0000000180d23c18 libsystem_pthread.dylib`_pthread_terminate + 384 frame #3: 0x0000000180d23a98 libsystem_pthread.dylib`_pthread_terminate_invoke + 92 frame #4: 0x0000000180d26740 libsystem_pthread.dylib`_pthread_exit + 112 frame #5: 0x0000000180d26040 libsystem_pthread.dylib`_pthread_start + 148 ``` there are none of the functions from the test file present on this thread. In this patch, instead of counting the number of threads, I iterate over the threads looking for functions from our test file (by name) and only count threads that have at least one of them. It's a lower frequency failure than the darwin kernel bug causing an extra step instruction mach exception when hardware breakpoint/watchpoints are used, but once I fixed that, this came up as the next most common failure for these tests. rdar://110555062
1 parent 630f82e commit dbc40b3

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed
 

‎lldb/packages/Python/lldbsuite/test/concurrent_base.py

+31-3
Original file line numberDiff line numberDiff line change
@@ -264,12 +264,40 @@ def do_thread_actions(
264264
"Expected main thread (finish) breakpoint to be hit once",
265265
)
266266

267-
num_threads = self.inferior_process.GetNumThreads()
267+
# There should be a single active thread (the main one) which hit
268+
# the breakpoint after joining. Depending on the pthread
269+
# implementation we may have a worker thread finishing the pthread_join()
270+
# after it has returned. Filter the threads to only count those
271+
# with user functions on them from our test case file,
272+
# lldb/test/API/functionalities/thread/concurrent_events/main.cpp
273+
user_code_funcnames = [
274+
"breakpoint_func",
275+
"crash_func",
276+
"do_action_args",
277+
"dotest",
278+
"main",
279+
"register_signal_handler",
280+
"signal_func",
281+
"sigusr1_handler",
282+
"start_threads",
283+
"watchpoint_func",
284+
]
285+
num_threads_with_usercode = 0
286+
for t in self.inferior_process.threads:
287+
thread_has_user_code = False
288+
for f in t.frames:
289+
for funcname in user_code_funcnames:
290+
if funcname in f.GetDisplayFunctionName():
291+
thread_has_user_code = True
292+
break
293+
if thread_has_user_code:
294+
num_threads_with_usercode += 1
295+
268296
self.assertEqual(
269297
1,
270-
num_threads,
298+
num_threads_with_usercode,
271299
"Expecting 1 thread but seeing %d. Details:%s"
272-
% (num_threads, "\n\t".join(self.describe_threads())),
300+
% (num_threads_with_usercode, "\n\t".join(self.describe_threads())),
273301
)
274302
self.runCmd("continue")
275303

0 commit comments

Comments
 (0)