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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « content/common/host_discardable_shared_memory_manager.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/common/host_discardable_shared_memory_manager.h" 5 #include "content/common/host_discardable_shared_memory_manager.h"
6 6
7 #include "content/public/common/child_process_host.h" 7 #include "content/public/common/child_process_host.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 namespace content { 10 namespace content {
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 183
184 manager_->set_enforce_memory_policy_pending(false); 184 manager_->set_enforce_memory_policy_pending(false);
185 manager_->SetNow(base::Time::FromDoubleT(4)); 185 manager_->SetNow(base::Time::FromDoubleT(4));
186 manager_->EnforceMemoryPolicy(); 186 manager_->EnforceMemoryPolicy();
187 // Memory policy should have successfully been enforced. 187 // Memory policy should have successfully been enforced.
188 EXPECT_FALSE(manager_->enforce_memory_policy_pending()); 188 EXPECT_FALSE(manager_->enforce_memory_policy_pending());
189 189
190 EXPECT_EQ(base::DiscardableSharedMemory::FAILED, memory.Lock(0, 0)); 190 EXPECT_EQ(base::DiscardableSharedMemory::FAILED, memory.Lock(0, 0));
191 } 191 }
192 192
193 TEST_F(HostDiscardableSharedMemoryManagerTest,
194 ReduceMemoryAfterSegmentHasBeenDeleted) {
195 const int kDataSize = 1024;
196
197 base::SharedMemoryHandle shared_handle1;
198 manager_->AllocateLockedDiscardableSharedMemoryForChild(
199 base::GetCurrentProcessHandle(), ChildProcessHost::kInvalidUniqueID,
200 kDataSize, 1, &shared_handle1);
201 ASSERT_TRUE(base::SharedMemory::IsHandleValid(shared_handle1));
202
203 TestDiscardableSharedMemory memory1(shared_handle1);
204 bool rv = memory1.Map(kDataSize);
205 ASSERT_TRUE(rv);
206
207 base::SharedMemoryHandle shared_handle2;
208 manager_->AllocateLockedDiscardableSharedMemoryForChild(
209 base::GetCurrentProcessHandle(), ChildProcessHost::kInvalidUniqueID,
210 kDataSize, 2, &shared_handle2);
211 ASSERT_TRUE(base::SharedMemory::IsHandleValid(shared_handle2));
212
213 TestDiscardableSharedMemory memory2(shared_handle2);
214 rv = memory2.Map(kDataSize);
215 ASSERT_TRUE(rv);
216
217 // Unlock and delete segment 1.
218 memory1.SetNow(base::Time::FromDoubleT(1));
219 memory1.Unlock(0, 0);
220 memory1.Unmap();
221 memory1.Close();
222 manager_->ChildDeletedDiscardableSharedMemory(
223 1, ChildProcessHost::kInvalidUniqueID);
224
225 // Make sure the manager is able to reduce memory after the segment 1 was
226 // deleted.
227 manager_->SetNow(base::Time::FromDoubleT(2));
228 manager_->SetMemoryLimit(0);
229
230 // Unlock segment 2.
231 memory2.SetNow(base::Time::FromDoubleT(3));
232 memory2.Unlock(0, 0);
233 }
234
193 } // namespace 235 } // namespace
194 } // namespace content 236 } // namespace content
OLDNEW
« 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