Commit 663260e1 authored by Geliang Tang's avatar Geliang Tang Committed by Jakub Kicinski

selftests: mptcp: extract mptcp_lib_check_expected

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. check_expected_one() is
moved into mptcp_lib.sh too as mptcp_lib_check_expected_one().
Signed-off-by: default avatarGeliang Tang <tanggeliang@kylinos.cn>
Reviewed-by: default avatarMatthieu Baerts (NGI0) <matttbe@kernel.org>
Signed-off-by: default avatarMatthieu Baerts (NGI0) <matttbe@kernel.org>
Link: https://lore.kernel.org/r/20240308-upstream-net-next-20240308-selftests-mptcp-unification-v1-11-4f42c347b653@kernel.orgSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 339c225e
......@@ -438,3 +438,33 @@ mptcp_lib_print_title() {
# shellcheck disable=SC2059 # the format is in a variable
printf "${MPTCP_LIB_TEST_FORMAT}" "$((++MPTCP_LIB_TEST_COUNTER))" "${*}"
}
# $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
mptcp_lib_pr_fail
fi
mptcp_lib_print_err "Expected value for '${var}': '${!exp}', got '${!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
return "${rc}"
}
......@@ -5,7 +5,7 @@
# code but we accept it.
#shellcheck disable=SC2086
# Some variables are used below but indirectly, see check_expected_one()
# Some variables are used below but indirectly, see verify_*_event()
#shellcheck disable=SC2034
. "$(dirname "${0}")/mptcp_lib.sh"
......@@ -228,39 +228,10 @@ 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
mptcp_lib_pr_fail
fi
mptcp_lib_print_err "\tExpected value for '${var}': '${!exp}', got '${!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 ]
if mptcp_lib_check_expected "${@}"
then
test_pass
return 0
......
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