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 v7 6/8] selftests: mptcp: add test counter helpers
Date: Thu, 29 Feb 2024 12:58:15 +0100 [thread overview]
Message-ID: <fea0084f-665b-4ea2-96cd-f9c025c02a28@kernel.org> (raw)
In-Reply-To: <9a31a17605edb4546467a172d8619eff3f15a002.1709200070.git.tanggeliang@kylinos.cn>
Hi Geliang,
On 29/02/2024 10:51, Geliang Tang wrote:
> From: Geliang Tang <tanggeliang@kylinos.cn>
>
> This patch adds two vars in mptcp_lib.sh, MPTCP_LIB_TEST_COUNTER for
> the test counter and MPTCP_LIB_TEST_FORMAT for the test print format.
> Also add two helpers, mptcp_lib_inc_test_counter(), increase the test
> counter, and mptcp_lib_pr_title_counter(), print the test title with
> counter. They are used in mptcp_join.sh first.
Please add the reason, something like: Each MPTCP selftest is having
subtests, and it helps to give them a number to quickly identify them.
This can be managed by mptcp_lib.sh, reusing what has been done here.
The following commit will use these new helpers in the other tests.
> Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
> ---
> tools/testing/selftests/net/mptcp/mptcp_join.sh | 16 ++++++++--------
> tools/testing/selftests/net/mptcp/mptcp_lib.sh | 17 +++++++++++++++++
> 2 files changed, 25 insertions(+), 8 deletions(-)
>
> diff --git a/tools/testing/selftests/net/mptcp/mptcp_join.sh b/tools/testing/selftests/net/mptcp/mptcp_join.sh
> index 1df2d24979a0..7acc6064eb17 100755
> --- a/tools/testing/selftests/net/mptcp/mptcp_join.sh
> +++ b/tools/testing/selftests/net/mptcp/mptcp_join.sh
> @@ -48,7 +48,6 @@ declare -A all_tests
> declare -a only_tests_ids
> declare -a only_tests_names
> declare -A failed_tests
> -TEST_COUNT=0
> TEST_NAME=""
> nr_blank=6
>
> @@ -172,7 +171,8 @@ cleanup()
>
> print_title()
> {
> - printf "%03u %s\n" "${TEST_COUNT}" "${TEST_NAME}"
> + MPTCP_LIB_TEST_FORMAT="%03u %s\n"
No need to re-set it all the time, this line can be moved just before
"sourcing" mptcp_lib.sh I think, with a comment like:
# Here, we have more than 100 tests, having multiple checks
MPTCP_LIB_TEST_FORMAT="%03u %s\n"
. "$(dirname "${0}")/mptcp_lib.sh"
> + mptcp_lib_pr_title_counter "${TEST_NAME}"
> }
>
> print_check()
(...)
> diff --git a/tools/testing/selftests/net/mptcp/mptcp_lib.sh b/tools/testing/selftests/net/mptcp/mptcp_lib.sh
> index 763a2989ca6d..cbf0dd2cc4cb 100644
> --- a/tools/testing/selftests/net/mptcp/mptcp_lib.sh
> +++ b/tools/testing/selftests/net/mptcp/mptcp_lib.sh
> @@ -411,3 +411,20 @@ mptcp_lib_events() {
> ip netns exec "${ns}" ./pm_nl_ctl events >> "${evts}" 2>&1 &
> pid=$!
> }
> +
> +MPTCP_LIB_TEST_COUNTER=0
> +MPTCP_LIB_TEST_FORMAT=""
Can you declare them at the top, around the other ones?
(MPTCP_LIB_SUBTESTS, etc.)
And I think you should set the default value there too, like what I was
suggesting in patch 07/12 from v5:
: "${MPTCP_LIB_TEST_FORMAT:="%02u %-50s"}"
MPTCP_LIB_TEST_COUNTER=0
So we can change the format by setting MPTCP_LIB_TEST_FORMAT before
"sourcing" mptcp_lib.sh.
No?
*If* we need to alter the format just for one title, we can always do:
MPTCP_LIB_TEST_FORMAT="..." \
mptcp_lib_pr_title_counter "<title>"
But best to avoid that.
> +
> +mptcp_lib_inc_test_counter() {
> + : "${MPTCP_LIB_TEST_COUNTER:?}"
I don't think that's needed, it has been defined in the file, no?
> +
> + MPTCP_LIB_TEST_COUNTER=$((MPTCP_LIB_TEST_COUNTER+1))
> +}
> +
> +#shellcheck disable=SC2059
Please always justify why you need to ignore a rule.
Also, always try to reduce the scope as much as possible: just for one
line, for one function, for the whole file → here, move it just before
calling 'printf':
# shellcheck disable=SC2059 # the format is in a variable
printf "${MPTCP_LIB_TEST_FORMAT}" (...)
(and add a space after '#')
> +mptcp_lib_pr_title_counter() {
> + : "${MPTCP_LIB_TEST_COUNTER:?}"
> + : "${MPTCP_LIB_TEST_FORMAT:="%02u %-50s"}"
> +
> + printf "${MPTCP_LIB_TEST_FORMAT}" "${MPTCP_LIB_TEST_COUNTER}" "${*}"
I didn't check: can you not print the title and increment the counter
(via mptcp_lib_inc_test_counter) from here? I think that would be a good
practice to do that instead of having to deal with the counter in
different places.
We would only call "mptcp_lib_inc_test_counter()" from other scripts
when a test is skipped.
> +}
Cheers,
Matt
--
Sponsored by the NGI0 Core fund.
next prev parent reply other threads:[~2024-02-29 11:58 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-29 9:51 [PATCH mptcp-next v7 0/8] add helpers and vars in mptcp_lib.sh, part 3 Geliang Tang
2024-02-29 9:51 ` [PATCH mptcp-net v7 1/8] selftests: mptcp: diag: return KSFT_FAIL not test_cnt Geliang Tang
2024-02-29 10:51 ` Matthieu Baerts
2024-02-29 9:51 ` [PATCH mptcp-next v7 2/8] selftests: mptcp: connect: add dedicated port counter Geliang Tang
2024-02-29 11:23 ` Matthieu Baerts
2024-02-29 12:18 ` Geliang Tang
2024-02-29 12:22 ` Matthieu Baerts
2024-03-01 7:01 ` Geliang Tang
2024-02-29 9:51 ` [PATCH mptcp-next v7 3/8] selftests: mptcp: connect: fix misaligned output Geliang Tang
2024-02-29 9:51 ` [PATCH mptcp-next v7 4/8] selftests: mptcp: simult_flows: " Geliang Tang
2024-02-29 10:07 ` Geliang Tang
2024-02-29 10:27 ` Matthieu Baerts
2024-02-29 12:01 ` Geliang Tang
2024-02-29 12:18 ` Matthieu Baerts
2024-02-29 14:35 ` Matthieu Baerts
2024-02-29 9:51 ` [PATCH mptcp-next v7 5/8] selftests: mptcp: sockopt: unify ipv4/ipv6 as v4/v6 Geliang Tang
2024-02-29 11:31 ` Matthieu Baerts
2024-02-29 12:08 ` Geliang Tang
2024-02-29 12:20 ` Matthieu Baerts
2024-02-29 9:51 ` [PATCH mptcp-next v7 6/8] selftests: mptcp: add test counter helpers Geliang Tang
2024-02-29 11:58 ` Matthieu Baerts [this message]
2024-02-29 12:03 ` Matthieu Baerts
2024-02-29 12:28 ` Matthieu Baerts
2024-03-01 7:03 ` Geliang Tang
2024-02-29 9:51 ` [PATCH mptcp-next v7 7/8] selftests: mptcp: print test results with counters Geliang Tang
2024-02-29 12:44 ` Matthieu Baerts
2024-02-29 9:51 ` [PATCH mptcp-next v7 8/8] selftests: mptcp: print test results with colors Geliang Tang
2024-02-29 10:43 ` selftests: mptcp: print test results with colors: Tests Results MPTCP CI
2024-02-29 13:04 ` [PATCH mptcp-next v7 8/8] selftests: mptcp: print test results with colors Matthieu Baerts
2024-03-01 7:16 ` Geliang Tang
2024-03-04 11:12 ` 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=fea0084f-665b-4ea2-96cd-f9c025c02a28@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.