brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.9 KiB · 19f88d8 Raw
83 lines · python
1"""2Test lldb-dap disconnect request3"""4 5 6from lldbsuite.test.decorators import *7from lldbsuite.test.lldbtest import *8from lldbsuite.test import lldbutil9import lldbdap_testcase10import time11import os12 13 14class TestDAP_disconnect(lldbdap_testcase.DAPTestCaseBase):15    source = "main.cpp"16 17    def disconnect_and_assert_no_output_printed(self):18        self.dap_server.request_disconnect()19        # verify we didn't get any input after disconnect20        time.sleep(2)21        output = self.get_stdout()22        self.assertTrue(output is None or len(output) == 0)23 24    @skipIfWindows25    def test_launch(self):26        """27        This test launches a process that would creates a file, but we disconnect28        before the file is created, which terminates the process and thus the file is not29        created.30        """31        program = self.getBuildArtifact("a.out")32        self.build_and_launch(program, stopOnEntry=True, disconnectAutomatically=False)33 34        # We set a breakpoint right before the side effect file is created35        self.set_source_breakpoints(36            self.source, [line_number(self.source, "// breakpoint")]37        )38        self.continue_to_next_stop()39 40        # verify we haven't produced the side effect file yet41        self.assertFalse(os.path.exists(program + ".side_effect"))42 43        self.dap_server.request_disconnect()44 45        # verify we didn't produce the side effect file46        time.sleep(1)47        self.assertFalse(os.path.exists(program + ".side_effect"))48 49    @skipIfWindows50    @expectedFailureNetBSD51    def test_attach(self):52        """53        This test attaches to a process that creates a file. We attach and disconnect54        before the file is created, and as the process is not terminated upon disconnection,55        the file is created anyway.56        """57        self.build_and_create_debug_adapter()58        program = self.getBuildArtifact("a.out")59 60        # Use a file as a synchronization point between test and inferior.61        sync_file_path = lldbutil.append_to_process_working_directory(62            self, "sync_file_%d" % (int(time.time()))63        )64        self.addTearDownHook(65            lambda: self.run_platform_command("rm %s" % (sync_file_path))66        )67 68        proc = self.spawnSubprocess(program, [sync_file_path])69        lldbutil.wait_for_file_on_target(self, sync_file_path)70 71        self.attach(pid=proc.pid, disconnectAutomatically=False, stopOnEntry=True)72        self.continue_to_next_stop()73        response = self.dap_server.request_evaluate("wait_for_attach = false;")74        self.assertTrue(response["success"])75 76        # verify we haven't produced the side effect file yet77        self.assertFalse(os.path.exists(program + ".side_effect"))78 79        self.dap_server.request_disconnect()80        time.sleep(2)81        # verify we produced the side effect file, as the program continued after disconnecting82        self.assertTrue(os.path.exists(program + ".side_effect"))83