Re: [net-next PATCH v5 2/4] test: hsr: Move common code to hsr_common.sh file

From: Paolo Abeni
Date: Thu Apr 18 2024 - 04:41:54 EST


On Mon, 2024-04-15 at 14:49 +0200, Lukasz Majewski wrote:
> Some of the code already present in the hsr_ping.sh test program can be
> moved to a separate script file, so it can be reused by other HSR
> functionality (like HSR-SAN) tests.
>
> Signed-off-by: Lukasz Majewski <lukma@xxxxxxx>
> ---
> tools/testing/selftests/net/hsr/hsr_common.sh | 96 +++++++++++++++++++
> tools/testing/selftests/net/hsr/hsr_ping.sh | 93 +-----------------
> 2 files changed, 99 insertions(+), 90 deletions(-)
> create mode 100644 tools/testing/selftests/net/hsr/hsr_common.sh
>
> diff --git a/tools/testing/selftests/net/hsr/hsr_common.sh b/tools/testing/selftests/net/hsr/hsr_common.sh
> new file mode 100644
> index 000000000000..822165391573
> --- /dev/null
> +++ b/tools/testing/selftests/net/hsr/hsr_common.sh
> @@ -0,0 +1,96 @@
> +# SPDX-License-Identifier: GPL-2.0
> +# Common code for HSR testing scripts
> +
> +ret=0
> +ksft_skip=4
> +
> +sec=$(date +%s)
> +rndh=$(printf %x $sec)-$(mktemp -u XXXXXX)
> +ns1="ns1-$rndh"
> +ns2="ns2-$rndh"
> +ns3="ns3-$rndh"

Since you are touching the initialization code, please move it to using
the lib.sh helpers. The above will become:

setup_ns ns1 ns2 ns3

> +
> +cleanup()
> +{
> + local netns
> + for netns in "$ns1" "$ns2" "$ns3" ;do
> + ip netns del $netns
> + done
> +}

And this:

cleanup_all_ns


Thanks,

Paolo