From nobody Wed Oct 8 05:52:40 2025 Received: from relay15.mail.gandi.net (relay15.mail.gandi.net [217.70.178.235]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 89799238C16; Wed, 2 Jul 2025 08:28:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.178.235 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751444906; cv=none; b=Vn26NhkSxOEoJv9QL1Xu+lchCF++Y+VrvQk3HXOjWBtvjnztElhznQYRWBnqTCsonV2u2+JV4VfOtxqCvUpfsOpFUBS0Rmxi5PGu/ERhM+nb6kHtzXQgPGf0f+4hrn4D4PnjOot7wHohJQgcQhnThcikaKUgktIfSE0f8JvXPQo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751444906; c=relaxed/simple; bh=qHk9m++LBoQx3yiAbc9n1ih8ke/7OTNO0TG9b0fRLmg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qAXsEaF+gz1Z2mmNW0zA4FDNh/szBqpBtIlTyyhXU4f6kkBf2nuGqnxdQNJ9ui+npLkUkuv6e7APsXTIz0LmhMcM3SFqoUqZ6vc1AkgrvxVG/rR4IZ5komPHOhMn1DX8EIiwXVNAUQ2ylSWfqsavttDqtr5nzImAE3RmLB6dIVA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=LNodZ4nY; arc=none smtp.client-ip=217.70.178.235 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="LNodZ4nY" Received: by mail.gandi.net (Postfix) with ESMTPSA id BE9A443184; Wed, 2 Jul 2025 08:28:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1751444895; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Tj6eZS5+WFS158/nz+Vj1Mv/y1Y7UeIf31eukYPIixI=; b=LNodZ4nYYCUz4vO99K3G5/Cmr5ybFCmpiOy0Jc23cyvaeK9ygWD1kTx30M+LZ5M0m4lx0x lNoTTvr8Q/4TXRSgFhDen7kfv4xJJnSaiuL11bvIVL54Lzwaje3lT4Pkt8rNBiFhYn+GYk nWLR+ngRCeuz19zN/P+YcnvAbn5v8U89ZUjcoxU8UiFaxjDp4mDli1n/OQruLgglV91jyA xMxrcWHC9ovBMVjzx7n/wNTkMi5ik1phKh4Kd109SCLEUqNPtDzHpUT086/iyqbPlOZFBx x6YLiDnhlA6YNs95nUd7sPdIqusr+LkYmxlS3l0Xaj0R9sF7hsc1JY74tBMgIw== From: Maxime Chevallier To: davem@davemloft.net Cc: Maxime Chevallier , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, thomas.petazzoni@bootlin.com, Andrew Lunn , Jakub Kicinski , Eric Dumazet , Paolo Abeni , Russell King , Florian Fainelli , Heiner Kallweit , Vladimir Oltean , =?UTF-8?q?K=C3=B6ry=20Maincent?= , Oleksij Rempel , Simon Horman , Shuah Khan , linux-kselftest@vger.kernel.org Subject: [PATCH net-next 3/3] selftests: ethtool: Introduce ethernet PHY selftests on netdevsim Date: Wed, 2 Jul 2025 10:28:05 +0200 Message-ID: <20250702082806.706973-4-maxime.chevallier@bootlin.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250702082806.706973-1-maxime.chevallier@bootlin.com> References: <20250702082806.706973-1-maxime.chevallier@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-GND-State: clean X-GND-Score: -100 X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdefgdduieelvdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfitefpfffkpdcuggftfghnshhusghstghrihgsvgenuceurghilhhouhhtmecufedtudenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkofgjfhgggfestdekredtredttdenucfhrhhomhepofgrgihimhgvucevhhgvvhgrlhhlihgvrhcuoehmrgigihhmvgdrtghhvghvrghllhhivghrsegsohhothhlihhnrdgtohhmqeenucggtffrrghtthgvrhhnpeevgedtffelffelveeuleelgfejfeevvdejhfehgeefgfffvdefteegvedutefftdenucfkphepvdgrtddumegtsgduleemkegugeehmeegledttdemieehieekmedvlegsudemlegvfhehmegvkegtjeenucevlhhushhtvghrufhiiigvpedvnecurfgrrhgrmhepihhnvghtpedvrgdtudemtggsudelmeekugegheemgeeltddtmeeiheeikeemvdelsgdumeelvghfheemvgektgejpdhhvghlohepfhgvughorhgrrdhhohhmvgdpmhgrihhlfhhrohhmpehmrgigihhmvgdrtghhvghvrghllhhivghrsegsohhothhlihhnrdgtohhmpdhnsggprhgtphhtthhopedukedprhgtphhtthhopegurghvvghmsegurghvvghmlhhofhhtrdhnvghtpdhrtghpthhtohepmhgrgihimhgvrdgthhgvvhgrlhhlihgvrhessghoohhtlhhinhdrtghomhdprhgtphhtthhopehnvghtuggvvhesvhhgvghrrdhkv ghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehthhhomhgrshdrphgvthgriiiiohhnihessghoohhtlhhinhdrtghomhdprhgtphhtthhopegrnhgurhgvfieslhhunhhnrdgthhdprhgtphhtthhopehkuhgsrgeskhgvrhhnvghlrdhorhhgpdhrtghpthhtohepvgguuhhmrgiivghtsehgohhoghhlvgdrtghomh Content-Type: text/plain; charset="utf-8" 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 --- .../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-p= hy.sh diff --git a/tools/testing/selftests/drivers/net/netdevsim/config b/tools/t= esting/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=3Dm CONFIG_NET_SCH_MQPRIO=3Dy CONFIG_NET_SCH_MULTIQ=3Dy CONFIG_NET_SCH_PRIO=3Dy +CONFIG_PHYLIB=3Dm CONFIG_PSAMPLE=3Dy CONFIG_PTP_1588_CLOCK_MOCK=3Dy CONFIG_VXLAN=3Dm diff --git a/tools/testing/selftests/drivers/net/netdevsim/ethtool-common.s= h 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=3D$1 + local parent=3D$2 + + local ndev_dfs=3D/sys/kernel/debug/netdevsim/netdevsim$parent_ndev_nsi= m_id/ports/0 + + old_dev_dfs=3D$(find $ndev_dfs -type d) + echo $parent > $ndev_dfs/phy_add + new_dev_dfs=3D$(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..7b740a3fda1d --- /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 2>&1 >/dev/null; then + echo "SKIP: No --show-phys support in ethtool" + exit 4 +fi + +function make_netdev_from_id { + local new_nsim_id=3D"$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=3D"$1" + echo $to_del_nsim_id > /sys/bus/netdevsim/del_device +} + +NSIM_NETDEV=3D$(make_netdev) + +set -o pipefail + +# Check simple PHY addition and listing + +# Parent =3D=3D 0 means that the PHY's parent is the netdev +PHY_DFS=3D$(make_phydev_on_netdev $NSIM_ID 0) + +# First PHY gets index 1 +index=3D$(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=3D$(make_phydev_on_netdev $NSIM_ID 0) + +# Create another netdev +NSIM_ID2=3D$((RANDOM % 1024)) +NSIM_NETDEV_2=3D$(make_netdev_from_id "$NSIM_ID2") + +PHY3_DFS=3D$(make_phydev_on_netdev $NSIM_ID2 0); + +# Check unfiltered PHY Dump +n_phy=3D$(ethtool --show-phys '*' | grep "PHY index" | wc -l) +check $? "$n_phy" "3" + +# Check filtered Dump +n_phy=3D$(ethtool --show-phys $NSIM_NETDEV | grep "PHY index" | wc -l) +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 --=20 2.49.0