Chromium Code Reviews| Index: Source/wtf/PartitionAllocTest.cpp |
| diff --git a/Source/wtf/PartitionAllocTest.cpp b/Source/wtf/PartitionAllocTest.cpp |
| index aef6f5c86b35ca3d8c32e08be56288b9d716ef1f..0fe399aa72a5890419360a5e5d036570c280e9c4 100644 |
| --- a/Source/wtf/PartitionAllocTest.cpp |
| +++ b/Source/wtf/PartitionAllocTest.cpp |
| @@ -574,6 +574,53 @@ 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; |
| + |
| + // Allocate something small. |
| + requestedSize = 512; |
|
Chris Evans
2014/02/18 22:19:59
I think you might need to adjust the size dependin
Chris Evans
2014/02/18 22:19:59
I have another idea. Can we make all the sizes odd
|
| + ptr = partitionAllocGeneric(genericAllocator.root(), requestedSize); |
| + EXPECT_TRUE(ptr); |
| + actualSize = partitionAllocGetSize(genericAllocator.root(), ptr); |
| + EXPECT_LE(requestedSize, actualSize); |
| + partitionFreeGeneric(genericAllocator.root(), ptr); |
| + |
| + // Allocate something slightly larger. |
| + requestedSize = 200 * 1024; |
| + ptr = partitionAllocGeneric(genericAllocator.root(), requestedSize); |
| + EXPECT_TRUE(ptr); |
| + actualSize = partitionAllocGetSize(genericAllocator.root(), ptr); |
| + EXPECT_LE(requestedSize, actualSize); |
| + partitionFreeGeneric(genericAllocator.root(), ptr); |
| + |
| + // Allocate something slightly larger and uneven. GetSize() should return a |
| + // larger size than we asked for now. |
| + requestedSize = 200 * 1024 + 250; |
|
Chris Evans
2014/02/18 22:19:59
A nicer size to test might be (256 * 1024) - kSyst
|
| + ptr = partitionAllocGeneric(genericAllocator.root(), requestedSize); |
| + EXPECT_TRUE(ptr); |
| + actualSize = partitionAllocGetSize(genericAllocator.root(), ptr); |
| + EXPECT_LT(requestedSize, 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. GetSize() should return zero. |
|
Chris Evans
2014/02/18 22:19:59
Does this actually happen? I see that you're testi
|
| + requestedSize = 512 * 1024 * 1024; |
| + ptr = partitionAllocGeneric(genericAllocator.root(), requestedSize); |
| + EXPECT_TRUE(ptr); |
| + actualSize = partitionAllocGetSize(genericAllocator.root(), ptr); |
| + EXPECT_LE(requestedSize, actualSize); |
| + partitionFreeGeneric(genericAllocator.root(), ptr); |
| + |
| + TestShutdown(); |
| +} |
| + |
| // Test the realloc() contract. |
| TEST(WTF_PartitionAlloc, Realloc) |
| { |