Vendor import of lldb release_39 branch r276489:
[freebsd.git] / packages / Python / lldbsuite / test / tools / lldb-server / TestGdbRemoteProcessInfo.py
1 from __future__ import print_function
2
3
4 import sys
5
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
11
12 class TestGdbRemoteProcessInfo(gdbremote_testcase.GdbRemoteTestCaseBase):
13
14     mydir = TestBase.compute_mydir(__file__)
15
16     def qProcessInfo_returns_running_process(self):
17         procs = self.prep_debug_monitor_and_inferior()
18         self.add_process_info_collection_packets()
19
20         # Run the stream
21         context = self.expect_gdbremote_sequence()
22         self.assertIsNotNone(context)
23
24         # Gather process info response
25         process_info = self.parse_process_info_response(context)
26         self.assertIsNotNone(process_info)
27
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)
33
34         # If possible, verify that the process is running.
35         self.assertTrue(lldbgdbserverutils.process_is_running(pid, True))
36
37     @debugserver_test
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(timeout_seconds = 8)
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     def test_attach_commandline_qProcessInfo_reports_correct_pid_debugserver(self):
70         self.init_debugserver_test()
71         self.build()
72         self.set_inferior_startup_attach()
73         self.attach_commandline_qProcessInfo_reports_correct_pid()
74
75     @llgs_test
76     def test_attach_commandline_qProcessInfo_reports_correct_pid_llgs(self):
77         self.init_llgs_test()
78         self.build()
79         self.set_inferior_startup_attach()
80         self.attach_commandline_qProcessInfo_reports_correct_pid()
81
82     def qProcessInfo_reports_valid_endian(self):
83         procs = self.prep_debug_monitor_and_inferior()
84         self.add_process_info_collection_packets()
85
86         # Run the stream
87         context = self.expect_gdbremote_sequence()
88         self.assertIsNotNone(context)
89
90         # Gather process info response
91         process_info = self.parse_process_info_response(context)
92         self.assertIsNotNone(process_info)
93
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"])
98
99     @debugserver_test
100     def test_qProcessInfo_reports_valid_endian_debugserver(self):
101         self.init_debugserver_test()
102         self.build()
103         self.qProcessInfo_reports_valid_endian()
104
105     @llgs_test
106     def test_qProcessInfo_reports_valid_endian_llgs(self):
107         self.init_llgs_test()
108         self.build()
109         self.qProcessInfo_reports_valid_endian()
110
111     def qProcessInfo_contains_keys(self, expected_key_set):
112         procs = self.prep_debug_monitor_and_inferior()
113         self.add_process_info_collection_packets()
114
115         # Run the stream
116         context = self.expect_gdbremote_sequence()
117         self.assertIsNotNone(context)
118
119         # Gather process info response
120         process_info = self.parse_process_info_response(context)
121         self.assertIsNotNone(process_info)
122
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)
128
129         self.assertEqual(missing_key_set, set(), "the listed keys are missing in the qProcessInfo result")
130
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()
134
135         # Run the stream
136         context = self.expect_gdbremote_sequence()
137         self.assertIsNotNone(context)
138
139         # Gather process info response
140         process_info = self.parse_process_info_response(context)
141         self.assertIsNotNone(process_info)
142
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)
148
149         self.assertEqual(unexpected_key_set, set(), "the listed keys were present but unexpected in qProcessInfo result")
150
151     @skipUnlessDarwin
152     @debugserver_test
153     def test_qProcessInfo_contains_cputype_cpusubtype_debugserver_darwin(self):
154         self.init_debugserver_test()
155         self.build()
156         self.qProcessInfo_contains_keys(set(['cputype', 'cpusubtype']))
157
158     @skipUnlessPlatform(["linux"])
159     @llgs_test
160     def test_qProcessInfo_contains_triple_llgs_linux(self):
161         self.init_llgs_test()
162         self.build()
163         self.qProcessInfo_contains_keys(set(['triple']))
164
165     @skipUnlessDarwin
166     @debugserver_test
167     def test_qProcessInfo_does_not_contain_triple_debugserver_darwin(self):
168         self.init_debugserver_test()
169         self.build()
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']))
174
175     @skipUnlessPlatform(["linux"])
176     @llgs_test
177     def test_qProcessInfo_does_not_contain_cputype_cpusubtype_llgs_linux(self):
178         self.init_llgs_test()
179         self.build()
180         self.qProcessInfo_does_not_contain_keys(set(['cputype', 'cpusubtype']))