Skip to content

Commit 11a4d43

Browse files
author
Miro Bucko
authored
Fix flaky TestDAP_console test. (#94494)
Test Plan: llvm-lit llvm-project/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py
1 parent 0ee7112 commit 11a4d43

File tree

6 files changed

+42
-14
lines changed

6 files changed

+42
-14
lines changed

lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,13 +171,15 @@ def get_output(self, category, timeout=0.0, clear=True):
171171
self.output_condition.release()
172172
return output
173173

174-
def collect_output(self, category, duration, clear=True):
175-
end_time = time.time() + duration
174+
def collect_output(self, category, timeout_secs, pattern, clear=True):
175+
end_time = time.time() + timeout_secs
176176
collected_output = ""
177177
while end_time > time.time():
178178
output = self.get_output(category, timeout=0.25, clear=clear)
179179
if output:
180180
collected_output += output
181+
if pattern is not None and pattern in output:
182+
break
181183
return collected_output if collected_output else None
182184

183185
def enqueue_recv_packet(self, packet):

lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,10 @@ def get_stdout(self, timeout=0.0):
195195
def get_console(self, timeout=0.0):
196196
return self.dap_server.get_output("console", timeout=timeout)
197197

198-
def collect_console(self, duration):
199-
return self.dap_server.collect_output("console", duration=duration)
198+
def collect_console(self, timeout_secs, pattern=None):
199+
return self.dap_server.collect_output(
200+
"console", timeout_secs=timeout_secs, pattern=pattern
201+
)
200202

201203
def get_local_as_int(self, name, threadId=None):
202204
value = self.dap_server.get_local_variable_value(name, threadId=threadId)

lldb/test/API/tools/lldb-dap/attach/TestDAP_attach.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,10 @@ def test_commands(self):
200200
# Get output from the console. This should contain both the
201201
# "exitCommands" that were run after the second breakpoint was hit
202202
# and the "terminateCommands" due to the debugging session ending
203-
output = self.collect_console(duration=1.0)
203+
output = self.collect_console(
204+
timeout_secs=1.0,
205+
pattern=terminateCommands[0],
206+
)
204207
self.verify_commands("exitCommands", output, exitCommands)
205208
self.verify_commands("terminateCommands", output, terminateCommands)
206209

@@ -235,5 +238,8 @@ def test_terminate_commands(self):
235238
# Once it's disconnected the console should contain the
236239
# "terminateCommands"
237240
self.dap_server.request_disconnect(terminateDebuggee=True)
238-
output = self.collect_console(duration=1.0)
241+
output = self.collect_console(
242+
timeout_secs=1.0,
243+
pattern=terminateCommands[0],
244+
)
239245
self.verify_commands("terminateCommands", output, terminateCommands)

lldb/test/API/tools/lldb-dap/commands/TestDAP_commands.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ def test_command_directive_quiet_on_success(self):
2222
stopCommands=["?" + command_quiet, command_not_quiet],
2323
exitCommands=["?" + command_quiet, command_not_quiet],
2424
)
25-
full_output = self.collect_console(duration=1.0)
25+
full_output = self.collect_console(
26+
timeout_secs=1.0,
27+
pattern=command_not_quiet,
28+
)
2629
self.assertNotIn(command_quiet, full_output)
2730
self.assertIn(command_not_quiet, full_output)
2831

@@ -47,7 +50,10 @@ def do_test_abort_on_error(
4750
postRunCommands=commands if use_post_run_commands else None,
4851
expectFailure=True,
4952
)
50-
full_output = self.collect_console(duration=1.0)
53+
full_output = self.collect_console(
54+
timeout_secs=1.0,
55+
pattern=command_abort_on_error,
56+
)
5157
self.assertNotIn(command_quiet, full_output)
5258
self.assertIn(command_abort_on_error, full_output)
5359

@@ -75,6 +81,9 @@ def test_command_directive_abort_on_error_attach_commands(self):
7581
attachCommands=["?!" + command_quiet, "!" + command_abort_on_error],
7682
expectFailure=True,
7783
)
78-
full_output = self.collect_console(duration=1.0)
84+
full_output = self.collect_console(
85+
timeout_secs=1.0,
86+
pattern=command_abort_on_error,
87+
)
7988
self.assertNotIn(command_quiet, full_output)
8089
self.assertIn(command_abort_on_error, full_output)

lldb/test/API/tools/lldb-dap/console/TestDAP_console.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,9 @@ def test_exit_status_message_sigterm(self):
140140
process.wait()
141141

142142
# Get the console output
143-
console_output = self.collect_console(1.0)
143+
console_output = self.collect_console(
144+
timeout_secs=10.0, pattern="exited with status"
145+
)
144146

145147
# Verify the exit status message is printed.
146148
self.assertIn(
@@ -151,13 +153,14 @@ def test_exit_status_message_sigterm(self):
151153

152154
@skipIfWindows
153155
def test_exit_status_message_ok(self):
154-
source = "main.cpp"
155156
program = self.getBuildArtifact("a.out")
156157
self.build_and_launch(program, commandEscapePrefix="")
157158
self.continue_to_exit()
158159

159160
# Get the console output
160-
console_output = self.collect_console(1.0)
161+
console_output = self.collect_console(
162+
timeout_secs=10.0, pattern="exited with status"
163+
)
161164

162165
# Verify the exit status message is printed.
163166
self.assertIn(

lldb/test/API/tools/lldb-dap/launch/TestDAP_launch.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,10 @@ def test_commands(self):
337337
# Get output from the console. This should contain both the
338338
# "exitCommands" that were run after the second breakpoint was hit
339339
# and the "terminateCommands" due to the debugging session ending
340-
output = self.collect_console(duration=1.0)
340+
output = self.collect_console(
341+
timeout_secs=1.0,
342+
pattern=terminateCommands[0],
343+
)
341344
self.verify_commands("exitCommands", output, exitCommands)
342345
self.verify_commands("terminateCommands", output, terminateCommands)
343346

@@ -467,5 +470,8 @@ def test_terminate_commands(self):
467470
# Once it's disconnected the console should contain the
468471
# "terminateCommands"
469472
self.dap_server.request_disconnect(terminateDebuggee=True)
470-
output = self.collect_console(duration=1.0)
473+
output = self.collect_console(
474+
timeout_secs=1.0,
475+
pattern=terminateCommands[0],
476+
)
471477
self.verify_commands("terminateCommands", output, terminateCommands)

0 commit comments

Comments
 (0)