Commit 3fb8c33e authored by Geliang Tang's avatar Geliang Tang Committed by Jakub Kicinski

selftests: mptcp: add mptcp_lib_check_tools helper

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", "iptables" and "ip6tables" are passed into this helper
to indicate whether to check ip tool, ss tool, iptables and ip6tables
tools.

This helper can be used in every scripts.
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/20240306-upstream-net-next-20240304-selftests-mptcp-shared-code-shellcheck-v2-2-bc79e6e5e6a0@kernel.orgSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 7c2eac64
...@@ -34,17 +34,7 @@ cleanup() ...@@ -34,17 +34,7 @@ cleanup()
} }
mptcp_lib_check_mptcp mptcp_lib_check_mptcp
mptcp_lib_check_tools ip ss
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
get_msk_inuse() get_msk_inuse()
{ {
......
...@@ -147,12 +147,7 @@ cleanup() ...@@ -147,12 +147,7 @@ cleanup()
mptcp_lib_check_mptcp mptcp_lib_check_mptcp
mptcp_lib_check_kallsyms mptcp_lib_check_kallsyms
mptcp_lib_check_tools ip
ip -Version > /dev/null 2>&1
if [ $? -ne 0 ];then
echo "SKIP: Could not run test without ip tool"
exit $ksft_skip
fi
sin=$(mktemp) sin=$(mktemp)
sout=$(mktemp) sout=$(mktemp)
......
...@@ -152,34 +152,12 @@ cleanup_partial() ...@@ -152,34 +152,12 @@ cleanup_partial()
done 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() {
init=1 init=1
check_tools mptcp_lib_check_mptcp
mptcp_lib_check_kallsyms
mptcp_lib_check_tools ip ss "${iptables}" "${ip6tables}"
sin=$(mktemp) sin=$(mktemp)
sout=$(mktemp) sout=$(mktemp)
......
...@@ -342,3 +342,34 @@ mptcp_lib_check_output() { ...@@ -342,3 +342,34 @@ mptcp_lib_check_output() {
return 1 return 1
fi fi
} }
mptcp_lib_check_tools() {
local tool
for tool in "${@}"; do
case "${tool}" in
"ip")
if ! ip -Version &> /dev/null; then
mptcp_lib_print_warn "SKIP: Could not run test without ip tool"
exit ${KSFT_SKIP}
fi
;;
"ss")
if ! ss -h | grep -q MPTCP; then
mptcp_lib_print_warn "SKIP: ss tool does not support MPTCP"
exit ${KSFT_SKIP}
fi
;;
"iptables"* | "ip6tables"*)
if ! "${tool}" -V &> /dev/null; then
mptcp_lib_print_warn "SKIP: Could not run all tests without ${tool}"
exit ${KSFT_SKIP}
fi
;;
*)
mptcp_lib_print_err "Internal error: unsupported tool: ${tool}"
exit ${KSFT_FAIL}
;;
esac
done
}
...@@ -89,20 +89,7 @@ cleanup() ...@@ -89,20 +89,7 @@ cleanup()
mptcp_lib_check_mptcp mptcp_lib_check_mptcp
mptcp_lib_check_kallsyms mptcp_lib_check_kallsyms
mptcp_lib_check_tools ip "${iptables}" "${ip6tables}"
ip -Version > /dev/null 2>&1
if [ $? -ne 0 ];then
echo "SKIP: Could not run test without ip tool"
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
check_mark() check_mark()
{ {
......
...@@ -36,12 +36,7 @@ cleanup() ...@@ -36,12 +36,7 @@ cleanup()
} }
mptcp_lib_check_mptcp mptcp_lib_check_mptcp
mptcp_lib_check_tools ip
ip -Version > /dev/null 2>&1
if [ $? -ne 0 ];then
echo "SKIP: Could not run test without ip tool"
exit $ksft_skip
fi
trap cleanup EXIT trap cleanup EXIT
......
...@@ -43,12 +43,7 @@ cleanup() ...@@ -43,12 +43,7 @@ cleanup()
} }
mptcp_lib_check_mptcp mptcp_lib_check_mptcp
mptcp_lib_check_tools ip
ip -Version > /dev/null 2>&1
if [ $? -ne 0 ];then
echo "SKIP: Could not run test without ip tool"
exit $ksft_skip
fi
# "$ns1" ns2 ns3 # "$ns1" ns2 ns3
# ns1eth1 ns2eth1 ns2eth3 ns3eth1 # ns1eth1 ns2eth1 ns2eth3 ns3eth1
......
...@@ -17,11 +17,7 @@ if ! mptcp_lib_has_file '/proc/sys/net/mptcp/pm_type'; then ...@@ -17,11 +17,7 @@ if ! mptcp_lib_has_file '/proc/sys/net/mptcp/pm_type'; then
echo "userspace pm tests are not supported by the kernel: SKIP" echo "userspace pm tests are not supported by the kernel: SKIP"
exit ${KSFT_SKIP} exit ${KSFT_SKIP}
fi fi
mptcp_lib_check_tools ip
if ! ip -Version &> /dev/null; then
echo "SKIP: Cannot not run test without ip tool"
exit ${KSFT_SKIP}
fi
ANNOUNCED=6 # MPTCP_EVENT_ANNOUNCED ANNOUNCED=6 # MPTCP_EVENT_ANNOUNCED
REMOVED=7 # MPTCP_EVENT_REMOVED REMOVED=7 # MPTCP_EVENT_REMOVED
......
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