Skip to content

Commit 596c881

Browse files
pmachatakuba-moo
authored andcommitted
selftests: forwarding: Have RET track kselftest framework constants
The variable RET keeps track of whether the test under execution has so far failed or not. Currently it works in binary fashion: zero means everything is fine, non-zero means something failed. log_test() then uses the value to given a human-readable message. In order to allow log_test() to report skips and xfails, the semantics of RET need to be more fine-grained. Therefore have RET value be one of kselftest framework constants: $ksft_fail, $ksft_xfail, etc. The current logic in check_err() is such that first non-zero value of RET trumps all those that follow. But that is not right when RET has more fine-grained value semantics. Different outcomes have different weights. The results of PASS and XFAIL are mostly the same: they both communicate a test that did not go wrong. SKIP communicates lack of tooling, which the user should go and try to fix, and as such should not be overridden by the passes. So far, the higher-numbered statuses can be considered weightier. But FAIL should be the weightiest. Add a helper, ksft_status_merge(), which merges two statuses in a way that respects the above conditions. Express it in a generic manner, because exit status merge is subtly different, and we want to reuse the same logic. Use the new helper when setting RET in check_err(). Re-express check_fail() in terms of check_err() to avoid duplication. Signed-off-by: Petr Machata <petrm@nvidia.com> Link: https://lore.kernel.org/r/7dfff51cc925c7a3ac879b9050a0d6a327c8d21f.1711464583.git.petrm@nvidia.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 51ccf26 commit 596c881

File tree

2 files changed

+44
-7
lines changed

2 files changed

+44
-7
lines changed

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

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -396,14 +396,24 @@ EXIT_STATUS=0
396396
# Per-test return value. Clear at the beginning of each test.
397397
RET=0
398398

399+
ret_set_ksft_status()
400+
{
401+
local ksft_status=$1; shift
402+
local msg=$1; shift
403+
404+
RET=$(ksft_status_merge $RET $ksft_status)
405+
if (( $? )); then
406+
retmsg=$msg
407+
fi
408+
}
409+
399410
check_err()
400411
{
401412
local err=$1
402413
local msg=$2
403414

404-
if [[ $RET -eq 0 && $err -ne 0 ]]; then
405-
RET=$err
406-
retmsg=$msg
415+
if ((err)); then
416+
ret_set_ksft_status $ksft_fail "$msg"
407417
fi
408418
}
409419

@@ -412,10 +422,7 @@ check_fail()
412422
local err=$1
413423
local msg=$2
414424

415-
if [[ $RET -eq 0 && $err -eq 0 ]]; then
416-
RET=1
417-
retmsg=$msg
418-
fi
425+
check_err $((!err)) "$msg"
419426
}
420427

421428
check_err_fail()

tools/testing/selftests/net/lib.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,36 @@ NS_LIST=""
1919

2020
##############################################################################
2121
# Helpers
22+
23+
__ksft_status_merge()
24+
{
25+
local a=$1; shift
26+
local b=$1; shift
27+
local -A weights
28+
local weight=0
29+
30+
for i in "$@"; do
31+
weights[$i]=$((weight++))
32+
done
33+
34+
if [[ ${weights[$a]} > ${weights[$b]} ]]; then
35+
echo "$a"
36+
return 0
37+
else
38+
echo "$b"
39+
return 1
40+
fi
41+
}
42+
43+
ksft_status_merge()
44+
{
45+
local a=$1; shift
46+
local b=$1; shift
47+
48+
__ksft_status_merge "$a" "$b" \
49+
$ksft_pass $ksft_xfail $ksft_skip $ksft_fail
50+
}
51+
2252
busywait()
2353
{
2454
local timeout=$1; shift

0 commit comments

Comments
 (0)