• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1from __future__ import print_function
2
3# lldb test suite imports
4from lldbsuite.test.decorators import *
5from lldbsuite.test.lldbtest import TestBase
6
7# gdb-remote-specific imports
8import lldbgdbserverutils
9from gdbremote_testcase import GdbRemoteTestCaseBase
10
11
12class TestGdbRemoteHostInfo(GdbRemoteTestCaseBase):
13
14    mydir = TestBase.compute_mydir(__file__)
15
16    KNOWN_HOST_INFO_KEYS = set([
17        "arch",
18        "cputype",
19        "cpusubtype",
20        "distribution_id",
21        "endian",
22        "hostname",
23        "ostype",
24        "os_build",
25        "os_kernel",
26        "os_version",
27        "maccatalyst_version",
28        "ptrsize",
29        "triple",
30        "vendor",
31        "watchpoint_exceptions_received",
32        "default_packet_timeout",
33    ])
34
35    DARWIN_REQUIRED_HOST_INFO_KEYS = set([
36        "cputype",
37        "cpusubtype",
38        "endian",
39        "ostype",
40        "ptrsize",
41        "vendor",
42        "watchpoint_exceptions_received"
43    ])
44
45    def add_host_info_collection_packets(self):
46        self.test_sequence.add_log_lines(
47            ["read packet: $qHostInfo#9b",
48             {"direction": "send", "regex": r"^\$(.+)#[0-9a-fA-F]{2}$",
49              "capture": {1: "host_info_raw"}}],
50            True)
51
52    def parse_host_info_response(self, context):
53        # Ensure we have a host info response.
54        self.assertIsNotNone(context)
55        host_info_raw = context.get("host_info_raw")
56        self.assertIsNotNone(host_info_raw)
57
58        # Pull out key:value; pairs.
59        host_info_dict = {match.group(1): match.group(2)
60                          for match in re.finditer(r"([^:]+):([^;]+);",
61                                                   host_info_raw)}
62
63        import pprint
64        print("\nqHostInfo response:")
65        pprint.pprint(host_info_dict)
66
67        # Validate keys are known.
68        for (key, val) in list(host_info_dict.items()):
69            self.assertTrue(key in self.KNOWN_HOST_INFO_KEYS,
70                            "unknown qHostInfo key: " + key)
71            self.assertIsNotNone(val)
72
73        # Return the key:val pairs.
74        return host_info_dict
75
76    def get_qHostInfo_response(self):
77        # Launch the debug monitor stub, attaching to the inferior.
78        server = self.connect_to_debug_monitor()
79        self.assertIsNotNone(server)
80        self.add_no_ack_remote_stream()
81
82        # Request qHostInfo and get response
83        self.add_host_info_collection_packets()
84        context = self.expect_gdbremote_sequence()
85        self.assertIsNotNone(context)
86
87        # Parse qHostInfo response.
88        host_info = self.parse_host_info_response(context)
89        self.assertIsNotNone(host_info)
90        self.assertGreater(len(host_info), 0, "qHostInfo should have returned "
91                           "at least one key:val pair.")
92        return host_info
93
94    def validate_darwin_minimum_host_info_keys(self, host_info_dict):
95        self.assertIsNotNone(host_info_dict)
96        missing_keys = [key for key in self.DARWIN_REQUIRED_HOST_INFO_KEYS
97                        if key not in host_info_dict]
98        self.assertEquals(0, len(missing_keys),
99                          "qHostInfo is missing the following required "
100                          "keys: " + str(missing_keys))
101
102    @skipIfDarwinEmbedded # <rdar://problem/34539270> lldb-server tests not updated to work on ios etc yet
103    @debugserver_test
104    def test_qHostInfo_returns_at_least_one_key_val_pair_debugserver(self):
105        self.init_debugserver_test()
106        self.build()
107        self.get_qHostInfo_response()
108
109    @skipIfDarwinEmbedded # <rdar://problem/34539270> lldb-server tests not updated to work on ios etc yet
110    @llgs_test
111    def test_qHostInfo_returns_at_least_one_key_val_pair_llgs(self):
112        self.init_llgs_test()
113        self.build()
114        self.get_qHostInfo_response()
115
116    @skipUnlessDarwin
117    @skipIfDarwinEmbedded # <rdar://problem/34539270> lldb-server tests not updated to work on ios etc yet
118    @debugserver_test
119    def test_qHostInfo_contains_darwin_required_keys_debugserver(self):
120        self.init_debugserver_test()
121        self.build()
122        host_info_dict = self.get_qHostInfo_response()
123        self.validate_darwin_minimum_host_info_keys(host_info_dict)
124
125    @skipUnlessDarwin
126    @skipIfDarwinEmbedded # <rdar://problem/34539270> lldb-server tests not updated to work on ios etc yet
127    @llgs_test
128    def test_qHostInfo_contains_darwin_required_keys_llgs(self):
129        self.init_llgs_test()
130        self.build()
131        host_info_dict = self.get_qHostInfo_response()
132        self.validate_darwin_minimum_host_info_keys(host_info_dict)
133