All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jakub Kicinski <kuba@kernel.org>
To: 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: Fri, 1 May 2026 17:39:18 -0700	[thread overview]
Message-ID: <20260501173918.575ecdc4@kernel.org> (raw)
In-Reply-To: <20260430132820.1944517-2-willemdebruijn.kernel@gmail.com>

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..

>              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-02  0:39 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 [this message]
2026-05-03 22:14     ` Willem de Bruijn
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=20260501173918.575ecdc4@kernel.org \
    --to=kuba@kernel.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=horms@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 \
    --cc=willemdebruijn.kernel@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.