Skip to content

Commit 2499451

Browse files
Cypresslinkuba-moo
authored andcommitted
selftests: net: devlink_port_split.py: skip test if no suitable device available
The `devlink -j port show` command output may not contain the "flavour" key, an example from Ubuntu 22.10 s390x LPAR(5.19.0-37-generic), with mlx4 driver and iproute2-5.15.0: {"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. Create a validate_devlink_output() to check for this "flavour" from devlink command output to avoid this KeyError exception. Also let it handle the check for `devlink -j dev show` output in main(). Apart from this, if the test was not started because the max lanes of the designated device is 0. The script will still return 0 and thus causing a false-negative test result. Use a found_max_lanes flag to determine if these tests were skipped due to this reason and return KSFT_SKIP to make it more clear. Link: https://bugs.launchpad.net/bugs/1937133 Fixes: f3348a8 ("selftests: net: Add port split test") Signed-off-by: Po-Hsu Lin <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent f383733 commit 2499451

File tree

1 file changed

+31
-5
lines changed

1 file changed

+31
-5
lines changed

tools/testing/selftests/net/devlink_port_split.py

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ def get_if_names(dev):
5959
assert stderr == ""
6060
ports = json.loads(stdout)['port']
6161

62+
validate_devlink_output(ports, 'flavour')
63+
6264
for port in ports:
6365
if dev in port:
6466
if ports[port]['flavour'] == 'physical':
@@ -220,6 +222,27 @@ def split_splittable_port(port, k, lanes, dev):
220222
unsplit(port.bus_info)
221223

222224

225+
def validate_devlink_output(devlink_data, target_property=None):
226+
"""
227+
Determine if test should be skipped by checking:
228+
1. devlink_data contains values
229+
2. The target_property exist in devlink_data
230+
"""
231+
skip_reason = None
232+
if any(devlink_data.values()):
233+
if target_property:
234+
skip_reason = "{} not found in devlink output, test skipped".format(target_property)
235+
for key in devlink_data:
236+
if target_property in devlink_data[key]:
237+
skip_reason = None
238+
else:
239+
skip_reason = 'devlink output is empty, test skipped'
240+
241+
if skip_reason:
242+
print(skip_reason)
243+
sys.exit(KSFT_SKIP)
244+
245+
223246
def make_parser():
224247
parser = argparse.ArgumentParser(description='A test for port splitting.')
225248
parser.add_argument('--dev',
@@ -240,12 +263,9 @@ def main(cmdline=None):
240263
stdout, stderr = run_command(cmd)
241264
assert stderr == ""
242265

266+
validate_devlink_output(json.loads(stdout))
243267
devs = json.loads(stdout)['dev']
244-
if devs:
245-
dev = list(devs.keys())[0]
246-
else:
247-
print("no devlink device was found, test skipped")
248-
sys.exit(KSFT_SKIP)
268+
dev = list(devs.keys())[0]
249269

250270
cmd = "devlink dev show %s" % dev
251271
stdout, stderr = run_command(cmd)
@@ -255,6 +275,7 @@ def main(cmdline=None):
255275

256276
ports = devlink_ports(dev)
257277

278+
found_max_lanes = False
258279
for port in ports.if_names:
259280
max_lanes = get_max_lanes(port.name)
260281

@@ -277,6 +298,11 @@ def main(cmdline=None):
277298
split_splittable_port(port, lane, max_lanes, dev)
278299

279300
lane //= 2
301+
found_max_lanes = True
302+
303+
if not found_max_lanes:
304+
print(f"Test not started, no port of device {dev} reports max_lanes")
305+
sys.exit(KSFT_SKIP)
280306

281307

282308
if __name__ == "__main__":

0 commit comments

Comments
 (0)