Skip to content

Commit

Permalink
selftests: mptcp: add mptcp_lib_check_tools helper
Browse files Browse the repository at this point in the history
This patch exports check_tools() helper from mptcp_join.sh into
mptcp_lib.sh as a public one mptcp_lib_check_tools(). The arguments
"ip", "ss", and "iptables" are passed into this helper to indicate
whether to check ip tool, ss tool and iptables tools.

This helper can be used in every scripts.

Signed-off-by: Geliang Tang <[email protected]>
  • Loading branch information
Geliang Tang authored and intel-lab-lkp committed Feb 16, 2024
1 parent b78af15 commit 6f08214
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 92 deletions.
13 changes: 1 addition & 12 deletions tools/testing/selftests/net/mptcp/diag.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,7 @@ cleanup()
ip netns del $ns
}

mptcp_lib_check_mptcp

ip -Version > /dev/null 2>&1
if [ $? -ne 0 ];then
echo "SKIP: Could not run test without ip tool"
exit $ksft_skip
fi
ss -h | grep -q MPTCP
if [ $? -ne 0 ];then
echo "SKIP: ss tool does not support MPTCP"
exit $ksft_skip
fi
mptcp_lib_check_tools "ip" "ss"

get_msk_inuse()
{
Expand Down
14 changes: 1 addition & 13 deletions tools/testing/selftests/net/mptcp/mptcp_connect.sh
Original file line number Diff line number Diff line change
Expand Up @@ -145,19 +145,7 @@ cleanup()
done
}

mptcp_lib_check_mptcp
mptcp_lib_check_kallsyms

ip -Version > /dev/null 2>&1
if [ $? -ne 0 ];then
echo "SKIP: Could not run test without ip tool"
exit $ksft_skip
fi

if ! ss -h | grep -q MPTCP; then
echo "SKIP: ss tool does not support MPTCP"
exit $ksft_skip
fi
mptcp_lib_check_tools "ip" "ss"

sin=$(mktemp)
sout=$(mktemp)
Expand Down
26 changes: 1 addition & 25 deletions tools/testing/selftests/net/mptcp/mptcp_join.sh
Original file line number Diff line number Diff line change
Expand Up @@ -149,34 +149,10 @@ cleanup_partial()
done
}

check_tools()
{
mptcp_lib_check_mptcp
mptcp_lib_check_kallsyms

if ! ip -Version &> /dev/null; then
echo "SKIP: Could not run test without ip tool"
exit $ksft_skip
fi

if ! ss -h | grep -q MPTCP; then
echo "SKIP: ss tool does not support MPTCP"
exit $ksft_skip
fi

if ! iptables -V &> /dev/null; then
echo "SKIP: Could not run all tests without iptables tool"
exit $ksft_skip
elif ! ip6tables -V &> /dev/null; then
echo "SKIP: Could not run all tests without ip6tables tool"
exit $ksft_skip
fi
}

init() {
init=1

check_tools
mptcp_lib_check_tools "ip" "ss" "iptables"

sin=$(mktemp)
sout=$(mktemp)
Expand Down
29 changes: 29 additions & 0 deletions tools/testing/selftests/net/mptcp/mptcp_lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -319,3 +319,32 @@ mptcp_lib_wait_local_port_listen() {
sleep 0.1
done
}

mptcp_lib_check_tools() {
mptcp_lib_check_mptcp
mptcp_lib_check_kallsyms

if [ "${1:-""}" == "ip" ]; then
if ! ip -Version &> /dev/null; then
mptcp_lib_print_warn "SKIP: Could not run test without ip tool"
exit ${KSFT_SKIP}
fi
fi

if [ "${2:-""}" == "ss" ]; then
if ! ss -h | grep -q MPTCP; then
mptcp_lib_print_warn "SKIP: ss tool does not support MPTCP"
exit ${KSFT_SKIP}
fi
fi

if [ "${3:-""}" == "iptables" ]; then
if ! iptables -V &> /dev/null; then
mptcp_lib_print_warn "SKIP: Could not run all tests without iptables tool"
exit ${KSFT_SKIP}
elif ! ip6tables -V &> /dev/null; then
mptcp_lib_print_warn "SKIP: Could not run all tests without ip6tables tool"
exit ${KSFT_SKIP}
fi
fi
}
22 changes: 1 addition & 21 deletions tools/testing/selftests/net/mptcp/mptcp_sockopt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -85,27 +85,7 @@ cleanup()
rm -f "$sin" "$sout"
}

mptcp_lib_check_mptcp
mptcp_lib_check_kallsyms

ip -Version > /dev/null 2>&1
if [ $? -ne 0 ];then
echo "SKIP: Could not run test without ip tool"
exit $ksft_skip
fi

if ! ss -h | grep -q MPTCP; then
echo "SKIP: ss tool does not support MPTCP"
exit $ksft_skip
fi

if ! iptables -V &> /dev/null; then
echo "SKIP: Could not run all tests without iptables tool"
exit $ksft_skip
elif ! ip6tables -V &> /dev/null; then
echo "SKIP: Could not run all tests without ip6tables tool"
exit $ksft_skip
fi
mptcp_lib_check_tools "ip" "ss" "iptables"

check_mark()
{
Expand Down
8 changes: 1 addition & 7 deletions tools/testing/selftests/net/mptcp/pm_netlink.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,7 @@ cleanup()
ip netns del $ns1
}

mptcp_lib_check_mptcp

ip -Version > /dev/null 2>&1
if [ $? -ne 0 ];then
echo "SKIP: Could not run test without ip tool"
exit $ksft_skip
fi
mptcp_lib_check_tools "ip"

trap cleanup EXIT

Expand Down
8 changes: 1 addition & 7 deletions tools/testing/selftests/net/mptcp/simult_flows.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,7 @@ cleanup()
done
}

mptcp_lib_check_mptcp

ip -Version > /dev/null 2>&1
if [ $? -ne 0 ];then
echo "SKIP: Could not run test without ip tool"
exit $ksft_skip
fi
mptcp_lib_check_tools "ip"

# "$ns1" ns2 ns3
# ns1eth1 ns2eth1 ns2eth3 ns3eth1
Expand Down
8 changes: 1 addition & 7 deletions tools/testing/selftests/net/mptcp/userspace_pm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,13 @@

. "$(dirname "${0}")/mptcp_lib.sh"

mptcp_lib_check_mptcp
mptcp_lib_check_kallsyms
mptcp_lib_check_tools "ip"

if ! mptcp_lib_has_file '/proc/sys/net/mptcp/pm_type'; then
echo "userspace pm tests are not supported by the kernel: SKIP"
exit ${KSFT_SKIP}
fi

if ! ip -Version &> /dev/null; then
echo "SKIP: Cannot not run test without ip tool"
exit ${KSFT_SKIP}
fi

ANNOUNCED=6 # MPTCP_EVENT_ANNOUNCED
REMOVED=7 # MPTCP_EVENT_REMOVED
SUB_ESTABLISHED=10 # MPTCP_EVENT_SUB_ESTABLISHED
Expand Down

0 comments on commit 6f08214

Please sign in to comment.