diff --git a/tests/check_lib.c b/tests/check_lib.c index 86155cc..7a30e3f 100644 --- a/tests/check_lib.c +++ b/tests/check_lib.c @@ -105,19 +105,16 @@ subcmd_prng ( int argc, char *argv[] ) { - static uint64_t seed[4]; - int cnt = 0; + static uint64_t buf[4]; + uint64_t *seed = NULL; int n = 0; getopt_foreach(argc, argv, ":s:n:") { case 's': - cnt = sscanf(optarg, - "%16" SCNx64 "%16" SCNx64 "%16" SCNx64 "%16" SCNx64, - &seed[0], &seed[1], &seed[2], &seed[3]); - if (cnt != 4) { - log_printf("bad seed '%s'", optarg); + if (0 != prng_seed_from_hex(buf, optarg)) { return -1; } + seed = buf; break; case 'n': @@ -129,7 +126,7 @@ subcmd_prng ( return -1; } - if (0 != prng_seed(cnt == 0 ? NULL : seed)) { + if (0 != prng_seed(seed)) { return -1; } for (; n > 0; --n) { @@ -138,6 +135,21 @@ subcmd_prng ( return 0; } +int +prng_seed_from_hex ( + uint64_t *buf, + char const *str +) { + int cnt = sscanf(str, + "%16" SCNx64 "%16" SCNx64 "%16" SCNx64 "%16" SCNx64, + &buf[0], &buf[1], &buf[2], &buf[3]); + if (cnt != 4) { + log_printf("bad seed '%s'", optarg); + return -1; + } + return 0; +} + int main ( int argc, diff --git a/tests/check_lib.h b/tests/check_lib.h index eb6e0f7..2fa2b47 100644 --- a/tests/check_lib.h +++ b/tests/check_lib.h @@ -21,6 +21,8 @@ #ifndef BOOKMARKFS_CHECK_LIB_H_ #define BOOKMARKFS_CHECK_LIB_H_ +#include + #include "xstd.h" #define ASSERT_EXPR_INT(expr, r, cond, action_if_false) \ @@ -45,4 +47,10 @@ check_watcher ( char *argv[] ); +int +prng_seed_from_hex ( + uint64_t *buf, + char const *str +); + #endif /* !defined(BOOKMARKFS_CHECK_LIB_H_) */ diff --git a/tests/lib_prng.at b/tests/lib_prng.at index 5155a56..5f1123f 100644 --- a/tests/lib_prng.at +++ b/tests/lib_prng.at @@ -18,16 +18,7 @@ ATX_CHECK_LIB([ check-util-lib prng -s$1 -n$2 } - gen_seed() { - seed_1=$(ath_fn_rand_u64_hex) - seed_2=$(ath_fn_rand_u64_hex) - seed_3=$(ath_fn_rand_u64_hex) - seed_4=$(ath_fn_rand_u64_hex) - - echo $seed_1$seed_2$seed_3$seed_4 - } - - seed=$(gen_seed) + seed=$(ath_fn_prng_seed) count=32 num_1=$(gen_num $seed $count) diff --git a/tests/testsuite.at b/tests/testsuite.at index c8bdb9f..60a95cd 100644 --- a/tests/testsuite.at +++ b/tests/testsuite.at @@ -93,6 +93,15 @@ AT_TEST_HELPER_FN([rand_base64], , , [ echo $(head -c$1 /dev/urandom | base64 -w0) ]) +AT_TEST_HELPER_FN([prng_seed], , , [ + seed_1=$(ath_fn_rand_u64_hex) + seed_2=$(ath_fn_rand_u64_hex) + seed_3=$(ath_fn_rand_u64_hex) + seed_4=$(ath_fn_rand_u64_hex) + + echo $seed_1$seed_2$seed_3$seed_4 +]) + AT_BANNER([The Utility Library]) m4_include([lib_hash.at]) m4_include([lib_prng.at])