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

Unified Diff: content/common/host_discardable_shared_memory_manager_unittest.cc

Issue 1409743002: Re-land: base: Use MADV_REMOVE instead of ftruncate to purge discardable memory segments. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix problem with segment having been released before we try to purge Created 5 years, 2 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 | « content/common/host_discardable_shared_memory_manager.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/common/host_discardable_shared_memory_manager_unittest.cc
diff --git a/content/common/host_discardable_shared_memory_manager_unittest.cc b/content/common/host_discardable_shared_memory_manager_unittest.cc
index 40ce711623d1f80bdb97c09c95084fb0d4230bb6..8f09ef05f12962437fa59f091077a8df1eded31d 100644
--- a/content/common/host_discardable_shared_memory_manager_unittest.cc
+++ b/content/common/host_discardable_shared_memory_manager_unittest.cc
@@ -190,5 +190,47 @@ TEST_F(HostDiscardableSharedMemoryManagerTest, EnforceMemoryPolicy) {
EXPECT_EQ(base::DiscardableSharedMemory::FAILED, memory.Lock(0, 0));
}
+TEST_F(HostDiscardableSharedMemoryManagerTest,
+ ReduceMemoryAfterSegmentHasBeenDeleted) {
+ const int kDataSize = 1024;
+
+ base::SharedMemoryHandle shared_handle1;
+ manager_->AllocateLockedDiscardableSharedMemoryForChild(
+ base::GetCurrentProcessHandle(), ChildProcessHost::kInvalidUniqueID,
+ kDataSize, 1, &shared_handle1);
+ ASSERT_TRUE(base::SharedMemory::IsHandleValid(shared_handle1));
+
+ TestDiscardableSharedMemory memory1(shared_handle1);
+ bool rv = memory1.Map(kDataSize);
+ ASSERT_TRUE(rv);
+
+ base::SharedMemoryHandle shared_handle2;
+ manager_->AllocateLockedDiscardableSharedMemoryForChild(
+ base::GetCurrentProcessHandle(), ChildProcessHost::kInvalidUniqueID,
+ kDataSize, 2, &shared_handle2);
+ ASSERT_TRUE(base::SharedMemory::IsHandleValid(shared_handle2));
+
+ TestDiscardableSharedMemory memory2(shared_handle2);
+ rv = memory2.Map(kDataSize);
+ ASSERT_TRUE(rv);
+
+ // Unlock and delete segment 1.
+ memory1.SetNow(base::Time::FromDoubleT(1));
+ memory1.Unlock(0, 0);
+ memory1.Unmap();
+ memory1.Close();
+ manager_->ChildDeletedDiscardableSharedMemory(
+ 1, ChildProcessHost::kInvalidUniqueID);
+
+ // Make sure the manager is able to reduce memory after the segment 1 was
+ // deleted.
+ manager_->SetNow(base::Time::FromDoubleT(2));
+ manager_->SetMemoryLimit(0);
+
+ // Unlock segment 2.
+ memory2.SetNow(base::Time::FromDoubleT(3));
+ memory2.Unlock(0, 0);
+}
+
} // namespace
} // namespace content
« no previous file with comments | « content/common/host_discardable_shared_memory_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698