https://github.com/mbucko updated https://github.com/llvm/llvm-project/pull/94494
>From 5e92ee56b2b278b3ddad04cfdb1f440d3568389c Mon Sep 17 00:00:00 2001 From: Miro Bucko <mbu...@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 --- .../Python/lldbsuite/test/tools/lldb-dap/dap_server.py | 6 ++++-- .../lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py | 6 ++++-- lldb/test/API/tools/lldb-dap/attach/TestDAP_attach.py | 4 ++-- .../test/API/tools/lldb-dap/commands/TestDAP_commands.py | 6 +++--- lldb/test/API/tools/lldb-dap/console/TestDAP_console.py | 9 ++++++--- lldb/test/API/tools/lldb-dap/launch/TestDAP_launch.py | 4 ++-- 6 files changed, 21 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..17a54d996cea6 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,7 @@ 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) self.verify_commands("exitCommands", output, exitCommands) self.verify_commands("terminateCommands", output, terminateCommands) @@ -235,5 +235,5 @@ 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) 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..313ae3685b91a 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,7 @@ 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) self.assertNotIn(command_quiet, full_output) self.assertIn(command_not_quiet, full_output) @@ -47,7 +47,7 @@ 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) self.assertNotIn(command_quiet, full_output) self.assertIn(command_abort_on_error, full_output) @@ -75,6 +75,6 @@ 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) 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..af4cebef306cb 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,7 @@ 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) self.verify_commands("exitCommands", output, exitCommands) self.verify_commands("terminateCommands", output, terminateCommands) @@ -467,5 +467,5 @@ 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) self.verify_commands("terminateCommands", output, terminateCommands) _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits