aboutsummaryrefslogtreecommitdiffstats
path: root/tools/testing/selftests/drivers/net/netdevsim/ethtool-coalesce.sh
blob: 9adfba8f87e63ffc19c028901181f5b8076c6f74 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0-only

source ethtool-common.sh

function get_value {
    local query="${SETTINGS_MAP[$1]}"

    echo $(ethtool -c $NSIM_NETDEV | \
        awk -F':' -v pattern="$query:" '$0 ~ pattern {gsub(/[ \t]/, "", $2); print $2}')
}

function update_current_settings {
    for key in ${!SETTINGS_MAP[@]}; do
        CURRENT_SETTINGS[$key]=$(get_value $key)
    done
    echo ${CURRENT_SETTINGS[@]}
}

if ! ethtool -h | grep -q coalesce; then
    echo "SKIP: No --coalesce support in ethtool"
    exit 4
fi

NSIM_NETDEV=$(make_netdev)

set -o pipefail

declare -A SETTINGS_MAP=(
    ["rx-frames-low"]="rx-frame-low"
    ["tx-frames-low"]="tx-frame-low"
    ["rx-frames-high"]="rx-frame-high"
    ["tx-frames-high"]="tx-frame-high"
    ["rx-usecs"]="rx-usecs"
    ["rx-frames"]="rx-frames"
    ["rx-usecs-irq"]="rx-usecs-irq"
    ["rx-frames-irq"]="rx-frames-irq"
    ["tx-usecs"]="tx-usecs"
    ["tx-frames"]="tx-frames"
    ["tx-usecs-irq"]="tx-usecs-irq"
    ["tx-frames-irq"]="tx-frames-irq"
    ["stats-block-usecs"]="stats-block-usecs"
    ["pkt-rate-low"]="pkt-rate-low"
    ["rx-usecs-low"]="rx-usecs-low"
    ["tx-usecs-low"]="tx-usecs-low"
    ["pkt-rate-high"]="pkt-rate-high"
    ["rx-usecs-high"]="rx-usecs-high"
    ["tx-usecs-high"]="tx-usecs-high"
    ["sample-interval"]="sample-interval"
)

declare -A CURRENT_SETTINGS=(
    ["rx-frames-low"]=""
    ["tx-frames-low"]=""
    ["rx-frames-high"]=""
    ["tx-frames-high"]=""
    ["rx-usecs"]=""
    ["rx-frames"]=""
    ["rx-usecs-irq"]=""
    ["rx-frames-irq"]=""
    ["tx-usecs"]=""
    ["tx-frames"]=""
    ["tx-usecs-irq"]=""
    ["tx-frames-irq"]=""
    ["stats-block-usecs"]=""
    ["pkt-rate-low"]=""
    ["rx-usecs-low"]=""
    ["tx-usecs-low"]=""
    ["pkt-rate-high"]=""
    ["rx-usecs-high"]=""
    ["tx-usecs-high"]=""
    ["sample-interval"]=""
)

declare -A EXPECTED_SETTINGS=(
    ["rx-frames-low"]=""
    ["tx-frames-low"]=""
    ["rx-frames-high"]=""
    ["tx-frames-high"]=""
    ["rx-usecs"]=""
    ["rx-frames"]=""
    ["rx-usecs-irq"]=""
    ["rx-frames-irq"]=""
    ["tx-usecs"]=""
    ["tx-frames"]=""
    ["tx-usecs-irq"]=""
    ["tx-frames-irq"]=""
    ["stats-block-usecs"]=""
    ["pkt-rate-low"]=""
    ["rx-usecs-low"]=""
    ["tx-usecs-low"]=""
    ["pkt-rate-high"]=""
    ["rx-usecs-high"]=""
    ["tx-usecs-high"]=""
    ["sample-interval"]=""
)

# populate the expected settings map
for key in ${!SETTINGS_MAP[@]}; do
    EXPECTED_SETTINGS[$key]=$(get_value $key)
done

# test
for key in ${!SETTINGS_MAP[@]}; do
    value=$((RANDOM % $((2**32-1))))

    ethtool -C $NSIM_NETDEV "$key" "$value"

    EXPECTED_SETTINGS[$key]="$value"
    expected=${EXPECTED_SETTINGS[@]}
    current=$(update_current_settings)

    check $? "$current" "$expected"
    set +x
done

# bool settings which ethtool displays on the same line
ethtool -C $NSIM_NETDEV adaptive-rx on
s=$(ethtool -c $NSIM_NETDEV | grep -q "Adaptive RX: on  TX: off")
check $? "$s" ""

ethtool -C $NSIM_NETDEV adaptive-tx on
s=$(ethtool -c $NSIM_NETDEV | grep -q "Adaptive RX: on  TX: on")
check $? "$s" ""

if [ $num_errors -eq 0 ]; then
    echo "PASSED all $((num_passes)) checks"
    exit 0
else
    echo "FAILED $num_errors/$((num_errors+num_passes)) checks"
    exit 1
fi