[compiler-rt] 7af9b03 - [NFC][scudo] Use TYPED_TEST to split large test

Vitaly Buka via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 1 17:34:22 PDT 2021


Author: Vitaly Buka
Date: 2021-04-01T17:34:13-07:00
New Revision: 7af9b03c9d6b1c53756a8392a98edbe03a6bd327

URL: https://github.com/llvm/llvm-project/commit/7af9b03c9d6b1c53756a8392a98edbe03a6bd327
DIFF: https://github.com/llvm/llvm-project/commit/7af9b03c9d6b1c53756a8392a98edbe03a6bd327.diff

LOG: [NFC][scudo] Use TYPED_TEST to split large test

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 3afc32408e8e..b93efd4453db 100644
--- a/compiler-rt/lib/scudo/standalone/tests/combined_test.cpp
+++ b/compiler-rt/lib/scudo/standalone/tests/combined_test.cpp
@@ -84,7 +84,35 @@ template <typename Config> struct TestAllocator : scudo::Allocator<Config> {
   ~TestAllocator() { this->unmapTestOnly(); }
 };
 
-template <class Config> static void testAllocator() {
+namespace testing {
+namespace internal {
+#define SCUDO_DEFINE_GTEST_TYPE_NAME(TYPE)                                     \
+  template <> std::string GetTypeName<scudo::TYPE>() { return #TYPE; }
+SCUDO_DEFINE_GTEST_TYPE_NAME(AndroidSvelteConfig)
+#if SCUDO_FUCHSIA
+SCUDO_DEFINE_GTEST_TYPE_NAME(FuchsiaConfig)
+#else
+SCUDO_DEFINE_GTEST_TYPE_NAME(DefaultConfig)
+SCUDO_DEFINE_GTEST_TYPE_NAME(AndroidConfig)
+#endif
+#undef SCUDO_DEFINE_GTEST_TYPE_NAME
+} // namespace internal
+} // namespace testing
+
+template <class T> struct ScudoCombinedTest : public ::testing::Test {};
+
+using ScudoCombinedTestTypes = testing::Types<scudo::AndroidSvelteConfig,
+#if SCUDO_FUCHSIA
+                                              scudo::FuchsiaConfig,
+#else
+                                              scudo::DefaultConfig,
+                                              scudo::AndroidConfig
+#endif
+                                              >;
+TYPED_TEST_CASE(ScudoCombinedTest, ScudoCombinedTestTypes);
+
+TYPED_TEST(ScudoCombinedTest, BasicCombined) {
+  using Config = TypeParam;
   UseQuarantineSetter<Config> MUQ(
       std::is_same<Config, scudo::AndroidConfig>::value);
   using AllocatorT = TestAllocator<Config>;
@@ -321,28 +349,6 @@ template <class Config> static void testAllocator() {
     TSD->unlock();
 }
 
-// Test that multiple instantiations of the allocator have not messed up the
-// process's signal handlers (GWP-ASan used to do this).
-void testSEGV() {
-  const scudo::uptr Size = 4 * scudo::getPageSizeCached();
-  scudo::MapPlatformData Data = {};
-  void *P = scudo::map(nullptr, Size, "testSEGV", MAP_NOACCESS, &Data);
-  EXPECT_NE(P, nullptr);
-  EXPECT_DEATH(memset(P, 0xaa, Size), "");
-  scudo::unmap(P, Size, UNMAP_ALL, &Data);
-}
-
-TEST(ScudoCombinedTest, BasicCombined) {
-  testAllocator<scudo::AndroidSvelteConfig>();
-#if SCUDO_FUCHSIA
-  testAllocator<scudo::FuchsiaConfig>();
-#else
-  testAllocator<scudo::DefaultConfig>();
-  testAllocator<scudo::AndroidConfig>();
-  testSEGV();
-#endif
-}
-
 template <typename AllocatorT> static void stressAllocator(AllocatorT *A) {
   {
     std::unique_lock<std::mutex> Lock(Mutex);
@@ -364,7 +370,8 @@ template <typename AllocatorT> static void stressAllocator(AllocatorT *A) {
   }
 }
 
-template <class Config> static void testAllocatorThreaded() {
+TYPED_TEST(ScudoCombinedTest, ThreadedCombined) {
+  using Config = TypeParam;
   Ready = false;
   using AllocatorT = TestAllocator<Config>;
   auto Allocator = std::unique_ptr<AllocatorT>(new AllocatorT());
@@ -381,14 +388,21 @@ template <class Config> static void testAllocatorThreaded() {
   Allocator->releaseToOS();
 }
 
-TEST(ScudoCombinedTest, ThreadedCombined) {
-  testAllocatorThreaded<scudo::AndroidSvelteConfig>();
 #if SCUDO_FUCHSIA
-  testAllocatorThreaded<scudo::FuchsiaConfig>();
+#define SKIP_ON_FUCHSIA(T) DISABLED_##T
 #else
-  testAllocatorThreaded<scudo::DefaultConfig>();
-  testAllocatorThreaded<scudo::AndroidConfig>();
+#define SKIP_ON_FUCHSIA(T) T
 #endif
+
+// Test that multiple instantiations of the allocator have not messed up the
+// process's signal handlers (GWP-ASan used to do this).
+TEST(ScudoCombinedTest, SKIP_ON_FUCHSIA(testSEGV)) {
+  const scudo::uptr Size = 4 * scudo::getPageSizeCached();
+  scudo::MapPlatformData Data = {};
+  void *P = scudo::map(nullptr, Size, "testSEGV", MAP_NOACCESS, &Data);
+  EXPECT_NE(P, nullptr);
+  EXPECT_DEATH(memset(P, 0xaa, Size), "");
+  scudo::unmap(P, Size, UNMAP_ALL, &Data);
 }
 
 struct DeathSizeClassConfig {


        


More information about the llvm-commits mailing list