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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 | 106 // Test behavior when creating enough instances that could use up a 32-bit |
107 // address space. | 107 // address space. |
| 108 // This is disabled under AddressSanitizer on Windows as it crashes (by design) |
| 109 // on OOM. See http://llvm.org/PR22026 for the details. |
| 110 #if !defined(ADDRESS_SANITIZER) || !defined(OS_WIN) |
108 TEST_P(DiscardableMemoryTest, AddressSpace) { | 111 TEST_P(DiscardableMemoryTest, AddressSpace) { |
109 const size_t kLargeSize = 4 * 1024 * 1024; // 4MiB. | 112 const size_t kLargeSize = 4 * 1024 * 1024; // 4MiB. |
110 const size_t kNumberOfInstances = 1024 + 1; // >4GiB total. | 113 const size_t kNumberOfInstances = 1024 + 1; // >4GiB total. |
111 | 114 |
112 scoped_ptr<DiscardableMemory> instances[kNumberOfInstances]; | 115 scoped_ptr<DiscardableMemory> instances[kNumberOfInstances]; |
113 for (auto& memory : instances) { | 116 for (auto& memory : instances) { |
114 memory = CreateLockedMemory(kLargeSize); | 117 memory = CreateLockedMemory(kLargeSize); |
115 ASSERT_TRUE(memory); | 118 ASSERT_TRUE(memory); |
116 void* addr = memory->Memory(); | 119 void* addr = memory->Memory(); |
117 ASSERT_NE(nullptr, addr); | 120 ASSERT_NE(nullptr, addr); |
118 memory->Unlock(); | 121 memory->Unlock(); |
119 } | 122 } |
120 } | 123 } |
| 124 #endif |
121 | 125 |
122 std::vector<DiscardableMemoryType> GetSupportedDiscardableMemoryTypes() { | 126 std::vector<DiscardableMemoryType> GetSupportedDiscardableMemoryTypes() { |
123 std::vector<DiscardableMemoryType> supported_types; | 127 std::vector<DiscardableMemoryType> supported_types; |
124 DiscardableMemory::GetSupportedTypes(&supported_types); | 128 DiscardableMemory::GetSupportedTypes(&supported_types); |
125 return supported_types; | 129 return supported_types; |
126 } | 130 } |
127 | 131 |
128 INSTANTIATE_TEST_CASE_P( | 132 INSTANTIATE_TEST_CASE_P( |
129 DiscardableMemoryTests, | 133 DiscardableMemoryTests, |
130 DiscardableMemoryTest, | 134 DiscardableMemoryTest, |
131 ::testing::ValuesIn(GetSupportedDiscardableMemoryTypes())); | 135 ::testing::ValuesIn(GetSupportedDiscardableMemoryTypes())); |
132 | 136 |
133 } // namespace | 137 } // namespace |
134 } // namespace base | 138 } // namespace base |
OLD | NEW |