|
4 | 4 |
|
5 | 5 | import dap_server
|
6 | 6 | import lldbdap_testcase
|
| 7 | +import psutil |
7 | 8 | from lldbsuite.test import lldbutil
|
8 | 9 | from lldbsuite.test.decorators import *
|
9 | 10 | from lldbsuite.test.lldbtest import *
|
10 | 11 |
|
| 12 | +def get_latest_pid(process_name): |
| 13 | + processes = [] |
| 14 | + for proc in psutil.process_iter(): |
| 15 | + try: |
| 16 | + if proc.name() == process_name: |
| 17 | + processes += [proc] |
| 18 | + except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess): |
| 19 | + pass |
| 20 | + if len(processes) == 0: |
| 21 | + print("No lldb-server process found", flush=True, file=sys.stderr) |
| 22 | + return None |
| 23 | + |
| 24 | + processes = sorted(processes, key=lambda x:x.create_time()) |
| 25 | + return processes[-1].pid |
| 26 | + |
| 27 | +def killProcess(pid, process_name): |
| 28 | + process = psutil.Process(pid) |
| 29 | + process.terminate() |
| 30 | + try: |
| 31 | + process.wait(timeout=5) |
| 32 | + except psutil.TimeoutExpired: |
| 33 | + self.assertTrue(False, process_name + " process should have exited by now") |
11 | 34 |
|
12 | 35 | class TestDAP_console(lldbdap_testcase.DAPTestCaseBase):
|
13 | 36 | def check_lldb_command(
|
@@ -104,3 +127,27 @@ def test_empty_escape_prefix(self):
|
104 | 127 | "Help can be invoked",
|
105 | 128 | command_escape_prefix="",
|
106 | 129 | )
|
| 130 | + |
| 131 | + @skipIfWindows |
| 132 | + @skipIfRemote |
| 133 | + def test_exit_status_message(self): |
| 134 | + source = "main.cpp" |
| 135 | + program = self.getBuildArtifact("a.out") |
| 136 | + self.build_and_launch(program, commandEscapePrefix="") |
| 137 | + breakpoint1_line = line_number(source, "// breakpoint 1") |
| 138 | + breakpoint_ids = self.set_source_breakpoints(source, [breakpoint1_line]) |
| 139 | + self.continue_to_breakpoints(breakpoint_ids) |
| 140 | + |
| 141 | + # Kill lldb-server process. |
| 142 | + process_name = "lldb-server" |
| 143 | + pid = get_latest_pid(process_name) |
| 144 | + killProcess(pid, process_name) |
| 145 | + # Get the console output |
| 146 | + console_output = self.collect_console(1.0) |
| 147 | + |
| 148 | + # Verify the exit status message is printed. |
| 149 | + self.assertIn( |
| 150 | + "exited with status = -1 (0xffffffff) debugserver died with signal SIGTERM", |
| 151 | + console_output, |
| 152 | + "Exit status does not contain message 'exited with status'" |
| 153 | + ) |
0 commit comments