2 # SPDX-License-Identifier: GPL-2.0
4 lib_dir
=$
(dirname $0)/..
/..
/..
/net
/forwarding
6 ALL_TESTS
="fw_flash_test params_test regions_test reload_test \
7 netns_reload_test resource_test dev_info_test \
8 empty_reporter_test dummy_reporter_test"
10 source $lib_dir/lib.sh
14 DEV_NAME
=netdevsim
$BUS_ADDR
15 SYSFS_NET_DIR
=/sys
/bus
/netdevsim
/devices
/$DEV_NAME/net
/
16 DEBUGFS_DIR
=/sys
/kernel
/debug
/netdevsim
/$DEV_NAME/
17 DL_HANDLE
=netdevsim
/$DEV_NAME
23 devlink dev flash
$DL_HANDLE file dummy
24 check_err $?
"Failed to flash with status updates on"
26 devlink dev flash
$DL_HANDLE file dummy component fw.mgmt
27 check_err $?
"Failed to flash with component attribute"
29 devlink dev flash
$DL_HANDLE file dummy overwrite settings
30 check_fail $?
"Flash with overwrite settings should be rejected"
32 echo "1"> $DEBUGFS_DIR/fw_update_overwrite_mask
33 check_err $?
"Failed to change allowed overwrite mask"
35 devlink dev flash
$DL_HANDLE file dummy overwrite settings
36 check_err $?
"Failed to flash with settings overwrite enabled"
38 devlink dev flash
$DL_HANDLE file dummy overwrite identifiers
39 check_fail $?
"Flash with overwrite settings should be identifiers"
41 echo "3"> $DEBUGFS_DIR/fw_update_overwrite_mask
42 check_err $?
"Failed to change allowed overwrite mask"
44 devlink dev flash
$DL_HANDLE file dummy overwrite identifiers overwrite settings
45 check_err $?
"Failed to flash with settings and identifiers overwrite enabled"
47 echo "n"> $DEBUGFS_DIR/fw_update_status
48 check_err $?
"Failed to disable status updates"
50 devlink dev flash
$DL_HANDLE file dummy
51 check_err $?
"Failed to flash with status updates off"
53 log_test
"fw flash test"
60 cmd_jq
"devlink dev param show $DL_HANDLE name $name -j" \
61 '.[][][].values[] | select(.cmode == "driverinit").value'
69 devlink dev param
set $DL_HANDLE name
$name cmode driverinit value
$value
76 local expected_param_value
=$3
77 local expected_debugfs_value
=$4
80 value
=$
(param_get
$name)
81 check_err $?
"Failed to get $name param value"
82 [ "$value" == "$expected_param_value" ]
83 check_err $?
"Unexpected $phase_name $name param value"
84 value
=$
(<$DEBUGFS_DIR/$name)
85 check_err $?
"Failed to get $name debugfs value"
86 [ "$value" == "$expected_debugfs_value" ]
87 check_err $?
"Unexpected $phase_name $name debugfs value"
97 check_value max_macs initial
32 32
98 check_value test1 initial true Y
100 param_set max_macs
16
101 check_err $?
"Failed to set max_macs param value"
102 param_set test1 false
103 check_err $?
"Failed to set test1 param value"
105 check_value max_macs post-set
16 32
106 check_value test1 post-set false Y
108 devlink dev reload
$DL_HANDLE
110 check_value max_macs post-reload
16 16
111 check_value test1 post-reload false N
113 log_test
"params test"
121 size
=$
(devlink region show
$DL_HANDLE/$name -j | jq
-e -r '.[][].size')
122 check_err $?
"Failed to get $name region size"
124 check_err $?
"Invalid $name region size"
127 check_region_snapshot_count
()
131 local expected_count
=$3
134 count
=$
(devlink region show
$DL_HANDLE/$name -j | jq
-e -r '.[][].snapshot | length')
135 [ $count -eq $expected_count ]
136 check_err $?
"Unexpected $phase_name snapshot count"
145 check_region_size dummy
146 check_region_snapshot_count dummy initial
0
148 echo ""> $DEBUGFS_DIR/take_snapshot
149 check_err $?
"Failed to take first dummy region snapshot"
150 check_region_snapshot_count dummy post-first-snapshot
1
152 echo ""> $DEBUGFS_DIR/take_snapshot
153 check_err $?
"Failed to take second dummy region snapshot"
154 check_region_snapshot_count dummy post-second-snapshot
2
156 echo ""> $DEBUGFS_DIR/take_snapshot
157 check_err $?
"Failed to take third dummy region snapshot"
158 check_region_snapshot_count dummy post-third-snapshot
3
160 devlink region del
$DL_HANDLE/dummy snapshot
1
161 check_err $?
"Failed to delete first dummy region snapshot"
163 check_region_snapshot_count dummy post-first-delete
2
165 devlink region new
$DL_HANDLE/dummy snapshot
25
166 check_err $?
"Failed to create a new snapshot with id 25"
168 check_region_snapshot_count dummy post-first-request
3
170 devlink region dump
$DL_HANDLE/dummy snapshot
25 >> /dev
/null
171 check_err $?
"Failed to dump snapshot with id 25"
173 devlink region
read $DL_HANDLE/dummy snapshot
25 addr
0 len
1 >> /dev
/null
174 check_err $?
"Failed to read snapshot with id 25 (1 byte)"
176 devlink region
read $DL_HANDLE/dummy snapshot
25 addr
128 len
128 >> /dev
/null
177 check_err $?
"Failed to read snapshot with id 25 (128 bytes)"
179 devlink region
read $DL_HANDLE/dummy snapshot
25 addr
128 len $
((1<<32)) >> /dev/null
180 check_err $? "Failed to read snapshot with id 25 (oversized)"
182 devlink region read $DL_HANDLE/dummy snapshot 25 addr $((1<<32)) len 128 >> /dev/null 2>&1
183 check_fail $? "Bad read of snapshot with id 25 did not fail"
185 devlink region del $DL_HANDLE/dummy snapshot 25
186 check_err $? "Failed to delete snapshot with id 25"
188 check_region_snapshot_count dummy post-second-delete 2
190 sid=$(devlink -j region new $DL_HANDLE/dummy | jq '.[][][][]')
191 check_err $? "Failed to create a new snapshot with id allocated by the kernel"
193 check_region_snapshot_count dummy post-first-request 3
195 devlink region dump $DL_HANDLE/dummy snapshot $sid >> /dev/null
196 check_err $? "Failed to dump a snapshot with id allocated by the kernel"
198 devlink region del $DL_HANDLE/dummy snapshot $sid
199 check_err $? "Failed to delete snapshot with id allocated by the kernel"
201 check_region_snapshot_count dummy post-first-request 2
203 log_test "regions test"
210 devlink dev reload $DL_HANDLE
211 check_err $? "Failed to reload"
213 echo "y"> $DEBUGFS_DIR/fail_reload
214 check_err $? "Failed to setup devlink reload to fail"
216 devlink dev reload $DL_HANDLE
217 check_fail $? "Unexpected success of devlink reload"
219 echo "n"> $DEBUGFS_DIR/fail_reload
220 check_err $? "Failed to setup devlink reload not to fail"
222 devlink dev reload $DL_HANDLE
223 check_err $? "Failed to reload after set not to fail"
225 echo "y"> $DEBUGFS_DIR/dont_allow_reload
226 check_err $? "Failed to forbid devlink reload"
228 devlink dev reload $DL_HANDLE
229 check_fail $? "Unexpected success of devlink reload"
231 echo "n"> $DEBUGFS_DIR/dont_allow_reload
232 check_err $? "Failed to re-enable devlink reload"
234 devlink dev reload $DL_HANDLE
235 check_err $? "Failed to reload after re-enable"
237 log_test "reload test"
245 check_err $? "Failed add netns \"testns1\""
247 check_err $? "Failed add netns \"testns2\""
249 devlink dev reload $DL_HANDLE netns testns1
250 check_err $? "Failed to reload into netns \"testns1\""
252 devlink -N testns1 dev reload $DL_HANDLE netns testns2
253 check_err $? "Failed to reload from netns \"testns1\" into netns \"testns2\""
258 log_test "netns reload test"
270 cmd_jq "devlink -N $netns resource show $DL_HANDLE -j" \
271 ".[][][] | select(.name == \"$parentname\").resources[] \
272 | select(.name == \"$name\").$type"
280 check_err $? "Failed add netns \"testns1\""
282 check_err $? "Failed add netns \"testns2\""
284 devlink dev reload $DL_HANDLE netns testns1
285 check_err $? "Failed to reload into netns \"testns1\""
287 # Create dummy dev to add the address and routes on.
289 ip -n testns1 link add name $DUMMYDEV type dummy
290 check_err $? "Failed create dummy device"
291 ip -n testns1 link set $DUMMYDEV up
292 check_err $? "Failed bring up dummy device"
293 ip -n testns1 a a 192.0.1.1/24 dev $DUMMYDEV
294 check_err $? "Failed add an IP address to dummy device"
296 local occ=$(res_val_get testns1 IPv4 fib occ)
297 local limit=$((occ+1))
299 # Set fib size limit to handle one another route only.
301 devlink -N testns1 resource set $DL_HANDLE path IPv4/fib size $limit
302 check_err $? "Failed to set IPv4/fib resource size"
303 local size_new=$(res_val_get testns1 IPv4 fib size_new)
304 [ "$size_new" -eq "$limit" ]
305 check_err $? "Unexpected \"size_new\" value (got $size_new, expected $limit)"
307 devlink -N testns1 dev reload $DL_HANDLE
308 check_err $? "Failed to reload"
309 local size=$(res_val_get testns1 IPv4 fib size)
310 [ "$size" -eq "$limit" ]
311 check_err $? "Unexpected \"size\" value (got $size, expected $limit)"
313 # Insert 2 routes, the first is going to be inserted,
314 # the second is expected to fail to be inserted.
316 ip -n testns1 r a 192.0.2.0/24 via 192.0.1.2
317 check_err $? "Failed to add route"
319 ip -n testns1 r a 192.0.3.0/24 via 192.0.1.2
320 check_fail $? "Unexpected successful route add over limit"
322 # Now create another dummy in second network namespace and
323 # insert two routes. That is over the limit of the netdevsim
324 # instance in the first namespace. Move the netdevsim instance
325 # into the second namespace and expect it to fail.
327 ip -n testns2 link add name $DUMMYDEV type dummy
328 check_err $? "Failed create dummy device"
329 ip -n testns2 link set $DUMMYDEV up
330 check_err $? "Failed bring up dummy device"
331 ip -n testns2 a a 192.0.1.1/24 dev $DUMMYDEV
332 check_err $? "Failed add an IP address to dummy device"
333 ip -n testns2 r a 192.0.2.0/24 via 192.0.1.2
334 check_err $? "Failed to add route"
335 ip -n testns2 r a 192.0.3.0/24 via 192.0.1.2
336 check_err $? "Failed to add route"
338 devlink -N testns1 dev reload $DL_HANDLE netns testns2
339 check_fail $? "Unexpected successful reload from netns \"testns1\" into netns \"testns2\""
341 devlink -N testns2 resource set $DL_HANDLE path IPv4/fib size ' -1'
342 check_err $? "Failed to reset IPv4/fib resource size"
344 devlink -N testns2 dev reload $DL_HANDLE netns 1
345 check_err $? "Failed to reload devlink back"
350 log_test "resource test"
357 cmd_jq "devlink dev info $DL_HANDLE -j" ".[][][\"$name\"]" "-e"
364 driver=$(info_get "driver")
365 check_err $? "Failed to get driver name"
366 [ "$driver" == "netdevsim" ]
367 check_err $? "Unexpected driver name $driver"
369 log_test "dev_info test"
372 empty_reporter_test()
376 devlink health show $DL_HANDLE reporter empty >/dev/null
377 check_err $? "Failed show empty reporter"
379 devlink health dump show $DL_HANDLE reporter empty >/dev/null
380 check_err $? "Failed show dump of empty reporter"
382 devlink health diagnose $DL_HANDLE reporter empty >/dev/null
383 check_err $? "Failed diagnose empty reporter"
385 devlink health recover $DL_HANDLE reporter empty
386 check_err $? "Failed recover empty reporter"
388 log_test "empty reporter test"
391 check_reporter_info()
394 local expected_state=$2
395 local expected_error=$3
396 local expected_recover=$4
397 local expected_grace_period=$5
398 local expected_auto_recover=$6
400 local show=$(devlink health show $DL_HANDLE reporter $name -j | jq -e -r ".[][][]")
401 check_err $? "Failed show $name reporter"
403 local state=$(echo $show | jq -r ".state")
404 [ "$state" == "$expected_state" ]
405 check_err $? "Unexpected \"state\" value (got $state, expected $expected_state)"
407 local error=$(echo $show | jq -r ".error")
408 [ "$error" == "$expected_error" ]
409 check_err $? "Unexpected \"error\" value (got $error, expected $expected_error)"
411 local recover=`echo $show | jq -r ".recover"`
412 [ "$recover" == "$expected_recover" ]
413 check_err $? "Unexpected \"recover\" value (got $recover, expected $expected_recover)"
415 local grace_period=$(echo $show | jq -r ".grace_period")
416 check_err $? "Failed get $name reporter grace_period"
417 [ "$grace_period" == "$expected_grace_period" ]
418 check_err $? "Unexpected \"grace_period\" value (got $grace_period, expected $expected_grace_period)"
420 local auto_recover=$(echo $show | jq -r ".auto_recover")
421 [ "$auto_recover" == "$expected_auto_recover" ]
422 check_err $? "Unexpected \"auto_recover\" value (got $auto_recover, expected $expected_auto_recover)"
425 dummy_reporter_test()
429 check_reporter_info dummy healthy 0 0 0 true
431 devlink health set $DL_HANDLE reporter dummy auto_recover false
432 check_err $? "Failed to dummy reporter auto_recover option"
434 check_reporter_info dummy healthy 0 0 0 false
436 local BREAK_MSG="foo bar"
437 echo "$BREAK_MSG"> $DEBUGFS_DIR/health/break_health
438 check_err $? "Failed to break dummy reporter"
440 check_reporter_info dummy error 1 0 0 false
442 local dump=$(devlink health dump show $DL_HANDLE reporter dummy -j)
443 check_err $? "Failed show dump of dummy reporter"
445 local dump_break_msg=$(echo $dump | jq -r ".break_message")
446 [ "$dump_break_msg" == "$BREAK_MSG" ]
447 check_err $? "Unexpected dump break message value (got $dump_break_msg, expected $BREAK_MSG)"
449 devlink health dump clear $DL_HANDLE reporter dummy
450 check_err $? "Failed clear dump of dummy reporter"
452 devlink health recover $DL_HANDLE reporter dummy
453 check_err $? "Failed recover dummy reporter"
455 check_reporter_info dummy healthy 1 1 0 false
457 devlink health set $DL_HANDLE reporter dummy auto_recover true
458 check_err $? "Failed to dummy reporter auto_recover option"
460 check_reporter_info dummy healthy 1 1 0 true
462 echo "$BREAK_MSG"> $DEBUGFS_DIR/health/break_health
463 check_err $? "Failed to break dummy reporter"
465 check_reporter_info dummy healthy 2 2 0 true
467 local diagnose=$(devlink health diagnose $DL_HANDLE reporter dummy -j -p)
468 check_err $? "Failed show diagnose of dummy reporter"
470 local rcvrd_break_msg=$(echo $diagnose | jq -r ".recovered_break_message")
471 [ "$rcvrd_break_msg" == "$BREAK_MSG" ]
472 check_err $? "Unexpected recovered break message value (got $rcvrd_break_msg, expected $BREAK_MSG)"
474 devlink health set $DL_HANDLE reporter dummy grace_period 10
475 check_err $? "Failed to dummy reporter grace_period option"
477 check_reporter_info dummy healthy 2 2 10 true
479 echo "Y"> $DEBUGFS_DIR/health/fail_recover
480 check_err $? "Failed set dummy reporter recovery to fail"
482 echo "$BREAK_MSG"> $DEBUGFS_DIR/health/break_health
483 check_fail $? "Unexpected success of dummy reporter break"
485 check_reporter_info dummy error 3 2 10 true
487 devlink health recover $DL_HANDLE reporter dummy
488 check_fail $? "Unexpected success of dummy reporter recover"
490 echo "N"> $DEBUGFS_DIR/health/fail_recover
491 check_err $? "Failed set dummy reporter recovery to be successful"
493 devlink health recover $DL_HANDLE reporter dummy
494 check_err $? "Failed recover dummy reporter"
496 check_reporter_info dummy healthy 3 3 10 true
498 echo 8192> $DEBUGFS_DIR/health/binary_len
499 check_fail $? "Failed set dummy reporter binary len to 8192"
501 local dump=$(devlink health dump show $DL_HANDLE reporter dummy -j)
502 check_err $? "Failed show dump of dummy reporter"
504 devlink health dump clear $DL_HANDLE reporter dummy
505 check_err $? "Failed clear dump of dummy reporter"
507 log_test "dummy reporter test"
513 echo "$BUS_ADDR $PORT_COUNT" > /sys/bus/netdevsim/new_device
514 while [ ! -d $SYSFS_NET_DIR ] ; do :; done
520 echo "$BUS_ADDR" > /sys/bus/netdevsim/del_device
521 modprobe -r netdevsim