mirror of
https://github.com/torvalds/linux.git
synced 2024-11-22 20:22:09 +00:00
selftests: netdevsim: add tests for devlink reload with resources
Add couple of tests for devlink reload testing and also resource limitations testing, along with devlink reload. Signed-off-by: Jiri Pirko <jiri@mellanox.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
070c63f20f
commit
b74c37fd35
@ -3,7 +3,8 @@
|
||||
|
||||
lib_dir=$(dirname $0)/../../../net/forwarding
|
||||
|
||||
ALL_TESTS="fw_flash_test params_test regions_test"
|
||||
ALL_TESTS="fw_flash_test params_test regions_test reload_test \
|
||||
netns_reload_test resource_test"
|
||||
NUM_NETIFS=0
|
||||
source $lib_dir/lib.sh
|
||||
|
||||
@ -142,6 +143,123 @@ regions_test()
|
||||
log_test "regions test"
|
||||
}
|
||||
|
||||
reload_test()
|
||||
{
|
||||
RET=0
|
||||
|
||||
devlink dev reload $DL_HANDLE
|
||||
check_err $? "Failed to reload"
|
||||
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user