Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(840)

Unified Diff: media/blink/multibuffer_unittest.cc

Issue 2363953003: multibuffer: Evict lower blocks first after inserting multiple blocks
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « media/blink/multibuffer.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/blink/multibuffer_unittest.cc
diff --git a/media/blink/multibuffer_unittest.cc b/media/blink/multibuffer_unittest.cc
index ae607798dca9390a0c1bbc1dbb9d5a04e8a585c9..ca68cb8a21c8bc7e9fdcbb6684572a9d6a854aef 100644
--- a/media/blink/multibuffer_unittest.cc
+++ b/media/blink/multibuffer_unittest.cc
@@ -448,6 +448,72 @@ TEST_F(MultiBufferTest, LRUTestExpirationTest) {
EXPECT_FALSE(lru_->Pruneable());
}
+// When seeking, multiple blocks may enter the LRU at once. Make sure that
+// afterwards, the eviction order is lower-position-first.
+TEST_F(MultiBufferTest, LRUOnSeek) {
+ const size_t file_size = 1000 << kBlockSizeShift;
+ multibuffer_.SetFileSize(file_size);
+ multibuffer_.SetMaxWriters(2);
+ lru_->IncrementMaxSize(6);
+
+ // Choose a value that will result in a gap between "present" blocks.
+ const int64_t seek_position = kMaxWaitForWriterOffset + 4;
+
+ MultiBufferReader reader(&multibuffer_, 0, file_size,
+ base::Callback<void(int64_t, int64_t)>());
+ reader.SetPinRange(seek_position << kBlockSizeShift, (2 * seek_position)
+ << kBlockSizeShift);
+ reader.SetPreload(10000, 10000);
+
+ // Provide the first 3 blocks. Initially, they will be pinned.
+ for (size_t block = 0; block < 3; ++block)
+ CHECK(AdvanceAll());
+ for (size_t block = 0; block < 3; ++block)
+ ASSERT_FALSE(lru_->Contains(&multibuffer_, block));
+
+ // Move the reader and create a new writer. When providing further blocks,
+ // there will now be two ranges of "present" blocks.
+ reader.Seek(seek_position << kBlockSizeShift);
+ for (size_t block = seek_position; block < seek_position + 3; ++block)
+ CHECK(AdvanceAll());
+ for (size_t block = seek_position; block < seek_position + 3; ++block)
+ ASSERT_FALSE(lru_->Contains(&multibuffer_, block));
+
+ // Advance the reader far enough to unpin both "present" ranges. The 6
+ // previously pinned blocks, in two ranges, will move into the LRU.
+ const auto new_seek_position = seek_position * 3;
+ reader.Seek(new_seek_position << kBlockSizeShift);
+ for (size_t block = 0; block < 3; ++block)
+ ASSERT_TRUE(lru_->Contains(&multibuffer_, block));
+ for (size_t block = seek_position; block < seek_position + 3; ++block)
+ ASSERT_TRUE(lru_->Contains(&multibuffer_, block));
+
+ // As further blocks are provided, older blocks will gradually move out of
+ // the LRU. Make sure the lowest position blocks leave the LRU first.
+ const char* expected_order[] = {
+ "011 111",
+ "001 111",
+ "000 111",
+ "000 011",
+ "000 001",
+ "000 000",
+ };
+ for (size_t i = 0; i < 6; ++i) {
+ CHECK(AdvanceAll());
+ std::string order;
+ for (size_t block = 0; block < 3; ++block) {
+ order += lru_->Contains(&multibuffer_, block) ? "1" : "0";
+ }
+ order += " ";
+ for (size_t block = seek_position; block < seek_position + 3; ++block) {
+ order += lru_->Contains(&multibuffer_, block) ? "1" : "0";
+ }
+ EXPECT_EQ(expected_order[i], order);
+ }
+
+ lru_->IncrementMaxSize(-6);
+}
+
class ReadHelper {
public:
ReadHelper(size_t end,
« no previous file with comments | « media/blink/multibuffer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698