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

Side by Side Diff: net/disk_cache/blockfile/index_table_v3_unittest.cc

Issue 266243004: Clang format slam. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/logging.h" 6 #include "base/logging.h"
7 #include "net/disk_cache/blockfile/addr.h" 7 #include "net/disk_cache/blockfile/addr.h"
8 #include "net/disk_cache/blockfile/disk_format_v3.h" 8 #include "net/disk_cache/blockfile/disk_format_v3.h"
9 #include "net/disk_cache/blockfile/index_table_v3.h" 9 #include "net/disk_cache/blockfile/index_table_v3.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 } 101 }
102 102
103 void TestCacheTables::GetInitData(IndexTableInitData* result) { 103 void TestCacheTables::GetInitData(IndexTableInitData* result) {
104 result->index_bitmap = 104 result->index_bitmap =
105 reinterpret_cast<disk_cache::IndexBitmap*>(main_bitmap_.get()); 105 reinterpret_cast<disk_cache::IndexBitmap*>(main_bitmap_.get());
106 106
107 result->main_table = main_table_.get(); 107 result->main_table = main_table_.get();
108 result->extra_table = extra_table_.get(); 108 result->extra_table = extra_table_.get();
109 109
110 result->backup_header.reset(new disk_cache::IndexHeaderV3); 110 result->backup_header.reset(new disk_cache::IndexHeaderV3);
111 memcpy(result->backup_header.get(), result->index_bitmap, 111 memcpy(result->backup_header.get(),
112 result->index_bitmap,
112 sizeof(result->index_bitmap->header)); 113 sizeof(result->index_bitmap->header));
113 114
114 result->backup_bitmap.reset(new uint32[num_bitmap_bytes_ / sizeof(uint32)]); 115 result->backup_bitmap.reset(new uint32[num_bitmap_bytes_ / sizeof(uint32)]);
115 memcpy(result->backup_bitmap.get(), result->index_bitmap->bitmap, 116 memcpy(result->backup_bitmap.get(),
117 result->index_bitmap->bitmap,
116 num_bitmap_bytes_); 118 num_bitmap_bytes_);
117 } 119 }
118 120
119 void TestCacheTables::CopyFrom(const TestCacheTables& other) { 121 void TestCacheTables::CopyFrom(const TestCacheTables& other) {
120 disk_cache::IndexBitmap* this_bitmap = 122 disk_cache::IndexBitmap* this_bitmap =
121 reinterpret_cast<disk_cache::IndexBitmap*>(main_bitmap_.get()); 123 reinterpret_cast<disk_cache::IndexBitmap*>(main_bitmap_.get());
122 disk_cache::IndexBitmap* other_bitmap = 124 disk_cache::IndexBitmap* other_bitmap =
123 reinterpret_cast<disk_cache::IndexBitmap*>(other.main_bitmap_.get()); 125 reinterpret_cast<disk_cache::IndexBitmap*>(other.main_bitmap_.get());
124 126
125 DCHECK_GE(this_bitmap->header.table_len, other_bitmap->header.table_len); 127 DCHECK_GE(this_bitmap->header.table_len, other_bitmap->header.table_len);
126 DCHECK_GE(num_bitmap_bytes_, other.num_bitmap_bytes_); 128 DCHECK_GE(num_bitmap_bytes_, other.num_bitmap_bytes_);
127 129
128 memcpy(this_bitmap->bitmap, other_bitmap->bitmap, other.num_bitmap_bytes_); 130 memcpy(this_bitmap->bitmap, other_bitmap->bitmap, other.num_bitmap_bytes_);
129 131
130 int main_table_buckets = (other_bitmap->header.table_len * 2 / 3) / 4; 132 int main_table_buckets = (other_bitmap->header.table_len * 2 / 3) / 4;
131 int extra_table_buckets = (other_bitmap->header.table_len * 1 / 3) / 4; 133 int extra_table_buckets = (other_bitmap->header.table_len * 1 / 3) / 4;
132 memcpy(main_table_.get(), other.main_table_.get(), 134 memcpy(main_table_.get(),
135 other.main_table_.get(),
133 main_table_buckets * sizeof(disk_cache::IndexBucket)); 136 main_table_buckets * sizeof(disk_cache::IndexBucket));
134 memcpy(extra_table_.get(), other.extra_table_.get(), 137 memcpy(extra_table_.get(),
138 other.extra_table_.get(),
135 extra_table_buckets * sizeof(disk_cache::IndexBucket)); 139 extra_table_buckets * sizeof(disk_cache::IndexBucket));
136 140
137 this_bitmap->header.num_entries = other_bitmap->header.num_entries; 141 this_bitmap->header.num_entries = other_bitmap->header.num_entries;
138 this_bitmap->header.used_cells = other_bitmap->header.used_cells; 142 this_bitmap->header.used_cells = other_bitmap->header.used_cells;
139 this_bitmap->header.max_bucket = other_bitmap->header.max_bucket; 143 this_bitmap->header.max_bucket = other_bitmap->header.max_bucket;
140 this_bitmap->header.create_time = other_bitmap->header.create_time; 144 this_bitmap->header.create_time = other_bitmap->header.create_time;
141 this_bitmap->header.base_time = other_bitmap->header.base_time; 145 this_bitmap->header.base_time = other_bitmap->header.base_time;
142 this_bitmap->header.flags = other_bitmap->header.flags; 146 this_bitmap->header.flags = other_bitmap->header.flags;
143 start_time_ = other.start_time_; 147 start_time_ = other.start_time_;
144 } 148 }
145 149
146 } // namespace 150 } // namespace
147 151
148 TEST(DiskCacheIndexTable, EntryCell) { 152 TEST(DiskCacheIndexTable, EntryCell) {
149 uint32 hash = 0x55aa6699; 153 uint32 hash = 0x55aa6699;
150 disk_cache::Addr addr(disk_cache::BLOCK_ENTRIES, 1, 5, 0x4531); 154 disk_cache::Addr addr(disk_cache::BLOCK_ENTRIES, 1, 5, 0x4531);
151 bool small_table = true; 155 bool small_table = true;
152 int cell_num = 88; 156 int cell_num = 88;
153 int reuse = 6; 157 int reuse = 6;
154 int timestamp = 123456; 158 int timestamp = 123456;
155 disk_cache::EntryState state = disk_cache::ENTRY_MODIFIED; 159 disk_cache::EntryState state = disk_cache::ENTRY_MODIFIED;
156 disk_cache::EntryGroup group = disk_cache::ENTRY_HIGH_USE; 160 disk_cache::EntryGroup group = disk_cache::ENTRY_HIGH_USE;
157 161
158 for (int i = 0; i < 4; i++) { 162 for (int i = 0; i < 4; i++) {
159 SCOPED_TRACE(i); 163 SCOPED_TRACE(i);
160 EntryCell entry = EntryCell::GetEntryCellForTest(cell_num, hash, addr, NULL, 164 EntryCell entry =
161 small_table); 165 EntryCell::GetEntryCellForTest(cell_num, hash, addr, NULL, small_table);
162 EXPECT_EQ(disk_cache::ENTRY_NO_USE, entry.GetGroup()); 166 EXPECT_EQ(disk_cache::ENTRY_NO_USE, entry.GetGroup());
163 EXPECT_EQ(disk_cache::ENTRY_NEW, entry.GetState()); 167 EXPECT_EQ(disk_cache::ENTRY_NEW, entry.GetState());
164 168
165 entry.SetGroup(group); 169 entry.SetGroup(group);
166 entry.SetState(state); 170 entry.SetState(state);
167 entry.SetReuse(reuse); 171 entry.SetReuse(reuse);
168 entry.SetTimestamp(timestamp); 172 entry.SetTimestamp(timestamp);
169 173
170 EXPECT_TRUE(entry.IsValid()); 174 EXPECT_TRUE(entry.IsValid());
171 EXPECT_EQ(hash, entry.hash()); 175 EXPECT_EQ(hash, entry.hash());
172 EXPECT_EQ(cell_num, entry.cell_num()); 176 EXPECT_EQ(cell_num, entry.cell_num());
173 EXPECT_EQ(addr.value(), entry.GetAddress().value()); 177 EXPECT_EQ(addr.value(), entry.GetAddress().value());
174 178
175 EXPECT_EQ(group, entry.GetGroup()); 179 EXPECT_EQ(group, entry.GetGroup());
176 EXPECT_EQ(state, entry.GetState()); 180 EXPECT_EQ(state, entry.GetState());
177 EXPECT_EQ(reuse, entry.GetReuse()); 181 EXPECT_EQ(reuse, entry.GetReuse());
178 EXPECT_EQ(timestamp, entry.GetTimestamp()); 182 EXPECT_EQ(timestamp, entry.GetTimestamp());
179 183
180 // Store the data and read it again. 184 // Store the data and read it again.
181 IndexCell cell; 185 IndexCell cell;
182 entry.SerializaForTest(&cell); 186 entry.SerializaForTest(&cell);
183 187
184 EntryCell entry2 = EntryCell::GetEntryCellForTest(cell_num, hash, addr, 188 EntryCell entry2 = EntryCell::GetEntryCellForTest(
185 &cell, small_table); 189 cell_num, hash, addr, &cell, small_table);
186 190
187 EXPECT_EQ(addr.value(), entry2.GetAddress().value()); 191 EXPECT_EQ(addr.value(), entry2.GetAddress().value());
188 192
189 EXPECT_EQ(group, entry2.GetGroup()); 193 EXPECT_EQ(group, entry2.GetGroup());
190 EXPECT_EQ(state, entry2.GetState()); 194 EXPECT_EQ(state, entry2.GetState());
191 EXPECT_EQ(reuse, entry2.GetReuse()); 195 EXPECT_EQ(reuse, entry2.GetReuse());
192 EXPECT_EQ(timestamp, entry2.GetTimestamp()); 196 EXPECT_EQ(timestamp, entry2.GetTimestamp());
193 197
194 small_table = !small_table; 198 small_table = !small_table;
195 if (i == 1) { 199 if (i == 1) {
196 hash = ~hash; 200 hash = ~hash;
197 cell_num *= 5; 201 cell_num *= 5;
198 state = disk_cache::ENTRY_USED; 202 state = disk_cache::ENTRY_USED;
199 group = disk_cache::ENTRY_EVICTED; 203 group = disk_cache::ENTRY_EVICTED;
200 addr = disk_cache::Addr(disk_cache::BLOCK_EVICTED, 1, 6, 0x18a5); 204 addr = disk_cache::Addr(disk_cache::BLOCK_EVICTED, 1, 6, 0x18a5);
201 reuse = 15; // 4 bits 205 reuse = 15; // 4 bits
202 timestamp = 0xfffff; // 20 bits. 206 timestamp = 0xfffff; // 20 bits.
203 } 207 }
204 } 208 }
205 } 209 }
206 210
207 // Goes over some significant values for a cell's sum. 211 // Goes over some significant values for a cell's sum.
208 TEST(DiskCacheIndexTable, EntryCellSum) { 212 TEST(DiskCacheIndexTable, EntryCellSum) {
209 IndexCell source; 213 IndexCell source;
210 source.Clear(); 214 source.Clear();
211 EXPECT_EQ(0, GetChecksum(source)); 215 EXPECT_EQ(0, GetChecksum(source));
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 277
274 // Write some entries. 278 // Write some entries.
275 disk_cache::CellList entries; 279 disk_cache::CellList entries;
276 for (int i = 0; i < 250; i++) { 280 for (int i = 0; i < 250; i++) {
277 SCOPED_TRACE(i); 281 SCOPED_TRACE(i);
278 uint32 hash = i * i * 1111 + i * 11; 282 uint32 hash = i * i * 1111 + i * 11;
279 disk_cache::Addr addr(disk_cache::BLOCK_ENTRIES, 1, 5, i * 13 + 1); 283 disk_cache::Addr addr(disk_cache::BLOCK_ENTRIES, 1, 5, i * 13 + 1);
280 EntryCell entry = index.CreateEntryCell(hash, addr); 284 EntryCell entry = index.CreateEntryCell(hash, addr);
281 EXPECT_TRUE(entry.IsValid()); 285 EXPECT_TRUE(entry.IsValid());
282 286
283 disk_cache::CellInfo info = { hash, addr }; 287 disk_cache::CellInfo info = {hash, addr};
284 entries.push_back(info); 288 entries.push_back(info);
285 } 289 }
286 290
287 // Read them back. 291 // Read them back.
288 for (size_t i = 0; i < entries.size(); i++) { 292 for (size_t i = 0; i < entries.size(); i++) {
289 SCOPED_TRACE(i); 293 SCOPED_TRACE(i);
290 uint32 hash = entries[i].hash; 294 uint32 hash = entries[i].hash;
291 disk_cache::Addr addr = entries[i].address; 295 disk_cache::Addr addr = entries[i].address;
292 296
293 disk_cache::EntrySet found_entries = index.LookupEntries(hash); 297 disk_cache::EntrySet found_entries = index.LookupEntries(hash);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 index.Init(&init_data); 338 index.Init(&init_data);
335 339
336 disk_cache::CellList entries; 340 disk_cache::CellList entries;
337 uint32 hash = 0x55aa55bb; 341 uint32 hash = 0x55aa55bb;
338 for (int i = 0; i < 6; i++) { 342 for (int i = 0; i < 6; i++) {
339 SCOPED_TRACE(i); 343 SCOPED_TRACE(i);
340 disk_cache::Addr addr(disk_cache::BLOCK_ENTRIES, 1, 5, i * 13 + 1); 344 disk_cache::Addr addr(disk_cache::BLOCK_ENTRIES, 1, 5, i * 13 + 1);
341 EntryCell entry = index.CreateEntryCell(hash, addr); 345 EntryCell entry = index.CreateEntryCell(hash, addr);
342 EXPECT_TRUE(entry.IsValid()); 346 EXPECT_TRUE(entry.IsValid());
343 347
344 disk_cache::CellInfo info = { hash, addr }; 348 disk_cache::CellInfo info = {hash, addr};
345 entries.push_back(info); 349 entries.push_back(info);
346 } 350 }
347 351
348 disk_cache::EntrySet found_entries = index.LookupEntries(hash); 352 disk_cache::EntrySet found_entries = index.LookupEntries(hash);
349 EXPECT_EQ(0, found_entries.evicted_count); 353 EXPECT_EQ(0, found_entries.evicted_count);
350 ASSERT_EQ(6u, found_entries.cells.size()); 354 ASSERT_EQ(6u, found_entries.cells.size());
351 355
352 for (size_t i = 0; i < found_entries.cells.size(); i++) { 356 for (size_t i = 0; i < found_entries.cells.size(); i++) {
353 SCOPED_TRACE(i); 357 SCOPED_TRACE(i);
354 EXPECT_EQ(entries[i].address, found_entries.cells[i].GetAddress()); 358 EXPECT_EQ(entries[i].address, found_entries.cells[i].GetAddress());
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 for (int i = 0; i < 44; i++) { 479 for (int i = 0; i < 44; i++) {
476 SCOPED_TRACE(i); 480 SCOPED_TRACE(i);
477 uint32 hash = i; // The entries will be ordered on the table. 481 uint32 hash = i; // The entries will be ordered on the table.
478 disk_cache::Addr addr(disk_cache::BLOCK_ENTRIES, 1, 5, i * 13 + 1); 482 disk_cache::Addr addr(disk_cache::BLOCK_ENTRIES, 1, 5, i * 13 + 1);
479 if (i < 10 || i == 40) 483 if (i < 10 || i == 40)
480 addr = disk_cache::Addr(disk_cache::BLOCK_EVICTED, 1, 6, i * 13 + 1); 484 addr = disk_cache::Addr(disk_cache::BLOCK_EVICTED, 1, 6, i * 13 + 1);
481 485
482 EntryCell entry = index.CreateEntryCell(hash, addr); 486 EntryCell entry = index.CreateEntryCell(hash, addr);
483 EXPECT_TRUE(entry.IsValid()); 487 EXPECT_TRUE(entry.IsValid());
484 488
485 disk_cache::CellInfo info = { hash, addr }; 489 disk_cache::CellInfo info = {hash, addr};
486 entries.push_back(info); 490 entries.push_back(info);
487 491
488 if (i < 10 || i == 40) { 492 if (i < 10 || i == 40) {
489 // Do nothing. These are ENTRY_EVICTED by default. 493 // Do nothing. These are ENTRY_EVICTED by default.
490 } else if (i < 20 || i == 41) { 494 } else if (i < 20 || i == 41) {
491 entry.SetGroup(disk_cache::ENTRY_HIGH_USE); 495 entry.SetGroup(disk_cache::ENTRY_HIGH_USE);
492 index.Save(&entry); 496 index.Save(&entry);
493 } else if (i < 30 || i == 42) { 497 } else if (i < 30 || i == 42) {
494 entry.SetGroup(disk_cache::ENTRY_LOW_USE); 498 entry.SetGroup(disk_cache::ENTRY_LOW_USE);
495 index.Save(&entry); 499 index.Save(&entry);
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
590 index.Init(&init_data); 594 index.Init(&init_data);
591 595
592 // Write some entries. 596 // Write some entries.
593 for (int i = 0; i < 250; i++, entry_id++) { 597 for (int i = 0; i < 250; i++, entry_id++) {
594 SCOPED_TRACE(entry_id); 598 SCOPED_TRACE(entry_id);
595 uint32 hash = entry_id * i * 321 + entry_id * 13; 599 uint32 hash = entry_id * i * 321 + entry_id * 13;
596 disk_cache::Addr addr(disk_cache::BLOCK_ENTRIES, 1, 5, entry_id * 17 + 1); 600 disk_cache::Addr addr(disk_cache::BLOCK_ENTRIES, 1, 5, entry_id * 17 + 1);
597 EntryCell entry = index.CreateEntryCell(hash, addr); 601 EntryCell entry = index.CreateEntryCell(hash, addr);
598 EXPECT_TRUE(entry.IsValid()); 602 EXPECT_TRUE(entry.IsValid());
599 603
600 disk_cache::CellInfo info = { hash, addr }; 604 disk_cache::CellInfo info = {hash, addr};
601 entries.push_back(info); 605 entries.push_back(info);
602 } 606 }
603 size *= 2; 607 size *= 2;
604 } 608 }
605 609
606 // Access all the entries. 610 // Access all the entries.
607 for (size_t i = 0; i < entries.size(); i++) { 611 for (size_t i = 0; i < entries.size(); i++) {
608 SCOPED_TRACE(i); 612 SCOPED_TRACE(i);
609 disk_cache::EntrySet found_entries = index.LookupEntries(entries[i].hash); 613 disk_cache::EntrySet found_entries = index.LookupEntries(entries[i].hash);
610 ASSERT_EQ(1u, found_entries.cells.size()); 614 ASSERT_EQ(1u, found_entries.cells.size());
(...skipping 13 matching lines...) Expand all
624 index.Init(&init_data); 628 index.Init(&init_data);
625 629
626 // Write some entries. 630 // Write some entries.
627 for (int i = 0; i < 8; i++) { 631 for (int i = 0; i < 8; i++) {
628 SCOPED_TRACE(i); 632 SCOPED_TRACE(i);
629 uint32 hash = i * 256; 633 uint32 hash = i * 256;
630 disk_cache::Addr addr(disk_cache::BLOCK_ENTRIES, 1, 5, i * 7 + 1); 634 disk_cache::Addr addr(disk_cache::BLOCK_ENTRIES, 1, 5, i * 7 + 1);
631 EntryCell entry = index.CreateEntryCell(hash, addr); 635 EntryCell entry = index.CreateEntryCell(hash, addr);
632 EXPECT_TRUE(entry.IsValid()); 636 EXPECT_TRUE(entry.IsValid());
633 637
634 disk_cache::CellInfo info = { hash, addr }; 638 disk_cache::CellInfo info = {hash, addr};
635 entries.push_back(info); 639 entries.push_back(info);
636 } 640 }
637 641
638 // Double the size. 642 // Double the size.
639 scoped_ptr<TestCacheTables> old_cache(cache.Pass()); 643 scoped_ptr<TestCacheTables> old_cache(cache.Pass());
640 cache.reset(new TestCacheTables(size * 2)); 644 cache.reset(new TestCacheTables(size * 2));
641 cache.get()->CopyFrom(*old_cache.get()); 645 cache.get()->CopyFrom(*old_cache.get());
642 646
643 cache.get()->GetInitData(&init_data); 647 cache.get()->GetInitData(&init_data);
644 index.Init(&init_data); 648 index.Init(&init_data);
645 649
646 // Write more entries, starting with the upper half of the table. 650 // Write more entries, starting with the upper half of the table.
647 for (int i = 9; i < 11; i++) { 651 for (int i = 9; i < 11; i++) {
648 SCOPED_TRACE(i); 652 SCOPED_TRACE(i);
649 uint32 hash = i * 256; 653 uint32 hash = i * 256;
650 disk_cache::Addr addr(disk_cache::BLOCK_ENTRIES, 1, 5, i * 7 + 1); 654 disk_cache::Addr addr(disk_cache::BLOCK_ENTRIES, 1, 5, i * 7 + 1);
651 EntryCell entry = index.CreateEntryCell(hash, addr); 655 EntryCell entry = index.CreateEntryCell(hash, addr);
652 EXPECT_TRUE(entry.IsValid()); 656 EXPECT_TRUE(entry.IsValid());
653 657
654 disk_cache::CellInfo info = { hash, addr }; 658 disk_cache::CellInfo info = {hash, addr};
655 entries.push_back(info); 659 entries.push_back(info);
656 } 660 }
657 661
658 // Access all the entries. 662 // Access all the entries.
659 for (size_t i = 0; i < entries.size(); i++) { 663 for (size_t i = 0; i < entries.size(); i++) {
660 SCOPED_TRACE(i); 664 SCOPED_TRACE(i);
661 disk_cache::EntrySet found_entries = index.LookupEntries(entries[i].hash); 665 disk_cache::EntrySet found_entries = index.LookupEntries(entries[i].hash);
662 ASSERT_EQ(1u, found_entries.cells.size()); 666 ASSERT_EQ(1u, found_entries.cells.size());
663 EXPECT_TRUE(found_entries.cells[0].IsValid()); 667 EXPECT_TRUE(found_entries.cells[0].IsValid());
664 } 668 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
697 701
698 uint32 hash = 0; 702 uint32 hash = 0;
699 disk_cache::Addr addr(disk_cache::BLOCK_ENTRIES, 1, 5, 6); 703 disk_cache::Addr addr(disk_cache::BLOCK_ENTRIES, 1, 5, 6);
700 EntryCell entry = index.CreateEntryCell(hash, addr); 704 EntryCell entry = index.CreateEntryCell(hash, addr);
701 EXPECT_TRUE(entry.IsValid()); 705 EXPECT_TRUE(entry.IsValid());
702 706
703 index.OnBackupTimer(); 707 index.OnBackupTimer();
704 int expected = (1024 + 512) / 8 + sizeof(disk_cache::IndexHeaderV3); 708 int expected = (1024 + 512) / 8 + sizeof(disk_cache::IndexHeaderV3);
705 EXPECT_EQ(expected, backend.buffer_len()); 709 EXPECT_EQ(expected, backend.buffer_len());
706 } 710 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698