gvisor.dev/gvisor@v0.0.0-20240520182842-f9d4d51c7e0f/test/syscalls/linux/socket_inet_loopback_test_params.h (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  #ifndef GVISOR_TEST_SYSCALLS_LINUX_SOCKET_INET_LOOPBACK_TEST_PARAMS_H_
    16  #define GVISOR_TEST_SYSCALLS_LINUX_SOCKET_INET_LOOPBACK_TEST_PARAMS_H_
    17  
    18  #include "gtest/gtest.h"
    19  #include "test/util/socket_util.h"
    20  
    21  namespace gvisor {
    22  namespace testing {
    23  
    24  struct SocketInetTestParam {
    25    TestAddress listener;
    26    TestAddress connector;
    27  };
    28  
    29  inline std::string DescribeSocketInetTestParam(
    30      ::testing::TestParamInfo<SocketInetTestParam> const& info) {
    31    return absl::StrCat("Listen", info.param.listener.description, "_Connect",
    32                        info.param.connector.description);
    33  }
    34  
    35  inline auto SocketInetLoopbackTestValues() {
    36    return ::testing::Values(
    37        // Listeners bound to IPv4 addresses refuse connections using IPv6
    38        // addresses.
    39        SocketInetTestParam{V4Any(), V4Any()},
    40        SocketInetTestParam{V4Any(), V4Loopback()},
    41        SocketInetTestParam{V4Any(), V4MappedAny()},
    42        SocketInetTestParam{V4Any(), V4MappedLoopback()},
    43        SocketInetTestParam{V4Loopback(), V4Any()},
    44        SocketInetTestParam{V4Loopback(), V4Loopback()},
    45        SocketInetTestParam{V4Loopback(), V4MappedLoopback()},
    46        SocketInetTestParam{V4MappedAny(), V4Any()},
    47        SocketInetTestParam{V4MappedAny(), V4Loopback()},
    48        SocketInetTestParam{V4MappedAny(), V4MappedAny()},
    49        SocketInetTestParam{V4MappedAny(), V4MappedLoopback()},
    50        SocketInetTestParam{V4MappedLoopback(), V4Any()},
    51        SocketInetTestParam{V4MappedLoopback(), V4Loopback()},
    52        SocketInetTestParam{V4MappedLoopback(), V4MappedLoopback()},
    53  
    54        // Listeners bound to IN6ADDR_ANY accept all connections.
    55        SocketInetTestParam{V6Any(), V4Any()},
    56        SocketInetTestParam{V6Any(), V4Loopback()},
    57        SocketInetTestParam{V6Any(), V4MappedAny()},
    58        SocketInetTestParam{V6Any(), V4MappedLoopback()},
    59        SocketInetTestParam{V6Any(), V6Any()},
    60        SocketInetTestParam{V6Any(), V6Loopback()},
    61  
    62        // Listeners bound to IN6ADDR_LOOPBACK refuse connections using IPv4
    63        // addresses.
    64        SocketInetTestParam{V6Loopback(), V6Any()},
    65        SocketInetTestParam{V6Loopback(), V6Loopback()});
    66  }
    67  
    68  struct ProtocolTestParam {
    69    std::string description;
    70    int type;
    71  };
    72  
    73  inline std::string DescribeProtocolTestParam(
    74      ::testing::TestParamInfo<ProtocolTestParam> const& info) {
    75    return info.param.description;
    76  }
    77  
    78  inline auto ProtocolTestValues() {
    79    return ::testing::Values(ProtocolTestParam{"TCP", SOCK_STREAM},
    80                             ProtocolTestParam{"UDP", SOCK_DGRAM});
    81  }
    82  
    83  }  // namespace testing
    84  }  // namespace gvisor
    85  
    86  #endif  // GVISOR_TEST_SYSCALLS_LINUX_SOCKET_INET_LOOPBACK_TEST_PARAMS_H_