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 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 } | 70 } |
71 | 71 |
72 // Test Lock() and Unlock() functionalities. | 72 // Test Lock() and Unlock() functionalities. |
73 TEST_P(DiscardableMemoryTest, LockAndUnLock) { | 73 TEST_P(DiscardableMemoryTest, LockAndUnLock) { |
74 const scoped_ptr<DiscardableMemory> memory(CreateLockedMemory(kSize)); | 74 const scoped_ptr<DiscardableMemory> memory(CreateLockedMemory(kSize)); |
75 ASSERT_TRUE(memory); | 75 ASSERT_TRUE(memory); |
76 void* addr = memory->Memory(); | 76 void* addr = memory->Memory(); |
77 ASSERT_NE(static_cast<void*>(NULL), addr); | 77 ASSERT_NE(static_cast<void*>(NULL), addr); |
78 | 78 |
79 memory->Unlock(); | 79 memory->Unlock(); |
80 // The system should have no reason to purge discardable blocks in this brief | 80 |
81 // interval, though technically speaking this might flake. | 81 EXPECT_NE(DISCARDABLE_MEMORY_LOCK_STATUS_FAILED, memory->Lock()); |
82 EXPECT_EQ(DISCARDABLE_MEMORY_LOCK_STATUS_SUCCESS, memory->Lock()); | |
83 addr = memory->Memory(); | 82 addr = memory->Memory(); |
84 ASSERT_NE(static_cast<void*>(NULL), addr); | 83 ASSERT_NE(static_cast<void*>(NULL), addr); |
85 | 84 |
86 memory->Unlock(); | 85 memory->Unlock(); |
87 } | 86 } |
88 | 87 |
89 // Test delete a discardable memory while it is locked. | 88 // Test delete a discardable memory while it is locked. |
90 TEST_P(DiscardableMemoryTest, DeleteWhileLocked) { | 89 TEST_P(DiscardableMemoryTest, DeleteWhileLocked) { |
91 const scoped_ptr<DiscardableMemory> memory(CreateLockedMemory(kSize)); | 90 const scoped_ptr<DiscardableMemory> memory(CreateLockedMemory(kSize)); |
92 ASSERT_TRUE(memory); | 91 ASSERT_TRUE(memory); |
(...skipping 30 matching lines...) Expand all Loading... |
123 return supported_types; | 122 return supported_types; |
124 } | 123 } |
125 | 124 |
126 INSTANTIATE_TEST_CASE_P( | 125 INSTANTIATE_TEST_CASE_P( |
127 DiscardableMemoryTests, | 126 DiscardableMemoryTests, |
128 DiscardableMemoryTest, | 127 DiscardableMemoryTest, |
129 ::testing::ValuesIn(GetSupportedDiscardableMemoryTypes())); | 128 ::testing::ValuesIn(GetSupportedDiscardableMemoryTypes())); |
130 | 129 |
131 } // namespace | 130 } // namespace |
132 } // namespace base | 131 } // namespace base |
OLD | NEW |