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

Unified Diff: base/metrics/persistent_memory_allocator_unittest.cc

Issue 1654053002: New test and off-by-one fix for data persisted to disk. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: allow crash-test to run with dcheck enabled Created 4 years, 10 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 | « base/metrics/persistent_memory_allocator.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/metrics/persistent_memory_allocator_unittest.cc
diff --git a/base/metrics/persistent_memory_allocator_unittest.cc b/base/metrics/persistent_memory_allocator_unittest.cc
index 8b98ee4cd44406d8fd80a3ca9e9e4a418250bb05..6a8190182c3df8368c9bfb5b22860577aa0ff6d2 100644
--- a/base/metrics/persistent_memory_allocator_unittest.cc
+++ b/base/metrics/persistent_memory_allocator_unittest.cc
@@ -451,6 +451,8 @@ TEST(FilePersistentMemoryAllocatorTest, AcceptableTest) {
FilePath file_path_base = temp_dir.path().AppendASCII("persistent_memory_");
LocalPersistentMemoryAllocator local(TEST_MEMORY_SIZE, TEST_ID, "");
+ local.Allocate(1, 1);
+ local.Allocate(11, 11);
const size_t minsize = local.used();
scoped_ptr<char[]> garbage(new char[minsize]);
RandBytes(garbage.get(), minsize);
@@ -472,9 +474,25 @@ TEST(FilePersistentMemoryAllocatorTest, AcceptableTest) {
mmfile->Initialize(file_path);
EXPECT_EQ(filesize, mmfile->length());
if (FilePersistentMemoryAllocator::IsFileAcceptable(*mmfile)) {
- // Just need to make sure it doesn't crash.
+ // Make sure construction doesn't crash.
FilePersistentMemoryAllocator allocator(mmfile.release(), 0, "");
- (void)allocator; // Ensure compiler can't optimize-out above variable.
+ // Also make sure that iteration doesn't crash.
+ PersistentMemoryAllocator::Iterator iter;
+ allocator.CreateIterator(&iter);
+ for (;;) {
+ Reference ref = allocator.GetNextIterable(&iter, 0);
+ if (!ref)
+ break;
+ const char* data = allocator.GetAsObject<char>(ref, 0);
+ uint32_t type = allocator.GetType(ref);
+ size_t size = allocator.GetAllocSize(ref);
+ // Ensure compiler can't optimize-out above variables.
+ (void)data;
+ (void)type;
+ (void)size;
+ // Ensure that corruption-detected flag gets properly set.
+ EXPECT_EQ(filesize != minsize, allocator.IsCorrupt());
+ }
} else {
// For filesize >= minsize, the file must be acceptable. This
// else clause (file-not-acceptable) should be reached only if
@@ -482,7 +500,6 @@ TEST(FilePersistentMemoryAllocatorTest, AcceptableTest) {
EXPECT_LT(filesize, minsize);
}
-#if !DCHECK_IS_ON() // DCHECK builds will die at a NOTREACHED().
strings::SafeSPrintf(filename, "memory_%d_B", filesize);
file_path = temp_dir.path().AppendASCII(filename);
ASSERT_FALSE(PathExists(file_path));
@@ -506,7 +523,6 @@ TEST(FilePersistentMemoryAllocatorTest, AcceptableTest) {
// filesize < minsize.
EXPECT_GT(minsize, filesize);
}
-#endif
}
}
« no previous file with comments | « base/metrics/persistent_memory_allocator.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698