Commit e04a30f7 authored by Menglong Dong's avatar Menglong Dong Committed by David S. Miller

selftest: mptcp: add test for mptcp socket in use

Add the function chk_msk_inuse() to diag.sh, which is used to check the
statistics of mptcp socket in use. As mptcp socket in listen state will
be closed randomly after 'accept', we need to get the count of listening
mptcp socket through 'ss' command.

All tests pass.
Acked-by: default avatarPaolo Abeni <pabeni@redhat.com>
Signed-off-by: default avatarMenglong Dong <imagedong@tencent.com>
Signed-off-by: default avatarMat Martineau <mathew.j.martineau@linux.intel.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 4a753ca5
...@@ -17,6 +17,11 @@ flush_pids() ...@@ -17,6 +17,11 @@ flush_pids()
sleep 1.1 sleep 1.1
ip netns pids "${ns}" | xargs --no-run-if-empty kill -SIGUSR1 &>/dev/null ip netns pids "${ns}" | xargs --no-run-if-empty kill -SIGUSR1 &>/dev/null
for _ in $(seq 10); do
[ -z "$(ip netns pids "${ns}")" ] && break
sleep 0.1
done
} }
cleanup() cleanup()
...@@ -37,15 +42,20 @@ if [ $? -ne 0 ];then ...@@ -37,15 +42,20 @@ if [ $? -ne 0 ];then
exit $ksft_skip exit $ksft_skip
fi fi
get_msk_inuse()
{
ip netns exec $ns cat /proc/net/protocols | awk '$1~/^MPTCP$/{print $3}'
}
__chk_nr() __chk_nr()
{ {
local condition="$1" local command="$1"
local expected=$2 local expected=$2
local msg nr local msg nr
shift 2 shift 2
msg=$* msg=$*
nr=$(ss -inmHMN $ns | $condition) nr=$(eval $command)
printf "%-50s" "$msg" printf "%-50s" "$msg"
if [ $nr != $expected ]; then if [ $nr != $expected ]; then
...@@ -57,9 +67,17 @@ __chk_nr() ...@@ -57,9 +67,17 @@ __chk_nr()
test_cnt=$((test_cnt+1)) test_cnt=$((test_cnt+1))
} }
__chk_msk_nr()
{
local condition=$1
shift 1
__chk_nr "ss -inmHMN $ns | $condition" $*
}
chk_msk_nr() chk_msk_nr()
{ {
__chk_nr "grep -c token:" $* __chk_msk_nr "grep -c token:" $*
} }
wait_msk_nr() wait_msk_nr()
...@@ -97,12 +115,12 @@ wait_msk_nr() ...@@ -97,12 +115,12 @@ wait_msk_nr()
chk_msk_fallback_nr() chk_msk_fallback_nr()
{ {
__chk_nr "grep -c fallback" $* __chk_msk_nr "grep -c fallback" $*
} }
chk_msk_remote_key_nr() chk_msk_remote_key_nr()
{ {
__chk_nr "grep -c remote_key" $* __chk_msk_nr "grep -c remote_key" $*
} }
__chk_listen() __chk_listen()
...@@ -142,6 +160,26 @@ chk_msk_listen() ...@@ -142,6 +160,26 @@ chk_msk_listen()
nr=$(ss -Ml $filter | wc -l) nr=$(ss -Ml $filter | wc -l)
} }
chk_msk_inuse()
{
local expected=$1
local listen_nr
shift 1
listen_nr=$(ss -N "${ns}" -Ml | grep -c LISTEN)
expected=$((expected + listen_nr))
for _ in $(seq 10); do
if [ $(get_msk_inuse) -eq $expected ];then
break
fi
sleep 0.1
done
__chk_nr get_msk_inuse $expected $*
}
# $1: ns, $2: port # $1: ns, $2: port
wait_local_port_listen() wait_local_port_listen()
{ {
...@@ -195,8 +233,10 @@ wait_connected $ns 10000 ...@@ -195,8 +233,10 @@ wait_connected $ns 10000
chk_msk_nr 2 "after MPC handshake " chk_msk_nr 2 "after MPC handshake "
chk_msk_remote_key_nr 2 "....chk remote_key" chk_msk_remote_key_nr 2 "....chk remote_key"
chk_msk_fallback_nr 0 "....chk no fallback" chk_msk_fallback_nr 0 "....chk no fallback"
chk_msk_inuse 2 "....chk 2 msk in use"
flush_pids flush_pids
chk_msk_inuse 0 "....chk 0 msk in use after flush"
echo "a" | \ echo "a" | \
timeout ${timeout_test} \ timeout ${timeout_test} \
...@@ -211,8 +251,11 @@ echo "b" | \ ...@@ -211,8 +251,11 @@ echo "b" | \
127.0.0.1 >/dev/null & 127.0.0.1 >/dev/null &
wait_connected $ns 10001 wait_connected $ns 10001
chk_msk_fallback_nr 1 "check fallback" chk_msk_fallback_nr 1 "check fallback"
chk_msk_inuse 1 "....chk 1 msk in use"
flush_pids flush_pids
chk_msk_inuse 0 "....chk 0 msk in use after flush"
NR_CLIENTS=100 NR_CLIENTS=100
for I in `seq 1 $NR_CLIENTS`; do for I in `seq 1 $NR_CLIENTS`; do
echo "a" | \ echo "a" | \
...@@ -232,6 +275,9 @@ for I in `seq 1 $NR_CLIENTS`; do ...@@ -232,6 +275,9 @@ for I in `seq 1 $NR_CLIENTS`; do
done done
wait_msk_nr $((NR_CLIENTS*2)) "many msk socket present" wait_msk_nr $((NR_CLIENTS*2)) "many msk socket present"
chk_msk_inuse $((NR_CLIENTS*2)) "....chk many msk in use"
flush_pids flush_pids
chk_msk_inuse 0 "....chk 0 msk in use after flush"
exit $ret exit $ret
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