henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2004 The WebRTC Project Authors. All rights reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
Jonas Olsson | a4d8737 | 2019-07-05 17:08:33 | [diff] [blame] | 11 | #include "rtc_base/physical_socket_server.h" |
| 12 | |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 | [diff] [blame] | 13 | #include <signal.h> |
Jonas Olsson | a4d8737 | 2019-07-05 17:08:33 | [diff] [blame] | 14 | |
Yves Gerey | 3e70781 | 2018-11-28 15:47:49 | [diff] [blame] | 15 | #include <algorithm> |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 16 | #include <memory> |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 | [diff] [blame] | 17 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 18 | #include "rtc_base/gunit.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 19 | #include "rtc_base/ip_address.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 20 | #include "rtc_base/logging.h" |
Mirko Bonadei | e5f4c6b | 2021-01-15 09:41:01 | [diff] [blame] | 21 | #include "rtc_base/net_helpers.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 22 | #include "rtc_base/network_monitor.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 23 | #include "rtc_base/socket_unittest.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 24 | #include "rtc_base/test_utils.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 25 | #include "rtc_base/thread.h" |
Yves Gerey | 3e70781 | 2018-11-28 15:47:49 | [diff] [blame] | 26 | #include "test/gtest.h" |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 | [diff] [blame] | 27 | |
| 28 | namespace rtc { |
| 29 | |
Mirko Bonadei | 675513b | 2017-11-09 10:09:25 | [diff] [blame] | 30 | #define MAYBE_SKIP_IPV4 \ |
| 31 | if (!HasIPv4Enabled()) { \ |
| 32 | RTC_LOG(LS_INFO) << "No IPv4... skipping"; \ |
| 33 | return; \ |
deadbeef | 9a6f4d4 | 2017-05-16 02:43:33 | [diff] [blame] | 34 | } |
| 35 | |
Mirko Bonadei | 675513b | 2017-11-09 10:09:25 | [diff] [blame] | 36 | #define MAYBE_SKIP_IPV6 \ |
| 37 | if (!HasIPv6Enabled()) { \ |
| 38 | RTC_LOG(LS_INFO) << "No IPv6... skipping"; \ |
| 39 | return; \ |
Taylor Brandstetter | 2b3bf6b | 2016-05-19 21:57:31 | [diff] [blame] | 40 | } |
| 41 | |
jbauch | 095ae15 | 2015-12-18 09:39:55 | [diff] [blame] | 42 | class PhysicalSocketTest; |
| 43 | |
| 44 | class FakeSocketDispatcher : public SocketDispatcher { |
| 45 | public: |
| 46 | explicit FakeSocketDispatcher(PhysicalSocketServer* ss) |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 47 | : SocketDispatcher(ss) {} |
jbauch | 095ae15 | 2015-12-18 09:39:55 | [diff] [blame] | 48 | |
jbauch | f2a2bf4 | 2016-02-04 00:45:32 | [diff] [blame] | 49 | FakeSocketDispatcher(SOCKET s, PhysicalSocketServer* ss) |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 50 | : SocketDispatcher(s, ss) {} |
jbauch | f2a2bf4 | 2016-02-04 00:45:32 | [diff] [blame] | 51 | |
jbauch | 095ae15 | 2015-12-18 09:39:55 | [diff] [blame] | 52 | protected: |
| 53 | SOCKET DoAccept(SOCKET socket, sockaddr* addr, socklen_t* addrlen) override; |
jbauch | f2a2bf4 | 2016-02-04 00:45:32 | [diff] [blame] | 54 | int DoSend(SOCKET socket, const char* buf, int len, int flags) override; |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 55 | int DoSendTo(SOCKET socket, |
| 56 | const char* buf, |
| 57 | int len, |
| 58 | int flags, |
| 59 | const struct sockaddr* dest_addr, |
| 60 | socklen_t addrlen) override; |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 | [diff] [blame] | 61 | }; |
| 62 | |
jbauch | 095ae15 | 2015-12-18 09:39:55 | [diff] [blame] | 63 | class FakePhysicalSocketServer : public PhysicalSocketServer { |
| 64 | public: |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 65 | explicit FakePhysicalSocketServer(PhysicalSocketTest* test) : test_(test) {} |
jbauch | 095ae15 | 2015-12-18 09:39:55 | [diff] [blame] | 66 | |
jbauch | 095ae15 | 2015-12-18 09:39:55 | [diff] [blame] | 67 | AsyncSocket* CreateAsyncSocket(int family, int type) override { |
| 68 | SocketDispatcher* dispatcher = new FakeSocketDispatcher(this); |
jbauch | f2a2bf4 | 2016-02-04 00:45:32 | [diff] [blame] | 69 | if (!dispatcher->Create(family, type)) { |
jbauch | 095ae15 | 2015-12-18 09:39:55 | [diff] [blame] | 70 | delete dispatcher; |
| 71 | return nullptr; |
| 72 | } |
jbauch | f2a2bf4 | 2016-02-04 00:45:32 | [diff] [blame] | 73 | return dispatcher; |
| 74 | } |
| 75 | |
| 76 | AsyncSocket* WrapSocket(SOCKET s) override { |
| 77 | SocketDispatcher* dispatcher = new FakeSocketDispatcher(s, this); |
| 78 | if (!dispatcher->Initialize()) { |
| 79 | delete dispatcher; |
| 80 | return nullptr; |
| 81 | } |
| 82 | return dispatcher; |
jbauch | 095ae15 | 2015-12-18 09:39:55 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | PhysicalSocketTest* GetTest() const { return test_; } |
| 86 | |
| 87 | private: |
| 88 | PhysicalSocketTest* test_; |
| 89 | }; |
| 90 | |
deadbeef | c874d12 | 2017-02-13 23:41:59 | [diff] [blame] | 91 | class FakeNetworkBinder : public NetworkBinderInterface { |
| 92 | public: |
| 93 | NetworkBindingResult BindSocketToNetwork(int, const IPAddress&) override { |
deadbeef | 9ffa13f | 2017-02-22 00:18:00 | [diff] [blame] | 94 | ++num_binds_; |
deadbeef | c874d12 | 2017-02-13 23:41:59 | [diff] [blame] | 95 | return result_; |
| 96 | } |
| 97 | |
| 98 | void set_result(NetworkBindingResult result) { result_ = result; } |
| 99 | |
deadbeef | 9ffa13f | 2017-02-22 00:18:00 | [diff] [blame] | 100 | int num_binds() { return num_binds_; } |
| 101 | |
deadbeef | c874d12 | 2017-02-13 23:41:59 | [diff] [blame] | 102 | private: |
| 103 | NetworkBindingResult result_ = NetworkBindingResult::SUCCESS; |
deadbeef | 9ffa13f | 2017-02-22 00:18:00 | [diff] [blame] | 104 | int num_binds_ = 0; |
deadbeef | c874d12 | 2017-02-13 23:41:59 | [diff] [blame] | 105 | }; |
| 106 | |
jbauch | 095ae15 | 2015-12-18 09:39:55 | [diff] [blame] | 107 | class PhysicalSocketTest : public SocketTest { |
| 108 | public: |
| 109 | // Set flag to simluate failures when calling "::accept" on a AsyncSocket. |
| 110 | void SetFailAccept(bool fail) { fail_accept_ = fail; } |
| 111 | bool FailAccept() const { return fail_accept_; } |
| 112 | |
jbauch | f2a2bf4 | 2016-02-04 00:45:32 | [diff] [blame] | 113 | // Maximum size to ::send to a socket. Set to < 0 to disable limiting. |
| 114 | void SetMaxSendSize(int max_size) { max_send_size_ = max_size; } |
| 115 | int MaxSendSize() const { return max_send_size_; } |
| 116 | |
jbauch | 095ae15 | 2015-12-18 09:39:55 | [diff] [blame] | 117 | protected: |
| 118 | PhysicalSocketTest() |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 119 | : server_(new FakePhysicalSocketServer(this)), |
| 120 | thread_(server_.get()), |
| 121 | fail_accept_(false), |
| 122 | max_send_size_(-1) {} |
jbauch | 095ae15 | 2015-12-18 09:39:55 | [diff] [blame] | 123 | |
| 124 | void ConnectInternalAcceptError(const IPAddress& loopback); |
jbauch | f2a2bf4 | 2016-02-04 00:45:32 | [diff] [blame] | 125 | void WritableAfterPartialWrite(const IPAddress& loopback); |
jbauch | 095ae15 | 2015-12-18 09:39:55 | [diff] [blame] | 126 | |
jbauch | 555604a | 2016-04-26 10:13:22 | [diff] [blame] | 127 | std::unique_ptr<FakePhysicalSocketServer> server_; |
nisse | 7eaa4ea | 2017-05-08 12:25:41 | [diff] [blame] | 128 | rtc::AutoSocketServerThread thread_; |
jbauch | 095ae15 | 2015-12-18 09:39:55 | [diff] [blame] | 129 | bool fail_accept_; |
jbauch | f2a2bf4 | 2016-02-04 00:45:32 | [diff] [blame] | 130 | int max_send_size_; |
jbauch | 095ae15 | 2015-12-18 09:39:55 | [diff] [blame] | 131 | }; |
| 132 | |
| 133 | SOCKET FakeSocketDispatcher::DoAccept(SOCKET socket, |
| 134 | sockaddr* addr, |
| 135 | socklen_t* addrlen) { |
| 136 | FakePhysicalSocketServer* ss = |
| 137 | static_cast<FakePhysicalSocketServer*>(socketserver()); |
| 138 | if (ss->GetTest()->FailAccept()) { |
| 139 | return INVALID_SOCKET; |
| 140 | } |
| 141 | |
| 142 | return SocketDispatcher::DoAccept(socket, addr, addrlen); |
| 143 | } |
| 144 | |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 145 | int FakeSocketDispatcher::DoSend(SOCKET socket, |
| 146 | const char* buf, |
| 147 | int len, |
| 148 | int flags) { |
jbauch | f2a2bf4 | 2016-02-04 00:45:32 | [diff] [blame] | 149 | FakePhysicalSocketServer* ss = |
| 150 | static_cast<FakePhysicalSocketServer*>(socketserver()); |
| 151 | if (ss->GetTest()->MaxSendSize() >= 0) { |
| 152 | len = std::min(len, ss->GetTest()->MaxSendSize()); |
| 153 | } |
| 154 | |
| 155 | return SocketDispatcher::DoSend(socket, buf, len, flags); |
| 156 | } |
| 157 | |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 158 | int FakeSocketDispatcher::DoSendTo(SOCKET socket, |
| 159 | const char* buf, |
| 160 | int len, |
| 161 | int flags, |
| 162 | const struct sockaddr* dest_addr, |
| 163 | socklen_t addrlen) { |
jbauch | f2a2bf4 | 2016-02-04 00:45:32 | [diff] [blame] | 164 | FakePhysicalSocketServer* ss = |
| 165 | static_cast<FakePhysicalSocketServer*>(socketserver()); |
| 166 | if (ss->GetTest()->MaxSendSize() >= 0) { |
| 167 | len = std::min(len, ss->GetTest()->MaxSendSize()); |
| 168 | } |
| 169 | |
| 170 | return SocketDispatcher::DoSendTo(socket, buf, len, flags, dest_addr, |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 171 | addrlen); |
jbauch | f2a2bf4 | 2016-02-04 00:45:32 | [diff] [blame] | 172 | } |
| 173 | |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 | [diff] [blame] | 174 | TEST_F(PhysicalSocketTest, TestConnectIPv4) { |
deadbeef | 9a6f4d4 | 2017-05-16 02:43:33 | [diff] [blame] | 175 | MAYBE_SKIP_IPV4; |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 | [diff] [blame] | 176 | SocketTest::TestConnectIPv4(); |
| 177 | } |
| 178 | |
Taylor Brandstetter | 2b3bf6b | 2016-05-19 21:57:31 | [diff] [blame] | 179 | TEST_F(PhysicalSocketTest, TestConnectIPv6) { |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 | [diff] [blame] | 180 | SocketTest::TestConnectIPv6(); |
| 181 | } |
| 182 | |
| 183 | TEST_F(PhysicalSocketTest, TestConnectWithDnsLookupIPv4) { |
deadbeef | 9a6f4d4 | 2017-05-16 02:43:33 | [diff] [blame] | 184 | MAYBE_SKIP_IPV4; |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 | [diff] [blame] | 185 | SocketTest::TestConnectWithDnsLookupIPv4(); |
| 186 | } |
| 187 | |
| 188 | TEST_F(PhysicalSocketTest, TestConnectWithDnsLookupIPv6) { |
| 189 | SocketTest::TestConnectWithDnsLookupIPv6(); |
| 190 | } |
| 191 | |
| 192 | TEST_F(PhysicalSocketTest, TestConnectFailIPv4) { |
deadbeef | 9a6f4d4 | 2017-05-16 02:43:33 | [diff] [blame] | 193 | MAYBE_SKIP_IPV4; |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 | [diff] [blame] | 194 | SocketTest::TestConnectFailIPv4(); |
| 195 | } |
| 196 | |
jbauch | 095ae15 | 2015-12-18 09:39:55 | [diff] [blame] | 197 | void PhysicalSocketTest::ConnectInternalAcceptError(const IPAddress& loopback) { |
kwiberg | d0d8148 | 2017-04-18 10:18:22 | [diff] [blame] | 198 | webrtc::testing::StreamSink sink; |
jbauch | 095ae15 | 2015-12-18 09:39:55 | [diff] [blame] | 199 | SocketAddress accept_addr; |
| 200 | |
| 201 | // Create two clients. |
jbauch | 555604a | 2016-04-26 10:13:22 | [diff] [blame] | 202 | std::unique_ptr<AsyncSocket> client1( |
| 203 | server_->CreateAsyncSocket(loopback.family(), SOCK_STREAM)); |
jbauch | 095ae15 | 2015-12-18 09:39:55 | [diff] [blame] | 204 | sink.Monitor(client1.get()); |
| 205 | EXPECT_EQ(AsyncSocket::CS_CLOSED, client1->GetState()); |
Jonas Olsson | abbe841 | 2018-04-03 11:40:05 | [diff] [blame] | 206 | EXPECT_TRUE(IsUnspecOrEmptyIP(client1->GetLocalAddress().ipaddr())); |
jbauch | 095ae15 | 2015-12-18 09:39:55 | [diff] [blame] | 207 | |
jbauch | 555604a | 2016-04-26 10:13:22 | [diff] [blame] | 208 | std::unique_ptr<AsyncSocket> client2( |
| 209 | server_->CreateAsyncSocket(loopback.family(), SOCK_STREAM)); |
jbauch | 095ae15 | 2015-12-18 09:39:55 | [diff] [blame] | 210 | sink.Monitor(client2.get()); |
| 211 | EXPECT_EQ(AsyncSocket::CS_CLOSED, client2->GetState()); |
Jonas Olsson | abbe841 | 2018-04-03 11:40:05 | [diff] [blame] | 212 | EXPECT_TRUE(IsUnspecOrEmptyIP(client2->GetLocalAddress().ipaddr())); |
jbauch | 095ae15 | 2015-12-18 09:39:55 | [diff] [blame] | 213 | |
| 214 | // Create server and listen. |
jbauch | 555604a | 2016-04-26 10:13:22 | [diff] [blame] | 215 | std::unique_ptr<AsyncSocket> server( |
jbauch | 095ae15 | 2015-12-18 09:39:55 | [diff] [blame] | 216 | server_->CreateAsyncSocket(loopback.family(), SOCK_STREAM)); |
| 217 | sink.Monitor(server.get()); |
| 218 | EXPECT_EQ(0, server->Bind(SocketAddress(loopback, 0))); |
| 219 | EXPECT_EQ(0, server->Listen(5)); |
| 220 | EXPECT_EQ(AsyncSocket::CS_CONNECTING, server->GetState()); |
| 221 | |
| 222 | // Ensure no pending server connections, since we haven't done anything yet. |
kwiberg | d0d8148 | 2017-04-18 10:18:22 | [diff] [blame] | 223 | EXPECT_FALSE(sink.Check(server.get(), webrtc::testing::SSE_READ)); |
jbauch | 095ae15 | 2015-12-18 09:39:55 | [diff] [blame] | 224 | EXPECT_TRUE(nullptr == server->Accept(&accept_addr)); |
| 225 | EXPECT_TRUE(accept_addr.IsNil()); |
| 226 | |
| 227 | // Attempt first connect to listening socket. |
| 228 | EXPECT_EQ(0, client1->Connect(server->GetLocalAddress())); |
| 229 | EXPECT_FALSE(client1->GetLocalAddress().IsNil()); |
| 230 | EXPECT_NE(server->GetLocalAddress(), client1->GetLocalAddress()); |
| 231 | |
| 232 | // Client is connecting, outcome not yet determined. |
| 233 | EXPECT_EQ(AsyncSocket::CS_CONNECTING, client1->GetState()); |
kwiberg | d0d8148 | 2017-04-18 10:18:22 | [diff] [blame] | 234 | EXPECT_FALSE(sink.Check(client1.get(), webrtc::testing::SSE_OPEN)); |
| 235 | EXPECT_FALSE(sink.Check(client1.get(), webrtc::testing::SSE_CLOSE)); |
jbauch | 095ae15 | 2015-12-18 09:39:55 | [diff] [blame] | 236 | |
| 237 | // Server has pending connection, try to accept it (will fail). |
kwiberg | d0d8148 | 2017-04-18 10:18:22 | [diff] [blame] | 238 | EXPECT_TRUE_WAIT((sink.Check(server.get(), webrtc::testing::SSE_READ)), |
| 239 | kTimeout); |
jbauch | 095ae15 | 2015-12-18 09:39:55 | [diff] [blame] | 240 | // Simulate "::accept" returning an error. |
| 241 | SetFailAccept(true); |
jbauch | 555604a | 2016-04-26 10:13:22 | [diff] [blame] | 242 | std::unique_ptr<AsyncSocket> accepted(server->Accept(&accept_addr)); |
jbauch | 095ae15 | 2015-12-18 09:39:55 | [diff] [blame] | 243 | EXPECT_FALSE(accepted); |
| 244 | ASSERT_TRUE(accept_addr.IsNil()); |
| 245 | |
| 246 | // Ensure no more pending server connections. |
kwiberg | d0d8148 | 2017-04-18 10:18:22 | [diff] [blame] | 247 | EXPECT_FALSE(sink.Check(server.get(), webrtc::testing::SSE_READ)); |
jbauch | 095ae15 | 2015-12-18 09:39:55 | [diff] [blame] | 248 | EXPECT_TRUE(nullptr == server->Accept(&accept_addr)); |
| 249 | EXPECT_TRUE(accept_addr.IsNil()); |
| 250 | |
| 251 | // Attempt second connect to listening socket. |
| 252 | EXPECT_EQ(0, client2->Connect(server->GetLocalAddress())); |
| 253 | EXPECT_FALSE(client2->GetLocalAddress().IsNil()); |
| 254 | EXPECT_NE(server->GetLocalAddress(), client2->GetLocalAddress()); |
| 255 | |
| 256 | // Client is connecting, outcome not yet determined. |
| 257 | EXPECT_EQ(AsyncSocket::CS_CONNECTING, client2->GetState()); |
kwiberg | d0d8148 | 2017-04-18 10:18:22 | [diff] [blame] | 258 | EXPECT_FALSE(sink.Check(client2.get(), webrtc::testing::SSE_OPEN)); |
| 259 | EXPECT_FALSE(sink.Check(client2.get(), webrtc::testing::SSE_CLOSE)); |
jbauch | 095ae15 | 2015-12-18 09:39:55 | [diff] [blame] | 260 | |
| 261 | // Server has pending connection, try to accept it (will succeed). |
kwiberg | d0d8148 | 2017-04-18 10:18:22 | [diff] [blame] | 262 | EXPECT_TRUE_WAIT((sink.Check(server.get(), webrtc::testing::SSE_READ)), |
| 263 | kTimeout); |
jbauch | 095ae15 | 2015-12-18 09:39:55 | [diff] [blame] | 264 | SetFailAccept(false); |
jbauch | 555604a | 2016-04-26 10:13:22 | [diff] [blame] | 265 | std::unique_ptr<AsyncSocket> accepted2(server->Accept(&accept_addr)); |
jbauch | 095ae15 | 2015-12-18 09:39:55 | [diff] [blame] | 266 | ASSERT_TRUE(accepted2); |
| 267 | EXPECT_FALSE(accept_addr.IsNil()); |
| 268 | EXPECT_EQ(accepted2->GetRemoteAddress(), accept_addr); |
| 269 | } |
| 270 | |
| 271 | TEST_F(PhysicalSocketTest, TestConnectAcceptErrorIPv4) { |
deadbeef | 9a6f4d4 | 2017-05-16 02:43:33 | [diff] [blame] | 272 | MAYBE_SKIP_IPV4; |
jbauch | 095ae15 | 2015-12-18 09:39:55 | [diff] [blame] | 273 | ConnectInternalAcceptError(kIPv4Loopback); |
| 274 | } |
| 275 | |
Taylor Brandstetter | 2b3bf6b | 2016-05-19 21:57:31 | [diff] [blame] | 276 | TEST_F(PhysicalSocketTest, TestConnectAcceptErrorIPv6) { |
| 277 | MAYBE_SKIP_IPV6; |
jbauch | 095ae15 | 2015-12-18 09:39:55 | [diff] [blame] | 278 | ConnectInternalAcceptError(kIPv6Loopback); |
| 279 | } |
| 280 | |
jbauch | f2a2bf4 | 2016-02-04 00:45:32 | [diff] [blame] | 281 | void PhysicalSocketTest::WritableAfterPartialWrite(const IPAddress& loopback) { |
| 282 | // Simulate a really small maximum send size. |
| 283 | const int kMaxSendSize = 128; |
| 284 | SetMaxSendSize(kMaxSendSize); |
| 285 | |
| 286 | // Run the default send/receive socket tests with a smaller amount of data |
| 287 | // to avoid long running times due to the small maximum send size. |
| 288 | const size_t kDataSize = 128 * 1024; |
| 289 | TcpInternal(loopback, kDataSize, kMaxSendSize); |
| 290 | } |
| 291 | |
danilchap | b7b9dca | 2016-08-05 12:55:43 | [diff] [blame] | 292 | // https://bugs.chromium.org/p/webrtc/issues/detail?id=6167 |
| 293 | #if defined(WEBRTC_WIN) |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 294 | #define MAYBE_TestWritableAfterPartialWriteIPv4 \ |
| 295 | DISABLED_TestWritableAfterPartialWriteIPv4 |
danilchap | b7b9dca | 2016-08-05 12:55:43 | [diff] [blame] | 296 | #else |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 297 | #define MAYBE_TestWritableAfterPartialWriteIPv4 \ |
| 298 | TestWritableAfterPartialWriteIPv4 |
danilchap | b7b9dca | 2016-08-05 12:55:43 | [diff] [blame] | 299 | #endif |
| 300 | TEST_F(PhysicalSocketTest, MAYBE_TestWritableAfterPartialWriteIPv4) { |
deadbeef | 9a6f4d4 | 2017-05-16 02:43:33 | [diff] [blame] | 301 | MAYBE_SKIP_IPV4; |
jbauch | f2a2bf4 | 2016-02-04 00:45:32 | [diff] [blame] | 302 | WritableAfterPartialWrite(kIPv4Loopback); |
| 303 | } |
| 304 | |
danilchap | b7b9dca | 2016-08-05 12:55:43 | [diff] [blame] | 305 | // https://bugs.chromium.org/p/webrtc/issues/detail?id=6167 |
| 306 | #if defined(WEBRTC_WIN) |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 307 | #define MAYBE_TestWritableAfterPartialWriteIPv6 \ |
| 308 | DISABLED_TestWritableAfterPartialWriteIPv6 |
danilchap | b7b9dca | 2016-08-05 12:55:43 | [diff] [blame] | 309 | #else |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 310 | #define MAYBE_TestWritableAfterPartialWriteIPv6 \ |
| 311 | TestWritableAfterPartialWriteIPv6 |
danilchap | b7b9dca | 2016-08-05 12:55:43 | [diff] [blame] | 312 | #endif |
| 313 | TEST_F(PhysicalSocketTest, MAYBE_TestWritableAfterPartialWriteIPv6) { |
Taylor Brandstetter | 2b3bf6b | 2016-05-19 21:57:31 | [diff] [blame] | 314 | MAYBE_SKIP_IPV6; |
jbauch | f2a2bf4 | 2016-02-04 00:45:32 | [diff] [blame] | 315 | WritableAfterPartialWrite(kIPv6Loopback); |
| 316 | } |
| 317 | |
Taylor Brandstetter | 2b3bf6b | 2016-05-19 21:57:31 | [diff] [blame] | 318 | TEST_F(PhysicalSocketTest, TestConnectFailIPv6) { |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 | [diff] [blame] | 319 | SocketTest::TestConnectFailIPv6(); |
| 320 | } |
| 321 | |
| 322 | TEST_F(PhysicalSocketTest, TestConnectWithDnsLookupFailIPv4) { |
deadbeef | 9a6f4d4 | 2017-05-16 02:43:33 | [diff] [blame] | 323 | MAYBE_SKIP_IPV4; |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 | [diff] [blame] | 324 | SocketTest::TestConnectWithDnsLookupFailIPv4(); |
| 325 | } |
| 326 | |
Taylor Brandstetter | 2b3bf6b | 2016-05-19 21:57:31 | [diff] [blame] | 327 | TEST_F(PhysicalSocketTest, TestConnectWithDnsLookupFailIPv6) { |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 | [diff] [blame] | 328 | SocketTest::TestConnectWithDnsLookupFailIPv6(); |
| 329 | } |
| 330 | |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 | [diff] [blame] | 331 | TEST_F(PhysicalSocketTest, TestConnectWithClosedSocketIPv4) { |
deadbeef | 9a6f4d4 | 2017-05-16 02:43:33 | [diff] [blame] | 332 | MAYBE_SKIP_IPV4; |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 | [diff] [blame] | 333 | SocketTest::TestConnectWithClosedSocketIPv4(); |
| 334 | } |
| 335 | |
Taylor Brandstetter | 2b3bf6b | 2016-05-19 21:57:31 | [diff] [blame] | 336 | TEST_F(PhysicalSocketTest, TestConnectWithClosedSocketIPv6) { |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 | [diff] [blame] | 337 | SocketTest::TestConnectWithClosedSocketIPv6(); |
| 338 | } |
| 339 | |
| 340 | TEST_F(PhysicalSocketTest, TestConnectWhileNotClosedIPv4) { |
deadbeef | 9a6f4d4 | 2017-05-16 02:43:33 | [diff] [blame] | 341 | MAYBE_SKIP_IPV4; |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 | [diff] [blame] | 342 | SocketTest::TestConnectWhileNotClosedIPv4(); |
| 343 | } |
| 344 | |
Taylor Brandstetter | 2b3bf6b | 2016-05-19 21:57:31 | [diff] [blame] | 345 | TEST_F(PhysicalSocketTest, TestConnectWhileNotClosedIPv6) { |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 | [diff] [blame] | 346 | SocketTest::TestConnectWhileNotClosedIPv6(); |
| 347 | } |
| 348 | |
| 349 | TEST_F(PhysicalSocketTest, TestServerCloseDuringConnectIPv4) { |
deadbeef | 9a6f4d4 | 2017-05-16 02:43:33 | [diff] [blame] | 350 | MAYBE_SKIP_IPV4; |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 | [diff] [blame] | 351 | SocketTest::TestServerCloseDuringConnectIPv4(); |
| 352 | } |
| 353 | |
Taylor Brandstetter | 2b3bf6b | 2016-05-19 21:57:31 | [diff] [blame] | 354 | TEST_F(PhysicalSocketTest, TestServerCloseDuringConnectIPv6) { |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 | [diff] [blame] | 355 | SocketTest::TestServerCloseDuringConnectIPv6(); |
| 356 | } |
| 357 | |
| 358 | TEST_F(PhysicalSocketTest, TestClientCloseDuringConnectIPv4) { |
deadbeef | 9a6f4d4 | 2017-05-16 02:43:33 | [diff] [blame] | 359 | MAYBE_SKIP_IPV4; |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 | [diff] [blame] | 360 | SocketTest::TestClientCloseDuringConnectIPv4(); |
| 361 | } |
| 362 | |
Taylor Brandstetter | 2b3bf6b | 2016-05-19 21:57:31 | [diff] [blame] | 363 | TEST_F(PhysicalSocketTest, TestClientCloseDuringConnectIPv6) { |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 | [diff] [blame] | 364 | SocketTest::TestClientCloseDuringConnectIPv6(); |
| 365 | } |
| 366 | |
| 367 | TEST_F(PhysicalSocketTest, TestServerCloseIPv4) { |
deadbeef | 9a6f4d4 | 2017-05-16 02:43:33 | [diff] [blame] | 368 | MAYBE_SKIP_IPV4; |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 | [diff] [blame] | 369 | SocketTest::TestServerCloseIPv4(); |
| 370 | } |
| 371 | |
Taylor Brandstetter | 2b3bf6b | 2016-05-19 21:57:31 | [diff] [blame] | 372 | TEST_F(PhysicalSocketTest, TestServerCloseIPv6) { |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 | [diff] [blame] | 373 | SocketTest::TestServerCloseIPv6(); |
| 374 | } |
| 375 | |
| 376 | TEST_F(PhysicalSocketTest, TestCloseInClosedCallbackIPv4) { |
deadbeef | 9a6f4d4 | 2017-05-16 02:43:33 | [diff] [blame] | 377 | MAYBE_SKIP_IPV4; |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 | [diff] [blame] | 378 | SocketTest::TestCloseInClosedCallbackIPv4(); |
| 379 | } |
| 380 | |
Taylor Brandstetter | 2b3bf6b | 2016-05-19 21:57:31 | [diff] [blame] | 381 | TEST_F(PhysicalSocketTest, TestCloseInClosedCallbackIPv6) { |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 | [diff] [blame] | 382 | SocketTest::TestCloseInClosedCallbackIPv6(); |
| 383 | } |
| 384 | |
Taylor Brandstetter | 7b69a44 | 2020-08-20 23:43:13 | [diff] [blame] | 385 | TEST_F(PhysicalSocketTest, TestDeleteInReadCallbackIPv4) { |
| 386 | MAYBE_SKIP_IPV4; |
| 387 | SocketTest::TestDeleteInReadCallbackIPv4(); |
| 388 | } |
| 389 | |
| 390 | TEST_F(PhysicalSocketTest, TestDeleteInReadCallbackIPv6) { |
| 391 | SocketTest::TestDeleteInReadCallbackIPv6(); |
| 392 | } |
| 393 | |
henrike@webrtc.org | c732a3e | 2014-10-09 22:08:15 | [diff] [blame] | 394 | TEST_F(PhysicalSocketTest, TestSocketServerWaitIPv4) { |
deadbeef | 9a6f4d4 | 2017-05-16 02:43:33 | [diff] [blame] | 395 | MAYBE_SKIP_IPV4; |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 | [diff] [blame] | 396 | SocketTest::TestSocketServerWaitIPv4(); |
| 397 | } |
| 398 | |
Taylor Brandstetter | 2b3bf6b | 2016-05-19 21:57:31 | [diff] [blame] | 399 | TEST_F(PhysicalSocketTest, TestSocketServerWaitIPv6) { |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 | [diff] [blame] | 400 | SocketTest::TestSocketServerWaitIPv6(); |
| 401 | } |
| 402 | |
| 403 | TEST_F(PhysicalSocketTest, TestTcpIPv4) { |
deadbeef | 9a6f4d4 | 2017-05-16 02:43:33 | [diff] [blame] | 404 | MAYBE_SKIP_IPV4; |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 | [diff] [blame] | 405 | SocketTest::TestTcpIPv4(); |
| 406 | } |
| 407 | |
Taylor Brandstetter | 2b3bf6b | 2016-05-19 21:57:31 | [diff] [blame] | 408 | TEST_F(PhysicalSocketTest, TestTcpIPv6) { |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 | [diff] [blame] | 409 | SocketTest::TestTcpIPv6(); |
| 410 | } |
| 411 | |
| 412 | TEST_F(PhysicalSocketTest, TestUdpIPv4) { |
deadbeef | 9a6f4d4 | 2017-05-16 02:43:33 | [diff] [blame] | 413 | MAYBE_SKIP_IPV4; |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 | [diff] [blame] | 414 | SocketTest::TestUdpIPv4(); |
| 415 | } |
| 416 | |
Taylor Brandstetter | 2b3bf6b | 2016-05-19 21:57:31 | [diff] [blame] | 417 | TEST_F(PhysicalSocketTest, TestUdpIPv6) { |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 | [diff] [blame] | 418 | SocketTest::TestUdpIPv6(); |
| 419 | } |
| 420 | |
henrike@webrtc.org | 6f833c3 | 2014-06-27 16:21:49 | [diff] [blame] | 421 | // Disable for TSan v2, see |
| 422 | // https://code.google.com/p/webrtc/issues/detail?id=3498 for details. |
deadbeef | c97be6a | 2015-09-25 18:00:38 | [diff] [blame] | 423 | // Also disable for MSan, see: |
| 424 | // https://code.google.com/p/webrtc/issues/detail?id=4958 |
| 425 | // TODO(deadbeef): Enable again once test is reimplemented to be unflaky. |
minyue | df200d1 | 2015-10-17 20:10:46 | [diff] [blame] | 426 | // Also disable for ASan. |
Henrik Kjellander | 0be3e04 | 2015-10-30 20:21:03 | [diff] [blame] | 427 | // Disabled on Android: https://code.google.com/p/webrtc/issues/detail?id=4364 |
ivoc | f399f21 | 2015-11-19 14:44:32 | [diff] [blame] | 428 | // Disabled on Linux: https://bugs.chromium.org/p/webrtc/issues/detail?id=5233 |
minyue | df200d1 | 2015-10-17 20:10:46 | [diff] [blame] | 429 | #if defined(THREAD_SANITIZER) || defined(MEMORY_SANITIZER) || \ |
ivoc | f399f21 | 2015-11-19 14:44:32 | [diff] [blame] | 430 | defined(ADDRESS_SANITIZER) || defined(WEBRTC_ANDROID) || \ |
| 431 | defined(WEBRTC_LINUX) |
minyue | df200d1 | 2015-10-17 20:10:46 | [diff] [blame] | 432 | #define MAYBE_TestUdpReadyToSendIPv4 DISABLED_TestUdpReadyToSendIPv4 |
| 433 | #else |
| 434 | #define MAYBE_TestUdpReadyToSendIPv4 TestUdpReadyToSendIPv4 |
| 435 | #endif |
| 436 | TEST_F(PhysicalSocketTest, MAYBE_TestUdpReadyToSendIPv4) { |
deadbeef | 9a6f4d4 | 2017-05-16 02:43:33 | [diff] [blame] | 437 | MAYBE_SKIP_IPV4; |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 | [diff] [blame] | 438 | SocketTest::TestUdpReadyToSendIPv4(); |
| 439 | } |
| 440 | |
danilchap | b7b9dca | 2016-08-05 12:55:43 | [diff] [blame] | 441 | // https://bugs.chromium.org/p/webrtc/issues/detail?id=6167 |
| 442 | #if defined(WEBRTC_WIN) |
| 443 | #define MAYBE_TestUdpReadyToSendIPv6 DISABLED_TestUdpReadyToSendIPv6 |
| 444 | #else |
| 445 | #define MAYBE_TestUdpReadyToSendIPv6 TestUdpReadyToSendIPv6 |
| 446 | #endif |
| 447 | TEST_F(PhysicalSocketTest, MAYBE_TestUdpReadyToSendIPv6) { |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 | [diff] [blame] | 448 | SocketTest::TestUdpReadyToSendIPv6(); |
| 449 | } |
| 450 | |
| 451 | TEST_F(PhysicalSocketTest, TestGetSetOptionsIPv4) { |
deadbeef | 9a6f4d4 | 2017-05-16 02:43:33 | [diff] [blame] | 452 | MAYBE_SKIP_IPV4; |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 | [diff] [blame] | 453 | SocketTest::TestGetSetOptionsIPv4(); |
| 454 | } |
| 455 | |
| 456 | TEST_F(PhysicalSocketTest, TestGetSetOptionsIPv6) { |
| 457 | SocketTest::TestGetSetOptionsIPv6(); |
| 458 | } |
| 459 | |
| 460 | #if defined(WEBRTC_POSIX) |
| 461 | |
Taylor Brandstetter | 6f82535 | 2016-08-11 22:38:28 | [diff] [blame] | 462 | // We don't get recv timestamps on Mac. |
Stefan Holmer | 9131efd | 2016-05-23 16:19:26 | [diff] [blame] | 463 | #if !defined(WEBRTC_MAC) |
| 464 | TEST_F(PhysicalSocketTest, TestSocketRecvTimestampIPv4) { |
deadbeef | 9a6f4d4 | 2017-05-16 02:43:33 | [diff] [blame] | 465 | MAYBE_SKIP_IPV4; |
Taylor Brandstetter | 6f82535 | 2016-08-11 22:38:28 | [diff] [blame] | 466 | SocketTest::TestSocketRecvTimestampIPv4(); |
Stefan Holmer | 9131efd | 2016-05-23 16:19:26 | [diff] [blame] | 467 | } |
| 468 | |
Taylor Brandstetter | 6f82535 | 2016-08-11 22:38:28 | [diff] [blame] | 469 | TEST_F(PhysicalSocketTest, TestSocketRecvTimestampIPv6) { |
| 470 | SocketTest::TestSocketRecvTimestampIPv6(); |
Stefan Holmer | 9131efd | 2016-05-23 16:19:26 | [diff] [blame] | 471 | } |
| 472 | #endif |
| 473 | |
deadbeef | c874d12 | 2017-02-13 23:41:59 | [diff] [blame] | 474 | // Verify that if the socket was unable to be bound to a real network interface |
| 475 | // (not loopback), Bind will return an error. |
| 476 | TEST_F(PhysicalSocketTest, |
| 477 | BindFailsIfNetworkBinderFailsForNonLoopbackInterface) { |
deadbeef | 9a6f4d4 | 2017-05-16 02:43:33 | [diff] [blame] | 478 | MAYBE_SKIP_IPV4; |
deadbeef | c874d12 | 2017-02-13 23:41:59 | [diff] [blame] | 479 | FakeNetworkBinder fake_network_binder; |
| 480 | server_->set_network_binder(&fake_network_binder); |
| 481 | std::unique_ptr<AsyncSocket> socket( |
| 482 | server_->CreateAsyncSocket(AF_INET, SOCK_DGRAM)); |
| 483 | fake_network_binder.set_result(NetworkBindingResult::FAILURE); |
| 484 | EXPECT_EQ(-1, socket->Bind(SocketAddress("192.168.0.1", 0))); |
| 485 | server_->set_network_binder(nullptr); |
| 486 | } |
| 487 | |
deadbeef | 9ffa13f | 2017-02-22 00:18:00 | [diff] [blame] | 488 | // Network binder shouldn't be used if the socket is bound to the "any" IP. |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 489 | TEST_F(PhysicalSocketTest, NetworkBinderIsNotUsedForAnyIp) { |
deadbeef | 9a6f4d4 | 2017-05-16 02:43:33 | [diff] [blame] | 490 | MAYBE_SKIP_IPV4; |
deadbeef | 9ffa13f | 2017-02-22 00:18:00 | [diff] [blame] | 491 | FakeNetworkBinder fake_network_binder; |
| 492 | server_->set_network_binder(&fake_network_binder); |
| 493 | std::unique_ptr<AsyncSocket> socket( |
| 494 | server_->CreateAsyncSocket(AF_INET, SOCK_DGRAM)); |
| 495 | EXPECT_EQ(0, socket->Bind(SocketAddress("0.0.0.0", 0))); |
| 496 | EXPECT_EQ(0, fake_network_binder.num_binds()); |
| 497 | server_->set_network_binder(nullptr); |
| 498 | } |
| 499 | |
deadbeef | c874d12 | 2017-02-13 23:41:59 | [diff] [blame] | 500 | // For a loopback interface, failures to bind to the interface should be |
| 501 | // tolerated. |
| 502 | TEST_F(PhysicalSocketTest, |
| 503 | BindSucceedsIfNetworkBinderFailsForLoopbackInterface) { |
deadbeef | 9a6f4d4 | 2017-05-16 02:43:33 | [diff] [blame] | 504 | MAYBE_SKIP_IPV4; |
deadbeef | c874d12 | 2017-02-13 23:41:59 | [diff] [blame] | 505 | FakeNetworkBinder fake_network_binder; |
| 506 | server_->set_network_binder(&fake_network_binder); |
| 507 | std::unique_ptr<AsyncSocket> socket( |
| 508 | server_->CreateAsyncSocket(AF_INET, SOCK_DGRAM)); |
| 509 | fake_network_binder.set_result(NetworkBindingResult::FAILURE); |
| 510 | EXPECT_EQ(0, socket->Bind(SocketAddress(kIPv4Loopback, 0))); |
| 511 | server_->set_network_binder(nullptr); |
| 512 | } |
| 513 | |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 | [diff] [blame] | 514 | #endif |
| 515 | |
| 516 | } // namespace rtc |