Skip to content

Commit 1ca25a2

Browse files
author
kendal
committed
Fix flake in TestZerothFrame.py
This test is relying on the order of `process.threads` which is nondeterministic. By switching from `process.GetThreadAtIndex` to `process.GetThreadByIndex` we consistently retrieve the correct thread. Adds a helper function to find thread executing a file
1 parent 0c56fd0 commit 1ca25a2

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

lldb/test/API/functionalities/unwind/zeroth_frame/TestZerothFrame.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@
2828

2929

3030
class ZerothFrame(TestBase):
31+
def _is_thread_executing_file(self, thread, file_basename):
32+
frame = thread.GetSelectedFrame()
33+
module = frame.GetModule()
34+
filename = module.GetFileSpec().GetFilename()
35+
return os.path.basename(filename) == file_basename
36+
3137
def test(self):
3238
"""
3339
Test that line information is recalculated properly for a frame when it moves
@@ -53,14 +59,23 @@ def test(self):
5359
process = target.LaunchSimple(None, None, self.get_process_working_directory())
5460
self.assertTrue(process, VALID_PROCESS)
5561

56-
thread = process.GetThreadAtIndex(0)
62+
# Find the thread that is running a.out.
63+
thread = None
64+
for i in range(len(process.thread)):
65+
if self._is_thread_executing_file(process.thread[i], "a.out"):
66+
thread = process.thread[i]
67+
break
68+
69+
self.assertTrue(thread != None, "failed to find thread executing a.out")
70+
5771
if self.TraceOn():
5872
print("Backtrace at the first breakpoint:")
5973
for f in thread.frames:
6074
print(f)
75+
6176
# Check that we have stopped at correct breakpoint.
6277
self.assertEqual(
63-
process.GetThreadAtIndex(0).frame[0].GetLineEntry().GetLine(),
78+
thread.frame[0].GetLineEntry().GetLine(),
6479
bp1_line,
6580
"LLDB reported incorrect line number.",
6681
)
@@ -70,7 +85,6 @@ def test(self):
7085
# 'continue' command.
7186
process.Continue()
7287

73-
thread = process.GetThreadAtIndex(0)
7488
if self.TraceOn():
7589
print("Backtrace at the second breakpoint:")
7690
for f in thread.frames:

0 commit comments

Comments
 (0)