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 v5 09/12] selftests: mptcp: extract mptcp_lib_check_expected
Date: Mon, 26 Feb 2024 13:41:53 +0100	[thread overview]
Message-ID: <5273bf67-282b-4b16-8576-670b12447d6a@kernel.org> (raw)
In-Reply-To: <71d2dc8ad19fd8d87c8e128ed3f02a6c77d1c9d2.1708939962.git.tanggeliang@kylinos.cn>

Hi Geliang,

On 26/02/2024 10:43, Geliang Tang wrote:
> From: Geliang Tang <tanggeliang@kylinos.cn>
> 
> Extract the main part of check_expected() in userspace_pm.sh to a new
> function mptcp_lib_check_expected() in mptcp_lib.sh. It will be used
> in both mptcp_john.sh and userspace_pm.sh.
> 
> check_expected_one() is moved into mptcp_lib.sh too as a sub function
> of mptcp_lib_check_expected().

Out of curiosity: why a subfunction?

(see below)

> Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
> ---
>  .../testing/selftests/net/mptcp/mptcp_lib.sh  | 48 +++++++++++++++++++
>  .../selftests/net/mptcp/userspace_pm.sh       | 39 ++-------------
>  2 files changed, 52 insertions(+), 35 deletions(-)
> 
> diff --git a/tools/testing/selftests/net/mptcp/mptcp_lib.sh b/tools/testing/selftests/net/mptcp/mptcp_lib.sh
> index df495658f043..ed0013b47edb 100644
> --- a/tools/testing/selftests/net/mptcp/mptcp_lib.sh
> +++ b/tools/testing/selftests/net/mptcp/mptcp_lib.sh
> @@ -1,6 +1,9 @@
>  #! /bin/bash
>  # SPDX-License-Identifier: GPL-2.0
>  
> +# Some variables are used below but indirectly, see check_expected_one()
> +#shellcheck disable=SC2034

Please move that just above the lines or functions having these
false-positive errors to reduce the scope. Otherwise, this rule will be
applied everywhere, and maybe missing valid issues.

In other words, don't declare it here, but in mptcp_join.sh, where used.
For userspace_pm.sh, you can keep it where it is, I suppose.

> +
>  readonly KSFT_PASS=0
>  readonly KSFT_FAIL=1
>  readonly KSFT_SKIP=4
> @@ -419,3 +422,48 @@ mptcp_lib_print_test_counter() {
>  
>  	printf "%02u ${fmt}" "$((++counter))" "${msg}"
>  }
> +
> +# $@: all var names to check
> +mptcp_lib_check_expected() {
> +	# $1: var name ; $2: prev ret
> +	check_expected_one() {

You still need to prefix it with mptcp_lib_ because you could override
functions with the same name declared elsewhere: when
mptcp_lib_check_expected(), this subfunction will be created globally,
potentially overriding other ones with the same name.

> +		local var="${1}"
> +		local exp="e_${var}"
> +		local prev_ret="${2}"
> +
> +		if [ "${!var}" = "${!exp}" ]

Please keep the same code style as in the rest of this file: "then" and
"do" are on the same line as "if" / "for".

> +		then
> +			return 0
> +		fi
> +
> +		if [ "${prev_ret}" = "0" ]
> +		then
> +			return 2
> +		fi
> +
> +		printf "\tExpected value for '%s': '%s', got '%s'.\n" \
> +			"${var}" "${!exp}" "${!var}"
> +		return 1
> +	}
> +
> +	local rc=0
> +	local var
> +
> +	for var in "${@}"
> +	do
> +		check_expected_one "${var}" "${rc}" || rc="${?}"
> +		if [ "${rc}" -eq 2 ]
> +		then
> +			break
> +		fi
> +	done
> +	unset -f check_expected_one
> +
> +	if [ ${rc} -eq 0 ]
> +	then
> +		mptcp_lib_print_ok "[ OK ]"
> +		return 0
> +	fi
> +
> +	return "${rc}"
> +}
> diff --git a/tools/testing/selftests/net/mptcp/userspace_pm.sh b/tools/testing/selftests/net/mptcp/userspace_pm.sh
> index 473639a8009f..3f475ae44d0b 100755
> --- a/tools/testing/selftests/net/mptcp/userspace_pm.sh
> +++ b/tools/testing/selftests/net/mptcp/userspace_pm.sh
> @@ -5,7 +5,7 @@
>  # code but we accept it.
>  #shellcheck disable=SC2086
>  
> -# Some variables are used below but indirectly, see check_expected_one()
> +# Some variables are used below but indirectly

Maybe point to check_expected now?

>  #shellcheck disable=SC2034
>  
>  . "$(dirname "${0}")/mptcp_lib.sh"
> @@ -233,46 +233,15 @@ make_connection()
>  	fi
>  }
>  
> -# $1: var name ; $2: prev ret
> -check_expected_one()
> -{
> -	local var="${1}"
> -	local exp="e_${var}"
> -	local prev_ret="${2}"
> -
> -	if [ "${!var}" = "${!exp}" ]
> -	then
> -		return 0
> -	fi
> -
> -	if [ "${prev_ret}" = "0" ]
> -	then
> -		return 2
> -	fi
> -
> -	_printf "\tExpected value for '%s': '%s', got '%s'.\n" \
> -		"${var}" "${!exp}" "${!var}"
> -	return 1
> -}
> -
>  # $@: all var names to check
>  check_expected()
>  {
>  	local rc=0
> -	local var
>  
> -	for var in "${@}"
> -	do
> -		check_expected_one "${var}" "${rc}" || rc="${?}"
> -		if [ "${rc}" -eq 2 ]
> -		then
> -			break
> -		fi
> -	done
> -
> -	if [ ${rc} -eq 0 ]
> +	mptcp_lib_check_expected "${@}" || rc="${?}"
> +	if [ "${rc}" -eq 0 ]
>  	then
> -		test_pass
> +		mptcp_lib_result_pass "${test_name}"
>  		return 0
>  	elif [ "${rc}" -eq 2 ]
>  	then

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

  reply	other threads:[~2024-02-26 12:41 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-26  9:43 [PATCH mptcp-next v5 00/12] add helpers and vars in mptcp_lib.sh, part 3 Geliang Tang
2024-02-26  9:43 ` [PATCH mptcp-next v5 01/12] selftests: mptcp: capitalize ok/fail/skip Geliang Tang
2024-02-26 12:40   ` Matthieu Baerts
2024-02-28  7:47     ` Geliang Tang
2024-02-26  9:43 ` [PATCH mptcp-next v5 02/12] selftests: mptcp: sockopt: print every test result Geliang Tang
2024-02-26 12:40   ` Matthieu Baerts
2024-02-28  7:57     ` Geliang Tang
2024-02-28  9:13       ` Matthieu Baerts
2024-02-28  9:51         ` Geliang Tang
2024-02-26  9:43 ` [PATCH mptcp-next v5 03/12] selftests: mptcp: connect: fix misaligned OK/FAIL Geliang Tang
2024-02-26 12:40   ` Matthieu Baerts
2024-02-28  7:58     ` Geliang Tang
2024-02-26  9:43 ` [PATCH mptcp-next v5 04/12] selftests: mptcp: print test results with colors Geliang Tang
2024-02-26 12:41   ` Matthieu Baerts
2024-02-28  8:06     ` Geliang Tang
2024-02-26  9:43 ` [PATCH mptcp-next v5 05/12] selftests: mptcp: connect: add dedicated port counter Geliang Tang
2024-02-26 12:41   ` Matthieu Baerts
2024-02-28  8:09     ` Geliang Tang
2024-02-26  9:43 ` [PATCH mptcp-next v5 06/12] selftests: mptcp: connect: print out ping tests info Geliang Tang
2024-02-26 12:41   ` Matthieu Baerts
2024-02-28  8:31     ` Geliang Tang
2024-02-26  9:43 ` [PATCH mptcp-next v5 07/12] selftests: mptcp: print test results with counters Geliang Tang
2024-02-26 12:41   ` Matthieu Baerts
2024-02-28  8:23     ` Geliang Tang
2024-02-28 10:20       ` Matthieu Baerts
2024-02-26  9:43 ` [PATCH mptcp-next v5 08/12] selftests: mptcp: move test_fail out of check_expected_one Geliang Tang
2024-02-26 12:41   ` Matthieu Baerts
2024-02-26  9:43 ` [PATCH mptcp-next v5 09/12] selftests: mptcp: extract mptcp_lib_check_expected Geliang Tang
2024-02-26 12:41   ` Matthieu Baerts [this message]
2024-02-26  9:43 ` [PATCH mptcp-next v5 10/12] selftests: mptcp: export event macros in mptcp_lib Geliang Tang
2024-02-26 12:42   ` Matthieu Baerts
2024-02-26  9:43 ` [PATCH mptcp-next v5 11/12] selftests: mptcp: add mptcp_lib_verify_listener_events Geliang Tang
2024-02-26 12:42   ` Matthieu Baerts
2024-02-26  9:43 ` [PATCH mptcp-next v5 12/12] selftests: mptcp: use KSFT_SKIP/KSFT_PASS/KSFT_FAIL Geliang Tang
2024-02-26 10:33   ` selftests: mptcp: use KSFT_SKIP/KSFT_PASS/KSFT_FAIL: Tests Results MPTCP CI
2024-02-26 12:40 ` [PATCH mptcp-next v5 00/12] add helpers and vars in mptcp_lib.sh, part 3 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=5273bf67-282b-4b16-8576-670b12447d6a@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