Chromium Code Reviews| 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 |