Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0-only
3
4source ethtool-common.sh
5
6function 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
13function 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
20if ! ethtool -h | grep -q coalesce; then
21 echo "SKIP: No --coalesce support in ethtool"
22 exit 4
23fi
24
25NSIM_NETDEV=$(make_netdev)
26
27set -o pipefail
28
29declare -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
52declare -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
75declare -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
99for key in ${!SETTINGS_MAP[@]}; do
100 EXPECTED_SETTINGS[$key]=$(get_value $key)
101done
102
103# test
104for 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
115done
116
117# bool settings which ethtool displays on the same line
118ethtool -C $NSIM_NETDEV adaptive-rx on
119s=$(ethtool -c $NSIM_NETDEV | grep -q "Adaptive RX: on TX: off")
120check $? "$s" ""
121
122ethtool -C $NSIM_NETDEV adaptive-tx on
123s=$(ethtool -c $NSIM_NETDEV | grep -q "Adaptive RX: on TX: on")
124check $? "$s" ""
125
126if [ $num_errors -eq 0 ]; then
127 echo "PASSED all $((num_passes)) checks"
128 exit 0
129else
130 echo "FAILED $num_errors/$((num_errors+num_passes)) checks"
131 exit 1
132fi