|
4 | 4 |
|
5 | 5 | import dap_server
|
6 | 6 | import lldbdap_testcase
|
| 7 | +import psutil |
| 8 | +from collections import deque |
7 | 9 | from lldbsuite.test import lldbutil
|
8 | 10 | from lldbsuite.test.decorators import *
|
9 | 11 | from lldbsuite.test.lldbtest import *
|
10 | 12 |
|
| 13 | +def get_subprocess(process_name): |
| 14 | + queue = deque([psutil.Process(os.getpid())]) |
| 15 | + while queue: |
| 16 | + process = queue.popleft() |
| 17 | + if process.name() == process_name: |
| 18 | + return process |
| 19 | + queue.extend(process.children()) |
| 20 | + |
| 21 | + self.assertTrue(False, "No subprocess with name %s found" % process_name) |
11 | 22 |
|
12 | 23 | class TestDAP_console(lldbdap_testcase.DAPTestCaseBase):
|
13 | 24 | def check_lldb_command(
|
@@ -104,3 +115,49 @@ def test_empty_escape_prefix(self):
|
104 | 115 | "Help can be invoked",
|
105 | 116 | command_escape_prefix="",
|
106 | 117 | )
|
| 118 | + |
| 119 | + @skipIfWindows |
| 120 | + @skipIfRemote |
| 121 | + def test_exit_status_message_sigterm(self): |
| 122 | + source = "main.cpp" |
| 123 | + program = self.getBuildArtifact("a.out") |
| 124 | + self.build_and_launch(program, commandEscapePrefix="") |
| 125 | + breakpoint1_line = line_number(source, "// breakpoint 1") |
| 126 | + breakpoint_ids = self.set_source_breakpoints(source, [breakpoint1_line]) |
| 127 | + self.continue_to_breakpoints(breakpoint_ids) |
| 128 | + |
| 129 | + # Kill lldb-server process. |
| 130 | + process_name = ( |
| 131 | + "debugserver" if platform.platform() == "MacOS" else "lldb-server" |
| 132 | + ) |
| 133 | + process = get_subprocess(process_name) |
| 134 | + process.terminate() |
| 135 | + process.wait(timeout=5) |
| 136 | + |
| 137 | + # Get the console output |
| 138 | + console_output = self.collect_console(1.0) |
| 139 | + |
| 140 | + # Verify the exit status message is printed. |
| 141 | + self.assertIn( |
| 142 | + "exited with status = -1 (0xffffffff) debugserver died with signal SIGTERM", |
| 143 | + console_output, |
| 144 | + "Exit status does not contain message 'exited with status'", |
| 145 | + ) |
| 146 | + |
| 147 | + @skipIfWindows |
| 148 | + @skipIfRemote |
| 149 | + def test_exit_status_message_ok(self): |
| 150 | + source = "main.cpp" |
| 151 | + program = self.getBuildArtifact("a.out") |
| 152 | + self.build_and_launch(program, commandEscapePrefix="") |
| 153 | + self.continue_to_exit() |
| 154 | + |
| 155 | + # Get the console output |
| 156 | + console_output = self.collect_console(1.0) |
| 157 | + |
| 158 | + # Verify the exit status message is printed. |
| 159 | + self.assertIn( |
| 160 | + "exited with status = 0 (0x00000000)", |
| 161 | + console_output, |
| 162 | + "Exit status does not contain message 'exited with status'", |
| 163 | + ) |
0 commit comments