Skip to contentSkip to conversation

selftests: drivers: bash support for remote traffic generators

PATCH Applied Ioana Ciornei 4 participants 15 messages Mar 30 – Apr 3

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

v5 cover selftests: drivers: bash support for remote traffic generators

This patch set aims to add the necessary support so that bash written selftests are also able to easily run with a remote traffic generator system, either be it in another netns or one accessible through ssh.

This patch set is a result of the discussion from v1:
https://lore.kernel.org/all/[email protected]/
Even though the python infrastructure is already established, some things are easier in bash and it would be a shame to leave behind the bash tests that we already have.

This support is based on the requirements described in the tools/testing/selftests/drivers/net/README.rst file.

Mainly, the drivers/net selftests should be able to run on a interface specified through the NETIF env variable. On top of that, variables such as REMOTE_TYPE and REMOTE_ARGS define how the remote traffic generator can be accessed. Patch 3/10 parses these env variables and constructs the NETIFS array that bash tests are accustomed to. This is with the intention of enabling already written tests to incur minimal changes.

The second patch also defines the TARGETS array which will hold the necessary information about the target on which a specific interface is located.

For example, a net.config which looks like below:

	NETIF=eth0
	LOCAL_V4=192.168.1.1
	REMOTE_V4=192.168.1.2
	REMOTE_TYPE=ssh
	[email protected]

will generate the NETIFS and TARGETS arrays with the following data.

	NETIFS[p1]="eth0"
	NETIFS[p2]="eth2"

	TARGETS[eth0]="local:"
	TARGETS[eth2]="ssh:[email protected]"

The above will be true if on the remote target, the interface which has the 192.168.1.2 address is named eth2.

The values held in the TARGETS array will be used by the new 'run_on' helper added in patch 2/10 to know how to run a specific command, on the local system, on another netns or by using ssh. Patch 4/10 updates some helpers to use run_on so that, for example, lib.sh is able to ensure stable MAC addresses even with the remote interface located in another netns.

The next 5 patches, 5/10-9/10 update the ethtool_rmon.sh script so that it can work with the kselftest infrastructure and the new NETIF/REMOTE_TYPE etc way of working. Beside updating each ip link or ethtool command to use the run_on helper, the patches also remove any testing done on the remote interface.

The last patch adds a new test which checks the standard counters - eth-ctrl, eth-mac and pause - and uses the new infrastructure put in place by the first patches.

With this patch set, both tests can be run using a net.config file and run_kselftest.sh as shown below.

 $ make -C tools/testing/selftests/ TARGETS="drivers/net drivers/net/hw" \
 install INSTALL_PATH=/tmp/ksft-net-drv
 $ cd /tmp/ksft-net-drv/
 $ cat > ./drivers/net/net.config <<EOF
 NETIF=endpmac17
 LOCAL_V4=17.0.0.1
 REMOTE_V4=17.0.0.2
 REMOTE_TYPE=ssh
 [email protected]
 EOF
 $ ./run_kselftest.sh -t drivers/net/hw:ethtool_rmon.sh
 TAP version 13
 1..1
 # timeout set to 0
 # selftests: drivers/net/hw: ethtool_rmon.sh
 # TAP version 13
 # 1..14
 # ok 1 ethtool_rmon.rx-pkts64to64
 # ok 2 ethtool_rmon.rx-pkts65to127
 # ok 3 ethtool_rmon.rx-pkts128to255
 # ok 4 ethtool_rmon.rx-pkts256to511
 # ok 5 ethtool_rmon.rx-pkts512to1023
 # ok 6 ethtool_rmon.rx-pkts1024to1518
 # ok 7 ethtool_rmon.rx-pkts1519to10240
 # ok 8 ethtool_rmon.tx-pkts64to64
 # ok 9 ethtool_rmon.tx-pkts65to127
 # ok 10 ethtool_rmon.tx-pkts128to255
 # ok 11 ethtool_rmon.tx-pkts256to511
 # ok 12 ethtool_rmon.tx-pkts512to1023
 # ok 13 ethtool_rmon.tx-pkts1024to1518
 # ok 14 ethtool_rmon.tx-pkts1519to10240
 # # Totals: pass:14 fail:0 xfail:0 xpass:0 skip:0 error:0
 ok 1 selftests: drivers/net/hw: ethtool_rmon.sh
 $ ./run_kselftest.sh -t drivers/net/hw:ethtool_std_stats.sh
 TAP version 13
 1..1
 # timeout set to 0
 # selftests: drivers/net/hw: ethtool_std_stats.sh
 # TAP version 13
 # 1..26
 # ok 1 ethtool_std_stats.eth-ctrl-MACControlFramesTransmitted
 # ok 2 ethtool_std_stats.eth-ctrl-MACControlFramesReceived
 # ok 3 ethtool_std_stats.eth-mac-FrameCheckSequenceErrors
 # ok 4 ethtool_std_stats.eth-mac-AlignmentErrors
 # ok 5 ethtool_std_stats.eth-mac-FramesLostDueToIntMACXmitError
 # ok 6 ethtool_std_stats.eth-mac-CarrierSenseErrors # SKIP
 # ok 7 ethtool_std_stats.eth-mac-FramesLostDueToIntMACRcvError
 # ok 8 ethtool_std_stats.eth-mac-InRangeLengthErrors # SKIP
 # ok 9 ethtool_std_stats.eth-mac-OutOfRangeLengthField # SKIP
 # ok 10 ethtool_std_stats.eth-mac-FrameTooLongErrors # SKIP
 # ok 11 ethtool_std_stats.eth-mac-FramesAbortedDueToXSColls # SKIP
 # ok 12 ethtool_std_stats.eth-mac-SingleCollisionFrames # SKIP
 # ok 13 ethtool_std_stats.eth-mac-MultipleCollisionFrames # SKIP
 # ok 14 ethtool_std_stats.eth-mac-FramesWithDeferredXmissions # SKIP
 # ok 15 ethtool_std_stats.eth-mac-LateCollisions # SKIP
 # ok 16 ethtool_std_stats.eth-mac-FramesWithExcessiveDeferral # SKIP
 # ok 17 ethtool_std_stats.eth-mac-BroadcastFramesXmittedOK
 # ok 18 ethtool_std_stats.eth-mac-OctetsTransmittedOK
 # ok 19 ethtool_std_stats.eth-mac-BroadcastFramesReceivedOK
 # ok 20 ethtool_std_stats.eth-mac-OctetsReceivedOK
 # ok 21 ethtool_std_stats.eth-mac-FramesTransmittedOK
 # ok 22 ethtool_std_stats.eth-mac-MulticastFramesXmittedOK
 # ok 23 ethtool_std_stats.eth-mac-FramesReceivedOK
 # ok 24 ethtool_std_stats.eth-mac-MulticastFramesReceivedOK
 # ok 25 ethtool_std_stats.pause-tx_pause_frames
 # ok 26 ethtool_std_stats.pause-rx_pause_frames
 # # 10 skipped test(s) detected.  Consider enabling relevant config options to improve coverage.
 # # Totals: pass:16 fail:0 xfail:0 xpass:0 skip:10 error:0
 ok 1 selftests: drivers/net/hw: ethtool_std_stats.sh

Changes in v5:
- 2/10: move 'shellcheck disable' at start of the script
- 2/10: move 'declare -A TARGETS' before the if statement
- 2/10: move the DRIVER_TEST_CONFORMANT declaration before the if statement
- 2/10: move the __run_on() and run_on() helpers in net/forwarding/lib.sh
- 2/10: add a stub run_on() in net/lib.sh
- 2/10: check for DRIVER_TEST_CONFORMANT = yes in run_on()
- 2/10: squash patches 2 and 3 since with the change above each patch depends on the other one. There is no point keeping them separate.

Changes in v4:
- 1/10: wrap the lines to max 80 chars
- 1/10: replace the if-else with a simple if and return in order to be easier to maintain the 80 chars limit.
- 2/10: reworked the helpers so that no global variable is used and information is passed only through parameters
- 3/10: reword the entry in README.rst to mention that the different interface names is only a bash restriction and the python infrastructure does not have the same problem.
- 3/10: only declare the TARGETS array when necessary
- 3/10: add a new flags - DRIVER_TEST_CONFORMANT - that needs to be set by the test
- 3/10: rework the check_env() function so that its logic is simpler
- 3/10: source drivers/net/net.config only if DRIVER_TEST_CONFORMANT == yes
- 3/10: check that NETIF and the remote netif have different names and abort test is not
- 4/10: split some lines to 80 chars
- 5/10: split one line to 80 chars
- 8/10: patch is added in this version so that ethtool_rmon.sh is converted to KTAP output
- 9/10: set DRIVER_TEST_CONFORMANT to yes
- 9/10: update the commit message to reflect the current output
- 9/10: split some more lines to 80 chars
- 10/10: move to a the KTAP format output by using ktap_helpers.sh
- 10/10: update commit message to reflect the current output
- 10/10: use DRIVER_TEST_CONFORMANT

Changes in v3:
- Change the TARGET variable into CUR_TARGET
- Always fallback on running a command locally when either TARGETS is not declared or there is no entry for a specific interface
- Swap patches 2 & 3 between them so that the run_cmd used in now patch #2 is defined in patch #2
- Add some more double quoting

Changes in v2:
- 1/9: Convert jq to the --arg usage form
- Patches 2/9-8/9 are new in this version
- 9/9: Use the new run_on helper
- 9/9: No longer checking that each counter has a 1% tolerance against the target. The only upper limit is UINT32_MAX.
- 9/9: Check that both the error counters and the collision related ones are zero since this is the most probable scenario (we don't expect errors with the traffic that we are sending).
- 9/9: Removed any checks performed on the remot interface counters since that is being used only as a traffic generator.

Ioana Ciornei (9):
selftests: forwarding: extend ethtool_std_stats_get with pause
statistics
selftests: net: extend lib.sh to parse drivers/net/net.config
selftests: net: update some helpers to use run_on
selftests: drivers: hw: cleanup shellcheck warnings in the rmon test
selftests: drivers: hw: test rmon counters only on first interface
selftests: drivers: hw: replace counter upper limit with UINT32_MAX in
rmon test
selftests: drivers: hw: move to KTAP output
selftests: drivers: hw: update ethtool_rmon to work with a single
local interface
selftests: drivers: hw: add test for the ethtool standard counters

 .../testing/selftests/drivers/net/README.rst  |   4 +
 .../testing/selftests/drivers/net/hw/Makefile |   1 +
 .../selftests/drivers/net/hw/ethtool_rmon.sh  |  82 ++++---
 .../drivers/net/hw/ethtool_std_stats.sh       | 206 ++++++++++++++++++
 tools/testing/selftests/net/forwarding/lib.sh | 171 +++++++++++++--
 tools/testing/selftests/net/lib.sh            |   8 +-
 6 files changed, 421 insertions(+), 51 deletions(-)
 create mode 100755 tools/testing/selftests/drivers/net/hw/ethtool_std_stats.sh
Signature · 1 line
2.25.1
#1 lore raw

PATCH v5 1/9 selftests: forwarding: extend ethtool_std_stats_get with pause statistics

Even though pause frame statistics are not exported through the same ethtool command, there is no point in adding another helper just for them. Extent the ethtool_std_stats_get() function so that we are able to interrogate using the same helper all the standard statistics.

And since we are touching the function, convert the initial ethtool call as well to the jq --arg form in order to be easier to read.

---
Changes in v5:
- none
Changes in v4:
- wrap the lines to max 80 chars
- replace the if-else with a simple if and return in order to be easier to maintain the 80 chars limit.
Changes in v3:
- none
Changes in v2:
- convert jq to the --arg usage form

 tools/testing/selftests/net/forwarding/lib.sh | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
tools/testing/selftests/net/forwarding/lib.sh +8 -2
index a9034f0bb58b..3009ce00c5dc 100644
@@ -831,8 +831,14 @@ ethtool_std_stats_get()
 	local name=$1; shift
 	local src=$1; shift
 
-	ethtool --json -S $dev --groups $grp -- --src $src | \
-		jq '.[]."'"$grp"'"."'$name'"'
+	if [[ "$grp" == "pause" ]]; then
+		ethtool -I --json -a "$dev" --src "$src" | \
+			jq --arg name "$name" '.[].statistics[$name]'
+		return
+	fi
+
+	ethtool --json -S "$dev" --groups "$grp" -- --src "$src" | \
+		jq --arg grp "$grp" --arg name "$name" '.[][$grp][$name]'
 }
 
 qdisc_stats_get()
Signature · 1 line
2.25.1
#2 lore raw

PATCH v5 2/9 selftests: net: extend lib.sh to parse drivers/net/net.config

In reply to Ioana Ciornei

Extend lib.sh so that it's able to parse driver/net/net.config and environment variables such as NETIF, REMOTE_TYPE, LOCAL_V4 etc described in drivers/net/README.rst.

In order to make the transition towards running with a single local interface smoother for the bash networking driver tests, beside sourcing the net.config file also translate the new env variables into the old style based on the NETIFS array. Since the NETIFS array only holds the network interface names, also add a new array - TARGETS - which keeps track of the target on which a specific interfaces resides - local, netns or accesible through an ssh command.

For example, a net.config which looks like below:

	NETIF=eth0
	LOCAL_V4=192.168.1.1
	REMOTE_V4=192.168.1.2
	REMOTE_TYPE=ssh
	[email protected]

will generate the NETIFS and TARGETS arrays with the following data.

	NETIFS[p1]="eth0"
	NETIFS[p2]="eth2"

	TARGETS[eth0]="local:"
	TARGETS[eth2]="ssh:[email protected]"

The above will be true if on the remote target, the interface which has the 192.168.1.2 address is named eth2.

Since the TARGETS array is indexed by the network interface name, document a new restriction README.rst which states that the remote interface cannot have the same name as the local one. Keep the old way of populating the NETIFS variable based on the command line arguments. This will be invoked in case DRIVER_TEST_CONFORMANT = "no".

Also add a couple of helpers which can be used by tests which need to run a specific bash command on a different target than the local system, be it either another netns or a remote system accessible through ssh. The __run_on() function is passed through $1 the target on which the command should be executed while run_on() is passed the name of the interface that is then used to retrieve the target from the TARGETS array.

Also add a stub run_on() function in net/lib.sh so that users of the net/lib.sh are going through the stub only since neither NETIFS nor TARGETS are valid in that circumstance.

---
Changes in v5:
- move 'shellcheck disable' at start of the script
- move 'declare -A TARGETS' before the if statement
- move the DRIVER_TEST_CONFORMANT declaration before the if statement
- move the __run_on() and run_on() helpers in net/forwarding/lib.sh
- add a stub run_on() in net/lib.sh
- check for DRIVER_TEST_CONFORMANT = yes in run_on()
- squash patches 2 and 3 since with the change above each patch depends on the other one. There is no point keeping them separate.
Changes in v4:
- reworked the helpers so that no global variable is used and information is passed only through parameters
- reword the entry in README.rst to mention that the different interface names is only a bash restriction and the python infrastructure does not have the same problem.
- only declare the TARGETS array at the point where it's necessary, instead of it being an user API.
- add a new flags - DRIVER_TEST_CONFORMANT - that needs to be set by the test
- rework the check_env() function so that its logic is simpler
- source drivers/net/net.config only if DRIVER_TEST_CONFORMANT == yes
- check that NETIF and the remote netif have different names and abort test is not
Changes in v3:
- s/TARGET/CUR_TARGET
- always fallback on running a command locally when either TARGETS is not declared or there is no entry for a specific interface
Changes in v2:
- patch is new

 .../testing/selftests/drivers/net/README.rst  |   4 +
 tools/testing/selftests/net/forwarding/lib.sh | 146 ++++++++++++++++--
 tools/testing/selftests/net/lib.sh            |   5 +
 3 files changed, 146 insertions(+), 9 deletions(-)
tools/testing/selftests/drivers/net/README.rst +4 -0
index c94992acf10b..1897aa1583ec 100644
@@ -26,6 +26,10 @@ The netdevice against which tests will be run must exist, be running
 Refer to list of :ref:`Variables` later in this file to set up running
 the tests against a real device.
 
+The current support for bash tests restricts the use of the same interface name
+on the local system and the remote one and will bail if this case is
+encountered.
+
 Both modes required
 ~~~~~~~~~~~~~~~~~~~
 
tools/testing/selftests/net/forwarding/lib.sh +137 -9

159 lines not on this page · raw message

tools/testing/selftests/net/lib.sh +5 -0
index b40694573f4c..3f79bf1ec977 100644
@@ -670,3 +670,8 @@ cmd_jq()
 	# return success only in case of non-empty output
 	[ ! -z "$output" ]
 }
+
+run_on()
+{
+	shift; "$@"
+}
Signature · 1 line
2.25.1
Reviewed-by on v5 2/9
#3 lore raw

Re: [PATCH net-next v5 2/9] selftests: net: extend lib.sh to parse drivers/net/net.config

Quoted 45 lines · Ioana Ciornei

Extend lib.sh so that it's able to parse driver/net/net.config and environment variables such as NETIF, REMOTE_TYPE, LOCAL_V4 etc described in drivers/net/README.rst.

In order to make the transition towards running with a single local interface smoother for the bash networking driver tests, beside sourcing the net.config file also translate the new env variables into the old style based on the NETIFS array. Since the NETIFS array only holds the network interface names, also add a new array - TARGETS - which keeps track of the target on which a specific interfaces resides - local, netns or accesible through an ssh command.

For example, a net.config which looks like below:

	NETIF=eth0
	LOCAL_V4=192.168.1.1
	REMOTE_V4=192.168.1.2
	REMOTE_TYPE=ssh
	[email protected]

will generate the NETIFS and TARGETS arrays with the following data.

	NETIFS[p1]="eth0"
	NETIFS[p2]="eth2"

	TARGETS[eth0]="local:"
	TARGETS[eth2]="ssh:[email protected]"

The above will be true if on the remote target, the interface which has the 192.168.1.2 address is named eth2.

Since the TARGETS array is indexed by the network interface name, document a new restriction README.rst which states that the remote interface cannot have the same name as the local one. Keep the old way of populating the NETIFS variable based on the command line arguments. This will be invoked in case DRIVER_TEST_CONFORMANT = "no".

Also add a couple of helpers which can be used by tests which need to run a specific bash command on a different target than the local system, be it either another netns or a remote system accessible through ssh. The __run_on() function is passed through $1 the target on which the command should be executed while run_on() is passed the name of the interface that is then used to retrieve the target from the TARGETS array.

Quoted 5 lines

Also add a stub run_on() function in net/lib.sh so that users of the net/lib.sh are going through the stub only since neither NETIFS nor TARGETS are valid in that circumstance.

tools/testing/selftests/net/forwarding/lib.sh fi · line 476

Quoted 9 lines
tools/testing/selftests/net/forwarding/lib.sh +9 -0
+else
+	count=0
+
+	while [[ $# -gt 0 ]]; do
+		if [[ "$count" -eq "0" ]]; then
+			unset NETIFS
+			declare -A NETIFS
+		fi
+		count=$((count + 1))

This is coming from the original as well, but I find the piece of code really unobvious. I'm not going to block the patchset over this, but this would IMHO be a better way to express the intent:

	# Prime NETIFS from the command line, but retain if none given.
	if [[ $# -gt 0 ]]; then
		unset NETIFS
		declare -A NETIFS

		while [[ $# -gt 0 ]]; do
			((count++))
			etc
		done
	fi

If there is a v6, please roll it in.

Quoted 5 lines
tools/testing/selftests/net/forwarding/lib.sh +5 -0
+		NETIFS[p$count]="$1"
+		TARGETS[$1]="local:"
+		shift
+	done
+fi
#4 lore raw

PATCH v5 3/9 selftests: net: update some helpers to use run_on

In reply to Ioana Ciornei

Update some helpers so that they are capable to run commands on different targets than the local one. This patch makes the necesasy modification for those helpers / sections of code which are needed for the ethtool_rmon.sh test that will be converted in the next patches.

For example, mac_addr_prepare() and mac_addr_restore() used when STABLE_MAC_ADDRS=yes need to ensure stable MAC addresses on interfaces located even in other namespaces. In order to do that, append the 'ip link' commands with a 'run_on $dev' tag.

The same run_on is necessary also when verifying if all the interfaces listed in NETIFS are indeed available.

---
Changes in v5:
- none
Changes in v4:
- split some lines to 80 chars
Changes in v3:
- added some more double quotes
Changes in v2:
- patch is new

 tools/testing/selftests/net/forwarding/lib.sh | 19 ++++++++++++-------
 tools/testing/selftests/net/lib.sh            |  3 ++-
 2 files changed, 14 insertions(+), 8 deletions(-)
tools/testing/selftests/net/forwarding/lib.sh +12 -7
index 83249aafa669..d8cc4c64148d 100644
@@ -546,10 +546,11 @@ mac_addr_prepare()
 		dev=${NETIFS[p$i]}
 		new_addr=$(printf "00:01:02:03:04:%02x" $i)
 
-		MAC_ADDR_ORIG["$dev"]=$(ip -j link show dev $dev | jq -e '.[].address')
+		MAC_ADDR_ORIG["$dev"]=$(run_on "$dev" \
+			ip -j link show dev "$dev" | jq -e '.[].address')
 		# Strip quotes
 		MAC_ADDR_ORIG["$dev"]=${MAC_ADDR_ORIG["$dev"]//\"/}
-		ip link set dev $dev address $new_addr
+		run_on "$dev" ip link set dev "$dev" address $new_addr
 	done
 }
 
@@ -559,7 +560,8 @@ mac_addr_restore()
 
 	for ((i = 1; i <= NUM_NETIFS; ++i)); do
 		dev=${NETIFS[p$i]}
-		ip link set dev $dev address ${MAC_ADDR_ORIG["$dev"]}
+		run_on "$dev" \
+			ip link set dev "$dev" address ${MAC_ADDR_ORIG["$dev"]}
 	done
 }
 
@@ -572,7 +574,9 @@ if [[ "$STABLE_MAC_ADDRS" = "yes" ]]; then
 fi
 
 for ((i = 1; i <= NUM_NETIFS; ++i)); do
-	ip link show dev ${NETIFS[p$i]} &> /dev/null
+	int="${NETIFS[p$i]}"
+
+	run_on "$int" ip link show dev "$int" &> /dev/null
 	if [[ $? -ne 0 ]]; then
 		echo "SKIP: could not find all required interfaces"
 		exit $ksft_skip
@@ -655,7 +659,7 @@ setup_wait_dev_with_timeout()
 	local i
 
 	for ((i = 1; i <= $max_iterations; ++i)); do
-		ip link show dev $dev up \
+		run_on "$dev" ip link show dev "$dev" up \
 			| grep 'state UP' &> /dev/null
 		if [[ $? -ne 0 ]]; then
 			sleep 1
@@ -960,12 +964,13 @@ ethtool_std_stats_get()
 	local src=$1; shift
 
 	if [[ "$grp" == "pause" ]]; then
-		ethtool -I --json -a "$dev" --src "$src" | \
+		run_on "$dev" ethtool -I --json -a "$dev" --src "$src" | \
 			jq --arg name "$name" '.[].statistics[$name]'
 		return
 	fi
 
-	ethtool --json -S "$dev" --groups "$grp" -- --src "$src" | \
+	run_on "$dev" \
+		ethtool --json -S "$dev" --groups "$grp" -- --src "$src" | \
 		jq --arg grp "$grp" --arg name "$name" '.[][$grp][$name]'
 }
 
tools/testing/selftests/net/lib.sh +2 -1
index 3f79bf1ec977..e915386daf1b 100644
@@ -514,7 +514,8 @@ mac_get()
 {
 	local if_name=$1
 
-	ip -j link show dev $if_name | jq -r '.[]["address"]'
+	run_on "$if_name" \
+		ip -j link show dev "$if_name" | jq -r '.[]["address"]'
 }
 
 kill_process()
Signature · 1 line
2.25.1
#5 lore raw

PATCH v5 4/9 selftests: drivers: hw: cleanup shellcheck warnings in the rmon test

In reply to Ioana Ciornei

If run on the ethtool_rmon.sh script, shellcheck generates a bunch of false positive errors. Suppress those checks that generate them.

Also cleanup the remaining warnings by using double quoting around the used variables.

---
Changes in v5:
- none
Changes in v4:
- split one line to 80 chars
Changes in v3:
- none
Changes in v2:
- patch is new

 .../selftests/drivers/net/hw/ethtool_rmon.sh  | 54 ++++++++++---------
 1 file changed, 29 insertions(+), 25 deletions(-)
tools/testing/selftests/drivers/net/hw/ethtool_rmon.sh +29 -25
index 8f60c1685ad4..13b3760e3a40 100755
@@ -1,5 +1,7 @@
 #!/bin/bash
 # SPDX-License-Identifier: GPL-2.0
+#shellcheck disable=SC2034 # SC does not see the global variables
+#shellcheck disable=SC2317,SC2329 # unused functions
 
 ALL_TESTS="
 	rmon_rx_histogram
@@ -19,11 +21,12 @@ ensure_mtu()
 {
 	local iface=$1; shift
 	local len=$1; shift
-	local current=$(ip -j link show dev $iface | jq -r '.[0].mtu')
 	local required=$((len - ETH_HLEN - ETH_FCS_LEN))
+	local current
 
-	if [ $current -lt $required ]; then
-		ip link set dev $iface mtu $required || return 1
+	current=$(ip -j link show dev "$iface" | jq -r '.[0].mtu')
+	if [ "$current" -lt "$required" ]; then
+		ip link set dev "$iface" mtu "$required" || return 1
 	fi
 }
 
@@ -46,23 +49,23 @@ bucket_test()
 	len=$((len - ETH_FCS_LEN))
 	len=$((len > 0 ? len : 0))
 
-	before=$(ethtool --json -S $iface --groups rmon | \
+	before=$(ethtool --json -S "$iface" --groups rmon | \
 		jq -r ".[0].rmon[\"${set}-pktsNtoM\"][$bucket].val")
 
 	# Send 10k one way and 20k in the other, to detect counters
 	# mapped to the wrong direction
-	$MZ $neigh -q -c $num_rx -p $len -a own -b bcast -d 10us
-	$MZ $iface -q -c $num_tx -p $len -a own -b bcast -d 10us
+	"$MZ" "$neigh" -q -c "$num_rx" -p "$len" -a own -b bcast -d 10us
+	"$MZ" "$iface" -q -c "$num_tx" -p "$len" -a own -b bcast -d 10us
 
-	after=$(ethtool --json -S $iface --groups rmon | \
+	after=$(ethtool --json -S "$iface" --groups rmon | \
 		jq -r ".[0].rmon[\"${set}-pktsNtoM\"][$bucket].val")
 
 	delta=$((after - before))
 
-	expected=$([ $set = rx ] && echo $num_rx || echo $num_tx)
+	expected=$([ "$set" = rx ] && echo "$num_rx" || echo "$num_tx")
 
 	# Allow some extra tolerance for other packets sent by the stack
-	[ $delta -ge $expected ] && [ $delta -le $((expected + 100)) ]
+	[ "$delta" -ge "$expected" ] && [ "$delta" -le $((expected + 100)) ]
 }
 
 rmon_histogram()
@@ -78,23 +81,23 @@ rmon_histogram()
 	while read -r -a bucket; do
 		step="$set-pkts${bucket[0]}to${bucket[1]} on $iface"
 
-		for if in $iface $neigh; do
-			if ! ensure_mtu $if ${bucket[0]}; then
+		for if in "$iface" "$neigh"; do
+			if ! ensure_mtu "$if" "${bucket[0]}"; then
 				log_test_xfail "$if does not support the required MTU for $step"
 				return
 			fi
 		done
 
-		if ! bucket_test $iface $neigh $set $nbuckets ${bucket[0]}; then
+		if ! bucket_test "$iface" "$neigh" "$set" "$nbuckets" "${bucket[0]}"; then
 			check_err 1 "$step failed"
 			return 1
 		fi
 		log_test "$step"
 		nbuckets=$((nbuckets + 1))
-	done < <(ethtool --json -S $iface --groups rmon | \
+	done < <(ethtool --json -S "$iface" --groups rmon | \
 		jq -r ".[0].rmon[\"${set}-pktsNtoM\"][]|[.low, .high]|@tsv" 2>/dev/null)
 
-	if [ $nbuckets -eq 0 ]; then
+	if [ "$nbuckets" -eq 0 ]; then
 		log_test_xfail "$iface does not support $set histogram counters"
 		return
 	fi
@@ -102,14 +105,14 @@ rmon_histogram()
 
 rmon_rx_histogram()
 {
-	rmon_histogram $h1 $h2 rx
-	rmon_histogram $h2 $h1 rx
+	rmon_histogram "$h1" "$h2" rx
+	rmon_histogram "$h2" "$h1" rx
 }
 
 rmon_tx_histogram()
 {
-	rmon_histogram $h1 $h2 tx
-	rmon_histogram $h2 $h1 tx
+	rmon_histogram "$h1" "$h2" tx
+	rmon_histogram "$h2" "$h1" tx
 }
 
 setup_prepare()
@@ -117,9 +120,10 @@ setup_prepare()
 	h1=${NETIFS[p1]}
 	h2=${NETIFS[p2]}
 
-	for iface in $h1 $h2; do
-		netif_mtu[$iface]=$(ip -j link show dev $iface | jq -r '.[0].mtu')
-		ip link set dev $iface up
+	for iface in "$h1" "$h2"; do
+		netif_mtu["$iface"]=$(ip -j link show dev "$iface" | \
+			jq -r '.[0].mtu')
+		ip link set dev "$iface" up
 	done
 }
 
@@ -127,9 +131,9 @@ cleanup()
 {
 	pre_cleanup
 
-	for iface in $h2 $h1; do
-		ip link set dev $iface \
-			mtu ${netif_mtu[$iface]} \
+	for iface in "$h2" "$h1"; do
+		ip link set dev "$iface" \
+			mtu "${netif_mtu[$iface]}" \
 			down
 	done
 }
@@ -142,4 +146,4 @@ setup_wait
 
 tests_run
 
-exit $EXIT_STATUS
+exit "$EXIT_STATUS"
Signature · 1 line
2.25.1
#6 lore raw

PATCH v5 5/9 selftests: drivers: hw: test rmon counters only on first interface

In reply to Ioana Ciornei

The selftests in drivers/net are slowly transitioning to being able to be used on systems with a single network interface. The first step for the ethtool_rmon.sh test is to only validate that the rmon counters are properly exported on the first interface supplied as an argument.

Remove the rmon_histogram calls which intend to test also the rmon counters on the 2nd interface. This also removes the need for the remote system, which should be used only to inject traffic, to also support rmon counters.

---
Changes in v5:
- none
Changes in v4:
- none
Changes in v3:
- none
Changes in v2:
- patch is new

 tools/testing/selftests/drivers/net/hw/ethtool_rmon.sh | 2 --
 1 file changed, 2 deletions(-)
tools/testing/selftests/drivers/net/hw/ethtool_rmon.sh +0 -2
index 13b3760e3a40..80e75b9b40fd 100755
@@ -106,13 +106,11 @@ rmon_histogram()
 rmon_rx_histogram()
 {
 	rmon_histogram "$h1" "$h2" rx
-	rmon_histogram "$h2" "$h1" rx
 }
 
 rmon_tx_histogram()
 {
 	rmon_histogram "$h1" "$h2" tx
-	rmon_histogram "$h2" "$h1" tx
 }
 
 setup_prepare()
Signature · 1 line
2.25.1
#7 lore raw

PATCH v5 6/9 selftests: drivers: hw: replace counter upper limit with UINT32_MAX in rmon test

In reply to Ioana Ciornei

The ethtool_rmon.sh script checks that the number of packets sent / received during a test matches the expected value with a 1% tolerance.

Since in the next patches this test will gain the capability to also be run on systems with a single interface where the traffic generator is accesible through ssh, use the UINT32_MAX as the upper limit. This is necessary since the same interface will be used also for control traffic (the ssh commands) as well as the mausezahn generated one.

---
Changes in v5:
- none
Changes in v4:
- none
Changes in v3:
- none
Changes in v2:
- patch is new

 tools/testing/selftests/drivers/net/hw/ethtool_rmon.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/testing/selftests/drivers/net/hw/ethtool_rmon.sh +2 -2
index 80e75b9b40fd..f290ce1832f1 100755
@@ -12,6 +12,7 @@ NUM_NETIFS=2
 lib_dir=$(dirname "$0")
 source "$lib_dir"/../../../net/forwarding/lib.sh
 
+UINT32_MAX=$((2**32 - 1))
 ETH_FCS_LEN=4
 ETH_HLEN=$((6+6+2))
 
@@ -64,8 +65,7 @@ bucket_test()
 
 	expected=$([ "$set" = rx ] && echo "$num_rx" || echo "$num_tx")
 
-	# Allow some extra tolerance for other packets sent by the stack
-	[ "$delta" -ge "$expected" ] && [ "$delta" -le $((expected + 100)) ]
+	[ "$delta" -ge "$expected" ] && [ "$delta" -le "$UINT32_MAX" ]
 }
 
 rmon_histogram()
Signature · 1 line
2.25.1
#8 lore raw

PATCH v5 7/9 selftests: drivers: hw: move to KTAP output

In reply to Ioana Ciornei

Update the ethtool_rmon.sh test so that it uses the KTAP format for its output. This is achieved by using the helpers found in ktap_helpers.sh. An example output can be found below.

 $ ./ethtool_rmon.sh endpmac3 endpmac4
 TAP version 13
 1..14
 ok 1 ethtool_rmon.rx-pkts64to64
 ok 2 ethtool_rmon.rx-pkts65to127
 ok 3 ethtool_rmon.rx-pkts128to255
 ok 4 ethtool_rmon.rx-pkts256to511
 ok 5 ethtool_rmon.rx-pkts512to1023
 ok 6 ethtool_rmon.rx-pkts1024to1518
 ok 7 ethtool_rmon.rx-pkts1519to10240
 ok 8 ethtool_rmon.tx-pkts64to64
 ok 9 ethtool_rmon.tx-pkts65to127
 ok 10 ethtool_rmon.tx-pkts128to255
 ok 11 ethtool_rmon.tx-pkts256to511
 ok 12 ethtool_rmon.tx-pkts512to1023
 ok 13 ethtool_rmon.tx-pkts1024to1518
 ok 14 ethtool_rmon.tx-pkts1519to10240
 # Totals: pass:14 fail:0 xfail:0 xpass:0 skip:0 error:0

---
Changes in v5:
- none
Changes in v4:
- patch is added in this version so that ethtool_rmon.sh is converted to KTAP output

 .../selftests/drivers/net/hw/ethtool_rmon.sh  | 24 ++++++++++++-------
 1 file changed, 16 insertions(+), 8 deletions(-)
tools/testing/selftests/drivers/net/hw/ethtool_rmon.sh +16 -8
index f290ce1832f1..ed81bdc33536 100755
@@ -11,10 +11,12 @@ ALL_TESTS="
 NUM_NETIFS=2
 lib_dir=$(dirname "$0")
 source "$lib_dir"/../../../net/forwarding/lib.sh
+source "$lib_dir"/../../../kselftest/ktap_helpers.sh
 
 UINT32_MAX=$((2**32 - 1))
 ETH_FCS_LEN=4
 ETH_HLEN=$((6+6+2))
+TEST_NAME=$(basename "$0" .sh)
 
 declare -A netif_mtu
 
@@ -76,29 +78,28 @@ rmon_histogram()
 	local nbuckets=0
 	local step=
 
-	RET=0
-
 	while read -r -a bucket; do
-		step="$set-pkts${bucket[0]}to${bucket[1]} on $iface"
+		step="$set-pkts${bucket[0]}to${bucket[1]}"
 
 		for if in "$iface" "$neigh"; do
 			if ! ensure_mtu "$if" "${bucket[0]}"; then
-				log_test_xfail "$if does not support the required MTU for $step"
+				ktap_print_msg "$if does not support the required MTU for $step"
+				ktap_test_xfail "$TEST_NAME.$step"
 				return
 			fi
 		done
 
 		if ! bucket_test "$iface" "$neigh" "$set" "$nbuckets" "${bucket[0]}"; then
-			check_err 1 "$step failed"
+			ktap_test_fail "$TEST_NAME.$step"
 			return 1
 		fi
-		log_test "$step"
+		ktap_test_pass "$TEST_NAME.$step"
 		nbuckets=$((nbuckets + 1))
 	done < <(ethtool --json -S "$iface" --groups rmon | \
 		jq -r ".[0].rmon[\"${set}-pktsNtoM\"][]|[.low, .high]|@tsv" 2>/dev/null)
 
 	if [ "$nbuckets" -eq 0 ]; then
-		log_test_xfail "$iface does not support $set histogram counters"
+		ktap_print_msg "$iface does not support $set histogram counters"
 		return
 	fi
 }
@@ -139,9 +140,16 @@ cleanup()
 check_ethtool_counter_group_support
 trap cleanup EXIT
 
+bucket_count=$(ethtool --json -S "${NETIFS[p1]}" --groups rmon | \
+	jq -r '.[0].rmon |
+		"\((."rx-pktsNtoM" | length) +
+		   (."tx-pktsNtoM" | length))"')
+ktap_print_header
+ktap_set_plan "$bucket_count"
+
 setup_prepare
 setup_wait
 
 tests_run
 
-exit "$EXIT_STATUS"
+ktap_finished
Signature · 1 line
2.25.1
maintainer
#9 lore raw

Re: [PATCH net-next v5 7/9] selftests: drivers: hw: move to KTAP output

tools/testing/selftests/drivers/net/hw/ethtool_rmon.sh ALL_TESTS=" · line 14

Quoted 9 lines · Ioana Ciornei
tools/testing/selftests/drivers/net/hw/ethtool_rmon.sh +1 -0
index f290ce1832f1..ed81bdc33536 100755
@@ -11,10 +11,12 @@ ALL_TESTS="
 NUM_NETIFS=2
 lib_dir=$(dirname "$0")
 source "$lib_dir"/../../../net/forwarding/lib.sh
+source "$lib_dir"/../../../kselftest/ktap_helpers.sh

AI review noted:
---
Will this test work correctly after installation? The test sources ktap_helpers.sh but the file doesn't appear to be included in the Makefile's TEST_INCLUDES variable.

Looking at tools/testing/selftests/drivers/net/hw/Makefile, when 'make install' is run, only files listed in TEST_PROGS, TEST_FILES, and TEST_INCLUDES are copied to the installation directory. Files referenced via 'source' need to be in TEST_INCLUDES to be available at runtime.

Without adding '../../../kselftest/ktap_helpers.sh' to TEST_INCLUDES, the test will fail with 'No such file or directory' when run from an installed location.
---

IMHO this is better handled with a follow-up as opposed to a repost. While at that, please also take care of Petr's comment on 2/9.

Thanks,

Paolo

#10 lore raw

Re: [PATCH net-next v5 7/9] selftests: drivers: hw: move to KTAP output

Quoted 23 lines · Paolo Abeni

tools/testing/selftests/drivers/net/hw/ethtool_rmon.sh ALL_TESTS=" · line 14

Quoted 9 lines · Ioana Ciornei
tools/testing/selftests/drivers/net/hw/ethtool_rmon.sh +1 -0
index f290ce1832f1..ed81bdc33536 100755
@@ -11,10 +11,12 @@ ALL_TESTS="
 NUM_NETIFS=2
 lib_dir=$(dirname "$0")
 source "$lib_dir"/../../../net/forwarding/lib.sh
+source "$lib_dir"/../../../kselftest/ktap_helpers.sh

AI review noted:
---
Will this test work correctly after installation? The test sources ktap_helpers.sh but the file doesn't appear to be included in the Makefile's TEST_INCLUDES variable.

Looking at tools/testing/selftests/drivers/net/hw/Makefile, when 'make install' is run, only files listed in TEST_PROGS, TEST_FILES, and TEST_INCLUDES are copied to the installation directory. Files referenced via 'source' need to be in TEST_INCLUDES to be available at runtime.

Quoted 7 lines

Without adding '../../../kselftest/ktap_helpers.sh' to TEST_INCLUDES, the test will fail with 'No such file or directory' when run from an installed location.
---

IMHO this is better handled with a follow-up as opposed to a repost. While at that, please also take care of Petr's comment on 2/9.

Sure. I can submit a follow-up with these small fixes.

Thanks,
Ioana

#11 lore raw

Re: [PATCH net-next v5 7/9] selftests: drivers: hw: move to KTAP output

In reply to Paolo Abeni
Quoted 23 lines · Paolo Abeni

tools/testing/selftests/drivers/net/hw/ethtool_rmon.sh ALL_TESTS=" · line 14

Quoted 9 lines · Ioana Ciornei
tools/testing/selftests/drivers/net/hw/ethtool_rmon.sh +1 -0
index f290ce1832f1..ed81bdc33536 100755
@@ -11,10 +11,12 @@ ALL_TESTS="
 NUM_NETIFS=2
 lib_dir=$(dirname "$0")
 source "$lib_dir"/../../../net/forwarding/lib.sh
+source "$lib_dir"/../../../kselftest/ktap_helpers.sh

AI review noted:
---
Will this test work correctly after installation? The test sources ktap_helpers.sh but the file doesn't appear to be included in the Makefile's TEST_INCLUDES variable.

Looking at tools/testing/selftests/drivers/net/hw/Makefile, when 'make install' is run, only files listed in TEST_PROGS, TEST_FILES, and TEST_INCLUDES are copied to the installation directory. Files referenced via 'source' need to be in TEST_INCLUDES to be available at runtime.

Quoted 3 lines

Without adding '../../../kselftest/ktap_helpers.sh' to TEST_INCLUDES, the test will fail with 'No such file or directory' when run from an installed location.

Now that I actually looked at this, I don't think that adding ktap_helpers.sh in TEST_INCLUDES is actually needed.

tools/testing/selftests/Makefile installs ktap_helpers.sh irrespective of it being included in any TEST_INCLUDES.

	install: all
	ifdef INSTALL_PATH
		@# Ask all targets to install their files
		mkdir -p $(INSTALL_PATH)/kselftest
		install -m 744 kselftest/module.sh $(INSTALL_PATH)/kselftest/
		install -m 744 kselftest/runner.sh $(INSTALL_PATH)/kselftest/
		install -m 744 kselftest/prefix.pl $(INSTALL_PATH)/kselftest/
		install -m 744 kselftest/ktap_helpers.sh $(INSTALL_PATH)/kselftest/

I tested this and even if I only install drivers/net/hw I still get ktap_helpers.sh in the install path.

Ioana

#12 lore raw

PATCH v5 8/9 selftests: drivers: hw: update ethtool_rmon to work with a single local interface

In reply to Ioana Ciornei

This patch finalizes the transition to work with a single local interface for the ethtool_rmon.sh test. Each 'ip link' and 'ethtool' command used by the test is annotated with the necessary run_on in order to be executed on the necessary target system, be it local, in another network namespace or through ssh.

Since we need NETIF up and running also for control traffic, we now expect that the interfaces are up and running and do not touch bring them up or down at the end of the test. This is also documented in the drivers/net/README.rst.

The ethtool_rmon.sh script can still be used in the older fashion by passing two interfaces as command line arguments, the only restriction is that those interfaces need to be already up.

 $ DRIVER_TEST_CONFORMANT=no ./ethtool_rmon.sh eth0 eth1

As part of the kselftest infrastructure, this test can be run in the following manner:

 $ make -C tools/testing/selftests/ TARGETS="drivers/net drivers/net/hw" \
 install INSTALL_PATH=/tmp/ksft-net-drv
 $ cd /tmp/ksft-net-drv/
 $ cat > ./drivers/net/net.config <<EOF
 NETIF=endpmac17
 LOCAL_V4=17.0.0.1
 REMOTE_V4=17.0.0.2
 REMOTE_TYPE=ssh
 [email protected]
 EOF
 $ ./run_kselftest.sh -t drivers/net/hw:ethtool_rmon.sh
 TAP version 13
 1..1
 # timeout set to 0
 # selftests: drivers/net/hw: ethtool_rmon.sh
 # TAP version 13
 # 1..14
 # ok 1 ethtool_rmon.rx-pkts64to64
 # ok 2 ethtool_rmon.rx-pkts65to127
 # ok 3 ethtool_rmon.rx-pkts128to255
 # ok 4 ethtool_rmon.rx-pkts256to511
 # ok 5 ethtool_rmon.rx-pkts512to1023
 # ok 6 ethtool_rmon.rx-pkts1024to1518
 # ok 7 ethtool_rmon.rx-pkts1519to10240
 # ok 8 ethtool_rmon.tx-pkts64to64
 # ok 9 ethtool_rmon.tx-pkts65to127
 # ok 10 ethtool_rmon.tx-pkts128to255
 # ok 11 ethtool_rmon.tx-pkts256to511
 # ok 12 ethtool_rmon.tx-pkts512to1023
 # ok 13 ethtool_rmon.tx-pkts1024to1518
 # ok 14 ethtool_rmon.tx-pkts1519to10240
 # # Totals: pass:14 fail:0 xfail:0 xpass:0 skip:0 error:0
 ok 1 selftests: drivers/net/hw: ethtool_rmon.sh

---
Changes in v5:
- none
Changes in v4:
- set DRIVER_TEST_CONFORMANT to yes
- update the commit message to reflect the current output
- split some more lines to 80 chars
Changes in v3:
- none
Changes in v2:
- patch is new

 .../selftests/drivers/net/hw/ethtool_rmon.sh  | 30 +++++++++++--------
 1 file changed, 17 insertions(+), 13 deletions(-)
tools/testing/selftests/drivers/net/hw/ethtool_rmon.sh +17 -13
index ed81bdc33536..2ec19edddfaa 100755
@@ -8,6 +8,7 @@ ALL_TESTS="
 	rmon_tx_histogram
 "
 
+: "${DRIVER_TEST_CONFORMANT:=yes}"
 NUM_NETIFS=2
 lib_dir=$(dirname "$0")
 source "$lib_dir"/../../../net/forwarding/lib.sh
@@ -27,9 +28,11 @@ ensure_mtu()
 	local required=$((len - ETH_HLEN - ETH_FCS_LEN))
 	local current
 
-	current=$(ip -j link show dev "$iface" | jq -r '.[0].mtu')
+	current=$(run_on "$iface" \
+		ip -j link show dev "$iface" | jq -r '.[0].mtu')
 	if [ "$current" -lt "$required" ]; then
-		ip link set dev "$iface" mtu "$required" || return 1
+		run_on "$iface" ip link set dev "$iface" mtu "$required" \
+			|| return 1
 	fi
 }
 
@@ -52,15 +55,17 @@ bucket_test()
 	len=$((len - ETH_FCS_LEN))
 	len=$((len > 0 ? len : 0))
 
-	before=$(ethtool --json -S "$iface" --groups rmon | \
+	before=$(run_on "$iface" ethtool --json -S "$iface" --groups rmon | \
 		jq -r ".[0].rmon[\"${set}-pktsNtoM\"][$bucket].val")
 
 	# Send 10k one way and 20k in the other, to detect counters
 	# mapped to the wrong direction
-	"$MZ" "$neigh" -q -c "$num_rx" -p "$len" -a own -b bcast -d 10us
-	"$MZ" "$iface" -q -c "$num_tx" -p "$len" -a own -b bcast -d 10us
+	run_on "$neigh" \
+		"$MZ" "$neigh" -q -c "$num_rx" -p "$len" -a own -b bcast -d 10us
+	run_on "$iface" \
+		"$MZ" "$iface" -q -c "$num_tx" -p "$len" -a own -b bcast -d 10us
 
-	after=$(ethtool --json -S "$iface" --groups rmon | \
+	after=$(run_on "$iface" ethtool --json -S "$iface" --groups rmon | \
 		jq -r ".[0].rmon[\"${set}-pktsNtoM\"][$bucket].val")
 
 	delta=$((after - before))
@@ -95,7 +100,7 @@ rmon_histogram()
 		fi
 		ktap_test_pass "$TEST_NAME.$step"
 		nbuckets=$((nbuckets + 1))
-	done < <(ethtool --json -S "$iface" --groups rmon | \
+	done < <(run_on "$iface" ethtool --json -S "$iface" --groups rmon | \
 		jq -r ".[0].rmon[\"${set}-pktsNtoM\"][]|[.low, .high]|@tsv" 2>/dev/null)
 
 	if [ "$nbuckets" -eq 0 ]; then
@@ -120,9 +125,8 @@ setup_prepare()
 	h2=${NETIFS[p2]}
 
 	for iface in "$h1" "$h2"; do
-		netif_mtu["$iface"]=$(ip -j link show dev "$iface" | \
-			jq -r '.[0].mtu')
-		ip link set dev "$iface" up
+		netif_mtu["$iface"]=$(run_on "$iface" \
+			ip -j link show dev "$iface" | jq -r '.[0].mtu')
 	done
 }
 
@@ -130,10 +134,10 @@ cleanup()
 {
 	pre_cleanup
 
+	# Do not bring down the interfaces, just configure the initial MTU
 	for iface in "$h2" "$h1"; do
-		ip link set dev "$iface" \
-			mtu "${netif_mtu[$iface]}" \
-			down
+		run_on "$iface" ip link set dev "$iface" \
+			mtu "${netif_mtu[$iface]}"
 	done
 }
 
Signature · 1 line
2.25.1
#13 lore raw

PATCH v5 9/9 selftests: drivers: hw: add test for the ethtool standard counters

In reply to Ioana Ciornei

Add a new selftest - ethtool_std_stats.sh - which validates the eth-ctrl, eth-mac and pause standard statistics exported by an interface. Collision related eth-mac counters as well as the error ones will be checked against zero since that is the most likely correct scenario.

The central part of this patch is the traffic_test() function which gathers the 'before' counter values, sends a batch of traffic and then interrogates again the same counters in order to determine if the delta is on target. The function receives an array through which the caller can request what counters to be interrogated and, for each of them, what is their target delta value.

The output from this selftest looks as follows on a LX2160ARDB board:

 $ ./run_kselftest.sh -t drivers/net/hw:ethtool_std_stats.sh
 TAP version 13
 1..1
 # timeout set to 0
 # selftests: drivers/net/hw: ethtool_std_stats.sh
 # TAP version 13
 # 1..26
 # ok 1 ethtool_std_stats.eth-ctrl-MACControlFramesTransmitted
 # ok 2 ethtool_std_stats.eth-ctrl-MACControlFramesReceived
 # ok 3 ethtool_std_stats.eth-mac-FrameCheckSequenceErrors
 # ok 4 ethtool_std_stats.eth-mac-AlignmentErrors
 # ok 5 ethtool_std_stats.eth-mac-FramesLostDueToIntMACXmitError
 # ok 6 ethtool_std_stats.eth-mac-CarrierSenseErrors # SKIP
 # ok 7 ethtool_std_stats.eth-mac-FramesLostDueToIntMACRcvError
 # ok 8 ethtool_std_stats.eth-mac-InRangeLengthErrors # SKIP
 # ok 9 ethtool_std_stats.eth-mac-OutOfRangeLengthField # SKIP
 # ok 10 ethtool_std_stats.eth-mac-FrameTooLongErrors # SKIP
 # ok 11 ethtool_std_stats.eth-mac-FramesAbortedDueToXSColls # SKIP
 # ok 12 ethtool_std_stats.eth-mac-SingleCollisionFrames # SKIP
 # ok 13 ethtool_std_stats.eth-mac-MultipleCollisionFrames # SKIP
 # ok 14 ethtool_std_stats.eth-mac-FramesWithDeferredXmissions # SKIP
 # ok 15 ethtool_std_stats.eth-mac-LateCollisions # SKIP
 # ok 16 ethtool_std_stats.eth-mac-FramesWithExcessiveDeferral # SKIP
 # ok 17 ethtool_std_stats.eth-mac-BroadcastFramesXmittedOK
 # ok 18 ethtool_std_stats.eth-mac-OctetsTransmittedOK
 # ok 19 ethtool_std_stats.eth-mac-BroadcastFramesReceivedOK
 # ok 20 ethtool_std_stats.eth-mac-OctetsReceivedOK
 # ok 21 ethtool_std_stats.eth-mac-FramesTransmittedOK
 # ok 22 ethtool_std_stats.eth-mac-MulticastFramesXmittedOK
 # ok 23 ethtool_std_stats.eth-mac-FramesReceivedOK
 # ok 24 ethtool_std_stats.eth-mac-MulticastFramesReceivedOK
 # ok 25 ethtool_std_stats.pause-tx_pause_frames
 # ok 26 ethtool_std_stats.pause-rx_pause_frames
 # # 10 skipped test(s) detected.  Consider enabling relevant config options to improve coverage.
 # # Totals: pass:16 fail:0 xfail:0 xpass:0 skip:10 error:0
 ok 1 selftests: drivers/net/hw: ethtool_std_stats.sh

Please note that not all MACs are counting the software injected pause frames as real Tx pause. For example, on a LS1028ARDB the selftest output will reflect the fact that neither the ENETC MAC, nor the Felix switch MAC are able to detect Tx pause frames injected by software.

 $ ./run_kselftest.sh -t drivers/net/hw:ethtool_std_stats.sh
 (...)
 # # software sent pause frames not detected
 # ok 25 ethtool_std_stats.pause-tx_pause_frames # XFAIL
 # ok 26 ethtool_std_stats.pause-rx_pause_frames

---
Changes in v5:
- none
Changes in v4:
- move to a the KTAP format output by using ktap_helpers.sh
- update commit message to reflect the current output
- use DRIVER_TEST_CONFORMANT
Changes in v3:
- none
Changes in v2:
- Use the new run_on helper
- No longer checking that each counter has a 1% tolerance against the target. The only upper limit is UINT32_MAX.
- Check that both the error counters and the collision related ones are zero since this is the most probable scenario (we don't expect errors with the traffic that we are sending).
- Removed any checks performed on the remot interface counters since that is being used only as a traffic generator.

 .../testing/selftests/drivers/net/hw/Makefile |   1 +
 .../drivers/net/hw/ethtool_std_stats.sh       | 206 ++++++++++++++++++
 2 files changed, 207 insertions(+)
 create mode 100755 tools/testing/selftests/drivers/net/hw/ethtool_std_stats.sh
tools/testing/selftests/drivers/net/hw/Makefile +1 -0
index 884cc77daeaa..deeca3f8d080 100644
@@ -26,6 +26,7 @@ TEST_PROGS = \
 	ethtool_extended_state.sh \
 	ethtool_mm.sh \
 	ethtool_rmon.sh \
+	ethtool_std_stats.sh \
 	gro_hw.py \
 	hw_stats_l3.sh \
 	hw_stats_l3_gre.sh \
tools/testing/selftests/drivers/net/hw/ethtool_std_stats.sh new file +206 -0

206 lines not on this page · raw message

Signature · 1 line
2.25.1
#14 lore raw
In reply to Ioana Ciornei
This series was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:

Hello:

This series was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:

Quoted 11 lines · On Mon, 30 Mar 2026 18:29:24 +0300 you wrote:

This patch set aims to add the necessary support so that bash written selftests are also able to easily run with a remote traffic generator system, either be it in another netns or one accessible through ssh.

This patch set is a result of the discussion from v1:
https://lore.kernel.org/all/[email protected]/
Even though the python infrastructure is already established, some things are easier in bash and it would be a shame to leave behind the bash tests that we already have.

[...]

Here is the summary with links:
- [net-next,v5,1/9] selftests: forwarding: extend ethtool_std_stats_get with pause statistics

    https://git.kernel.org/netdev/net-next/c/4799ff80c68a
  - [net-next,v5,2/9] selftests: net: extend lib.sh to parse drivers/net/net.config
    https://git.kernel.org/netdev/net-next/c/2de16ebe78f0
  - [net-next,v5,3/9] selftests: net: update some helpers to use run_on
    https://git.kernel.org/netdev/net-next/c/7db9da4c67c7
  - [net-next,v5,4/9] selftests: drivers: hw: cleanup shellcheck warnings in the rmon test
    https://git.kernel.org/netdev/net-next/c/afd1b9bf7529
  - [net-next,v5,5/9] selftests: drivers: hw: test rmon counters only on first interface
    https://git.kernel.org/netdev/net-next/c/e76c71483a56
  - [net-next,v5,6/9] selftests: drivers: hw: replace counter upper limit with UINT32_MAX in rmon test
    https://git.kernel.org/netdev/net-next/c/557c067c0001
  - [net-next,v5,7/9] selftests: drivers: hw: move to KTAP output
    https://git.kernel.org/netdev/net-next/c/eec1b9057c24
  - [net-next,v5,8/9] selftests: drivers: hw: update ethtool_rmon to work with a single local interface
    https://git.kernel.org/netdev/net-next/c/abe4929bc7d0
  - [net-next,v5,9/9] selftests: drivers: hw: add test for the ethtool standard counters
    https://git.kernel.org/netdev/net-next/c/3016574ea2f8

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html