[compiler-rt] 8e93d10 - scudo: Test realloc on increasing size buffers.
Peter Collingbourne via llvm-commits
llvm-commits at lists.llvm.org
Tue May 18 14:59:54 PDT 2021
Author: Peter Collingbourne
Date: 2021-05-18T14:59:30-07:00
New Revision: 8e93d10633d751a3e9169bf9fa68326925ffa097
URL: https://github.com/llvm/llvm-project/commit/8e93d10633d751a3e9169bf9fa68326925ffa097
DIFF: https://github.com/llvm/llvm-project/commit/8e93d10633d751a3e9169bf9fa68326925ffa097.diff
LOG: scudo: Test realloc on increasing size buffers.
While developing a change to the allocator I ended up breaking
realloc on secondary allocations with increasing sizes. That didn't
cause any of the unit tests to fail, which indicated that we're
missing some test coverage here. Add a unit test for that case.
Differential Revision: https://reviews.llvm.org/D102716
Added:
Modified:
compiler-rt/lib/scudo/standalone/tests/combined_test.cpp
Removed:
################################################################################
diff --git a/compiler-rt/lib/scudo/standalone/tests/combined_test.cpp b/compiler-rt/lib/scudo/standalone/tests/combined_test.cpp
index 5db249d0a85a..50602efcf642 100644
--- a/compiler-rt/lib/scudo/standalone/tests/combined_test.cpp
+++ b/compiler-rt/lib/scudo/standalone/tests/combined_test.cpp
@@ -253,7 +253,28 @@ SCUDO_TYPED_TEST(ScudoCombinedTest, BlockReuse) {
EXPECT_TRUE(Found);
}
-SCUDO_TYPED_TEST(ScudoCombinedTest, ReallocateLarge) {
+SCUDO_TYPED_TEST(ScudoCombinedTest, ReallocateLargeIncreasing) {
+ auto *Allocator = this->Allocator.get();
+
+ // Reallocate a chunk all the way up to a secondary allocation, verifying that
+ // we preserve the data in the process.
+ scudo::uptr Size = 16;
+ void *P = Allocator->allocate(Size, Origin);
+ const char Marker = 0xab;
+ memset(P, Marker, Size);
+ while (Size < TypeParam::Primary::SizeClassMap::MaxSize * 4) {
+ void *NewP = Allocator->reallocate(P, Size * 2);
+ EXPECT_NE(NewP, nullptr);
+ for (scudo::uptr J = 0; J < Size; J++)
+ EXPECT_EQ((reinterpret_cast<char *>(NewP))[J], Marker);
+ memset(reinterpret_cast<char *>(NewP) + Size, Marker, Size);
+ Size *= 2U;
+ P = NewP;
+ }
+ Allocator->deallocate(P, Origin);
+}
+
+SCUDO_TYPED_TEST(ScudoCombinedTest, ReallocateLargeDecreasing) {
auto *Allocator = this->Allocator.get();
// Reallocate a large chunk all the way down to a byte, verifying that we
More information about the llvm-commits
mailing list