diff options
author | Kevin Krakauer <krakauer@google.com> | 2021-04-30 17:55:54 -0700 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2021-04-30 17:58:13 -0700 |
commit | 6fb8c01bb488e22c741a307e030b61c512dcd34f (patch) | |
tree | 08b422694a6c1db3497aa11e580fc32c3eff4fbc /test | |
parent | eb2b39f70287b2ee54127699fa34a06484aaed8b (diff) |
Fix //test/syscalls:tcp_socket_test_native
The data written was larger than the write buffer, and nobody was reading the
other end.
PiperOrigin-RevId: 371436084
Diffstat (limited to 'test')
-rw-r--r-- | test/syscalls/linux/BUILD | 1 | ||||
-rw-r--r-- | test/syscalls/linux/tcp_socket.cc | 14 |
2 files changed, 14 insertions, 1 deletions
diff --git a/test/syscalls/linux/BUILD b/test/syscalls/linux/BUILD index 94a582256..b07f556de 100644 --- a/test/syscalls/linux/BUILD +++ b/test/syscalls/linux/BUILD @@ -3710,6 +3710,7 @@ cc_binary( deps = [ ":socket_test_util", "//test/util:file_descriptor", + "@com_google_absl//absl/strings", "@com_google_absl//absl/time", gtest, "//test/util:posix_error", diff --git a/test/syscalls/linux/tcp_socket.cc b/test/syscalls/linux/tcp_socket.cc index 011b60f0e..ef3452306 100644 --- a/test/syscalls/linux/tcp_socket.cc +++ b/test/syscalls/linux/tcp_socket.cc @@ -27,6 +27,7 @@ #include <vector> #include "gtest/gtest.h" +#include "absl/strings/str_split.h" #include "absl/time/clock.h" #include "absl/time/time.h" #include "test/syscalls/linux/socket_test_util.h" @@ -1144,6 +1145,17 @@ TEST_P(SimpleTcpSocketTest, SelfConnectSendRecv) { } TEST_P(SimpleTcpSocketTest, SelfConnectSend) { + // Ensure the write size is not larger than the write buffer. + size_t write_size = 512 << 10; // 512 KiB. + constexpr char kWMem[] = "/proc/sys/net/ipv4/tcp_wmem"; + std::string wmem = ASSERT_NO_ERRNO_AND_VALUE(GetContents(kWMem)); + std::vector<std::string> vals = absl::StrSplit(wmem, absl::ByAnyChar("\t ")); + size_t max_wmem; + ASSERT_TRUE(absl::SimpleAtoi(vals.back(), &max_wmem)); + if (write_size > max_wmem) { + write_size = max_wmem; + } + // Initialize address to the loopback one. sockaddr_storage addr = ASSERT_NO_ERRNO_AND_VALUE(InetLoopbackAddr(GetParam())); @@ -1164,7 +1176,7 @@ TEST_P(SimpleTcpSocketTest, SelfConnectSend) { ASSERT_THAT(RetryEINTR(connect)(s.get(), AsSockAddr(&addr), addrlen), SyscallSucceeds()); - std::vector<char> writebuf(512 << 10); // 512 KiB. + std::vector<char> writebuf(write_size); // Try to send the whole thing. int n; |