Todd Fiala | f76a891 | 2014-08-26 17:19:10 +0000 | [diff] [blame] | 1 | import gdbremote_testcase |
| 2 | import lldbgdbserverutils |
Todd Fiala | c540dd0 | 2014-08-26 18:21:02 +0000 | [diff] [blame] | 3 | import sys |
| 4 | import unittest2 |
Todd Fiala | f76a891 | 2014-08-26 17:19:10 +0000 | [diff] [blame] | 5 | |
| 6 | from lldbtest import * |
| 7 | |
| 8 | class TestGdbRemoteProcessInfo(gdbremote_testcase.GdbRemoteTestCaseBase): |
| 9 | |
Vince Harron | 65f9916 | 2015-05-21 18:54:12 +0000 | [diff] [blame^] | 10 | mydir = TestBase.compute_mydir(__file__) |
| 11 | |
Todd Fiala | f76a891 | 2014-08-26 17:19:10 +0000 | [diff] [blame] | 12 | def qProcessInfo_returns_running_process(self): |
| 13 | procs = self.prep_debug_monitor_and_inferior() |
| 14 | self.add_process_info_collection_packets() |
| 15 | |
| 16 | # Run the stream |
| 17 | context = self.expect_gdbremote_sequence() |
| 18 | self.assertIsNotNone(context) |
| 19 | |
| 20 | # Gather process info response |
| 21 | process_info = self.parse_process_info_response(context) |
| 22 | self.assertIsNotNone(process_info) |
| 23 | |
| 24 | # Ensure the process id looks reasonable. |
| 25 | pid_text = process_info.get("pid") |
| 26 | self.assertIsNotNone(pid_text) |
| 27 | pid = int(pid_text, base=16) |
| 28 | self.assertNotEqual(0, pid) |
| 29 | |
| 30 | # If possible, verify that the process is running. |
| 31 | self.assertTrue(lldbgdbserverutils.process_is_running(pid, True)) |
| 32 | |
| 33 | @debugserver_test |
| 34 | @dsym_test |
| 35 | def test_qProcessInfo_returns_running_process_debugserver_dsym(self): |
| 36 | self.init_debugserver_test() |
| 37 | self.buildDsym() |
| 38 | self.qProcessInfo_returns_running_process() |
| 39 | |
| 40 | @llgs_test |
| 41 | @dwarf_test |
| 42 | def test_qProcessInfo_returns_running_process_llgs_dwarf(self): |
| 43 | self.init_llgs_test() |
| 44 | self.buildDwarf() |
| 45 | self.qProcessInfo_returns_running_process() |
| 46 | |
| 47 | def attach_commandline_qProcessInfo_reports_correct_pid(self): |
| 48 | procs = self.prep_debug_monitor_and_inferior() |
| 49 | self.assertIsNotNone(procs) |
| 50 | self.add_process_info_collection_packets() |
| 51 | |
| 52 | # Run the stream |
| 53 | context = self.expect_gdbremote_sequence() |
| 54 | self.assertIsNotNone(context) |
| 55 | |
| 56 | # Gather process info response |
| 57 | process_info = self.parse_process_info_response(context) |
| 58 | self.assertIsNotNone(process_info) |
| 59 | |
| 60 | # Ensure the process id matches what we expected. |
| 61 | pid_text = process_info.get('pid', None) |
| 62 | self.assertIsNotNone(pid_text) |
| 63 | reported_pid = int(pid_text, base=16) |
| 64 | self.assertEqual(reported_pid, procs["inferior"].pid) |
| 65 | |
| 66 | @debugserver_test |
| 67 | @dsym_test |
| 68 | def test_attach_commandline_qProcessInfo_reports_correct_pid_debugserver_dsym(self): |
| 69 | self.init_debugserver_test() |
| 70 | self.buildDsym() |
| 71 | self.set_inferior_startup_attach() |
| 72 | self.attach_commandline_qProcessInfo_reports_correct_pid() |
| 73 | |
| 74 | @llgs_test |
| 75 | @dwarf_test |
| 76 | def test_attach_commandline_qProcessInfo_reports_correct_pid_llgs_dwarf(self): |
| 77 | self.init_llgs_test() |
| 78 | self.buildDwarf() |
| 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 | @dsym_test |
| 101 | def test_qProcessInfo_reports_valid_endian_debugserver_dsym(self): |
| 102 | self.init_debugserver_test() |
| 103 | self.buildDsym() |
| 104 | self.qProcessInfo_reports_valid_endian() |
| 105 | |
| 106 | @llgs_test |
| 107 | @dwarf_test |
| 108 | def test_qProcessInfo_reports_valid_endian_llgs_dwarf(self): |
| 109 | self.init_llgs_test() |
| 110 | self.buildDwarf() |
| 111 | self.qProcessInfo_reports_valid_endian() |
| 112 | |
Todd Fiala | c540dd0 | 2014-08-26 18:21:02 +0000 | [diff] [blame] | 113 | def qProcessInfo_contains_keys(self, expected_key_set): |
| 114 | procs = self.prep_debug_monitor_and_inferior() |
| 115 | self.add_process_info_collection_packets() |
| 116 | |
| 117 | # Run the stream |
| 118 | context = self.expect_gdbremote_sequence() |
| 119 | self.assertIsNotNone(context) |
| 120 | |
| 121 | # Gather process info response |
| 122 | process_info = self.parse_process_info_response(context) |
| 123 | self.assertIsNotNone(process_info) |
| 124 | |
| 125 | # Ensure the expected keys are present and non-None within the process info. |
| 126 | missing_key_set = set() |
| 127 | for expected_key in expected_key_set: |
| 128 | if expected_key not in process_info: |
| 129 | missing_key_set.add(expected_key) |
| 130 | |
| 131 | self.assertEquals(missing_key_set, set(), "the listed keys are missing in the qProcessInfo result") |
| 132 | |
Todd Fiala | 6c9053e | 2014-08-26 18:40:56 +0000 | [diff] [blame] | 133 | def qProcessInfo_does_not_contain_keys(self, absent_key_set): |
| 134 | procs = self.prep_debug_monitor_and_inferior() |
| 135 | self.add_process_info_collection_packets() |
| 136 | |
| 137 | # Run the stream |
| 138 | context = self.expect_gdbremote_sequence() |
| 139 | self.assertIsNotNone(context) |
| 140 | |
| 141 | # Gather process info response |
| 142 | process_info = self.parse_process_info_response(context) |
| 143 | self.assertIsNotNone(process_info) |
| 144 | |
| 145 | # Ensure the unexpected keys are not present |
| 146 | unexpected_key_set = set() |
| 147 | for unexpected_key in absent_key_set: |
| 148 | if unexpected_key in process_info: |
| 149 | unexpected_key_set.add(unexpected_key) |
| 150 | |
| 151 | self.assertEquals(unexpected_key_set, set(), "the listed keys were present but unexpected in qProcessInfo result") |
| 152 | |
Robert Flack | 13c7ad9 | 2015-03-30 14:12:17 +0000 | [diff] [blame] | 153 | @skipUnlessDarwin |
Todd Fiala | c540dd0 | 2014-08-26 18:21:02 +0000 | [diff] [blame] | 154 | @debugserver_test |
| 155 | @dsym_test |
| 156 | def test_qProcessInfo_contains_cputype_cpusubtype_debugserver_darwin(self): |
| 157 | self.init_debugserver_test() |
| 158 | self.buildDsym() |
| 159 | self.qProcessInfo_contains_keys(set(['cputype', 'cpusubtype'])) |
| 160 | |
Robert Flack | 13c7ad9 | 2015-03-30 14:12:17 +0000 | [diff] [blame] | 161 | @skipUnlessPlatform(["linux"]) |
Todd Fiala | c540dd0 | 2014-08-26 18:21:02 +0000 | [diff] [blame] | 162 | @llgs_test |
| 163 | @dwarf_test |
| 164 | def test_qProcessInfo_contains_triple_llgs_linux(self): |
| 165 | self.init_llgs_test() |
| 166 | self.buildDwarf() |
| 167 | self.qProcessInfo_contains_keys(set(['triple'])) |
| 168 | |
Robert Flack | 13c7ad9 | 2015-03-30 14:12:17 +0000 | [diff] [blame] | 169 | @skipUnlessDarwin |
Todd Fiala | 6c9053e | 2014-08-26 18:40:56 +0000 | [diff] [blame] | 170 | @debugserver_test |
| 171 | @dsym_test |
| 172 | def test_qProcessInfo_does_not_contain_triple_debugserver_darwin(self): |
| 173 | self.init_debugserver_test() |
| 174 | self.buildDsym() |
| 175 | # We don't expect to see triple on darwin. If we do, we'll prefer triple |
| 176 | # to cputype/cpusubtype and skip some darwin-based ProcessGDBRemote ArchSpec setup |
| 177 | # for the remote Host and Process. |
| 178 | self.qProcessInfo_does_not_contain_keys(set(['triple'])) |
| 179 | |
Robert Flack | 13c7ad9 | 2015-03-30 14:12:17 +0000 | [diff] [blame] | 180 | @skipUnlessPlatform(["linux"]) |
Todd Fiala | 6c9053e | 2014-08-26 18:40:56 +0000 | [diff] [blame] | 181 | @llgs_test |
| 182 | @dwarf_test |
| 183 | def test_qProcessInfo_does_not_contain_cputype_cpusubtype_llgs_linux(self): |
| 184 | self.init_llgs_test() |
| 185 | self.buildDwarf() |
| 186 | self.qProcessInfo_does_not_contain_keys(set(['cputype', 'cpusubtype'])) |
| 187 | |
Todd Fiala | f76a891 | 2014-08-26 17:19:10 +0000 | [diff] [blame] | 188 | |
| 189 | if __name__ == '__main__': |
| 190 | unittest2.main() |