brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.0 KiB · 9fbe9aa Raw
88 lines · python
1"""2Test lldb-dap IO handling.3"""4 5import sys6 7from lldbsuite.test.decorators import *8import lldbdap_testcase9import dap_server10 11EXIT_FAILURE = 112EXIT_SUCCESS = 013 14 15class TestDAP_io(lldbdap_testcase.DAPTestCaseBase):16    def launch(self):17        log_file_path = self.getBuildArtifact("dap.txt")18        process, _ = dap_server.DebugAdapterServer.launch(19            executable=self.lldbDAPExec, log_file=log_file_path20        )21 22        def cleanup():23            # If the process is still alive, terminate it.24            if process.poll() is None:25                process.terminate()26                process.wait()27            stdout_data = process.stdout.read().decode()28            print("========= STDOUT =========", file=sys.stderr)29            print(stdout_data, file=sys.stderr)30            print("========= END =========", file=sys.stderr)31            print("========= DEBUG ADAPTER PROTOCOL LOGS =========", file=sys.stderr)32            with open(log_file_path, "r") as file:33                print(file.read(), file=sys.stderr)34            print("========= END =========", file=sys.stderr)35 36        # Execute the cleanup function during test case tear down.37        self.addTearDownHook(cleanup)38 39        return process40 41    def test_eof_immediately(self):42        """43        lldb-dap handles EOF without any other input.44        """45        process = self.launch()46        process.stdin.close()47        self.assertEqual(process.wait(timeout=self.DEFAULT_TIMEOUT), EXIT_SUCCESS)48 49    def test_invalid_header(self):50        """51        lldb-dap returns a failure exit code when the input stream is closed52        with a malformed request header.53        """54        process = self.launch()55        process.stdin.write(b"not the correct message header")56        process.stdin.close()57        self.assertEqual(process.wait(timeout=self.DEFAULT_TIMEOUT), EXIT_FAILURE)58 59    def test_partial_header(self):60        """61        lldb-dap returns a failure exit code when the input stream is closed62        with an incomplete message header is in the message buffer.63        """64        process = self.launch()65        process.stdin.write(b"Content-Length: ")66        process.stdin.close()67        self.assertEqual(process.wait(timeout=self.DEFAULT_TIMEOUT), EXIT_FAILURE)68 69    def test_incorrect_content_length(self):70        """71        lldb-dap returns a failure exit code when reading malformed content72        length headers.73        """74        process = self.launch()75        process.stdin.write(b"Content-Length: abc")76        process.stdin.close()77        self.assertEqual(process.wait(timeout=self.DEFAULT_TIMEOUT), EXIT_FAILURE)78 79    def test_partial_content_length(self):80        """81        lldb-dap returns a failure exit code when the input stream is closed82        with a partial message in the message buffer.83        """84        process = self.launch()85        process.stdin.write(b"Content-Length: 10\r\n\r\n{")86        process.stdin.close()87        self.assertEqual(process.wait(timeout=self.DEFAULT_TIMEOUT), EXIT_FAILURE)88