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

Unified Diff: base/metrics/persistent_memory_allocator_unittest.cc

Issue 2742193002: Harden allocator for file-backed memory. (Closed)
Patch Set: addressed final review comments Created 3 years, 9 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') | components/metrics/file_metrics_provider.h » ('j') | 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 d12e00f6d6b5d070ab6053184036db014a7db5ff..c3027ecc1211522f6408bce94fbc57b407f70c2b 100644
--- a/base/metrics/persistent_memory_allocator_unittest.cc
+++ b/base/metrics/persistent_memory_allocator_unittest.cc
@@ -100,6 +100,8 @@ TEST_F(PersistentMemoryAllocatorTest, AllocateAndIterate) {
EXPECT_TRUE(allocator_->used_histogram_);
EXPECT_EQ("UMA.PersistentAllocator." + base_name + ".UsedPct",
allocator_->used_histogram_->histogram_name());
+ EXPECT_EQ(PersistentMemoryAllocator::MEMORY_INITIALIZED,
+ allocator_->GetMemoryState());
// Get base memory info for later comparison.
PersistentMemoryAllocator::MemoryInfo meminfo0;
@@ -254,6 +256,11 @@ TEST_F(PersistentMemoryAllocatorTest, AllocateAndIterate) {
allocator_->Delete(obj2);
PersistentMemoryAllocator::Iterator iter1z(allocator_.get());
EXPECT_EQ(nullptr, iter1z.GetNextOfObject<TestObject2>());
+
+ // Ensure that the memory state can be set.
+ allocator_->SetMemoryState(PersistentMemoryAllocator::MEMORY_DELETED);
+ EXPECT_EQ(PersistentMemoryAllocator::MEMORY_DELETED,
+ allocator_->GetMemoryState());
}
TEST_F(PersistentMemoryAllocatorTest, PageTest) {
@@ -691,8 +698,8 @@ TEST(FilePersistentMemoryAllocatorTest, CreationTest) {
const size_t mmlength = mmfile->length();
EXPECT_GE(meminfo1.total, mmlength);
- FilePersistentMemoryAllocator file(std::move(mmfile), 0, 0, "", true);
- EXPECT_TRUE(file.IsReadonly());
+ FilePersistentMemoryAllocator file(std::move(mmfile), 0, 0, "", false);
+ EXPECT_FALSE(file.IsReadonly());
EXPECT_EQ(TEST_ID, file.Id());
EXPECT_FALSE(file.IsFull());
EXPECT_FALSE(file.IsCorrupt());
@@ -713,6 +720,11 @@ TEST(FilePersistentMemoryAllocatorTest, CreationTest) {
EXPECT_GE(meminfo1.free, meminfo2.free);
EXPECT_EQ(mmlength, meminfo2.total);
EXPECT_EQ(0U, meminfo2.free);
+
+ // There's no way of knowing if Flush actually does anything but at least
+ // verify that it runs without CHECK violations.
+ file.Flush(false);
+ file.Flush(true);
}
TEST(FilePersistentMemoryAllocatorTest, ExtendTest) {
« no previous file with comments | « base/metrics/persistent_memory_allocator.cc ('k') | components/metrics/file_metrics_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698