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 v13 08/14] selftests: mptcp: add check_output helper
Date: Mon, 19 Feb 2024 15:51:17 +0100 [thread overview]
Message-ID: <245af371-13ea-4e67-9d8d-93844e5cdf9a@kernel.org> (raw)
In-Reply-To: <203718fd9b34ac092a198737bed0e36baa447d69.1708069036.git.tanggeliang@kylinos.cn>
Hi Geliang,
On 16/02/2024 08:42, Geliang Tang wrote:
> From: Geliang Tang <tanggeliang@kylinos.cn>
>
> Similar to check() in pm_netlink.sh, add a new helper check_output()
> in mptcp_join.sh to check the output of the given commands.
>
> Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
> ---
> .../testing/selftests/net/mptcp/mptcp_join.sh | 27 +++++++++++++++++++
> 1 file changed, 27 insertions(+)
>
> diff --git a/tools/testing/selftests/net/mptcp/mptcp_join.sh b/tools/testing/selftests/net/mptcp/mptcp_join.sh
> index b807e2a42c61..6f7e83f61707 100755
> --- a/tools/testing/selftests/net/mptcp/mptcp_join.sh
> +++ b/tools/testing/selftests/net/mptcp/mptcp_join.sh
> @@ -21,6 +21,7 @@ cinfail=""
> cinsent=""
> tmpfile=""
> cout=""
> +check_output_err=""
> capout=""
> ns1=""
> ns2=""
> @@ -182,6 +183,7 @@ init() {
> cout=$(mktemp)
> evts_ns1=$(mktemp)
> evts_ns2=$(mktemp)
> + check_output_err=$(mktemp)
>
> trap cleanup EXIT
>
> @@ -195,6 +197,7 @@ cleanup()
> rm -f "$sin" "$sout" "$cinsent" "$cinfail"
> rm -f "$tmpfile"
> rm -rf $evts_ns1 $evts_ns2
> + rm -f $check_output_err
> cleanup_partial
> }
>
> @@ -3347,6 +3350,30 @@ userspace_pm_rm_sf()
> wait_rm_sf $1 "${cnt}"
> }
>
> +check_output()
> +{
> + local cmd="$1"
> + local expected="$2"
> + local msg="$3"
> + local out=`$cmd 2>$check_output_err`
This causes the following warnings from shellcheck:
> $ shellcheck -x mptcp_join.sh
>
> In mptcp_join.sh line 3365:
> local out=`$cmd 2>$check_output_err`
> ^-^ SC2155 (warning): Declare and assign separately to avoid masking return values.
> ^------------------------^ SC2006 (style): Use $(...) notation instead of legacy backticks `...`.
>
> Did you mean:
> local out=$($cmd 2>$check_output_err)
I guess it should be:
local out cmd_ret=0
out=$(${cmd} 2>${check_output_err}) || cmd_ret=${?}
Please check you don't introduce new shellcheck warnings. There are
shellcheck plugins for various text editors.
> + local cmd_ret=$?
> +
> + printf "%-42s" "$msg"
You should not need this. Can you not use print_check() instead?
And in fact, you should not call 'print_check' from here, but from the
caller, where you would have 'print_skip', see patches 9 and 14/14.
> + if [ $cmd_ret -ne 0 ]; then
> + mptcp_lib_print_err "[FAIL] command execution '$cmd' stderr "
Here, you should call fail_test() instead, and not set ret=<FAIL>: there
is a single function setting ret to a different value, best not to
change that.
Also, fail_test() will print more info if needed, and mark the test as
failed.
> + cat $check_output_err
> + ret=${KSFT_FAIL}
> + return $cmd_ret
> + elif [ "$out" = "$expected" ]; then
> + mptcp_lib_print_ok "[ OK ]"
And here you should call print_ok().
> + return 0
> + else
> + mptcp_lib_print_err "[FAIL] expected '$expected' got '$out'"
> + ret=${KSFT_FAIL}
> + return 1
Same here: fail_test().
> + fi
> +}
> +
> userspace_tests()
> {
> # userspace pm type prevents add_addr
(looking at the modifications that are specific to mptcp_join.sh, you
might have to drop "selftests: mptcp: add mptcp_lib_check_output helper"
from "add helpers and vars in mptcp_lib.sh, part 2" series. But of
course, still OK to use mptcp_lib_print_XXX from pm_netlink.sh and other
.sh scripts to add colours!)
Cheers,
Matt
--
Sponsored by the NGI0 Core fund.
next prev parent reply other threads:[~2024-02-19 14:51 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-16 7:42 [PATCH mptcp-next v13 00/14] dump for userspace pm Geliang Tang
2024-02-16 7:42 ` [PATCH mptcp-next v13 01/14] mptcp: export mptcp_genl_family & mptcp_nl_fill_addr Geliang Tang
2024-02-16 7:42 ` [PATCH mptcp-next v13 02/14] mptcp: implement mptcp_userspace_pm_dump_addr Geliang Tang
2024-02-16 7:42 ` [PATCH mptcp-next v13 03/14] mptcp: add token for get-addr in yaml Geliang Tang
2024-02-16 7:42 ` [PATCH mptcp-next v13 04/14] mptcp: dump addrs in userspace pm list Geliang Tang
2024-02-16 7:42 ` [PATCH mptcp-next v13 05/14] mptcp: check userspace pm flags Geliang Tang
2024-02-19 14:53 ` Matthieu Baerts
2024-02-16 7:42 ` [PATCH mptcp-next v13 06/14] selftests: mptcp: add userspace pm subflow flag Geliang Tang
2024-02-16 7:42 ` [PATCH mptcp-next v13 07/14] selftests: mptcp: add token for dump_addr Geliang Tang
2024-02-16 7:42 ` [PATCH mptcp-next v13 08/14] selftests: mptcp: add check_output helper Geliang Tang
2024-02-19 14:51 ` Matthieu Baerts [this message]
2024-02-16 7:42 ` [PATCH mptcp-next v13 09/14] selftests: mptcp: dump userspace addrs list Geliang Tang
2024-02-19 14:55 ` Matthieu Baerts
2024-02-16 7:42 ` [PATCH mptcp-next v13 10/14] mptcp: add userspace_pm_lookup_addr_by_id helper Geliang Tang
2024-02-16 7:42 ` [PATCH mptcp-next v13 11/14] mptcp: implement mptcp_userspace_pm_get_addr Geliang Tang
2024-02-16 7:42 ` [PATCH mptcp-next v13 12/14] mptcp: get addr in userspace pm list Geliang Tang
2024-02-16 7:42 ` [PATCH mptcp-next v13 13/14] selftests: mptcp: add token for get_addr Geliang Tang
2024-02-16 7:42 ` [PATCH mptcp-next v13 14/14] selftests: mptcp: userspace pm get addr tests Geliang Tang
2024-02-16 8:34 ` selftests: mptcp: userspace pm get addr tests: Tests Results MPTCP CI
2024-02-16 9:55 ` MPTCP CI
2024-02-16 10:14 ` MPTCP CI
2024-02-16 10:24 ` Matthieu Baerts
2024-02-16 11:08 ` MPTCP CI
2024-02-16 11:31 ` MPTCP CI
2024-02-16 20:33 ` MPTCP CI
2024-02-19 14:56 ` [PATCH mptcp-next v13 14/14] selftests: mptcp: userspace pm get addr tests Matthieu Baerts
2024-02-16 19:31 ` [PATCH mptcp-next v13 00/14] dump for userspace pm Mat Martineau
2024-02-19 14:52 ` 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=245af371-13ea-4e67-9d8d-93844e5cdf9a@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.