Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(751)

Side by Side Diff: base/memory/discardable_memory_unittest.cc

Issue 101953003: Revert "Revert 239763 "Add DiscardableMemoryAllocator to minimize use of..."" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove comment Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/memory/discardable_memory_android.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #if defined(OS_ANDROID)
16 TEST(DiscardableMemoryTest, TooLargeAllocationFails) {
17 const size_t kPageSize = 4096;
18 const size_t max_allowed_allocation_size =
19 std::numeric_limits<size_t>::max() - kPageSize + 1;
20 scoped_ptr<DiscardableMemory> memory(
21 DiscardableMemory::CreateLockedMemory(max_allowed_allocation_size + 1));
22 // On certain platforms (e.g. Android), page-alignment would have caused an
23 // overflow resulting in a small allocation if the input size wasn't checked
24 // correctly.
25 ASSERT_FALSE(memory);
26 }
27 #endif
28
12 TEST(DiscardableMemoryTest, SupportedNatively) { 29 TEST(DiscardableMemoryTest, SupportedNatively) {
13 #if defined(DISCARDABLE_MEMORY_ALWAYS_SUPPORTED_NATIVELY) 30 #if defined(DISCARDABLE_MEMORY_ALWAYS_SUPPORTED_NATIVELY)
14 ASSERT_TRUE(DiscardableMemory::SupportedNatively()); 31 ASSERT_TRUE(DiscardableMemory::SupportedNatively());
15 #else 32 #else
16 // If we ever have a platform that decides at runtime if it can support 33 // 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 34 // 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 35 // natively' define for this case. At present, if it's not always supported
19 // natively, it's never supported. 36 // natively, it's never supported.
20 ASSERT_FALSE(DiscardableMemory::SupportedNatively()); 37 ASSERT_FALSE(DiscardableMemory::SupportedNatively());
21 #endif 38 #endif
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 const scoped_ptr<DiscardableMemory> memory( 84 const scoped_ptr<DiscardableMemory> memory(
68 DiscardableMemory::CreateLockedMemory(kSize)); 85 DiscardableMemory::CreateLockedMemory(kSize));
69 ASSERT_TRUE(memory); 86 ASSERT_TRUE(memory);
70 memory->Unlock(); 87 memory->Unlock();
71 ASSERT_DEATH_IF_SUPPORTED( 88 ASSERT_DEATH_IF_SUPPORTED(
72 { *static_cast<int*>(memory->Memory()) = 0xdeadbeef; }, ".*"); 89 { *static_cast<int*>(memory->Memory()) = 0xdeadbeef; }, ".*");
73 } 90 }
74 #endif 91 #endif
75 92
76 } 93 }
OLDNEW
« no previous file with comments | « base/memory/discardable_memory_android.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698