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: Where necessary and possible, disable the platform's OOM-killing | |
danakj
2017/01/05 23:00:44
TODO, unlike the old FIXME, always comes with a na
palmer
2017/01/06 00:30:53
Done.
| |
615 // behavior. OOM-killing makes this test flaky on low-memory devices. | |
616 // crbug.com/678782 | |
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: Where necessary and possible, disable the platform's OOM-killing | |
718 // behavior. OOM-killing makes this test flaky on low-memory devices. | |
danakj
2017/01/05 23:00:44
If it's flaky shouldn't it be disabled, or is the
palmer
2017/01/06 00:30:53
Oops, forgot to put the actual code in. Sigh.
| |
719 // crbug.com/678782 | |
720 | |
711 TestSetup(); | 721 TestSetup(); |
712 | 722 |
713 void* ptr; | 723 void* ptr; |
714 size_t requestedSize, actualSize, predictedSize; | 724 size_t requestedSize, actualSize, predictedSize; |
715 | 725 |
716 EXPECT_TRUE(partitionAllocSupportsGetSize()); | 726 EXPECT_TRUE(partitionAllocSupportsGetSize()); |
717 | 727 |
718 // Allocate something small. | 728 // Allocate something small. |
719 requestedSize = 511 - kExtraAllocSize; | 729 requestedSize = 511 - kExtraAllocSize; |
720 predictedSize = | 730 predictedSize = |
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1259 EXPECT_TRUE(bucket->activePagesHead); | 1269 EXPECT_TRUE(bucket->activePagesHead); |
1260 EXPECT_TRUE(bucket->emptyPagesHead); | 1270 EXPECT_TRUE(bucket->emptyPagesHead); |
1261 EXPECT_TRUE(bucket->decommittedPagesHead); | 1271 EXPECT_TRUE(bucket->decommittedPagesHead); |
1262 | 1272 |
1263 TestShutdown(); | 1273 TestShutdown(); |
1264 } | 1274 } |
1265 | 1275 |
1266 #if !defined(ARCH_CPU_64_BITS) || defined(OS_POSIX) | 1276 #if !defined(ARCH_CPU_64_BITS) || defined(OS_POSIX) |
1267 | 1277 |
1268 static void DoReturnNullTest(size_t allocSize) { | 1278 static void DoReturnNullTest(size_t allocSize) { |
1279 // TODO: Where necessary and possible, disable the platform's OOM-killing | |
1280 // behavior. OOM-killing makes this test flaky on low-memory devices. | |
1281 // crbug.com/678782 | |
1282 if (!IsLargeMemoryDevice()) | |
1283 return; | |
1284 | |
1269 TestSetup(); | 1285 TestSetup(); |
1270 | 1286 |
1271 EXPECT_TRUE(SetAddressSpaceLimit()); | 1287 EXPECT_TRUE(SetAddressSpaceLimit()); |
1272 | 1288 |
1273 // Work out the number of allocations for 6 GB of memory. | 1289 // Work out the number of allocations for 6 GB of memory. |
1274 const int numAllocations = (6 * 1024 * 1024) / (allocSize / 1024); | 1290 const int numAllocations = (6 * 1024 * 1024) / (allocSize / 1024); |
1275 | 1291 |
1276 void** ptrs = reinterpret_cast<void**>(partitionAllocGeneric( | 1292 void** ptrs = reinterpret_cast<void**>(partitionAllocGeneric( |
1277 genericAllocator.root(), numAllocations * sizeof(void*), typeName)); | 1293 genericAllocator.root(), numAllocations * sizeof(void*), typeName)); |
1278 int i; | 1294 int i; |
(...skipping 834 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2113 partitionFreeGeneric(genericAllocator.root(), ptr1); | 2129 partitionFreeGeneric(genericAllocator.root(), ptr1); |
2114 partitionFreeGeneric(genericAllocator.root(), ptr2); | 2130 partitionFreeGeneric(genericAllocator.root(), ptr2); |
2115 } | 2131 } |
2116 | 2132 |
2117 TestShutdown(); | 2133 TestShutdown(); |
2118 } | 2134 } |
2119 | 2135 |
2120 } // namespace base | 2136 } // namespace base |
2121 | 2137 |
2122 #endif // !defined(MEMORY_TOOL_REPLACES_ALLOCATOR) | 2138 #endif // !defined(MEMORY_TOOL_REPLACES_ALLOCATOR) |
OLD | NEW |