1
2
3
4import gdbremote_testcase
5import lldbgdbserverutils
6from lldbsuite.test.decorators import *
7from lldbsuite.test.lldbtest import *
8from lldbsuite.test import lldbutil
9
10
11class TestGdbRemoteProcessInfo(gdbremote_testcase.GdbRemoteTestCaseBase):
12
13    mydir = TestBase.compute_mydir(__file__)
14
15    def qProcessInfo_returns_running_process(self):
16        procs = self.prep_debug_monitor_and_inferior()
17        self.add_process_info_collection_packets()
18
19        # Run the stream
20        context = self.expect_gdbremote_sequence()
21        self.assertIsNotNone(context)
22
23        # Gather process info response
24        process_info = self.parse_process_info_response(context)
25        self.assertIsNotNone(process_info)
26
27        # Ensure the process id looks reasonable.
28        pid_text = process_info.get("pid")
29        self.assertIsNotNone(pid_text)
30        pid = int(pid_text, base=16)
31        self.assertNotEqual(0, pid)
32
33        # If possible, verify that the process is running.
34        self.assertTrue(lldbgdbserverutils.process_is_running(pid, True))
35
36    @debugserver_test
37    @skipIfDarwinEmbedded # <rdar://problem/34539270> lldb-server tests not updated to work on ios etc yet
38    def test_qProcessInfo_returns_running_process_debugserver(self):
39        self.init_debugserver_test()
40        self.build()
41        self.qProcessInfo_returns_running_process()
42
43    @llgs_test
44    def test_qProcessInfo_returns_running_process_llgs(self):
45        self.init_llgs_test()
46        self.build()
47        self.qProcessInfo_returns_running_process()
48
49    def attach_commandline_qProcessInfo_reports_correct_pid(self):
50        procs = self.prep_debug_monitor_and_inferior()
51        self.assertIsNotNone(procs)
52        self.add_process_info_collection_packets()
53
54        # Run the stream
55        context = self.expect_gdbremote_sequence()
56        self.assertIsNotNone(context)
57
58        # Gather process info response
59        process_info = self.parse_process_info_response(context)
60        self.assertIsNotNone(process_info)
61
62        # Ensure the process id matches what we expected.
63        pid_text = process_info.get('pid', None)
64        self.assertIsNotNone(pid_text)
65        reported_pid = int(pid_text, base=16)
66        self.assertEqual(reported_pid, procs["inferior"].pid)
67
68    @debugserver_test
69    @skipIfDarwinEmbedded # <rdar://problem/34539270> lldb-server tests not updated to work on ios etc yet
70    def test_attach_commandline_qProcessInfo_reports_correct_pid_debugserver(
71            self):
72        self.init_debugserver_test()
73        self.build()
74        self.set_inferior_startup_attach()
75        self.attach_commandline_qProcessInfo_reports_correct_pid()
76
77    @expectedFailureNetBSD
78    @llgs_test
79    def test_attach_commandline_qProcessInfo_reports_correct_pid_llgs(self):
80        self.init_llgs_test()
81        self.build()
82        self.set_inferior_startup_attach()
83        self.attach_commandline_qProcessInfo_reports_correct_pid()
84
85    def qProcessInfo_reports_valid_endian(self):
86        procs = self.prep_debug_monitor_and_inferior()
87        self.add_process_info_collection_packets()
88
89        # Run the stream
90        context = self.expect_gdbremote_sequence()
91        self.assertIsNotNone(context)
92
93        # Gather process info response
94        process_info = self.parse_process_info_response(context)
95        self.assertIsNotNone(process_info)
96
97        # Ensure the process id looks reasonable.
98        endian = process_info.get("endian")
99        self.assertIsNotNone(endian)
100        self.assertTrue(endian in ["little", "big", "pdp"])
101
102    @debugserver_test
103    @skipIfDarwinEmbedded # <rdar://problem/34539270> lldb-server tests not updated to work on ios etc yet
104    def test_qProcessInfo_reports_valid_endian_debugserver(self):
105        self.init_debugserver_test()
106        self.build()
107        self.qProcessInfo_reports_valid_endian()
108
109    @llgs_test
110    def test_qProcessInfo_reports_valid_endian_llgs(self):
111        self.init_llgs_test()
112        self.build()
113        self.qProcessInfo_reports_valid_endian()
114
115    def qProcessInfo_contains_keys(self, expected_key_set):
116        procs = self.prep_debug_monitor_and_inferior()
117        self.add_process_info_collection_packets()
118
119        # Run the stream
120        context = self.expect_gdbremote_sequence()
121        self.assertIsNotNone(context)
122
123        # Gather process info response
124        process_info = self.parse_process_info_response(context)
125        self.assertIsNotNone(process_info)
126
127        # Ensure the expected keys are present and non-None within the process
128        # info.
129        missing_key_set = set()
130        for expected_key in expected_key_set:
131            if expected_key not in process_info:
132                missing_key_set.add(expected_key)
133
134        self.assertEqual(
135            missing_key_set,
136            set(),
137            "the listed keys are missing in the qProcessInfo result")
138
139    def qProcessInfo_does_not_contain_keys(self, absent_key_set):
140        procs = self.prep_debug_monitor_and_inferior()
141        self.add_process_info_collection_packets()
142
143        # Run the stream
144        context = self.expect_gdbremote_sequence()
145        self.assertIsNotNone(context)
146
147        # Gather process info response
148        process_info = self.parse_process_info_response(context)
149        self.assertIsNotNone(process_info)
150
151        # Ensure the unexpected keys are not present
152        unexpected_key_set = set()
153        for unexpected_key in absent_key_set:
154            if unexpected_key in process_info:
155                unexpected_key_set.add(unexpected_key)
156
157        self.assertEqual(
158            unexpected_key_set,
159            set(),
160            "the listed keys were present but unexpected in qProcessInfo result")
161
162    @skipUnlessDarwin
163    @debugserver_test
164    @skipIfDarwinEmbedded # <rdar://problem/34539270> lldb-server tests not updated to work on ios etc yet
165    def test_qProcessInfo_contains_cputype_cpusubtype_debugserver_darwin(self):
166        self.init_debugserver_test()
167        self.build()
168        self.qProcessInfo_contains_keys(set(['cputype', 'cpusubtype']))
169
170    @skipUnlessDarwin
171    @llgs_test
172    def test_qProcessInfo_contains_cputype_cpusubtype_llgs_darwin(self):
173        self.init_llgs_test()
174        self.build()
175        self.qProcessInfo_contains_keys(set(['cputype', 'cpusubtype']))
176
177    @llgs_test
178    def test_qProcessInfo_contains_triple_ppid_llgs(self):
179        self.init_llgs_test()
180        self.build()
181        self.qProcessInfo_contains_keys(set(['triple', 'parent-pid']))
182
183    @skipUnlessDarwin
184    @debugserver_test
185    @skipIfDarwinEmbedded # <rdar://problem/34539270> lldb-server tests not updated to work on ios etc yet
186    def test_qProcessInfo_does_not_contain_triple_debugserver_darwin(self):
187        self.init_debugserver_test()
188        self.build()
189        # We don't expect to see triple on darwin.  If we do, we'll prefer triple
190        # to cputype/cpusubtype and skip some darwin-based ProcessGDBRemote ArchSpec setup
191        # for the remote Host and Process.
192        self.qProcessInfo_does_not_contain_keys(set(['triple']))
193
194    @skipUnlessDarwin
195    @llgs_test
196    def test_qProcessInfo_does_not_contain_triple_llgs_darwin(self):
197        self.init_llgs_test()
198        self.build()
199        # We don't expect to see triple on darwin.  If we do, we'll prefer triple
200        # to cputype/cpusubtype and skip some darwin-based ProcessGDBRemote ArchSpec setup
201        # for the remote Host and Process.
202        self.qProcessInfo_does_not_contain_keys(set(['triple']))
203
204    @skipIfDarwin
205    @llgs_test
206    def test_qProcessInfo_does_not_contain_cputype_cpusubtype_llgs(self):
207        self.init_llgs_test()
208        self.build()
209        self.qProcessInfo_does_not_contain_keys(set(['cputype', 'cpusubtype']))
210