Skip to content

Commit

Permalink
Fix flake in TestZerothFrame.py
Browse files Browse the repository at this point in the history
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
  • Loading branch information
kendal committed Jun 27, 2024
1 parent 0c56fd0 commit 1ca25a2
Showing 1 changed file with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@


class ZerothFrame(TestBase):
def _is_thread_executing_file(self, thread, file_basename):
frame = thread.GetSelectedFrame()
module = frame.GetModule()
filename = module.GetFileSpec().GetFilename()
return os.path.basename(filename) == file_basename

def test(self):
"""
Test that line information is recalculated properly for a frame when it moves
Expand All @@ -53,14 +59,23 @@ def test(self):
process = target.LaunchSimple(None, None, self.get_process_working_directory())
self.assertTrue(process, VALID_PROCESS)

thread = process.GetThreadAtIndex(0)
# Find the thread that is running a.out.
thread = None
for i in range(len(process.thread)):
if self._is_thread_executing_file(process.thread[i], "a.out"):
thread = process.thread[i]
break

self.assertTrue(thread != None, "failed to find thread executing a.out")

if self.TraceOn():
print("Backtrace at the first breakpoint:")
for f in thread.frames:
print(f)

# Check that we have stopped at correct breakpoint.
self.assertEqual(
process.GetThreadAtIndex(0).frame[0].GetLineEntry().GetLine(),
thread.frame[0].GetLineEntry().GetLine(),
bp1_line,
"LLDB reported incorrect line number.",
)
Expand All @@ -70,7 +85,6 @@ def test(self):
# 'continue' command.
process.Continue()

thread = process.GetThreadAtIndex(0)
if self.TraceOn():
print("Backtrace at the second breakpoint:")
for f in thread.frames:
Expand Down

0 comments on commit 1ca25a2

Please sign in to comment.