Fix flaky TestDAP_console test. (#94494)

Test Plan:
llvm-lit
llvm-project/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py
This commit is contained in:
Miro Bucko 2024-06-12 06:21:17 +07:00 committed by GitHub
parent 0ee71124f4
commit 11a4d43f4a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 42 additions and 14 deletions

View File

@ -171,13 +171,15 @@ class DebugCommunication(object):
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):

View File

@ -195,8 +195,10 @@ class DAPTestCaseBase(TestBase):
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)

View File

@ -200,7 +200,10 @@ class TestDAP_attach(lldbdap_testcase.DAPTestCaseBase):
# 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 @@ class TestDAP_attach(lldbdap_testcase.DAPTestCaseBase):
# 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)

View File

@ -22,7 +22,10 @@ class TestDAP_commands(lldbdap_testcase.DAPTestCaseBase):
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 @@ class TestDAP_commands(lldbdap_testcase.DAPTestCaseBase):
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 @@ class TestDAP_commands(lldbdap_testcase.DAPTestCaseBase):
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)

View File

@ -140,7 +140,9 @@ class TestDAP_console(lldbdap_testcase.DAPTestCaseBase):
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 @@ class TestDAP_console(lldbdap_testcase.DAPTestCaseBase):
@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(

View File

@ -337,7 +337,10 @@ class TestDAP_launch(lldbdap_testcase.DAPTestCaseBase):
# 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 @@ class TestDAP_launch(lldbdap_testcase.DAPTestCaseBase):
# 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)