Skip to content

[lldb-dap] Improving tests logging to understand CI failures. #139311

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 14, 2025

Conversation

ashgti
Copy link
Contributor

@ashgti ashgti commented May 9, 2025

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.

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.
@ashgti ashgti requested a review from JDevlieghere as a code owner May 9, 2025 18:59
@llvmbot llvmbot added the lldb label May 9, 2025
@llvmbot
Copy link
Member

llvmbot commented May 9, 2025

@llvm/pr-subscribers-lldb

Author: John Harrison (ashgti)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/139311.diff

3 Files Affected:

  • (modified) lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py (+30-6)
  • (modified) lldb/test/API/tools/lldb-dap/console/TestDAP_console.py (+3-2)
  • (modified) lldb/test/API/tools/lldb-dap/io/TestDAP_io.py (-4)
diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py
index e10342b72f4f0..292209f8ab042 100644
--- a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py
+++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py
@@ -8,6 +8,7 @@
 import socket
 import string
 import subprocess
+import signal
 import sys
 import threading
 import time
@@ -1269,7 +1270,7 @@ def launch(cls, /, executable, env=None, log_file=None, connection=None):
             args,
             stdin=subprocess.PIPE,
             stdout=subprocess.PIPE,
-            stderr=subprocess.PIPE,
+            stderr=sys.stderr,
             env=adapter_env,
         )
 
@@ -1302,14 +1303,37 @@ def get_pid(self):
     def terminate(self):
         super(DebugAdapterServer, self).terminate()
         if self.process is not None:
-            self.process.terminate()
+            process = self.process
+            self.process = None
             try:
-                self.process.wait(timeout=20)
+                # When we close stdin it should signal the lldb-dap that no 
+                # new messages will arrive and it should shutdown on its own.
+                process.stdin.close()
+                process.wait(timeout=20)
             except subprocess.TimeoutExpired:
-                self.process.kill()
-                self.process.wait()
-            self.process = None
+                process.kill()
+                process.wait()
+            if process.returncode != 0:
+                raise DebugAdapterProcessError(process.returncode)
+
 
+class DebugAdapterError(Exception): pass
+
+class DebugAdapterProcessError(DebugAdapterError):
+    """Raised when the lldb-dap process exits with a non-zero exit status.
+    """
+
+    def __init__(self, returncode):
+        self.returncode = returncode
+
+    def __str__(self):
+        if self.returncode and self.returncode < 0:
+            try:
+                return f"lldb-dap died with {signal.Signals(-self.returncode).name}."
+            except ValueError:
+                return f"lldb-dap died with unknown signal {-self.returncode}."
+        else:
+            return f"lldb-dap returned non-zero exit status {self.returncode}."
 
 def attach_options_specified(options):
     if options.pid is not None:
diff --git a/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py b/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py
index 8642e317f9b3a..f6809c0cdcb60 100644
--- a/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py
+++ b/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py
@@ -176,9 +176,10 @@ def test_diagnositcs(self):
             f"target create --core  {core}", context="repl"
         )
 
-        output = self.get_important()
+        diag_message = self.collect_important(timeout_secs=self.timeoutval, pattern="minidump file")
+
         self.assertIn(
             "warning: unable to retrieve process ID from minidump file",
-            output,
+            diag_message,
             "diagnostic found in important output",
         )
diff --git a/lldb/test/API/tools/lldb-dap/io/TestDAP_io.py b/lldb/test/API/tools/lldb-dap/io/TestDAP_io.py
index f05f876e57b49..b72b98de412b4 100644
--- a/lldb/test/API/tools/lldb-dap/io/TestDAP_io.py
+++ b/lldb/test/API/tools/lldb-dap/io/TestDAP_io.py
@@ -22,13 +22,9 @@ def cleanup():
                 process.terminate()
                 process.wait()
             stdout_data = process.stdout.read().decode()
-            stderr_data = process.stderr.read().decode()
             print("========= STDOUT =========", file=sys.stderr)
             print(stdout_data, file=sys.stderr)
             print("========= END =========", file=sys.stderr)
-            print("========= STDERR =========", file=sys.stderr)
-            print(stderr_data, file=sys.stderr)
-            print("========= END =========", file=sys.stderr)
             print("========= DEBUG ADAPTER PROTOCOL LOGS =========", file=sys.stderr)
             with open(log_file_path, "r") as file:
                 print(file.read(), file=sys.stderr)

@ashgti ashgti requested a review from eronnen May 9, 2025 19:00
Copy link

github-actions bot commented May 9, 2025

✅ With the latest revision this PR passed the Python code formatter.

Copy link
Contributor

@eronnen eronnen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ashgti ashgti merged commit 1a0b825 into llvm:main May 14, 2025
10 checks passed
@llvm-ci
Copy link
Collaborator

llvm-ci commented May 14, 2025

LLVM Buildbot has detected a new failure on builder lldb-aarch64-ubuntu running on linaro-lldb-aarch64-ubuntu while building lldb at step 6 "test".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/59/builds/17653

Here is the relevant piece of the build log for the reference
Step 6 (test) failure: build (failure)
...
PASS: lldb-unit :: ValueObject/./LLDBValueObjectTests/8/11 (2170 of 2179)
PASS: lldb-unit :: ValueObject/./LLDBValueObjectTests/9/11 (2171 of 2179)
PASS: lldb-unit :: tools/lldb-server/tests/./LLDBServerTests/0/2 (2172 of 2179)
PASS: lldb-unit :: tools/lldb-server/tests/./LLDBServerTests/1/2 (2173 of 2179)
PASS: lldb-unit :: Utility/./UtilityTests/4/9 (2174 of 2179)
PASS: lldb-unit :: Host/./HostTests/8/13 (2175 of 2179)
PASS: lldb-unit :: Target/./TargetTests/11/14 (2176 of 2179)
PASS: lldb-api :: tools/lldb-server/TestLldbGdbServer.py (2177 of 2179)
PASS: lldb-unit :: Process/gdb-remote/./ProcessGdbRemoteTests/8/9 (2178 of 2179)
TIMEOUT: lldb-unit :: Host/./HostTests/0/13 (2179 of 2179)
******************** TEST 'lldb-unit :: Host/./HostTests/0/13' FAILED ********************
Script(shard):
--
GTEST_OUTPUT=json:/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/tools/lldb/unittests/Host/./HostTests-lldb-unit-3604624-0-13.json GTEST_SHUFFLE=0 GTEST_TOTAL_SHARDS=13 GTEST_SHARD_INDEX=0 /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/tools/lldb/unittests/Host/./HostTests
--

Note: This is test shard 1 of 13.
[==========] Running 8 tests from 8 test suites.
[----------] Global test environment set-up.
[----------] 1 test from ConnectionFileDescriptorTest
[ RUN      ] ConnectionFileDescriptorTest.TCPGetURIv4
[       OK ] ConnectionFileDescriptorTest.TCPGetURIv4 (0 ms)
[----------] 1 test from ConnectionFileDescriptorTest (0 ms total)

[----------] 1 test from FileSystemTest
[ RUN      ] FileSystemTest.EnumerateDirectory
[       OK ] FileSystemTest.EnumerateDirectory (0 ms)
[----------] 1 test from FileSystemTest (0 ms total)

[----------] 1 test from Host
[ RUN      ] Host.LaunchProcessDuplicatesHandle
Note: Google Test filter = Host.LaunchProcessDuplicatesHandle
[==========] Running 1 test from 1 test suite.
[----------] Global test environment set-up.
[----------] 1 test from Host
[ RUN      ] Host.LaunchProcessDuplicatesHandle
[       OK ] Host.LaunchProcessDuplicatesHandle (3 ms)
[----------] 1 test from Host (3 ms total)

[----------] 1 test from MainLoopTest
[ RUN      ] MainLoopTest.SignalOnOtherThread

--
exit: -9
--
Reached timeout of 600 seconds
********************
********************
Timed Out Tests (1):

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants