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

selftests: add ring and coalesce selftests

Add scripts to test ring and coalesce settings
of netdevsim.

Signed-off-by: Antonio Cardace <acardace@redhat.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Antonio Cardace and committed by
Jakub Kicinski
fbb7a1f8 9e48ee80

+217
+132
tools/testing/selftests/drivers/net/netdevsim/ethtool-coalesce.sh
··· 1 + #!/bin/bash 2 + # SPDX-License-Identifier: GPL-2.0-only 3 + 4 + source ethtool-common.sh 5 + 6 + function get_value { 7 + local query="${SETTINGS_MAP[$1]}" 8 + 9 + echo $(ethtool -c $NSIM_NETDEV | \ 10 + awk -F':' -v pattern="$query:" '$0 ~ pattern {gsub(/[ \t]/, "", $2); print $2}') 11 + } 12 + 13 + function update_current_settings { 14 + for key in ${!SETTINGS_MAP[@]}; do 15 + CURRENT_SETTINGS[$key]=$(get_value $key) 16 + done 17 + echo ${CURRENT_SETTINGS[@]} 18 + } 19 + 20 + if ! ethtool -h | grep -q coalesce; then 21 + echo "SKIP: No --coalesce support in ethtool" 22 + exit 4 23 + fi 24 + 25 + NSIM_NETDEV=$(make_netdev) 26 + 27 + set -o pipefail 28 + 29 + declare -A SETTINGS_MAP=( 30 + ["rx-frames-low"]="rx-frame-low" 31 + ["tx-frames-low"]="tx-frame-low" 32 + ["rx-frames-high"]="rx-frame-high" 33 + ["tx-frames-high"]="tx-frame-high" 34 + ["rx-usecs"]="rx-usecs" 35 + ["rx-frames"]="rx-frames" 36 + ["rx-usecs-irq"]="rx-usecs-irq" 37 + ["rx-frames-irq"]="rx-frames-irq" 38 + ["tx-usecs"]="tx-usecs" 39 + ["tx-frames"]="tx-frames" 40 + ["tx-usecs-irq"]="tx-usecs-irq" 41 + ["tx-frames-irq"]="tx-frames-irq" 42 + ["stats-block-usecs"]="stats-block-usecs" 43 + ["pkt-rate-low"]="pkt-rate-low" 44 + ["rx-usecs-low"]="rx-usecs-low" 45 + ["tx-usecs-low"]="tx-usecs-low" 46 + ["pkt-rate-high"]="pkt-rate-high" 47 + ["rx-usecs-high"]="rx-usecs-high" 48 + ["tx-usecs-high"]="tx-usecs-high" 49 + ["sample-interval"]="sample-interval" 50 + ) 51 + 52 + declare -A CURRENT_SETTINGS=( 53 + ["rx-frames-low"]="" 54 + ["tx-frames-low"]="" 55 + ["rx-frames-high"]="" 56 + ["tx-frames-high"]="" 57 + ["rx-usecs"]="" 58 + ["rx-frames"]="" 59 + ["rx-usecs-irq"]="" 60 + ["rx-frames-irq"]="" 61 + ["tx-usecs"]="" 62 + ["tx-frames"]="" 63 + ["tx-usecs-irq"]="" 64 + ["tx-frames-irq"]="" 65 + ["stats-block-usecs"]="" 66 + ["pkt-rate-low"]="" 67 + ["rx-usecs-low"]="" 68 + ["tx-usecs-low"]="" 69 + ["pkt-rate-high"]="" 70 + ["rx-usecs-high"]="" 71 + ["tx-usecs-high"]="" 72 + ["sample-interval"]="" 73 + ) 74 + 75 + declare -A EXPECTED_SETTINGS=( 76 + ["rx-frames-low"]="" 77 + ["tx-frames-low"]="" 78 + ["rx-frames-high"]="" 79 + ["tx-frames-high"]="" 80 + ["rx-usecs"]="" 81 + ["rx-frames"]="" 82 + ["rx-usecs-irq"]="" 83 + ["rx-frames-irq"]="" 84 + ["tx-usecs"]="" 85 + ["tx-frames"]="" 86 + ["tx-usecs-irq"]="" 87 + ["tx-frames-irq"]="" 88 + ["stats-block-usecs"]="" 89 + ["pkt-rate-low"]="" 90 + ["rx-usecs-low"]="" 91 + ["tx-usecs-low"]="" 92 + ["pkt-rate-high"]="" 93 + ["rx-usecs-high"]="" 94 + ["tx-usecs-high"]="" 95 + ["sample-interval"]="" 96 + ) 97 + 98 + # populate the expected settings map 99 + for key in ${!SETTINGS_MAP[@]}; do 100 + EXPECTED_SETTINGS[$key]=$(get_value $key) 101 + done 102 + 103 + # test 104 + for key in ${!SETTINGS_MAP[@]}; do 105 + value=$((RANDOM % $((2**32-1)))) 106 + 107 + ethtool -C $NSIM_NETDEV "$key" "$value" 108 + 109 + EXPECTED_SETTINGS[$key]="$value" 110 + expected=${EXPECTED_SETTINGS[@]} 111 + current=$(update_current_settings) 112 + 113 + check $? "$current" "$expected" 114 + set +x 115 + done 116 + 117 + # bool settings which ethtool displays on the same line 118 + ethtool -C $NSIM_NETDEV adaptive-rx on 119 + s=$(ethtool -c $NSIM_NETDEV | grep -q "Adaptive RX: on TX: off") 120 + check $? "$s" "" 121 + 122 + ethtool -C $NSIM_NETDEV adaptive-tx on 123 + s=$(ethtool -c $NSIM_NETDEV | grep -q "Adaptive RX: on TX: on") 124 + check $? "$s" "" 125 + 126 + if [ $num_errors -eq 0 ]; then 127 + echo "PASSED all $((num_passes)) checks" 128 + exit 0 129 + else 130 + echo "FAILED $num_errors/$((num_errors+num_passes)) checks" 131 + exit 1 132 + fi
+85
tools/testing/selftests/drivers/net/netdevsim/ethtool-ring.sh
··· 1 + #!/bin/bash 2 + # SPDX-License-Identifier: GPL-2.0-only 3 + 4 + source ethtool-common.sh 5 + 6 + function get_value { 7 + local query="${SETTINGS_MAP[$1]}" 8 + 9 + echo $(ethtool -g $NSIM_NETDEV | \ 10 + tail -n +$CURR_SETT_LINE | \ 11 + awk -F':' -v pattern="$query:" '$0 ~ pattern {gsub(/[\t ]/, "", $2); print $2}') 12 + } 13 + 14 + function update_current_settings { 15 + for key in ${!SETTINGS_MAP[@]}; do 16 + CURRENT_SETTINGS[$key]=$(get_value $key) 17 + done 18 + echo ${CURRENT_SETTINGS[@]} 19 + } 20 + 21 + if ! ethtool -h | grep -q set-ring >/dev/null; then 22 + echo "SKIP: No --set-ring support in ethtool" 23 + exit 4 24 + fi 25 + 26 + NSIM_NETDEV=$(make_netdev) 27 + 28 + set -o pipefail 29 + 30 + declare -A SETTINGS_MAP=( 31 + ["rx"]="RX" 32 + ["rx-mini"]="RX Mini" 33 + ["rx-jumbo"]="RX Jumbo" 34 + ["tx"]="TX" 35 + ) 36 + 37 + declare -A EXPECTED_SETTINGS=( 38 + ["rx"]="" 39 + ["rx-mini"]="" 40 + ["rx-jumbo"]="" 41 + ["tx"]="" 42 + ) 43 + 44 + declare -A CURRENT_SETTINGS=( 45 + ["rx"]="" 46 + ["rx-mini"]="" 47 + ["rx-jumbo"]="" 48 + ["tx"]="" 49 + ) 50 + 51 + MAX_VALUE=$((RANDOM % $((2**32-1)))) 52 + RING_MAX_LIST=$(ls $NSIM_DEV_DFS/ethtool/ring/) 53 + 54 + for ring_max_entry in $RING_MAX_LIST; do 55 + echo $MAX_VALUE > $NSIM_DEV_DFS/ethtool/ring/$ring_max_entry 56 + done 57 + 58 + CURR_SETT_LINE=$(ethtool -g $NSIM_NETDEV | grep -i -m1 -n 'Current hardware settings' | cut -f1 -d:) 59 + 60 + # populate the expected settings map 61 + for key in ${!SETTINGS_MAP[@]}; do 62 + EXPECTED_SETTINGS[$key]=$(get_value $key) 63 + done 64 + 65 + # test 66 + for key in ${!SETTINGS_MAP[@]}; do 67 + value=$((RANDOM % $MAX_VALUE)) 68 + 69 + ethtool -G $NSIM_NETDEV "$key" "$value" 70 + 71 + EXPECTED_SETTINGS[$key]="$value" 72 + expected=${EXPECTED_SETTINGS[@]} 73 + current=$(update_current_settings) 74 + 75 + check $? "$current" "$expected" 76 + set +x 77 + done 78 + 79 + if [ $num_errors -eq 0 ]; then 80 + echo "PASSED all $((num_passes)) checks" 81 + exit 0 82 + else 83 + echo "FAILED $num_errors/$((num_errors+num_passes)) checks" 84 + exit 1 85 + fi