Skip to content

Commit 663260e

Browse files
Geliang Tangkuba-moo
authored andcommitted
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: Geliang Tang <[email protected]> Reviewed-by: Matthieu Baerts (NGI0) <[email protected]> Signed-off-by: Matthieu Baerts (NGI0) <[email protected]> Link: https://lore.kernel.org/r/20240308-upstream-net-next-20240308-selftests-mptcp-unification-v1-11-4f42c347b653@kernel.org Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 339c225 commit 663260e

File tree

2 files changed

+32
-31
lines changed

2 files changed

+32
-31
lines changed

tools/testing/selftests/net/mptcp/mptcp_lib.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,3 +438,33 @@ mptcp_lib_print_title() {
438438
# shellcheck disable=SC2059 # the format is in a variable
439439
printf "${MPTCP_LIB_TEST_FORMAT}" "$((++MPTCP_LIB_TEST_COUNTER))" "${*}"
440440
}
441+
442+
# $1: var name ; $2: prev ret
443+
mptcp_lib_check_expected_one() {
444+
local var="${1}"
445+
local exp="e_${var}"
446+
local prev_ret="${2}"
447+
448+
if [ "${!var}" = "${!exp}" ]; then
449+
return 0
450+
fi
451+
452+
if [ "${prev_ret}" = "0" ]; then
453+
mptcp_lib_pr_fail
454+
fi
455+
456+
mptcp_lib_print_err "Expected value for '${var}': '${!exp}', got '${!var}'."
457+
return 1
458+
}
459+
460+
# $@: all var names to check
461+
mptcp_lib_check_expected() {
462+
local rc=0
463+
local var
464+
465+
for var in "${@}"; do
466+
mptcp_lib_check_expected_one "${var}" "${rc}" || rc=1
467+
done
468+
469+
return "${rc}"
470+
}

tools/testing/selftests/net/mptcp/userspace_pm.sh

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# code but we accept it.
66
#shellcheck disable=SC2086
77

8-
# Some variables are used below but indirectly, see check_expected_one()
8+
# Some variables are used below but indirectly, see verify_*_event()
99
#shellcheck disable=SC2034
1010

1111
. "$(dirname "${0}")/mptcp_lib.sh"
@@ -228,39 +228,10 @@ make_connection()
228228
fi
229229
}
230230

231-
# $1: var name ; $2: prev ret
232-
check_expected_one()
233-
{
234-
local var="${1}"
235-
local exp="e_${var}"
236-
local prev_ret="${2}"
237-
238-
if [ "${!var}" = "${!exp}" ]
239-
then
240-
return 0
241-
fi
242-
243-
if [ "${prev_ret}" = "0" ]
244-
then
245-
mptcp_lib_pr_fail
246-
fi
247-
248-
mptcp_lib_print_err "\tExpected value for '${var}': '${!exp}', got '${!var}'."
249-
return 1
250-
}
251-
252231
# $@: all var names to check
253232
check_expected()
254233
{
255-
local rc=0
256-
local var
257-
258-
for var in "${@}"
259-
do
260-
check_expected_one "${var}" "${rc}" || rc=1
261-
done
262-
263-
if [ ${rc} -eq 0 ]
234+
if mptcp_lib_check_expected "${@}"
264235
then
265236
test_pass
266237
return 0

0 commit comments

Comments
 (0)