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 "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 // Death tests are not supported with Android APKs. | 96 // Death tests are not supported with Android APKs. |
97 TEST_P(DiscardableMemoryTest, UnlockedMemoryAccessCrashesInDebugMode) { | 97 TEST_P(DiscardableMemoryTest, UnlockedMemoryAccessCrashesInDebugMode) { |
98 const scoped_ptr<DiscardableMemory> memory(CreateLockedMemory(kSize)); | 98 const scoped_ptr<DiscardableMemory> memory(CreateLockedMemory(kSize)); |
99 ASSERT_TRUE(memory); | 99 ASSERT_TRUE(memory); |
100 memory->Unlock(); | 100 memory->Unlock(); |
101 ASSERT_DEATH_IF_SUPPORTED( | 101 ASSERT_DEATH_IF_SUPPORTED( |
102 { *static_cast<int*>(memory->Memory()) = 0xdeadbeef; }, ".*"); | 102 { *static_cast<int*>(memory->Memory()) = 0xdeadbeef; }, ".*"); |
103 } | 103 } |
104 #endif | 104 #endif |
105 | 105 |
| 106 // Test behavior when creating enough instances that could use up a 32-bit |
| 107 // address space. |
| 108 TEST_P(DiscardableMemoryTest, AddressSpace) { |
| 109 const size_t kLargeSize = 4 * 1024 * 1024; // 4MiB. |
| 110 const size_t kNumberOfInstances = 1024 + 1; // >4GiB total. |
| 111 |
| 112 scoped_ptr<DiscardableMemory> instances[kNumberOfInstances]; |
| 113 for (auto& memory : instances) { |
| 114 memory = CreateLockedMemory(kLargeSize); |
| 115 ASSERT_TRUE(memory); |
| 116 void* addr = memory->Memory(); |
| 117 ASSERT_NE(nullptr, addr); |
| 118 memory->Unlock(); |
| 119 } |
| 120 } |
| 121 |
106 std::vector<DiscardableMemoryType> GetSupportedDiscardableMemoryTypes() { | 122 std::vector<DiscardableMemoryType> GetSupportedDiscardableMemoryTypes() { |
107 std::vector<DiscardableMemoryType> supported_types; | 123 std::vector<DiscardableMemoryType> supported_types; |
108 DiscardableMemory::GetSupportedTypes(&supported_types); | 124 DiscardableMemory::GetSupportedTypes(&supported_types); |
109 return supported_types; | 125 return supported_types; |
110 } | 126 } |
111 | 127 |
112 INSTANTIATE_TEST_CASE_P( | 128 INSTANTIATE_TEST_CASE_P( |
113 DiscardableMemoryTests, | 129 DiscardableMemoryTests, |
114 DiscardableMemoryTest, | 130 DiscardableMemoryTest, |
115 ::testing::ValuesIn(GetSupportedDiscardableMemoryTypes())); | 131 ::testing::ValuesIn(GetSupportedDiscardableMemoryTypes())); |
116 | 132 |
117 } // namespace | 133 } // namespace |
118 } // namespace base | 134 } // namespace base |
OLD | NEW |