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 | 4 |
5 #include "net/quic/stream_sequencer_buffer.h" | 5 #include "net/quic/stream_sequencer_buffer.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/rand_util.h" | 9 #include "base/rand_util.h" |
10 #include "net/quic/test_tools/mock_clock.h" | 10 #include "net/quic/test_tools/mock_clock.h" |
(...skipping 745 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
756 | 756 |
757 void SetUp() override { | 757 void SetUp() override { |
758 // Test against a larger capacity then above tests. Also make sure the last | 758 // Test against a larger capacity then above tests. Also make sure the last |
759 // block is partially available to use. | 759 // block is partially available to use. |
760 max_capacity_bytes_ = 6.25 * kBlockSizeBytes; | 760 max_capacity_bytes_ = 6.25 * kBlockSizeBytes; |
761 // Stream to be buffered should be larger than the capacity to test wrap | 761 // Stream to be buffered should be larger than the capacity to test wrap |
762 // around. | 762 // around. |
763 bytes_to_buffer_ = 2 * max_capacity_bytes_; | 763 bytes_to_buffer_ = 2 * max_capacity_bytes_; |
764 Initialize(); | 764 Initialize(); |
765 | 765 |
766 uint32 seed = base::RandInt(0, std::numeric_limits<int32>::max()); | 766 uint32_t seed = base::RandInt(0, std::numeric_limits<int32_t>::max()); |
767 LOG(INFO) << "RandomWriteAndProcessInPlace test seed is " << seed; | 767 LOG(INFO) << "RandomWriteAndProcessInPlace test seed is " << seed; |
768 rng_.set_seed(seed); | 768 rng_.set_seed(seed); |
769 } | 769 } |
770 | 770 |
771 // Create an out-of-order source stream with given size to populate | 771 // Create an out-of-order source stream with given size to populate |
772 // shuffled_buf_. | 772 // shuffled_buf_. |
773 void CreateSourceAndShuffle(size_t max_chunk_size_bytes) { | 773 void CreateSourceAndShuffle(size_t max_chunk_size_bytes) { |
774 max_chunk_size_bytes_ = max_chunk_size_bytes; | 774 max_chunk_size_bytes_ = max_chunk_size_bytes; |
775 std::unique_ptr<OffsetSizePair[]> chopped_stream( | 775 std::unique_ptr<OffsetSizePair[]> chopped_stream( |
776 new OffsetSizePair[bytes_to_buffer_]); | 776 new OffsetSizePair[bytes_to_buffer_]); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
848 const size_t kNumReads = 2; | 848 const size_t kNumReads = 2; |
849 // Since write and read operation have equal possibility to be called. Bytes | 849 // Since write and read operation have equal possibility to be called. Bytes |
850 // to be written into and read out of should roughly the same. | 850 // to be written into and read out of should roughly the same. |
851 const size_t kMaxWriteSize = kNumReads * kMaxReadSize; | 851 const size_t kMaxWriteSize = kNumReads * kMaxReadSize; |
852 size_t iterations = 0; | 852 size_t iterations = 0; |
853 | 853 |
854 CreateSourceAndShuffle(kMaxWriteSize); | 854 CreateSourceAndShuffle(kMaxWriteSize); |
855 | 855 |
856 while ((!shuffled_buf_.empty() || total_bytes_read_ < bytes_to_buffer_) && | 856 while ((!shuffled_buf_.empty() || total_bytes_read_ < bytes_to_buffer_) && |
857 iterations <= 2 * bytes_to_buffer_) { | 857 iterations <= 2 * bytes_to_buffer_) { |
858 uint8 next_action = | 858 uint8_t next_action = |
859 shuffled_buf_.empty() ? uint8{1} : rng_.RandUint64() % 2; | 859 shuffled_buf_.empty() ? uint8_t{1} : rng_.RandUint64() % 2; |
860 DVLOG(1) << "iteration: " << iterations; | 860 DVLOG(1) << "iteration: " << iterations; |
861 switch (next_action) { | 861 switch (next_action) { |
862 case 0: { // write | 862 case 0: { // write |
863 WriteNextChunkToBuffer(); | 863 WriteNextChunkToBuffer(); |
864 ASSERT_TRUE(helper_->CheckBufferInvariants()); | 864 ASSERT_TRUE(helper_->CheckBufferInvariants()); |
865 break; | 865 break; |
866 } | 866 } |
867 case 1: { // readv | 867 case 1: { // readv |
868 std::unique_ptr<char[][kMaxReadSize]> read_buf{ | 868 std::unique_ptr<char[][kMaxReadSize]> read_buf{ |
869 new char[kNumReads][kMaxReadSize]}; | 869 new char[kNumReads][kMaxReadSize]}; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
906 const size_t kMaxNumReads = 4; | 906 const size_t kMaxNumReads = 4; |
907 // Adjust write amount be roughly equal to that GetReadableRegions() can get. | 907 // Adjust write amount be roughly equal to that GetReadableRegions() can get. |
908 const size_t kMaxWriteSize = kMaxNumReads * kBlockSizeBytes; | 908 const size_t kMaxWriteSize = kMaxNumReads * kBlockSizeBytes; |
909 ASSERT_LE(kMaxWriteSize, max_capacity_bytes_); | 909 ASSERT_LE(kMaxWriteSize, max_capacity_bytes_); |
910 size_t iterations = 0; | 910 size_t iterations = 0; |
911 | 911 |
912 CreateSourceAndShuffle(kMaxWriteSize); | 912 CreateSourceAndShuffle(kMaxWriteSize); |
913 | 913 |
914 while ((!shuffled_buf_.empty() || total_bytes_read_ < bytes_to_buffer_) && | 914 while ((!shuffled_buf_.empty() || total_bytes_read_ < bytes_to_buffer_) && |
915 iterations <= 2 * bytes_to_buffer_) { | 915 iterations <= 2 * bytes_to_buffer_) { |
916 uint8 next_action = | 916 uint8_t next_action = |
917 shuffled_buf_.empty() ? uint8{1} : rng_.RandUint64() % 2; | 917 shuffled_buf_.empty() ? uint8_t{1} : rng_.RandUint64() % 2; |
918 DVLOG(1) << "iteration: " << iterations; | 918 DVLOG(1) << "iteration: " << iterations; |
919 switch (next_action) { | 919 switch (next_action) { |
920 case 0: { // write | 920 case 0: { // write |
921 WriteNextChunkToBuffer(); | 921 WriteNextChunkToBuffer(); |
922 ASSERT_TRUE(helper_->CheckBufferInvariants()); | 922 ASSERT_TRUE(helper_->CheckBufferInvariants()); |
923 break; | 923 break; |
924 } | 924 } |
925 case 1: { // GetReadableRegions and then MarkConsumed | 925 case 1: { // GetReadableRegions and then MarkConsumed |
926 size_t num_read = rng_.RandUint64() % kMaxNumReads + 1; | 926 size_t num_read = rng_.RandUint64() % kMaxNumReads + 1; |
927 iovec dest_iov[kMaxNumReads]; | 927 iovec dest_iov[kMaxNumReads]; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
972 EXPECT_LE(bytes_to_buffer_, total_bytes_read_) << "iterations: " | 972 EXPECT_LE(bytes_to_buffer_, total_bytes_read_) << "iterations: " |
973 << iterations; | 973 << iterations; |
974 EXPECT_LE(bytes_to_buffer_, total_bytes_written_); | 974 EXPECT_LE(bytes_to_buffer_, total_bytes_written_); |
975 } | 975 } |
976 | 976 |
977 } // anonymous namespace | 977 } // anonymous namespace |
978 | 978 |
979 } // namespace test | 979 } // namespace test |
980 | 980 |
981 } // namespace net | 981 } // namespace net |
OLD | NEW |