Skip to content

Commit e04a30f

Browse files
menglongdongdavem330
authored andcommitted
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: Paolo Abeni <[email protected]> Signed-off-by: Menglong Dong <[email protected]> Signed-off-by: Mat Martineau <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 4a753ca commit e04a30f

File tree

1 file changed

+51
-5
lines changed
  • tools/testing/selftests/net/mptcp

1 file changed

+51
-5
lines changed

tools/testing/selftests/net/mptcp/diag.sh

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ flush_pids()
1717
sleep 1.1
1818

1919
ip netns pids "${ns}" | xargs --no-run-if-empty kill -SIGUSR1 &>/dev/null
20+
21+
for _ in $(seq 10); do
22+
[ -z "$(ip netns pids "${ns}")" ] && break
23+
sleep 0.1
24+
done
2025
}
2126

2227
cleanup()
@@ -37,15 +42,20 @@ if [ $? -ne 0 ];then
3742
exit $ksft_skip
3843
fi
3944

45+
get_msk_inuse()
46+
{
47+
ip netns exec $ns cat /proc/net/protocols | awk '$1~/^MPTCP$/{print $3}'
48+
}
49+
4050
__chk_nr()
4151
{
42-
local condition="$1"
52+
local command="$1"
4353
local expected=$2
4454
local msg nr
4555

4656
shift 2
4757
msg=$*
48-
nr=$(ss -inmHMN $ns | $condition)
58+
nr=$(eval $command)
4959

5060
printf "%-50s" "$msg"
5161
if [ $nr != $expected ]; then
@@ -57,9 +67,17 @@ __chk_nr()
5767
test_cnt=$((test_cnt+1))
5868
}
5969

70+
__chk_msk_nr()
71+
{
72+
local condition=$1
73+
shift 1
74+
75+
__chk_nr "ss -inmHMN $ns | $condition" $*
76+
}
77+
6078
chk_msk_nr()
6179
{
62-
__chk_nr "grep -c token:" $*
80+
__chk_msk_nr "grep -c token:" $*
6381
}
6482

6583
wait_msk_nr()
@@ -97,12 +115,12 @@ wait_msk_nr()
97115

98116
chk_msk_fallback_nr()
99117
{
100-
__chk_nr "grep -c fallback" $*
118+
__chk_msk_nr "grep -c fallback" $*
101119
}
102120

103121
chk_msk_remote_key_nr()
104122
{
105-
__chk_nr "grep -c remote_key" $*
123+
__chk_msk_nr "grep -c remote_key" $*
106124
}
107125

108126
__chk_listen()
@@ -142,6 +160,26 @@ chk_msk_listen()
142160
nr=$(ss -Ml $filter | wc -l)
143161
}
144162

163+
chk_msk_inuse()
164+
{
165+
local expected=$1
166+
local listen_nr
167+
168+
shift 1
169+
170+
listen_nr=$(ss -N "${ns}" -Ml | grep -c LISTEN)
171+
expected=$((expected + listen_nr))
172+
173+
for _ in $(seq 10); do
174+
if [ $(get_msk_inuse) -eq $expected ];then
175+
break
176+
fi
177+
sleep 0.1
178+
done
179+
180+
__chk_nr get_msk_inuse $expected $*
181+
}
182+
145183
# $1: ns, $2: port
146184
wait_local_port_listen()
147185
{
@@ -195,8 +233,10 @@ wait_connected $ns 10000
195233
chk_msk_nr 2 "after MPC handshake "
196234
chk_msk_remote_key_nr 2 "....chk remote_key"
197235
chk_msk_fallback_nr 0 "....chk no fallback"
236+
chk_msk_inuse 2 "....chk 2 msk in use"
198237
flush_pids
199238

239+
chk_msk_inuse 0 "....chk 0 msk in use after flush"
200240

201241
echo "a" | \
202242
timeout ${timeout_test} \
@@ -211,8 +251,11 @@ echo "b" | \
211251
127.0.0.1 >/dev/null &
212252
wait_connected $ns 10001
213253
chk_msk_fallback_nr 1 "check fallback"
254+
chk_msk_inuse 1 "....chk 1 msk in use"
214255
flush_pids
215256

257+
chk_msk_inuse 0 "....chk 0 msk in use after flush"
258+
216259
NR_CLIENTS=100
217260
for I in `seq 1 $NR_CLIENTS`; do
218261
echo "a" | \
@@ -232,6 +275,9 @@ for I in `seq 1 $NR_CLIENTS`; do
232275
done
233276

234277
wait_msk_nr $((NR_CLIENTS*2)) "many msk socket present"
278+
chk_msk_inuse $((NR_CLIENTS*2)) "....chk many msk in use"
235279
flush_pids
236280

281+
chk_msk_inuse 0 "....chk 0 msk in use after flush"
282+
237283
exit $ret

0 commit comments

Comments
 (0)