Path: blob/master/tools/testing/selftests/drivers/net/hw/ethtool_rmon.sh
26295 views
#!/bin/bash1# SPDX-License-Identifier: GPL-2.023ALL_TESTS="4rmon_rx_histogram5rmon_tx_histogram6"78NUM_NETIFS=29lib_dir=$(dirname "$0")10source "$lib_dir"/../../../net/forwarding/lib.sh1112ETH_FCS_LEN=413ETH_HLEN=$((6+6+2))1415declare -A netif_mtu1617ensure_mtu()18{19local iface=$1; shift20local len=$1; shift21local current=$(ip -j link show dev $iface | jq -r '.[0].mtu')22local required=$((len - ETH_HLEN - ETH_FCS_LEN))2324if [ $current -lt $required ]; then25ip link set dev $iface mtu $required || return 126fi27}2829bucket_test()30{31local iface=$1; shift32local neigh=$1; shift33local set=$1; shift34local bucket=$1; shift35local len=$1; shift36local num_rx=1000037local num_tx=2000038local expected=39local before=40local after=41local delta=4243# Mausezahn does not include FCS bytes in its length - but the44# histogram counters do45len=$((len - ETH_FCS_LEN))46len=$((len > 0 ? len : 0))4748before=$(ethtool --json -S $iface --groups rmon | \49jq -r ".[0].rmon[\"${set}-pktsNtoM\"][$bucket].val")5051# Send 10k one way and 20k in the other, to detect counters52# mapped to the wrong direction53$MZ $neigh -q -c $num_rx -p $len -a own -b bcast -d 10us54$MZ $iface -q -c $num_tx -p $len -a own -b bcast -d 10us5556after=$(ethtool --json -S $iface --groups rmon | \57jq -r ".[0].rmon[\"${set}-pktsNtoM\"][$bucket].val")5859delta=$((after - before))6061expected=$([ $set = rx ] && echo $num_rx || echo $num_tx)6263# Allow some extra tolerance for other packets sent by the stack64[ $delta -ge $expected ] && [ $delta -le $((expected + 100)) ]65}6667rmon_histogram()68{69local iface=$1; shift70local neigh=$1; shift71local set=$1; shift72local nbuckets=073local step=7475RET=07677while read -r -a bucket; do78step="$set-pkts${bucket[0]}to${bucket[1]} on $iface"7980for if in $iface $neigh; do81if ! ensure_mtu $if ${bucket[0]}; then82log_test_xfail "$if does not support the required MTU for $step"83return84fi85done8687if ! bucket_test $iface $neigh $set $nbuckets ${bucket[0]}; then88check_err 1 "$step failed"89return 190fi91log_test "$step"92nbuckets=$((nbuckets + 1))93done < <(ethtool --json -S $iface --groups rmon | \94jq -r ".[0].rmon[\"${set}-pktsNtoM\"][]|[.low, .high]|@tsv" 2>/dev/null)9596if [ $nbuckets -eq 0 ]; then97log_test_xfail "$iface does not support $set histogram counters"98return99fi100}101102rmon_rx_histogram()103{104rmon_histogram $h1 $h2 rx105rmon_histogram $h2 $h1 rx106}107108rmon_tx_histogram()109{110rmon_histogram $h1 $h2 tx111rmon_histogram $h2 $h1 tx112}113114setup_prepare()115{116h1=${NETIFS[p1]}117h2=${NETIFS[p2]}118119for iface in $h1 $h2; do120netif_mtu[$iface]=$(ip -j link show dev $iface | jq -r '.[0].mtu')121ip link set dev $iface up122done123}124125cleanup()126{127pre_cleanup128129for iface in $h2 $h1; do130ip link set dev $iface \131mtu ${netif_mtu[$iface]} \132down133done134}135136check_ethtool_counter_group_support137trap cleanup EXIT138139setup_prepare140setup_wait141142tests_run143144exit $EXIT_STATUS145146147