1 #!/bin/bash 1 #!/bin/bash 2 # SPDX-License-Identifier: GPL-2.0 2 # SPDX-License-Identifier: GPL-2.0 3 3 4 lib_dir=$(dirname $0)/../../../net/forwarding 4 lib_dir=$(dirname $0)/../../../net/forwarding 5 5 6 ALL_TESTS="fw_flash_test params_test regions_t 6 ALL_TESTS="fw_flash_test params_test regions_test reload_test \ 7 netns_reload_test resource_test dev 7 netns_reload_test resource_test dev_info_test \ 8 empty_reporter_test dummy_reporter_ 8 empty_reporter_test dummy_reporter_test rate_test" 9 NUM_NETIFS=0 9 NUM_NETIFS=0 10 source $lib_dir/lib.sh 10 source $lib_dir/lib.sh 11 11 12 BUS_ADDR=10 12 BUS_ADDR=10 13 PORT_COUNT=4 13 PORT_COUNT=4 14 VF_COUNT=4 14 VF_COUNT=4 15 DEV_NAME=netdevsim$BUS_ADDR 15 DEV_NAME=netdevsim$BUS_ADDR 16 SYSFS_NET_DIR=/sys/bus/netdevsim/devices/$DEV_ 16 SYSFS_NET_DIR=/sys/bus/netdevsim/devices/$DEV_NAME/net/ 17 DEBUGFS_DIR=/sys/kernel/debug/netdevsim/$DEV_N 17 DEBUGFS_DIR=/sys/kernel/debug/netdevsim/$DEV_NAME/ 18 DL_HANDLE=netdevsim/$DEV_NAME 18 DL_HANDLE=netdevsim/$DEV_NAME 19 19 20 wait_for_devlink() 20 wait_for_devlink() 21 { 21 { 22 "$@" | grep -q $DL_HANDLE 22 "$@" | grep -q $DL_HANDLE 23 } 23 } 24 24 25 devlink_wait() 25 devlink_wait() 26 { 26 { 27 local timeout=$1 27 local timeout=$1 28 28 29 busywait "$timeout" wait_for_devlink d 29 busywait "$timeout" wait_for_devlink devlink dev 30 } 30 } 31 31 32 fw_flash_test() 32 fw_flash_test() 33 { 33 { 34 DUMMYFILE=$(find /lib/firmware -type f 34 DUMMYFILE=$(find /lib/firmware -type f -printf '%P\n' | head -1) 35 RET=0 35 RET=0 36 36 37 if [ -z "$DUMMYFILE" ] 37 if [ -z "$DUMMYFILE" ] 38 then 38 then 39 echo "SKIP: unable to find sui 39 echo "SKIP: unable to find suitable dummy firmware file" 40 return 40 return 41 fi 41 fi 42 42 43 devlink dev flash $DL_HANDLE file $DUM 43 devlink dev flash $DL_HANDLE file $DUMMYFILE 44 check_err $? "Failed to flash with sta 44 check_err $? "Failed to flash with status updates on" 45 45 46 devlink dev flash $DL_HANDLE file $DUM 46 devlink dev flash $DL_HANDLE file $DUMMYFILE component fw.mgmt 47 check_err $? "Failed to flash with com 47 check_err $? "Failed to flash with component attribute" 48 48 49 devlink dev flash $DL_HANDLE file $DUM 49 devlink dev flash $DL_HANDLE file $DUMMYFILE overwrite settings 50 check_fail $? "Flash with overwrite se 50 check_fail $? "Flash with overwrite settings should be rejected" 51 51 52 echo "1"> $DEBUGFS_DIR/fw_update_overw 52 echo "1"> $DEBUGFS_DIR/fw_update_overwrite_mask 53 check_err $? "Failed to change allowed 53 check_err $? "Failed to change allowed overwrite mask" 54 54 55 devlink dev flash $DL_HANDLE file $DUM 55 devlink dev flash $DL_HANDLE file $DUMMYFILE overwrite settings 56 check_err $? "Failed to flash with set 56 check_err $? "Failed to flash with settings overwrite enabled" 57 57 58 devlink dev flash $DL_HANDLE file $DUM 58 devlink dev flash $DL_HANDLE file $DUMMYFILE overwrite identifiers 59 check_fail $? "Flash with overwrite se 59 check_fail $? "Flash with overwrite settings should be identifiers" 60 60 61 echo "3"> $DEBUGFS_DIR/fw_update_overw 61 echo "3"> $DEBUGFS_DIR/fw_update_overwrite_mask 62 check_err $? "Failed to change allowed 62 check_err $? "Failed to change allowed overwrite mask" 63 63 64 devlink dev flash $DL_HANDLE file $DUM 64 devlink dev flash $DL_HANDLE file $DUMMYFILE overwrite identifiers overwrite settings 65 check_err $? "Failed to flash with set 65 check_err $? "Failed to flash with settings and identifiers overwrite enabled" 66 66 67 echo "n"> $DEBUGFS_DIR/fw_update_statu 67 echo "n"> $DEBUGFS_DIR/fw_update_status 68 check_err $? "Failed to disable status 68 check_err $? "Failed to disable status updates" 69 69 70 devlink dev flash $DL_HANDLE file $DUM 70 devlink dev flash $DL_HANDLE file $DUMMYFILE 71 check_err $? "Failed to flash with sta 71 check_err $? "Failed to flash with status updates off" 72 72 73 log_test "fw flash test" 73 log_test "fw flash test" 74 } 74 } 75 75 76 param_get() 76 param_get() 77 { 77 { 78 local name=$1 78 local name=$1 79 79 80 cmd_jq "devlink dev param show $DL_HAN 80 cmd_jq "devlink dev param show $DL_HANDLE name $name -j" \ 81 '.[][][].values[] | select(.cmo 81 '.[][][].values[] | select(.cmode == "driverinit").value' 82 } 82 } 83 83 84 param_set() 84 param_set() 85 { 85 { 86 local name=$1 86 local name=$1 87 local value=$2 87 local value=$2 88 88 89 devlink dev param set $DL_HANDLE name 89 devlink dev param set $DL_HANDLE name $name cmode driverinit value $value 90 } 90 } 91 91 92 check_value() 92 check_value() 93 { 93 { 94 local name=$1 94 local name=$1 95 local phase_name=$2 95 local phase_name=$2 96 local expected_param_value=$3 96 local expected_param_value=$3 97 local expected_debugfs_value=$4 97 local expected_debugfs_value=$4 98 local value 98 local value 99 99 100 value=$(param_get $name) 100 value=$(param_get $name) 101 check_err $? "Failed to get $name para 101 check_err $? "Failed to get $name param value" 102 [ "$value" == "$expected_param_value" 102 [ "$value" == "$expected_param_value" ] 103 check_err $? "Unexpected $phase_name $ 103 check_err $? "Unexpected $phase_name $name param value" 104 value=$(<$DEBUGFS_DIR/$name) 104 value=$(<$DEBUGFS_DIR/$name) 105 check_err $? "Failed to get $name debu 105 check_err $? "Failed to get $name debugfs value" 106 [ "$value" == "$expected_debugfs_value 106 [ "$value" == "$expected_debugfs_value" ] 107 check_err $? "Unexpected $phase_name $ 107 check_err $? "Unexpected $phase_name $name debugfs value" 108 } 108 } 109 109 110 params_test() 110 params_test() 111 { 111 { 112 RET=0 112 RET=0 113 113 114 local max_macs 114 local max_macs 115 local test1 115 local test1 116 116 117 check_value max_macs initial 32 32 117 check_value max_macs initial 32 32 118 check_value test1 initial true Y 118 check_value test1 initial true Y 119 119 120 param_set max_macs 16 120 param_set max_macs 16 121 check_err $? "Failed to set max_macs p 121 check_err $? "Failed to set max_macs param value" 122 param_set test1 false 122 param_set test1 false 123 check_err $? "Failed to set test1 para 123 check_err $? "Failed to set test1 param value" 124 124 125 check_value max_macs post-set 16 32 125 check_value max_macs post-set 16 32 126 check_value test1 post-set false Y 126 check_value test1 post-set false Y 127 127 128 devlink dev reload $DL_HANDLE 128 devlink dev reload $DL_HANDLE 129 129 130 check_value max_macs post-reload 16 16 130 check_value max_macs post-reload 16 16 131 check_value test1 post-reload false N 131 check_value test1 post-reload false N 132 132 133 log_test "params test" 133 log_test "params test" 134 } 134 } 135 135 136 check_region_size() 136 check_region_size() 137 { 137 { 138 local name=$1 138 local name=$1 139 local size 139 local size 140 140 141 size=$(devlink region show $DL_HANDLE/ 141 size=$(devlink region show $DL_HANDLE/$name -j | jq -e -r '.[][].size') 142 check_err $? "Failed to get $name regi 142 check_err $? "Failed to get $name region size" 143 [ $size -eq 32768 ] 143 [ $size -eq 32768 ] 144 check_err $? "Invalid $name region siz 144 check_err $? "Invalid $name region size" 145 } 145 } 146 146 147 check_region_snapshot_count() 147 check_region_snapshot_count() 148 { 148 { 149 local name=$1 149 local name=$1 150 local phase_name=$2 150 local phase_name=$2 151 local expected_count=$3 151 local expected_count=$3 152 local count 152 local count 153 153 154 count=$(devlink region show $DL_HANDLE 154 count=$(devlink region show $DL_HANDLE/$name -j | jq -e -r '.[][].snapshot | length') 155 [ $count -eq $expected_count ] 155 [ $count -eq $expected_count ] 156 check_err $? "Unexpected $phase_name s 156 check_err $? "Unexpected $phase_name snapshot count" 157 } 157 } 158 158 159 regions_test() 159 regions_test() 160 { 160 { 161 RET=0 161 RET=0 162 162 163 local count 163 local count 164 164 165 check_region_size dummy 165 check_region_size dummy 166 check_region_snapshot_count dummy init 166 check_region_snapshot_count dummy initial 0 167 167 168 echo ""> $DEBUGFS_DIR/take_snapshot 168 echo ""> $DEBUGFS_DIR/take_snapshot 169 check_err $? "Failed to take first dum 169 check_err $? "Failed to take first dummy region snapshot" 170 check_region_snapshot_count dummy post 170 check_region_snapshot_count dummy post-first-snapshot 1 171 171 172 echo ""> $DEBUGFS_DIR/take_snapshot 172 echo ""> $DEBUGFS_DIR/take_snapshot 173 check_err $? "Failed to take second du 173 check_err $? "Failed to take second dummy region snapshot" 174 check_region_snapshot_count dummy post 174 check_region_snapshot_count dummy post-second-snapshot 2 175 175 176 echo ""> $DEBUGFS_DIR/take_snapshot 176 echo ""> $DEBUGFS_DIR/take_snapshot 177 check_err $? "Failed to take third dum 177 check_err $? "Failed to take third dummy region snapshot" 178 check_region_snapshot_count dummy post 178 check_region_snapshot_count dummy post-third-snapshot 3 179 179 180 devlink region del $DL_HANDLE/dummy sn 180 devlink region del $DL_HANDLE/dummy snapshot 1 181 check_err $? "Failed to delete first d 181 check_err $? "Failed to delete first dummy region snapshot" 182 182 183 check_region_snapshot_count dummy post 183 check_region_snapshot_count dummy post-first-delete 2 184 184 185 devlink region new $DL_HANDLE/dummy sn 185 devlink region new $DL_HANDLE/dummy snapshot 25 186 check_err $? "Failed to create a new s 186 check_err $? "Failed to create a new snapshot with id 25" 187 187 188 check_region_snapshot_count dummy post 188 check_region_snapshot_count dummy post-first-request 3 189 189 190 devlink region dump $DL_HANDLE/dummy s 190 devlink region dump $DL_HANDLE/dummy snapshot 25 >> /dev/null 191 check_err $? "Failed to dump snapshot 191 check_err $? "Failed to dump snapshot with id 25" 192 192 193 devlink region read $DL_HANDLE/dummy s 193 devlink region read $DL_HANDLE/dummy snapshot 25 addr 0 len 1 >> /dev/null 194 check_err $? "Failed to read snapshot 194 check_err $? "Failed to read snapshot with id 25 (1 byte)" 195 195 196 devlink region read $DL_HANDLE/dummy s 196 devlink region read $DL_HANDLE/dummy snapshot 25 addr 128 len 128 >> /dev/null 197 check_err $? "Failed to read snapshot 197 check_err $? "Failed to read snapshot with id 25 (128 bytes)" 198 198 199 devlink region read $DL_HANDLE/dummy s 199 devlink region read $DL_HANDLE/dummy snapshot 25 addr 128 len $((1<<32)) >> /dev/null 200 check_err $? "Failed to read snapshot 200 check_err $? "Failed to read snapshot with id 25 (oversized)" 201 201 202 devlink region read $DL_HANDLE/dummy s 202 devlink region read $DL_HANDLE/dummy snapshot 25 addr $((1<<32)) len 128 >> /dev/null 2>&1 203 check_fail $? "Bad read of snapshot wi 203 check_fail $? "Bad read of snapshot with id 25 did not fail" 204 204 205 devlink region del $DL_HANDLE/dummy sn 205 devlink region del $DL_HANDLE/dummy snapshot 25 206 check_err $? "Failed to delete snapsho 206 check_err $? "Failed to delete snapshot with id 25" 207 207 208 check_region_snapshot_count dummy post 208 check_region_snapshot_count dummy post-second-delete 2 209 209 210 sid=$(devlink -j region new $DL_HANDLE 210 sid=$(devlink -j region new $DL_HANDLE/dummy | jq '.[][][][]') 211 check_err $? "Failed to create a new s 211 check_err $? "Failed to create a new snapshot with id allocated by the kernel" 212 212 213 check_region_snapshot_count dummy post 213 check_region_snapshot_count dummy post-first-request 3 214 214 215 devlink region dump $DL_HANDLE/dummy s 215 devlink region dump $DL_HANDLE/dummy snapshot $sid >> /dev/null 216 check_err $? "Failed to dump a snapsho 216 check_err $? "Failed to dump a snapshot with id allocated by the kernel" 217 217 218 devlink region del $DL_HANDLE/dummy sn 218 devlink region del $DL_HANDLE/dummy snapshot $sid 219 check_err $? "Failed to delete snapsho 219 check_err $? "Failed to delete snapshot with id allocated by the kernel" 220 220 221 check_region_snapshot_count dummy post 221 check_region_snapshot_count dummy post-first-request 2 222 222 223 log_test "regions test" 223 log_test "regions test" 224 } 224 } 225 225 226 reload_test() 226 reload_test() 227 { 227 { 228 RET=0 228 RET=0 229 229 230 devlink dev reload $DL_HANDLE 230 devlink dev reload $DL_HANDLE 231 check_err $? "Failed to reload" 231 check_err $? "Failed to reload" 232 232 233 echo "y"> $DEBUGFS_DIR/fail_reload 233 echo "y"> $DEBUGFS_DIR/fail_reload 234 check_err $? "Failed to setup devlink 234 check_err $? "Failed to setup devlink reload to fail" 235 235 236 devlink dev reload $DL_HANDLE 236 devlink dev reload $DL_HANDLE 237 check_fail $? "Unexpected success of d 237 check_fail $? "Unexpected success of devlink reload" 238 238 239 echo "n"> $DEBUGFS_DIR/fail_reload 239 echo "n"> $DEBUGFS_DIR/fail_reload 240 check_err $? "Failed to setup devlink 240 check_err $? "Failed to setup devlink reload not to fail" 241 241 242 devlink dev reload $DL_HANDLE 242 devlink dev reload $DL_HANDLE 243 check_err $? "Failed to reload after s 243 check_err $? "Failed to reload after set not to fail" 244 244 245 echo "y"> $DEBUGFS_DIR/dont_allow_relo 245 echo "y"> $DEBUGFS_DIR/dont_allow_reload 246 check_err $? "Failed to forbid devlink 246 check_err $? "Failed to forbid devlink reload" 247 247 248 devlink dev reload $DL_HANDLE 248 devlink dev reload $DL_HANDLE 249 check_fail $? "Unexpected success of d 249 check_fail $? "Unexpected success of devlink reload" 250 250 251 echo "n"> $DEBUGFS_DIR/dont_allow_relo 251 echo "n"> $DEBUGFS_DIR/dont_allow_reload 252 check_err $? "Failed to re-enable devl 252 check_err $? "Failed to re-enable devlink reload" 253 253 254 devlink dev reload $DL_HANDLE 254 devlink dev reload $DL_HANDLE 255 check_err $? "Failed to reload after r 255 check_err $? "Failed to reload after re-enable" 256 256 257 log_test "reload test" 257 log_test "reload test" 258 } 258 } 259 259 260 netns_reload_test() 260 netns_reload_test() 261 { 261 { 262 RET=0 262 RET=0 263 263 264 ip netns add testns1 264 ip netns add testns1 265 check_err $? "Failed add netns \"testn 265 check_err $? "Failed add netns \"testns1\"" 266 ip netns add testns2 266 ip netns add testns2 267 check_err $? "Failed add netns \"testn 267 check_err $? "Failed add netns \"testns2\"" 268 268 269 devlink dev reload $DL_HANDLE netns te 269 devlink dev reload $DL_HANDLE netns testns1 270 check_err $? "Failed to reload into ne 270 check_err $? "Failed to reload into netns \"testns1\"" 271 271 272 devlink -N testns1 dev reload $DL_HAND 272 devlink -N testns1 dev reload $DL_HANDLE netns testns2 273 check_err $? "Failed to reload from ne 273 check_err $? "Failed to reload from netns \"testns1\" into netns \"testns2\"" 274 274 275 ip netns del testns2 275 ip netns del testns2 276 ip netns del testns1 276 ip netns del testns1 277 277 278 # Wait until netns async cleanup is do 278 # Wait until netns async cleanup is done. 279 devlink_wait 2000 279 devlink_wait 2000 280 280 281 log_test "netns reload test" 281 log_test "netns reload test" 282 } 282 } 283 283 284 DUMMYDEV="dummytest" 284 DUMMYDEV="dummytest" 285 285 286 res_val_get() 286 res_val_get() 287 { 287 { 288 local netns=$1 288 local netns=$1 289 local parentname=$2 289 local parentname=$2 290 local name=$3 290 local name=$3 291 local type=$4 291 local type=$4 292 292 293 cmd_jq "devlink -N $netns resource sho 293 cmd_jq "devlink -N $netns resource show $DL_HANDLE -j" \ 294 ".[][][] | select(.name == \"$p 294 ".[][][] | select(.name == \"$parentname\").resources[] \ 295 | select(.name == \"$name\").$ 295 | select(.name == \"$name\").$type" 296 } 296 } 297 297 298 resource_test() 298 resource_test() 299 { 299 { 300 RET=0 300 RET=0 301 301 302 ip netns add testns1 302 ip netns add testns1 303 check_err $? "Failed add netns \"testn 303 check_err $? "Failed add netns \"testns1\"" 304 ip netns add testns2 304 ip netns add testns2 305 check_err $? "Failed add netns \"testn 305 check_err $? "Failed add netns \"testns2\"" 306 306 307 devlink dev reload $DL_HANDLE netns te 307 devlink dev reload $DL_HANDLE netns testns1 308 check_err $? "Failed to reload into ne 308 check_err $? "Failed to reload into netns \"testns1\"" 309 309 310 # Create dummy dev to add the address 310 # Create dummy dev to add the address and routes on. 311 311 312 ip -n testns1 link add name $DUMMYDEV 312 ip -n testns1 link add name $DUMMYDEV type dummy 313 check_err $? "Failed create dummy devi 313 check_err $? "Failed create dummy device" 314 ip -n testns1 link set $DUMMYDEV up 314 ip -n testns1 link set $DUMMYDEV up 315 check_err $? "Failed bring up dummy de 315 check_err $? "Failed bring up dummy device" 316 ip -n testns1 a a 192.0.1.1/24 dev $DU 316 ip -n testns1 a a 192.0.1.1/24 dev $DUMMYDEV 317 check_err $? "Failed add an IP address 317 check_err $? "Failed add an IP address to dummy device" 318 318 319 local occ=$(res_val_get testns1 IPv4 f 319 local occ=$(res_val_get testns1 IPv4 fib occ) 320 local limit=$((occ+1)) 320 local limit=$((occ+1)) 321 321 322 # Set fib size limit to handle one ano 322 # Set fib size limit to handle one another route only. 323 323 324 devlink -N testns1 resource set $DL_HA 324 devlink -N testns1 resource set $DL_HANDLE path IPv4/fib size $limit 325 check_err $? "Failed to set IPv4/fib r 325 check_err $? "Failed to set IPv4/fib resource size" 326 local size_new=$(res_val_get testns1 I 326 local size_new=$(res_val_get testns1 IPv4 fib size_new) 327 [ "$size_new" -eq "$limit" ] 327 [ "$size_new" -eq "$limit" ] 328 check_err $? "Unexpected \"size_new\" 328 check_err $? "Unexpected \"size_new\" value (got $size_new, expected $limit)" 329 329 330 devlink -N testns1 dev reload $DL_HAND 330 devlink -N testns1 dev reload $DL_HANDLE 331 check_err $? "Failed to reload" 331 check_err $? "Failed to reload" 332 local size=$(res_val_get testns1 IPv4 332 local size=$(res_val_get testns1 IPv4 fib size) 333 [ "$size" -eq "$limit" ] 333 [ "$size" -eq "$limit" ] 334 check_err $? "Unexpected \"size\" valu 334 check_err $? "Unexpected \"size\" value (got $size, expected $limit)" 335 335 336 # Insert 2 routes, the first is going 336 # Insert 2 routes, the first is going to be inserted, 337 # the second is expected to fail to be 337 # the second is expected to fail to be inserted. 338 338 339 ip -n testns1 r a 192.0.2.0/24 via 192 339 ip -n testns1 r a 192.0.2.0/24 via 192.0.1.2 340 check_err $? "Failed to add route" 340 check_err $? "Failed to add route" 341 341 342 ip -n testns1 r a 192.0.3.0/24 via 192 342 ip -n testns1 r a 192.0.3.0/24 via 192.0.1.2 343 check_fail $? "Unexpected successful r 343 check_fail $? "Unexpected successful route add over limit" 344 344 345 # Now create another dummy in second n 345 # Now create another dummy in second network namespace and 346 # insert two routes. That is over the 346 # insert two routes. That is over the limit of the netdevsim 347 # instance in the first namespace. Mov 347 # instance in the first namespace. Move the netdevsim instance 348 # into the second namespace and expect 348 # into the second namespace and expect it to fail. 349 349 350 ip -n testns2 link add name $DUMMYDEV 350 ip -n testns2 link add name $DUMMYDEV type dummy 351 check_err $? "Failed create dummy devi 351 check_err $? "Failed create dummy device" 352 ip -n testns2 link set $DUMMYDEV up 352 ip -n testns2 link set $DUMMYDEV up 353 check_err $? "Failed bring up dummy de 353 check_err $? "Failed bring up dummy device" 354 ip -n testns2 a a 192.0.1.1/24 dev $DU 354 ip -n testns2 a a 192.0.1.1/24 dev $DUMMYDEV 355 check_err $? "Failed add an IP address 355 check_err $? "Failed add an IP address to dummy device" 356 ip -n testns2 r a 192.0.2.0/24 via 192 356 ip -n testns2 r a 192.0.2.0/24 via 192.0.1.2 357 check_err $? "Failed to add route" 357 check_err $? "Failed to add route" 358 ip -n testns2 r a 192.0.3.0/24 via 192 358 ip -n testns2 r a 192.0.3.0/24 via 192.0.1.2 359 check_err $? "Failed to add route" 359 check_err $? "Failed to add route" 360 360 361 devlink -N testns1 dev reload $DL_HAND 361 devlink -N testns1 dev reload $DL_HANDLE netns testns2 362 check_fail $? "Unexpected successful r 362 check_fail $? "Unexpected successful reload from netns \"testns1\" into netns \"testns2\"" 363 363 364 devlink -N testns2 resource set $DL_HA 364 devlink -N testns2 resource set $DL_HANDLE path IPv4/fib size ' -1' 365 check_err $? "Failed to reset IPv4/fib 365 check_err $? "Failed to reset IPv4/fib resource size" 366 366 367 devlink -N testns2 dev reload $DL_HAND 367 devlink -N testns2 dev reload $DL_HANDLE netns 1 368 check_err $? "Failed to reload devlink 368 check_err $? "Failed to reload devlink back" 369 369 370 ip netns del testns2 370 ip netns del testns2 371 ip netns del testns1 371 ip netns del testns1 372 372 373 # Wait until netns async cleanup is do 373 # Wait until netns async cleanup is done. 374 devlink_wait 2000 374 devlink_wait 2000 375 375 376 log_test "resource test" 376 log_test "resource test" 377 } 377 } 378 378 379 info_get() 379 info_get() 380 { 380 { 381 local name=$1 381 local name=$1 382 382 383 cmd_jq "devlink dev info $DL_HANDLE -j 383 cmd_jq "devlink dev info $DL_HANDLE -j" ".[][][\"$name\"]" "-e" 384 } 384 } 385 385 386 dev_info_test() 386 dev_info_test() 387 { 387 { 388 RET=0 388 RET=0 389 389 390 driver=$(info_get "driver") 390 driver=$(info_get "driver") 391 check_err $? "Failed to get driver nam 391 check_err $? "Failed to get driver name" 392 [ "$driver" == "netdevsim" ] 392 [ "$driver" == "netdevsim" ] 393 check_err $? "Unexpected driver name $ 393 check_err $? "Unexpected driver name $driver" 394 394 395 log_test "dev_info test" 395 log_test "dev_info test" 396 } 396 } 397 397 398 empty_reporter_test() 398 empty_reporter_test() 399 { 399 { 400 RET=0 400 RET=0 401 401 402 devlink health show $DL_HANDLE reporte 402 devlink health show $DL_HANDLE reporter empty >/dev/null 403 check_err $? "Failed show empty report 403 check_err $? "Failed show empty reporter" 404 404 405 devlink health dump show $DL_HANDLE re 405 devlink health dump show $DL_HANDLE reporter empty >/dev/null 406 check_err $? "Failed show dump of empt 406 check_err $? "Failed show dump of empty reporter" 407 407 408 devlink health diagnose $DL_HANDLE rep 408 devlink health diagnose $DL_HANDLE reporter empty >/dev/null 409 check_err $? "Failed diagnose empty re 409 check_err $? "Failed diagnose empty reporter" 410 410 411 devlink health recover $DL_HANDLE repo 411 devlink health recover $DL_HANDLE reporter empty 412 check_err $? "Failed recover empty rep 412 check_err $? "Failed recover empty reporter" 413 413 414 log_test "empty reporter test" 414 log_test "empty reporter test" 415 } 415 } 416 416 417 check_reporter_info() 417 check_reporter_info() 418 { 418 { 419 local name=$1 419 local name=$1 420 local expected_state=$2 420 local expected_state=$2 421 local expected_error=$3 421 local expected_error=$3 422 local expected_recover=$4 422 local expected_recover=$4 423 local expected_grace_period=$5 423 local expected_grace_period=$5 424 local expected_auto_recover=$6 424 local expected_auto_recover=$6 425 425 426 local show=$(devlink health show $DL_H 426 local show=$(devlink health show $DL_HANDLE reporter $name -j | jq -e -r ".[][][]") 427 check_err $? "Failed show $name report 427 check_err $? "Failed show $name reporter" 428 428 429 local state=$(echo $show | jq -r ".sta 429 local state=$(echo $show | jq -r ".state") 430 [ "$state" == "$expected_state" ] 430 [ "$state" == "$expected_state" ] 431 check_err $? "Unexpected \"state\" val 431 check_err $? "Unexpected \"state\" value (got $state, expected $expected_state)" 432 432 433 local error=$(echo $show | jq -r ".err 433 local error=$(echo $show | jq -r ".error") 434 [ "$error" == "$expected_error" ] 434 [ "$error" == "$expected_error" ] 435 check_err $? "Unexpected \"error\" val 435 check_err $? "Unexpected \"error\" value (got $error, expected $expected_error)" 436 436 437 local recover=`echo $show | jq -r ".re 437 local recover=`echo $show | jq -r ".recover"` 438 [ "$recover" == "$expected_recover" ] 438 [ "$recover" == "$expected_recover" ] 439 check_err $? "Unexpected \"recover\" v 439 check_err $? "Unexpected \"recover\" value (got $recover, expected $expected_recover)" 440 440 441 local grace_period=$(echo $show | jq - 441 local grace_period=$(echo $show | jq -r ".grace_period") 442 check_err $? "Failed get $name reporte 442 check_err $? "Failed get $name reporter grace_period" 443 [ "$grace_period" == "$expected_grace_ 443 [ "$grace_period" == "$expected_grace_period" ] 444 check_err $? "Unexpected \"grace_perio 444 check_err $? "Unexpected \"grace_period\" value (got $grace_period, expected $expected_grace_period)" 445 445 446 local auto_recover=$(echo $show | jq - 446 local auto_recover=$(echo $show | jq -r ".auto_recover") 447 [ "$auto_recover" == "$expected_auto_r 447 [ "$auto_recover" == "$expected_auto_recover" ] 448 check_err $? "Unexpected \"auto_recove 448 check_err $? "Unexpected \"auto_recover\" value (got $auto_recover, expected $expected_auto_recover)" 449 } 449 } 450 450 451 dummy_reporter_test() 451 dummy_reporter_test() 452 { 452 { 453 RET=0 453 RET=0 454 454 455 check_reporter_info dummy healthy 0 0 455 check_reporter_info dummy healthy 0 0 0 true 456 456 457 devlink health set $DL_HANDLE reporter 457 devlink health set $DL_HANDLE reporter dummy auto_recover false 458 check_err $? "Failed to dummy reporter 458 check_err $? "Failed to dummy reporter auto_recover option" 459 459 460 check_reporter_info dummy healthy 0 0 460 check_reporter_info dummy healthy 0 0 0 false 461 461 462 local BREAK_MSG="foo bar" 462 local BREAK_MSG="foo bar" 463 echo "$BREAK_MSG"> $DEBUGFS_DIR/health 463 echo "$BREAK_MSG"> $DEBUGFS_DIR/health/break_health 464 check_err $? "Failed to break dummy re 464 check_err $? "Failed to break dummy reporter" 465 465 466 check_reporter_info dummy error 1 0 0 466 check_reporter_info dummy error 1 0 0 false 467 467 468 local dump=$(devlink health dump show 468 local dump=$(devlink health dump show $DL_HANDLE reporter dummy -j) 469 check_err $? "Failed show dump of dumm 469 check_err $? "Failed show dump of dummy reporter" 470 470 471 local dump_break_msg=$(echo $dump | jq 471 local dump_break_msg=$(echo $dump | jq -r ".break_message") 472 [ "$dump_break_msg" == "$BREAK_MSG" ] 472 [ "$dump_break_msg" == "$BREAK_MSG" ] 473 check_err $? "Unexpected dump break me 473 check_err $? "Unexpected dump break message value (got $dump_break_msg, expected $BREAK_MSG)" 474 474 475 devlink health dump clear $DL_HANDLE r 475 devlink health dump clear $DL_HANDLE reporter dummy 476 check_err $? "Failed clear dump of dum 476 check_err $? "Failed clear dump of dummy reporter" 477 477 478 devlink health recover $DL_HANDLE repo 478 devlink health recover $DL_HANDLE reporter dummy 479 check_err $? "Failed recover dummy rep 479 check_err $? "Failed recover dummy reporter" 480 480 481 check_reporter_info dummy healthy 1 1 481 check_reporter_info dummy healthy 1 1 0 false 482 482 483 devlink health set $DL_HANDLE reporter 483 devlink health set $DL_HANDLE reporter dummy auto_recover true 484 check_err $? "Failed to dummy reporter 484 check_err $? "Failed to dummy reporter auto_recover option" 485 485 486 check_reporter_info dummy healthy 1 1 486 check_reporter_info dummy healthy 1 1 0 true 487 487 488 echo "$BREAK_MSG"> $DEBUGFS_DIR/health 488 echo "$BREAK_MSG"> $DEBUGFS_DIR/health/break_health 489 check_err $? "Failed to break dummy re 489 check_err $? "Failed to break dummy reporter" 490 490 491 check_reporter_info dummy healthy 2 2 491 check_reporter_info dummy healthy 2 2 0 true 492 492 493 local diagnose=$(devlink health diagno 493 local diagnose=$(devlink health diagnose $DL_HANDLE reporter dummy -j -p) 494 check_err $? "Failed show diagnose of 494 check_err $? "Failed show diagnose of dummy reporter" 495 495 496 local rcvrd_break_msg=$(echo $diagnose 496 local rcvrd_break_msg=$(echo $diagnose | jq -r ".recovered_break_message") 497 [ "$rcvrd_break_msg" == "$BREAK_MSG" ] 497 [ "$rcvrd_break_msg" == "$BREAK_MSG" ] 498 check_err $? "Unexpected recovered bre 498 check_err $? "Unexpected recovered break message value (got $rcvrd_break_msg, expected $BREAK_MSG)" 499 499 500 devlink health set $DL_HANDLE reporter 500 devlink health set $DL_HANDLE reporter dummy grace_period 10 501 check_err $? "Failed to dummy reporter 501 check_err $? "Failed to dummy reporter grace_period option" 502 502 503 check_reporter_info dummy healthy 2 2 503 check_reporter_info dummy healthy 2 2 10 true 504 504 505 echo "Y"> $DEBUGFS_DIR/health/fail_rec 505 echo "Y"> $DEBUGFS_DIR/health/fail_recover 506 check_err $? "Failed set dummy reporte 506 check_err $? "Failed set dummy reporter recovery to fail" 507 507 508 echo "$BREAK_MSG"> $DEBUGFS_DIR/health 508 echo "$BREAK_MSG"> $DEBUGFS_DIR/health/break_health 509 check_fail $? "Unexpected success of d 509 check_fail $? "Unexpected success of dummy reporter break" 510 510 511 check_reporter_info dummy error 3 2 10 511 check_reporter_info dummy error 3 2 10 true 512 512 513 devlink health recover $DL_HANDLE repo 513 devlink health recover $DL_HANDLE reporter dummy 514 check_fail $? "Unexpected success of d 514 check_fail $? "Unexpected success of dummy reporter recover" 515 515 516 echo "N"> $DEBUGFS_DIR/health/fail_rec 516 echo "N"> $DEBUGFS_DIR/health/fail_recover 517 check_err $? "Failed set dummy reporte 517 check_err $? "Failed set dummy reporter recovery to be successful" 518 518 519 devlink health recover $DL_HANDLE repo 519 devlink health recover $DL_HANDLE reporter dummy 520 check_err $? "Failed recover dummy rep 520 check_err $? "Failed recover dummy reporter" 521 521 522 check_reporter_info dummy healthy 3 3 522 check_reporter_info dummy healthy 3 3 10 true 523 523 524 echo 8192 > $DEBUGFS_DIR/health/binary 524 echo 8192 > $DEBUGFS_DIR/health/binary_len 525 check_err $? "Failed set dummy reporte 525 check_err $? "Failed set dummy reporter binary len to 8192" 526 526 527 local dump=$(devlink health dump show 527 local dump=$(devlink health dump show $DL_HANDLE reporter dummy -j) 528 check_err $? "Failed show dump of dumm 528 check_err $? "Failed show dump of dummy reporter" 529 529 530 devlink health dump clear $DL_HANDLE r 530 devlink health dump clear $DL_HANDLE reporter dummy 531 check_err $? "Failed clear dump of dum 531 check_err $? "Failed clear dump of dummy reporter" 532 532 533 log_test "dummy reporter test" 533 log_test "dummy reporter test" 534 } 534 } 535 535 536 rate_leafs_get() 536 rate_leafs_get() 537 { 537 { 538 local handle=$1 538 local handle=$1 539 539 540 cmd_jq "devlink port function rate sho 540 cmd_jq "devlink port function rate show -j" \ 541 '.[] | to_entries | .[] | selec 541 '.[] | to_entries | .[] | select(.value.type == "leaf") | .key | select(contains("'$handle'"))' 542 } 542 } 543 543 544 rate_nodes_get() 544 rate_nodes_get() 545 { 545 { 546 local handle=$1 546 local handle=$1 547 547 548 cmd_jq "devlink port function rate sho 548 cmd_jq "devlink port function rate show -j" \ 549 '.[] | to_entries | .[] | sele 549 '.[] | to_entries | .[] | select(.value.type == "node") | .key | select(contains("'$handle'"))' 550 } 550 } 551 551 552 rate_attr_set() 552 rate_attr_set() 553 { 553 { 554 local handle=$1 554 local handle=$1 555 local name=$2 555 local name=$2 556 local value=$3 556 local value=$3 557 local units=$4 557 local units=$4 558 558 559 devlink port function rate set $handle 559 devlink port function rate set $handle $name $value$units 560 } 560 } 561 561 562 rate_attr_get() 562 rate_attr_get() 563 { 563 { 564 local handle=$1 564 local handle=$1 565 local name=$2 565 local name=$2 566 566 567 cmd_jq "devlink port function rate sho 567 cmd_jq "devlink port function rate show $handle -j" '.[][].'$name 568 } 568 } 569 569 570 rate_attr_tx_rate_check() 570 rate_attr_tx_rate_check() 571 { 571 { 572 local handle=$1 572 local handle=$1 573 local name=$2 573 local name=$2 574 local rate=$3 574 local rate=$3 575 local debug_file=$4 575 local debug_file=$4 576 576 577 rate_attr_set $handle $name $rate mbit 577 rate_attr_set $handle $name $rate mbit 578 check_err $? "Failed to set $name valu 578 check_err $? "Failed to set $name value" 579 579 580 local debug_value=$(cat $debug_file) 580 local debug_value=$(cat $debug_file) 581 check_err $? "Failed to read $name val 581 check_err $? "Failed to read $name value from debugfs" 582 [ "$debug_value" == "$rate" ] 582 [ "$debug_value" == "$rate" ] 583 check_err $? "Unexpected $name debug v 583 check_err $? "Unexpected $name debug value $debug_value != $rate" 584 584 585 local api_value=$(( $(rate_attr_get $h 585 local api_value=$(( $(rate_attr_get $handle $name) * 8 / 1000000 )) 586 check_err $? "Failed to get $name attr 586 check_err $? "Failed to get $name attr value" 587 [ "$api_value" == "$rate" ] 587 [ "$api_value" == "$rate" ] 588 check_err $? "Unexpected $name attr va 588 check_err $? "Unexpected $name attr value $api_value != $rate" 589 } 589 } 590 590 591 rate_attr_parent_check() 591 rate_attr_parent_check() 592 { 592 { 593 local handle=$1 593 local handle=$1 594 local parent=$2 594 local parent=$2 595 local debug_file=$3 595 local debug_file=$3 596 596 597 rate_attr_set $handle parent $parent 597 rate_attr_set $handle parent $parent 598 check_err $? "Failed to set parent" 598 check_err $? "Failed to set parent" 599 599 600 debug_value=$(cat $debug_file) 600 debug_value=$(cat $debug_file) 601 check_err $? "Failed to get parent deb 601 check_err $? "Failed to get parent debugfs value" 602 [ "$debug_value" == "$parent" ] 602 [ "$debug_value" == "$parent" ] 603 check_err $? "Unexpected parent debug 603 check_err $? "Unexpected parent debug value $debug_value != $parent" 604 604 605 api_value=$(rate_attr_get $r_obj paren 605 api_value=$(rate_attr_get $r_obj parent) 606 check_err $? "Failed to get parent att 606 check_err $? "Failed to get parent attr value" 607 [ "$api_value" == "$parent" ] 607 [ "$api_value" == "$parent" ] 608 check_err $? "Unexpected parent attr v 608 check_err $? "Unexpected parent attr value $api_value != $parent" 609 } 609 } 610 610 611 rate_node_add() 611 rate_node_add() 612 { 612 { 613 local handle=$1 613 local handle=$1 614 614 615 devlink port function rate add $handle 615 devlink port function rate add $handle 616 } 616 } 617 617 618 rate_node_del() 618 rate_node_del() 619 { 619 { 620 local handle=$1 620 local handle=$1 621 621 622 devlink port function rate del $handle 622 devlink port function rate del $handle 623 } 623 } 624 624 625 rate_test() 625 rate_test() 626 { 626 { 627 RET=0 627 RET=0 628 628 629 echo $VF_COUNT > /sys/bus/netdevsim/de 629 echo $VF_COUNT > /sys/bus/netdevsim/devices/$DEV_NAME/sriov_numvfs 630 devlink dev eswitch set $DL_HANDLE mod 630 devlink dev eswitch set $DL_HANDLE mode switchdev 631 local leafs=`rate_leafs_get $DL_HANDLE 631 local leafs=`rate_leafs_get $DL_HANDLE` 632 local num_leafs=`echo $leafs | wc -w` 632 local num_leafs=`echo $leafs | wc -w` 633 [ "$num_leafs" == "$VF_COUNT" ] 633 [ "$num_leafs" == "$VF_COUNT" ] 634 check_err $? "Expected $VF_COUNT rate 634 check_err $? "Expected $VF_COUNT rate leafs but got $num_leafs" 635 635 636 rate=10 636 rate=10 637 for r_obj in $leafs 637 for r_obj in $leafs 638 do 638 do 639 rate_attr_tx_rate_check $r_obj 639 rate_attr_tx_rate_check $r_obj tx_share $rate \ 640 $DEBUGFS_DIR/ports/${r 640 $DEBUGFS_DIR/ports/${r_obj##*/}/tx_share 641 rate=$(($rate+10)) 641 rate=$(($rate+10)) 642 done 642 done 643 643 644 rate=100 644 rate=100 645 for r_obj in $leafs 645 for r_obj in $leafs 646 do 646 do 647 rate_attr_tx_rate_check $r_obj 647 rate_attr_tx_rate_check $r_obj tx_max $rate \ 648 $DEBUGFS_DIR/ports/${r 648 $DEBUGFS_DIR/ports/${r_obj##*/}/tx_max 649 rate=$(($rate+100)) 649 rate=$(($rate+100)) 650 done 650 done 651 651 652 local node1_name='group1' 652 local node1_name='group1' 653 local node1="$DL_HANDLE/$node1_name" 653 local node1="$DL_HANDLE/$node1_name" 654 rate_node_add "$node1" 654 rate_node_add "$node1" 655 check_err $? "Failed to add node $node 655 check_err $? "Failed to add node $node1" 656 656 657 local num_nodes=`rate_nodes_get $DL_HA 657 local num_nodes=`rate_nodes_get $DL_HANDLE | wc -w` 658 [ $num_nodes == 1 ] 658 [ $num_nodes == 1 ] 659 check_err $? "Expected 1 rate node in 659 check_err $? "Expected 1 rate node in output but got $num_nodes" 660 660 661 local node_tx_share=10 661 local node_tx_share=10 662 rate_attr_tx_rate_check $node1 tx_shar 662 rate_attr_tx_rate_check $node1 tx_share $node_tx_share \ 663 $DEBUGFS_DIR/rate_nodes/${node 663 $DEBUGFS_DIR/rate_nodes/${node1##*/}/tx_share 664 664 665 local node_tx_max=100 665 local node_tx_max=100 666 rate_attr_tx_rate_check $node1 tx_max 666 rate_attr_tx_rate_check $node1 tx_max $node_tx_max \ 667 $DEBUGFS_DIR/rate_nodes/${node 667 $DEBUGFS_DIR/rate_nodes/${node1##*/}/tx_max 668 668 669 rate_node_del "$node1" 669 rate_node_del "$node1" 670 check_err $? "Failed to delete node $n 670 check_err $? "Failed to delete node $node1" 671 local num_nodes=`rate_nodes_get $DL_HA 671 local num_nodes=`rate_nodes_get $DL_HANDLE | wc -w` 672 [ $num_nodes == 0 ] 672 [ $num_nodes == 0 ] 673 check_err $? "Expected 0 rate node but 673 check_err $? "Expected 0 rate node but got $num_nodes" 674 674 675 local node1_name='group1' 675 local node1_name='group1' 676 local node1="$DL_HANDLE/$node1_name" 676 local node1="$DL_HANDLE/$node1_name" 677 rate_node_add "$node1" 677 rate_node_add "$node1" 678 check_err $? "Failed to add node $node 678 check_err $? "Failed to add node $node1" 679 679 680 rate_attr_parent_check $r_obj $node1_n 680 rate_attr_parent_check $r_obj $node1_name \ 681 $DEBUGFS_DIR/ports/${r_obj##*/ 681 $DEBUGFS_DIR/ports/${r_obj##*/}/rate_parent 682 682 683 local node2_name='group2' 683 local node2_name='group2' 684 local node2="$DL_HANDLE/$node2_name" 684 local node2="$DL_HANDLE/$node2_name" 685 rate_node_add "$node2" 685 rate_node_add "$node2" 686 check_err $? "Failed to add node $node 686 check_err $? "Failed to add node $node2" 687 687 688 rate_attr_parent_check $node2 $node1_n 688 rate_attr_parent_check $node2 $node1_name \ 689 $DEBUGFS_DIR/rate_nodes/$node2 689 $DEBUGFS_DIR/rate_nodes/$node2_name/rate_parent 690 rate_node_del "$node2" 690 rate_node_del "$node2" 691 check_err $? "Failed to delete node $n 691 check_err $? "Failed to delete node $node2" 692 rate_attr_set "$r_obj" noparent 692 rate_attr_set "$r_obj" noparent 693 check_err $? "Failed to unset $r_obj p 693 check_err $? "Failed to unset $r_obj parent node" 694 rate_node_del "$node1" 694 rate_node_del "$node1" 695 check_err $? "Failed to delete node $n 695 check_err $? "Failed to delete node $node1" 696 696 697 log_test "rate test" 697 log_test "rate test" 698 } 698 } 699 699 700 setup_prepare() 700 setup_prepare() 701 { 701 { 702 modprobe netdevsim 702 modprobe netdevsim 703 echo "$BUS_ADDR $PORT_COUNT" > /sys/bu 703 echo "$BUS_ADDR $PORT_COUNT" > /sys/bus/netdevsim/new_device 704 while [ ! -d $SYSFS_NET_DIR ] ; do :; 704 while [ ! -d $SYSFS_NET_DIR ] ; do :; done 705 } 705 } 706 706 707 cleanup() 707 cleanup() 708 { 708 { 709 pre_cleanup 709 pre_cleanup 710 echo "$BUS_ADDR" > /sys/bus/netdevsim/ 710 echo "$BUS_ADDR" > /sys/bus/netdevsim/del_device 711 modprobe -r netdevsim 711 modprobe -r netdevsim 712 } 712 } 713 713 714 trap cleanup EXIT 714 trap cleanup EXIT 715 715 716 setup_prepare 716 setup_prepare 717 717 718 tests_run 718 tests_run 719 719 720 exit $EXIT_STATUS 720 exit $EXIT_STATUS
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.