use helpers in lib.sh and net_helpers.sh
Subsystems (3)
Geliang Tang
reviewercover use helpers in lib.sh and net_helpers.sh
From: Geliang Tang <[email protected]>
This set uses the public helpers defined in net selftests to replace helers in mptcp_lib.sh.
Geliang Tang (4):
selftests: mptcp: rename ns to ns1 in diag.sh
selftests: mptcp: use setup_ns helper in lib.sh
selftests: mptcp: use cleanup_all_ns helper in lib.sh
selftests: mptcp: use wait_local_port_listen helper
tools/testing/selftests/net/mptcp/diag.sh | 58 +++++++++---------- .../selftests/net/mptcp/mptcp_connect.sh | 3 +- .../testing/selftests/net/mptcp/mptcp_join.sh | 2 +- .../testing/selftests/net/mptcp/mptcp_lib.sh | 43 +++----------- .../selftests/net/mptcp/mptcp_sockopt.sh | 2 +- .../testing/selftests/net/mptcp/pm_netlink.sh | 2 +- .../selftests/net/mptcp/simult_flows.sh | 2 +- .../selftests/net/mptcp/userspace_pm.sh | 2 +- 8 files changed, 44 insertions(+), 70 deletions(-)
Signature · 1 line
2.43.0
Geliang Tang
reviewerPATCH 1/4 selftests: mptcp: rename ns to ns1 in diag.sh
From: Geliang Tang <[email protected]>
The next commit will use setup_ns helper in lib.sh instead of mptcp helper mptcp_lib_ns_init. But the namespace "ns" in diag.sh makes setup_ns helper not working. Since "ns" is a local variable in this helper. So this patch renames it as "ns1".
--- tools/testing/selftests/net/mptcp/diag.sh | 58 +++++++++++------------ 1 file changed, 29 insertions(+), 29 deletions(-)
tools/testing/selftests/net/mptcp/diag.sh +29 -29
@@ -8,7 +8,7 @@ . "$(dirname "${0}")/mptcp_lib.sh" -ns="" +ns1="" timeout_poll=30 timeout_test=$((timeout_poll * 2 + 1)) ret=0
@@ -19,10 +19,10 @@ flush_pids() # give it some time sleep 1.1 - ip netns pids "${ns}" | xargs --no-run-if-empty kill -SIGUSR1 &>/dev/null + ip netns pids "${ns1}" | xargs --no-run-if-empty kill -SIGUSR1 &>/dev/null for _ in $(seq $((timeout_poll * 10))); do - [ -z "$(ip netns pids "${ns}")" ] && break + [ -z "$(ip netns pids "${ns1}")" ] && break sleep 0.1 done }
@@ -31,9 +31,9 @@ flush_pids() #shellcheck disable=SC2317 cleanup() { - ip netns pids "${ns}" | xargs --no-run-if-empty kill -SIGKILL &>/dev/null + ip netns pids "${ns1}" | xargs --no-run-if-empty kill -SIGKILL &>/dev/null - mptcp_lib_ns_exit "${ns}" + mptcp_lib_ns_exit "${ns1}" } mptcp_lib_check_mptcp
@@ -41,7 +41,7 @@ mptcp_lib_check_tools ip ss get_msk_inuse() { - ip netns exec $ns cat /proc/net/protocols | awk '$1~/^MPTCP$/{print $3}' + ip netns exec $ns1 cat /proc/net/protocols | awk '$1~/^MPTCP$/{print $3}' } __chk_nr()
@@ -75,7 +75,7 @@ __chk_msk_nr() local condition=$1 shift 1 - __chk_nr "ss -inmHMN $ns | $condition" "$@" + __chk_nr "ss -inmHMN $ns1 | $condition" "$@" } chk_msk_nr()
@@ -88,8 +88,8 @@ chk_listener_nr() local expected=$1 local msg="$2" - __chk_nr "ss -nlHMON $ns | wc -l" "$expected" "$msg - mptcp" 0 - __chk_nr "ss -nlHtON $ns | wc -l" "$expected" "$msg - subflows" + __chk_nr "ss -nlHMON $ns1 | wc -l" "$expected" "$msg - mptcp" 0 + __chk_nr "ss -nlHtON $ns1 | wc -l" "$expected" "$msg - subflows" } wait_msk_nr()
@@ -105,7 +105,7 @@ wait_msk_nr() msg=$* while [ $i -lt $timeout ]; do - nr=$(ss -inmHMN $ns | $condition) + nr=$(ss -inmHMN $ns1 | $condition) [ $nr == $expected ] && break; [ $nr -gt $max ] && max=$nr i=$((i + 1))
@@ -143,7 +143,7 @@ __chk_listen() local expected=$2 local msg="$3" - __chk_nr "ss -N $ns -Ml '$filter' | grep -c LISTEN" "$expected" "$msg" 0 + __chk_nr "ss -N $ns1 -Ml '$filter' | grep -c LISTEN" "$expected" "$msg" 0 } chk_msk_listen()
@@ -173,7 +173,7 @@ chk_msk_inuse() msg+=" after flush" fi - listen_nr=$(ss -N "${ns}" -Ml | grep -c LISTEN) + listen_nr=$(ss -N "${ns1}" -Ml | grep -c LISTEN) expected=$((expected + listen_nr)) for _ in $(seq 10); do
@@ -196,7 +196,7 @@ chk_msk_cestab() msg+=" after flush" fi - __chk_nr "mptcp_lib_get_counter ${ns} MPTcpExtMPCurrEstab" \ + __chk_nr "mptcp_lib_get_counter ${ns1} MPTcpExtMPCurrEstab" \ "${expected}" "${msg}" "" }
@@ -205,7 +205,7 @@ msk_info_get_value() local port="${1}" local info="${2}" - ss -N "${ns}" -inHM dport "${port}" | \ + ss -N "${ns1}" -inHM dport "${port}" | \ mptcp_lib_get_info_value "${info}" "${info}" }
@@ -267,23 +267,23 @@ wait_connected() } trap cleanup EXIT -mptcp_lib_ns_init ns +mptcp_lib_ns_init ns1 echo "a" | \ timeout ${timeout_test} \ - ip netns exec $ns \ + ip netns exec $ns1 \ ./mptcp_connect -p 10000 -l -t ${timeout_poll} -w 20 \ 0.0.0.0 >/dev/null & -mptcp_lib_wait_local_port_listen $ns 10000 +mptcp_lib_wait_local_port_listen $ns1 10000 chk_msk_nr 0 "no msk on netns creation" chk_msk_listen 10000 echo "b" | \ timeout ${timeout_test} \ - ip netns exec $ns \ + ip netns exec $ns1 \ ./mptcp_connect -p 10000 -r 0 -t ${timeout_poll} -w 20 \ 127.0.0.1 >/dev/null & -wait_connected $ns 10000 +wait_connected $ns1 10000 chk_msk_nr 2 "after MPC handshake " chk_last_time_info 10000 chk_msk_remote_key_nr 2 "....chk remote_key"
@@ -297,16 +297,16 @@ chk_msk_cestab 0 "2->0" echo "a" | \ timeout ${timeout_test} \ - ip netns exec $ns \ + ip netns exec $ns1 \ ./mptcp_connect -p 10001 -l -s TCP -t ${timeout_poll} -w 20 \ 0.0.0.0 >/dev/null & -mptcp_lib_wait_local_port_listen $ns 10001 +mptcp_lib_wait_local_port_listen $ns1 10001 echo "b" | \ timeout ${timeout_test} \ - ip netns exec $ns \ + ip netns exec $ns1 \ ./mptcp_connect -p 10001 -r 0 -t ${timeout_poll} -w 20 \ 127.0.0.1 >/dev/null & -wait_connected $ns 10001 +wait_connected $ns1 10001 chk_msk_fallback_nr 1 "check fallback" chk_msk_inuse 1 chk_msk_cestab 1
@@ -319,16 +319,16 @@ NR_CLIENTS=100 for I in $(seq 1 $NR_CLIENTS); do echo "a" | \ timeout ${timeout_test} \ - ip netns exec $ns \ + ip netns exec $ns1 \ ./mptcp_connect -p $((I+10001)) -l -w 20 \ -t ${timeout_poll} 0.0.0.0 >/dev/null & done -mptcp_lib_wait_local_port_listen $ns $((NR_CLIENTS + 10001)) +mptcp_lib_wait_local_port_listen $ns1 $((NR_CLIENTS + 10001)) for I in $(seq 1 $NR_CLIENTS); do echo "b" | \ timeout ${timeout_test} \ - ip netns exec $ns \ + ip netns exec $ns1 \ ./mptcp_connect -p $((I+10001)) -w 20 \ -t ${timeout_poll} 127.0.0.1 >/dev/null & done
@@ -344,16 +344,16 @@ chk_msk_cestab 0 "many->0" chk_listener_nr 0 "no listener sockets" NR_SERVERS=100 for I in $(seq 1 $NR_SERVERS); do - ip netns exec $ns ./mptcp_connect -p $((I + 20001)) \ + ip netns exec $ns1 ./mptcp_connect -p $((I + 20001)) \ -t ${timeout_poll} -l 0.0.0.0 >/dev/null 2>&1 & done -mptcp_lib_wait_local_port_listen $ns $((NR_SERVERS + 20001)) +mptcp_lib_wait_local_port_listen $ns1 $((NR_SERVERS + 20001)) chk_listener_nr $NR_SERVERS "many listener sockets" # graceful termination for I in $(seq 1 $NR_SERVERS); do - echo a | ip netns exec $ns ./mptcp_connect -p $((I + 20001)) 127.0.0.1 >/dev/null 2>&1 & + echo a | ip netns exec $ns1 ./mptcp_connect -p $((I + 20001)) 127.0.0.1 >/dev/null 2>&1 & done flush_pids
Signature · 1 line
2.43.0
Geliang Tang
reviewerPATCH 2/4 selftests: mptcp: use setup_ns helper in lib.sh
In reply to Geliang TangFrom: Geliang Tang <[email protected]>
This patch includes lib.sh into mptcp_lib.sh, uses setup_ns() helper in lib.sh to set up namespaces in mptcp_lib_ns_init(). Then for each namespace in NS_LIST, run all sysctl commands. This can drop some duplicate code.
--- .../testing/selftests/net/mptcp/mptcp_lib.sh | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-)
tools/testing/selftests/net/mptcp/mptcp_lib.sh +7 -12
@@ -1,6 +1,8 @@ #! /bin/bash # SPDX-License-Identifier: GPL-2.0 +. "$(dirname "${0}")/../lib.sh" + readonly KSFT_PASS=0 readonly KSFT_FAIL=1 readonly KSFT_SKIP=4
@@ -412,20 +414,13 @@ mptcp_lib_check_tools() { } mptcp_lib_ns_init() { - local sec rndh - - sec=$(date +%s) - rndh=$(printf %x "${sec}")-$(mktemp -u XXXXXX) + setup_ns "${@}" local netns - for netns in "${@}"; do - eval "${netns}=${netns}-${rndh}" - - ip netns add "${!netns}" || exit ${KSFT_SKIP} - ip -net "${!netns}" link set lo up - ip netns exec "${!netns}" sysctl -q net.mptcp.enabled=1 - ip netns exec "${!netns}" sysctl -q net.ipv4.conf.all.rp_filter=0 - ip netns exec "${!netns}" sysctl -q net.ipv4.conf.default.rp_filter=0 + for netns in $NS_LIST; do + ip netns exec "${netns}" sysctl -q net.mptcp.enabled=1 + ip netns exec "${netns}" sysctl -q net.ipv4.conf.all.rp_filter=0 + ip netns exec "${netns}" sysctl -q net.ipv4.conf.default.rp_filter=0 done }
Signature · 1 line
2.43.0
Geliang Tang
reviewerPATCH 3/4 selftests: mptcp: use cleanup_all_ns helper in lib.sh
In reply to Geliang TangFrom: Geliang Tang <[email protected]>
This patch uses cleanup_all_ns() helper in lib.sh instead of all mptcp_lib_ns_exit() in mptcp seltests. And drop this duplicate mptcp helper in mptcp_lib.sh.
--- tools/testing/selftests/net/mptcp/diag.sh | 2 +- tools/testing/selftests/net/mptcp/mptcp_connect.sh | 3 +-- tools/testing/selftests/net/mptcp/mptcp_join.sh | 2 +- tools/testing/selftests/net/mptcp/mptcp_lib.sh | 8 -------- tools/testing/selftests/net/mptcp/mptcp_sockopt.sh | 2 +- tools/testing/selftests/net/mptcp/pm_netlink.sh | 2 +- tools/testing/selftests/net/mptcp/simult_flows.sh | 2 +- tools/testing/selftests/net/mptcp/userspace_pm.sh | 2 +- 8 files changed, 7 insertions(+), 16 deletions(-)
tools/testing/selftests/net/mptcp/diag.sh +1 -1
@@ -33,7 +33,7 @@ cleanup() { ip netns pids "${ns1}" | xargs --no-run-if-empty kill -SIGKILL &>/dev/null - mptcp_lib_ns_exit "${ns1}" + cleanup_all_ns } mptcp_lib_check_mptcp
tools/testing/selftests/net/mptcp/mptcp_connect.sh +1 -2
@@ -142,7 +142,7 @@ cleanup() rm -f "$sin" "$sout" rm -f "$capout" - mptcp_lib_ns_exit "${ns1}" "${ns2}" "${ns3}" "${ns4}" + cleanup_all_ns } mptcp_lib_check_mptcp
@@ -271,7 +271,6 @@ check_mptcp_disabled() local err=0 LC_ALL=C ip netns exec ${disabled_ns} ./mptcp_connect -p 10000 -s MPTCP 127.0.0.1 < "$cin" 2>&1 | \ grep -q "^socket: Protocol not available$" && err=1 - mptcp_lib_ns_exit "${disabled_ns}" if [ ${err} -eq 0 ]; then mptcp_lib_pr_fail "New MPTCP socket cannot be blocked via sysctl"
tools/testing/selftests/net/mptcp/mptcp_join.sh +1 -1
@@ -133,7 +133,7 @@ cleanup_partial() { rm -f "$capout" - mptcp_lib_ns_exit "${ns1}" "${ns2}" + cleanup_all_ns } init() {
tools/testing/selftests/net/mptcp/mptcp_lib.sh +0 -8
@@ -424,14 +424,6 @@ mptcp_lib_ns_init() { done } -mptcp_lib_ns_exit() { - local netns - for netns in "${@}"; do - ip netns del "${netns}" - rm -f /tmp/"${netns}".{nstat,out} - done -} - mptcp_lib_events() { local ns="${1}" local evts="${2}"
tools/testing/selftests/net/mptcp/mptcp_sockopt.sh +1 -1
@@ -98,7 +98,7 @@ init() #shellcheck disable=SC2317 cleanup() { - mptcp_lib_ns_exit "${ns1}" "${ns2}" "${ns_sbox}" + cleanup_all_ns rm -f "$cin" "$cout" rm -f "$sin" "$sout" }
tools/testing/selftests/net/mptcp/pm_netlink.sh +1 -1
@@ -36,7 +36,7 @@ err=$(mktemp) cleanup() { rm -f "${err}" - mptcp_lib_ns_exit "${ns1}" + cleanup_all_ns } mptcp_lib_check_mptcp
tools/testing/selftests/net/mptcp/simult_flows.sh +1 -1
@@ -42,7 +42,7 @@ cleanup() rm -f "$large" "$small" rm -f "$capout" - mptcp_lib_ns_exit "${ns1}" "${ns2}" "${ns3}" + cleanup_all_ns } mptcp_lib_check_mptcp
tools/testing/selftests/net/mptcp/userspace_pm.sh +1 -1
@@ -107,7 +107,7 @@ cleanup() mptcp_lib_kill_wait $pid done - mptcp_lib_ns_exit "${ns1}" "${ns2}" + cleanup_all_ns rm -rf $file $client_evts $server_evts
Signature · 1 line
2.43.0
Geliang Tang
reviewerPATCH 4/4 selftests: mptcp: use wait_local_port_listen helper
In reply to Geliang TangFrom: Geliang Tang <[email protected]>
This patch includes net_helper.sh into mptcp_lib.sh, uses the helper wait_local_port_listen() in it to implement the similar mptcp helper. This can drop some duplicate code.
--- tools/testing/selftests/net/mptcp/mptcp_lib.sh | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-)
tools/testing/selftests/net/mptcp/mptcp_lib.sh +2 -14
@@ -2,6 +2,7 @@ # SPDX-License-Identifier: GPL-2.0 . "$(dirname "${0}")/../lib.sh" +. "$(dirname "${0}")/../net_helper.sh" readonly KSFT_PASS=0 readonly KSFT_FAIL=1
@@ -337,20 +338,7 @@ mptcp_lib_check_transfer() { # $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 _ - for _ 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_local_port_listen "${@}" "tcp" } mptcp_lib_check_output() {
Signature · 1 line
2.43.0
Hi Geliang,
Thank you for your modifications, that's great!
Our CI did some validations and here is its report:
- KVM Validation: normal: Unstable: 1 failed test(s): selftest_simult_flows 🔴
- KVM Validation: debug: Success! ✅
- KVM Validation: btf (only bpftest_all): Success! ✅
- Task: https://github.com/multipath-tcp/mptcp_net-next/actions/runs/9173398814
Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/80b3dee68420
Patchwork: https://patchwork.kernel.org/project/mptcp/list/?series=854683
If there are some issues, you can reproduce them using the same environment as the one used by the CI thanks to a docker image, e.g.:
$ cd [kernel source code]
$ docker run -v "${PWD}:${PWD}:rw" -w "${PWD}" --privileged --rm -it \
--pull always mptcp/mptcp-upstream-virtme-docker:latest \
auto-normalFor more details:
https://github.com/multipath-tcp/mptcp-upstream-virtme-docker
Please note that despite all the efforts that have been already done to have a stable tests suite when executed on a public CI like here, it is possible some reported issues are not due to your modifications. Still, do not hesitate to help us improve that ;-)
Cheers,
MPTCP GH Action bot
Bot operated by Matthieu Baerts (NGI0 Core)