blob: 3762762f856f0dd6b0d130d8b3d8dc0e17ec6224 [file] [log] [blame]
henrike@webrtc.orgf0488722014-05-13 18:00:261/*
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 Olssona4d87372019-07-05 17:08:3311#include "rtc_base/physical_socket_server.h"
12
henrike@webrtc.orgf0488722014-05-13 18:00:2613#include <signal.h>
Jonas Olssona4d87372019-07-05 17:08:3314
Yves Gerey3e707812018-11-28 15:47:4915#include <algorithm>
Yves Gerey665174f2018-06-19 13:03:0516#include <memory>
henrike@webrtc.orgf0488722014-05-13 18:00:2617
Mirko Bonadei92ea95e2017-09-15 04:47:3118#include "rtc_base/gunit.h"
Steve Anton10542f22019-01-11 17:11:0019#include "rtc_base/ip_address.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3120#include "rtc_base/logging.h"
Mirko Bonadeie5f4c6b2021-01-15 09:41:0121#include "rtc_base/net_helpers.h"
Steve Anton10542f22019-01-11 17:11:0022#include "rtc_base/network_monitor.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3123#include "rtc_base/socket_unittest.h"
Steve Anton10542f22019-01-11 17:11:0024#include "rtc_base/test_utils.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3125#include "rtc_base/thread.h"
Yves Gerey3e707812018-11-28 15:47:4926#include "test/gtest.h"
henrike@webrtc.orgf0488722014-05-13 18:00:2627
28namespace rtc {
29
Mirko Bonadei675513b2017-11-09 10:09:2530#define MAYBE_SKIP_IPV4 \
31 if (!HasIPv4Enabled()) { \
32 RTC_LOG(LS_INFO) << "No IPv4... skipping"; \
33 return; \
deadbeef9a6f4d42017-05-16 02:43:3334 }
35
Mirko Bonadei675513b2017-11-09 10:09:2536#define MAYBE_SKIP_IPV6 \
37 if (!HasIPv6Enabled()) { \
38 RTC_LOG(LS_INFO) << "No IPv6... skipping"; \
39 return; \
Taylor Brandstetter2b3bf6b2016-05-19 21:57:3140 }
41
jbauch095ae152015-12-18 09:39:5542class PhysicalSocketTest;
43
44class FakeSocketDispatcher : public SocketDispatcher {
45 public:
46 explicit FakeSocketDispatcher(PhysicalSocketServer* ss)
Yves Gerey665174f2018-06-19 13:03:0547 : SocketDispatcher(ss) {}
jbauch095ae152015-12-18 09:39:5548
jbauchf2a2bf42016-02-04 00:45:3249 FakeSocketDispatcher(SOCKET s, PhysicalSocketServer* ss)
Yves Gerey665174f2018-06-19 13:03:0550 : SocketDispatcher(s, ss) {}
jbauchf2a2bf42016-02-04 00:45:3251
jbauch095ae152015-12-18 09:39:5552 protected:
53 SOCKET DoAccept(SOCKET socket, sockaddr* addr, socklen_t* addrlen) override;
jbauchf2a2bf42016-02-04 00:45:3254 int DoSend(SOCKET socket, const char* buf, int len, int flags) override;
Yves Gerey665174f2018-06-19 13:03:0555 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.orgf0488722014-05-13 18:00:2661};
62
jbauch095ae152015-12-18 09:39:5563class FakePhysicalSocketServer : public PhysicalSocketServer {
64 public:
Yves Gerey665174f2018-06-19 13:03:0565 explicit FakePhysicalSocketServer(PhysicalSocketTest* test) : test_(test) {}
jbauch095ae152015-12-18 09:39:5566
jbauch095ae152015-12-18 09:39:5567 AsyncSocket* CreateAsyncSocket(int family, int type) override {
68 SocketDispatcher* dispatcher = new FakeSocketDispatcher(this);
jbauchf2a2bf42016-02-04 00:45:3269 if (!dispatcher->Create(family, type)) {
jbauch095ae152015-12-18 09:39:5570 delete dispatcher;
71 return nullptr;
72 }
jbauchf2a2bf42016-02-04 00:45:3273 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;
jbauch095ae152015-12-18 09:39:5583 }
84
85 PhysicalSocketTest* GetTest() const { return test_; }
86
87 private:
88 PhysicalSocketTest* test_;
89};
90
deadbeefc874d122017-02-13 23:41:5991class FakeNetworkBinder : public NetworkBinderInterface {
92 public:
93 NetworkBindingResult BindSocketToNetwork(int, const IPAddress&) override {
deadbeef9ffa13f2017-02-22 00:18:0094 ++num_binds_;
deadbeefc874d122017-02-13 23:41:5995 return result_;
96 }
97
98 void set_result(NetworkBindingResult result) { result_ = result; }
99
deadbeef9ffa13f2017-02-22 00:18:00100 int num_binds() { return num_binds_; }
101
deadbeefc874d122017-02-13 23:41:59102 private:
103 NetworkBindingResult result_ = NetworkBindingResult::SUCCESS;
deadbeef9ffa13f2017-02-22 00:18:00104 int num_binds_ = 0;
deadbeefc874d122017-02-13 23:41:59105};
106
jbauch095ae152015-12-18 09:39:55107class 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
jbauchf2a2bf42016-02-04 00:45:32113 // 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
jbauch095ae152015-12-18 09:39:55117 protected:
118 PhysicalSocketTest()
Yves Gerey665174f2018-06-19 13:03:05119 : server_(new FakePhysicalSocketServer(this)),
120 thread_(server_.get()),
121 fail_accept_(false),
122 max_send_size_(-1) {}
jbauch095ae152015-12-18 09:39:55123
124 void ConnectInternalAcceptError(const IPAddress& loopback);
jbauchf2a2bf42016-02-04 00:45:32125 void WritableAfterPartialWrite(const IPAddress& loopback);
jbauch095ae152015-12-18 09:39:55126
jbauch555604a2016-04-26 10:13:22127 std::unique_ptr<FakePhysicalSocketServer> server_;
nisse7eaa4ea2017-05-08 12:25:41128 rtc::AutoSocketServerThread thread_;
jbauch095ae152015-12-18 09:39:55129 bool fail_accept_;
jbauchf2a2bf42016-02-04 00:45:32130 int max_send_size_;
jbauch095ae152015-12-18 09:39:55131};
132
133SOCKET 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 Gerey665174f2018-06-19 13:03:05145int FakeSocketDispatcher::DoSend(SOCKET socket,
146 const char* buf,
147 int len,
148 int flags) {
jbauchf2a2bf42016-02-04 00:45:32149 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 Gerey665174f2018-06-19 13:03:05158int FakeSocketDispatcher::DoSendTo(SOCKET socket,
159 const char* buf,
160 int len,
161 int flags,
162 const struct sockaddr* dest_addr,
163 socklen_t addrlen) {
jbauchf2a2bf42016-02-04 00:45:32164 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 Gerey665174f2018-06-19 13:03:05171 addrlen);
jbauchf2a2bf42016-02-04 00:45:32172}
173
henrike@webrtc.orgf0488722014-05-13 18:00:26174TEST_F(PhysicalSocketTest, TestConnectIPv4) {
deadbeef9a6f4d42017-05-16 02:43:33175 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26176 SocketTest::TestConnectIPv4();
177}
178
Taylor Brandstetter2b3bf6b2016-05-19 21:57:31179TEST_F(PhysicalSocketTest, TestConnectIPv6) {
henrike@webrtc.orgf0488722014-05-13 18:00:26180 SocketTest::TestConnectIPv6();
181}
182
183TEST_F(PhysicalSocketTest, TestConnectWithDnsLookupIPv4) {
deadbeef9a6f4d42017-05-16 02:43:33184 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26185 SocketTest::TestConnectWithDnsLookupIPv4();
186}
187
188TEST_F(PhysicalSocketTest, TestConnectWithDnsLookupIPv6) {
189 SocketTest::TestConnectWithDnsLookupIPv6();
190}
191
192TEST_F(PhysicalSocketTest, TestConnectFailIPv4) {
deadbeef9a6f4d42017-05-16 02:43:33193 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26194 SocketTest::TestConnectFailIPv4();
195}
196
jbauch095ae152015-12-18 09:39:55197void PhysicalSocketTest::ConnectInternalAcceptError(const IPAddress& loopback) {
kwibergd0d81482017-04-18 10:18:22198 webrtc::testing::StreamSink sink;
jbauch095ae152015-12-18 09:39:55199 SocketAddress accept_addr;
200
201 // Create two clients.
jbauch555604a2016-04-26 10:13:22202 std::unique_ptr<AsyncSocket> client1(
203 server_->CreateAsyncSocket(loopback.family(), SOCK_STREAM));
jbauch095ae152015-12-18 09:39:55204 sink.Monitor(client1.get());
205 EXPECT_EQ(AsyncSocket::CS_CLOSED, client1->GetState());
Jonas Olssonabbe8412018-04-03 11:40:05206 EXPECT_TRUE(IsUnspecOrEmptyIP(client1->GetLocalAddress().ipaddr()));
jbauch095ae152015-12-18 09:39:55207
jbauch555604a2016-04-26 10:13:22208 std::unique_ptr<AsyncSocket> client2(
209 server_->CreateAsyncSocket(loopback.family(), SOCK_STREAM));
jbauch095ae152015-12-18 09:39:55210 sink.Monitor(client2.get());
211 EXPECT_EQ(AsyncSocket::CS_CLOSED, client2->GetState());
Jonas Olssonabbe8412018-04-03 11:40:05212 EXPECT_TRUE(IsUnspecOrEmptyIP(client2->GetLocalAddress().ipaddr()));
jbauch095ae152015-12-18 09:39:55213
214 // Create server and listen.
jbauch555604a2016-04-26 10:13:22215 std::unique_ptr<AsyncSocket> server(
jbauch095ae152015-12-18 09:39:55216 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.
kwibergd0d81482017-04-18 10:18:22223 EXPECT_FALSE(sink.Check(server.get(), webrtc::testing::SSE_READ));
jbauch095ae152015-12-18 09:39:55224 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());
kwibergd0d81482017-04-18 10:18:22234 EXPECT_FALSE(sink.Check(client1.get(), webrtc::testing::SSE_OPEN));
235 EXPECT_FALSE(sink.Check(client1.get(), webrtc::testing::SSE_CLOSE));
jbauch095ae152015-12-18 09:39:55236
237 // Server has pending connection, try to accept it (will fail).
kwibergd0d81482017-04-18 10:18:22238 EXPECT_TRUE_WAIT((sink.Check(server.get(), webrtc::testing::SSE_READ)),
239 kTimeout);
jbauch095ae152015-12-18 09:39:55240 // Simulate "::accept" returning an error.
241 SetFailAccept(true);
jbauch555604a2016-04-26 10:13:22242 std::unique_ptr<AsyncSocket> accepted(server->Accept(&accept_addr));
jbauch095ae152015-12-18 09:39:55243 EXPECT_FALSE(accepted);
244 ASSERT_TRUE(accept_addr.IsNil());
245
246 // Ensure no more pending server connections.
kwibergd0d81482017-04-18 10:18:22247 EXPECT_FALSE(sink.Check(server.get(), webrtc::testing::SSE_READ));
jbauch095ae152015-12-18 09:39:55248 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());
kwibergd0d81482017-04-18 10:18:22258 EXPECT_FALSE(sink.Check(client2.get(), webrtc::testing::SSE_OPEN));
259 EXPECT_FALSE(sink.Check(client2.get(), webrtc::testing::SSE_CLOSE));
jbauch095ae152015-12-18 09:39:55260
261 // Server has pending connection, try to accept it (will succeed).
kwibergd0d81482017-04-18 10:18:22262 EXPECT_TRUE_WAIT((sink.Check(server.get(), webrtc::testing::SSE_READ)),
263 kTimeout);
jbauch095ae152015-12-18 09:39:55264 SetFailAccept(false);
jbauch555604a2016-04-26 10:13:22265 std::unique_ptr<AsyncSocket> accepted2(server->Accept(&accept_addr));
jbauch095ae152015-12-18 09:39:55266 ASSERT_TRUE(accepted2);
267 EXPECT_FALSE(accept_addr.IsNil());
268 EXPECT_EQ(accepted2->GetRemoteAddress(), accept_addr);
269}
270
271TEST_F(PhysicalSocketTest, TestConnectAcceptErrorIPv4) {
deadbeef9a6f4d42017-05-16 02:43:33272 MAYBE_SKIP_IPV4;
jbauch095ae152015-12-18 09:39:55273 ConnectInternalAcceptError(kIPv4Loopback);
274}
275
Taylor Brandstetter2b3bf6b2016-05-19 21:57:31276TEST_F(PhysicalSocketTest, TestConnectAcceptErrorIPv6) {
277 MAYBE_SKIP_IPV6;
jbauch095ae152015-12-18 09:39:55278 ConnectInternalAcceptError(kIPv6Loopback);
279}
280
jbauchf2a2bf42016-02-04 00:45:32281void 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
danilchapb7b9dca2016-08-05 12:55:43292// https://bugs.chromium.org/p/webrtc/issues/detail?id=6167
293#if defined(WEBRTC_WIN)
Yves Gerey665174f2018-06-19 13:03:05294#define MAYBE_TestWritableAfterPartialWriteIPv4 \
295 DISABLED_TestWritableAfterPartialWriteIPv4
danilchapb7b9dca2016-08-05 12:55:43296#else
Yves Gerey665174f2018-06-19 13:03:05297#define MAYBE_TestWritableAfterPartialWriteIPv4 \
298 TestWritableAfterPartialWriteIPv4
danilchapb7b9dca2016-08-05 12:55:43299#endif
300TEST_F(PhysicalSocketTest, MAYBE_TestWritableAfterPartialWriteIPv4) {
deadbeef9a6f4d42017-05-16 02:43:33301 MAYBE_SKIP_IPV4;
jbauchf2a2bf42016-02-04 00:45:32302 WritableAfterPartialWrite(kIPv4Loopback);
303}
304
danilchapb7b9dca2016-08-05 12:55:43305// https://bugs.chromium.org/p/webrtc/issues/detail?id=6167
306#if defined(WEBRTC_WIN)
Yves Gerey665174f2018-06-19 13:03:05307#define MAYBE_TestWritableAfterPartialWriteIPv6 \
308 DISABLED_TestWritableAfterPartialWriteIPv6
danilchapb7b9dca2016-08-05 12:55:43309#else
Yves Gerey665174f2018-06-19 13:03:05310#define MAYBE_TestWritableAfterPartialWriteIPv6 \
311 TestWritableAfterPartialWriteIPv6
danilchapb7b9dca2016-08-05 12:55:43312#endif
313TEST_F(PhysicalSocketTest, MAYBE_TestWritableAfterPartialWriteIPv6) {
Taylor Brandstetter2b3bf6b2016-05-19 21:57:31314 MAYBE_SKIP_IPV6;
jbauchf2a2bf42016-02-04 00:45:32315 WritableAfterPartialWrite(kIPv6Loopback);
316}
317
Taylor Brandstetter2b3bf6b2016-05-19 21:57:31318TEST_F(PhysicalSocketTest, TestConnectFailIPv6) {
henrike@webrtc.orgf0488722014-05-13 18:00:26319 SocketTest::TestConnectFailIPv6();
320}
321
322TEST_F(PhysicalSocketTest, TestConnectWithDnsLookupFailIPv4) {
deadbeef9a6f4d42017-05-16 02:43:33323 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26324 SocketTest::TestConnectWithDnsLookupFailIPv4();
325}
326
Taylor Brandstetter2b3bf6b2016-05-19 21:57:31327TEST_F(PhysicalSocketTest, TestConnectWithDnsLookupFailIPv6) {
henrike@webrtc.orgf0488722014-05-13 18:00:26328 SocketTest::TestConnectWithDnsLookupFailIPv6();
329}
330
henrike@webrtc.orgf0488722014-05-13 18:00:26331TEST_F(PhysicalSocketTest, TestConnectWithClosedSocketIPv4) {
deadbeef9a6f4d42017-05-16 02:43:33332 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26333 SocketTest::TestConnectWithClosedSocketIPv4();
334}
335
Taylor Brandstetter2b3bf6b2016-05-19 21:57:31336TEST_F(PhysicalSocketTest, TestConnectWithClosedSocketIPv6) {
henrike@webrtc.orgf0488722014-05-13 18:00:26337 SocketTest::TestConnectWithClosedSocketIPv6();
338}
339
340TEST_F(PhysicalSocketTest, TestConnectWhileNotClosedIPv4) {
deadbeef9a6f4d42017-05-16 02:43:33341 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26342 SocketTest::TestConnectWhileNotClosedIPv4();
343}
344
Taylor Brandstetter2b3bf6b2016-05-19 21:57:31345TEST_F(PhysicalSocketTest, TestConnectWhileNotClosedIPv6) {
henrike@webrtc.orgf0488722014-05-13 18:00:26346 SocketTest::TestConnectWhileNotClosedIPv6();
347}
348
349TEST_F(PhysicalSocketTest, TestServerCloseDuringConnectIPv4) {
deadbeef9a6f4d42017-05-16 02:43:33350 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26351 SocketTest::TestServerCloseDuringConnectIPv4();
352}
353
Taylor Brandstetter2b3bf6b2016-05-19 21:57:31354TEST_F(PhysicalSocketTest, TestServerCloseDuringConnectIPv6) {
henrike@webrtc.orgf0488722014-05-13 18:00:26355 SocketTest::TestServerCloseDuringConnectIPv6();
356}
357
358TEST_F(PhysicalSocketTest, TestClientCloseDuringConnectIPv4) {
deadbeef9a6f4d42017-05-16 02:43:33359 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26360 SocketTest::TestClientCloseDuringConnectIPv4();
361}
362
Taylor Brandstetter2b3bf6b2016-05-19 21:57:31363TEST_F(PhysicalSocketTest, TestClientCloseDuringConnectIPv6) {
henrike@webrtc.orgf0488722014-05-13 18:00:26364 SocketTest::TestClientCloseDuringConnectIPv6();
365}
366
367TEST_F(PhysicalSocketTest, TestServerCloseIPv4) {
deadbeef9a6f4d42017-05-16 02:43:33368 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26369 SocketTest::TestServerCloseIPv4();
370}
371
Taylor Brandstetter2b3bf6b2016-05-19 21:57:31372TEST_F(PhysicalSocketTest, TestServerCloseIPv6) {
henrike@webrtc.orgf0488722014-05-13 18:00:26373 SocketTest::TestServerCloseIPv6();
374}
375
376TEST_F(PhysicalSocketTest, TestCloseInClosedCallbackIPv4) {
deadbeef9a6f4d42017-05-16 02:43:33377 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26378 SocketTest::TestCloseInClosedCallbackIPv4();
379}
380
Taylor Brandstetter2b3bf6b2016-05-19 21:57:31381TEST_F(PhysicalSocketTest, TestCloseInClosedCallbackIPv6) {
henrike@webrtc.orgf0488722014-05-13 18:00:26382 SocketTest::TestCloseInClosedCallbackIPv6();
383}
384
Taylor Brandstetter7b69a442020-08-20 23:43:13385TEST_F(PhysicalSocketTest, TestDeleteInReadCallbackIPv4) {
386 MAYBE_SKIP_IPV4;
387 SocketTest::TestDeleteInReadCallbackIPv4();
388}
389
390TEST_F(PhysicalSocketTest, TestDeleteInReadCallbackIPv6) {
391 SocketTest::TestDeleteInReadCallbackIPv6();
392}
393
henrike@webrtc.orgc732a3e2014-10-09 22:08:15394TEST_F(PhysicalSocketTest, TestSocketServerWaitIPv4) {
deadbeef9a6f4d42017-05-16 02:43:33395 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26396 SocketTest::TestSocketServerWaitIPv4();
397}
398
Taylor Brandstetter2b3bf6b2016-05-19 21:57:31399TEST_F(PhysicalSocketTest, TestSocketServerWaitIPv6) {
henrike@webrtc.orgf0488722014-05-13 18:00:26400 SocketTest::TestSocketServerWaitIPv6();
401}
402
403TEST_F(PhysicalSocketTest, TestTcpIPv4) {
deadbeef9a6f4d42017-05-16 02:43:33404 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26405 SocketTest::TestTcpIPv4();
406}
407
Taylor Brandstetter2b3bf6b2016-05-19 21:57:31408TEST_F(PhysicalSocketTest, TestTcpIPv6) {
henrike@webrtc.orgf0488722014-05-13 18:00:26409 SocketTest::TestTcpIPv6();
410}
411
412TEST_F(PhysicalSocketTest, TestUdpIPv4) {
deadbeef9a6f4d42017-05-16 02:43:33413 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26414 SocketTest::TestUdpIPv4();
415}
416
Taylor Brandstetter2b3bf6b2016-05-19 21:57:31417TEST_F(PhysicalSocketTest, TestUdpIPv6) {
henrike@webrtc.orgf0488722014-05-13 18:00:26418 SocketTest::TestUdpIPv6();
419}
420
henrike@webrtc.org6f833c32014-06-27 16:21:49421// Disable for TSan v2, see
422// https://code.google.com/p/webrtc/issues/detail?id=3498 for details.
deadbeefc97be6a2015-09-25 18:00:38423// 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.
minyuedf200d12015-10-17 20:10:46426// Also disable for ASan.
Henrik Kjellander0be3e042015-10-30 20:21:03427// Disabled on Android: https://code.google.com/p/webrtc/issues/detail?id=4364
ivocf399f212015-11-19 14:44:32428// Disabled on Linux: https://bugs.chromium.org/p/webrtc/issues/detail?id=5233
minyuedf200d12015-10-17 20:10:46429#if defined(THREAD_SANITIZER) || defined(MEMORY_SANITIZER) || \
ivocf399f212015-11-19 14:44:32430 defined(ADDRESS_SANITIZER) || defined(WEBRTC_ANDROID) || \
431 defined(WEBRTC_LINUX)
minyuedf200d12015-10-17 20:10:46432#define MAYBE_TestUdpReadyToSendIPv4 DISABLED_TestUdpReadyToSendIPv4
433#else
434#define MAYBE_TestUdpReadyToSendIPv4 TestUdpReadyToSendIPv4
435#endif
436TEST_F(PhysicalSocketTest, MAYBE_TestUdpReadyToSendIPv4) {
deadbeef9a6f4d42017-05-16 02:43:33437 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26438 SocketTest::TestUdpReadyToSendIPv4();
439}
440
danilchapb7b9dca2016-08-05 12:55:43441// 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
447TEST_F(PhysicalSocketTest, MAYBE_TestUdpReadyToSendIPv6) {
henrike@webrtc.orgf0488722014-05-13 18:00:26448 SocketTest::TestUdpReadyToSendIPv6();
449}
450
451TEST_F(PhysicalSocketTest, TestGetSetOptionsIPv4) {
deadbeef9a6f4d42017-05-16 02:43:33452 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26453 SocketTest::TestGetSetOptionsIPv4();
454}
455
456TEST_F(PhysicalSocketTest, TestGetSetOptionsIPv6) {
457 SocketTest::TestGetSetOptionsIPv6();
458}
459
460#if defined(WEBRTC_POSIX)
461
Taylor Brandstetter6f825352016-08-11 22:38:28462// We don't get recv timestamps on Mac.
Stefan Holmer9131efd2016-05-23 16:19:26463#if !defined(WEBRTC_MAC)
464TEST_F(PhysicalSocketTest, TestSocketRecvTimestampIPv4) {
deadbeef9a6f4d42017-05-16 02:43:33465 MAYBE_SKIP_IPV4;
Taylor Brandstetter6f825352016-08-11 22:38:28466 SocketTest::TestSocketRecvTimestampIPv4();
Stefan Holmer9131efd2016-05-23 16:19:26467}
468
Taylor Brandstetter6f825352016-08-11 22:38:28469TEST_F(PhysicalSocketTest, TestSocketRecvTimestampIPv6) {
470 SocketTest::TestSocketRecvTimestampIPv6();
Stefan Holmer9131efd2016-05-23 16:19:26471}
472#endif
473
deadbeefc874d122017-02-13 23:41:59474// Verify that if the socket was unable to be bound to a real network interface
475// (not loopback), Bind will return an error.
476TEST_F(PhysicalSocketTest,
477 BindFailsIfNetworkBinderFailsForNonLoopbackInterface) {
deadbeef9a6f4d42017-05-16 02:43:33478 MAYBE_SKIP_IPV4;
deadbeefc874d122017-02-13 23:41:59479 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
deadbeef9ffa13f2017-02-22 00:18:00488// Network binder shouldn't be used if the socket is bound to the "any" IP.
Yves Gerey665174f2018-06-19 13:03:05489TEST_F(PhysicalSocketTest, NetworkBinderIsNotUsedForAnyIp) {
deadbeef9a6f4d42017-05-16 02:43:33490 MAYBE_SKIP_IPV4;
deadbeef9ffa13f2017-02-22 00:18:00491 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
deadbeefc874d122017-02-13 23:41:59500// For a loopback interface, failures to bind to the interface should be
501// tolerated.
502TEST_F(PhysicalSocketTest,
503 BindSucceedsIfNetworkBinderFailsForLoopbackInterface) {
deadbeef9a6f4d42017-05-16 02:43:33504 MAYBE_SKIP_IPV4;
deadbeefc874d122017-02-13 23:41:59505 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.orgf0488722014-05-13 18:00:26514#endif
515
516} // namespace rtc