1 from __future__ import print_function
3 import gdbremote_testcase
4 import lldbgdbserverutils
8 from lldbsuite.test.decorators import *
9 from lldbsuite.test.lldbtest import *
10 from lldbsuite.test import lldbutil
13 class TestStubReverseConnect(gdbremote_testcase.GdbRemoteTestCaseBase):
15 mydir = TestBase.compute_mydir(__file__)
17 _DEFAULT_TIMEOUT = 20 * (10 if ('ASAN_OPTIONS' in os.environ) else 1)
21 gdbremote_testcase.GdbRemoteTestCaseBase.setUp(self)
23 # Create a listener on a local port.
24 self.listener_socket = self.create_listener_socket()
25 self.assertIsNotNone(self.listener_socket)
26 self.listener_port = self.listener_socket.getsockname()[1]
28 def create_listener_socket(self, timeout_seconds=_DEFAULT_TIMEOUT):
29 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
30 self.assertIsNotNone(sock)
32 sock.settimeout(timeout_seconds)
33 sock.bind(("127.0.0.1", 0))
36 def tear_down_listener():
38 sock.shutdown(socket.SHUT_RDWR)
43 self.addTearDownHook(tear_down_listener)
46 def reverse_connect_works(self):
47 # Indicate stub startup should do a reverse connect.
48 appended_stub_args = ["--reverse-connect"]
49 if self.debug_monitor_extra_args:
50 self.debug_monitor_extra_args += appended_stub_args
52 self.debug_monitor_extra_args = appended_stub_args
54 self.stub_hostname = "127.0.0.1"
55 self.port = self.listener_port
57 triple = self.dbg.GetSelectedPlatform().GetTriple()
58 if re.match(".*-.*-.*-android", triple):
59 self.forward_adb_port(
66 server = self.launch_debug_monitor(logfile=sys.stdout)
67 self.assertIsNotNone(server)
69 lldbgdbserverutils.process_is_running(
72 # Listen for the stub's connection to us.
73 (stub_socket, address) = self.listener_socket.accept()
74 self.assertIsNotNone(stub_socket)
75 self.assertIsNotNone(address)
76 print("connected to stub {} on {}".format(
77 address, stub_socket.getsockname()))
79 # Verify we can do the handshake. If that works, we'll call it good.
80 self.do_handshake(stub_socket, timeout_seconds=self._DEFAULT_TIMEOUT)
83 stub_socket.shutdown(socket.SHUT_RDWR)
86 @skipIfDarwinEmbedded # <rdar://problem/34539270> lldb-server tests not updated to work on ios etc yet
87 def test_reverse_connect_works_debugserver(self):
88 self.init_debugserver_test(use_named_pipe=False)
89 self.set_inferior_startup_launch()
90 self.reverse_connect_works()
93 @skipIfRemote # reverse connect is not a supported use case for now
94 def test_reverse_connect_works_llgs(self):
95 self.init_llgs_test(use_named_pipe=False)
96 self.set_inferior_startup_launch()
97 self.reverse_connect_works()