Skip to content

Commit becab1c

Browse files
committed
[lldb] Fix the SocketTest::TCPListen0MultiListenerGetListeningConnectionURI failure on unsupported hosts.
This failure https://lab.llvm.org/buildbot/#/builders/195/builds/1909 happened due to the host not having a `localhost` /etc/hosts entry for an ipv6 address. To fix this, I added a helper to validate if the host has an /etc/hosts entry for both ipv4 and ipv6, otherwise we skip the test.
1 parent ed2db3b commit becab1c

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

lldb/unittests/Host/SocketTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ TEST_P(SocketTest, TCPListen0GetListeningConnectionURI) {
271271
}
272272

273273
TEST_F(SocketTest, TCPListen0MultiListenerGetListeningConnectionURI) {
274-
if (!HostSupportsIPv6() || !HostSupportsIPv4())
274+
if (!HostSupportsLocalhostToIPv4() || !HostSupportsLocalhostToIPv6())
275275
return;
276276

277277
llvm::Expected<std::unique_ptr<TCPSocket>> sock =

lldb/unittests/TestingSupport/Host/SocketTestUtilities.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,24 @@ bool lldb_private::HostSupportsIPv6() {
116116
return CheckIPSupport("IPv6", "[::1]:0");
117117
}
118118

119+
bool lldb_private::HostSupportsLocalhostToIPv4() {
120+
if (!HostSupportsIPv4())
121+
return false;
122+
123+
auto addresses = SocketAddress::GetAddressInfo("localhost", nullptr, AF_INET,
124+
SOCK_STREAM, IPPROTO_TCP);
125+
return !addresses.empty();
126+
}
127+
128+
bool lldb_private::HostSupportsLocalhostToIPv6() {
129+
if (!HostSupportsIPv6())
130+
return false;
131+
132+
auto addresses = SocketAddress::GetAddressInfo("localhost", nullptr, AF_INET6,
133+
SOCK_STREAM, IPPROTO_TCP);
134+
return !addresses.empty();
135+
}
136+
119137
llvm::Expected<std::string> lldb_private::GetLocalhostIP() {
120138
if (HostSupportsIPv4())
121139
return "127.0.0.1";

lldb/unittests/TestingSupport/Host/SocketTestUtilities.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ void CreateDomainConnectedSockets(llvm::StringRef path,
4343
bool HostSupportsIPv6();
4444
bool HostSupportsIPv4();
4545

46+
/// Returns true if the name `localhost` maps to a loopback IPv4 address.
47+
bool HostSupportsLocalhostToIPv4();
48+
/// Returns true if the name `localhost` maps to a loopback IPv6 address.
49+
bool HostSupportsLocalhostToIPv6();
50+
4651
/// Return an IP for localhost based on host support.
4752
///
4853
/// This will return either "127.0.0.1" if IPv4 is detected, or "[::1]" if IPv6

0 commit comments

Comments
 (0)