mirror of
https://git.sr.ht/~cismonx/bookmarkfs
synced 2025-07-22 09:08:51 +00:00
Tests that require PRNG are by default seeded from `/dev/urandom`. However, the user should be able to override with a given seed to reproduce a failing test. Instead of messing with command-line arguments, a cleaner approach is to fetch the seed from an environment variable.
46 lines
1.2 KiB
Text
46 lines
1.2 KiB
Text
dnl
|
|
dnl Copyright (C) 2025 CismonX <admin@cismon.net>
|
|
dnl
|
|
dnl Copying and distribution of this file, with or without modification,
|
|
dnl are permitted in any medium without royalty,
|
|
dnl provided the copyright notice and this notice are preserved.
|
|
dnl This file is offered as-is, without any warranty.
|
|
dnl
|
|
|
|
AT_SETUP([util lib: prng])
|
|
AT_KEYWORDS([lib prng])
|
|
|
|
# This test only serves as a basic sanity check.
|
|
#
|
|
# For reliable testing of PRNGs, see <https://prng.di.unimi.it/#quality>.
|
|
ATX_CHECK_LIB([
|
|
gen_num() {
|
|
env BOOKMARKFS_TEST_PRNG_SEED=$1 check-util-lib prng -n$2
|
|
}
|
|
|
|
repeat=1
|
|
if test -z "$BOOKMARKFS_TEST_PRNG_SEED"; then
|
|
repeat=16
|
|
fi
|
|
ATX_RUN_REPEAT([$repeat], [
|
|
seed=$(check-util-lib prng -n4 | tr -d '\n')
|
|
count=32
|
|
|
|
num_1=$(gen_num $seed $count)
|
|
num_2=$(gen_num $seed $count)
|
|
num_3=$(gen_num $seed $count)
|
|
|
|
if test "$num_1" != "$num_2" -o "$num_2" != "$num_3"; then
|
|
echo 'bad prng: inconsistent number sequence'
|
|
exit 1
|
|
fi
|
|
|
|
uniq_count=$(echo "$num_1" | sort | uniq | wc -l)
|
|
if test $uniq_count -ne $count; then
|
|
echo 'bad prng: getting duplicates too soon'
|
|
exit 1
|
|
fi
|
|
])
|
|
])
|
|
|
|
AT_CLEANUP
|