Skip to content

Commit

Permalink
selftests: mptcp: add mptcp_lib_wait_local_port_listen
Browse files Browse the repository at this point in the history
To avoid duplicated code in different MPTCP selftests, we can add
and use helpers defined in mptcp_lib.sh.

wait_local_port_listen() helper is defined in diag.sh, mptcp_connect.sh,
mptcp_join.sh and simult_flows.sh, export it into mptcp_lib.sh and
rename it with mptcp_lib_ prefix. Use this new helper in all these
scripts.

Note: We only have IPv4 connections in this helper, not looking at IPv6
(tcp6) but that's OK because we only have IPv4 connections here in diag.sh.

Reviewed-by: Matthieu Baerts <matttbe@kernel.org>
Signed-off-by: Geliang Tang <geliang.tang@suse.com>
  • Loading branch information
geliangtang authored and intel-lab-lkp committed Oct 17, 2023
1 parent 04dd382 commit c6c98bc
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 75 deletions.
23 changes: 3 additions & 20 deletions tools/testing/selftests/net/mptcp/diag.sh
Original file line number Diff line number Diff line change
Expand Up @@ -182,23 +182,6 @@ chk_msk_inuse()
__chk_nr get_msk_inuse $expected "$msg" 0
}

# $1: ns, $2: port
wait_local_port_listen()
{
local listener_ns="${1}"
local port="${2}"

local port_hex i

port_hex="$(printf "%04X" "${port}")"
for i in $(seq 10); do
ip netns exec "${listener_ns}" cat /proc/net/tcp | \
awk "BEGIN {rc=1} {if (\$2 ~ /:${port_hex}\$/ && \$4 ~ /0A/) {rc=0; exit}} END {exit rc}" &&
break
sleep 0.1
done
}

wait_connected()
{
local listener_ns="${1}"
Expand All @@ -222,7 +205,7 @@ echo "a" | \
ip netns exec $ns \
./mptcp_connect -p 10000 -l -t ${timeout_poll} -w 20 \
0.0.0.0 >/dev/null &
wait_local_port_listen $ns 10000
mptcp_lib_wait_local_port_listen $ns 10000
chk_msk_nr 0 "no msk on netns creation"
chk_msk_listen 10000

Expand All @@ -245,7 +228,7 @@ echo "a" | \
ip netns exec $ns \
./mptcp_connect -p 10001 -l -s TCP -t ${timeout_poll} -w 20 \
0.0.0.0 >/dev/null &
wait_local_port_listen $ns 10001
mptcp_lib_wait_local_port_listen $ns 10001
echo "b" | \
timeout ${timeout_test} \
ip netns exec $ns \
Expand All @@ -266,7 +249,7 @@ for I in `seq 1 $NR_CLIENTS`; do
./mptcp_connect -p $((I+10001)) -l -w 20 \
-t ${timeout_poll} 0.0.0.0 >/dev/null &
done
wait_local_port_listen $ns $((NR_CLIENTS + 10001))
mptcp_lib_wait_local_port_listen $ns $((NR_CLIENTS + 10001))

for I in `seq 1 $NR_CLIENTS`; do
echo "b" | \
Expand Down
19 changes: 1 addition & 18 deletions tools/testing/selftests/net/mptcp/mptcp_connect.sh
Original file line number Diff line number Diff line change
Expand Up @@ -310,23 +310,6 @@ do_ping()
return 0
}

# $1: ns, $2: port
wait_local_port_listen()
{
local listener_ns="${1}"
local port="${2}"

local port_hex i

port_hex="$(printf "%04X" "${port}")"
for i in $(seq 10); do
ip netns exec "${listener_ns}" cat /proc/net/tcp* | \
awk "BEGIN {rc=1} {if (\$2 ~ /:${port_hex}\$/ && \$4 ~ /0A/) {rc=0; exit}} END {exit rc}" &&
break
sleep 0.1
done
}

do_transfer()
{
local listener_ns="$1"
Expand Down Expand Up @@ -408,7 +391,7 @@ do_transfer()
$extra_args $local_addr < "$sin" > "$sout" &
local spid=$!

wait_local_port_listen "${listener_ns}" "${port}"
mptcp_lib_wait_local_port_listen "${listener_ns}" "${port}"

local start
start=$(date +%s%3N)
Expand Down
20 changes: 1 addition & 19 deletions tools/testing/selftests/net/mptcp/mptcp_join.sh
Original file line number Diff line number Diff line change
Expand Up @@ -580,24 +580,6 @@ link_failure()
done
}

# $1: ns, $2: port
wait_local_port_listen()
{
local listener_ns="${1}"
local port="${2}"

local port_hex
port_hex="$(printf "%04X" "${port}")"

local i
for i in $(seq 10); do
ip netns exec "${listener_ns}" cat /proc/net/tcp* | \
awk "BEGIN {rc=1} {if (\$2 ~ /:${port_hex}\$/ && \$4 ~ /0A/) {rc=0; exit}} END {exit rc}" &&
break
sleep 0.1
done
}

rm_addr_count()
{
mptcp_lib_get_counter "${1}" "MPTcpExtRmAddr"
Expand Down Expand Up @@ -1082,7 +1064,7 @@ do_transfer()
fi
local spid=$!

wait_local_port_listen "${listener_ns}" "${port}"
mptcp_lib_wait_local_port_listen "${listener_ns}" "${port}"

extra_cl_args="$extra_args $extra_cl_args"
if [ "$test_linkfail" -eq 0 ];then
Expand Down
18 changes: 18 additions & 0 deletions tools/testing/selftests/net/mptcp/mptcp_lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -281,3 +281,21 @@ mptcp_lib_check_transfer() {

return 0
}

# $1: ns, $2: port
mptcp_lib_wait_local_port_listen() {
local listener_ns="${1}"
local port="${2}"

local port_hex
port_hex="$(printf "%04X" "${port}")"

local i
for i in $(seq 10); do
ip netns exec "${listener_ns}" cat /proc/net/tcp* | \
awk "BEGIN {rc=1} {if (\$2 ~ /:${port_hex}\$/ && \$4 ~ /0A/) \
{rc=0; exit}} END {exit rc}" &&
break
sleep 0.1
done
}
19 changes: 1 addition & 18 deletions tools/testing/selftests/net/mptcp/simult_flows.sh
Original file line number Diff line number Diff line change
Expand Up @@ -123,23 +123,6 @@ setup()
grep -q ' kmemleak_init$\| lockdep_init$\| kasan_init$\| prove_locking$' /proc/kallsyms && slack=$((slack+550))
}

# $1: ns, $2: port
wait_local_port_listen()
{
local listener_ns="${1}"
local port="${2}"

local port_hex i

port_hex="$(printf "%04X" "${port}")"
for i in $(seq 10); do
ip netns exec "${listener_ns}" cat /proc/net/tcp* | \
awk "BEGIN {rc=1} {if (\$2 ~ /:${port_hex}\$/ && \$4 ~ /0A/) {rc=0; exit}} END {exit rc}" &&
break
sleep 0.1
done
}

do_transfer()
{
local cin=$1
Expand Down Expand Up @@ -179,7 +162,7 @@ do_transfer()
0.0.0.0 < "$sin" > "$sout" &
local spid=$!

wait_local_port_listen "${ns3}" "${port}"
mptcp_lib_wait_local_port_listen "${ns3}" "${port}"

timeout ${timeout_test} \
ip netns exec ${ns1} \
Expand Down

0 comments on commit c6c98bc

Please sign in to comment.