diff options
author | Ian Gudger <igudger@google.com> | 2018-12-13 13:19:39 -0800 |
---|---|---|
committer | Shentubot <shentubot@google.com> | 2018-12-13 13:20:46 -0800 |
commit | 4659f7ed1a63f031b5450d065684ef6c32d35f01 (patch) | |
tree | cfb15ddd2e80b2a497e3160352155fa6a2060c0f /test/syscalls/linux/socket_generic.cc | |
parent | 6253d32cc932e76608be5c57a4870b3d61464487 (diff) |
Fix WAITALL and RCVTIMEO interaction
PiperOrigin-RevId: 225424296
Change-Id: I60fcc2b859339dca9963cb32227a287e719ab765
Diffstat (limited to 'test/syscalls/linux/socket_generic.cc')
-rw-r--r-- | test/syscalls/linux/socket_generic.cc | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/test/syscalls/linux/socket_generic.cc b/test/syscalls/linux/socket_generic.cc index fdc346d4d..a9edbb950 100644 --- a/test/syscalls/linux/socket_generic.cc +++ b/test/syscalls/linux/socket_generic.cc @@ -395,6 +395,8 @@ TEST_P(AllSocketPairTest, RecvWaitAll) { ASSERT_THAT(RetryEINTR(recv)(sockets->second_fd(), received_data, sizeof(received_data), MSG_WAITALL), SyscallSucceedsWithValue(sizeof(sent_data))); + + EXPECT_EQ(0, memcmp(sent_data, received_data, sizeof(sent_data))); } TEST_P(AllSocketPairTest, RecvWaitAllDontWait) { @@ -406,5 +408,29 @@ TEST_P(AllSocketPairTest, RecvWaitAllDontWait) { SyscallFailsWithErrno(EAGAIN)); } +TEST_P(AllSocketPairTest, RecvTimeoutWaitAll) { + auto sockets = ASSERT_NO_ERRNO_AND_VALUE(NewSocketPair()); + + struct timeval tv { + .tv_sec = 0, .tv_usec = 200000 // 200ms + }; + EXPECT_THAT(setsockopt(sockets->second_fd(), SOL_SOCKET, SO_RCVTIMEO, &tv, + sizeof(tv)), + SyscallSucceeds()); + + char sent_data[100]; + RandomizeBuffer(sent_data, sizeof(sent_data)); + + ASSERT_THAT(write(sockets->first_fd(), sent_data, sizeof(sent_data)), + SyscallSucceedsWithValue(sizeof(sent_data))); + + char received_data[sizeof(sent_data) * 2] = {}; + ASSERT_THAT(RetryEINTR(recv)(sockets->second_fd(), received_data, + sizeof(received_data), MSG_WAITALL), + SyscallSucceedsWithValue(sizeof(sent_data))); + + EXPECT_EQ(0, memcmp(sent_data, received_data, sizeof(sent_data))); +} + } // namespace testing } // namespace gvisor |