xref: /llvm-project/lldb/test/API/tools/lldb-server/commandline/TestGdbRemoteConnection.py (revision a52be0cc114cc58a35bee65c517adaeb66ee6d89)
18cc49becSPavel Labathimport gdbremote_testcase
2872b1da6SPavel Labathimport random
38cc49becSPavel Labathimport socket
48cc49becSPavel Labathfrom lldbsuite.test.decorators import *
58cc49becSPavel Labathfrom lldbsuite.test.lldbtest import *
6872b1da6SPavel Labathfrom lldbgdbserverutils import Server
785f025e5SPavel Labathimport lldbsuite.test.lldbplatformutil
8*a52be0ccSSanthosh Kumar Ellendulafrom lldbgdbserverutils import Pipe
98cc49becSPavel Labath
108cc49becSPavel Labath
118cc49becSPavel Labathclass TestGdbRemoteConnection(gdbremote_testcase.GdbRemoteTestCaseBase):
128cc49becSPavel Labath    @skipIfRemote  # reverse connect is not a supported use case for now
13a63daf69SPavel Labath    def test_reverse_connect(self):
148cc49becSPavel Labath        # Reverse connect is the default connection method.
158cc49becSPavel Labath        self.connect_to_debug_monitor()
168cc49becSPavel Labath        # Verify we can do the handshake.  If that works, we'll call it good.
17872b1da6SPavel Labath        self.do_handshake()
188cc49becSPavel Labath
198cc49becSPavel Labath    @skipIfRemote
20a63daf69SPavel Labath    def test_named_pipe(self):
218cc49becSPavel Labath        family, type, proto, _, addr = socket.getaddrinfo(
222238dcc3SJonas Devlieghere            self.stub_hostname, 0, proto=socket.IPPROTO_TCP
232238dcc3SJonas Devlieghere        )[0]
248cc49becSPavel Labath        self.sock = socket.socket(family, type, proto)
258cc49becSPavel Labath        self.sock.settimeout(self.DEFAULT_TIMEOUT)
268cc49becSPavel Labath
278cc49becSPavel Labath        self.addTearDownHook(lambda: self.sock.close())
288cc49becSPavel Labath
2985f025e5SPavel Labath        pipe = Pipe(self.getBuildDir())
308cc49becSPavel Labath
3185f025e5SPavel Labath        self.addTearDownHook(lambda: pipe.close())
328cc49becSPavel Labath
338cc49becSPavel Labath        args = self.debug_monitor_extra_args
348cc49becSPavel Labath        if lldb.remote_platform:
358cc49becSPavel Labath            args += ["*:0"]
368cc49becSPavel Labath        else:
378cc49becSPavel Labath            args += ["localhost:0"]
388cc49becSPavel Labath
3985f025e5SPavel Labath        args += ["--named-pipe", pipe.name]
408cc49becSPavel Labath
418cc49becSPavel Labath        server = self.spawnSubprocess(
422238dcc3SJonas Devlieghere            self.debug_monitor_exe, args, install_remote=False
432238dcc3SJonas Devlieghere        )
448cc49becSPavel Labath
4585f025e5SPavel Labath        pipe.finish_connection(self.DEFAULT_TIMEOUT)
4685f025e5SPavel Labath        port = pipe.read(10, self.DEFAULT_TIMEOUT)
478cc49becSPavel Labath        # Trim null byte, convert to int
488cc49becSPavel Labath        addr = (addr[0], int(port[:-1]))
498cc49becSPavel Labath        self.sock.connect(addr)
50872b1da6SPavel Labath        self._server = Server(self.sock, server)
518cc49becSPavel Labath
528cc49becSPavel Labath        # Verify we can do the handshake.  If that works, we'll call it good.
53872b1da6SPavel Labath        self.do_handshake()
54