On 2024-04-12 17:13 +0200, Jiri Pirko wrote: > From: Jiri Pirko <jiri@xxxxxxxxxx> > > 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@xxxxxxxxxx> > --- > 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:=}" > + This section of the file sets default values for variables that can be set by users in forwarding.config. NETIF_FIND_DRIVER is more like NUM_NETIFS, it is set by tests, so I don't think it should be listed there. > # 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"` -p and -e can be omitted