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
|
"""
Test lldb-dap runInTerminal reverse request
"""
import dap_server
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil
import lldbdap_testcase
import time
import os
import subprocess
import shutil
import json
from threading import Thread
class TestDAP_runInTerminal(lldbdap_testcase.DAPTestCaseBase):
def readPidMessage(self, fifo_file):
with open(fifo_file, "r") as file:
self.assertIn("pid", file.readline())
def sendDidAttachMessage(self, fifo_file):
with open(fifo_file, "w") as file:
file.write(json.dumps({"kind": "didAttach"}) + "\n")
def readErrorMessage(self, fifo_file):
with open(fifo_file, "r") as file:
return file.readline()
def isTestSupported(self):
# For some strange reason, this test fails on python3.6
if not (sys.version_info.major == 3 and sys.version_info.minor >= 7):
return False
try:
# We skip this test for debug builds because it takes too long parsing lldb's own
# debug info. Release builds are fine.
# Checking the size of the lldb-dap binary seems to be a decent proxy for a quick
# detection. It should be far less than 1 MB in Release builds.
if os.path.getsize(os.environ["LLDBDAP_EXEC"]) < 1000000:
return True
except:
return False
@skipIfLinux # FIXME: doesn't seem to work on Ubuntu 16.04.
@skipIfWindows
@skipIfRemote
@skipIf(archs=no_match(["x86_64"]))
def test_runInTerminal(self):
if not self.isTestSupported():
return
"""
Tests the "runInTerminal" reverse request. It makes sure that the IDE can
launch the inferior with the correct environment variables and arguments.
"""
program = self.getBuildArtifact("a.out")
source = "main.c"
self.build_and_launch(
program, runInTerminal=True, args=["foobar"], env=["FOO=bar"]
)
self.assertEqual(
len(self.dap_server.reverse_requests),
1,
"make sure we got a reverse request",
)
request = self.dap_server.reverse_requests[0]
self.assertIn(self.lldbDAPExec, request["arguments"]["args"])
self.assertIn(program, request["arguments"]["args"])
self.assertIn("foobar", request["arguments"]["args"])
self.assertIn("FOO", request["arguments"]["env"])
breakpoint_line = line_number(source, "// breakpoint")
self.set_source_breakpoints(source, [breakpoint_line])
self.continue_to_next_stop()
# We verify we actually stopped inside the loop
counter = int(self.dap_server.get_local_variable_value("counter"))
self.assertTrue(counter > 0)
# We verify we were able to set the launch arguments
argc = int(self.dap_server.get_local_variable_value("argc"))
self.assertEqual(argc, 2)
argv1 = self.dap_server.request_evaluate("argv[1]")["body"]["result"]
self.assertIn("foobar", argv1)
# We verify we were able to set the environment
env = self.dap_server.request_evaluate("foo")["body"]["result"]
self.assertIn("bar", env)
@skipIfLinux # FIXME: doesn't seem to work on Ubuntu 16.04.
@skipIfWindows
@skipIfRemote
@skipIf(archs=no_match(["x86_64"]))
def test_runInTerminalInvalidTarget(self):
if not self.isTestSupported():
return
self.build_and_create_debug_adaptor()
response = self.launch(
"INVALIDPROGRAM",
runInTerminal=True,
args=["foobar"],
env=["FOO=bar"],
expectFailure=True,
)
self.assertFalse(response["success"])
self.assertIn(
"Could not create a target for a program 'INVALIDPROGRAM': unable to find executable",
response["message"],
)
@skipIfLinux # FIXME: doesn't seem to work on Ubuntu 16.04.
@skipIfWindows
@skipIfRemote
@skipIf(archs=no_match(["x86_64"]))
def test_missingArgInRunInTerminalLauncher(self):
if not self.isTestSupported():
return
proc = subprocess.run(
[self.lldbDAPExec, "--launch-target", "INVALIDPROGRAM"],
capture_output=True,
universal_newlines=True,
)
self.assertTrue(proc.returncode != 0)
self.assertIn(
'"--launch-target" requires "--comm-file" to be specified', proc.stderr
)
@skipIfLinux # FIXME: doesn't seem to work on Ubuntu 16.04.
@skipIfWindows
@skipIfRemote
@skipIf(archs=no_match(["x86_64"]))
def test_FakeAttachedRunInTerminalLauncherWithInvalidProgram(self):
if not self.isTestSupported():
return
comm_file = os.path.join(self.getBuildDir(), "comm-file")
os.mkfifo(comm_file)
proc = subprocess.Popen(
[
self.lldbDAPExec,
"--comm-file",
comm_file,
"--launch-target",
"INVALIDPROGRAM",
],
universal_newlines=True,
stderr=subprocess.PIPE,
)
self.readPidMessage(comm_file)
self.sendDidAttachMessage(comm_file)
self.assertIn("No such file or directory", self.readErrorMessage(comm_file))
_, stderr = proc.communicate()
self.assertIn("No such file or directory", stderr)
@skipIfLinux # FIXME: doesn't seem to work on Ubuntu 16.04.
@skipIfWindows
@skipIfRemote
@skipIf(archs=no_match(["x86_64"]))
def test_FakeAttachedRunInTerminalLauncherWithValidProgram(self):
if not self.isTestSupported():
return
comm_file = os.path.join(self.getBuildDir(), "comm-file")
os.mkfifo(comm_file)
proc = subprocess.Popen(
[
self.lldbDAPExec,
"--comm-file",
comm_file,
"--launch-target",
"echo",
"foo",
],
universal_newlines=True,
stdout=subprocess.PIPE,
)
self.readPidMessage(comm_file)
self.sendDidAttachMessage(comm_file)
stdout, _ = proc.communicate()
self.assertIn("foo", stdout)
@skipIfLinux # FIXME: doesn't seem to work on Ubuntu 16.04.
@skipIfWindows
@skipIfRemote
@skipIf(archs=no_match(["x86_64"]))
def test_FakeAttachedRunInTerminalLauncherAndCheckEnvironment(self):
if not self.isTestSupported():
return
comm_file = os.path.join(self.getBuildDir(), "comm-file")
os.mkfifo(comm_file)
proc = subprocess.Popen(
[self.lldbDAPExec, "--comm-file", comm_file, "--launch-target", "env"],
universal_newlines=True,
stdout=subprocess.PIPE,
env={**os.environ, "FOO": "BAR"},
)
self.readPidMessage(comm_file)
self.sendDidAttachMessage(comm_file)
stdout, _ = proc.communicate()
self.assertIn("FOO=BAR", stdout)
@skipIfLinux # FIXME: doesn't seem to work on Ubuntu 16.04.
@skipIfWindows
@skipIfRemote
@skipIf(archs=no_match(["x86_64"]))
def test_NonAttachedRunInTerminalLauncher(self):
if not self.isTestSupported():
return
comm_file = os.path.join(self.getBuildDir(), "comm-file")
os.mkfifo(comm_file)
proc = subprocess.Popen(
[
self.lldbDAPExec,
"--comm-file",
comm_file,
"--launch-target",
"echo",
"foo",
],
universal_newlines=True,
stderr=subprocess.PIPE,
env={**os.environ, "LLDB_DAP_RIT_TIMEOUT_IN_MS": "1000"},
)
self.readPidMessage(comm_file)
_, stderr = proc.communicate()
self.assertIn("Timed out trying to get messages from the debug adaptor", stderr)
|