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

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

Issue 1004043002: Re-land: base: Implement browser process support for discardable memory. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "base/memory/discardable_memory.h"
6
7 #include "testing/gtest/include/gtest/gtest.h"
8
9 namespace base {
10 namespace {
11
12 const size_t kSize = 1024;
13
14 // Test Lock() and Unlock() functionalities.
15 TEST(DiscardableMemoryTest, LockAndUnLock) {
16 const scoped_ptr<DiscardableMemory> memory(
17 DiscardableMemory::CreateLockedMemory(kSize));
18 ASSERT_TRUE(memory);
19 void* addr = memory->Memory();
20 EXPECT_NE(nullptr, addr);
21 memory->Unlock();
22 }
23
24 // Test delete a discardable memory while it is locked.
25 TEST(DiscardableMemoryTest, DeleteWhileLocked) {
26 const scoped_ptr<DiscardableMemory> memory(
27 DiscardableMemory::CreateLockedMemory(kSize));
28 ASSERT_TRUE(memory);
29 }
30
31 #if !defined(NDEBUG) && !defined(OS_ANDROID)
32 // Death tests are not supported with Android APKs.
33 TEST(DiscardableMemoryTest, UnlockedMemoryAccessCrashesInDebugMode) {
34 const scoped_ptr<DiscardableMemory> memory(
35 DiscardableMemory::CreateLockedMemory(kSize));
36 ASSERT_TRUE(memory);
37 memory->Unlock();
38 ASSERT_DEATH_IF_SUPPORTED(
39 { *static_cast<int*>(memory->Memory()) = 0xdeadbeef; }, ".*");
40 }
41 #endif
42
43 // Test behavior when creating enough instances that could use up a 32-bit
44 // address space.
45 // This is disabled under AddressSanitizer on Windows as it crashes (by design)
46 // on OOM. See http://llvm.org/PR22026 for the details.
47 #if !defined(ADDRESS_SANITIZER) || !defined(OS_WIN)
48 TEST(DiscardableMemoryTest, AddressSpace) {
49 const size_t kLargeSize = 4 * 1024 * 1024; // 4MiB.
50 const size_t kNumberOfInstances = 1024 + 1; // >4GiB total.
51
52 scoped_ptr<DiscardableMemory> instances[kNumberOfInstances];
53 for (auto& memory : instances) {
54 memory = DiscardableMemory::CreateLockedMemory(kLargeSize);
55 ASSERT_TRUE(memory);
56 void* addr = memory->Memory();
57 EXPECT_NE(nullptr, addr);
58 memory->Unlock();
59 }
60 }
61 #endif
62
63 } // namespace
64 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698