[test] Use either `127.0.0.1` or `[::1]` to run in ipv6-only environments.
Test for both IPv4 and IPv6 support to determine if either `127.0.0.1` or `[::1]` are appropriate IP addresses to attempt to connect to. In an IPv6-only environment, `127.0.0.1` is not available. Using `localhost` is problematic because we might not be able to get the same port on each IP flavor, and later try to connect to the wrong thing. Reviewed By: labath Differential Revision: https://reviews.llvm.org/D133393
This commit is contained in:
parent
eb65327fe9
commit
1b988ff092
|
@ -126,3 +126,13 @@ bool lldb_private::HostSupportsIPv4() {
|
|||
bool lldb_private::HostSupportsIPv6() {
|
||||
return CheckIPSupport("IPv6", "[::1]:0");
|
||||
}
|
||||
|
||||
llvm::Expected<std::string> lldb_private::GetLocalhostIP() {
|
||||
if (HostSupportsIPv4())
|
||||
return "127.0.0.1";
|
||||
if (HostSupportsIPv6())
|
||||
return "[::1]";
|
||||
return llvm::make_error<llvm::StringError>(
|
||||
"Neither IPv4 nor IPv6 appear to be supported",
|
||||
llvm::inconvertibleErrorCode());
|
||||
}
|
||||
|
|
|
@ -42,6 +42,13 @@ void CreateDomainConnectedSockets(llvm::StringRef path,
|
|||
|
||||
bool HostSupportsIPv6();
|
||||
bool HostSupportsIPv4();
|
||||
|
||||
/// Return an IP for localhost based on host support.
|
||||
///
|
||||
/// This will return either "127.0.0.1" if IPv4 is detected, or "[::1]" if IPv6
|
||||
/// is detected. If neither are detected, return an error.
|
||||
llvm::Expected<std::string> GetLocalhostIP();
|
||||
|
||||
} // namespace lldb_private
|
||||
|
||||
#endif
|
||||
|
|
|
@ -7,6 +7,7 @@ add_lldb_unittest(LLDBServerTests
|
|||
LINK_LIBS
|
||||
lldbHost
|
||||
lldbCore
|
||||
lldbHostHelpers
|
||||
lldbInterpreter
|
||||
lldbTarget
|
||||
lldbPluginPlatformLinux
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "TestClient.h"
|
||||
#include "TestingSupport/Host/SocketTestUtilities.h"
|
||||
#include "lldb/Host/HostInfo.h"
|
||||
#include "lldb/Host/common/TCPSocket.h"
|
||||
#include "lldb/Host/posix/ConnectionFileDescriptorPosix.h"
|
||||
|
@ -77,14 +78,20 @@ Expected<std::unique_ptr<TestClient>> TestClient::launchCustom(StringRef Log, Ar
|
|||
args.AppendArgument("--log-flags=0x800000");
|
||||
}
|
||||
|
||||
auto LocalhostIPOrErr = GetLocalhostIP();
|
||||
if (!LocalhostIPOrErr)
|
||||
return LocalhostIPOrErr.takeError();
|
||||
const std::string &LocalhostIP = *LocalhostIPOrErr;
|
||||
|
||||
Status status;
|
||||
TCPSocket listen_socket(true, false);
|
||||
status = listen_socket.Listen("127.0.0.1:0", 5);
|
||||
status = listen_socket.Listen(LocalhostIP + ":0", 5);
|
||||
if (status.Fail())
|
||||
return status.ToError();
|
||||
|
||||
args.AppendArgument(
|
||||
("127.0.0.1:" + Twine(listen_socket.GetLocalPortNumber())).str());
|
||||
formatv("{0}:{1}", LocalhostIP, listen_socket.GetLocalPortNumber())
|
||||
.str());
|
||||
|
||||
for (StringRef arg : ServerArgs)
|
||||
args.AppendArgument(arg);
|
||||
|
|
Loading…
Reference in New Issue