@@ -301,8 +301,39 @@ mptcp_lib_wait_local_port_listen() {
done
}
+check_output_err=$(mktemp)
+
+mptcp_lib_check_output() {
+ : "${check_output_err:?}"
+ : "${ret:?}"
+
+ local cmd="$1"
+ local expected="$2"
+ local msg="$3"
+ local out=`$cmd 2>$check_output_err`
+ local cmd_ret=$?
+
+ printf "%-42s" "$msg"
+ if [ $cmd_ret -ne 0 ]; then
+ mptcp_lib_print_err "[ FAIL ] command execution '$cmd' stderr "
+ cat $check_output_err
+ ret=${KSFT_FAIL}
+ return $cmd_ret
+ elif [ "$out" = "$expected" ]; then
+ mptcp_lib_print_ok "[ OK ]"
+ return 0
+ else
+ mptcp_lib_print_err "[ FAIL ] expected '$expected' got '$out'"
+ ret=${KSFT_FAIL}
+ return 1
+ fi
+}
+
mptcp_lib_cleanup() {
+ : "${check_output_err:?}"
+
echo "cleanup"
+ rm -f $check_output_err
}
echo -e "\n${KSFT_TEST}\n"
@@ -26,11 +26,9 @@ done
sec=$(date +%s)
rndh=$(printf %x $sec)-$(mktemp -u XXXXXX)
ns1="ns1-$rndh"
-err=$(mktemp)
cleanup()
{
- rm -f $err
ip netns del $ns1
mptcp_lib_cleanup
}
@@ -51,26 +49,15 @@ ip netns exec $ns1 sysctl -q net.mptcp.enabled=1
check()
{
- local cmd="$1"
- local expected="$2"
- local msg="$3"
- local out=`$cmd 2>$err`
- local cmd_ret=$?
-
- 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}"
- ret=1
- elif [ "$out" = "$expected" ]; then
- echo "[ OK ]"
- mptcp_lib_result_pass "${msg}"
+ # ${*} doesn't work here since there're spaces in some arguments.
+ mptcp_lib_check_output "${1}" "${2}" "${3}"
+ local rc=$?
+ if [ ${rc} -eq 0 ]; then
+ mptcp_lib_result_pass "${3}"
+ elif [ ${rc} -eq 1 ]; then
+ mptcp_lib_result_fail "${3} # different output"
else
- echo -n "[FAIL] "
- echo "expected '$expected' got '$out'"
- mptcp_lib_result_fail "${msg} # different output"
- ret=1
+ mptcp_lib_result_fail "${3} # error ${rc}"
fi
}
Extract the main part of check() in pm_netlink.sh to a new function mptcp_lib_check_output() in mptcp_lib.sh. And use mptcp_lib_print_ok() and _err() in it to print test results with colors. This helper will be used in mptcp_john.sh later. Signed-off-by: Geliang Tang <geliang.tang@suse.com> --- .../testing/selftests/net/mptcp/mptcp_lib.sh | 31 +++++++++++++++++++ .../testing/selftests/net/mptcp/pm_netlink.sh | 29 +++++------------ 2 files changed, 39 insertions(+), 21 deletions(-)