blob: 3762762f856f0dd6b0d130d8b3d8dc0e17ec6224 [file] [log] [blame]
henrike@webrtc.orgf0488722014-05-13 18:00:26 +00001/*
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 19:08:33 +020011#include "rtc_base/physical_socket_server.h"
12
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000013#include <signal.h>
Jonas Olssona4d87372019-07-05 19:08:33 +020014
Yves Gerey3e707812018-11-28 16:47:49 +010015#include <algorithm>
Yves Gerey665174f2018-06-19 15:03:05 +020016#include <memory>
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000017
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020018#include "rtc_base/gunit.h"
Steve Anton10542f22019-01-11 09:11:00 -080019#include "rtc_base/ip_address.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020020#include "rtc_base/logging.h"
Mirko Bonadeie5f4c6b2021-01-15 10:41:01 +010021#include "rtc_base/net_helpers.h"
Steve Anton10542f22019-01-11 09:11:00 -080022#include "rtc_base/network_monitor.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020023#include "rtc_base/socket_unittest.h"
Steve Anton10542f22019-01-11 09:11:00 -080024#include "rtc_base/test_utils.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020025#include "rtc_base/thread.h"
Yves Gerey3e707812018-11-28 16:47:49 +010026#include "test/gtest.h"
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000027
28namespace rtc {
29
Mirko Bonadei675513b2017-11-09 11:09:25 +010030#define MAYBE_SKIP_IPV4 \
31 if (!HasIPv4Enabled()) { \
32 RTC_LOG(LS_INFO) << "No IPv4... skipping"; \
33 return; \
deadbeef9a6f4d42017-05-15 19:43:33 -070034 }
35
Mirko Bonadei675513b2017-11-09 11:09:25 +010036#define MAYBE_SKIP_IPV6 \
37 if (!HasIPv6Enabled()) { \
38 RTC_LOG(LS_INFO) << "No IPv6... skipping"; \
39 return; \
Taylor Brandstetter2b3bf6b2016-05-19 14:57:31 -070040 }
41
jbauch095ae152015-12-18 01:39:55 -080042class PhysicalSocketTest;
43
44class FakeSocketDispatcher : public SocketDispatcher {
45 public:
46 explicit FakeSocketDispatcher(PhysicalSocketServer* ss)
Yves Gerey665174f2018-06-19 15:03:05 +020047 : SocketDispatcher(ss) {}
jbauch095ae152015-12-18 01:39:55 -080048
jbauchf2a2bf42016-02-03 16:45:32 -080049 FakeSocketDispatcher(SOCKET s, PhysicalSocketServer* ss)
Yves Gerey665174f2018-06-19 15:03:05 +020050 : SocketDispatcher(s, ss) {}
jbauchf2a2bf42016-02-03 16:45:32 -080051
jbauch095ae152015-12-18 01:39:55 -080052 protected:
53 SOCKET DoAccept(SOCKET socket, sockaddr* addr, socklen_t* addrlen) override;
jbauchf2a2bf42016-02-03 16:45:32 -080054 int DoSend(SOCKET socket, const char* buf, int len, int flags) override;
Yves Gerey665174f2018-06-19 15:03:05 +020055 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:26 +000061};
62
jbauch095ae152015-12-18 01:39:55 -080063class FakePhysicalSocketServer : public PhysicalSocketServer {
64 public:
Yves Gerey665174f2018-06-19 15:03:05 +020065 explicit FakePhysicalSocketServer(PhysicalSocketTest* test) : test_(test) {}
jbauch095ae152015-12-18 01:39:55 -080066
jbauch095ae152015-12-18 01:39:55 -080067 AsyncSocket* CreateAsyncSocket(int family, int type) override {
68 SocketDispatcher* dispatcher = new FakeSocketDispatcher(this);
jbauchf2a2bf42016-02-03 16:45:32 -080069 if (!dispatcher->Create(family, type)) {
jbauch095ae152015-12-18 01:39:55 -080070 delete dispatcher;
71 return nullptr;
72 }
jbauchf2a2bf42016-02-03 16:45:32 -080073 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 01:39:55 -080083 }
84
85 PhysicalSocketTest* GetTest() const { return test_; }
86
87 private:
88 PhysicalSocketTest* test_;
89};
90
deadbeefc874d122017-02-13 15:41:59 -080091class FakeNetworkBinder : public NetworkBinderInterface {
92 public:
93 NetworkBindingResult BindSocketToNetwork(int, const IPAddress&) override {
deadbeef9ffa13f2017-02-21 16:18:00 -080094 ++num_binds_;
deadbeefc874d122017-02-13 15:41:59 -080095 return result_;
96 }
97
98 void set_result(NetworkBindingResult result) { result_ = result; }
99
deadbeef9ffa13f2017-02-21 16:18:00 -0800100 int num_binds() { return num_binds_; }
101
deadbeefc874d122017-02-13 15:41:59 -0800102 private:
103 NetworkBindingResult result_ = NetworkBindingResult::SUCCESS;
deadbeef9ffa13f2017-02-21 16:18:00 -0800104 int num_binds_ = 0;
deadbeefc874d122017-02-13 15:41:59 -0800105};
106
jbauch095ae152015-12-18 01:39:55 -0800107class 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-03 16:45:32 -0800113 // 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 01:39:55 -0800117 protected:
118 PhysicalSocketTest()
Yves Gerey665174f2018-06-19 15:03:05 +0200119 : server_(new FakePhysicalSocketServer(this)),
120 thread_(server_.get()),
121 fail_accept_(false),
122 max_send_size_(-1) {}
jbauch095ae152015-12-18 01:39:55 -0800123
124 void ConnectInternalAcceptError(const IPAddress& loopback);
jbauchf2a2bf42016-02-03 16:45:32 -0800125 void WritableAfterPartialWrite(const IPAddress& loopback);
jbauch095ae152015-12-18 01:39:55 -0800126
jbauch555604a2016-04-26 03:13:22 -0700127 std::unique_ptr<FakePhysicalSocketServer> server_;
nisse7eaa4ea2017-05-08 05:25:41 -0700128 rtc::AutoSocketServerThread thread_;
jbauch095ae152015-12-18 01:39:55 -0800129 bool fail_accept_;
jbauchf2a2bf42016-02-03 16:45:32 -0800130 int max_send_size_;
jbauch095ae152015-12-18 01:39:55 -0800131};
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 15:03:05 +0200145int FakeSocketDispatcher::DoSend(SOCKET socket,
146 const char* buf,
147 int len,
148 int flags) {
jbauchf2a2bf42016-02-03 16:45:32 -0800149 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 15:03:05 +0200158int 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-03 16:45:32 -0800164 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 15:03:05 +0200171 addrlen);
jbauchf2a2bf42016-02-03 16:45:32 -0800172}
173
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000174TEST_F(PhysicalSocketTest, TestConnectIPv4) {
deadbeef9a6f4d42017-05-15 19:43:33 -0700175 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000176 SocketTest::TestConnectIPv4();
177}
178
Taylor Brandstetter2b3bf6b2016-05-19 14:57:31 -0700179TEST_F(PhysicalSocketTest, TestConnectIPv6) {
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000180 SocketTest::TestConnectIPv6();
181}
182
183TEST_F(PhysicalSocketTest, TestConnectWithDnsLookupIPv4) {
deadbeef9a6f4d42017-05-15 19:43:33 -0700184 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000185 SocketTest::TestConnectWithDnsLookupIPv4();
186}
187
188TEST_F(PhysicalSocketTest, TestConnectWithDnsLookupIPv6) {
189 SocketTest::TestConnectWithDnsLookupIPv6();
190}
191
192TEST_F(PhysicalSocketTest, TestConnectFailIPv4) {
deadbeef9a6f4d42017-05-15 19:43:33 -0700193 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000194 SocketTest::TestConnectFailIPv4();
195}
196
jbauch095ae152015-12-18 01:39:55 -0800197void PhysicalSocketTest::ConnectInternalAcceptError(const IPAddress& loopback) {
kwibergd0d81482017-04-18 03:18:22 -0700198 webrtc::testing::StreamSink sink;
jbauch095ae152015-12-18 01:39:55 -0800199 SocketAddress accept_addr;
200
201 // Create two clients.
jbauch555604a2016-04-26 03:13:22 -0700202 std::unique_ptr<AsyncSocket> client1(
203 server_->CreateAsyncSocket(loopback.family(), SOCK_STREAM));
jbauch095ae152015-12-18 01:39:55 -0800204 sink.Monitor(client1.get());
205 EXPECT_EQ(AsyncSocket::CS_CLOSED, client1->GetState());
Jonas Olssonabbe8412018-04-03 13:40:05 +0200206 EXPECT_TRUE(IsUnspecOrEmptyIP(client1->GetLocalAddress().ipaddr()));
jbauch095ae152015-12-18 01:39:55 -0800207
jbauch555604a2016-04-26 03:13:22 -0700208 std::unique_ptr<AsyncSocket> client2(
209 server_->CreateAsyncSocket(loopback.family(), SOCK_STREAM));
jbauch095ae152015-12-18 01:39:55 -0800210 sink.Monitor(client2.get());
211 EXPECT_EQ(AsyncSocket::CS_CLOSED, client2->GetState());
Jonas Olssonabbe8412018-04-03 13:40:05 +0200212 EXPECT_TRUE(IsUnspecOrEmptyIP(client2->GetLocalAddress().ipaddr()));
jbauch095ae152015-12-18 01:39:55 -0800213
214 // Create server and listen.
jbauch555604a2016-04-26 03:13:22 -0700215 std::unique_ptr<AsyncSocket> server(
jbauch095ae152015-12-18 01:39:55 -0800216 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 03:18:22 -0700223 EXPECT_FALSE(sink.Check(server.get(), webrtc::testing::SSE_READ));
jbauch095ae152015-12-18 01:39:55 -0800224 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 03:18:22 -0700234 EXPECT_FALSE(sink.Check(client1.get(), webrtc::testing::SSE_OPEN));
235 EXPECT_FALSE(sink.Check(client1.get(), webrtc::testing::SSE_CLOSE));
jbauch095ae152015-12-18 01:39:55 -0800236
237 // Server has pending connection, try to accept it (will fail).
kwibergd0d81482017-04-18 03:18:22 -0700238 EXPECT_TRUE_WAIT((sink.Check(server.get(), webrtc::testing::SSE_READ)),
239 kTimeout);
jbauch095ae152015-12-18 01:39:55 -0800240 // Simulate "::accept" returning an error.
241 SetFailAccept(true);
jbauch555604a2016-04-26 03:13:22 -0700242 std::unique_ptr<AsyncSocket> accepted(server->Accept(&accept_addr));
jbauch095ae152015-12-18 01:39:55 -0800243 EXPECT_FALSE(accepted);
244 ASSERT_TRUE(accept_addr.IsNil());
245
246 // Ensure no more pending server connections.
kwibergd0d81482017-04-18 03:18:22 -0700247 EXPECT_FALSE(sink.Check(server.get(), webrtc::testing::SSE_READ));
jbauch095ae152015-12-18 01:39:55 -0800248 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 03:18:22 -0700258 EXPECT_FALSE(sink.Check(client2.get(), webrtc::testing::SSE_OPEN));
259 EXPECT_FALSE(sink.Check(client2.get(), webrtc::testing::SSE_CLOSE));
jbauch095ae152015-12-18 01:39:55 -0800260
261 // Server has pending connection, try to accept it (will succeed).
kwibergd0d81482017-04-18 03:18:22 -0700262 EXPECT_TRUE_WAIT((sink.Check(server.get(), webrtc::testing::SSE_READ)),
263 kTimeout);
jbauch095ae152015-12-18 01:39:55 -0800264 SetFailAccept(false);
jbauch555604a2016-04-26 03:13:22 -0700265 std::unique_ptr<AsyncSocket> accepted2(server->Accept(&accept_addr));
jbauch095ae152015-12-18 01:39:55 -0800266 ASSERT_TRUE(accepted2);
267 EXPECT_FALSE(accept_addr.IsNil());
268 EXPECT_EQ(accepted2->GetRemoteAddress(), accept_addr);
269}
270
271TEST_F(PhysicalSocketTest, TestConnectAcceptErrorIPv4) {
deadbeef9a6f4d42017-05-15 19:43:33 -0700272 MAYBE_SKIP_IPV4;
jbauch095ae152015-12-18 01:39:55 -0800273 ConnectInternalAcceptError(kIPv4Loopback);
274}
275
Taylor Brandstetter2b3bf6b2016-05-19 14:57:31 -0700276TEST_F(PhysicalSocketTest, TestConnectAcceptErrorIPv6) {
277 MAYBE_SKIP_IPV6;
jbauch095ae152015-12-18 01:39:55 -0800278 ConnectInternalAcceptError(kIPv6Loopback);
279}
280
jbauchf2a2bf42016-02-03 16:45:32 -0800281void 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 05:55:43 -0700292// https://bugs.chromium.org/p/webrtc/issues/detail?id=6167
293#if defined(WEBRTC_WIN)
Yves Gerey665174f2018-06-19 15:03:05 +0200294#define MAYBE_TestWritableAfterPartialWriteIPv4 \
295 DISABLED_TestWritableAfterPartialWriteIPv4
danilchapb7b9dca2016-08-05 05:55:43 -0700296#else
Yves Gerey665174f2018-06-19 15:03:05 +0200297#define MAYBE_TestWritableAfterPartialWriteIPv4 \
298 TestWritableAfterPartialWriteIPv4
danilchapb7b9dca2016-08-05 05:55:43 -0700299#endif
300TEST_F(PhysicalSocketTest, MAYBE_TestWritableAfterPartialWriteIPv4) {
deadbeef9a6f4d42017-05-15 19:43:33 -0700301 MAYBE_SKIP_IPV4;
jbauchf2a2bf42016-02-03 16:45:32 -0800302 WritableAfterPartialWrite(kIPv4Loopback);
303}
304
danilchapb7b9dca2016-08-05 05:55:43 -0700305// https://bugs.chromium.org/p/webrtc/issues/detail?id=6167
306#if defined(WEBRTC_WIN)
Yves Gerey665174f2018-06-19 15:03:05 +0200307#define MAYBE_TestWritableAfterPartialWriteIPv6 \
308 DISABLED_TestWritableAfterPartialWriteIPv6
danilchapb7b9dca2016-08-05 05:55:43 -0700309#else
Yves Gerey665174f2018-06-19 15:03:05 +0200310#define MAYBE_TestWritableAfterPartialWriteIPv6 \
311 TestWritableAfterPartialWriteIPv6
danilchapb7b9dca2016-08-05 05:55:43 -0700312#endif
313TEST_F(PhysicalSocketTest, MAYBE_TestWritableAfterPartialWriteIPv6) {
Taylor Brandstetter2b3bf6b2016-05-19 14:57:31 -0700314 MAYBE_SKIP_IPV6;
jbauchf2a2bf42016-02-03 16:45:32 -0800315 WritableAfterPartialWrite(kIPv6Loopback);
316}
317
Taylor Brandstetter2b3bf6b2016-05-19 14:57:31 -0700318TEST_F(PhysicalSocketTest, TestConnectFailIPv6) {
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000319 SocketTest::TestConnectFailIPv6();
320}
321
322TEST_F(PhysicalSocketTest, TestConnectWithDnsLookupFailIPv4) {
deadbeef9a6f4d42017-05-15 19:43:33 -0700323 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000324 SocketTest::TestConnectWithDnsLookupFailIPv4();
325}
326
Taylor Brandstetter2b3bf6b2016-05-19 14:57:31 -0700327TEST_F(PhysicalSocketTest, TestConnectWithDnsLookupFailIPv6) {
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000328 SocketTest::TestConnectWithDnsLookupFailIPv6();
329}
330
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000331TEST_F(PhysicalSocketTest, TestConnectWithClosedSocketIPv4) {
deadbeef9a6f4d42017-05-15 19:43:33 -0700332 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000333 SocketTest::TestConnectWithClosedSocketIPv4();
334}
335
Taylor Brandstetter2b3bf6b2016-05-19 14:57:31 -0700336TEST_F(PhysicalSocketTest, TestConnectWithClosedSocketIPv6) {
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000337 SocketTest::TestConnectWithClosedSocketIPv6();
338}
339
340TEST_F(PhysicalSocketTest, TestConnectWhileNotClosedIPv4) {
deadbeef9a6f4d42017-05-15 19:43:33 -0700341 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000342 SocketTest::TestConnectWhileNotClosedIPv4();
343}
344
Taylor Brandstetter2b3bf6b2016-05-19 14:57:31 -0700345TEST_F(PhysicalSocketTest, TestConnectWhileNotClosedIPv6) {
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000346 SocketTest::TestConnectWhileNotClosedIPv6();
347}
348
349TEST_F(PhysicalSocketTest, TestServerCloseDuringConnectIPv4) {
deadbeef9a6f4d42017-05-15 19:43:33 -0700350 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000351 SocketTest::TestServerCloseDuringConnectIPv4();
352}
353
Taylor Brandstetter2b3bf6b2016-05-19 14:57:31 -0700354TEST_F(PhysicalSocketTest, TestServerCloseDuringConnectIPv6) {
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000355 SocketTest::TestServerCloseDuringConnectIPv6();
356}
357
358TEST_F(PhysicalSocketTest, TestClientCloseDuringConnectIPv4) {
deadbeef9a6f4d42017-05-15 19:43:33 -0700359 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000360 SocketTest::TestClientCloseDuringConnectIPv4();
361}
362
Taylor Brandstetter2b3bf6b2016-05-19 14:57:31 -0700363TEST_F(PhysicalSocketTest, TestClientCloseDuringConnectIPv6) {
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000364 SocketTest::TestClientCloseDuringConnectIPv6();
365}
366
367TEST_F(PhysicalSocketTest, TestServerCloseIPv4) {
deadbeef9a6f4d42017-05-15 19:43:33 -0700368 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000369 SocketTest::TestServerCloseIPv4();
370}
371
Taylor Brandstetter2b3bf6b2016-05-19 14:57:31 -0700372TEST_F(PhysicalSocketTest, TestServerCloseIPv6) {
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000373 SocketTest::TestServerCloseIPv6();
374}
375
376TEST_F(PhysicalSocketTest, TestCloseInClosedCallbackIPv4) {
deadbeef9a6f4d42017-05-15 19:43:33 -0700377 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000378 SocketTest::TestCloseInClosedCallbackIPv4();
379}
380
Taylor Brandstetter2b3bf6b2016-05-19 14:57:31 -0700381TEST_F(PhysicalSocketTest, TestCloseInClosedCallbackIPv6) {
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000382 SocketTest::TestCloseInClosedCallbackIPv6();
383}
384
Taylor Brandstetter7b69a442020-08-20 23:43:13 +0000385TEST_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:15 +0000394TEST_F(PhysicalSocketTest, TestSocketServerWaitIPv4) {
deadbeef9a6f4d42017-05-15 19:43:33 -0700395 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000396 SocketTest::TestSocketServerWaitIPv4();
397}
398
Taylor Brandstetter2b3bf6b2016-05-19 14:57:31 -0700399TEST_F(PhysicalSocketTest, TestSocketServerWaitIPv6) {
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000400 SocketTest::TestSocketServerWaitIPv6();
401}
402
403TEST_F(PhysicalSocketTest, TestTcpIPv4) {
deadbeef9a6f4d42017-05-15 19:43:33 -0700404 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000405 SocketTest::TestTcpIPv4();
406}
407
Taylor Brandstetter2b3bf6b2016-05-19 14:57:31 -0700408TEST_F(PhysicalSocketTest, TestTcpIPv6) {
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000409 SocketTest::TestTcpIPv6();
410}
411
412TEST_F(PhysicalSocketTest, TestUdpIPv4) {
deadbeef9a6f4d42017-05-15 19:43:33 -0700413 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000414 SocketTest::TestUdpIPv4();
415}
416
Taylor Brandstetter2b3bf6b2016-05-19 14:57:31 -0700417TEST_F(PhysicalSocketTest, TestUdpIPv6) {
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000418 SocketTest::TestUdpIPv6();
419}
420
henrike@webrtc.org6f833c32014-06-27 16:21:49 +0000421// Disable for TSan v2, see
422// https://code.google.com/p/webrtc/issues/detail?id=3498 for details.
deadbeefc97be6a2015-09-25 11:00:38 -0700423// 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 13:10:46 -0700426// Also disable for ASan.
Henrik Kjellander0be3e042015-10-30 21:21:03 +0100427// Disabled on Android: https://code.google.com/p/webrtc/issues/detail?id=4364
ivocf399f212015-11-19 06:44:32 -0800428// Disabled on Linux: https://bugs.chromium.org/p/webrtc/issues/detail?id=5233
minyuedf200d12015-10-17 13:10:46 -0700429#if defined(THREAD_SANITIZER) || defined(MEMORY_SANITIZER) || \
ivocf399f212015-11-19 06:44:32 -0800430 defined(ADDRESS_SANITIZER) || defined(WEBRTC_ANDROID) || \
431 defined(WEBRTC_LINUX)
minyuedf200d12015-10-17 13:10:46 -0700432#define MAYBE_TestUdpReadyToSendIPv4 DISABLED_TestUdpReadyToSendIPv4
433#else
434#define MAYBE_TestUdpReadyToSendIPv4 TestUdpReadyToSendIPv4
435#endif
436TEST_F(PhysicalSocketTest, MAYBE_TestUdpReadyToSendIPv4) {
deadbeef9a6f4d42017-05-15 19:43:33 -0700437 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000438 SocketTest::TestUdpReadyToSendIPv4();
439}
440
danilchapb7b9dca2016-08-05 05:55:43 -0700441// 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:26 +0000448 SocketTest::TestUdpReadyToSendIPv6();
449}
450
451TEST_F(PhysicalSocketTest, TestGetSetOptionsIPv4) {
deadbeef9a6f4d42017-05-15 19:43:33 -0700452 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000453 SocketTest::TestGetSetOptionsIPv4();
454}
455
456TEST_F(PhysicalSocketTest, TestGetSetOptionsIPv6) {
457 SocketTest::TestGetSetOptionsIPv6();
458}
459
460#if defined(WEBRTC_POSIX)
461
Taylor Brandstetter6f825352016-08-11 15:38:28 -0700462// We don't get recv timestamps on Mac.
Stefan Holmer9131efd2016-05-23 18:19:26 +0200463#if !defined(WEBRTC_MAC)
464TEST_F(PhysicalSocketTest, TestSocketRecvTimestampIPv4) {
deadbeef9a6f4d42017-05-15 19:43:33 -0700465 MAYBE_SKIP_IPV4;
Taylor Brandstetter6f825352016-08-11 15:38:28 -0700466 SocketTest::TestSocketRecvTimestampIPv4();
Stefan Holmer9131efd2016-05-23 18:19:26 +0200467}
468
Taylor Brandstetter6f825352016-08-11 15:38:28 -0700469TEST_F(PhysicalSocketTest, TestSocketRecvTimestampIPv6) {
470 SocketTest::TestSocketRecvTimestampIPv6();
Stefan Holmer9131efd2016-05-23 18:19:26 +0200471}
472#endif
473
deadbeefc874d122017-02-13 15:41:59 -0800474// 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-15 19:43:33 -0700478 MAYBE_SKIP_IPV4;
deadbeefc874d122017-02-13 15:41:59 -0800479 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-21 16:18:00 -0800488// Network binder shouldn't be used if the socket is bound to the "any" IP.
Yves Gerey665174f2018-06-19 15:03:05 +0200489TEST_F(PhysicalSocketTest, NetworkBinderIsNotUsedForAnyIp) {
deadbeef9a6f4d42017-05-15 19:43:33 -0700490 MAYBE_SKIP_IPV4;
deadbeef9ffa13f2017-02-21 16:18:00 -0800491 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 15:41:59 -0800500// For a loopback interface, failures to bind to the interface should be
501// tolerated.
502TEST_F(PhysicalSocketTest,
503 BindSucceedsIfNetworkBinderFailsForLoopbackInterface) {
deadbeef9a6f4d42017-05-15 19:43:33 -0700504 MAYBE_SKIP_IPV4;
deadbeefc874d122017-02-13 15:41:59 -0800505 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:26 +0000514#endif
515
516} // namespace rtc