Skip to content

Commit 1a0b825

Browse files
authored
[lldb-dap] Improving tests logging to understand CI failures. (llvm#139311)
To improve logging this adjusts two properties of the existing tests: * Forwards stderr from lldb-dap to the process in case errors are reported to stderr. * Adjusts `DebugAdapterServer.terminate` to close stdin and wait for the process to exit instead of sending SIGTERM. Additionally, if we end up with a non-zero exit status we now raise an error to note the unexpected exit status. With these changes, I did find one test case in `TestDAP_console.test_diagnositcs` that was not waiting to ensure the expected event had arrived by the time it performed an assert.
1 parent 5a7e72d commit 1a0b825

File tree

3 files changed

+37
-12
lines changed

3 files changed

+37
-12
lines changed

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

+32-6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import socket
99
import string
1010
import subprocess
11+
import signal
1112
import sys
1213
import threading
1314
import time
@@ -1263,7 +1264,7 @@ def launch(cls, /, executable, env=None, log_file=None, connection=None):
12631264
args,
12641265
stdin=subprocess.PIPE,
12651266
stdout=subprocess.PIPE,
1266-
stderr=subprocess.PIPE,
1267+
stderr=sys.stderr,
12671268
env=adapter_env,
12681269
)
12691270

@@ -1296,13 +1297,38 @@ def get_pid(self):
12961297
def terminate(self):
12971298
super(DebugAdapterServer, self).terminate()
12981299
if self.process is not None:
1299-
self.process.terminate()
1300+
process = self.process
1301+
self.process = None
13001302
try:
1301-
self.process.wait(timeout=20)
1303+
# When we close stdin it should signal the lldb-dap that no
1304+
# new messages will arrive and it should shutdown on its own.
1305+
process.stdin.close()
1306+
process.wait(timeout=20)
13021307
except subprocess.TimeoutExpired:
1303-
self.process.kill()
1304-
self.process.wait()
1305-
self.process = None
1308+
process.kill()
1309+
process.wait()
1310+
if process.returncode != 0:
1311+
raise DebugAdapterProcessError(process.returncode)
1312+
1313+
1314+
class DebugAdapterError(Exception):
1315+
pass
1316+
1317+
1318+
class DebugAdapterProcessError(DebugAdapterError):
1319+
"""Raised when the lldb-dap process exits with a non-zero exit status."""
1320+
1321+
def __init__(self, returncode):
1322+
self.returncode = returncode
1323+
1324+
def __str__(self):
1325+
if self.returncode and self.returncode < 0:
1326+
try:
1327+
return f"lldb-dap died with {signal.Signals(-self.returncode).name}."
1328+
except ValueError:
1329+
return f"lldb-dap died with unknown signal {-self.returncode}."
1330+
else:
1331+
return f"lldb-dap returned non-zero exit status {self.returncode}."
13061332

13071333

13081334
def attach_options_specified(options):

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

+5-2
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,12 @@ def test_diagnositcs(self):
176176
f"target create --core {core}", context="repl"
177177
)
178178

179-
output = self.get_important(timeout=2.0)
179+
diagnostics = self.collect_important(
180+
timeout_secs=self.timeoutval, pattern="minidump file"
181+
)
182+
180183
self.assertIn(
181184
"warning: unable to retrieve process ID from minidump file",
182-
output,
185+
diagnostics,
183186
"diagnostic found in important output",
184187
)

lldb/test/API/tools/lldb-dap/io/TestDAP_io.py

-4
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,9 @@ def cleanup():
2222
process.terminate()
2323
process.wait()
2424
stdout_data = process.stdout.read().decode()
25-
stderr_data = process.stderr.read().decode()
2625
print("========= STDOUT =========", file=sys.stderr)
2726
print(stdout_data, file=sys.stderr)
2827
print("========= END =========", file=sys.stderr)
29-
print("========= STDERR =========", file=sys.stderr)
30-
print(stderr_data, file=sys.stderr)
31-
print("========= END =========", file=sys.stderr)
3228
print("========= DEBUG ADAPTER PROTOCOL LOGS =========", file=sys.stderr)
3329
with open(log_file_path, "r") as file:
3430
print(file.read(), file=sys.stderr)

0 commit comments

Comments
 (0)