Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / lldb / test / API / tools / lldb-server / TestGdbRemoteLaunch.py
blob799eb9d867cd574b9c554f052944ff7d5f9847cb
1 import itertools
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):
14 self.build()
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)
21 self.do_handshake()
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",
29 "read packet: $c#00",
30 "send packet: $W00#00",
32 True,
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):
40 self.build()
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)
47 self.do_handshake()
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]+)"},
52 "read packet: $c#00",
53 "send packet: $W00#00",
55 True,
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):
62 self.build()
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)
68 self.do_handshake()
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]+)"},
73 "read packet: $c#00",
74 "send packet: $W00#00",
76 True,
78 self.expect_gdbremote_sequence()
80 @add_test_categories(["llgs"])
81 def test_launch_failure_via_vRun(self):
82 self.build()
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)
88 self.do_handshake()
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,
95 "direction": "send",
96 "regex": r"^\$E..;([0-9a-fA-F]+)#",
97 "capture": {1: "msg"},
100 True,
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):
112 self.build()
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)
120 self.do_handshake()
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",
128 True,
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",
137 True,
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):
145 self.build()
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)
153 self.do_handshake()
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",
162 True,
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",
171 True,
173 context = self.expect_gdbremote_sequence()
174 self.assertEqual(context["O_content"], b"test\r\na=z\r\na*}#z\r\n")