* [PATCH net-next] selftests: forwarding: lib: rewrite processing of command line arguments
@ 2026-04-03 14:19 Ioana Ciornei
2026-04-06 15:31 ` Simon Horman
0 siblings, 1 reply; 3+ messages in thread
From: Ioana Ciornei @ 2026-04-03 14:19 UTC (permalink / raw)
To: netdev
Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Simon Horman, linux-kernel, petrm, willemb,
linux-kselftest
The piece of code which processes the command line arguments and
populates NETIFS based on them is really unobvious. Rewrite it so that
the intention is clear and the code is easy to follow.
Suggested-by: Petr Machata <petrm@nvidia.com>
Signed-off-by: Ioana Ciornei <ioana.ciornei@nxp.com>
---
tools/testing/selftests/net/forwarding/lib.sh | 22 +++++++++----------
1 file changed, 11 insertions(+), 11 deletions(-)
diff --git a/tools/testing/selftests/net/forwarding/lib.sh b/tools/testing/selftests/net/forwarding/lib.sh
index d8cc4c64148d..922cdaf2ceb9 100644
--- a/tools/testing/selftests/net/forwarding/lib.sh
+++ b/tools/testing/selftests/net/forwarding/lib.sh
@@ -466,18 +466,18 @@ if [ "${DRIVER_TEST_CONFORMANT}" = "yes" ]; then
NETIFS[p2]="$remote_netif"
TARGETS[$remote_netif]="$REMOTE_TYPE:$REMOTE_ARGS"
else
- count=0
+ # Prime NETIFS from the command line, but retain if none given.
+ if [[ $# -gt 0 ]]; then
+ unset NETIFS
+ declare -A NETIFS
- while [[ $# -gt 0 ]]; do
- if [[ "$count" -eq "0" ]]; then
- unset NETIFS
- declare -A NETIFS
- fi
- count=$((count + 1))
- NETIFS[p$count]="$1"
- TARGETS[$1]="local:"
- shift
- done
+ while [[ $# -gt 0 ]]; do
+ count=$((count + 1))
+ NETIFS[p$count]="$1"
+ TARGETS[$1]="local:"
+ shift
+ done
+ fi
fi
##############################################################################
--
2.25.1
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH net-next] selftests: forwarding: lib: rewrite processing of command line arguments
2026-04-03 14:19 [PATCH net-next] selftests: forwarding: lib: rewrite processing of command line arguments Ioana Ciornei
@ 2026-04-06 15:31 ` Simon Horman
2026-04-07 9:13 ` Ioana Ciornei
0 siblings, 1 reply; 3+ messages in thread
From: Simon Horman @ 2026-04-06 15:31 UTC (permalink / raw)
To: Ioana Ciornei
Cc: netdev, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, linux-kernel, petrm, willemb,
linux-kselftest
On Fri, Apr 03, 2026 at 05:19:12PM +0300, Ioana Ciornei wrote:
> The piece of code which processes the command line arguments and
> populates NETIFS based on them is really unobvious. Rewrite it so that
> the intention is clear and the code is easy to follow.
>
> Suggested-by: Petr Machata <petrm@nvidia.com>
> Signed-off-by: Ioana Ciornei <ioana.ciornei@nxp.com>
> ---
> tools/testing/selftests/net/forwarding/lib.sh | 22 +++++++++----------
> 1 file changed, 11 insertions(+), 11 deletions(-)
>
> diff --git a/tools/testing/selftests/net/forwarding/lib.sh b/tools/testing/selftests/net/forwarding/lib.sh
> index d8cc4c64148d..922cdaf2ceb9 100644
> --- a/tools/testing/selftests/net/forwarding/lib.sh
> +++ b/tools/testing/selftests/net/forwarding/lib.sh
> @@ -466,18 +466,18 @@ if [ "${DRIVER_TEST_CONFORMANT}" = "yes" ]; then
> NETIFS[p2]="$remote_netif"
> TARGETS[$remote_netif]="$REMOTE_TYPE:$REMOTE_ARGS"
> else
> - count=0
AI generated review on Sashiko.dev suggests that initialising count should
be retained to ensure correct behaviour in the (unlikely) case that count
is already set (to a non-zero value) in the environment.
And this seems like a good idea to me.
> + # Prime NETIFS from the command line, but retain if none given.
> + if [[ $# -gt 0 ]]; then
> + unset NETIFS
> + declare -A NETIFS
>
> - while [[ $# -gt 0 ]]; do
> - if [[ "$count" -eq "0" ]]; then
> - unset NETIFS
> - declare -A NETIFS
> - fi
> - count=$((count + 1))
> - NETIFS[p$count]="$1"
> - TARGETS[$1]="local:"
> - shift
> - done
> + while [[ $# -gt 0 ]]; do
> + count=$((count + 1))
> + NETIFS[p$count]="$1"
> + TARGETS[$1]="local:"
> + shift
> + done
> + fi
> fi
>
> ##############################################################################
> --
> 2.25.1
>
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH net-next] selftests: forwarding: lib: rewrite processing of command line arguments
2026-04-06 15:31 ` Simon Horman
@ 2026-04-07 9:13 ` Ioana Ciornei
0 siblings, 0 replies; 3+ messages in thread
From: Ioana Ciornei @ 2026-04-07 9:13 UTC (permalink / raw)
To: Simon Horman
Cc: netdev, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, linux-kernel, petrm, willemb,
linux-kselftest
On Mon, Apr 06, 2026 at 04:31:50PM +0100, Simon Horman wrote:
> On Fri, Apr 03, 2026 at 05:19:12PM +0300, Ioana Ciornei wrote:
> > The piece of code which processes the command line arguments and
> > populates NETIFS based on them is really unobvious. Rewrite it so that
> > the intention is clear and the code is easy to follow.
> >
> > Suggested-by: Petr Machata <petrm@nvidia.com>
> > Signed-off-by: Ioana Ciornei <ioana.ciornei@nxp.com>
> > ---
> > tools/testing/selftests/net/forwarding/lib.sh | 22 +++++++++----------
> > 1 file changed, 11 insertions(+), 11 deletions(-)
> >
> > diff --git a/tools/testing/selftests/net/forwarding/lib.sh b/tools/testing/selftests/net/forwarding/lib.sh
> > index d8cc4c64148d..922cdaf2ceb9 100644
> > --- a/tools/testing/selftests/net/forwarding/lib.sh
> > +++ b/tools/testing/selftests/net/forwarding/lib.sh
> > @@ -466,18 +466,18 @@ if [ "${DRIVER_TEST_CONFORMANT}" = "yes" ]; then
> > NETIFS[p2]="$remote_netif"
> > TARGETS[$remote_netif]="$REMOTE_TYPE:$REMOTE_ARGS"
> > else
> > - count=0
>
> AI generated review on Sashiko.dev suggests that initialising count should
> be retained to ensure correct behaviour in the (unlikely) case that count
> is already set (to a non-zero value) in the environment.
>
> And this seems like a good idea to me.
Ok. Will add this in v2.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-04-07 9:14 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-03 14:19 [PATCH net-next] selftests: forwarding: lib: rewrite processing of command line arguments Ioana Ciornei
2026-04-06 15:31 ` Simon Horman
2026-04-07 9:13 ` Ioana Ciornei
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox