[compiler-rt] [scudo] Added test fixture for cache tests. (PR #102230)

Christopher Ferris via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 6 14:54:49 PDT 2024


================
@@ -265,3 +265,99 @@ TEST_F(MapAllocatorWithReleaseTest, SecondaryThreadsRace) {
   Allocator->getStats(&Str);
   Str.output();
 }
+
+struct MapAllocatorCacheTest : public Test {
+  static constexpr scudo::u32 MarkerBytes = 0xDEADBEEF;
+
+  static void testUnmapCallback(scudo::MemMapT &MemMap) {
+    scudo::u32 *Ptr = reinterpret_cast<scudo::u32 *>(MemMap.getBase());
+    *Ptr = MarkerBytes;
+  }
+
+  using Config = scudo::DefaultConfig;
+  using SecondaryConfig = scudo::SecondaryConfig<Config>;
+  using CacheConfig = SecondaryConfig::CacheConfig;
+  using CacheT = scudo::MapAllocatorCache<CacheConfig, testUnmapCallback>;
+
+  std::unique_ptr<CacheT> Cache = std::make_unique<CacheT>();
+
+  const scudo::uptr PageSize = scudo::getPageSizeCached();
+  static constexpr scudo::uptr DefaultAllocSize = scudo::uptr(1U) << 16;
----------------
cferris1000 wrote:

You add a comment about why you chose this size.

Also, a small nit, DefaultAllocSize isn't a very descriptive variable name, perhaps something like TestAllocSize along with the comment would help explain this.

https://github.com/llvm/llvm-project/pull/102230


More information about the llvm-commits mailing list