public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
To: Jakub Kicinski <kuba@kernel.org>,
	 Willem de Bruijn <willemdebruijn.kernel@gmail.com>
Cc: netdev@vger.kernel.org,  davem@davemloft.net,
	 edumazet@google.com,  pabeni@redhat.com,  horms@kernel.org,
	 linux-kselftest@vger.kernel.org,  shuah@kernel.org,
	 Willem de Bruijn <willemb@google.com>
Subject: Re: [PATCH net-next v6 1/3] selftests: net: py: support cmd verifying expected failure
Date: Sun, 03 May 2026 18:14:37 -0400	[thread overview]
Message-ID: <willemdebruijn.kernel.258359727e7a2@gmail.com> (raw)
In-Reply-To: <20260501173918.575ecdc4@kernel.org>

Jakub Kicinski wrote:
> On Thu, 30 Apr 2026 09:28:04 -0400 Willem de Bruijn wrote:
> > From: Willem de Bruijn <willemb@google.com>
> > 
> > Support negative tests, where cmd raises an exception if the command
> > succeeded.
> > 
> > Existing fail values are
> > 
> > - True:            Pass if returncode == 0, raise Exception otherwise
> > - False:           Pass unconditionally
> > - None:            True iff not terminated explicitly
> > 
> > Introduce a variant of True that inverses the condition:
> > 
> > - 'verify_failed': Pass if returncode != 0, raise Exception otherwise
> > 
> > We cannot reuse False for this, because existing tests rely on current
> > behavior to pass unconditionally.
> > 
> > Only suppress regular test failure. Python subprocess may set a
> > negative return code on process crash or timeout. Those are not
> > anticipated failures.
> 
> The fact that subprocess sets retcode to negative on crash / timeout
> may be worth a comment in the code. I didn't know that.
> 
> > diff --git a/tools/testing/selftests/net/lib/py/utils.py b/tools/testing/selftests/net/lib/py/utils.py
> > index 6c44a3d2bbf7..ef31c0ba47fc 100644
> > --- a/tools/testing/selftests/net/lib/py/utils.py
> > +++ b/tools/testing/selftests/net/lib/py/utils.py
> > @@ -111,10 +111,14 @@ class cmd:
> >  
> >          stdout, stderr = self._process_terminate(terminate=terminate,
> >                                                   timeout=timeout)
> > -        if self.proc.returncode != 0 and fail:
> > +
> > +        if (self.proc.returncode != 0 and fail and
> > +            (self.proc.returncode < 0 or fail != 'verify_failed')):
> 
> Personal preference but doesn't feel clean. I would have added 
> a dedicated argument for this. Up to you..

Do you mean adding an expect_fail as below? I have to thread it to cmd and bkg,
but it's not too bad.

@@ -112,13 +120,17 @@ class cmd:
         stdout, stderr = self._process_terminate(terminate=terminate,
                                                  timeout=timeout)

-        if (self.proc.returncode != 0 and fail and
-            (self.proc.returncode < 0 or fail != 'verify_failed')):
+        # Fail on unexpected test failure if fail.
+        # Fail on unexpected test success if expect_fail.
+        # Fail on negative returncode if either:
+        # Set by subprocess on crash or signal, this is never expected failure.
+        if (self.proc.returncode != 0 and fail or
+            (self.proc.returncode < 0 and expect_fail)):
             if len(stderr) > 0 and stderr[-1] == "\n":
                 stderr = stderr[:-1]
             raise CmdExitFailure("Command failed", self)
-        elif self.proc.returncode == 0 and fail == 'verify_failed':
-            raise CmdExitFailure("Command succeeded while should fail", self)
+        elif self.proc.returncode == 0 and expect_fail:
+            raise CmdExitZeroFailure("Command succeeded (expected fail)", self)

 
> >              if len(stderr) > 0 and stderr[-1] == "\n":
> >                  stderr = stderr[:-1]
> >              raise CmdExitFailure("Command failed", self)
> > +        elif self.proc.returncode == 0 and fail == 'verify_failed':
> > +            raise CmdExitFailure("Command succeeded while should fail", self)
> 
> Can we create a new exception type? Just inherit CmdExitFailure 
> but name it more appropriately.
> 
> Regarding the message maybe: "Command succeeded (expected fail)" or
> "Command succeeded (unexpectedly)"



  reply	other threads:[~2026-05-03 22:14 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-30 13:28 [PATCH net-next v6 0/3] selftests: drv-net: convert so_txtime to drv-net Willem de Bruijn
2026-04-30 13:28 ` [PATCH net-next v6 1/3] selftests: net: py: support cmd verifying expected failure Willem de Bruijn
2026-05-02  0:39   ` Jakub Kicinski
2026-05-03 22:14     ` Willem de Bruijn [this message]
2026-04-30 13:28 ` [PATCH net-next v6 2/3] selftests: net: py: add tc utility Willem de Bruijn
2026-04-30 13:28 ` [PATCH net-next v6 3/3] selftests: drv-net: convert so_txtime to drv-net Willem de Bruijn
2026-05-02  0:45   ` Jakub Kicinski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=willemdebruijn.kernel.258359727e7a2@gmail.com \
    --to=willemdebruijn.kernel@gmail.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=shuah@kernel.org \
    --cc=willemb@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox