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 | |
| 10 | def qProcessInfo_returns_running_process(self): |
| 11 | procs = self.prep_debug_monitor_and_inferior() |
| 12 | self.add_process_info_collection_packets() |
| 13 | |
| 14 | # Run the stream |
| 15 | context = self.expect_gdbremote_sequence() |
| 16 | self.assertIsNotNone(context) |
| 17 | |
| 18 | # Gather process info response |
| 19 | process_info = self.parse_process_info_response(context) |
| 20 | self.assertIsNotNone(process_info) |
| 21 | |
| 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) |
| 27 | |
| 28 | # If possible, verify that the process is running. |
| 29 | self.assertTrue(lldbgdbserverutils.process_is_running(pid, True)) |
| 30 | |
| 31 | @debugserver_test |
| 32 | @dsym_test |
| 33 | def test_qProcessInfo_returns_running_process_debugserver_dsym(self): |
| 34 | self.init_debugserver_test() |
| 35 | self.buildDsym() |
| 36 | self.qProcessInfo_returns_running_process() |
| 37 | |
| 38 | @llgs_test |
| 39 | @dwarf_test |
| 40 | def test_qProcessInfo_returns_running_process_llgs_dwarf(self): |
| 41 | self.init_llgs_test() |
| 42 | self.buildDwarf() |
| 43 | self.qProcessInfo_returns_running_process() |
| 44 | |
| 45 | def attach_commandline_qProcessInfo_reports_correct_pid(self): |
| 46 | procs = self.prep_debug_monitor_and_inferior() |
| 47 | self.assertIsNotNone(procs) |
| 48 | self.add_process_info_collection_packets() |
| 49 | |
| 50 | # Run the stream |
| 51 | context = self.expect_gdbremote_sequence() |
| 52 | self.assertIsNotNone(context) |
| 53 | |
| 54 | # Gather process info response |
| 55 | process_info = self.parse_process_info_response(context) |
| 56 | self.assertIsNotNone(process_info) |
| 57 | |
| 58 | # Ensure the process id matches what we expected. |
| 59 | pid_text = process_info.get('pid', None) |
| 60 | self.assertIsNotNone(pid_text) |
| 61 | reported_pid = int(pid_text, base=16) |
| 62 | self.assertEqual(reported_pid, procs["inferior"].pid) |
| 63 | |
| 64 | @debugserver_test |
| 65 | @dsym_test |
| 66 | def test_attach_commandline_qProcessInfo_reports_correct_pid_debugserver_dsym(self): |
| 67 | self.init_debugserver_test() |
| 68 | self.buildDsym() |
| 69 | self.set_inferior_startup_attach() |
| 70 | self.attach_commandline_qProcessInfo_reports_correct_pid() |
| 71 | |
| 72 | @llgs_test |
| 73 | @dwarf_test |
| 74 | def test_attach_commandline_qProcessInfo_reports_correct_pid_llgs_dwarf(self): |
| 75 | self.init_llgs_test() |
| 76 | self.buildDwarf() |
| 77 | self.set_inferior_startup_attach() |
| 78 | self.attach_commandline_qProcessInfo_reports_correct_pid() |
| 79 | |
| 80 | def qProcessInfo_reports_valid_endian(self): |
| 81 | procs = self.prep_debug_monitor_and_inferior() |
| 82 | self.add_process_info_collection_packets() |
| 83 | |
| 84 | # Run the stream |
| 85 | context = self.expect_gdbremote_sequence() |
| 86 | self.assertIsNotNone(context) |
| 87 | |
| 88 | # Gather process info response |
| 89 | process_info = self.parse_process_info_response(context) |
| 90 | self.assertIsNotNone(process_info) |
| 91 | |
| 92 | # Ensure the process id looks reasonable. |
| 93 | endian = process_info.get("endian") |
| 94 | self.assertIsNotNone(endian) |
| 95 | self.assertTrue(endian in ["little", "big", "pdp"]) |
| 96 | |
| 97 | @debugserver_test |
| 98 | @dsym_test |
| 99 | def test_qProcessInfo_reports_valid_endian_debugserver_dsym(self): |
| 100 | self.init_debugserver_test() |
| 101 | self.buildDsym() |
| 102 | self.qProcessInfo_reports_valid_endian() |
| 103 | |
| 104 | @llgs_test |
| 105 | @dwarf_test |
| 106 | def test_qProcessInfo_reports_valid_endian_llgs_dwarf(self): |
| 107 | self.init_llgs_test() |
| 108 | self.buildDwarf() |
| 109 | self.qProcessInfo_reports_valid_endian() |
| 110 | |
Todd Fiala | c540dd0 | 2014-08-26 18:21:02 +0000 | [diff] [blame] | 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.assertEquals(missing_key_set, set(), "the listed keys are missing in the qProcessInfo result") |
| 130 | |
Todd Fiala | 6c9053e | 2014-08-26 18:40:56 +0000 | [diff] [blame] | 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.assertEquals(unexpected_key_set, set(), "the listed keys were present but unexpected in qProcessInfo result") |
| 150 | |
Robert Flack | 13c7ad9 | 2015-03-30 14:12:17 +0000 | [diff] [blame^] | 151 | @skipUnlessDarwin |
Todd Fiala | c540dd0 | 2014-08-26 18:21:02 +0000 | [diff] [blame] | 152 | @debugserver_test |
| 153 | @dsym_test |
| 154 | def test_qProcessInfo_contains_cputype_cpusubtype_debugserver_darwin(self): |
| 155 | self.init_debugserver_test() |
| 156 | self.buildDsym() |
| 157 | self.qProcessInfo_contains_keys(set(['cputype', 'cpusubtype'])) |
| 158 | |
Robert Flack | 13c7ad9 | 2015-03-30 14:12:17 +0000 | [diff] [blame^] | 159 | @skipUnlessPlatform(["linux"]) |
Todd Fiala | c540dd0 | 2014-08-26 18:21:02 +0000 | [diff] [blame] | 160 | @llgs_test |
| 161 | @dwarf_test |
| 162 | def test_qProcessInfo_contains_triple_llgs_linux(self): |
| 163 | self.init_llgs_test() |
| 164 | self.buildDwarf() |
| 165 | self.qProcessInfo_contains_keys(set(['triple'])) |
| 166 | |
Robert Flack | 13c7ad9 | 2015-03-30 14:12:17 +0000 | [diff] [blame^] | 167 | @skipUnlessDarwin |
Todd Fiala | 6c9053e | 2014-08-26 18:40:56 +0000 | [diff] [blame] | 168 | @debugserver_test |
| 169 | @dsym_test |
| 170 | def test_qProcessInfo_does_not_contain_triple_debugserver_darwin(self): |
| 171 | self.init_debugserver_test() |
| 172 | self.buildDsym() |
| 173 | # We don't expect to see triple on darwin. If we do, we'll prefer triple |
| 174 | # to cputype/cpusubtype and skip some darwin-based ProcessGDBRemote ArchSpec setup |
| 175 | # for the remote Host and Process. |
| 176 | self.qProcessInfo_does_not_contain_keys(set(['triple'])) |
| 177 | |
Robert Flack | 13c7ad9 | 2015-03-30 14:12:17 +0000 | [diff] [blame^] | 178 | @skipUnlessPlatform(["linux"]) |
Todd Fiala | 6c9053e | 2014-08-26 18:40:56 +0000 | [diff] [blame] | 179 | @llgs_test |
| 180 | @dwarf_test |
| 181 | def test_qProcessInfo_does_not_contain_cputype_cpusubtype_llgs_linux(self): |
| 182 | self.init_llgs_test() |
| 183 | self.buildDwarf() |
| 184 | self.qProcessInfo_does_not_contain_keys(set(['cputype', 'cpusubtype'])) |
| 185 | |
Todd Fiala | f76a891 | 2014-08-26 17:19:10 +0000 | [diff] [blame] | 186 | |
| 187 | if __name__ == '__main__': |
| 188 | unittest2.main() |