mbox series

[net-next,v2,00/10] selftests: net: Introduce deferred commands

Message ID cover.1729157566.git.petrm@nvidia.com (mailing list archive)
Headers show
Series selftests: net: Introduce deferred commands | expand

Message

Petr Machata Oct. 17, 2024, 9:45 a.m. UTC
Recently, 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 patchset therefore introduces a framework of several helpers that
serve to schedule cleanups in bash selftests.

- Patch #1 has more details about the primitives being introduced.
  Patch #2 adds a fallback cleanup() function to lib.sh, because ideally
  selftests wouldn't need to introduce a dedicated cleanup function at all.

- Patch #3 adds a parameter to stop_traffic(), which makes it possible to
  start other background processes after the traffic is started without
  confusing the cleanup.

- Patches #4 to #10 convert a number of selftests.

  The goal was to convert all tests that use start_traffic / stop_traffic
  to the defer framework. Leftover traffic generators are a particularly
  painful sort of a missed cleanup. Normal unfinished cleanups can usually
  be cleaned up simply by rerunning the test and interrupting it early to
  let the cleanups run again / in full. This does not work with
  stop_traffic, because it is only issued at the end of the test case that
  starts the traffic. At the same time, leftover traffic generators
  influence follow-up test runs, and are hard to notice.

  The tests were however converted whole-sale, not just their traffic bits.
  Thus they form a proof of concept of the defer framework.

v2:
- Patch #1:
    - In __defer__schedule(), use ndefers in place of
      ${__DEFER__NJOBS[$ndefers_key]}
- Patch #4:
    - Defer stop_traffic including the sleep. The sleep is actually
      necessary and v1 was wrong in that it had the sleep prior to the
      stop_traffic invocation.

v1 (from the RFC):
- Patch #1:
    - Added the priority defer track
    - Dropped defer_scoped_fn, added in_defer_scope
    - Extracted to a separate independent module
- Patch #2:
    - Moved this bit to a separate patch
- Patch #3:
    - New patch
- Patch #4 (RED):
    - Squashed the individual RED-related patches into one
    - Converted the SW datapath RED selftest as well
- Patch #5 (TBF):
    - Fully converted the selftest, not just stop_traffic
- Patches #6, #7, #8, #9, #10:
    - New patch

Petr Machata (10):
  selftests: net: lib: Introduce deferred commands
  selftests: forwarding: Add a fallback cleanup()
  selftests: forwarding: lib: Allow passing PID to stop_traffic()
  selftests: RED: Use defer for test cleanup
  selftests: TBF: Use defer for test cleanup
  selftests: ETS: Use defer for test cleanup
  selftests: mlxsw: qos_mc_aware: Use defer for test cleanup
  selftests: mlxsw: qos_ets_strict: Use defer for test cleanup
  selftests: mlxsw: qos_max_descriptors: Use defer for test cleanup
  selftests: mlxsw: devlink_trap_police: Use defer for test cleanup

 .../drivers/net/mlxsw/devlink_trap_policer.sh |  85 ++++----
 .../drivers/net/mlxsw/qos_ets_strict.sh       | 167 ++++++++--------
 .../drivers/net/mlxsw/qos_max_descriptors.sh  | 118 ++++-------
 .../drivers/net/mlxsw/qos_mc_aware.sh         | 146 +++++++-------
 .../selftests/drivers/net/mlxsw/sch_ets.sh    |  26 ++-
 .../drivers/net/mlxsw/sch_red_core.sh         | 185 +++++++++---------
 .../drivers/net/mlxsw/sch_red_ets.sh          |  24 +--
 .../drivers/net/mlxsw/sch_red_root.sh         |  18 +-
 tools/testing/selftests/net/forwarding/lib.sh |  13 +-
 .../selftests/net/forwarding/sch_ets.sh       |   7 +-
 .../selftests/net/forwarding/sch_ets_core.sh  |  81 +++-----
 .../selftests/net/forwarding/sch_ets_tests.sh |  14 +-
 .../selftests/net/forwarding/sch_red.sh       | 103 ++++------
 .../selftests/net/forwarding/sch_tbf_core.sh  |  91 +++------
 .../net/forwarding/sch_tbf_etsprio.sh         |   7 +-
 .../selftests/net/forwarding/sch_tbf_root.sh  |   3 +-
 tools/testing/selftests/net/lib.sh            |   3 +
 tools/testing/selftests/net/lib/Makefile      |   2 +-
 tools/testing/selftests/net/lib/sh/defer.sh   | 115 +++++++++++
 19 files changed, 595 insertions(+), 613 deletions(-)
 create mode 100644 tools/testing/selftests/net/lib/sh/defer.sh

Comments

patchwork-bot+netdevbpf@kernel.org Oct. 22, 2024, 11:50 a.m. UTC | #1
Hello:

This series was applied to netdev/net-next.git (main)
by Paolo Abeni <pabeni@redhat.com>:

On Thu, 17 Oct 2024 11:45:42 +0200 you wrote:
> Recently, 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.
> 
> [...]

Here is the summary with links:
  - [net-next,v2,01/10] selftests: net: lib: Introduce deferred commands
    https://git.kernel.org/netdev/net-next/c/a6e263f125cd
  - [net-next,v2,02/10] selftests: forwarding: Add a fallback cleanup()
    https://git.kernel.org/netdev/net-next/c/b4b0549a4e59
  - [net-next,v2,03/10] selftests: forwarding: lib: Allow passing PID to stop_traffic()
    https://git.kernel.org/netdev/net-next/c/0e07d5dbfbd9
  - [net-next,v2,04/10] selftests: RED: Use defer for test cleanup
    (no matching commit)
  - [net-next,v2,05/10] selftests: TBF: Use defer for test cleanup
    https://git.kernel.org/netdev/net-next/c/a1b3741dcfd1
  - [net-next,v2,06/10] selftests: ETS: Use defer for test cleanup
    (no matching commit)
  - [net-next,v2,07/10] selftests: mlxsw: qos_mc_aware: Use defer for test cleanup
    (no matching commit)
  - [net-next,v2,08/10] selftests: mlxsw: qos_ets_strict: Use defer for test cleanup
    https://git.kernel.org/netdev/net-next/c/424745af5271
  - [net-next,v2,09/10] selftests: mlxsw: qos_max_descriptors: Use defer for test cleanup
    https://git.kernel.org/netdev/net-next/c/919419a8870b
  - [net-next,v2,10/10] selftests: mlxsw: devlink_trap_police: Use defer for test cleanup
    https://git.kernel.org/netdev/net-next/c/cebd281f3c75

You are awesome, thank you!