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

Side by Side Diff: base/metrics/persistent_memory_allocator_unittest.cc

Issue 2534643002: Add support for turning pointers back to references. (Closed)
Patch Set: added underflow check Created 4 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
« no previous file with comments | « base/metrics/persistent_memory_allocator.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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/metrics/persistent_memory_allocator.h" 5 #include "base/metrics/persistent_memory_allocator.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/files/file.h" 9 #include "base/files/file.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 EXPECT_NE(nullptr, allocator_->GetAsObject<TestObject1>(block1, 1)); 114 EXPECT_NE(nullptr, allocator_->GetAsObject<TestObject1>(block1, 1));
115 EXPECT_EQ(nullptr, allocator_->GetAsObject<TestObject2>(block1, 1)); 115 EXPECT_EQ(nullptr, allocator_->GetAsObject<TestObject2>(block1, 1));
116 EXPECT_LE(sizeof(TestObject1), allocator_->GetAllocSize(block1)); 116 EXPECT_LE(sizeof(TestObject1), allocator_->GetAllocSize(block1));
117 EXPECT_GT(sizeof(TestObject1) + kAllocAlignment, 117 EXPECT_GT(sizeof(TestObject1) + kAllocAlignment,
118 allocator_->GetAllocSize(block1)); 118 allocator_->GetAllocSize(block1));
119 PersistentMemoryAllocator::MemoryInfo meminfo1; 119 PersistentMemoryAllocator::MemoryInfo meminfo1;
120 allocator_->GetMemoryInfo(&meminfo1); 120 allocator_->GetMemoryInfo(&meminfo1);
121 EXPECT_EQ(meminfo0.total, meminfo1.total); 121 EXPECT_EQ(meminfo0.total, meminfo1.total);
122 EXPECT_GT(meminfo0.free, meminfo1.free); 122 EXPECT_GT(meminfo0.free, meminfo1.free);
123 123
124 // Verify that pointers can be turned back into references and that invalid
125 // addresses return null.
126 char* memory1 = allocator_->GetAsArray<char>(block1, 1, 1);
127 ASSERT_TRUE(memory1);
128 EXPECT_EQ(block1, allocator_->GetAsReference(memory1, 0));
129 EXPECT_EQ(block1, allocator_->GetAsReference(memory1, 1));
130 EXPECT_EQ(0U, allocator_->GetAsReference(memory1, 2));
131 EXPECT_EQ(0U, allocator_->GetAsReference(memory1 + 1, 0));
132 EXPECT_EQ(0U, allocator_->GetAsReference(memory1 + 16, 0));
133 EXPECT_EQ(0U, allocator_->GetAsReference(nullptr, 0));
134 EXPECT_EQ(0U, allocator_->GetAsReference(&base_name, 0));
135
124 // Ensure that the test-object can be made iterable. 136 // Ensure that the test-object can be made iterable.
125 PersistentMemoryAllocator::Iterator iter1a(allocator_.get()); 137 PersistentMemoryAllocator::Iterator iter1a(allocator_.get());
126 EXPECT_EQ(0U, iter1a.GetLast()); 138 EXPECT_EQ(0U, iter1a.GetLast());
127 uint32_t type; 139 uint32_t type;
128 EXPECT_EQ(0U, iter1a.GetNext(&type)); 140 EXPECT_EQ(0U, iter1a.GetNext(&type));
129 allocator_->MakeIterable(block1); 141 allocator_->MakeIterable(block1);
130 EXPECT_EQ(block1, iter1a.GetNext(&type)); 142 EXPECT_EQ(block1, iter1a.GetNext(&type));
131 EXPECT_EQ(1U, type); 143 EXPECT_EQ(1U, type);
132 EXPECT_EQ(block1, iter1a.GetLast()); 144 EXPECT_EQ(block1, iter1a.GetLast());
133 EXPECT_EQ(0U, iter1a.GetNext(&type)); 145 EXPECT_EQ(0U, iter1a.GetNext(&type));
(...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after
830 // For filesize >= minsize, the file must be acceptable. This 842 // For filesize >= minsize, the file must be acceptable. This
831 // else clause (file-not-acceptable) should be reached only if 843 // else clause (file-not-acceptable) should be reached only if
832 // filesize < minsize. 844 // filesize < minsize.
833 EXPECT_GT(minsize, filesize); 845 EXPECT_GT(minsize, filesize);
834 } 846 }
835 } 847 }
836 } 848 }
837 #endif // !defined(OS_NACL) 849 #endif // !defined(OS_NACL)
838 850
839 } // namespace base 851 } // namespace base
OLDNEW
« no previous file with comments | « base/metrics/persistent_memory_allocator.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698