[Lldb-commits] [PATCH] D133393: [test] Use either `127.0.0.1` or `[::1]` to run in ipv6-only environments.
Jordan Rupprecht via Phabricator via lldb-commits
lldb-commits at lists.llvm.org
Fri Sep 9 14:09:30 PDT 2022
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1b988ff092a0: [test] Use either `127.0.0.1` or `[::1]` to run in ipv6-only environments. (authored by rupprecht).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D133393/new/
https://reviews.llvm.org/D133393
Files:
lldb/unittests/TestingSupport/Host/SocketTestUtilities.cpp
lldb/unittests/TestingSupport/Host/SocketTestUtilities.h
lldb/unittests/tools/lldb-server/tests/CMakeLists.txt
lldb/unittests/tools/lldb-server/tests/TestClient.cpp
Index: lldb/unittests/tools/lldb-server/tests/TestClient.cpp
===================================================================
--- lldb/unittests/tools/lldb-server/tests/TestClient.cpp
+++ lldb/unittests/tools/lldb-server/tests/TestClient.cpp
@@ -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 @@
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);
Index: lldb/unittests/tools/lldb-server/tests/CMakeLists.txt
===================================================================
--- lldb/unittests/tools/lldb-server/tests/CMakeLists.txt
+++ lldb/unittests/tools/lldb-server/tests/CMakeLists.txt
@@ -7,6 +7,7 @@
LINK_LIBS
lldbHost
lldbCore
+ lldbHostHelpers
lldbInterpreter
lldbTarget
lldbPluginPlatformLinux
Index: lldb/unittests/TestingSupport/Host/SocketTestUtilities.h
===================================================================
--- lldb/unittests/TestingSupport/Host/SocketTestUtilities.h
+++ lldb/unittests/TestingSupport/Host/SocketTestUtilities.h
@@ -42,6 +42,13 @@
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
Index: lldb/unittests/TestingSupport/Host/SocketTestUtilities.cpp
===================================================================
--- lldb/unittests/TestingSupport/Host/SocketTestUtilities.cpp
+++ lldb/unittests/TestingSupport/Host/SocketTestUtilities.cpp
@@ -126,3 +126,13 @@
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());
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D133393.459199.patch
Type: text/x-patch
Size: 2977 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20220909/e46959bd/attachment-0001.bin>
More information about the lldb-commits
mailing list