[Devel] [PATCH vz10 3/4] selftests: net: py: report a refused environment as a skip
Eva Kurchatova
eva.kurchatova at virtuozzo.com
Tue Sep 1 01:50:53 MSK 2026
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
--
2.55.0
More information about the Devel
mailing list