Skip to content

Commit 0d8021c

Browse files
committed
selftests: net: py: check process exit code in bkg() and background cmd()
JIRA: https://issues.redhat.com/browse/RHEL-57764 commit e1bb5e6 Author: Jakub Kicinski <kuba@kernel.org> Date: Wed May 1 19:53:25 2024 -0700 selftests: net: py: check process exit code in bkg() and background cmd() We're a bit too loose with error checking for background processes. cmd() completely ignores the fail argument passed to the constructor if background is True. Default to checking for errors if process is not terminated explicitly. Caller can override with True / False. For bkg() the processing step is called magically by __exit__ so record the value passed in the constructor. Reported-by: Willem de Bruijn <willemb@google.com> Tested-by: Willem de Bruijn <willemb@google.com> Link: https://lore.kernel.org/r/20240502025325.1924923-1-kuba@kernel.org Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Ivan Vecera <ivecera@redhat.com>
1 parent d60527b commit 0d8021c

File tree

1 file changed

+6
-2
lines changed
  • tools/testing/selftests/net/lib/py

1 file changed

+6
-2
lines changed

tools/testing/selftests/net/lib/py/utils.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ def __init__(self, comm, shell=True, fail=True, ns=None, background=False, host=
2626
self.process(terminate=False, fail=fail)
2727

2828
def process(self, terminate=True, fail=None):
29+
if fail is None:
30+
fail = not terminate
31+
2932
if terminate:
3033
self.proc.terminate()
3134
stdout, stderr = self.proc.communicate(timeout=5)
@@ -42,17 +45,18 @@ def process(self, terminate=True, fail=None):
4245

4346

4447
class bkg(cmd):
45-
def __init__(self, comm, shell=True, fail=True, ns=None, host=None,
48+
def __init__(self, comm, shell=True, fail=None, ns=None, host=None,
4649
exit_wait=False):
4750
super().__init__(comm, background=True,
4851
shell=shell, fail=fail, ns=ns, host=host)
4952
self.terminate = not exit_wait
53+
self.check_fail = fail
5054

5155
def __enter__(self):
5256
return self
5357

5458
def __exit__(self, ex_type, ex_value, ex_tb):
55-
return self.process(terminate=self.terminate)
59+
return self.process(terminate=self.terminate, fail=self.check_fail)
5660

5761

5862
def ip(args, json=None, ns=None, host=None):

0 commit comments

Comments
 (0)