Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(463)

Unified Diff: Source/wtf/PartitionAllocTest.cpp

Issue 169523004: Add partitionAllocGetSize() for determining actual size of allocation (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« Source/wtf/PartitionAlloc.h ('K') | « Source/wtf/PartitionAlloc.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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)
{
« Source/wtf/PartitionAlloc.h ('K') | « Source/wtf/PartitionAlloc.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698