1*3cd8d7b1SGongyu Dengimport tempfile
2*3cd8d7b1SGongyu Dengimport gdbremote_testcase
3*3cd8d7b1SGongyu Dengfrom lldbsuite.test.lldbtest import *
4*3cd8d7b1SGongyu Dengfrom lldbsuite.test.decorators import *
5*3cd8d7b1SGongyu Dengfrom lldbgdbserverutils import *
6*3cd8d7b1SGongyu Deng
7*3cd8d7b1SGongyu Dengclass GdbRemoteCompletionTestCase(gdbremote_testcase.GdbRemoteTestCaseBase):
8*3cd8d7b1SGongyu Deng    mydir = TestBase.compute_mydir(__file__)
9*3cd8d7b1SGongyu Deng
10*3cd8d7b1SGongyu Deng    def init_lldb_server(self):
11*3cd8d7b1SGongyu Deng        self.debug_monitor_exe = get_lldb_server_exe()
12*3cd8d7b1SGongyu Deng        if not self.debug_monitor_exe:
13*3cd8d7b1SGongyu Deng            self.skipTest("lldb-server exe not found")
14*3cd8d7b1SGongyu Deng        port_file = tempfile.NamedTemporaryFile().name
15*3cd8d7b1SGongyu Deng        commandline_args = [
16*3cd8d7b1SGongyu Deng            "platform",
17*3cd8d7b1SGongyu Deng            "--listen",
18*3cd8d7b1SGongyu Deng            "*:0",
19*3cd8d7b1SGongyu Deng            "--socket-file",
20*3cd8d7b1SGongyu Deng            port_file
21*3cd8d7b1SGongyu Deng        ]
22*3cd8d7b1SGongyu Deng        server = self.spawnSubprocess(
23*3cd8d7b1SGongyu Deng            get_lldb_server_exe(),
24*3cd8d7b1SGongyu Deng            commandline_args,
25*3cd8d7b1SGongyu Deng            install_remote=False)
26*3cd8d7b1SGongyu Deng        self.assertIsNotNone(server)
27*3cd8d7b1SGongyu Deng        self.stub_hostname = "localhost"
28*3cd8d7b1SGongyu Deng        self.port = int(lldbutil.wait_for_file_on_target(self, port_file))
29*3cd8d7b1SGongyu Deng        self.sock = self.create_socket()
30*3cd8d7b1SGongyu Deng
31*3cd8d7b1SGongyu Deng        self.add_no_ack_remote_stream()
32*3cd8d7b1SGongyu Deng
33*3cd8d7b1SGongyu Deng    def generate_hex_path(self, target):
34*3cd8d7b1SGongyu Deng        return str(os.path.join(self.getBuildDir(), target)).encode().hex()
35*3cd8d7b1SGongyu Deng
36*3cd8d7b1SGongyu Deng    @skipIfDarwinEmbedded # <rdar://problem/34539270> lldb-server tests not updated to work on ios etc yet
37*3cd8d7b1SGongyu Deng    @llgs_test
38*3cd8d7b1SGongyu Deng    def test_autocomplete_path(self):
39*3cd8d7b1SGongyu Deng        self.build()
40*3cd8d7b1SGongyu Deng        self.init_lldb_server()
41*3cd8d7b1SGongyu Deng
42*3cd8d7b1SGongyu Deng        # Test file-included completion when flag is set to 0.
43*3cd8d7b1SGongyu Deng        self.test_sequence.add_log_lines(
44*3cd8d7b1SGongyu Deng            ["read packet: $qPathComplete:0,{}#00".format(
45*3cd8d7b1SGongyu Deng                self.generate_hex_path("main")),
46*3cd8d7b1SGongyu Deng             "send packet: $M{},{}#00".format(
47*3cd8d7b1SGongyu Deng                self.generate_hex_path("main.d"),
48*3cd8d7b1SGongyu Deng                self.generate_hex_path("main.o"))
49*3cd8d7b1SGongyu Deng            ],
50*3cd8d7b1SGongyu Deng            True)
51*3cd8d7b1SGongyu Deng
52*3cd8d7b1SGongyu Deng        # Test directory-only completion when flag is set to 1.
53*3cd8d7b1SGongyu Deng        os.makedirs(os.path.join(self.getBuildDir(), "test"))
54*3cd8d7b1SGongyu Deng        self.test_sequence.add_log_lines(
55*3cd8d7b1SGongyu Deng            ["read packet: $qPathComplete:1,{}#00".format(
56*3cd8d7b1SGongyu Deng                self.generate_hex_path("tes")),
57*3cd8d7b1SGongyu Deng             "send packet: $M{}{}#00".format(
58*3cd8d7b1SGongyu Deng                self.generate_hex_path("test"),
59*3cd8d7b1SGongyu Deng                os.path.sep.encode().hex()) # "test/" or "test\".
60*3cd8d7b1SGongyu Deng            ],
61*3cd8d7b1SGongyu Deng            True)
62*3cd8d7b1SGongyu Deng
63*3cd8d7b1SGongyu Deng        self.expect_gdbremote_sequence()
64