github.com/SagerNet/gvisor@v0.0.0-20210707092255-7731c139d75c/test/syscalls/linux/socket_stream_nonblock.cc (about) 1 // Copyright 2018 The gVisor Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #include "test/syscalls/linux/socket_stream_nonblock.h" 16 17 #include <sys/socket.h> 18 #include <sys/types.h> 19 #include <sys/uio.h> 20 #include <sys/un.h> 21 22 #include "gtest/gtest.h" 23 #include "test/syscalls/linux/socket_test_util.h" 24 #include "test/syscalls/linux/unix_domain_socket_test_util.h" 25 #include "test/util/test_util.h" 26 27 namespace gvisor { 28 namespace testing { 29 30 using ::testing::Le; 31 32 TEST_P(NonBlockingStreamSocketPairTest, SendMsgTooLarge) { 33 auto sockets = ASSERT_NO_ERRNO_AND_VALUE(NewSocketPair()); 34 35 int sndbuf; 36 socklen_t length = sizeof(sndbuf); 37 ASSERT_THAT( 38 getsockopt(sockets->first_fd(), SOL_SOCKET, SO_SNDBUF, &sndbuf, &length), 39 SyscallSucceeds()); 40 41 // Make the call too large to fit in the send buffer. 42 const int buffer_size = 3 * sndbuf; 43 44 EXPECT_THAT(SendLargeSendMsg(sockets, buffer_size, false /* reader */), 45 SyscallSucceedsWithValue(Le(buffer_size))); 46 } 47 48 } // namespace testing 49 } // namespace gvisor