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

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

Issue 100103003: Revert 239763 "Add DiscardableMemoryAllocator to minimize use of..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: 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 | « trunk/src/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
9 #include "testing/gtest/include/gtest/gtest.h" 6 #include "testing/gtest/include/gtest/gtest.h"
10 7
11 namespace base { 8 namespace base {
12 9
13 const size_t kSize = 1024; 10 const size_t kSize = 1024;
14 11
15 TEST(DiscardableMemoryTest, TooLargeAllocationFails) {
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
27 TEST(DiscardableMemoryTest, SupportedNatively) { 12 TEST(DiscardableMemoryTest, SupportedNatively) {
28 #if defined(DISCARDABLE_MEMORY_ALWAYS_SUPPORTED_NATIVELY) 13 #if defined(DISCARDABLE_MEMORY_ALWAYS_SUPPORTED_NATIVELY)
29 ASSERT_TRUE(DiscardableMemory::SupportedNatively()); 14 ASSERT_TRUE(DiscardableMemory::SupportedNatively());
30 #else 15 #else
31 // If we ever have a platform that decides at runtime if it can support 16 // If we ever have a platform that decides at runtime if it can support
32 // discardable memory natively, then we'll have to add a 'never supported 17 // discardable memory natively, then we'll have to add a 'never supported
33 // natively' define for this case. At present, if it's not always supported 18 // natively' define for this case. At present, if it's not always supported
34 // natively, it's never supported. 19 // natively, it's never supported.
35 ASSERT_FALSE(DiscardableMemory::SupportedNatively()); 20 ASSERT_FALSE(DiscardableMemory::SupportedNatively());
36 #endif 21 #endif
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 const scoped_ptr<DiscardableMemory> memory( 67 const scoped_ptr<DiscardableMemory> memory(
83 DiscardableMemory::CreateLockedMemory(kSize)); 68 DiscardableMemory::CreateLockedMemory(kSize));
84 ASSERT_TRUE(memory); 69 ASSERT_TRUE(memory);
85 memory->Unlock(); 70 memory->Unlock();
86 ASSERT_DEATH_IF_SUPPORTED( 71 ASSERT_DEATH_IF_SUPPORTED(
87 { *static_cast<int*>(memory->Memory()) = 0xdeadbeef; }, ".*"); 72 { *static_cast<int*>(memory->Memory()) = 0xdeadbeef; }, ".*");
88 } 73 }
89 #endif 74 #endif
90 75
91 } 76 }
OLDNEW
« no previous file with comments | « trunk/src/base/memory/discardable_memory_android.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698