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

Side by Side Diff: base/memory/discardable_shared_memory_unittest.cc

Issue 1146103002: content: Close in-process discardable memory segments. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix comment typo Created 5 years, 7 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
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 "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/memory/discardable_shared_memory.h" 6 #include "base/memory/discardable_shared_memory.h"
7 #include "base/process/process_metrics.h" 7 #include "base/process/process_metrics.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 namespace base { 10 namespace base {
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 299
300 TEST(DiscardableSharedMemoryTest, MappedSize) { 300 TEST(DiscardableSharedMemoryTest, MappedSize) {
301 const uint32 kDataSize = 1024; 301 const uint32 kDataSize = 1024;
302 302
303 TestDiscardableSharedMemory memory; 303 TestDiscardableSharedMemory memory;
304 bool rv = memory.CreateAndMap(kDataSize); 304 bool rv = memory.CreateAndMap(kDataSize);
305 ASSERT_TRUE(rv); 305 ASSERT_TRUE(rv);
306 306
307 EXPECT_LE(kDataSize, memory.mapped_size()); 307 EXPECT_LE(kDataSize, memory.mapped_size());
308 308
309 // Mapped size should be 0 after memory segment has been closed. 309 // Mapped size should be 0 after memory segment has been unmapped.
310 rv = memory.Unmap();
311 EXPECT_TRUE(rv);
312 EXPECT_EQ(0u, memory.mapped_size());
313 }
314
315 TEST(DiscardableSharedMemoryTest, Close) {
316 const uint32 kDataSize = 1024;
317
318 TestDiscardableSharedMemory memory;
319 bool rv = memory.CreateAndMap(kDataSize);
320 ASSERT_TRUE(rv);
321
322 // Mapped size should be unchanged after memory segment has been closed.
310 memory.Close(); 323 memory.Close();
311 EXPECT_EQ(0u, memory.mapped_size()); 324 EXPECT_LE(kDataSize, memory.mapped_size());
325
326 // Memory is initially locked. Unlock it.
327 memory.SetNow(Time::FromDoubleT(1));
328 memory.Unlock(0, 0);
329
330 // Lock and unlock memory.
331 auto lock_rv = memory.Lock(0, 0);
332 EXPECT_EQ(DiscardableSharedMemory::SUCCESS, lock_rv);
333 memory.SetNow(Time::FromDoubleT(2));
334 memory.Unlock(0, 0);
312 } 335 }
313 336
314 #if defined(DISCARDABLE_SHARED_MEMORY_SHRINKING) 337 #if defined(DISCARDABLE_SHARED_MEMORY_SHRINKING)
315 TEST(DiscardableSharedMemoryTest, Shrink) { 338 TEST(DiscardableSharedMemoryTest, Shrink) {
316 const uint32 kDataSize = 1024; 339 const uint32 kDataSize = 1024;
317 340
318 TestDiscardableSharedMemory memory; 341 TestDiscardableSharedMemory memory;
319 bool rv = memory.CreateAndMap(kDataSize); 342 bool rv = memory.CreateAndMap(kDataSize);
320 ASSERT_TRUE(rv); 343 ASSERT_TRUE(rv);
321 344
322 EXPECT_NE(0u, memory.mapped_size()); 345 EXPECT_NE(0u, memory.mapped_size());
323 346
324 // Mapped size should be 0 after shrinking memory segment. 347 // Mapped size should be 0 after shrinking memory segment.
325 memory.Shrink(); 348 memory.Shrink();
326 EXPECT_EQ(0u, memory.mapped_size()); 349 EXPECT_EQ(0u, memory.mapped_size());
327 } 350 }
328 #endif 351 #endif
329 352
330 } // namespace 353 } // namespace
331 } // namespace base 354 } // namespace base
OLDNEW
« no previous file with comments | « base/memory/discardable_shared_memory.cc ('k') | content/common/host_discardable_shared_memory_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698