[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240412151314.3365034-4-jiri@resnulli.us>
Date: Fri, 12 Apr 2024 17:13:11 +0200
From: Jiri Pirko <jiri@...nulli.us>
To: netdev@...r.kernel.org
Cc: kuba@...nel.org,
pabeni@...hat.com,
davem@...emloft.net,
edumazet@...gle.com,
parav@...dia.com,
mst@...hat.com,
jasowang@...hat.com,
xuanzhuo@...ux.alibaba.com,
shuah@...nel.org,
petrm@...dia.com,
liuhangbin@...il.com,
vladimir.oltean@....com,
bpoirier@...dia.com,
idosch@...dia.com,
virtualization@...ts.linux.dev
Subject: [patch net-next 3/6] selftests: forwarding: add ability to assemble NETIFS array by driver name
From: Jiri Pirko <jiri@...dia.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@...dia.com>
---
tools/testing/selftests/net/forwarding/lib.sh | 39 +++++++++++++++++++
1 file changed, 39 insertions(+)
diff --git a/tools/testing/selftests/net/forwarding/lib.sh b/tools/testing/selftests/net/forwarding/lib.sh
index 6f6a0f13465f..06633518b3aa 100644
--- a/tools/testing/selftests/net/forwarding/lib.sh
+++ b/tools/testing/selftests/net/forwarding/lib.sh
@@ -55,6 +55,9 @@ declare -A NETIFS=(
: "${NETIF_CREATE:=yes}"
: "${NETIF_TYPE:=veth}"
+# Whether to find netdevice according to the specified driver.
+: "${NETIF_FIND_DRIVER:=}"
+
# Constants for ping tests:
# How many packets should be sent.
: "${PING_COUNT:=10}"
@@ -94,6 +97,42 @@ if [[ ! -v NUM_NETIFS ]]; then
exit $ksft_skip
fi
+##############################################################################
+# 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
+ echo ""
+ else
+ basename `realpath $driver_path`
+ fi
+}
+
+find_netif()
+{
+ local ifnames=`ip -j -p link show | jq -e -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
+}
+
+if [[ ! -z $NETIF_FIND_DRIVER ]]; then
+ unset NETIFS
+ declare -A NETIFS
+ find_netif
+fi
+
net_forwarding_dir=$(dirname "$(readlink -e "${BASH_SOURCE[0]}")")
if [[ -f $net_forwarding_dir/forwarding.config ]]; then
--
2.44.0
Powered by blists - more mailing lists