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

Side by Side Diff: media/blink/multibuffer_unittest.cc

Issue 2363953003: multibuffer: Evict lower blocks first after inserting multiple blocks
Patch Set: Created 4 years, 2 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 unified diff | Download patch
« no previous file with comments | « media/blink/multibuffer.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 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 <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include <deque> 8 #include <deque>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 441
442 // Make the rest of the packets pruneable. 442 // Make the rest of the packets pruneable.
443 lru_->IncrementMaxSize(-max_size); 443 lru_->IncrementMaxSize(-max_size);
444 444
445 // After another 30 seconds, everything should be pruned. 445 // After another 30 seconds, everything should be pruned.
446 task_runner_->Sleep(base::TimeDelta::FromSeconds(30)); 446 task_runner_->Sleep(base::TimeDelta::FromSeconds(30));
447 EXPECT_EQ(0, lru_->Size()); 447 EXPECT_EQ(0, lru_->Size());
448 EXPECT_FALSE(lru_->Pruneable()); 448 EXPECT_FALSE(lru_->Pruneable());
449 } 449 }
450 450
451 // When seeking, multiple blocks may enter the LRU at once. Make sure that
452 // afterwards, the eviction order is lower-position-first.
453 TEST_F(MultiBufferTest, LRUOnSeek) {
454 const size_t file_size = 1000 << kBlockSizeShift;
455 multibuffer_.SetFileSize(file_size);
456 multibuffer_.SetMaxWriters(2);
457 lru_->IncrementMaxSize(6);
458
459 // Choose a value that will result in a gap between "present" blocks.
460 const int64_t seek_position = kMaxWaitForWriterOffset + 4;
461
462 MultiBufferReader reader(&multibuffer_, 0, file_size,
463 base::Callback<void(int64_t, int64_t)>());
464 reader.SetPinRange(seek_position << kBlockSizeShift, (2 * seek_position)
465 << kBlockSizeShift);
466 reader.SetPreload(10000, 10000);
467
468 // Provide the first 3 blocks. Initially, they will be pinned.
469 for (size_t block = 0; block < 3; ++block)
470 CHECK(AdvanceAll());
471 for (size_t block = 0; block < 3; ++block)
472 ASSERT_FALSE(lru_->Contains(&multibuffer_, block));
473
474 // Move the reader and create a new writer. When providing further blocks,
475 // there will now be two ranges of "present" blocks.
476 reader.Seek(seek_position << kBlockSizeShift);
477 for (size_t block = seek_position; block < seek_position + 3; ++block)
478 CHECK(AdvanceAll());
479 for (size_t block = seek_position; block < seek_position + 3; ++block)
480 ASSERT_FALSE(lru_->Contains(&multibuffer_, block));
481
482 // Advance the reader far enough to unpin both "present" ranges. The 6
483 // previously pinned blocks, in two ranges, will move into the LRU.
484 const auto new_seek_position = seek_position * 3;
485 reader.Seek(new_seek_position << kBlockSizeShift);
486 for (size_t block = 0; block < 3; ++block)
487 ASSERT_TRUE(lru_->Contains(&multibuffer_, block));
488 for (size_t block = seek_position; block < seek_position + 3; ++block)
489 ASSERT_TRUE(lru_->Contains(&multibuffer_, block));
490
491 // As further blocks are provided, older blocks will gradually move out of
492 // the LRU. Make sure the lowest position blocks leave the LRU first.
493 const char* expected_order[] = {
494 "011 111",
495 "001 111",
496 "000 111",
497 "000 011",
498 "000 001",
499 "000 000",
500 };
501 for (size_t i = 0; i < 6; ++i) {
502 CHECK(AdvanceAll());
503 std::string order;
504 for (size_t block = 0; block < 3; ++block) {
505 order += lru_->Contains(&multibuffer_, block) ? "1" : "0";
506 }
507 order += " ";
508 for (size_t block = seek_position; block < seek_position + 3; ++block) {
509 order += lru_->Contains(&multibuffer_, block) ? "1" : "0";
510 }
511 EXPECT_EQ(expected_order[i], order);
512 }
513
514 lru_->IncrementMaxSize(-6);
515 }
516
451 class ReadHelper { 517 class ReadHelper {
452 public: 518 public:
453 ReadHelper(size_t end, 519 ReadHelper(size_t end,
454 size_t max_read_size, 520 size_t max_read_size,
455 MultiBuffer* multibuffer, 521 MultiBuffer* multibuffer,
456 TestRandom* rnd) 522 TestRandom* rnd)
457 : pos_(0), 523 : pos_(0),
458 end_(end), 524 end_(end),
459 max_read_size_(max_read_size), 525 max_read_size_(max_read_size),
460 read_size_(0), 526 read_size_(0),
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 multibuffer_.CheckLRUState(); 633 multibuffer_.CheckLRUState();
568 } 634 }
569 multibuffer_.CheckPresentState(); 635 multibuffer_.CheckPresentState();
570 while (!read_helpers.empty()) { 636 while (!read_helpers.empty()) {
571 delete read_helpers.back(); 637 delete read_helpers.back();
572 read_helpers.pop_back(); 638 read_helpers.pop_back();
573 } 639 }
574 } 640 }
575 641
576 } // namespace media 642 } // namespace media
OLDNEW
« 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