Commit a923af1c authored by Petr Machata's avatar Petr Machata Committed by Jakub Kicinski

selftests: forwarding: Convert log_test() to recognize RET values

In a previous patch, the interpretation of RET value was changed to mean
the kselftest framework constant with the test outcome: $ksft_pass,
$ksft_xfail, etc.

Update log_test() to recognize the various possible RET values.

Then have EXIT_STATUS track the RET value of the current test. This differs
subtly from the way RET tracks the value: while for RET we want to
recognize XFAIL as a separate status, for purposes of exit code, we want to
to conflate XFAIL and PASS, because they both communicate non-failure. Thus
add a new helper, ksft_exit_status_merge().

With this log_test_skip() and log_test_xfail() can be reexpressed as thin
wrappers around log_test.
Signed-off-by: default avatarPetr Machata <petrm@nvidia.com>
Link: https://lore.kernel.org/r/e5f807cb5476ab795fd14ac74da53a731a9fc432.1711464583.git.petrm@nvidia.comSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 596c8819
...@@ -438,6 +438,62 @@ check_err_fail() ...@@ -438,6 +438,62 @@ check_err_fail()
fi fi
} }
log_test_result()
{
local test_name=$1; shift
local opt_str=$1; shift
local result=$1; shift
local retmsg=$1; shift
printf "TEST: %-60s [%s]\n" "$test_name $opt_str" "$result"
if [[ $retmsg ]]; then
printf "\t%s\n" "$retmsg"
fi
}
pause_on_fail()
{
if [[ $PAUSE_ON_FAIL == yes ]]; then
echo "Hit enter to continue, 'q' to quit"
read a
[[ $a == q ]] && exit 1
fi
}
handle_test_result_pass()
{
local test_name=$1; shift
local opt_str=$1; shift
log_test_result "$test_name" "$opt_str" " OK "
}
handle_test_result_fail()
{
local test_name=$1; shift
local opt_str=$1; shift
log_test_result "$test_name" "$opt_str" FAIL "$retmsg"
pause_on_fail
}
handle_test_result_xfail()
{
local test_name=$1; shift
local opt_str=$1; shift
log_test_result "$test_name" "$opt_str" XFAIL "$retmsg"
pause_on_fail
}
handle_test_result_skip()
{
local test_name=$1; shift
local opt_str=$1; shift
log_test_result "$test_name" "$opt_str" SKIP "$retmsg"
}
log_test() log_test()
{ {
local test_name=$1 local test_name=$1
...@@ -447,40 +503,28 @@ log_test() ...@@ -447,40 +503,28 @@ log_test()
opt_str="($opt_str)" opt_str="($opt_str)"
fi fi
if [[ $RET -ne 0 ]]; then if ((RET == ksft_pass)); then
EXIT_STATUS=1 handle_test_result_pass "$test_name" "$opt_str"
printf "TEST: %-60s [FAIL]\n" "$test_name $opt_str" elif ((RET == ksft_xfail)); then
if [[ ! -z "$retmsg" ]]; then handle_test_result_xfail "$test_name" "$opt_str"
printf "\t%s\n" "$retmsg" elif ((RET == ksft_skip)); then
fi handle_test_result_skip "$test_name" "$opt_str"
if [ "${PAUSE_ON_FAIL}" = "yes" ]; then else
echo "Hit enter to continue, 'q' to quit" handle_test_result_fail "$test_name" "$opt_str"
read a
[ "$a" = "q" ] && exit 1
fi
return 1
fi fi
printf "TEST: %-60s [ OK ]\n" "$test_name $opt_str" EXIT_STATUS=$(ksft_exit_status_merge $EXIT_STATUS $RET)
return 0 return $RET
} }
log_test_skip() log_test_skip()
{ {
local test_name=$1 RET=$ksft_skip retmsg= log_test "$@"
local opt_str=$2
printf "TEST: %-60s [SKIP]\n" "$test_name $opt_str"
return 0
} }
log_test_xfail() log_test_xfail()
{ {
local test_name=$1 RET=$ksft_xfail retmsg= log_test "$@"
local opt_str=$2
printf "TEST: %-60s [XFAIL]\n" "$test_name $opt_str"
return 0
} }
log_info() log_info()
......
...@@ -49,6 +49,15 @@ ksft_status_merge() ...@@ -49,6 +49,15 @@ ksft_status_merge()
$ksft_pass $ksft_xfail $ksft_skip $ksft_fail $ksft_pass $ksft_xfail $ksft_skip $ksft_fail
} }
ksft_exit_status_merge()
{
local a=$1; shift
local b=$1; shift
__ksft_status_merge "$a" "$b" \
$ksft_xfail $ksft_pass $ksft_skip $ksft_fail
}
busywait() busywait()
{ {
local timeout=$1; shift local timeout=$1; shift
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment