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

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

Issue 655003003: base: Add discardable memory test that check behavior when creating enough instances that could use… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 months 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
« no previous file with comments | « no previous file | 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 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 // Death tests are not supported with Android APKs. 96 // Death tests are not supported with Android APKs.
97 TEST_P(DiscardableMemoryTest, UnlockedMemoryAccessCrashesInDebugMode) { 97 TEST_P(DiscardableMemoryTest, UnlockedMemoryAccessCrashesInDebugMode) {
98 const scoped_ptr<DiscardableMemory> memory(CreateLockedMemory(kSize)); 98 const scoped_ptr<DiscardableMemory> memory(CreateLockedMemory(kSize));
99 ASSERT_TRUE(memory); 99 ASSERT_TRUE(memory);
100 memory->Unlock(); 100 memory->Unlock();
101 ASSERT_DEATH_IF_SUPPORTED( 101 ASSERT_DEATH_IF_SUPPORTED(
102 { *static_cast<int*>(memory->Memory()) = 0xdeadbeef; }, ".*"); 102 { *static_cast<int*>(memory->Memory()) = 0xdeadbeef; }, ".*");
103 } 103 }
104 #endif 104 #endif
105 105
106 // Test behavior when creating enough instances that could use up a 32-bit
107 // address space.
108 TEST_P(DiscardableMemoryTest, AddressSpace) {
109 const size_t kLargeSize = 4 * 1024 * 1024; // 4MB.
110 const size_t kNumberOfInstances = 1024 + 1; // >4GiB total.
Avi (use Gerrit) 2014/10/15 21:11:27 Why "4MB" on the line above, and "4GiB" here? Eith
reveman 2014/10/16 20:50:34 Done.
111
112 scoped_ptr<DiscardableMemory> instances[kNumberOfInstances];
113 for (auto& memory : instances) {
114 memory = CreateLockedMemory(kLargeSize);
115 ASSERT_TRUE(memory);
116 void* addr = memory->Memory();
117 ASSERT_NE(static_cast<void*>(NULL), addr);
Avi (use Gerrit) 2014/10/15 21:11:27 nullptr, plus you shouldn't need a cast with it.
reveman 2014/10/16 20:50:34 Done.
118 memory->Unlock();
119 }
120 }
121
106 std::vector<DiscardableMemoryType> GetSupportedDiscardableMemoryTypes() { 122 std::vector<DiscardableMemoryType> GetSupportedDiscardableMemoryTypes() {
107 std::vector<DiscardableMemoryType> supported_types; 123 std::vector<DiscardableMemoryType> supported_types;
108 DiscardableMemory::GetSupportedTypes(&supported_types); 124 DiscardableMemory::GetSupportedTypes(&supported_types);
109 return supported_types; 125 return supported_types;
110 } 126 }
111 127
112 INSTANTIATE_TEST_CASE_P( 128 INSTANTIATE_TEST_CASE_P(
113 DiscardableMemoryTests, 129 DiscardableMemoryTests,
114 DiscardableMemoryTest, 130 DiscardableMemoryTest,
115 ::testing::ValuesIn(GetSupportedDiscardableMemoryTypes())); 131 ::testing::ValuesIn(GetSupportedDiscardableMemoryTypes()));
116 132
117 } // namespace 133 } // namespace
118 } // namespace base 134 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698