diff --git a/compiler-rt/lib/scudo/standalone/tests/combined_test.cpp b/compiler-rt/lib/scudo/standalone/tests/combined_test.cpp index a90a9320ceba2a..ec65010c8e3014 100644 --- a/compiler-rt/lib/scudo/standalone/tests/combined_test.cpp +++ b/compiler-rt/lib/scudo/standalone/tests/combined_test.cpp @@ -20,11 +20,6 @@ static constexpr scudo::Chunk::Origin Origin = scudo::Chunk::Origin::Malloc; -template struct UseQuarantineSetter { - UseQuarantineSetter(bool Value) { UseQuarantine = Value; } - ~UseQuarantineSetter() { UseQuarantine = true; } -}; - // Fuchsia complains that the function is not used. UNUSED static void disableDebuggerdMaybe() { #if SCUDO_ANDROID @@ -95,7 +90,16 @@ SCUDO_DEFINE_GTEST_TYPE_NAME(AndroidConfig) } // namespace internal } // namespace testing -template struct ScudoCombinedTest : public ::testing::Test {}; +template struct ScudoCombinedTest : public ::testing::Test { + ScudoCombinedTest() { + UseQuarantine = std::is_same::value; + Allocator = std::make_unique(); + } + ~ScudoCombinedTest() { UseQuarantine = true; } + + using AllocatorT = TestAllocator; + std::unique_ptr Allocator; +}; using ScudoCombinedTestTypes = testing::Types MUQ( - std::is_same::value); - using AllocatorT = TestAllocator; - auto Allocator = std::unique_ptr(new AllocatorT()); - + auto *Allocator = this->Allocator.get(); static scudo::u8 StaticBuffer[scudo::Chunk::getHeaderSize() + 1]; EXPECT_FALSE( Allocator->isOwned(&StaticBuffer[scudo::Chunk::getHeaderSize()])); @@ -143,7 +142,7 @@ TYPED_TEST(ScudoCombinedTest, BasicCombined) { EXPECT_TRUE(scudo::isAligned(reinterpret_cast(P), Align)); EXPECT_LE(Size, Allocator->getUsableSize(P)); memset(P, 0xaa, Size); - checkMemoryTaggingMaybe(Allocator.get(), P, Size, Align); + checkMemoryTaggingMaybe(Allocator, P, Size, Align); Allocator->deallocate(P, Origin, Size); } } @@ -190,7 +189,8 @@ TYPED_TEST(ScudoCombinedTest, BasicCombined) { EXPECT_NE(P, nullptr); for (scudo::uptr I = 0; I < Size; I++) { unsigned char V = (reinterpret_cast(P))[I]; - if (isPrimaryAllocation(Size, 1U << MinAlignLog) && + if (isPrimaryAllocation>(Size, + 1U << MinAlignLog) && !Allocator->useMemoryTaggingTestOnly()) ASSERT_EQ(V, scudo::PatternFillByte); else @@ -216,7 +216,7 @@ TYPED_TEST(ScudoCombinedTest, BasicCombined) { } EXPECT_TRUE(Found); - constexpr scudo::uptr MaxSize = Config::Primary::SizeClassMap::MaxSize; + constexpr scudo::uptr MaxSize = TypeParam::Primary::SizeClassMap::MaxSize; // Reallocate a large chunk all the way down to a byte, verifying that we // preserve the data in the process. @@ -248,7 +248,7 @@ TYPED_TEST(ScudoCombinedTest, BasicCombined) { EXPECT_EQ(NewP, P); for (scudo::uptr I = 0; I < ReallocSize - 32; I++) EXPECT_EQ((reinterpret_cast(NewP))[I], Marker); - checkMemoryTaggingMaybe(Allocator.get(), NewP, NewSize, 0); + checkMemoryTaggingMaybe(Allocator, NewP, NewSize, 0); } Allocator->deallocate(P, Origin); @@ -349,8 +349,7 @@ TYPED_TEST(ScudoCombinedTest, ThreadedCombined) { std::mutex Mutex; std::condition_variable Cv; bool Ready = false; - using AllocatorT = TestAllocator; - auto Allocator = std::unique_ptr(new AllocatorT()); + auto *Allocator = this->Allocator.get(); std::thread Threads[32]; for (scudo::uptr I = 0; I < ARRAY_SIZE(Threads); I++) Threads[I] = std::thread([&]() {