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

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: Created 4 years, 11 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..572eada6ec3eb230795cc0706e6a16c581263c12 100644
--- a/base/metrics/persistent_memory_allocator_unittest.cc
+++ b/base/metrics/persistent_memory_allocator_unittest.cc
@@ -445,12 +445,15 @@ TEST(FilePersistentMemoryAllocatorTest, CreationTest) {
EXPECT_EQ(0U, meminfo2.free);
}
+#if !DCHECK_IS_ON() // DCHECK builds die at a various debug checks.
Alexei Svitkine (slow) 2016/02/08 21:43:26 Aren't most of our tests run with DCHECKs? So this
bcwhite 2016/02/10 16:28:58 I think all the bot-tests run off a release build.
Alexei Svitkine (slow) 2016/02/10 16:35:34 I believe the bots run Release with DCHECK on. I
bcwhite 2016/02/10 16:54:09 Complicated. Result to the caller is always "good
TEST(FilePersistentMemoryAllocatorTest, AcceptableTest) {
ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
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 +475,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 +501,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,8 +524,8 @@ TEST(FilePersistentMemoryAllocatorTest, AcceptableTest) {
// filesize < minsize.
EXPECT_GT(minsize, filesize);
}
-#endif
}
}
+#endif // !DCHECK_IS_ON()
} // namespace base
« 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