Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/allocator/partition_allocator/partition_alloc.h" | 5 #include "base/allocator/partition_allocator/partition_alloc.h" |
| 6 | 6 |
| 7 #include <stdlib.h> | 7 #include <stdlib.h> |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 593 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 604 newCharPtr = static_cast<char*>(newPtr); | 604 newCharPtr = static_cast<char*>(newPtr); |
| 605 EXPECT_EQ(*newCharPtr, 'F'); | 605 EXPECT_EQ(*newCharPtr, 'F'); |
| 606 | 606 |
| 607 partitionFreeGeneric(genericAllocator.root(), newPtr); | 607 partitionFreeGeneric(genericAllocator.root(), newPtr); |
| 608 TestShutdown(); | 608 TestShutdown(); |
| 609 } | 609 } |
| 610 | 610 |
| 611 // Test the generic allocation functions can handle some specific sizes of | 611 // Test the generic allocation functions can handle some specific sizes of |
| 612 // interest. | 612 // interest. |
| 613 TEST(PartitionAllocTest, GenericAllocSizes) { | 613 TEST(PartitionAllocTest, GenericAllocSizes) { |
| 614 // TODO(crbug.com/678782): Where necessary and possible, disable the | |
|
Primiano Tucci (use gerrit)
2017/01/06 10:58:36
I don't think this is needed. If you look in the b
danakj
2017/01/06 15:20:10
Maybe we can move the TODO down there then
| |
| 615 // platform's OOM-killing behavior. OOM-killing makes this test flaky on | |
| 616 // low-memory devices. | |
| 617 if (!IsLargeMemoryDevice()) | |
| 618 return; | |
| 619 | |
| 614 TestSetup(); | 620 TestSetup(); |
| 615 | 621 |
| 616 void* ptr = partitionAllocGeneric(genericAllocator.root(), 0, typeName); | 622 void* ptr = partitionAllocGeneric(genericAllocator.root(), 0, typeName); |
| 617 EXPECT_TRUE(ptr); | 623 EXPECT_TRUE(ptr); |
| 618 partitionFreeGeneric(genericAllocator.root(), ptr); | 624 partitionFreeGeneric(genericAllocator.root(), ptr); |
| 619 | 625 |
| 620 // kPartitionPageSize is interesting because it results in just one | 626 // kPartitionPageSize is interesting because it results in just one |
| 621 // allocation per page, which tripped up some corner cases. | 627 // allocation per page, which tripped up some corner cases. |
| 622 size_t size = kPartitionPageSize - kExtraAllocSize; | 628 size_t size = kPartitionPageSize - kExtraAllocSize; |
| 623 ptr = partitionAllocGeneric(genericAllocator.root(), size, typeName); | 629 ptr = partitionAllocGeneric(genericAllocator.root(), size, typeName); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 701 // Do we correctly get a null for a failed allocation? | 707 // Do we correctly get a null for a failed allocation? |
| 702 EXPECT_EQ(0, partitionAllocGenericFlags(genericAllocator.root(), | 708 EXPECT_EQ(0, partitionAllocGenericFlags(genericAllocator.root(), |
| 703 PartitionAllocReturnNull, | 709 PartitionAllocReturnNull, |
| 704 3u * 1024 * 1024 * 1024, typeName)); | 710 3u * 1024 * 1024 * 1024, typeName)); |
| 705 | 711 |
| 706 TestShutdown(); | 712 TestShutdown(); |
| 707 } | 713 } |
| 708 | 714 |
| 709 // Test that we can fetch the real allocated size after an allocation. | 715 // Test that we can fetch the real allocated size after an allocation. |
| 710 TEST(PartitionAllocTest, GenericAllocGetSize) { | 716 TEST(PartitionAllocTest, GenericAllocGetSize) { |
| 717 // TODO(crbug.com/678782): Where necessary and possible, disable the | |
| 718 // platform's OOM-killing behavior. OOM-killing makes this test flaky on | |
| 719 // low-memory devices. | |
| 720 if (!IsLargeMemoryDevice()) | |
|
Primiano Tucci (use gerrit)
2017/01/06 10:58:36
ditto, I added a narrower exclusion below on the p
| |
| 721 return; | |
| 722 | |
| 711 TestSetup(); | 723 TestSetup(); |
| 712 | 724 |
| 713 void* ptr; | 725 void* ptr; |
| 714 size_t requestedSize, actualSize, predictedSize; | 726 size_t requestedSize, actualSize, predictedSize; |
| 715 | 727 |
| 716 EXPECT_TRUE(partitionAllocSupportsGetSize()); | 728 EXPECT_TRUE(partitionAllocSupportsGetSize()); |
| 717 | 729 |
| 718 // Allocate something small. | 730 // Allocate something small. |
| 719 requestedSize = 511 - kExtraAllocSize; | 731 requestedSize = 511 - kExtraAllocSize; |
| 720 predictedSize = | 732 predictedSize = |
| (...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1259 EXPECT_TRUE(bucket->activePagesHead); | 1271 EXPECT_TRUE(bucket->activePagesHead); |
| 1260 EXPECT_TRUE(bucket->emptyPagesHead); | 1272 EXPECT_TRUE(bucket->emptyPagesHead); |
| 1261 EXPECT_TRUE(bucket->decommittedPagesHead); | 1273 EXPECT_TRUE(bucket->decommittedPagesHead); |
| 1262 | 1274 |
| 1263 TestShutdown(); | 1275 TestShutdown(); |
| 1264 } | 1276 } |
| 1265 | 1277 |
| 1266 #if !defined(ARCH_CPU_64_BITS) || defined(OS_POSIX) | 1278 #if !defined(ARCH_CPU_64_BITS) || defined(OS_POSIX) |
| 1267 | 1279 |
| 1268 static void DoReturnNullTest(size_t allocSize) { | 1280 static void DoReturnNullTest(size_t allocSize) { |
| 1281 // TODO(crbug.com/678782): Where necessary and possible, disable the | |
| 1282 // platform's OOM-killing behavior. OOM-killing makes this test flaky on | |
| 1283 // low-memory devices. | |
| 1284 if (!IsLargeMemoryDevice()) | |
| 1285 return; | |
|
Primiano Tucci (use gerrit)
2017/01/06 10:58:36
Maybe add a LOG(WARNING) << "Skipping this test on
| |
| 1286 | |
| 1269 TestSetup(); | 1287 TestSetup(); |
| 1270 | 1288 |
| 1271 EXPECT_TRUE(SetAddressSpaceLimit()); | 1289 EXPECT_TRUE(SetAddressSpaceLimit()); |
| 1272 | 1290 |
| 1273 // Work out the number of allocations for 6 GB of memory. | 1291 // Work out the number of allocations for 6 GB of memory. |
| 1274 const int numAllocations = (6 * 1024 * 1024) / (allocSize / 1024); | 1292 const int numAllocations = (6 * 1024 * 1024) / (allocSize / 1024); |
| 1275 | 1293 |
| 1276 void** ptrs = reinterpret_cast<void**>(partitionAllocGeneric( | 1294 void** ptrs = reinterpret_cast<void**>(partitionAllocGeneric( |
| 1277 genericAllocator.root(), numAllocations * sizeof(void*), typeName)); | 1295 genericAllocator.root(), numAllocations * sizeof(void*), typeName)); |
| 1278 int i; | 1296 int i; |
| (...skipping 834 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2113 partitionFreeGeneric(genericAllocator.root(), ptr1); | 2131 partitionFreeGeneric(genericAllocator.root(), ptr1); |
| 2114 partitionFreeGeneric(genericAllocator.root(), ptr2); | 2132 partitionFreeGeneric(genericAllocator.root(), ptr2); |
| 2115 } | 2133 } |
| 2116 | 2134 |
| 2117 TestShutdown(); | 2135 TestShutdown(); |
| 2118 } | 2136 } |
| 2119 | 2137 |
| 2120 } // namespace base | 2138 } // namespace base |
| 2121 | 2139 |
| 2122 #endif // !defined(MEMORY_TOOL_REPLACES_ALLOCATOR) | 2140 #endif // !defined(MEMORY_TOOL_REPLACES_ALLOCATOR) |
| OLD | NEW |