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 @llgs_test 78 def test_attach_commandline_qProcessInfo_reports_correct_pid_llgs(self): 79 self.init_llgs_test() 80 self.build() 81 self.set_inferior_startup_attach() 82 self.attach_commandline_qProcessInfo_reports_correct_pid() 83 84 def qProcessInfo_reports_valid_endian(self): 85 procs = self.prep_debug_monitor_and_inferior() 86 self.add_process_info_collection_packets() 87 88 # Run the stream 89 context = self.expect_gdbremote_sequence() 90 self.assertIsNotNone(context) 91 92 # Gather process info response 93 process_info = self.parse_process_info_response(context) 94 self.assertIsNotNone(process_info) 95 96 # Ensure the process id looks reasonable. 97 endian = process_info.get("endian") 98 self.assertIsNotNone(endian) 99 self.assertTrue(endian in ["little", "big", "pdp"]) 100 101 @debugserver_test 102 @skipIfDarwinEmbedded # <rdar://problem/34539270> lldb-server tests not updated to work on ios etc yet 103 def test_qProcessInfo_reports_valid_endian_debugserver(self): 104 self.init_debugserver_test() 105 self.build() 106 self.qProcessInfo_reports_valid_endian() 107 108 @llgs_test 109 def test_qProcessInfo_reports_valid_endian_llgs(self): 110 self.init_llgs_test() 111 self.build() 112 self.qProcessInfo_reports_valid_endian() 113 114 def qProcessInfo_contains_keys(self, expected_key_set): 115 procs = self.prep_debug_monitor_and_inferior() 116 self.add_process_info_collection_packets() 117 118 # Run the stream 119 context = self.expect_gdbremote_sequence() 120 self.assertIsNotNone(context) 121 122 # Gather process info response 123 process_info = self.parse_process_info_response(context) 124 self.assertIsNotNone(process_info) 125 126 # Ensure the expected keys are present and non-None within the process 127 # info. 128 missing_key_set = set() 129 for expected_key in expected_key_set: 130 if expected_key not in process_info: 131 missing_key_set.add(expected_key) 132 133 self.assertEqual( 134 missing_key_set, 135 set(), 136 "the listed keys are missing in the qProcessInfo result") 137 138 def qProcessInfo_does_not_contain_keys(self, absent_key_set): 139 procs = self.prep_debug_monitor_and_inferior() 140 self.add_process_info_collection_packets() 141 142 # Run the stream 143 context = self.expect_gdbremote_sequence() 144 self.assertIsNotNone(context) 145 146 # Gather process info response 147 process_info = self.parse_process_info_response(context) 148 self.assertIsNotNone(process_info) 149 150 # Ensure the unexpected keys are not present 151 unexpected_key_set = set() 152 for unexpected_key in absent_key_set: 153 if unexpected_key in process_info: 154 unexpected_key_set.add(unexpected_key) 155 156 self.assertEqual( 157 unexpected_key_set, 158 set(), 159 "the listed keys were present but unexpected in qProcessInfo result") 160 161 @skipUnlessDarwin 162 @debugserver_test 163 @skipIfDarwinEmbedded # <rdar://problem/34539270> lldb-server tests not updated to work on ios etc yet 164 def test_qProcessInfo_contains_cputype_cpusubtype_debugserver_darwin(self): 165 self.init_debugserver_test() 166 self.build() 167 self.qProcessInfo_contains_keys(set(['cputype', 'cpusubtype'])) 168 169 @skipUnlessDarwin 170 @llgs_test 171 def test_qProcessInfo_contains_cputype_cpusubtype_llgs_darwin(self): 172 self.init_llgs_test() 173 self.build() 174 self.qProcessInfo_contains_keys(set(['cputype', 'cpusubtype'])) 175 176 @llgs_test 177 def test_qProcessInfo_contains_triple_ppid_llgs(self): 178 self.init_llgs_test() 179 self.build() 180 self.qProcessInfo_contains_keys(set(['triple', 'parent-pid'])) 181 182 @skipUnlessDarwin 183 @debugserver_test 184 @skipIfDarwinEmbedded # <rdar://problem/34539270> lldb-server tests not updated to work on ios etc yet 185 def test_qProcessInfo_does_not_contain_triple_debugserver_darwin(self): 186 self.init_debugserver_test() 187 self.build() 188 # We don't expect to see triple on darwin. If we do, we'll prefer triple 189 # to cputype/cpusubtype and skip some darwin-based ProcessGDBRemote ArchSpec setup 190 # for the remote Host and Process. 191 self.qProcessInfo_does_not_contain_keys(set(['triple'])) 192 193 @skipUnlessDarwin 194 @llgs_test 195 def test_qProcessInfo_does_not_contain_triple_llgs_darwin(self): 196 self.init_llgs_test() 197 self.build() 198 # We don't expect to see triple on darwin. If we do, we'll prefer triple 199 # to cputype/cpusubtype and skip some darwin-based ProcessGDBRemote ArchSpec setup 200 # for the remote Host and Process. 201 self.qProcessInfo_does_not_contain_keys(set(['triple'])) 202 203 @skipIfDarwin 204 @llgs_test 205 def test_qProcessInfo_does_not_contain_cputype_cpusubtype_llgs(self): 206 self.init_llgs_test() 207 self.build() 208 self.qProcessInfo_does_not_contain_keys(set(['cputype', 'cpusubtype'])) 209