Skip to content

Commit f879306

Browse files
Stanislav Fomichevkuba-moo
authored andcommitted
selftests: net: ksft: support marking tests as disruptive
Add new @ksft_disruptive decorator to mark the tests that might be disruptive to the system. Depending on how well the previous test works in the CI we might want to disable disruptive tests by default and only let the developers run them manually. KSFT framework runs disruptive tests by default. DISRUPTIVE=False environment (or config file) can be used to disable these tests. ksft_setup should be called by the test cases that want to use new decorator (ksft_setup is only called via NetDrvEnv/NetDrvEpEnv for now). In the future we can add similar decorators to, for example, avoid running slow tests all the time. And/or have some option to run only 'fast' tests for some sort of smoke test scenario. $ DISRUPTIVE=False ./stats.py KTAP version 1 1..5 ok 1 stats.check_pause ok 2 stats.check_fec ok 3 stats.pkt_byte_sum ok 4 stats.qstat_by_ifindex ok 5 stats.check_down # SKIP marked as disruptive # Totals: pass:4 fail:0 xfail:0 xpass:0 skip:1 error:0 v3: - parse yes and properly treat non-zero nums as true (Petr) v2: - convert from cli argument to env variable (Jakub) Signed-off-by: Stanislav Fomichev <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent ab10009 commit f879306

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed

tools/testing/selftests/drivers/net/lib/py/env.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import time
55
from pathlib import Path
66
from lib.py import KsftSkipEx, KsftXfailEx
7+
from lib.py import ksft_setup
78
from lib.py import cmd, ethtool, ip
89
from lib.py import NetNS, NetdevSimDev
910
from .remote import Remote
@@ -14,7 +15,7 @@ def _load_env_file(src_path):
1415

1516
src_dir = Path(src_path).parent.resolve()
1617
if not (src_dir / "net.config").exists():
17-
return env
18+
return ksft_setup(env)
1819

1920
with open((src_dir / "net.config").as_posix(), 'r') as fp:
2021
for line in fp.readlines():
@@ -30,7 +31,7 @@ def _load_env_file(src_path):
3031
if len(pair) != 2:
3132
raise Exception("Can't parse configuration line:", full_file)
3233
env[pair[0]] = pair[1]
33-
return env
34+
return ksft_setup(env)
3435

3536

3637
class NetDrvEnv:

tools/testing/selftests/drivers/net/stats.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import errno
55
from lib.py import ksft_run, ksft_exit, ksft_pr
66
from lib.py import ksft_ge, ksft_eq, ksft_in, ksft_true, ksft_raises, KsftSkipEx, KsftXfailEx
7+
from lib.py import ksft_disruptive
78
from lib.py import EthtoolFamily, NetdevFamily, RtnlFamily, NlError
89
from lib.py import NetDrvEnv
910
from lib.py import ip, defer
@@ -135,6 +136,7 @@ def qstat_by_ifindex(cfg) -> None:
135136
ksft_eq(cm.exception.nl_msg.extack['bad-attr'], '.ifindex')
136137

137138

139+
@ksft_disruptive
138140
def check_down(cfg) -> None:
139141
try:
140142
qstat = netfam.qstats_get({"ifindex": cfg.ifindex}, dump=True)[0]

tools/testing/selftests/net/lib/py/ksft.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# SPDX-License-Identifier: GPL-2.0
22

33
import builtins
4+
import functools
45
import inspect
56
import sys
67
import time
@@ -10,6 +11,7 @@
1011

1112
KSFT_RESULT = None
1213
KSFT_RESULT_ALL = True
14+
KSFT_DISRUPTIVE = True
1315

1416

1517
class KsftFailEx(Exception):
@@ -127,6 +129,44 @@ def ksft_flush_defer():
127129
KSFT_RESULT = False
128130

129131

132+
def ksft_disruptive(func):
133+
"""
134+
Decorator that marks the test as disruptive (e.g. the test
135+
that can down the interface). Disruptive tests can be skipped
136+
by passing DISRUPTIVE=False environment variable.
137+
"""
138+
139+
@functools.wraps(func)
140+
def wrapper(*args, **kwargs):
141+
if not KSFT_DISRUPTIVE:
142+
raise KsftSkipEx(f"marked as disruptive")
143+
return func(*args, **kwargs)
144+
return wrapper
145+
146+
147+
def ksft_setup(env):
148+
"""
149+
Setup test framework global state from the environment.
150+
"""
151+
152+
def get_bool(env, name):
153+
value = env.get(name, "").lower()
154+
if value in ["yes", "true"]:
155+
return True
156+
if value in ["no", "false"]:
157+
return False
158+
try:
159+
return bool(int(value))
160+
except:
161+
raise Exception(f"failed to parse {name}")
162+
163+
if "DISRUPTIVE" in env:
164+
global KSFT_DISRUPTIVE
165+
KSFT_DISRUPTIVE = get_bool(env, "DISRUPTIVE")
166+
167+
return env
168+
169+
130170
def ksft_run(cases=None, globs=None, case_pfx=None, args=()):
131171
cases = cases or []
132172

0 commit comments

Comments
 (0)