forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[lldb-dap] Improving EOF handling on stream input and adding new unit…
… tests (llvm#129581) This should improve the handling of EOF on stdin and adding some new unit tests to malformed requests.
- Loading branch information
Showing
3 changed files
with
87 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
""" | ||
Test lldb-dap IO handling. | ||
""" | ||
|
||
from lldbsuite.test.decorators import * | ||
import lldbdap_testcase | ||
import dap_server | ||
|
||
|
||
class TestDAP_io(lldbdap_testcase.DAPTestCaseBase): | ||
def launch(self): | ||
log_file_path = self.getBuildArtifact("dap.txt") | ||
process, _ = dap_server.DebugAdapterServer.launch( | ||
executable=self.lldbDAPExec, log_file=log_file_path | ||
) | ||
|
||
def cleanup(): | ||
# If the process is still alive, terminate it. | ||
if process.poll() is None: | ||
process.terminate() | ||
stdout_data = process.stdout.read() | ||
stderr_data = process.stderr.read() | ||
print("========= STDOUT =========") | ||
print(stdout_data) | ||
print("========= END =========") | ||
print("========= STDERR =========") | ||
print(stderr_data) | ||
print("========= END =========") | ||
print("========= DEBUG ADAPTER PROTOCOL LOGS =========") | ||
with open(log_file_path, "r") as file: | ||
print(file.read()) | ||
print("========= END =========") | ||
|
||
# Execute the cleanup function during test case tear down. | ||
self.addTearDownHook(cleanup) | ||
|
||
return process | ||
|
||
def test_eof_immediately(self): | ||
""" | ||
lldb-dap handles EOF without any other input. | ||
""" | ||
process = self.launch() | ||
process.stdin.close() | ||
self.assertEqual(process.wait(timeout=5.0), 0) | ||
|
||
def test_partial_header(self): | ||
""" | ||
lldb-dap handles parital message headers. | ||
""" | ||
process = self.launch() | ||
process.stdin.write(b"Content-Length: ") | ||
process.stdin.close() | ||
self.assertEqual(process.wait(timeout=5.0), 0) | ||
|
||
def test_incorrect_content_length(self): | ||
""" | ||
lldb-dap handles malformed content length headers. | ||
""" | ||
process = self.launch() | ||
process.stdin.write(b"Content-Length: abc") | ||
process.stdin.close() | ||
self.assertEqual(process.wait(timeout=5.0), 0) | ||
|
||
def test_partial_content_length(self): | ||
""" | ||
lldb-dap handles partial messages. | ||
""" | ||
process = self.launch() | ||
process.stdin.write(b"Content-Length: 10{") | ||
process.stdin.close() | ||
self.assertEqual(process.wait(timeout=5.0), 0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters