From 7d0227ff16f4397924fb008a7452f6ed3f8205e0 Mon Sep 17 00:00:00 2001 From: Ian Gudger Date: Thu, 21 Mar 2019 18:52:03 -0700 Subject: Add test for short recvmsg iovec length. PiperOrigin-RevId: 239718991 Change-Id: Idc78557a8e9bfdd3cb7d8ec4db708364652640a4 --- test/syscalls/linux/socket_generic.cc | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/test/syscalls/linux/socket_generic.cc b/test/syscalls/linux/socket_generic.cc index c83fb82fe..d04d5abe0 100644 --- a/test/syscalls/linux/socket_generic.cc +++ b/test/syscalls/linux/socket_generic.cc @@ -257,6 +257,32 @@ TEST_P(AllSocketPairTest, RecvmsgPeekMsghdrFlagsCleared) { EXPECT_EQ(msg.msg_flags, 0); } +TEST_P(AllSocketPairTest, RecvmsgIovNotUpdated) { + auto sockets = ASSERT_NO_ERRNO_AND_VALUE(NewSocketPair()); + + char sent_data[10]; + RandomizeBuffer(sent_data, sizeof(sent_data)); + ASSERT_THAT( + RetryEINTR(send)(sockets->first_fd(), sent_data, sizeof(sent_data), 0), + SyscallSucceedsWithValue(sizeof(sent_data))); + + char received_data[sizeof(sent_data) * 2] = {}; + + struct iovec iov; + iov.iov_base = received_data; + iov.iov_len = sizeof(received_data); + struct msghdr msg = {}; + msg.msg_iov = &iov; + msg.msg_iovlen = 1; + + ASSERT_THAT(RetryEINTR(recvmsg)(sockets->second_fd(), &msg, 0), + SyscallSucceedsWithValue(sizeof(sent_data))); + EXPECT_EQ(0, memcmp(received_data, sent_data, sizeof(sent_data))); + + // Check that the iovec length was not updated. + EXPECT_EQ(msg.msg_iov->iov_len, sizeof(received_data)); +} + TEST_P(AllSocketPairTest, RecvmmsgInvalidTimeout) { auto sockets = ASSERT_NO_ERRNO_AND_VALUE(NewSocketPair()); char buf[10]; -- cgit v1.2.3