Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests: lib: Add a generic helper for obtaining HW stats

The function get_l3_stats() from the test hw_stats_l3.sh will be useful for
any test that wishes to work with L3 stats. Furthermore, it is easy to
generalize to other HW stats suites (for when such are added). Therefore,
move the code to lib.sh, rewrite it to have the same interface as the other
stats-collecting functions, and generalize to take the name of the HW stats
suite to collect as an argument.

Signed-off-by: Petr Machata <petrm@nvidia.com>
Signed-off-by: Ido Schimmel <idosch@nvidia.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Petr Machata and committed by
David S. Miller
32fb67a3 c353fb0d

+15 -12
+4 -12
tools/testing/selftests/net/forwarding/hw_stats_l3.sh
··· 162 162 ping_test $h1.200 2001:db8:2::1 " IPv6" 163 163 } 164 164 165 - get_l3_stat() 166 - { 167 - local selector=$1; shift 168 - 169 - ip -j stats show dev $rp1.200 group offload subgroup l3_stats | 170 - jq '.[0].stats64.'$selector 171 - } 172 - 173 165 send_packets_rx_ipv4() 174 166 { 175 167 # Send 21 packets instead of 20, because the first one might trap and go ··· 200 208 local a 201 209 local b 202 210 203 - a=$(get_l3_stat ${dir}.packets) 211 + a=$(hw_stats_get l3_stats $rp1.200 ${dir} packets) 204 212 send_packets_${dir}_${prot} 205 213 "$@" 206 214 b=$(busywait "$TC_HIT_TIMEOUT" until_counter_is ">= $a + 20" \ 207 - get_l3_stat ${dir}.packets) 215 + hw_stats_get l3_stats $rp1.200 ${dir} packets) 208 216 check_err $? "Traffic not reflected in the counter: $a -> $b" 209 217 } 210 218 ··· 273 281 274 282 RET=0 275 283 276 - a=$(get_l3_stat ${dir}.packets) 284 + a=$(hw_stats_get l3_stats $rp1.200 ${dir} packets) 277 285 send_packets_${dir}_${prot} 278 286 ip address flush dev $rp1.200 279 287 b=$(busywait "$TC_HIT_TIMEOUT" until_counter_is ">= $a + 20" \ 280 - get_l3_stat ${dir}.packets) 288 + hw_stats_get l3_stats $rp1.200 ${dir} packets) 281 289 check_err $? "Traffic not reflected in the counter: $a -> $b" 282 290 log_test "Test ${dir} packets: stats pushed on loss of L3" 283 291
+11
tools/testing/selftests/net/forwarding/lib.sh
··· 828 828 cat /proc/net/dev_snmp6/$dev | grep "^$stat" | cut -f2 829 829 } 830 830 831 + hw_stats_get() 832 + { 833 + local suite=$1; shift 834 + local if_name=$1; shift 835 + local dir=$1; shift 836 + local stat=$1; shift 837 + 838 + ip -j stats show dev $if_name group offload subgroup $suite | 839 + jq ".[0].stats64.$dir.$stat" 840 + } 841 + 831 842 humanize() 832 843 { 833 844 local speed=$1; shift