Skip to content

Commit abb7aad

Browse files
committed
[lldb-dap] Improving tests logging to understand CI failures.
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 51ca3cb commit abb7aad

File tree

3 files changed

+33
-12
lines changed

3 files changed

+33
-12
lines changed

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

Lines changed: 30 additions & 6 deletions
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
@@ -1269,7 +1270,7 @@ def launch(cls, /, executable, env=None, log_file=None, connection=None):
12691270
args,
12701271
stdin=subprocess.PIPE,
12711272
stdout=subprocess.PIPE,
1272-
stderr=subprocess.PIPE,
1273+
stderr=sys.stderr,
12731274
env=adapter_env,
12741275
)
12751276

@@ -1302,14 +1303,37 @@ def get_pid(self):
13021303
def terminate(self):
13031304
super(DebugAdapterServer, self).terminate()
13041305
if self.process is not None:
1305-
self.process.terminate()
1306+
process = self.process
1307+
self.process = None
13061308
try:
1307-
self.process.wait(timeout=20)
1309+
# When we close stdin it should signal the lldb-dap that no
1310+
# new messages will arrive and it should shutdown on its own.
1311+
process.stdin.close()
1312+
process.wait(timeout=20)
13081313
except subprocess.TimeoutExpired:
1309-
self.process.kill()
1310-
self.process.wait()
1311-
self.process = None
1314+
process.kill()
1315+
process.wait()
1316+
if process.returncode != 0:
1317+
raise DebugAdapterProcessError(process.returncode)
1318+
13121319

1320+
class DebugAdapterError(Exception): pass
1321+
1322+
class DebugAdapterProcessError(DebugAdapterError):
1323+
"""Raised when the lldb-dap process exits with a non-zero exit status.
1324+
"""
1325+
1326+
def __init__(self, returncode):
1327+
self.returncode = returncode
1328+
1329+
def __str__(self):
1330+
if self.returncode and self.returncode < 0:
1331+
try:
1332+
return f"lldb-dap died with {signal.Signals(-self.returncode).name}."
1333+
except ValueError:
1334+
return f"lldb-dap died with unknown signal {-self.returncode}."
1335+
else:
1336+
return f"lldb-dap returned non-zero exit status {self.returncode}."
13131337

13141338
def attach_options_specified(options):
13151339
if options.pid is not None:

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,10 @@ def test_diagnositcs(self):
176176
f"target create --core {core}", context="repl"
177177
)
178178

179-
output = self.get_important()
179+
diag_message = self.collect_important(timeout_secs=self.timeoutval, pattern="minidump file")
180+
180181
self.assertIn(
181182
"warning: unable to retrieve process ID from minidump file",
182-
output,
183+
diag_message,
183184
"diagnostic found in important output",
184185
)

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

Lines changed: 0 additions & 4 deletions
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)