blob: 3d9dc0570663a93c8cfc2a3cbb72e1f7157deaae [file] [log] [blame]
henrike@webrtc.orgf0488722014-05-13 18:00:261/*
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
Jonas Olssona4d87372019-07-05 17:08:3311#include "rtc_base/physical_socket_server.h"
12
Yves Gerey3e707812018-11-28 15:47:4913#include <algorithm>
Evan Shrubsoled9593032025-01-17 13:19:4514#include <cstddef>
Yves Gerey665174f2018-06-19 13:03:0515#include <memory>
henrike@webrtc.orgf0488722014-05-13 18:00:2616
Evan Shrubsoled9593032025-01-17 13:19:4517#include "api/test/rtc_error_matchers.h"
Steve Anton10542f22019-01-11 17:11:0018#include "rtc_base/ip_address.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3119#include "rtc_base/logging.h"
Mirko Bonadeie5f4c6b2021-01-15 09:41:0120#include "rtc_base/net_helpers.h"
Mirko Bonadei0d8b79e2023-07-27 06:55:4921#include "rtc_base/net_test_helpers.h"
Steve Anton10542f22019-01-11 17:11:0022#include "rtc_base/network_monitor.h"
Evan Shrubsoled9593032025-01-17 13:19:4523#include "rtc_base/socket.h"
24#include "rtc_base/socket_address.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3125#include "rtc_base/socket_unittest.h"
Steve Anton10542f22019-01-11 17:11:0026#include "rtc_base/test_utils.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3127#include "rtc_base/thread.h"
Evan Shrubsoled9593032025-01-17 13:19:4528#include "test/gmock.h"
Yves Gerey3e707812018-11-28 15:47:4929#include "test/gtest.h"
Evan Shrubsoled9593032025-01-17 13:19:4530#include "test/wait_until.h"
henrike@webrtc.orgf0488722014-05-13 18:00:2631
32namespace rtc {
33
Mirko Bonadei675513b2017-11-09 10:09:2534#define MAYBE_SKIP_IPV4 \
35 if (!HasIPv4Enabled()) { \
36 RTC_LOG(LS_INFO) << "No IPv4... skipping"; \
37 return; \
deadbeef9a6f4d42017-05-16 02:43:3338 }
39
Mirko Bonadei675513b2017-11-09 10:09:2540#define MAYBE_SKIP_IPV6 \
41 if (!HasIPv6Enabled()) { \
42 RTC_LOG(LS_INFO) << "No IPv6... skipping"; \
43 return; \
Taylor Brandstetter2b3bf6b2016-05-19 21:57:3144 }
45
jbauch095ae152015-12-18 09:39:5546class PhysicalSocketTest;
47
48class FakeSocketDispatcher : public SocketDispatcher {
49 public:
50 explicit FakeSocketDispatcher(PhysicalSocketServer* ss)
Yves Gerey665174f2018-06-19 13:03:0551 : SocketDispatcher(ss) {}
jbauch095ae152015-12-18 09:39:5552
jbauchf2a2bf42016-02-04 00:45:3253 FakeSocketDispatcher(SOCKET s, PhysicalSocketServer* ss)
Yves Gerey665174f2018-06-19 13:03:0554 : SocketDispatcher(s, ss) {}
jbauchf2a2bf42016-02-04 00:45:3255
jbauch095ae152015-12-18 09:39:5556 protected:
57 SOCKET DoAccept(SOCKET socket, sockaddr* addr, socklen_t* addrlen) override;
jbauchf2a2bf42016-02-04 00:45:3258 int DoSend(SOCKET socket, const char* buf, int len, int flags) override;
Yves Gerey665174f2018-06-19 13:03:0559 int DoSendTo(SOCKET socket,
60 const char* buf,
61 int len,
62 int flags,
63 const struct sockaddr* dest_addr,
64 socklen_t addrlen) override;
henrike@webrtc.orgf0488722014-05-13 18:00:2665};
66
jbauch095ae152015-12-18 09:39:5567class FakePhysicalSocketServer : public PhysicalSocketServer {
68 public:
Yves Gerey665174f2018-06-19 13:03:0569 explicit FakePhysicalSocketServer(PhysicalSocketTest* test) : test_(test) {}
jbauch095ae152015-12-18 09:39:5570
Niels Möllerd0b88792021-08-12 08:32:3071 Socket* CreateSocket(int family, int type) override {
jbauch095ae152015-12-18 09:39:5572 SocketDispatcher* dispatcher = new FakeSocketDispatcher(this);
jbauchf2a2bf42016-02-04 00:45:3273 if (!dispatcher->Create(family, type)) {
jbauch095ae152015-12-18 09:39:5574 delete dispatcher;
75 return nullptr;
76 }
jbauchf2a2bf42016-02-04 00:45:3277 return dispatcher;
78 }
79
Niels Möllerd0b88792021-08-12 08:32:3080 Socket* WrapSocket(SOCKET s) override {
jbauchf2a2bf42016-02-04 00:45:3281 SocketDispatcher* dispatcher = new FakeSocketDispatcher(s, this);
82 if (!dispatcher->Initialize()) {
83 delete dispatcher;
84 return nullptr;
85 }
86 return dispatcher;
jbauch095ae152015-12-18 09:39:5587 }
88
89 PhysicalSocketTest* GetTest() const { return test_; }
90
91 private:
92 PhysicalSocketTest* test_;
93};
94
deadbeefc874d122017-02-13 23:41:5995class FakeNetworkBinder : public NetworkBinderInterface {
96 public:
Evan Shrubsole6202bf12025-03-11 12:37:5697 NetworkBindingResult BindSocketToNetwork(int,
98 const webrtc::IPAddress&) override {
deadbeef9ffa13f2017-02-22 00:18:0099 ++num_binds_;
deadbeefc874d122017-02-13 23:41:59100 return result_;
101 }
102
103 void set_result(NetworkBindingResult result) { result_ = result; }
104
deadbeef9ffa13f2017-02-22 00:18:00105 int num_binds() { return num_binds_; }
106
deadbeefc874d122017-02-13 23:41:59107 private:
108 NetworkBindingResult result_ = NetworkBindingResult::SUCCESS;
deadbeef9ffa13f2017-02-22 00:18:00109 int num_binds_ = 0;
deadbeefc874d122017-02-13 23:41:59110};
111
jbauch095ae152015-12-18 09:39:55112class PhysicalSocketTest : public SocketTest {
113 public:
Niels Möllerd0b88792021-08-12 08:32:30114 // Set flag to simluate failures when calling "::accept" on a Socket.
jbauch095ae152015-12-18 09:39:55115 void SetFailAccept(bool fail) { fail_accept_ = fail; }
116 bool FailAccept() const { return fail_accept_; }
117
jbauchf2a2bf42016-02-04 00:45:32118 // Maximum size to ::send to a socket. Set to < 0 to disable limiting.
119 void SetMaxSendSize(int max_size) { max_send_size_ = max_size; }
120 int MaxSendSize() const { return max_send_size_; }
121
jbauch095ae152015-12-18 09:39:55122 protected:
123 PhysicalSocketTest()
Niels Möller50f7c2c2021-09-08 12:05:16124 : SocketTest(&server_),
125 server_(this),
126 thread_(&server_),
Yves Gerey665174f2018-06-19 13:03:05127 fail_accept_(false),
128 max_send_size_(-1) {}
jbauch095ae152015-12-18 09:39:55129
Evan Shrubsole6202bf12025-03-11 12:37:56130 void ConnectInternalAcceptError(const webrtc::IPAddress& loopback);
131 void WritableAfterPartialWrite(const webrtc::IPAddress& loopback);
jbauch095ae152015-12-18 09:39:55132
Niels Möller50f7c2c2021-09-08 12:05:16133 FakePhysicalSocketServer server_;
nisse7eaa4ea2017-05-08 12:25:41134 rtc::AutoSocketServerThread thread_;
jbauch095ae152015-12-18 09:39:55135 bool fail_accept_;
jbauchf2a2bf42016-02-04 00:45:32136 int max_send_size_;
jbauch095ae152015-12-18 09:39:55137};
138
139SOCKET FakeSocketDispatcher::DoAccept(SOCKET socket,
140 sockaddr* addr,
141 socklen_t* addrlen) {
142 FakePhysicalSocketServer* ss =
143 static_cast<FakePhysicalSocketServer*>(socketserver());
144 if (ss->GetTest()->FailAccept()) {
145 return INVALID_SOCKET;
146 }
147
148 return SocketDispatcher::DoAccept(socket, addr, addrlen);
149}
150
Yves Gerey665174f2018-06-19 13:03:05151int FakeSocketDispatcher::DoSend(SOCKET socket,
152 const char* buf,
153 int len,
154 int flags) {
jbauchf2a2bf42016-02-04 00:45:32155 FakePhysicalSocketServer* ss =
156 static_cast<FakePhysicalSocketServer*>(socketserver());
157 if (ss->GetTest()->MaxSendSize() >= 0) {
158 len = std::min(len, ss->GetTest()->MaxSendSize());
159 }
160
161 return SocketDispatcher::DoSend(socket, buf, len, flags);
162}
163
Yves Gerey665174f2018-06-19 13:03:05164int FakeSocketDispatcher::DoSendTo(SOCKET socket,
165 const char* buf,
166 int len,
167 int flags,
168 const struct sockaddr* dest_addr,
169 socklen_t addrlen) {
jbauchf2a2bf42016-02-04 00:45:32170 FakePhysicalSocketServer* ss =
171 static_cast<FakePhysicalSocketServer*>(socketserver());
172 if (ss->GetTest()->MaxSendSize() >= 0) {
173 len = std::min(len, ss->GetTest()->MaxSendSize());
174 }
175
176 return SocketDispatcher::DoSendTo(socket, buf, len, flags, dest_addr,
Yves Gerey665174f2018-06-19 13:03:05177 addrlen);
jbauchf2a2bf42016-02-04 00:45:32178}
179
henrike@webrtc.orgf0488722014-05-13 18:00:26180TEST_F(PhysicalSocketTest, TestConnectIPv4) {
deadbeef9a6f4d42017-05-16 02:43:33181 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26182 SocketTest::TestConnectIPv4();
183}
184
Taylor Brandstetter2b3bf6b2016-05-19 21:57:31185TEST_F(PhysicalSocketTest, TestConnectIPv6) {
henrike@webrtc.orgf0488722014-05-13 18:00:26186 SocketTest::TestConnectIPv6();
187}
188
189TEST_F(PhysicalSocketTest, TestConnectWithDnsLookupIPv4) {
deadbeef9a6f4d42017-05-16 02:43:33190 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26191 SocketTest::TestConnectWithDnsLookupIPv4();
192}
193
194TEST_F(PhysicalSocketTest, TestConnectWithDnsLookupIPv6) {
195 SocketTest::TestConnectWithDnsLookupIPv6();
196}
197
198TEST_F(PhysicalSocketTest, TestConnectFailIPv4) {
deadbeef9a6f4d42017-05-16 02:43:33199 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26200 SocketTest::TestConnectFailIPv4();
201}
202
Evan Shrubsole6202bf12025-03-11 12:37:56203void PhysicalSocketTest::ConnectInternalAcceptError(
204 const webrtc::IPAddress& loopback) {
kwibergd0d81482017-04-18 10:18:22205 webrtc::testing::StreamSink sink;
Evan Shrubsole64b076f42025-03-12 12:56:28206 webrtc::SocketAddress accept_addr;
jbauch095ae152015-12-18 09:39:55207
208 // Create two clients.
Niels Möllerd0b88792021-08-12 08:32:30209 std::unique_ptr<Socket> client1(
Niels Möller50f7c2c2021-09-08 12:05:16210 server_.CreateSocket(loopback.family(), SOCK_STREAM));
jbauch095ae152015-12-18 09:39:55211 sink.Monitor(client1.get());
Niels Möllerd0b88792021-08-12 08:32:30212 EXPECT_EQ(Socket::CS_CLOSED, client1->GetState());
Jonas Olssonabbe8412018-04-03 11:40:05213 EXPECT_TRUE(IsUnspecOrEmptyIP(client1->GetLocalAddress().ipaddr()));
jbauch095ae152015-12-18 09:39:55214
Niels Möllerd0b88792021-08-12 08:32:30215 std::unique_ptr<Socket> client2(
Niels Möller50f7c2c2021-09-08 12:05:16216 server_.CreateSocket(loopback.family(), SOCK_STREAM));
jbauch095ae152015-12-18 09:39:55217 sink.Monitor(client2.get());
Niels Möllerd0b88792021-08-12 08:32:30218 EXPECT_EQ(Socket::CS_CLOSED, client2->GetState());
Jonas Olssonabbe8412018-04-03 11:40:05219 EXPECT_TRUE(IsUnspecOrEmptyIP(client2->GetLocalAddress().ipaddr()));
jbauch095ae152015-12-18 09:39:55220
221 // Create server and listen.
Niels Möllerd0b88792021-08-12 08:32:30222 std::unique_ptr<Socket> server(
Niels Möller50f7c2c2021-09-08 12:05:16223 server_.CreateSocket(loopback.family(), SOCK_STREAM));
jbauch095ae152015-12-18 09:39:55224 sink.Monitor(server.get());
Evan Shrubsole64b076f42025-03-12 12:56:28225 EXPECT_EQ(0, server->Bind(webrtc::SocketAddress(loopback, 0)));
jbauch095ae152015-12-18 09:39:55226 EXPECT_EQ(0, server->Listen(5));
Niels Möllerd0b88792021-08-12 08:32:30227 EXPECT_EQ(Socket::CS_CONNECTING, server->GetState());
jbauch095ae152015-12-18 09:39:55228
229 // Ensure no pending server connections, since we haven't done anything yet.
kwibergd0d81482017-04-18 10:18:22230 EXPECT_FALSE(sink.Check(server.get(), webrtc::testing::SSE_READ));
jbauch095ae152015-12-18 09:39:55231 EXPECT_TRUE(nullptr == server->Accept(&accept_addr));
232 EXPECT_TRUE(accept_addr.IsNil());
233
234 // Attempt first connect to listening socket.
235 EXPECT_EQ(0, client1->Connect(server->GetLocalAddress()));
236 EXPECT_FALSE(client1->GetLocalAddress().IsNil());
237 EXPECT_NE(server->GetLocalAddress(), client1->GetLocalAddress());
238
239 // Client is connecting, outcome not yet determined.
Niels Möllerd0b88792021-08-12 08:32:30240 EXPECT_EQ(Socket::CS_CONNECTING, client1->GetState());
kwibergd0d81482017-04-18 10:18:22241 EXPECT_FALSE(sink.Check(client1.get(), webrtc::testing::SSE_OPEN));
242 EXPECT_FALSE(sink.Check(client1.get(), webrtc::testing::SSE_CLOSE));
jbauch095ae152015-12-18 09:39:55243
244 // Server has pending connection, try to accept it (will fail).
Evan Shrubsoled9593032025-01-17 13:19:45245 EXPECT_THAT(
246 webrtc::WaitUntil(
247 [&] { return (sink.Check(server.get(), webrtc::testing::SSE_READ)); },
248 ::testing::IsTrue()),
249 webrtc::IsRtcOk());
jbauch095ae152015-12-18 09:39:55250 // Simulate "::accept" returning an error.
251 SetFailAccept(true);
Niels Möllerd0b88792021-08-12 08:32:30252 std::unique_ptr<Socket> accepted(server->Accept(&accept_addr));
jbauch095ae152015-12-18 09:39:55253 EXPECT_FALSE(accepted);
254 ASSERT_TRUE(accept_addr.IsNil());
255
256 // Ensure no more pending server connections.
kwibergd0d81482017-04-18 10:18:22257 EXPECT_FALSE(sink.Check(server.get(), webrtc::testing::SSE_READ));
jbauch095ae152015-12-18 09:39:55258 EXPECT_TRUE(nullptr == server->Accept(&accept_addr));
259 EXPECT_TRUE(accept_addr.IsNil());
260
261 // Attempt second connect to listening socket.
262 EXPECT_EQ(0, client2->Connect(server->GetLocalAddress()));
263 EXPECT_FALSE(client2->GetLocalAddress().IsNil());
264 EXPECT_NE(server->GetLocalAddress(), client2->GetLocalAddress());
265
266 // Client is connecting, outcome not yet determined.
Niels Möllerd0b88792021-08-12 08:32:30267 EXPECT_EQ(Socket::CS_CONNECTING, client2->GetState());
kwibergd0d81482017-04-18 10:18:22268 EXPECT_FALSE(sink.Check(client2.get(), webrtc::testing::SSE_OPEN));
269 EXPECT_FALSE(sink.Check(client2.get(), webrtc::testing::SSE_CLOSE));
jbauch095ae152015-12-18 09:39:55270
271 // Server has pending connection, try to accept it (will succeed).
Evan Shrubsoled9593032025-01-17 13:19:45272 EXPECT_THAT(
273 webrtc::WaitUntil(
274 [&] { return (sink.Check(server.get(), webrtc::testing::SSE_READ)); },
275 ::testing::IsTrue()),
276 webrtc::IsRtcOk());
jbauch095ae152015-12-18 09:39:55277 SetFailAccept(false);
Niels Möllerd0b88792021-08-12 08:32:30278 std::unique_ptr<Socket> accepted2(server->Accept(&accept_addr));
jbauch095ae152015-12-18 09:39:55279 ASSERT_TRUE(accepted2);
280 EXPECT_FALSE(accept_addr.IsNil());
281 EXPECT_EQ(accepted2->GetRemoteAddress(), accept_addr);
282}
283
284TEST_F(PhysicalSocketTest, TestConnectAcceptErrorIPv4) {
deadbeef9a6f4d42017-05-16 02:43:33285 MAYBE_SKIP_IPV4;
jbauch095ae152015-12-18 09:39:55286 ConnectInternalAcceptError(kIPv4Loopback);
287}
288
Taylor Brandstetter2b3bf6b2016-05-19 21:57:31289TEST_F(PhysicalSocketTest, TestConnectAcceptErrorIPv6) {
290 MAYBE_SKIP_IPV6;
jbauch095ae152015-12-18 09:39:55291 ConnectInternalAcceptError(kIPv6Loopback);
292}
293
Evan Shrubsole6202bf12025-03-11 12:37:56294void PhysicalSocketTest::WritableAfterPartialWrite(
295 const webrtc::IPAddress& loopback) {
jbauchf2a2bf42016-02-04 00:45:32296 // Simulate a really small maximum send size.
297 const int kMaxSendSize = 128;
298 SetMaxSendSize(kMaxSendSize);
299
300 // Run the default send/receive socket tests with a smaller amount of data
301 // to avoid long running times due to the small maximum send size.
302 const size_t kDataSize = 128 * 1024;
303 TcpInternal(loopback, kDataSize, kMaxSendSize);
304}
305
danilchapb7b9dca2016-08-05 12:55:43306// https://bugs.chromium.org/p/webrtc/issues/detail?id=6167
307#if defined(WEBRTC_WIN)
Yves Gerey665174f2018-06-19 13:03:05308#define MAYBE_TestWritableAfterPartialWriteIPv4 \
309 DISABLED_TestWritableAfterPartialWriteIPv4
danilchapb7b9dca2016-08-05 12:55:43310#else
Yves Gerey665174f2018-06-19 13:03:05311#define MAYBE_TestWritableAfterPartialWriteIPv4 \
312 TestWritableAfterPartialWriteIPv4
danilchapb7b9dca2016-08-05 12:55:43313#endif
314TEST_F(PhysicalSocketTest, MAYBE_TestWritableAfterPartialWriteIPv4) {
deadbeef9a6f4d42017-05-16 02:43:33315 MAYBE_SKIP_IPV4;
jbauchf2a2bf42016-02-04 00:45:32316 WritableAfterPartialWrite(kIPv4Loopback);
317}
318
danilchapb7b9dca2016-08-05 12:55:43319// https://bugs.chromium.org/p/webrtc/issues/detail?id=6167
320#if defined(WEBRTC_WIN)
Yves Gerey665174f2018-06-19 13:03:05321#define MAYBE_TestWritableAfterPartialWriteIPv6 \
322 DISABLED_TestWritableAfterPartialWriteIPv6
danilchapb7b9dca2016-08-05 12:55:43323#else
Yves Gerey665174f2018-06-19 13:03:05324#define MAYBE_TestWritableAfterPartialWriteIPv6 \
325 TestWritableAfterPartialWriteIPv6
danilchapb7b9dca2016-08-05 12:55:43326#endif
327TEST_F(PhysicalSocketTest, MAYBE_TestWritableAfterPartialWriteIPv6) {
Taylor Brandstetter2b3bf6b2016-05-19 21:57:31328 MAYBE_SKIP_IPV6;
jbauchf2a2bf42016-02-04 00:45:32329 WritableAfterPartialWrite(kIPv6Loopback);
330}
331
Taylor Brandstetter2b3bf6b2016-05-19 21:57:31332TEST_F(PhysicalSocketTest, TestConnectFailIPv6) {
henrike@webrtc.orgf0488722014-05-13 18:00:26333 SocketTest::TestConnectFailIPv6();
334}
335
336TEST_F(PhysicalSocketTest, TestConnectWithDnsLookupFailIPv4) {
deadbeef9a6f4d42017-05-16 02:43:33337 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26338 SocketTest::TestConnectWithDnsLookupFailIPv4();
339}
340
Taylor Brandstetter2b3bf6b2016-05-19 21:57:31341TEST_F(PhysicalSocketTest, TestConnectWithDnsLookupFailIPv6) {
henrike@webrtc.orgf0488722014-05-13 18:00:26342 SocketTest::TestConnectWithDnsLookupFailIPv6();
343}
344
henrike@webrtc.orgf0488722014-05-13 18:00:26345TEST_F(PhysicalSocketTest, TestConnectWithClosedSocketIPv4) {
deadbeef9a6f4d42017-05-16 02:43:33346 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26347 SocketTest::TestConnectWithClosedSocketIPv4();
348}
349
Taylor Brandstetter2b3bf6b2016-05-19 21:57:31350TEST_F(PhysicalSocketTest, TestConnectWithClosedSocketIPv6) {
henrike@webrtc.orgf0488722014-05-13 18:00:26351 SocketTest::TestConnectWithClosedSocketIPv6();
352}
353
354TEST_F(PhysicalSocketTest, TestConnectWhileNotClosedIPv4) {
deadbeef9a6f4d42017-05-16 02:43:33355 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26356 SocketTest::TestConnectWhileNotClosedIPv4();
357}
358
Taylor Brandstetter2b3bf6b2016-05-19 21:57:31359TEST_F(PhysicalSocketTest, TestConnectWhileNotClosedIPv6) {
henrike@webrtc.orgf0488722014-05-13 18:00:26360 SocketTest::TestConnectWhileNotClosedIPv6();
361}
362
363TEST_F(PhysicalSocketTest, TestServerCloseDuringConnectIPv4) {
deadbeef9a6f4d42017-05-16 02:43:33364 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26365 SocketTest::TestServerCloseDuringConnectIPv4();
366}
367
Taylor Brandstetter2b3bf6b2016-05-19 21:57:31368TEST_F(PhysicalSocketTest, TestServerCloseDuringConnectIPv6) {
henrike@webrtc.orgf0488722014-05-13 18:00:26369 SocketTest::TestServerCloseDuringConnectIPv6();
370}
371
372TEST_F(PhysicalSocketTest, TestClientCloseDuringConnectIPv4) {
deadbeef9a6f4d42017-05-16 02:43:33373 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26374 SocketTest::TestClientCloseDuringConnectIPv4();
375}
376
Taylor Brandstetter2b3bf6b2016-05-19 21:57:31377TEST_F(PhysicalSocketTest, TestClientCloseDuringConnectIPv6) {
henrike@webrtc.orgf0488722014-05-13 18:00:26378 SocketTest::TestClientCloseDuringConnectIPv6();
379}
380
381TEST_F(PhysicalSocketTest, TestServerCloseIPv4) {
deadbeef9a6f4d42017-05-16 02:43:33382 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26383 SocketTest::TestServerCloseIPv4();
384}
385
Taylor Brandstetter2b3bf6b2016-05-19 21:57:31386TEST_F(PhysicalSocketTest, TestServerCloseIPv6) {
henrike@webrtc.orgf0488722014-05-13 18:00:26387 SocketTest::TestServerCloseIPv6();
388}
389
390TEST_F(PhysicalSocketTest, TestCloseInClosedCallbackIPv4) {
deadbeef9a6f4d42017-05-16 02:43:33391 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26392 SocketTest::TestCloseInClosedCallbackIPv4();
393}
394
Taylor Brandstetter2b3bf6b2016-05-19 21:57:31395TEST_F(PhysicalSocketTest, TestCloseInClosedCallbackIPv6) {
henrike@webrtc.orgf0488722014-05-13 18:00:26396 SocketTest::TestCloseInClosedCallbackIPv6();
397}
398
Taylor Brandstetter7b69a442020-08-20 23:43:13399TEST_F(PhysicalSocketTest, TestDeleteInReadCallbackIPv4) {
400 MAYBE_SKIP_IPV4;
401 SocketTest::TestDeleteInReadCallbackIPv4();
402}
403
404TEST_F(PhysicalSocketTest, TestDeleteInReadCallbackIPv6) {
405 SocketTest::TestDeleteInReadCallbackIPv6();
406}
407
henrike@webrtc.orgc732a3e2014-10-09 22:08:15408TEST_F(PhysicalSocketTest, TestSocketServerWaitIPv4) {
deadbeef9a6f4d42017-05-16 02:43:33409 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26410 SocketTest::TestSocketServerWaitIPv4();
411}
412
Taylor Brandstetter2b3bf6b2016-05-19 21:57:31413TEST_F(PhysicalSocketTest, TestSocketServerWaitIPv6) {
henrike@webrtc.orgf0488722014-05-13 18:00:26414 SocketTest::TestSocketServerWaitIPv6();
415}
416
417TEST_F(PhysicalSocketTest, TestTcpIPv4) {
deadbeef9a6f4d42017-05-16 02:43:33418 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26419 SocketTest::TestTcpIPv4();
420}
421
Taylor Brandstetter2b3bf6b2016-05-19 21:57:31422TEST_F(PhysicalSocketTest, TestTcpIPv6) {
henrike@webrtc.orgf0488722014-05-13 18:00:26423 SocketTest::TestTcpIPv6();
424}
425
426TEST_F(PhysicalSocketTest, TestUdpIPv4) {
deadbeef9a6f4d42017-05-16 02:43:33427 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26428 SocketTest::TestUdpIPv4();
429}
430
Taylor Brandstetter2b3bf6b2016-05-19 21:57:31431TEST_F(PhysicalSocketTest, TestUdpIPv6) {
henrike@webrtc.orgf0488722014-05-13 18:00:26432 SocketTest::TestUdpIPv6();
433}
434
henrike@webrtc.org6f833c32014-06-27 16:21:49435// Disable for TSan v2, see
436// https://code.google.com/p/webrtc/issues/detail?id=3498 for details.
deadbeefc97be6a2015-09-25 18:00:38437// Also disable for MSan, see:
438// https://code.google.com/p/webrtc/issues/detail?id=4958
439// TODO(deadbeef): Enable again once test is reimplemented to be unflaky.
minyuedf200d12015-10-17 20:10:46440// Also disable for ASan.
Henrik Kjellander0be3e042015-10-30 20:21:03441// Disabled on Android: https://code.google.com/p/webrtc/issues/detail?id=4364
ivocf399f212015-11-19 14:44:32442// Disabled on Linux: https://bugs.chromium.org/p/webrtc/issues/detail?id=5233
minyuedf200d12015-10-17 20:10:46443#if defined(THREAD_SANITIZER) || defined(MEMORY_SANITIZER) || \
ivocf399f212015-11-19 14:44:32444 defined(ADDRESS_SANITIZER) || defined(WEBRTC_ANDROID) || \
445 defined(WEBRTC_LINUX)
minyuedf200d12015-10-17 20:10:46446#define MAYBE_TestUdpReadyToSendIPv4 DISABLED_TestUdpReadyToSendIPv4
447#else
448#define MAYBE_TestUdpReadyToSendIPv4 TestUdpReadyToSendIPv4
449#endif
450TEST_F(PhysicalSocketTest, MAYBE_TestUdpReadyToSendIPv4) {
deadbeef9a6f4d42017-05-16 02:43:33451 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26452 SocketTest::TestUdpReadyToSendIPv4();
453}
454
danilchapb7b9dca2016-08-05 12:55:43455// https://bugs.chromium.org/p/webrtc/issues/detail?id=6167
456#if defined(WEBRTC_WIN)
457#define MAYBE_TestUdpReadyToSendIPv6 DISABLED_TestUdpReadyToSendIPv6
458#else
459#define MAYBE_TestUdpReadyToSendIPv6 TestUdpReadyToSendIPv6
460#endif
461TEST_F(PhysicalSocketTest, MAYBE_TestUdpReadyToSendIPv6) {
henrike@webrtc.orgf0488722014-05-13 18:00:26462 SocketTest::TestUdpReadyToSendIPv6();
463}
464
465TEST_F(PhysicalSocketTest, TestGetSetOptionsIPv4) {
deadbeef9a6f4d42017-05-16 02:43:33466 MAYBE_SKIP_IPV4;
henrike@webrtc.orgf0488722014-05-13 18:00:26467 SocketTest::TestGetSetOptionsIPv4();
468}
469
470TEST_F(PhysicalSocketTest, TestGetSetOptionsIPv6) {
471 SocketTest::TestGetSetOptionsIPv6();
472}
473
474#if defined(WEBRTC_POSIX)
475
Stefan Holmer9131efd2016-05-23 16:19:26476TEST_F(PhysicalSocketTest, TestSocketRecvTimestampIPv4) {
deadbeef9a6f4d42017-05-16 02:43:33477 MAYBE_SKIP_IPV4;
Taylor Brandstetter6f825352016-08-11 22:38:28478 SocketTest::TestSocketRecvTimestampIPv4();
Stefan Holmer9131efd2016-05-23 16:19:26479}
480
Taylor Brandstetter6f825352016-08-11 22:38:28481TEST_F(PhysicalSocketTest, TestSocketRecvTimestampIPv6) {
482 SocketTest::TestSocketRecvTimestampIPv6();
Stefan Holmer9131efd2016-05-23 16:19:26483}
Stefan Holmer9131efd2016-05-23 16:19:26484
Per K8df31c92024-03-11 09:21:48485#if !defined(WEBRTC_MAC) && !defined(WEBRTC_IOS)
486// TODO(bugs.webrtc.org/15368): IpV4 fails on IOS and MAC. IPV6 works.
487TEST_F(PhysicalSocketTest, TestSocketSendRecvWithEcnIPv4) {
488 MAYBE_SKIP_IPV6;
489 SocketTest::TestSocketSendRecvWithEcnIPV4();
490}
491#endif
492
493TEST_F(PhysicalSocketTest, TestSocketSendRecvWithEcnIPv6) {
494 MAYBE_SKIP_IPV6;
495 SocketTest::TestSocketSendRecvWithEcnIPV6();
496}
497
deadbeefc874d122017-02-13 23:41:59498// Verify that if the socket was unable to be bound to a real network interface
499// (not loopback), Bind will return an error.
500TEST_F(PhysicalSocketTest,
501 BindFailsIfNetworkBinderFailsForNonLoopbackInterface) {
deadbeef9a6f4d42017-05-16 02:43:33502 MAYBE_SKIP_IPV4;
deadbeefc874d122017-02-13 23:41:59503 FakeNetworkBinder fake_network_binder;
Niels Möller50f7c2c2021-09-08 12:05:16504 server_.set_network_binder(&fake_network_binder);
505 std::unique_ptr<Socket> socket(server_.CreateSocket(AF_INET, SOCK_DGRAM));
deadbeefc874d122017-02-13 23:41:59506 fake_network_binder.set_result(NetworkBindingResult::FAILURE);
Evan Shrubsole64b076f42025-03-12 12:56:28507 EXPECT_EQ(-1, socket->Bind(webrtc::SocketAddress("192.168.0.1", 0)));
Niels Möller50f7c2c2021-09-08 12:05:16508 server_.set_network_binder(nullptr);
deadbeefc874d122017-02-13 23:41:59509}
510
deadbeef9ffa13f2017-02-22 00:18:00511// Network binder shouldn't be used if the socket is bound to the "any" IP.
Yves Gerey665174f2018-06-19 13:03:05512TEST_F(PhysicalSocketTest, NetworkBinderIsNotUsedForAnyIp) {
deadbeef9a6f4d42017-05-16 02:43:33513 MAYBE_SKIP_IPV4;
deadbeef9ffa13f2017-02-22 00:18:00514 FakeNetworkBinder fake_network_binder;
Niels Möller50f7c2c2021-09-08 12:05:16515 server_.set_network_binder(&fake_network_binder);
516 std::unique_ptr<Socket> socket(server_.CreateSocket(AF_INET, SOCK_DGRAM));
Evan Shrubsole64b076f42025-03-12 12:56:28517 EXPECT_EQ(0, socket->Bind(webrtc::SocketAddress("0.0.0.0", 0)));
deadbeef9ffa13f2017-02-22 00:18:00518 EXPECT_EQ(0, fake_network_binder.num_binds());
Niels Möller50f7c2c2021-09-08 12:05:16519 server_.set_network_binder(nullptr);
deadbeef9ffa13f2017-02-22 00:18:00520}
521
deadbeefc874d122017-02-13 23:41:59522// For a loopback interface, failures to bind to the interface should be
523// tolerated.
524TEST_F(PhysicalSocketTest,
525 BindSucceedsIfNetworkBinderFailsForLoopbackInterface) {
deadbeef9a6f4d42017-05-16 02:43:33526 MAYBE_SKIP_IPV4;
deadbeefc874d122017-02-13 23:41:59527 FakeNetworkBinder fake_network_binder;
Niels Möller50f7c2c2021-09-08 12:05:16528 server_.set_network_binder(&fake_network_binder);
529 std::unique_ptr<Socket> socket(server_.CreateSocket(AF_INET, SOCK_DGRAM));
deadbeefc874d122017-02-13 23:41:59530 fake_network_binder.set_result(NetworkBindingResult::FAILURE);
Evan Shrubsole64b076f42025-03-12 12:56:28531 EXPECT_EQ(0, socket->Bind(webrtc::SocketAddress(kIPv4Loopback, 0)));
Niels Möller50f7c2c2021-09-08 12:05:16532 server_.set_network_binder(nullptr);
deadbeefc874d122017-02-13 23:41:59533}
534
henrike@webrtc.orgf0488722014-05-13 18:00:26535#endif
536
Per K7efd3722023-03-21 13:10:44537TEST_F(PhysicalSocketTest, UdpSocketRecvTimestampUseRtcEpochIPv4) {
Per Kjellander3daf6962022-11-08 17:23:43538 MAYBE_SKIP_IPV4;
Per Kjellander3daf6962022-11-08 17:23:43539 SocketTest::TestUdpSocketRecvTimestampUseRtcEpochIPv4();
540}
541
Per K7efd3722023-03-21 13:10:44542TEST_F(PhysicalSocketTest, UdpSocketRecvTimestampUseRtcEpochIPv6) {
Per Kjellander3daf6962022-11-08 17:23:43543 SocketTest::TestUdpSocketRecvTimestampUseRtcEpochIPv6();
544}
545
henrike@webrtc.orgf0488722014-05-13 18:00:26546} // namespace rtc