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

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

Issue 1001833005: Update from https://crrev.com/320343 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Supress 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
« no previous file with comments | « base/memory/discardable_memory_shmem.cc ('k') | base/memory/discardable_memory_win.cc » ('j') | 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 20 matching lines...) Expand all
31 31
32 const size_t kSize = 1024; 32 const size_t kSize = 1024;
33 33
34 TEST_P(DiscardableMemoryTest, IsNamed) { 34 TEST_P(DiscardableMemoryTest, IsNamed) {
35 std::string type_name(DiscardableMemory::GetTypeName(GetParam())); 35 std::string type_name(DiscardableMemory::GetTypeName(GetParam()));
36 EXPECT_NE("unknown", type_name); 36 EXPECT_NE("unknown", type_name);
37 EXPECT_EQ(GetParam(), DiscardableMemory::GetNamedType(type_name)); 37 EXPECT_EQ(GetParam(), DiscardableMemory::GetNamedType(type_name));
38 } 38 }
39 39
40 bool IsNativeType(DiscardableMemoryType type) { 40 bool IsNativeType(DiscardableMemoryType type) {
41 return type == DISCARDABLE_MEMORY_TYPE_ASHMEM || 41 #if defined(OS_ANDROID)
42 type == DISCARDABLE_MEMORY_TYPE_MACH; 42 // SHMEM is backed by native discardable memory on Android.
43 return type == DISCARDABLE_MEMORY_TYPE_SHMEM;
44 #else
45 return false;
46 #endif
43 } 47 }
44 48
45 TEST_P(DiscardableMemoryTest, SupportedNatively) { 49 TEST_P(DiscardableMemoryTest, SupportedNatively) {
46 std::vector<DiscardableMemoryType> supported_types; 50 std::vector<DiscardableMemoryType> supported_types;
47 DiscardableMemory::GetSupportedTypes(&supported_types); 51 DiscardableMemory::GetSupportedTypes(&supported_types);
48 #if defined(DISCARDABLE_MEMORY_ALWAYS_SUPPORTED_NATIVELY) 52 #if defined(DISCARDABLE_MEMORY_ALWAYS_SUPPORTED_NATIVELY)
49 EXPECT_NE(0, std::count_if(supported_types.begin(), 53 EXPECT_NE(0, std::count_if(supported_types.begin(),
50 supported_types.end(), 54 supported_types.end(),
51 IsNativeType)); 55 IsNativeType));
52 #else 56 #else
53 // If we ever have a platform that decides at runtime if it can support 57 // If we ever have a platform that decides at runtime if it can support
54 // discardable memory natively, then we'll have to add a 'never supported 58 // discardable memory natively, then we'll have to add a 'never supported
55 // natively' define for this case. At present, if it's not always supported 59 // natively' define for this case. At present, if it's not always supported
56 // natively, it's never supported. 60 // natively, it's never supported.
57 EXPECT_EQ(0, std::count_if(supported_types.begin(), 61 EXPECT_EQ(0, std::count_if(supported_types.begin(),
58 supported_types.end(), 62 supported_types.end(),
59 IsNativeType)); 63 IsNativeType));
60 #endif 64 #endif
61 } 65 }
62 66
63 // Test Lock() and Unlock() functionalities. 67 // Test Lock() and Unlock() functionalities.
64 TEST_P(DiscardableMemoryTest, LockAndUnLock) { 68 TEST_P(DiscardableMemoryTest, LockAndUnLock) {
65 const scoped_ptr<DiscardableMemory> memory(CreateLockedMemory(kSize)); 69 const scoped_ptr<DiscardableMemory> memory(CreateLockedMemory(kSize));
66 ASSERT_TRUE(memory); 70 ASSERT_TRUE(memory);
67 void* addr = memory->Memory(); 71 void* addr = memory->Memory();
68 ASSERT_NE(nullptr, addr); 72 EXPECT_NE(nullptr, addr);
69
70 memory->Unlock();
71
72 EXPECT_NE(DISCARDABLE_MEMORY_LOCK_STATUS_FAILED, memory->Lock());
73 addr = memory->Memory();
74 ASSERT_NE(nullptr, addr);
75
76 memory->Unlock(); 73 memory->Unlock();
77 } 74 }
78 75
79 // Test delete a discardable memory while it is locked. 76 // Test delete a discardable memory while it is locked.
80 TEST_P(DiscardableMemoryTest, DeleteWhileLocked) { 77 TEST_P(DiscardableMemoryTest, DeleteWhileLocked) {
81 const scoped_ptr<DiscardableMemory> memory(CreateLockedMemory(kSize)); 78 const scoped_ptr<DiscardableMemory> memory(CreateLockedMemory(kSize));
82 ASSERT_TRUE(memory); 79 ASSERT_TRUE(memory);
83 } 80 }
84 81
85 #if !defined(NDEBUG) && !defined(OS_ANDROID) 82 #if !defined(NDEBUG) && !defined(OS_ANDROID)
(...skipping 14 matching lines...) Expand all
100 #if !defined(ADDRESS_SANITIZER) || !defined(OS_WIN) 97 #if !defined(ADDRESS_SANITIZER) || !defined(OS_WIN)
101 TEST_P(DiscardableMemoryTest, AddressSpace) { 98 TEST_P(DiscardableMemoryTest, AddressSpace) {
102 const size_t kLargeSize = 4 * 1024 * 1024; // 4MiB. 99 const size_t kLargeSize = 4 * 1024 * 1024; // 4MiB.
103 const size_t kNumberOfInstances = 1024 + 1; // >4GiB total. 100 const size_t kNumberOfInstances = 1024 + 1; // >4GiB total.
104 101
105 scoped_ptr<DiscardableMemory> instances[kNumberOfInstances]; 102 scoped_ptr<DiscardableMemory> instances[kNumberOfInstances];
106 for (auto& memory : instances) { 103 for (auto& memory : instances) {
107 memory = CreateLockedMemory(kLargeSize); 104 memory = CreateLockedMemory(kLargeSize);
108 ASSERT_TRUE(memory); 105 ASSERT_TRUE(memory);
109 void* addr = memory->Memory(); 106 void* addr = memory->Memory();
110 ASSERT_NE(nullptr, addr); 107 EXPECT_NE(nullptr, addr);
111 memory->Unlock(); 108 memory->Unlock();
112 } 109 }
113 } 110 }
114 #endif 111 #endif
115 112
116 std::vector<DiscardableMemoryType> GetSupportedDiscardableMemoryTypes() { 113 std::vector<DiscardableMemoryType> GetSupportedDiscardableMemoryTypes() {
117 std::vector<DiscardableMemoryType> supported_types; 114 std::vector<DiscardableMemoryType> supported_types;
118 DiscardableMemory::GetSupportedTypes(&supported_types); 115 DiscardableMemory::GetSupportedTypes(&supported_types);
119 return supported_types; 116 return supported_types;
120 } 117 }
121 118
122 INSTANTIATE_TEST_CASE_P( 119 INSTANTIATE_TEST_CASE_P(
123 DiscardableMemoryTests, 120 DiscardableMemoryTests,
124 DiscardableMemoryTest, 121 DiscardableMemoryTest,
125 ::testing::ValuesIn(GetSupportedDiscardableMemoryTypes())); 122 ::testing::ValuesIn(GetSupportedDiscardableMemoryTypes()));
126 123
127 } // namespace 124 } // namespace
128 } // namespace base 125 } // namespace base
OLDNEW
« no previous file with comments | « base/memory/discardable_memory_shmem.cc ('k') | base/memory/discardable_memory_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698