| OLD | NEW |
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2015 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 #include "net/quic/core/quic_stream_sequencer_buffer.h" | 4 #include "net/quic/core/quic_stream_sequencer_buffer.h" |
| 5 | 5 |
| 6 #include <algorithm> | 6 #include <algorithm> |
| 7 #include <limits> | 7 #include <limits> |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 EXPECT_TRUE(buffer_->HasBytesToRead()); | 409 EXPECT_TRUE(buffer_->HasBytesToRead()); |
| 410 EXPECT_EQ(2u, helper_->frame_arrival_time_map()->size()); | 410 EXPECT_EQ(2u, helper_->frame_arrival_time_map()->size()); |
| 411 // Read into a iovec array with total capacity of 120 bytes. | 411 // Read into a iovec array with total capacity of 120 bytes. |
| 412 char dest[120]; | 412 char dest[120]; |
| 413 iovec iovecs[3]{iovec{dest, 40}, iovec{dest + 40, 40}, iovec{dest + 80, 40}}; | 413 iovec iovecs[3]{iovec{dest, 40}, iovec{dest + 40, 40}, iovec{dest + 80, 40}}; |
| 414 size_t read = buffer_->Readv(iovecs, 3); | 414 size_t read = buffer_->Readv(iovecs, 3); |
| 415 EXPECT_EQ(100u, read); | 415 EXPECT_EQ(100u, read); |
| 416 EXPECT_EQ(100u, buffer_->BytesConsumed()); | 416 EXPECT_EQ(100u, buffer_->BytesConsumed()); |
| 417 EXPECT_EQ(source, string(dest, read)); | 417 EXPECT_EQ(source, string(dest, read)); |
| 418 EXPECT_EQ(1u, helper_->frame_arrival_time_map()->size()); | 418 EXPECT_EQ(1u, helper_->frame_arrival_time_map()->size()); |
| 419 if (FLAGS_quic_sequencer_buffer_retire_block_in_time) { | 419 // The first block should be released as its data has been read out. |
| 420 // The first block should be released as its data has been read out. | 420 EXPECT_EQ(nullptr, helper_->GetBlock(0)); |
| 421 EXPECT_EQ(nullptr, helper_->GetBlock(0)); | |
| 422 } | |
| 423 EXPECT_TRUE(helper_->CheckBufferInvariants()); | 421 EXPECT_TRUE(helper_->CheckBufferInvariants()); |
| 424 } | 422 } |
| 425 | 423 |
| 426 TEST_F(QuicStreamSequencerBufferTest, ReadvAcrossBlocks) { | 424 TEST_F(QuicStreamSequencerBufferTest, ReadvAcrossBlocks) { |
| 427 string source(kBlockSizeBytes + 50, 'a'); | 425 string source(kBlockSizeBytes + 50, 'a'); |
| 428 // Write 1st block to full and extand 50 bytes to next block. | 426 // Write 1st block to full and extand 50 bytes to next block. |
| 429 size_t written; | 427 size_t written; |
| 430 buffer_->OnStreamData(0, source, clock_.ApproximateNow(), &written, | 428 buffer_->OnStreamData(0, source, clock_.ApproximateNow(), &written, |
| 431 &error_details_); | 429 &error_details_); |
| 432 EXPECT_EQ(source.size(), helper_->ReadableBytes()); | 430 EXPECT_EQ(source.size(), helper_->ReadableBytes()); |
| (...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 863 EXPECT_EQ(max_capacity_bytes_ + 512, buffer_->BytesConsumed()); | 861 EXPECT_EQ(max_capacity_bytes_ + 512, buffer_->BytesConsumed()); |
| 864 EXPECT_TRUE(buffer_->Empty()); | 862 EXPECT_TRUE(buffer_->Empty()); |
| 865 EXPECT_TRUE(helper_->CheckBufferInvariants()); | 863 EXPECT_TRUE(helper_->CheckBufferInvariants()); |
| 866 // Clear buffer at this point should still preserve BytesConsumed(). | 864 // Clear buffer at this point should still preserve BytesConsumed(). |
| 867 buffer_->Clear(); | 865 buffer_->Clear(); |
| 868 EXPECT_EQ(max_capacity_bytes_ + 512, buffer_->BytesConsumed()); | 866 EXPECT_EQ(max_capacity_bytes_ + 512, buffer_->BytesConsumed()); |
| 869 EXPECT_TRUE(helper_->CheckBufferInvariants()); | 867 EXPECT_TRUE(helper_->CheckBufferInvariants()); |
| 870 } | 868 } |
| 871 | 869 |
| 872 TEST_F(QuicStreamSequencerBufferTest, TooManyGaps) { | 870 TEST_F(QuicStreamSequencerBufferTest, TooManyGaps) { |
| 873 QuicFlagSaver flags; | |
| 874 FLAGS_quic_limit_frame_gaps_in_buffer = true; | |
| 875 // Make sure max capacity is large enough that it is possible to have more | 871 // Make sure max capacity is large enough that it is possible to have more |
| 876 // than |kMaxNumGapsAllowed| number of gaps. | 872 // than |kMaxNumGapsAllowed| number of gaps. |
| 877 max_capacity_bytes_ = 3 * kBlockSizeBytes; | 873 max_capacity_bytes_ = 3 * kBlockSizeBytes; |
| 878 // Feed buffer with 1-byte discontiguous frames. e.g. [1,2), [3,4), [5,6)... | 874 // Feed buffer with 1-byte discontiguous frames. e.g. [1,2), [3,4), [5,6)... |
| 879 for (QuicStreamOffset begin = 1; begin <= max_capacity_bytes_; begin += 2) { | 875 for (QuicStreamOffset begin = 1; begin <= max_capacity_bytes_; begin += 2) { |
| 880 size_t written; | 876 size_t written; |
| 881 QuicErrorCode rs = buffer_->OnStreamData( | 877 QuicErrorCode rs = buffer_->OnStreamData( |
| 882 begin, "a", clock_.ApproximateNow(), &written, &error_details_); | 878 begin, "a", clock_.ApproximateNow(), &written, &error_details_); |
| 883 | 879 |
| 884 QuicStreamOffset last_straw = 2 * kMaxNumGapsAllowed - 1; | 880 QuicStreamOffset last_straw = 2 * kMaxNumGapsAllowed - 1; |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1114 EXPECT_LE(bytes_to_buffer_, total_bytes_read_) << "iterations: " | 1110 EXPECT_LE(bytes_to_buffer_, total_bytes_read_) << "iterations: " |
| 1115 << iterations; | 1111 << iterations; |
| 1116 EXPECT_LE(bytes_to_buffer_, total_bytes_written_); | 1112 EXPECT_LE(bytes_to_buffer_, total_bytes_written_); |
| 1117 } | 1113 } |
| 1118 | 1114 |
| 1119 } // anonymous namespace | 1115 } // anonymous namespace |
| 1120 | 1116 |
| 1121 } // namespace test | 1117 } // namespace test |
| 1122 | 1118 |
| 1123 } // namespace net | 1119 } // namespace net |
| OLD | NEW |