| OLD | NEW |
| 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 Loading... |
| 114 EXPECT_LE(sizeof(TestObject1), allocator_->GetAllocSize(block1)); | 114 EXPECT_LE(sizeof(TestObject1), allocator_->GetAllocSize(block1)); |
| 115 EXPECT_GT(sizeof(TestObject1) + kAllocAlignment, | 115 EXPECT_GT(sizeof(TestObject1) + kAllocAlignment, |
| 116 allocator_->GetAllocSize(block1)); | 116 allocator_->GetAllocSize(block1)); |
| 117 PersistentMemoryAllocator::MemoryInfo meminfo1; | 117 PersistentMemoryAllocator::MemoryInfo meminfo1; |
| 118 allocator_->GetMemoryInfo(&meminfo1); | 118 allocator_->GetMemoryInfo(&meminfo1); |
| 119 EXPECT_EQ(meminfo0.total, meminfo1.total); | 119 EXPECT_EQ(meminfo0.total, meminfo1.total); |
| 120 EXPECT_GT(meminfo0.free, meminfo1.free); | 120 EXPECT_GT(meminfo0.free, meminfo1.free); |
| 121 | 121 |
| 122 // Ensure that the test-object can be made iterable. | 122 // Ensure that the test-object can be made iterable. |
| 123 PersistentMemoryAllocator::Iterator iter1a(allocator_.get()); | 123 PersistentMemoryAllocator::Iterator iter1a(allocator_.get()); |
| 124 EXPECT_EQ(0U, iter1a.GetLast()); |
| 124 uint32_t type; | 125 uint32_t type; |
| 125 EXPECT_EQ(0U, iter1a.GetNext(&type)); | 126 EXPECT_EQ(0U, iter1a.GetNext(&type)); |
| 126 allocator_->MakeIterable(block1); | 127 allocator_->MakeIterable(block1); |
| 127 EXPECT_EQ(block1, iter1a.GetNext(&type)); | 128 EXPECT_EQ(block1, iter1a.GetNext(&type)); |
| 128 EXPECT_EQ(1U, type); | 129 EXPECT_EQ(1U, type); |
| 130 EXPECT_EQ(block1, iter1a.GetLast()); |
| 129 EXPECT_EQ(0U, iter1a.GetNext(&type)); | 131 EXPECT_EQ(0U, iter1a.GetNext(&type)); |
| 132 EXPECT_EQ(block1, iter1a.GetLast()); |
| 130 | 133 |
| 131 // Create second test-object and ensure everything is good and it cannot | 134 // Create second test-object and ensure everything is good and it cannot |
| 132 // be confused with test-object of another type. | 135 // be confused with test-object of another type. |
| 133 Reference block2 = allocator_->Allocate(sizeof(TestObject2), 2); | 136 Reference block2 = allocator_->Allocate(sizeof(TestObject2), 2); |
| 134 EXPECT_NE(0U, block2); | 137 EXPECT_NE(0U, block2); |
| 135 EXPECT_NE(nullptr, allocator_->GetAsObject<TestObject2>(block2, 2)); | 138 EXPECT_NE(nullptr, allocator_->GetAsObject<TestObject2>(block2, 2)); |
| 136 EXPECT_EQ(nullptr, allocator_->GetAsObject<TestObject2>(block2, 1)); | 139 EXPECT_EQ(nullptr, allocator_->GetAsObject<TestObject2>(block2, 1)); |
| 137 EXPECT_LE(sizeof(TestObject2), allocator_->GetAllocSize(block2)); | 140 EXPECT_LE(sizeof(TestObject2), allocator_->GetAllocSize(block2)); |
| 138 EXPECT_GT(sizeof(TestObject2) + kAllocAlignment, | 141 EXPECT_GT(sizeof(TestObject2) + kAllocAlignment, |
| 139 allocator_->GetAllocSize(block2)); | 142 allocator_->GetAllocSize(block2)); |
| 140 PersistentMemoryAllocator::MemoryInfo meminfo2; | 143 PersistentMemoryAllocator::MemoryInfo meminfo2; |
| 141 allocator_->GetMemoryInfo(&meminfo2); | 144 allocator_->GetMemoryInfo(&meminfo2); |
| 142 EXPECT_EQ(meminfo1.total, meminfo2.total); | 145 EXPECT_EQ(meminfo1.total, meminfo2.total); |
| 143 EXPECT_GT(meminfo1.free, meminfo2.free); | 146 EXPECT_GT(meminfo1.free, meminfo2.free); |
| 144 | 147 |
| 145 // Ensure that second test-object can also be made iterable. | 148 // Ensure that second test-object can also be made iterable. |
| 146 allocator_->MakeIterable(block2); | 149 allocator_->MakeIterable(block2); |
| 147 EXPECT_EQ(block2, iter1a.GetNext(&type)); | 150 EXPECT_EQ(block2, iter1a.GetNext(&type)); |
| 148 EXPECT_EQ(2U, type); | 151 EXPECT_EQ(2U, type); |
| 152 EXPECT_EQ(block2, iter1a.GetLast()); |
| 153 EXPECT_EQ(0U, iter1a.GetNext(&type)); |
| 154 EXPECT_EQ(block2, iter1a.GetLast()); |
| 155 |
| 156 // Check that the iterator can be reset to the beginning. |
| 157 iter1a.Reset(); |
| 158 EXPECT_EQ(0U, iter1a.GetLast()); |
| 159 EXPECT_EQ(block1, iter1a.GetNext(&type)); |
| 160 EXPECT_EQ(block1, iter1a.GetLast()); |
| 161 EXPECT_EQ(block2, iter1a.GetNext(&type)); |
| 162 EXPECT_EQ(block2, iter1a.GetLast()); |
| 163 EXPECT_EQ(0U, iter1a.GetNext(&type)); |
| 164 |
| 165 // Check that the iterator can be reset to an arbitrary location. |
| 166 iter1a.Reset(block1); |
| 167 EXPECT_EQ(block1, iter1a.GetLast()); |
| 168 EXPECT_EQ(block2, iter1a.GetNext(&type)); |
| 169 EXPECT_EQ(block2, iter1a.GetLast()); |
| 149 EXPECT_EQ(0U, iter1a.GetNext(&type)); | 170 EXPECT_EQ(0U, iter1a.GetNext(&type)); |
| 150 | 171 |
| 151 // Check that iteration can begin after an arbitrary location. | 172 // Check that iteration can begin after an arbitrary location. |
| 152 PersistentMemoryAllocator::Iterator iter1b(allocator_.get(), block1); | 173 PersistentMemoryAllocator::Iterator iter1b(allocator_.get(), block1); |
| 153 EXPECT_EQ(block2, iter1b.GetNext(&type)); | 174 EXPECT_EQ(block2, iter1b.GetNext(&type)); |
| 154 EXPECT_EQ(0U, iter1b.GetNext(&type)); | 175 EXPECT_EQ(0U, iter1b.GetNext(&type)); |
| 155 | 176 |
| 156 // Ensure nothing has gone noticably wrong. | 177 // Ensure nothing has gone noticably wrong. |
| 157 EXPECT_FALSE(allocator_->IsFull()); | 178 EXPECT_FALSE(allocator_->IsFull()); |
| 158 EXPECT_FALSE(allocator_->IsCorrupt()); | 179 EXPECT_FALSE(allocator_->IsCorrupt()); |
| (...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 806 // For filesize >= minsize, the file must be acceptable. This | 827 // For filesize >= minsize, the file must be acceptable. This |
| 807 // else clause (file-not-acceptable) should be reached only if | 828 // else clause (file-not-acceptable) should be reached only if |
| 808 // filesize < minsize. | 829 // filesize < minsize. |
| 809 EXPECT_GT(minsize, filesize); | 830 EXPECT_GT(minsize, filesize); |
| 810 } | 831 } |
| 811 } | 832 } |
| 812 } | 833 } |
| 813 #endif // !defined(OS_NACL) | 834 #endif // !defined(OS_NACL) |
| 814 | 835 |
| 815 } // namespace base | 836 } // namespace base |
| OLD | NEW |