lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250805213356.3348348-4-dechen@redhat.com>
Date: Tue,  5 Aug 2025 17:33:56 -0400
From: Dennis Chen <dechen@...hat.com>
To: netdev@...r.kernel.org
Cc: dechen@...hat.com,
	dchen27@...u.edu,
	kuba@...nel.org,
	davem@...emloft.net,
	edumazet@...gle.com,
	pabeni@...hat.com,
	andrew+netdev@...n.ch,
	petrm@...dia.com
Subject: [PATCH net-next 3/3] selftests: netdevsim: Add test for ethtool stats

Add a test that verifies ethtool correctly exposes driver-specific
stats.

Signed-off-by: Dennis Chen <dechen@...hat.com>
---
 .../selftests/drivers/net/netdevsim/Makefile  |  1 +
 .../drivers/net/netdevsim/ethtool-common.sh   | 13 +++++++
 .../drivers/net/netdevsim/ethtool-stats.sh    | 36 +++++++++++++++++++
 3 files changed, 50 insertions(+)
 create mode 100755 tools/testing/selftests/drivers/net/netdevsim/ethtool-stats.sh

diff --git a/tools/testing/selftests/drivers/net/netdevsim/Makefile b/tools/testing/selftests/drivers/net/netdevsim/Makefile
index 07b7c46d3311..67055a403e74 100644
--- a/tools/testing/selftests/drivers/net/netdevsim/Makefile
+++ b/tools/testing/selftests/drivers/net/netdevsim/Makefile
@@ -8,6 +8,7 @@ TEST_PROGS = devlink.sh \
 	ethtool-fec.sh \
 	ethtool-pause.sh \
 	ethtool-ring.sh \
+	ethtool-stats.sh \
 	fib.sh \
 	fib_notifications.sh \
 	hw_stats_l3.sh \
diff --git a/tools/testing/selftests/drivers/net/netdevsim/ethtool-common.sh b/tools/testing/selftests/drivers/net/netdevsim/ethtool-common.sh
index 80160579e0cc..556ff74f443d 100644
--- a/tools/testing/selftests/drivers/net/netdevsim/ethtool-common.sh
+++ b/tools/testing/selftests/drivers/net/netdevsim/ethtool-common.sh
@@ -42,6 +42,19 @@ function check {
     ((num_passes++))
 }
 
+function check_code {
+    local code=$1
+    local msg=$2
+
+    if ((err)); then
+    echo -e $msg
+    ((num_errors++))
+    return
+    fi
+
+    ((num_passes++))
+}
+
 function make_netdev {
     # Make a netdevsim
     old_netdevs=$(ls /sys/class/net)
diff --git a/tools/testing/selftests/drivers/net/netdevsim/ethtool-stats.sh b/tools/testing/selftests/drivers/net/netdevsim/ethtool-stats.sh
new file mode 100755
index 000000000000..281bc24ddcd2
--- /dev/null
+++ b/tools/testing/selftests/drivers/net/netdevsim/ethtool-stats.sh
@@ -0,0 +1,36 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0-only
+
+source ethtool-common.sh
+
+set -o pipefail
+
+NSIM_NETDEV=$(make_netdev)
+MOCK_STATS_DFS=$NSIM_DEV_DFS/ethtool/mock_stats/enabled
+
+echo y > $MOCK_STATS_DFS
+
+stat=$(ethtool -S $NSIM_NETDEV | grep "hw_out_of_buffer" | awk '{print $2}')
+((stat == 0))
+check_code $? "ethtool stats show > 0 packets immediately after enabling"
+
+sleep 2.5
+
+stat=$(ethtool -S $NSIM_NETDEV | grep "hw_out_of_buffer" | awk '{print $2}')
+((stat >= 20))
+check_code $? "ethtool stats show < 20 packets after 2.5s passed"
+
+echo n > $MOCK_STATS_DFS
+echo y > $MOCK_STATS_DFS
+
+stat=$(ethtool -S $NSIM_NETDEV | grep "hw_out_of_buffer" | awk '{print $2}')
+((stat == 0))
+check_code $? "ethtool stats show > 0 packets after disabling and re-enabling"
+
+if [ $num_errors -eq 0 ]; then
+    echo "PASSED all $((num_passes)) checks"
+    exit 0
+else
+    echo "FAILED $num_errors/$((num_errors+num_passes)) checks"
+    exit 1
+fi
-- 
2.50.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ