[Lldb-commits] [lldb] Fix flake in TestZerothFrame.py (PR #96685)

Kendal Harland via lldb-commits lldb-commits at lists.llvm.org
Thu Jun 27 09:31:58 PDT 2024


https://github.com/kendalharland updated https://github.com/llvm/llvm-project/pull/96685

>From 1ca25a240cf459e16fb762f750e84260610c1077 Mon Sep 17 00:00:00 2001
From: kendal <kendal at 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 switching from `process.GetThreadAtIndex` to
`process.GetThreadByIndex` we consistently retrieve the correct thread.

Adds a helper function to find thread executing a file
---
 .../unwind/zeroth_frame/TestZerothFrame.py    | 20 ++++++++++++++++---
 1 file changed, 17 insertions(+), 3 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..892522f5cc63e 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
@@ -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.",
         )
@@ -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:



More information about the lldb-commits mailing list