@@ -32,7 +32,7 @@ template <typename Config> static scudo::Options getOptionsForConfig() {
3232 return AO.load ();
3333}
3434
35- template <typename Config> static void testSecondaryBasic (void ) {
35+ template <typename Config> static void testBasic (void ) {
3636 using SecondaryT = scudo::MapAllocator<scudo::SecondaryConfig<Config>>;
3737 scudo::Options Options =
3838 getOptionsForConfig<scudo::SecondaryConfig<Config>>();
@@ -85,7 +85,7 @@ template <typename Config> static void testSecondaryBasic(void) {
8585 L->unmapTestOnly ();
8686}
8787
88- struct NoCacheConfig {
88+ struct TestNoCacheConfig {
8989 static const bool MaySupportMemoryTagging = false ;
9090 template <typename > using TSDRegistryT = void ;
9191 template <typename > using PrimaryT = void ;
@@ -97,7 +97,7 @@ struct NoCacheConfig {
9797 };
9898};
9999
100- struct TestConfig {
100+ struct TestCacheConfig {
101101 static const bool MaySupportMemoryTagging = false ;
102102 template <typename > using TSDRegistryT = void ;
103103 template <typename > using PrimaryT = void ;
@@ -117,15 +117,15 @@ struct TestConfig {
117117 };
118118};
119119
120- TEST (ScudoSecondaryTest, SecondaryBasic ) {
121- testSecondaryBasic<NoCacheConfig >();
122- testSecondaryBasic<scudo::DefaultConfig >();
123- testSecondaryBasic<TestConfig >();
120+ TEST (ScudoSecondaryTest, Basic ) {
121+ testBasic<TestNoCacheConfig >();
122+ testBasic<TestCacheConfig >();
123+ testBasic<scudo::DefaultConfig >();
124124}
125125
126- struct MapAllocatorTest : public Test {
127- using Config = scudo::DefaultConfig;
128- using LargeAllocator = scudo::MapAllocator<scudo::SecondaryConfig<Config >>;
126+ struct ScudoSecondaryAllocatorTest : public Test {
127+ using LargeAllocator =
128+ scudo::MapAllocator<scudo::SecondaryConfig<TestNoCacheConfig >>;
129129
130130 void SetUp () override { Allocator->init (nullptr ); }
131131
@@ -134,13 +134,13 @@ struct MapAllocatorTest : public Test {
134134 std::unique_ptr<LargeAllocator> Allocator =
135135 std::make_unique<LargeAllocator>();
136136 scudo::Options Options =
137- getOptionsForConfig<scudo::SecondaryConfig<Config >>();
137+ getOptionsForConfig<scudo::SecondaryConfig<TestNoCacheConfig >>();
138138};
139139
140140// This exercises a variety of combinations of size and alignment for the
141141// MapAllocator. The size computation done here mimic the ones done by the
142142// combined allocator.
143- TEST_F (MapAllocatorTest, SecondaryCombinations ) {
143+ TEST_F (ScudoSecondaryAllocatorTest, Combinations ) {
144144 constexpr scudo::uptr MinAlign = FIRST_32_SECOND_64 (8 , 16 );
145145 constexpr scudo::uptr HeaderSize = scudo::roundUp (8 , MinAlign);
146146 for (scudo::uptr SizeLog = 0 ; SizeLog <= 20 ; SizeLog++) {
@@ -168,7 +168,7 @@ TEST_F(MapAllocatorTest, SecondaryCombinations) {
168168 Str.output ();
169169}
170170
171- TEST_F (MapAllocatorTest, SecondaryIterate ) {
171+ TEST_F (ScudoSecondaryAllocatorTest, Iterate ) {
172172 std::vector<void *> V;
173173 const scudo::uptr PageSize = scudo::getPageSizeCached ();
174174 for (scudo::uptr I = 0 ; I < 32U ; I++)
@@ -190,34 +190,8 @@ TEST_F(MapAllocatorTest, SecondaryIterate) {
190190 Str.output ();
191191}
192192
193- TEST_F (MapAllocatorTest, SecondaryCacheOptions) {
194- if (!Allocator->canCache (0U ))
195- TEST_SKIP (" Secondary Cache disabled" );
196-
197- // Attempt to set a maximum number of entries higher than the array size.
198- EXPECT_TRUE (Allocator->setOption (scudo::Option::MaxCacheEntriesCount, 4096U ));
199-
200- // Attempt to set an invalid (negative) number of entries
201- EXPECT_FALSE (Allocator->setOption (scudo::Option::MaxCacheEntriesCount, -1 ));
202-
203- // Various valid combinations.
204- EXPECT_TRUE (Allocator->setOption (scudo::Option::MaxCacheEntriesCount, 4U ));
205- EXPECT_TRUE (
206- Allocator->setOption (scudo::Option::MaxCacheEntrySize, 1UL << 20 ));
207- EXPECT_TRUE (Allocator->canCache (1UL << 18 ));
208- EXPECT_TRUE (
209- Allocator->setOption (scudo::Option::MaxCacheEntrySize, 1UL << 17 ));
210- EXPECT_FALSE (Allocator->canCache (1UL << 18 ));
211- EXPECT_TRUE (Allocator->canCache (1UL << 16 ));
212- EXPECT_TRUE (Allocator->setOption (scudo::Option::MaxCacheEntriesCount, 0U ));
213- EXPECT_FALSE (Allocator->canCache (1UL << 16 ));
214- EXPECT_TRUE (Allocator->setOption (scudo::Option::MaxCacheEntriesCount, 4U ));
215- EXPECT_TRUE (
216- Allocator->setOption (scudo::Option::MaxCacheEntrySize, 1UL << 20 ));
217- EXPECT_TRUE (Allocator->canCache (1UL << 16 ));
218- }
219-
220- struct MapAllocatorWithReleaseTest : public MapAllocatorTest {
193+ struct ScudoSecondaryAllocatorWithReleaseTest
194+ : public ScudoSecondaryAllocatorTest {
221195 void SetUp () override { Allocator->init (nullptr , /* ReleaseToOsInterval=*/ 0 ); }
222196
223197 void performAllocations () {
@@ -249,11 +223,11 @@ struct MapAllocatorWithReleaseTest : public MapAllocatorTest {
249223 bool Ready = false ;
250224};
251225
252- TEST_F (MapAllocatorWithReleaseTest, SecondaryThreadsRace ) {
226+ TEST_F (ScudoSecondaryAllocatorWithReleaseTest, ThreadsRace ) {
253227 std::thread Threads[16 ];
254228 for (scudo::uptr I = 0 ; I < ARRAY_SIZE (Threads); I++)
255- Threads[I] =
256- std::thread (&MapAllocatorWithReleaseTest ::performAllocations, this );
229+ Threads[I] = std::thread (
230+ &ScudoSecondaryAllocatorWithReleaseTest ::performAllocations, this );
257231 {
258232 std::unique_lock<std::mutex> Lock (Mutex);
259233 Ready = true ;
@@ -266,15 +240,15 @@ TEST_F(MapAllocatorWithReleaseTest, SecondaryThreadsRace) {
266240 Str.output ();
267241}
268242
269- struct MapAllocatorCacheTest : public Test {
243+ struct ScudoSecondaryAllocatorCacheTest : public Test {
270244 static constexpr scudo::u32 UnmappedMarker = 0xDEADBEEF ;
271245
272246 static void testUnmapCallback (scudo::MemMapT &MemMap) {
273247 scudo::u32 *Ptr = reinterpret_cast <scudo::u32 *>(MemMap.getBase ());
274248 *Ptr = UnmappedMarker;
275249 }
276250
277- using SecondaryConfig = scudo::SecondaryConfig<TestConfig >;
251+ using SecondaryConfig = scudo::SecondaryConfig<TestCacheConfig >;
278252 using CacheConfig = SecondaryConfig::CacheConfig;
279253 using CacheT = scudo::MapAllocatorCache<CacheConfig, testUnmapCallback>;
280254
@@ -315,7 +289,7 @@ struct MapAllocatorCacheTest : public Test {
315289 }
316290};
317291
318- TEST_F (MapAllocatorCacheTest, CacheOrder ) {
292+ TEST_F (ScudoSecondaryAllocatorCacheTest, EntryOrder ) {
319293 std::vector<scudo::MemMapT> MemMaps;
320294 Cache->setOption (scudo::Option::MaxCacheEntriesCount,
321295 CacheConfig::getEntriesArraySize ());
@@ -336,7 +310,7 @@ TEST_F(MapAllocatorCacheTest, CacheOrder) {
336310 MemMap.unmap ();
337311}
338312
339- TEST_F (MapAllocatorCacheTest , PartialChunkHeuristicRetrievalTest) {
313+ TEST_F (ScudoSecondaryAllocatorCacheTest , PartialChunkHeuristicRetrievalTest) {
340314 const scudo::uptr FragmentedPages =
341315 1 + scudo::CachedBlock::MaxReleasedCachePages;
342316 scudo::uptr EntryHeaderPos;
@@ -360,7 +334,7 @@ TEST_F(MapAllocatorCacheTest, PartialChunkHeuristicRetrievalTest) {
360334 MemMap.unmap ();
361335}
362336
363- TEST_F (MapAllocatorCacheTest , MemoryLeakTest) {
337+ TEST_F (ScudoSecondaryAllocatorCacheTest , MemoryLeakTest) {
364338 std::vector<scudo::MemMapT> MemMaps;
365339 // Fill the cache above MaxEntriesCount to force an eviction
366340 // The first cache entry should be evicted (because it is the oldest)
@@ -387,3 +361,24 @@ TEST_F(MapAllocatorCacheTest, MemoryLeakTest) {
387361 for (auto &MemMap : MemMaps)
388362 MemMap.unmap ();
389363}
364+
365+ TEST_F (ScudoSecondaryAllocatorCacheTest, Options) {
366+ // Attempt to set a maximum number of entries higher than the array size.
367+ EXPECT_TRUE (Cache->setOption (scudo::Option::MaxCacheEntriesCount, 4096U ));
368+
369+ // Attempt to set an invalid (negative) number of entries
370+ EXPECT_FALSE (Cache->setOption (scudo::Option::MaxCacheEntriesCount, -1 ));
371+
372+ // Various valid combinations.
373+ EXPECT_TRUE (Cache->setOption (scudo::Option::MaxCacheEntriesCount, 4U ));
374+ EXPECT_TRUE (Cache->setOption (scudo::Option::MaxCacheEntrySize, 1UL << 20 ));
375+ EXPECT_TRUE (Cache->canCache (1UL << 18 ));
376+ EXPECT_TRUE (Cache->setOption (scudo::Option::MaxCacheEntrySize, 1UL << 17 ));
377+ EXPECT_FALSE (Cache->canCache (1UL << 18 ));
378+ EXPECT_TRUE (Cache->canCache (1UL << 16 ));
379+ EXPECT_TRUE (Cache->setOption (scudo::Option::MaxCacheEntriesCount, 0U ));
380+ EXPECT_FALSE (Cache->canCache (1UL << 16 ));
381+ EXPECT_TRUE (Cache->setOption (scudo::Option::MaxCacheEntriesCount, 4U ));
382+ EXPECT_TRUE (Cache->setOption (scudo::Option::MaxCacheEntrySize, 1UL << 20 ));
383+ EXPECT_TRUE (Cache->canCache (1UL << 16 ));
384+ }
0 commit comments