xref: /llvm-project/lldb/test/API/tools/lldb-server/commandline/TestGdbRemoteConnection.py (revision a52be0cc114cc58a35bee65c517adaeb66ee6d89)
1import gdbremote_testcase
2import random
3import socket
4from lldbsuite.test.decorators import *
5from lldbsuite.test.lldbtest import *
6from lldbgdbserverutils import Server
7import lldbsuite.test.lldbplatformutil
8from lldbgdbserverutils import Pipe
9
10
11class TestGdbRemoteConnection(gdbremote_testcase.GdbRemoteTestCaseBase):
12    @skipIfRemote  # reverse connect is not a supported use case for now
13    def test_reverse_connect(self):
14        # Reverse connect is the default connection method.
15        self.connect_to_debug_monitor()
16        # Verify we can do the handshake.  If that works, we'll call it good.
17        self.do_handshake()
18
19    @skipIfRemote
20    def test_named_pipe(self):
21        family, type, proto, _, addr = socket.getaddrinfo(
22            self.stub_hostname, 0, proto=socket.IPPROTO_TCP
23        )[0]
24        self.sock = socket.socket(family, type, proto)
25        self.sock.settimeout(self.DEFAULT_TIMEOUT)
26
27        self.addTearDownHook(lambda: self.sock.close())
28
29        pipe = Pipe(self.getBuildDir())
30
31        self.addTearDownHook(lambda: pipe.close())
32
33        args = self.debug_monitor_extra_args
34        if lldb.remote_platform:
35            args += ["*:0"]
36        else:
37            args += ["localhost:0"]
38
39        args += ["--named-pipe", pipe.name]
40
41        server = self.spawnSubprocess(
42            self.debug_monitor_exe, args, install_remote=False
43        )
44
45        pipe.finish_connection(self.DEFAULT_TIMEOUT)
46        port = pipe.read(10, self.DEFAULT_TIMEOUT)
47        # Trim null byte, convert to int
48        addr = (addr[0], int(port[:-1]))
49        self.sock.connect(addr)
50        self._server = Server(self.sock, server)
51
52        # Verify we can do the handshake.  If that works, we'll call it good.
53        self.do_handshake()
54