|
| 1 | +""" |
| 2 | +Test lldb-dap IO handling. |
| 3 | +""" |
| 4 | + |
| 5 | +from lldbsuite.test.decorators import * |
| 6 | +import lldbdap_testcase |
| 7 | +import dap_server |
| 8 | + |
| 9 | + |
| 10 | +class TestDAP_io(lldbdap_testcase.DAPTestCaseBase): |
| 11 | + def launch(self): |
| 12 | + log_file_path = self.getBuildArtifact("dap.txt") |
| 13 | + process, _ = dap_server.DebugAdapterServer.launch( |
| 14 | + executable=self.lldbDAPExec, log_file=log_file_path |
| 15 | + ) |
| 16 | + |
| 17 | + def cleanup(): |
| 18 | + # If the process is still alive, terminate it. |
| 19 | + if process.poll() is None: |
| 20 | + process.terminate() |
| 21 | + stdout_data = process.stdout.read() |
| 22 | + stderr_data = process.stderr.read() |
| 23 | + print("========= STDOUT =========") |
| 24 | + print(stdout_data) |
| 25 | + print("========= END =========") |
| 26 | + print("========= STDERR =========") |
| 27 | + print(stderr_data) |
| 28 | + print("========= END =========") |
| 29 | + print("========= DEBUG ADAPTER PROTOCOL LOGS =========") |
| 30 | + with open(log_file_path, "r") as file: |
| 31 | + print(file.read()) |
| 32 | + print("========= END =========") |
| 33 | + |
| 34 | + # Execute the cleanup function during test case tear down. |
| 35 | + self.addTearDownHook(cleanup) |
| 36 | + |
| 37 | + return process |
| 38 | + |
| 39 | + def test_eof_immediately(self): |
| 40 | + """ |
| 41 | + lldb-dap handles EOF without any other input. |
| 42 | + """ |
| 43 | + process = self.launch() |
| 44 | + process.stdin.close() |
| 45 | + self.assertEqual(process.wait(timeout=5.0), 0) |
| 46 | + |
| 47 | + def test_partial_header(self): |
| 48 | + """ |
| 49 | + lldb-dap handles parital message headers. |
| 50 | + """ |
| 51 | + process = self.launch() |
| 52 | + process.stdin.write(b"Content-Length: ") |
| 53 | + process.stdin.close() |
| 54 | + self.assertEqual(process.wait(timeout=5.0), 0) |
| 55 | + |
| 56 | + def test_incorrect_content_length(self): |
| 57 | + """ |
| 58 | + lldb-dap handles malformed content length headers. |
| 59 | + """ |
| 60 | + process = self.launch() |
| 61 | + process.stdin.write(b"Content-Length: abc") |
| 62 | + process.stdin.close() |
| 63 | + self.assertEqual(process.wait(timeout=5.0), 0) |
| 64 | + |
| 65 | + def test_partial_content_length(self): |
| 66 | + """ |
| 67 | + lldb-dap handles partial messages. |
| 68 | + """ |
| 69 | + process = self.launch() |
| 70 | + process.stdin.write(b"Content-Length: 10{") |
| 71 | + process.stdin.close() |
| 72 | + self.assertEqual(process.wait(timeout=5.0), 0) |
0 commit comments