[Devel] [PATCH vz10 3/4] selftests: net: py: report a refused environment as a skip
Konstantin Khorenko
khorenko at virtuozzo.com
Thu Sep 24 16:28:07 MSK 2026
Committed to branch-rh10-6.12.0-211.52.1.22.x.vz10-ovz, will be released in rh10-6.12.0-211.52.1.22.3.vz10
82d64c72dbd1
selftests: net: py: report a refused environment as a skip
A KsftSkipEx or KsftXfailEx raised outside ksft_run(), which is where an
environment check belongs, reaches the interpreter and is printed as a
traceback with exit status 1. A test that only wanted to say that this
machine cannot run it is then reported as a failure.
Install an excepthook that turns those two into the "1..0 # SKIP" or
XFAIL line the runner expects and exits with the skip status. It is set
when the library is imported, so every test using it gets this without
changes.
https://virtuozzo.atlassian.net/browse/VSTOR-139651
Feature: fix selftests
Signed-off-by: Eva Kurchatova <eva.kurchatova at virtuozzo.com>
Link: http://lore.virtuozzo.com/20260831225137.1642608-3-eva.kurchatova@virtuozzo.com
--
Best regards,
Konstantin Khorenko,
Virtuozzo Linux Kernel Team
On 9/1/26 00:50, Eva Kurchatova wrote:
> A KsftSkipEx or KsftXfailEx raised outside ksft_run(), which is where an
> environment check belongs, reaches the interpreter and is printed as a
> traceback with exit status 1. A test that only wanted to say that this
> machine cannot run it is then reported as a failure.
>
> Install an excepthook that turns those two into the "1..0 # SKIP" or
> XFAIL line the runner expects and exits with the skip status.
>
> https://virtuozzo.atlassian.net/browse/VSTOR-139651
> Feature: fix selftests
> Signed-off-by: Eva Kurchatova <eva.kurchatova at virtuozzo.com>
> ---
> tools/testing/selftests/net/lib/py/ksft.py | 27 ++++++++++++++++++++++
> 1 file changed, 27 insertions(+)
>
> diff --git a/tools/testing/selftests/net/lib/py/ksft.py b/tools/testing/selftests/net/lib/py/ksft.py
> index 61287c203b6e..332f8c105512 100644
> --- a/tools/testing/selftests/net/lib/py/ksft.py
> +++ b/tools/testing/selftests/net/lib/py/ksft.py
> @@ -10,6 +10,8 @@ import traceback
> from .consts import KSFT_MAIN_NAME
> from .utils import global_defer_queue
>
> +KSFT_SKIP = 4
> +
> KSFT_RESULT = None
> KSFT_RESULT_ALL = True
> KSFT_DISRUPTIVE = True
> @@ -278,3 +280,28 @@ def ksft_run(cases=None, globs=None, case_pfx=None, args=()):
> def ksft_exit():
> global KSFT_RESULT_ALL
> sys.exit(0 if KSFT_RESULT_ALL else 1)
> +
> +
> +def _ksft_no_tests_ran(comment):
> + print("TAP version 13")
> + print("1..0 # " + comment)
> + sys.exit(KSFT_SKIP)
> +
> +
> +def _ksft_excepthook(exc_type, exc_value, tb):
> + """
> + A test whose environment refuses it, e.g. one that needs a real
> + device and is handed netdevsim, raises while the environment is
> + being built, before there is a ksft_run() to catch anything. The
> + traceback that then leaves main() is reported as a failed test,
> + although the test never ran. Say what happened and exit the way
> + the kselftest runner expects for a test that did not run.
> + """
> + if issubclass(exc_type, KsftSkipEx):
> + _ksft_no_tests_ran("SKIP " + str(exc_value))
> + if issubclass(exc_type, KsftXfailEx):
> + _ksft_no_tests_ran("XFAIL " + str(exc_value))
> + sys.__excepthook__(exc_type, exc_value, tb)
> +
> +
> +sys.excepthook = _ksft_excepthook
More information about the Devel
mailing list