Skip to content

Commit 4510fab

Browse files
matttbegregkh
authored andcommitted
selftests: mptcp: check output: catch cmd errors
commit 65db7b2 upstream. Using '${?}' inside the if-statement to check the returned value from the command that was evaluated as part of the if-statement is not correct: here, '${?}' will be linked to the previous instruction, not the one that is expected here (${cmd}). Instead, simply mark the error, except if an error is expected. If that's the case, 1 can be passed as the 4th argument of this helper. Three checks from pm_netlink.sh expect an error. While at it, improve the error message when the command unexpectedly fails or succeeds. Note that we could expect a specific returned value, but the checks currently expecting an error can be used with 'ip mptcp' or 'pm_nl_ctl', and these two tools don't return the same error code. Fixes: 2d0c1d2 ("selftests: mptcp: add mptcp_lib_check_output helper") Cc: stable@vger.kernel.org Reviewed-by: Mat Martineau <martineau@kernel.org> Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org> Link: https://patch.msgid.link/20260505-net-mptcp-pm-fixes-7-1-rc3-v1-10-fca8091060a4@kernel.org Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 00c9e07 commit 4510fab

2 files changed

Lines changed: 16 additions & 10 deletions

File tree

tools/testing/selftests/net/mptcp/mptcp_lib.sh

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -474,20 +474,24 @@ mptcp_lib_wait_local_port_listen() {
474474
wait_local_port_listen "${@}" "tcp"
475475
}
476476

477+
# $1: error file, $2: cmd, $3: expected msg, [$4: expected error]
477478
mptcp_lib_check_output() {
478479
local err="${1}"
479480
local cmd="${2}"
480481
local expected="${3}"
482+
local exp_error="${4:-0}"
481483
local cmd_ret=0
482484
local out
483485

484-
if ! out=$(${cmd} 2>"${err}"); then
485-
cmd_ret=${?}
486-
fi
486+
out=$(${cmd} 2>"${err}") || cmd_ret=1
487487

488-
if [ ${cmd_ret} -ne 0 ]; then
489-
mptcp_lib_pr_fail "command execution '${cmd}' stderr"
490-
cat "${err}"
488+
if [ "${cmd_ret}" != "${exp_error}" ]; then
489+
mptcp_lib_pr_fail "unexpected returned code for '${cmd}', info:"
490+
if [ "${exp_error}" = 0 ]; then
491+
cat "${err}"
492+
else
493+
echo "${out}"
494+
fi
491495
return 2
492496
elif [ "${out}" = "${expected}" ]; then
493497
return 0

tools/testing/selftests/net/mptcp/pm_netlink.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,12 @@ check()
122122
local cmd="$1"
123123
local expected="$2"
124124
local msg="$3"
125+
local exp_error="$4"
125126
local rc=0
126127

127128
mptcp_lib_print_title "$msg"
128-
mptcp_lib_check_output "${err}" "${cmd}" "${expected}" || rc=${?}
129+
mptcp_lib_check_output "${err}" "${cmd}" "${expected}" "${exp_error}" ||
130+
rc=${?}
129131
if [ ${rc} -eq 2 ]; then
130132
mptcp_lib_result_fail "${msg} # error ${rc}"
131133
ret=${KSFT_FAIL}
@@ -158,13 +160,13 @@ check "show_endpoints" \
158160
"3,10.0.1.3,signal backup")" "dump addrs"
159161

160162
del_endpoint 2
161-
check "get_endpoint 2" "" "simple del addr"
163+
check "get_endpoint 2" "" "simple del addr" 1
162164
check "show_endpoints" \
163165
"$(format_endpoints "1,10.0.1.1" \
164166
"3,10.0.1.3,signal backup")" "dump addrs after del"
165167

166168
add_endpoint 10.0.1.3 2>/dev/null
167-
check "get_endpoint 4" "" "duplicate addr"
169+
check "get_endpoint 4" "" "duplicate addr" 1
168170

169171
add_endpoint 10.0.1.4 flags signal
170172
check "get_endpoint 4" "$(format_endpoints "4,10.0.1.4,signal")" "id addr increment"
@@ -173,7 +175,7 @@ for i in $(seq 5 9); do
173175
add_endpoint "10.0.1.${i}" flags signal >/dev/null 2>&1
174176
done
175177
check "get_endpoint 9" "$(format_endpoints "9,10.0.1.9,signal")" "hard addr limit"
176-
check "get_endpoint 10" "" "above hard addr limit"
178+
check "get_endpoint 10" "" "above hard addr limit" 1
177179

178180
del_endpoint 9
179181
for i in $(seq 10 255); do

0 commit comments

Comments
 (0)