Linux Kernel Selftest development
 help / color / mirror / Atom feed
From: Ido Schimmel <idosch@nvidia.com>
To: Petr Machata <petrm@nvidia.com>
Cc: Shuah Khan <shuah@kernel.org>,
	linux-kselftest@vger.kernel.org, netdev@vger.kernel.org,
	Jakub Kicinski <kuba@kernel.org>, Amit Cohen <amcohen@nvidia.com>,
	Benjamin Poirier <bpoirier@nvidia.com>,
	Hangbin Liu <liuhangbin@gmail.com>,
	Vladimir Oltean <vladimir.oltean@nxp.com>,
	mlxsw@nvidia.com
Subject: Re: [RFC PATCH net-next 1/5] selftests: forwarding: Introduce deferred commands
Date: Mon, 26 Aug 2024 13:35:55 +0300	[thread overview]
Message-ID: <Zsxai0ACHxfbwH-t@shredder.mtl.com> (raw)
In-Reply-To: <d5f8364b42f277daa9e235d23398e3dce5549e92.1724324945.git.petrm@nvidia.com>

On Thu, Aug 22, 2024 at 03:49:40PM +0200, Petr Machata wrote:
> In commit 8510801a9dbd ("selftests: drv-net: add ability to schedule
> cleanup with defer()"), a defer helper was added to Python selftests.
> The idea is to keep cleanup commands close to their dirtying counterparts,
> thereby making it more transparent what is cleaning up what, making it
> harder to miss a cleanup, and make the whole cleanup business exception
> safe. All these benefits are applicable to bash as well, exception safety
> can be interpreted in terms of safety vs. a SIGINT.
> 
> This patch therefore introduces a framework of several helpers that serve
> to schedule cleanups in bash selftests:
> 
> - defer_scope_push(), defer_scope_pop(): Deferred statements can be batched
>   together in scopes. When a scope is popped, the deferred commands
>   schoduled in that scope are executed in the order opposite to order of

s/schoduled/scheduled/

>   their scheduling.
> 
> - defer(): Schedules a defer to the most recently pushed scope (or the
>   default scope if none was pushed.)
> 
> - defer_scopes_cleanup(): Pops any unpopped scopes, including the default
>   one. The selftests that use defer should run this in their cleanup
>   function. This is important to get cleanups of interrupted scripts.
> 
>   Consistent use of defers however obviates the need for a separate cleanup
>   function -- everything is just taken care of in defers. So this patch
>   actually introduces a cleanup() helper in the forwarding lib.sh, which
>   calls just pre_cleanup() and defer_scopes_cleanup(). Selftests are
>   obviously still free to override the function.
> 
> - defer_scoped_fn(): Sometimes a function would like to introduce a new
>   defer scope, then run whatever it is that it wants to run, and then pop
>   the scope to run the deferred cleanups. The helper defer_scoped_fn() can
>   be used to derive from one function its wrapper that pushes a defer scope
>   before the function is called, and pops it after it returns.
> 
> The following patches will convert several selftests to this new framework.

The intention is to make sure new tests are using these helpers?

> 
> Signed-off-by: Petr Machata <petrm@nvidia.com>
> ---
>  tools/testing/selftests/net/forwarding/lib.sh | 83 +++++++++++++++++++

Does it make sense to place these helpers in net/lib.sh?

  reply	other threads:[~2024-08-26 10:36 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-22 13:49 [RFC PATCH net-next 0/5] selftests: forwarding: Introduce deferred commands Petr Machata
2024-08-22 13:49 ` [RFC PATCH net-next 1/5] " Petr Machata
2024-08-26 10:35   ` Ido Schimmel [this message]
2024-08-26 14:25     ` Petr Machata
2024-08-26 20:03       ` Jakub Kicinski
2024-08-26 20:04         ` Jakub Kicinski
2024-08-26 13:09   ` Przemek Kitszel
2024-08-26 15:20     ` Petr Machata
2024-08-27  6:21       ` Przemek Kitszel
2024-08-27  8:53         ` Petr Machata
2024-08-27 14:17           ` Jakub Kicinski
2024-08-27 15:37             ` Petr Machata
2024-08-22 13:49 ` [RFC PATCH net-next 2/5] selftests: mlxsw: sch_red_core: Use defer for test cleanup Petr Machata
2024-08-26 11:37   ` Ido Schimmel
2024-08-22 13:49 ` [RFC PATCH net-next 3/5] selftests: mlxsw: sch_red_core: Use defer for stopping traffic Petr Machata
2024-08-26 12:01   ` Ido Schimmel
2024-08-22 13:49 ` [RFC PATCH net-next 4/5] selftests: mlxsw: sch_red_*: Use defer for qdisc management Petr Machata
2024-08-26 12:03   ` Ido Schimmel
2024-08-22 13:49 ` [RFC PATCH net-next 5/5] selftests: sch_tbf_core: Use defer for stopping traffic Petr Machata
2024-08-26 12:07   ` Ido Schimmel
2024-08-26 14:31     ` Petr Machata

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=Zsxai0ACHxfbwH-t@shredder.mtl.com \
    --to=idosch@nvidia.com \
    --cc=amcohen@nvidia.com \
    --cc=bpoirier@nvidia.com \
    --cc=kuba@kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=liuhangbin@gmail.com \
    --cc=mlxsw@nvidia.com \
    --cc=netdev@vger.kernel.org \
    --cc=petrm@nvidia.com \
    --cc=shuah@kernel.org \
    --cc=vladimir.oltean@nxp.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