[Lldb-commits] [lldb] 1695c84 - [lldb] Generalize an deflake gdb-remote *client* tests

Pavel Labath via lldb-commits lldb-commits at lists.llvm.org
Mon Nov 2 07:34:33 PST 2020


Author: Pavel Labath
Date: 2020-11-02T16:34:25+01:00
New Revision: 1695c8420a1c43ff6f4ff442ce5fa0cdd2f6e78f

URL: https://github.com/llvm/llvm-project/commit/1695c8420a1c43ff6f4ff442ce5fa0cdd2f6e78f
DIFF: https://github.com/llvm/llvm-project/commit/1695c8420a1c43ff6f4ff442ce5fa0cdd2f6e78f.diff

LOG: [lldb] Generalize an deflake gdb-remote *client* tests

This is similar in spirit to what D90313 did for server tests.

Added: 
    

Modified: 
    lldb/test/API/functionalities/gdb_remote_client/TestGDBRemoteDiskFileCompletion.py
    lldb/test/API/functionalities/gdb_remote_client/TestPlatformClient.py
    lldb/test/API/functionalities/gdb_remote_client/TestProcessConnect.py
    lldb/test/API/functionalities/gdb_remote_client/gdbclientutils.py

Removed: 
    


################################################################################
diff  --git a/lldb/test/API/functionalities/gdb_remote_client/TestGDBRemoteDiskFileCompletion.py b/lldb/test/API/functionalities/gdb_remote_client/TestGDBRemoteDiskFileCompletion.py
index 90f830c4a278..c0afce00a4cf 100644
--- a/lldb/test/API/functionalities/gdb_remote_client/TestGDBRemoteDiskFileCompletion.py
+++ b/lldb/test/API/functionalities/gdb_remote_client/TestGDBRemoteDiskFileCompletion.py
@@ -16,8 +16,8 @@ def qPathComplete(self):
 
         try:
             self.runCmd("platform select remote-gdb-server")
-            self.runCmd("platform connect connect://localhost:%d" %
-                        self.server.port)
+            self.runCmd("platform connect connect://" +
+                        self.server.get_connect_address())
             self.assertTrue(self.dbg.GetSelectedPlatform().IsConnected())
 
             self.complete_from_to('platform get-size ', ['test', '123'])

diff  --git a/lldb/test/API/functionalities/gdb_remote_client/TestPlatformClient.py b/lldb/test/API/functionalities/gdb_remote_client/TestPlatformClient.py
index 2da8dd59e17c..e05089ecc18e 100644
--- a/lldb/test/API/functionalities/gdb_remote_client/TestPlatformClient.py
+++ b/lldb/test/API/functionalities/gdb_remote_client/TestPlatformClient.py
@@ -49,8 +49,7 @@ def qsProcessInfo(self):
 
         try:
             self.runCmd("platform select remote-linux")
-            self.runCmd("platform connect connect://localhost:%d" %
-                        self.server.port)
+            self.runCmd("platform connect connect://" + self.server.get_connect_address())
             self.assertTrue(self.dbg.GetSelectedPlatform().IsConnected())
             self.expect("platform process list -x",
                         substrs=["2 matching processes were found", "test_process", "another_test_process"])

diff  --git a/lldb/test/API/functionalities/gdb_remote_client/TestProcessConnect.py b/lldb/test/API/functionalities/gdb_remote_client/TestProcessConnect.py
index 32a585d5bd34..af9f212c7439 100644
--- a/lldb/test/API/functionalities/gdb_remote_client/TestProcessConnect.py
+++ b/lldb/test/API/functionalities/gdb_remote_client/TestProcessConnect.py
@@ -16,7 +16,7 @@ def test_gdb_remote_sync(self):
         """Test the gdb-remote command in synchronous mode"""
         try:
             self.dbg.SetAsync(False)
-            self.expect("gdb-remote %d" % self.server.port,
+            self.expect("gdb-remote " + self.server.get_connect_address(),
                         substrs=['Process', 'stopped'])
         finally:
             self.dbg.GetSelectedPlatform().DisconnectRemote()
@@ -27,7 +27,7 @@ def test_gdb_remote_async(self):
         """Test the gdb-remote command in asynchronous mode"""
         try:
             self.dbg.SetAsync(True)
-            self.expect("gdb-remote %d" % self.server.port,
+            self.expect("gdb-remote " + self.server.get_connect_address(),
                         matching=False,
                         substrs=['Process', 'stopped'])
             lldbutil.expect_state_changes(self, self.dbg.GetListener(),
@@ -40,8 +40,8 @@ def test_process_connect_sync(self):
         """Test the gdb-remote command in synchronous mode"""
         try:
             self.dbg.SetAsync(False)
-            self.expect("process connect connect://localhost:%d" %
-                        self.server.port,
+            self.expect("process connect connect://" +
+                        self.server.get_connect_address(),
                         substrs=['Process', 'stopped'])
         finally:
             self.dbg.GetSelectedPlatform().DisconnectRemote()
@@ -52,8 +52,8 @@ def test_process_connect_async(self):
         """Test the gdb-remote command in asynchronous mode"""
         try:
             self.dbg.SetAsync(True)
-            self.expect("process connect connect://localhost:%d" %
-                        self.server.port,
+            self.expect("process connect connect://" +
+                        self.server.get_connect_address(),
                         matching=False,
                         substrs=['Process', 'stopped'])
             lldbutil.expect_state_changes(self, self.dbg.GetListener(),

diff  --git a/lldb/test/API/functionalities/gdb_remote_client/gdbclientutils.py b/lldb/test/API/functionalities/gdb_remote_client/gdbclientutils.py
index dabe9423434d..4c5ff03ef5a4 100644
--- a/lldb/test/API/functionalities/gdb_remote_client/gdbclientutils.py
+++ b/lldb/test/API/functionalities/gdb_remote_client/gdbclientutils.py
@@ -307,7 +307,6 @@ class MockGDBServer:
     """
 
     responder = None
-    port = 0
     _socket = None
     _client = None
     _thread = None
@@ -315,26 +314,19 @@ class MockGDBServer:
     _receivedDataOffset = None
     _shouldSendAck = True
 
-    def __init__(self, port = 0):
+    def __init__(self):
         self.responder = MockGDBServerResponder()
-        self.port = port
-        try:
-            self._socket = socket.socket(family=socket.AF_INET)
-        except OSError as e:
-            if e.errno != errno.EAFNOSUPPORT:
-                raise
-            self._socket = socket.socket(family=socket.AF_INET6)
 
     def start(self):
-        # Block until the socket is up, so self.port is available immediately.
-        # Then start a thread that waits for a client connection.
-        if self._socket.family == socket.AF_INET:
-            addr = ("127.0.0.1", self.port)
-        elif self._socket.family == socket.AF_INET6:
-            addr = ("::1", self.port)
+        family, type, proto, _, addr = socket.getaddrinfo("localhost", 0,
+                proto=socket.IPPROTO_TCP)[0]
+        self._socket = socket.socket(family, type, proto)
+
+
         self._socket.bind(addr)
-        self.port = self._socket.getsockname()[1]
         self._socket.listen(1)
+
+        # Start a thread that waits for a client connection.
         self._thread = threading.Thread(target=self._run)
         self._thread.start()
 
@@ -343,6 +335,9 @@ def stop(self):
         self._thread.join()
         self._thread = None
 
+    def get_connect_address(self):
+        return "[{}]:{}".format(*self._socket.getsockname())
+
     def _run(self):
         # For testing purposes, we only need to worry about one client
         # connecting just one time.
@@ -528,8 +523,8 @@ def connect(self, target):
         """
         listener = self.dbg.GetListener()
         error = lldb.SBError()
-        url = "connect://localhost:%d" % self.server.port
-        process = target.ConnectRemote(listener, url, "gdb-remote", error)
+        process = target.ConnectRemote(listener,
+                "connect://" + self.server.get_connect_address(), "gdb-remote", error)
         self.assertTrue(error.Success(), error.description)
         self.assertTrue(process, PROCESS_IS_VALID)
         return process


        


More information about the lldb-commits mailing list