diff mbox series

[net-next] selftests: net: py: check process exit code in bkg() and background cmd()

Message ID 20240502025325.1924923-1-kuba@kernel.org (mailing list archive)
State Accepted
Commit e1bb5e65de8355ee76f51c6bfee2328ac5b2be15
Delegated to: Netdev Maintainers
Headers show
Series [net-next] selftests: net: py: check process exit code in bkg() and background cmd() | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 8 this patch: 8
netdev/build_tools success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers warning 2 maintainers not CCed: shuah@kernel.org linux-kselftest@vger.kernel.org
netdev/build_clang success Errors and warnings before: 8 this patch: 8
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 8 this patch: 8
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 29 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-05-02--15-00 (tests: 1000)

Commit Message

Jakub Kicinski May 2, 2024, 2:53 a.m. UTC
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>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
 tools/testing/selftests/net/lib/py/utils.py | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

Comments

Willem de Bruijn May 2, 2024, 2:22 p.m. UTC | #1
Jakub Kicinski wrote:
> 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>
> Signed-off-by: Jakub Kicinski <kuba@kernel.org>

Tested-by: Willem de Bruijn <willemb@google.com>

Thanks!
patchwork-bot+netdevbpf@kernel.org May 3, 2024, 1:40 a.m. UTC | #2
Hello:

This patch was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Wed,  1 May 2024 19:53:25 -0700 you wrote:
> 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.
> 
> [...]

Here is the summary with links:
  - [net-next] selftests: net: py: check process exit code in bkg() and background cmd()
    https://git.kernel.org/netdev/net-next/c/e1bb5e65de83

You are awesome, thank you!
diff mbox series

Patch

diff --git a/tools/testing/selftests/net/lib/py/utils.py b/tools/testing/selftests/net/lib/py/utils.py
index b57d467afd0f..ec8b086b4fcb 100644
--- a/tools/testing/selftests/net/lib/py/utils.py
+++ b/tools/testing/selftests/net/lib/py/utils.py
@@ -26,6 +26,9 @@  import time
             self.process(terminate=False, fail=fail)
 
     def process(self, terminate=True, fail=None):
+        if fail is None:
+            fail = not terminate
+
         if terminate:
             self.proc.terminate()
         stdout, stderr = self.proc.communicate(timeout=5)
@@ -43,17 +46,18 @@  import time
 
 
 class bkg(cmd):
-    def __init__(self, comm, shell=True, fail=True, ns=None, host=None,
+    def __init__(self, comm, shell=True, fail=None, ns=None, host=None,
                  exit_wait=False):
         super().__init__(comm, background=True,
                          shell=shell, fail=fail, ns=ns, host=host)
         self.terminate = not exit_wait
+        self.check_fail = fail
 
     def __enter__(self):
         return self
 
     def __exit__(self, ex_type, ex_value, ex_tb):
-        return self.process(terminate=self.terminate)
+        return self.process(terminate=self.terminate, fail=self.check_fail)
 
 
 def tool(name, args, json=None, ns=None, host=None):