@@ -32,7 +32,7 @@ template <typename Config> static scudo::Options getOptionsForConfig() {
32
32
return AO.load ();
33
33
}
34
34
35
- template <typename Config> static void testSecondaryBasic (void ) {
35
+ template <typename Config> static void testBasic (void ) {
36
36
using SecondaryT = scudo::MapAllocator<scudo::SecondaryConfig<Config>>;
37
37
scudo::Options Options =
38
38
getOptionsForConfig<scudo::SecondaryConfig<Config>>();
@@ -85,7 +85,7 @@ template <typename Config> static void testSecondaryBasic(void) {
85
85
L->unmapTestOnly ();
86
86
}
87
87
88
- struct NoCacheConfig {
88
+ struct TestNoCacheConfig {
89
89
static const bool MaySupportMemoryTagging = false ;
90
90
template <typename > using TSDRegistryT = void ;
91
91
template <typename > using PrimaryT = void ;
@@ -97,7 +97,7 @@ struct NoCacheConfig {
97
97
};
98
98
};
99
99
100
- struct TestConfig {
100
+ struct TestCacheConfig {
101
101
static const bool MaySupportMemoryTagging = false ;
102
102
template <typename > using TSDRegistryT = void ;
103
103
template <typename > using PrimaryT = void ;
@@ -117,15 +117,15 @@ struct TestConfig {
117
117
};
118
118
};
119
119
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 >();
124
124
}
125
125
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 >>;
129
129
130
130
void SetUp () override { Allocator->init (nullptr ); }
131
131
@@ -134,13 +134,13 @@ struct MapAllocatorTest : public Test {
134
134
std::unique_ptr<LargeAllocator> Allocator =
135
135
std::make_unique<LargeAllocator>();
136
136
scudo::Options Options =
137
- getOptionsForConfig<scudo::SecondaryConfig<Config >>();
137
+ getOptionsForConfig<scudo::SecondaryConfig<TestNoCacheConfig >>();
138
138
};
139
139
140
140
// This exercises a variety of combinations of size and alignment for the
141
141
// MapAllocator. The size computation done here mimic the ones done by the
142
142
// combined allocator.
143
- TEST_F (MapAllocatorTest, SecondaryCombinations ) {
143
+ TEST_F (ScudoSecondaryAllocatorTest, Combinations ) {
144
144
constexpr scudo::uptr MinAlign = FIRST_32_SECOND_64 (8 , 16 );
145
145
constexpr scudo::uptr HeaderSize = scudo::roundUp (8 , MinAlign);
146
146
for (scudo::uptr SizeLog = 0 ; SizeLog <= 20 ; SizeLog++) {
@@ -168,7 +168,7 @@ TEST_F(MapAllocatorTest, SecondaryCombinations) {
168
168
Str.output ();
169
169
}
170
170
171
- TEST_F (MapAllocatorTest, SecondaryIterate ) {
171
+ TEST_F (ScudoSecondaryAllocatorTest, Iterate ) {
172
172
std::vector<void *> V;
173
173
const scudo::uptr PageSize = scudo::getPageSizeCached ();
174
174
for (scudo::uptr I = 0 ; I < 32U ; I++)
@@ -190,34 +190,8 @@ TEST_F(MapAllocatorTest, SecondaryIterate) {
190
190
Str.output ();
191
191
}
192
192
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 {
221
195
void SetUp () override { Allocator->init (nullptr , /* ReleaseToOsInterval=*/ 0 ); }
222
196
223
197
void performAllocations () {
@@ -249,11 +223,11 @@ struct MapAllocatorWithReleaseTest : public MapAllocatorTest {
249
223
bool Ready = false ;
250
224
};
251
225
252
- TEST_F (MapAllocatorWithReleaseTest, SecondaryThreadsRace ) {
226
+ TEST_F (ScudoSecondaryAllocatorWithReleaseTest, ThreadsRace ) {
253
227
std::thread Threads[16 ];
254
228
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 );
257
231
{
258
232
std::unique_lock<std::mutex> Lock (Mutex);
259
233
Ready = true ;
@@ -266,15 +240,15 @@ TEST_F(MapAllocatorWithReleaseTest, SecondaryThreadsRace) {
266
240
Str.output ();
267
241
}
268
242
269
- struct MapAllocatorCacheTest : public Test {
243
+ struct ScudoSecondaryAllocatorCacheTest : public Test {
270
244
static constexpr scudo::u32 UnmappedMarker = 0xDEADBEEF ;
271
245
272
246
static void testUnmapCallback (scudo::MemMapT &MemMap) {
273
247
scudo::u32 *Ptr = reinterpret_cast <scudo::u32 *>(MemMap.getBase ());
274
248
*Ptr = UnmappedMarker;
275
249
}
276
250
277
- using SecondaryConfig = scudo::SecondaryConfig<TestConfig >;
251
+ using SecondaryConfig = scudo::SecondaryConfig<TestCacheConfig >;
278
252
using CacheConfig = SecondaryConfig::CacheConfig;
279
253
using CacheT = scudo::MapAllocatorCache<CacheConfig, testUnmapCallback>;
280
254
@@ -315,7 +289,7 @@ struct MapAllocatorCacheTest : public Test {
315
289
}
316
290
};
317
291
318
- TEST_F (MapAllocatorCacheTest, CacheOrder ) {
292
+ TEST_F (ScudoSecondaryAllocatorCacheTest, EntryOrder ) {
319
293
std::vector<scudo::MemMapT> MemMaps;
320
294
Cache->setOption (scudo::Option::MaxCacheEntriesCount,
321
295
CacheConfig::getEntriesArraySize ());
@@ -336,7 +310,7 @@ TEST_F(MapAllocatorCacheTest, CacheOrder) {
336
310
MemMap.unmap ();
337
311
}
338
312
339
- TEST_F (MapAllocatorCacheTest , PartialChunkHeuristicRetrievalTest) {
313
+ TEST_F (ScudoSecondaryAllocatorCacheTest , PartialChunkHeuristicRetrievalTest) {
340
314
const scudo::uptr FragmentedPages =
341
315
1 + scudo::CachedBlock::MaxReleasedCachePages;
342
316
scudo::uptr EntryHeaderPos;
@@ -360,7 +334,7 @@ TEST_F(MapAllocatorCacheTest, PartialChunkHeuristicRetrievalTest) {
360
334
MemMap.unmap ();
361
335
}
362
336
363
- TEST_F (MapAllocatorCacheTest , MemoryLeakTest) {
337
+ TEST_F (ScudoSecondaryAllocatorCacheTest , MemoryLeakTest) {
364
338
std::vector<scudo::MemMapT> MemMaps;
365
339
// Fill the cache above MaxEntriesCount to force an eviction
366
340
// The first cache entry should be evicted (because it is the oldest)
@@ -387,3 +361,24 @@ TEST_F(MapAllocatorCacheTest, MemoryLeakTest) {
387
361
for (auto &MemMap : MemMaps)
388
362
MemMap.unmap ();
389
363
}
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