OLD | NEW |
---|---|
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 // In future, if support is conditional on a runtime check, we'll need another | |
12 // case here. | |
Avi (use Gerrit)
2013/06/20 21:16:41
... especially here; the idea that the #define wou
| |
13 #if defined(DISCARDABLE_MEMORY_SUPPORTED_NATIVELY) | |
14 ASSERT_TRUE(DiscardableMemory::SupportedNatively()); | |
15 #else | |
16 ASSERT_FALSE(DiscardableMemory::SupportedNatively()); | |
17 #endif | |
18 } | |
19 | |
11 // Test Lock() and Unlock() functionalities. | 20 // Test Lock() and Unlock() functionalities. |
12 TEST(DiscardableMemoryTest, LockAndUnLock) { | 21 TEST(DiscardableMemoryTest, LockAndUnLock) { |
13 ASSERT_TRUE(DiscardableMemory::Supported()); | |
14 | |
15 const size_t size = 1024; | 22 const size_t size = 1024; |
16 | 23 |
17 DiscardableMemory memory; | 24 DiscardableMemory memory; |
18 ASSERT_TRUE(memory.InitializeAndLock(size)); | 25 ASSERT_TRUE(memory.InitializeAndLock(size)); |
19 void* addr = memory.Memory(); | 26 void* addr = memory.Memory(); |
20 ASSERT_NE(static_cast<void*>(NULL), addr); | 27 ASSERT_NE(static_cast<void*>(NULL), addr); |
21 | 28 |
22 memory.Unlock(); | 29 memory.Unlock(); |
23 // The system should have no reason to purge discardable blocks in this brief | 30 // The system should have no reason to purge discardable blocks in this brief |
24 // interval, though technically speaking this might flake. | 31 // interval, though technically speaking this might flake. |
25 EXPECT_EQ(DISCARDABLE_MEMORY_SUCCESS, memory.Lock()); | 32 EXPECT_EQ(DISCARDABLE_MEMORY_SUCCESS, memory.Lock()); |
26 addr = memory.Memory(); | 33 addr = memory.Memory(); |
27 ASSERT_NE(static_cast<void*>(NULL), addr); | 34 ASSERT_NE(static_cast<void*>(NULL), addr); |
28 | 35 |
29 memory.Unlock(); | 36 memory.Unlock(); |
30 } | 37 } |
31 | 38 |
32 // Test delete a discardable memory while it is locked. | 39 // Test delete a discardable memory while it is locked. |
33 TEST(DiscardableMemoryTest, DeleteWhileLocked) { | 40 TEST(DiscardableMemoryTest, DeleteWhileLocked) { |
34 ASSERT_TRUE(DiscardableMemory::Supported()); | |
35 | |
36 const size_t size = 1024; | 41 const size_t size = 1024; |
37 | 42 |
38 DiscardableMemory memory; | 43 DiscardableMemory memory; |
39 ASSERT_TRUE(memory.InitializeAndLock(size)); | 44 ASSERT_TRUE(memory.InitializeAndLock(size)); |
40 } | 45 } |
41 | 46 |
42 #if defined(OS_MACOSX) | 47 #if !defined(OS_ANDROID) |
43 // Test forced purging. | 48 // Test forced purging. |
44 TEST(DiscardableMemoryTest, Purge) { | 49 TEST(DiscardableMemoryTest, Purge) { |
45 ASSERT_TRUE(DiscardableMemory::Supported()); | |
46 ASSERT_TRUE(DiscardableMemory::PurgeForTestingSupported()); | 50 ASSERT_TRUE(DiscardableMemory::PurgeForTestingSupported()); |
47 | 51 |
48 const size_t size = 1024; | 52 const size_t size = 1024; |
49 | 53 |
50 DiscardableMemory memory; | 54 DiscardableMemory memory; |
51 ASSERT_TRUE(memory.InitializeAndLock(size)); | 55 ASSERT_TRUE(memory.InitializeAndLock(size)); |
52 memory.Unlock(); | 56 memory.Unlock(); |
53 | 57 |
54 DiscardableMemory::PurgeForTesting(); | 58 DiscardableMemory::PurgeForTesting(); |
55 EXPECT_EQ(DISCARDABLE_MEMORY_PURGED, memory.Lock()); | 59 EXPECT_EQ(DISCARDABLE_MEMORY_PURGED, memory.Lock()); |
56 } | 60 } |
57 #endif // OS_MACOSX | 61 #endif // !OS_ANDROID |
58 | |
59 #endif // OS_* | |
60 | 62 |
61 } | 63 } |
OLD | NEW |