From: Jiri Pirko <jiri@resnulli.us>
To: netdev@vger.kernel.org
Cc: kuba@kernel.org, pabeni@redhat.com, davem@davemloft.net,
edumazet@google.com, parav@nvidia.com, mst@redhat.com,
jasowang@redhat.com, xuanzhuo@linux.alibaba.com,
shuah@kernel.org, petrm@nvidia.com, liuhangbin@gmail.com,
vladimir.oltean@nxp.com, bpoirier@nvidia.com, idosch@nvidia.com,
virtualization@lists.linux.dev
Subject: [patch net-next v5 2/5] selftests: forwarding: add ability to assemble NETIFS array by driver name
Date: Mon, 22 Apr 2024 17:32:57 +0200 [thread overview]
Message-ID: <20240422153303.3860947-2-jiri@resnulli.us> (raw)
In-Reply-To: <20240418160830.3751846-1-jiri@resnulli.us>
From: Jiri Pirko <jiri@nvidia.com>
Allow driver tests to work without specifying the netdevice names.
Introduce a possibility to search for available netdevices according to
set driver name. Allow test to specify the name by setting
NETIF_FIND_DRIVER variable.
Note that user overrides this either by passing netdevice names on the
command line or by declaring NETIFS array in custom forwarding.config
configuration file.
Signed-off-by: Jiri Pirko <jiri@nvidia.com>
Reviewed-by: Petr Machata <petrm@nvidia.com>
---
v4->v5:
- rebased on top of previous patch removal
v3->v4:
- rebased on top of changes in patch #2
- reworded NETIF_FIND_DRIVER comment to explicitly refer to "importer"
- simplified driver_name_get() avoiding else branch
- s/find_netif/netif_find_driver/
v1->v2:
- removed unnecessary "-p" and "-e" options
- removed unnecessary "! -z" from the check
- moved NETIF_FIND_DRIVER declaration from the config options
---
tools/testing/selftests/net/forwarding/lib.sh | 37 +++++++++++++++++++
1 file changed, 37 insertions(+)
diff --git a/tools/testing/selftests/net/forwarding/lib.sh b/tools/testing/selftests/net/forwarding/lib.sh
index 7913c6ee418d..9d6802c6c023 100644
--- a/tools/testing/selftests/net/forwarding/lib.sh
+++ b/tools/testing/selftests/net/forwarding/lib.sh
@@ -84,6 +84,43 @@ declare -A NETIFS=(
# e.g. a low-power board.
: "${KSFT_MACHINE_SLOW:=no}"
+##############################################################################
+# Find netifs by test-specified driver name
+
+driver_name_get()
+{
+ local dev=$1; shift
+ local driver_path="/sys/class/net/$dev/device/driver"
+
+ if [[ -L $driver_path ]]; then
+ basename `realpath $driver_path`
+ fi
+}
+
+netif_find_driver()
+{
+ local ifnames=`ip -j link show | jq -r ".[].ifname"`
+ local count=0
+
+ for ifname in $ifnames
+ do
+ local driver_name=`driver_name_get $ifname`
+ if [[ ! -z $driver_name && $driver_name == $NETIF_FIND_DRIVER ]]; then
+ count=$((count + 1))
+ NETIFS[p$count]="$ifname"
+ fi
+ done
+}
+
+# Whether to find netdevice according to the driver speficied by the importer
+: "${NETIF_FIND_DRIVER:=}"
+
+if [[ $NETIF_FIND_DRIVER ]]; then
+ unset NETIFS
+ declare -A NETIFS
+ netif_find_driver
+fi
+
net_forwarding_dir=$(dirname "$(readlink -e "${BASH_SOURCE[0]}")")
if [[ -f $net_forwarding_dir/forwarding.config ]]; then
--
2.44.0
next prev parent reply other threads:[~2024-04-22 15:33 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-18 16:08 [patch net-next v4 0/6] selftests: virtio_net: introduce initial testing infrastructure Jiri Pirko
2024-04-18 16:08 ` [patch net-next v4 1/6] virtio: add debugfs infrastructure to allow to debug virtio features Jiri Pirko
2024-04-19 23:52 ` kernel test robot
2024-04-18 16:08 ` [patch net-next v4 2/6] selftests: forwarding: move initial root check to the beginning Jiri Pirko
2024-04-18 16:56 ` Petr Machata
2024-04-18 18:48 ` Benjamin Poirier
2024-04-19 13:51 ` Jiri Pirko
2024-04-18 16:08 ` [patch net-next v4 3/6] selftests: forwarding: add ability to assemble NETIFS array by driver name Jiri Pirko
2024-04-18 16:58 ` Petr Machata
2024-04-18 16:08 ` [patch net-next v4 4/6] selftests: forwarding: add check_driver() helper Jiri Pirko
2024-04-18 16:08 ` [patch net-next v4 5/6] selftests: forwarding: add wait_for_dev() helper Jiri Pirko
2024-04-18 16:59 ` Petr Machata
2024-04-18 16:08 ` [patch net-next v4 6/6] selftests: virtio_net: add initial tests Jiri Pirko
2024-04-18 17:01 ` Petr Machata
2024-04-22 15:32 ` [patch net-next v5 0/5] selftests: virtio_net: introduce initial testing infrastructure Jiri Pirko
2024-04-22 15:32 ` [patch net-next v5 1/5] virtio: add debugfs infrastructure to allow to debug virtio features Jiri Pirko
2024-04-22 15:32 ` Jiri Pirko [this message]
2024-04-22 15:32 ` [patch net-next v5 3/5] selftests: forwarding: add check_driver() helper Jiri Pirko
2024-04-22 18:47 ` Benjamin Poirier
2024-04-23 10:59 ` Jiri Pirko
2024-04-22 15:32 ` [patch net-next v5 4/5] selftests: forwarding: add wait_for_dev() helper Jiri Pirko
2024-04-22 15:33 ` [patch net-next v5 5/5] selftests: virtio_net: add initial tests Jiri Pirko
2024-04-22 21:04 ` [patch net-next v4 0/6] selftests: virtio_net: introduce initial testing infrastructure Michael S. Tsirkin
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=20240422153303.3860947-2-jiri@resnulli.us \
--to=jiri@resnulli.us \
--cc=bpoirier@nvidia.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=idosch@nvidia.com \
--cc=jasowang@redhat.com \
--cc=kuba@kernel.org \
--cc=liuhangbin@gmail.com \
--cc=mst@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=parav@nvidia.com \
--cc=petrm@nvidia.com \
--cc=shuah@kernel.org \
--cc=virtualization@lists.linux.dev \
--cc=vladimir.oltean@nxp.com \
--cc=xuanzhuo@linux.alibaba.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;
as well as URLs for NNTP newsgroup(s).