Skip to content

Commit

Permalink
selftests: net: devlink_port_split.py: skip the test if no devlink de…
Browse files Browse the repository at this point in the history
…vice

When there is no devlink device, the following command will return:
  $ devlink -j dev show
  {dev:{}}

This will cause IndexError when trying to access the first element
in dev of this json dataset. Use the kselftest framework skip code
to skip this test in this case.

Example output with this change:
  # selftests: net: devlink_port_split.py
  # no devlink device was found, test skipped
  ok 7 selftests: net: devlink_port_split.py # SKIP

Link: https://bugs.launchpad.net/bugs/1928889
Signed-off-by: Po-Hsu Lin <po-hsu.lin@canonical.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Po-Hsu Lin authored and David S. Miller committed May 20, 2021
1 parent 07b5dc1 commit 25173dd
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion tools/testing/selftests/net/devlink_port_split.py
Original file line number Diff line number Diff line change
@@ -18,6 +18,8 @@
#


# Kselftest framework requirement - SKIP code is 4
KSFT_SKIP=4
Port = collections.namedtuple('Port', 'bus_info name')


@@ -239,7 +241,11 @@ def main(cmdline=None):
assert stderr == ""

devs = json.loads(stdout)['dev']
dev = list(devs.keys())[0]
if devs:
dev = list(devs.keys())[0]
else:
print("no devlink device was found, test skipped")
sys.exit(KSFT_SKIP)

cmd = "devlink dev show %s" % dev
stdout, stderr = run_command(cmd)

0 comments on commit 25173dd

Please sign in to comment.