1 from __future__ import print_function
6 import gdbremote_testcase
7 import lldbgdbserverutils
8 from lldbsuite.test.decorators import *
9 from lldbsuite.test.lldbtest import *
10 from lldbsuite.test import lldbutil
12 class TestGdbRemoteProcessInfo(gdbremote_testcase.GdbRemoteTestCaseBase):
14 mydir = TestBase.compute_mydir(__file__)
16 def qProcessInfo_returns_running_process(self):
17 procs = self.prep_debug_monitor_and_inferior()
18 self.add_process_info_collection_packets()
21 context = self.expect_gdbremote_sequence()
22 self.assertIsNotNone(context)
24 # Gather process info response
25 process_info = self.parse_process_info_response(context)
26 self.assertIsNotNone(process_info)
28 # Ensure the process id looks reasonable.
29 pid_text = process_info.get("pid")
30 self.assertIsNotNone(pid_text)
31 pid = int(pid_text, base=16)
32 self.assertNotEqual(0, pid)
34 # If possible, verify that the process is running.
35 self.assertTrue(lldbgdbserverutils.process_is_running(pid, True))
38 def test_qProcessInfo_returns_running_process_debugserver(self):
39 self.init_debugserver_test()
41 self.qProcessInfo_returns_running_process()
44 def test_qProcessInfo_returns_running_process_llgs(self):
47 self.qProcessInfo_returns_running_process()
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()
55 context = self.expect_gdbremote_sequence(timeout_seconds = 8)
56 self.assertIsNotNone(context)
58 # Gather process info response
59 process_info = self.parse_process_info_response(context)
60 self.assertIsNotNone(process_info)
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)
69 def test_attach_commandline_qProcessInfo_reports_correct_pid_debugserver(self):
70 self.init_debugserver_test()
72 self.set_inferior_startup_attach()
73 self.attach_commandline_qProcessInfo_reports_correct_pid()
76 def test_attach_commandline_qProcessInfo_reports_correct_pid_llgs(self):
79 self.set_inferior_startup_attach()
80 self.attach_commandline_qProcessInfo_reports_correct_pid()
82 def qProcessInfo_reports_valid_endian(self):
83 procs = self.prep_debug_monitor_and_inferior()
84 self.add_process_info_collection_packets()
87 context = self.expect_gdbremote_sequence()
88 self.assertIsNotNone(context)
90 # Gather process info response
91 process_info = self.parse_process_info_response(context)
92 self.assertIsNotNone(process_info)
94 # Ensure the process id looks reasonable.
95 endian = process_info.get("endian")
96 self.assertIsNotNone(endian)
97 self.assertTrue(endian in ["little", "big", "pdp"])
100 def test_qProcessInfo_reports_valid_endian_debugserver(self):
101 self.init_debugserver_test()
103 self.qProcessInfo_reports_valid_endian()
106 def test_qProcessInfo_reports_valid_endian_llgs(self):
107 self.init_llgs_test()
109 self.qProcessInfo_reports_valid_endian()
111 def qProcessInfo_contains_keys(self, expected_key_set):
112 procs = self.prep_debug_monitor_and_inferior()
113 self.add_process_info_collection_packets()
116 context = self.expect_gdbremote_sequence()
117 self.assertIsNotNone(context)
119 # Gather process info response
120 process_info = self.parse_process_info_response(context)
121 self.assertIsNotNone(process_info)
123 # Ensure the expected keys are present and non-None within the process info.
124 missing_key_set = set()
125 for expected_key in expected_key_set:
126 if expected_key not in process_info:
127 missing_key_set.add(expected_key)
129 self.assertEqual(missing_key_set, set(), "the listed keys are missing in the qProcessInfo result")
131 def qProcessInfo_does_not_contain_keys(self, absent_key_set):
132 procs = self.prep_debug_monitor_and_inferior()
133 self.add_process_info_collection_packets()
136 context = self.expect_gdbremote_sequence()
137 self.assertIsNotNone(context)
139 # Gather process info response
140 process_info = self.parse_process_info_response(context)
141 self.assertIsNotNone(process_info)
143 # Ensure the unexpected keys are not present
144 unexpected_key_set = set()
145 for unexpected_key in absent_key_set:
146 if unexpected_key in process_info:
147 unexpected_key_set.add(unexpected_key)
149 self.assertEqual(unexpected_key_set, set(), "the listed keys were present but unexpected in qProcessInfo result")
153 def test_qProcessInfo_contains_cputype_cpusubtype_debugserver_darwin(self):
154 self.init_debugserver_test()
156 self.qProcessInfo_contains_keys(set(['cputype', 'cpusubtype']))
158 @skipUnlessPlatform(["linux"])
160 def test_qProcessInfo_contains_triple_llgs_linux(self):
161 self.init_llgs_test()
163 self.qProcessInfo_contains_keys(set(['triple']))
167 def test_qProcessInfo_does_not_contain_triple_debugserver_darwin(self):
168 self.init_debugserver_test()
170 # We don't expect to see triple on darwin. If we do, we'll prefer triple
171 # to cputype/cpusubtype and skip some darwin-based ProcessGDBRemote ArchSpec setup
172 # for the remote Host and Process.
173 self.qProcessInfo_does_not_contain_keys(set(['triple']))
175 @skipUnlessPlatform(["linux"])
177 def test_qProcessInfo_does_not_contain_cputype_cpusubtype_llgs_linux(self):
178 self.init_llgs_test()
180 self.qProcessInfo_does_not_contain_keys(set(['cputype', 'cpusubtype']))