Chromium Code Reviews| 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 | |
| 7 #include <limits> | |
| 8 | |
| 6 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 7 | 10 |
| 8 namespace base { | 11 namespace base { |
| 9 | 12 |
| 10 const size_t kSize = 1024; | 13 const size_t kSize = 1024; |
| 11 | 14 |
| 15 TEST(DiscardableMemoryTest, TooLargeAllocationFails) { | |
|
reveman
2013/12/05 23:21:40
The addition of this test is causing emulated disc
| |
| 16 const size_t kPageSize = 4096; | |
| 17 const size_t max_allowed_allocation_size = | |
| 18 std::numeric_limits<size_t>::max() - kPageSize + 1; | |
| 19 scoped_ptr<DiscardableMemory> memory( | |
| 20 DiscardableMemory::CreateLockedMemory(max_allowed_allocation_size + 1)); | |
| 21 // On certain platforms (e.g. Android), page-alignment would have caused an | |
| 22 // overflow resulting in a small allocation if the input size wasn't checked | |
| 23 // correctly. | |
| 24 ASSERT_FALSE(memory); | |
| 25 } | |
| 26 | |
| 12 TEST(DiscardableMemoryTest, SupportedNatively) { | 27 TEST(DiscardableMemoryTest, SupportedNatively) { |
| 13 #if defined(DISCARDABLE_MEMORY_ALWAYS_SUPPORTED_NATIVELY) | 28 #if defined(DISCARDABLE_MEMORY_ALWAYS_SUPPORTED_NATIVELY) |
| 14 ASSERT_TRUE(DiscardableMemory::SupportedNatively()); | 29 ASSERT_TRUE(DiscardableMemory::SupportedNatively()); |
| 15 #else | 30 #else |
| 16 // If we ever have a platform that decides at runtime if it can support | 31 // If we ever have a platform that decides at runtime if it can support |
| 17 // discardable memory natively, then we'll have to add a 'never supported | 32 // discardable memory natively, then we'll have to add a 'never supported |
| 18 // natively' define for this case. At present, if it's not always supported | 33 // natively' define for this case. At present, if it's not always supported |
| 19 // natively, it's never supported. | 34 // natively, it's never supported. |
| 20 ASSERT_FALSE(DiscardableMemory::SupportedNatively()); | 35 ASSERT_FALSE(DiscardableMemory::SupportedNatively()); |
| 21 #endif | 36 #endif |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 67 const scoped_ptr<DiscardableMemory> memory( | 82 const scoped_ptr<DiscardableMemory> memory( |
| 68 DiscardableMemory::CreateLockedMemory(kSize)); | 83 DiscardableMemory::CreateLockedMemory(kSize)); |
| 69 ASSERT_TRUE(memory); | 84 ASSERT_TRUE(memory); |
| 70 memory->Unlock(); | 85 memory->Unlock(); |
| 71 ASSERT_DEATH_IF_SUPPORTED( | 86 ASSERT_DEATH_IF_SUPPORTED( |
| 72 { *static_cast<int*>(memory->Memory()) = 0xdeadbeef; }, ".*"); | 87 { *static_cast<int*>(memory->Memory()) = 0xdeadbeef; }, ".*"); |
| 73 } | 88 } |
| 74 #endif | 89 #endif |
| 75 | 90 |
| 76 } | 91 } |
| OLD | NEW |