MPTCP Linux Development
 help / color / mirror / Atom feed
From: Matthieu Baerts <matttbe@kernel.org>
To: Geliang Tang <geliang@kernel.org>, mptcp@lists.linux.dev
Cc: Geliang Tang <tanggeliang@kylinos.cn>
Subject: Re: [PATCH mptcp-next v2 7/7] selftests: mptcp: add mptcp_lib_check_tools helper
Date: Fri, 16 Feb 2024 14:48:03 +0100	[thread overview]
Message-ID: <951d1f6a-0ed7-49a0-abeb-c94a90ca6748@kernel.org> (raw)
In-Reply-To: <f7ca03a3e2d9b8c8a49e9226d88b40c935875e14.1708076886.git.tanggeliang@kylinos.cn>

Hi Geliang,

On 16/02/2024 10:50, Geliang Tang wrote:
> From: Geliang Tang <tanggeliang@kylinos.cn>
> 
> This patch exports check_tools() helper from mptcp_join.sh into
> mptcp_lib.sh as a public one mptcp_lib_check_tools(). The arguments
> "ip", "ss", and "iptables" are passed into this helper to indicate
> whether to check ip tool, ss tool and iptables tools.
> 
> This helper can be used in every scripts.
> 
> Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
> ---
>  tools/testing/selftests/net/mptcp/diag.sh     | 13 +--------
>  .../selftests/net/mptcp/mptcp_connect.sh      | 14 +--------
>  .../testing/selftests/net/mptcp/mptcp_join.sh | 26 +----------------
>  .../testing/selftests/net/mptcp/mptcp_lib.sh  | 29 +++++++++++++++++++
>  .../selftests/net/mptcp/mptcp_sockopt.sh      | 22 +-------------
>  .../testing/selftests/net/mptcp/pm_netlink.sh |  8 +----
>  .../selftests/net/mptcp/simult_flows.sh       |  8 +----
>  .../selftests/net/mptcp/userspace_pm.sh       |  8 +----
>  8 files changed, 36 insertions(+), 92 deletions(-)
> 
> diff --git a/tools/testing/selftests/net/mptcp/diag.sh b/tools/testing/selftests/net/mptcp/diag.sh
> index 8573326d326a..7c68160ad3b9 100755
> --- a/tools/testing/selftests/net/mptcp/diag.sh
> +++ b/tools/testing/selftests/net/mptcp/diag.sh
> @@ -33,18 +33,7 @@ cleanup()
>  	ip netns del $ns
>  }
>  
> -mptcp_lib_check_mptcp

(see below) Here, we don't need to check for mptcp_lib_check_kallsyms.

(...)

> mptcp_lib_check_tools "ip" "ss"

(you can remove the double quotes if you don't use variables)

> diff --git a/tools/testing/selftests/net/mptcp/mptcp_lib.sh b/tools/testing/selftests/net/mptcp/mptcp_lib.sh
> index 108a1e12436c..cdb8948749eb 100644
> --- a/tools/testing/selftests/net/mptcp/mptcp_lib.sh
> +++ b/tools/testing/selftests/net/mptcp/mptcp_lib.sh
> @@ -319,3 +319,32 @@ mptcp_lib_wait_local_port_listen() {
>  		sleep 0.1
>  	done
>  }
> +
> +mptcp_lib_check_tools() {
> +	mptcp_lib_check_mptcp
> +	mptcp_lib_check_kallsyms

I would not move that here, better to have an explicit check in each
selftest I think. Also, see above/below: some selftests don't need kallsyms.

> +	if [ "${1:-""}" == "ip" ]; then

Probably better to use a switch/case, so the order is not important, no?


  local tool

  for tool in "${@}"; do
      case "${tool}" in
      "ip")
          if ! ip -Version &> /dev/null; then
              (...)
          fi
          ;;
      "ss")
          (...)
          ;;
      "iptables"* | "ip6tables"*)  ## including extensions
          if ! "${tool}" -V &> /dev/null; then
          (...)
      *)
          mptcp_lib_print_warn "Unsupported tool: ${tool}"
          exit ${KSFT_FAIL}
          ;;
      esac
  done


So we can use this helper with parameters in any order, e.g.

  mptcp_lib_check_tools ss iptables-nft


> +		if ! ip -Version &> /dev/null; then
> +			mptcp_lib_print_warn "SKIP: Could not run test without ip tool"
> +			exit ${KSFT_SKIP}
> +		fi
> +	fi
> +
> +	if [ "${2:-""}" == "ss" ]; then
> +		if ! ss -h | grep -q MPTCP; then
> +			mptcp_lib_print_warn "SKIP: ss tool does not support MPTCP"
> +			exit ${KSFT_SKIP}
> +		fi
> +	fi
> +
> +	if [ "${3:-""}" == "iptables" ]; then
> +		if ! iptables -V &> /dev/null; then
> +			mptcp_lib_print_warn "SKIP: Could not run all tests without iptables tool"
> +			exit ${KSFT_SKIP}
> +		elif ! ip6tables -V &> /dev/null; then
> +			mptcp_lib_print_warn "SKIP: Could not run all tests without ip6tables tool"
> +			exit ${KSFT_SKIP}
> +		fi

I would split "iptables" and "ip6tables" cases, please see above: just
not to repeat the same err message, and maybe a selftest will only need one.

> +	fi
> +}

(...)

> diff --git a/tools/testing/selftests/net/mptcp/pm_netlink.sh b/tools/testing/selftests/net/mptcp/pm_netlink.sh
> index ebfefae71e13..e7ab5eca3e75 100755
> --- a/tools/testing/selftests/net/mptcp/pm_netlink.sh
> +++ b/tools/testing/selftests/net/mptcp/pm_netlink.sh
> @@ -35,13 +35,7 @@ cleanup()
>  	ip netns del $ns1
>  }
>  
> -mptcp_lib_check_mptcp

(see above) Here, we don't need to check for mptcp_lib_check_kallsyms.

> -ip -Version > /dev/null 2>&1
> -if [ $? -ne 0 ];then
> -	echo "SKIP: Could not run test without ip tool"
> -	exit $ksft_skip
> -fi
> +mptcp_lib_check_tools "ip"
>  
>  trap cleanup EXIT
>  
> diff --git a/tools/testing/selftests/net/mptcp/simult_flows.sh b/tools/testing/selftests/net/mptcp/simult_flows.sh
> index e6e5b933a1b9..053f40bf25c1 100755
> --- a/tools/testing/selftests/net/mptcp/simult_flows.sh
> +++ b/tools/testing/selftests/net/mptcp/simult_flows.sh
> @@ -42,13 +42,7 @@ cleanup()
>  	done
>  }
>  
> -mptcp_lib_check_mptcp

(see above) Here, we don't need to check for mptcp_lib_check_kallsyms.

(...)

Cheers,
Matt
-- 
Sponsored by the NGI0 Core fund.

  parent reply	other threads:[~2024-02-16 13:48 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-16  9:50 [PATCH mptcp-next v2 0/7] add helpers and vars in mptcp_lib.sh, part 1 Geliang Tang
2024-02-16  9:50 ` [PATCH mptcp-next v2 1/7] selftests: mptcp: netlink: drop duplicate var ret Geliang Tang
2024-02-16  9:50 ` [PATCH mptcp-next v2 2/7] selftests: mptcp: simult flows: define missing vars Geliang Tang
2024-02-16  9:50 ` [PATCH mptcp-next v2 3/7] selftests: mptcp: join: change capture/checksum as bool Geliang Tang
2024-02-16  9:50 ` [PATCH mptcp-next v2 4/7] selftests: mptcp: diag: change timeout_poll to 30 Geliang Tang
2024-02-16  9:50 ` [PATCH mptcp-next v2 5/7] selftests: mptcp: drop iptables/ip6tables vars Geliang Tang
2024-02-16 13:45   ` Matthieu Baerts
2024-02-16  9:50 ` [PATCH mptcp-next v2 6/7] selftests: mptcp: add ss mptcp support checks Geliang Tang
2024-02-16 13:46   ` Matthieu Baerts
2024-02-16  9:50 ` [PATCH mptcp-next v2 7/7] selftests: mptcp: add mptcp_lib_check_tools helper Geliang Tang
2024-02-16 10:14   ` selftests: mptcp: add mptcp_lib_check_tools helper: Tests Results MPTCP CI
2024-02-16 10:24     ` Matthieu Baerts
2024-02-16 10:45   ` MPTCP CI
2024-02-16 11:08   ` MPTCP CI
2024-02-16 11:27   ` MPTCP CI
2024-02-16 13:48   ` Matthieu Baerts [this message]
2024-02-16 13:43 ` [PATCH mptcp-next v2 0/7] add helpers and vars in mptcp_lib.sh, part 1 Matthieu Baerts
2024-02-16 13:56   ` Matthieu Baerts

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=951d1f6a-0ed7-49a0-abeb-c94a90ca6748@kernel.org \
    --to=matttbe@kernel.org \
    --cc=geliang@kernel.org \
    --cc=mptcp@lists.linux.dev \
    --cc=tanggeliang@kylinos.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox