mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2025-08-16 06:53:33 +00:00

The HSR test, hsr_ping.sh, actually needs 7 min to run. Around 375s to be exact, and even more on a debug kernel or kernel with other network security limits. The timeout setting for the kselftest is currently 45 seconds, which is way too short to integrate hsr tests to run_kselftest infrastructure. However, timeout of hundreds of seconds is quite a long time, especially in a CI/CD environment. It seems that we need accelerate the test and balance with timeout setting. The most time-consuming func is do_ping_long, where ping command sends 10 packages to the given address. The default interval between two ping packages is 1s according to the ping Mannual. There isn't any operation between pings thus we could pass -i 0.1 to ping to make it 10 times faster. While even with this short interval, the test still need about 46.4 seconds to finish because of the two HSR interfaces, each of which is tested by calling do_ping func 12 times and do_ping_long func 19 times and sleep for 3s. So, an explicit setting is also needed to slightly increase the timeout. And to leave us some slack, use 50 as default timeout. Signed-off-by: Yunshui Jiang <jiangyunshui@kylinos.cn> Link: https://patch.msgid.link/20241028082757.2945232-1-jiangyunshui@kylinos.cn Signed-off-by: Jakub Kicinski <kuba@kernel.org>
85 lines
1.5 KiB
Bash
85 lines
1.5 KiB
Bash
# SPDX-License-Identifier: GPL-2.0
|
|
# Common code for HSR testing scripts
|
|
|
|
source ../lib.sh
|
|
ret=0
|
|
ksft_skip=4
|
|
|
|
# $1: IP address
|
|
is_v6()
|
|
{
|
|
[ -z "${1##*:*}" ]
|
|
}
|
|
|
|
do_ping()
|
|
{
|
|
local netns="$1"
|
|
local connect_addr="$2"
|
|
local ping_args="-q -c 2 -i 0.1"
|
|
|
|
if is_v6 "${connect_addr}"; then
|
|
$ipv6 || return 0
|
|
ping_args="${ping_args} -6"
|
|
fi
|
|
|
|
ip netns exec ${netns} ping ${ping_args} $connect_addr >/dev/null
|
|
if [ $? -ne 0 ] ; then
|
|
echo "$netns -> $connect_addr connectivity [ FAIL ]" 1>&2
|
|
ret=1
|
|
return 1
|
|
fi
|
|
|
|
return 0
|
|
}
|
|
|
|
do_ping_long()
|
|
{
|
|
local netns="$1"
|
|
local connect_addr="$2"
|
|
local ping_args="-q -c 10 -i 0.1"
|
|
|
|
if is_v6 "${connect_addr}"; then
|
|
$ipv6 || return 0
|
|
ping_args="${ping_args} -6"
|
|
fi
|
|
|
|
OUT="$(LANG=C ip netns exec ${netns} ping ${ping_args} $connect_addr | grep received)"
|
|
if [ $? -ne 0 ] ; then
|
|
echo "$netns -> $connect_addr ping [ FAIL ]" 1>&2
|
|
ret=1
|
|
return 1
|
|
fi
|
|
|
|
VAL="$(echo $OUT | cut -d' ' -f1-8)"
|
|
SED_VAL="$(echo ${VAL} | sed -r -e 's/([0-9]{2}).*([0-9]{2}).*[[:space:]]([0-9]+%).*/\1 transmitted \2 received \3 loss/')"
|
|
if [ "${SED_VAL}" != "10 transmitted 10 received 0% loss" ]
|
|
then
|
|
echo "$netns -> $connect_addr ping TEST [ FAIL ]"
|
|
echo "Expect to send and receive 10 packets and no duplicates."
|
|
echo "Full message: ${OUT}."
|
|
ret=1
|
|
return 1
|
|
fi
|
|
|
|
return 0
|
|
}
|
|
|
|
stop_if_error()
|
|
{
|
|
local msg="$1"
|
|
|
|
if [ ${ret} -ne 0 ]; then
|
|
echo "FAIL: ${msg}" 1>&2
|
|
exit ${ret}
|
|
fi
|
|
}
|
|
|
|
check_prerequisites()
|
|
{
|
|
ip -Version > /dev/null 2>&1
|
|
if [ $? -ne 0 ];then
|
|
echo "SKIP: Could not run test without ip tool"
|
|
exit $ksft_skip
|
|
fi
|
|
}
|