blob: 3da777a23503560e16686683b1b2b1f8cba2024d [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
Niels Möllerd0b88792021-08-12 10:32:30 +020067 Socket* CreateSocket(int family, int type) override {
jbauch095ae152015-12-18 01:39:55 -080068 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
Niels Möllerd0b88792021-08-12 10:32:30 +020076 Socket* WrapSocket(SOCKET s) override {
jbauchf2a2bf42016-02-03 16:45:32 -080077 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:
Niels Möllerd0b88792021-08-12 10:32:30 +0200109 // Set flag to simluate failures when calling "::accept" on a Socket.
jbauch095ae152015-12-18 01:39:55 -0800110 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()
Niels Möller50f7c2c2021-09-08 14:05:16 +0200119 : SocketTest(&server_),
120 server_(this),
121 thread_(&server_),
Yves Gerey665174f2018-06-19 15:03:05 +0200122 fail_accept_(false),
123 max_send_size_(-1) {}
jbauch095ae152015-12-18 01:39:55 -0800124
125 void ConnectInternalAcceptError(const IPAddress& loopback);
jbauchf2a2bf42016-02-03 16:45:32 -0800126 void WritableAfterPartialWrite(const IPAddress& loopback);
jbauch095ae152015-12-18 01:39:55 -0800127
Niels Möller50f7c2c2021-09-08 14:05:16 +0200128 FakePhysicalSocketServer server_;
nisse7eaa4ea2017-05-08 05:25:41 -0700129 rtc::AutoSocketServerThread thread_;
jbauch095ae152015-12-18 01:39:55 -0800130 bool fail_accept_;
jbauchf2a2bf42016-02-03 16:45:32 -0800131 int max_send_size_;
jbauch095ae152015-12-18 01:39:55 -0800132};
133
134SOCKET FakeSocketDispatcher::DoAccept(SOCKET socket,
135 sockaddr* addr,
136 socklen_t* addrlen) {
137 FakePhysicalSocketServer* ss =
138 static_cast<FakePhysicalSocketServer*>(socketserver());
139 if (ss->GetTest()->FailAccept()) {
140 return INVALID_SOCKET;
141 }
142
143 return SocketDispatcher::DoAccept(socket, addr, addrlen);
144}
145
Yves Gerey665174f2018-06-19 15:03:05 +0200146int FakeSocketDispatcher::DoSend(SOCKET socket,
147 const char* buf,
148 int len,
149 int flags) {
jbauchf2a2bf42016-02-03 16:45:32 -0800150 FakePhysicalSocketServer* ss =
151 static_cast<FakePhysicalSocketServer*>(socketserver());
152 if (ss->GetTest()->MaxSendSize() >= 0) {
153 len = std::min(len, ss->GetTest()->MaxSendSize());
154 }
155
156 return SocketDispatcher::DoSend(socket, buf, len, flags);
157}
158
Yves Gerey665174f2018-06-19 15:03:05 +0200159int FakeSocketDispatcher::DoSendTo(SOCKET socket,
160 const char* buf,
161 int len,
162 int flags,
163 const struct sockaddr* dest_addr,
164 socklen_t addrlen) {
jbauchf2a2bf42016-02-03 16:45:32 -0800165 FakePhysicalSocketServer* ss =
166 static_cast<FakePhysicalSocketServer*>(socketserver());
167 if (ss->GetTest()->MaxSendSize() >= 0) {
168 len = std::min(len, ss->GetTest()->MaxSendSize());
169 }
170
171 return SocketDispatcher::DoSendTo(socket, buf, len, flags, dest_addr,
Yves Gerey665174f2018-06-19 15:03:05 +0200172 addrlen);
jbauchf2a2bf42016-02-03 16:45:32 -0800173}
174
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000175TEST_F(PhysicalSocketTest, TestConnectIPv4) {
deadbeef9a6f4d42017-05-15 19:43:33 -0700176 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000177 SocketTest::TestConnectIPv4();
178}
179
Taylor Brandstetter2b3bf6b2016-05-19 14:57:31 -0700180TEST_F(PhysicalSocketTest, TestConnectIPv6) {
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000181 SocketTest::TestConnectIPv6();
182}
183
184TEST_F(PhysicalSocketTest, TestConnectWithDnsLookupIPv4) {
deadbeef9a6f4d42017-05-15 19:43:33 -0700185 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000186 SocketTest::TestConnectWithDnsLookupIPv4();
187}
188
189TEST_F(PhysicalSocketTest, TestConnectWithDnsLookupIPv6) {
190 SocketTest::TestConnectWithDnsLookupIPv6();
191}
192
193TEST_F(PhysicalSocketTest, TestConnectFailIPv4) {
deadbeef9a6f4d42017-05-15 19:43:33 -0700194 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000195 SocketTest::TestConnectFailIPv4();
196}
197
jbauch095ae152015-12-18 01:39:55 -0800198void PhysicalSocketTest::ConnectInternalAcceptError(const IPAddress& loopback) {
kwibergd0d81482017-04-18 03:18:22 -0700199 webrtc::testing::StreamSink sink;
jbauch095ae152015-12-18 01:39:55 -0800200 SocketAddress accept_addr;
201
202 // Create two clients.
Niels Möllerd0b88792021-08-12 10:32:30 +0200203 std::unique_ptr<Socket> client1(
Niels Möller50f7c2c2021-09-08 14:05:16 +0200204 server_.CreateSocket(loopback.family(), SOCK_STREAM));
jbauch095ae152015-12-18 01:39:55 -0800205 sink.Monitor(client1.get());
Niels Möllerd0b88792021-08-12 10:32:30 +0200206 EXPECT_EQ(Socket::CS_CLOSED, client1->GetState());
Jonas Olssonabbe8412018-04-03 13:40:05 +0200207 EXPECT_TRUE(IsUnspecOrEmptyIP(client1->GetLocalAddress().ipaddr()));
jbauch095ae152015-12-18 01:39:55 -0800208
Niels Möllerd0b88792021-08-12 10:32:30 +0200209 std::unique_ptr<Socket> client2(
Niels Möller50f7c2c2021-09-08 14:05:16 +0200210 server_.CreateSocket(loopback.family(), SOCK_STREAM));
jbauch095ae152015-12-18 01:39:55 -0800211 sink.Monitor(client2.get());
Niels Möllerd0b88792021-08-12 10:32:30 +0200212 EXPECT_EQ(Socket::CS_CLOSED, client2->GetState());
Jonas Olssonabbe8412018-04-03 13:40:05 +0200213 EXPECT_TRUE(IsUnspecOrEmptyIP(client2->GetLocalAddress().ipaddr()));
jbauch095ae152015-12-18 01:39:55 -0800214
215 // Create server and listen.
Niels Möllerd0b88792021-08-12 10:32:30 +0200216 std::unique_ptr<Socket> server(
Niels Möller50f7c2c2021-09-08 14:05:16 +0200217 server_.CreateSocket(loopback.family(), SOCK_STREAM));
jbauch095ae152015-12-18 01:39:55 -0800218 sink.Monitor(server.get());
219 EXPECT_EQ(0, server->Bind(SocketAddress(loopback, 0)));
220 EXPECT_EQ(0, server->Listen(5));
Niels Möllerd0b88792021-08-12 10:32:30 +0200221 EXPECT_EQ(Socket::CS_CONNECTING, server->GetState());
jbauch095ae152015-12-18 01:39:55 -0800222
223 // Ensure no pending server connections, since we haven't done anything yet.
kwibergd0d81482017-04-18 03:18:22 -0700224 EXPECT_FALSE(sink.Check(server.get(), webrtc::testing::SSE_READ));
jbauch095ae152015-12-18 01:39:55 -0800225 EXPECT_TRUE(nullptr == server->Accept(&accept_addr));
226 EXPECT_TRUE(accept_addr.IsNil());
227
228 // Attempt first connect to listening socket.
229 EXPECT_EQ(0, client1->Connect(server->GetLocalAddress()));
230 EXPECT_FALSE(client1->GetLocalAddress().IsNil());
231 EXPECT_NE(server->GetLocalAddress(), client1->GetLocalAddress());
232
233 // Client is connecting, outcome not yet determined.
Niels Möllerd0b88792021-08-12 10:32:30 +0200234 EXPECT_EQ(Socket::CS_CONNECTING, client1->GetState());
kwibergd0d81482017-04-18 03:18:22 -0700235 EXPECT_FALSE(sink.Check(client1.get(), webrtc::testing::SSE_OPEN));
236 EXPECT_FALSE(sink.Check(client1.get(), webrtc::testing::SSE_CLOSE));
jbauch095ae152015-12-18 01:39:55 -0800237
238 // Server has pending connection, try to accept it (will fail).
kwibergd0d81482017-04-18 03:18:22 -0700239 EXPECT_TRUE_WAIT((sink.Check(server.get(), webrtc::testing::SSE_READ)),
240 kTimeout);
jbauch095ae152015-12-18 01:39:55 -0800241 // Simulate "::accept" returning an error.
242 SetFailAccept(true);
Niels Möllerd0b88792021-08-12 10:32:30 +0200243 std::unique_ptr<Socket> accepted(server->Accept(&accept_addr));
jbauch095ae152015-12-18 01:39:55 -0800244 EXPECT_FALSE(accepted);
245 ASSERT_TRUE(accept_addr.IsNil());
246
247 // Ensure no more pending server connections.
kwibergd0d81482017-04-18 03:18:22 -0700248 EXPECT_FALSE(sink.Check(server.get(), webrtc::testing::SSE_READ));
jbauch095ae152015-12-18 01:39:55 -0800249 EXPECT_TRUE(nullptr == server->Accept(&accept_addr));
250 EXPECT_TRUE(accept_addr.IsNil());
251
252 // Attempt second connect to listening socket.
253 EXPECT_EQ(0, client2->Connect(server->GetLocalAddress()));
254 EXPECT_FALSE(client2->GetLocalAddress().IsNil());
255 EXPECT_NE(server->GetLocalAddress(), client2->GetLocalAddress());
256
257 // Client is connecting, outcome not yet determined.
Niels Möllerd0b88792021-08-12 10:32:30 +0200258 EXPECT_EQ(Socket::CS_CONNECTING, client2->GetState());
kwibergd0d81482017-04-18 03:18:22 -0700259 EXPECT_FALSE(sink.Check(client2.get(), webrtc::testing::SSE_OPEN));
260 EXPECT_FALSE(sink.Check(client2.get(), webrtc::testing::SSE_CLOSE));
jbauch095ae152015-12-18 01:39:55 -0800261
262 // Server has pending connection, try to accept it (will succeed).
kwibergd0d81482017-04-18 03:18:22 -0700263 EXPECT_TRUE_WAIT((sink.Check(server.get(), webrtc::testing::SSE_READ)),
264 kTimeout);
jbauch095ae152015-12-18 01:39:55 -0800265 SetFailAccept(false);
Niels Möllerd0b88792021-08-12 10:32:30 +0200266 std::unique_ptr<Socket> accepted2(server->Accept(&accept_addr));
jbauch095ae152015-12-18 01:39:55 -0800267 ASSERT_TRUE(accepted2);
268 EXPECT_FALSE(accept_addr.IsNil());
269 EXPECT_EQ(accepted2->GetRemoteAddress(), accept_addr);
270}
271
272TEST_F(PhysicalSocketTest, TestConnectAcceptErrorIPv4) {
deadbeef9a6f4d42017-05-15 19:43:33 -0700273 MAYBE_SKIP_IPV4;
jbauch095ae152015-12-18 01:39:55 -0800274 ConnectInternalAcceptError(kIPv4Loopback);
275}
276
Taylor Brandstetter2b3bf6b2016-05-19 14:57:31 -0700277TEST_F(PhysicalSocketTest, TestConnectAcceptErrorIPv6) {
278 MAYBE_SKIP_IPV6;
jbauch095ae152015-12-18 01:39:55 -0800279 ConnectInternalAcceptError(kIPv6Loopback);
280}
281
jbauchf2a2bf42016-02-03 16:45:32 -0800282void PhysicalSocketTest::WritableAfterPartialWrite(const IPAddress& loopback) {
283 // Simulate a really small maximum send size.
284 const int kMaxSendSize = 128;
285 SetMaxSendSize(kMaxSendSize);
286
287 // Run the default send/receive socket tests with a smaller amount of data
288 // to avoid long running times due to the small maximum send size.
289 const size_t kDataSize = 128 * 1024;
290 TcpInternal(loopback, kDataSize, kMaxSendSize);
291}
292
danilchapb7b9dca2016-08-05 05:55:43 -0700293// https://bugs.chromium.org/p/webrtc/issues/detail?id=6167
294#if defined(WEBRTC_WIN)
Yves Gerey665174f2018-06-19 15:03:05 +0200295#define MAYBE_TestWritableAfterPartialWriteIPv4 \
296 DISABLED_TestWritableAfterPartialWriteIPv4
danilchapb7b9dca2016-08-05 05:55:43 -0700297#else
Yves Gerey665174f2018-06-19 15:03:05 +0200298#define MAYBE_TestWritableAfterPartialWriteIPv4 \
299 TestWritableAfterPartialWriteIPv4
danilchapb7b9dca2016-08-05 05:55:43 -0700300#endif
301TEST_F(PhysicalSocketTest, MAYBE_TestWritableAfterPartialWriteIPv4) {
deadbeef9a6f4d42017-05-15 19:43:33 -0700302 MAYBE_SKIP_IPV4;
jbauchf2a2bf42016-02-03 16:45:32 -0800303 WritableAfterPartialWrite(kIPv4Loopback);
304}
305
danilchapb7b9dca2016-08-05 05:55:43 -0700306// https://bugs.chromium.org/p/webrtc/issues/detail?id=6167
307#if defined(WEBRTC_WIN)
Yves Gerey665174f2018-06-19 15:03:05 +0200308#define MAYBE_TestWritableAfterPartialWriteIPv6 \
309 DISABLED_TestWritableAfterPartialWriteIPv6
danilchapb7b9dca2016-08-05 05:55:43 -0700310#else
Yves Gerey665174f2018-06-19 15:03:05 +0200311#define MAYBE_TestWritableAfterPartialWriteIPv6 \
312 TestWritableAfterPartialWriteIPv6
danilchapb7b9dca2016-08-05 05:55:43 -0700313#endif
314TEST_F(PhysicalSocketTest, MAYBE_TestWritableAfterPartialWriteIPv6) {
Taylor Brandstetter2b3bf6b2016-05-19 14:57:31 -0700315 MAYBE_SKIP_IPV6;
jbauchf2a2bf42016-02-03 16:45:32 -0800316 WritableAfterPartialWrite(kIPv6Loopback);
317}
318
Taylor Brandstetter2b3bf6b2016-05-19 14:57:31 -0700319TEST_F(PhysicalSocketTest, TestConnectFailIPv6) {
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000320 SocketTest::TestConnectFailIPv6();
321}
322
323TEST_F(PhysicalSocketTest, TestConnectWithDnsLookupFailIPv4) {
deadbeef9a6f4d42017-05-15 19:43:33 -0700324 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000325 SocketTest::TestConnectWithDnsLookupFailIPv4();
326}
327
Taylor Brandstetter2b3bf6b2016-05-19 14:57:31 -0700328TEST_F(PhysicalSocketTest, TestConnectWithDnsLookupFailIPv6) {
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000329 SocketTest::TestConnectWithDnsLookupFailIPv6();
330}
331
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000332TEST_F(PhysicalSocketTest, TestConnectWithClosedSocketIPv4) {
deadbeef9a6f4d42017-05-15 19:43:33 -0700333 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000334 SocketTest::TestConnectWithClosedSocketIPv4();
335}
336
Taylor Brandstetter2b3bf6b2016-05-19 14:57:31 -0700337TEST_F(PhysicalSocketTest, TestConnectWithClosedSocketIPv6) {
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000338 SocketTest::TestConnectWithClosedSocketIPv6();
339}
340
341TEST_F(PhysicalSocketTest, TestConnectWhileNotClosedIPv4) {
deadbeef9a6f4d42017-05-15 19:43:33 -0700342 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000343 SocketTest::TestConnectWhileNotClosedIPv4();
344}
345
Taylor Brandstetter2b3bf6b2016-05-19 14:57:31 -0700346TEST_F(PhysicalSocketTest, TestConnectWhileNotClosedIPv6) {
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000347 SocketTest::TestConnectWhileNotClosedIPv6();
348}
349
350TEST_F(PhysicalSocketTest, TestServerCloseDuringConnectIPv4) {
deadbeef9a6f4d42017-05-15 19:43:33 -0700351 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000352 SocketTest::TestServerCloseDuringConnectIPv4();
353}
354
Taylor Brandstetter2b3bf6b2016-05-19 14:57:31 -0700355TEST_F(PhysicalSocketTest, TestServerCloseDuringConnectIPv6) {
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000356 SocketTest::TestServerCloseDuringConnectIPv6();
357}
358
359TEST_F(PhysicalSocketTest, TestClientCloseDuringConnectIPv4) {
deadbeef9a6f4d42017-05-15 19:43:33 -0700360 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000361 SocketTest::TestClientCloseDuringConnectIPv4();
362}
363
Taylor Brandstetter2b3bf6b2016-05-19 14:57:31 -0700364TEST_F(PhysicalSocketTest, TestClientCloseDuringConnectIPv6) {
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000365 SocketTest::TestClientCloseDuringConnectIPv6();
366}
367
368TEST_F(PhysicalSocketTest, TestServerCloseIPv4) {
deadbeef9a6f4d42017-05-15 19:43:33 -0700369 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000370 SocketTest::TestServerCloseIPv4();
371}
372
Taylor Brandstetter2b3bf6b2016-05-19 14:57:31 -0700373TEST_F(PhysicalSocketTest, TestServerCloseIPv6) {
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000374 SocketTest::TestServerCloseIPv6();
375}
376
377TEST_F(PhysicalSocketTest, TestCloseInClosedCallbackIPv4) {
deadbeef9a6f4d42017-05-15 19:43:33 -0700378 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000379 SocketTest::TestCloseInClosedCallbackIPv4();
380}
381
Taylor Brandstetter2b3bf6b2016-05-19 14:57:31 -0700382TEST_F(PhysicalSocketTest, TestCloseInClosedCallbackIPv6) {
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000383 SocketTest::TestCloseInClosedCallbackIPv6();
384}
385
Taylor Brandstetter7b69a442020-08-20 23:43:13 +0000386TEST_F(PhysicalSocketTest, TestDeleteInReadCallbackIPv4) {
387 MAYBE_SKIP_IPV4;
388 SocketTest::TestDeleteInReadCallbackIPv4();
389}
390
391TEST_F(PhysicalSocketTest, TestDeleteInReadCallbackIPv6) {
392 SocketTest::TestDeleteInReadCallbackIPv6();
393}
394
henrike@webrtc.orgc732a3e2014-10-09 22:08:15 +0000395TEST_F(PhysicalSocketTest, TestSocketServerWaitIPv4) {
deadbeef9a6f4d42017-05-15 19:43:33 -0700396 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000397 SocketTest::TestSocketServerWaitIPv4();
398}
399
Taylor Brandstetter2b3bf6b2016-05-19 14:57:31 -0700400TEST_F(PhysicalSocketTest, TestSocketServerWaitIPv6) {
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000401 SocketTest::TestSocketServerWaitIPv6();
402}
403
404TEST_F(PhysicalSocketTest, TestTcpIPv4) {
deadbeef9a6f4d42017-05-15 19:43:33 -0700405 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000406 SocketTest::TestTcpIPv4();
407}
408
Taylor Brandstetter2b3bf6b2016-05-19 14:57:31 -0700409TEST_F(PhysicalSocketTest, TestTcpIPv6) {
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000410 SocketTest::TestTcpIPv6();
411}
412
413TEST_F(PhysicalSocketTest, TestUdpIPv4) {
deadbeef9a6f4d42017-05-15 19:43:33 -0700414 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000415 SocketTest::TestUdpIPv4();
416}
417
Taylor Brandstetter2b3bf6b2016-05-19 14:57:31 -0700418TEST_F(PhysicalSocketTest, TestUdpIPv6) {
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000419 SocketTest::TestUdpIPv6();
420}
421
henrike@webrtc.org6f833c32014-06-27 16:21:49 +0000422// Disable for TSan v2, see
423// https://code.google.com/p/webrtc/issues/detail?id=3498 for details.
deadbeefc97be6a2015-09-25 11:00:38 -0700424// Also disable for MSan, see:
425// https://code.google.com/p/webrtc/issues/detail?id=4958
426// TODO(deadbeef): Enable again once test is reimplemented to be unflaky.
minyuedf200d12015-10-17 13:10:46 -0700427// Also disable for ASan.
Henrik Kjellander0be3e042015-10-30 21:21:03 +0100428// Disabled on Android: https://code.google.com/p/webrtc/issues/detail?id=4364
ivocf399f212015-11-19 06:44:32 -0800429// Disabled on Linux: https://bugs.chromium.org/p/webrtc/issues/detail?id=5233
minyuedf200d12015-10-17 13:10:46 -0700430#if defined(THREAD_SANITIZER) || defined(MEMORY_SANITIZER) || \
ivocf399f212015-11-19 06:44:32 -0800431 defined(ADDRESS_SANITIZER) || defined(WEBRTC_ANDROID) || \
432 defined(WEBRTC_LINUX)
minyuedf200d12015-10-17 13:10:46 -0700433#define MAYBE_TestUdpReadyToSendIPv4 DISABLED_TestUdpReadyToSendIPv4
434#else
435#define MAYBE_TestUdpReadyToSendIPv4 TestUdpReadyToSendIPv4
436#endif
437TEST_F(PhysicalSocketTest, MAYBE_TestUdpReadyToSendIPv4) {
deadbeef9a6f4d42017-05-15 19:43:33 -0700438 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000439 SocketTest::TestUdpReadyToSendIPv4();
440}
441
danilchapb7b9dca2016-08-05 05:55:43 -0700442// https://bugs.chromium.org/p/webrtc/issues/detail?id=6167
443#if defined(WEBRTC_WIN)
444#define MAYBE_TestUdpReadyToSendIPv6 DISABLED_TestUdpReadyToSendIPv6
445#else
446#define MAYBE_TestUdpReadyToSendIPv6 TestUdpReadyToSendIPv6
447#endif
448TEST_F(PhysicalSocketTest, MAYBE_TestUdpReadyToSendIPv6) {
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000449 SocketTest::TestUdpReadyToSendIPv6();
450}
451
452TEST_F(PhysicalSocketTest, TestGetSetOptionsIPv4) {
deadbeef9a6f4d42017-05-15 19:43:33 -0700453 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000454 SocketTest::TestGetSetOptionsIPv4();
455}
456
457TEST_F(PhysicalSocketTest, TestGetSetOptionsIPv6) {
458 SocketTest::TestGetSetOptionsIPv6();
459}
460
461#if defined(WEBRTC_POSIX)
462
Taylor Brandstetter6f825352016-08-11 15:38:28 -0700463// We don't get recv timestamps on Mac.
Stefan Holmer9131efd2016-05-23 18:19:26 +0200464#if !defined(WEBRTC_MAC)
465TEST_F(PhysicalSocketTest, TestSocketRecvTimestampIPv4) {
deadbeef9a6f4d42017-05-15 19:43:33 -0700466 MAYBE_SKIP_IPV4;
Taylor Brandstetter6f825352016-08-11 15:38:28 -0700467 SocketTest::TestSocketRecvTimestampIPv4();
Stefan Holmer9131efd2016-05-23 18:19:26 +0200468}
469
Taylor Brandstetter6f825352016-08-11 15:38:28 -0700470TEST_F(PhysicalSocketTest, TestSocketRecvTimestampIPv6) {
471 SocketTest::TestSocketRecvTimestampIPv6();
Stefan Holmer9131efd2016-05-23 18:19:26 +0200472}
473#endif
474
deadbeefc874d122017-02-13 15:41:59 -0800475// Verify that if the socket was unable to be bound to a real network interface
476// (not loopback), Bind will return an error.
477TEST_F(PhysicalSocketTest,
478 BindFailsIfNetworkBinderFailsForNonLoopbackInterface) {
deadbeef9a6f4d42017-05-15 19:43:33 -0700479 MAYBE_SKIP_IPV4;
deadbeefc874d122017-02-13 15:41:59 -0800480 FakeNetworkBinder fake_network_binder;
Niels Möller50f7c2c2021-09-08 14:05:16 +0200481 server_.set_network_binder(&fake_network_binder);
482 std::unique_ptr<Socket> socket(server_.CreateSocket(AF_INET, SOCK_DGRAM));
deadbeefc874d122017-02-13 15:41:59 -0800483 fake_network_binder.set_result(NetworkBindingResult::FAILURE);
484 EXPECT_EQ(-1, socket->Bind(SocketAddress("192.168.0.1", 0)));
Niels Möller50f7c2c2021-09-08 14:05:16 +0200485 server_.set_network_binder(nullptr);
deadbeefc874d122017-02-13 15:41:59 -0800486}
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;
Niels Möller50f7c2c2021-09-08 14:05:16 +0200492 server_.set_network_binder(&fake_network_binder);
493 std::unique_ptr<Socket> socket(server_.CreateSocket(AF_INET, SOCK_DGRAM));
deadbeef9ffa13f2017-02-21 16:18:00 -0800494 EXPECT_EQ(0, socket->Bind(SocketAddress("0.0.0.0", 0)));
495 EXPECT_EQ(0, fake_network_binder.num_binds());
Niels Möller50f7c2c2021-09-08 14:05:16 +0200496 server_.set_network_binder(nullptr);
deadbeef9ffa13f2017-02-21 16:18:00 -0800497}
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;
Niels Möller50f7c2c2021-09-08 14:05:16 +0200505 server_.set_network_binder(&fake_network_binder);
506 std::unique_ptr<Socket> socket(server_.CreateSocket(AF_INET, SOCK_DGRAM));
deadbeefc874d122017-02-13 15:41:59 -0800507 fake_network_binder.set_result(NetworkBindingResult::FAILURE);
508 EXPECT_EQ(0, socket->Bind(SocketAddress(kIPv4Loopback, 0)));
Niels Möller50f7c2c2021-09-08 14:05:16 +0200509 server_.set_network_binder(nullptr);
deadbeefc874d122017-02-13 15:41:59 -0800510}
511
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000512#endif
513
514} // namespace rtc