diff options
author | Ian Gudger <igudger@google.com> | 2019-03-21 18:10:13 -0700 |
---|---|---|
committer | Shentubot <shentubot@google.com> | 2019-03-21 18:11:22 -0700 |
commit | 125d3a19e3a0e8d5549dca061f3dec9e0f5aa9d4 (patch) | |
tree | 73b0e43720d6152a81abfc5ccd4ff39493e50f4c /test | |
parent | 0cd5f2004444b1c792ab3d4bd3b01699b11b9553 (diff) |
Test TCP sockets with MSG_TRUNC|MSG_PEEK.
PiperOrigin-RevId: 239714368
Change-Id: I35860b880a1d8885eb8c2d4ff267caaf72d91088
Diffstat (limited to 'test')
-rw-r--r-- | test/syscalls/linux/socket_ip_tcp_generic.cc | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/test/syscalls/linux/socket_ip_tcp_generic.cc b/test/syscalls/linux/socket_ip_tcp_generic.cc index e8a6210e1..8a222008e 100644 --- a/test/syscalls/linux/socket_ip_tcp_generic.cc +++ b/test/syscalls/linux/socket_ip_tcp_generic.cc @@ -538,5 +538,34 @@ TEST_P(TCPSocketPairTest, SetOOBInline) { EXPECT_EQ(get, kSockOptOn); } +TEST_P(TCPSocketPairTest, MsgTruncMsgPeek) { + auto sockets = ASSERT_NO_ERRNO_AND_VALUE(NewSocketPair()); + + char sent_data[512]; + RandomizeBuffer(sent_data, sizeof(sent_data)); + ASSERT_THAT( + RetryEINTR(send)(sockets->first_fd(), sent_data, sizeof(sent_data), 0), + SyscallSucceedsWithValue(sizeof(sent_data))); + + // Read half of the data with MSG_TRUNC | MSG_PEEK. This way there will still + // be some data left to read in the next step even if the data gets consumed. + char received_data1[sizeof(sent_data) / 2] = {}; + ASSERT_THAT(RetryEINTR(recv)(sockets->second_fd(), received_data1, + sizeof(received_data1), MSG_TRUNC | MSG_PEEK), + SyscallSucceedsWithValue(sizeof(received_data1))); + + // Check that we didn't get anything. + char zeros[sizeof(received_data1)] = {}; + EXPECT_EQ(0, memcmp(zeros, received_data1, sizeof(received_data1))); + + // Check that all of the data is still there. + char received_data2[sizeof(sent_data)] = {}; + ASSERT_THAT(RetryEINTR(recv)(sockets->second_fd(), received_data2, + sizeof(received_data2), 0), + SyscallSucceedsWithValue(sizeof(sent_data))); + + EXPECT_EQ(0, memcmp(received_data2, sent_data, sizeof(sent_data))); +} + } // namespace testing } // namespace gvisor |