https://github.com/kendalharland updated https://github.com/llvm/llvm-project/pull/96685
>From 836b5ee62a5e1e31fe973e1f4ff6cd47f10eca84 Mon Sep 17 00:00:00 2001 From: kendal <kendal@thebrowser.company> Date: Mon, 24 Jun 2024 13:42:20 -0700 Subject: [PATCH] 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. --- .../unwind/zeroth_frame/TestZerothFrame.py | 32 +++++++++++-------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/lldb/test/API/functionalities/unwind/zeroth_frame/TestZerothFrame.py b/lldb/test/API/functionalities/unwind/zeroth_frame/TestZerothFrame.py index f4e883d314644..d6a1be8052995 100644 --- a/lldb/test/API/functionalities/unwind/zeroth_frame/TestZerothFrame.py +++ b/lldb/test/API/functionalities/unwind/zeroth_frame/TestZerothFrame.py @@ -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 @@ -40,28 +46,27 @@ def test(self): target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) - bp1_line = line_number("main.c", "// Set breakpoint 1 here") - bp2_line = line_number("main.c", "// Set breakpoint 2 here") - - lldbutil.run_break_set_by_file_and_line( - self, "main.c", bp1_line, num_expected_locations=1 - ) - lldbutil.run_break_set_by_file_and_line( - self, "main.c", bp2_line, num_expected_locations=1 - ) + main_dot_c = lldb.SBFileSpec("main.c") + bp1 = target.BreakpointCreateBySourceRegex("// Set breakpoint 1 here", main_dot_c) + bp2 = target.BreakpointCreateBySourceRegex("// Set breakpoint 2 here", main_dot_c) process = target.LaunchSimple(None, None, self.get_process_working_directory()) self.assertTrue(process, VALID_PROCESS) - thread = process.GetThreadAtIndex(0) + # Get the thread executing a.out. + threads = lldbutil.get_threads_stopped_at_breakpoint(process, bp1) + self.assertEqual(len(threads), 1) + thread = threads[0] + 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(), - bp1_line, + thread.frame[0].GetLineEntry().GetLine(), + bp1.GetLocationAtIndex(0).GetAddress().GetLineEntry().GetLine(), "LLDB reported incorrect line number.", ) @@ -70,7 +75,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: @@ -78,7 +82,7 @@ def test(self): # Check that we have stopped at the breakpoint self.assertEqual( thread.frame[0].GetLineEntry().GetLine(), - bp2_line, + bp2.GetLocationAtIndex(0).GetAddress().GetLineEntry().GetLine(), "LLDB reported incorrect line number.", ) # Double-check with GetPCAddress() _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits