Skip to contentSkip to conversation

selftests: netdevsim: add devlink params tests

PATCH In review Jiri Pirko 2 participants 3 messages Aug 13, 2019 – Aug 14, 2019

Subsystems (4)
lore
Share & tools
lore

Jiri Pirko

author
#0 lore raw

PATCH 1/1 selftests: netdevsim: add devlink params tests

From: Jiri Pirko <[email protected]>

Test recently added netdevsim devlink param implementation.

---
 .../drivers/net/netdevsim/devlink.sh          | 62 ++++++++++++++++++-
 1 file changed, 61 insertions(+), 1 deletion(-)
tools/testing/selftests/drivers/net/netdevsim/devlink.sh +61 -1
index 9d8baf5d14b3..858ebdc8d8a3 100755
@@ -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
 
@@ -30,6 +30,66 @@ fw_flash_test()
 	log_test "fw flash test"
 }
 
+param_get()
+{
+	local name=$1
+
+	devlink dev param show $DL_HANDLE name $name -j | \
+		jq -e -r '.[][][].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
Signature · 1 line
2.21.0
#1 lore raw
Quoted 5 lines · Jiri Pirko

From: Jiri Pirko <[email protected]>

Test recently added netdevsim devlink param implementation.

Thanks for the test, but it doesn't pass here:

TEST: fw flash test [ OK ]
TEST: params test [FAIL]
Failed to get test1 param value

Quoted 14 lines
tools/testing/selftests/drivers/net/netdevsim/devlink.sh +1 -1
index 9d8baf5d14b3..858ebdc8d8a3 100755
@@ -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
 

tools/testing/selftests/drivers/net/netdevsim/devlink.sh fw_flash_test() · line 38

Quoted 9 lines
tools/testing/selftests/drivers/net/netdevsim/devlink.sh +6 -0
@@ -30,6 +30,66 @@ fw_flash_test()
 	log_test "fw flash test"
 }
 
+param_get()
+{
+	local name=$1
+
+	devlink dev param show $DL_HANDLE name $name -j | \
+		jq -e -r '.[][][].values[] | select(.cmode == "driverinit").value'
                   ^^

The -e makes jq set exit code to 1 when test1 param is false.

Quoting the man page:

· -e / --exit-status:

Sets the exit status of jq to 0 if the last output values was neither false nor null, 1 if the last output value was either false or null, or 4 if no valid result was ever produced. Normally jq exits with 2 if there was any usage problem or system error, 3 if there was a jq program compile error, or 0 if the jq program ran.

Without the -e all is well:

# ./devlink.sh 
TEST: fw flash test                                                 [ OK ]
TEST: params test                                                   [ OK ]
Quoted 2 lines
tools/testing/selftests/drivers/net/netdevsim/devlink.sh +2 -0
+}
+
author
#2 lore raw
Quoted 5 lines · Wed, Aug 14, 2019 at 12:41:08AM CEST, [email protected] wrote:
Quoted 4 lines · Jiri Pirko

From: Jiri Pirko <[email protected]>

Test recently added netdevsim devlink param implementation.

Quoted 7 lines
Quoted 1 line

Thanks for the test, but it doesn't pass here:

TEST: fw flash test [ OK ]
TEST: params test [FAIL]
Failed to get test1 param value

Interesting. Fors for me correctly. When I run it manually, I get this:
bash-5.0# devlink dev param show netdevsim/netdevsim11 name test1 -j | jq -e -r '.[][][].values[] | select(.cmode == "driverinit").value' true
bash-5.0# echo $?
0
bash-5.0# devlink dev param set netdevsim/netdevsim11 name test1 cmode driverinit value false
bash-5.0# devlink dev param show netdevsim/netdevsim11 name test1 -j | jq -e -r '.[][][].values[] | select(.cmode == "driverinit").value' false
bash-5.0# echo $?
0

Quoted 33 lines
Quoted 15 lines
tools/testing/selftests/drivers/net/netdevsim/devlink.sh +1 -1
index 9d8baf5d14b3..858ebdc8d8a3 100755
@@ -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
 

tools/testing/selftests/drivers/net/netdevsim/devlink.sh fw_flash_test() · line 38

Quoted 9 lines
tools/testing/selftests/drivers/net/netdevsim/devlink.sh +6 -0
@@ -30,6 +30,66 @@ fw_flash_test()
 	log_test "fw flash test"
 }
 
+param_get()
+{
+	local name=$1
+
+	devlink dev param show $DL_HANDLE name $name -j | \
+		jq -e -r '.[][][].values[] | select(.cmode == "driverinit").value'
                  ^^

The -e makes jq set exit code to 1 when test1 param is false.

Quoting the man page:

· -e / --exit-status:

Quoted 8 lines

Sets the exit status of jq to 0 if the last output values was neither false nor null, 1 if the last output value was either false or null, or 4 if no valid result was ever produced. Normally jq exits with 2 if there was any usage problem or system error, 3 if there was a jq program compile error, or 0 if the jq program ran.

Without the -e all is well:

Not really, for non-existent param the return value would be wrong:
bash-5.0# devlink dev param show netdevsim/netdevsim11 name test2 -j | jq -e -r '.[][][].values[] | select(.cmode == "driverinit").value' devlink answers: Invalid argument
bash-5.0# echo $?
4
bash-5.0# devlink dev param show netdevsim/netdevsim11 name test2 -j | jq -r '.[][][].values[] | select(.cmode == "driverinit").value' devlink answers: Invalid argument
bash-5.0# echo $?
0

The return value is 0 like everyone is fine. You probably have a different jq version (1.6). Looks like I need to use the same workaround I have in tools/testing/selftests/net/forwarding/tc_common.sh. I thought that -e would avoid that.

Quoted 7 lines
# ./devlink.sh 
TEST: fw flash test                                                 [ OK ]
TEST: params test                                                   [ OK ]
Quoted 2 lines
tools/testing/selftests/drivers/net/netdevsim/devlink.sh +2 -0
+}
+