Skip to content

Commit 1d2c11e

Browse files
author
kendal
committed
Fix flake in TestZerothFrame.py
This test is relying on the order of `process.threads` which is nondeterministic. By selecting the thread based on whether it is stopped at our breakpoint we can reliably select the correct one.
1 parent 0c56fd0 commit 1d2c11e

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

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

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,28 +40,24 @@ def test(self):
4040
target = self.dbg.CreateTarget(exe)
4141
self.assertTrue(target, VALID_TARGET)
4242

43-
bp1_line = line_number("main.c", "// Set breakpoint 1 here")
44-
bp2_line = line_number("main.c", "// Set breakpoint 2 here")
45-
46-
lldbutil.run_break_set_by_file_and_line(
47-
self, "main.c", bp1_line, num_expected_locations=1
48-
)
49-
lldbutil.run_break_set_by_file_and_line(
50-
self, "main.c", bp2_line, num_expected_locations=1
51-
)
43+
main_dot_c = lldb.SBFileSpec("main.c")
44+
bp1 = target.BreakpointCreateBySourceRegex("// Set breakpoint 1 here", main_dot_c)
45+
bp2 = target.BreakpointCreateBySourceRegex("// Set breakpoint 2 here", main_dot_c)
5246

5347
process = target.LaunchSimple(None, None, self.get_process_working_directory())
5448
self.assertTrue(process, VALID_PROCESS)
5549

56-
thread = process.GetThreadAtIndex(0)
50+
thread = self.thread()
51+
5752
if self.TraceOn():
5853
print("Backtrace at the first breakpoint:")
5954
for f in thread.frames:
6055
print(f)
56+
6157
# Check that we have stopped at correct breakpoint.
6258
self.assertEqual(
63-
process.GetThreadAtIndex(0).frame[0].GetLineEntry().GetLine(),
64-
bp1_line,
59+
thread.frame[0].GetLineEntry().GetLine(),
60+
bp1.GetLocationAtIndex(0).GetAddress().GetLineEntry().GetLine(),
6561
"LLDB reported incorrect line number.",
6662
)
6763

@@ -70,15 +66,14 @@ def test(self):
7066
# 'continue' command.
7167
process.Continue()
7268

73-
thread = process.GetThreadAtIndex(0)
7469
if self.TraceOn():
7570
print("Backtrace at the second breakpoint:")
7671
for f in thread.frames:
7772
print(f)
7873
# Check that we have stopped at the breakpoint
7974
self.assertEqual(
8075
thread.frame[0].GetLineEntry().GetLine(),
81-
bp2_line,
76+
bp2.GetLocationAtIndex(0).GetAddress().GetLineEntry().GetLine(),
8277
"LLDB reported incorrect line number.",
8378
)
8479
# Double-check with GetPCAddress()

0 commit comments

Comments
 (0)