Chromium Code Reviews| Index: Source/wtf/PartitionAllocTest.cpp |
| diff --git a/Source/wtf/PartitionAllocTest.cpp b/Source/wtf/PartitionAllocTest.cpp |
| index 7adc14a566f339f2e3d63fd5062b2d0f94f0a692..c1f2f2a5bdedd732066e19fe16741a23bc262420 100644 |
| --- a/Source/wtf/PartitionAllocTest.cpp |
| +++ b/Source/wtf/PartitionAllocTest.cpp |
| @@ -1097,6 +1097,35 @@ TEST(PartitionAllocTest, LostFreePagesBug) |
| TestShutdown(); |
| } |
| +// Tests that if an allocation fails in "return null" mode, repeating it doesn't |
| +// crash, and still returns null. The test allocates 6 GB of memory in 512 kB |
| +// blocks. This may never fail on 64-bit systems, in which case this test fails |
|
Jens Widell
2014/10/22 19:40:12
To make these allocations fail on 64-bit, I've bee
|
| +// to test what it sets out to test. |
| +TEST(PartitionAllocTest, RepeatedReturnNull) |
| +{ |
| + TestSetup(); |
| + |
| + void* ptrs[8192]; |
| + int i; |
| + |
| + for (i = 0; i < 6144; ++i) { |
| + ptrs[i] = partitionAllocGenericFlags(genericAllocator.root(), WTF::PartitionAllocReturnNull, 512*1024); |
| + if (!ptrs[i]) { |
| + ptrs[i] = partitionAllocGenericFlags(genericAllocator.root(), WTF::PartitionAllocReturnNull, 512*1024); |
| + EXPECT_FALSE(ptrs[i]); |
| + break; |
| + } |
| + } |
| + |
| + for (--i; i >= 0; --i) { |
| + partitionFreeGeneric(genericAllocator.root(), ptrs[i]); |
| + ptrs[i] = partitionAllocGenericFlags(genericAllocator.root(), WTF::PartitionAllocReturnNull, 512*1024); |
| + partitionFreeGeneric(genericAllocator.root(), ptrs[i]); |
| + } |
| + |
| + TestShutdown(); |
| +} |
| + |
| #if !OS(ANDROID) |
| // Make sure that malloc(-1) dies. |