Skip to content

Commit 2f5d03e

Browse files
committed
Add better comments to describe the tests.
Remove a redundant check. Make all allocatoins for the guard page verification use an alignment.
1 parent 97064b0 commit 2f5d03e

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,10 @@ void testGetMappedSize(scudo::uptr Size, scudo::uptr *mapped,
304304
*mapped = Stats[scudo::StatMapped];
305305
Stats[scudo::StatMapped] = 0;
306306

307-
void *Ptr = Info.Allocator->allocate(Info.Options, Size);
307+
// Make sure the allocation is aligned to a page boundary so that the checks
308+
// in the tests can avoid problems due to allocations having different
309+
// alignments.
310+
void *Ptr = Info.Allocator->allocate(Info.Options, Size, PageSize);
308311
EXPECT_NE(Ptr, nullptr);
309312

310313
Info.GlobalStats.get(Stats);
@@ -319,21 +322,28 @@ void testGetMappedSize(scudo::uptr Size, scudo::uptr *mapped,
319322
TEST(ScudoSecondaryTest, VerifyGuardPageOption) {
320323
static scudo::uptr AllocSize = 1000 * PageSize;
321324

325+
// Verify that a config with guard pages enabled:
326+
// - Non-zero sized guard page
327+
// - Mapped in at least the size of the allocation plus 2 * guard page size
322328
scudo::uptr guard_mapped = 0;
323329
scudo::uptr guard_page_size = 0;
324330
testGetMappedSize<TestNoCacheConfig>(AllocSize, &guard_mapped,
325331
&guard_page_size);
326332
EXPECT_GT(guard_page_size, 0U);
327333
EXPECT_GE(guard_mapped, AllocSize + 2 * guard_page_size);
328334

335+
// Verify that a config with guard pages disabled:
336+
// - Zero sized guard page
337+
// - The total mapped in is greater than the allocation size
329338
scudo::uptr no_guard_mapped = 0;
330339
scudo::uptr no_guard_page_size = 0;
331340
testGetMappedSize<TestNoCacheNoGuardPageConfig>(AllocSize, &no_guard_mapped,
332341
&no_guard_page_size);
333342
EXPECT_EQ(no_guard_page_size, 0U);
334343
EXPECT_GE(no_guard_mapped, AllocSize);
335344

336-
EXPECT_GE(guard_mapped, no_guard_mapped);
345+
// Verify that a guard page config mapped in at least twice the size of
346+
// their guard page when compared to a no guard page config.
337347
EXPECT_GE(guard_mapped, no_guard_mapped + guard_page_size * 2);
338348
}
339349

0 commit comments

Comments
 (0)