Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
torvalds
GitHub Repository: torvalds/linux
Path: blob/master/tools/net/ynl/tests/test_ynl_ethtool.sh
38189 views
1
#!/bin/bash
2
# SPDX-License-Identifier: GPL-2.0
3
# Test YNL ethtool functionality
4
5
# Load KTAP test helpers
6
KSELFTEST_KTAP_HELPERS="$(dirname "$(realpath "$0")")/../../../testing/selftests/kselftest/ktap_helpers.sh"
7
# shellcheck source=../../../testing/selftests/kselftest/ktap_helpers.sh
8
source "$KSELFTEST_KTAP_HELPERS"
9
10
# Default ynl-ethtool path for direct execution, can be overridden by make install
11
ynl_ethtool="../pyynl/ethtool.py"
12
13
readonly NSIM_ID="1337"
14
readonly NSIM_DEV_NAME="nsim${NSIM_ID}"
15
readonly VETH_A="veth_a"
16
readonly VETH_B="veth_b"
17
18
testns="ynl-ethtool-$(mktemp -u XXXXXX)"
19
TESTS_NO=0
20
21
# Uses veth device as netdevsim doesn't support basic ethtool device info
22
ethtool_device_info()
23
{
24
local info_output
25
26
info_output=$(ip netns exec "$testns" $ynl_ethtool "$VETH_A" 2>/dev/null)
27
28
if ! echo "$info_output" | grep -q "Settings for"; then
29
ktap_test_fail "YNL ethtool device info (device info output missing expected content)"
30
return
31
fi
32
33
ktap_test_pass "YNL ethtool device info"
34
}
35
TESTS_NO=$((TESTS_NO + 1))
36
37
ethtool_statistics()
38
{
39
local stats_output
40
41
stats_output=$(ip netns exec "$testns" $ynl_ethtool --statistics "$NSIM_DEV_NAME" 2>/dev/null)
42
43
if ! echo "$stats_output" | grep -q -E "(NIC statistics|packets|bytes)"; then
44
ktap_test_fail "YNL ethtool statistics (statistics output missing expected content)"
45
return
46
fi
47
48
ktap_test_pass "YNL ethtool statistics"
49
}
50
TESTS_NO=$((TESTS_NO + 1))
51
52
ethtool_ring_params()
53
{
54
local ring_output
55
56
ring_output=$(ip netns exec "$testns" $ynl_ethtool --show-ring "$NSIM_DEV_NAME" 2>/dev/null)
57
58
if ! echo "$ring_output" | grep -q -E "(Ring parameters|RX|TX)"; then
59
ktap_test_fail "YNL ethtool ring parameters (ring parameters output missing expected content)"
60
return
61
fi
62
63
if ! ip netns exec "$testns" $ynl_ethtool --set-ring "$NSIM_DEV_NAME" rx 64 2>/dev/null; then
64
ktap_test_fail "YNL ethtool ring parameters (set-ring command failed unexpectedly)"
65
return
66
fi
67
68
ktap_test_pass "YNL ethtool ring parameters (show/set)"
69
}
70
TESTS_NO=$((TESTS_NO + 1))
71
72
ethtool_coalesce_params()
73
{
74
if ! ip netns exec "$testns" $ynl_ethtool --show-coalesce "$NSIM_DEV_NAME" &>/dev/null; then
75
ktap_test_fail "YNL ethtool coalesce parameters (failed to get coalesce parameters)"
76
return
77
fi
78
79
if ! ip netns exec "$testns" $ynl_ethtool --set-coalesce "$NSIM_DEV_NAME" rx-usecs 50 2>/dev/null; then
80
ktap_test_fail "YNL ethtool coalesce parameters (set-coalesce command failed unexpectedly)"
81
return
82
fi
83
84
ktap_test_pass "YNL ethtool coalesce parameters (show/set)"
85
}
86
TESTS_NO=$((TESTS_NO + 1))
87
88
ethtool_pause_params()
89
{
90
if ! ip netns exec "$testns" $ynl_ethtool --show-pause "$NSIM_DEV_NAME" &>/dev/null; then
91
ktap_test_fail "YNL ethtool pause parameters (failed to get pause parameters)"
92
return
93
fi
94
95
if ! ip netns exec "$testns" $ynl_ethtool --set-pause "$NSIM_DEV_NAME" tx 1 rx 1 2>/dev/null; then
96
ktap_test_fail "YNL ethtool pause parameters (set-pause command failed unexpectedly)"
97
return
98
fi
99
100
ktap_test_pass "YNL ethtool pause parameters (show/set)"
101
}
102
TESTS_NO=$((TESTS_NO + 1))
103
104
ethtool_features_info()
105
{
106
local features_output
107
108
features_output=$(ip netns exec "$testns" $ynl_ethtool --show-features "$NSIM_DEV_NAME" 2>/dev/null)
109
110
if ! echo "$features_output" | grep -q -E "(Features|offload)"; then
111
ktap_test_fail "YNL ethtool features info (features output missing expected content)"
112
return
113
fi
114
115
ktap_test_pass "YNL ethtool features info (show/set)"
116
}
117
TESTS_NO=$((TESTS_NO + 1))
118
119
ethtool_channels_info()
120
{
121
local channels_output
122
123
channels_output=$(ip netns exec "$testns" $ynl_ethtool --show-channels "$NSIM_DEV_NAME" 2>/dev/null)
124
125
if ! echo "$channels_output" | grep -q -E "(Channel|Combined|RX|TX)"; then
126
ktap_test_fail "YNL ethtool channels info (channels output missing expected content)"
127
return
128
fi
129
130
if ! ip netns exec "$testns" $ynl_ethtool --set-channels "$NSIM_DEV_NAME" combined-count 1 2>/dev/null; then
131
ktap_test_fail "YNL ethtool channels info (set-channels command failed unexpectedly)"
132
return
133
fi
134
135
ktap_test_pass "YNL ethtool channels info (show/set)"
136
}
137
TESTS_NO=$((TESTS_NO + 1))
138
139
ethtool_time_stamping()
140
{
141
local ts_output
142
143
ts_output=$(ip netns exec "$testns" $ynl_ethtool --show-time-stamping "$NSIM_DEV_NAME" 2>/dev/null)
144
145
if ! echo "$ts_output" | grep -q -E "(Time stamping|timestamping|SOF_TIMESTAMPING)"; then
146
ktap_test_fail "YNL ethtool time stamping (time stamping output missing expected content)"
147
return
148
fi
149
150
ktap_test_pass "YNL ethtool time stamping"
151
}
152
TESTS_NO=$((TESTS_NO + 1))
153
154
setup()
155
{
156
modprobe netdevsim &> /dev/null
157
if ! [ -f /sys/bus/netdevsim/new_device ]; then
158
ktap_skip_all "netdevsim module not available"
159
exit "$KSFT_SKIP"
160
fi
161
162
if ! ip netns add "$testns" 2>/dev/null; then
163
ktap_skip_all "failed to create test namespace"
164
exit "$KSFT_SKIP"
165
fi
166
167
echo "$NSIM_ID 1" | ip netns exec "$testns" tee /sys/bus/netdevsim/new_device >/dev/null 2>&1 || {
168
ktap_skip_all "failed to create netdevsim device"
169
exit "$KSFT_SKIP"
170
}
171
172
local dev
173
dev=$(ip netns exec "$testns" ls /sys/bus/netdevsim/devices/netdevsim$NSIM_ID/net 2>/dev/null | head -1)
174
if [[ -z "$dev" ]]; then
175
ktap_skip_all "failed to find netdevsim device"
176
exit "$KSFT_SKIP"
177
fi
178
179
ip -netns "$testns" link set dev "$dev" name "$NSIM_DEV_NAME" 2>/dev/null || {
180
ktap_skip_all "failed to rename netdevsim device"
181
exit "$KSFT_SKIP"
182
}
183
184
ip -netns "$testns" link set dev "$NSIM_DEV_NAME" up 2>/dev/null
185
186
if ! ip -n "$testns" link add "$VETH_A" type veth peer name "$VETH_B" 2>/dev/null; then
187
ktap_skip_all "failed to create veth pair"
188
exit "$KSFT_SKIP"
189
fi
190
191
ip -n "$testns" link set "$VETH_A" up 2>/dev/null
192
ip -n "$testns" link set "$VETH_B" up 2>/dev/null
193
}
194
195
cleanup()
196
{
197
ip netns exec "$testns" bash -c "echo $NSIM_ID > /sys/bus/netdevsim/del_device" 2>/dev/null || true
198
ip netns del "$testns" 2>/dev/null || true
199
}
200
201
# Check if ynl-ethtool command is available
202
if ! command -v $ynl_ethtool &>/dev/null && [[ ! -x $ynl_ethtool ]]; then
203
ktap_skip_all "ynl-ethtool command not found: $ynl_ethtool"
204
exit "$KSFT_SKIP"
205
fi
206
207
trap cleanup EXIT
208
209
ktap_print_header
210
setup
211
ktap_set_plan "${TESTS_NO}"
212
213
ethtool_device_info
214
ethtool_statistics
215
ethtool_ring_params
216
ethtool_coalesce_params
217
ethtool_pause_params
218
ethtool_features_info
219
ethtool_channels_info
220
ethtool_time_stamping
221
222
ktap_finished
223
224