summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorTamir Duberstein <tamird@google.com>2021-10-06 08:34:55 -0700
committergVisor bot <gvisor-bot@google.com>2021-10-06 08:37:22 -0700
commit158372f0401bbe6d34a8fc5fe0b41cbda5eaf367 (patch)
treec41d1079f4dbd63f46080af365b0694b4e25db4b
parente104c1c47991a5d2733d6d58ce3c67c5cab5a4bc (diff)
Do not skip IPv6 tests when we don't have IPv4
PiperOrigin-RevId: 401251635
-rw-r--r--test/syscalls/linux/BUILD9
-rw-r--r--test/syscalls/linux/socket_ip_udp_unbound_external_networking.cc72
-rw-r--r--test/syscalls/linux/socket_ip_udp_unbound_external_networking.h17
-rw-r--r--test/syscalls/linux/socket_ipv4_udp_unbound_external_networking.cc51
-rw-r--r--test/syscalls/linux/socket_ipv4_udp_unbound_external_networking.h18
5 files changed, 71 insertions, 96 deletions
diff --git a/test/syscalls/linux/BUILD b/test/syscalls/linux/BUILD
index c46ec7a53..d844a61a7 100644
--- a/test/syscalls/linux/BUILD
+++ b/test/syscalls/linux/BUILD
@@ -2660,17 +2660,11 @@ cc_library(
cc_library(
name = "socket_ip_udp_unbound_external_networking",
testonly = 1,
- srcs = [
- "socket_ip_udp_unbound_external_networking.cc",
- ],
hdrs = [
"socket_ip_udp_unbound_external_networking.h",
],
deps = [
":ip_socket_test_util",
- "//test/util:socket_util",
- "//test/util:test_util",
- "@com_google_absl//absl/cleanup",
],
alwayslink = 1,
)
@@ -2686,6 +2680,9 @@ cc_library(
],
deps = [
":socket_ip_udp_unbound_external_networking",
+ "//test/util:socket_util",
+ "//test/util:test_util",
+ "@com_google_absl//absl/cleanup",
gtest,
],
alwayslink = 1,
diff --git a/test/syscalls/linux/socket_ip_udp_unbound_external_networking.cc b/test/syscalls/linux/socket_ip_udp_unbound_external_networking.cc
deleted file mode 100644
index 14da2717b..000000000
--- a/test/syscalls/linux/socket_ip_udp_unbound_external_networking.cc
+++ /dev/null
@@ -1,72 +0,0 @@
-// Copyright 2020 The gVisor Authors.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#include "test/syscalls/linux/socket_ip_udp_unbound_external_networking.h"
-
-#include "absl/cleanup/cleanup.h"
-#include "test/util/socket_util.h"
-#include "test/util/test_util.h"
-
-namespace gvisor {
-namespace testing {
-
-void IPUDPUnboundExternalNetworkingSocketTest::SetUp() {
-#ifdef ANDROID
- GTEST_SKIP() << "Android does not support getifaddrs in r22";
-#endif
-
- ifaddrs* ifaddr;
- ASSERT_THAT(getifaddrs(&ifaddr), SyscallSucceeds());
- auto cleanup = absl::MakeCleanup([ifaddr] { freeifaddrs(ifaddr); });
-
- for (const ifaddrs* ifa = ifaddr; ifa != nullptr; ifa = ifa->ifa_next) {
- ASSERT_NE(ifa->ifa_name, nullptr);
- ASSERT_NE(ifa->ifa_addr, nullptr);
-
- if (ifa->ifa_addr->sa_family != AF_INET) {
- continue;
- }
-
- std::optional<std::pair<int, sockaddr_in>>& if_pair = *[this, ifa]() {
- if (strcmp(ifa->ifa_name, "lo") == 0) {
- return &lo_if_;
- }
- return &eth_if_;
- }();
-
- const int if_index =
- ASSERT_NO_ERRNO_AND_VALUE(InterfaceIndex(ifa->ifa_name));
-
- std::cout << " name=" << ifa->ifa_name
- << " addr=" << GetAddrStr(ifa->ifa_addr) << " index=" << if_index
- << " has_value=" << if_pair.has_value() << std::endl;
-
- if (if_pair.has_value()) {
- continue;
- }
-
- if_pair = std::make_pair(
- if_index, *reinterpret_cast<const sockaddr_in*>(ifa->ifa_addr));
- }
-
- if (!(eth_if_.has_value() && lo_if_.has_value())) {
- // FIXME(b/137899561): Linux instance for syscall tests sometimes misses its
- // IPv4 address on eth0.
- GTEST_SKIP() << " eth_if_.has_value()=" << eth_if_.has_value()
- << " lo_if_.has_value()=" << lo_if_.has_value();
- }
-}
-
-} // namespace testing
-} // namespace gvisor
diff --git a/test/syscalls/linux/socket_ip_udp_unbound_external_networking.h b/test/syscalls/linux/socket_ip_udp_unbound_external_networking.h
index 0387cf8eb..92c20eba9 100644
--- a/test/syscalls/linux/socket_ip_udp_unbound_external_networking.h
+++ b/test/syscalls/linux/socket_ip_udp_unbound_external_networking.h
@@ -16,28 +16,13 @@
#define GVISOR_TEST_SYSCALLS_LINUX_SOCKET_IP_UDP_UNBOUND_EXTERNAL_NETWORKING_H_
#include "test/syscalls/linux/ip_socket_test_util.h"
-#include "test/util/socket_util.h"
namespace gvisor {
namespace testing {
// Test fixture for tests that apply to unbound IP UDP sockets in a sandbox
// with external networking support.
-class IPUDPUnboundExternalNetworkingSocketTest : public SimpleSocketTest {
- protected:
- void SetUp() override;
-
- int lo_if_idx() const { return std::get<0>(lo_if_.value()); }
- int eth_if_idx() const { return std::get<0>(eth_if_.value()); }
-
- const sockaddr_in& lo_if_addr() const { return std::get<1>(lo_if_.value()); }
- const sockaddr_in& eth_if_addr() const {
- return std::get<1>(eth_if_.value());
- }
-
- private:
- std::optional<std::pair<int, sockaddr_in>> lo_if_, eth_if_;
-};
+class IPUDPUnboundExternalNetworkingSocketTest : public SimpleSocketTest {};
} // namespace testing
} // namespace gvisor
diff --git a/test/syscalls/linux/socket_ipv4_udp_unbound_external_networking.cc b/test/syscalls/linux/socket_ipv4_udp_unbound_external_networking.cc
index c198c6563..12e19571b 100644
--- a/test/syscalls/linux/socket_ipv4_udp_unbound_external_networking.cc
+++ b/test/syscalls/linux/socket_ipv4_udp_unbound_external_networking.cc
@@ -14,9 +14,60 @@
#include "test/syscalls/linux/socket_ipv4_udp_unbound_external_networking.h"
+#include "absl/cleanup/cleanup.h"
+#include "test/util/socket_util.h"
+#include "test/util/test_util.h"
+
namespace gvisor {
namespace testing {
+void IPv4UDPUnboundExternalNetworkingSocketTest::SetUp() {
+#ifdef ANDROID
+ GTEST_SKIP() << "Android does not support getifaddrs in r22";
+#endif
+
+ ifaddrs* ifaddr;
+ ASSERT_THAT(getifaddrs(&ifaddr), SyscallSucceeds());
+ auto cleanup = absl::MakeCleanup([ifaddr] { freeifaddrs(ifaddr); });
+
+ for (const ifaddrs* ifa = ifaddr; ifa != nullptr; ifa = ifa->ifa_next) {
+ ASSERT_NE(ifa->ifa_name, nullptr);
+ ASSERT_NE(ifa->ifa_addr, nullptr);
+
+ if (ifa->ifa_addr->sa_family != AF_INET) {
+ continue;
+ }
+
+ std::optional<std::pair<int, sockaddr_in>>& if_pair = *[this, ifa]() {
+ if (strcmp(ifa->ifa_name, "lo") == 0) {
+ return &lo_if_;
+ }
+ return &eth_if_;
+ }();
+
+ const int if_index =
+ ASSERT_NO_ERRNO_AND_VALUE(InterfaceIndex(ifa->ifa_name));
+
+ std::cout << " name=" << ifa->ifa_name
+ << " addr=" << GetAddrStr(ifa->ifa_addr) << " index=" << if_index
+ << " has_value=" << if_pair.has_value() << std::endl;
+
+ if (if_pair.has_value()) {
+ continue;
+ }
+
+ if_pair = std::make_pair(
+ if_index, *reinterpret_cast<const sockaddr_in*>(ifa->ifa_addr));
+ }
+
+ if (!(eth_if_.has_value() && lo_if_.has_value())) {
+ // FIXME(b/137899561): Linux instance for syscall tests sometimes misses its
+ // IPv4 address on eth0.
+ GTEST_SKIP() << " eth_if_.has_value()=" << eth_if_.has_value()
+ << " lo_if_.has_value()=" << lo_if_.has_value();
+ }
+}
+
TestAddress V4EmptyAddress() {
TestAddress t("V4Empty");
t.addr.ss_family = AF_INET;
diff --git a/test/syscalls/linux/socket_ipv4_udp_unbound_external_networking.h b/test/syscalls/linux/socket_ipv4_udp_unbound_external_networking.h
index 20922ac1f..ac917b32c 100644
--- a/test/syscalls/linux/socket_ipv4_udp_unbound_external_networking.h
+++ b/test/syscalls/linux/socket_ipv4_udp_unbound_external_networking.h
@@ -22,8 +22,22 @@ namespace testing {
// Test fixture for tests that apply to unbound IPv4 UDP sockets in a sandbox
// with external networking support.
-using IPv4UDPUnboundExternalNetworkingSocketTest =
- IPUDPUnboundExternalNetworkingSocketTest;
+class IPv4UDPUnboundExternalNetworkingSocketTest
+ : public IPUDPUnboundExternalNetworkingSocketTest {
+ protected:
+ void SetUp() override;
+
+ int lo_if_idx() const { return std::get<0>(lo_if_.value()); }
+ int eth_if_idx() const { return std::get<0>(eth_if_.value()); }
+
+ const sockaddr_in& lo_if_addr() const { return std::get<1>(lo_if_.value()); }
+ const sockaddr_in& eth_if_addr() const {
+ return std::get<1>(eth_if_.value());
+ }
+
+ private:
+ std::optional<std::pair<int, sockaddr_in>> lo_if_, eth_if_;
+};
} // namespace testing
} // namespace gvisor