[Lldb-commits] [lldb] [lldb][test] Always call quit when tearing down pexpect tests (PR #201100)
via lldb-commits
lldb-commits at lists.llvm.org
Tue Jun 2 04:58:20 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-lldb
Author: Raphael Isemann (Teemperor)
<details>
<summary>Changes</summary>
Right now we manually have to call quit at the end of each pexpect test. This patches makes this call automatic.
This also makes tests that missed the call and where previously waiting for a timeout faster. For example, TestClangREPL.py now only takes about 10 seconds to run instead of 1 minute.
---
Full diff: https://github.com/llvm/llvm-project/pull/201100.diff
20 Files Affected:
- (modified) lldb/packages/Python/lldbsuite/test/lldbpexpect.py (+10)
- (modified) lldb/test/API/commands/apropos/formatting/TestAproposFormatting.py (-3)
- (modified) lldb/test/API/commands/expression/multiline-completion/TestMultilineCompletion.py (-1)
- (modified) lldb/test/API/commands/expression/multiline-navigation/TestMultilineNavigation.py (-3)
- (modified) lldb/test/API/commands/gui/basic/TestGuiBasic.py (-1)
- (modified) lldb/test/API/commands/gui/basicdebug/TestGuiBasicDebug.py (-1)
- (modified) lldb/test/API/commands/gui/breakpoints/TestGuiBreakpoints.py (-1)
- (modified) lldb/test/API/commands/gui/expand-threads-tree/TestGuiExpandThreadsTree.py (-1)
- (modified) lldb/test/API/commands/gui/spawn-threads/TestGuiSpawnThreads.py (-1)
- (modified) lldb/test/API/commands/gui/viewlarge/TestGuiViewLarge.py (-1)
- (modified) lldb/test/API/iohandler/autosuggestion/TestAutosuggestion.py (-3)
- (modified) lldb/test/API/iohandler/completion/TestIOHandlerCompletion.py (-1)
- (modified) lldb/test/API/iohandler/resize/TestIOHandlerResize.py (-1)
- (modified) lldb/test/API/iohandler/sigint/TestIOHandlerPythonREPLSigint.py (-2)
- (modified) lldb/test/API/iohandler/sigint/TestProcessIOHandlerInterrupt.py (-1)
- (modified) lldb/test/API/iohandler/stdio/TestIOHandlerProcessSTDIO.py (-1)
- (modified) lldb/test/API/iohandler/unicode/TestUnicode.py (-1)
- (modified) lldb/test/API/repl/clang/TestClangREPL.py (-1)
- (modified) lldb/test/API/terminal/TestDisabledBreakpoints.py (-1)
- (modified) lldb/test/API/terminal/TestEditline.py (-1)
``````````diff
diff --git a/lldb/packages/Python/lldbsuite/test/lldbpexpect.py b/lldb/packages/Python/lldbsuite/test/lldbpexpect.py
index ff8c4dd3fc037..dfd9cba82bf13 100644
--- a/lldb/packages/Python/lldbsuite/test/lldbpexpect.py
+++ b/lldb/packages/Python/lldbsuite/test/lldbpexpect.py
@@ -100,7 +100,17 @@ def expect(self, cmd, substrs=None):
self.child.expect_exact(s)
self.expect_prompt()
+ def tearDown(self):
+ # Ensure the child is always cleaned up, even if the test didn't call
+ # quit() explicitly or failed before reaching it.
+ if self.child is not None:
+ self.quit()
+ super().tearDown()
+
def quit(self, gracefully=True):
+ if self.child is None:
+ return
+
self.child.sendeof()
self.child.close(force=not gracefully)
self.child = None
diff --git a/lldb/test/API/commands/apropos/formatting/TestAproposFormatting.py b/lldb/test/API/commands/apropos/formatting/TestAproposFormatting.py
index b9a8f52dbdc16..a3b44a3ca1115 100644
--- a/lldb/test/API/commands/apropos/formatting/TestAproposFormatting.py
+++ b/lldb/test/API/commands/apropos/formatting/TestAproposFormatting.py
@@ -32,7 +32,6 @@ def test_apropos_with_settings_alignment(self):
)
self.expect_prompt()
- self.quit()
@skipIfAsan
@skipIfEditlineSupportMissing
@@ -73,7 +72,6 @@ def test_apropos_highlights_matches(self):
# Settings descriptions.
self.child.expect_exact("'" + ansi_green + "plug" + ansi_reset + "in")
self.expect_prompt()
- self.quit()
@skipIfAsan
@skipIfEditlineSupportMissing
@@ -95,4 +93,3 @@ def test_apropos_highlights_across_line_break(self):
self.child.expect_exact(ansi_green + "will")
self.child.expect_exact("this" + ansi_reset)
self.expect_prompt()
- self.quit()
diff --git a/lldb/test/API/commands/expression/multiline-completion/TestMultilineCompletion.py b/lldb/test/API/commands/expression/multiline-completion/TestMultilineCompletion.py
index c578a1d4149fa..1dddeabe0442f 100644
--- a/lldb/test/API/commands/expression/multiline-completion/TestMultilineCompletion.py
+++ b/lldb/test/API/commands/expression/multiline-completion/TestMultilineCompletion.py
@@ -64,4 +64,3 @@ def test_basic_completion(self):
self.child.expect_exact("only_local ")
self.exit_expression_editor()
- self.quit()
diff --git a/lldb/test/API/commands/expression/multiline-navigation/TestMultilineNavigation.py b/lldb/test/API/commands/expression/multiline-navigation/TestMultilineNavigation.py
index ce5f2f798bd32..90f05c73ad42d 100644
--- a/lldb/test/API/commands/expression/multiline-navigation/TestMultilineNavigation.py
+++ b/lldb/test/API/commands/expression/multiline-navigation/TestMultilineNavigation.py
@@ -36,7 +36,6 @@ def test_nav_arrow_up(self):
# and not 123 (the one we initially typed).
self.child.expect_exact("(int) $0 = 124")
- self.quit()
@skipIfAsan
@skipIfEditlineSupportMissing
@@ -68,7 +67,6 @@ def test_nav_arrow_down(self):
# us back to the second line.
self.child.expect_exact("(int) $0 = 334")
- self.quit()
@skipIfAsan
@skipIfEditlineSupportMissing
@@ -101,4 +99,3 @@ def test_nav_arrow_up_empty(self):
self.child.send("\n\n")
self.expect_prompt()
- self.quit()
diff --git a/lldb/test/API/commands/gui/basic/TestGuiBasic.py b/lldb/test/API/commands/gui/basic/TestGuiBasic.py
index 0c864e6b5f2bf..842121e19b854 100644
--- a/lldb/test/API/commands/gui/basic/TestGuiBasic.py
+++ b/lldb/test/API/commands/gui/basic/TestGuiBasic.py
@@ -51,4 +51,3 @@ def test_gui(self):
self.child.send(escape_key)
self.expect_prompt()
- self.quit()
diff --git a/lldb/test/API/commands/gui/basicdebug/TestGuiBasicDebug.py b/lldb/test/API/commands/gui/basicdebug/TestGuiBasicDebug.py
index 835ddeb97a5f3..ecb7556eefeeb 100644
--- a/lldb/test/API/commands/gui/basicdebug/TestGuiBasicDebug.py
+++ b/lldb/test/API/commands/gui/basicdebug/TestGuiBasicDebug.py
@@ -58,4 +58,3 @@ def test_gui(self):
self.child.send(escape_key)
self.expect_prompt()
- self.quit()
diff --git a/lldb/test/API/commands/gui/breakpoints/TestGuiBreakpoints.py b/lldb/test/API/commands/gui/breakpoints/TestGuiBreakpoints.py
index ebc01880a294c..2d76e7dc5caa5 100644
--- a/lldb/test/API/commands/gui/breakpoints/TestGuiBreakpoints.py
+++ b/lldb/test/API/commands/gui/breakpoints/TestGuiBreakpoints.py
@@ -72,4 +72,3 @@ def test_gui(self):
self.child.send(escape_key)
self.expect_prompt()
- self.quit()
diff --git a/lldb/test/API/commands/gui/expand-threads-tree/TestGuiExpandThreadsTree.py b/lldb/test/API/commands/gui/expand-threads-tree/TestGuiExpandThreadsTree.py
index 266601bafe7ad..aeecc790f554f 100644
--- a/lldb/test/API/commands/gui/expand-threads-tree/TestGuiExpandThreadsTree.py
+++ b/lldb/test/API/commands/gui/expand-threads-tree/TestGuiExpandThreadsTree.py
@@ -55,4 +55,3 @@ def test_gui(self):
self.child.send(escape_key)
self.expect_prompt()
- self.quit()
diff --git a/lldb/test/API/commands/gui/spawn-threads/TestGuiSpawnThreads.py b/lldb/test/API/commands/gui/spawn-threads/TestGuiSpawnThreads.py
index c504abe8b5ef2..3592b502e9845 100644
--- a/lldb/test/API/commands/gui/spawn-threads/TestGuiSpawnThreads.py
+++ b/lldb/test/API/commands/gui/spawn-threads/TestGuiSpawnThreads.py
@@ -48,4 +48,3 @@ def test_gui(self):
self.child.send(escape_key)
self.expect_prompt()
- self.quit()
diff --git a/lldb/test/API/commands/gui/viewlarge/TestGuiViewLarge.py b/lldb/test/API/commands/gui/viewlarge/TestGuiViewLarge.py
index 8dbf5e8cdcda5..a144f2d9ab2b6 100644
--- a/lldb/test/API/commands/gui/viewlarge/TestGuiViewLarge.py
+++ b/lldb/test/API/commands/gui/viewlarge/TestGuiViewLarge.py
@@ -75,4 +75,3 @@ def test_gui(self):
self.child.send(escape_key)
self.expect_prompt()
- self.quit()
diff --git a/lldb/test/API/iohandler/autosuggestion/TestAutosuggestion.py b/lldb/test/API/iohandler/autosuggestion/TestAutosuggestion.py
index 0f714a156e50f..401b06f6c9b49 100644
--- a/lldb/test/API/iohandler/autosuggestion/TestAutosuggestion.py
+++ b/lldb/test/API/iohandler/autosuggestion/TestAutosuggestion.py
@@ -46,7 +46,6 @@ def test_autosuggestion_add_spaces(self):
+ " "
)
- self.quit()
@skipIfAsan
@skipIfEditlineSupportMissing
@@ -132,7 +131,6 @@ def test_autosuggestion(self):
self.child.send(ctrl_f + "help breakpoint" + "\n")
self.child.expect_exact(breakpoint_output_needle)
- self.quit()
@skipIfAsan
@skipIfEditlineSupportMissing
@@ -156,4 +154,3 @@ def test_autosuggestion_custom_ansi_prefix_suffix(self):
self.child.expect_exact(self.ANSI_RED + "ame variable" + self.ANSI_CYAN)
self.child.send("\n")
- self.quit()
diff --git a/lldb/test/API/iohandler/completion/TestIOHandlerCompletion.py b/lldb/test/API/iohandler/completion/TestIOHandlerCompletion.py
index 6128393558f9a..43eb2d752ec70 100644
--- a/lldb/test/API/iohandler/completion/TestIOHandlerCompletion.py
+++ b/lldb/test/API/iohandler/completion/TestIOHandlerCompletion.py
@@ -85,4 +85,3 @@ def test_completion(self):
self.child.send("regoinvalid\t")
self.expect_prompt()
- self.quit()
diff --git a/lldb/test/API/iohandler/resize/TestIOHandlerResize.py b/lldb/test/API/iohandler/resize/TestIOHandlerResize.py
index 84a8ab9f4d417..3f0c6a91298b7 100644
--- a/lldb/test/API/iohandler/resize/TestIOHandlerResize.py
+++ b/lldb/test/API/iohandler/resize/TestIOHandlerResize.py
@@ -33,4 +33,3 @@ def test_resize(self):
self.child.expect_exact(
"(lldb) This is a long sentence missing its first letter."
)
- self.quit()
diff --git a/lldb/test/API/iohandler/sigint/TestIOHandlerPythonREPLSigint.py b/lldb/test/API/iohandler/sigint/TestIOHandlerPythonREPLSigint.py
index 63bda4b4871ad..1532d7942dfe3 100644
--- a/lldb/test/API/iohandler/sigint/TestIOHandlerPythonREPLSigint.py
+++ b/lldb/test/API/iohandler/sigint/TestIOHandlerPythonREPLSigint.py
@@ -49,7 +49,6 @@ def test_while_evaluating_code(self):
# Send EOF to quit the Python REPL.
self.child.sendeof()
- self.quit()
# PExpect uses many timeouts internally and doesn't play well
# under ASAN on a loaded machine..
@@ -71,4 +70,3 @@ def test_while_waiting_on_input(self):
# Send EOF to quit the Python REPL.
self.child.sendeof()
- self.quit()
diff --git a/lldb/test/API/iohandler/sigint/TestProcessIOHandlerInterrupt.py b/lldb/test/API/iohandler/sigint/TestProcessIOHandlerInterrupt.py
index 7ceb2d5ac38dd..7ae122db1614c 100644
--- a/lldb/test/API/iohandler/sigint/TestProcessIOHandlerInterrupt.py
+++ b/lldb/test/API/iohandler/sigint/TestProcessIOHandlerInterrupt.py
@@ -42,4 +42,3 @@ def test(self):
self.child.expect("Process .* exited")
self.expect_prompt()
- self.quit()
diff --git a/lldb/test/API/iohandler/stdio/TestIOHandlerProcessSTDIO.py b/lldb/test/API/iohandler/stdio/TestIOHandlerProcessSTDIO.py
index 27299f9cd6961..a63cde5d1000b 100644
--- a/lldb/test/API/iohandler/stdio/TestIOHandlerProcessSTDIO.py
+++ b/lldb/test/API/iohandler/stdio/TestIOHandlerProcessSTDIO.py
@@ -26,4 +26,3 @@ def test(self):
self.child.expect_exact("stdout: baz")
self.child.sendcontrol("d")
- self.quit()
diff --git a/lldb/test/API/iohandler/unicode/TestUnicode.py b/lldb/test/API/iohandler/unicode/TestUnicode.py
index c9bb1c2af0bd0..903744fb77681 100644
--- a/lldb/test/API/iohandler/unicode/TestUnicode.py
+++ b/lldb/test/API/iohandler/unicode/TestUnicode.py
@@ -27,4 +27,3 @@ def test_unicode_input(self):
substrs=["error: '\u1234' is not a valid command".encode("utf-8")],
)
- self.quit()
diff --git a/lldb/test/API/repl/clang/TestClangREPL.py b/lldb/test/API/repl/clang/TestClangREPL.py
index 97d91d1b8f7a5..8189e2db6124e 100644
--- a/lldb/test/API/repl/clang/TestClangREPL.py
+++ b/lldb/test/API/repl/clang/TestClangREPL.py
@@ -54,7 +54,6 @@ def test_basic_completion(self):
# Try using the persistent variable from before.
self.expect_repl("$persistent + 10", substrs=["(long) $2 = 17"])
- self.quit()
# PExpect uses many timeouts internally and doesn't play well
# under ASAN on a loaded machine..
diff --git a/lldb/test/API/terminal/TestDisabledBreakpoints.py b/lldb/test/API/terminal/TestDisabledBreakpoints.py
index a644c94c8a178..c29a220439e45 100644
--- a/lldb/test/API/terminal/TestDisabledBreakpoints.py
+++ b/lldb/test/API/terminal/TestDisabledBreakpoints.py
@@ -22,4 +22,3 @@ def test_disabling_breakpoints_with_color(self):
self.expect("b main")
self.expect("br dis")
self.expect("br l", substrs=[ansi_red_color_code + "1:"])
- self.quit()
diff --git a/lldb/test/API/terminal/TestEditline.py b/lldb/test/API/terminal/TestEditline.py
index 4696b1e1b112e..91ec1c51719e2 100644
--- a/lldb/test/API/terminal/TestEditline.py
+++ b/lldb/test/API/terminal/TestEditline.py
@@ -42,7 +42,6 @@ def test_left_right_arrow(self):
substrs=["Syntax: print"],
)
- self.quit()
@skipIfAsan
@skipIfEditlineSupportMissing
``````````
</details>
https://github.com/llvm/llvm-project/pull/201100
More information about the lldb-commits
mailing list