]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/tools/lldb-vscode/launch/TestVSCode_launch.py
Vendor import of lldb trunk r351319 (just before the release_80 branch
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / tools / lldb-vscode / launch / TestVSCode_launch.py
1 """
2 Test lldb-vscode setBreakpoints request
3 """
4
5 from __future__ import print_function
6
7 import pprint
8 import unittest2
9 import vscode
10 from lldbsuite.test.decorators import *
11 from lldbsuite.test.lldbtest import *
12 from lldbsuite.test import lldbutil
13 import lldbvscode_testcase
14 import os
15 import time
16
17
18 class TestVSCode_launch(lldbvscode_testcase.VSCodeTestCaseBase):
19
20     mydir = TestBase.compute_mydir(__file__)
21
22     @skipIfWindows
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
25     @no_debug_info_test
26     def test_default(self):
27         '''
28             Tests the default launch of a simple program. No arguments,
29             environment, or anything else is specified.
30         '''
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")
41
42     @skipIfWindows
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
45     @no_debug_info_test
46     def test_stopOnEntry(self):
47         '''
48             Tests the default launch of a simple program that stops at the
49             entry point instead of continuing.
50         '''
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']
58                 if 'reason' in body:
59                     reason = body['reason']
60                     self.assertTrue(
61                         reason != 'breakpoint',
62                         'verify stop isn\'t "main" breakpoint')
63
64     @skipIfWindows
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
67     @no_debug_info_test
68     def test_cwd(self):
69         '''
70             Tests the default launch of a simple program with a current working
71             directory.
72         '''
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()
83         found = False
84         for line in lines:
85             if line.startswith('cwd = \"'):
86                 quote_path = '"%s"' % (program_parent_dir)
87                 found = True
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")
92
93     @skipIfWindows
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
96     @no_debug_info_test
97     def test_debuggerRoot(self):
98         '''
99             Tests the "debuggerRoot" will change the working directory of
100             the lldb-vscode debug adaptor.
101         '''
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()
112         prefix = 'cwd = '
113         found = False
114         for line in lines:
115             if line.startswith(prefix):
116                 found = True
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()
122
123     @skipIfWindows
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
126     @no_debug_info_test
127     def test_sourcePath(self):
128         '''
129             Tests the "sourcePath" will set the target.source-map.
130         '''
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 "." '
140         found = False
141         for line in lines:
142             if line.startswith(prefix):
143                 found = True
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()
150
151     @skipIfWindows
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
154     @no_debug_info_test
155     def test_disableSTDIO(self):
156         '''
157             Tests the default launch of a simple program with STDIO disabled.
158         '''
159         program = self.getBuildArtifact("a.out")
160         self.build_and_launch(program,
161                               disableSTDIO=True)
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")
167
168     @skipIfWindows
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
171     @no_debug_info_test
172     def test_shellExpandArguments_enabled(self):
173         '''
174             Tests the default launch of a simple program with shell expansion
175             enabled.
176         '''
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()
187         for line in lines:
188             quote_path = '"%s"' % (program)
189             if line.startswith("arg[1] ="):
190                 self.assertTrue(quote_path in line,
191                                 'verify "%s" expanded to "%s"' % (
192                                     glob, program))
193
194     @skipIfWindows
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
197     @no_debug_info_test
198     def test_shellExpandArguments_disabled(self):
199         '''
200             Tests the default launch of a simple program with shell expansion
201             disabled.
202         '''
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,
207                               args=[glob],
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()
215         for line in lines:
216             quote_path = '"%s"' % (glob)
217             if line.startswith("arg[1] ="):
218                 self.assertTrue(quote_path in line,
219                                 'verify "%s" stayed to "%s"' % (
220                                     glob, glob))
221
222     @skipIfWindows
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
225     @no_debug_info_test
226     def test_args(self):
227         '''
228             Tests launch of a simple program with arguments
229         '''
230         program = self.getBuildArtifact("a.out")
231         args = ["one", "with space", "'with single quotes'",
232                 '"with double quotes"']
233         self.build_and_launch(program,
234                               args=args)
235         self.continue_to_exit()
236
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
243         lines.pop(0)
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]))
249
250     @skipIfWindows
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
253     @no_debug_info_test
254     def test_environment(self):
255         '''
256             Tests launch of a simple program with environment variables
257         '''
258         program = self.getBuildArtifact("a.out")
259         env = ["NO_VALUE", "WITH_VALUE=BAR", "EMPTY_VALUE=",
260                "SPACE=Hello World"]
261         self.build_and_launch(program,
262                               env=env)
263         self.continue_to_exit()
264
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["):
272             lines.pop(0)
273         # Make sure each environment variable in "env" is actually set in the
274         # program environment that was printed to STDOUT
275         for var in env:
276             found = False
277             for program_var in lines:
278                 if var in program_var:
279                     found = True
280                     break
281             self.assertTrue(found,
282                             '"%s" must exist in program environment (%s)' % (
283                                 var, lines))
284
285     @skipIfWindows
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
288     @no_debug_info_test
289     def test_commands(self):
290         '''
291             Tests the "initCommands", "preRunCommands", "stopCommands" and
292             "exitCommands" that can be passed during launch.
293
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
301             the process exits
302         '''
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)
313
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)
321
322         source = 'main.c'
323         first_line = line_number(source, '// breakpoint 1')
324         second_line = line_number(source, '// breakpoint 2')
325         lines = [first_line, second_line]
326
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")
332
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)
339
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)
346
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)