Chromium Code Reviews| Index: Source/wtf/PartitionAllocTest.cpp |
| diff --git a/Source/wtf/PartitionAllocTest.cpp b/Source/wtf/PartitionAllocTest.cpp |
| index aef6f5c86b35ca3d8c32e08be56288b9d716ef1f..fd1d7b39642275081a91776fb8211c5bd66620e8 100644 |
| --- a/Source/wtf/PartitionAllocTest.cpp |
| +++ b/Source/wtf/PartitionAllocTest.cpp |
| @@ -574,6 +574,55 @@ TEST(WTF_PartitionAlloc, GenericAllocSizes) |
| TestShutdown(); |
| } |
| +// Test that we can fetch the real allocated size after an allocation. |
| +TEST(WTF_PartitionAlloc, GenericAllocGetSize) |
| +{ |
| + TestSetup(); |
| + |
| + void* ptr; |
| + size_t requestedSize, actualSize; |
| + |
| + EXPECT_TRUE(partitionAllocSupportsGetSize()); |
| + |
| + // Allocate something small. |
| + requestedSize = 511 - kExtraAllocSize; |
| + ptr = partitionAllocGeneric(genericAllocator.root(), requestedSize); |
| + EXPECT_TRUE(ptr); |
| + actualSize = partitionAllocGetSize(ptr); |
| + EXPECT_LT(requestedSize, actualSize); |
| + partitionFreeGeneric(genericAllocator.root(), ptr); |
| + |
| + // Allocate that should be a perfect match for a bucket. |
|
Chris Evans
2014/02/19 07:15:52
Grammar: should be "allocation" or "allocate a siz
|
| + requestedSize = (256 * 1024) - kExtraAllocSize; |
| + ptr = partitionAllocGeneric(genericAllocator.root(), requestedSize); |
| + EXPECT_TRUE(ptr); |
| + actualSize = partitionAllocGetSize(ptr); |
| + EXPECT_EQ(requestedSize, actualSize); |
| + partitionFreeGeneric(genericAllocator.root(), ptr); |
| + |
| + // Allocate something slightly larger and uneven. GetSize() should return a |
|
Chris Evans
2014/02/19 07:15:52
The size is not uneven as far as I can see? Maybe
|
| + // larger size than we asked for now. |
| + requestedSize = (256 * 1024) - WTF::kSystemPageSize - kExtraAllocSize; |
| + ptr = partitionAllocGeneric(genericAllocator.root(), requestedSize); |
| + EXPECT_TRUE(ptr); |
| + actualSize = partitionAllocGetSize(ptr); |
| + EXPECT_EQ(requestedSize + WTF::kSystemPageSize, actualSize); |
| + // Check that we can write at the end of the reported size too. |
| + char* charPtr = reinterpret_cast<char*>(ptr); |
| + *(charPtr + (actualSize - 1)) = 'A'; |
| + partitionFreeGeneric(genericAllocator.root(), ptr); |
| + |
| + // Allocate something very large. |
| + requestedSize = 512 * 1024 * 1024; |
|
Chris Evans
2014/02/19 07:15:52
Let's do (512 * 1024 * 1024) - 1, and then we can
|
| + ptr = partitionAllocGeneric(genericAllocator.root(), requestedSize); |
| + EXPECT_TRUE(ptr); |
| + actualSize = partitionAllocGetSize(ptr); |
| + EXPECT_LE(requestedSize, actualSize); |
| + partitionFreeGeneric(genericAllocator.root(), ptr); |
| + |
| + TestShutdown(); |
| +} |
| + |
| // Test the realloc() contract. |
| TEST(WTF_PartitionAlloc, Realloc) |
| { |