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> | |
reveman
2013/12/10 16:25:46
#if defined(OS_ANDROID) to only include what you n
| |
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 #if defined(OS_ANDROID) | |
16 // TODO(pliard): enable this on all platforms. This currently fails when | |
Philippe
2013/12/10 15:18:38
FYI, I'm not proud of doing this but I want to get
reveman
2013/12/10 15:56:32
I don't think we should have a test that pass a hu
Philippe
2013/12/10 16:00:28
Yeah, agreed. I need to keep it here ideally on An
Philippe
2013/12/10 16:15:07
I would be ok with moving it to the allocator unit
reveman
2013/12/10 16:25:46
I'm fine with an ANDROID ifdef for now.
I think t
Philippe
2013/12/10 16:38:43
Done, thanks.
| |
17 // malloc() is used (by discardable memory emulation) with ASAN due to ASAN | |
18 // asserting that malloc() doesn't return NULL. | |
19 TEST(DiscardableMemoryTest, TooLargeAllocationFails) { | |
20 const size_t kPageSize = 4096; | |
21 const size_t max_allowed_allocation_size = | |
22 std::numeric_limits<size_t>::max() - kPageSize + 1; | |
23 scoped_ptr<DiscardableMemory> memory( | |
24 DiscardableMemory::CreateLockedMemory(max_allowed_allocation_size + 1)); | |
25 // On certain platforms (e.g. Android), page-alignment would have caused an | |
26 // overflow resulting in a small allocation if the input size wasn't checked | |
27 // correctly. | |
28 ASSERT_FALSE(memory); | |
29 } | |
30 #endif | |
31 | |
12 TEST(DiscardableMemoryTest, SupportedNatively) { | 32 TEST(DiscardableMemoryTest, SupportedNatively) { |
13 #if defined(DISCARDABLE_MEMORY_ALWAYS_SUPPORTED_NATIVELY) | 33 #if defined(DISCARDABLE_MEMORY_ALWAYS_SUPPORTED_NATIVELY) |
14 ASSERT_TRUE(DiscardableMemory::SupportedNatively()); | 34 ASSERT_TRUE(DiscardableMemory::SupportedNatively()); |
15 #else | 35 #else |
16 // If we ever have a platform that decides at runtime if it can support | 36 // 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 | 37 // 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 | 38 // natively' define for this case. At present, if it's not always supported |
19 // natively, it's never supported. | 39 // natively, it's never supported. |
20 ASSERT_FALSE(DiscardableMemory::SupportedNatively()); | 40 ASSERT_FALSE(DiscardableMemory::SupportedNatively()); |
21 #endif | 41 #endif |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
67 const scoped_ptr<DiscardableMemory> memory( | 87 const scoped_ptr<DiscardableMemory> memory( |
68 DiscardableMemory::CreateLockedMemory(kSize)); | 88 DiscardableMemory::CreateLockedMemory(kSize)); |
69 ASSERT_TRUE(memory); | 89 ASSERT_TRUE(memory); |
70 memory->Unlock(); | 90 memory->Unlock(); |
71 ASSERT_DEATH_IF_SUPPORTED( | 91 ASSERT_DEATH_IF_SUPPORTED( |
72 { *static_cast<int*>(memory->Memory()) = 0xdeadbeef; }, ".*"); | 92 { *static_cast<int*>(memory->Memory()) = 0xdeadbeef; }, ".*"); |
73 } | 93 } |
74 #endif | 94 #endif |
75 | 95 |
76 } | 96 } |
OLD | NEW |