netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3] sefltests: net: Add on/off checks for network interface non fixed features
@ 2024-06-14 11:32 Abhinav Jain
  2024-06-15  1:50 ` Jakub Kicinski
  0 siblings, 1 reply; 2+ messages in thread
From: Abhinav Jain @ 2024-06-14 11:32 UTC (permalink / raw)
  To: kuba, horms, davem, edumazet, pabeni, shuah, netdev,
	linux-kselftest, linux-kernel
  Cc: skhan, javier.carrasco.cruz, jain.abhinav177

This patch addresses the TODO (add non fixed feature on/off check).
I have tested it manually on my system after making changes as suggested
in v1 and v2 linked below for reference.
Patch now restores the features being tested to their initial state.

Signed-off-by: Abhinav Jain <jain.abhinav177@gmail.com>
---
PATCH v2:
https://lore.kernel.org/all/20240609132124.51683-1-jain.abhinav177@gmail.com/

Changes since v2:
 - Added a check for netdev if it exists.
 - If netdev doesn't exist, create a veth pair for testing.
 - Restore the feature being tested to its intial state.

PATCH v1:
https://lore.kernel.org/all/20240606212714.27472-1-jain.abhinav177@gmail.com/

Changes since v1:
 - Removed the addition of tail command as it was not required after
   below change.
 - Used read to parse the temp features file rather than using for loop
   and took out awk/grep/sed from v1.
---
 tools/testing/selftests/net/netdevice.sh | 55 +++++++++++++++++++++++-
 1 file changed, 54 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/net/netdevice.sh b/tools/testing/selftests/net/netdevice.sh
index e3afcb424710..d937d39dda6a 100755
--- a/tools/testing/selftests/net/netdevice.sh
+++ b/tools/testing/selftests/net/netdevice.sh
@@ -104,6 +104,20 @@ kci_netdev_ethtool()
 {
 	netdev=$1
 
+	#check if netdev is provided as an argument
+	if [ -z "$netdev" ]; then
+		echo "No network device provided, creating a veth pair"
+		ip link add veth0 type veth peer name veth1
+		netdev="veth0"
+		veth_created=1
+	else
+		#check if the provided netdev exists
+		if ! ip link show "$netdev" > /dev/null 2>&1; then
+			echo "Network device $netdev does not exist."
+			return 1
+		fi
+	fi
+
 	#check presence of ethtool
 	ethtool --version 2>/dev/null >/dev/null
 	if [ $? -ne 0 ];then
@@ -124,11 +138,50 @@ kci_netdev_ethtool()
 		return 1
 	fi
 	echo "PASS: $netdev: ethtool list features"
-	#TODO for each non fixed features, try to turn them on/off
+
+	while read -r FEATURE VALUE FIXED; do
+		[ "$FEATURE" != "Features" ] || continue # Skip "Features" line
+		[ "$FIXED" != "[fixed]" ] || continue # Skip fixed features
+		feature = "${FEATURE%:*}"
+
+		initial_state=$(ethtool -k "$netdev" | grep "$feature:" | awk '{print $2}')
+		ethtool --offload "$netdev" "$feature" off
+		if [ $? -eq 0 ]; then
+			echo "PASS: $netdev: Turned off feature: $feature"
+		else
+			echo "FAIL: $netdev: Failed to turn off feature: $feature"
+		fi
+
+		ethtool --offload "$netdev" "$feature" on
+		if [ $? -eq 0 ]; then
+			echo "PASS: $netdev: Turned on feature: $feature"
+		else
+			echo "FAIL: $netdev: Failed to turn on feature: $feature"
+		fi
+
+		#restore the feature to its initial state
+		ethtool --offload "$netdev" "$feature" "$initial_state"
+		if [$? -eq 0]; then
+			echo "PASS: $netdev: Restore feature $feature to" \
+				" initial state $initial_state"
+		else
+			echo "FAIL: $netdev: Failed to restore feature " \
+				"$feature to initial state $initial_state"
+		fi
+
+	done < "$TMP_ETHTOOL_FEATURES"
+
 	rm "$TMP_ETHTOOL_FEATURES"
 
 	kci_netdev_ethtool_test 74 'dump' "ethtool -d $netdev"
 	kci_netdev_ethtool_test 94 'stats' "ethtool -S $netdev"
+
+	#clean up veth interface pair if it was created
+	if ["$veth_created" ]; then
+		ip link delete veth0
+		echo "Removed veth pair"
+	fi
+
 	return 0
 }
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v3] sefltests: net: Add on/off checks for network interface non fixed features
  2024-06-14 11:32 [PATCH v3] sefltests: net: Add on/off checks for network interface non fixed features Abhinav Jain
@ 2024-06-15  1:50 ` Jakub Kicinski
  0 siblings, 0 replies; 2+ messages in thread
From: Jakub Kicinski @ 2024-06-15  1:50 UTC (permalink / raw)
  To: Abhinav Jain
  Cc: horms, davem, edumazet, pabeni, shuah, netdev, linux-kselftest,
	linux-kernel, skhan, javier.carrasco.cruz

On Fri, 14 Jun 2024 11:32:40 +0000 Abhinav Jain wrote:
> This patch addresses the TODO (add non fixed feature on/off check).
> I have tested it manually on my system after making changes as suggested
> in v1 and v2 linked below for reference.
> Patch now restores the features being tested to their initial state.

Can you separate the features on/off and auto-adding veth into two
commits/patches? Then send them as a series?

> diff --git a/tools/testing/selftests/net/netdevice.sh b/tools/testing/selftests/net/netdevice.sh
> index e3afcb424710..d937d39dda6a 100755
> --- a/tools/testing/selftests/net/netdevice.sh
> +++ b/tools/testing/selftests/net/netdevice.sh
> @@ -104,6 +104,20 @@ kci_netdev_ethtool()
>  {
>  	netdev=$1
>  
> +	#check if netdev is provided as an argument
> +	if [ -z "$netdev" ]; then
> +		echo "No network device provided, creating a veth pair"
> +		ip link add veth0 type veth peer name veth1
> +		netdev="veth0"
> +		veth_created=1
> +	else
> +		#check if the provided netdev exists
> +		if ! ip link show "$netdev" > /dev/null 2>&1; then
> +			echo "Network device $netdev does not exist."
> +			return 1
> +		fi
> +	fi

I don't think this will work, since the function won't get called at
all if there is no netdev. You need to do the auto-adding around the

while read netdev

loop.

To test locally you can use network namespaces, or build and boot a
network-less kernel using vng:
https://github.com/linux-netdev/nipa/wiki/How-to-run-netdev-selftests-CI-style

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-06-15  1:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-14 11:32 [PATCH v3] sefltests: net: Add on/off checks for network interface non fixed features Abhinav Jain
2024-06-15  1:50 ` Jakub Kicinski

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).