blob: ba8ac85e6c03e734860aadada5c772647ab51a9f [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"
Per Kjellanderfdcfefa2022-11-08 12:48:52 +010026#include "test/field_trial.h"
Yves Gerey3e707812018-11-28 16:47:49 +010027#include "test/gtest.h"
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000028
29namespace rtc {
30
Mirko Bonadei675513b2017-11-09 11:09:25 +010031#define MAYBE_SKIP_IPV4 \
32 if (!HasIPv4Enabled()) { \
33 RTC_LOG(LS_INFO) << "No IPv4... skipping"; \
34 return; \
deadbeef9a6f4d42017-05-15 19:43:33 -070035 }
36
Mirko Bonadei675513b2017-11-09 11:09:25 +010037#define MAYBE_SKIP_IPV6 \
38 if (!HasIPv6Enabled()) { \
39 RTC_LOG(LS_INFO) << "No IPv6... skipping"; \
40 return; \
Taylor Brandstetter2b3bf6b2016-05-19 14:57:31 -070041 }
42
jbauch095ae152015-12-18 01:39:55 -080043class PhysicalSocketTest;
44
45class FakeSocketDispatcher : public SocketDispatcher {
46 public:
47 explicit FakeSocketDispatcher(PhysicalSocketServer* ss)
Yves Gerey665174f2018-06-19 15:03:05 +020048 : SocketDispatcher(ss) {}
jbauch095ae152015-12-18 01:39:55 -080049
jbauchf2a2bf42016-02-03 16:45:32 -080050 FakeSocketDispatcher(SOCKET s, PhysicalSocketServer* ss)
Yves Gerey665174f2018-06-19 15:03:05 +020051 : SocketDispatcher(s, ss) {}
jbauchf2a2bf42016-02-03 16:45:32 -080052
jbauch095ae152015-12-18 01:39:55 -080053 protected:
54 SOCKET DoAccept(SOCKET socket, sockaddr* addr, socklen_t* addrlen) override;
jbauchf2a2bf42016-02-03 16:45:32 -080055 int DoSend(SOCKET socket, const char* buf, int len, int flags) override;
Yves Gerey665174f2018-06-19 15:03:05 +020056 int DoSendTo(SOCKET socket,
57 const char* buf,
58 int len,
59 int flags,
60 const struct sockaddr* dest_addr,
61 socklen_t addrlen) override;
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000062};
63
jbauch095ae152015-12-18 01:39:55 -080064class FakePhysicalSocketServer : public PhysicalSocketServer {
65 public:
Yves Gerey665174f2018-06-19 15:03:05 +020066 explicit FakePhysicalSocketServer(PhysicalSocketTest* test) : test_(test) {}
jbauch095ae152015-12-18 01:39:55 -080067
Niels Möllerd0b88792021-08-12 10:32:30 +020068 Socket* CreateSocket(int family, int type) override {
jbauch095ae152015-12-18 01:39:55 -080069 SocketDispatcher* dispatcher = new FakeSocketDispatcher(this);
jbauchf2a2bf42016-02-03 16:45:32 -080070 if (!dispatcher->Create(family, type)) {
jbauch095ae152015-12-18 01:39:55 -080071 delete dispatcher;
72 return nullptr;
73 }
jbauchf2a2bf42016-02-03 16:45:32 -080074 return dispatcher;
75 }
76
Niels Möllerd0b88792021-08-12 10:32:30 +020077 Socket* WrapSocket(SOCKET s) override {
jbauchf2a2bf42016-02-03 16:45:32 -080078 SocketDispatcher* dispatcher = new FakeSocketDispatcher(s, this);
79 if (!dispatcher->Initialize()) {
80 delete dispatcher;
81 return nullptr;
82 }
83 return dispatcher;
jbauch095ae152015-12-18 01:39:55 -080084 }
85
86 PhysicalSocketTest* GetTest() const { return test_; }
87
88 private:
89 PhysicalSocketTest* test_;
90};
91
deadbeefc874d122017-02-13 15:41:59 -080092class FakeNetworkBinder : public NetworkBinderInterface {
93 public:
94 NetworkBindingResult BindSocketToNetwork(int, const IPAddress&) override {
deadbeef9ffa13f2017-02-21 16:18:00 -080095 ++num_binds_;
deadbeefc874d122017-02-13 15:41:59 -080096 return result_;
97 }
98
99 void set_result(NetworkBindingResult result) { result_ = result; }
100
deadbeef9ffa13f2017-02-21 16:18:00 -0800101 int num_binds() { return num_binds_; }
102
deadbeefc874d122017-02-13 15:41:59 -0800103 private:
104 NetworkBindingResult result_ = NetworkBindingResult::SUCCESS;
deadbeef9ffa13f2017-02-21 16:18:00 -0800105 int num_binds_ = 0;
deadbeefc874d122017-02-13 15:41:59 -0800106};
107
jbauch095ae152015-12-18 01:39:55 -0800108class PhysicalSocketTest : public SocketTest {
109 public:
Niels Möllerd0b88792021-08-12 10:32:30 +0200110 // Set flag to simluate failures when calling "::accept" on a Socket.
jbauch095ae152015-12-18 01:39:55 -0800111 void SetFailAccept(bool fail) { fail_accept_ = fail; }
112 bool FailAccept() const { return fail_accept_; }
113
jbauchf2a2bf42016-02-03 16:45:32 -0800114 // Maximum size to ::send to a socket. Set to < 0 to disable limiting.
115 void SetMaxSendSize(int max_size) { max_send_size_ = max_size; }
116 int MaxSendSize() const { return max_send_size_; }
117
jbauch095ae152015-12-18 01:39:55 -0800118 protected:
119 PhysicalSocketTest()
Niels Möller50f7c2c2021-09-08 14:05:16 +0200120 : SocketTest(&server_),
121 server_(this),
122 thread_(&server_),
Yves Gerey665174f2018-06-19 15:03:05 +0200123 fail_accept_(false),
124 max_send_size_(-1) {}
jbauch095ae152015-12-18 01:39:55 -0800125
126 void ConnectInternalAcceptError(const IPAddress& loopback);
jbauchf2a2bf42016-02-03 16:45:32 -0800127 void WritableAfterPartialWrite(const IPAddress& loopback);
jbauch095ae152015-12-18 01:39:55 -0800128
Niels Möller50f7c2c2021-09-08 14:05:16 +0200129 FakePhysicalSocketServer server_;
nisse7eaa4ea2017-05-08 05:25:41 -0700130 rtc::AutoSocketServerThread thread_;
jbauch095ae152015-12-18 01:39:55 -0800131 bool fail_accept_;
jbauchf2a2bf42016-02-03 16:45:32 -0800132 int max_send_size_;
jbauch095ae152015-12-18 01:39:55 -0800133};
134
135SOCKET FakeSocketDispatcher::DoAccept(SOCKET socket,
136 sockaddr* addr,
137 socklen_t* addrlen) {
138 FakePhysicalSocketServer* ss =
139 static_cast<FakePhysicalSocketServer*>(socketserver());
140 if (ss->GetTest()->FailAccept()) {
141 return INVALID_SOCKET;
142 }
143
144 return SocketDispatcher::DoAccept(socket, addr, addrlen);
145}
146
Yves Gerey665174f2018-06-19 15:03:05 +0200147int FakeSocketDispatcher::DoSend(SOCKET socket,
148 const char* buf,
149 int len,
150 int flags) {
jbauchf2a2bf42016-02-03 16:45:32 -0800151 FakePhysicalSocketServer* ss =
152 static_cast<FakePhysicalSocketServer*>(socketserver());
153 if (ss->GetTest()->MaxSendSize() >= 0) {
154 len = std::min(len, ss->GetTest()->MaxSendSize());
155 }
156
157 return SocketDispatcher::DoSend(socket, buf, len, flags);
158}
159
Yves Gerey665174f2018-06-19 15:03:05 +0200160int FakeSocketDispatcher::DoSendTo(SOCKET socket,
161 const char* buf,
162 int len,
163 int flags,
164 const struct sockaddr* dest_addr,
165 socklen_t addrlen) {
jbauchf2a2bf42016-02-03 16:45:32 -0800166 FakePhysicalSocketServer* ss =
167 static_cast<FakePhysicalSocketServer*>(socketserver());
168 if (ss->GetTest()->MaxSendSize() >= 0) {
169 len = std::min(len, ss->GetTest()->MaxSendSize());
170 }
171
172 return SocketDispatcher::DoSendTo(socket, buf, len, flags, dest_addr,
Yves Gerey665174f2018-06-19 15:03:05 +0200173 addrlen);
jbauchf2a2bf42016-02-03 16:45:32 -0800174}
175
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000176TEST_F(PhysicalSocketTest, TestConnectIPv4) {
deadbeef9a6f4d42017-05-15 19:43:33 -0700177 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000178 SocketTest::TestConnectIPv4();
179}
180
Taylor Brandstetter2b3bf6b2016-05-19 14:57:31 -0700181TEST_F(PhysicalSocketTest, TestConnectIPv6) {
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000182 SocketTest::TestConnectIPv6();
183}
184
185TEST_F(PhysicalSocketTest, TestConnectWithDnsLookupIPv4) {
deadbeef9a6f4d42017-05-15 19:43:33 -0700186 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000187 SocketTest::TestConnectWithDnsLookupIPv4();
188}
189
190TEST_F(PhysicalSocketTest, TestConnectWithDnsLookupIPv6) {
191 SocketTest::TestConnectWithDnsLookupIPv6();
192}
193
194TEST_F(PhysicalSocketTest, TestConnectFailIPv4) {
deadbeef9a6f4d42017-05-15 19:43:33 -0700195 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000196 SocketTest::TestConnectFailIPv4();
197}
198
jbauch095ae152015-12-18 01:39:55 -0800199void PhysicalSocketTest::ConnectInternalAcceptError(const IPAddress& loopback) {
kwibergd0d81482017-04-18 03:18:22 -0700200 webrtc::testing::StreamSink sink;
jbauch095ae152015-12-18 01:39:55 -0800201 SocketAddress accept_addr;
202
203 // Create two clients.
Niels Möllerd0b88792021-08-12 10:32:30 +0200204 std::unique_ptr<Socket> client1(
Niels Möller50f7c2c2021-09-08 14:05:16 +0200205 server_.CreateSocket(loopback.family(), SOCK_STREAM));
jbauch095ae152015-12-18 01:39:55 -0800206 sink.Monitor(client1.get());
Niels Möllerd0b88792021-08-12 10:32:30 +0200207 EXPECT_EQ(Socket::CS_CLOSED, client1->GetState());
Jonas Olssonabbe8412018-04-03 13:40:05 +0200208 EXPECT_TRUE(IsUnspecOrEmptyIP(client1->GetLocalAddress().ipaddr()));
jbauch095ae152015-12-18 01:39:55 -0800209
Niels Möllerd0b88792021-08-12 10:32:30 +0200210 std::unique_ptr<Socket> client2(
Niels Möller50f7c2c2021-09-08 14:05:16 +0200211 server_.CreateSocket(loopback.family(), SOCK_STREAM));
jbauch095ae152015-12-18 01:39:55 -0800212 sink.Monitor(client2.get());
Niels Möllerd0b88792021-08-12 10:32:30 +0200213 EXPECT_EQ(Socket::CS_CLOSED, client2->GetState());
Jonas Olssonabbe8412018-04-03 13:40:05 +0200214 EXPECT_TRUE(IsUnspecOrEmptyIP(client2->GetLocalAddress().ipaddr()));
jbauch095ae152015-12-18 01:39:55 -0800215
216 // Create server and listen.
Niels Möllerd0b88792021-08-12 10:32:30 +0200217 std::unique_ptr<Socket> server(
Niels Möller50f7c2c2021-09-08 14:05:16 +0200218 server_.CreateSocket(loopback.family(), SOCK_STREAM));
jbauch095ae152015-12-18 01:39:55 -0800219 sink.Monitor(server.get());
220 EXPECT_EQ(0, server->Bind(SocketAddress(loopback, 0)));
221 EXPECT_EQ(0, server->Listen(5));
Niels Möllerd0b88792021-08-12 10:32:30 +0200222 EXPECT_EQ(Socket::CS_CONNECTING, server->GetState());
jbauch095ae152015-12-18 01:39:55 -0800223
224 // Ensure no pending server connections, since we haven't done anything yet.
kwibergd0d81482017-04-18 03:18:22 -0700225 EXPECT_FALSE(sink.Check(server.get(), webrtc::testing::SSE_READ));
jbauch095ae152015-12-18 01:39:55 -0800226 EXPECT_TRUE(nullptr == server->Accept(&accept_addr));
227 EXPECT_TRUE(accept_addr.IsNil());
228
229 // Attempt first connect to listening socket.
230 EXPECT_EQ(0, client1->Connect(server->GetLocalAddress()));
231 EXPECT_FALSE(client1->GetLocalAddress().IsNil());
232 EXPECT_NE(server->GetLocalAddress(), client1->GetLocalAddress());
233
234 // Client is connecting, outcome not yet determined.
Niels Möllerd0b88792021-08-12 10:32:30 +0200235 EXPECT_EQ(Socket::CS_CONNECTING, client1->GetState());
kwibergd0d81482017-04-18 03:18:22 -0700236 EXPECT_FALSE(sink.Check(client1.get(), webrtc::testing::SSE_OPEN));
237 EXPECT_FALSE(sink.Check(client1.get(), webrtc::testing::SSE_CLOSE));
jbauch095ae152015-12-18 01:39:55 -0800238
239 // Server has pending connection, try to accept it (will fail).
kwibergd0d81482017-04-18 03:18:22 -0700240 EXPECT_TRUE_WAIT((sink.Check(server.get(), webrtc::testing::SSE_READ)),
241 kTimeout);
jbauch095ae152015-12-18 01:39:55 -0800242 // Simulate "::accept" returning an error.
243 SetFailAccept(true);
Niels Möllerd0b88792021-08-12 10:32:30 +0200244 std::unique_ptr<Socket> accepted(server->Accept(&accept_addr));
jbauch095ae152015-12-18 01:39:55 -0800245 EXPECT_FALSE(accepted);
246 ASSERT_TRUE(accept_addr.IsNil());
247
248 // Ensure no more pending server connections.
kwibergd0d81482017-04-18 03:18:22 -0700249 EXPECT_FALSE(sink.Check(server.get(), webrtc::testing::SSE_READ));
jbauch095ae152015-12-18 01:39:55 -0800250 EXPECT_TRUE(nullptr == server->Accept(&accept_addr));
251 EXPECT_TRUE(accept_addr.IsNil());
252
253 // Attempt second connect to listening socket.
254 EXPECT_EQ(0, client2->Connect(server->GetLocalAddress()));
255 EXPECT_FALSE(client2->GetLocalAddress().IsNil());
256 EXPECT_NE(server->GetLocalAddress(), client2->GetLocalAddress());
257
258 // Client is connecting, outcome not yet determined.
Niels Möllerd0b88792021-08-12 10:32:30 +0200259 EXPECT_EQ(Socket::CS_CONNECTING, client2->GetState());
kwibergd0d81482017-04-18 03:18:22 -0700260 EXPECT_FALSE(sink.Check(client2.get(), webrtc::testing::SSE_OPEN));
261 EXPECT_FALSE(sink.Check(client2.get(), webrtc::testing::SSE_CLOSE));
jbauch095ae152015-12-18 01:39:55 -0800262
263 // Server has pending connection, try to accept it (will succeed).
kwibergd0d81482017-04-18 03:18:22 -0700264 EXPECT_TRUE_WAIT((sink.Check(server.get(), webrtc::testing::SSE_READ)),
265 kTimeout);
jbauch095ae152015-12-18 01:39:55 -0800266 SetFailAccept(false);
Niels Möllerd0b88792021-08-12 10:32:30 +0200267 std::unique_ptr<Socket> accepted2(server->Accept(&accept_addr));
jbauch095ae152015-12-18 01:39:55 -0800268 ASSERT_TRUE(accepted2);
269 EXPECT_FALSE(accept_addr.IsNil());
270 EXPECT_EQ(accepted2->GetRemoteAddress(), accept_addr);
271}
272
273TEST_F(PhysicalSocketTest, TestConnectAcceptErrorIPv4) {
deadbeef9a6f4d42017-05-15 19:43:33 -0700274 MAYBE_SKIP_IPV4;
jbauch095ae152015-12-18 01:39:55 -0800275 ConnectInternalAcceptError(kIPv4Loopback);
276}
277
Taylor Brandstetter2b3bf6b2016-05-19 14:57:31 -0700278TEST_F(PhysicalSocketTest, TestConnectAcceptErrorIPv6) {
279 MAYBE_SKIP_IPV6;
jbauch095ae152015-12-18 01:39:55 -0800280 ConnectInternalAcceptError(kIPv6Loopback);
281}
282
jbauchf2a2bf42016-02-03 16:45:32 -0800283void PhysicalSocketTest::WritableAfterPartialWrite(const IPAddress& loopback) {
284 // Simulate a really small maximum send size.
285 const int kMaxSendSize = 128;
286 SetMaxSendSize(kMaxSendSize);
287
288 // Run the default send/receive socket tests with a smaller amount of data
289 // to avoid long running times due to the small maximum send size.
290 const size_t kDataSize = 128 * 1024;
291 TcpInternal(loopback, kDataSize, kMaxSendSize);
292}
293
danilchapb7b9dca2016-08-05 05:55:43 -0700294// https://bugs.chromium.org/p/webrtc/issues/detail?id=6167
295#if defined(WEBRTC_WIN)
Yves Gerey665174f2018-06-19 15:03:05 +0200296#define MAYBE_TestWritableAfterPartialWriteIPv4 \
297 DISABLED_TestWritableAfterPartialWriteIPv4
danilchapb7b9dca2016-08-05 05:55:43 -0700298#else
Yves Gerey665174f2018-06-19 15:03:05 +0200299#define MAYBE_TestWritableAfterPartialWriteIPv4 \
300 TestWritableAfterPartialWriteIPv4
danilchapb7b9dca2016-08-05 05:55:43 -0700301#endif
302TEST_F(PhysicalSocketTest, MAYBE_TestWritableAfterPartialWriteIPv4) {
deadbeef9a6f4d42017-05-15 19:43:33 -0700303 MAYBE_SKIP_IPV4;
jbauchf2a2bf42016-02-03 16:45:32 -0800304 WritableAfterPartialWrite(kIPv4Loopback);
305}
306
danilchapb7b9dca2016-08-05 05:55:43 -0700307// https://bugs.chromium.org/p/webrtc/issues/detail?id=6167
308#if defined(WEBRTC_WIN)
Yves Gerey665174f2018-06-19 15:03:05 +0200309#define MAYBE_TestWritableAfterPartialWriteIPv6 \
310 DISABLED_TestWritableAfterPartialWriteIPv6
danilchapb7b9dca2016-08-05 05:55:43 -0700311#else
Yves Gerey665174f2018-06-19 15:03:05 +0200312#define MAYBE_TestWritableAfterPartialWriteIPv6 \
313 TestWritableAfterPartialWriteIPv6
danilchapb7b9dca2016-08-05 05:55:43 -0700314#endif
315TEST_F(PhysicalSocketTest, MAYBE_TestWritableAfterPartialWriteIPv6) {
Taylor Brandstetter2b3bf6b2016-05-19 14:57:31 -0700316 MAYBE_SKIP_IPV6;
jbauchf2a2bf42016-02-03 16:45:32 -0800317 WritableAfterPartialWrite(kIPv6Loopback);
318}
319
Taylor Brandstetter2b3bf6b2016-05-19 14:57:31 -0700320TEST_F(PhysicalSocketTest, TestConnectFailIPv6) {
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000321 SocketTest::TestConnectFailIPv6();
322}
323
324TEST_F(PhysicalSocketTest, TestConnectWithDnsLookupFailIPv4) {
deadbeef9a6f4d42017-05-15 19:43:33 -0700325 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000326 SocketTest::TestConnectWithDnsLookupFailIPv4();
327}
328
Taylor Brandstetter2b3bf6b2016-05-19 14:57:31 -0700329TEST_F(PhysicalSocketTest, TestConnectWithDnsLookupFailIPv6) {
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000330 SocketTest::TestConnectWithDnsLookupFailIPv6();
331}
332
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000333TEST_F(PhysicalSocketTest, TestConnectWithClosedSocketIPv4) {
deadbeef9a6f4d42017-05-15 19:43:33 -0700334 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000335 SocketTest::TestConnectWithClosedSocketIPv4();
336}
337
Taylor Brandstetter2b3bf6b2016-05-19 14:57:31 -0700338TEST_F(PhysicalSocketTest, TestConnectWithClosedSocketIPv6) {
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000339 SocketTest::TestConnectWithClosedSocketIPv6();
340}
341
342TEST_F(PhysicalSocketTest, TestConnectWhileNotClosedIPv4) {
deadbeef9a6f4d42017-05-15 19:43:33 -0700343 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000344 SocketTest::TestConnectWhileNotClosedIPv4();
345}
346
Taylor Brandstetter2b3bf6b2016-05-19 14:57:31 -0700347TEST_F(PhysicalSocketTest, TestConnectWhileNotClosedIPv6) {
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000348 SocketTest::TestConnectWhileNotClosedIPv6();
349}
350
351TEST_F(PhysicalSocketTest, TestServerCloseDuringConnectIPv4) {
deadbeef9a6f4d42017-05-15 19:43:33 -0700352 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000353 SocketTest::TestServerCloseDuringConnectIPv4();
354}
355
Taylor Brandstetter2b3bf6b2016-05-19 14:57:31 -0700356TEST_F(PhysicalSocketTest, TestServerCloseDuringConnectIPv6) {
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000357 SocketTest::TestServerCloseDuringConnectIPv6();
358}
359
360TEST_F(PhysicalSocketTest, TestClientCloseDuringConnectIPv4) {
deadbeef9a6f4d42017-05-15 19:43:33 -0700361 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000362 SocketTest::TestClientCloseDuringConnectIPv4();
363}
364
Taylor Brandstetter2b3bf6b2016-05-19 14:57:31 -0700365TEST_F(PhysicalSocketTest, TestClientCloseDuringConnectIPv6) {
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000366 SocketTest::TestClientCloseDuringConnectIPv6();
367}
368
369TEST_F(PhysicalSocketTest, TestServerCloseIPv4) {
deadbeef9a6f4d42017-05-15 19:43:33 -0700370 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000371 SocketTest::TestServerCloseIPv4();
372}
373
Taylor Brandstetter2b3bf6b2016-05-19 14:57:31 -0700374TEST_F(PhysicalSocketTest, TestServerCloseIPv6) {
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000375 SocketTest::TestServerCloseIPv6();
376}
377
378TEST_F(PhysicalSocketTest, TestCloseInClosedCallbackIPv4) {
deadbeef9a6f4d42017-05-15 19:43:33 -0700379 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000380 SocketTest::TestCloseInClosedCallbackIPv4();
381}
382
Taylor Brandstetter2b3bf6b2016-05-19 14:57:31 -0700383TEST_F(PhysicalSocketTest, TestCloseInClosedCallbackIPv6) {
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000384 SocketTest::TestCloseInClosedCallbackIPv6();
385}
386
Taylor Brandstetter7b69a442020-08-20 23:43:13 +0000387TEST_F(PhysicalSocketTest, TestDeleteInReadCallbackIPv4) {
388 MAYBE_SKIP_IPV4;
389 SocketTest::TestDeleteInReadCallbackIPv4();
390}
391
392TEST_F(PhysicalSocketTest, TestDeleteInReadCallbackIPv6) {
393 SocketTest::TestDeleteInReadCallbackIPv6();
394}
395
henrike@webrtc.orgc732a3e2014-10-09 22:08:15 +0000396TEST_F(PhysicalSocketTest, TestSocketServerWaitIPv4) {
deadbeef9a6f4d42017-05-15 19:43:33 -0700397 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000398 SocketTest::TestSocketServerWaitIPv4();
399}
400
Taylor Brandstetter2b3bf6b2016-05-19 14:57:31 -0700401TEST_F(PhysicalSocketTest, TestSocketServerWaitIPv6) {
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000402 SocketTest::TestSocketServerWaitIPv6();
403}
404
405TEST_F(PhysicalSocketTest, TestTcpIPv4) {
deadbeef9a6f4d42017-05-15 19:43:33 -0700406 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000407 SocketTest::TestTcpIPv4();
408}
409
Taylor Brandstetter2b3bf6b2016-05-19 14:57:31 -0700410TEST_F(PhysicalSocketTest, TestTcpIPv6) {
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000411 SocketTest::TestTcpIPv6();
412}
413
414TEST_F(PhysicalSocketTest, TestUdpIPv4) {
deadbeef9a6f4d42017-05-15 19:43:33 -0700415 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000416 SocketTest::TestUdpIPv4();
417}
418
Taylor Brandstetter2b3bf6b2016-05-19 14:57:31 -0700419TEST_F(PhysicalSocketTest, TestUdpIPv6) {
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000420 SocketTest::TestUdpIPv6();
421}
422
henrike@webrtc.org6f833c32014-06-27 16:21:49 +0000423// Disable for TSan v2, see
424// https://code.google.com/p/webrtc/issues/detail?id=3498 for details.
deadbeefc97be6a2015-09-25 11:00:38 -0700425// Also disable for MSan, see:
426// https://code.google.com/p/webrtc/issues/detail?id=4958
427// TODO(deadbeef): Enable again once test is reimplemented to be unflaky.
minyuedf200d12015-10-17 13:10:46 -0700428// Also disable for ASan.
Henrik Kjellander0be3e042015-10-30 21:21:03 +0100429// Disabled on Android: https://code.google.com/p/webrtc/issues/detail?id=4364
ivocf399f212015-11-19 06:44:32 -0800430// Disabled on Linux: https://bugs.chromium.org/p/webrtc/issues/detail?id=5233
minyuedf200d12015-10-17 13:10:46 -0700431#if defined(THREAD_SANITIZER) || defined(MEMORY_SANITIZER) || \
ivocf399f212015-11-19 06:44:32 -0800432 defined(ADDRESS_SANITIZER) || defined(WEBRTC_ANDROID) || \
433 defined(WEBRTC_LINUX)
minyuedf200d12015-10-17 13:10:46 -0700434#define MAYBE_TestUdpReadyToSendIPv4 DISABLED_TestUdpReadyToSendIPv4
435#else
436#define MAYBE_TestUdpReadyToSendIPv4 TestUdpReadyToSendIPv4
437#endif
438TEST_F(PhysicalSocketTest, MAYBE_TestUdpReadyToSendIPv4) {
deadbeef9a6f4d42017-05-15 19:43:33 -0700439 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000440 SocketTest::TestUdpReadyToSendIPv4();
441}
442
danilchapb7b9dca2016-08-05 05:55:43 -0700443// https://bugs.chromium.org/p/webrtc/issues/detail?id=6167
444#if defined(WEBRTC_WIN)
445#define MAYBE_TestUdpReadyToSendIPv6 DISABLED_TestUdpReadyToSendIPv6
446#else
447#define MAYBE_TestUdpReadyToSendIPv6 TestUdpReadyToSendIPv6
448#endif
449TEST_F(PhysicalSocketTest, MAYBE_TestUdpReadyToSendIPv6) {
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000450 SocketTest::TestUdpReadyToSendIPv6();
451}
452
453TEST_F(PhysicalSocketTest, TestGetSetOptionsIPv4) {
deadbeef9a6f4d42017-05-15 19:43:33 -0700454 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000455 SocketTest::TestGetSetOptionsIPv4();
456}
457
458TEST_F(PhysicalSocketTest, TestGetSetOptionsIPv6) {
459 SocketTest::TestGetSetOptionsIPv6();
460}
461
462#if defined(WEBRTC_POSIX)
463
Stefan Holmer9131efd2016-05-23 18:19:26 +0200464#if !defined(WEBRTC_MAC)
Per Kjellanderfdcfefa2022-11-08 12:48:52 +0100465// We don't get recv timestamps on Mac without the experiment
466// WebRTC-SCM-Timestamp
Stefan Holmer9131efd2016-05-23 18:19:26 +0200467TEST_F(PhysicalSocketTest, TestSocketRecvTimestampIPv4) {
deadbeef9a6f4d42017-05-15 19:43:33 -0700468 MAYBE_SKIP_IPV4;
Taylor Brandstetter6f825352016-08-11 15:38:28 -0700469 SocketTest::TestSocketRecvTimestampIPv4();
Stefan Holmer9131efd2016-05-23 18:19:26 +0200470}
471
Taylor Brandstetter6f825352016-08-11 15:38:28 -0700472TEST_F(PhysicalSocketTest, TestSocketRecvTimestampIPv6) {
473 SocketTest::TestSocketRecvTimestampIPv6();
Stefan Holmer9131efd2016-05-23 18:19:26 +0200474}
475#endif
476
Per Kjellanderfdcfefa2022-11-08 12:48:52 +0100477TEST_F(PhysicalSocketTest, TestSocketRecvTimestampIPv4ScmExperiment) {
478 MAYBE_SKIP_IPV4;
479 webrtc::test::ScopedFieldTrials trial("WebRTC-SCM-Timestamp/Enabled/");
480 SocketTest::TestSocketRecvTimestampIPv4();
481}
482
483TEST_F(PhysicalSocketTest, TestSocketRecvTimestampIPv6ScmExperiment) {
484 webrtc::test::ScopedFieldTrials trial("WebRTC-SCM-Timestamp/Enabled/");
485 SocketTest::TestSocketRecvTimestampIPv6();
486}
Per Kjellander3daf6962022-11-08 18:23:43 +0100487
deadbeefc874d122017-02-13 15:41:59 -0800488// Verify that if the socket was unable to be bound to a real network interface
489// (not loopback), Bind will return an error.
490TEST_F(PhysicalSocketTest,
491 BindFailsIfNetworkBinderFailsForNonLoopbackInterface) {
deadbeef9a6f4d42017-05-15 19:43:33 -0700492 MAYBE_SKIP_IPV4;
deadbeefc874d122017-02-13 15:41:59 -0800493 FakeNetworkBinder fake_network_binder;
Niels Möller50f7c2c2021-09-08 14:05:16 +0200494 server_.set_network_binder(&fake_network_binder);
495 std::unique_ptr<Socket> socket(server_.CreateSocket(AF_INET, SOCK_DGRAM));
deadbeefc874d122017-02-13 15:41:59 -0800496 fake_network_binder.set_result(NetworkBindingResult::FAILURE);
497 EXPECT_EQ(-1, socket->Bind(SocketAddress("192.168.0.1", 0)));
Niels Möller50f7c2c2021-09-08 14:05:16 +0200498 server_.set_network_binder(nullptr);
deadbeefc874d122017-02-13 15:41:59 -0800499}
500
deadbeef9ffa13f2017-02-21 16:18:00 -0800501// Network binder shouldn't be used if the socket is bound to the "any" IP.
Yves Gerey665174f2018-06-19 15:03:05 +0200502TEST_F(PhysicalSocketTest, NetworkBinderIsNotUsedForAnyIp) {
deadbeef9a6f4d42017-05-15 19:43:33 -0700503 MAYBE_SKIP_IPV4;
deadbeef9ffa13f2017-02-21 16:18:00 -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));
deadbeef9ffa13f2017-02-21 16:18:00 -0800507 EXPECT_EQ(0, socket->Bind(SocketAddress("0.0.0.0", 0)));
508 EXPECT_EQ(0, fake_network_binder.num_binds());
Niels Möller50f7c2c2021-09-08 14:05:16 +0200509 server_.set_network_binder(nullptr);
deadbeef9ffa13f2017-02-21 16:18:00 -0800510}
511
deadbeefc874d122017-02-13 15:41:59 -0800512// For a loopback interface, failures to bind to the interface should be
513// tolerated.
514TEST_F(PhysicalSocketTest,
515 BindSucceedsIfNetworkBinderFailsForLoopbackInterface) {
deadbeef9a6f4d42017-05-15 19:43:33 -0700516 MAYBE_SKIP_IPV4;
deadbeefc874d122017-02-13 15:41:59 -0800517 FakeNetworkBinder fake_network_binder;
Niels Möller50f7c2c2021-09-08 14:05:16 +0200518 server_.set_network_binder(&fake_network_binder);
519 std::unique_ptr<Socket> socket(server_.CreateSocket(AF_INET, SOCK_DGRAM));
deadbeefc874d122017-02-13 15:41:59 -0800520 fake_network_binder.set_result(NetworkBindingResult::FAILURE);
521 EXPECT_EQ(0, socket->Bind(SocketAddress(kIPv4Loopback, 0)));
Niels Möller50f7c2c2021-09-08 14:05:16 +0200522 server_.set_network_binder(nullptr);
deadbeefc874d122017-02-13 15:41:59 -0800523}
524
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000525#endif
526
Per Kjellander3daf6962022-11-08 18:23:43 +0100527TEST_F(PhysicalSocketTest, UdpSocketRecvTimestampUseRtcEpochIPv4ScmExperiment) {
528 MAYBE_SKIP_IPV4;
529 webrtc::test::ScopedFieldTrials trial("WebRTC-SCM-Timestamp/Enabled/");
530 SocketTest::TestUdpSocketRecvTimestampUseRtcEpochIPv4();
531}
532
533TEST_F(PhysicalSocketTest, UdpSocketRecvTimestampUseRtcEpochIPv6ScmExperiment) {
534 webrtc::test::ScopedFieldTrials trial("WebRTC-SCM-Timestamp/Enabled/");
535 SocketTest::TestUdpSocketRecvTimestampUseRtcEpochIPv6();
536}
537
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000538} // namespace rtc