1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345
|
"""
Test lldb-vscode setBreakpoints request
"""
from __future__ import print_function
import pprint
import unittest2
import vscode
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil
import lldbvscode_testcase
import os
import time
class TestVSCode_launch(lldbvscode_testcase.VSCodeTestCaseBase):
mydir = TestBase.compute_mydir(__file__)
@skipIfWindows
@skipIfDarwin # Skip this test for now until we can figure out why tings aren't working on build bots
@no_debug_info_test
def test_default(self):
'''
Tests the default launch of a simple program. No arguments,
environment, or anything else is specified.
'''
program = self.getBuildArtifact("a.out")
self.build_and_launch(program)
self.continue_to_exit()
# Now get the STDOUT and verify our program argument is correct
output = self.get_stdout()
self.assertTrue(output and len(output) > 0,
"expect program output")
lines = output.splitlines()
self.assertTrue(program in lines[0],
"make sure program path is in first argument")
@skipIfWindows
@skipIfDarwin # Skip this test for now until we can figure out why tings aren't working on build bots
@no_debug_info_test
def test_stopOnEntry(self):
'''
Tests the default launch of a simple program that stops at the
entry point instead of continuing.
'''
program = self.getBuildArtifact("a.out")
self.build_and_launch(program, stopOnEntry=True)
self.set_function_breakpoints(['main'])
stopped_events = self.continue_to_next_stop()
for stopped_event in stopped_events:
if 'body' in stopped_event:
body = stopped_event['body']
if 'reason' in body:
reason = body['reason']
self.assertTrue(
reason != 'breakpoint',
'verify stop isn\'t "main" breakpoint')
@skipIfWindows
@skipIfDarwin # Skip this test for now until we can figure out why tings aren't working on build bots
@expectedFailureNetBSD
@no_debug_info_test
def test_cwd(self):
'''
Tests the default launch of a simple program with a current working
directory.
'''
program = self.getBuildArtifact("a.out")
program_parent_dir = os.path.split(os.path.split(program)[0])[0]
self.build_and_launch(program,
cwd=program_parent_dir)
self.continue_to_exit()
# Now get the STDOUT and verify our program argument is correct
output = self.get_stdout()
self.assertTrue(output and len(output) > 0,
"expect program output")
lines = output.splitlines()
found = False
for line in lines:
if line.startswith('cwd = \"'):
quote_path = '"%s"' % (program_parent_dir)
found = True
self.assertTrue(quote_path in line,
"working directory '%s' not in '%s'" % (
program_parent_dir, line))
self.assertTrue(found, "verified program working directory")
@skipIfWindows
@skipIfDarwin # Skip this test for now until we can figure out why tings aren't working on build bots
@expectedFailureNetBSD
@no_debug_info_test
def test_debuggerRoot(self):
'''
Tests the "debuggerRoot" will change the working directory of
the lldb-vscode debug adaptor.
'''
program = self.getBuildArtifact("a.out")
program_parent_dir = os.path.split(os.path.split(program)[0])[0]
commands = ['platform shell echo cwd = $PWD']
self.build_and_launch(program,
debuggerRoot=program_parent_dir,
initCommands=commands)
output = self.get_console()
self.assertTrue(output and len(output) > 0,
"expect console output")
lines = output.splitlines()
prefix = 'cwd = '
found = False
for line in lines:
if line.startswith(prefix):
found = True
self.assertTrue(program_parent_dir == line[len(prefix):],
"lldb-vscode working dir '%s' == '%s'" % (
program_parent_dir, line[6:]))
self.assertTrue(found, "verified lldb-vscode working directory")
self.continue_to_exit()
@skipIfWindows
@skipIfDarwin # Skip this test for now until we can figure out why tings aren't working on build bots
@no_debug_info_test
def test_sourcePath(self):
'''
Tests the "sourcePath" will set the target.source-map.
'''
program = self.getBuildArtifact("a.out")
program_dir = os.path.split(program)[0]
self.build_and_launch(program,
sourcePath=program_dir)
output = self.get_console()
self.assertTrue(output and len(output) > 0,
"expect console output")
lines = output.splitlines()
prefix = '(lldb) settings set target.source-map "." '
found = False
for line in lines:
if line.startswith(prefix):
found = True
quoted_path = '"%s"' % (program_dir)
self.assertTrue(quoted_path == line[len(prefix):],
"lldb-vscode working dir %s == %s" % (
quoted_path, line[6:]))
self.assertTrue(found, 'found "sourcePath" in console output')
self.continue_to_exit()
@skipIfWindows
@skipIfDarwin # Skip this test for now until we can figure out why tings aren't working on build bots
@no_debug_info_test
def test_disableSTDIO(self):
'''
Tests the default launch of a simple program with STDIO disabled.
'''
program = self.getBuildArtifact("a.out")
self.build_and_launch(program,
disableSTDIO=True)
self.continue_to_exit()
# Now get the STDOUT and verify our program argument is correct
output = self.get_stdout()
self.assertTrue(output is None or len(output) == 0,
"expect no program output")
@skipIfWindows
@skipIfDarwin # Skip this test for now until we can figure out why tings aren't working on build bots
@skipIfLinux # shell argument expansion doesn't seem to work on Linux
@expectedFailureNetBSD
@no_debug_info_test
def test_shellExpandArguments_enabled(self):
'''
Tests the default launch of a simple program with shell expansion
enabled.
'''
program = self.getBuildArtifact("a.out")
program_dir = os.path.split(program)[0]
glob = os.path.join(program_dir, '*.out')
self.build_and_launch(program, args=[glob], shellExpandArguments=True)
self.continue_to_exit()
# Now get the STDOUT and verify our program argument is correct
output = self.get_stdout()
self.assertTrue(output and len(output) > 0,
"expect no program output")
lines = output.splitlines()
for line in lines:
quote_path = '"%s"' % (program)
if line.startswith("arg[1] ="):
self.assertTrue(quote_path in line,
'verify "%s" expanded to "%s"' % (
glob, program))
@skipIfWindows
@skipIfDarwin # Skip this test for now until we can figure out why tings aren't working on build bots
@no_debug_info_test
def test_shellExpandArguments_disabled(self):
'''
Tests the default launch of a simple program with shell expansion
disabled.
'''
program = self.getBuildArtifact("a.out")
program_dir = os.path.split(program)[0]
glob = os.path.join(program_dir, '*.out')
self.build_and_launch(program,
args=[glob],
shellExpandArguments=False)
self.continue_to_exit()
# Now get the STDOUT and verify our program argument is correct
output = self.get_stdout()
self.assertTrue(output and len(output) > 0,
"expect no program output")
lines = output.splitlines()
for line in lines:
quote_path = '"%s"' % (glob)
if line.startswith("arg[1] ="):
self.assertTrue(quote_path in line,
'verify "%s" stayed to "%s"' % (
glob, glob))
@skipIfWindows
@skipIfDarwin # Skip this test for now until we can figure out why tings aren't working on build bots
@no_debug_info_test
def test_args(self):
'''
Tests launch of a simple program with arguments
'''
program = self.getBuildArtifact("a.out")
args = ["one", "with space", "'with single quotes'",
'"with double quotes"']
self.build_and_launch(program,
args=args)
self.continue_to_exit()
# Now get the STDOUT and verify our arguments got passed correctly
output = self.get_stdout()
self.assertTrue(output and len(output) > 0,
"expect program output")
lines = output.splitlines()
# Skip the first argument that contains the program name
lines.pop(0)
# Make sure arguments we specified are correct
for (i, arg) in enumerate(args):
quoted_arg = '"%s"' % (arg)
self.assertTrue(quoted_arg in lines[i],
'arg[%i] "%s" not in "%s"' % (i+1, quoted_arg, lines[i]))
@skipIfWindows
@skipIfDarwin # Skip this test for now until we can figure out why tings aren't working on build bots
@no_debug_info_test
def test_environment(self):
'''
Tests launch of a simple program with environment variables
'''
program = self.getBuildArtifact("a.out")
env = ["NO_VALUE", "WITH_VALUE=BAR", "EMPTY_VALUE=",
"SPACE=Hello World"]
self.build_and_launch(program,
env=env)
self.continue_to_exit()
# Now get the STDOUT and verify our arguments got passed correctly
output = self.get_stdout()
self.assertTrue(output and len(output) > 0,
"expect program output")
lines = output.splitlines()
# Skip the all arguments so we have only environment vars left
while len(lines) and lines[0].startswith("arg["):
lines.pop(0)
# Make sure each environment variable in "env" is actually set in the
# program environment that was printed to STDOUT
for var in env:
found = False
for program_var in lines:
if var in program_var:
found = True
break
self.assertTrue(found,
'"%s" must exist in program environment (%s)' % (
var, lines))
@skipIfWindows
@skipIfDarwin # Skip this test for now until we can figure out why tings aren't working on build bots
@no_debug_info_test
def test_commands(self):
'''
Tests the "initCommands", "preRunCommands", "stopCommands" and
"exitCommands" that can be passed during launch.
"initCommands" are a list of LLDB commands that get executed
before the targt is created.
"preRunCommands" are a list of LLDB commands that get executed
after the target has been created and before the launch.
"stopCommands" are a list of LLDB commands that get executed each
time the program stops.
"exitCommands" are a list of LLDB commands that get executed when
the process exits
'''
program = self.getBuildArtifact("a.out")
initCommands = ['target list', 'platform list']
preRunCommands = ['image list a.out', 'image dump sections a.out']
stopCommands = ['frame variable', 'bt']
exitCommands = ['expr 2+3', 'expr 3+4']
self.build_and_launch(program,
initCommands=initCommands,
preRunCommands=preRunCommands,
stopCommands=stopCommands,
exitCommands=exitCommands)
# Get output from the console. This should contain both the
# "initCommands" and the "preRunCommands".
output = self.get_console()
# Verify all "initCommands" were found in console output
self.verify_commands('initCommands', output, initCommands)
# Verify all "preRunCommands" were found in console output
self.verify_commands('preRunCommands', output, preRunCommands)
source = 'main.c'
first_line = line_number(source, '// breakpoint 1')
second_line = line_number(source, '// breakpoint 2')
lines = [first_line, second_line]
# Set 2 breakoints so we can verify that "stopCommands" get run as the
# breakpoints get hit
breakpoint_ids = self.set_source_breakpoints(source, lines)
self.assertTrue(len(breakpoint_ids) == len(lines),
"expect correct number of breakpoints")
# Continue after launch and hit the first breakpoint.
# Get output from the console. This should contain both the
# "stopCommands" that were run after the first breakpoint was hit
self.continue_to_breakpoints(breakpoint_ids)
output = self.get_console(timeout=1.0)
self.verify_commands('stopCommands', output, stopCommands)
# Continue again and hit the second breakpoint.
# Get output from the console. This should contain both the
# "stopCommands" that were run after the second breakpoint was hit
self.continue_to_breakpoints(breakpoint_ids)
output = self.get_console(timeout=1.0)
self.verify_commands('stopCommands', output, stopCommands)
# Continue until the program exits
self.continue_to_exit()
# Get output from the console. This should contain both the
# "exitCommands" that were run after the second breakpoint was hit
output = self.get_console(timeout=1.0)
self.verify_commands('exitCommands', output, exitCommands)
|