Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/file_path.h" | 5 #include "base/file_path.h" |
| 6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
| 7 #include "base/path_service.h" | 7 #include "base/path_service.h" |
| 8 #include "base/time.h" | 8 #include "base/time.h" |
| 9 #include "base/synchronization/waitable_event.h" | 9 #include "base/synchronization/waitable_event.h" |
| 10 #include "base/test/test_timeouts.h" | 10 #include "base/test/test_timeouts.h" |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 316 scoped_refptr<Session> client_session_; | 316 scoped_refptr<Session> client_session_; |
| 317 net::Socket* socket_1_; | 317 net::Socket* socket_1_; |
| 318 net::Socket* socket_2_; | 318 net::Socket* socket_2_; |
| 319 base::WaitableEvent done_event_; | 319 base::WaitableEvent done_event_; |
| 320 }; | 320 }; |
| 321 | 321 |
| 322 class TCPChannelTester : public ChannelTesterBase { | 322 class TCPChannelTester : public ChannelTesterBase { |
| 323 public: | 323 public: |
| 324 TCPChannelTester(MessageLoop* message_loop, | 324 TCPChannelTester(MessageLoop* message_loop, |
| 325 Session* host_session, | 325 Session* host_session, |
| 326 Session* client_session) | 326 Session* client_session, |
| 327 int message_size, int message_count) | |
| 327 : ChannelTesterBase(message_loop, host_session, client_session), | 328 : ChannelTesterBase(message_loop, host_session, client_session), |
| 328 ALLOW_THIS_IN_INITIALIZER_LIST( | 329 ALLOW_THIS_IN_INITIALIZER_LIST( |
| 329 write_cb_(this, &TCPChannelTester::OnWritten)), | 330 write_cb_(this, &TCPChannelTester::OnWritten)), |
| 330 ALLOW_THIS_IN_INITIALIZER_LIST( | 331 ALLOW_THIS_IN_INITIALIZER_LIST( |
| 331 read_cb_(this, &TCPChannelTester::OnRead)), | 332 read_cb_(this, &TCPChannelTester::OnRead)), |
| 332 write_errors_(0), | 333 write_errors_(0), |
| 333 read_errors_(0) { | 334 read_errors_(0), |
| 335 message_size_(message_size), | |
| 336 message_count_(message_count), | |
| 337 test_data_size_(message_size * message_count) { | |
| 334 } | 338 } |
| 335 | 339 |
| 336 virtual ~TCPChannelTester() { } | 340 virtual ~TCPChannelTester() { } |
| 337 | 341 |
| 338 virtual void CheckResults() { | 342 virtual void CheckResults() { |
| 339 EXPECT_EQ(0, write_errors_); | 343 EXPECT_EQ(0, write_errors_); |
| 340 EXPECT_EQ(0, read_errors_); | 344 EXPECT_EQ(0, read_errors_); |
| 341 | 345 |
| 342 ASSERT_EQ(kTestDataSize + kMessageSize, input_buffer_->capacity()); | 346 ASSERT_EQ(test_data_size_ + message_size_, input_buffer_->capacity()); |
| 343 | 347 |
| 344 output_buffer_->SetOffset(0); | 348 output_buffer_->SetOffset(0); |
| 345 ASSERT_EQ(kTestDataSize, output_buffer_->size()); | 349 ASSERT_EQ(test_data_size_, output_buffer_->size()); |
| 346 | 350 |
| 347 EXPECT_EQ(0, memcmp(output_buffer_->data(), | 351 EXPECT_EQ(0, memcmp(output_buffer_->data(), |
| 348 input_buffer_->StartOfBuffer(), kTestDataSize)); | 352 input_buffer_->StartOfBuffer(), test_data_size_)); |
| 349 } | 353 } |
| 350 | 354 |
| 351 protected: | 355 protected: |
| 352 virtual void InitBuffers() { | 356 virtual void InitBuffers() { |
| 353 output_buffer_ = new net::DrainableIOBuffer( | 357 output_buffer_ = new net::DrainableIOBuffer( |
| 354 new net::IOBuffer(kTestDataSize), kTestDataSize); | 358 new net::IOBuffer(test_data_size_), test_data_size_); |
| 355 memset(output_buffer_->data(), 123, kTestDataSize); | 359 memset(output_buffer_->data(), 123, test_data_size_); |
| 356 | 360 |
| 357 input_buffer_ = new net::GrowableIOBuffer(); | 361 input_buffer_ = new net::GrowableIOBuffer(); |
| 358 // Always keep kMessageSize bytes available at the end of the input buffer. | 362 // Always keep message_size_ bytes available at the end of the input buffer. |
| 359 input_buffer_->SetCapacity(kMessageSize); | 363 input_buffer_->SetCapacity(message_size_); |
| 360 } | 364 } |
| 361 | 365 |
| 362 virtual void DoWrite() { | 366 virtual void DoWrite() { |
| 363 int result = 1; | 367 int result = 1; |
| 364 while (result > 0) { | 368 while (result > 0) { |
| 365 if (output_buffer_->BytesRemaining() == 0) | 369 if (output_buffer_->BytesRemaining() == 0) |
| 366 break; | 370 break; |
| 367 | 371 |
| 368 int bytes_to_write = std::min(output_buffer_->BytesRemaining(), | 372 int bytes_to_write = std::min(output_buffer_->BytesRemaining(), |
| 369 kMessageSize); | 373 message_size_); |
| 370 result = socket_1_->Write(output_buffer_, bytes_to_write, &write_cb_); | 374 result = socket_1_->Write(output_buffer_, bytes_to_write, &write_cb_); |
| 371 HandleWriteResult(result); | 375 HandleWriteResult(result); |
| 372 }; | 376 }; |
| 373 } | 377 } |
| 374 | 378 |
| 375 void OnWritten(int result) { | 379 void OnWritten(int result) { |
| 376 HandleWriteResult(result); | 380 HandleWriteResult(result); |
| 377 DoWrite(); | 381 DoWrite(); |
| 378 } | 382 } |
| 379 | 383 |
| 380 void HandleWriteResult(int result) { | 384 void HandleWriteResult(int result) { |
| 381 if (result <= 0 && result != net::ERR_IO_PENDING) { | 385 if (result <= 0 && result != net::ERR_IO_PENDING) { |
| 382 LOG(ERROR) << "Received error " << result << " when trying to write"; | 386 LOG(ERROR) << "Received error " << result << " when trying to write"; |
| 383 write_errors_++; | 387 write_errors_++; |
| 384 done_event_.Signal(); | 388 done_event_.Signal(); |
| 385 } else if (result > 0) { | 389 } else if (result > 0) { |
| 386 output_buffer_->DidConsume(result); | 390 output_buffer_->DidConsume(result); |
| 387 } | 391 } |
| 388 } | 392 } |
| 389 | 393 |
| 390 virtual void DoRead() { | 394 virtual void DoRead() { |
| 391 int result = 1; | 395 int result = 1; |
| 392 while (result > 0) { | 396 while (result > 0) { |
| 393 input_buffer_->set_offset(input_buffer_->capacity() - kMessageSize); | 397 input_buffer_->set_offset(input_buffer_->capacity() - message_size_); |
| 394 | 398 |
| 395 result = socket_2_->Read(input_buffer_, kMessageSize, &read_cb_); | 399 result = socket_2_->Read(input_buffer_, message_size_, &read_cb_); |
| 396 HandleReadResult(result); | 400 HandleReadResult(result); |
| 397 }; | 401 }; |
| 398 } | 402 } |
| 399 | 403 |
| 400 void OnRead(int result) { | 404 void OnRead(int result) { |
| 401 HandleReadResult(result); | 405 HandleReadResult(result); |
| 402 if (!done_event_.IsSignaled()) | 406 if (!done_event_.IsSignaled()) |
| 403 DoRead(); // Don't try to read again when we are done reading. | 407 DoRead(); // Don't try to read again when we are done reading. |
| 404 } | 408 } |
| 405 | 409 |
| 406 void HandleReadResult(int result) { | 410 void HandleReadResult(int result) { |
| 407 if (result <= 0 && result != net::ERR_IO_PENDING) { | 411 if (result <= 0 && result != net::ERR_IO_PENDING) { |
| 408 if (!done_event_.IsSignaled()) { | 412 if (!done_event_.IsSignaled()) { |
| 409 LOG(ERROR) << "Received error " << result << " when trying to read"; | 413 LOG(ERROR) << "Received error " << result << " when trying to read"; |
| 410 read_errors_++; | 414 read_errors_++; |
| 411 done_event_.Signal(); | 415 done_event_.Signal(); |
| 412 } | 416 } |
| 413 } else if (result > 0) { | 417 } else if (result > 0) { |
| 414 // Allocate memory for the next read. | 418 // Allocate memory for the next read. |
| 415 input_buffer_->SetCapacity(input_buffer_->capacity() + result); | 419 input_buffer_->SetCapacity(input_buffer_->capacity() + result); |
| 416 if (input_buffer_->capacity() == kTestDataSize + kMessageSize) | 420 if (input_buffer_->capacity() == test_data_size_ + message_size_) |
| 417 done_event_.Signal(); | 421 done_event_.Signal(); |
| 418 } | 422 } |
| 419 } | 423 } |
| 420 | 424 |
| 421 private: | |
| 422 scoped_refptr<net::DrainableIOBuffer> output_buffer_; | 425 scoped_refptr<net::DrainableIOBuffer> output_buffer_; |
| 423 scoped_refptr<net::GrowableIOBuffer> input_buffer_; | 426 scoped_refptr<net::GrowableIOBuffer> input_buffer_; |
| 424 | 427 |
| 425 net::CompletionCallbackImpl<TCPChannelTester> write_cb_; | 428 net::CompletionCallbackImpl<TCPChannelTester> write_cb_; |
| 426 net::CompletionCallbackImpl<TCPChannelTester> read_cb_; | 429 net::CompletionCallbackImpl<TCPChannelTester> read_cb_; |
| 427 int write_errors_; | 430 int write_errors_; |
| 428 int read_errors_; | 431 int read_errors_; |
| 432 int message_size_; | |
| 433 int message_count_; | |
| 434 int test_data_size_; | |
| 435 }; | |
| 436 | |
| 437 class ChannelLatencyTester : public TCPChannelTester { | |
| 438 public: | |
| 439 ChannelLatencyTester(MessageLoop* message_loop, | |
| 440 Session* host_session, | |
| 441 Session* client_session, | |
| 442 int message_size) | |
| 443 : TCPChannelTester(message_loop, host_session, | |
| 444 client_session, message_size, 1) { | |
| 445 CHECK(message_size >= 8); | |
| 446 } | |
| 447 | |
| 448 virtual ~ChannelLatencyTester() { } | |
| 449 | |
| 450 virtual void CheckResults() { | |
| 451 } | |
| 452 | |
| 453 base::TimeDelta GetLatency() { | |
| 454 return base::Time::Now() - start_time_; | |
| 455 } | |
| 456 | |
| 457 protected: | |
| 458 virtual void InitBuffers() { | |
| 459 TCPChannelTester::InitBuffers(); | |
| 460 | |
| 461 start_time_ = base::Time::Now(); | |
| 462 } | |
| 463 | |
| 464 base::Time start_time_; | |
| 429 }; | 465 }; |
| 430 | 466 |
| 431 class UDPChannelTester : public ChannelTesterBase { | 467 class UDPChannelTester : public ChannelTesterBase { |
| 432 public: | 468 public: |
| 433 UDPChannelTester(MessageLoop* message_loop, | 469 UDPChannelTester(MessageLoop* message_loop, |
| 434 Session* host_session, | 470 Session* host_session, |
| 435 Session* client_session) | 471 Session* client_session) |
| 436 : ChannelTesterBase(message_loop, host_session, client_session), | 472 : ChannelTesterBase(message_loop, host_session, client_session), |
| 437 ALLOW_THIS_IN_INITIALIZER_LIST( | 473 ALLOW_THIS_IN_INITIALIZER_LIST( |
| 438 write_cb_(this, &UDPChannelTester::OnWritten)), | 474 write_cb_(this, &UDPChannelTester::OnWritten)), |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 599 CreateServerPair(); | 635 CreateServerPair(); |
| 600 ASSERT_TRUE(InitiateConnection()); | 636 ASSERT_TRUE(InitiateConnection()); |
| 601 } | 637 } |
| 602 | 638 |
| 603 // Verify that data can be transmitted over the event channel. | 639 // Verify that data can be transmitted over the event channel. |
| 604 TEST_F(JingleSessionTest, TestControlChannel) { | 640 TEST_F(JingleSessionTest, TestControlChannel) { |
| 605 CreateServerPair(); | 641 CreateServerPair(); |
| 606 ASSERT_TRUE(InitiateConnection()); | 642 ASSERT_TRUE(InitiateConnection()); |
| 607 scoped_refptr<TCPChannelTester> tester( | 643 scoped_refptr<TCPChannelTester> tester( |
| 608 new TCPChannelTester(thread_.message_loop(), host_session_, | 644 new TCPChannelTester(thread_.message_loop(), host_session_, |
| 609 client_session_)); | 645 client_session_, kMessageSize, kMessages)); |
| 610 tester->Start(ChannelTesterBase::CONTROL); | 646 tester->Start(ChannelTesterBase::CONTROL); |
| 611 ASSERT_TRUE(tester->WaitFinished()); | 647 ASSERT_TRUE(tester->WaitFinished()); |
| 612 tester->CheckResults(); | 648 tester->CheckResults(); |
| 613 | 649 |
| 614 // Connections must be closed while |tester| still exists. | 650 // Connections must be closed while |tester| still exists. |
| 615 CloseSessions(); | 651 CloseSessions(); |
| 616 } | 652 } |
| 617 | 653 |
| 618 // Verify that data can be transmitted over the video channel. | 654 // Verify that data can be transmitted over the video channel. |
| 619 TEST_F(JingleSessionTest, TestVideoChannel) { | 655 TEST_F(JingleSessionTest, TestVideoChannel) { |
| 620 CreateServerPair(); | 656 CreateServerPair(); |
| 621 ASSERT_TRUE(InitiateConnection()); | 657 ASSERT_TRUE(InitiateConnection()); |
| 622 scoped_refptr<TCPChannelTester> tester( | 658 scoped_refptr<TCPChannelTester> tester( |
| 623 new TCPChannelTester(thread_.message_loop(), host_session_, | 659 new TCPChannelTester(thread_.message_loop(), host_session_, |
| 624 client_session_)); | 660 client_session_, kMessageSize, kMessageSize)); |
| 625 tester->Start(ChannelTesterBase::VIDEO); | 661 tester->Start(ChannelTesterBase::VIDEO); |
| 626 ASSERT_TRUE(tester->WaitFinished()); | 662 ASSERT_TRUE(tester->WaitFinished()); |
| 627 tester->CheckResults(); | 663 tester->CheckResults(); |
| 628 | 664 |
| 629 // Connections must be closed while |tester| still exists. | 665 // Connections must be closed while |tester| still exists. |
| 630 CloseSessions(); | 666 CloseSessions(); |
| 631 } | 667 } |
| 632 | 668 |
| 633 // Verify that data can be transmitted over the event channel. | 669 // Verify that data can be transmitted over the event channel. |
| 634 TEST_F(JingleSessionTest, TestEventChannel) { | 670 TEST_F(JingleSessionTest, TestEventChannel) { |
| 635 CreateServerPair(); | 671 CreateServerPair(); |
| 636 ASSERT_TRUE(InitiateConnection()); | 672 ASSERT_TRUE(InitiateConnection()); |
| 637 scoped_refptr<TCPChannelTester> tester( | 673 scoped_refptr<TCPChannelTester> tester( |
| 638 new TCPChannelTester(thread_.message_loop(), host_session_, | 674 new TCPChannelTester(thread_.message_loop(), host_session_, |
| 639 client_session_)); | 675 client_session_, kMessageSize, kMessageSize)); |
| 640 tester->Start(ChannelTesterBase::EVENT); | 676 tester->Start(ChannelTesterBase::EVENT); |
| 641 ASSERT_TRUE(tester->WaitFinished()); | 677 ASSERT_TRUE(tester->WaitFinished()); |
| 642 tester->CheckResults(); | 678 tester->CheckResults(); |
| 643 | 679 |
| 644 // Connections must be closed while |tester| still exists. | 680 // Connections must be closed while |tester| still exists. |
| 645 CloseSessions(); | 681 CloseSessions(); |
| 646 } | 682 } |
| 647 | 683 |
| 648 // Verify that data can be transmitted over the video RTP channel. | 684 // Verify that data can be transmitted over the video RTP channel. |
| 649 TEST_F(JingleSessionTest, TestVideoRtpChannel) { | 685 TEST_F(JingleSessionTest, TestVideoRtpChannel) { |
| 650 CreateServerPair(); | 686 CreateServerPair(); |
| 651 ASSERT_TRUE(InitiateConnection()); | 687 ASSERT_TRUE(InitiateConnection()); |
| 652 scoped_refptr<UDPChannelTester> tester( | 688 scoped_refptr<UDPChannelTester> tester( |
| 653 new UDPChannelTester(thread_.message_loop(), host_session_, | 689 new UDPChannelTester(thread_.message_loop(), host_session_, |
| 654 client_session_)); | 690 client_session_)); |
| 655 tester->Start(ChannelTesterBase::VIDEO_RTP); | 691 tester->Start(ChannelTesterBase::VIDEO_RTP); |
| 656 ASSERT_TRUE(tester->WaitFinished()); | 692 ASSERT_TRUE(tester->WaitFinished()); |
| 657 tester->CheckResults(); | 693 tester->CheckResults(); |
| 658 | 694 |
| 659 // Connections must be closed while |tester| still exists. | 695 // Connections must be closed while |tester| still exists. |
| 660 CloseSessions(); | 696 CloseSessions(); |
| 661 } | 697 } |
| 662 | 698 |
| 699 TEST_F(JingleSessionTest, TestLatency) { | |
|
Sergey Ulanov
2011/06/28 18:34:26
Add comment that explain what this test verifies.
| |
| 700 CreateServerPair(); | |
| 701 ASSERT_TRUE(InitiateConnection()); | |
| 702 scoped_refptr<ChannelLatencyTester> tester; | |
| 703 | |
| 704 tester = new ChannelLatencyTester(thread_.message_loop(), host_session_, | |
| 705 client_session_, 512); | |
| 706 tester->Start(ChannelTesterBase::VIDEO); | |
| 707 ASSERT_TRUE(tester->WaitFinished()); | |
| 708 LOG(INFO) << "Latency for 512 bytes " | |
| 709 << tester->GetLatency().InMilliseconds() << " ms."; | |
| 710 | |
| 711 tester = new ChannelLatencyTester(thread_.message_loop(), host_session_, | |
| 712 client_session_, 1024); | |
| 713 tester->Start(ChannelTesterBase::VIDEO); | |
| 714 ASSERT_TRUE(tester->WaitFinished()); | |
| 715 LOG(INFO) << "Latency for 1024 bytes " | |
| 716 << tester->GetLatency().InMilliseconds() << " ms."; | |
| 717 | |
| 718 tester = new ChannelLatencyTester(thread_.message_loop(), host_session_, | |
| 719 client_session_, 51200); | |
| 720 tester->Start(ChannelTesterBase::VIDEO); | |
| 721 ASSERT_TRUE(tester->WaitFinished()); | |
| 722 LOG(INFO) << "Latency for 50k bytes " | |
| 723 << tester->GetLatency().InMilliseconds() << " ms."; | |
| 724 | |
| 725 tester = new ChannelLatencyTester(thread_.message_loop(), host_session_, | |
| 726 client_session_, 512000); | |
| 727 tester->Start(ChannelTesterBase::VIDEO); | |
| 728 ASSERT_TRUE(tester->WaitFinished()); | |
| 729 LOG(INFO) << "Latency for 500k bytes " | |
| 730 << tester->GetLatency().InMilliseconds() << " ms."; | |
| 731 | |
| 732 // Connections must be closed while |tester| still exists. | |
| 733 CloseSessions(); | |
| 734 } | |
| 735 | |
| 663 #endif | 736 #endif |
| 664 | 737 |
| 665 } // namespace protocol | 738 } // namespace protocol |
| 666 } // namespace remoting | 739 } // namespace remoting |
| OLD | NEW |