1 import gdbremote_testcase
2 import lldbgdbserverutils
3 from lldbsuite
.test
.decorators
import *
4 from lldbsuite
.test
.lldbtest
import *
5 from lldbsuite
.test
import lldbutil
8 class TestGdbRemoteProcessInfo(gdbremote_testcase
.GdbRemoteTestCaseBase
):
9 def test_qProcessInfo_returns_running_process(self
):
11 procs
= self
.prep_debug_monitor_and_inferior()
12 self
.add_process_info_collection_packets()
15 context
= self
.expect_gdbremote_sequence()
16 self
.assertIsNotNone(context
)
18 # Gather process info response
19 process_info
= self
.parse_process_info_response(context
)
20 self
.assertIsNotNone(process_info
)
22 # Ensure the process id looks reasonable.
23 pid_text
= process_info
.get("pid")
24 self
.assertIsNotNone(pid_text
)
25 pid
= int(pid_text
, base
=16)
26 self
.assertNotEqual(0, pid
)
28 # If possible, verify that the process is running.
29 self
.assertTrue(lldbgdbserverutils
.process_is_running(pid
, True))
31 def test_attach_commandline_qProcessInfo_reports_correct_pid(self
):
33 self
.set_inferior_startup_attach()
34 procs
= self
.prep_debug_monitor_and_inferior()
35 self
.assertIsNotNone(procs
)
36 self
.add_process_info_collection_packets()
39 context
= self
.expect_gdbremote_sequence()
40 self
.assertIsNotNone(context
)
42 # Gather process info response
43 process_info
= self
.parse_process_info_response(context
)
44 self
.assertIsNotNone(process_info
)
46 # Ensure the process id matches what we expected.
47 pid_text
= process_info
.get("pid", None)
48 self
.assertIsNotNone(pid_text
)
49 reported_pid
= int(pid_text
, base
=16)
50 self
.assertEqual(reported_pid
, procs
["inferior"].pid
)
52 def test_qProcessInfo_reports_valid_endian(self
):
54 procs
= self
.prep_debug_monitor_and_inferior()
55 self
.add_process_info_collection_packets()
58 context
= self
.expect_gdbremote_sequence()
59 self
.assertIsNotNone(context
)
61 # Gather process info response
62 process_info
= self
.parse_process_info_response(context
)
63 self
.assertIsNotNone(process_info
)
65 # Ensure the process id looks reasonable.
66 endian
= process_info
.get("endian")
67 self
.assertIsNotNone(endian
)
68 self
.assertIn(endian
, ["little", "big", "pdp"])
70 def qProcessInfo_contains_keys(self
, expected_key_set
):
71 procs
= self
.prep_debug_monitor_and_inferior()
72 self
.add_process_info_collection_packets()
75 context
= self
.expect_gdbremote_sequence()
76 self
.assertIsNotNone(context
)
78 # Gather process info response
79 process_info
= self
.parse_process_info_response(context
)
80 self
.assertIsNotNone(process_info
)
82 # Ensure the expected keys are present and non-None within the process
84 missing_key_set
= set()
85 for expected_key
in expected_key_set
:
86 if expected_key
not in process_info
:
87 missing_key_set
.add(expected_key
)
92 "the listed keys are missing in the qProcessInfo result",
95 def qProcessInfo_does_not_contain_keys(self
, absent_key_set
):
96 procs
= self
.prep_debug_monitor_and_inferior()
97 self
.add_process_info_collection_packets()
100 context
= self
.expect_gdbremote_sequence()
101 self
.assertIsNotNone(context
)
103 # Gather process info response
104 process_info
= self
.parse_process_info_response(context
)
105 self
.assertIsNotNone(process_info
)
107 # Ensure the unexpected keys are not present
108 unexpected_key_set
= set()
109 for unexpected_key
in absent_key_set
:
110 if unexpected_key
in process_info
:
111 unexpected_key_set
.add(unexpected_key
)
116 "the listed keys were present but unexpected in qProcessInfo result",
119 @add_test_categories(["debugserver"])
120 def test_qProcessInfo_contains_cputype_cpusubtype(self
):
122 self
.qProcessInfo_contains_keys(set(["cputype", "cpusubtype"]))
124 @add_test_categories(["llgs"])
125 def test_qProcessInfo_contains_triple_ppid(self
):
127 self
.qProcessInfo_contains_keys(set(["triple", "parent-pid"]))
129 @add_test_categories(["debugserver"])
130 def test_qProcessInfo_does_not_contain_triple(self
):
132 # We don't expect to see triple on darwin. If we do, we'll prefer triple
133 # to cputype/cpusubtype and skip some darwin-based ProcessGDBRemote ArchSpec setup
134 # for the remote Host and Process.
135 self
.qProcessInfo_does_not_contain_keys(set(["triple"]))
137 @add_test_categories(["llgs"])
138 def test_qProcessInfo_does_not_contain_cputype_cpusubtype(self
):
140 self
.qProcessInfo_does_not_contain_keys(set(["cputype", "cpusubtype"]))