netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] selftests: net: devlink_port_split.py: skip test if no suitable device available
@ 2023-03-06 11:19 Po-Hsu Lin
  2023-03-06 18:33 ` Jakub Kicinski
  0 siblings, 1 reply; 3+ messages in thread
From: Po-Hsu Lin @ 2023-03-06 11:19 UTC (permalink / raw)
  To: linux-kernel, linux-kselftest, netdev
  Cc: idosch, danieller, petrm, shuah, pabeni, kuba, edumazet, davem,
	po-hsu.lin

The `devlink -j dev show` command output may not contain the "flavour"
key, for example:
  $ devlink -j dev show
  {"dev":{"pci/0001:00:00.0":{},"pci/0002:00:00.0":{}}}

This will cause a KeyError exception. Fix this by checking the key
existence first.

Also, if max lanes is 0 the port splitting won't be tested at all.
but the script will end normally and thus causing a false-negative
test result.

Use a test_ran flag to determine if these tests were skipped and
return KSFT_SKIP accordingly.

Link: https://bugs.launchpad.net/bugs/1937133
Fixes: f3348a82e727 ("selftests: net: Add port split test")
Signed-off-by: Po-Hsu Lin <po-hsu.lin@canonical.com>
---
 tools/testing/selftests/net/devlink_port_split.py | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/net/devlink_port_split.py b/tools/testing/selftests/net/devlink_port_split.py
index 2b5d6ff..462f3df 100755
--- a/tools/testing/selftests/net/devlink_port_split.py
+++ b/tools/testing/selftests/net/devlink_port_split.py
@@ -61,7 +61,7 @@ class devlink_ports(object):
 
         for port in ports:
             if dev in port:
-                if ports[port]['flavour'] == 'physical':
+                if 'flavour' in ports[port] and ports[port]['flavour'] == 'physical':
                     arr.append(Port(bus_info=port, name=ports[port]['netdev']))
 
         return arr
@@ -231,6 +231,7 @@ def make_parser():
 
 
 def main(cmdline=None):
+    test_ran = False
     parser = make_parser()
     args = parser.parse_args(cmdline)
 
@@ -277,6 +278,11 @@ def main(cmdline=None):
                 split_splittable_port(port, lane, max_lanes, dev)
 
                 lane //= 2
+        test_ran = True
+
+    if not test_ran:
+        print("No suitable device for the test, test skipped")
+        sys.exit(KSFT_SKIP)
 
 
 if __name__ == "__main__":
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] selftests: net: devlink_port_split.py: skip test if no suitable device available
  2023-03-06 11:19 [PATCH] selftests: net: devlink_port_split.py: skip test if no suitable device available Po-Hsu Lin
@ 2023-03-06 18:33 ` Jakub Kicinski
  2023-03-07  2:24   ` Po-Hsu Lin
  0 siblings, 1 reply; 3+ messages in thread
From: Jakub Kicinski @ 2023-03-06 18:33 UTC (permalink / raw)
  To: Po-Hsu Lin
  Cc: linux-kernel, linux-kselftest, netdev, idosch, danieller, petrm,
	shuah, pabeni, edumazet, davem

On Mon,  6 Mar 2023 19:19:59 +0800 Po-Hsu Lin wrote:
> The `devlink -j dev show` command output may not contain the "flavour"
> key, for example:
>   $ devlink -j dev show
>   {"dev":{"pci/0001:00:00.0":{},"pci/0002:00:00.0":{}}}

It's not dev that's supposed to have the flavor, it's port.

  devlink -j port show

Are you running with old kernel or old user space?
Flavor is not an optional attribute.

> This will cause a KeyError exception. Fix this by checking the key
> existence first.
> 
> Also, if max lanes is 0 the port splitting won't be tested at all.
> but the script will end normally and thus causing a false-negative
> test result.
> 
> Use a test_ran flag to determine if these tests were skipped and
> return KSFT_SKIP accordingly.
> 
> Link: https://bugs.launchpad.net/bugs/1937133
> Fixes: f3348a82e727 ("selftests: net: Add port split test")
> Signed-off-by: Po-Hsu Lin <po-hsu.lin@canonical.com>

Could you factor out the existing skipping logic from main()
(the code under "if not dev:") and add the test for flavors
to the same function? It'll be a bit more code but cleaner
result IMHO.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] selftests: net: devlink_port_split.py: skip test if no suitable device available
  2023-03-06 18:33 ` Jakub Kicinski
@ 2023-03-07  2:24   ` Po-Hsu Lin
  0 siblings, 0 replies; 3+ messages in thread
From: Po-Hsu Lin @ 2023-03-07  2:24 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: linux-kernel, linux-kselftest, netdev, idosch, danieller, petrm,
	shuah, pabeni, edumazet, davem

On Tue, Mar 7, 2023 at 2:33 AM Jakub Kicinski <kuba@kernel.org> wrote:
>
> On Mon,  6 Mar 2023 19:19:59 +0800 Po-Hsu Lin wrote:
> > The `devlink -j dev show` command output may not contain the "flavour"
> > key, for example:
> >   $ devlink -j dev show
> >   {"dev":{"pci/0001:00:00.0":{},"pci/0002:00:00.0":{}}}
>
> It's not dev that's supposed to have the flavor, it's port.
>
>   devlink -j port show
Ah yes, it's using output from this command, thanks for catching this.

>
> Are you running with old kernel or old user space?
> Flavor is not an optional attribute.
This was from a s390x LPAR instance with Ubuntu 22.10 (5.19.0-37-generic)
iproute2-5.15.0

$ devlink -j port show
{"port":{"pci/0001:00:00.0/1":{"type":"eth","netdev":"ens301"},"pci/0001:00:00.0/2":{"type":"eth","netdev":"ens301d1"},"pci/0002:00:00.0/1":{"type":"eth","netdev":"ens317"},"pci/0002:00:00.0/2":{"type":"eth","netdev":"ens317d1"}}}

>
> > This will cause a KeyError exception. Fix this by checking the key
> > existence first.
> >
> > Also, if max lanes is 0 the port splitting won't be tested at all.
> > but the script will end normally and thus causing a false-negative
> > test result.
> >
> > Use a test_ran flag to determine if these tests were skipped and
> > return KSFT_SKIP accordingly.
> >
> > Link: https://bugs.launchpad.net/bugs/1937133
> > Fixes: f3348a82e727 ("selftests: net: Add port split test")
> > Signed-off-by: Po-Hsu Lin <po-hsu.lin@canonical.com>
>
> Could you factor out the existing skipping logic from main()
> (the code under "if not dev:") and add the test for flavors
> to the same function? It'll be a bit more code but cleaner
> result IMHO.
Sure, will do with V2.
Thanks!

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-03-07  2:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-03-06 11:19 [PATCH] selftests: net: devlink_port_split.py: skip test if no suitable device available Po-Hsu Lin
2023-03-06 18:33 ` Jakub Kicinski
2023-03-07  2:24   ` Po-Hsu Lin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).