Skip to content

[lldb-dap] Test Gardening, attach tests. #141981

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 1 commit into from
Jun 5, 2025
Merged

Conversation

ashgti
Copy link
Contributor

@ashgti ashgti commented May 29, 2025

Trimming unused imports, adjusting the test to use the DEFAULT_TIMEOUT instead of a custom timeout and adjusting the flow to stopOnEntry for improving consistency.

Trimming unused imports, adjusting the test to use the `DEFAULT_TIMEOUT` instead of a custom timeout and adjusting the flow to stopOnEntry for improving consistency.
@ashgti ashgti requested a review from JDevlieghere as a code owner May 29, 2025 16:52
@llvmbot llvmbot added the lldb label May 29, 2025
@llvmbot
Copy link
Member

llvmbot commented May 29, 2025

@llvm/pr-subscribers-lldb

Author: John Harrison (ashgti)

Changes

Trimming unused imports, adjusting the test to use the DEFAULT_TIMEOUT instead of a custom timeout and adjusting the flow to stopOnEntry for improving consistency.


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

1 Files Affected:

  • (modified) lldb/test/API/tools/lldb-dap/attach/TestDAP_attachByPortNum.py (+26-35)
diff --git a/lldb/test/API/tools/lldb-dap/attach/TestDAP_attachByPortNum.py b/lldb/test/API/tools/lldb-dap/attach/TestDAP_attachByPortNum.py
index 7c2b540195d15..edb87a9314d78 100644
--- a/lldb/test/API/tools/lldb-dap/attach/TestDAP_attachByPortNum.py
+++ b/lldb/test/API/tools/lldb-dap/attach/TestDAP_attachByPortNum.py
@@ -2,26 +2,16 @@
 Test lldb-dap "port" configuration to "attach" request
 """
 
-import dap_server
 from lldbsuite.test.decorators import *
 from lldbsuite.test.lldbtest import *
-from lldbsuite.test import lldbutil
 from lldbsuite.test import lldbplatformutil
 from lldbgdbserverutils import Pipe
 import lldbdap_testcase
-import os
-import shutil
-import subprocess
-import tempfile
-import threading
-import sys
-import socket
+import lldb
 
 
-@skip("https://github.com/llvm/llvm-project/issues/138803")
+@skip(bugnumber="https://github.com/llvm/llvm-project/issues/138803")
 class TestDAP_attachByPortNum(lldbdap_testcase.DAPTestCaseBase):
-    default_timeout = 20
-
     def set_and_hit_breakpoint(self, continueToExit=True):
         self.dap_server.wait_for_stopped()
 
@@ -50,7 +40,7 @@ def get_debug_server_command_line_args(self):
     def get_debug_server_pipe(self):
         pipe = Pipe(self.getBuildDir())
         self.addTearDownHook(lambda: pipe.close())
-        pipe.finish_connection(self.default_timeout)
+        pipe.finish_connection(self.DEFAULT_TIMEOUT)
         return pipe
 
     @skipIfWindows
@@ -73,28 +63,33 @@ def test_by_port(self):
         )
 
         # Read the port number from the debug server pipe.
-        port = pipe.read(10, self.default_timeout)
+        port = pipe.read(10, self.DEFAULT_TIMEOUT)
         # Trim null byte, convert to int
         port = int(port[:-1])
         self.assertIsNotNone(
             port, " Failed to read the port number from debug server pipe"
         )
 
-        self.attach(program=program, gdbRemotePort=port, sourceInitFile=True)
+        self.attach(
+            program=program,
+            gdbRemotePort=port,
+            sourceInitFile=True,
+            stopOnEntry=True,
+        )
         self.set_and_hit_breakpoint(continueToExit=True)
-        self.process.terminate()
 
     @skipIfWindows
     @skipIfNetBSD
-    def test_by_port_and_pid(self):
+    def test_fails_if_both_port_and_pid_are_set(self):
         """
         Tests attaching to a process by process ID and port number.
         """
         program = self.build_and_create_debug_adapter_for_attach()
 
-        # It is not necessary to launch "lldb-server" to obtain the actual port and pid for attaching.
-        # However, when providing the port number and pid directly, "lldb-dap" throws an error message, which is expected.
-        # So, used random pid and port numbers here.
+        # It is not necessary to launch "lldb-server" to obtain the actual port
+        # and pid for attaching. However, when providing the port number and pid
+        # directly, "lldb-dap" throws an error message, which is expected. So,
+        # used random pid and port numbers here.
 
         pid = 1354
         port = 1234
@@ -106,10 +101,9 @@ def test_by_port_and_pid(self):
             sourceInitFile=True,
             expectFailure=True,
         )
-        if not (response and response["success"]):
-            self.assertFalse(
-                response["success"], "The user can't specify both pid and port"
-            )
+        self.assertFalse(
+            response["success"], "The user can't specify both pid and port"
+        )
 
     @skipIfWindows
     @skipIfNetBSD
@@ -123,11 +117,10 @@ def test_by_invalid_port(self):
         response = self.attach(
             program=program, gdbRemotePort=port, sourceInitFile=True, expectFailure=True
         )
-        if not (response and response["success"]):
-            self.assertFalse(
-                response["success"],
-                "The user can't attach with invalid port (%s)" % port,
-            )
+        self.assertFalse(
+            response["success"],
+            "The user can't attach with invalid port (%s)" % port,
+        )
 
     @skipIfWindows
     @skipIfNetBSD
@@ -147,9 +140,7 @@ def test_by_illegal_port(self):
         response = self.attach(
             program=program, gdbRemotePort=port, sourceInitFile=True, expectFailure=True
         )
-        if not (response and response["success"]):
-            self.assertFalse(
-                response["success"],
-                "The user can't attach with illegal port (%s)" % port,
-            )
-        self.process.terminate()
+        self.assertFalse(
+            response["success"],
+            "The user can't attach with illegal port (%s)" % port,
+        )

@ashgti ashgti merged commit 7278805 into llvm:main Jun 5, 2025
12 checks passed
@ashgti ashgti deleted the gardening-attach branch June 5, 2025 00:07
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.

3 participants