mirror of
https://github.com/torvalds/linux.git
synced 2026-04-19 23:34:00 -04:00
There's a lot of cases where we try to re-run the same code with
different parameters. We currently need to either use a generator
method or create a "main" case implementation which then gets called
by trivial case functions:
def _test(x, y, z):
...
def case_int():
_test(1, 2, 3)
def case_str():
_test('a', 'b', 'c')
Add support for variants, similar to kselftests_harness.h and
a lot of other frameworks. Variants can be added as decorator
to test functions:
@ksft_variants([(1, 2, 3), ('a', 'b', 'c')])
def case(x, y, z):
...
ksft_run() will auto-generate case names:
case.1_2_3
case.a_b_c
Because the names may not always be pretty (and to avoid forcing
classes to implement case-friendly __str__()) add a wrapper class
KsftNamedVariant which lets the user specify the name for the variant.
Note that ksft_run's args are still supported. ksft_run splices args
and variant params together.
Reviewed-by: Willem de Bruijn <willemb@google.com>
Reviewed-by: Petr Machata <petrm@nvidia.com>
Link: https://patch.msgid.link/20251120021024.2944527-4-kuba@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
34 lines
1.6 KiB
Python
34 lines
1.6 KiB
Python
# SPDX-License-Identifier: GPL-2.0
|
|
|
|
"""
|
|
Python selftest helpers for netdev.
|
|
"""
|
|
|
|
from .consts import KSRC
|
|
from .ksft import KsftFailEx, KsftSkipEx, KsftXfailEx, ksft_pr, ksft_eq, \
|
|
ksft_ne, ksft_true, ksft_not_none, ksft_in, ksft_not_in, ksft_is, \
|
|
ksft_ge, ksft_gt, ksft_lt, ksft_raises, ksft_busy_wait, \
|
|
ktap_result, ksft_disruptive, ksft_setup, ksft_run, ksft_exit, \
|
|
ksft_variants, KsftNamedVariant
|
|
from .netns import NetNS, NetNSEnter
|
|
from .nsim import NetdevSim, NetdevSimDev
|
|
from .utils import CmdExitFailure, fd_read_timeout, cmd, bkg, defer, \
|
|
bpftool, ip, ethtool, bpftrace, rand_port, wait_port_listen, wait_file
|
|
from .ynl import NlError, YnlFamily, EthtoolFamily, NetdevFamily, RtnlFamily, RtnlAddrFamily
|
|
from .ynl import NetshaperFamily, DevlinkFamily, PSPFamily
|
|
|
|
__all__ = ["KSRC",
|
|
"KsftFailEx", "KsftSkipEx", "KsftXfailEx", "ksft_pr", "ksft_eq",
|
|
"ksft_ne", "ksft_true", "ksft_not_none", "ksft_in", "ksft_not_in",
|
|
"ksft_is", "ksft_ge", "ksft_gt", "ksft_lt", "ksft_raises",
|
|
"ksft_busy_wait", "ktap_result", "ksft_disruptive", "ksft_setup",
|
|
"ksft_run", "ksft_exit", "ksft_variants", "KsftNamedVariant",
|
|
"NetNS", "NetNSEnter",
|
|
"CmdExitFailure", "fd_read_timeout", "cmd", "bkg", "defer",
|
|
"bpftool", "ip", "ethtool", "bpftrace", "rand_port",
|
|
"wait_port_listen", "wait_file",
|
|
"NetdevSim", "NetdevSimDev",
|
|
"NetshaperFamily", "DevlinkFamily", "PSPFamily", "NlError",
|
|
"YnlFamily", "EthtoolFamily", "NetdevFamily", "RtnlFamily",
|
|
"RtnlAddrFamily"]
|