| 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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 | 104 |
| 105 TEST_F(QuicStreamSequencerBufferTest, OnStreamData0length) { | 105 TEST_F(QuicStreamSequencerBufferTest, OnStreamData0length) { |
| 106 size_t written; | 106 size_t written; |
| 107 QuicErrorCode error = buffer_->OnStreamData(800, "", clock_.ApproximateNow(), | 107 QuicErrorCode error = buffer_->OnStreamData(800, "", clock_.ApproximateNow(), |
| 108 &written, &error_details_); | 108 &written, &error_details_); |
| 109 EXPECT_EQ(error, QUIC_EMPTY_STREAM_FRAME_NO_FIN); | 109 EXPECT_EQ(error, QUIC_EMPTY_STREAM_FRAME_NO_FIN); |
| 110 EXPECT_TRUE(helper_->CheckBufferInvariants()); | 110 EXPECT_TRUE(helper_->CheckBufferInvariants()); |
| 111 } | 111 } |
| 112 | 112 |
| 113 TEST_F(QuicStreamSequencerBufferTest, OnStreamDataWithinBlock) { | 113 TEST_F(QuicStreamSequencerBufferTest, OnStreamDataWithinBlock) { |
| 114 if (FLAGS_quic_reduce_sequencer_buffer_memory_life_time) { // NOLINT | 114 EXPECT_FALSE(helper_->IsBufferAllocated()); |
| 115 EXPECT_FALSE(helper_->IsBufferAllocated()); | |
| 116 } | |
| 117 string source(1024, 'a'); | 115 string source(1024, 'a'); |
| 118 size_t written; | 116 size_t written; |
| 119 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(1)); | 117 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(1)); |
| 120 QuicTime t = clock_.ApproximateNow(); | 118 QuicTime t = clock_.ApproximateNow(); |
| 121 EXPECT_EQ(QUIC_NO_ERROR, | 119 EXPECT_EQ(QUIC_NO_ERROR, |
| 122 buffer_->OnStreamData(800, source, t, &written, &error_details_)); | 120 buffer_->OnStreamData(800, source, t, &written, &error_details_)); |
| 123 BufferBlock* block_ptr = helper_->GetBlock(0); | 121 BufferBlock* block_ptr = helper_->GetBlock(0); |
| 124 for (size_t i = 0; i < source.size(); ++i) { | 122 for (size_t i = 0; i < source.size(); ++i) { |
| 125 ASSERT_EQ('a', block_ptr->buffer[helper_->GetInBlockOffset(800) + i]); | 123 ASSERT_EQ('a', block_ptr->buffer[helper_->GetInBlockOffset(800) + i]); |
| 126 } | 124 } |
| (...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 485 TEST_F(QuicStreamSequencerBufferTest, GetReadableRegionsEmpty) { | 483 TEST_F(QuicStreamSequencerBufferTest, GetReadableRegionsEmpty) { |
| 486 iovec iovs[2]; | 484 iovec iovs[2]; |
| 487 int iov_count = buffer_->GetReadableRegions(iovs, 2); | 485 int iov_count = buffer_->GetReadableRegions(iovs, 2); |
| 488 EXPECT_EQ(0, iov_count); | 486 EXPECT_EQ(0, iov_count); |
| 489 EXPECT_EQ(nullptr, iovs[iov_count].iov_base); | 487 EXPECT_EQ(nullptr, iovs[iov_count].iov_base); |
| 490 EXPECT_EQ(0u, iovs[iov_count].iov_len); | 488 EXPECT_EQ(0u, iovs[iov_count].iov_len); |
| 491 } | 489 } |
| 492 | 490 |
| 493 TEST_F(QuicStreamSequencerBufferTest, ReleaseWholeBuffer) { | 491 TEST_F(QuicStreamSequencerBufferTest, ReleaseWholeBuffer) { |
| 494 // Tests that buffer is not deallocated unless ReleaseWholeBuffer() is called. | 492 // Tests that buffer is not deallocated unless ReleaseWholeBuffer() is called. |
| 495 if (!FLAGS_quic_reduce_sequencer_buffer_memory_life_time) { // NOLINT | |
| 496 // Won't release buffer when flag is off. | |
| 497 return; | |
| 498 } | |
| 499 | 493 |
| 500 string source(100, 'b'); | 494 string source(100, 'b'); |
| 501 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(1)); | 495 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(1)); |
| 502 QuicTime t1 = clock_.ApproximateNow(); | 496 QuicTime t1 = clock_.ApproximateNow(); |
| 503 // Write something into [0, 100). | 497 // Write something into [0, 100). |
| 504 size_t written; | 498 size_t written; |
| 505 buffer_->OnStreamData(0, source, t1, &written, &error_details_); | 499 buffer_->OnStreamData(0, source, t1, &written, &error_details_); |
| 506 EXPECT_TRUE(buffer_->HasBytesToRead()); | 500 EXPECT_TRUE(buffer_->HasBytesToRead()); |
| 507 char dest[120]; | 501 char dest[120]; |
| 508 iovec iovecs[3]{iovec{dest, 40}, iovec{dest + 40, 40}, iovec{dest + 80, 40}}; | 502 iovec iovecs[3]{iovec{dest, 40}, iovec{dest + 40, 40}, iovec{dest + 80, 40}}; |
| (...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1054 EXPECT_LE(bytes_to_buffer_, total_bytes_read_) << "iterations: " | 1048 EXPECT_LE(bytes_to_buffer_, total_bytes_read_) << "iterations: " |
| 1055 << iterations; | 1049 << iterations; |
| 1056 EXPECT_LE(bytes_to_buffer_, total_bytes_written_); | 1050 EXPECT_LE(bytes_to_buffer_, total_bytes_written_); |
| 1057 } | 1051 } |
| 1058 | 1052 |
| 1059 } // anonymous namespace | 1053 } // anonymous namespace |
| 1060 | 1054 |
| 1061 } // namespace test | 1055 } // namespace test |
| 1062 | 1056 |
| 1063 } // namespace net | 1057 } // namespace net |
| OLD | NEW |