From: Maxime Chevallier <maxime.chevallier@bootlin.com>
To: davem@davemloft.net
Cc: "Maxime Chevallier" <maxime.chevallier@bootlin.com>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
thomas.petazzoni@bootlin.com, "Andrew Lunn" <andrew@lunn.ch>,
"Jakub Kicinski" <kuba@kernel.org>,
"Eric Dumazet" <edumazet@google.com>,
"Paolo Abeni" <pabeni@redhat.com>,
"Russell King" <linux@armlinux.org.uk>,
"Florian Fainelli" <f.fainelli@gmail.com>,
"Heiner Kallweit" <hkallweit1@gmail.com>,
"Vladimir Oltean" <vladimir.oltean@nxp.com>,
"Köry Maincent" <kory.maincent@bootlin.com>,
"Oleksij Rempel" <o.rempel@pengutronix.de>,
"Simon Horman" <horms@kernel.org>,
"Shuah Khan" <shuah@kernel.org>,
linux-kselftest@vger.kernel.org
Subject: [PATCH net-next v3 3/3] selftests: ethtool: Introduce ethernet PHY selftests on netdevsim
Date: Thu, 10 Jul 2025 08:22:47 +0200 [thread overview]
Message-ID: <20250710062248.378459-4-maxime.chevallier@bootlin.com> (raw)
In-Reply-To: <20250710062248.378459-1-maxime.chevallier@bootlin.com>
Now that netdevsim supports PHY device simulation, we can start writing
some tests to cover a little bit all PHY-related ethtool commands.
So far we only test the basic use of "ethtool --show-phys", with :
- A simple command to get a PHY we just added
- A DUMP command listing PHYs on multiple netdevsim instances
- A Filtered DUMP command listing all PHYs on a netdevsim
Introduce some helpers to create netdevsim PHYs, and a new test file.
Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
---
.../selftests/drivers/net/netdevsim/config | 1 +
.../drivers/net/netdevsim/ethtool-common.sh | 15 +++++
.../drivers/net/netdevsim/ethtool-phy.sh | 64 +++++++++++++++++++
3 files changed, 80 insertions(+)
create mode 100755 tools/testing/selftests/drivers/net/netdevsim/ethtool-phy.sh
diff --git a/tools/testing/selftests/drivers/net/netdevsim/config b/tools/testing/selftests/drivers/net/netdevsim/config
index 5117c78ddf0a..223e82cb7759 100644
--- a/tools/testing/selftests/drivers/net/netdevsim/config
+++ b/tools/testing/selftests/drivers/net/netdevsim/config
@@ -6,6 +6,7 @@ CONFIG_NETDEVSIM=m
CONFIG_NET_SCH_MQPRIO=y
CONFIG_NET_SCH_MULTIQ=y
CONFIG_NET_SCH_PRIO=y
+CONFIG_PHYLIB=m
CONFIG_PSAMPLE=y
CONFIG_PTP_1588_CLOCK_MOCK=y
CONFIG_VXLAN=m
diff --git a/tools/testing/selftests/drivers/net/netdevsim/ethtool-common.sh b/tools/testing/selftests/drivers/net/netdevsim/ethtool-common.sh
index d9c7a3d397a9..1bd0ac5e7bba 100644
--- a/tools/testing/selftests/drivers/net/netdevsim/ethtool-common.sh
+++ b/tools/testing/selftests/drivers/net/netdevsim/ethtool-common.sh
@@ -53,3 +53,18 @@ function make_netdev {
# get new device name
ls /sys/bus/netdevsim/devices/netdevsim${NSIM_ID}/net/
}
+
+function make_phydev_on_netdev {
+ local parent_ndev_nsim_id=$1
+ local parent=$2
+
+ local ndev_dfs=/sys/kernel/debug/netdevsim/netdevsim$parent_ndev_nsim_id/ports/0
+
+ old_dev_dfs=$(find $ndev_dfs -type d)
+ echo $parent > $ndev_dfs/phy_add
+ new_dev_dfs=$(find $ndev_dfs -type d)
+
+ # The new phydev name corresponds to the new file that was created. Its
+ # name isn't predictable.
+ echo $old_dev_dfs $new_dev_dfs | xargs -n1 | sort | uniq -u
+}
diff --git a/tools/testing/selftests/drivers/net/netdevsim/ethtool-phy.sh b/tools/testing/selftests/drivers/net/netdevsim/ethtool-phy.sh
new file mode 100755
index 000000000000..b10440d108b2
--- /dev/null
+++ b/tools/testing/selftests/drivers/net/netdevsim/ethtool-phy.sh
@@ -0,0 +1,64 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0-only
+
+source ethtool-common.sh
+
+# Bail if ethtool is too old
+if ! ethtool -h | grep show-phys >/dev/null 2>&1; then
+ echo "SKIP: No --show-phys support in ethtool"
+ exit 4
+fi
+
+function make_netdev_from_id {
+ local new_nsim_id="$1"
+ # Make a netdevsim
+ echo "$new_nsim_id" > /sys/bus/netdevsim/new_device
+ udevadm settle
+ # get new device name
+ ls /sys/bus/netdevsim/devices/netdevsim"${new_nsim_id}"/net/
+}
+
+function cleanup_netdev_from_id {
+ local to_del_nsim_id="$1"
+ echo "$to_del_nsim_id" > /sys/bus/netdevsim/del_device
+}
+
+NSIM_NETDEV=$(make_netdev)
+
+set -o pipefail
+
+# Check simple PHY addition and listing
+
+# Parent == 0 means that the PHY's parent is the netdev
+PHY_DFS=$(make_phydev_on_netdev "$NSIM_ID" 0)
+
+# First PHY gets index 1
+index=$(ethtool --show-phys "$NSIM_NETDEV" | grep "PHY index" | cut -d ' ' -f 3)
+check $? "$index" "1"
+
+# Insert a second PHY, same parent. It gets index 2.
+PHY2_DFS=$(make_phydev_on_netdev "$NSIM_ID" 0)
+
+# Create another netdev
+NSIM_ID2=$((RANDOM % 1024))
+NSIM_NETDEV_2=$(make_netdev_from_id "$NSIM_ID2")
+
+PHY3_DFS=$(make_phydev_on_netdev "$NSIM_ID2" 0);
+
+# Check unfiltered PHY Dump
+n_phy=$(ethtool --show-phys '*' | grep -c "PHY index")
+check $? "$n_phy" "3"
+
+# Check filtered Dump
+n_phy=$(ethtool --show-phys "$NSIM_NETDEV" | grep -c "PHY index")
+check $? "$n_phy" "2"
+
+cleanup_netdev_from_id "$NSIM_ID2"
+
+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.49.0
next prev parent reply other threads:[~2025-07-10 6:23 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-10 6:22 [PATCH net-next v3 0/3] netdevsim: add support for PHY devices Maxime Chevallier
2025-07-10 6:22 ` [PATCH net-next v3 1/3] net: netdevsim: Add PHY support in netdevsim Maxime Chevallier
2025-07-11 23:55 ` Jakub Kicinski
2025-07-15 6:08 ` Maxime Chevallier
2025-07-12 16:54 ` Andrew Lunn
2025-07-15 6:05 ` Maxime Chevallier
2025-07-15 13:23 ` Andrew Lunn
2025-07-15 13:56 ` Maxime Chevallier
2025-07-15 15:16 ` Andrew Lunn
2025-07-10 6:22 ` [PATCH net-next v3 2/3] selftests: ethtool: Drop the unused old_netdevs variable Maxime Chevallier
2025-07-10 6:22 ` Maxime Chevallier [this message]
2025-07-11 23:58 ` [PATCH net-next v3 3/3] selftests: ethtool: Introduce ethernet PHY selftests on netdevsim Jakub Kicinski
2025-07-15 5:45 ` Maxime Chevallier
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=20250710062248.378459-4-maxime.chevallier@bootlin.com \
--to=maxime.chevallier@bootlin.com \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=f.fainelli@gmail.com \
--cc=hkallweit1@gmail.com \
--cc=horms@kernel.org \
--cc=kory.maincent@bootlin.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=netdev@vger.kernel.org \
--cc=o.rempel@pengutronix.de \
--cc=pabeni@redhat.com \
--cc=shuah@kernel.org \
--cc=thomas.petazzoni@bootlin.com \
--cc=vladimir.oltean@nxp.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
all inboxes | Powered by JetHome®