diff mbox series

[net-next,v2,7/7] netdevsim: Add netdevsim port add test cases

Message ID 20210207084412.252259-8-parav@nvidia.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series netdevsim port add, delete support | expand

Checks

Context Check Description
netdev/cover_letter success Link
netdev/fixes_present success Link
netdev/patch_count success Link
netdev/tree_selection success Clearly marked for net-next
netdev/subject_prefix success Link
netdev/cc_maintainers warning 5 maintainers not CCed: eranbe@mellanox.com linux-kselftest@vger.kernel.org jiri@mellanox.com jacob.e.keller@intel.com shuah@kernel.org
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Link
netdev/module_param success Was 0 now: 0
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/verify_fixes success Link
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 84 lines checked
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/header_inline success Link
netdev/stable success Stable not CCed

Commit Message

Parav Pandit Feb. 7, 2021, 8:44 a.m. UTC
Add tests for PCI PF and SF port add, configure and delete.

Signed-off-by: Parav Pandit <parav@nvidia.com>
---
 .../drivers/net/netdevsim/devlink.sh          | 72 ++++++++++++++++++-
 1 file changed, 71 insertions(+), 1 deletion(-)

Comments

Jakub Kicinski Feb. 8, 2021, 9:21 p.m. UTC | #1
On Sun, 7 Feb 2021 10:44:12 +0200 Parav Pandit wrote:
> +	RET=0
> +	USR_PF_PORT_INDEX=600
> +	USR_PFNUM_A=2
> +	USR_PFNUM_B=3
> +	USR_SF_PORT_INDEX=601
> +	USR_SFNUM_A=44
> +	USR_SFNUM_B=55
> +
> +	devlink port add $DL_HANDLE flavour pcipf pfnum $USR_PFNUM_A
> +	check_err $? "Failed PF port addition"
> +
> +	devlink port show
> +	check_err $? "Failed PF port show"
> +
> +	devlink port add $DL_HANDLE flavour pcisf pfnum $USR_PFNUM_A
> +	check_err $? "Failed SF port addition"
> +
> +	devlink port add $DL_HANDLE flavour pcisf pfnum $USR_PFNUM_A \
> +			sfnum $USR_SFNUM_A
> +	check_err $? "Failed SF port addition"
> +
> +	devlink port add $DL_HANDLE flavour pcipf pfnum $USR_PFNUM_B
> +	check_err $? "Failed second PF port addition"
> +
> +	devlink port add $DL_HANDLE/$USR_SF_PORT_INDEX flavour pcisf \
> +			pfnum $USR_PFNUM_B sfnum $USR_SFNUM_B
> +	check_err $? "Failed SF port addition"
> +
> +	devlink port show
> +	check_err $? "Failed PF port show"
> +
> +	state=$(function_state_get "state")
> +	check_err $? "Failed to get function state"
> +	[ "$state" == "inactive" ]
> +	check_err $? "Unexpected function state $state"
> +
> +	state=$(function_state_get "opstate")
> +	check_err $? "Failed to get operational state"
> +	[ "$state" == "detached" ]
> +	check_err $? "Unexpected function opstate $opstate"
> +
> +	devlink port function set $DL_HANDLE/$USR_SF_PORT_INDEX state active
> +	check_err $? "Failed to set state"
> +
> +	state=$(function_state_get "state")
> +	check_err $? "Failed to get function state"
> +	[ "$state" == "active" ]
> +	check_err $? "Unexpected function state $state"
> +
> +	state=$(function_state_get "opstate")
> +	check_err $? "Failed to get operational state"
> +	[ "$state" == "attached" ]
> +	check_err $? "Unexpected function opstate $opstate"
> +
> +	devlink port del $DL_HANDLE/$USR_SF_PORT_INDEX
> +	check_err $? "Failed SF port deletion"
> +
> +	log_test "port_add test"

I don't think this very basic test is worth the 600 LoC of netdevsim
code.

If you come up with something better please don't post v3 it in reply 
to previous threads.
Parav Pandit Feb. 9, 2021, 3:59 a.m. UTC | #2
> From: Jakub Kicinski <kuba@kernel.org>
> Sent: Tuesday, February 9, 2021 2:51 AM
> 
> On Sun, 7 Feb 2021 10:44:12 +0200 Parav Pandit wrote:
> > +	RET=0
> > +	USR_PF_PORT_INDEX=600
> > +	USR_PFNUM_A=2
> > +	USR_PFNUM_B=3
> > +	USR_SF_PORT_INDEX=601
> > +	USR_SFNUM_A=44
> > +	USR_SFNUM_B=55
> > +
> > +	devlink port add $DL_HANDLE flavour pcipf pfnum $USR_PFNUM_A
> > +	check_err $? "Failed PF port addition"
> > +
> > +	devlink port show
> > +	check_err $? "Failed PF port show"
> > +
> > +	devlink port add $DL_HANDLE flavour pcisf pfnum $USR_PFNUM_A
> > +	check_err $? "Failed SF port addition"
> > +
> > +	devlink port add $DL_HANDLE flavour pcisf pfnum $USR_PFNUM_A \
> > +			sfnum $USR_SFNUM_A
> > +	check_err $? "Failed SF port addition"
> > +
> > +	devlink port add $DL_HANDLE flavour pcipf pfnum $USR_PFNUM_B
> > +	check_err $? "Failed second PF port addition"
> > +
> > +	devlink port add $DL_HANDLE/$USR_SF_PORT_INDEX flavour pcisf \
> > +			pfnum $USR_PFNUM_B sfnum $USR_SFNUM_B
> > +	check_err $? "Failed SF port addition"
> > +
> > +	devlink port show
> > +	check_err $? "Failed PF port show"
> > +
> > +	state=$(function_state_get "state")
> > +	check_err $? "Failed to get function state"
> > +	[ "$state" == "inactive" ]
> > +	check_err $? "Unexpected function state $state"
> > +
> > +	state=$(function_state_get "opstate")
> > +	check_err $? "Failed to get operational state"
> > +	[ "$state" == "detached" ]
> > +	check_err $? "Unexpected function opstate $opstate"
> > +
> > +	devlink port function set $DL_HANDLE/$USR_SF_PORT_INDEX state
> active
> > +	check_err $? "Failed to set state"
> > +
> > +	state=$(function_state_get "state")
> > +	check_err $? "Failed to get function state"
> > +	[ "$state" == "active" ]
> > +	check_err $? "Unexpected function state $state"
> > +
> > +	state=$(function_state_get "opstate")
> > +	check_err $? "Failed to get operational state"
> > +	[ "$state" == "attached" ]
> > +	check_err $? "Unexpected function opstate $opstate"
> > +
> > +	devlink port del $DL_HANDLE/$USR_SF_PORT_INDEX
> > +	check_err $? "Failed SF port deletion"
> > +
> > +	log_test "port_add test"
> 
> I don't think this very basic test is worth the 600 LoC of netdevsim code.
> 
Do you mean I should improve the test to do more code coverage for 600 LoC?

> If you come up with something better please don't post v3 it in reply to
> previous threads.
Can you please explain? If only test case improves, wouldn't it be v3 for the last patch?
I must be missing something here.
diff mbox series

Patch

diff --git a/tools/testing/selftests/drivers/net/netdevsim/devlink.sh b/tools/testing/selftests/drivers/net/netdevsim/devlink.sh
index 40909c254365..ba349909a37e 100755
--- a/tools/testing/selftests/drivers/net/netdevsim/devlink.sh
+++ b/tools/testing/selftests/drivers/net/netdevsim/devlink.sh
@@ -5,7 +5,7 @@  lib_dir=$(dirname $0)/../../../net/forwarding
 
 ALL_TESTS="fw_flash_test params_test regions_test reload_test \
 	   netns_reload_test resource_test dev_info_test \
-	   empty_reporter_test dummy_reporter_test"
+	   empty_reporter_test dummy_reporter_test devlink_port_add_test"
 NUM_NETIFS=0
 source $lib_dir/lib.sh
 
@@ -507,6 +507,76 @@  dummy_reporter_test()
 	log_test "dummy reporter test"
 }
 
+function_state_get()
+{
+	local name=$1
+
+	cmd_jq "devlink port show $DL_HANDLE/$USR_SF_PORT_INDEX -j" \
+		" .[][].function.$1"
+}
+
+devlink_port_add_test()
+{
+	RET=0
+	USR_PF_PORT_INDEX=600
+	USR_PFNUM_A=2
+	USR_PFNUM_B=3
+	USR_SF_PORT_INDEX=601
+	USR_SFNUM_A=44
+	USR_SFNUM_B=55
+
+	devlink port add $DL_HANDLE flavour pcipf pfnum $USR_PFNUM_A
+	check_err $? "Failed PF port addition"
+
+	devlink port show
+	check_err $? "Failed PF port show"
+
+	devlink port add $DL_HANDLE flavour pcisf pfnum $USR_PFNUM_A
+	check_err $? "Failed SF port addition"
+
+	devlink port add $DL_HANDLE flavour pcisf pfnum $USR_PFNUM_A \
+			sfnum $USR_SFNUM_A
+	check_err $? "Failed SF port addition"
+
+	devlink port add $DL_HANDLE flavour pcipf pfnum $USR_PFNUM_B
+	check_err $? "Failed second PF port addition"
+
+	devlink port add $DL_HANDLE/$USR_SF_PORT_INDEX flavour pcisf \
+			pfnum $USR_PFNUM_B sfnum $USR_SFNUM_B
+	check_err $? "Failed SF port addition"
+
+	devlink port show
+	check_err $? "Failed PF port show"
+
+	state=$(function_state_get "state")
+	check_err $? "Failed to get function state"
+	[ "$state" == "inactive" ]
+	check_err $? "Unexpected function state $state"
+
+	state=$(function_state_get "opstate")
+	check_err $? "Failed to get operational state"
+	[ "$state" == "detached" ]
+	check_err $? "Unexpected function opstate $opstate"
+
+	devlink port function set $DL_HANDLE/$USR_SF_PORT_INDEX state active
+	check_err $? "Failed to set state"
+
+	state=$(function_state_get "state")
+	check_err $? "Failed to get function state"
+	[ "$state" == "active" ]
+	check_err $? "Unexpected function state $state"
+
+	state=$(function_state_get "opstate")
+	check_err $? "Failed to get operational state"
+	[ "$state" == "attached" ]
+	check_err $? "Unexpected function opstate $opstate"
+
+	devlink port del $DL_HANDLE/$USR_SF_PORT_INDEX
+	check_err $? "Failed SF port deletion"
+
+	log_test "port_add test"
+}
+
 setup_prepare()
 {
 	modprobe netdevsim