diff --git a/compiler-rt/lib/scudo/standalone/tests/combined_test.cpp b/compiler-rt/lib/scudo/standalone/tests/combined_test.cpp --- a/compiler-rt/lib/scudo/standalone/tests/combined_test.cpp +++ b/compiler-rt/lib/scudo/standalone/tests/combined_test.cpp @@ -76,17 +76,9 @@ ~TestAllocator() { this->unmapTestOnly(); } }; -SCUDO_DEFINE_GTEST_TYPE_NAME(scudo::AndroidSvelteConfig) -#if SCUDO_FUCHSIA -SCUDO_DEFINE_GTEST_TYPE_NAME(scudo::FuchsiaConfig) -#else -SCUDO_DEFINE_GTEST_TYPE_NAME(scudo::DefaultConfig) -SCUDO_DEFINE_GTEST_TYPE_NAME(scudo::AndroidConfig) -#endif - -template struct ScudoCombinedTest : public ::testing::Test { +template struct ScudoCombinedTest : public Test { ScudoCombinedTest() { - UseQuarantine = std::is_same::value; + UseQuarantine = std::is_same::value; Allocator = std::make_unique(); } ~ScudoCombinedTest() { @@ -94,23 +86,38 @@ UseQuarantine = true; } + void RunTest(); + void BasicTest(scudo::uptr SizeLogMin, scudo::uptr SizeLogMax); - using AllocatorT = TestAllocator; + using AllocatorT = TestAllocator; std::unique_ptr Allocator; }; -using ScudoCombinedTestTypes = testing::Types; -TYPED_TEST_CASE(ScudoCombinedTest, ScudoCombinedTestTypes); -TYPED_TEST(ScudoCombinedTest, IsOwned) { +#define SCUDO_TYPED_TEST_TYPE(FIXTURE, NAME, TYPE) \ + using FIXTURE##NAME##_##TYPE = FIXTURE##NAME; \ + TEST_F(FIXTURE##NAME##_##TYPE, NAME) { Run(); } + +#define SCUDO_TYPED_TEST(FIXTURE, NAME) \ + template \ + struct FIXTURE##NAME : public FIXTURE { \ + void Run(); \ + }; \ + SCUDO_TYPED_TEST_ALL_TYPES(FIXTURE, NAME) \ + template void FIXTURE##NAME::Run() + +SCUDO_TYPED_TEST(ScudoCombinedTest, IsOwned) { auto *Allocator = this->Allocator.get(); static scudo::u8 StaticBuffer[scudo::Chunk::getHeaderSize() + 1]; EXPECT_FALSE( @@ -152,12 +159,12 @@ } } -TYPED_TEST(ScudoCombinedTest, BasicCombined0) { this->BasicTest(0, 16); } -TYPED_TEST(ScudoCombinedTest, BasicCombined1) { this->BasicTest(17, 18); } -TYPED_TEST(ScudoCombinedTest, BasicCombined2) { this->BasicTest(19, 19); } -TYPED_TEST(ScudoCombinedTest, BasicCombined3) { this->BasicTest(20, 20); } +SCUDO_TYPED_TEST(ScudoCombinedTest, BasicCombined0) { this->BasicTest(0, 16); } +SCUDO_TYPED_TEST(ScudoCombinedTest, BasicCombined1) { this->BasicTest(17, 18); } +SCUDO_TYPED_TEST(ScudoCombinedTest, BasicCombined2) { this->BasicTest(19, 19); } +SCUDO_TYPED_TEST(ScudoCombinedTest, BasicCombined3) { this->BasicTest(20, 20); } -TYPED_TEST(ScudoCombinedTest, ZeroContents) { +SCUDO_TYPED_TEST(ScudoCombinedTest, ZeroContents) { auto *Allocator = this->Allocator.get(); // Ensure that specifying ZeroContents returns a zero'd out block. @@ -174,7 +181,7 @@ } } -TYPED_TEST(ScudoCombinedTest, ZeroFill) { +SCUDO_TYPED_TEST(ScudoCombinedTest, ZeroFill) { auto *Allocator = this->Allocator.get(); // Ensure that specifying ZeroContents returns a zero'd out block. @@ -192,7 +199,7 @@ } } -TYPED_TEST(ScudoCombinedTest, PatternOrZeroFill) { +SCUDO_TYPED_TEST(ScudoCombinedTest, PatternOrZeroFill) { auto *Allocator = this->Allocator.get(); // Ensure that specifying PatternOrZeroFill returns a pattern or zero filled @@ -219,7 +226,7 @@ } } -TYPED_TEST(ScudoCombinedTest, BlockReuse) { +SCUDO_TYPED_TEST(ScudoCombinedTest, BlockReuse) { auto *Allocator = this->Allocator.get(); // Verify that a chunk will end up being reused, at some point. @@ -237,7 +244,7 @@ EXPECT_TRUE(Found); } -TYPED_TEST(ScudoCombinedTest, ReallocateLarge) { +SCUDO_TYPED_TEST(ScudoCombinedTest, ReallocateLarge) { auto *Allocator = this->Allocator.get(); // Reallocate a large chunk all the way down to a byte, verifying that we @@ -258,7 +265,7 @@ Allocator->deallocate(P, Origin); } -TYPED_TEST(ScudoCombinedTest, ReallocateSame) { +SCUDO_TYPED_TEST(ScudoCombinedTest, ReallocateSame) { auto *Allocator = this->Allocator.get(); // Check that reallocating a chunk to a slightly smaller or larger size @@ -281,7 +288,7 @@ Allocator->deallocate(P, Origin); } -TYPED_TEST(ScudoCombinedTest, IterateOverChunks) { +SCUDO_TYPED_TEST(ScudoCombinedTest, IterateOverChunks) { auto *Allocator = this->Allocator.get(); // Allocates a bunch of chunks, then iterate over all the chunks, ensuring // they are the ones we allocated. This requires the allocator to not have any @@ -309,7 +316,7 @@ } } -TYPED_TEST(ScudoCombinedTest, UseAfterFree) { +SCUDO_TYPED_TEST(ScudoCombinedTest, UseAfterFree) { auto *Allocator = this->Allocator.get(); // Check that use-after-free is detected. @@ -336,7 +343,7 @@ } } -TYPED_TEST(ScudoCombinedTest, DisableMemoryTagging) { +SCUDO_TYPED_TEST(ScudoCombinedTest, DisableMemoryTagging) { auto *Allocator = this->Allocator.get(); if (Allocator->useMemoryTaggingTestOnly()) { @@ -361,7 +368,7 @@ } } -TYPED_TEST(ScudoCombinedTest, Stats) { +SCUDO_TYPED_TEST(ScudoCombinedTest, Stats) { auto *Allocator = this->Allocator.get(); scudo::uptr BufferSize = 8192; @@ -380,7 +387,7 @@ EXPECT_NE(Stats.find("Stats: Quarantine"), std::string::npos); } -TYPED_TEST(ScudoCombinedTest, CacheDrain) { +SCUDO_TYPED_TEST(ScudoCombinedTest, CacheDrain) { auto *Allocator = this->Allocator.get(); std::vector V; @@ -399,7 +406,7 @@ TSD->unlock(); } -TYPED_TEST(ScudoCombinedTest, ThreadedCombined) { +SCUDO_TYPED_TEST(ScudoCombinedTest, ThreadedCombined) { std::mutex Mutex; std::condition_variable Cv; bool Ready = false; diff --git a/compiler-rt/lib/scudo/standalone/tests/primary_test.cpp b/compiler-rt/lib/scudo/standalone/tests/primary_test.cpp --- a/compiler-rt/lib/scudo/standalone/tests/primary_test.cpp +++ b/compiler-rt/lib/scudo/standalone/tests/primary_test.cpp @@ -65,20 +65,32 @@ ~TestAllocator() { this->unmapTestOnly(); } }; -SCUDO_DEFINE_GTEST_TYPE_NAME(TestConfig1) -SCUDO_DEFINE_GTEST_TYPE_NAME(TestConfig2) -SCUDO_DEFINE_GTEST_TYPE_NAME(TestConfig3) +template struct ScudoPrimaryTest : public Test {}; -template struct ScudoPrimaryTest : public ::testing::Test {}; - -using ScudoPrimaryTestTypes = testing::Types< -#if !SCUDO_FUCHSIA - TestConfig1, +#if SCUDO_FUCHSIA +#define SCUDO_TYPED_TEST_ALL_TYPES(FIXTURE, NAME) \ + SCUDO_TYPED_TEST_TYPE(FIXTURE, NAME, TestConfig2) \ + SCUDO_TYPED_TEST_TYPE(FIXTURE, NAME, TestConfig3) +#else +#define SCUDO_TYPED_TEST_ALL_TYPES(FIXTURE, NAME) \ + SCUDO_TYPED_TEST_TYPE(FIXTURE, NAME, TestConfig1) \ + SCUDO_TYPED_TEST_TYPE(FIXTURE, NAME, TestConfig2) \ + SCUDO_TYPED_TEST_TYPE(FIXTURE, NAME, TestConfig3) #endif - TestConfig2, TestConfig3>; -TYPED_TEST_CASE(ScudoPrimaryTest, ScudoPrimaryTestTypes); -TYPED_TEST(ScudoPrimaryTest, BasicPrimary) { +#define SCUDO_TYPED_TEST_TYPE(FIXTURE, NAME, TYPE) \ + using FIXTURE##NAME##_##TYPE = FIXTURE##NAME; \ + TEST_F(FIXTURE##NAME##_##TYPE, NAME) { Run(); } + +#define SCUDO_TYPED_TEST(FIXTURE, NAME) \ + template \ + struct FIXTURE##NAME : public FIXTURE { \ + void Run(); \ + }; \ + SCUDO_TYPED_TEST_ALL_TYPES(FIXTURE, NAME) \ + template void FIXTURE##NAME::Run() + +SCUDO_TYPED_TEST(ScudoPrimaryTest, BasicPrimary) { using Primary = TestAllocator; std::unique_ptr Allocator(new Primary); Allocator->init(/*ReleaseToOsInterval=*/-1); @@ -154,7 +166,7 @@ Allocator.unmapTestOnly(); } -TYPED_TEST(ScudoPrimaryTest, PrimaryIterate) { +SCUDO_TYPED_TEST(ScudoPrimaryTest, PrimaryIterate) { using Primary = TestAllocator; std::unique_ptr Allocator(new Primary); Allocator->init(/*ReleaseToOsInterval=*/-1); @@ -190,7 +202,7 @@ Str.output(); } -TYPED_TEST(ScudoPrimaryTest, PrimaryThreaded) { +SCUDO_TYPED_TEST(ScudoPrimaryTest, PrimaryThreaded) { using Primary = TestAllocator; std::unique_ptr Allocator(new Primary); Allocator->init(/*ReleaseToOsInterval=*/-1); @@ -240,7 +252,7 @@ // Through a simple allocation that spans two pages, verify that releaseToOS // actually releases some bytes (at least one page worth). This is a regression // test for an error in how the release criteria were computed. -TYPED_TEST(ScudoPrimaryTest, ReleaseToOS) { +SCUDO_TYPED_TEST(ScudoPrimaryTest, ReleaseToOS) { using Primary = TestAllocator; std::unique_ptr Allocator(new Primary); Allocator->init(/*ReleaseToOsInterval=*/-1); diff --git a/compiler-rt/lib/scudo/standalone/tests/scudo_unit_test.h b/compiler-rt/lib/scudo/standalone/tests/scudo_unit_test.h --- a/compiler-rt/lib/scudo/standalone/tests/scudo_unit_test.h +++ b/compiler-rt/lib/scudo/standalone/tests/scudo_unit_test.h @@ -10,8 +10,10 @@ #if SCUDO_FUCHSIA #include +using Test = ::zxtest::Test; #else #include "gtest/gtest.h" +using Test = ::testing::Test; #endif // If EXPECT_DEATH isn't defined, make it a no-op. @@ -32,8 +34,3 @@ #endif extern bool UseQuarantine; - -#define SCUDO_DEFINE_GTEST_TYPE_NAME(TYPE) \ - template <> std::string testing::internal::GetTypeName() { \ - return #TYPE; \ - }