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

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

Issue 25293002: Add DiscardableMemoryAllocator to work around FD limit issue. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase 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
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 <limits>
6
5 #include "base/memory/discardable_memory.h" 7 #include "base/memory/discardable_memory.h"
willchan no longer on Chromium 2013/12/01 00:58:56 foo.h always goes first in foo_unittest.cc, see th
Philippe 2013/12/02 10:56:39 Done.
6 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
7 9
8 namespace base { 10 namespace base {
9 11
10 const size_t kSize = 1024; 12 const size_t kSize = 1024;
11 13
14 TEST(DiscardableMemoryTest, TooLargeAllocationFails) {
15 const size_t kPageSize = 4096;
16 const size_t max_allowed_allocation_size =
17 std::numeric_limits<size_t>::max() - kPageSize + 1;
18 scoped_ptr<DiscardableMemory> memory(
19 DiscardableMemory::CreateLockedMemory(max_allowed_allocation_size + 1));
20 // On certain platforms (e.g. Android), page-alignment would have caused an
21 // overflow resulting in a small allocation if the input size wasn't checked
22 // correctly.
23 ASSERT_FALSE(memory);
24 }
25
12 TEST(DiscardableMemoryTest, SupportedNatively) { 26 TEST(DiscardableMemoryTest, SupportedNatively) {
13 #if defined(DISCARDABLE_MEMORY_ALWAYS_SUPPORTED_NATIVELY) 27 #if defined(DISCARDABLE_MEMORY_ALWAYS_SUPPORTED_NATIVELY)
14 ASSERT_TRUE(DiscardableMemory::SupportedNatively()); 28 ASSERT_TRUE(DiscardableMemory::SupportedNatively());
15 #else 29 #else
16 // If we ever have a platform that decides at runtime if it can support 30 // 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 31 // 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 32 // natively' define for this case. At present, if it's not always supported
19 // natively, it's never supported. 33 // natively, it's never supported.
20 ASSERT_FALSE(DiscardableMemory::SupportedNatively()); 34 ASSERT_FALSE(DiscardableMemory::SupportedNatively());
21 #endif 35 #endif
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 const scoped_ptr<DiscardableMemory> memory( 81 const scoped_ptr<DiscardableMemory> memory(
68 DiscardableMemory::CreateLockedMemory(kSize)); 82 DiscardableMemory::CreateLockedMemory(kSize));
69 ASSERT_TRUE(memory); 83 ASSERT_TRUE(memory);
70 memory->Unlock(); 84 memory->Unlock();
71 ASSERT_DEATH_IF_SUPPORTED( 85 ASSERT_DEATH_IF_SUPPORTED(
72 { *static_cast<int*>(memory->Memory()) = 0xdeadbeef; }, ".*"); 86 { *static_cast<int*>(memory->Memory()) = 0xdeadbeef; }, ".*");
73 } 87 }
74 #endif 88 #endif
75 89
76 } 90 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698