diff mbox series

[v7,net-next,2/3] selftests: net: Add on/off checks for non-fixed features of interface

Message ID 20240815105924.1389290-3-jain.abhinav177@gmail.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series Enhance network interface feature testing | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 7 this patch: 7
netdev/build_tools success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers success CCed 6 of 6 maintainers
netdev/build_clang success Errors and warnings before: 7 this patch: 7
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success net selftest script(s) already in Makefile
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 7 this patch: 7
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 43 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-08-16--21-00 (tests: 710)

Commit Message

Abhinav Jain Aug. 15, 2024, 10:59 a.m. UTC
Implement on/off testing for all non-fixed features via while loop.
Save the initial state so that it can be restored after on/off checks.

Signed-off-by: Abhinav Jain <jain.abhinav177@gmail.com>
---
 tools/testing/selftests/net/netdevice.sh | 37 +++++++++++++++++++++++-
 1 file changed, 36 insertions(+), 1 deletion(-)

Comments

Simon Horman Aug. 15, 2024, 1:03 p.m. UTC | #1
On Thu, Aug 15, 2024 at 04:29:23PM +0530, Abhinav Jain wrote:
> Implement on/off testing for all non-fixed features via while loop.
> Save the initial state so that it can be restored after on/off checks.
> 
> Signed-off-by: Abhinav Jain <jain.abhinav177@gmail.com>
> ---
>  tools/testing/selftests/net/netdevice.sh | 37 +++++++++++++++++++++++-
>  1 file changed, 36 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/testing/selftests/net/netdevice.sh b/tools/testing/selftests/net/netdevice.sh
> index 0c32950fdd17..50f7b9d1163d 100755
> --- a/tools/testing/selftests/net/netdevice.sh
> +++ b/tools/testing/selftests/net/netdevice.sh
> @@ -124,7 +124,42 @@ 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"
> +		[ "$FIXED" != "[fixed]" ] || continue # Skip fixed features
> +		feature="${FEATURE%:*}"
> +
> +		initial_state=$(ethtool -k "$netdev" | grep "$feature:" \
> +			| awk '{print $2}')

Hi Abhinav,

Isn't the value being read into $initial_state here already present in $VALUE?

> +		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 default $initial_state"
> +		fi
> +
> +	done < "$TMP_ETHTOOL_FEATURES"
> +
>  	rm "$TMP_ETHTOOL_FEATURES"
>  
>  	kci_netdev_ethtool_test 74 'dump' "ethtool -d $netdev"
> -- 
> 2.34.1
> 
>
Abhinav Jain Aug. 15, 2024, 4:46 p.m. UTC | #2
On Thu, 15 Aug 2024 14:03:53 +0100, Simon Horman wrote:

> Hi Abhinav,
> 
> Isn't the value being read into $initial_state here already present in $VALUE?

Yes, that is correct. I will wait for a day and send v8 using $VALUE.
Thanks.
---
diff mbox series

Patch

diff --git a/tools/testing/selftests/net/netdevice.sh b/tools/testing/selftests/net/netdevice.sh
index 0c32950fdd17..50f7b9d1163d 100755
--- a/tools/testing/selftests/net/netdevice.sh
+++ b/tools/testing/selftests/net/netdevice.sh
@@ -124,7 +124,42 @@  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"
+		[ "$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 default $initial_state"
+		fi
+
+	done < "$TMP_ETHTOOL_FEATURES"
+
 	rm "$TMP_ETHTOOL_FEATURES"
 
 	kci_netdev_ethtool_test 74 'dump' "ethtool -d $netdev"