| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include <memory> | 11 #include <memory> |
| 12 #include <signal.h> | 12 #include <signal.h> |
| 13 #include <stdarg.h> | 13 #include <stdarg.h> |
| 14 | 14 |
| 15 #include "webrtc/base/gunit.h" | 15 #include "webrtc/base/gunit.h" |
| 16 #include "webrtc/base/logging.h" | 16 #include "webrtc/base/logging.h" |
| 17 #include "webrtc/base/physicalsocketserver.h" | 17 #include "webrtc/base/physicalsocketserver.h" |
| 18 #include "webrtc/base/socket_unittest.h" | 18 #include "webrtc/base/socket_unittest.h" |
| 19 #include "webrtc/base/testutils.h" | 19 #include "webrtc/base/testutils.h" |
| 20 #include "webrtc/base/thread.h" | 20 #include "webrtc/base/thread.h" |
| 21 | 21 |
| 22 namespace rtc { | 22 namespace rtc { |
| 23 | 23 |
| 24 #define MAYBE_SKIP_IPV6 \ |
| 25 if (!HasIPv6Enabled()) { \ |
| 26 LOG(LS_INFO) << "No IPv6... skipping"; \ |
| 27 return; \ |
| 28 } |
| 29 |
| 24 class PhysicalSocketTest; | 30 class PhysicalSocketTest; |
| 25 | 31 |
| 26 class FakeSocketDispatcher : public SocketDispatcher { | 32 class FakeSocketDispatcher : public SocketDispatcher { |
| 27 public: | 33 public: |
| 28 explicit FakeSocketDispatcher(PhysicalSocketServer* ss) | 34 explicit FakeSocketDispatcher(PhysicalSocketServer* ss) |
| 29 : SocketDispatcher(ss) { | 35 : SocketDispatcher(ss) { |
| 30 } | 36 } |
| 31 | 37 |
| 32 FakeSocketDispatcher(SOCKET s, PhysicalSocketServer* ss) | 38 FakeSocketDispatcher(SOCKET s, PhysicalSocketServer* ss) |
| 33 : SocketDispatcher(s, ss) { | 39 : SocketDispatcher(s, ss) { |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 } | 144 } |
| 139 | 145 |
| 140 return SocketDispatcher::DoSendTo(socket, buf, len, flags, dest_addr, | 146 return SocketDispatcher::DoSendTo(socket, buf, len, flags, dest_addr, |
| 141 addrlen); | 147 addrlen); |
| 142 } | 148 } |
| 143 | 149 |
| 144 TEST_F(PhysicalSocketTest, TestConnectIPv4) { | 150 TEST_F(PhysicalSocketTest, TestConnectIPv4) { |
| 145 SocketTest::TestConnectIPv4(); | 151 SocketTest::TestConnectIPv4(); |
| 146 } | 152 } |
| 147 | 153 |
| 148 // Crashes on Linux. See webrtc:4923. | 154 TEST_F(PhysicalSocketTest, TestConnectIPv6) { |
| 149 #if defined(WEBRTC_LINUX) | |
| 150 #define MAYBE_TestConnectIPv6 DISABLED_TestConnectIPv6 | |
| 151 #else | |
| 152 #define MAYBE_TestConnectIPv6 TestConnectIPv6 | |
| 153 #endif | |
| 154 TEST_F(PhysicalSocketTest, MAYBE_TestConnectIPv6) { | |
| 155 SocketTest::TestConnectIPv6(); | 155 SocketTest::TestConnectIPv6(); |
| 156 } | 156 } |
| 157 | 157 |
| 158 TEST_F(PhysicalSocketTest, TestConnectWithDnsLookupIPv4) { | 158 TEST_F(PhysicalSocketTest, TestConnectWithDnsLookupIPv4) { |
| 159 SocketTest::TestConnectWithDnsLookupIPv4(); | 159 SocketTest::TestConnectWithDnsLookupIPv4(); |
| 160 } | 160 } |
| 161 | 161 |
| 162 TEST_F(PhysicalSocketTest, TestConnectWithDnsLookupIPv6) { | 162 TEST_F(PhysicalSocketTest, TestConnectWithDnsLookupIPv6) { |
| 163 SocketTest::TestConnectWithDnsLookupIPv6(); | 163 SocketTest::TestConnectWithDnsLookupIPv6(); |
| 164 } | 164 } |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 std::unique_ptr<AsyncSocket> accepted2(server->Accept(&accept_addr)); | 236 std::unique_ptr<AsyncSocket> accepted2(server->Accept(&accept_addr)); |
| 237 ASSERT_TRUE(accepted2); | 237 ASSERT_TRUE(accepted2); |
| 238 EXPECT_FALSE(accept_addr.IsNil()); | 238 EXPECT_FALSE(accept_addr.IsNil()); |
| 239 EXPECT_EQ(accepted2->GetRemoteAddress(), accept_addr); | 239 EXPECT_EQ(accepted2->GetRemoteAddress(), accept_addr); |
| 240 } | 240 } |
| 241 | 241 |
| 242 TEST_F(PhysicalSocketTest, TestConnectAcceptErrorIPv4) { | 242 TEST_F(PhysicalSocketTest, TestConnectAcceptErrorIPv4) { |
| 243 ConnectInternalAcceptError(kIPv4Loopback); | 243 ConnectInternalAcceptError(kIPv4Loopback); |
| 244 } | 244 } |
| 245 | 245 |
| 246 // Crashes on Linux. See webrtc:4923. | 246 TEST_F(PhysicalSocketTest, TestConnectAcceptErrorIPv6) { |
| 247 #if defined(WEBRTC_LINUX) | 247 MAYBE_SKIP_IPV6; |
| 248 #define MAYBE_TestConnectAcceptErrorIPv6 DISABLED_TestConnectAcceptErrorIPv6 | |
| 249 #else | |
| 250 #define MAYBE_TestConnectAcceptErrorIPv6 TestConnectAcceptErrorIPv6 | |
| 251 #endif | |
| 252 TEST_F(PhysicalSocketTest, MAYBE_TestConnectAcceptErrorIPv6) { | |
| 253 ConnectInternalAcceptError(kIPv6Loopback); | 248 ConnectInternalAcceptError(kIPv6Loopback); |
| 254 } | 249 } |
| 255 | 250 |
| 256 void PhysicalSocketTest::WritableAfterPartialWrite(const IPAddress& loopback) { | 251 void PhysicalSocketTest::WritableAfterPartialWrite(const IPAddress& loopback) { |
| 257 // Simulate a really small maximum send size. | 252 // Simulate a really small maximum send size. |
| 258 const int kMaxSendSize = 128; | 253 const int kMaxSendSize = 128; |
| 259 SetMaxSendSize(kMaxSendSize); | 254 SetMaxSendSize(kMaxSendSize); |
| 260 | 255 |
| 261 // Run the default send/receive socket tests with a smaller amount of data | 256 // Run the default send/receive socket tests with a smaller amount of data |
| 262 // to avoid long running times due to the small maximum send size. | 257 // to avoid long running times due to the small maximum send size. |
| 263 const size_t kDataSize = 128 * 1024; | 258 const size_t kDataSize = 128 * 1024; |
| 264 TcpInternal(loopback, kDataSize, kMaxSendSize); | 259 TcpInternal(loopback, kDataSize, kMaxSendSize); |
| 265 } | 260 } |
| 266 | 261 |
| 267 TEST_F(PhysicalSocketTest, TestWritableAfterPartialWriteIPv4) { | 262 TEST_F(PhysicalSocketTest, TestWritableAfterPartialWriteIPv4) { |
| 268 WritableAfterPartialWrite(kIPv4Loopback); | 263 WritableAfterPartialWrite(kIPv4Loopback); |
| 269 } | 264 } |
| 270 | 265 |
| 271 // Crashes on Linux. See webrtc:4923. | 266 TEST_F(PhysicalSocketTest, TestWritableAfterPartialWriteIPv6) { |
| 272 #if defined(WEBRTC_LINUX) | 267 MAYBE_SKIP_IPV6; |
| 273 #define MAYBE_TestWritableAfterPartialWriteIPv6 \ | |
| 274 DISABLED_TestWritableAfterPartialWriteIPv6 | |
| 275 #else | |
| 276 #define MAYBE_TestWritableAfterPartialWriteIPv6 \ | |
| 277 TestWritableAfterPartialWriteIPv6 | |
| 278 #endif | |
| 279 TEST_F(PhysicalSocketTest, MAYBE_TestWritableAfterPartialWriteIPv6) { | |
| 280 WritableAfterPartialWrite(kIPv6Loopback); | 268 WritableAfterPartialWrite(kIPv6Loopback); |
| 281 } | 269 } |
| 282 | 270 |
| 283 // Crashes on Linux. See webrtc:4923. | 271 TEST_F(PhysicalSocketTest, TestConnectFailIPv6) { |
| 284 #if defined(WEBRTC_LINUX) | |
| 285 #define MAYBE_TestConnectFailIPv6 DISABLED_TestConnectFailIPv6 | |
| 286 #else | |
| 287 #define MAYBE_TestConnectFailIPv6 TestConnectFailIPv6 | |
| 288 #endif | |
| 289 TEST_F(PhysicalSocketTest, MAYBE_TestConnectFailIPv6) { | |
| 290 SocketTest::TestConnectFailIPv6(); | 272 SocketTest::TestConnectFailIPv6(); |
| 291 } | 273 } |
| 292 | 274 |
| 293 TEST_F(PhysicalSocketTest, TestConnectWithDnsLookupFailIPv4) { | 275 TEST_F(PhysicalSocketTest, TestConnectWithDnsLookupFailIPv4) { |
| 294 SocketTest::TestConnectWithDnsLookupFailIPv4(); | 276 SocketTest::TestConnectWithDnsLookupFailIPv4(); |
| 295 } | 277 } |
| 296 | 278 |
| 297 // Crashes on Linux. See webrtc:4923. | 279 TEST_F(PhysicalSocketTest, TestConnectWithDnsLookupFailIPv6) { |
| 298 #if defined(WEBRTC_LINUX) | |
| 299 #define MAYBE_TestConnectWithDnsLookupFailIPv6 \ | |
| 300 DISABLED_TestConnectWithDnsLookupFailIPv6 | |
| 301 #else | |
| 302 #define MAYBE_TestConnectWithDnsLookupFailIPv6 \ | |
| 303 TestConnectWithDnsLookupFailIPv6 | |
| 304 #endif | |
| 305 TEST_F(PhysicalSocketTest, MAYBE_TestConnectWithDnsLookupFailIPv6) { | |
| 306 SocketTest::TestConnectWithDnsLookupFailIPv6(); | 280 SocketTest::TestConnectWithDnsLookupFailIPv6(); |
| 307 } | 281 } |
| 308 | 282 |
| 309 | 283 |
| 310 TEST_F(PhysicalSocketTest, TestConnectWithClosedSocketIPv4) { | 284 TEST_F(PhysicalSocketTest, TestConnectWithClosedSocketIPv4) { |
| 311 SocketTest::TestConnectWithClosedSocketIPv4(); | 285 SocketTest::TestConnectWithClosedSocketIPv4(); |
| 312 } | 286 } |
| 313 | 287 |
| 314 // Crashes on Linux. See webrtc:4923. | 288 TEST_F(PhysicalSocketTest, TestConnectWithClosedSocketIPv6) { |
| 315 #if defined(WEBRTC_LINUX) | |
| 316 #define MAYBE_TestConnectWithClosedSocketIPv6 \ | |
| 317 DISABLED_TestConnectWithClosedSocketIPv6 | |
| 318 #else | |
| 319 #define MAYBE_TestConnectWithClosedSocketIPv6 TestConnectWithClosedSocketIPv6 | |
| 320 #endif | |
| 321 TEST_F(PhysicalSocketTest, MAYBE_TestConnectWithClosedSocketIPv6) { | |
| 322 SocketTest::TestConnectWithClosedSocketIPv6(); | 289 SocketTest::TestConnectWithClosedSocketIPv6(); |
| 323 } | 290 } |
| 324 | 291 |
| 325 TEST_F(PhysicalSocketTest, TestConnectWhileNotClosedIPv4) { | 292 TEST_F(PhysicalSocketTest, TestConnectWhileNotClosedIPv4) { |
| 326 SocketTest::TestConnectWhileNotClosedIPv4(); | 293 SocketTest::TestConnectWhileNotClosedIPv4(); |
| 327 } | 294 } |
| 328 | 295 |
| 329 // Crashes on Linux. See webrtc:4923. | 296 TEST_F(PhysicalSocketTest, TestConnectWhileNotClosedIPv6) { |
| 330 #if defined(WEBRTC_LINUX) | |
| 331 #define MAYBE_TestConnectWhileNotClosedIPv6 \ | |
| 332 DISABLED_TestConnectWhileNotClosedIPv6 | |
| 333 #else | |
| 334 #define MAYBE_TestConnectWhileNotClosedIPv6 TestConnectWhileNotClosedIPv6 | |
| 335 #endif | |
| 336 TEST_F(PhysicalSocketTest, MAYBE_TestConnectWhileNotClosedIPv6) { | |
| 337 SocketTest::TestConnectWhileNotClosedIPv6(); | 297 SocketTest::TestConnectWhileNotClosedIPv6(); |
| 338 } | 298 } |
| 339 | 299 |
| 340 TEST_F(PhysicalSocketTest, TestServerCloseDuringConnectIPv4) { | 300 TEST_F(PhysicalSocketTest, TestServerCloseDuringConnectIPv4) { |
| 341 SocketTest::TestServerCloseDuringConnectIPv4(); | 301 SocketTest::TestServerCloseDuringConnectIPv4(); |
| 342 } | 302 } |
| 343 | 303 |
| 344 // Crashes on Linux. See webrtc:4923. | 304 TEST_F(PhysicalSocketTest, TestServerCloseDuringConnectIPv6) { |
| 345 #if defined(WEBRTC_LINUX) | |
| 346 #define MAYBE_TestServerCloseDuringConnectIPv6 \ | |
| 347 DISABLED_TestServerCloseDuringConnectIPv6 | |
| 348 #else | |
| 349 #define MAYBE_TestServerCloseDuringConnectIPv6 TestServerCloseDuringConnectIPv6 | |
| 350 #endif | |
| 351 TEST_F(PhysicalSocketTest, MAYBE_TestServerCloseDuringConnectIPv6) { | |
| 352 SocketTest::TestServerCloseDuringConnectIPv6(); | 305 SocketTest::TestServerCloseDuringConnectIPv6(); |
| 353 } | 306 } |
| 354 | 307 |
| 355 TEST_F(PhysicalSocketTest, TestClientCloseDuringConnectIPv4) { | 308 TEST_F(PhysicalSocketTest, TestClientCloseDuringConnectIPv4) { |
| 356 SocketTest::TestClientCloseDuringConnectIPv4(); | 309 SocketTest::TestClientCloseDuringConnectIPv4(); |
| 357 } | 310 } |
| 358 | 311 |
| 359 // Crashes on Linux. See webrtc:4923. | 312 TEST_F(PhysicalSocketTest, TestClientCloseDuringConnectIPv6) { |
| 360 #if defined(WEBRTC_LINUX) | |
| 361 #define MAYBE_TestClientCloseDuringConnectIPv6 \ | |
| 362 DISABLED_TestClientCloseDuringConnectIPv6 | |
| 363 #else | |
| 364 #define MAYBE_TestClientCloseDuringConnectIPv6 TestClientCloseDuringConnectIPv6 | |
| 365 #endif | |
| 366 TEST_F(PhysicalSocketTest, MAYBE_TestClientCloseDuringConnectIPv6) { | |
| 367 SocketTest::TestClientCloseDuringConnectIPv6(); | 313 SocketTest::TestClientCloseDuringConnectIPv6(); |
| 368 } | 314 } |
| 369 | 315 |
| 370 TEST_F(PhysicalSocketTest, TestServerCloseIPv4) { | 316 TEST_F(PhysicalSocketTest, TestServerCloseIPv4) { |
| 371 SocketTest::TestServerCloseIPv4(); | 317 SocketTest::TestServerCloseIPv4(); |
| 372 } | 318 } |
| 373 | 319 |
| 374 // Crashes on Linux. See webrtc:4923. | 320 TEST_F(PhysicalSocketTest, TestServerCloseIPv6) { |
| 375 #if defined(WEBRTC_LINUX) | |
| 376 #define MAYBE_TestServerCloseIPv6 DISABLED_TestServerCloseIPv6 | |
| 377 #else | |
| 378 #define MAYBE_TestServerCloseIPv6 TestServerCloseIPv6 | |
| 379 #endif | |
| 380 TEST_F(PhysicalSocketTest, MAYBE_TestServerCloseIPv6) { | |
| 381 SocketTest::TestServerCloseIPv6(); | 321 SocketTest::TestServerCloseIPv6(); |
| 382 } | 322 } |
| 383 | 323 |
| 384 TEST_F(PhysicalSocketTest, TestCloseInClosedCallbackIPv4) { | 324 TEST_F(PhysicalSocketTest, TestCloseInClosedCallbackIPv4) { |
| 385 SocketTest::TestCloseInClosedCallbackIPv4(); | 325 SocketTest::TestCloseInClosedCallbackIPv4(); |
| 386 } | 326 } |
| 387 | 327 |
| 388 // Crashes on Linux. See webrtc:4923. | 328 TEST_F(PhysicalSocketTest, TestCloseInClosedCallbackIPv6) { |
| 389 #if defined(WEBRTC_LINUX) | |
| 390 #define MAYBE_TestCloseInClosedCallbackIPv6 \ | |
| 391 DISABLED_TestCloseInClosedCallbackIPv6 | |
| 392 #else | |
| 393 #define MAYBE_TestCloseInClosedCallbackIPv6 TestCloseInClosedCallbackIPv6 | |
| 394 #endif | |
| 395 TEST_F(PhysicalSocketTest, MAYBE_TestCloseInClosedCallbackIPv6) { | |
| 396 SocketTest::TestCloseInClosedCallbackIPv6(); | 329 SocketTest::TestCloseInClosedCallbackIPv6(); |
| 397 } | 330 } |
| 398 | 331 |
| 399 TEST_F(PhysicalSocketTest, TestSocketServerWaitIPv4) { | 332 TEST_F(PhysicalSocketTest, TestSocketServerWaitIPv4) { |
| 400 SocketTest::TestSocketServerWaitIPv4(); | 333 SocketTest::TestSocketServerWaitIPv4(); |
| 401 } | 334 } |
| 402 | 335 |
| 403 // Crashes on Linux. See webrtc:4923. | 336 TEST_F(PhysicalSocketTest, TestSocketServerWaitIPv6) { |
| 404 #if defined(WEBRTC_LINUX) | |
| 405 #define MAYBE_TestSocketServerWaitIPv6 DISABLED_TestSocketServerWaitIPv6 | |
| 406 #else | |
| 407 #define MAYBE_TestSocketServerWaitIPv6 TestSocketServerWaitIPv6 | |
| 408 #endif | |
| 409 TEST_F(PhysicalSocketTest, MAYBE_TestSocketServerWaitIPv6) { | |
| 410 SocketTest::TestSocketServerWaitIPv6(); | 337 SocketTest::TestSocketServerWaitIPv6(); |
| 411 } | 338 } |
| 412 | 339 |
| 413 TEST_F(PhysicalSocketTest, TestTcpIPv4) { | 340 TEST_F(PhysicalSocketTest, TestTcpIPv4) { |
| 414 SocketTest::TestTcpIPv4(); | 341 SocketTest::TestTcpIPv4(); |
| 415 } | 342 } |
| 416 | 343 |
| 417 // Crashes on Linux. See webrtc:4923. | 344 TEST_F(PhysicalSocketTest, TestTcpIPv6) { |
| 418 #if defined(WEBRTC_LINUX) | |
| 419 #define MAYBE_TestTcpIPv6 DISABLED_TestTcpIPv6 | |
| 420 #else | |
| 421 #define MAYBE_TestTcpIPv6 TestTcpIPv6 | |
| 422 #endif | |
| 423 TEST_F(PhysicalSocketTest, MAYBE_TestTcpIPv6) { | |
| 424 SocketTest::TestTcpIPv6(); | 345 SocketTest::TestTcpIPv6(); |
| 425 } | 346 } |
| 426 | 347 |
| 427 TEST_F(PhysicalSocketTest, TestUdpIPv4) { | 348 TEST_F(PhysicalSocketTest, TestUdpIPv4) { |
| 428 SocketTest::TestUdpIPv4(); | 349 SocketTest::TestUdpIPv4(); |
| 429 } | 350 } |
| 430 | 351 |
| 431 // Crashes on Linux. See webrtc:4923. | 352 TEST_F(PhysicalSocketTest, TestUdpIPv6) { |
| 432 #if defined(WEBRTC_LINUX) | |
| 433 #define MAYBE_TestUdpIPv6 DISABLED_TestUdpIPv6 | |
| 434 #else | |
| 435 #define MAYBE_TestUdpIPv6 TestUdpIPv6 | |
| 436 #endif | |
| 437 TEST_F(PhysicalSocketTest, MAYBE_TestUdpIPv6) { | |
| 438 SocketTest::TestUdpIPv6(); | 353 SocketTest::TestUdpIPv6(); |
| 439 } | 354 } |
| 440 | 355 |
| 441 // Disable for TSan v2, see | 356 // Disable for TSan v2, see |
| 442 // https://code.google.com/p/webrtc/issues/detail?id=3498 for details. | 357 // https://code.google.com/p/webrtc/issues/detail?id=3498 for details. |
| 443 // Also disable for MSan, see: | 358 // Also disable for MSan, see: |
| 444 // https://code.google.com/p/webrtc/issues/detail?id=4958 | 359 // https://code.google.com/p/webrtc/issues/detail?id=4958 |
| 445 // TODO(deadbeef): Enable again once test is reimplemented to be unflaky. | 360 // TODO(deadbeef): Enable again once test is reimplemented to be unflaky. |
| 446 // Also disable for ASan. | 361 // Also disable for ASan. |
| 447 // Disabled on Android: https://code.google.com/p/webrtc/issues/detail?id=4364 | 362 // Disabled on Android: https://code.google.com/p/webrtc/issues/detail?id=4364 |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 588 thread->Start(runnable.get()); | 503 thread->Start(runnable.get()); |
| 589 EXPECT_TRUE(ss_->Wait(1500, true)); | 504 EXPECT_TRUE(ss_->Wait(1500, true)); |
| 590 EXPECT_TRUE(ExpectSignal(SIGTERM)); | 505 EXPECT_TRUE(ExpectSignal(SIGTERM)); |
| 591 EXPECT_EQ(Thread::Current(), signaled_thread_); | 506 EXPECT_EQ(Thread::Current(), signaled_thread_); |
| 592 EXPECT_TRUE(ExpectNone()); | 507 EXPECT_TRUE(ExpectNone()); |
| 593 } | 508 } |
| 594 | 509 |
| 595 #endif | 510 #endif |
| 596 | 511 |
| 597 } // namespace rtc | 512 } // namespace rtc |
| OLD | NEW |