diff mbox series

[mptcp-next,v2,4/4] selftests: mptcp: use wait_local_port_listen helper

Message ID 97fa6e63c052859546163fad4ff96a78ce95415a.1716451525.git.tanggeliang@kylinos.cn (mailing list archive)
State Superseded, archived
Delegated to: Matthieu Baerts
Headers show
Series use helpers in lib.sh and net_helpers.sh | expand

Checks

Context Check Description
matttbe/build success Build and static analysis OK
matttbe/checkpatch warning total: 0 errors, 1 warnings, 0 checks, 28 lines checked
matttbe/shellcheck success No ShellCheck issues
matttbe/KVM_Validation__normal success Success! ✅
matttbe/KVM_Validation__debug success Success! ✅
matttbe/KVM_Validation__btf__only_bpftest_all_ success Success! ✅

Commit Message

Geliang Tang May 23, 2024, 8:09 a.m. UTC
From: Geliang Tang <tanggeliang@kylinos.cn>

This patch includes net_helper.sh into mptcp_lib.sh, uses the helper
wait_local_port_listen() defined in it to implement the similar mptcp
helper. This can drop some duplicate code.

Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
---
 tools/testing/selftests/net/mptcp/mptcp_lib.sh | 16 ++--------------
 1 file changed, 2 insertions(+), 14 deletions(-)

Comments

Matthieu Baerts (NGI0) May 23, 2024, 9:24 a.m. UTC | #1
Hi Geliang,

On 23/05/2024 10:09, Geliang Tang wrote:
> From: Geliang Tang <tanggeliang@kylinos.cn>
> 
> This patch includes net_helper.sh into mptcp_lib.sh, uses the helper
> wait_local_port_listen() defined in it to implement the similar mptcp
> helper. This can drop some duplicate code.
> 
> Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
> ---
>  tools/testing/selftests/net/mptcp/mptcp_lib.sh | 16 ++--------------
>  1 file changed, 2 insertions(+), 14 deletions(-)
> 
> diff --git a/tools/testing/selftests/net/mptcp/mptcp_lib.sh b/tools/testing/selftests/net/mptcp/mptcp_lib.sh
> index bd7d78e4aa83..e039c88a64ed 100644
> --- a/tools/testing/selftests/net/mptcp/mptcp_lib.sh
> +++ b/tools/testing/selftests/net/mptcp/mptcp_lib.sh

(...)

> @@ -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"

That's a shame people who duplicated the code didn't do that for us (or
at least they could have mentioned where the code was coming from)...

Anyway, good you saw that, and good idea to use it.

>  }
>  
>  mptcp_lib_check_output() {

Cheers,
Matt
diff mbox series

Patch

diff --git a/tools/testing/selftests/net/mptcp/mptcp_lib.sh b/tools/testing/selftests/net/mptcp/mptcp_lib.sh
index bd7d78e4aa83..e039c88a64ed 100644
--- a/tools/testing/selftests/net/mptcp/mptcp_lib.sh
+++ b/tools/testing/selftests/net/mptcp/mptcp_lib.sh
@@ -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() {