diff options
Diffstat (limited to 'test')
-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 |