netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Petr Machata <petrm@nvidia.com>
To: Paolo Abeni <pabeni@redhat.com>
Cc: Guillaume Nault <gnault@redhat.com>,
	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 14:13:34 +0100	[thread overview]
Message-ID: <87v7svfqa0.fsf@nvidia.com> (raw)
In-Reply-To: <d1e3d6a6-90b8-45bd-a57f-c8175d0bd906@redhat.com>


Paolo Abeni <pabeni@redhat.com> writes:

> 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.
>
>> +}
>> +
>> +# 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
>
>> +}
>> +
>> +# 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

The pause-on-fail bits? lib.sh has them as pause_on_fail(). log_test()
invokes them on FAIL an XFAIL results.

FWIW, this is untested, but with lib.sh, I think it would be:

check_ipv6_ll_addr()
{
	local DEV="$1"
	local EXTRA_MATCH="$2"
	local XRET="$3"
	local MSG="$4"

	RET=0
        set +e
	ip -netns "${NS0}" -6 address show dev "${DEV}" scope link | grep "fe80::" | grep -q "${EXTRA_MATCH}"
        check_err_fail $XRET $? ""
        log_test "${MSG}"
        set -e
}

The set +e domain needs to extend over log_test() as well, because that
at one point calls log_test_result() with one fewer argument, and the
shift in there produces a non-zero exit code.

  reply	other threads:[~2025-02-27 13:53 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 [this message]
2025-02-27 16:47     ` Guillaume Nault

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=87v7svfqa0.fsf@nvidia.com \
    --to=petrm@nvidia.com \
    --cc=antonio@mandelbit.com \
    --cc=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=edumazet@google.com \
    --cc=gnault@redhat.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).