@@ -391,6 +391,48 @@ mptcp_lib_evts_remove() {
rm -rf "${server_evts}" "${client_evts}"
}
+# $1: var name ; $2: prev ret
+mptcp_lib_check_expected_one()
+{
+ local var="${1}"
+ local exp="e_${var}"
+ local prev_ret="${2}"
+
+ if [ "${!var}" = "${!exp}" ]
+ then
+ return 0
+ fi
+
+ if [ "${prev_ret}" = "0" ]
+ then
+ ret=1
+ fi
+
+ printf "\tExpected value for '%s': '%s', got '%s'.\n" \
+ "${var}" "${!exp}" "${!var}"
+ return 1
+}
+
+# $@: all var names to check
+mptcp_lib_check_expected()
+{
+ local rc=0
+ local var
+
+ for var in "${@}"
+ do
+ mptcp_lib_check_expected_one "${var}" "${rc}" || rc=1
+ done
+
+ if [ ${rc} -eq 0 ]
+ then
+ mptcp_lib_print_ok "[ OK ]"
+ return 0
+ fi
+
+ return 1
+}
+
mptcp_lib_cleanup()
{
echo "cleanup"
@@ -237,46 +237,15 @@ make_connection()
fi
}
-# $1: var name ; $2: prev ret
-check_expected_one()
-{
- local var="${1}"
- local exp="e_${var}"
- local prev_ret="${2}"
-
- if [ "${!var}" = "${!exp}" ]
- then
- return 0
- fi
-
- if [ "${prev_ret}" = "0" ]
- then
- test_fail
- fi
-
- _printf "\tExpected value for '%s': '%s', got '%s'.\n" \
- "${var}" "${!exp}" "${!var}"
- return 1
-}
-
# $@: all var names to check
check_expected()
{
- local rc=0
- local var
-
- for var in "${@}"
- do
- check_expected_one "${var}" "${rc}" || rc=1
- done
-
- if [ ${rc} -eq 0 ]
- then
- test_pass
- return 0
+ mptcp_lib_check_expected ${*}
+ if [ $? -eq 0 ]; then
+ mptcp_lib_result_pass "${TEST_NAME}"
+ else
+ test_fail
fi
-
- return 1
}
verify_announce_event()
Extract the main part of check_expected() in userspace_pm.sh to a new function mptcp_lib_check_expected() in mptcp_lib.sh. It will be used in both mptcp_john.sh and userspace_pm.sh. Signed-off-by: Geliang Tang <geliang.tang@suse.com> --- .../testing/selftests/net/mptcp/mptcp_lib.sh | 42 +++++++++++++++++++ .../selftests/net/mptcp/userspace_pm.sh | 41 +++--------------- 2 files changed, 47 insertions(+), 36 deletions(-)