[lldb] Fix TestPlatformProcessConnect.py

The test was marked as remote-only, which means it was run ~never, and
accumulated various problems. This commit modifies the test to run
locally and includes a couple of other fixes necessary to make it run:
- moves the "invoke" method into the "Base" test class
- adds []'s around the IP address in a couple more places to make things
  work with IPv6

The test is now marked as skipped when running the remote test suite. It
would be possible to make it run both locally and remotely, but this
would require writing a lot special logic for the remote case, and that
is not worth it.
This commit is contained in:
Pavel Labath
2021-01-06 17:05:27 +01:00
parent ed205f63b4
commit 4b284b9ca8
4 changed files with 27 additions and 55 deletions

View File

@@ -1765,6 +1765,19 @@ class Base(unittest2.TestCase):
"Don't know how to do cleanup with dictionary: " +
dictionary)
def invoke(self, obj, name, trace=False):
"""Use reflection to call a method dynamically with no argument."""
trace = (True if traceAlways else trace)
method = getattr(obj, name)
import inspect
self.assertTrue(inspect.ismethod(method),
name + "is a method name of object: " + str(obj))
result = method()
with recording(self, trace) as sbuf:
print(str(method) + ":", result, file=sbuf)
return result
def getLLDBLibraryEnvVal(self):
""" Returns the path that the OS-specific library search environment variable
(self.dylibPath) should be set to in order for a program to find the LLDB
@@ -2624,19 +2637,6 @@ FileCheck output:
value_check.check_value(self, eval_result, str(eval_result))
return eval_result
def invoke(self, obj, name, trace=False):
"""Use reflection to call a method dynamically with no argument."""
trace = (True if traceAlways else trace)
method = getattr(obj, name)
import inspect
self.assertTrue(inspect.ismethod(method),
name + "is a method name of object: " + str(obj))
result = method()
with recording(self, trace) as sbuf:
print(str(method) + ":", result, file=sbuf)
return result
def build(
self,
architecture=None,

View File

@@ -825,7 +825,7 @@ std::string PlatformRemoteGDBServer::MakeUrl(const char *scheme,
const char *hostname,
uint16_t port, const char *path) {
StreamString result;
result.Printf("%s://%s", scheme, hostname);
result.Printf("%s://[%s]", scheme, hostname);
if (port != 0)
result.Printf(":%u", port);
if (path)

View File

@@ -205,7 +205,7 @@ Status GDBRemoteCommunicationServerPlatform::LaunchGDBServer(
platform_port, platform_path);
UNUSED_IF_ASSERT_DISABLED(ok);
assert(ok);
url << platform_ip.str() << ":" << *port;
url << '[' << platform_ip.str() << "]:" << *port;
} else {
socket_name = GetDomainSocketPath("gdbserver").GetPath();
url << socket_name;

View File

@@ -1,44 +1,22 @@
import time
import socket
import gdbremote_testcase
import lldbgdbserverutils
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil
class TestPlatformProcessConnect(gdbremote_testcase.GdbRemoteTestCaseBase):
mydir = TestBase.compute_mydir(__file__)
@llgs_test
@no_debug_info_test
@skipIf(remote=False)
@skipIfRemote
@expectedFailureAll(hostoslist=["windows"], triple='.*-android')
def test_platform_process_connect(self):
self.build()
working_dir = lldb.remote_platform.GetWorkingDirectory()
src = lldb.SBFileSpec(self.getBuildArtifact("a.out"))
dest = lldb.SBFileSpec(os.path.join(working_dir, "a.out"))
err = lldb.remote_platform.Put(src, dest)
if err.Fail():
raise RuntimeError(
"Unable copy '%s' to '%s'.\n>>> %s" %
(f, wd, err.GetCString()))
hostname = socket.getaddrinfo("localhost", 0, proto=socket.IPPROTO_TCP)[0][4][0]
listen_url = "[%s]:0"%hostname
m = re.search("^(.*)://([^:/]*)", configuration.lldb_platform_url)
protocol = m.group(1)
hostname = m.group(2)
unix_protocol = protocol.startswith("unix-")
if unix_protocol:
p = re.search("^(.*)-connect", protocol)
path = lldbutil.join_remote_paths(configuration.lldb_platform_working_dir,
self.getBuildDirBasename(), "platform-%d.sock" % int(time.time()))
listen_url = "%s://%s" % (p.group(1), path)
else:
listen_url = "*:0"
port_file = "%s/port" % working_dir
port_file = self.getBuildArtifact("port")
commandline_args = [
"platform",
"--listen",
@@ -46,25 +24,19 @@ class TestPlatformProcessConnect(gdbremote_testcase.GdbRemoteTestCaseBase):
"--socket-file",
port_file,
"--",
"%s/a.out" %
working_dir,
self.getBuildArtifact("a.out"),
"foo"]
self.spawnSubprocess(
self.debug_monitor_exe,
commandline_args,
install_remote=False)
lldbgdbserverutils.get_lldb_server_exe(),
commandline_args)
socket_id = lldbutil.wait_for_file_on_target(self, port_file)
self.dbg.SetAsync(False)
new_platform = lldb.SBPlatform(lldb.remote_platform.GetName())
new_platform = lldb.SBPlatform("remote-" + self.getPlatform())
self.dbg.SetSelectedPlatform(new_platform)
if unix_protocol:
connect_url = "%s://%s%s" % (protocol, hostname, socket_id)
else:
connect_url = "%s://%s:%s" % (protocol, hostname, socket_id)
connect_url = "connect://[%s]:%s" % (hostname, socket_id)
command = "platform connect %s" % (connect_url)
result = lldb.SBCommandReturnObject()
@@ -72,7 +44,7 @@ class TestPlatformProcessConnect(gdbremote_testcase.GdbRemoteTestCaseBase):
self.assertTrue(
result.Succeeded(),
"platform process connect failed: %s" %
result.GetOutput())
result.GetError())
target = self.dbg.GetSelectedTarget()
process = target.GetProcess()