[Lldb-commits] [lldb] [lldb-dap] refactor monitor thread in tests (PR #172879)
via lldb-commits
lldb-commits at lists.llvm.org
Thu Dec 18 09:03:28 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-lldb
Author: Charles Zablit (charles-zablit)
<details>
<summary>Changes</summary>
This patch fixes a timeout in the monitor thread of the `test_by_name_waitFor` test.
Currently, if `self.attach` fails, the `spawn_thread` will never finish and the test will eventually timeout after the 15mins timeout. We now ensure that we always join the thread at the end of the test.
---
Full diff: https://github.com/llvm/llvm-project/pull/172879.diff
1 Files Affected:
- (modified) lldb/test/API/tools/lldb-dap/attach/TestDAP_attach.py (+18-7)
``````````diff
diff --git a/lldb/test/API/tools/lldb-dap/attach/TestDAP_attach.py b/lldb/test/API/tools/lldb-dap/attach/TestDAP_attach.py
index d6287397a93b0..7d1b3750a04a2 100644
--- a/lldb/test/API/tools/lldb-dap/attach/TestDAP_attach.py
+++ b/lldb/test/API/tools/lldb-dap/attach/TestDAP_attach.py
@@ -16,7 +16,7 @@
@skipIf(oslist=["linux"], archs=["arm$"])
class TestDAP_attach(lldbdap_testcase.DAPTestCaseBase):
def spawn(self, args):
- self.process = subprocess.Popen(
+ self.target_process = subprocess.Popen(
args,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
@@ -27,12 +27,17 @@ def spawn(self, args):
def spawn_and_wait(self, program, delay):
time.sleep(delay)
self.spawn([program])
- self.process.wait()
+ proc = self.target_process
+ # Wait for either the process to exit or the event to be set
+ while proc.poll() is None and not self.spawn_event.is_set():
+ time.sleep(0.1)
+ proc.kill()
+ proc.wait()
def continue_and_verify_pid(self):
self.do_continue()
- out, _ = self.process.communicate("foo")
- self.assertIn(f"pid = {self.process.pid}", out)
+ out, _ = self.target_process.communicate("foo")
+ self.assertIn(f"pid = {self.target_process.pid}", out)
def test_by_pid(self):
"""
@@ -40,7 +45,7 @@ def test_by_pid(self):
"""
program = self.build_and_create_debug_adapter_for_attach()
self.spawn([program])
- self.attach(pid=self.process.pid)
+ self.attach(pid=self.target_process.pid)
self.continue_and_verify_pid()
def test_by_name(self):
@@ -65,6 +70,7 @@ def test_by_name_waitFor(self):
doesn't exist yet.
"""
program = self.build_and_create_debug_adapter_for_attach()
+ self.spawn_event = threading.Event()
self.spawn_thread = threading.Thread(
target=self.spawn_and_wait,
args=(
@@ -73,8 +79,13 @@ def test_by_name_waitFor(self):
),
)
self.spawn_thread.start()
- self.attach(program=program, waitFor=True)
- self.continue_and_verify_pid()
+ try:
+ self.attach(program=program, waitFor=True)
+ self.continue_and_verify_pid()
+ finally:
+ self.spawn_event.set()
+ if self.spawn_thread.is_alive():
+ self.spawn_thread.join(timeout=10)
def test_attach_with_missing_debuggerId_or_targetId(self):
"""
``````````
</details>
https://github.com/llvm/llvm-project/pull/172879
More information about the lldb-commits
mailing list