Skip to content

Commit a923af1

Browse files
pmachatakuba-moo
authored andcommitted
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: Petr Machata <petrm@nvidia.com> Link: https://lore.kernel.org/r/e5f807cb5476ab795fd14ac74da53a731a9fc432.1711464583.git.petrm@nvidia.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 596c881 commit a923af1

File tree

2 files changed

+77
-24
lines changed

2 files changed

+77
-24
lines changed

tools/testing/selftests/net/forwarding/lib.sh

Lines changed: 68 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,62 @@ check_err_fail()
438438
fi
439439
}
440440

441+
log_test_result()
442+
{
443+
local test_name=$1; shift
444+
local opt_str=$1; shift
445+
local result=$1; shift
446+
local retmsg=$1; shift
447+
448+
printf "TEST: %-60s [%s]\n" "$test_name $opt_str" "$result"
449+
if [[ $retmsg ]]; then
450+
printf "\t%s\n" "$retmsg"
451+
fi
452+
}
453+
454+
pause_on_fail()
455+
{
456+
if [[ $PAUSE_ON_FAIL == yes ]]; then
457+
echo "Hit enter to continue, 'q' to quit"
458+
read a
459+
[[ $a == q ]] && exit 1
460+
fi
461+
}
462+
463+
handle_test_result_pass()
464+
{
465+
local test_name=$1; shift
466+
local opt_str=$1; shift
467+
468+
log_test_result "$test_name" "$opt_str" " OK "
469+
}
470+
471+
handle_test_result_fail()
472+
{
473+
local test_name=$1; shift
474+
local opt_str=$1; shift
475+
476+
log_test_result "$test_name" "$opt_str" FAIL "$retmsg"
477+
pause_on_fail
478+
}
479+
480+
handle_test_result_xfail()
481+
{
482+
local test_name=$1; shift
483+
local opt_str=$1; shift
484+
485+
log_test_result "$test_name" "$opt_str" XFAIL "$retmsg"
486+
pause_on_fail
487+
}
488+
489+
handle_test_result_skip()
490+
{
491+
local test_name=$1; shift
492+
local opt_str=$1; shift
493+
494+
log_test_result "$test_name" "$opt_str" SKIP "$retmsg"
495+
}
496+
441497
log_test()
442498
{
443499
local test_name=$1
@@ -447,40 +503,28 @@ log_test()
447503
opt_str="($opt_str)"
448504
fi
449505

450-
if [[ $RET -ne 0 ]]; then
451-
EXIT_STATUS=1
452-
printf "TEST: %-60s [FAIL]\n" "$test_name $opt_str"
453-
if [[ ! -z "$retmsg" ]]; then
454-
printf "\t%s\n" "$retmsg"
455-
fi
456-
if [ "${PAUSE_ON_FAIL}" = "yes" ]; then
457-
echo "Hit enter to continue, 'q' to quit"
458-
read a
459-
[ "$a" = "q" ] && exit 1
460-
fi
461-
return 1
506+
if ((RET == ksft_pass)); then
507+
handle_test_result_pass "$test_name" "$opt_str"
508+
elif ((RET == ksft_xfail)); then
509+
handle_test_result_xfail "$test_name" "$opt_str"
510+
elif ((RET == ksft_skip)); then
511+
handle_test_result_skip "$test_name" "$opt_str"
512+
else
513+
handle_test_result_fail "$test_name" "$opt_str"
462514
fi
463515

464-
printf "TEST: %-60s [ OK ]\n" "$test_name $opt_str"
465-
return 0
516+
EXIT_STATUS=$(ksft_exit_status_merge $EXIT_STATUS $RET)
517+
return $RET
466518
}
467519

468520
log_test_skip()
469521
{
470-
local test_name=$1
471-
local opt_str=$2
472-
473-
printf "TEST: %-60s [SKIP]\n" "$test_name $opt_str"
474-
return 0
522+
RET=$ksft_skip retmsg= log_test "$@"
475523
}
476524

477525
log_test_xfail()
478526
{
479-
local test_name=$1
480-
local opt_str=$2
481-
482-
printf "TEST: %-60s [XFAIL]\n" "$test_name $opt_str"
483-
return 0
527+
RET=$ksft_xfail retmsg= log_test "$@"
484528
}
485529

486530
log_info()

tools/testing/selftests/net/lib.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,15 @@ ksft_status_merge()
4949
$ksft_pass $ksft_xfail $ksft_skip $ksft_fail
5050
}
5151

52+
ksft_exit_status_merge()
53+
{
54+
local a=$1; shift
55+
local b=$1; shift
56+
57+
__ksft_status_merge "$a" "$b" \
58+
$ksft_xfail $ksft_pass $ksft_skip $ksft_fail
59+
}
60+
5261
busywait()
5362
{
5463
local timeout=$1; shift

0 commit comments

Comments
 (0)