Skip to content

Commit

Permalink
Merge branch 'selftests-netdevsim-add-devlink-paramstests'
Browse files Browse the repository at this point in the history
Jiri Pirko says:

====================
selftests: netdevsim: add devlink paramstests

The first patch is just a helper addition as a dependency of the actual
test in patch number two.
====================

Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
David S. Miller committed Aug 15, 2019
2 parents 873343e + dc8a670 commit bd00cc3
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 14 deletions.
62 changes: 61 additions & 1 deletion tools/testing/selftests/drivers/net/netdevsim/devlink.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

lib_dir=$(dirname $0)/../../../net/forwarding

ALL_TESTS="fw_flash_test"
ALL_TESTS="fw_flash_test params_test"
NUM_NETIFS=0
source $lib_dir/lib.sh

Expand All @@ -30,6 +30,66 @@ fw_flash_test()
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"
}

setup_prepare()
{
modprobe netdevsim
Expand Down
19 changes: 19 additions & 0 deletions tools/testing/selftests/net/forwarding/lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,25 @@ setup_wait()
sleep $WAIT_TIME
}

cmd_jq()
{
local cmd=$1
local jq_exp=$2
local ret
local output

output="$($cmd)"
# it the command fails, return error right away
ret=$?
if [[ $ret -ne 0 ]]; then
return $ret
fi
output=$(echo $output | jq -r "$jq_exp")
echo $output
# return success only in case of non-empty output
[ ! -z "$output" ]
}

lldpad_app_wait_set()
{
local dev=$1; shift
Expand Down
17 changes: 4 additions & 13 deletions tools/testing/selftests/net/forwarding/tc_common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,9 @@ tc_check_packets()
local id=$1
local handle=$2
local count=$3
local ret

output="$(tc -j -s filter show $id)"
# workaround the jq bug which causes jq to return 0 in case input is ""
ret=$?
if [[ $ret -ne 0 ]]; then
return $ret
fi
echo $output | \
jq -e ".[] \
| select(.options.handle == $handle) \
| select(.options.actions[0].stats.packets == $count)" \
&> /dev/null
return $?
cmd_jq "tc -j -s filter show $id" \
".[] | select(.options.handle == $handle) | \
select(.options.actions[0].stats.packets == $count)" \
&> /dev/null
}

0 comments on commit bd00cc3

Please sign in to comment.