[Lldb-commits] [lldb] Fix flaky TestDAP_console test. (PR #94494)
Miro Bucko via lldb-commits
lldb-commits at lists.llvm.org
Mon Jun 10 13:07:47 PDT 2024
https://github.com/mbucko updated https://github.com/llvm/llvm-project/pull/94494
>From 39c8c9aa1cc45fd4cfd16fe841f65a4d1cb08cf4 Mon Sep 17 00:00:00 2001
From: Miro Bucko <mbucko at meta.com>
Date: Wed, 5 Jun 2024 09:03:38 -0700
Subject: [PATCH] Fix flaky TestDAP_console test.
Test Plan:
llvm-lit llvm-project/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py
---
.../lldbsuite/test/tools/lldb-dap/dap_server.py | 6 ++++--
.../test/tools/lldb-dap/lldbdap_testcase.py | 6 ++++--
.../API/tools/lldb-dap/attach/TestDAP_attach.py | 10 ++++++++--
.../tools/lldb-dap/commands/TestDAP_commands.py | 15 ++++++++++++---
.../API/tools/lldb-dap/console/TestDAP_console.py | 9 ++++++---
.../API/tools/lldb-dap/launch/TestDAP_launch.py | 10 ++++++++--
6 files changed, 42 insertions(+), 14 deletions(-)
diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py
index e2126d67a5fe7..a9eeec1840990 100644
--- a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py
+++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py
@@ -171,13 +171,15 @@ def get_output(self, category, timeout=0.0, clear=True):
self.output_condition.release()
return output
- def collect_output(self, category, duration, clear=True):
- end_time = time.time() + duration
+ def collect_output(self, category, timeout_secs, pattern, clear=True):
+ end_time = time.time() + timeout_secs
collected_output = ""
while end_time > time.time():
output = self.get_output(category, timeout=0.25, clear=clear)
if output:
collected_output += output
+ if pattern is not None and pattern in output:
+ break
return collected_output if collected_output else None
def enqueue_recv_packet(self, packet):
diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py
index d56ea5dca14be..600dc2b5fe9bb 100644
--- a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py
+++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py
@@ -195,8 +195,10 @@ def get_stdout(self, timeout=0.0):
def get_console(self, timeout=0.0):
return self.dap_server.get_output("console", timeout=timeout)
- def collect_console(self, duration):
- return self.dap_server.collect_output("console", duration=duration)
+ def collect_console(self, timeout_secs, pattern=None):
+ return self.dap_server.collect_output(
+ "console", timeout_secs=timeout_secs, pattern=pattern
+ )
def get_local_as_int(self, name, threadId=None):
value = self.dap_server.get_local_variable_value(name, threadId=threadId)
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 b3ba69749f673..1dbe00144f352 100644
--- a/lldb/test/API/tools/lldb-dap/attach/TestDAP_attach.py
+++ b/lldb/test/API/tools/lldb-dap/attach/TestDAP_attach.py
@@ -200,7 +200,10 @@ def test_commands(self):
# Get output from the console. This should contain both the
# "exitCommands" that were run after the second breakpoint was hit
# and the "terminateCommands" due to the debugging session ending
- output = self.collect_console(duration=1.0)
+ output = self.collect_console(
+ timeout_secs=1.0,
+ pattern=terminateCommands[0],
+ )
self.verify_commands("exitCommands", output, exitCommands)
self.verify_commands("terminateCommands", output, terminateCommands)
@@ -235,5 +238,8 @@ def test_terminate_commands(self):
# Once it's disconnected the console should contain the
# "terminateCommands"
self.dap_server.request_disconnect(terminateDebuggee=True)
- output = self.collect_console(duration=1.0)
+ output = self.collect_console(
+ timeout_secs=1.0,
+ pattern=terminateCommands[0],
+ )
self.verify_commands("terminateCommands", output, terminateCommands)
diff --git a/lldb/test/API/tools/lldb-dap/commands/TestDAP_commands.py b/lldb/test/API/tools/lldb-dap/commands/TestDAP_commands.py
index 226b9385fe719..e4cf903fc0d11 100644
--- a/lldb/test/API/tools/lldb-dap/commands/TestDAP_commands.py
+++ b/lldb/test/API/tools/lldb-dap/commands/TestDAP_commands.py
@@ -22,7 +22,10 @@ def test_command_directive_quiet_on_success(self):
stopCommands=["?" + command_quiet, command_not_quiet],
exitCommands=["?" + command_quiet, command_not_quiet],
)
- full_output = self.collect_console(duration=1.0)
+ full_output = self.collect_console(
+ timeout_secs=1.0,
+ pattern=command_not_quiet,
+ )
self.assertNotIn(command_quiet, full_output)
self.assertIn(command_not_quiet, full_output)
@@ -47,7 +50,10 @@ def do_test_abort_on_error(
postRunCommands=commands if use_post_run_commands else None,
expectFailure=True,
)
- full_output = self.collect_console(duration=1.0)
+ full_output = self.collect_console(
+ timeout_secs=1.0,
+ pattern=command_abort_on_error,
+ )
self.assertNotIn(command_quiet, full_output)
self.assertIn(command_abort_on_error, full_output)
@@ -75,6 +81,9 @@ def test_command_directive_abort_on_error_attach_commands(self):
attachCommands=["?!" + command_quiet, "!" + command_abort_on_error],
expectFailure=True,
)
- full_output = self.collect_console(duration=1.0)
+ full_output = self.collect_console(
+ timeout_secs=1.0,
+ pattern=command_abort_on_error,
+ )
self.assertNotIn(command_quiet, full_output)
self.assertIn(command_abort_on_error, full_output)
diff --git a/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py b/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py
index e6345818bf087..9e64dfe1daf0e 100644
--- a/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py
+++ b/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py
@@ -140,7 +140,9 @@ def test_exit_status_message_sigterm(self):
process.wait()
# Get the console output
- console_output = self.collect_console(1.0)
+ console_output = self.collect_console(
+ timeout_secs=10.0, pattern="exited with status"
+ )
# Verify the exit status message is printed.
self.assertIn(
@@ -151,13 +153,14 @@ def test_exit_status_message_sigterm(self):
@skipIfWindows
def test_exit_status_message_ok(self):
- source = "main.cpp"
program = self.getBuildArtifact("a.out")
self.build_and_launch(program, commandEscapePrefix="")
self.continue_to_exit()
# Get the console output
- console_output = self.collect_console(1.0)
+ console_output = self.collect_console(
+ timeout_secs=10.0, pattern="exited with status"
+ )
# Verify the exit status message is printed.
self.assertIn(
diff --git a/lldb/test/API/tools/lldb-dap/launch/TestDAP_launch.py b/lldb/test/API/tools/lldb-dap/launch/TestDAP_launch.py
index 05873e926b64e..cde2d0e583d44 100644
--- a/lldb/test/API/tools/lldb-dap/launch/TestDAP_launch.py
+++ b/lldb/test/API/tools/lldb-dap/launch/TestDAP_launch.py
@@ -337,7 +337,10 @@ def test_commands(self):
# Get output from the console. This should contain both the
# "exitCommands" that were run after the second breakpoint was hit
# and the "terminateCommands" due to the debugging session ending
- output = self.collect_console(duration=1.0)
+ output = self.collect_console(
+ timeout_secs=1.0,
+ pattern=terminateCommands[0],
+ )
self.verify_commands("exitCommands", output, exitCommands)
self.verify_commands("terminateCommands", output, terminateCommands)
@@ -467,5 +470,8 @@ def test_terminate_commands(self):
# Once it's disconnected the console should contain the
# "terminateCommands"
self.dap_server.request_disconnect(terminateDebuggee=True)
- output = self.collect_console(duration=1.0)
+ output = self.collect_console(
+ timeout_secs=1.0,
+ pattern=terminateCommands[0],
+ )
self.verify_commands("terminateCommands", output, terminateCommands)
More information about the lldb-commits
mailing list