blob: de3174431b8ead65260d134af3ff21704d718ae1 (
plain)
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
|
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
lib_dir=$(dirname $0)/../../../net/forwarding
ALL_TESTS="fw_flash_test params_test regions_test reload_test \
netns_reload_test resource_test"
NUM_NETIFS=0
source $lib_dir/lib.sh
BUS_ADDR=10
PORT_COUNT=4
DEV_NAME=netdevsim$BUS_ADDR
SYSFS_NET_DIR=/sys/bus/netdevsim/devices/$DEV_NAME/net/
DEBUGFS_DIR=/sys/kernel/debug/netdevsim/$DEV_NAME/
DL_HANDLE=netdevsim/$DEV_NAME
fw_flash_test()
{
RET=0
devlink dev flash $DL_HANDLE file dummy
check_err $? "Failed to flash with status updates on"
echo "n"> $DEBUGFS_DIR/fw_update_status
check_err $? "Failed to disable status updates"
devlink dev flash $DL_HANDLE file dummy
check_err $? "Failed to flash with status updates off"
log_test "fw flash test"
}
param_get()
{
local name=$1
cmd_jq "devlink dev param show $DL_HANDLE name $name -j" \
'.[][][].values[] | select(.cmode == "driverinit").value'
}
param_set()
{
local name=$1
local value=$2
devlink dev param set $DL_HANDLE name $name cmode driverinit value $value
}
check_value()
{
local name=$1
local phase_name=$2
local expected_param_value=$3
local expected_debugfs_value=$4
local value
value=$(param_get $name)
check_err $? "Failed to get $name param value"
[ "$value" == "$expected_param_value" ]
check_err $? "Unexpected $phase_name $name param value"
value=$(<$DEBUGFS_DIR/$name)
check_err $? "Failed to get $name debugfs value"
[ "$value" == "$expected_debugfs_value" ]
check_err $? "Unexpected $phase_name $name debugfs value"
}
params_test()
{
RET=0
local max_macs
local test1
check_value max_macs initial 32 32
check_value test1 initial true Y
param_set max_macs 16
check_err $? "Failed to set max_macs param value"
param_set test1 false
check_err $? "Failed to set test1 param value"
check_value max_macs post-set 16 32
check_value test1 post-set false Y
devlink dev reload $DL_HANDLE
check_value max_macs post-reload 16 16
check_value test1 post-reload false N
log_test "params test"
}
check_region_size()
{
local name=$1
local size
size=$(devlink region show $DL_HANDLE/$name -j | jq -e -r '.[][].size')
check_err $? "Failed to get $name region size"
[ $size -eq 32768 ]
check_err $? "Invalid $name region size"
}
check_region_snapshot_count()
{
local name=$1
local phase_name=$2
local expected_count=$3
local count
count=$(devlink region show $DL_HANDLE/$name -j | jq -e -r '.[][].snapshot | length')
[ $count -eq $expected_count ]
check_err $? "Unexpected $phase_name snapshot count"
}
regions_test()
{
RET=0
local count
check_region_size dummy
check_region_snapshot_count dummy initial 0
echo ""> $DEBUGFS_DIR/take_snapshot
check_err $? "Failed to take first dummy region snapshot"
check_region_snapshot_count dummy post-first-snapshot 1
echo ""> $DEBUGFS_DIR/take_snapshot
check_err $? "Failed to take second dummy region snapshot"
check_region_snapshot_count dummy post-second-snapshot 2
echo ""> $DEBUGFS_DIR/take_snapshot
check_err $? "Failed to take third dummy region snapshot"
check_region_snapshot_count dummy post-third-snapshot 3
devlink region del $DL_HANDLE/dummy snapshot 1
check_err $? "Failed to delete first dummy region snapshot"
check_region_snapshot_count dummy post-first-delete 2
log_test "regions test"
}
reload_test()
{
RET=0
devlink dev reload $DL_HANDLE
check_err $? "Failed to reload"
echo "y"> $DEBUGFS_DIR/fail_reload
check_err $? "Failed to setup devlink reload to fail"
devlink dev reload $DL_HANDLE
check_fail $? "Unexpected success of devlink reload"
echo "n"> $DEBUGFS_DIR/fail_reload
check_err $? "Failed to setup devlink reload not to fail"
devlink dev reload $DL_HANDLE
check_err $? "Failed to reload after set not to fail"
echo "y"> $DEBUGFS_DIR/dont_allow_reload
check_err $? "Failed to forbid devlink reload"
devlink dev reload $DL_HANDLE
check_fail $? "Unexpected success of devlink reload"
echo "n"> $DEBUGFS_DIR/dont_allow_reload
check_err $? "Failed to re-enable devlink reload"
devlink dev reload $DL_HANDLE
check_err $? "Failed to reload after re-enable"
log_test "reload test"
}
netns_reload_test()
{
RET=0
ip netns add testns1
check_err $? "Failed add netns \"testns1\""
ip netns add testns2
check_err $? "Failed add netns \"testns2\""
devlink dev reload $DL_HANDLE netns testns1
check_err $? "Failed to reload into netns \"testns1\""
devlink -N testns1 dev reload $DL_HANDLE netns testns2
check_err $? "Failed to reload from netns \"testns1\" into netns \"testns2\""
ip netns del testns2
ip netns del testns1
log_test "netns reload test"
}
DUMMYDEV="dummytest"
res_val_get()
{
local netns=$1
local parentname=$2
local name=$3
local type=$4
cmd_jq "devlink -N $netns resource show $DL_HANDLE -j" \
".[][][] | select(.name == \"$parentname\").resources[] \
| select(.name == \"$name\").$type"
}
resource_test()
{
RET=0
ip netns add testns1
check_err $? "Failed add netns \"testns1\""
ip netns add testns2
check_err $? "Failed add netns \"testns2\""
devlink dev reload $DL_HANDLE netns testns1
check_err $? "Failed to reload into netns \"testns1\""
# Create dummy dev to add the address and routes on.
ip -n testns1 link add name $DUMMYDEV type dummy
check_err $? "Failed create dummy device"
ip -n testns1 link set $DUMMYDEV up
check_err $? "Failed bring up dummy device"
ip -n testns1 a a 192.0.1.1/24 dev $DUMMYDEV
check_err $? "Failed add an IP address to dummy device"
local occ=$(res_val_get testns1 IPv4 fib occ)
local limit=$((occ+1))
# Set fib size limit to handle one another route only.
devlink -N testns1 resource set $DL_HANDLE path IPv4/fib size $limit
check_err $? "Failed to set IPv4/fib resource size"
local size_new=$(res_val_get testns1 IPv4 fib size_new)
[ "$size_new" -eq "$limit" ]
check_err $? "Unexpected \"size_new\" value (got $size_new, expected $limit)"
devlink -N testns1 dev reload $DL_HANDLE
check_err $? "Failed to reload"
local size=$(res_val_get testns1 IPv4 fib size)
[ "$size" -eq "$limit" ]
check_err $? "Unexpected \"size\" value (got $size, expected $limit)"
# Insert 2 routes, the first is going to be inserted,
# the second is expected to fail to be inserted.
ip -n testns1 r a 192.0.2.0/24 via 192.0.1.2
check_err $? "Failed to add route"
ip -n testns1 r a 192.0.3.0/24 via 192.0.1.2
check_fail $? "Unexpected successful route add over limit"
# Now create another dummy in second network namespace and
# insert two routes. That is over the limit of the netdevsim
# instance in the first namespace. Move the netdevsim instance
# into the second namespace and expect it to fail.
ip -n testns2 link add name $DUMMYDEV type dummy
check_err $? "Failed create dummy device"
ip -n testns2 link set $DUMMYDEV up
check_err $? "Failed bring up dummy device"
ip -n testns2 a a 192.0.1.1/24 dev $DUMMYDEV
check_err $? "Failed add an IP address to dummy device"
ip -n testns2 r a 192.0.2.0/24 via 192.0.1.2
check_err $? "Failed to add route"
ip -n testns2 r a 192.0.3.0/24 via 192.0.1.2
check_err $? "Failed to add route"
devlink -N testns1 dev reload $DL_HANDLE netns testns2
check_fail $? "Unexpected successful reload from netns \"testns1\" into netns \"testns2\""
ip netns del testns2
ip netns del testns1
log_test "resource test"
}
setup_prepare()
{
modprobe netdevsim
echo "$BUS_ADDR $PORT_COUNT" > /sys/bus/netdevsim/new_device
while [ ! -d $SYSFS_NET_DIR ] ; do :; done
}
cleanup()
{
pre_cleanup
echo "$BUS_ADDR" > /sys/bus/netdevsim/del_device
modprobe -r netdevsim
}
trap cleanup EXIT
setup_prepare
tests_run
exit $EXIT_STATUS
|