Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / lldb / test / API / tools / lldb-server / TestPtyServer.py
blobaa5bd635650ac8fdc4ecc5112b97173746062556
1 import gdbremote_testcase
2 import lldbgdbserverutils
3 from lldbsuite.test.decorators import *
4 from lldbsuite.test.lldbtest import *
5 from lldbgdbserverutils import *
7 import xml.etree.ElementTree as ET
10 @skipIfWindows
11 class PtyServerTestCase(gdbremote_testcase.GdbRemoteTestCaseBase):
12 def setUp(self):
13 super().setUp()
14 import pty
15 import tty
17 primary, secondary = pty.openpty()
18 tty.setraw(primary)
19 self._primary = io.FileIO(primary, "r+b")
20 self._secondary = io.FileIO(secondary, "r+b")
22 def get_debug_monitor_command_line_args(self, attach_pid=None):
23 commandline_args = self.debug_monitor_extra_args
24 if attach_pid:
25 commandline_args += ["--attach=%d" % attach_pid]
27 libc = ctypes.CDLL(None)
28 libc.ptsname.argtypes = (ctypes.c_int,)
29 libc.ptsname.restype = ctypes.c_char_p
30 pty_path = libc.ptsname(self._primary.fileno()).decode()
31 commandline_args += ["serial://%s" % (pty_path,)]
32 return commandline_args
34 def connect_to_debug_monitor(self, attach_pid=None):
35 self.reverse_connect = False
36 server = self.launch_debug_monitor(attach_pid=attach_pid)
37 self.assertIsNotNone(server)
39 # TODO: make it into proper abstraction
40 class FakeSocket:
41 def __init__(self, fd):
42 self.fd = fd
44 def sendall(self, frame):
45 self.fd.write(frame)
47 def recv(self, count):
48 return self.fd.read(count)
50 self.sock = FakeSocket(self._primary)
51 self._server = Server(self.sock, server)
52 return server
54 @add_test_categories(["llgs"])
55 def test_pty_server(self):
56 self.build()
57 self.set_inferior_startup_launch()
58 self.prep_debug_monitor_and_inferior()
60 # target.xml transfer should trigger a large enough packet to check
61 # for partial write regression
62 self.test_sequence.add_log_lines(
64 "read packet: $qXfer:features:read:target.xml:0,200000#00",
66 "direction": "send",
67 "regex": re.compile("^\$l(.+)#[0-9a-fA-F]{2}$", flags=re.DOTALL),
68 "capture": {1: "target_xml"},
71 True,
73 context = self.expect_gdbremote_sequence()
74 # verify that we have received a complete, non-malformed XML
75 self.assertIsNotNone(ET.fromstring(context.get("target_xml")))