Commit 2d0c1d27 authored by Geliang Tang's avatar Geliang Tang Committed by David S. Miller

selftests: mptcp: add mptcp_lib_check_output helper

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.
Co-developed-by: default avatarMatthieu Baerts (NGI0) <matttbe@kernel.org>
Signed-off-by: default avatarMatthieu Baerts (NGI0) <matttbe@kernel.org>
Signed-off-by: default avatarGeliang Tang <tanggeliang@kylinos.cn>
Reviewed-by: default avatarMatthieu Baerts (NGI0) <matttbe@kernel.org>
Reviewed-by: default avatarMat Martineau <martineau@kernel.org>
Signed-off-by: default avatarMatthieu Baerts (NGI0) <matttbe@kernel.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 950c3321
...@@ -319,3 +319,26 @@ mptcp_lib_wait_local_port_listen() { ...@@ -319,3 +319,26 @@ mptcp_lib_wait_local_port_listen() {
sleep 0.1 sleep 0.1
done done
} }
mptcp_lib_check_output() {
local err="${1}"
local cmd="${2}"
local expected="${3}"
local cmd_ret=0
local out
if ! out=$(${cmd} 2>"${err}"); then
cmd_ret=${?}
fi
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
}
...@@ -54,21 +54,17 @@ check() ...@@ -54,21 +54,17 @@ check()
local cmd="$1" local cmd="$1"
local expected="$2" local expected="$2"
local msg="$3" local msg="$3"
local out=`$cmd 2>$err` local rc=0
local cmd_ret=$?
printf "%-50s" "$msg" printf "%-50s" "$msg"
if [ $cmd_ret -ne 0 ]; then mptcp_lib_check_output "${err}" "${cmd}" "${expected}" || rc=${?}
echo "[FAIL] command execution '$cmd' stderr " if [ ${rc} -eq 2 ]; then
cat $err mptcp_lib_result_fail "${msg} # error ${rc}"
mptcp_lib_result_fail "${msg} # error ${cmd_ret}"
ret=1 ret=1
elif [ "$out" = "$expected" ]; then elif [ ${rc} -eq 0 ]; then
echo "[ OK ]" mptcp_lib_print_ok "[ OK ]"
mptcp_lib_result_pass "${msg}" mptcp_lib_result_pass "${msg}"
else elif [ ${rc} -eq 1 ]; then
echo -n "[FAIL] "
echo "expected '$expected' got '$out'"
mptcp_lib_result_fail "${msg} # different output" mptcp_lib_result_fail "${msg} # different output"
ret=1 ret=1
fi fi
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment