[compiler-rt] 180b99c - [scudo] Relax MemtagTag.SelectRandomTag. (#68048)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 9 13:14:23 PST 2023
Author: Evgenii Stepanov
Date: 2023-11-09T13:14:20-08:00
New Revision: 180b99c3027f0e26a0d9874b32569d58d109bafe
URL: https://github.com/llvm/llvm-project/commit/180b99c3027f0e26a0d9874b32569d58d109bafe
DIFF: https://github.com/llvm/llvm-project/commit/180b99c3027f0e26a0d9874b32569d58d109bafe.diff
LOG: [scudo] Relax MemtagTag.SelectRandomTag. (#68048)
As it turns out, PRNGs have varying quality.
Relax the test to accept less-then-perfect tag distribution.
Added:
Modified:
compiler-rt/lib/scudo/standalone/tests/memtag_test.cpp
Removed:
################################################################################
diff --git a/compiler-rt/lib/scudo/standalone/tests/memtag_test.cpp b/compiler-rt/lib/scudo/standalone/tests/memtag_test.cpp
index 2488e04856bd972..fd277f962a9aaac 100644
--- a/compiler-rt/lib/scudo/standalone/tests/memtag_test.cpp
+++ b/compiler-rt/lib/scudo/standalone/tests/memtag_test.cpp
@@ -120,7 +120,15 @@ TEST_F(MemtagTest, SelectRandomTag) {
uptr Tags = 0;
for (uptr I = 0; I < 100000; ++I)
Tags = Tags | (1u << extractTag(selectRandomTag(Ptr, 0)));
- EXPECT_EQ(0xfffeull, Tags);
+ // std::popcnt is C++20
+ int PopCnt = 0;
+ while (Tags) {
+ PopCnt += Tags & 1;
+ Tags >>= 1;
+ }
+ // Random tags are not always very random, and this test is not about PRNG
+ // quality. Anything above half would be satisfactory.
+ EXPECT_GE(PopCnt, 8);
}
}
More information about the llvm-commits
mailing list