Skip to content

Commit

Permalink
Fix flaky TestDAP_console test. (llvm#94494)
Browse files Browse the repository at this point in the history
Test Plan:
llvm-lit
llvm-project/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py
  • Loading branch information
mbucko authored Jun 11, 2024
1 parent 0ee7112 commit 11a4d43
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 8 additions & 2 deletions lldb/test/API/tools/lldb-dap/attach/TestDAP_attach.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
15 changes: 12 additions & 3 deletions lldb/test/API/tools/lldb-dap/commands/TestDAP_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)

Expand Down Expand Up @@ -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)
9 changes: 6 additions & 3 deletions lldb/test/API/tools/lldb-dap/console/TestDAP_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand Down
10 changes: 8 additions & 2 deletions lldb/test/API/tools/lldb-dap/launch/TestDAP_launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)

0 comments on commit 11a4d43

Please sign in to comment.