3 import gdbremote_testcase
4 import lldbgdbserverutils
5 from lldbsuite
.support
import seven
6 from lldbsuite
.test
.decorators
import *
7 from lldbsuite
.test
.lldbtest
import *
10 class GdbRemoteLaunchTestCase(gdbremote_testcase
.GdbRemoteTestCaseBase
):
11 @skipIfWindows # No pty support to test any inferior output
12 @add_test_categories(["llgs"])
13 def test_launch_via_A(self
):
15 exe_path
= self
.getBuildArtifact("a.out")
16 args
= [exe_path
, "stderr:arg1", "stderr:arg2", "stderr:arg3"]
17 hex_args
= [seven
.hexlify(x
) for x
in args
]
19 server
= self
.connect_to_debug_monitor()
20 self
.assertIsNotNone(server
)
22 # NB: strictly speaking we should use %x here but this packet
23 # is deprecated, so no point in changing lldb-server's expectations
24 self
.test_sequence
.add_log_lines(
26 "read packet: $A %d,0,%s,%d,1,%s,%d,2,%s,%d,3,%s#00"
27 % tuple(itertools
.chain
.from_iterable([(len(x
), x
) for x
in hex_args
])),
28 "send packet: $OK#00",
30 "send packet: $W00#00",
34 context
= self
.expect_gdbremote_sequence()
35 self
.assertEqual(context
["O_content"], b
"arg1\r\narg2\r\narg3\r\n")
37 @skipIfWindows # No pty support to test any inferior output
38 @add_test_categories(["llgs"])
39 def test_launch_via_vRun(self
):
41 exe_path
= self
.getBuildArtifact("a.out")
42 args
= [exe_path
, "stderr:arg1", "stderr:arg2", "stderr:arg3"]
43 hex_args
= [seven
.hexlify(x
) for x
in args
]
45 server
= self
.connect_to_debug_monitor()
46 self
.assertIsNotNone(server
)
48 self
.test_sequence
.add_log_lines(
50 "read packet: $vRun;%s;%s;%s;%s#00" % tuple(hex_args
),
51 {"direction": "send", "regex": r
"^\$T([0-9a-fA-F]+)"},
53 "send packet: $W00#00",
57 context
= self
.expect_gdbremote_sequence()
58 self
.assertEqual(context
["O_content"], b
"arg1\r\narg2\r\narg3\r\n")
60 @add_test_categories(["llgs"])
61 def test_launch_via_vRun_no_args(self
):
63 exe_path
= self
.getBuildArtifact("a.out")
64 hex_path
= seven
.hexlify(exe_path
)
66 server
= self
.connect_to_debug_monitor()
67 self
.assertIsNotNone(server
)
69 self
.test_sequence
.add_log_lines(
71 "read packet: $vRun;%s#00" % (hex_path
,),
72 {"direction": "send", "regex": r
"^\$T([0-9a-fA-F]+)"},
74 "send packet: $W00#00",
78 self
.expect_gdbremote_sequence()
80 @add_test_categories(["llgs"])
81 def test_launch_failure_via_vRun(self
):
83 exe_path
= self
.getBuildArtifact("a.out")
84 hex_path
= seven
.hexlify(exe_path
)
86 server
= self
.connect_to_debug_monitor()
87 self
.assertIsNotNone(server
)
89 self
.test_sequence
.add_log_lines(
91 "read packet: $QEnableErrorStrings#00",
92 "send packet: $OK#00",
93 "read packet: $vRun;%s#00" % hex_path
,
96 "regex": r
"^\$E..;([0-9a-fA-F]+)#",
97 "capture": {1: "msg"},
102 with
open(exe_path
, "ab") as exe_for_writing
:
103 context
= self
.expect_gdbremote_sequence()
104 self
.assertRegexpMatches(
105 seven
.unhexlify(context
.get("msg")),
106 r
"(execve failed: Text file busy|The process cannot access the file because it is being used by another process.)",
109 @skipIfWindows # No pty support to test any inferior output
110 @add_test_categories(["llgs"])
111 def test_QEnvironment(self
):
113 exe_path
= self
.getBuildArtifact("a.out")
114 env
= {"FOO": "test", "BAR": "a=z"}
115 args
= [exe_path
, "print-env:FOO", "print-env:BAR"]
116 hex_args
= [seven
.hexlify(x
) for x
in args
]
118 server
= self
.connect_to_debug_monitor()
119 self
.assertIsNotNone(server
)
122 for key
, value
in env
.items():
123 self
.test_sequence
.add_log_lines(
125 "read packet: $QEnvironment:%s=%s#00" % (key
, value
),
126 "send packet: $OK#00",
130 self
.test_sequence
.add_log_lines(
132 "read packet: $vRun;%s#00" % (";".join(hex_args
),),
133 {"direction": "send", "regex": r
"^\$T([0-9a-fA-F]+)"},
134 "read packet: $c#00",
135 "send packet: $W00#00",
139 context
= self
.expect_gdbremote_sequence()
140 self
.assertEqual(context
["O_content"], b
"test\r\na=z\r\n")
142 @skipIfWindows # No pty support to test any inferior output
143 @add_test_categories(["llgs"])
144 def test_QEnvironmentHexEncoded(self
):
146 exe_path
= self
.getBuildArtifact("a.out")
147 env
= {"FOO": "test", "BAR": "a=z", "BAZ": "a*}#z"}
148 args
= [exe_path
, "print-env:FOO", "print-env:BAR", "print-env:BAZ"]
149 hex_args
= [seven
.hexlify(x
) for x
in args
]
151 server
= self
.connect_to_debug_monitor()
152 self
.assertIsNotNone(server
)
155 for key
, value
in env
.items():
156 hex_enc
= seven
.hexlify("%s=%s" % (key
, value
))
157 self
.test_sequence
.add_log_lines(
159 "read packet: $QEnvironmentHexEncoded:%s#00" % (hex_enc
,),
160 "send packet: $OK#00",
164 self
.test_sequence
.add_log_lines(
166 "read packet: $vRun;%s#00" % (";".join(hex_args
),),
167 {"direction": "send", "regex": r
"^\$T([0-9a-fA-F]+)"},
168 "read packet: $c#00",
169 "send packet: $W00#00",
173 context
= self
.expect_gdbremote_sequence()
174 self
.assertEqual(context
["O_content"], b
"test\r\na=z\r\na*}#z\r\n")