Skip to content

Commit

Permalink
selftests: mptcp: add mptcp_lib_events helper
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.

This patch unifies "pm_nl_ctl events" related code in userspace_pm.sh
and mptcp_join.sh into a helper mptcp_lib_events(). Define it in
mptcp_lib.sh and use it in both scripts.

Signed-off-by: Geliang Tang <[email protected]>
  • Loading branch information
Geliang Tang authored and intel-lab-lkp committed Feb 22, 2024
1 parent 4b3ef40 commit e2b67ae
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
8 changes: 2 additions & 6 deletions tools/testing/selftests/net/mptcp/mptcp_join.sh
Original file line number Diff line number Diff line change
Expand Up @@ -430,12 +430,8 @@ reset_with_events()
{
reset "${1}" || return 1

:> "$evts_ns1"
:> "$evts_ns2"
ip netns exec $ns1 ./pm_nl_ctl events >> "$evts_ns1" 2>&1 &
evts_ns1_pid=$!
ip netns exec $ns2 ./pm_nl_ctl events >> "$evts_ns2" 2>&1 &
evts_ns2_pid=$!
mptcp_lib_events "${ns1}" "${evts_ns1}" evts_ns1_pid
mptcp_lib_events "${ns2}" "${evts_ns2}" evts_ns2_pid
}

reset_with_tcp_filter()
Expand Down
14 changes: 14 additions & 0 deletions tools/testing/selftests/net/mptcp/mptcp_lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -399,3 +399,17 @@ mptcp_lib_ns_exit() {
rm -f /tmp/"$netns".{nstat,out}
done
}

mptcp_lib_events() {
local ns="${1}"
local evts="${2}"
declare -n pid="${3}"

:>"${evts}"

if [ ${pid} -ne 0 ]; then
mptcp_lib_kill_wait "${pid}"
fi
ip netns exec "${ns}" ./pm_nl_ctl events >> "${evts}" 2>&1 &
pid=$!
}
14 changes: 2 additions & 12 deletions tools/testing/selftests/net/mptcp/userspace_pm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -178,21 +178,11 @@ make_connection()
if [ -z "$client_evts" ]; then
client_evts=$(mktemp)
fi
:>"$client_evts"
if [ $client_evts_pid -ne 0 ]; then
mptcp_lib_kill_wait $client_evts_pid
fi
ip netns exec "$ns2" ./pm_nl_ctl events >> "$client_evts" 2>&1 &
client_evts_pid=$!
mptcp_lib_events "${ns2}" "${client_evts}" client_evts_pid
if [ -z "$server_evts" ]; then
server_evts=$(mktemp)
fi
:>"$server_evts"
if [ $server_evts_pid -ne 0 ]; then
mptcp_lib_kill_wait $server_evts_pid
fi
ip netns exec "$ns1" ./pm_nl_ctl events >> "$server_evts" 2>&1 &
server_evts_pid=$!
mptcp_lib_events "${ns1}" "${server_evts}" server_evts_pid
sleep 0.5

# Run the server
Expand Down

0 comments on commit e2b67ae

Please sign in to comment.