OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "net/quic/quic_stream_sequencer.h" | 5 #include "net/quic/quic_stream_sequencer.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
352 int OneToN(int n) { | 352 int OneToN(int n) { |
353 return base::RandInt(1, n); | 353 return base::RandInt(1, n); |
354 } | 354 } |
355 | 355 |
356 int MaybeProcessMaybeBuffer(const char* data, uint32 len) { | 356 int MaybeProcessMaybeBuffer(const char* data, uint32 len) { |
357 int to_process = len; | 357 int to_process = len; |
358 if (base::RandUint64() % 2 != 0) { | 358 if (base::RandUint64() % 2 != 0) { |
359 to_process = base::RandInt(0, len); | 359 to_process = base::RandInt(0, len); |
360 } | 360 } |
361 output_.append(data, to_process); | 361 output_.append(data, to_process); |
362 peeked_.append(data, to_process); | |
362 return to_process; | 363 return to_process; |
363 } | 364 } |
364 | 365 |
365 string output_; | 366 string output_; |
367 // Data which peek at using GetReadableRegion if we back up. | |
368 string peeked_; | |
366 FrameList list_; | 369 FrameList list_; |
367 }; | 370 }; |
368 | 371 |
369 // All frames are processed as soon as we have sequential data. | 372 // All frames are processed as soon as we have sequential data. |
370 // Infinite buffering, so all frames are acked right away. | 373 // Infinite buffering, so all frames are acked right away. |
371 TEST_F(QuicSequencerRandomTest, RandomFramesNoDroppingNoBackup) { | 374 TEST_F(QuicSequencerRandomTest, RandomFramesNoDroppingNoBackup) { |
372 InSequence s; | 375 InSequence s; |
373 for (size_t i = 0; i < list_.size(); ++i) { | 376 for (size_t i = 0; i < list_.size(); ++i) { |
374 string* data = &list_[i].second; | 377 string* data = &list_[i].second; |
375 EXPECT_CALL(stream_, ProcessRawData(StrEq(*data), data->size())) | 378 EXPECT_CALL(stream_, ProcessRawData(StrEq(*data), data->size())) |
376 .WillOnce(Return(data->size())); | 379 .WillOnce(Return(data->size())); |
377 } | 380 } |
378 | 381 |
379 while (!list_.empty()) { | 382 while (!list_.empty()) { |
380 int index = OneToN(list_.size()) - 1; | 383 int index = OneToN(list_.size()) - 1; |
381 LOG(ERROR) << "Sending index " << index << " " << list_[index].second; | 384 LOG(ERROR) << "Sending index " << index << " " << list_[index].second; |
382 OnFrame(list_[index].first, list_[index].second.data()); | 385 OnFrame(list_[index].first, list_[index].second.data()); |
383 | 386 |
384 list_.erase(list_.begin() + index); | 387 list_.erase(list_.begin() + index); |
385 } | 388 } |
386 } | 389 } |
387 | 390 |
391 TEST_F(QuicSequencerRandomTest, RandomFramesNoDroppingBackup) { | |
ramant (doing other things)
2015/07/17 01:27:45
Hi Ryan,
While porting this CL, found this test
| |
392 char buffer[10]; | |
393 iovec iov[2]; | |
394 iov[0].iov_base = &buffer[0]; | |
395 iov[0].iov_len = 5; | |
396 iov[1].iov_base = &buffer[5]; | |
397 iov[1].iov_len = 5; | |
398 | |
399 EXPECT_CALL(stream_, ProcessRawData(_, _)) | |
400 .Times(AnyNumber()) | |
401 .WillRepeatedly( | |
402 Invoke(this, &QuicSequencerRandomTest::MaybeProcessMaybeBuffer)); | |
403 | |
404 while (output_.size() != arraysize(kPayload) - 1) { | |
405 if (!list_.empty() && (base::RandUint64() % 2 == 0)) { // Send data | |
406 int index = OneToN(list_.size()) - 1; | |
407 OnFrame(list_[index].first, list_[index].second.data()); | |
408 list_.erase(list_.begin() + index); | |
409 } else { // Read data | |
410 bool has_bytes = sequencer_->HasBytesToRead(); | |
411 iovec peek_iov[20]; | |
412 int iovs_peeked = sequencer_->GetReadableRegions(peek_iov, 20); | |
413 if (has_bytes) { | |
414 ASSERT_LT(0, iovs_peeked); | |
415 } else { | |
416 ASSERT_EQ(0, iovs_peeked); | |
417 } | |
418 int total_bytes_to_peek = arraysize(buffer); | |
419 for (int i = 0; i < iovs_peeked; ++i) { | |
420 int bytes_to_peek = min<int>(peek_iov[i].iov_len, total_bytes_to_peek); | |
421 peeked_.append(static_cast<char*>(peek_iov[i].iov_base), bytes_to_peek); | |
422 total_bytes_to_peek -= bytes_to_peek; | |
423 if (total_bytes_to_peek == 0) { | |
424 break; | |
425 } | |
426 } | |
427 int bytes_read = sequencer_->Readv(iov, 2); | |
428 output_.append(buffer, bytes_read); | |
429 ASSERT_EQ(output_.size(), peeked_.size()); | |
430 } | |
431 } | |
432 EXPECT_EQ(0, strcmp(kPayload, output_.data())); | |
433 EXPECT_EQ(0, strcmp(kPayload, peeked_.data())); | |
434 } | |
435 | |
388 // Same as above, just using a different method for reading. | 436 // Same as above, just using a different method for reading. |
389 TEST_F(QuicStreamSequencerTest, MarkConsumed) { | 437 TEST_F(QuicStreamSequencerTest, MarkConsumed) { |
390 InSequence s; | 438 InSequence s; |
391 EXPECT_CALL(stream_, ProcessRawData(StrEq("abc"), 3)).WillOnce(Return(0)); | 439 EXPECT_CALL(stream_, ProcessRawData(StrEq("abc"), 3)).WillOnce(Return(0)); |
392 | 440 |
393 OnFrame(0, "abc"); | 441 OnFrame(0, "abc"); |
394 OnFrame(3, "def"); | 442 OnFrame(3, "def"); |
395 OnFrame(6, "ghi"); | 443 OnFrame(6, "ghi"); |
396 | 444 |
397 // abcdefghi buffered. | 445 // abcdefghi buffered. |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
506 QuicStreamFrame frame2(kClientDataStreamId1, false, 2, StringPiece("hello")); | 554 QuicStreamFrame frame2(kClientDataStreamId1, false, 2, StringPiece("hello")); |
507 EXPECT_TRUE(FrameOverlapsBufferedData(frame2)); | 555 EXPECT_TRUE(FrameOverlapsBufferedData(frame2)); |
508 EXPECT_CALL(stream_, CloseConnectionWithDetails(QUIC_INVALID_STREAM_FRAME, _)) | 556 EXPECT_CALL(stream_, CloseConnectionWithDetails(QUIC_INVALID_STREAM_FRAME, _)) |
509 .Times(1); | 557 .Times(1); |
510 sequencer_->OnStreamFrame(frame2); | 558 sequencer_->OnStreamFrame(frame2); |
511 } | 559 } |
512 | 560 |
513 } // namespace | 561 } // namespace |
514 } // namespace test | 562 } // namespace test |
515 } // namespace net | 563 } // namespace net |
OLD | NEW |