test: misc refactor

- Repeat simple tests that may fail upon multiple invocations.
- ...
This commit is contained in:
CismonX 2025-03-28 14:29:18 +08:00
parent bdfa812d79
commit 9da346753d
No known key found for this signature in database
GPG key ID: 3094873E29A482FB
5 changed files with 52 additions and 41 deletions

View file

@ -154,19 +154,11 @@ check_watcher (
int argc,
char *argv[]
) {
char const *path = NULL;
OPT_START(argc, argv, "d:")
OPT_OPT('d') {
path = optarg;
break;
}
OPT_END
if (path == NULL) {
if (--argc < 1) {
log_puts("path not specified");
return -1;
}
char const *path = *(++argv);
int dirfd = open(path, O_RDONLY | O_DIRECTORY);
if (dirfd < 0) {

View file

@ -19,8 +19,10 @@ ATX_CHECK_LIB([
echo "$2" | check-util-lib hash -s$1
}
ATX_RUN_REPEAT([16], [
seed=$(ath_fn_rand_u64_hex)
input=$(ath_fn_rand_base64 300)
echo "hash seed: $seed; input: $input"
hash_1=$(calc_digest $seed $input)
hash_2=$(calc_digest $seed $input)
@ -36,6 +38,7 @@ ATX_CHECK_LIB([
echo 'bad hash function: collision'
exit 1
fi
])
])
AT_CLEANUP

View file

@ -18,8 +18,10 @@ ATX_CHECK_LIB([
check-util-lib prng -s$1 -n$2
}
ATX_RUN_REPEAT([16], [
seed=$(ath_fn_prng_seed)
count=32
echo "prng seed: $seed"
num_1=$(gen_num $seed $count)
num_2=$(gen_num $seed $count)
@ -35,6 +37,7 @@ ATX_CHECK_LIB([
echo 'bad prng: getting duplicates too soon'
exit 1
fi
])
])
AT_CLEANUP

View file

@ -16,7 +16,7 @@ ATX_CHECK_LIB([
mkdir $tmpdir
ATX_RUN([
check-util-lib watcher -d $tmpdir
check-util-lib watcher $tmpdir
])
])

View file

@ -50,6 +50,19 @@ m4_define([ATX_FEAT_PREREQ], [
fi
])
dnl
dnl ATX_RUN_REPEAT(n, script)
dnl
dnl Run script n times. Cannot be nested.
dnl
m4_define([ATX_RUN_REPEAT], [
atx_counter_=$1
while test $atx_counter_ -gt 0; do
$2
atx_counter_=$(($atx_counter_ - 1))
done
])
dnl
dnl ATX_RUN_ONE(cmd)
dnl
@ -71,10 +84,10 @@ m4_define([ATX_RUN], [
])
dnl
dnl ATX_CHECK_SIMPLE(script)
dnl ATX_CHECK_SIMPLE(script, [cleanup])
dnl
m4_define([ATX_CHECK_SIMPLE], [
AT_CHECK([$1], , [ignore], [ignore])
AT_CHECK([$1], , [ignore], [ignore], [$2], [$2])
])
dnl