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

This is similar in spirit to what D90313 did for server tests.
This commit is contained in:
Pavel Labath 2020-11-02 16:11:47 +01:00
parent c88390468c
commit 1695c8420a
4 changed files with 22 additions and 28 deletions

View File

@ -16,8 +16,8 @@ class TestGDBRemoteDiskFileCompletion(GDBRemoteTestBase):
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'])

View File

@ -49,8 +49,7 @@ class TestPlatformClient(GDBRemoteTestBase):
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"])

View File

@ -16,7 +16,7 @@ class TestProcessConnect(GDBRemoteTestBase):
"""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 @@ class TestProcessConnect(GDBRemoteTestBase):
"""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 @@ class TestProcessConnect(GDBRemoteTestBase):
"""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 @@ class TestProcessConnect(GDBRemoteTestBase):
"""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(),

View File

@ -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 @@ class MockGDBServer:
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 @@ class GDBRemoteTestBase(TestBase):
"""
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