Skip to content

Commit eb97175

Browse files
update test
1 parent d106a7f commit eb97175

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

libc/test/integration/src/stdlib/linux/vsdo_rng_test.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,20 @@ void basic_test() {
2020
// Try to get a guard
2121
if (auto guard = local_state.get()) {
2222
// Fill a small buffer with random data
23-
long long buffer[32] = {0};
23+
char buffer[256]{};
2424
guard->fill(buffer, sizeof(buffer));
2525

26-
// Basic sanity check - buffer should not have zero
26+
// Basic sanity check - count zero bytes.
27+
// With 256 bytes, getting more than ~10 zero bytes would be suspicious
28+
size_t zero_count = 0;
2729
for (auto &i : buffer)
2830
if (i == 0)
29-
__builtin_trap();
31+
zero_count++;
32+
33+
// With uniform distribution, expect ~1 zero byte per 256 bytes
34+
// Having more than 16 zero bytes in 256 bytes is very unlikely
35+
if (zero_count > 16)
36+
__builtin_trap();
3037
}
3138
// If we can't get a guard, that's okay - the vDSO might not be available
3239
// or the system might not support getrandom

0 commit comments

Comments
 (0)