Skip to content

Commit bed22c7

Browse files
idoschkuba-moo
authored andcommitted
selftests: net: lib: Do not overwrite error messages
ret_set_ksft_status() calls ksft_status_merge() with the current return status and the last one. It treats a non-zero return code from ksft_status_merge() as an indication that the return status was overwritten by the last one and therefore overwrites the return message with the last one. Currently, ksft_status_merge() returns a non-zero return code even if the current return status and the last one are equal. This results in return messages being overwritten which is counter-productive since we are more interested in the first failure message and not the last one. Fix by changing ksft_status_merge() to only return a non-zero return code if the current return status was actually changed. Add a test case which checks that the first error message is not overwritten. Before: # ./lib_sh_test.sh [...] TEST: RET tfail2 tfail -> fail [FAIL] retmsg=tfail expected tfail2 [...] # echo $? 1 After: # ./lib_sh_test.sh [...] TEST: RET tfail2 tfail -> fail [ OK ] [...] # echo $? 0 Fixes: 596c881 ("selftests: forwarding: Have RET track kselftest framework constants") Reviewed-by: Petr Machata <petrm@nvidia.com> Signed-off-by: Ido Schimmel <idosch@nvidia.com> Link: https://patch.msgid.link/20251116081029.69112-1-idosch@nvidia.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent da02a18 commit bed22c7

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ tfail()
3030
do_test "tfail" false
3131
}
3232

33+
tfail2()
34+
{
35+
do_test "tfail2" false
36+
}
37+
3338
txfail()
3439
{
3540
FAIL_TO_XFAIL=yes do_test "txfail" false
@@ -132,6 +137,8 @@ test_ret()
132137
ret_subtest $ksft_fail "tfail" txfail tfail
133138

134139
ret_subtest $ksft_xfail "txfail" txfail txfail
140+
141+
ret_subtest $ksft_fail "tfail2" tfail2 tfail
135142
}
136143

137144
exit_status_tests_run()

tools/testing/selftests/net/lib.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ __ksft_status_merge()
4343
weights[$i]=$((weight++))
4444
done
4545

46-
if [[ ${weights[$a]} > ${weights[$b]} ]]; then
46+
if [[ ${weights[$a]} -ge ${weights[$b]} ]]; then
4747
echo "$a"
4848
return 0
4949
else

0 commit comments

Comments
 (0)