summaryrefslogtreecommitdiffhomepage
path: root/test/syscalls/linux
diff options
context:
space:
mode:
authorGhanan Gowripalan <ghanan@google.com>2021-07-22 16:34:55 -0700
committergVisor bot <gvisor-bot@google.com>2021-07-22 16:37:15 -0700
commitaa2698170041e9bc00542378269231b5eaeffd5d (patch)
treee033d115eee728364e8cb3bd6e11fe037a25dad0 /test/syscalls/linux
parent24487496a30666103f21c2d42be69d0f8ba2b388 (diff)
Move socket_test_util to //test/util
...and rename the library to socket_util. PiperOrigin-RevId: 386348306
Diffstat (limited to 'test/syscalls/linux')
-rw-r--r--test/syscalls/linux/BUILD228
-rw-r--r--test/syscalls/linux/accept_bind.cc2
-rw-r--r--test/syscalls/linux/accept_bind_stream.cc2
-rw-r--r--test/syscalls/linux/bind.cc2
-rw-r--r--test/syscalls/linux/connect_external.cc2
-rw-r--r--test/syscalls/linux/fallocate.cc2
-rw-r--r--test/syscalls/linux/fcntl.cc2
-rw-r--r--test/syscalls/linux/flock.cc2
-rw-r--r--test/syscalls/linux/ioctl.cc2
-rw-r--r--test/syscalls/linux/ip6tables.cc2
-rw-r--r--test/syscalls/linux/ip_socket_test_util.h2
-rw-r--r--test/syscalls/linux/network_namespace.cc2
-rw-r--r--test/syscalls/linux/packet_socket.cc2
-rw-r--r--test/syscalls/linux/packet_socket_raw.cc2
-rw-r--r--test/syscalls/linux/partial_bad_buffer.cc2
-rw-r--r--test/syscalls/linux/ping_socket.cc2
-rw-r--r--test/syscalls/linux/proc_net.cc2
-rw-r--r--test/syscalls/linux/raw_socket.cc2
-rw-r--r--test/syscalls/linux/raw_socket_hdrincl.cc2
-rw-r--r--test/syscalls/linux/raw_socket_icmp.cc2
-rw-r--r--test/syscalls/linux/readahead.cc2
-rw-r--r--test/syscalls/linux/sendfile_socket.cc2
-rw-r--r--test/syscalls/linux/socket.cc2
-rw-r--r--test/syscalls/linux/socket_abstract.cc2
-rw-r--r--test/syscalls/linux/socket_bind_to_device.cc2
-rw-r--r--test/syscalls/linux/socket_bind_to_device_distribution.cc2
-rw-r--r--test/syscalls/linux/socket_bind_to_device_sequence.cc2
-rw-r--r--test/syscalls/linux/socket_blocking.cc2
-rw-r--r--test/syscalls/linux/socket_blocking.h2
-rw-r--r--test/syscalls/linux/socket_capability.cc2
-rw-r--r--test/syscalls/linux/socket_filesystem.cc2
-rw-r--r--test/syscalls/linux/socket_generic.h2
-rw-r--r--test/syscalls/linux/socket_generic_stress.cc2
-rw-r--r--test/syscalls/linux/socket_generic_test_cases.cc2
-rw-r--r--test/syscalls/linux/socket_inet_loopback.cc2
-rw-r--r--test/syscalls/linux/socket_inet_loopback_isolated.cc2
-rw-r--r--test/syscalls/linux/socket_inet_loopback_nogotsan.cc2
-rw-r--r--test/syscalls/linux/socket_inet_loopback_test_params.h2
-rw-r--r--test/syscalls/linux/socket_ip_loopback_blocking.cc2
-rw-r--r--test/syscalls/linux/socket_ip_tcp_generic.cc2
-rw-r--r--test/syscalls/linux/socket_ip_tcp_generic.h2
-rw-r--r--test/syscalls/linux/socket_ip_tcp_generic_loopback.cc2
-rw-r--r--test/syscalls/linux/socket_ip_tcp_loopback.cc2
-rw-r--r--test/syscalls/linux/socket_ip_tcp_loopback_blocking.cc2
-rw-r--r--test/syscalls/linux/socket_ip_tcp_loopback_nonblock.cc2
-rw-r--r--test/syscalls/linux/socket_ip_tcp_udp_generic.cc2
-rw-r--r--test/syscalls/linux/socket_ip_udp_generic.cc2
-rw-r--r--test/syscalls/linux/socket_ip_udp_generic.h2
-rw-r--r--test/syscalls/linux/socket_ip_udp_loopback.cc2
-rw-r--r--test/syscalls/linux/socket_ip_udp_loopback_blocking.cc2
-rw-r--r--test/syscalls/linux/socket_ip_udp_loopback_nonblock.cc2
-rw-r--r--test/syscalls/linux/socket_ip_udp_unbound_external_networking.cc2
-rw-r--r--test/syscalls/linux/socket_ip_udp_unbound_external_networking.h2
-rw-r--r--test/syscalls/linux/socket_ip_unbound.cc2
-rw-r--r--test/syscalls/linux/socket_ip_unbound_netlink.cc2
-rw-r--r--test/syscalls/linux/socket_ipv4_udp_unbound.cc2
-rw-r--r--test/syscalls/linux/socket_ipv4_udp_unbound.h2
-rw-r--r--test/syscalls/linux/socket_ipv4_udp_unbound_external_networking_test.cc2
-rw-r--r--test/syscalls/linux/socket_ipv4_udp_unbound_loopback.cc2
-rw-r--r--test/syscalls/linux/socket_ipv4_udp_unbound_loopback_netlink.cc2
-rw-r--r--test/syscalls/linux/socket_ipv4_udp_unbound_loopback_nogotsan.cc2
-rw-r--r--test/syscalls/linux/socket_ipv4_udp_unbound_netlink.h2
-rw-r--r--test/syscalls/linux/socket_ipv6_udp_unbound.cc2
-rw-r--r--test/syscalls/linux/socket_ipv6_udp_unbound.h2
-rw-r--r--test/syscalls/linux/socket_ipv6_udp_unbound_external_networking_test.cc2
-rw-r--r--test/syscalls/linux/socket_ipv6_udp_unbound_loopback.cc2
-rw-r--r--test/syscalls/linux/socket_ipv6_udp_unbound_loopback_netlink.cc2
-rw-r--r--test/syscalls/linux/socket_ipv6_udp_unbound_netlink.h2
-rw-r--r--test/syscalls/linux/socket_netdevice.cc2
-rw-r--r--test/syscalls/linux/socket_netlink.cc2
-rw-r--r--test/syscalls/linux/socket_netlink_route.cc2
-rw-r--r--test/syscalls/linux/socket_netlink_uevent.cc2
-rw-r--r--test/syscalls/linux/socket_netlink_util.cc2
-rw-r--r--test/syscalls/linux/socket_non_blocking.cc2
-rw-r--r--test/syscalls/linux/socket_non_blocking.h2
-rw-r--r--test/syscalls/linux/socket_non_stream.cc2
-rw-r--r--test/syscalls/linux/socket_non_stream.h2
-rw-r--r--test/syscalls/linux/socket_non_stream_blocking.cc2
-rw-r--r--test/syscalls/linux/socket_non_stream_blocking.h2
-rw-r--r--test/syscalls/linux/socket_stream.cc2
-rw-r--r--test/syscalls/linux/socket_stream.h2
-rw-r--r--test/syscalls/linux/socket_stream_blocking.cc2
-rw-r--r--test/syscalls/linux/socket_stream_blocking.h2
-rw-r--r--test/syscalls/linux/socket_stream_nonblock.cc2
-rw-r--r--test/syscalls/linux/socket_stream_nonblock.h2
-rw-r--r--test/syscalls/linux/socket_test_util.cc1117
-rw-r--r--test/syscalls/linux/socket_test_util.h591
-rw-r--r--test/syscalls/linux/socket_test_util_impl.cc28
-rw-r--r--test/syscalls/linux/socket_unix.cc2
-rw-r--r--test/syscalls/linux/socket_unix.h2
-rw-r--r--test/syscalls/linux/socket_unix_abstract_nonblock.cc2
-rw-r--r--test/syscalls/linux/socket_unix_blocking_local.cc2
-rw-r--r--test/syscalls/linux/socket_unix_cmsg.cc2
-rw-r--r--test/syscalls/linux/socket_unix_cmsg.h2
-rw-r--r--test/syscalls/linux/socket_unix_dgram.cc2
-rw-r--r--test/syscalls/linux/socket_unix_dgram.h2
-rw-r--r--test/syscalls/linux/socket_unix_dgram_local.cc2
-rw-r--r--test/syscalls/linux/socket_unix_dgram_non_blocking.cc2
-rw-r--r--test/syscalls/linux/socket_unix_domain.cc2
-rw-r--r--test/syscalls/linux/socket_unix_filesystem_nonblock.cc2
-rw-r--r--test/syscalls/linux/socket_unix_non_stream.cc2
-rw-r--r--test/syscalls/linux/socket_unix_non_stream.h2
-rw-r--r--test/syscalls/linux/socket_unix_non_stream_blocking_local.cc2
-rw-r--r--test/syscalls/linux/socket_unix_pair.cc2
-rw-r--r--test/syscalls/linux/socket_unix_pair_nonblock.cc2
-rw-r--r--test/syscalls/linux/socket_unix_seqpacket.cc2
-rw-r--r--test/syscalls/linux/socket_unix_seqpacket.h2
-rw-r--r--test/syscalls/linux/socket_unix_seqpacket_local.cc2
-rw-r--r--test/syscalls/linux/socket_unix_stream.cc2
-rw-r--r--test/syscalls/linux/socket_unix_stream_blocking_local.cc2
-rw-r--r--test/syscalls/linux/socket_unix_stream_local.cc2
-rw-r--r--test/syscalls/linux/socket_unix_stream_nonblock_local.cc2
-rw-r--r--test/syscalls/linux/socket_unix_unbound_abstract.cc2
-rw-r--r--test/syscalls/linux/socket_unix_unbound_dgram.cc2
-rw-r--r--test/syscalls/linux/socket_unix_unbound_filesystem.cc2
-rw-r--r--test/syscalls/linux/socket_unix_unbound_seqpacket.cc2
-rw-r--r--test/syscalls/linux/socket_unix_unbound_stream.cc2
-rw-r--r--test/syscalls/linux/tcp_socket.cc2
-rw-r--r--test/syscalls/linux/tuntap.cc2
-rw-r--r--test/syscalls/linux/udp_bind.cc2
-rw-r--r--test/syscalls/linux/udp_socket.cc2
-rw-r--r--test/syscalls/linux/unix_domain_socket_test_util.h2
122 files changed, 220 insertions, 1980 deletions
diff --git a/test/syscalls/linux/BUILD b/test/syscalls/linux/BUILD
index 9e955f797..7185df076 100644
--- a/test/syscalls/linux/BUILD
+++ b/test/syscalls/linux/BUILD
@@ -1,4 +1,4 @@
-load("//tools:defs.bzl", "cc_binary", "cc_library", "default_net_util", "gbenchmark", "gtest", "select_arch", "select_system")
+load("//tools:defs.bzl", "cc_binary", "cc_library", "gbenchmark", "gtest", "select_arch", "select_system")
package(
default_visibility = ["//:sandbox"],
@@ -128,9 +128,9 @@ cc_library(
srcs = ["socket_netlink_util.cc"],
hdrs = ["socket_netlink_util.h"],
deps = [
- ":socket_test_util",
"//test/util:file_descriptor",
"//test/util:posix_error",
+ "//test/util:socket_util",
"@com_google_absl//absl/strings",
],
)
@@ -146,36 +146,12 @@ cc_library(
)
cc_library(
- name = "socket_test_util",
- testonly = 1,
- srcs = [
- "socket_test_util.cc",
- "socket_test_util_impl.cc",
- ],
- hdrs = ["socket_test_util.h"],
- defines = select_system(),
- deps = default_net_util() + [
- gtest,
- "@com_google_absl//absl/memory",
- "@com_google_absl//absl/strings",
- "@com_google_absl//absl/strings:str_format",
- "@com_google_absl//absl/time",
- "@com_google_absl//absl/types:optional",
- "//test/util:file_descriptor",
- "//test/util:posix_error",
- "//test/util:temp_path",
- "//test/util:test_util",
- "//test/util:thread_util",
- ],
-)
-
-cc_library(
name = "unix_domain_socket_test_util",
testonly = 1,
srcs = ["unix_domain_socket_test_util.cc"],
hdrs = ["unix_domain_socket_test_util.h"],
deps = [
- ":socket_test_util",
+ "//test/util:socket_util",
"@com_google_absl//absl/strings",
gtest,
"//test/util:test_util",
@@ -188,7 +164,7 @@ cc_library(
srcs = ["ip_socket_test_util.cc"],
hdrs = ["ip_socket_test_util.h"],
deps = [
- ":socket_test_util",
+ "//test/util:socket_util",
"@com_google_absl//absl/strings",
],
)
@@ -233,9 +209,9 @@ cc_binary(
srcs = ["accept_bind.cc"],
linkstatic = 1,
deps = [
- ":socket_test_util",
":unix_domain_socket_test_util",
"//test/util:file_descriptor",
+ "//test/util:socket_util",
gtest,
"//test/util:test_main",
"//test/util:test_util",
@@ -248,9 +224,9 @@ cc_binary(
srcs = ["accept_bind_stream.cc"],
linkstatic = 1,
deps = [
- ":socket_test_util",
":unix_domain_socket_test_util",
"//test/util:file_descriptor",
+ "//test/util:socket_util",
gtest,
"//test/util:test_main",
"//test/util:test_util",
@@ -349,8 +325,8 @@ cc_binary(
srcs = ["bind.cc"],
linkstatic = 1,
deps = [
- ":socket_test_util",
":unix_domain_socket_test_util",
+ "//test/util:socket_util",
gtest,
"//test/util:test_main",
"//test/util:test_util",
@@ -363,7 +339,7 @@ cc_binary(
srcs = ["socket.cc"],
linkstatic = 1,
deps = [
- ":socket_test_util",
+ "//test/util:socket_util",
gtest,
"//test/util:file_descriptor",
"//test/util:temp_umask",
@@ -378,9 +354,9 @@ cc_binary(
srcs = ["socket_capability.cc"],
linkstatic = 1,
deps = [
- ":socket_test_util",
"//test/util:capability_util",
"//test/util:file_descriptor",
+ "//test/util:socket_util",
gtest,
"//test/util:test_main",
"//test/util:test_util",
@@ -540,9 +516,9 @@ cc_binary(
srcs = ["connect_external.cc"],
linkstatic = 1,
deps = [
- ":socket_test_util",
"//test/util:file_descriptor",
"//test/util:fs_util",
+ "//test/util:socket_util",
gtest,
"//test/util:test_main",
"//test/util:test_util",
@@ -755,10 +731,10 @@ cc_binary(
linkstatic = 1,
deps = [
":file_base",
- ":socket_test_util",
"//test/util:cleanup",
"//test/util:eventfd_util",
"//test/util:file_descriptor",
+ "//test/util:socket_util",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/time",
gtest,
@@ -801,12 +777,12 @@ cc_binary(
srcs = ["fcntl.cc"],
linkstatic = 1,
deps = [
- ":socket_test_util",
"//test/util:capability_util",
"//test/util:cleanup",
"//test/util:eventfd_util",
"//test/util:file_descriptor",
"//test/util:fs_util",
+ "//test/util:socket_util",
"@com_google_absl//absl/base:core_headers",
"@com_google_absl//absl/flags:flag",
"@com_google_absl//absl/memory",
@@ -834,8 +810,8 @@ cc_binary(
],
linkstatic = 1,
deps = [
- ":socket_test_util",
"//test/util:file_descriptor",
+ "//test/util:socket_util",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/time",
gtest,
@@ -1021,9 +997,9 @@ cc_binary(
linkstatic = 1,
deps = [
":ip_socket_test_util",
- ":socket_test_util",
":unix_domain_socket_test_util",
"//test/util:file_descriptor",
+ "//test/util:socket_util",
gtest,
"//test/util:signal_util",
"//test/util:test_main",
@@ -1065,9 +1041,9 @@ cc_binary(
linkstatic = 1,
deps = [
":iptables_types",
- ":socket_test_util",
"//test/util:capability_util",
"//test/util:file_descriptor",
+ "//test/util:socket_util",
gtest,
"//test/util:test_main",
"//test/util:test_util",
@@ -1083,9 +1059,9 @@ cc_binary(
linkstatic = 1,
deps = [
":iptables_types",
- ":socket_test_util",
"//test/util:capability_util",
"//test/util:file_descriptor",
+ "//test/util:socket_util",
gtest,
"//test/util:test_main",
"//test/util:test_util",
@@ -1464,10 +1440,10 @@ cc_binary(
defines = select_system(),
linkstatic = 1,
deps = [
- ":socket_test_util",
":unix_domain_socket_test_util",
"//test/util:capability_util",
"//test/util:file_descriptor",
+ "//test/util:socket_util",
"@com_google_absl//absl/base:core_headers",
"@com_google_absl//absl/base:endian",
gtest,
@@ -1482,10 +1458,10 @@ cc_binary(
srcs = ["packet_socket.cc"],
linkstatic = 1,
deps = [
- ":socket_test_util",
":unix_domain_socket_test_util",
"//test/util:capability_util",
"//test/util:file_descriptor",
+ "//test/util:socket_util",
"@com_google_absl//absl/base:core_headers",
"@com_google_absl//absl/base:endian",
gtest,
@@ -1541,9 +1517,9 @@ cc_binary(
srcs = select_system(linux = ["partial_bad_buffer.cc"]),
linkstatic = 1,
deps = [
- ":socket_test_util",
"//test/util:file_descriptor",
"//test/util:fs_util",
+ "//test/util:socket_util",
"@com_google_absl//absl/time",
gtest,
"//test/util:posix_error",
@@ -1576,8 +1552,8 @@ cc_binary(
linkstatic = 1,
deps = [
":ip_socket_test_util",
- ":socket_test_util",
"//test/util:file_descriptor",
+ "//test/util:socket_util",
"@com_google_absl//absl/algorithm:container",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/types:optional",
@@ -1795,10 +1771,10 @@ cc_binary(
srcs = ["proc_net.cc"],
linkstatic = 1,
deps = [
- ":socket_test_util",
"//test/util:capability_util",
"//test/util:file_descriptor",
"//test/util:fs_util",
+ "//test/util:socket_util",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/time",
gtest,
@@ -1942,10 +1918,10 @@ cc_binary(
srcs = ["raw_socket_hdrincl.cc"],
linkstatic = 1,
deps = [
- ":socket_test_util",
":unix_domain_socket_test_util",
"//test/util:capability_util",
"//test/util:file_descriptor",
+ "//test/util:socket_util",
"@com_google_absl//absl/base:core_headers",
"@com_google_absl//absl/base:endian",
gtest,
@@ -1961,10 +1937,10 @@ cc_binary(
defines = select_system(),
linkstatic = 1,
deps = [
- ":socket_test_util",
":unix_domain_socket_test_util",
"//test/util:capability_util",
"//test/util:file_descriptor",
+ "//test/util:socket_util",
"@com_google_absl//absl/base:core_headers",
gtest,
"//test/util:test_main",
@@ -1978,10 +1954,10 @@ cc_binary(
srcs = ["raw_socket_icmp.cc"],
linkstatic = 1,
deps = [
- ":socket_test_util",
":unix_domain_socket_test_util",
"//test/util:capability_util",
"//test/util:file_descriptor",
+ "//test/util:socket_util",
"@com_google_absl//absl/base:core_headers",
gtest,
"//test/util:test_main",
@@ -2011,8 +1987,8 @@ cc_binary(
srcs = ["readahead.cc"],
linkstatic = 1,
deps = [
- ":socket_test_util",
"//test/util:file_descriptor",
+ "//test/util:socket_util",
gtest,
"//test/util:temp_path",
"//test/util:test_main",
@@ -2211,8 +2187,8 @@ cc_binary(
srcs = ["sendfile_socket.cc"],
linkstatic = 1,
deps = [
- ":socket_test_util",
"//test/util:file_descriptor",
+ "//test/util:socket_util",
"@com_google_absl//absl/strings",
gtest,
":ip_socket_test_util",
@@ -2390,8 +2366,8 @@ cc_library(
"socket_generic.h",
],
deps = [
- ":socket_test_util",
":unix_domain_socket_test_util",
+ "//test/util:socket_util",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/strings:str_format",
gtest,
@@ -2411,8 +2387,8 @@ cc_binary(
deps = [
gtest,
":ip_socket_test_util",
- ":socket_test_util",
"//test/util:file_descriptor",
+ "//test/util:socket_util",
"//test/util:test_main",
"//test/util:test_util",
"//test/util:thread_util",
@@ -2427,8 +2403,8 @@ cc_library(
srcs = ["socket_unix_dgram.cc"],
hdrs = ["socket_unix_dgram.h"],
deps = [
- ":socket_test_util",
":unix_domain_socket_test_util",
+ "//test/util:socket_util",
"@com_google_absl//absl/time",
gtest,
"//test/util:test_util",
@@ -2442,8 +2418,8 @@ cc_library(
srcs = ["socket_unix_seqpacket.cc"],
hdrs = ["socket_unix_seqpacket.h"],
deps = [
- ":socket_test_util",
":unix_domain_socket_test_util",
+ "//test/util:socket_util",
"@com_google_absl//absl/time",
gtest,
"//test/util:test_util",
@@ -2461,7 +2437,7 @@ cc_library(
"socket_ip_tcp_generic.h",
],
deps = [
- ":socket_test_util",
+ "//test/util:socket_util",
"@com_google_absl//absl/memory",
"@com_google_absl//absl/time",
gtest,
@@ -2482,8 +2458,8 @@ cc_library(
"socket_non_blocking.h",
],
deps = [
- ":socket_test_util",
":unix_domain_socket_test_util",
+ "//test/util:socket_util",
gtest,
"//test/util:test_util",
],
@@ -2500,8 +2476,8 @@ cc_library(
"socket_unix_non_stream.h",
],
deps = [
- ":socket_test_util",
":unix_domain_socket_test_util",
+ "//test/util:socket_util",
gtest,
"//test/util:memory_util",
"//test/util:test_util",
@@ -2520,8 +2496,8 @@ cc_library(
],
deps = [
":ip_socket_test_util",
- ":socket_test_util",
":unix_domain_socket_test_util",
+ "//test/util:socket_util",
gtest,
"//test/util:test_util",
],
@@ -2539,7 +2515,7 @@ cc_library(
],
deps = [
":ip_socket_test_util",
- ":socket_test_util",
+ "//test/util:socket_util",
gtest,
"//test/util:test_util",
],
@@ -2557,7 +2533,7 @@ cc_library(
],
deps = [
":ip_socket_test_util",
- ":socket_test_util",
+ "//test/util:socket_util",
"@com_google_absl//absl/memory",
gtest,
"//test/util:posix_error",
@@ -2578,7 +2554,7 @@ cc_library(
],
deps = [
":ip_socket_test_util",
- ":socket_test_util",
+ "//test/util:socket_util",
"@com_google_absl//absl/memory",
gtest,
"//test/util:posix_error",
@@ -2599,9 +2575,9 @@ cc_library(
],
deps = [
":socket_netlink_route_util",
- ":socket_test_util",
"//test/util:capability_util",
"//test/util:cleanup",
+ "//test/util:socket_util",
gtest,
],
alwayslink = 1,
@@ -2618,8 +2594,8 @@ cc_library(
],
deps = [
":socket_netlink_route_util",
- ":socket_test_util",
"//test/util:capability_util",
+ "//test/util:socket_util",
gtest,
],
alwayslink = 1,
@@ -2636,7 +2612,7 @@ cc_library(
],
deps = [
":ip_socket_test_util",
- ":socket_test_util",
+ "//test/util:socket_util",
"//test/util:test_util",
],
alwayslink = 1,
@@ -2683,10 +2659,10 @@ cc_binary(
linkstatic = 1,
deps = [
":socket_generic_test_cases",
- ":socket_test_util",
":socket_unix_cmsg_test_cases",
":socket_unix_test_cases",
":unix_domain_socket_test_util",
+ "//test/util:socket_util",
"//test/util:test_main",
"//test/util:test_util",
],
@@ -2701,8 +2677,8 @@ cc_binary(
linkstatic = 1,
deps = [
":socket_non_blocking_test_cases",
- ":socket_test_util",
":unix_domain_socket_test_util",
+ "//test/util:socket_util",
"//test/util:test_main",
"//test/util:test_util",
],
@@ -2715,10 +2691,10 @@ cc_binary(
linkstatic = 1,
deps = [
":socket_non_stream_test_cases",
- ":socket_test_util",
":socket_unix_dgram_test_cases",
":socket_unix_non_stream_test_cases",
":unix_domain_socket_test_util",
+ "//test/util:socket_util",
"//test/util:test_main",
"//test/util:test_util",
],
@@ -2730,8 +2706,8 @@ cc_binary(
srcs = ["socket_unix_dgram_non_blocking.cc"],
linkstatic = 1,
deps = [
- ":socket_test_util",
":unix_domain_socket_test_util",
+ "//test/util:socket_util",
gtest,
"//test/util:test_main",
"//test/util:test_util",
@@ -2747,10 +2723,10 @@ cc_binary(
linkstatic = 1,
deps = [
":socket_non_stream_test_cases",
- ":socket_test_util",
":socket_unix_non_stream_test_cases",
":socket_unix_seqpacket_test_cases",
":unix_domain_socket_test_util",
+ "//test/util:socket_util",
"//test/util:test_main",
"//test/util:test_util",
],
@@ -2762,8 +2738,8 @@ cc_binary(
srcs = ["socket_unix_stream.cc"],
linkstatic = 1,
deps = [
- ":socket_test_util",
":unix_domain_socket_test_util",
+ "//test/util:socket_util",
"@com_google_absl//absl/time",
gtest,
"//test/util:test_main",
@@ -2781,7 +2757,7 @@ cc_binary(
deps = [
":ip_socket_test_util",
":socket_ip_tcp_generic_test_cases",
- ":socket_test_util",
+ "//test/util:socket_util",
"//test/util:test_main",
"//test/util:test_util",
],
@@ -2796,7 +2772,7 @@ cc_binary(
linkstatic = 1,
deps = [
":ip_socket_test_util",
- ":socket_test_util",
+ "//test/util:socket_util",
gtest,
"//test/util:test_main",
"//test/util:test_util",
@@ -2813,7 +2789,7 @@ cc_binary(
deps = [
":ip_socket_test_util",
":socket_generic_test_cases",
- ":socket_test_util",
+ "//test/util:socket_util",
"//test/util:test_main",
"//test/util:test_util",
],
@@ -2829,7 +2805,7 @@ cc_binary(
deps = [
":ip_socket_test_util",
":socket_non_blocking_test_cases",
- ":socket_test_util",
+ "//test/util:socket_util",
"//test/util:test_main",
"//test/util:test_util",
],
@@ -2847,7 +2823,7 @@ cc_binary(
":socket_generic_test_cases",
":socket_ip_udp_test_cases",
":socket_non_stream_test_cases",
- ":socket_test_util",
+ "//test/util:socket_util",
"//test/util:test_main",
"//test/util:test_util",
],
@@ -2863,7 +2839,7 @@ cc_binary(
deps = [
":ip_socket_test_util",
":socket_ipv4_udp_unbound_external_networking_test_cases",
- ":socket_test_util",
+ "//test/util:socket_util",
"//test/util:test_main",
"//test/util:test_util",
],
@@ -2879,7 +2855,7 @@ cc_binary(
deps = [
":ip_socket_test_util",
":socket_ipv6_udp_unbound_external_networking_test_cases",
- ":socket_test_util",
+ "//test/util:socket_util",
"//test/util:test_main",
"//test/util:test_util",
],
@@ -2895,8 +2871,8 @@ cc_binary(
deps = [
":ip_socket_test_util",
":socket_bind_to_device_util",
- ":socket_test_util",
"//test/util:capability_util",
+ "//test/util:socket_util",
gtest,
"//test/util:test_main",
"//test/util:test_util",
@@ -2914,8 +2890,8 @@ cc_binary(
deps = [
":ip_socket_test_util",
":socket_bind_to_device_util",
- ":socket_test_util",
"//test/util:capability_util",
+ "//test/util:socket_util",
"@com_google_absl//absl/container:node_hash_map",
gtest,
"//test/util:test_main",
@@ -2934,8 +2910,8 @@ cc_binary(
deps = [
":ip_socket_test_util",
":socket_bind_to_device_util",
- ":socket_test_util",
"//test/util:capability_util",
+ "//test/util:socket_util",
gtest,
"//test/util:test_main",
"//test/util:test_util",
@@ -2953,7 +2929,7 @@ cc_binary(
deps = [
":ip_socket_test_util",
":socket_non_blocking_test_cases",
- ":socket_test_util",
+ "//test/util:socket_util",
"//test/util:test_main",
"//test/util:test_util",
],
@@ -2969,7 +2945,7 @@ cc_binary(
deps = [
":ip_socket_test_util",
":socket_ipv4_udp_unbound_test_cases",
- ":socket_test_util",
+ "//test/util:socket_util",
"//test/util:test_main",
"//test/util:test_util",
],
@@ -2985,7 +2961,7 @@ cc_binary(
deps = [
":ip_socket_test_util",
":socket_ipv6_udp_unbound_test_cases",
- ":socket_test_util",
+ "//test/util:socket_util",
"//test/util:test_main",
"//test/util:test_util",
],
@@ -3000,7 +2976,7 @@ cc_binary(
linkstatic = 1,
deps = [
":ip_socket_test_util",
- ":socket_test_util",
+ "//test/util:socket_util",
gtest,
"//test/util:test_main",
"//test/util:test_util",
@@ -3018,7 +2994,7 @@ cc_binary(
deps = [
":ip_socket_test_util",
":socket_ipv4_udp_unbound_netlink_test_cases",
- ":socket_test_util",
+ "//test/util:socket_util",
"//test/util:test_main",
"//test/util:test_util",
],
@@ -3034,7 +3010,7 @@ cc_binary(
deps = [
":ip_socket_test_util",
":socket_ipv6_udp_unbound_netlink_test_cases",
- ":socket_test_util",
+ "//test/util:socket_util",
"//test/util:test_main",
"//test/util:test_util",
],
@@ -3049,7 +3025,7 @@ cc_binary(
linkstatic = 1,
deps = [
":ip_socket_test_util",
- ":socket_test_util",
+ "//test/util:socket_util",
gtest,
"//test/util:test_main",
"//test/util:test_util",
@@ -3066,8 +3042,8 @@ cc_binary(
deps = [
":ip_socket_test_util",
":socket_netlink_route_util",
- ":socket_test_util",
"//test/util:capability_util",
+ "//test/util:socket_util",
gtest,
"//test/util:test_main",
"//test/util:test_util",
@@ -3083,8 +3059,8 @@ cc_binary(
linkstatic = 1,
deps = [
":socket_generic_test_cases",
- ":socket_test_util",
":unix_domain_socket_test_util",
+ "//test/util:socket_util",
"//test/util:test_main",
"//test/util:test_util",
],
@@ -3099,8 +3075,8 @@ cc_binary(
linkstatic = 1,
deps = [
":socket_non_blocking_test_cases",
- ":socket_test_util",
":unix_domain_socket_test_util",
+ "//test/util:socket_util",
"//test/util:test_main",
"//test/util:test_util",
],
@@ -3115,10 +3091,10 @@ cc_binary(
linkstatic = 1,
deps = [
":socket_generic_test_cases",
- ":socket_test_util",
":socket_unix_cmsg_test_cases",
":socket_unix_test_cases",
":unix_domain_socket_test_util",
+ "//test/util:socket_util",
"//test/util:test_main",
"//test/util:test_util",
],
@@ -3133,8 +3109,8 @@ cc_binary(
linkstatic = 1,
deps = [
":socket_non_blocking_test_cases",
- ":socket_test_util",
":unix_domain_socket_test_util",
+ "//test/util:socket_util",
"//test/util:test_main",
"//test/util:test_util",
],
@@ -3145,7 +3121,7 @@ cc_library(
testonly = 1,
hdrs = ["socket_inet_loopback_test_params.h"],
deps = [
- ":socket_test_util",
+ "//test/util:socket_util",
gtest,
],
)
@@ -3158,8 +3134,8 @@ cc_binary(
deps = [
":ip_socket_test_util",
":socket_inet_loopback_test_params",
- ":socket_test_util",
"//test/util:file_descriptor",
+ "//test/util:socket_util",
"@com_google_absl//absl/memory",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/time",
@@ -3180,8 +3156,8 @@ cc_binary(
deps = [
":ip_socket_test_util",
":socket_inet_loopback_test_params",
- ":socket_test_util",
"//test/util:file_descriptor",
+ "//test/util:socket_util",
"@com_google_absl//absl/strings",
gtest,
"//test/util:posix_error",
@@ -3199,7 +3175,7 @@ cc_binary(
deps = [
":socket_inet_loopback_test_params",
":socket_netlink_util",
- ":socket_test_util",
+ "//test/util:socket_util",
gtest,
"//test/util:test_main",
"//test/util:test_util",
@@ -3213,8 +3189,8 @@ cc_binary(
srcs = ["socket_netlink.cc"],
linkstatic = 1,
deps = [
- ":socket_test_util",
"//test/util:file_descriptor",
+ "//test/util:socket_util",
gtest,
"//test/util:test_main",
"//test/util:test_util",
@@ -3229,10 +3205,10 @@ cc_binary(
deps = [
":socket_netlink_route_util",
":socket_netlink_util",
- ":socket_test_util",
"//test/util:capability_util",
"//test/util:cleanup",
"//test/util:file_descriptor",
+ "//test/util:socket_util",
"@com_google_absl//absl/strings:str_format",
gtest,
"//test/util:test_main",
@@ -3247,8 +3223,8 @@ cc_binary(
linkstatic = 1,
deps = [
":socket_netlink_util",
- ":socket_test_util",
"//test/util:file_descriptor",
+ "//test/util:socket_util",
gtest,
"//test/util:test_main",
"//test/util:test_util",
@@ -3267,8 +3243,8 @@ cc_library(
"socket_stream.h",
],
deps = [
- ":socket_test_util",
":unix_domain_socket_test_util",
+ "//test/util:socket_util",
"@com_google_absl//absl/time",
gtest,
"//test/util:test_util",
@@ -3286,8 +3262,8 @@ cc_library(
"socket_blocking.h",
],
deps = [
- ":socket_test_util",
":unix_domain_socket_test_util",
+ "//test/util:socket_util",
"@com_google_absl//absl/time",
gtest,
"//test/util:test_util",
@@ -3307,8 +3283,8 @@ cc_library(
"socket_unix.h",
],
deps = [
- ":socket_test_util",
":unix_domain_socket_test_util",
+ "//test/util:socket_util",
"@com_google_absl//absl/strings",
gtest,
"//test/util:test_util",
@@ -3327,8 +3303,8 @@ cc_library(
"socket_unix_cmsg.h",
],
deps = [
- ":socket_test_util",
":unix_domain_socket_test_util",
+ "//test/util:socket_util",
"@com_google_absl//absl/strings",
gtest,
"//test/util:test_util",
@@ -3347,8 +3323,8 @@ cc_library(
"socket_stream_blocking.h",
],
deps = [
- ":socket_test_util",
":unix_domain_socket_test_util",
+ "//test/util:socket_util",
"@com_google_absl//absl/time",
gtest,
"//test/util:test_util",
@@ -3368,8 +3344,8 @@ cc_library(
"socket_stream_nonblock.h",
],
deps = [
- ":socket_test_util",
":unix_domain_socket_test_util",
+ "//test/util:socket_util",
gtest,
"//test/util:test_util",
],
@@ -3386,8 +3362,8 @@ cc_library(
"socket_non_stream_blocking.h",
],
deps = [
- ":socket_test_util",
":unix_domain_socket_test_util",
+ "//test/util:socket_util",
"@com_google_absl//absl/time",
gtest,
"//test/util:test_util",
@@ -3422,8 +3398,8 @@ cc_binary(
linkstatic = 1,
deps = [
":socket_stream_test_cases",
- ":socket_test_util",
":unix_domain_socket_test_util",
+ "//test/util:socket_util",
"//test/util:test_main",
"//test/util:test_util",
],
@@ -3438,8 +3414,8 @@ cc_binary(
linkstatic = 1,
deps = [
":socket_stream_blocking_test_cases",
- ":socket_test_util",
":unix_domain_socket_test_util",
+ "//test/util:socket_util",
"//test/util:test_main",
"//test/util:test_util",
],
@@ -3455,7 +3431,7 @@ cc_binary(
deps = [
":ip_socket_test_util",
":socket_stream_blocking_test_cases",
- ":socket_test_util",
+ "//test/util:socket_util",
"//test/util:test_main",
"//test/util:test_util",
],
@@ -3470,8 +3446,8 @@ cc_binary(
linkstatic = 1,
deps = [
":socket_stream_nonblocking_test_cases",
- ":socket_test_util",
":unix_domain_socket_test_util",
+ "//test/util:socket_util",
"//test/util:test_main",
"//test/util:test_util",
],
@@ -3483,8 +3459,8 @@ cc_binary(
srcs = ["socket_unix_unbound_dgram.cc"],
linkstatic = 1,
deps = [
- ":socket_test_util",
":unix_domain_socket_test_util",
+ "//test/util:socket_util",
gtest,
"//test/util:test_main",
"//test/util:test_util",
@@ -3497,8 +3473,8 @@ cc_binary(
srcs = ["socket_unix_unbound_abstract.cc"],
linkstatic = 1,
deps = [
- ":socket_test_util",
":unix_domain_socket_test_util",
+ "//test/util:socket_util",
gtest,
"//test/util:test_main",
"//test/util:test_util",
@@ -3511,8 +3487,8 @@ cc_binary(
srcs = ["socket_unix_unbound_filesystem.cc"],
linkstatic = 1,
deps = [
- ":socket_test_util",
":unix_domain_socket_test_util",
+ "//test/util:socket_util",
gtest,
"//test/util:file_descriptor",
"//test/util:test_main",
@@ -3529,8 +3505,8 @@ cc_binary(
linkstatic = 1,
deps = [
":socket_blocking_test_cases",
- ":socket_test_util",
":unix_domain_socket_test_util",
+ "//test/util:socket_util",
gtest,
"//test/util:test_main",
"//test/util:test_util",
@@ -3547,7 +3523,7 @@ cc_binary(
deps = [
":ip_socket_test_util",
":socket_blocking_test_cases",
- ":socket_test_util",
+ "//test/util:socket_util",
gtest,
"//test/util:test_main",
"//test/util:test_util",
@@ -3563,8 +3539,8 @@ cc_binary(
linkstatic = 1,
deps = [
":socket_non_stream_blocking_test_cases",
- ":socket_test_util",
":unix_domain_socket_test_util",
+ "//test/util:socket_util",
gtest,
"//test/util:test_main",
"//test/util:test_util",
@@ -3581,7 +3557,7 @@ cc_binary(
deps = [
":ip_socket_test_util",
":socket_non_stream_blocking_test_cases",
- ":socket_test_util",
+ "//test/util:socket_util",
gtest,
"//test/util:test_main",
"//test/util:test_util",
@@ -3596,10 +3572,10 @@ cc_binary(
],
linkstatic = 1,
deps = [
- ":socket_test_util",
":socket_unix_cmsg_test_cases",
":socket_unix_test_cases",
":unix_domain_socket_test_util",
+ "//test/util:socket_util",
gtest,
"//test/util:test_main",
"//test/util:test_util",
@@ -3612,8 +3588,8 @@ cc_binary(
srcs = ["socket_unix_unbound_seqpacket.cc"],
linkstatic = 1,
deps = [
- ":socket_test_util",
":unix_domain_socket_test_util",
+ "//test/util:socket_util",
gtest,
"//test/util:test_main",
"//test/util:test_util",
@@ -3626,8 +3602,8 @@ cc_binary(
srcs = ["socket_unix_unbound_stream.cc"],
linkstatic = 1,
deps = [
- ":socket_test_util",
":unix_domain_socket_test_util",
+ "//test/util:socket_util",
gtest,
"//test/util:test_main",
"//test/util:test_util",
@@ -3641,8 +3617,8 @@ cc_binary(
linkstatic = 1,
deps = [
":socket_netlink_util",
- ":socket_test_util",
"//test/util:file_descriptor",
+ "//test/util:socket_util",
"@com_google_absl//absl/base:endian",
gtest,
"//test/util:test_main",
@@ -3799,8 +3775,8 @@ cc_binary(
defines = select_system(),
linkstatic = 1,
deps = [
- ":socket_test_util",
"//test/util:file_descriptor",
+ "//test/util:socket_util",
"@com_google_absl//absl/time",
gtest,
"//test/util:posix_error",
@@ -3910,7 +3886,7 @@ cc_binary(
srcs = ["tuntap.cc"],
linkstatic = 1,
deps = [
- ":socket_test_util",
+ "//test/util:socket_util",
gtest,
":socket_netlink_route_util",
"//test/util:capability_util",
@@ -3943,8 +3919,8 @@ cc_binary(
linkstatic = 1,
deps = [
":ip_socket_test_util",
- ":socket_test_util",
":unix_domain_socket_test_util",
+ "//test/util:socket_util",
"@com_google_absl//absl/base:core_headers",
"@com_google_absl//absl/strings:str_format",
"@com_google_absl//absl/time",
@@ -3963,8 +3939,8 @@ cc_binary(
srcs = ["udp_bind.cc"],
linkstatic = 1,
deps = [
- ":socket_test_util",
"//test/util:file_descriptor",
+ "//test/util:socket_util",
gtest,
"//test/util:test_main",
"//test/util:test_util",
@@ -4144,7 +4120,7 @@ cc_binary(
srcs = ["network_namespace.cc"],
linkstatic = 1,
deps = [
- ":socket_test_util",
+ "//test/util:socket_util",
gtest,
"//test/util:capability_util",
"//test/util:posix_error",
diff --git a/test/syscalls/linux/accept_bind.cc b/test/syscalls/linux/accept_bind.cc
index ba3747290..0d16d1d83 100644
--- a/test/syscalls/linux/accept_bind.cc
+++ b/test/syscalls/linux/accept_bind.cc
@@ -20,9 +20,9 @@
#include <vector>
#include "gtest/gtest.h"
-#include "test/syscalls/linux/socket_test_util.h"
#include "test/syscalls/linux/unix_domain_socket_test_util.h"
#include "test/util/file_descriptor.h"
+#include "test/util/socket_util.h"
#include "test/util/test_util.h"
namespace gvisor {
diff --git a/test/syscalls/linux/accept_bind_stream.cc b/test/syscalls/linux/accept_bind_stream.cc
index 4857f160b..5f2b07105 100644
--- a/test/syscalls/linux/accept_bind_stream.cc
+++ b/test/syscalls/linux/accept_bind_stream.cc
@@ -19,9 +19,9 @@
#include <vector>
#include "gtest/gtest.h"
-#include "test/syscalls/linux/socket_test_util.h"
#include "test/syscalls/linux/unix_domain_socket_test_util.h"
#include "test/util/file_descriptor.h"
+#include "test/util/socket_util.h"
#include "test/util/test_util.h"
namespace gvisor {
diff --git a/test/syscalls/linux/bind.cc b/test/syscalls/linux/bind.cc
index 9547c4ab2..8e1d00619 100644
--- a/test/syscalls/linux/bind.cc
+++ b/test/syscalls/linux/bind.cc
@@ -17,8 +17,8 @@
#include <sys/un.h>
#include "gtest/gtest.h"
-#include "test/syscalls/linux/socket_test_util.h"
#include "test/syscalls/linux/unix_domain_socket_test_util.h"
+#include "test/util/socket_util.h"
#include "test/util/test_util.h"
namespace gvisor {
diff --git a/test/syscalls/linux/connect_external.cc b/test/syscalls/linux/connect_external.cc
index 1edb50e47..fb2476da4 100644
--- a/test/syscalls/linux/connect_external.cc
+++ b/test/syscalls/linux/connect_external.cc
@@ -22,9 +22,9 @@
#include <tuple>
#include "gtest/gtest.h"
-#include "test/syscalls/linux/socket_test_util.h"
#include "test/util/file_descriptor.h"
#include "test/util/fs_util.h"
+#include "test/util/socket_util.h"
#include "test/util/test_util.h"
// This file contains tests specific to connecting to host UDS managed outside
diff --git a/test/syscalls/linux/fallocate.cc b/test/syscalls/linux/fallocate.cc
index 5c839447e..5f1b4d5e5 100644
--- a/test/syscalls/linux/fallocate.cc
+++ b/test/syscalls/linux/fallocate.cc
@@ -31,11 +31,11 @@
#include "absl/strings/str_cat.h"
#include "absl/time/time.h"
#include "test/syscalls/linux/file_base.h"
-#include "test/syscalls/linux/socket_test_util.h"
#include "test/util/cleanup.h"
#include "test/util/eventfd_util.h"
#include "test/util/file_descriptor.h"
#include "test/util/posix_error.h"
+#include "test/util/socket_util.h"
#include "test/util/temp_path.h"
#include "test/util/test_util.h"
diff --git a/test/syscalls/linux/fcntl.cc b/test/syscalls/linux/fcntl.cc
index 91526572b..0e78a4d4a 100644
--- a/test/syscalls/linux/fcntl.cc
+++ b/test/syscalls/linux/fcntl.cc
@@ -35,7 +35,6 @@
#include "absl/strings/str_cat.h"
#include "absl/time/clock.h"
#include "absl/time/time.h"
-#include "test/syscalls/linux/socket_test_util.h"
#include "test/util/capability_util.h"
#include "test/util/cleanup.h"
#include "test/util/eventfd_util.h"
@@ -46,6 +45,7 @@
#include "test/util/posix_error.h"
#include "test/util/save_util.h"
#include "test/util/signal_util.h"
+#include "test/util/socket_util.h"
#include "test/util/temp_path.h"
#include "test/util/test_util.h"
#include "test/util/thread_util.h"
diff --git a/test/syscalls/linux/flock.cc b/test/syscalls/linux/flock.cc
index 10dad042f..686b779be 100644
--- a/test/syscalls/linux/flock.cc
+++ b/test/syscalls/linux/flock.cc
@@ -21,8 +21,8 @@
#include "absl/time/clock.h"
#include "absl/time/time.h"
#include "test/syscalls/linux/file_base.h"
-#include "test/syscalls/linux/socket_test_util.h"
#include "test/util/file_descriptor.h"
+#include "test/util/socket_util.h"
#include "test/util/temp_path.h"
#include "test/util/test_util.h"
#include "test/util/thread_util.h"
diff --git a/test/syscalls/linux/ioctl.cc b/test/syscalls/linux/ioctl.cc
index 9b16d1558..88056ef2e 100644
--- a/test/syscalls/linux/ioctl.cc
+++ b/test/syscalls/linux/ioctl.cc
@@ -26,10 +26,10 @@
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "test/syscalls/linux/ip_socket_test_util.h"
-#include "test/syscalls/linux/socket_test_util.h"
#include "test/syscalls/linux/unix_domain_socket_test_util.h"
#include "test/util/file_descriptor.h"
#include "test/util/signal_util.h"
+#include "test/util/socket_util.h"
#include "test/util/test_util.h"
namespace gvisor {
diff --git a/test/syscalls/linux/ip6tables.cc b/test/syscalls/linux/ip6tables.cc
index e0e146067..d11b45d4a 100644
--- a/test/syscalls/linux/ip6tables.cc
+++ b/test/syscalls/linux/ip6tables.cc
@@ -17,9 +17,9 @@
#include "gtest/gtest.h"
#include "test/syscalls/linux/iptables.h"
-#include "test/syscalls/linux/socket_test_util.h"
#include "test/util/capability_util.h"
#include "test/util/file_descriptor.h"
+#include "test/util/socket_util.h"
#include "test/util/test_util.h"
namespace gvisor {
diff --git a/test/syscalls/linux/ip_socket_test_util.h b/test/syscalls/linux/ip_socket_test_util.h
index bde481f7e..8f26f1cd0 100644
--- a/test/syscalls/linux/ip_socket_test_util.h
+++ b/test/syscalls/linux/ip_socket_test_util.h
@@ -21,7 +21,7 @@
#include <string>
-#include "test/syscalls/linux/socket_test_util.h"
+#include "test/util/socket_util.h"
namespace gvisor {
namespace testing {
diff --git a/test/syscalls/linux/network_namespace.cc b/test/syscalls/linux/network_namespace.cc
index 133fdecf0..1984feedd 100644
--- a/test/syscalls/linux/network_namespace.cc
+++ b/test/syscalls/linux/network_namespace.cc
@@ -20,9 +20,9 @@
#include "gmock/gmock.h"
#include "gtest/gtest.h"
-#include "test/syscalls/linux/socket_test_util.h"
#include "test/util/capability_util.h"
#include "test/util/posix_error.h"
+#include "test/util/socket_util.h"
#include "test/util/test_util.h"
#include "test/util/thread_util.h"
diff --git a/test/syscalls/linux/packet_socket.cc b/test/syscalls/linux/packet_socket.cc
index 1e246c421..98339277b 100644
--- a/test/syscalls/linux/packet_socket.cc
+++ b/test/syscalls/linux/packet_socket.cc
@@ -29,10 +29,10 @@
#include "gtest/gtest.h"
#include "absl/base/internal/endian.h"
-#include "test/syscalls/linux/socket_test_util.h"
#include "test/syscalls/linux/unix_domain_socket_test_util.h"
#include "test/util/capability_util.h"
#include "test/util/file_descriptor.h"
+#include "test/util/socket_util.h"
#include "test/util/test_util.h"
// Some of these tests involve sending packets via AF_PACKET sockets and the
diff --git a/test/syscalls/linux/packet_socket_raw.cc b/test/syscalls/linux/packet_socket_raw.cc
index 7e439466e..07beb8ba0 100644
--- a/test/syscalls/linux/packet_socket_raw.cc
+++ b/test/syscalls/linux/packet_socket_raw.cc
@@ -30,10 +30,10 @@
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "absl/base/internal/endian.h"
-#include "test/syscalls/linux/socket_test_util.h"
#include "test/syscalls/linux/unix_domain_socket_test_util.h"
#include "test/util/capability_util.h"
#include "test/util/file_descriptor.h"
+#include "test/util/socket_util.h"
#include "test/util/test_util.h"
// Some of these tests involve sending packets via AF_PACKET sockets and the
diff --git a/test/syscalls/linux/partial_bad_buffer.cc b/test/syscalls/linux/partial_bad_buffer.cc
index 223ddc0c8..1bdfcbbe3 100644
--- a/test/syscalls/linux/partial_bad_buffer.cc
+++ b/test/syscalls/linux/partial_bad_buffer.cc
@@ -26,10 +26,10 @@
#include "gtest/gtest.h"
#include "absl/time/clock.h"
-#include "test/syscalls/linux/socket_test_util.h"
#include "test/util/file_descriptor.h"
#include "test/util/fs_util.h"
#include "test/util/posix_error.h"
+#include "test/util/socket_util.h"
#include "test/util/temp_path.h"
#include "test/util/test_util.h"
diff --git a/test/syscalls/linux/ping_socket.cc b/test/syscalls/linux/ping_socket.cc
index 8268e91da..7ec1938bf 100644
--- a/test/syscalls/linux/ping_socket.cc
+++ b/test/syscalls/linux/ping_socket.cc
@@ -29,8 +29,8 @@
#include "absl/strings/str_join.h"
#include "absl/types/optional.h"
#include "test/syscalls/linux/ip_socket_test_util.h"
-#include "test/syscalls/linux/socket_test_util.h"
#include "test/util/file_descriptor.h"
+#include "test/util/socket_util.h"
#include "test/util/test_util.h"
// Note: These tests require /proc/sys/net/ipv4/ping_group_range to be
diff --git a/test/syscalls/linux/proc_net.cc b/test/syscalls/linux/proc_net.cc
index 3b8a71ab4..4cbe30fc1 100644
--- a/test/syscalls/linux/proc_net.cc
+++ b/test/syscalls/linux/proc_net.cc
@@ -28,10 +28,10 @@
#include "absl/strings/str_split.h"
#include "absl/strings/string_view.h"
#include "absl/time/clock.h"
-#include "test/syscalls/linux/socket_test_util.h"
#include "test/util/capability_util.h"
#include "test/util/file_descriptor.h"
#include "test/util/fs_util.h"
+#include "test/util/socket_util.h"
#include "test/util/test_util.h"
namespace gvisor {
diff --git a/test/syscalls/linux/raw_socket.cc b/test/syscalls/linux/raw_socket.cc
index f8798bc76..e19fe8f6b 100644
--- a/test/syscalls/linux/raw_socket.cc
+++ b/test/syscalls/linux/raw_socket.cc
@@ -27,10 +27,10 @@
#include <algorithm>
#include "gtest/gtest.h"
-#include "test/syscalls/linux/socket_test_util.h"
#include "test/syscalls/linux/unix_domain_socket_test_util.h"
#include "test/util/capability_util.h"
#include "test/util/file_descriptor.h"
+#include "test/util/socket_util.h"
#include "test/util/test_util.h"
// Note: in order to run these tests, /proc/sys/net/ipv4/ping_group_range will
diff --git a/test/syscalls/linux/raw_socket_hdrincl.cc b/test/syscalls/linux/raw_socket_hdrincl.cc
index 4611b6283..f1d8fd295 100644
--- a/test/syscalls/linux/raw_socket_hdrincl.cc
+++ b/test/syscalls/linux/raw_socket_hdrincl.cc
@@ -27,10 +27,10 @@
#include "gtest/gtest.h"
#include "absl/base/internal/endian.h"
-#include "test/syscalls/linux/socket_test_util.h"
#include "test/syscalls/linux/unix_domain_socket_test_util.h"
#include "test/util/capability_util.h"
#include "test/util/file_descriptor.h"
+#include "test/util/socket_util.h"
#include "test/util/test_util.h"
namespace gvisor {
diff --git a/test/syscalls/linux/raw_socket_icmp.cc b/test/syscalls/linux/raw_socket_icmp.cc
index 275996bd3..27d3fffee 100644
--- a/test/syscalls/linux/raw_socket_icmp.cc
+++ b/test/syscalls/linux/raw_socket_icmp.cc
@@ -24,10 +24,10 @@
#include <cstdint>
#include "gtest/gtest.h"
-#include "test/syscalls/linux/socket_test_util.h"
#include "test/syscalls/linux/unix_domain_socket_test_util.h"
#include "test/util/capability_util.h"
#include "test/util/file_descriptor.h"
+#include "test/util/socket_util.h"
#include "test/util/test_util.h"
namespace gvisor {
diff --git a/test/syscalls/linux/readahead.cc b/test/syscalls/linux/readahead.cc
index 71073bb3c..04104c912 100644
--- a/test/syscalls/linux/readahead.cc
+++ b/test/syscalls/linux/readahead.cc
@@ -16,8 +16,8 @@
#include <fcntl.h>
#include "gtest/gtest.h"
-#include "test/syscalls/linux/socket_test_util.h"
#include "test/util/file_descriptor.h"
+#include "test/util/socket_util.h"
#include "test/util/temp_path.h"
#include "test/util/test_util.h"
diff --git a/test/syscalls/linux/sendfile_socket.cc b/test/syscalls/linux/sendfile_socket.cc
index c101fe9d2..ac6e89e91 100644
--- a/test/syscalls/linux/sendfile_socket.cc
+++ b/test/syscalls/linux/sendfile_socket.cc
@@ -24,8 +24,8 @@
#include "gtest/gtest.h"
#include "absl/strings/string_view.h"
#include "test/syscalls/linux/ip_socket_test_util.h"
-#include "test/syscalls/linux/socket_test_util.h"
#include "test/util/file_descriptor.h"
+#include "test/util/socket_util.h"
#include "test/util/temp_path.h"
#include "test/util/test_util.h"
#include "test/util/thread_util.h"
diff --git a/test/syscalls/linux/socket.cc b/test/syscalls/linux/socket.cc
index 2742d19be..d2762b6e9 100644
--- a/test/syscalls/linux/socket.cc
+++ b/test/syscalls/linux/socket.cc
@@ -20,8 +20,8 @@
#include <unistd.h>
#include "gtest/gtest.h"
-#include "test/syscalls/linux/socket_test_util.h"
#include "test/util/file_descriptor.h"
+#include "test/util/socket_util.h"
#include "test/util/temp_umask.h"
#include "test/util/test_util.h"
diff --git a/test/syscalls/linux/socket_abstract.cc b/test/syscalls/linux/socket_abstract.cc
index 00999f192..d450fad14 100644
--- a/test/syscalls/linux/socket_abstract.cc
+++ b/test/syscalls/linux/socket_abstract.cc
@@ -15,10 +15,10 @@
#include <vector>
#include "test/syscalls/linux/socket_generic.h"
-#include "test/syscalls/linux/socket_test_util.h"
#include "test/syscalls/linux/socket_unix.h"
#include "test/syscalls/linux/socket_unix_cmsg.h"
#include "test/syscalls/linux/unix_domain_socket_test_util.h"
+#include "test/util/socket_util.h"
#include "test/util/test_util.h"
namespace gvisor {
diff --git a/test/syscalls/linux/socket_bind_to_device.cc b/test/syscalls/linux/socket_bind_to_device.cc
index 6b27f6eab..dac31a90c 100644
--- a/test/syscalls/linux/socket_bind_to_device.cc
+++ b/test/syscalls/linux/socket_bind_to_device.cc
@@ -34,8 +34,8 @@
#include "gtest/gtest.h"
#include "test/syscalls/linux/ip_socket_test_util.h"
#include "test/syscalls/linux/socket_bind_to_device_util.h"
-#include "test/syscalls/linux/socket_test_util.h"
#include "test/util/capability_util.h"
+#include "test/util/socket_util.h"
#include "test/util/test_util.h"
#include "test/util/thread_util.h"
diff --git a/test/syscalls/linux/socket_bind_to_device_distribution.cc b/test/syscalls/linux/socket_bind_to_device_distribution.cc
index 70b0b2742..4cddb875a 100644
--- a/test/syscalls/linux/socket_bind_to_device_distribution.cc
+++ b/test/syscalls/linux/socket_bind_to_device_distribution.cc
@@ -35,8 +35,8 @@
#include "gtest/gtest.h"
#include "test/syscalls/linux/ip_socket_test_util.h"
#include "test/syscalls/linux/socket_bind_to_device_util.h"
-#include "test/syscalls/linux/socket_test_util.h"
#include "test/util/capability_util.h"
+#include "test/util/socket_util.h"
#include "test/util/test_util.h"
#include "test/util/thread_util.h"
diff --git a/test/syscalls/linux/socket_bind_to_device_sequence.cc b/test/syscalls/linux/socket_bind_to_device_sequence.cc
index d3cc71dbf..334b46730 100644
--- a/test/syscalls/linux/socket_bind_to_device_sequence.cc
+++ b/test/syscalls/linux/socket_bind_to_device_sequence.cc
@@ -36,8 +36,8 @@
#include "absl/container/node_hash_map.h"
#include "test/syscalls/linux/ip_socket_test_util.h"
#include "test/syscalls/linux/socket_bind_to_device_util.h"
-#include "test/syscalls/linux/socket_test_util.h"
#include "test/util/capability_util.h"
+#include "test/util/socket_util.h"
#include "test/util/test_util.h"
#include "test/util/thread_util.h"
diff --git a/test/syscalls/linux/socket_blocking.cc b/test/syscalls/linux/socket_blocking.cc
index 7e88aa2d9..5262e9ed9 100644
--- a/test/syscalls/linux/socket_blocking.cc
+++ b/test/syscalls/linux/socket_blocking.cc
@@ -23,8 +23,8 @@
#include "gtest/gtest.h"
#include "absl/time/clock.h"
#include "absl/time/time.h"
-#include "test/syscalls/linux/socket_test_util.h"
#include "test/syscalls/linux/unix_domain_socket_test_util.h"
+#include "test/util/socket_util.h"
#include "test/util/test_util.h"
#include "test/util/thread_util.h"
#include "test/util/timer_util.h"
diff --git a/test/syscalls/linux/socket_blocking.h b/test/syscalls/linux/socket_blocking.h
index db26e5ef5..89134ec30 100644
--- a/test/syscalls/linux/socket_blocking.h
+++ b/test/syscalls/linux/socket_blocking.h
@@ -15,7 +15,7 @@
#ifndef GVISOR_TEST_SYSCALLS_LINUX_SOCKET_BLOCKING_H_
#define GVISOR_TEST_SYSCALLS_LINUX_SOCKET_BLOCKING_H_
-#include "test/syscalls/linux/socket_test_util.h"
+#include "test/util/socket_util.h"
namespace gvisor {
namespace testing {
diff --git a/test/syscalls/linux/socket_capability.cc b/test/syscalls/linux/socket_capability.cc
index f75482aba..95cf1f6b4 100644
--- a/test/syscalls/linux/socket_capability.cc
+++ b/test/syscalls/linux/socket_capability.cc
@@ -16,9 +16,9 @@
// headers).
#include "gtest/gtest.h"
-#include "test/syscalls/linux/socket_test_util.h"
#include "test/util/capability_util.h"
#include "test/util/file_descriptor.h"
+#include "test/util/socket_util.h"
#include "test/util/test_util.h"
namespace gvisor {
diff --git a/test/syscalls/linux/socket_filesystem.cc b/test/syscalls/linux/socket_filesystem.cc
index 287359363..a611e9f4e 100644
--- a/test/syscalls/linux/socket_filesystem.cc
+++ b/test/syscalls/linux/socket_filesystem.cc
@@ -15,10 +15,10 @@
#include <vector>
#include "test/syscalls/linux/socket_generic.h"
-#include "test/syscalls/linux/socket_test_util.h"
#include "test/syscalls/linux/socket_unix.h"
#include "test/syscalls/linux/socket_unix_cmsg.h"
#include "test/syscalls/linux/unix_domain_socket_test_util.h"
+#include "test/util/socket_util.h"
#include "test/util/test_util.h"
namespace gvisor {
diff --git a/test/syscalls/linux/socket_generic.h b/test/syscalls/linux/socket_generic.h
index 00ae7bfc3..a13262355 100644
--- a/test/syscalls/linux/socket_generic.h
+++ b/test/syscalls/linux/socket_generic.h
@@ -15,7 +15,7 @@
#ifndef GVISOR_TEST_SYSCALLS_LINUX_SOCKET_GENERIC_H_
#define GVISOR_TEST_SYSCALLS_LINUX_SOCKET_GENERIC_H_
-#include "test/syscalls/linux/socket_test_util.h"
+#include "test/util/socket_util.h"
namespace gvisor {
namespace testing {
diff --git a/test/syscalls/linux/socket_generic_stress.cc b/test/syscalls/linux/socket_generic_stress.cc
index 778c32a8e..9ff385b41 100644
--- a/test/syscalls/linux/socket_generic_stress.cc
+++ b/test/syscalls/linux/socket_generic_stress.cc
@@ -29,8 +29,8 @@
#include "absl/time/clock.h"
#include "absl/time/time.h"
#include "test/syscalls/linux/ip_socket_test_util.h"
-#include "test/syscalls/linux/socket_test_util.h"
#include "test/util/file_descriptor.h"
+#include "test/util/socket_util.h"
#include "test/util/test_util.h"
#include "test/util/thread_util.h"
diff --git a/test/syscalls/linux/socket_generic_test_cases.cc b/test/syscalls/linux/socket_generic_test_cases.cc
index fe5171bc8..c509d54e2 100644
--- a/test/syscalls/linux/socket_generic_test_cases.cc
+++ b/test/syscalls/linux/socket_generic_test_cases.cc
@@ -25,9 +25,9 @@
#include "gtest/gtest.h"
#include "absl/strings/str_format.h"
#include "absl/strings/string_view.h"
-#include "test/syscalls/linux/socket_test_util.h"
#include "test/syscalls/linux/unix_domain_socket_test_util.h"
#include "test/util/capability_util.h"
+#include "test/util/socket_util.h"
#include "test/util/test_util.h"
// This file is a generic socket test file. It must be built with another file
diff --git a/test/syscalls/linux/socket_inet_loopback.cc b/test/syscalls/linux/socket_inet_loopback.cc
index 9ae0cc59d..5f0b40ecf 100644
--- a/test/syscalls/linux/socket_inet_loopback.cc
+++ b/test/syscalls/linux/socket_inet_loopback.cc
@@ -35,10 +35,10 @@
#include "absl/time/time.h"
#include "test/syscalls/linux/ip_socket_test_util.h"
#include "test/syscalls/linux/socket_inet_loopback_test_params.h"
-#include "test/syscalls/linux/socket_test_util.h"
#include "test/util/file_descriptor.h"
#include "test/util/posix_error.h"
#include "test/util/save_util.h"
+#include "test/util/socket_util.h"
#include "test/util/test_util.h"
#include "test/util/thread_util.h"
diff --git a/test/syscalls/linux/socket_inet_loopback_isolated.cc b/test/syscalls/linux/socket_inet_loopback_isolated.cc
index ab2259b55..182d20a9e 100644
--- a/test/syscalls/linux/socket_inet_loopback_isolated.cc
+++ b/test/syscalls/linux/socket_inet_loopback_isolated.cc
@@ -18,7 +18,7 @@
#include "absl/time/clock.h"
#include "absl/time/time.h"
#include "test/syscalls/linux/socket_inet_loopback_test_params.h"
-#include "test/syscalls/linux/socket_test_util.h"
+#include "test/util/socket_util.h"
#include "test/util/test_util.h"
// Unit tests in this file will run in their own network namespace.
diff --git a/test/syscalls/linux/socket_inet_loopback_nogotsan.cc b/test/syscalls/linux/socket_inet_loopback_nogotsan.cc
index cc2773af1..479162487 100644
--- a/test/syscalls/linux/socket_inet_loopback_nogotsan.cc
+++ b/test/syscalls/linux/socket_inet_loopback_nogotsan.cc
@@ -28,10 +28,10 @@
#include "absl/strings/str_cat.h"
#include "test/syscalls/linux/ip_socket_test_util.h"
#include "test/syscalls/linux/socket_inet_loopback_test_params.h"
-#include "test/syscalls/linux/socket_test_util.h"
#include "test/util/file_descriptor.h"
#include "test/util/posix_error.h"
#include "test/util/save_util.h"
+#include "test/util/socket_util.h"
#include "test/util/test_util.h"
namespace gvisor {
diff --git a/test/syscalls/linux/socket_inet_loopback_test_params.h b/test/syscalls/linux/socket_inet_loopback_test_params.h
index 42b48eb8a..163e595a8 100644
--- a/test/syscalls/linux/socket_inet_loopback_test_params.h
+++ b/test/syscalls/linux/socket_inet_loopback_test_params.h
@@ -16,7 +16,7 @@
#define GVISOR_TEST_SYSCALLS_LINUX_SOCKET_INET_LOOPBACK_TEST_PARAMS_H_
#include "gtest/gtest.h"
-#include "test/syscalls/linux/socket_test_util.h"
+#include "test/util/socket_util.h"
namespace gvisor {
namespace testing {
diff --git a/test/syscalls/linux/socket_ip_loopback_blocking.cc b/test/syscalls/linux/socket_ip_loopback_blocking.cc
index fda252dd7..caa5c0c63 100644
--- a/test/syscalls/linux/socket_ip_loopback_blocking.cc
+++ b/test/syscalls/linux/socket_ip_loopback_blocking.cc
@@ -18,7 +18,7 @@
#include "test/syscalls/linux/ip_socket_test_util.h"
#include "test/syscalls/linux/socket_blocking.h"
-#include "test/syscalls/linux/socket_test_util.h"
+#include "test/util/socket_util.h"
#include "test/util/test_util.h"
namespace gvisor {
diff --git a/test/syscalls/linux/socket_ip_tcp_generic.cc b/test/syscalls/linux/socket_ip_tcp_generic.cc
index 2f5743cda..3271263c8 100644
--- a/test/syscalls/linux/socket_ip_tcp_generic.cc
+++ b/test/syscalls/linux/socket_ip_tcp_generic.cc
@@ -28,7 +28,7 @@
#include "absl/memory/memory.h"
#include "absl/time/clock.h"
#include "absl/time/time.h"
-#include "test/syscalls/linux/socket_test_util.h"
+#include "test/util/socket_util.h"
#include "test/util/temp_path.h"
#include "test/util/test_util.h"
#include "test/util/thread_util.h"
diff --git a/test/syscalls/linux/socket_ip_tcp_generic.h b/test/syscalls/linux/socket_ip_tcp_generic.h
index a3eff3c73..e9e60ef4c 100644
--- a/test/syscalls/linux/socket_ip_tcp_generic.h
+++ b/test/syscalls/linux/socket_ip_tcp_generic.h
@@ -15,7 +15,7 @@
#ifndef GVISOR_TEST_SYSCALLS_LINUX_SOCKET_IP_TCP_GENERIC_H_
#define GVISOR_TEST_SYSCALLS_LINUX_SOCKET_IP_TCP_GENERIC_H_
-#include "test/syscalls/linux/socket_test_util.h"
+#include "test/util/socket_util.h"
namespace gvisor {
namespace testing {
diff --git a/test/syscalls/linux/socket_ip_tcp_generic_loopback.cc b/test/syscalls/linux/socket_ip_tcp_generic_loopback.cc
index 4e79d21f4..3406874b8 100644
--- a/test/syscalls/linux/socket_ip_tcp_generic_loopback.cc
+++ b/test/syscalls/linux/socket_ip_tcp_generic_loopback.cc
@@ -18,7 +18,7 @@
#include "test/syscalls/linux/ip_socket_test_util.h"
#include "test/syscalls/linux/socket_ip_tcp_generic.h"
-#include "test/syscalls/linux/socket_test_util.h"
+#include "test/util/socket_util.h"
#include "test/util/test_util.h"
namespace gvisor {
diff --git a/test/syscalls/linux/socket_ip_tcp_loopback.cc b/test/syscalls/linux/socket_ip_tcp_loopback.cc
index 9db3037bc..0796b8634 100644
--- a/test/syscalls/linux/socket_ip_tcp_loopback.cc
+++ b/test/syscalls/linux/socket_ip_tcp_loopback.cc
@@ -16,7 +16,7 @@
#include "test/syscalls/linux/ip_socket_test_util.h"
#include "test/syscalls/linux/socket_generic.h"
-#include "test/syscalls/linux/socket_test_util.h"
+#include "test/util/socket_util.h"
#include "test/util/test_util.h"
namespace gvisor {
diff --git a/test/syscalls/linux/socket_ip_tcp_loopback_blocking.cc b/test/syscalls/linux/socket_ip_tcp_loopback_blocking.cc
index f996b93d2..533ccc3ae 100644
--- a/test/syscalls/linux/socket_ip_tcp_loopback_blocking.cc
+++ b/test/syscalls/linux/socket_ip_tcp_loopback_blocking.cc
@@ -18,7 +18,7 @@
#include "test/syscalls/linux/ip_socket_test_util.h"
#include "test/syscalls/linux/socket_stream_blocking.h"
-#include "test/syscalls/linux/socket_test_util.h"
+#include "test/util/socket_util.h"
#include "test/util/test_util.h"
namespace gvisor {
diff --git a/test/syscalls/linux/socket_ip_tcp_loopback_nonblock.cc b/test/syscalls/linux/socket_ip_tcp_loopback_nonblock.cc
index ffa377210..05fe2a738 100644
--- a/test/syscalls/linux/socket_ip_tcp_loopback_nonblock.cc
+++ b/test/syscalls/linux/socket_ip_tcp_loopback_nonblock.cc
@@ -18,7 +18,7 @@
#include "test/syscalls/linux/ip_socket_test_util.h"
#include "test/syscalls/linux/socket_non_blocking.h"
-#include "test/syscalls/linux/socket_test_util.h"
+#include "test/util/socket_util.h"
#include "test/util/test_util.h"
namespace gvisor {
diff --git a/test/syscalls/linux/socket_ip_tcp_udp_generic.cc b/test/syscalls/linux/socket_ip_tcp_udp_generic.cc
index f178f1af9..88adb5b1b 100644
--- a/test/syscalls/linux/socket_ip_tcp_udp_generic.cc
+++ b/test/syscalls/linux/socket_ip_tcp_udp_generic.cc
@@ -23,7 +23,7 @@
#include "gtest/gtest.h"
#include "test/syscalls/linux/ip_socket_test_util.h"
-#include "test/syscalls/linux/socket_test_util.h"
+#include "test/util/socket_util.h"
#include "test/util/test_util.h"
namespace gvisor {
diff --git a/test/syscalls/linux/socket_ip_udp_generic.cc b/test/syscalls/linux/socket_ip_udp_generic.cc
index 1694e188a..8a87f2667 100644
--- a/test/syscalls/linux/socket_ip_udp_generic.cc
+++ b/test/syscalls/linux/socket_ip_udp_generic.cc
@@ -28,7 +28,7 @@
#include <sys/un.h>
#include "gtest/gtest.h"
-#include "test/syscalls/linux/socket_test_util.h"
+#include "test/util/socket_util.h"
#include "test/util/test_util.h"
namespace gvisor {
diff --git a/test/syscalls/linux/socket_ip_udp_generic.h b/test/syscalls/linux/socket_ip_udp_generic.h
index 106c54e9f..a3a66c768 100644
--- a/test/syscalls/linux/socket_ip_udp_generic.h
+++ b/test/syscalls/linux/socket_ip_udp_generic.h
@@ -15,7 +15,7 @@
#ifndef GVISOR_TEST_SYSCALLS_LINUX_SOCKET_IP_UDP_GENERIC_H_
#define GVISOR_TEST_SYSCALLS_LINUX_SOCKET_IP_UDP_GENERIC_H_
-#include "test/syscalls/linux/socket_test_util.h"
+#include "test/util/socket_util.h"
namespace gvisor {
namespace testing {
diff --git a/test/syscalls/linux/socket_ip_udp_loopback.cc b/test/syscalls/linux/socket_ip_udp_loopback.cc
index c7fa44884..6d06bd580 100644
--- a/test/syscalls/linux/socket_ip_udp_loopback.cc
+++ b/test/syscalls/linux/socket_ip_udp_loopback.cc
@@ -18,7 +18,7 @@
#include "test/syscalls/linux/socket_generic.h"
#include "test/syscalls/linux/socket_ip_udp_generic.h"
#include "test/syscalls/linux/socket_non_stream.h"
-#include "test/syscalls/linux/socket_test_util.h"
+#include "test/util/socket_util.h"
#include "test/util/test_util.h"
namespace gvisor {
diff --git a/test/syscalls/linux/socket_ip_udp_loopback_blocking.cc b/test/syscalls/linux/socket_ip_udp_loopback_blocking.cc
index d6925a8df..60d02e079 100644
--- a/test/syscalls/linux/socket_ip_udp_loopback_blocking.cc
+++ b/test/syscalls/linux/socket_ip_udp_loopback_blocking.cc
@@ -16,7 +16,7 @@
#include "test/syscalls/linux/ip_socket_test_util.h"
#include "test/syscalls/linux/socket_non_stream_blocking.h"
-#include "test/syscalls/linux/socket_test_util.h"
+#include "test/util/socket_util.h"
#include "test/util/test_util.h"
namespace gvisor {
diff --git a/test/syscalls/linux/socket_ip_udp_loopback_nonblock.cc b/test/syscalls/linux/socket_ip_udp_loopback_nonblock.cc
index d675eddc6..c011e3658 100644
--- a/test/syscalls/linux/socket_ip_udp_loopback_nonblock.cc
+++ b/test/syscalls/linux/socket_ip_udp_loopback_nonblock.cc
@@ -16,7 +16,7 @@
#include "test/syscalls/linux/ip_socket_test_util.h"
#include "test/syscalls/linux/socket_non_blocking.h"
-#include "test/syscalls/linux/socket_test_util.h"
+#include "test/util/socket_util.h"
#include "test/util/test_util.h"
namespace gvisor {
diff --git a/test/syscalls/linux/socket_ip_udp_unbound_external_networking.cc b/test/syscalls/linux/socket_ip_udp_unbound_external_networking.cc
index fdbb2216b..af2459a2f 100644
--- a/test/syscalls/linux/socket_ip_udp_unbound_external_networking.cc
+++ b/test/syscalls/linux/socket_ip_udp_unbound_external_networking.cc
@@ -14,7 +14,7 @@
#include "test/syscalls/linux/socket_ip_udp_unbound_external_networking.h"
-#include "test/syscalls/linux/socket_test_util.h"
+#include "test/util/socket_util.h"
#include "test/util/test_util.h"
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 e5287addb..2e8aab129 100644
--- a/test/syscalls/linux/socket_ip_udp_unbound_external_networking.h
+++ b/test/syscalls/linux/socket_ip_udp_unbound_external_networking.h
@@ -16,7 +16,7 @@
#define GVISOR_TEST_SYSCALLS_LINUX_SOCKET_IP_UDP_UNBOUND_EXTERNAL_NETWORKING_H_
#include "test/syscalls/linux/ip_socket_test_util.h"
-#include "test/syscalls/linux/socket_test_util.h"
+#include "test/util/socket_util.h"
namespace gvisor {
namespace testing {
diff --git a/test/syscalls/linux/socket_ip_unbound.cc b/test/syscalls/linux/socket_ip_unbound.cc
index 029f1e872..930f19e59 100644
--- a/test/syscalls/linux/socket_ip_unbound.cc
+++ b/test/syscalls/linux/socket_ip_unbound.cc
@@ -24,7 +24,7 @@
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "test/syscalls/linux/ip_socket_test_util.h"
-#include "test/syscalls/linux/socket_test_util.h"
+#include "test/util/socket_util.h"
#include "test/util/test_util.h"
namespace gvisor {
diff --git a/test/syscalls/linux/socket_ip_unbound_netlink.cc b/test/syscalls/linux/socket_ip_unbound_netlink.cc
index b02222999..803a3b30b 100644
--- a/test/syscalls/linux/socket_ip_unbound_netlink.cc
+++ b/test/syscalls/linux/socket_ip_unbound_netlink.cc
@@ -25,8 +25,8 @@
#include "gtest/gtest.h"
#include "test/syscalls/linux/ip_socket_test_util.h"
#include "test/syscalls/linux/socket_netlink_route_util.h"
-#include "test/syscalls/linux/socket_test_util.h"
#include "test/util/capability_util.h"
+#include "test/util/socket_util.h"
#include "test/util/test_util.h"
namespace gvisor {
diff --git a/test/syscalls/linux/socket_ipv4_udp_unbound.cc b/test/syscalls/linux/socket_ipv4_udp_unbound.cc
index 18be4dcc7..816d1181c 100644
--- a/test/syscalls/linux/socket_ipv4_udp_unbound.cc
+++ b/test/syscalls/linux/socket_ipv4_udp_unbound.cc
@@ -26,9 +26,9 @@
#include "gtest/gtest.h"
#include "absl/memory/memory.h"
#include "test/syscalls/linux/ip_socket_test_util.h"
-#include "test/syscalls/linux/socket_test_util.h"
#include "test/util/posix_error.h"
#include "test/util/save_util.h"
+#include "test/util/socket_util.h"
#include "test/util/test_util.h"
namespace gvisor {
diff --git a/test/syscalls/linux/socket_ipv4_udp_unbound.h b/test/syscalls/linux/socket_ipv4_udp_unbound.h
index f64c57645..3818a3490 100644
--- a/test/syscalls/linux/socket_ipv4_udp_unbound.h
+++ b/test/syscalls/linux/socket_ipv4_udp_unbound.h
@@ -15,7 +15,7 @@
#ifndef GVISOR_TEST_SYSCALLS_LINUX_SOCKET_IPV4_UDP_UNBOUND_H_
#define GVISOR_TEST_SYSCALLS_LINUX_SOCKET_IPV4_UDP_UNBOUND_H_
-#include "test/syscalls/linux/socket_test_util.h"
+#include "test/util/socket_util.h"
namespace gvisor {
namespace testing {
diff --git a/test/syscalls/linux/socket_ipv4_udp_unbound_external_networking_test.cc b/test/syscalls/linux/socket_ipv4_udp_unbound_external_networking_test.cc
index f6e64c157..ebf2185f2 100644
--- a/test/syscalls/linux/socket_ipv4_udp_unbound_external_networking_test.cc
+++ b/test/syscalls/linux/socket_ipv4_udp_unbound_external_networking_test.cc
@@ -17,7 +17,7 @@
#include <vector>
#include "test/syscalls/linux/ip_socket_test_util.h"
-#include "test/syscalls/linux/socket_test_util.h"
+#include "test/util/socket_util.h"
#include "test/util/test_util.h"
namespace gvisor {
diff --git a/test/syscalls/linux/socket_ipv4_udp_unbound_loopback.cc b/test/syscalls/linux/socket_ipv4_udp_unbound_loopback.cc
index f121c044d..00930c544 100644
--- a/test/syscalls/linux/socket_ipv4_udp_unbound_loopback.cc
+++ b/test/syscalls/linux/socket_ipv4_udp_unbound_loopback.cc
@@ -16,7 +16,7 @@
#include "test/syscalls/linux/ip_socket_test_util.h"
#include "test/syscalls/linux/socket_ipv4_udp_unbound.h"
-#include "test/syscalls/linux/socket_test_util.h"
+#include "test/util/socket_util.h"
#include "test/util/test_util.h"
namespace gvisor {
diff --git a/test/syscalls/linux/socket_ipv4_udp_unbound_loopback_netlink.cc b/test/syscalls/linux/socket_ipv4_udp_unbound_loopback_netlink.cc
index 8052bf404..f90a48630 100644
--- a/test/syscalls/linux/socket_ipv4_udp_unbound_loopback_netlink.cc
+++ b/test/syscalls/linux/socket_ipv4_udp_unbound_loopback_netlink.cc
@@ -16,7 +16,7 @@
#include "test/syscalls/linux/ip_socket_test_util.h"
#include "test/syscalls/linux/socket_ipv4_udp_unbound_netlink.h"
-#include "test/syscalls/linux/socket_test_util.h"
+#include "test/util/socket_util.h"
#include "test/util/test_util.h"
namespace gvisor {
diff --git a/test/syscalls/linux/socket_ipv4_udp_unbound_loopback_nogotsan.cc b/test/syscalls/linux/socket_ipv4_udp_unbound_loopback_nogotsan.cc
index a2c6d4491..5a7bca658 100644
--- a/test/syscalls/linux/socket_ipv4_udp_unbound_loopback_nogotsan.cc
+++ b/test/syscalls/linux/socket_ipv4_udp_unbound_loopback_nogotsan.cc
@@ -18,7 +18,7 @@
#include "gtest/gtest.h"
#include "absl/memory/memory.h"
#include "test/syscalls/linux/ip_socket_test_util.h"
-#include "test/syscalls/linux/socket_test_util.h"
+#include "test/util/socket_util.h"
#include "test/util/test_util.h"
namespace gvisor {
diff --git a/test/syscalls/linux/socket_ipv4_udp_unbound_netlink.h b/test/syscalls/linux/socket_ipv4_udp_unbound_netlink.h
index 73e7836d5..17c8e2b84 100644
--- a/test/syscalls/linux/socket_ipv4_udp_unbound_netlink.h
+++ b/test/syscalls/linux/socket_ipv4_udp_unbound_netlink.h
@@ -15,7 +15,7 @@
#ifndef GVISOR_TEST_SYSCALLS_LINUX_SOCKET_IPV4_UDP_UNBOUND_NETLINK_UTIL_H_
#define GVISOR_TEST_SYSCALLS_LINUX_SOCKET_IPV4_UDP_UNBOUND_NETLINK_UTIL_H_
-#include "test/syscalls/linux/socket_test_util.h"
+#include "test/util/socket_util.h"
namespace gvisor {
namespace testing {
diff --git a/test/syscalls/linux/socket_ipv6_udp_unbound.cc b/test/syscalls/linux/socket_ipv6_udp_unbound.cc
index a4e3371f4..612fd531c 100644
--- a/test/syscalls/linux/socket_ipv6_udp_unbound.cc
+++ b/test/syscalls/linux/socket_ipv6_udp_unbound.cc
@@ -31,9 +31,9 @@
#include "gtest/gtest.h"
#include "absl/memory/memory.h"
#include "test/syscalls/linux/ip_socket_test_util.h"
-#include "test/syscalls/linux/socket_test_util.h"
#include "test/util/posix_error.h"
#include "test/util/save_util.h"
+#include "test/util/socket_util.h"
#include "test/util/test_util.h"
namespace gvisor {
diff --git a/test/syscalls/linux/socket_ipv6_udp_unbound.h b/test/syscalls/linux/socket_ipv6_udp_unbound.h
index 71e160f73..060343eaf 100644
--- a/test/syscalls/linux/socket_ipv6_udp_unbound.h
+++ b/test/syscalls/linux/socket_ipv6_udp_unbound.h
@@ -15,7 +15,7 @@
#ifndef GVISOR_TEST_SYSCALLS_LINUX_SOCKET_IPV6_UDP_UNBOUND_H_
#define GVISOR_TEST_SYSCALLS_LINUX_SOCKET_IPV6_UDP_UNBOUND_H_
-#include "test/syscalls/linux/socket_test_util.h"
+#include "test/util/socket_util.h"
namespace gvisor {
namespace testing {
diff --git a/test/syscalls/linux/socket_ipv6_udp_unbound_external_networking_test.cc b/test/syscalls/linux/socket_ipv6_udp_unbound_external_networking_test.cc
index 5c764b8fd..ff12eafc3 100644
--- a/test/syscalls/linux/socket_ipv6_udp_unbound_external_networking_test.cc
+++ b/test/syscalls/linux/socket_ipv6_udp_unbound_external_networking_test.cc
@@ -17,7 +17,7 @@
#include <vector>
#include "test/syscalls/linux/ip_socket_test_util.h"
-#include "test/syscalls/linux/socket_test_util.h"
+#include "test/util/socket_util.h"
#include "test/util/test_util.h"
namespace gvisor {
diff --git a/test/syscalls/linux/socket_ipv6_udp_unbound_loopback.cc b/test/syscalls/linux/socket_ipv6_udp_unbound_loopback.cc
index 058336ecc..f11f444a2 100644
--- a/test/syscalls/linux/socket_ipv6_udp_unbound_loopback.cc
+++ b/test/syscalls/linux/socket_ipv6_udp_unbound_loopback.cc
@@ -16,7 +16,7 @@
#include "test/syscalls/linux/ip_socket_test_util.h"
#include "test/syscalls/linux/socket_ipv6_udp_unbound.h"
-#include "test/syscalls/linux/socket_test_util.h"
+#include "test/util/socket_util.h"
#include "test/util/test_util.h"
namespace gvisor {
diff --git a/test/syscalls/linux/socket_ipv6_udp_unbound_loopback_netlink.cc b/test/syscalls/linux/socket_ipv6_udp_unbound_loopback_netlink.cc
index 17021ff82..565f9bc2e 100644
--- a/test/syscalls/linux/socket_ipv6_udp_unbound_loopback_netlink.cc
+++ b/test/syscalls/linux/socket_ipv6_udp_unbound_loopback_netlink.cc
@@ -16,7 +16,7 @@
#include "test/syscalls/linux/ip_socket_test_util.h"
#include "test/syscalls/linux/socket_ipv6_udp_unbound_netlink.h"
-#include "test/syscalls/linux/socket_test_util.h"
+#include "test/util/socket_util.h"
#include "test/util/test_util.h"
namespace gvisor {
diff --git a/test/syscalls/linux/socket_ipv6_udp_unbound_netlink.h b/test/syscalls/linux/socket_ipv6_udp_unbound_netlink.h
index 88098be82..f017a4c89 100644
--- a/test/syscalls/linux/socket_ipv6_udp_unbound_netlink.h
+++ b/test/syscalls/linux/socket_ipv6_udp_unbound_netlink.h
@@ -15,7 +15,7 @@
#ifndef GVISOR_TEST_SYSCALLS_LINUX_SOCKET_IPV6_UDP_UNBOUND_NETLINK_UTIL_H_
#define GVISOR_TEST_SYSCALLS_LINUX_SOCKET_IPV6_UDP_UNBOUND_NETLINK_UTIL_H_
-#include "test/syscalls/linux/socket_test_util.h"
+#include "test/util/socket_util.h"
namespace gvisor {
namespace testing {
diff --git a/test/syscalls/linux/socket_netdevice.cc b/test/syscalls/linux/socket_netdevice.cc
index 8d214a2b7..c95c5305d 100644
--- a/test/syscalls/linux/socket_netdevice.cc
+++ b/test/syscalls/linux/socket_netdevice.cc
@@ -22,8 +22,8 @@
#include "gtest/gtest.h"
#include "absl/base/internal/endian.h"
#include "test/syscalls/linux/socket_netlink_util.h"
-#include "test/syscalls/linux/socket_test_util.h"
#include "test/util/file_descriptor.h"
+#include "test/util/socket_util.h"
#include "test/util/test_util.h"
// Tests for netdevice queries.
diff --git a/test/syscalls/linux/socket_netlink.cc b/test/syscalls/linux/socket_netlink.cc
index 4ec0fd4fa..c78529a14 100644
--- a/test/syscalls/linux/socket_netlink.cc
+++ b/test/syscalls/linux/socket_netlink.cc
@@ -18,8 +18,8 @@
#include <unistd.h>
#include "gtest/gtest.h"
-#include "test/syscalls/linux/socket_test_util.h"
#include "test/util/file_descriptor.h"
+#include "test/util/socket_util.h"
#include "test/util/test_util.h"
// Tests for all netlink socket protocols.
diff --git a/test/syscalls/linux/socket_netlink_route.cc b/test/syscalls/linux/socket_netlink_route.cc
index ee3c08770..a5c788346 100644
--- a/test/syscalls/linux/socket_netlink_route.cc
+++ b/test/syscalls/linux/socket_netlink_route.cc
@@ -29,10 +29,10 @@
#include "absl/strings/str_format.h"
#include "test/syscalls/linux/socket_netlink_route_util.h"
#include "test/syscalls/linux/socket_netlink_util.h"
-#include "test/syscalls/linux/socket_test_util.h"
#include "test/util/capability_util.h"
#include "test/util/cleanup.h"
#include "test/util/file_descriptor.h"
+#include "test/util/socket_util.h"
#include "test/util/test_util.h"
// Tests for NETLINK_ROUTE sockets.
diff --git a/test/syscalls/linux/socket_netlink_uevent.cc b/test/syscalls/linux/socket_netlink_uevent.cc
index da425bed4..9e025911b 100644
--- a/test/syscalls/linux/socket_netlink_uevent.cc
+++ b/test/syscalls/linux/socket_netlink_uevent.cc
@@ -20,8 +20,8 @@
#include "gtest/gtest.h"
#include "test/syscalls/linux/socket_netlink_util.h"
-#include "test/syscalls/linux/socket_test_util.h"
#include "test/util/file_descriptor.h"
+#include "test/util/socket_util.h"
#include "test/util/test_util.h"
// Tests for NETLINK_KOBJECT_UEVENT sockets.
diff --git a/test/syscalls/linux/socket_netlink_util.cc b/test/syscalls/linux/socket_netlink_util.cc
index bdebea321..c1bff3c65 100644
--- a/test/syscalls/linux/socket_netlink_util.cc
+++ b/test/syscalls/linux/socket_netlink_util.cc
@@ -22,7 +22,7 @@
#include <vector>
#include "absl/strings/str_cat.h"
-#include "test/syscalls/linux/socket_test_util.h"
+#include "test/util/socket_util.h"
namespace gvisor {
namespace testing {
diff --git a/test/syscalls/linux/socket_non_blocking.cc b/test/syscalls/linux/socket_non_blocking.cc
index c3520cadd..3d09485d3 100644
--- a/test/syscalls/linux/socket_non_blocking.cc
+++ b/test/syscalls/linux/socket_non_blocking.cc
@@ -20,8 +20,8 @@
#include <sys/un.h>
#include "gtest/gtest.h"
-#include "test/syscalls/linux/socket_test_util.h"
#include "test/syscalls/linux/unix_domain_socket_test_util.h"
+#include "test/util/socket_util.h"
#include "test/util/test_util.h"
namespace gvisor {
diff --git a/test/syscalls/linux/socket_non_blocking.h b/test/syscalls/linux/socket_non_blocking.h
index bd3e02fd2..604206cfb 100644
--- a/test/syscalls/linux/socket_non_blocking.h
+++ b/test/syscalls/linux/socket_non_blocking.h
@@ -15,7 +15,7 @@
#ifndef GVISOR_TEST_SYSCALLS_LINUX_SOCKET_NON_BLOCKING_H_
#define GVISOR_TEST_SYSCALLS_LINUX_SOCKET_NON_BLOCKING_H_
-#include "test/syscalls/linux/socket_test_util.h"
+#include "test/util/socket_util.h"
namespace gvisor {
namespace testing {
diff --git a/test/syscalls/linux/socket_non_stream.cc b/test/syscalls/linux/socket_non_stream.cc
index c61817f14..7c3310909 100644
--- a/test/syscalls/linux/socket_non_stream.cc
+++ b/test/syscalls/linux/socket_non_stream.cc
@@ -20,8 +20,8 @@
#include "gtest/gtest.h"
#include "test/syscalls/linux/ip_socket_test_util.h"
-#include "test/syscalls/linux/socket_test_util.h"
#include "test/syscalls/linux/unix_domain_socket_test_util.h"
+#include "test/util/socket_util.h"
#include "test/util/test_util.h"
namespace gvisor {
diff --git a/test/syscalls/linux/socket_non_stream.h b/test/syscalls/linux/socket_non_stream.h
index 469fbe6a2..4876730f9 100644
--- a/test/syscalls/linux/socket_non_stream.h
+++ b/test/syscalls/linux/socket_non_stream.h
@@ -15,7 +15,7 @@
#ifndef GVISOR_TEST_SYSCALLS_LINUX_SOCKET_NON_STREAM_H_
#define GVISOR_TEST_SYSCALLS_LINUX_SOCKET_NON_STREAM_H_
-#include "test/syscalls/linux/socket_test_util.h"
+#include "test/util/socket_util.h"
namespace gvisor {
namespace testing {
diff --git a/test/syscalls/linux/socket_non_stream_blocking.cc b/test/syscalls/linux/socket_non_stream_blocking.cc
index b052f6e61..ac33407f8 100644
--- a/test/syscalls/linux/socket_non_stream_blocking.cc
+++ b/test/syscalls/linux/socket_non_stream_blocking.cc
@@ -22,8 +22,8 @@
#include "gtest/gtest.h"
#include "absl/time/clock.h"
#include "absl/time/time.h"
-#include "test/syscalls/linux/socket_test_util.h"
#include "test/syscalls/linux/unix_domain_socket_test_util.h"
+#include "test/util/socket_util.h"
#include "test/util/test_util.h"
#include "test/util/thread_util.h"
diff --git a/test/syscalls/linux/socket_non_stream_blocking.h b/test/syscalls/linux/socket_non_stream_blocking.h
index 6e205a039..71520bb37 100644
--- a/test/syscalls/linux/socket_non_stream_blocking.h
+++ b/test/syscalls/linux/socket_non_stream_blocking.h
@@ -15,7 +15,7 @@
#ifndef GVISOR_TEST_SYSCALLS_LINUX_SOCKET_NON_STREAM_BLOCKING_H_
#define GVISOR_TEST_SYSCALLS_LINUX_SOCKET_NON_STREAM_BLOCKING_H_
-#include "test/syscalls/linux/socket_test_util.h"
+#include "test/util/socket_util.h"
namespace gvisor {
namespace testing {
diff --git a/test/syscalls/linux/socket_stream.cc b/test/syscalls/linux/socket_stream.cc
index 6522b2e01..11903f28b 100644
--- a/test/syscalls/linux/socket_stream.cc
+++ b/test/syscalls/linux/socket_stream.cc
@@ -21,8 +21,8 @@
#include "gtest/gtest.h"
#include "absl/time/clock.h"
-#include "test/syscalls/linux/socket_test_util.h"
#include "test/syscalls/linux/unix_domain_socket_test_util.h"
+#include "test/util/socket_util.h"
#include "test/util/test_util.h"
namespace gvisor {
diff --git a/test/syscalls/linux/socket_stream.h b/test/syscalls/linux/socket_stream.h
index b837b8f8c..dc6fb2f98 100644
--- a/test/syscalls/linux/socket_stream.h
+++ b/test/syscalls/linux/socket_stream.h
@@ -15,7 +15,7 @@
#ifndef GVISOR_TEST_SYSCALLS_LINUX_SOCKET_STREAM_H_
#define GVISOR_TEST_SYSCALLS_LINUX_SOCKET_STREAM_H_
-#include "test/syscalls/linux/socket_test_util.h"
+#include "test/util/socket_util.h"
namespace gvisor {
namespace testing {
diff --git a/test/syscalls/linux/socket_stream_blocking.cc b/test/syscalls/linux/socket_stream_blocking.cc
index 0743322ac..e168f79ff 100644
--- a/test/syscalls/linux/socket_stream_blocking.cc
+++ b/test/syscalls/linux/socket_stream_blocking.cc
@@ -22,8 +22,8 @@
#include "gtest/gtest.h"
#include "absl/time/clock.h"
#include "absl/time/time.h"
-#include "test/syscalls/linux/socket_test_util.h"
#include "test/syscalls/linux/unix_domain_socket_test_util.h"
+#include "test/util/socket_util.h"
#include "test/util/test_util.h"
#include "test/util/thread_util.h"
#include "test/util/timer_util.h"
diff --git a/test/syscalls/linux/socket_stream_blocking.h b/test/syscalls/linux/socket_stream_blocking.h
index 9fd19ff90..f760188f6 100644
--- a/test/syscalls/linux/socket_stream_blocking.h
+++ b/test/syscalls/linux/socket_stream_blocking.h
@@ -15,7 +15,7 @@
#ifndef GVISOR_TEST_SYSCALLS_LINUX_SOCKET_STREAM_BLOCKING_H_
#define GVISOR_TEST_SYSCALLS_LINUX_SOCKET_STREAM_BLOCKING_H_
-#include "test/syscalls/linux/socket_test_util.h"
+#include "test/util/socket_util.h"
namespace gvisor {
namespace testing {
diff --git a/test/syscalls/linux/socket_stream_nonblock.cc b/test/syscalls/linux/socket_stream_nonblock.cc
index 74d608741..788fae906 100644
--- a/test/syscalls/linux/socket_stream_nonblock.cc
+++ b/test/syscalls/linux/socket_stream_nonblock.cc
@@ -20,8 +20,8 @@
#include <sys/un.h>
#include "gtest/gtest.h"
-#include "test/syscalls/linux/socket_test_util.h"
#include "test/syscalls/linux/unix_domain_socket_test_util.h"
+#include "test/util/socket_util.h"
#include "test/util/test_util.h"
namespace gvisor {
diff --git a/test/syscalls/linux/socket_stream_nonblock.h b/test/syscalls/linux/socket_stream_nonblock.h
index c3b7fad91..d1adaa95c 100644
--- a/test/syscalls/linux/socket_stream_nonblock.h
+++ b/test/syscalls/linux/socket_stream_nonblock.h
@@ -15,7 +15,7 @@
#ifndef GVISOR_TEST_SYSCALLS_LINUX_SOCKET_STREAM_NONBLOCK_H_
#define GVISOR_TEST_SYSCALLS_LINUX_SOCKET_STREAM_NONBLOCK_H_
-#include "test/syscalls/linux/socket_test_util.h"
+#include "test/util/socket_util.h"
namespace gvisor {
namespace testing {
diff --git a/test/syscalls/linux/socket_test_util.cc b/test/syscalls/linux/socket_test_util.cc
deleted file mode 100644
index c1cded834..000000000
--- a/test/syscalls/linux/socket_test_util.cc
+++ /dev/null
@@ -1,1117 +0,0 @@
-// Copyright 2018 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_test_util.h"
-
-#include <arpa/inet.h>
-#include <netinet/in.h>
-#include <poll.h>
-#include <sys/socket.h>
-
-#include <memory>
-
-#include "gtest/gtest.h"
-#include "absl/memory/memory.h"
-#include "absl/strings/str_cat.h"
-#include "absl/strings/str_split.h"
-#include "absl/time/clock.h"
-#include "absl/types/optional.h"
-#include "test/util/file_descriptor.h"
-#include "test/util/posix_error.h"
-#include "test/util/temp_path.h"
-#include "test/util/thread_util.h"
-
-namespace gvisor {
-namespace testing {
-
-Creator<SocketPair> SyscallSocketPairCreator(int domain, int type,
- int protocol) {
- return [=]() -> PosixErrorOr<std::unique_ptr<FDSocketPair>> {
- int pair[2];
- RETURN_ERROR_IF_SYSCALL_FAIL(socketpair(domain, type, protocol, pair));
- MaybeSave(); // Save on successful creation.
- return absl::make_unique<FDSocketPair>(pair[0], pair[1]);
- };
-}
-
-Creator<FileDescriptor> SyscallSocketCreator(int domain, int type,
- int protocol) {
- return [=]() -> PosixErrorOr<std::unique_ptr<FileDescriptor>> {
- int fd = 0;
- RETURN_ERROR_IF_SYSCALL_FAIL(fd = socket(domain, type, protocol));
- MaybeSave(); // Save on successful creation.
- return absl::make_unique<FileDescriptor>(fd);
- };
-}
-
-PosixErrorOr<struct sockaddr_un> UniqueUnixAddr(bool abstract, int domain) {
- struct sockaddr_un addr = {};
- std::string path = NewTempAbsPathInDir("/tmp");
- if (path.size() >= sizeof(addr.sun_path)) {
- return PosixError(EINVAL,
- "Unable to generate a temp path of appropriate length");
- }
-
- if (abstract) {
- // Indicate that the path is in the abstract namespace.
- path[0] = 0;
- }
- memcpy(addr.sun_path, path.c_str(), path.length());
- addr.sun_family = domain;
- return addr;
-}
-
-Creator<SocketPair> AcceptBindSocketPairCreator(bool abstract, int domain,
- int type, int protocol) {
- return [=]() -> PosixErrorOr<std::unique_ptr<AddrFDSocketPair>> {
- ASSIGN_OR_RETURN_ERRNO(struct sockaddr_un bind_addr,
- UniqueUnixAddr(abstract, domain));
- ASSIGN_OR_RETURN_ERRNO(struct sockaddr_un extra_addr,
- UniqueUnixAddr(abstract, domain));
-
- int bound;
- RETURN_ERROR_IF_SYSCALL_FAIL(bound = socket(domain, type, protocol));
- MaybeSave(); // Successful socket creation.
- RETURN_ERROR_IF_SYSCALL_FAIL(
- bind(bound, AsSockAddr(&bind_addr), sizeof(bind_addr)));
- MaybeSave(); // Successful bind.
- RETURN_ERROR_IF_SYSCALL_FAIL(
- listen(bound, /* backlog = */ 5)); // NOLINT(bugprone-argument-comment)
- MaybeSave(); // Successful listen.
-
- int connected;
- RETURN_ERROR_IF_SYSCALL_FAIL(connected = socket(domain, type, protocol));
- MaybeSave(); // Successful socket creation.
- RETURN_ERROR_IF_SYSCALL_FAIL(
- connect(connected, AsSockAddr(&bind_addr), sizeof(bind_addr)));
- MaybeSave(); // Successful connect.
-
- int accepted;
- RETURN_ERROR_IF_SYSCALL_FAIL(
- accepted = accept4(bound, nullptr, nullptr,
- type & (SOCK_NONBLOCK | SOCK_CLOEXEC)));
- MaybeSave(); // Successful connect.
-
- // Cleanup no longer needed resources.
- RETURN_ERROR_IF_SYSCALL_FAIL(close(bound));
- MaybeSave(); // Dropped original socket.
-
- // Only unlink if path is not in abstract namespace.
- if (bind_addr.sun_path[0] != 0) {
- RETURN_ERROR_IF_SYSCALL_FAIL(unlink(bind_addr.sun_path));
- MaybeSave(); // Unlinked path.
- }
-
- // accepted is before connected to destruct connected before accepted.
- // Destructors for nonstatic member objects are called in the reverse order
- // in which they appear in the class declaration.
- return absl::make_unique<AddrFDSocketPair>(accepted, connected, bind_addr,
- extra_addr);
- };
-}
-
-Creator<SocketPair> FilesystemAcceptBindSocketPairCreator(int domain, int type,
- int protocol) {
- return AcceptBindSocketPairCreator(/* abstract= */ false, domain, type,
- protocol);
-}
-
-Creator<SocketPair> AbstractAcceptBindSocketPairCreator(int domain, int type,
- int protocol) {
- return AcceptBindSocketPairCreator(/* abstract= */ true, domain, type,
- protocol);
-}
-
-Creator<SocketPair> BidirectionalBindSocketPairCreator(bool abstract,
- int domain, int type,
- int protocol) {
- return [=]() -> PosixErrorOr<std::unique_ptr<FDSocketPair>> {
- ASSIGN_OR_RETURN_ERRNO(struct sockaddr_un addr1,
- UniqueUnixAddr(abstract, domain));
- ASSIGN_OR_RETURN_ERRNO(struct sockaddr_un addr2,
- UniqueUnixAddr(abstract, domain));
-
- int sock1;
- RETURN_ERROR_IF_SYSCALL_FAIL(sock1 = socket(domain, type, protocol));
- MaybeSave(); // Successful socket creation.
- RETURN_ERROR_IF_SYSCALL_FAIL(
- bind(sock1, AsSockAddr(&addr1), sizeof(addr1)));
- MaybeSave(); // Successful bind.
-
- int sock2;
- RETURN_ERROR_IF_SYSCALL_FAIL(sock2 = socket(domain, type, protocol));
- MaybeSave(); // Successful socket creation.
- RETURN_ERROR_IF_SYSCALL_FAIL(
- bind(sock2, AsSockAddr(&addr2), sizeof(addr2)));
- MaybeSave(); // Successful bind.
-
- RETURN_ERROR_IF_SYSCALL_FAIL(
- connect(sock1, AsSockAddr(&addr2), sizeof(addr2)));
- MaybeSave(); // Successful connect.
-
- RETURN_ERROR_IF_SYSCALL_FAIL(
- connect(sock2, AsSockAddr(&addr1), sizeof(addr1)));
- MaybeSave(); // Successful connect.
-
- // Cleanup no longer needed resources.
-
- // Only unlink if path is not in abstract namespace.
- if (addr1.sun_path[0] != 0) {
- RETURN_ERROR_IF_SYSCALL_FAIL(unlink(addr1.sun_path));
- MaybeSave(); // Successful unlink.
- }
-
- // Only unlink if path is not in abstract namespace.
- if (addr2.sun_path[0] != 0) {
- RETURN_ERROR_IF_SYSCALL_FAIL(unlink(addr2.sun_path));
- MaybeSave(); // Successful unlink.
- }
-
- return absl::make_unique<FDSocketPair>(sock1, sock2);
- };
-}
-
-Creator<SocketPair> FilesystemBidirectionalBindSocketPairCreator(int domain,
- int type,
- int protocol) {
- return BidirectionalBindSocketPairCreator(/* abstract= */ false, domain, type,
- protocol);
-}
-
-Creator<SocketPair> AbstractBidirectionalBindSocketPairCreator(int domain,
- int type,
- int protocol) {
- return BidirectionalBindSocketPairCreator(/* abstract= */ true, domain, type,
- protocol);
-}
-
-Creator<SocketPair> SocketpairGoferSocketPairCreator(int domain, int type,
- int protocol) {
- return [=]() -> PosixErrorOr<std::unique_ptr<FDSocketPair>> {
- struct sockaddr_un addr = {};
- constexpr char kSocketGoferPath[] = "/socket";
- memcpy(addr.sun_path, kSocketGoferPath, sizeof(kSocketGoferPath));
- addr.sun_family = domain;
-
- int sock1;
- RETURN_ERROR_IF_SYSCALL_FAIL(sock1 = socket(domain, type, protocol));
- MaybeSave(); // Successful socket creation.
- RETURN_ERROR_IF_SYSCALL_FAIL(
- connect(sock1, AsSockAddr(&addr), sizeof(addr)));
- MaybeSave(); // Successful connect.
-
- int sock2;
- RETURN_ERROR_IF_SYSCALL_FAIL(sock2 = socket(domain, type, protocol));
- MaybeSave(); // Successful socket creation.
- RETURN_ERROR_IF_SYSCALL_FAIL(
- connect(sock2, AsSockAddr(&addr), sizeof(addr)));
- MaybeSave(); // Successful connect.
-
- // Make and close another socketpair to ensure that the duped ends of the
- // first socketpair get closed.
- //
- // The problem is that there is no way to atomically send and close an FD.
- // The closest that we can do is send and then immediately close the FD,
- // which is what we do in the gofer. The gofer won't respond to another
- // request until the reply is sent and the FD is closed, so forcing the
- // gofer to handle another request will ensure that this has happened.
- for (int i = 0; i < 2; i++) {
- int sock;
- RETURN_ERROR_IF_SYSCALL_FAIL(sock = socket(domain, type, protocol));
- RETURN_ERROR_IF_SYSCALL_FAIL(
- connect(sock, AsSockAddr(&addr), sizeof(addr)));
- RETURN_ERROR_IF_SYSCALL_FAIL(close(sock));
- }
-
- return absl::make_unique<FDSocketPair>(sock1, sock2);
- };
-}
-
-Creator<SocketPair> SocketpairGoferFileSocketPairCreator(int flags) {
- return [=]() -> PosixErrorOr<std::unique_ptr<FDSocketPair>> {
- constexpr char kSocketGoferPath[] = "/socket";
-
- int sock1;
- RETURN_ERROR_IF_SYSCALL_FAIL(sock1 =
- open(kSocketGoferPath, O_RDWR | flags));
- MaybeSave(); // Successful socket creation.
-
- int sock2;
- RETURN_ERROR_IF_SYSCALL_FAIL(sock2 =
- open(kSocketGoferPath, O_RDWR | flags));
- MaybeSave(); // Successful socket creation.
-
- return absl::make_unique<FDSocketPair>(sock1, sock2);
- };
-}
-
-Creator<SocketPair> UnboundSocketPairCreator(bool abstract, int domain,
- int type, int protocol) {
- return [=]() -> PosixErrorOr<std::unique_ptr<AddrFDSocketPair>> {
- ASSIGN_OR_RETURN_ERRNO(struct sockaddr_un addr1,
- UniqueUnixAddr(abstract, domain));
- ASSIGN_OR_RETURN_ERRNO(struct sockaddr_un addr2,
- UniqueUnixAddr(abstract, domain));
-
- int sock1;
- RETURN_ERROR_IF_SYSCALL_FAIL(sock1 = socket(domain, type, protocol));
- MaybeSave(); // Successful socket creation.
- int sock2;
- RETURN_ERROR_IF_SYSCALL_FAIL(sock2 = socket(domain, type, protocol));
- MaybeSave(); // Successful socket creation.
- return absl::make_unique<AddrFDSocketPair>(sock1, sock2, addr1, addr2);
- };
-}
-
-Creator<SocketPair> FilesystemUnboundSocketPairCreator(int domain, int type,
- int protocol) {
- return UnboundSocketPairCreator(/* abstract= */ false, domain, type,
- protocol);
-}
-
-Creator<SocketPair> AbstractUnboundSocketPairCreator(int domain, int type,
- int protocol) {
- return UnboundSocketPairCreator(/* abstract= */ true, domain, type, protocol);
-}
-
-void LocalhostAddr(struct sockaddr_in* addr, bool dual_stack) {
- addr->sin_family = AF_INET;
- addr->sin_port = htons(0);
- inet_pton(AF_INET, "127.0.0.1",
- reinterpret_cast<void*>(&addr->sin_addr.s_addr));
-}
-
-void LocalhostAddr(struct sockaddr_in6* addr, bool dual_stack) {
- addr->sin6_family = AF_INET6;
- addr->sin6_port = htons(0);
- if (dual_stack) {
- inet_pton(AF_INET6, "::ffff:127.0.0.1",
- reinterpret_cast<void*>(&addr->sin6_addr.s6_addr));
- } else {
- inet_pton(AF_INET6, "::1",
- reinterpret_cast<void*>(&addr->sin6_addr.s6_addr));
- }
- addr->sin6_scope_id = 0;
-}
-
-template <typename T>
-PosixErrorOr<T> BindIP(int fd, bool dual_stack) {
- T addr = {};
- LocalhostAddr(&addr, dual_stack);
- RETURN_ERROR_IF_SYSCALL_FAIL(bind(fd, AsSockAddr(&addr), sizeof(addr)));
- socklen_t addrlen = sizeof(addr);
- RETURN_ERROR_IF_SYSCALL_FAIL(getsockname(fd, AsSockAddr(&addr), &addrlen));
- return addr;
-}
-
-template <typename T>
-PosixErrorOr<T> TCPBindAndListen(int fd, bool dual_stack) {
- ASSIGN_OR_RETURN_ERRNO(T addr, BindIP<T>(fd, dual_stack));
- RETURN_ERROR_IF_SYSCALL_FAIL(
- listen(fd, /* backlog = */ 5)); // NOLINT(bugprone-argument-comment)
- return addr;
-}
-
-template <typename T>
-PosixErrorOr<std::unique_ptr<AddrFDSocketPair>>
-CreateTCPConnectAcceptSocketPair(int bound, int connected, int type,
- bool dual_stack, T bind_addr) {
- int connect_result = 0;
- RETURN_ERROR_IF_SYSCALL_FAIL(
- (connect_result = RetryEINTR(connect)(connected, AsSockAddr(&bind_addr),
- sizeof(bind_addr))) == -1 &&
- errno == EINPROGRESS
- ? 0
- : connect_result);
- MaybeSave(); // Successful connect.
-
- if (connect_result == -1) {
- struct pollfd connect_poll = {connected, POLLOUT | POLLERR | POLLHUP, 0};
- RETURN_ERROR_IF_SYSCALL_FAIL(RetryEINTR(poll)(&connect_poll, 1, 0));
- int error = 0;
- socklen_t errorlen = sizeof(error);
- RETURN_ERROR_IF_SYSCALL_FAIL(
- getsockopt(connected, SOL_SOCKET, SO_ERROR, &error, &errorlen));
- errno = error;
- RETURN_ERROR_IF_SYSCALL_FAIL(
- /* connect */ error == 0 ? 0 : -1);
- }
-
- int accepted = -1;
- struct pollfd accept_poll = {bound, POLLIN, 0};
- while (accepted == -1) {
- RETURN_ERROR_IF_SYSCALL_FAIL(RetryEINTR(poll)(&accept_poll, 1, 0));
-
- RETURN_ERROR_IF_SYSCALL_FAIL(
- (accepted = RetryEINTR(accept4)(
- bound, nullptr, nullptr, type & (SOCK_NONBLOCK | SOCK_CLOEXEC))) ==
- -1 &&
- errno == EAGAIN
- ? 0
- : accepted);
- }
- MaybeSave(); // Successful accept.
-
- T extra_addr = {};
- LocalhostAddr(&extra_addr, dual_stack);
- return absl::make_unique<AddrFDSocketPair>(connected, accepted, bind_addr,
- extra_addr);
-}
-
-template <typename T>
-PosixErrorOr<std::unique_ptr<AddrFDSocketPair>> CreateTCPAcceptBindSocketPair(
- int bound, int connected, int type, bool dual_stack) {
- ASSIGN_OR_RETURN_ERRNO(T bind_addr, TCPBindAndListen<T>(bound, dual_stack));
-
- auto result = CreateTCPConnectAcceptSocketPair(bound, connected, type,
- dual_stack, bind_addr);
-
- // Cleanup no longer needed resources.
- RETURN_ERROR_IF_SYSCALL_FAIL(close(bound));
- MaybeSave(); // Successful close.
-
- return result;
-}
-
-Creator<SocketPair> TCPAcceptBindSocketPairCreator(int domain, int type,
- int protocol,
- bool dual_stack) {
- return [=]() -> PosixErrorOr<std::unique_ptr<AddrFDSocketPair>> {
- int bound;
- RETURN_ERROR_IF_SYSCALL_FAIL(bound = socket(domain, type, protocol));
- MaybeSave(); // Successful socket creation.
-
- int connected;
- RETURN_ERROR_IF_SYSCALL_FAIL(connected = socket(domain, type, protocol));
- MaybeSave(); // Successful socket creation.
-
- if (domain == AF_INET) {
- return CreateTCPAcceptBindSocketPair<sockaddr_in>(bound, connected, type,
- dual_stack);
- }
- return CreateTCPAcceptBindSocketPair<sockaddr_in6>(bound, connected, type,
- dual_stack);
- };
-}
-
-Creator<SocketPair> TCPAcceptBindPersistentListenerSocketPairCreator(
- int domain, int type, int protocol, bool dual_stack) {
- // These are lazily initialized below, on the first call to the returned
- // lambda. These values are private to each returned lambda, but shared across
- // invocations of a specific lambda.
- //
- // The sharing allows pairs created with the same parameters to share a
- // listener. This prevents future connects from failing if the connecting
- // socket selects a port which had previously been used by a listening socket
- // that still has some connections in TIME-WAIT.
- //
- // The lazy initialization is to avoid creating sockets during parameter
- // enumeration. This is important because parameters are enumerated during the
- // build process where networking may not be available.
- auto listener = std::make_shared<absl::optional<int>>(absl::optional<int>());
- auto addr4 = std::make_shared<absl::optional<sockaddr_in>>(
- absl::optional<sockaddr_in>());
- auto addr6 = std::make_shared<absl::optional<sockaddr_in6>>(
- absl::optional<sockaddr_in6>());
-
- return [=]() -> PosixErrorOr<std::unique_ptr<AddrFDSocketPair>> {
- int connected;
- RETURN_ERROR_IF_SYSCALL_FAIL(connected = socket(domain, type, protocol));
- MaybeSave(); // Successful socket creation.
-
- // Share the listener across invocations.
- if (!listener->has_value()) {
- int fd = socket(domain, type, protocol);
- if (fd < 0) {
- return PosixError(errno, absl::StrCat("socket(", domain, ", ", type,
- ", ", protocol, ")"));
- }
- listener->emplace(fd);
- MaybeSave(); // Successful socket creation.
- }
-
- // Bind the listener once, but create a new connect/accept pair each
- // time.
- if (domain == AF_INET) {
- if (!addr4->has_value()) {
- addr4->emplace(
- TCPBindAndListen<sockaddr_in>(listener->value(), dual_stack)
- .ValueOrDie());
- }
- return CreateTCPConnectAcceptSocketPair(listener->value(), connected,
- type, dual_stack, addr4->value());
- }
- if (!addr6->has_value()) {
- addr6->emplace(
- TCPBindAndListen<sockaddr_in6>(listener->value(), dual_stack)
- .ValueOrDie());
- }
- return CreateTCPConnectAcceptSocketPair(listener->value(), connected, type,
- dual_stack, addr6->value());
- };
-}
-
-template <typename T>
-PosixErrorOr<std::unique_ptr<AddrFDSocketPair>> CreateUDPBoundSocketPair(
- int sock1, int sock2, int type, bool dual_stack) {
- ASSIGN_OR_RETURN_ERRNO(T addr1, BindIP<T>(sock1, dual_stack));
- ASSIGN_OR_RETURN_ERRNO(T addr2, BindIP<T>(sock2, dual_stack));
-
- return absl::make_unique<AddrFDSocketPair>(sock1, sock2, addr1, addr2);
-}
-
-template <typename T>
-PosixErrorOr<std::unique_ptr<AddrFDSocketPair>>
-CreateUDPBidirectionalBindSocketPair(int sock1, int sock2, int type,
- bool dual_stack) {
- ASSIGN_OR_RETURN_ERRNO(
- auto socks, CreateUDPBoundSocketPair<T>(sock1, sock2, type, dual_stack));
-
- // Connect sock1 to sock2.
- RETURN_ERROR_IF_SYSCALL_FAIL(connect(socks->first_fd(), socks->second_addr(),
- socks->second_addr_size()));
- MaybeSave(); // Successful connection.
-
- // Connect sock2 to sock1.
- RETURN_ERROR_IF_SYSCALL_FAIL(connect(socks->second_fd(), socks->first_addr(),
- socks->first_addr_size()));
- MaybeSave(); // Successful connection.
-
- return socks;
-}
-
-Creator<SocketPair> UDPBidirectionalBindSocketPairCreator(int domain, int type,
- int protocol,
- bool dual_stack) {
- return [=]() -> PosixErrorOr<std::unique_ptr<AddrFDSocketPair>> {
- int sock1;
- RETURN_ERROR_IF_SYSCALL_FAIL(sock1 = socket(domain, type, protocol));
- MaybeSave(); // Successful socket creation.
-
- int sock2;
- RETURN_ERROR_IF_SYSCALL_FAIL(sock2 = socket(domain, type, protocol));
- MaybeSave(); // Successful socket creation.
-
- if (domain == AF_INET) {
- return CreateUDPBidirectionalBindSocketPair<sockaddr_in>(
- sock1, sock2, type, dual_stack);
- }
- return CreateUDPBidirectionalBindSocketPair<sockaddr_in6>(sock1, sock2,
- type, dual_stack);
- };
-}
-
-Creator<SocketPair> UDPUnboundSocketPairCreator(int domain, int type,
- int protocol, bool dual_stack) {
- return [=]() -> PosixErrorOr<std::unique_ptr<FDSocketPair>> {
- int sock1;
- RETURN_ERROR_IF_SYSCALL_FAIL(sock1 = socket(domain, type, protocol));
- MaybeSave(); // Successful socket creation.
-
- int sock2;
- RETURN_ERROR_IF_SYSCALL_FAIL(sock2 = socket(domain, type, protocol));
- MaybeSave(); // Successful socket creation.
-
- return absl::make_unique<FDSocketPair>(sock1, sock2);
- };
-}
-
-SocketPairKind Reversed(SocketPairKind const& base) {
- auto const& creator = base.creator;
- return SocketPairKind{
- absl::StrCat("reversed ", base.description), base.domain, base.type,
- base.protocol,
- [creator]() -> PosixErrorOr<std::unique_ptr<ReversedSocketPair>> {
- ASSIGN_OR_RETURN_ERRNO(auto creator_value, creator());
- return absl::make_unique<ReversedSocketPair>(std::move(creator_value));
- }};
-}
-
-Creator<FileDescriptor> UnboundSocketCreator(int domain, int type,
- int protocol) {
- return [=]() -> PosixErrorOr<std::unique_ptr<FileDescriptor>> {
- int sock;
- RETURN_ERROR_IF_SYSCALL_FAIL(sock = socket(domain, type, protocol));
- MaybeSave(); // Successful socket creation.
-
- return absl::make_unique<FileDescriptor>(sock);
- };
-}
-
-std::vector<SocketPairKind> IncludeReversals(std::vector<SocketPairKind> vec) {
- return ApplyVecToVec<SocketPairKind>(std::vector<Middleware>{NoOp, Reversed},
- vec);
-}
-
-SocketPairKind NoOp(SocketPairKind const& base) { return base; }
-
-void TransferTest(int fd1, int fd2) {
- char buf1[20];
- RandomizeBuffer(buf1, sizeof(buf1));
- ASSERT_THAT(WriteFd(fd1, buf1, sizeof(buf1)),
- SyscallSucceedsWithValue(sizeof(buf1)));
-
- char buf2[20];
- ASSERT_THAT(ReadFd(fd2, buf2, sizeof(buf2)),
- SyscallSucceedsWithValue(sizeof(buf2)));
-
- EXPECT_EQ(0, memcmp(buf1, buf2, sizeof(buf1)));
-
- RandomizeBuffer(buf1, sizeof(buf1));
- ASSERT_THAT(WriteFd(fd2, buf1, sizeof(buf1)),
- SyscallSucceedsWithValue(sizeof(buf1)));
-
- ASSERT_THAT(ReadFd(fd1, buf2, sizeof(buf2)),
- SyscallSucceedsWithValue(sizeof(buf2)));
-
- EXPECT_EQ(0, memcmp(buf1, buf2, sizeof(buf1)));
-}
-
-// Initializes the given buffer with random data.
-void RandomizeBuffer(char* ptr, size_t len) {
- uint32_t seed = time(nullptr);
- for (size_t i = 0; i < len; ++i) {
- ptr[i] = static_cast<char>(rand_r(&seed));
- }
-}
-
-size_t CalculateUnixSockAddrLen(const char* sun_path) {
- // Abstract addresses always return the full length.
- if (sun_path[0] == 0) {
- return sizeof(sockaddr_un);
- }
- // Filesystem addresses use the address length plus the 2 byte sun_family
- // and null terminator.
- return strlen(sun_path) + 3;
-}
-
-struct sockaddr_storage AddrFDSocketPair::to_storage(const sockaddr_un& addr) {
- struct sockaddr_storage addr_storage = {};
- memcpy(&addr_storage, &addr, sizeof(addr));
- return addr_storage;
-}
-
-struct sockaddr_storage AddrFDSocketPair::to_storage(const sockaddr_in& addr) {
- struct sockaddr_storage addr_storage = {};
- memcpy(&addr_storage, &addr, sizeof(addr));
- return addr_storage;
-}
-
-struct sockaddr_storage AddrFDSocketPair::to_storage(const sockaddr_in6& addr) {
- struct sockaddr_storage addr_storage = {};
- memcpy(&addr_storage, &addr, sizeof(addr));
- return addr_storage;
-}
-
-SocketKind SimpleSocket(int fam, int type, int proto) {
- return SocketKind{
- absl::StrCat("Family ", fam, ", type ", type, ", proto ", proto), fam,
- type, proto, SyscallSocketCreator(fam, type, proto)};
-}
-
-ssize_t SendLargeSendMsg(const std::unique_ptr<SocketPair>& sockets,
- size_t size, bool reader) {
- const int rfd = sockets->second_fd();
- ScopedThread t([rfd, size, reader] {
- if (!reader) {
- return;
- }
-
- // Potentially too many syscalls in the loop.
- const DisableSave ds;
-
- std::vector<char> buf(size);
- size_t total = 0;
-
- while (total < size) {
- int ret = read(rfd, buf.data(), buf.size());
- if (ret == -1 && errno == EAGAIN) {
- continue;
- }
- if (ret > 0) {
- total += ret;
- }
-
- // Assert to return on first failure.
- ASSERT_THAT(ret, SyscallSucceeds());
- }
- });
-
- std::vector<char> buf(size);
-
- struct iovec iov = {};
- iov.iov_base = buf.data();
- iov.iov_len = buf.size();
-
- struct msghdr msg = {};
- msg.msg_iov = &iov;
- msg.msg_iovlen = 1;
-
- return RetryEINTR(sendmsg)(sockets->first_fd(), &msg, 0);
-}
-
-namespace internal {
-PosixErrorOr<int> TryPortAvailable(int port, AddressFamily family,
- SocketType type, bool reuse_addr) {
- if (port < 0) {
- return PosixError(EINVAL, "Invalid port");
- }
-
- // Both Ipv6 and Dualstack are AF_INET6.
- int sock_fam = (family == AddressFamily::kIpv4 ? AF_INET : AF_INET6);
- int sock_type = (type == SocketType::kTcp ? SOCK_STREAM : SOCK_DGRAM);
- ASSIGN_OR_RETURN_ERRNO(auto fd, Socket(sock_fam, sock_type, 0));
-
- if (reuse_addr) {
- int one = 1;
- RETURN_ERROR_IF_SYSCALL_FAIL(
- setsockopt(fd.get(), SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)));
- }
-
- // Try to bind.
- sockaddr_storage storage = {};
- int storage_size = 0;
- if (family == AddressFamily::kIpv4) {
- sockaddr_in* addr = reinterpret_cast<sockaddr_in*>(&storage);
- storage_size = sizeof(*addr);
- addr->sin_family = AF_INET;
- addr->sin_port = htons(port);
- addr->sin_addr.s_addr = htonl(INADDR_ANY);
- } else {
- sockaddr_in6* addr = reinterpret_cast<sockaddr_in6*>(&storage);
- storage_size = sizeof(*addr);
- addr->sin6_family = AF_INET6;
- addr->sin6_port = htons(port);
- if (family == AddressFamily::kDualStack) {
- inet_pton(AF_INET6, "::ffff:0.0.0.0",
- reinterpret_cast<void*>(&addr->sin6_addr.s6_addr));
- } else {
- addr->sin6_addr = in6addr_any;
- }
- }
-
- RETURN_ERROR_IF_SYSCALL_FAIL(
- bind(fd.get(), AsSockAddr(&storage), storage_size));
-
- // If the user specified 0 as the port, we will return the port that the
- // kernel gave us, otherwise we will validate that this socket bound to the
- // requested port.
- sockaddr_storage bound_storage = {};
- socklen_t bound_storage_size = sizeof(bound_storage);
- RETURN_ERROR_IF_SYSCALL_FAIL(
- getsockname(fd.get(), AsSockAddr(&bound_storage), &bound_storage_size));
-
- int available_port = -1;
- if (bound_storage.ss_family == AF_INET) {
- sockaddr_in* addr = reinterpret_cast<sockaddr_in*>(&bound_storage);
- available_port = ntohs(addr->sin_port);
- } else if (bound_storage.ss_family == AF_INET6) {
- sockaddr_in6* addr = reinterpret_cast<sockaddr_in6*>(&bound_storage);
- available_port = ntohs(addr->sin6_port);
- } else {
- return PosixError(EPROTOTYPE, "Getsockname returned invalid family");
- }
-
- // If we requested a specific port make sure our bound port is that port.
- if (port != 0 && available_port != port) {
- return PosixError(EINVAL,
- absl::StrCat("Bound port ", available_port,
- " was not equal to requested port ", port));
- }
-
- // If we're trying to do a TCP socket, let's also try to listen.
- if (type == SocketType::kTcp) {
- RETURN_ERROR_IF_SYSCALL_FAIL(listen(fd.get(), 1));
- }
-
- return available_port;
-}
-} // namespace internal
-
-PosixErrorOr<int> SendMsg(int sock, msghdr* msg, char buf[], int buf_size) {
- struct iovec iov;
- iov.iov_base = buf;
- iov.iov_len = buf_size;
- msg->msg_iov = &iov;
- msg->msg_iovlen = 1;
-
- int ret;
- RETURN_ERROR_IF_SYSCALL_FAIL(ret = RetryEINTR(sendmsg)(sock, msg, 0));
- return ret;
-}
-
-PosixErrorOr<int> RecvTimeout(int sock, char buf[], int buf_size, int timeout) {
- fd_set rfd;
- struct timeval to = {.tv_sec = timeout, .tv_usec = 0};
- FD_ZERO(&rfd);
- FD_SET(sock, &rfd);
-
- int ret;
- RETURN_ERROR_IF_SYSCALL_FAIL(ret = select(1, &rfd, NULL, NULL, &to));
- RETURN_ERROR_IF_SYSCALL_FAIL(
- ret = RetryEINTR(recv)(sock, buf, buf_size, MSG_DONTWAIT));
- return ret;
-}
-
-PosixErrorOr<int> RecvMsgTimeout(int sock, struct msghdr* msg, int timeout) {
- fd_set rfd;
- struct timeval to = {.tv_sec = timeout, .tv_usec = 0};
- FD_ZERO(&rfd);
- FD_SET(sock, &rfd);
-
- int ret;
- RETURN_ERROR_IF_SYSCALL_FAIL(ret = select(1, &rfd, NULL, NULL, &to));
- RETURN_ERROR_IF_SYSCALL_FAIL(
- ret = RetryEINTR(recvmsg)(sock, msg, MSG_DONTWAIT));
- return ret;
-}
-
-void RecvNoData(int sock) {
- char data = 0;
- struct iovec iov;
- iov.iov_base = &data;
- iov.iov_len = 1;
- struct msghdr msg = {};
- msg.msg_iov = &iov;
- msg.msg_iovlen = 1;
- ASSERT_THAT(RetryEINTR(recvmsg)(sock, &msg, MSG_DONTWAIT),
- SyscallFailsWithErrno(EAGAIN));
-}
-
-TestAddress TestAddress::WithPort(uint16_t port) const {
- TestAddress addr = *this;
- switch (addr.family()) {
- case AF_INET:
- reinterpret_cast<sockaddr_in*>(&addr.addr)->sin_port = htons(port);
- break;
- case AF_INET6:
- reinterpret_cast<sockaddr_in6*>(&addr.addr)->sin6_port = htons(port);
- break;
- }
- return addr;
-}
-
-namespace {
-
-TestAddress V4Addr(std::string description, in_addr_t addr) {
- TestAddress t(std::move(description));
- t.addr.ss_family = AF_INET;
- t.addr_len = sizeof(sockaddr_in);
- reinterpret_cast<sockaddr_in*>(&t.addr)->sin_addr.s_addr = addr;
- return t;
-}
-
-TestAddress V6Addr(std::string description, const in6_addr& addr) {
- TestAddress t(std::move(description));
- t.addr.ss_family = AF_INET6;
- t.addr_len = sizeof(sockaddr_in6);
- reinterpret_cast<sockaddr_in6*>(&t.addr)->sin6_addr = addr;
- return t;
-}
-
-} // namespace
-
-TestAddress V4AddrStr(std::string description, const char* addr) {
- in_addr_t s_addr;
- inet_pton(AF_INET, addr, &s_addr);
- return V4Addr(description, s_addr);
-}
-
-TestAddress V6AddrStr(std::string description, const char* addr) {
- struct in6_addr s_addr;
- inet_pton(AF_INET6, addr, &s_addr);
- return V6Addr(description, s_addr);
-}
-
-TestAddress V4Any() { return V4Addr("V4Any", htonl(INADDR_ANY)); }
-
-TestAddress V4Broadcast() {
- return V4Addr("V4Broadcast", htonl(INADDR_BROADCAST));
-}
-
-TestAddress V4Loopback() {
- return V4Addr("V4Loopback", htonl(INADDR_LOOPBACK));
-}
-
-TestAddress V4LoopbackSubnetBroadcast() {
- return V4AddrStr("V4LoopbackSubnetBroadcast", "127.255.255.255");
-}
-
-TestAddress V4MappedAny() { return V6AddrStr("V4MappedAny", "::ffff:0.0.0.0"); }
-
-TestAddress V4MappedLoopback() {
- return V6AddrStr("V4MappedLoopback", "::ffff:127.0.0.1");
-}
-
-TestAddress V4Multicast() {
- return V4Addr("V4Multicast", inet_addr(kMulticastAddress));
-}
-
-TestAddress V4MulticastAllHosts() {
- return V4Addr("V4MulticastAllHosts", htonl(INADDR_ALLHOSTS_GROUP));
-}
-
-TestAddress V6Any() { return V6Addr("V6Any", in6addr_any); }
-
-TestAddress V6Loopback() { return V6Addr("V6Loopback", in6addr_loopback); }
-
-TestAddress V6Multicast() { return V6AddrStr("V6Multicast", "ff05::1234"); }
-
-TestAddress V6MulticastInterfaceLocalAllNodes() {
- return V6AddrStr("V6MulticastInterfaceLocalAllNodes", "ff01::1");
-}
-
-TestAddress V6MulticastLinkLocalAllNodes() {
- return V6AddrStr("V6MulticastLinkLocalAllNodes", "ff02::1");
-}
-
-TestAddress V6MulticastLinkLocalAllRouters() {
- return V6AddrStr("V6MulticastLinkLocalAllRouters", "ff02::2");
-}
-
-// Checksum computes the internet checksum of a buffer.
-uint16_t Checksum(uint16_t* buf, ssize_t buf_size) {
- // Add up the 16-bit values in the buffer.
- uint32_t total = 0;
- for (unsigned int i = 0; i < buf_size; i += sizeof(*buf)) {
- total += *buf;
- buf++;
- }
-
- // If buf has an odd size, add the remaining byte.
- if (buf_size % 2) {
- total += *(reinterpret_cast<unsigned char*>(buf) - 1);
- }
-
- // This carries any bits past the lower 16 until everything fits in 16 bits.
- while (total >> 16) {
- uint16_t lower = total & 0xffff;
- uint16_t upper = total >> 16;
- total = lower + upper;
- }
-
- return ~total;
-}
-
-uint16_t IPChecksum(struct iphdr ip) {
- return Checksum(reinterpret_cast<uint16_t*>(&ip), sizeof(ip));
-}
-
-// The pseudo-header defined in RFC 768 for calculating the UDP checksum.
-struct udp_pseudo_hdr {
- uint32_t srcip;
- uint32_t destip;
- char zero;
- char protocol;
- uint16_t udplen;
-};
-
-uint16_t UDPChecksum(struct iphdr iphdr, struct udphdr udphdr,
- const char* payload, ssize_t payload_len) {
- struct udp_pseudo_hdr phdr = {};
- phdr.srcip = iphdr.saddr;
- phdr.destip = iphdr.daddr;
- phdr.zero = 0;
- phdr.protocol = IPPROTO_UDP;
- phdr.udplen = udphdr.len;
-
- ssize_t buf_size = sizeof(phdr) + sizeof(udphdr) + payload_len;
- char* buf = static_cast<char*>(malloc(buf_size));
- memcpy(buf, &phdr, sizeof(phdr));
- memcpy(buf + sizeof(phdr), &udphdr, sizeof(udphdr));
- memcpy(buf + sizeof(phdr) + sizeof(udphdr), payload, payload_len);
-
- uint16_t csum = Checksum(reinterpret_cast<uint16_t*>(buf), buf_size);
- free(buf);
- return csum;
-}
-
-uint16_t ICMPChecksum(struct icmphdr icmphdr, const char* payload,
- ssize_t payload_len) {
- ssize_t buf_size = sizeof(icmphdr) + payload_len;
- char* buf = static_cast<char*>(malloc(buf_size));
- memcpy(buf, &icmphdr, sizeof(icmphdr));
- memcpy(buf + sizeof(icmphdr), payload, payload_len);
-
- uint16_t csum = Checksum(reinterpret_cast<uint16_t*>(buf), buf_size);
- free(buf);
- return csum;
-}
-
-PosixErrorOr<uint16_t> AddrPort(int family, sockaddr_storage const& addr) {
- switch (family) {
- case AF_INET:
- return static_cast<uint16_t>(
- reinterpret_cast<sockaddr_in const*>(&addr)->sin_port);
- case AF_INET6:
- return static_cast<uint16_t>(
- reinterpret_cast<sockaddr_in6 const*>(&addr)->sin6_port);
- default:
- return PosixError(EINVAL,
- absl::StrCat("unknown socket family: ", family));
- }
-}
-
-PosixError SetAddrPort(int family, sockaddr_storage* addr, uint16_t port) {
- switch (family) {
- case AF_INET:
- reinterpret_cast<sockaddr_in*>(addr)->sin_port = port;
- return NoError();
- case AF_INET6:
- reinterpret_cast<sockaddr_in6*>(addr)->sin6_port = port;
- return NoError();
- default:
- return PosixError(EINVAL,
- absl::StrCat("unknown socket family: ", family));
- }
-}
-
-void SetupTimeWaitClose(const TestAddress* listener,
- const TestAddress* connector, bool reuse,
- bool accept_close, sockaddr_storage* listen_addr,
- sockaddr_storage* conn_bound_addr) {
- // Create the listening socket.
- FileDescriptor listen_fd = ASSERT_NO_ERRNO_AND_VALUE(
- Socket(listener->family(), SOCK_STREAM, IPPROTO_TCP));
- if (reuse) {
- ASSERT_THAT(setsockopt(listen_fd.get(), SOL_SOCKET, SO_REUSEADDR,
- &kSockOptOn, sizeof(kSockOptOn)),
- SyscallSucceeds());
- }
- ASSERT_THAT(
- bind(listen_fd.get(), AsSockAddr(listen_addr), listener->addr_len),
- SyscallSucceeds());
- ASSERT_THAT(listen(listen_fd.get(), SOMAXCONN), SyscallSucceeds());
-
- // Get the port bound by the listening socket.
- socklen_t addrlen = listener->addr_len;
- ASSERT_THAT(getsockname(listen_fd.get(), AsSockAddr(listen_addr), &addrlen),
- SyscallSucceeds());
-
- uint16_t const port =
- ASSERT_NO_ERRNO_AND_VALUE(AddrPort(listener->family(), *listen_addr));
-
- // Connect to the listening socket.
- FileDescriptor conn_fd = ASSERT_NO_ERRNO_AND_VALUE(
- Socket(connector->family(), SOCK_STREAM, IPPROTO_TCP));
-
- // We disable saves after this point as a S/R causes the netstack seed
- // to be regenerated which changes what ports/ISN is picked for a given
- // tuple (src ip,src port, dst ip, dst port). This can cause the final
- // SYN to use a sequence number that looks like one from the current
- // connection in TIME_WAIT and will not be accepted causing the test
- // to timeout.
- //
- // TODO(gvisor.dev/issue/940): S/R portSeed/portHint
- DisableSave ds;
-
- sockaddr_storage conn_addr = connector->addr;
- ASSERT_NO_ERRNO(SetAddrPort(connector->family(), &conn_addr, port));
- ASSERT_THAT(RetryEINTR(connect)(conn_fd.get(), AsSockAddr(&conn_addr),
- connector->addr_len),
- SyscallSucceeds());
-
- // Accept the connection.
- auto accepted =
- ASSERT_NO_ERRNO_AND_VALUE(Accept(listen_fd.get(), nullptr, nullptr));
-
- // Get the address/port bound by the connecting socket.
- socklen_t conn_addrlen = connector->addr_len;
- ASSERT_THAT(
- getsockname(conn_fd.get(), AsSockAddr(conn_bound_addr), &conn_addrlen),
- SyscallSucceeds());
-
- FileDescriptor active_closefd, passive_closefd;
- if (accept_close) {
- active_closefd = std::move(accepted);
- passive_closefd = std::move(conn_fd);
- } else {
- active_closefd = std::move(conn_fd);
- passive_closefd = std::move(accepted);
- }
-
- // shutdown to trigger TIME_WAIT.
- ASSERT_THAT(shutdown(active_closefd.get(), SHUT_WR), SyscallSucceeds());
- {
- constexpr int kTimeout = 10000;
- pollfd pfd = {
- .fd = passive_closefd.get(),
- .events = POLLIN,
- };
- ASSERT_THAT(poll(&pfd, 1, kTimeout), SyscallSucceedsWithValue(1));
- ASSERT_EQ(pfd.revents, POLLIN);
- }
- ASSERT_THAT(shutdown(passive_closefd.get(), SHUT_WR), SyscallSucceeds());
- {
- constexpr int kTimeout = 10000;
- constexpr int16_t want_events = POLLHUP;
- pollfd pfd = {
- .fd = active_closefd.get(),
- .events = want_events,
- };
- ASSERT_THAT(poll(&pfd, 1, kTimeout), SyscallSucceedsWithValue(1));
- }
-
- // This sleep is needed to reduce flake to ensure that the passive-close
- // ensures the state transitions to CLOSE from LAST_ACK.
- absl::SleepFor(absl::Seconds(1));
-}
-
-constexpr char kRangeFile[] = "/proc/sys/net/ipv4/ip_local_port_range";
-
-PosixErrorOr<int> MaybeLimitEphemeralPorts() {
- int min = 0;
- int max = 1 << 16;
-
- // Read the ephemeral range from /proc.
- ASSIGN_OR_RETURN_ERRNO(std::string rangefile, GetContents(kRangeFile));
- const std::string err_msg =
- absl::StrFormat("%s has invalid content: %s", kRangeFile, rangefile);
- if (rangefile.back() != '\n') {
- return PosixError(EINVAL, err_msg);
- }
- rangefile.pop_back();
- std::vector<std::string> range =
- absl::StrSplit(rangefile, absl::ByAnyChar("\t "));
- if (range.size() < 2 || !absl::SimpleAtoi(range.front(), &min) ||
- !absl::SimpleAtoi(range.back(), &max)) {
- return PosixError(EINVAL, err_msg);
- }
-
- // If we can open as writable, limit the range.
- if (!access(kRangeFile, W_OK)) {
- ASSIGN_OR_RETURN_ERRNO(FileDescriptor fd,
- Open(kRangeFile, O_WRONLY | O_TRUNC, 0));
- int newMax = min + 50;
- const std::string small_range = absl::StrFormat("%d %d", min, newMax);
- int n = write(fd.get(), small_range.c_str(), small_range.size());
- if (n < 0) {
- // Hostinet doesn't allow modifying the host port range. And if we're root
- // (as we are in some tests), access and open will succeed even if the
- // file mode is readonly.
- if (errno != EACCES) {
- return PosixError(
- errno,
- absl::StrFormat("write(%d [%s], \"%s\", %d)", fd.get(), kRangeFile,
- small_range.c_str(), small_range.size()));
- }
- } else {
- max = newMax;
- }
- }
- return max - min;
-}
-
-} // namespace testing
-} // namespace gvisor
diff --git a/test/syscalls/linux/socket_test_util.h b/test/syscalls/linux/socket_test_util.h
deleted file mode 100644
index 0e2be63cc..000000000
--- a/test/syscalls/linux/socket_test_util.h
+++ /dev/null
@@ -1,591 +0,0 @@
-// Copyright 2018 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.
-
-#ifndef GVISOR_TEST_SYSCALLS_SOCKET_TEST_UTIL_H_
-#define GVISOR_TEST_SYSCALLS_SOCKET_TEST_UTIL_H_
-
-#include <errno.h>
-#include <netinet/ip.h>
-#include <netinet/ip_icmp.h>
-#include <netinet/udp.h>
-#include <sys/socket.h>
-#include <sys/types.h>
-#include <sys/un.h>
-
-#include <functional>
-#include <memory>
-#include <string>
-#include <utility>
-#include <vector>
-
-#include "gtest/gtest.h"
-#include "absl/strings/str_format.h"
-#include "test/util/file_descriptor.h"
-#include "test/util/posix_error.h"
-#include "test/util/test_util.h"
-
-namespace gvisor {
-namespace testing {
-
-// Wrapper for socket(2) that returns a FileDescriptor.
-inline PosixErrorOr<FileDescriptor> Socket(int family, int type, int protocol) {
- int fd = socket(family, type, protocol);
- MaybeSave();
- if (fd < 0) {
- return PosixError(
- errno, absl::StrFormat("socket(%d, %d, %d)", family, type, protocol));
- }
- return FileDescriptor(fd);
-}
-
-// Wrapper for accept(2) that returns a FileDescriptor.
-inline PosixErrorOr<FileDescriptor> Accept(int sockfd, sockaddr* addr,
- socklen_t* addrlen) {
- int fd = RetryEINTR(accept)(sockfd, addr, addrlen);
- MaybeSave();
- if (fd < 0) {
- return PosixError(
- errno, absl::StrFormat("accept(%d, %p, %p)", sockfd, addr, addrlen));
- }
- return FileDescriptor(fd);
-}
-
-// Wrapper for accept4(2) that returns a FileDescriptor.
-inline PosixErrorOr<FileDescriptor> Accept4(int sockfd, sockaddr* addr,
- socklen_t* addrlen, int flags) {
- int fd = RetryEINTR(accept4)(sockfd, addr, addrlen, flags);
- MaybeSave();
- if (fd < 0) {
- return PosixError(errno, absl::StrFormat("accept4(%d, %p, %p, %#x)", sockfd,
- addr, addrlen, flags));
- }
- return FileDescriptor(fd);
-}
-
-inline ssize_t SendFd(int fd, void* buf, size_t count, int flags) {
- return internal::ApplyFileIoSyscall(
- [&](size_t completed) {
- return sendto(fd, static_cast<char*>(buf) + completed,
- count - completed, flags, nullptr, 0);
- },
- count);
-}
-
-PosixErrorOr<struct sockaddr_un> UniqueUnixAddr(bool abstract, int domain);
-
-// A Creator<T> is a function that attempts to create and return a new T. (This
-// is copy/pasted from cloud/gvisor/api/sandbox_util.h and is just duplicated
-// here for clarity.)
-template <typename T>
-using Creator = std::function<PosixErrorOr<std::unique_ptr<T>>()>;
-
-// A SocketPair represents a pair of socket file descriptors owned by the
-// SocketPair.
-class SocketPair {
- public:
- virtual ~SocketPair() = default;
-
- virtual int first_fd() const = 0;
- virtual int second_fd() const = 0;
- virtual int release_first_fd() = 0;
- virtual int release_second_fd() = 0;
- virtual const struct sockaddr* first_addr() const = 0;
- virtual const struct sockaddr* second_addr() const = 0;
- virtual size_t first_addr_size() const = 0;
- virtual size_t second_addr_size() const = 0;
- virtual size_t first_addr_len() const = 0;
- virtual size_t second_addr_len() const = 0;
-};
-
-// A FDSocketPair is a SocketPair that consists of only a pair of file
-// descriptors.
-class FDSocketPair : public SocketPair {
- public:
- FDSocketPair(int first_fd, int second_fd)
- : first_(first_fd), second_(second_fd) {}
- FDSocketPair(std::unique_ptr<FileDescriptor> first_fd,
- std::unique_ptr<FileDescriptor> second_fd)
- : first_(first_fd->release()), second_(second_fd->release()) {}
-
- int first_fd() const override { return first_.get(); }
- int second_fd() const override { return second_.get(); }
- int release_first_fd() override { return first_.release(); }
- int release_second_fd() override { return second_.release(); }
- const struct sockaddr* first_addr() const override { return nullptr; }
- const struct sockaddr* second_addr() const override { return nullptr; }
- size_t first_addr_size() const override { return 0; }
- size_t second_addr_size() const override { return 0; }
- size_t first_addr_len() const override { return 0; }
- size_t second_addr_len() const override { return 0; }
-
- private:
- FileDescriptor first_;
- FileDescriptor second_;
-};
-
-// CalculateUnixSockAddrLen calculates the length returned by recvfrom(2) and
-// recvmsg(2) for Unix sockets.
-size_t CalculateUnixSockAddrLen(const char* sun_path);
-
-// A AddrFDSocketPair is a SocketPair that consists of a pair of file
-// descriptors in addition to a pair of socket addresses.
-class AddrFDSocketPair : public SocketPair {
- public:
- AddrFDSocketPair(int first_fd, int second_fd,
- const struct sockaddr_un& first_address,
- const struct sockaddr_un& second_address)
- : first_(first_fd),
- second_(second_fd),
- first_addr_(to_storage(first_address)),
- second_addr_(to_storage(second_address)),
- first_len_(CalculateUnixSockAddrLen(first_address.sun_path)),
- second_len_(CalculateUnixSockAddrLen(second_address.sun_path)),
- first_size_(sizeof(first_address)),
- second_size_(sizeof(second_address)) {}
-
- AddrFDSocketPair(int first_fd, int second_fd,
- const struct sockaddr_in& first_address,
- const struct sockaddr_in& second_address)
- : first_(first_fd),
- second_(second_fd),
- first_addr_(to_storage(first_address)),
- second_addr_(to_storage(second_address)),
- first_len_(sizeof(first_address)),
- second_len_(sizeof(second_address)),
- first_size_(sizeof(first_address)),
- second_size_(sizeof(second_address)) {}
-
- AddrFDSocketPair(int first_fd, int second_fd,
- const struct sockaddr_in6& first_address,
- const struct sockaddr_in6& second_address)
- : first_(first_fd),
- second_(second_fd),
- first_addr_(to_storage(first_address)),
- second_addr_(to_storage(second_address)),
- first_len_(sizeof(first_address)),
- second_len_(sizeof(second_address)),
- first_size_(sizeof(first_address)),
- second_size_(sizeof(second_address)) {}
-
- int first_fd() const override { return first_.get(); }
- int second_fd() const override { return second_.get(); }
- int release_first_fd() override { return first_.release(); }
- int release_second_fd() override { return second_.release(); }
- const struct sockaddr* first_addr() const override {
- return reinterpret_cast<const struct sockaddr*>(&first_addr_);
- }
- const struct sockaddr* second_addr() const override {
- return reinterpret_cast<const struct sockaddr*>(&second_addr_);
- }
- size_t first_addr_size() const override { return first_size_; }
- size_t second_addr_size() const override { return second_size_; }
- size_t first_addr_len() const override { return first_len_; }
- size_t second_addr_len() const override { return second_len_; }
-
- private:
- // to_storage coverts a sockaddr_* to a sockaddr_storage.
- static struct sockaddr_storage to_storage(const sockaddr_un& addr);
- static struct sockaddr_storage to_storage(const sockaddr_in& addr);
- static struct sockaddr_storage to_storage(const sockaddr_in6& addr);
-
- FileDescriptor first_;
- FileDescriptor second_;
- const struct sockaddr_storage first_addr_;
- const struct sockaddr_storage second_addr_;
- const size_t first_len_;
- const size_t second_len_;
- const size_t first_size_;
- const size_t second_size_;
-};
-
-// SyscallSocketPairCreator returns a Creator<SocketPair> that obtains file
-// descriptors by invoking the socketpair() syscall.
-Creator<SocketPair> SyscallSocketPairCreator(int domain, int type,
- int protocol);
-
-// SyscallSocketCreator returns a Creator<FileDescriptor> that obtains a file
-// descriptor by invoking the socket() syscall.
-Creator<FileDescriptor> SyscallSocketCreator(int domain, int type,
- int protocol);
-
-// FilesystemBidirectionalBindSocketPairCreator returns a Creator<SocketPair>
-// that obtains file descriptors by invoking the bind() and connect() syscalls
-// on filesystem paths. Only works for DGRAM sockets.
-Creator<SocketPair> FilesystemBidirectionalBindSocketPairCreator(int domain,
- int type,
- int protocol);
-
-// AbstractBidirectionalBindSocketPairCreator returns a Creator<SocketPair> that
-// obtains file descriptors by invoking the bind() and connect() syscalls on
-// abstract namespace paths. Only works for DGRAM sockets.
-Creator<SocketPair> AbstractBidirectionalBindSocketPairCreator(int domain,
- int type,
- int protocol);
-
-// SocketpairGoferSocketPairCreator returns a Creator<SocketPair> that
-// obtains file descriptors by connect() syscalls on two sockets with socketpair
-// gofer paths.
-Creator<SocketPair> SocketpairGoferSocketPairCreator(int domain, int type,
- int protocol);
-
-// SocketpairGoferFileSocketPairCreator returns a Creator<SocketPair> that
-// obtains file descriptors by open() syscalls on socketpair gofer paths.
-Creator<SocketPair> SocketpairGoferFileSocketPairCreator(int flags);
-
-// FilesystemAcceptBindSocketPairCreator returns a Creator<SocketPair> that
-// obtains file descriptors by invoking the accept() and bind() syscalls on
-// a filesystem path. Only works for STREAM and SEQPACKET sockets.
-Creator<SocketPair> FilesystemAcceptBindSocketPairCreator(int domain, int type,
- int protocol);
-
-// AbstractAcceptBindSocketPairCreator returns a Creator<SocketPair> that
-// obtains file descriptors by invoking the accept() and bind() syscalls on a
-// abstract namespace path. Only works for STREAM and SEQPACKET sockets.
-Creator<SocketPair> AbstractAcceptBindSocketPairCreator(int domain, int type,
- int protocol);
-
-// FilesystemUnboundSocketPairCreator returns a Creator<SocketPair> that obtains
-// file descriptors by invoking the socket() syscall and generates a filesystem
-// path for binding.
-Creator<SocketPair> FilesystemUnboundSocketPairCreator(int domain, int type,
- int protocol);
-
-// AbstractUnboundSocketPairCreator returns a Creator<SocketPair> that obtains
-// file descriptors by invoking the socket() syscall and generates an abstract
-// path for binding.
-Creator<SocketPair> AbstractUnboundSocketPairCreator(int domain, int type,
- int protocol);
-
-// TCPAcceptBindSocketPairCreator returns a Creator<SocketPair> that obtains
-// file descriptors by invoking the accept() and bind() syscalls on TCP sockets.
-Creator<SocketPair> TCPAcceptBindSocketPairCreator(int domain, int type,
- int protocol,
- bool dual_stack);
-
-// TCPAcceptBindPersistentListenerSocketPairCreator is like
-// TCPAcceptBindSocketPairCreator, except it uses the same listening socket to
-// create all SocketPairs.
-Creator<SocketPair> TCPAcceptBindPersistentListenerSocketPairCreator(
- int domain, int type, int protocol, bool dual_stack);
-
-// UDPBidirectionalBindSocketPairCreator returns a Creator<SocketPair> that
-// obtains file descriptors by invoking the bind() and connect() syscalls on UDP
-// sockets.
-Creator<SocketPair> UDPBidirectionalBindSocketPairCreator(int domain, int type,
- int protocol,
- bool dual_stack);
-
-// UDPUnboundSocketPairCreator returns a Creator<SocketPair> that obtains file
-// descriptors by creating UDP sockets.
-Creator<SocketPair> UDPUnboundSocketPairCreator(int domain, int type,
- int protocol, bool dual_stack);
-
-// UnboundSocketCreator returns a Creator<FileDescriptor> that obtains a file
-// descriptor by creating a socket.
-Creator<FileDescriptor> UnboundSocketCreator(int domain, int type,
- int protocol);
-
-// A SocketPairKind couples a human-readable description of a socket pair with
-// a function that creates such a socket pair.
-struct SocketPairKind {
- std::string description;
- int domain;
- int type;
- int protocol;
- Creator<SocketPair> creator;
-
- // Create creates a socket pair of this kind.
- PosixErrorOr<std::unique_ptr<SocketPair>> Create() const { return creator(); }
-};
-
-// A SocketKind couples a human-readable description of a socket with
-// a function that creates such a socket.
-struct SocketKind {
- std::string description;
- int domain;
- int type;
- int protocol;
- Creator<FileDescriptor> creator;
-
- // Create creates a socket pair of this kind.
- PosixErrorOr<std::unique_ptr<FileDescriptor>> Create() const {
- return creator();
- }
-};
-
-// A ReversedSocketPair wraps another SocketPair but flips the first and second
-// file descriptors. ReversedSocketPair is used to test socket pairs that
-// should be symmetric.
-class ReversedSocketPair : public SocketPair {
- public:
- explicit ReversedSocketPair(std::unique_ptr<SocketPair> base)
- : base_(std::move(base)) {}
-
- int first_fd() const override { return base_->second_fd(); }
- int second_fd() const override { return base_->first_fd(); }
- int release_first_fd() override { return base_->release_second_fd(); }
- int release_second_fd() override { return base_->release_first_fd(); }
- const struct sockaddr* first_addr() const override {
- return base_->second_addr();
- }
- const struct sockaddr* second_addr() const override {
- return base_->first_addr();
- }
- size_t first_addr_size() const override { return base_->second_addr_size(); }
- size_t second_addr_size() const override { return base_->first_addr_size(); }
- size_t first_addr_len() const override { return base_->second_addr_len(); }
- size_t second_addr_len() const override { return base_->first_addr_len(); }
-
- private:
- std::unique_ptr<SocketPair> base_;
-};
-
-// Reversed returns a SocketPairKind that represents SocketPairs created by
-// flipping the file descriptors provided by another SocketPair.
-SocketPairKind Reversed(SocketPairKind const& base);
-
-// IncludeReversals returns a vector<SocketPairKind> that returns all
-// SocketPairKinds in `vec` as well as all SocketPairKinds obtained by flipping
-// the file descriptors provided by the kinds in `vec`.
-std::vector<SocketPairKind> IncludeReversals(std::vector<SocketPairKind> vec);
-
-// A Middleware is a function wraps a SocketPairKind.
-using Middleware = std::function<SocketPairKind(SocketPairKind)>;
-
-// Reversed returns a SocketPairKind that represents SocketPairs created by
-// flipping the file descriptors provided by another SocketPair.
-template <typename T>
-Middleware SetSockOpt(int level, int optname, T* value) {
- return [=](SocketPairKind const& base) {
- auto const& creator = base.creator;
- return SocketPairKind{
- absl::StrCat("setsockopt(", level, ", ", optname, ", ", *value, ") ",
- base.description),
- base.domain, base.type, base.protocol,
- [creator, level, optname,
- value]() -> PosixErrorOr<std::unique_ptr<SocketPair>> {
- ASSIGN_OR_RETURN_ERRNO(auto creator_value, creator());
- if (creator_value->first_fd() >= 0) {
- RETURN_ERROR_IF_SYSCALL_FAIL(setsockopt(
- creator_value->first_fd(), level, optname, value, sizeof(T)));
- }
- if (creator_value->second_fd() >= 0) {
- RETURN_ERROR_IF_SYSCALL_FAIL(setsockopt(
- creator_value->second_fd(), level, optname, value, sizeof(T)));
- }
- return creator_value;
- }};
- };
-}
-
-constexpr int kSockOptOn = 1;
-constexpr int kSockOptOff = 0;
-
-// NoOp returns the same SocketPairKind that it is passed.
-SocketPairKind NoOp(SocketPairKind const& base);
-
-// TransferTest tests that data can be send back and fourth between two
-// specified FDs. Note that calls to this function should be wrapped in
-// ASSERT_NO_FATAL_FAILURE().
-void TransferTest(int fd1, int fd2);
-
-// Fills [buf, buf+len) with random bytes.
-void RandomizeBuffer(char* buf, size_t len);
-
-// Base test fixture for tests that operate on pairs of connected sockets.
-class SocketPairTest : public ::testing::TestWithParam<SocketPairKind> {
- protected:
- SocketPairTest() {
- // gUnit uses printf, so so will we.
- printf("Testing with %s\n", GetParam().description.c_str());
- fflush(stdout);
- }
-
- PosixErrorOr<std::unique_ptr<SocketPair>> NewSocketPair() const {
- return GetParam().Create();
- }
-};
-
-// Base test fixture for tests that operate on simple Sockets.
-class SimpleSocketTest : public ::testing::TestWithParam<SocketKind> {
- protected:
- SimpleSocketTest() {
- // gUnit uses printf, so so will we.
- printf("Testing with %s\n", GetParam().description.c_str());
- }
-
- PosixErrorOr<std::unique_ptr<FileDescriptor>> NewSocket() const {
- return GetParam().Create();
- }
-};
-
-SocketKind SimpleSocket(int fam, int type, int proto);
-
-// Send a buffer of size 'size' to sockets->first_fd(), returning the result of
-// sendmsg.
-//
-// If reader, read from second_fd() until size bytes have been read.
-ssize_t SendLargeSendMsg(const std::unique_ptr<SocketPair>& sockets,
- size_t size, bool reader);
-
-// Initializes the given buffer with random data.
-void RandomizeBuffer(char* ptr, size_t len);
-
-enum class AddressFamily { kIpv4 = 1, kIpv6 = 2, kDualStack = 3 };
-enum class SocketType { kUdp = 1, kTcp = 2 };
-
-// Returns a PosixError or a port that is available. If 0 is specified as the
-// port it will bind port 0 (and allow the kernel to select any free port).
-// Otherwise, it will try to bind the specified port and validate that it can be
-// used for the requested family and socket type. The final option is
-// reuse_addr. This specifies whether SO_REUSEADDR should be applied before a
-// bind(2) attempt. SO_REUSEADDR means that sockets in TIME_WAIT states or other
-// bound UDP sockets would not cause an error on bind(2). This option should be
-// set if subsequent calls to bind on the returned port will also use
-// SO_REUSEADDR.
-//
-// Note: That this test will attempt to bind the ANY address for the respective
-// protocol.
-PosixErrorOr<int> PortAvailable(int port, AddressFamily family, SocketType type,
- bool reuse_addr);
-
-// FreeAvailablePort is used to return a port that was obtained by using
-// the PortAvailable helper with port 0.
-PosixError FreeAvailablePort(int port);
-
-// SendMsg converts a buffer to an iovec and adds it to msg before sending it.
-PosixErrorOr<int> SendMsg(int sock, msghdr* msg, char buf[], int buf_size);
-
-// RecvTimeout calls select on sock with timeout and then calls recv on sock.
-PosixErrorOr<int> RecvTimeout(int sock, char buf[], int buf_size, int timeout);
-
-// RecvMsgTimeout calls select on sock with timeout and then calls recvmsg on
-// sock.
-PosixErrorOr<int> RecvMsgTimeout(int sock, msghdr* msg, int timeout);
-
-// RecvNoData checks that no data is receivable on sock.
-void RecvNoData(int sock);
-
-// Base test fixture for tests that apply to all kinds of pairs of connected
-// sockets.
-using AllSocketPairTest = SocketPairTest;
-
-struct TestAddress {
- std::string description;
- sockaddr_storage addr;
- socklen_t addr_len;
-
- explicit TestAddress(std::string description = "")
- : description(std::move(description)), addr(), addr_len() {}
-
- int family() const { return addr.ss_family; }
-
- // Returns a new TestAddress with specified port. If port is not supported,
- // the same TestAddress is returned.
- TestAddress WithPort(uint16_t port) const;
-};
-
-constexpr char kMulticastAddress[] = "224.0.2.1";
-constexpr char kBroadcastAddress[] = "255.255.255.255";
-
-// Returns a TestAddress with `addr` parsed as an IPv4 address described by
-// `description`.
-TestAddress V4AddrStr(std::string description, const char* addr);
-// Returns a TestAddress with `addr` parsed as an IPv6 address described by
-// `description`.
-TestAddress V6AddrStr(std::string description, const char* addr);
-
-// Returns a TestAddress for the IPv4 any address.
-TestAddress V4Any();
-// Returns a TestAddress for the IPv4 limited broadcast address.
-TestAddress V4Broadcast();
-// Returns a TestAddress for the IPv4 loopback address.
-TestAddress V4Loopback();
-// Returns a TestAddress for the subnet broadcast of the IPv4 loopback address.
-TestAddress V4LoopbackSubnetBroadcast();
-// Returns a TestAddress for the IPv4-mapped IPv6 any address.
-TestAddress V4MappedAny();
-// Returns a TestAddress for the IPv4-mapped IPv6 loopback address.
-TestAddress V4MappedLoopback();
-// Returns a TestAddress for a IPv4 multicast address.
-TestAddress V4Multicast();
-// Returns a TestAddress for the IPv4 all-hosts multicast group address.
-TestAddress V4MulticastAllHosts();
-
-// Returns a TestAddress for the IPv6 any address.
-TestAddress V6Any();
-// Returns a TestAddress for the IPv6 loopback address.
-TestAddress V6Loopback();
-// Returns a TestAddress for a IPv6 multicast address.
-TestAddress V6Multicast();
-// Returns a TestAddress for the IPv6 interface-local all-nodes multicast group
-// address.
-TestAddress V6MulticastInterfaceLocalAllNodes();
-// Returns a TestAddress for the IPv6 link-local all-nodes multicast group
-// address.
-TestAddress V6MulticastLinkLocalAllNodes();
-// Returns a TestAddress for the IPv6 link-local all-routers multicast group
-// address.
-TestAddress V6MulticastLinkLocalAllRouters();
-
-// Compute the internet checksum of an IP header.
-uint16_t IPChecksum(struct iphdr ip);
-
-// Compute the internet checksum of a UDP header.
-uint16_t UDPChecksum(struct iphdr iphdr, struct udphdr udphdr,
- const char* payload, ssize_t payload_len);
-
-// Compute the internet checksum of an ICMP header.
-uint16_t ICMPChecksum(struct icmphdr icmphdr, const char* payload,
- ssize_t payload_len);
-
-// Convenient functions for reinterpreting common types to sockaddr pointer.
-inline sockaddr* AsSockAddr(sockaddr_storage* s) {
- return reinterpret_cast<sockaddr*>(s);
-}
-inline sockaddr* AsSockAddr(sockaddr_in* s) {
- return reinterpret_cast<sockaddr*>(s);
-}
-inline sockaddr* AsSockAddr(sockaddr_in6* s) {
- return reinterpret_cast<sockaddr*>(s);
-}
-inline sockaddr* AsSockAddr(sockaddr_un* s) {
- return reinterpret_cast<sockaddr*>(s);
-}
-
-PosixErrorOr<uint16_t> AddrPort(int family, sockaddr_storage const& addr);
-
-PosixError SetAddrPort(int family, sockaddr_storage* addr, uint16_t port);
-
-// setupTimeWaitClose sets up a socket endpoint in TIME_WAIT state.
-// Callers can choose to perform active close on either ends of the connection
-// and also specify if they want to enabled SO_REUSEADDR.
-void SetupTimeWaitClose(const TestAddress* listener,
- const TestAddress* connector, bool reuse,
- bool accept_close, sockaddr_storage* listen_addr,
- sockaddr_storage* conn_bound_addr);
-
-// MaybeLimitEphemeralPorts attempts to reduce the number of ephemeral ports and
-// returns the number of ephemeral ports.
-PosixErrorOr<int> MaybeLimitEphemeralPorts();
-
-namespace internal {
-PosixErrorOr<int> TryPortAvailable(int port, AddressFamily family,
- SocketType type, bool reuse_addr);
-} // namespace internal
-
-} // namespace testing
-} // namespace gvisor
-
-#endif // GVISOR_TEST_SYSCALLS_SOCKET_TEST_UTIL_H_
diff --git a/test/syscalls/linux/socket_test_util_impl.cc b/test/syscalls/linux/socket_test_util_impl.cc
deleted file mode 100644
index ef661a0e3..000000000
--- a/test/syscalls/linux/socket_test_util_impl.cc
+++ /dev/null
@@ -1,28 +0,0 @@
-// Copyright 2019 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_test_util.h"
-
-namespace gvisor {
-namespace testing {
-
-PosixErrorOr<int> PortAvailable(int port, AddressFamily family, SocketType type,
- bool reuse_addr) {
- return internal::TryPortAvailable(port, family, type, reuse_addr);
-}
-
-PosixError FreeAvailablePort(int port) { return NoError(); }
-
-} // namespace testing
-} // namespace gvisor
diff --git a/test/syscalls/linux/socket_unix.cc b/test/syscalls/linux/socket_unix.cc
index 591cab3fd..cf96b2075 100644
--- a/test/syscalls/linux/socket_unix.cc
+++ b/test/syscalls/linux/socket_unix.cc
@@ -26,8 +26,8 @@
#include "gtest/gtest.h"
#include "absl/strings/string_view.h"
-#include "test/syscalls/linux/socket_test_util.h"
#include "test/syscalls/linux/unix_domain_socket_test_util.h"
+#include "test/util/socket_util.h"
#include "test/util/test_util.h"
#include "test/util/thread_util.h"
diff --git a/test/syscalls/linux/socket_unix.h b/test/syscalls/linux/socket_unix.h
index 3625cc404..f6405f399 100644
--- a/test/syscalls/linux/socket_unix.h
+++ b/test/syscalls/linux/socket_unix.h
@@ -15,7 +15,7 @@
#ifndef GVISOR_TEST_SYSCALLS_LINUX_SOCKET_UNIX_H_
#define GVISOR_TEST_SYSCALLS_LINUX_SOCKET_UNIX_H_
-#include "test/syscalls/linux/socket_test_util.h"
+#include "test/util/socket_util.h"
namespace gvisor {
namespace testing {
diff --git a/test/syscalls/linux/socket_unix_abstract_nonblock.cc b/test/syscalls/linux/socket_unix_abstract_nonblock.cc
index 8bef76b67..617c5bfe5 100644
--- a/test/syscalls/linux/socket_unix_abstract_nonblock.cc
+++ b/test/syscalls/linux/socket_unix_abstract_nonblock.cc
@@ -15,8 +15,8 @@
#include <vector>
#include "test/syscalls/linux/socket_non_blocking.h"
-#include "test/syscalls/linux/socket_test_util.h"
#include "test/syscalls/linux/unix_domain_socket_test_util.h"
+#include "test/util/socket_util.h"
#include "test/util/test_util.h"
namespace gvisor {
diff --git a/test/syscalls/linux/socket_unix_blocking_local.cc b/test/syscalls/linux/socket_unix_blocking_local.cc
index 77cb8c6d6..ba34320bc 100644
--- a/test/syscalls/linux/socket_unix_blocking_local.cc
+++ b/test/syscalls/linux/socket_unix_blocking_local.cc
@@ -15,8 +15,8 @@
#include <vector>
#include "test/syscalls/linux/socket_blocking.h"
-#include "test/syscalls/linux/socket_test_util.h"
#include "test/syscalls/linux/unix_domain_socket_test_util.h"
+#include "test/util/socket_util.h"
#include "test/util/test_util.h"
namespace gvisor {
diff --git a/test/syscalls/linux/socket_unix_cmsg.cc b/test/syscalls/linux/socket_unix_cmsg.cc
index 22a4ee0d1..6191b1448 100644
--- a/test/syscalls/linux/socket_unix_cmsg.cc
+++ b/test/syscalls/linux/socket_unix_cmsg.cc
@@ -26,8 +26,8 @@
#include "gtest/gtest.h"
#include "absl/strings/string_view.h"
-#include "test/syscalls/linux/socket_test_util.h"
#include "test/syscalls/linux/unix_domain_socket_test_util.h"
+#include "test/util/socket_util.h"
#include "test/util/test_util.h"
#include "test/util/thread_util.h"
diff --git a/test/syscalls/linux/socket_unix_cmsg.h b/test/syscalls/linux/socket_unix_cmsg.h
index 431606903..f5a276155 100644
--- a/test/syscalls/linux/socket_unix_cmsg.h
+++ b/test/syscalls/linux/socket_unix_cmsg.h
@@ -15,7 +15,7 @@
#ifndef GVISOR_TEST_SYSCALLS_LINUX_SOCKET_UNIX_CMSG_H_
#define GVISOR_TEST_SYSCALLS_LINUX_SOCKET_UNIX_CMSG_H_
-#include "test/syscalls/linux/socket_test_util.h"
+#include "test/util/socket_util.h"
namespace gvisor {
namespace testing {
diff --git a/test/syscalls/linux/socket_unix_dgram.cc b/test/syscalls/linux/socket_unix_dgram.cc
index 5b0844493..d43c83d71 100644
--- a/test/syscalls/linux/socket_unix_dgram.cc
+++ b/test/syscalls/linux/socket_unix_dgram.cc
@@ -20,8 +20,8 @@
#include "gtest/gtest.h"
#include "absl/time/clock.h"
#include "absl/time/time.h"
-#include "test/syscalls/linux/socket_test_util.h"
#include "test/syscalls/linux/unix_domain_socket_test_util.h"
+#include "test/util/socket_util.h"
#include "test/util/test_util.h"
namespace gvisor {
diff --git a/test/syscalls/linux/socket_unix_dgram.h b/test/syscalls/linux/socket_unix_dgram.h
index 0764ef85b..e9b8373a5 100644
--- a/test/syscalls/linux/socket_unix_dgram.h
+++ b/test/syscalls/linux/socket_unix_dgram.h
@@ -15,7 +15,7 @@
#ifndef GVISOR_TEST_SYSCALLS_LINUX_SOCKET_UNIX_DGRAM_H_
#define GVISOR_TEST_SYSCALLS_LINUX_SOCKET_UNIX_DGRAM_H_
-#include "test/syscalls/linux/socket_test_util.h"
+#include "test/util/socket_util.h"
namespace gvisor {
namespace testing {
diff --git a/test/syscalls/linux/socket_unix_dgram_local.cc b/test/syscalls/linux/socket_unix_dgram_local.cc
index 31d2d5216..4760630b9 100644
--- a/test/syscalls/linux/socket_unix_dgram_local.cc
+++ b/test/syscalls/linux/socket_unix_dgram_local.cc
@@ -15,10 +15,10 @@
#include <vector>
#include "test/syscalls/linux/socket_non_stream.h"
-#include "test/syscalls/linux/socket_test_util.h"
#include "test/syscalls/linux/socket_unix_dgram.h"
#include "test/syscalls/linux/socket_unix_non_stream.h"
#include "test/syscalls/linux/unix_domain_socket_test_util.h"
+#include "test/util/socket_util.h"
#include "test/util/test_util.h"
namespace gvisor {
diff --git a/test/syscalls/linux/socket_unix_dgram_non_blocking.cc b/test/syscalls/linux/socket_unix_dgram_non_blocking.cc
index 2db8b68d3..ca277122e 100644
--- a/test/syscalls/linux/socket_unix_dgram_non_blocking.cc
+++ b/test/syscalls/linux/socket_unix_dgram_non_blocking.cc
@@ -16,8 +16,8 @@
#include <sys/un.h>
#include "gtest/gtest.h"
-#include "test/syscalls/linux/socket_test_util.h"
#include "test/syscalls/linux/unix_domain_socket_test_util.h"
+#include "test/util/socket_util.h"
#include "test/util/test_util.h"
namespace gvisor {
diff --git a/test/syscalls/linux/socket_unix_domain.cc b/test/syscalls/linux/socket_unix_domain.cc
index f7dff8b4d..d8cb5b892 100644
--- a/test/syscalls/linux/socket_unix_domain.cc
+++ b/test/syscalls/linux/socket_unix_domain.cc
@@ -15,8 +15,8 @@
#include <vector>
#include "test/syscalls/linux/socket_generic.h"
-#include "test/syscalls/linux/socket_test_util.h"
#include "test/syscalls/linux/unix_domain_socket_test_util.h"
+#include "test/util/socket_util.h"
#include "test/util/test_util.h"
namespace gvisor {
diff --git a/test/syscalls/linux/socket_unix_filesystem_nonblock.cc b/test/syscalls/linux/socket_unix_filesystem_nonblock.cc
index 6700b4d90..cdd38f681 100644
--- a/test/syscalls/linux/socket_unix_filesystem_nonblock.cc
+++ b/test/syscalls/linux/socket_unix_filesystem_nonblock.cc
@@ -15,8 +15,8 @@
#include <vector>
#include "test/syscalls/linux/socket_non_blocking.h"
-#include "test/syscalls/linux/socket_test_util.h"
#include "test/syscalls/linux/unix_domain_socket_test_util.h"
+#include "test/util/socket_util.h"
#include "test/util/test_util.h"
namespace gvisor {
diff --git a/test/syscalls/linux/socket_unix_non_stream.cc b/test/syscalls/linux/socket_unix_non_stream.cc
index 9425e87a6..d18f9e7b0 100644
--- a/test/syscalls/linux/socket_unix_non_stream.cc
+++ b/test/syscalls/linux/socket_unix_non_stream.cc
@@ -19,9 +19,9 @@
#include <sys/un.h>
#include "gtest/gtest.h"
-#include "test/syscalls/linux/socket_test_util.h"
#include "test/syscalls/linux/unix_domain_socket_test_util.h"
#include "test/util/memory_util.h"
+#include "test/util/socket_util.h"
#include "test/util/test_util.h"
namespace gvisor {
diff --git a/test/syscalls/linux/socket_unix_non_stream.h b/test/syscalls/linux/socket_unix_non_stream.h
index 7478ab172..44d1c0033 100644
--- a/test/syscalls/linux/socket_unix_non_stream.h
+++ b/test/syscalls/linux/socket_unix_non_stream.h
@@ -15,7 +15,7 @@
#ifndef GVISOR_TEST_SYSCALLS_LINUX_SOCKET_UNIX_NON_STREAM_H_
#define GVISOR_TEST_SYSCALLS_LINUX_SOCKET_UNIX_NON_STREAM_H_
-#include "test/syscalls/linux/socket_test_util.h"
+#include "test/util/socket_util.h"
namespace gvisor {
namespace testing {
diff --git a/test/syscalls/linux/socket_unix_non_stream_blocking_local.cc b/test/syscalls/linux/socket_unix_non_stream_blocking_local.cc
index fddcdf1c5..92f40f5e5 100644
--- a/test/syscalls/linux/socket_unix_non_stream_blocking_local.cc
+++ b/test/syscalls/linux/socket_unix_non_stream_blocking_local.cc
@@ -15,8 +15,8 @@
#include <vector>
#include "test/syscalls/linux/socket_non_stream_blocking.h"
-#include "test/syscalls/linux/socket_test_util.h"
#include "test/syscalls/linux/unix_domain_socket_test_util.h"
+#include "test/util/socket_util.h"
#include "test/util/test_util.h"
namespace gvisor {
diff --git a/test/syscalls/linux/socket_unix_pair.cc b/test/syscalls/linux/socket_unix_pair.cc
index 85999db04..28a437339 100644
--- a/test/syscalls/linux/socket_unix_pair.cc
+++ b/test/syscalls/linux/socket_unix_pair.cc
@@ -14,10 +14,10 @@
#include <vector>
-#include "test/syscalls/linux/socket_test_util.h"
#include "test/syscalls/linux/socket_unix.h"
#include "test/syscalls/linux/socket_unix_cmsg.h"
#include "test/syscalls/linux/unix_domain_socket_test_util.h"
+#include "test/util/socket_util.h"
#include "test/util/test_util.h"
namespace gvisor {
diff --git a/test/syscalls/linux/socket_unix_pair_nonblock.cc b/test/syscalls/linux/socket_unix_pair_nonblock.cc
index 281410a9a..39360896b 100644
--- a/test/syscalls/linux/socket_unix_pair_nonblock.cc
+++ b/test/syscalls/linux/socket_unix_pair_nonblock.cc
@@ -15,8 +15,8 @@
#include <vector>
#include "test/syscalls/linux/socket_non_blocking.h"
-#include "test/syscalls/linux/socket_test_util.h"
#include "test/syscalls/linux/unix_domain_socket_test_util.h"
+#include "test/util/socket_util.h"
#include "test/util/test_util.h"
namespace gvisor {
diff --git a/test/syscalls/linux/socket_unix_seqpacket.cc b/test/syscalls/linux/socket_unix_seqpacket.cc
index d6e7031c0..2a2741eb9 100644
--- a/test/syscalls/linux/socket_unix_seqpacket.cc
+++ b/test/syscalls/linux/socket_unix_seqpacket.cc
@@ -20,8 +20,8 @@
#include "gtest/gtest.h"
#include "absl/time/clock.h"
#include "absl/time/time.h"
-#include "test/syscalls/linux/socket_test_util.h"
#include "test/syscalls/linux/unix_domain_socket_test_util.h"
+#include "test/util/socket_util.h"
#include "test/util/test_util.h"
namespace gvisor {
diff --git a/test/syscalls/linux/socket_unix_seqpacket.h b/test/syscalls/linux/socket_unix_seqpacket.h
index 30d9b9edf..5bb36af92 100644
--- a/test/syscalls/linux/socket_unix_seqpacket.h
+++ b/test/syscalls/linux/socket_unix_seqpacket.h
@@ -15,7 +15,7 @@
#ifndef GVISOR_TEST_SYSCALLS_LINUX_SOCKET_UNIX_SEQPACKET_H_
#define GVISOR_TEST_SYSCALLS_LINUX_SOCKET_UNIX_SEQPACKET_H_
-#include "test/syscalls/linux/socket_test_util.h"
+#include "test/util/socket_util.h"
namespace gvisor {
namespace testing {
diff --git a/test/syscalls/linux/socket_unix_seqpacket_local.cc b/test/syscalls/linux/socket_unix_seqpacket_local.cc
index 69a5f150d..492416a77 100644
--- a/test/syscalls/linux/socket_unix_seqpacket_local.cc
+++ b/test/syscalls/linux/socket_unix_seqpacket_local.cc
@@ -15,10 +15,10 @@
#include <vector>
#include "test/syscalls/linux/socket_non_stream.h"
-#include "test/syscalls/linux/socket_test_util.h"
#include "test/syscalls/linux/socket_unix_non_stream.h"
#include "test/syscalls/linux/socket_unix_seqpacket.h"
#include "test/syscalls/linux/unix_domain_socket_test_util.h"
+#include "test/util/socket_util.h"
#include "test/util/test_util.h"
namespace gvisor {
diff --git a/test/syscalls/linux/socket_unix_stream.cc b/test/syscalls/linux/socket_unix_stream.cc
index 3ff810914..6e9f70f8c 100644
--- a/test/syscalls/linux/socket_unix_stream.cc
+++ b/test/syscalls/linux/socket_unix_stream.cc
@@ -19,8 +19,8 @@
#include "gtest/gtest.h"
#include "absl/time/clock.h"
#include "absl/time/time.h"
-#include "test/syscalls/linux/socket_test_util.h"
#include "test/syscalls/linux/unix_domain_socket_test_util.h"
+#include "test/util/socket_util.h"
#include "test/util/test_util.h"
namespace gvisor {
diff --git a/test/syscalls/linux/socket_unix_stream_blocking_local.cc b/test/syscalls/linux/socket_unix_stream_blocking_local.cc
index 8429bd429..97a6bb327 100644
--- a/test/syscalls/linux/socket_unix_stream_blocking_local.cc
+++ b/test/syscalls/linux/socket_unix_stream_blocking_local.cc
@@ -15,8 +15,8 @@
#include <vector>
#include "test/syscalls/linux/socket_stream_blocking.h"
-#include "test/syscalls/linux/socket_test_util.h"
#include "test/syscalls/linux/unix_domain_socket_test_util.h"
+#include "test/util/socket_util.h"
#include "test/util/test_util.h"
namespace gvisor {
diff --git a/test/syscalls/linux/socket_unix_stream_local.cc b/test/syscalls/linux/socket_unix_stream_local.cc
index a7e3449a9..4b267ccae 100644
--- a/test/syscalls/linux/socket_unix_stream_local.cc
+++ b/test/syscalls/linux/socket_unix_stream_local.cc
@@ -15,8 +15,8 @@
#include <vector>
#include "test/syscalls/linux/socket_stream.h"
-#include "test/syscalls/linux/socket_test_util.h"
#include "test/syscalls/linux/unix_domain_socket_test_util.h"
+#include "test/util/socket_util.h"
#include "test/util/test_util.h"
namespace gvisor {
diff --git a/test/syscalls/linux/socket_unix_stream_nonblock_local.cc b/test/syscalls/linux/socket_unix_stream_nonblock_local.cc
index 4b763c8e2..d7bf7747b 100644
--- a/test/syscalls/linux/socket_unix_stream_nonblock_local.cc
+++ b/test/syscalls/linux/socket_unix_stream_nonblock_local.cc
@@ -14,8 +14,8 @@
#include <vector>
#include "test/syscalls/linux/socket_stream_nonblock.h"
-#include "test/syscalls/linux/socket_test_util.h"
#include "test/syscalls/linux/unix_domain_socket_test_util.h"
+#include "test/util/socket_util.h"
#include "test/util/test_util.h"
namespace gvisor {
diff --git a/test/syscalls/linux/socket_unix_unbound_abstract.cc b/test/syscalls/linux/socket_unix_unbound_abstract.cc
index dd3d25450..0f6864266 100644
--- a/test/syscalls/linux/socket_unix_unbound_abstract.cc
+++ b/test/syscalls/linux/socket_unix_unbound_abstract.cc
@@ -16,8 +16,8 @@
#include <sys/un.h>
#include "gtest/gtest.h"
-#include "test/syscalls/linux/socket_test_util.h"
#include "test/syscalls/linux/unix_domain_socket_test_util.h"
+#include "test/util/socket_util.h"
#include "test/util/test_util.h"
namespace gvisor {
diff --git a/test/syscalls/linux/socket_unix_unbound_dgram.cc b/test/syscalls/linux/socket_unix_unbound_dgram.cc
index 907dca0f1..ccf2c94a1 100644
--- a/test/syscalls/linux/socket_unix_unbound_dgram.cc
+++ b/test/syscalls/linux/socket_unix_unbound_dgram.cc
@@ -17,8 +17,8 @@
#include <sys/un.h>
#include "gtest/gtest.h"
-#include "test/syscalls/linux/socket_test_util.h"
#include "test/syscalls/linux/unix_domain_socket_test_util.h"
+#include "test/util/socket_util.h"
#include "test/util/test_util.h"
namespace gvisor {
diff --git a/test/syscalls/linux/socket_unix_unbound_filesystem.cc b/test/syscalls/linux/socket_unix_unbound_filesystem.cc
index a035fb095..811fe12a1 100644
--- a/test/syscalls/linux/socket_unix_unbound_filesystem.cc
+++ b/test/syscalls/linux/socket_unix_unbound_filesystem.cc
@@ -17,9 +17,9 @@
#include <sys/un.h>
#include "gtest/gtest.h"
-#include "test/syscalls/linux/socket_test_util.h"
#include "test/syscalls/linux/unix_domain_socket_test_util.h"
#include "test/util/file_descriptor.h"
+#include "test/util/socket_util.h"
#include "test/util/test_util.h"
namespace gvisor {
diff --git a/test/syscalls/linux/socket_unix_unbound_seqpacket.cc b/test/syscalls/linux/socket_unix_unbound_seqpacket.cc
index cb99030f5..e22018890 100644
--- a/test/syscalls/linux/socket_unix_unbound_seqpacket.cc
+++ b/test/syscalls/linux/socket_unix_unbound_seqpacket.cc
@@ -16,8 +16,8 @@
#include <sys/un.h>
#include "gtest/gtest.h"
-#include "test/syscalls/linux/socket_test_util.h"
#include "test/syscalls/linux/unix_domain_socket_test_util.h"
+#include "test/util/socket_util.h"
#include "test/util/test_util.h"
namespace gvisor {
diff --git a/test/syscalls/linux/socket_unix_unbound_stream.cc b/test/syscalls/linux/socket_unix_unbound_stream.cc
index f185dded3..b10062bc2 100644
--- a/test/syscalls/linux/socket_unix_unbound_stream.cc
+++ b/test/syscalls/linux/socket_unix_unbound_stream.cc
@@ -16,8 +16,8 @@
#include <sys/un.h>
#include "gtest/gtest.h"
-#include "test/syscalls/linux/socket_test_util.h"
#include "test/syscalls/linux/unix_domain_socket_test_util.h"
+#include "test/util/socket_util.h"
#include "test/util/test_util.h"
namespace gvisor {
diff --git a/test/syscalls/linux/tcp_socket.cc b/test/syscalls/linux/tcp_socket.cc
index 183819faf..cb77986c2 100644
--- a/test/syscalls/linux/tcp_socket.cc
+++ b/test/syscalls/linux/tcp_socket.cc
@@ -29,9 +29,9 @@
#include "gtest/gtest.h"
#include "absl/time/clock.h"
#include "absl/time/time.h"
-#include "test/syscalls/linux/socket_test_util.h"
#include "test/util/file_descriptor.h"
#include "test/util/posix_error.h"
+#include "test/util/socket_util.h"
#include "test/util/test_util.h"
#include "test/util/thread_util.h"
diff --git a/test/syscalls/linux/tuntap.cc b/test/syscalls/linux/tuntap.cc
index 1c74b9724..7c9c5c870 100644
--- a/test/syscalls/linux/tuntap.cc
+++ b/test/syscalls/linux/tuntap.cc
@@ -31,11 +31,11 @@
#include "absl/strings/ascii.h"
#include "absl/strings/str_split.h"
#include "test/syscalls/linux/socket_netlink_route_util.h"
-#include "test/syscalls/linux/socket_test_util.h"
#include "test/util/capability_util.h"
#include "test/util/file_descriptor.h"
#include "test/util/fs_util.h"
#include "test/util/posix_error.h"
+#include "test/util/socket_util.h"
#include "test/util/test_util.h"
namespace gvisor {
diff --git a/test/syscalls/linux/udp_bind.cc b/test/syscalls/linux/udp_bind.cc
index f68d78aa2..5ed115a14 100644
--- a/test/syscalls/linux/udp_bind.cc
+++ b/test/syscalls/linux/udp_bind.cc
@@ -17,8 +17,8 @@
#include <sys/types.h>
#include "gtest/gtest.h"
-#include "test/syscalls/linux/socket_test_util.h"
#include "test/util/file_descriptor.h"
+#include "test/util/socket_util.h"
#include "test/util/test_util.h"
namespace gvisor {
diff --git a/test/syscalls/linux/udp_socket.cc b/test/syscalls/linux/udp_socket.cc
index b40598767..3353e58cb 100644
--- a/test/syscalls/linux/udp_socket.cc
+++ b/test/syscalls/linux/udp_socket.cc
@@ -39,10 +39,10 @@
#include "absl/time/clock.h"
#include "absl/time/time.h"
#include "test/syscalls/linux/ip_socket_test_util.h"
-#include "test/syscalls/linux/socket_test_util.h"
#include "test/syscalls/linux/unix_domain_socket_test_util.h"
#include "test/util/file_descriptor.h"
#include "test/util/posix_error.h"
+#include "test/util/socket_util.h"
#include "test/util/test_util.h"
#include "test/util/thread_util.h"
diff --git a/test/syscalls/linux/unix_domain_socket_test_util.h b/test/syscalls/linux/unix_domain_socket_test_util.h
index b8073db17..4240bd5f6 100644
--- a/test/syscalls/linux/unix_domain_socket_test_util.h
+++ b/test/syscalls/linux/unix_domain_socket_test_util.h
@@ -17,7 +17,7 @@
#include <string>
-#include "test/syscalls/linux/socket_test_util.h"
+#include "test/util/socket_util.h"
namespace gvisor {
namespace testing {