Index: base/allocator/partition_allocator/partition_alloc_unittest.cc |
diff --git a/base/allocator/partition_allocator/partition_alloc_unittest.cc b/base/allocator/partition_allocator/partition_alloc_unittest.cc |
index dbc8ed21018a193ff3b2ad26cd71771cd90862b5..7bc754fcdd857f2bc374e13c536064cd56768d1a 100644 |
--- a/base/allocator/partition_allocator/partition_alloc_unittest.cc |
+++ b/base/allocator/partition_allocator/partition_alloc_unittest.cc |
@@ -11,6 +11,7 @@ |
#include <vector> |
#include "base/bits.h" |
+#include "base/sys_info.h" |
#include "build/build_config.h" |
#include "testing/gtest/include/gtest/gtest.h" |
@@ -184,6 +185,10 @@ void CheckPageInCore(void* ptr, bool inCore) { |
#endif |
} |
+bool IsLargeMemoryDevice() { |
+ return base::SysInfo::AmountOfPhysicalMemory() >= 2LL * 1024 * 1024 * 1024; |
+} |
+ |
class MockPartitionStatsDumper : public PartitionStatsDumper { |
public: |
MockPartitionStatsDumper() |
@@ -669,9 +674,13 @@ TEST(PartitionAllocTest, GenericAllocSizes) { |
// Can we allocate a massive (512MB) size? |
// Allocate 512MB, but +1, to test for cookie writing alignment issues. |
- ptr = partitionAllocGeneric(genericAllocator.root(), 512 * 1024 * 1024 + 1, |
- typeName); |
- partitionFreeGeneric(genericAllocator.root(), ptr); |
+ // Test this only if the device has enough memory or it might fail due |
+ // to OOM. |
+ if (IsLargeMemoryDevice()) { |
+ ptr = partitionAllocGeneric(genericAllocator.root(), 512 * 1024 * 1024 + 1, |
+ typeName); |
+ partitionFreeGeneric(genericAllocator.root(), ptr); |
+ } |
// Check a more reasonable, but still direct mapped, size. |
// Chop a system page and a byte off to test for rounding errors. |
@@ -742,15 +751,18 @@ TEST(PartitionAllocTest, GenericAllocGetSize) { |
partitionFreeGeneric(genericAllocator.root(), ptr); |
// Allocate something very large, and uneven. |
- requestedSize = 512 * 1024 * 1024 - 1; |
- predictedSize = |
- partitionAllocActualSize(genericAllocator.root(), requestedSize); |
- ptr = partitionAllocGeneric(genericAllocator.root(), requestedSize, typeName); |
- EXPECT_TRUE(ptr); |
- actualSize = partitionAllocGetSize(ptr); |
- EXPECT_EQ(predictedSize, actualSize); |
- EXPECT_LT(requestedSize, actualSize); |
- partitionFreeGeneric(genericAllocator.root(), ptr); |
+ if (IsLargeMemoryDevice()) { |
+ requestedSize = 512 * 1024 * 1024 - 1; |
+ predictedSize = |
+ partitionAllocActualSize(genericAllocator.root(), requestedSize); |
+ ptr = |
+ partitionAllocGeneric(genericAllocator.root(), requestedSize, typeName); |
+ EXPECT_TRUE(ptr); |
+ actualSize = partitionAllocGetSize(ptr); |
+ EXPECT_EQ(predictedSize, actualSize); |
+ EXPECT_LT(requestedSize, actualSize); |
+ partitionFreeGeneric(genericAllocator.root(), ptr); |
+ } |
// Too large allocation. |
requestedSize = INT_MAX; |
@@ -1325,7 +1337,7 @@ TEST(PartitionAllocTest, MAYBE_RepeatedReturnNull) { |
#endif |
TEST(PartitionAllocTest, MAYBE_RepeatedReturnNullDirect) { |
// A direct-mapped allocation size. |
- DoReturnNullTest(256 * 1024 * 1024); |
+ DoReturnNullTest(32 * 1024 * 1024); |
} |
#endif // !defined(ARCH_CPU_64_BITS) || defined(OS_POSIX) |