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 | |
615 // platform's OOM-killing behavior. OOM-killing makes this test flaky on | |
616 // low-memory devices. | |
617 if (!IsLargeMemoryDevice()) | |
618 return; | |
619 | |
620 TestSetup(); | 614 TestSetup(); |
621 | 615 |
622 void* ptr = partitionAllocGeneric(genericAllocator.root(), 0, typeName); | 616 void* ptr = partitionAllocGeneric(genericAllocator.root(), 0, typeName); |
623 EXPECT_TRUE(ptr); | 617 EXPECT_TRUE(ptr); |
624 partitionFreeGeneric(genericAllocator.root(), ptr); | 618 partitionFreeGeneric(genericAllocator.root(), ptr); |
625 | 619 |
626 // kPartitionPageSize is interesting because it results in just one | 620 // kPartitionPageSize is interesting because it results in just one |
627 // allocation per page, which tripped up some corner cases. | 621 // allocation per page, which tripped up some corner cases. |
628 size_t size = kPartitionPageSize - kExtraAllocSize; | 622 size_t size = kPartitionPageSize - kExtraAllocSize; |
629 ptr = partitionAllocGeneric(genericAllocator.root(), size, typeName); | 623 ptr = partitionAllocGeneric(genericAllocator.root(), size, typeName); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
707 // Do we correctly get a null for a failed allocation? | 701 // Do we correctly get a null for a failed allocation? |
708 EXPECT_EQ(0, partitionAllocGenericFlags(genericAllocator.root(), | 702 EXPECT_EQ(0, partitionAllocGenericFlags(genericAllocator.root(), |
709 PartitionAllocReturnNull, | 703 PartitionAllocReturnNull, |
710 3u * 1024 * 1024 * 1024, typeName)); | 704 3u * 1024 * 1024 * 1024, typeName)); |
711 | 705 |
712 TestShutdown(); | 706 TestShutdown(); |
713 } | 707 } |
714 | 708 |
715 // Test that we can fetch the real allocated size after an allocation. | 709 // Test that we can fetch the real allocated size after an allocation. |
716 TEST(PartitionAllocTest, GenericAllocGetSize) { | 710 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()) | |
721 return; | |
722 | |
723 TestSetup(); | 711 TestSetup(); |
724 | 712 |
725 void* ptr; | 713 void* ptr; |
726 size_t requestedSize, actualSize, predictedSize; | 714 size_t requestedSize, actualSize, predictedSize; |
727 | 715 |
728 EXPECT_TRUE(partitionAllocSupportsGetSize()); | 716 EXPECT_TRUE(partitionAllocSupportsGetSize()); |
729 | 717 |
730 // Allocate something small. | 718 // Allocate something small. |
731 requestedSize = 511 - kExtraAllocSize; | 719 requestedSize = 511 - kExtraAllocSize; |
732 predictedSize = | 720 predictedSize = |
(...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1274 | 1262 |
1275 TestShutdown(); | 1263 TestShutdown(); |
1276 } | 1264 } |
1277 | 1265 |
1278 #if !defined(ARCH_CPU_64_BITS) || defined(OS_POSIX) | 1266 #if !defined(ARCH_CPU_64_BITS) || defined(OS_POSIX) |
1279 | 1267 |
1280 static void DoReturnNullTest(size_t allocSize) { | 1268 static void DoReturnNullTest(size_t allocSize) { |
1281 // TODO(crbug.com/678782): Where necessary and possible, disable the | 1269 // TODO(crbug.com/678782): Where necessary and possible, disable the |
1282 // platform's OOM-killing behavior. OOM-killing makes this test flaky on | 1270 // platform's OOM-killing behavior. OOM-killing makes this test flaky on |
1283 // low-memory devices. | 1271 // low-memory devices. |
1284 if (!IsLargeMemoryDevice()) | 1272 if (!IsLargeMemoryDevice()) { |
| 1273 LOG(WARNING) << "Skipping test on this device because of crbug.com/678782"; |
1285 return; | 1274 return; |
| 1275 } |
1286 | 1276 |
1287 TestSetup(); | 1277 TestSetup(); |
1288 | 1278 |
1289 EXPECT_TRUE(SetAddressSpaceLimit()); | 1279 EXPECT_TRUE(SetAddressSpaceLimit()); |
1290 | 1280 |
1291 // Work out the number of allocations for 6 GB of memory. | 1281 // Work out the number of allocations for 6 GB of memory. |
1292 const int numAllocations = (6 * 1024 * 1024) / (allocSize / 1024); | 1282 const int numAllocations = (6 * 1024 * 1024) / (allocSize / 1024); |
1293 | 1283 |
1294 void** ptrs = reinterpret_cast<void**>(partitionAllocGeneric( | 1284 void** ptrs = reinterpret_cast<void**>(partitionAllocGeneric( |
1295 genericAllocator.root(), numAllocations * sizeof(void*), typeName)); | 1285 genericAllocator.root(), numAllocations * sizeof(void*), typeName)); |
(...skipping 835 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2131 partitionFreeGeneric(genericAllocator.root(), ptr1); | 2121 partitionFreeGeneric(genericAllocator.root(), ptr1); |
2132 partitionFreeGeneric(genericAllocator.root(), ptr2); | 2122 partitionFreeGeneric(genericAllocator.root(), ptr2); |
2133 } | 2123 } |
2134 | 2124 |
2135 TestShutdown(); | 2125 TestShutdown(); |
2136 } | 2126 } |
2137 | 2127 |
2138 } // namespace base | 2128 } // namespace base |
2139 | 2129 |
2140 #endif // !defined(MEMORY_TOOL_REPLACES_ALLOCATOR) | 2130 #endif // !defined(MEMORY_TOOL_REPLACES_ALLOCATOR) |
OLD | NEW |