selftest: netdevsim: Add devlink rate test
authorDmytro Linkin <dlinkin@nvidia.com>
Wed, 2 Jun 2021 12:17:21 +0000 (15:17 +0300)
committerDavid S. Miller <davem@davemloft.net>
Wed, 2 Jun 2021 21:08:37 +0000 (14:08 -0700)
Test verifies that all netdevsim VF ports have rate leaf object created
by default.

Co-developed-by: Vlad Buslov <vladbu@nvidia.com>
Signed-off-by: Vlad Buslov <vladbu@nvidia.com>
Signed-off-by: Dmytro Linkin <dlinkin@nvidia.com>
Reviewed-by: Jiri Pirko <jiri@nvidia.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
tools/testing/selftests/drivers/net/netdevsim/devlink.sh

index 40909c2..c654be0 100755 (executable)
@@ -5,12 +5,13 @@ lib_dir=$(dirname $0)/../../../net/forwarding
 
 ALL_TESTS="fw_flash_test params_test regions_test reload_test \
           netns_reload_test resource_test dev_info_test \
-          empty_reporter_test dummy_reporter_test"
+          empty_reporter_test dummy_reporter_test rate_test"
 NUM_NETIFS=0
 source $lib_dir/lib.sh
 
 BUS_ADDR=10
 PORT_COUNT=4
+VF_COUNT=4
 DEV_NAME=netdevsim$BUS_ADDR
 SYSFS_NET_DIR=/sys/bus/netdevsim/devices/$DEV_NAME/net/
 DEBUGFS_DIR=/sys/kernel/debug/netdevsim/$DEV_NAME/
@@ -507,6 +508,28 @@ dummy_reporter_test()
        log_test "dummy reporter test"
 }
 
+rate_leafs_get()
+{
+       local handle=$1
+
+       cmd_jq "devlink port function rate show -j" \
+              '.[] | to_entries | .[] | select(.value.type == "leaf") | .key | select(contains("'$handle'"))'
+}
+
+rate_test()
+{
+       RET=0
+
+       echo $VF_COUNT > /sys/bus/netdevsim/devices/$DEV_NAME/sriov_numvfs
+       devlink dev eswitch set $DL_HANDLE mode switchdev
+       local leafs=`rate_leafs_get $DL_HANDLE`
+       local num_leafs=`echo $leafs | wc -w`
+       [ "$num_leafs" == "$VF_COUNT" ]
+       check_err $? "Expected $VF_COUNT rate leafs but got $num_leafs"
+
+       log_test "rate test"
+}
+
 setup_prepare()
 {
        modprobe netdevsim