Skip to content

Commit 180b99c

Browse files
authored
[scudo] Relax MemtagTag.SelectRandomTag. (#68048)
As it turns out, PRNGs have varying quality. Relax the test to accept less-then-perfect tag distribution.
1 parent d002ce5 commit 180b99c

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,15 @@ TEST_F(MemtagTest, SelectRandomTag) {
120120
uptr Tags = 0;
121121
for (uptr I = 0; I < 100000; ++I)
122122
Tags = Tags | (1u << extractTag(selectRandomTag(Ptr, 0)));
123-
EXPECT_EQ(0xfffeull, Tags);
123+
// std::popcnt is C++20
124+
int PopCnt = 0;
125+
while (Tags) {
126+
PopCnt += Tags & 1;
127+
Tags >>= 1;
128+
}
129+
// Random tags are not always very random, and this test is not about PRNG
130+
// quality. Anything above half would be satisfactory.
131+
EXPECT_GE(PopCnt, 8);
124132
}
125133
}
126134

0 commit comments

Comments
 (0)