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

Unified Diff: Source/wtf/PartitionAllocTest.cpp

Issue 180293003: Simplify partitionReallocGeneric() implementation (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: restore TODOs + extended test 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
« no previous file with comments | « Source/wtf/PartitionAlloc.cpp ('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 49af4635a39d32d43947c3f5d77ca52f10e086a4..531fcd4f70a4547e4d6ee1ace34097ab26b30527 100644
--- a/Source/wtf/PartitionAllocTest.cpp
+++ b/Source/wtf/PartitionAllocTest.cpp
@@ -664,6 +664,34 @@ TEST(WTF_PartitionAlloc, Realloc)
EXPECT_EQ(0, ptr2);
EXPECT_EQ(WTF::partitionCookieFreePointerAdjust(ptr), page->freelistHead);
+ // Test that growing an allocation with realloc() copies everything from the
+ // old allocation.
+ size_t size = WTF::kSystemPageSize - kExtraAllocSize;
+ EXPECT_EQ(size, partitionAllocActualSize(genericAllocator.root(), size));
+ ptr = partitionAllocGeneric(genericAllocator.root(), size);
+ memset(ptr, 'A', size);
+ ptr2 = partitionReallocGeneric(genericAllocator.root(), ptr, size + 1);
+ EXPECT_NE(ptr, ptr2);
+ char* charPtr2 = static_cast<char*>(ptr2);
+ EXPECT_EQ('A', charPtr2[0]);
+ EXPECT_EQ('A', charPtr2[size - 1]);
+#ifndef NDEBUG
+ EXPECT_EQ(WTF::kUninitializedByte, static_cast<unsigned char>(charPtr2[size]));
+#endif
+
+ // Test that shrinking an allocation with realloc() also copies everything
+ // from the old allocation.
+ ptr = partitionReallocGeneric(genericAllocator.root(), ptr2, size - 1);
+ EXPECT_NE(ptr2, ptr);
+ char* charPtr = static_cast<char*>(ptr);
+ EXPECT_EQ('A', charPtr[0]);
+ EXPECT_EQ('A', charPtr[size - 2]);
+#ifndef NDEBUG
+ EXPECT_EQ(WTF::kUninitializedByte, static_cast<unsigned char>(charPtr[size - 1]));
Chris Evans 2014/02/26 20:56:55 I think "size - 1" is technically out of bounds he
Jens Widell 2014/02/27 07:18:13 The test sets 'size' to be a "perfect fit" (and ch
+#endif
+
+ partitionFreeGeneric(genericAllocator.root(), ptr);
+
TestShutdown();
}
« no previous file with comments | « Source/wtf/PartitionAlloc.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698