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

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

Issue 17106004: Add discardable memory emulation for non-android/mac platforms (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address review feedback Created 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/memory/discardable_memory.h" 5 #include "base/memory/discardable_memory.h"
6 #include "testing/gtest/include/gtest/gtest.h" 6 #include "testing/gtest/include/gtest/gtest.h"
7 7
8 namespace base { 8 namespace base {
9 9
10 #if defined(OS_ANDROID) || defined(OS_MACOSX) 10 TEST(DiscardableMemoryTest, SupportedNatively) {
11 #if defined(DISCARDABLE_MEMORY_ALWAYS_SUPPORTED_NATIVELY)
12 ASSERT_TRUE(DiscardableMemory::SupportedNatively());
13 #else
14 // If we ever have a platform that decides at runtime if it can support
15 // discardable memory natively, then we'll have to add a 'never supported
16 // natively' define for this case. At present, if it's not always supported
17 // natively, it's never supported.
18 ASSERT_FALSE(DiscardableMemory::SupportedNatively());
19 #endif
20 }
21
11 // Test Lock() and Unlock() functionalities. 22 // Test Lock() and Unlock() functionalities.
12 TEST(DiscardableMemoryTest, LockAndUnLock) { 23 TEST(DiscardableMemoryTest, LockAndUnLock) {
13 ASSERT_TRUE(DiscardableMemory::Supported());
14
15 const size_t size = 1024; 24 const size_t size = 1024;
16 25
17 DiscardableMemory memory; 26 DiscardableMemory memory;
18 ASSERT_TRUE(memory.InitializeAndLock(size)); 27 ASSERT_TRUE(memory.InitializeAndLock(size));
19 void* addr = memory.Memory(); 28 void* addr = memory.Memory();
20 ASSERT_NE(static_cast<void*>(NULL), addr); 29 ASSERT_NE(static_cast<void*>(NULL), addr);
21 30
22 memory.Unlock(); 31 memory.Unlock();
23 // The system should have no reason to purge discardable blocks in this brief 32 // The system should have no reason to purge discardable blocks in this brief
24 // interval, though technically speaking this might flake. 33 // interval, though technically speaking this might flake.
25 EXPECT_EQ(DISCARDABLE_MEMORY_SUCCESS, memory.Lock()); 34 EXPECT_EQ(DISCARDABLE_MEMORY_SUCCESS, memory.Lock());
26 addr = memory.Memory(); 35 addr = memory.Memory();
27 ASSERT_NE(static_cast<void*>(NULL), addr); 36 ASSERT_NE(static_cast<void*>(NULL), addr);
28 37
29 memory.Unlock(); 38 memory.Unlock();
30 } 39 }
31 40
32 // Test delete a discardable memory while it is locked. 41 // Test delete a discardable memory while it is locked.
33 TEST(DiscardableMemoryTest, DeleteWhileLocked) { 42 TEST(DiscardableMemoryTest, DeleteWhileLocked) {
34 ASSERT_TRUE(DiscardableMemory::Supported());
35
36 const size_t size = 1024; 43 const size_t size = 1024;
37 44
38 DiscardableMemory memory; 45 DiscardableMemory memory;
39 ASSERT_TRUE(memory.InitializeAndLock(size)); 46 ASSERT_TRUE(memory.InitializeAndLock(size));
40 } 47 }
41 48
42 #if defined(OS_MACOSX) 49 #if !defined(OS_ANDROID)
43 // Test forced purging. 50 // Test forced purging.
44 TEST(DiscardableMemoryTest, Purge) { 51 TEST(DiscardableMemoryTest, Purge) {
45 ASSERT_TRUE(DiscardableMemory::Supported());
46 ASSERT_TRUE(DiscardableMemory::PurgeForTestingSupported()); 52 ASSERT_TRUE(DiscardableMemory::PurgeForTestingSupported());
47 53
48 const size_t size = 1024; 54 const size_t size = 1024;
49 55
50 DiscardableMemory memory; 56 DiscardableMemory memory;
51 ASSERT_TRUE(memory.InitializeAndLock(size)); 57 ASSERT_TRUE(memory.InitializeAndLock(size));
52 memory.Unlock(); 58 memory.Unlock();
53 59
54 DiscardableMemory::PurgeForTesting(); 60 DiscardableMemory::PurgeForTesting();
55 EXPECT_EQ(DISCARDABLE_MEMORY_PURGED, memory.Lock()); 61 EXPECT_EQ(DISCARDABLE_MEMORY_PURGED, memory.Lock());
56 } 62 }
57 #endif // OS_MACOSX 63 #endif // !OS_ANDROID
58
59 #endif // OS_*
60 64
61 } 65 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698