From bced141b98f8da6e88c7a11f521202fc4aae15dd Mon Sep 17 00:00:00 2001 From: CismonX Date: Mon, 24 Mar 2025 19:30:32 +0800 Subject: [PATCH] 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. --- tests/check_sandbox.c | 3 ++- tests/check_watcher.c | 3 ++- tests/lib_hash.at | 8 ++++---- tests/lib_prng.at | 8 ++++---- tests/testsuite.at | 19 ++++++------------- 5 files changed, 18 insertions(+), 23 deletions(-) diff --git a/tests/check_sandbox.c b/tests/check_sandbox.c index 87326c5..641bab2 100644 --- a/tests/check_sandbox.c +++ b/tests/check_sandbox.c @@ -24,6 +24,7 @@ #include #include +#include #include #include @@ -176,7 +177,7 @@ check_sandbox ( int dirfd = open(path, O_RDONLY | O_DIRECTORY); if (dirfd < 0) { - log_printf("failed to open '%s'", path); + log_printf("open: %s: %s", path, strerror(errno)); return -1; } int status = sandbox_enter(dirfd, flags); diff --git a/tests/check_watcher.c b/tests/check_watcher.c index e86c988..7740b84 100644 --- a/tests/check_watcher.c +++ b/tests/check_watcher.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -169,7 +170,7 @@ check_watcher ( int dirfd = open(path, O_RDONLY | O_DIRECTORY); if (dirfd < 0) { - log_printf("failed to open '%s'", path); + log_printf("open: %s: %s", path, strerror(errno)); return -1; } diff --git a/tests/lib_hash.at b/tests/lib_hash.at index 5704c99..ca9f789 100644 --- a/tests/lib_hash.at +++ b/tests/lib_hash.at @@ -27,14 +27,14 @@ ATX_CHECK_LIB([ hash_3=$(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 - ATX_FAIL + echo 'bad hash function: inconsistent digest' + exit 1 fi - # Bad hash function if we're getting collisions. if test "$hash_1" = "$hash_x"; then - ATX_FAIL + echo 'bad hash function: collision' + exit 1 fi ]) diff --git a/tests/lib_prng.at b/tests/lib_prng.at index 5f1123f..c0b5589 100644 --- a/tests/lib_prng.at +++ b/tests/lib_prng.at @@ -25,15 +25,15 @@ ATX_CHECK_LIB([ num_2=$(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 - ATX_FAIL + echo 'bad prng: inconsistent number sequence' + exit 1 fi - # Bad PRNG if we're getting duplicates too soon. uniq_count=$(echo "$num_1" | sort | uniq | wc -l) if test $uniq_count -ne $count; then - ATX_FAIL + echo 'bad prng: getting duplicates too soon' + exit 1 fi ]) diff --git a/tests/testsuite.at b/tests/testsuite.at index 3ed5605..b959729 100644 --- a/tests/testsuite.at +++ b/tests/testsuite.at @@ -10,12 +10,11 @@ dnl AT_INIT dnl -dnl Fail or skip the current test. +dnl ATX_REPEAT(n, string) dnl -dnl The status codes are defined by Autotest. +dnl Repeat string n times. dnl -m4_define([ATX_FAIL], [exit 99]) -m4_define([ATX_SKIP], [exit 77]) +m4_define([ATX_REPEAT], [m4_for([unused_], [1], [$1], , [$2])]) dnl 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 m4_define([ATX_FEAT_PREREQ], [ - if test -z "m4_map([ATX_FEAT_VAR], [$@])"; then - ATX_SKIP + if test "m4_map([ATX_FEAT_VAR], [$@])" != ATX_REPEAT([$#], [y]); then + exit 77 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 m4_define([ATX_RUN_ONE], [ - m4_ifnblank([$1], [ - if $1; then : - else - echo "exit status: $?" - ATX_FAIL - fi - ]) + m4_ifnblank([$1], [$1 || exit $?]) ]) dnl