OSDN Git Service

selftests: devlink_lib: Split out helper
authorIdo Schimmel <idosch@nvidia.com>
Tue, 8 Nov 2022 10:47:18 +0000 (11:47 +0100)
committerJakub Kicinski <kuba@kernel.org>
Thu, 10 Nov 2022 03:06:15 +0000 (19:06 -0800)
Merely checking whether a trap counter incremented or not without
logging a test result is useful on its own. Split this functionality to
a helper which will be used by subsequent patches.

Signed-off-by: Ido Schimmel <idosch@nvidia.com>
Reviewed-by: Petr Machata <petrm@nvidia.com>
Signed-off-by: Petr Machata <petrm@nvidia.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
tools/testing/selftests/net/forwarding/devlink_lib.sh

index 601990c..f1de525 100644 (file)
@@ -503,25 +503,30 @@ devlink_trap_drop_cleanup()
        tc filter del dev $dev egress protocol $proto pref $pref handle $handle flower
 }
 
-devlink_trap_stats_test()
+devlink_trap_stats_check()
 {
-       local test_name=$1; shift
        local trap_name=$1; shift
        local send_one="$@"
        local t0_packets
        local t1_packets
 
-       RET=0
-
        t0_packets=$(devlink_trap_rx_packets_get $trap_name)
 
        $send_one && sleep 1
 
        t1_packets=$(devlink_trap_rx_packets_get $trap_name)
 
-       if [[ $t1_packets -eq $t0_packets ]]; then
-               check_err 1 "Trap stats did not increase"
-       fi
+       [[ $t1_packets -ne $t0_packets ]]
+}
+
+devlink_trap_stats_test()
+{
+       local test_name=$1; shift
+
+       RET=0
+
+       devlink_trap_stats_check "$@"
+       check_err $? "Trap stats did not increase"
 
        log_test "$test_name"
 }