Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(705)

Side by Side Diff: webrtc/base/virtualsocket_unittest.cc

Issue 1944683002: Read recv timestamps from socket (posix only). (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Fix win build. Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2006 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2006 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
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 EXPECT_EQ(b->GetRemoteAddress(), a->GetLocalAddress()); 457 EXPECT_EQ(b->GetRemoteAddress(), a->GetLocalAddress());
458 458
459 EXPECT_EQ(1, a->Send("a", 1)); 459 EXPECT_EQ(1, a->Send("a", 1));
460 b->Close(); 460 b->Close();
461 EXPECT_EQ(1, a->Send("b", 1)); 461 EXPECT_EQ(1, a->Send("b", 1));
462 462
463 ss_->ProcessMessagesUntilIdle(); 463 ss_->ProcessMessagesUntilIdle();
464 464
465 char buffer[10]; 465 char buffer[10];
466 EXPECT_FALSE(sink.Check(b.get(), testing::SSE_READ)); 466 EXPECT_FALSE(sink.Check(b.get(), testing::SSE_READ));
467 EXPECT_EQ(-1, b->Recv(buffer, 10)); 467 int64_t timestamp;
468 EXPECT_EQ(-1, b->Recv(buffer, 10, &timestamp));
468 469
469 EXPECT_TRUE(sink.Check(a, testing::SSE_CLOSE)); 470 EXPECT_TRUE(sink.Check(a, testing::SSE_CLOSE));
470 EXPECT_EQ(a->GetState(), AsyncSocket::CS_CLOSED); 471 EXPECT_EQ(a->GetState(), AsyncSocket::CS_CLOSED);
471 EXPECT_EQ(a->GetRemoteAddress(), kEmptyAddr); 472 EXPECT_EQ(a->GetRemoteAddress(), kEmptyAddr);
472 473
473 // No signal for Closer 474 // No signal for Closer
474 EXPECT_FALSE(sink.Check(b.get(), testing::SSE_CLOSE)); 475 EXPECT_FALSE(sink.Check(b.get(), testing::SSE_CLOSE));
475 EXPECT_EQ(b->GetState(), AsyncSocket::CS_CLOSED); 476 EXPECT_EQ(b->GetState(), AsyncSocket::CS_CLOSED);
476 EXPECT_EQ(b->GetRemoteAddress(), kEmptyAddr); 477 EXPECT_EQ(b->GetRemoteAddress(), kEmptyAddr);
477 } 478 }
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 ss_->ProcessMessagesUntilIdle(); 525 ss_->ProcessMessagesUntilIdle();
525 EXPECT_FALSE(sink.Check(a, testing::SSE_WRITE)); 526 EXPECT_FALSE(sink.Check(a, testing::SSE_WRITE));
526 EXPECT_FALSE(sink.Check(b, testing::SSE_READ)); 527 EXPECT_FALSE(sink.Check(b, testing::SSE_READ));
527 528
528 // No more room in send or receive buffer 529 // No more room in send or receive buffer
529 result = a->Send(send_buffer + send_pos, kDataSize - send_pos); 530 result = a->Send(send_buffer + send_pos, kDataSize - send_pos);
530 EXPECT_EQ(-1, result); 531 EXPECT_EQ(-1, result);
531 EXPECT_TRUE(a->IsBlocking()); 532 EXPECT_TRUE(a->IsBlocking());
532 533
533 // Read a subset of the data 534 // Read a subset of the data
534 result = b->Recv(recv_buffer + recv_pos, 500); 535 int64_t timestamp;
536 result = b->Recv(recv_buffer + recv_pos, 500, &timestamp);
535 EXPECT_EQ(500, result); 537 EXPECT_EQ(500, result);
536 recv_pos += result; 538 recv_pos += result;
537 539
538 ss_->ProcessMessagesUntilIdle(); 540 ss_->ProcessMessagesUntilIdle();
539 EXPECT_TRUE(sink.Check(a, testing::SSE_WRITE)); 541 EXPECT_TRUE(sink.Check(a, testing::SSE_WRITE));
540 EXPECT_TRUE(sink.Check(b, testing::SSE_READ)); 542 EXPECT_TRUE(sink.Check(b, testing::SSE_READ));
541 543
542 // Room for more on the sending side 544 // Room for more on the sending side
543 result = a->Send(send_buffer + send_pos, kDataSize - send_pos); 545 result = a->Send(send_buffer + send_pos, kDataSize - send_pos);
544 EXPECT_EQ(500, result); 546 EXPECT_EQ(500, result);
545 send_pos += result; 547 send_pos += result;
546 548
547 // Empty the recv buffer 549 // Empty the recv buffer
548 while (true) { 550 while (true) {
549 result = b->Recv(recv_buffer + recv_pos, kDataSize - recv_pos); 551 result =
552 b->Recv(recv_buffer + recv_pos, kDataSize - recv_pos, &timestamp);
550 if (result < 0) { 553 if (result < 0) {
551 EXPECT_EQ(-1, result); 554 EXPECT_EQ(-1, result);
552 EXPECT_TRUE(b->IsBlocking()); 555 EXPECT_TRUE(b->IsBlocking());
553 break; 556 break;
554 } 557 }
555 recv_pos += result; 558 recv_pos += result;
556 } 559 }
557 560
558 ss_->ProcessMessagesUntilIdle(); 561 ss_->ProcessMessagesUntilIdle();
559 EXPECT_TRUE(sink.Check(b, testing::SSE_READ)); 562 EXPECT_TRUE(sink.Check(b, testing::SSE_READ));
560 563
561 // Continue to empty the recv buffer 564 // Continue to empty the recv buffer
562 while (true) { 565 while (true) {
563 result = b->Recv(recv_buffer + recv_pos, kDataSize - recv_pos); 566 result =
567 b->Recv(recv_buffer + recv_pos, kDataSize - recv_pos, &timestamp);
564 if (result < 0) { 568 if (result < 0) {
565 EXPECT_EQ(-1, result); 569 EXPECT_EQ(-1, result);
566 EXPECT_TRUE(b->IsBlocking()); 570 EXPECT_TRUE(b->IsBlocking());
567 break; 571 break;
568 } 572 }
569 recv_pos += result; 573 recv_pos += result;
570 } 574 }
571 575
572 // Send last of the data 576 // Send last of the data
573 result = a->Send(send_buffer + send_pos, kDataSize - send_pos); 577 result = a->Send(send_buffer + send_pos, kDataSize - send_pos);
574 EXPECT_EQ(500, result); 578 EXPECT_EQ(500, result);
575 send_pos += result; 579 send_pos += result;
576 580
577 ss_->ProcessMessagesUntilIdle(); 581 ss_->ProcessMessagesUntilIdle();
578 EXPECT_TRUE(sink.Check(b, testing::SSE_READ)); 582 EXPECT_TRUE(sink.Check(b, testing::SSE_READ));
579 583
580 // Receive the last of the data 584 // Receive the last of the data
581 while (true) { 585 while (true) {
582 result = b->Recv(recv_buffer + recv_pos, kDataSize - recv_pos); 586 result =
587 b->Recv(recv_buffer + recv_pos, kDataSize - recv_pos, &timestamp);
583 if (result < 0) { 588 if (result < 0) {
584 EXPECT_EQ(-1, result); 589 EXPECT_EQ(-1, result);
585 EXPECT_TRUE(b->IsBlocking()); 590 EXPECT_TRUE(b->IsBlocking());
586 break; 591 break;
587 } 592 }
588 recv_pos += result; 593 recv_pos += result;
589 } 594 }
590 595
591 ss_->ProcessMessagesUntilIdle(); 596 ss_->ProcessMessagesUntilIdle();
592 EXPECT_FALSE(sink.Check(b, testing::SSE_READ)); 597 EXPECT_FALSE(sink.Check(b, testing::SSE_READ));
(...skipping 26 matching lines...) Expand all
619 char buffer[2] = { 0, 0 }; 624 char buffer[2] = { 0, 0 };
620 const char cNumPackets = 10; 625 const char cNumPackets = 10;
621 for (char i = 0; i < cNumPackets; ++i) { 626 for (char i = 0; i < cNumPackets; ++i) {
622 buffer[0] = '0' + i; 627 buffer[0] = '0' + i;
623 EXPECT_EQ(1, a->Send(buffer, 1)); 628 EXPECT_EQ(1, a->Send(buffer, 1));
624 } 629 }
625 630
626 ss_->ProcessMessagesUntilIdle(); 631 ss_->ProcessMessagesUntilIdle();
627 632
628 for (char i = 0; i < cNumPackets; ++i) { 633 for (char i = 0; i < cNumPackets; ++i) {
629 EXPECT_EQ(1, b->Recv(buffer, sizeof(buffer))); 634 int64_t timestamp;
635 EXPECT_EQ(1, b->Recv(buffer, sizeof(buffer), &timestamp));
630 EXPECT_EQ(static_cast<char>('0' + i), buffer[0]); 636 EXPECT_EQ(static_cast<char>('0' + i), buffer[0]);
631 } 637 }
632 638
633 // Next, deliver packets at random intervals 639 // Next, deliver packets at random intervals
634 const uint32_t mean = 50; 640 const uint32_t mean = 50;
635 const uint32_t stddev = 50; 641 const uint32_t stddev = 50;
636 642
637 ss_->set_delay_mean(mean); 643 ss_->set_delay_mean(mean);
638 ss_->set_delay_stddev(stddev); 644 ss_->set_delay_stddev(stddev);
639 ss_->UpdateDelayDistribution(); 645 ss_->UpdateDelayDistribution();
640 646
641 for (char i = 0; i < cNumPackets; ++i) { 647 for (char i = 0; i < cNumPackets; ++i) {
642 buffer[0] = 'A' + i; 648 buffer[0] = 'A' + i;
643 EXPECT_EQ(1, a->Send(buffer, 1)); 649 EXPECT_EQ(1, a->Send(buffer, 1));
644 } 650 }
645 651
646 ss_->ProcessMessagesUntilIdle(); 652 ss_->ProcessMessagesUntilIdle();
647 653
648 for (char i = 0; i < cNumPackets; ++i) { 654 for (char i = 0; i < cNumPackets; ++i) {
649 EXPECT_EQ(1, b->Recv(buffer, sizeof(buffer))); 655 int64_t timestamp;
656 EXPECT_EQ(1, b->Recv(buffer, sizeof(buffer), &timestamp));
650 EXPECT_EQ(static_cast<char>('A' + i), buffer[0]); 657 EXPECT_EQ(static_cast<char>('A' + i), buffer[0]);
651 } 658 }
652 } 659 }
653 660
654 // It is important that initial_addr's port has to be 0 such that the 661 // It is important that initial_addr's port has to be 0 such that the
655 // incremental port behavior could ensure the 2 Binds result in different 662 // incremental port behavior could ensure the 2 Binds result in different
656 // address. 663 // address.
657 void BandwidthTest(const SocketAddress& initial_addr) { 664 void BandwidthTest(const SocketAddress& initial_addr) {
658 AsyncSocket* send_socket = 665 AsyncSocket* send_socket =
659 ss_->CreateAsyncSocket(initial_addr.family(), SOCK_DGRAM); 666 ss_->CreateAsyncSocket(initial_addr.family(), SOCK_DGRAM);
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after
1052 << " N=" << kTestSamples[sidx]; 1059 << " N=" << kTestSamples[sidx];
1053 EXPECT_NEAR(kStdDev, stddev, 0.1 * kStdDev) 1060 EXPECT_NEAR(kStdDev, stddev, 0.1 * kStdDev)
1054 << "M=" << kTestMean[midx] 1061 << "M=" << kTestMean[midx]
1055 << " SD=" << kStdDev 1062 << " SD=" << kStdDev
1056 << " N=" << kTestSamples[sidx]; 1063 << " N=" << kTestSamples[sidx];
1057 delete f; 1064 delete f;
1058 } 1065 }
1059 } 1066 }
1060 } 1067 }
1061 } 1068 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698