test: misc fix and refactor

- Do not exit with status 99.  It is considered a "hard failure"
  in Autotest, and cleanup script won't be executed.
- Fix ATX_FEAT_PREREQ().
- Remove unneeded helper macros.
- Add more log output.
This commit is contained in:
CismonX 2025-03-24 19:30:32 +08:00
parent 7b5ed129be
commit bced141b98
No known key found for this signature in database
GPG key ID: 3094873E29A482FB
5 changed files with 18 additions and 23 deletions

View file

@ -24,6 +24,7 @@
#include <errno.h> #include <errno.h>
#include <stdbool.h> #include <stdbool.h>
#include <string.h>
#include <fcntl.h> #include <fcntl.h>
#include <netinet/in.h> #include <netinet/in.h>
@ -176,7 +177,7 @@ check_sandbox (
int dirfd = open(path, O_RDONLY | O_DIRECTORY); int dirfd = open(path, O_RDONLY | O_DIRECTORY);
if (dirfd < 0) { if (dirfd < 0) {
log_printf("failed to open '%s'", path); log_printf("open: %s: %s", path, strerror(errno));
return -1; return -1;
} }
int status = sandbox_enter(dirfd, flags); int status = sandbox_enter(dirfd, flags);

View file

@ -25,6 +25,7 @@
#include <errno.h> #include <errno.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdio.h> #include <stdio.h>
#include <string.h>
#include <time.h> #include <time.h>
#include <fcntl.h> #include <fcntl.h>
@ -169,7 +170,7 @@ check_watcher (
int dirfd = open(path, O_RDONLY | O_DIRECTORY); int dirfd = open(path, O_RDONLY | O_DIRECTORY);
if (dirfd < 0) { if (dirfd < 0) {
log_printf("failed to open '%s'", path); log_printf("open: %s: %s", path, strerror(errno));
return -1; return -1;
} }

View file

@ -27,14 +27,14 @@ ATX_CHECK_LIB([
hash_3=$(calc_digest $seed $input) hash_3=$(calc_digest $seed $input)
hash_x=$(calc_digest $seed $input+) hash_x=$(calc_digest $seed $input+)
# Given the same seed and input, the digest should be consistent.
if test "$hash_1" != "$hash_2" -o "$hash_2" != "$hash_3"; then if test "$hash_1" != "$hash_2" -o "$hash_2" != "$hash_3"; then
ATX_FAIL echo 'bad hash function: inconsistent digest'
exit 1
fi fi
# Bad hash function if we're getting collisions.
if test "$hash_1" = "$hash_x"; then if test "$hash_1" = "$hash_x"; then
ATX_FAIL echo 'bad hash function: collision'
exit 1
fi fi
]) ])

View file

@ -25,15 +25,15 @@ ATX_CHECK_LIB([
num_2=$(gen_num $seed $count) num_2=$(gen_num $seed $count)
num_3=$(gen_num $seed $count) num_3=$(gen_num $seed $count)
# Given the same seed, the results should be consistent.
if test "$num_1" != "$num_2" -o "$num_2" != "$num_3"; then if test "$num_1" != "$num_2" -o "$num_2" != "$num_3"; then
ATX_FAIL echo 'bad prng: inconsistent number sequence'
exit 1
fi fi
# Bad PRNG if we're getting duplicates too soon.
uniq_count=$(echo "$num_1" | sort | uniq | wc -l) uniq_count=$(echo "$num_1" | sort | uniq | wc -l)
if test $uniq_count -ne $count; then if test $uniq_count -ne $count; then
ATX_FAIL echo 'bad prng: getting duplicates too soon'
exit 1
fi fi
]) ])

View file

@ -10,12 +10,11 @@ dnl
AT_INIT AT_INIT
dnl dnl
dnl Fail or skip the current test. dnl ATX_REPEAT(n, string)
dnl dnl
dnl The status codes are defined by Autotest. dnl Repeat string n times.
dnl dnl
m4_define([ATX_FAIL], [exit 99]) m4_define([ATX_REPEAT], [m4_for([unused_], [1], [$1], , [$2])])
m4_define([ATX_SKIP], [exit 77])
dnl dnl
dnl ATX_FEAT_VAR(feature) dnl ATX_FEAT_VAR(feature)
@ -46,8 +45,8 @@ dnl
dnl If any of the given features is not enabled, skip the current test. dnl If any of the given features is not enabled, skip the current test.
dnl dnl
m4_define([ATX_FEAT_PREREQ], [ m4_define([ATX_FEAT_PREREQ], [
if test -z "m4_map([ATX_FEAT_VAR], [$@])"; then if test "m4_map([ATX_FEAT_VAR], [$@])" != ATX_REPEAT([$#], [y]); then
ATX_SKIP exit 77
fi fi
]) ])
@ -58,13 +57,7 @@ dnl Run a pipeline of shell command(s).
dnl If it exits with a non-zero status, fail the current test. dnl If it exits with a non-zero status, fail the current test.
dnl dnl
m4_define([ATX_RUN_ONE], [ m4_define([ATX_RUN_ONE], [
m4_ifnblank([$1], [ m4_ifnblank([$1], [$1 || exit $?])
if $1; then :
else
echo "exit status: $?"
ATX_FAIL
fi
])
]) ])
dnl dnl