~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/drivers/net/hw/ethtool_rmon.sh

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 #!/bin/bash
  2 # SPDX-License-Identifier: GPL-2.0
  3 
  4 ALL_TESTS="
  5         rmon_rx_histogram
  6         rmon_tx_histogram
  7 "
  8 
  9 NUM_NETIFS=2
 10 lib_dir=$(dirname "$0")
 11 source "$lib_dir"/../../../net/forwarding/lib.sh
 12 
 13 ETH_FCS_LEN=4
 14 ETH_HLEN=$((6+6+2))
 15 
 16 declare -A netif_mtu
 17 
 18 ensure_mtu()
 19 {
 20         local iface=$1; shift
 21         local len=$1; shift
 22         local current=$(ip -j link show dev $iface | jq -r '.[0].mtu')
 23         local required=$((len - ETH_HLEN - ETH_FCS_LEN))
 24 
 25         if [ $current -lt $required ]; then
 26                 ip link set dev $iface mtu $required || return 1
 27         fi
 28 }
 29 
 30 bucket_test()
 31 {
 32         local iface=$1; shift
 33         local neigh=$1; shift
 34         local set=$1; shift
 35         local bucket=$1; shift
 36         local len=$1; shift
 37         local num_rx=10000
 38         local num_tx=20000
 39         local expected=
 40         local before=
 41         local after=
 42         local delta=
 43 
 44         # Mausezahn does not include FCS bytes in its length - but the
 45         # histogram counters do
 46         len=$((len - ETH_FCS_LEN))
 47         len=$((len > 0 ? len : 0))
 48 
 49         before=$(ethtool --json -S $iface --groups rmon | \
 50                 jq -r ".[0].rmon[\"${set}-pktsNtoM\"][$bucket].val")
 51 
 52         # Send 10k one way and 20k in the other, to detect counters
 53         # mapped to the wrong direction
 54         $MZ $neigh -q -c $num_rx -p $len -a own -b bcast -d 10us
 55         $MZ $iface -q -c $num_tx -p $len -a own -b bcast -d 10us
 56 
 57         after=$(ethtool --json -S $iface --groups rmon | \
 58                 jq -r ".[0].rmon[\"${set}-pktsNtoM\"][$bucket].val")
 59 
 60         delta=$((after - before))
 61 
 62         expected=$([ $set = rx ] && echo $num_rx || echo $num_tx)
 63 
 64         # Allow some extra tolerance for other packets sent by the stack
 65         [ $delta -ge $expected ] && [ $delta -le $((expected + 100)) ]
 66 }
 67 
 68 rmon_histogram()
 69 {
 70         local iface=$1; shift
 71         local neigh=$1; shift
 72         local set=$1; shift
 73         local nbuckets=0
 74         local step=
 75 
 76         RET=0
 77 
 78         while read -r -a bucket; do
 79                 step="$set-pkts${bucket[0]}to${bucket[1]} on $iface"
 80 
 81                 for if in $iface $neigh; do
 82                         if ! ensure_mtu $if ${bucket[0]}; then
 83                                 log_test_xfail "$if does not support the required MTU for $step"
 84                                 return
 85                         fi
 86                 done
 87 
 88                 if ! bucket_test $iface $neigh $set $nbuckets ${bucket[0]}; then
 89                         check_err 1 "$step failed"
 90                         return 1
 91                 fi
 92                 log_test "$step"
 93                 nbuckets=$((nbuckets + 1))
 94         done < <(ethtool --json -S $iface --groups rmon | \
 95                 jq -r ".[0].rmon[\"${set}-pktsNtoM\"][]|[.low, .high]|@tsv" 2>/dev/null)
 96 
 97         if [ $nbuckets -eq 0 ]; then
 98                 log_test_xfail "$iface does not support $set histogram counters"
 99                 return
100         fi
101 }
102 
103 rmon_rx_histogram()
104 {
105         rmon_histogram $h1 $h2 rx
106         rmon_histogram $h2 $h1 rx
107 }
108 
109 rmon_tx_histogram()
110 {
111         rmon_histogram $h1 $h2 tx
112         rmon_histogram $h2 $h1 tx
113 }
114 
115 setup_prepare()
116 {
117         h1=${NETIFS[p1]}
118         h2=${NETIFS[p2]}
119 
120         for iface in $h1 $h2; do
121                 netif_mtu[$iface]=$(ip -j link show dev $iface | jq -r '.[0].mtu')
122                 ip link set dev $iface up
123         done
124 }
125 
126 cleanup()
127 {
128         pre_cleanup
129 
130         for iface in $h2 $h1; do
131                 ip link set dev $iface \
132                         mtu ${netif_mtu[$iface]} \
133                         down
134         done
135 }
136 
137 check_ethtool_counter_group_support
138 trap cleanup EXIT
139 
140 setup_prepare
141 setup_wait
142 
143 tests_run
144 
145 exit $EXIT_STATUS

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php