summaryrefslogtreecommitdiff
path: root/tools/testing/selftests/net/mptcp/mptcp_lib.sh
diff options
context:
space:
mode:
authorGeliang Tang <geliang.tang@suse.com>2023-11-28 15:18:55 -0800
committerJakub Kicinski <kuba@kernel.org>2023-11-29 20:06:18 -0800
commit61c131f5d4d2b79904af2fdcb2839a9db8e7c55c (patch)
tree75ac557aac715967cf653d45c3b6b1d6322c7485 /tools/testing/selftests/net/mptcp/mptcp_lib.sh
parentb850f2c7dd85ecd14a333685c4ffd23f12665e94 (diff)
downloadlinux-next-61c131f5d4d2b79904af2fdcb2839a9db8e7c55c.tar.gz
linux-next-61c131f5d4d2b79904af2fdcb2839a9db8e7c55c.zip
selftests: mptcp: add mptcp_lib_get_counter
To avoid duplicated code in different MPTCP selftests, we can add and use helpers defined in mptcp_lib.sh. The helper get_counter() in mptcp_join.sh and get_mib_counter() in mptcp_connect.sh have the same functionality, export get_counter() into mptcp_lib.sh and rename it as mptcp_lib_get_counter(). Use this new helper instead of get_counter() and get_mib_counter(). Use this helper in test_prio() in userspace_pm.sh too instead of open-coding. Reviewed-by: Matthieu Baerts <matttbe@kernel.org> Signed-off-by: Geliang Tang <geliang.tang@suse.com> Signed-off-by: Mat Martineau <martineau@kernel.org> Link: https://lore.kernel.org/r/20231128-send-net-next-2023107-v4-11-8d6b94150f6b@kernel.org Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Diffstat (limited to 'tools/testing/selftests/net/mptcp/mptcp_lib.sh')
-rw-r--r--tools/testing/selftests/net/mptcp/mptcp_lib.sh16
1 files changed, 16 insertions, 0 deletions
diff --git a/tools/testing/selftests/net/mptcp/mptcp_lib.sh b/tools/testing/selftests/net/mptcp/mptcp_lib.sh
index 447292cad33c..718c79dda2b3 100644
--- a/tools/testing/selftests/net/mptcp/mptcp_lib.sh
+++ b/tools/testing/selftests/net/mptcp/mptcp_lib.sh
@@ -231,3 +231,19 @@ mptcp_lib_kill_wait() {
mptcp_lib_is_v6() {
[ -z "${1##*:*}" ]
}
+
+# $1: ns, $2: MIB counter
+mptcp_lib_get_counter() {
+ local ns="${1}"
+ local counter="${2}"
+ local count
+
+ count=$(ip netns exec "${ns}" nstat -asz "${counter}" |
+ awk 'NR==1 {next} {print $2}')
+ if [ -z "${count}" ]; then
+ mptcp_lib_fail_if_expected_feature "${counter} counter"
+ return 1
+ fi
+
+ echo "${count}"
+}