blob: 648f39701a9406b0cfeed756125b93699f0df541 [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"
Steve Anton10542f22019-01-11 09:11:00 -080021#include "rtc_base/network_monitor.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020022#include "rtc_base/socket_unittest.h"
Steve Anton10542f22019-01-11 09:11:00 -080023#include "rtc_base/test_utils.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020024#include "rtc_base/thread.h"
Yves Gerey3e707812018-11-28 16:47:49 +010025#include "test/gtest.h"
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000026
27namespace rtc {
28
Mirko Bonadei675513b2017-11-09 11:09:25 +010029#define MAYBE_SKIP_IPV4 \
30 if (!HasIPv4Enabled()) { \
31 RTC_LOG(LS_INFO) << "No IPv4... skipping"; \
32 return; \
deadbeef9a6f4d42017-05-15 19:43:33 -070033 }
34
Mirko Bonadei675513b2017-11-09 11:09:25 +010035#define MAYBE_SKIP_IPV6 \
36 if (!HasIPv6Enabled()) { \
37 RTC_LOG(LS_INFO) << "No IPv6... skipping"; \
38 return; \
Taylor Brandstetter2b3bf6b2016-05-19 14:57:31 -070039 }
40
jbauch095ae152015-12-18 01:39:55 -080041class PhysicalSocketTest;
42
43class FakeSocketDispatcher : public SocketDispatcher {
44 public:
45 explicit FakeSocketDispatcher(PhysicalSocketServer* ss)
Yves Gerey665174f2018-06-19 15:03:05 +020046 : SocketDispatcher(ss) {}
jbauch095ae152015-12-18 01:39:55 -080047
jbauchf2a2bf42016-02-03 16:45:32 -080048 FakeSocketDispatcher(SOCKET s, PhysicalSocketServer* ss)
Yves Gerey665174f2018-06-19 15:03:05 +020049 : SocketDispatcher(s, ss) {}
jbauchf2a2bf42016-02-03 16:45:32 -080050
jbauch095ae152015-12-18 01:39:55 -080051 protected:
52 SOCKET DoAccept(SOCKET socket, sockaddr* addr, socklen_t* addrlen) override;
jbauchf2a2bf42016-02-03 16:45:32 -080053 int DoSend(SOCKET socket, const char* buf, int len, int flags) override;
Yves Gerey665174f2018-06-19 15:03:05 +020054 int DoSendTo(SOCKET socket,
55 const char* buf,
56 int len,
57 int flags,
58 const struct sockaddr* dest_addr,
59 socklen_t addrlen) override;
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000060};
61
jbauch095ae152015-12-18 01:39:55 -080062class FakePhysicalSocketServer : public PhysicalSocketServer {
63 public:
Yves Gerey665174f2018-06-19 15:03:05 +020064 explicit FakePhysicalSocketServer(PhysicalSocketTest* test) : test_(test) {}
jbauch095ae152015-12-18 01:39:55 -080065
jbauch095ae152015-12-18 01:39:55 -080066 AsyncSocket* CreateAsyncSocket(int family, int type) override {
67 SocketDispatcher* dispatcher = new FakeSocketDispatcher(this);
jbauchf2a2bf42016-02-03 16:45:32 -080068 if (!dispatcher->Create(family, type)) {
jbauch095ae152015-12-18 01:39:55 -080069 delete dispatcher;
70 return nullptr;
71 }
jbauchf2a2bf42016-02-03 16:45:32 -080072 return dispatcher;
73 }
74
75 AsyncSocket* WrapSocket(SOCKET s) override {
76 SocketDispatcher* dispatcher = new FakeSocketDispatcher(s, this);
77 if (!dispatcher->Initialize()) {
78 delete dispatcher;
79 return nullptr;
80 }
81 return dispatcher;
jbauch095ae152015-12-18 01:39:55 -080082 }
83
84 PhysicalSocketTest* GetTest() const { return test_; }
85
86 private:
87 PhysicalSocketTest* test_;
88};
89
deadbeefc874d122017-02-13 15:41:59 -080090class FakeNetworkBinder : public NetworkBinderInterface {
91 public:
92 NetworkBindingResult BindSocketToNetwork(int, const IPAddress&) override {
deadbeef9ffa13f2017-02-21 16:18:00 -080093 ++num_binds_;
deadbeefc874d122017-02-13 15:41:59 -080094 return result_;
95 }
96
97 void set_result(NetworkBindingResult result) { result_ = result; }
98
deadbeef9ffa13f2017-02-21 16:18:00 -080099 int num_binds() { return num_binds_; }
100
deadbeefc874d122017-02-13 15:41:59 -0800101 private:
102 NetworkBindingResult result_ = NetworkBindingResult::SUCCESS;
deadbeef9ffa13f2017-02-21 16:18:00 -0800103 int num_binds_ = 0;
deadbeefc874d122017-02-13 15:41:59 -0800104};
105
jbauch095ae152015-12-18 01:39:55 -0800106class PhysicalSocketTest : public SocketTest {
107 public:
108 // Set flag to simluate failures when calling "::accept" on a AsyncSocket.
109 void SetFailAccept(bool fail) { fail_accept_ = fail; }
110 bool FailAccept() const { return fail_accept_; }
111
jbauchf2a2bf42016-02-03 16:45:32 -0800112 // Maximum size to ::send to a socket. Set to < 0 to disable limiting.
113 void SetMaxSendSize(int max_size) { max_send_size_ = max_size; }
114 int MaxSendSize() const { return max_send_size_; }
115
jbauch095ae152015-12-18 01:39:55 -0800116 protected:
117 PhysicalSocketTest()
Yves Gerey665174f2018-06-19 15:03:05 +0200118 : server_(new FakePhysicalSocketServer(this)),
119 thread_(server_.get()),
120 fail_accept_(false),
121 max_send_size_(-1) {}
jbauch095ae152015-12-18 01:39:55 -0800122
123 void ConnectInternalAcceptError(const IPAddress& loopback);
jbauchf2a2bf42016-02-03 16:45:32 -0800124 void WritableAfterPartialWrite(const IPAddress& loopback);
jbauch095ae152015-12-18 01:39:55 -0800125
jbauch555604a2016-04-26 03:13:22 -0700126 std::unique_ptr<FakePhysicalSocketServer> server_;
nisse7eaa4ea2017-05-08 05:25:41 -0700127 rtc::AutoSocketServerThread thread_;
jbauch095ae152015-12-18 01:39:55 -0800128 bool fail_accept_;
jbauchf2a2bf42016-02-03 16:45:32 -0800129 int max_send_size_;
jbauch095ae152015-12-18 01:39:55 -0800130};
131
132SOCKET FakeSocketDispatcher::DoAccept(SOCKET socket,
133 sockaddr* addr,
134 socklen_t* addrlen) {
135 FakePhysicalSocketServer* ss =
136 static_cast<FakePhysicalSocketServer*>(socketserver());
137 if (ss->GetTest()->FailAccept()) {
138 return INVALID_SOCKET;
139 }
140
141 return SocketDispatcher::DoAccept(socket, addr, addrlen);
142}
143
Yves Gerey665174f2018-06-19 15:03:05 +0200144int FakeSocketDispatcher::DoSend(SOCKET socket,
145 const char* buf,
146 int len,
147 int flags) {
jbauchf2a2bf42016-02-03 16:45:32 -0800148 FakePhysicalSocketServer* ss =
149 static_cast<FakePhysicalSocketServer*>(socketserver());
150 if (ss->GetTest()->MaxSendSize() >= 0) {
151 len = std::min(len, ss->GetTest()->MaxSendSize());
152 }
153
154 return SocketDispatcher::DoSend(socket, buf, len, flags);
155}
156
Yves Gerey665174f2018-06-19 15:03:05 +0200157int FakeSocketDispatcher::DoSendTo(SOCKET socket,
158 const char* buf,
159 int len,
160 int flags,
161 const struct sockaddr* dest_addr,
162 socklen_t addrlen) {
jbauchf2a2bf42016-02-03 16:45:32 -0800163 FakePhysicalSocketServer* ss =
164 static_cast<FakePhysicalSocketServer*>(socketserver());
165 if (ss->GetTest()->MaxSendSize() >= 0) {
166 len = std::min(len, ss->GetTest()->MaxSendSize());
167 }
168
169 return SocketDispatcher::DoSendTo(socket, buf, len, flags, dest_addr,
Yves Gerey665174f2018-06-19 15:03:05 +0200170 addrlen);
jbauchf2a2bf42016-02-03 16:45:32 -0800171}
172
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000173TEST_F(PhysicalSocketTest, TestConnectIPv4) {
deadbeef9a6f4d42017-05-15 19:43:33 -0700174 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000175 SocketTest::TestConnectIPv4();
176}
177
Taylor Brandstetter2b3bf6b2016-05-19 14:57:31 -0700178TEST_F(PhysicalSocketTest, TestConnectIPv6) {
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000179 SocketTest::TestConnectIPv6();
180}
181
182TEST_F(PhysicalSocketTest, TestConnectWithDnsLookupIPv4) {
deadbeef9a6f4d42017-05-15 19:43:33 -0700183 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000184 SocketTest::TestConnectWithDnsLookupIPv4();
185}
186
187TEST_F(PhysicalSocketTest, TestConnectWithDnsLookupIPv6) {
188 SocketTest::TestConnectWithDnsLookupIPv6();
189}
190
191TEST_F(PhysicalSocketTest, TestConnectFailIPv4) {
deadbeef9a6f4d42017-05-15 19:43:33 -0700192 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000193 SocketTest::TestConnectFailIPv4();
194}
195
jbauch095ae152015-12-18 01:39:55 -0800196void PhysicalSocketTest::ConnectInternalAcceptError(const IPAddress& loopback) {
kwibergd0d81482017-04-18 03:18:22 -0700197 webrtc::testing::StreamSink sink;
jbauch095ae152015-12-18 01:39:55 -0800198 SocketAddress accept_addr;
199
200 // Create two clients.
jbauch555604a2016-04-26 03:13:22 -0700201 std::unique_ptr<AsyncSocket> client1(
202 server_->CreateAsyncSocket(loopback.family(), SOCK_STREAM));
jbauch095ae152015-12-18 01:39:55 -0800203 sink.Monitor(client1.get());
204 EXPECT_EQ(AsyncSocket::CS_CLOSED, client1->GetState());
Jonas Olssonabbe8412018-04-03 13:40:05 +0200205 EXPECT_TRUE(IsUnspecOrEmptyIP(client1->GetLocalAddress().ipaddr()));
jbauch095ae152015-12-18 01:39:55 -0800206
jbauch555604a2016-04-26 03:13:22 -0700207 std::unique_ptr<AsyncSocket> client2(
208 server_->CreateAsyncSocket(loopback.family(), SOCK_STREAM));
jbauch095ae152015-12-18 01:39:55 -0800209 sink.Monitor(client2.get());
210 EXPECT_EQ(AsyncSocket::CS_CLOSED, client2->GetState());
Jonas Olssonabbe8412018-04-03 13:40:05 +0200211 EXPECT_TRUE(IsUnspecOrEmptyIP(client2->GetLocalAddress().ipaddr()));
jbauch095ae152015-12-18 01:39:55 -0800212
213 // Create server and listen.
jbauch555604a2016-04-26 03:13:22 -0700214 std::unique_ptr<AsyncSocket> server(
jbauch095ae152015-12-18 01:39:55 -0800215 server_->CreateAsyncSocket(loopback.family(), SOCK_STREAM));
216 sink.Monitor(server.get());
217 EXPECT_EQ(0, server->Bind(SocketAddress(loopback, 0)));
218 EXPECT_EQ(0, server->Listen(5));
219 EXPECT_EQ(AsyncSocket::CS_CONNECTING, server->GetState());
220
221 // Ensure no pending server connections, since we haven't done anything yet.
kwibergd0d81482017-04-18 03:18:22 -0700222 EXPECT_FALSE(sink.Check(server.get(), webrtc::testing::SSE_READ));
jbauch095ae152015-12-18 01:39:55 -0800223 EXPECT_TRUE(nullptr == server->Accept(&accept_addr));
224 EXPECT_TRUE(accept_addr.IsNil());
225
226 // Attempt first connect to listening socket.
227 EXPECT_EQ(0, client1->Connect(server->GetLocalAddress()));
228 EXPECT_FALSE(client1->GetLocalAddress().IsNil());
229 EXPECT_NE(server->GetLocalAddress(), client1->GetLocalAddress());
230
231 // Client is connecting, outcome not yet determined.
232 EXPECT_EQ(AsyncSocket::CS_CONNECTING, client1->GetState());
kwibergd0d81482017-04-18 03:18:22 -0700233 EXPECT_FALSE(sink.Check(client1.get(), webrtc::testing::SSE_OPEN));
234 EXPECT_FALSE(sink.Check(client1.get(), webrtc::testing::SSE_CLOSE));
jbauch095ae152015-12-18 01:39:55 -0800235
236 // Server has pending connection, try to accept it (will fail).
kwibergd0d81482017-04-18 03:18:22 -0700237 EXPECT_TRUE_WAIT((sink.Check(server.get(), webrtc::testing::SSE_READ)),
238 kTimeout);
jbauch095ae152015-12-18 01:39:55 -0800239 // Simulate "::accept" returning an error.
240 SetFailAccept(true);
jbauch555604a2016-04-26 03:13:22 -0700241 std::unique_ptr<AsyncSocket> accepted(server->Accept(&accept_addr));
jbauch095ae152015-12-18 01:39:55 -0800242 EXPECT_FALSE(accepted);
243 ASSERT_TRUE(accept_addr.IsNil());
244
245 // Ensure no more pending server connections.
kwibergd0d81482017-04-18 03:18:22 -0700246 EXPECT_FALSE(sink.Check(server.get(), webrtc::testing::SSE_READ));
jbauch095ae152015-12-18 01:39:55 -0800247 EXPECT_TRUE(nullptr == server->Accept(&accept_addr));
248 EXPECT_TRUE(accept_addr.IsNil());
249
250 // Attempt second connect to listening socket.
251 EXPECT_EQ(0, client2->Connect(server->GetLocalAddress()));
252 EXPECT_FALSE(client2->GetLocalAddress().IsNil());
253 EXPECT_NE(server->GetLocalAddress(), client2->GetLocalAddress());
254
255 // Client is connecting, outcome not yet determined.
256 EXPECT_EQ(AsyncSocket::CS_CONNECTING, client2->GetState());
kwibergd0d81482017-04-18 03:18:22 -0700257 EXPECT_FALSE(sink.Check(client2.get(), webrtc::testing::SSE_OPEN));
258 EXPECT_FALSE(sink.Check(client2.get(), webrtc::testing::SSE_CLOSE));
jbauch095ae152015-12-18 01:39:55 -0800259
260 // Server has pending connection, try to accept it (will succeed).
kwibergd0d81482017-04-18 03:18:22 -0700261 EXPECT_TRUE_WAIT((sink.Check(server.get(), webrtc::testing::SSE_READ)),
262 kTimeout);
jbauch095ae152015-12-18 01:39:55 -0800263 SetFailAccept(false);
jbauch555604a2016-04-26 03:13:22 -0700264 std::unique_ptr<AsyncSocket> accepted2(server->Accept(&accept_addr));
jbauch095ae152015-12-18 01:39:55 -0800265 ASSERT_TRUE(accepted2);
266 EXPECT_FALSE(accept_addr.IsNil());
267 EXPECT_EQ(accepted2->GetRemoteAddress(), accept_addr);
268}
269
270TEST_F(PhysicalSocketTest, TestConnectAcceptErrorIPv4) {
deadbeef9a6f4d42017-05-15 19:43:33 -0700271 MAYBE_SKIP_IPV4;
jbauch095ae152015-12-18 01:39:55 -0800272 ConnectInternalAcceptError(kIPv4Loopback);
273}
274
Taylor Brandstetter2b3bf6b2016-05-19 14:57:31 -0700275TEST_F(PhysicalSocketTest, TestConnectAcceptErrorIPv6) {
276 MAYBE_SKIP_IPV6;
jbauch095ae152015-12-18 01:39:55 -0800277 ConnectInternalAcceptError(kIPv6Loopback);
278}
279
jbauchf2a2bf42016-02-03 16:45:32 -0800280void PhysicalSocketTest::WritableAfterPartialWrite(const IPAddress& loopback) {
281 // Simulate a really small maximum send size.
282 const int kMaxSendSize = 128;
283 SetMaxSendSize(kMaxSendSize);
284
285 // Run the default send/receive socket tests with a smaller amount of data
286 // to avoid long running times due to the small maximum send size.
287 const size_t kDataSize = 128 * 1024;
288 TcpInternal(loopback, kDataSize, kMaxSendSize);
289}
290
danilchapb7b9dca2016-08-05 05:55:43 -0700291// https://bugs.chromium.org/p/webrtc/issues/detail?id=6167
292#if defined(WEBRTC_WIN)
Yves Gerey665174f2018-06-19 15:03:05 +0200293#define MAYBE_TestWritableAfterPartialWriteIPv4 \
294 DISABLED_TestWritableAfterPartialWriteIPv4
danilchapb7b9dca2016-08-05 05:55:43 -0700295#else
Yves Gerey665174f2018-06-19 15:03:05 +0200296#define MAYBE_TestWritableAfterPartialWriteIPv4 \
297 TestWritableAfterPartialWriteIPv4
danilchapb7b9dca2016-08-05 05:55:43 -0700298#endif
299TEST_F(PhysicalSocketTest, MAYBE_TestWritableAfterPartialWriteIPv4) {
deadbeef9a6f4d42017-05-15 19:43:33 -0700300 MAYBE_SKIP_IPV4;
jbauchf2a2bf42016-02-03 16:45:32 -0800301 WritableAfterPartialWrite(kIPv4Loopback);
302}
303
danilchapb7b9dca2016-08-05 05:55:43 -0700304// https://bugs.chromium.org/p/webrtc/issues/detail?id=6167
305#if defined(WEBRTC_WIN)
Yves Gerey665174f2018-06-19 15:03:05 +0200306#define MAYBE_TestWritableAfterPartialWriteIPv6 \
307 DISABLED_TestWritableAfterPartialWriteIPv6
danilchapb7b9dca2016-08-05 05:55:43 -0700308#else
Yves Gerey665174f2018-06-19 15:03:05 +0200309#define MAYBE_TestWritableAfterPartialWriteIPv6 \
310 TestWritableAfterPartialWriteIPv6
danilchapb7b9dca2016-08-05 05:55:43 -0700311#endif
312TEST_F(PhysicalSocketTest, MAYBE_TestWritableAfterPartialWriteIPv6) {
Taylor Brandstetter2b3bf6b2016-05-19 14:57:31 -0700313 MAYBE_SKIP_IPV6;
jbauchf2a2bf42016-02-03 16:45:32 -0800314 WritableAfterPartialWrite(kIPv6Loopback);
315}
316
Taylor Brandstetter2b3bf6b2016-05-19 14:57:31 -0700317TEST_F(PhysicalSocketTest, TestConnectFailIPv6) {
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000318 SocketTest::TestConnectFailIPv6();
319}
320
321TEST_F(PhysicalSocketTest, TestConnectWithDnsLookupFailIPv4) {
deadbeef9a6f4d42017-05-15 19:43:33 -0700322 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000323 SocketTest::TestConnectWithDnsLookupFailIPv4();
324}
325
Taylor Brandstetter2b3bf6b2016-05-19 14:57:31 -0700326TEST_F(PhysicalSocketTest, TestConnectWithDnsLookupFailIPv6) {
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000327 SocketTest::TestConnectWithDnsLookupFailIPv6();
328}
329
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000330TEST_F(PhysicalSocketTest, TestConnectWithClosedSocketIPv4) {
deadbeef9a6f4d42017-05-15 19:43:33 -0700331 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000332 SocketTest::TestConnectWithClosedSocketIPv4();
333}
334
Taylor Brandstetter2b3bf6b2016-05-19 14:57:31 -0700335TEST_F(PhysicalSocketTest, TestConnectWithClosedSocketIPv6) {
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000336 SocketTest::TestConnectWithClosedSocketIPv6();
337}
338
339TEST_F(PhysicalSocketTest, TestConnectWhileNotClosedIPv4) {
deadbeef9a6f4d42017-05-15 19:43:33 -0700340 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000341 SocketTest::TestConnectWhileNotClosedIPv4();
342}
343
Taylor Brandstetter2b3bf6b2016-05-19 14:57:31 -0700344TEST_F(PhysicalSocketTest, TestConnectWhileNotClosedIPv6) {
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000345 SocketTest::TestConnectWhileNotClosedIPv6();
346}
347
348TEST_F(PhysicalSocketTest, TestServerCloseDuringConnectIPv4) {
deadbeef9a6f4d42017-05-15 19:43:33 -0700349 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000350 SocketTest::TestServerCloseDuringConnectIPv4();
351}
352
Taylor Brandstetter2b3bf6b2016-05-19 14:57:31 -0700353TEST_F(PhysicalSocketTest, TestServerCloseDuringConnectIPv6) {
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000354 SocketTest::TestServerCloseDuringConnectIPv6();
355}
356
357TEST_F(PhysicalSocketTest, TestClientCloseDuringConnectIPv4) {
deadbeef9a6f4d42017-05-15 19:43:33 -0700358 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000359 SocketTest::TestClientCloseDuringConnectIPv4();
360}
361
Taylor Brandstetter2b3bf6b2016-05-19 14:57:31 -0700362TEST_F(PhysicalSocketTest, TestClientCloseDuringConnectIPv6) {
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000363 SocketTest::TestClientCloseDuringConnectIPv6();
364}
365
366TEST_F(PhysicalSocketTest, TestServerCloseIPv4) {
deadbeef9a6f4d42017-05-15 19:43:33 -0700367 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000368 SocketTest::TestServerCloseIPv4();
369}
370
Taylor Brandstetter2b3bf6b2016-05-19 14:57:31 -0700371TEST_F(PhysicalSocketTest, TestServerCloseIPv6) {
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000372 SocketTest::TestServerCloseIPv6();
373}
374
375TEST_F(PhysicalSocketTest, TestCloseInClosedCallbackIPv4) {
deadbeef9a6f4d42017-05-15 19:43:33 -0700376 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000377 SocketTest::TestCloseInClosedCallbackIPv4();
378}
379
Taylor Brandstetter2b3bf6b2016-05-19 14:57:31 -0700380TEST_F(PhysicalSocketTest, TestCloseInClosedCallbackIPv6) {
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000381 SocketTest::TestCloseInClosedCallbackIPv6();
382}
383
Taylor Brandstetter7b69a442020-08-20 23:43:13 +0000384TEST_F(PhysicalSocketTest, TestDeleteInReadCallbackIPv4) {
385 MAYBE_SKIP_IPV4;
386 SocketTest::TestDeleteInReadCallbackIPv4();
387}
388
389TEST_F(PhysicalSocketTest, TestDeleteInReadCallbackIPv6) {
390 SocketTest::TestDeleteInReadCallbackIPv6();
391}
392
henrike@webrtc.orgc732a3e2014-10-09 22:08:15 +0000393TEST_F(PhysicalSocketTest, TestSocketServerWaitIPv4) {
deadbeef9a6f4d42017-05-15 19:43:33 -0700394 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000395 SocketTest::TestSocketServerWaitIPv4();
396}
397
Taylor Brandstetter2b3bf6b2016-05-19 14:57:31 -0700398TEST_F(PhysicalSocketTest, TestSocketServerWaitIPv6) {
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000399 SocketTest::TestSocketServerWaitIPv6();
400}
401
402TEST_F(PhysicalSocketTest, TestTcpIPv4) {
deadbeef9a6f4d42017-05-15 19:43:33 -0700403 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000404 SocketTest::TestTcpIPv4();
405}
406
Taylor Brandstetter2b3bf6b2016-05-19 14:57:31 -0700407TEST_F(PhysicalSocketTest, TestTcpIPv6) {
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000408 SocketTest::TestTcpIPv6();
409}
410
411TEST_F(PhysicalSocketTest, TestUdpIPv4) {
deadbeef9a6f4d42017-05-15 19:43:33 -0700412 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000413 SocketTest::TestUdpIPv4();
414}
415
Taylor Brandstetter2b3bf6b2016-05-19 14:57:31 -0700416TEST_F(PhysicalSocketTest, TestUdpIPv6) {
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000417 SocketTest::TestUdpIPv6();
418}
419
henrike@webrtc.org6f833c32014-06-27 16:21:49 +0000420// Disable for TSan v2, see
421// https://code.google.com/p/webrtc/issues/detail?id=3498 for details.
deadbeefc97be6a2015-09-25 11:00:38 -0700422// Also disable for MSan, see:
423// https://code.google.com/p/webrtc/issues/detail?id=4958
424// TODO(deadbeef): Enable again once test is reimplemented to be unflaky.
minyuedf200d12015-10-17 13:10:46 -0700425// Also disable for ASan.
Henrik Kjellander0be3e042015-10-30 21:21:03 +0100426// Disabled on Android: https://code.google.com/p/webrtc/issues/detail?id=4364
ivocf399f212015-11-19 06:44:32 -0800427// Disabled on Linux: https://bugs.chromium.org/p/webrtc/issues/detail?id=5233
minyuedf200d12015-10-17 13:10:46 -0700428#if defined(THREAD_SANITIZER) || defined(MEMORY_SANITIZER) || \
ivocf399f212015-11-19 06:44:32 -0800429 defined(ADDRESS_SANITIZER) || defined(WEBRTC_ANDROID) || \
430 defined(WEBRTC_LINUX)
minyuedf200d12015-10-17 13:10:46 -0700431#define MAYBE_TestUdpReadyToSendIPv4 DISABLED_TestUdpReadyToSendIPv4
432#else
433#define MAYBE_TestUdpReadyToSendIPv4 TestUdpReadyToSendIPv4
434#endif
435TEST_F(PhysicalSocketTest, MAYBE_TestUdpReadyToSendIPv4) {
deadbeef9a6f4d42017-05-15 19:43:33 -0700436 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000437 SocketTest::TestUdpReadyToSendIPv4();
438}
439
danilchapb7b9dca2016-08-05 05:55:43 -0700440// https://bugs.chromium.org/p/webrtc/issues/detail?id=6167
441#if defined(WEBRTC_WIN)
442#define MAYBE_TestUdpReadyToSendIPv6 DISABLED_TestUdpReadyToSendIPv6
443#else
444#define MAYBE_TestUdpReadyToSendIPv6 TestUdpReadyToSendIPv6
445#endif
446TEST_F(PhysicalSocketTest, MAYBE_TestUdpReadyToSendIPv6) {
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000447 SocketTest::TestUdpReadyToSendIPv6();
448}
449
450TEST_F(PhysicalSocketTest, TestGetSetOptionsIPv4) {
deadbeef9a6f4d42017-05-15 19:43:33 -0700451 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000452 SocketTest::TestGetSetOptionsIPv4();
453}
454
455TEST_F(PhysicalSocketTest, TestGetSetOptionsIPv6) {
456 SocketTest::TestGetSetOptionsIPv6();
457}
458
459#if defined(WEBRTC_POSIX)
460
Taylor Brandstetter6f825352016-08-11 15:38:28 -0700461// We don't get recv timestamps on Mac.
Stefan Holmer9131efd2016-05-23 18:19:26 +0200462#if !defined(WEBRTC_MAC)
463TEST_F(PhysicalSocketTest, TestSocketRecvTimestampIPv4) {
deadbeef9a6f4d42017-05-15 19:43:33 -0700464 MAYBE_SKIP_IPV4;
Taylor Brandstetter6f825352016-08-11 15:38:28 -0700465 SocketTest::TestSocketRecvTimestampIPv4();
Stefan Holmer9131efd2016-05-23 18:19:26 +0200466}
467
Taylor Brandstetter6f825352016-08-11 15:38:28 -0700468TEST_F(PhysicalSocketTest, TestSocketRecvTimestampIPv6) {
469 SocketTest::TestSocketRecvTimestampIPv6();
Stefan Holmer9131efd2016-05-23 18:19:26 +0200470}
471#endif
472
deadbeefc874d122017-02-13 15:41:59 -0800473// Verify that if the socket was unable to be bound to a real network interface
474// (not loopback), Bind will return an error.
475TEST_F(PhysicalSocketTest,
476 BindFailsIfNetworkBinderFailsForNonLoopbackInterface) {
deadbeef9a6f4d42017-05-15 19:43:33 -0700477 MAYBE_SKIP_IPV4;
deadbeefc874d122017-02-13 15:41:59 -0800478 FakeNetworkBinder fake_network_binder;
479 server_->set_network_binder(&fake_network_binder);
480 std::unique_ptr<AsyncSocket> socket(
481 server_->CreateAsyncSocket(AF_INET, SOCK_DGRAM));
482 fake_network_binder.set_result(NetworkBindingResult::FAILURE);
483 EXPECT_EQ(-1, socket->Bind(SocketAddress("192.168.0.1", 0)));
484 server_->set_network_binder(nullptr);
485}
486
deadbeef9ffa13f2017-02-21 16:18:00 -0800487// Network binder shouldn't be used if the socket is bound to the "any" IP.
Yves Gerey665174f2018-06-19 15:03:05 +0200488TEST_F(PhysicalSocketTest, NetworkBinderIsNotUsedForAnyIp) {
deadbeef9a6f4d42017-05-15 19:43:33 -0700489 MAYBE_SKIP_IPV4;
deadbeef9ffa13f2017-02-21 16:18:00 -0800490 FakeNetworkBinder fake_network_binder;
491 server_->set_network_binder(&fake_network_binder);
492 std::unique_ptr<AsyncSocket> socket(
493 server_->CreateAsyncSocket(AF_INET, SOCK_DGRAM));
494 EXPECT_EQ(0, socket->Bind(SocketAddress("0.0.0.0", 0)));
495 EXPECT_EQ(0, fake_network_binder.num_binds());
496 server_->set_network_binder(nullptr);
497}
498
deadbeefc874d122017-02-13 15:41:59 -0800499// For a loopback interface, failures to bind to the interface should be
500// tolerated.
501TEST_F(PhysicalSocketTest,
502 BindSucceedsIfNetworkBinderFailsForLoopbackInterface) {
deadbeef9a6f4d42017-05-15 19:43:33 -0700503 MAYBE_SKIP_IPV4;
deadbeefc874d122017-02-13 15:41:59 -0800504 FakeNetworkBinder fake_network_binder;
505 server_->set_network_binder(&fake_network_binder);
506 std::unique_ptr<AsyncSocket> socket(
507 server_->CreateAsyncSocket(AF_INET, SOCK_DGRAM));
508 fake_network_binder.set_result(NetworkBindingResult::FAILURE);
509 EXPECT_EQ(0, socket->Bind(SocketAddress(kIPv4Loopback, 0)));
510 server_->set_network_binder(nullptr);
511}
512
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000513#endif
514
515} // namespace rtc