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
11 class PtyServerTestCase(gdbremote_testcase
.GdbRemoteTestCaseBase
):
17 primary
, secondary
= pty
.openpty()
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
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
41 def __init__(self
, fd
):
44 def sendall(self
, 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
)
54 @add_test_categories(["llgs"])
55 def test_pty_server(self
):
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",
67 "regex": re
.compile("^\$l(.+)#[0-9a-fA-F]{2}$", flags
=re
.DOTALL
),
68 "capture": {1: "target_xml"},
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")))