github.com/SagerNet/gvisor@v0.0.0-20210707092255-7731c139d75c/test/syscalls/linux/socket_ip_tcp_udp_generic.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 <netinet/in.h> 16 #include <netinet/tcp.h> 17 #include <poll.h> 18 #include <stdio.h> 19 #include <sys/ioctl.h> 20 #include <sys/socket.h> 21 #include <sys/types.h> 22 #include <sys/un.h> 23 24 #include "gtest/gtest.h" 25 #include "test/syscalls/linux/ip_socket_test_util.h" 26 #include "test/syscalls/linux/socket_test_util.h" 27 #include "test/util/test_util.h" 28 29 namespace gvisor { 30 namespace testing { 31 32 namespace { 33 34 // Test fixture for tests that apply to pairs of TCP and UDP sockets. 35 using TcpUdpSocketPairTest = SocketPairTest; 36 37 TEST_P(TcpUdpSocketPairTest, ShutdownWrFollowedBySendIsError) { 38 auto sockets = ASSERT_NO_ERRNO_AND_VALUE(NewSocketPair()); 39 40 // Now shutdown the write end of the first. 41 ASSERT_THAT(shutdown(sockets->first_fd(), SHUT_WR), SyscallSucceeds()); 42 43 char buf[10] = {}; 44 ASSERT_THAT(RetryEINTR(send)(sockets->first_fd(), buf, sizeof(buf), 0), 45 SyscallFailsWithErrno(EPIPE)); 46 } 47 48 std::vector<SocketPairKind> GetSocketPairs() { 49 return VecCat<SocketPairKind>( 50 ApplyVec<SocketPairKind>( 51 IPv6UDPBidirectionalBindSocketPair, 52 AllBitwiseCombinations(List<int>{0, SOCK_NONBLOCK})), 53 ApplyVec<SocketPairKind>( 54 IPv4UDPBidirectionalBindSocketPair, 55 AllBitwiseCombinations(List<int>{0, SOCK_NONBLOCK})), 56 ApplyVec<SocketPairKind>( 57 DualStackUDPBidirectionalBindSocketPair, 58 AllBitwiseCombinations(List<int>{0, SOCK_NONBLOCK})), 59 ApplyVec<SocketPairKind>( 60 IPv6TCPAcceptBindSocketPair, 61 AllBitwiseCombinations(List<int>{0, SOCK_NONBLOCK})), 62 ApplyVec<SocketPairKind>( 63 IPv4TCPAcceptBindSocketPair, 64 AllBitwiseCombinations(List<int>{0, SOCK_NONBLOCK})), 65 ApplyVec<SocketPairKind>( 66 DualStackTCPAcceptBindSocketPair, 67 AllBitwiseCombinations(List<int>{0, SOCK_NONBLOCK}))); 68 } 69 70 INSTANTIATE_TEST_SUITE_P( 71 AllIPSockets, TcpUdpSocketPairTest, 72 ::testing::ValuesIn(IncludeReversals(GetSocketPairs()))); 73 74 } // namespace 75 76 } // namespace testing 77 } // namespace gvisor