2 Test lldb-vscode setBreakpoints request
5 from __future__ import print_function
10 from lldbsuite.test.decorators import *
11 from lldbsuite.test.lldbtest import *
12 from lldbsuite.test import lldbutil
13 import lldbvscode_testcase
18 class TestVSCode_launch(lldbvscode_testcase.VSCodeTestCaseBase):
20 mydir = TestBase.compute_mydir(__file__)
23 @skipIfDarwin # Skip this test for now until we can figure out why tings aren't working on build bots
24 @skipIfLinux # This test is timing out and/or failing on Linux as well as Darwin
26 def test_default(self):
28 Tests the default launch of a simple program. No arguments,
29 environment, or anything else is specified.
31 program = self.getBuildArtifact("a.out")
32 self.build_and_launch(program)
33 self.continue_to_exit()
34 # Now get the STDOUT and verify our program argument is correct
35 output = self.get_stdout()
36 self.assertTrue(output and len(output) > 0,
37 "expect program output")
38 lines = output.splitlines()
39 self.assertTrue(program in lines[0],
40 "make sure program path is in first argument")
43 @skipIfDarwin # Skip this test for now until we can figure out why tings aren't working on build bots
44 @skipIfLinux # This test is timing out and/or failing on Linux as well as Darwin
46 def test_stopOnEntry(self):
48 Tests the default launch of a simple program that stops at the
49 entry point instead of continuing.
51 program = self.getBuildArtifact("a.out")
52 self.build_and_launch(program, stopOnEntry=True)
53 self.set_function_breakpoints(['main'])
54 stopped_events = self.continue_to_next_stop()
55 for stopped_event in stopped_events:
56 if 'body' in stopped_event:
57 body = stopped_event['body']
59 reason = body['reason']
61 reason != 'breakpoint',
62 'verify stop isn\'t "main" breakpoint')
65 @skipIfDarwin # Skip this test for now until we can figure out why tings aren't working on build bots
66 @skipIfLinux # This test is timing out and/or failing on Linux as well as Darwin
70 Tests the default launch of a simple program with a current working
73 program = self.getBuildArtifact("a.out")
74 program_parent_dir = os.path.split(os.path.split(program)[0])[0]
75 self.build_and_launch(program,
76 cwd=program_parent_dir)
77 self.continue_to_exit()
78 # Now get the STDOUT and verify our program argument is correct
79 output = self.get_stdout()
80 self.assertTrue(output and len(output) > 0,
81 "expect program output")
82 lines = output.splitlines()
85 if line.startswith('cwd = \"'):
86 quote_path = '"%s"' % (program_parent_dir)
88 self.assertTrue(quote_path in line,
89 "working directory '%s' not in '%s'" % (
90 program_parent_dir, line))
91 self.assertTrue(found, "verified program working directory")
94 @skipIfDarwin # Skip this test for now until we can figure out why tings aren't working on build bots
95 @skipIfLinux # This test is timing out and/or failing on Linux as well as Darwin
97 def test_debuggerRoot(self):
99 Tests the "debuggerRoot" will change the working directory of
100 the lldb-vscode debug adaptor.
102 program = self.getBuildArtifact("a.out")
103 program_parent_dir = os.path.split(os.path.split(program)[0])[0]
104 commands = ['platform shell echo cwd = $PWD']
105 self.build_and_launch(program,
106 debuggerRoot=program_parent_dir,
107 initCommands=commands)
108 output = self.get_console()
109 self.assertTrue(output and len(output) > 0,
110 "expect console output")
111 lines = output.splitlines()
115 if line.startswith(prefix):
117 self.assertTrue(program_parent_dir == line[len(prefix):],
118 "lldb-vscode working dir '%s' == '%s'" % (
119 program_parent_dir, line[6:]))
120 self.assertTrue(found, "verified lldb-vscode working directory")
121 self.continue_to_exit()
124 @skipIfDarwin # Skip this test for now until we can figure out why tings aren't working on build bots
125 @skipIfLinux # This test is timing out and/or failing on Linux as well as Darwin
127 def test_sourcePath(self):
129 Tests the "sourcePath" will set the target.source-map.
131 program = self.getBuildArtifact("a.out")
132 program_dir = os.path.split(program)[0]
133 self.build_and_launch(program,
134 sourcePath=program_dir)
135 output = self.get_console()
136 self.assertTrue(output and len(output) > 0,
137 "expect console output")
138 lines = output.splitlines()
139 prefix = '(lldb) settings set target.source-map "." '
142 if line.startswith(prefix):
144 quoted_path = '"%s"' % (program_dir)
145 self.assertTrue(quoted_path == line[len(prefix):],
146 "lldb-vscode working dir %s == %s" % (
147 quoted_path, line[6:]))
148 self.assertTrue(found, 'found "sourcePath" in console output')
149 self.continue_to_exit()
152 @skipIfDarwin # Skip this test for now until we can figure out why tings aren't working on build bots
153 @skipIfLinux # This test is timing out and/or failing on Linux as well as Darwin
155 def test_disableSTDIO(self):
157 Tests the default launch of a simple program with STDIO disabled.
159 program = self.getBuildArtifact("a.out")
160 self.build_and_launch(program,
162 self.continue_to_exit()
163 # Now get the STDOUT and verify our program argument is correct
164 output = self.get_stdout()
165 self.assertTrue(output is None or len(output) == 0,
166 "expect no program output")
169 @skipIfDarwin # Skip this test for now until we can figure out why tings aren't working on build bots
170 @skipIfLinux # This test is timing out and/or failing on Linux as well as Darwin
172 def test_shellExpandArguments_enabled(self):
174 Tests the default launch of a simple program with shell expansion
177 program = self.getBuildArtifact("a.out")
178 program_dir = os.path.split(program)[0]
179 glob = os.path.join(program_dir, '*.out')
180 self.build_and_launch(program, args=[glob], shellExpandArguments=True)
181 self.continue_to_exit()
182 # Now get the STDOUT and verify our program argument is correct
183 output = self.get_stdout()
184 self.assertTrue(output and len(output) > 0,
185 "expect no program output")
186 lines = output.splitlines()
188 quote_path = '"%s"' % (program)
189 if line.startswith("arg[1] ="):
190 self.assertTrue(quote_path in line,
191 'verify "%s" expanded to "%s"' % (
195 @skipIfDarwin # Skip this test for now until we can figure out why tings aren't working on build bots
196 @skipIfLinux # This test is timing out and/or failing on Linux as well as Darwin
198 def test_shellExpandArguments_disabled(self):
200 Tests the default launch of a simple program with shell expansion
203 program = self.getBuildArtifact("a.out")
204 program_dir = os.path.split(program)[0]
205 glob = os.path.join(program_dir, '*.out')
206 self.build_and_launch(program,
208 shellExpandArguments=False)
209 self.continue_to_exit()
210 # Now get the STDOUT and verify our program argument is correct
211 output = self.get_stdout()
212 self.assertTrue(output and len(output) > 0,
213 "expect no program output")
214 lines = output.splitlines()
216 quote_path = '"%s"' % (glob)
217 if line.startswith("arg[1] ="):
218 self.assertTrue(quote_path in line,
219 'verify "%s" stayed to "%s"' % (
223 @skipIfDarwin # Skip this test for now until we can figure out why tings aren't working on build bots
224 @skipIfLinux # This test is timing out and/or failing on Linux as well as Darwin
228 Tests launch of a simple program with arguments
230 program = self.getBuildArtifact("a.out")
231 args = ["one", "with space", "'with single quotes'",
232 '"with double quotes"']
233 self.build_and_launch(program,
235 self.continue_to_exit()
237 # Now get the STDOUT and verify our arguments got passed correctly
238 output = self.get_stdout()
239 self.assertTrue(output and len(output) > 0,
240 "expect program output")
241 lines = output.splitlines()
242 # Skip the first argument that contains the program name
244 # Make sure arguments we specified are correct
245 for (i, arg) in enumerate(args):
246 quoted_arg = '"%s"' % (arg)
247 self.assertTrue(quoted_arg in lines[i],
248 'arg[%i] "%s" not in "%s"' % (i+1, quoted_arg, lines[i]))
251 @skipIfDarwin # Skip this test for now until we can figure out why tings aren't working on build bots
252 @skipIfLinux # This test is timing out and/or failing on Linux as well as Darwin
254 def test_environment(self):
256 Tests launch of a simple program with environment variables
258 program = self.getBuildArtifact("a.out")
259 env = ["NO_VALUE", "WITH_VALUE=BAR", "EMPTY_VALUE=",
261 self.build_and_launch(program,
263 self.continue_to_exit()
265 # Now get the STDOUT and verify our arguments got passed correctly
266 output = self.get_stdout()
267 self.assertTrue(output and len(output) > 0,
268 "expect program output")
269 lines = output.splitlines()
270 # Skip the all arguments so we have only environment vars left
271 while len(lines) and lines[0].startswith("arg["):
273 # Make sure each environment variable in "env" is actually set in the
274 # program environment that was printed to STDOUT
277 for program_var in lines:
278 if var in program_var:
281 self.assertTrue(found,
282 '"%s" must exist in program environment (%s)' % (
286 @skipIfDarwin # Skip this test for now until we can figure out why tings aren't working on build bots
287 @skipIfLinux # This test is timing out and/or failing on Linux as well as Darwin
289 def test_commands(self):
291 Tests the "initCommands", "preRunCommands", "stopCommands" and
292 "exitCommands" that can be passed during launch.
294 "initCommands" are a list of LLDB commands that get executed
295 before the targt is created.
296 "preRunCommands" are a list of LLDB commands that get executed
297 after the target has been created and before the launch.
298 "stopCommands" are a list of LLDB commands that get executed each
299 time the program stops.
300 "exitCommands" are a list of LLDB commands that get executed when
303 program = self.getBuildArtifact("a.out")
304 initCommands = ['target list', 'platform list']
305 preRunCommands = ['image list a.out', 'image dump sections a.out']
306 stopCommands = ['frame variable', 'bt']
307 exitCommands = ['expr 2+3', 'expr 3+4']
308 self.build_and_launch(program,
309 initCommands=initCommands,
310 preRunCommands=preRunCommands,
311 stopCommands=stopCommands,
312 exitCommands=exitCommands)
314 # Get output from the console. This should contain both the
315 # "initCommands" and the "preRunCommands".
316 output = self.get_console()
317 # Verify all "initCommands" were found in console output
318 self.verify_commands('initCommands', output, initCommands)
319 # Verify all "preRunCommands" were found in console output
320 self.verify_commands('preRunCommands', output, preRunCommands)
323 first_line = line_number(source, '// breakpoint 1')
324 second_line = line_number(source, '// breakpoint 2')
325 lines = [first_line, second_line]
327 # Set 2 breakoints so we can verify that "stopCommands" get run as the
328 # breakpoints get hit
329 breakpoint_ids = self.set_source_breakpoints(source, lines)
330 self.assertTrue(len(breakpoint_ids) == len(lines),
331 "expect correct number of breakpoints")
333 # Continue after launch and hit the first breakpoint.
334 # Get output from the console. This should contain both the
335 # "stopCommands" that were run after the first breakpoint was hit
336 self.continue_to_breakpoints(breakpoint_ids)
337 output = self.get_console(timeout=1.0)
338 self.verify_commands('stopCommands', output, stopCommands)
340 # Continue again and hit the second breakpoint.
341 # Get output from the console. This should contain both the
342 # "stopCommands" that were run after the second breakpoint was hit
343 self.continue_to_breakpoints(breakpoint_ids)
344 output = self.get_console(timeout=1.0)
345 self.verify_commands('stopCommands', output, stopCommands)
347 # Continue until the program exits
348 self.continue_to_exit()
349 # Get output from the console. This should contain both the
350 # "exitCommands" that were run after the second breakpoint was hit
351 output = self.get_console(timeout=1.0)
352 self.verify_commands('exitCommands', output, exitCommands)