[compiler-rt] 33b579c - [NFC][scudo] Exctract getOptionsForConfig in test

Vitaly Buka via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 1 11:59:39 PDT 2021


Author: Vitaly Buka
Date: 2021-07-01T11:59:30-07:00
New Revision: 33b579c8a5efa476b8a1bd528fe5e47429249847

URL: https://github.com/llvm/llvm-project/commit/33b579c8a5efa476b8a1bd528fe5e47429249847
DIFF: https://github.com/llvm/llvm-project/commit/33b579c8a5efa476b8a1bd528fe5e47429249847.diff

LOG: [NFC][scudo] Exctract getOptionsForConfig in test

Added: 
    

Modified: 
    compiler-rt/lib/scudo/standalone/tests/secondary_test.cpp

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/scudo/standalone/tests/secondary_test.cpp b/compiler-rt/lib/scudo/standalone/tests/secondary_test.cpp
index bbaf79261ba7..6b8a60d386b8 100644
--- a/compiler-rt/lib/scudo/standalone/tests/secondary_test.cpp
+++ b/compiler-rt/lib/scudo/standalone/tests/secondary_test.cpp
@@ -19,19 +19,24 @@
 #include <thread>
 #include <vector>
 
+template <typename Config> static scudo::Options getOptionsForConfig() {
+  return {};
+}
+
 template <typename Config> static void testSecondaryBasic(void) {
   using SecondaryT = scudo::MapAllocator<Config>;
+  scudo::Options Options = getOptionsForConfig<Config>();
 
   scudo::GlobalStats S;
   S.init();
   std::unique_ptr<SecondaryT> L(new SecondaryT);
   L->init(&S);
   const scudo::uptr Size = 1U << 16;
-  void *P = L->allocate(scudo::Options{}, Size);
+  void *P = L->allocate(Options, Size);
   EXPECT_NE(P, nullptr);
   memset(P, 'A', Size);
   EXPECT_GE(SecondaryT::getBlockSize(P), Size);
-  L->deallocate(scudo::Options{}, P);
+  L->deallocate(Options, P);
 
   // If the Secondary can't cache that pointer, it will be unmapped.
   if (!L->canCache(Size)) {
@@ -40,8 +45,8 @@ template <typename Config> static void testSecondaryBasic(void) {
           // Repeat few time to avoid missing crash if it's mmaped by unrelated
           // code.
           for (int i = 0; i < 10; ++i) {
-            P = L->allocate(scudo::Options{}, Size);
-            L->deallocate(scudo::Options{}, P);
+            P = L->allocate(Options, Size);
+            L->deallocate(Options, P);
             memset(P, 'A', Size);
           }
         },
@@ -49,19 +54,19 @@ template <typename Config> static void testSecondaryBasic(void) {
   }
 
   const scudo::uptr Align = 1U << 16;
-  P = L->allocate(scudo::Options{}, Size + Align, Align);
+  P = L->allocate(Options, Size + Align, Align);
   EXPECT_NE(P, nullptr);
   void *AlignedP = reinterpret_cast<void *>(
       scudo::roundUpTo(reinterpret_cast<scudo::uptr>(P), Align));
   memset(AlignedP, 'A', Size);
-  L->deallocate(scudo::Options{}, P);
+  L->deallocate(Options, P);
 
   std::vector<void *> V;
   for (scudo::uptr I = 0; I < 32U; I++)
-    V.push_back(L->allocate(scudo::Options{}, Size));
+    V.push_back(L->allocate(Options, Size));
   std::shuffle(V.begin(), V.end(), std::mt19937(std::random_device()()));
   while (!V.empty()) {
-    L->deallocate(scudo::Options{}, V.back());
+    L->deallocate(Options, V.back());
     V.pop_back();
   }
   scudo::ScopedString Str;
@@ -92,16 +97,17 @@ TEST(ScudoSecondaryTest, SecondaryBasic) {
   testSecondaryBasic<TestConfig>();
 }
 
-using LargeAllocator = scudo::MapAllocator<scudo::DefaultConfig>;
-
 struct MapAllocatorTest : public Test {
+  using Config = scudo::DefaultConfig;
+  using LargeAllocator = scudo::MapAllocator<Config>;
+
   void SetUp() override { Allocator->init(nullptr); }
 
   void TearDown() override { Allocator->unmapTestOnly(); }
 
   std::unique_ptr<LargeAllocator> Allocator =
       std::make_unique<LargeAllocator>();
-  scudo::Options Options = {};
+  scudo::Options Options = getOptionsForConfig<Config>();
 };
 
 // This exercises a variety of combinations of size and alignment for the


        


More information about the llvm-commits mailing list