From: Guillaume Nault <gnault@redhat.com>
To: Paolo Abeni <pabeni@redhat.com>
Cc: David Miller <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>,
Eric Dumazet <edumazet@google.com>,
netdev@vger.kernel.org, Simon Horman <horms@kernel.org>,
David Ahern <dsahern@kernel.org>,
Antonio Quartulli <antonio@mandelbit.com>,
Ido Schimmel <idosch@idosch.org>
Subject: Re: [PATCH net v3 2/2] selftests: Add IPv6 link-local address generation tests for GRE devices.
Date: Thu, 27 Feb 2025 17:47:14 +0100 [thread overview]
Message-ID: <Z8CXEngzSuTuWylx@debian> (raw)
In-Reply-To: <d1e3d6a6-90b8-45bd-a57f-c8175d0bd906@redhat.com>
On Thu, Feb 27, 2025 at 01:33:25PM +0100, Paolo Abeni wrote:
> On 2/25/25 3:43 PM, Guillaume Nault wrote:
> > diff --git a/tools/testing/selftests/net/gre_ipv6_lladdr.sh b/tools/testing/selftests/net/gre_ipv6_lladdr.sh
> > new file mode 100755
> > index 000000000000..85e40b6df55e
> > --- /dev/null
> > +++ b/tools/testing/selftests/net/gre_ipv6_lladdr.sh
> > @@ -0,0 +1,227 @@
> > +#!/bin/sh
> > +# SPDX-License-Identifier: GPL-2.0
> > +
> > +ERR=4 # Return 4 by default, which is the SKIP code for kselftest
> > +PAUSE_ON_FAIL="no"
> > +
> > +readonly NS0=$(mktemp -u ns0-XXXXXXXX)
> > +
> > +# Exit the script after having removed the network namespaces it created
> > +#
> > +# Parameters:
> > +#
> > +# * The list of network namespaces to delete before exiting.
> > +#
> > +exit_cleanup()
> > +{
> > + for ns in "$@"; do
> > + ip netns delete "${ns}" 2>/dev/null || true
> > + done
> > +
> > + if [ "${ERR}" -eq 4 ]; then
> > + echo "Error: Setting up the testing environment failed." >&2
> > + fi
> > +
> > + exit "${ERR}"
>
> I'm sorry for the late feedback, but if you use the helper from lib.sh
> you could avoid some code duplication for ns setup and cleanup.
I considered using lib.sh, after Ido's suggestion in v2
(https://lore.kernel.org/netdev/Z7sw1PPY48pkEMxB@shredder/). But I
finally decided to keep the selftest as-is because the small gain in
code size reduction didn't seem worth and because lib.sh makes the script
slower as it mandates the use of bash
(https://lore.kernel.org/netdev/Z73dm4P+Ho4EiprQ@debian/).
> > +}
> > +
> > +# Create the network namespaces used by the script (NS0)
> > +#
> > +create_namespaces()
> > +{
> > + ip netns add "${NS0}" || exit_cleanup
>
> Also no need to check for failures at this point. If there is no
> namespace support most/all selftests will fail badly
That allows to fail cleanly, with the error message about environment
setup failure.
> > +}
> > +
> > +# The trap function handler
> > +#
> > +exit_cleanup_all()
> > +{
> > + exit_cleanup "${NS0}"
> > +}
> > +
> > +# Add fake IPv4 and IPv6 networks on the loopback device, to be used as
> > +# underlay by future GRE devices.
> > +#
> > +setup_basenet()
> > +{
> > + ip -netns "${NS0}" link set dev lo up
> > + ip -netns "${NS0}" address add dev lo 192.0.2.10/24
> > + ip -netns "${NS0}" address add dev lo 2001:db8::10/64 nodad
> > +}
> > +
> > +# Check if network device has an IPv6 link-local address assigned.
> > +#
> > +# Parameters:
> > +#
> > +# * $1: The network device to test
> > +# * $2: An extra regular expression that should be matched (to verify the
> > +# presence of extra attributes)
> > +# * $3: The expected return code from grep (to allow checking the abscence of
> > +# a link-local address)
> > +# * $4: The user visible name for the scenario being tested
> > +#
> > +check_ipv6_ll_addr()
> > +{
> > + local DEV="$1"
> > + local EXTRA_MATCH="$2"
> > + local XRET="$3"
> > + local MSG="$4"
> > + local RET
> > +
> > + printf "%-75s " "${MSG}"
> > +
> > + set +e
> > + ip -netns "${NS0}" -6 address show dev "${DEV}" scope link | grep "fe80::" | grep -q "${EXTRA_MATCH}"
> > + RET=$?
> > + set -e
> > +
> > + if [ "${RET}" -eq "${XRET}" ]; then
> > + printf "[ OK ]\n"
>
> You can use check_err / log_test from lib.sh to reduce code duplication
> with other tests and more consistent output.
>
> > + else
> > + ERR=1
> > + printf "[FAIL]\n"
> > + if [ "${PAUSE_ON_FAIL}" = "yes" ]; then
> > + printf "\nHit enter to continue, 'q' to quit\n"
> > + read -r a
> > + if [ "$a" = "q" ]; then
> > + exit 1
> > + fi
> > + fi
>
> I guess something like this could be placed into lib.sh, but that would
> be net-next material
>
> Thanks,
>
> Paolo
>
prev parent reply other threads:[~2025-02-27 16:47 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-25 14:43 [PATCH net v3 0/2] gre: Fix regressions in IPv6 link-local address generation Guillaume Nault
2025-02-25 14:43 ` [PATCH net v3 1/2] gre: Fix " Guillaume Nault
2025-02-25 16:05 ` Ido Schimmel
2025-02-25 14:43 ` [PATCH net v3 2/2] selftests: Add IPv6 link-local address generation tests for GRE devices Guillaume Nault
2025-02-27 12:33 ` Paolo Abeni
2025-02-27 13:13 ` Petr Machata
2025-02-27 16:47 ` Guillaume Nault [this message]
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=Z8CXEngzSuTuWylx@debian \
--to=gnault@redhat.com \
--cc=antonio@mandelbit.com \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=idosch@idosch.org \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/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.