File: TestDAP_disconnect.py

package info (click to toggle)
llvm-toolchain-19 1%3A19.1.7-3
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 1,998,520 kB
  • sloc: cpp: 6,951,680; ansic: 1,486,157; asm: 913,598; python: 232,024; f90: 80,126; objc: 75,281; lisp: 37,276; pascal: 16,990; sh: 10,009; ml: 5,058; perl: 4,724; awk: 3,523; makefile: 3,167; javascript: 2,504; xml: 892; fortran: 664; cs: 573
file content (79 lines) | stat: -rw-r--r-- 2,819 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
"""
Test lldb-dap disconnect request
"""


import dap_server
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil
import lldbdap_testcase
import subprocess
import time
import os


class TestDAP_launch(lldbdap_testcase.DAPTestCaseBase):
    source = "main.cpp"

    def disconnect_and_assert_no_output_printed(self):
        self.dap_server.request_disconnect()
        # verify we didn't get any input after disconnect
        time.sleep(2)
        output = self.get_stdout()
        self.assertTrue(output is None or len(output) == 0)

    @skipIfWindows
    def test_launch(self):
        """
        This test launches a process that would creates a file, but we disconnect
        before the file is created, which terminates the process and thus the file is not
        created.
        """
        program = self.getBuildArtifact("a.out")
        self.build_and_launch(program, disconnectAutomatically=False)

        # We set a breakpoint right before the side effect file is created
        self.set_source_breakpoints(
            self.source, [line_number(self.source, "// breakpoint")]
        )
        self.continue_to_next_stop()

        self.dap_server.request_disconnect()
        # verify we didn't produce the side effect file
        time.sleep(1)
        self.assertFalse(os.path.exists(program + ".side_effect"))

    @skipIfWindows
    @expectedFailureNetBSD
    def test_attach(self):
        """
        This test attaches to a process that creates a file. We attach and disconnect
        before the file is created, and as the process is not terminated upon disconnection,
        the file is created anyway.
        """
        self.build_and_create_debug_adaptor()
        program = self.getBuildArtifact("a.out")

        # Use a file as a synchronization point between test and inferior.
        sync_file_path = lldbutil.append_to_process_working_directory(
            self, "sync_file_%d" % (int(time.time()))
        )
        self.addTearDownHook(
            lambda: self.run_platform_command("rm %s" % (sync_file_path))
        )

        self.process = subprocess.Popen([program, sync_file_path])
        lldbutil.wait_for_file_on_target(self, sync_file_path)

        self.attach(pid=self.process.pid, disconnectAutomatically=False)
        response = self.dap_server.request_evaluate("wait_for_attach = false;")
        self.assertTrue(response["success"])

        # verify we haven't produced the side effect file yet
        self.assertFalse(os.path.exists(program + ".side_effect"))

        self.dap_server.request_disconnect()
        time.sleep(2)
        # verify we produced the side effect file, as the program continued after disconnecting
        self.assertTrue(os.path.exists(program + ".side_effect"))