@@ -300,7 +300,34 @@ mptcp_lib_wait_local_port_listen() {
done
}
+mptcp_lib_err=$(mktemp)
+
+mptcp_lib_check()
+{
+ local cmd="$1"
+ local expected="$2"
+ local msg="$3"
+ local out=`$cmd 2>$mptcp_lib_err`
+ local cmd_ret=$?
+
+ printf "%-42s" "$msg"
+ if [ $cmd_ret -ne 0 ]; then
+ mptcp_lib_print_err "[ FAIL ] command execution '$cmd' stderr "
+ cat $mptcp_lib_err
+ ret=1
+ 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=1
+ return 1
+ fi
+}
+
mptcp_lib_cleanup()
{
echo "cleanup"
+ rm -f $mptcp_lib_err
}
@@ -27,12 +27,10 @@ done
sec=$(date +%s)
rndh=$(printf %x $sec)-$(mktemp -u XXXXXX)
ns1="ns1-$rndh"
-err=$(mktemp)
ret=0
cleanup()
{
- rm -f $err
ip netns del $ns1
mptcp_lib_cleanup
}
@@ -53,26 +51,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 "${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() 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 | 27 +++++++++++++++++ .../testing/selftests/net/mptcp/pm_netlink.sh | 29 +++++-------------- 2 files changed, 35 insertions(+), 21 deletions(-)