Skip to content

Commit

Permalink
selftests: mptcp: add mptcp_lib_check_output helper
Browse files Browse the repository at this point in the history
Extract the main part of check() in pm_netlink.sh into a new helper
named mptcp_lib_check_output in mptcp_lib.sh.

This helper will be used for userspace dump addresses tests.

Signed-off-by: Geliang Tang <[email protected]>
  • Loading branch information
Geliang Tang authored and intel-lab-lkp committed Feb 20, 2024
1 parent c86f4b2 commit 6f36557
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
19 changes: 19 additions & 0 deletions tools/testing/selftests/net/mptcp/mptcp_lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -350,3 +350,22 @@ mptcp_lib_check_tools() {
esac
done
}

mptcp_lib_check_output() {
local err="$1"
local cmd="$2"
local expected="$3"
local cmd_ret=0
local out=$(${cmd} 2>${err}) || cmd_ret=${?}

if [ $cmd_ret -ne 0 ]; then
mptcp_lib_print_err "[FAIL] command execution '$cmd' stderr"
cat "${err}"
return 2
elif [ "$out" = "$expected" ]; then
return 0
else
mptcp_lib_print_err "[FAIL] expected '$expected' got '$out'"
return 1
fi
}
18 changes: 7 additions & 11 deletions tools/testing/selftests/net/mptcp/pm_netlink.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,17 @@ check()
local cmd="$1"
local expected="$2"
local msg="$3"
local out=`$cmd 2>$err`
local cmd_ret=$?
local rc=0

printf "%-50s" "$msg"
if [ $cmd_ret -ne 0 ]; then
echo "[FAIL] command execution '$cmd' stderr "
cat $err
mptcp_lib_result_fail "${msg} # error ${cmd_ret}"
mptcp_lib_check_output "${err}" "${cmd}" "${expected}" || rc=${?}
if [ ${rc} -eq 2 ]; then
mptcp_lib_result_fail "${msg} # error ${rc}"
ret=1
elif [ "$out" = "$expected" ]; then
echo "[ OK ]"
elif [ ${rc} -eq 0 ]; then
mptcp_lib_print_ok "[ OK ]"
mptcp_lib_result_pass "${msg}"
else
echo -n "[FAIL] "
echo "expected '$expected' got '$out'"
elif [ ${rc} -eq 1 ]; then
mptcp_lib_result_fail "${msg} # different output"
ret=1
fi
Expand Down

0 comments on commit 6f36557

Please sign in to comment.