* [Devel] [PATCH vz10 1/4] ms/selftests: net: Add python context manager for netns entering
@ 2026-08-31 22:50 Eva Kurchatova
2026-08-31 22:50 ` [Devel] [PATCH vz10 2/4] selftests: net: py: add the missing ksft_is() and ksft_not_in() helpers Eva Kurchatova
` (3 more replies)
0 siblings, 4 replies; 9+ messages in thread
From: Eva Kurchatova @ 2026-08-31 22:50 UTC (permalink / raw)
To: khorenko; +Cc: devel
From: Xiao Liang <shaw.leon@gmail.com>
Change netns of current thread and switch back on context exit.
For example:
with NetNSEnter("ns1"):
ip("link add dummy0 type dummy")
The command be executed in netns "ns1".
Signed-off-by: Xiao Liang <shaw.leon@gmail.com>
Link: https://patch.msgid.link/20250219125039.18024-13-shaw.leon@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
(cherry picked from commit 030329416232ff9f2e3e4bb065b29e6c9a7d5050)
https://virtuozzo.atlassian.net/browse/VSTOR-139651
Feature: fix selftests
Signed-off-by: Eva Kurchatova <eva.kurchatova@virtuozzo.com>
---
tools/testing/selftests/net/lib/py/__init__.py | 2 +-
tools/testing/selftests/net/lib/py/netns.py | 18 ++++++++++++++++++
2 files changed, 19 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/net/lib/py/__init__.py b/tools/testing/selftests/net/lib/py/__init__.py
index bffe01d5ee2d..02be28dcc089 100644
--- a/tools/testing/selftests/net/lib/py/__init__.py
+++ b/tools/testing/selftests/net/lib/py/__init__.py
@@ -2,7 +2,7 @@
from .consts import KSRC
from .ksft import *
-from .netns import NetNS
+from .netns import NetNS, NetNSEnter
from .nsim import *
from .utils import *
from .ynl import NlError, YnlFamily, EthtoolFamily, NetdevFamily, RtnlFamily, RtnlAddrFamily
diff --git a/tools/testing/selftests/net/lib/py/netns.py b/tools/testing/selftests/net/lib/py/netns.py
index ecff85f9074f..8e9317044eef 100644
--- a/tools/testing/selftests/net/lib/py/netns.py
+++ b/tools/testing/selftests/net/lib/py/netns.py
@@ -1,9 +1,12 @@
# SPDX-License-Identifier: GPL-2.0
from .utils import ip
+import ctypes
import random
import string
+libc = ctypes.cdll.LoadLibrary('libc.so.6')
+
class NetNS:
def __init__(self, name=None):
@@ -29,3 +32,18 @@ class NetNS:
def __repr__(self):
return f"NetNS({self.name})"
+
+
+class NetNSEnter:
+ def __init__(self, ns_name):
+ self.ns_path = f"/run/netns/{ns_name}"
+
+ def __enter__(self):
+ self.saved = open("/proc/thread-self/ns/net")
+ with open(self.ns_path) as ns_file:
+ libc.setns(ns_file.fileno(), 0)
+ return self
+
+ def __exit__(self, exc_type, exc_value, traceback):
+ libc.setns(self.saved.fileno(), 0)
+ self.saved.close()
--
2.55.0
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Devel] [PATCH vz10 2/4] selftests: net: py: add the missing ksft_is() and ksft_not_in() helpers
2026-08-31 22:50 [Devel] [PATCH vz10 1/4] ms/selftests: net: Add python context manager for netns entering Eva Kurchatova
@ 2026-08-31 22:50 ` Eva Kurchatova
2026-09-24 13:27 ` Konstantin Khorenko
2026-08-31 22:50 ` [Devel] [PATCH vz10 3/4] selftests: net: py: report a refused environment as a skip Eva Kurchatova
` (2 subsequent siblings)
3 siblings, 1 reply; 9+ messages in thread
From: Eva Kurchatova @ 2026-08-31 22:50 UTC (permalink / raw)
To: khorenko; +Cc: devel
rss_api.py and rss_flow_label.py call ksft_is() and ksft_not_in(), and
net/lib/py/__init__.py exports both, but ksft.py never defined them, so
importing the library fails and every test of the group goes down with
it:
ImportError: cannot import name 'ksft_is' from 'net.lib.py'
The tests and the export came in with the RHEL10 import, commit
9f055df11343 ("rh10: import RHEL10 kernel-6.12.0-211.16.1.el10"), the
helpers did not. Take them from the commits that added them upstream,
commit 31eae6d99587 ("selftests: drv-net: test drivers sleeping in
ndo_get_stats64") for ksft_is() and commit 4fde8398462f ("selftests:
drv-net: improve the use of ksft helpers in XSK queue test") for
ksft_not_in(). The tests those commits add are left out.
https://virtuozzo.atlassian.net/browse/VSTOR-139651
Feature: fix vz selftests
Signed-off-by: Eva Kurchatova <eva.kurchatova@virtuozzo.com>
---
tools/testing/selftests/net/lib/py/ksft.py | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/tools/testing/selftests/net/lib/py/ksft.py b/tools/testing/selftests/net/lib/py/ksft.py
index 7b50111340bb..61287c203b6e 100644
--- a/tools/testing/selftests/net/lib/py/ksft.py
+++ b/tools/testing/selftests/net/lib/py/ksft.py
@@ -76,6 +76,16 @@ def ksft_in(a, b, comment=""):
_fail("Check failed", a, "not in", b, comment)
+def ksft_not_in(a, b, comment=""):
+ if a in b:
+ _fail("Check failed", a, "in", b, comment)
+
+
+def ksft_is(a, b, comment=""):
+ if a is not b:
+ _fail("Check failed", a, "is not", b, comment)
+
+
def ksft_ge(a, b, comment=""):
if a < b:
_fail("Check failed", a, "<", b, comment)
--
2.55.0
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Devel] [PATCH vz10 3/4] selftests: net: py: report a refused environment as a skip
2026-08-31 22:50 [Devel] [PATCH vz10 1/4] ms/selftests: net: Add python context manager for netns entering Eva Kurchatova
2026-08-31 22:50 ` [Devel] [PATCH vz10 2/4] selftests: net: py: add the missing ksft_is() and ksft_not_in() helpers Eva Kurchatova
@ 2026-08-31 22:50 ` Eva Kurchatova
2026-09-24 13:28 ` Konstantin Khorenko
2026-08-31 22:50 ` [Devel] [PATCH vz10 4/4] selftests: drv-net-hw: skip the tests that need a real interface Eva Kurchatova
2026-09-24 13:27 ` [Devel] [PATCH vz10 1/4] ms/selftests: net: Add python context manager for netns entering Konstantin Khorenko
3 siblings, 1 reply; 9+ messages in thread
From: Eva Kurchatova @ 2026-08-31 22:50 UTC (permalink / raw)
To: khorenko; +Cc: devel
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@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
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Devel] [PATCH vz10 4/4] selftests: drv-net-hw: skip the tests that need a real interface
2026-08-31 22:50 [Devel] [PATCH vz10 1/4] ms/selftests: net: Add python context manager for netns entering Eva Kurchatova
2026-08-31 22:50 ` [Devel] [PATCH vz10 2/4] selftests: net: py: add the missing ksft_is() and ksft_not_in() helpers Eva Kurchatova
2026-08-31 22:50 ` [Devel] [PATCH vz10 3/4] selftests: net: py: report a refused environment as a skip Eva Kurchatova
@ 2026-08-31 22:50 ` Eva Kurchatova
2026-09-24 13:23 ` Konstantin Khorenko
2026-09-24 13:29 ` Konstantin Khorenko
2026-09-24 13:27 ` [Devel] [PATCH vz10 1/4] ms/selftests: net: Add python context manager for netns entering Konstantin Khorenko
3 siblings, 2 replies; 9+ messages in thread
From: Eva Kurchatova @ 2026-08-31 22:50 UTC (permalink / raw)
To: khorenko; +Cc: devel
ethtool, ethtool_extended_state, hw_stats_l3 and hw_stats_l3_gre need a
device that can set link speed and autonegotiation, report an extended
link state, or offload L3 statistics. Where none is configured, lib.sh
creates a veth pair instead, which supports none of that, so every case
fails on something the kernel correctly refuses.
Upstream answers this by keeping such tests in drivers/net/hw and not
running them on veth at all: commit 0c499a351777 ("selftests:
forwarding: Ditch skip_on_veth()") removed the equivalent check once the
directory was split out. This guard is therefore not for upstream, it
only stops a run that substitutes veth pairs from reporting failures.
Skip before sourcing lib.sh, because lib.sh makes the veth pair as it is
sourced. Exiting afterwards leaves the devices behind - vrf_cleanup()
removes them and a test that skips never gets there - and a later test
that adds a veth by one of those names then cannot. hw_stats_l3_gre
asks for six interfaces, so one run left veth0 to veth5 in the initial
namespace and the netfilter suite failed on it.
https://virtuozzo.atlassian.net/browse/VSTOR-139651
Feature: fix vz selftests
Signed-off-by: Eva Kurchatova <eva.kurchatova@virtuozzo.com>
---
.../testing/selftests/drivers/net/hw/ethtool.sh | 16 ++++++++++++++++
.../drivers/net/hw/ethtool_extended_state.sh | 16 ++++++++++++++++
.../selftests/drivers/net/hw/hw_stats_l3.sh | 16 ++++++++++++++++
.../selftests/drivers/net/hw/hw_stats_l3_gre.sh | 16 ++++++++++++++++
4 files changed, 64 insertions(+)
diff --git a/tools/testing/selftests/drivers/net/hw/ethtool.sh b/tools/testing/selftests/drivers/net/hw/ethtool.sh
index fa6953de6b6d..b1744758627c 100755
--- a/tools/testing/selftests/drivers/net/hw/ethtool.sh
+++ b/tools/testing/selftests/drivers/net/hw/ethtool.sh
@@ -11,6 +11,22 @@ ALL_TESTS="
"
NUM_NETIFS=2
lib_dir=$(dirname "$0")
+
+# The test needs a device capable of setting link speed and
+# autonegotiation. Where no real interfaces are configured, lib.sh makes
+# a veth pair instead, which cannot, and every case then fails on
+# something the kernel correctly refuses. Check this before sourcing
+# lib.sh: it creates that pair as it is sourced, so exiting afterwards
+# leaves the devices behind, and the next test that wants one of those
+# names cannot create it.
+
+: "${NETIF_CREATE:=yes}"
+: "${NETIF_TYPE:=veth}"
+if [[ "$NETIF_CREATE" = yes && "$NETIF_TYPE" = veth ]]; then
+ echo "SKIP: needs a real interface, set NETIFS in forwarding.config"
+ exit 4 # ksft_skip, lib.sh is not sourced yet
+fi
+
source "$lib_dir"/../../../net/forwarding/lib.sh
source ethtool_lib.sh
diff --git a/tools/testing/selftests/drivers/net/hw/ethtool_extended_state.sh b/tools/testing/selftests/drivers/net/hw/ethtool_extended_state.sh
index a7584448416e..c6c96117b1f1 100755
--- a/tools/testing/selftests/drivers/net/hw/ethtool_extended_state.sh
+++ b/tools/testing/selftests/drivers/net/hw/ethtool_extended_state.sh
@@ -9,6 +9,22 @@ ALL_TESTS="
NUM_NETIFS=2
lib_dir=$(dirname "$0")
+
+# The test needs a device capable of reporting an extended link state.
+# Where no real interfaces are configured, lib.sh makes a veth pair
+# instead, which cannot, and every case then fails on something the
+# kernel correctly refuses. Check this before sourcing lib.sh: it
+# creates that pair as it is sourced, so exiting afterwards leaves the
+# devices behind, and the next test that wants one of those names cannot
+# create it.
+
+: "${NETIF_CREATE:=yes}"
+: "${NETIF_TYPE:=veth}"
+if [[ "$NETIF_CREATE" = yes && "$NETIF_TYPE" = veth ]]; then
+ echo "SKIP: needs a real interface, set NETIFS in forwarding.config"
+ exit 4 # ksft_skip, lib.sh is not sourced yet
+fi
+
source "$lib_dir"/../../../net/forwarding/lib.sh
source ethtool_lib.sh
diff --git a/tools/testing/selftests/drivers/net/hw/hw_stats_l3.sh b/tools/testing/selftests/drivers/net/hw/hw_stats_l3.sh
index 67fafefc80be..1776a4954601 100755
--- a/tools/testing/selftests/drivers/net/hw/hw_stats_l3.sh
+++ b/tools/testing/selftests/drivers/net/hw/hw_stats_l3.sh
@@ -49,6 +49,22 @@ ALL_TESTS="
"
NUM_NETIFS=4
lib_dir=$(dirname "$0")
+
+# The test needs a device capable of offloading L3 statistics. Where no
+# real interfaces are configured, lib.sh makes a veth pair instead,
+# which cannot, and every case then fails on something the kernel
+# correctly refuses. Check this before sourcing lib.sh: it creates that
+# pair as it is sourced, so exiting afterwards leaves the devices
+# behind, and the next test that wants one of those names cannot create
+# it.
+
+: "${NETIF_CREATE:=yes}"
+: "${NETIF_TYPE:=veth}"
+if [[ "$NETIF_CREATE" = yes && "$NETIF_TYPE" = veth ]]; then
+ echo "SKIP: needs a real interface, set NETIFS in forwarding.config"
+ exit 4 # ksft_skip, lib.sh is not sourced yet
+fi
+
source "$lib_dir"/../../../net/forwarding/lib.sh
source "$lib_dir"/../../../net/forwarding/tc_common.sh
diff --git a/tools/testing/selftests/drivers/net/hw/hw_stats_l3_gre.sh b/tools/testing/selftests/drivers/net/hw/hw_stats_l3_gre.sh
index a94d92e1abce..2cbc2682f7b7 100755
--- a/tools/testing/selftests/drivers/net/hw/hw_stats_l3_gre.sh
+++ b/tools/testing/selftests/drivers/net/hw/hw_stats_l3_gre.sh
@@ -13,6 +13,22 @@ ALL_TESTS="
"
NUM_NETIFS=6
lib_dir=$(dirname "$0")
+
+# The test needs a device capable of offloading L3 statistics. Where no
+# real interfaces are configured, lib.sh makes a veth pair instead,
+# which cannot, and every case then fails on something the kernel
+# correctly refuses. Check this before sourcing lib.sh: it creates that
+# pair as it is sourced, so exiting afterwards leaves the devices
+# behind, and the next test that wants one of those names cannot create
+# it.
+
+: "${NETIF_CREATE:=yes}"
+: "${NETIF_TYPE:=veth}"
+if [[ "$NETIF_CREATE" = yes && "$NETIF_TYPE" = veth ]]; then
+ echo "SKIP: needs a real interface, set NETIFS in forwarding.config"
+ exit 4 # ksft_skip, lib.sh is not sourced yet
+fi
+
source "$lib_dir"/../../../net/forwarding/lib.sh
source "$lib_dir"/../../../net/forwarding/ipip_lib.sh
source "$lib_dir"/../../../net/forwarding/tc_common.sh
--
2.55.0
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Devel] [PATCH vz10 4/4] selftests: drv-net-hw: skip the tests that need a real interface
2026-08-31 22:50 ` [Devel] [PATCH vz10 4/4] selftests: drv-net-hw: skip the tests that need a real interface Eva Kurchatova
@ 2026-09-24 13:23 ` Konstantin Khorenko
2026-09-24 13:29 ` Konstantin Khorenko
1 sibling, 0 replies; 9+ messages in thread
From: Konstantin Khorenko @ 2026-09-24 13:23 UTC (permalink / raw)
To: Eva Kurchatova; +Cc: devel
> ethtool, ethtool_extended_state, hw_stats_l3 and hw_stats_l3_gre need a
> device that can set link speed and autonegotiation, report an extended
> link state, or offload L3 statistics. Where none is configured, lib.sh
> creates a veth pair instead, which supports none of that, so every case
> fails on something the kernel correctly refuses.
>
> Upstream answers this by keeping such tests in drivers/net/hw and not
> running them on veth at all: commit 0c499a351777 ("selftests:
> forwarding: Ditch skip_on_veth()") removed the equivalent check once the
> directory was split out. This guard is therefore not for upstream, it
> only stops a run that substitutes veth pairs from reporting failures.
>
> Skip before sourcing lib.sh, because lib.sh makes the veth pair as it is
> sourced. Exiting afterwards leaves the devices behind - vrf_cleanup()
> removes them and a test that skips never gets there - and a later test
> that adds a veth by one of those names then cannot. hw_stats_l3_gre
> asks for six interfaces, so one run left veth0 to veth5 in the initial
> namespace and the netfilter suite failed on it.
>
> https://virtuozzo.atlassian.net/browse/VSTOR-139651
> Feature: fix selftests
> Signed-off-by: Eva Kurchatova <eva.kurchatova@virtuozzo.com>
>
> diff --git a/tools/testing/selftests/drivers/net/hw/ethtool.sh b/tools/testing/selftests/drivers/net/hw/ethtool.sh
> index fa6953de6b6dd..b1744758627c2 100755
> --- a/tools/testing/selftests/drivers/net/hw/ethtool.sh
> +++ b/tools/testing/selftests/drivers/net/hw/ethtool.sh
> @@ -11,6 +11,22 @@ ALL_TESTS="
> "
> NUM_NETIFS=2
> lib_dir=$(dirname "$0")
> +
> +# The test needs a device capable of setting link speed and
> +# autonegotiation. Where no real interfaces are configured, lib.sh makes
> +# a veth pair instead, which cannot, and every case then fails on
> +# something the kernel correctly refuses. Check this before sourcing
> +# lib.sh: it creates that pair as it is sourced, so exiting afterwards
> +# leaves the devices behind, and the next test that wants one of those
> +# names cannot create it.
This is the commit message pasted into the test, four times. The
rationale belongs in the commit message only. In the code one line is
enough, something like:
> +
> +: "${NETIF_CREATE:=yes}"
> +: "${NETIF_TYPE:=veth}"
> +if [[ "$NETIF_CREATE" = yes && "$NETIF_TYPE" = veth ]]; then
> + echo "SKIP: needs a real interface, set NETIFS in forwarding.config"
> + exit 4 # ksft_skip, lib.sh is not sourced yet
> +fi
> +
> source "$lib_dir"/../../../net/forwarding/lib.sh
> source ethtool_lib.sh
>
> diff --git a/tools/testing/selftests/drivers/net/hw/ethtool_extended_state.sh b/tools/testing/selftests/drivers/net/hw/ethtool_extended_state.sh
> index a7584448416ea..c6c96117b1f12 100755
> --- a/tools/testing/selftests/drivers/net/hw/ethtool_extended_state.sh
> +++ b/tools/testing/selftests/drivers/net/hw/ethtool_extended_state.sh
> @@ -9,6 +9,22 @@ ALL_TESTS="
>
> NUM_NETIFS=2
> lib_dir=$(dirname "$0")
> +
> +# The test needs a device capable of reporting an extended link state.
> +# Where no real interfaces are configured, lib.sh makes a veth pair
> +# instead, which cannot, and every case then fails on something the
> +# kernel correctly refuses. Check this before sourcing lib.sh: it
> +# creates that pair as it is sourced, so exiting afterwards leaves the
> +# devices behind, and the next test that wants one of those names cannot
> +# create it.
> +
> +: "${NETIF_CREATE:=yes}"
> +: "${NETIF_TYPE:=veth}"
> +if [[ "$NETIF_CREATE" = yes && "$NETIF_TYPE" = veth ]]; then
> + echo "SKIP: needs a real interface, set NETIFS in forwarding.config"
> + exit 4 # ksft_skip, lib.sh is not sourced yet
> +fi
> +
> source "$lib_dir"/../../../net/forwarding/lib.sh
> source ethtool_lib.sh
>
> diff --git a/tools/testing/selftests/drivers/net/hw/hw_stats_l3.sh b/tools/testing/selftests/drivers/net/hw/hw_stats_l3.sh
> index 67fafefc80bea..1776a4954601b 100755
> --- a/tools/testing/selftests/drivers/net/hw/hw_stats_l3.sh
> +++ b/tools/testing/selftests/drivers/net/hw/hw_stats_l3.sh
> @@ -49,6 +49,22 @@ ALL_TESTS="
> "
> NUM_NETIFS=4
> lib_dir=$(dirname "$0")
> +
> +# The test needs a device capable of offloading L3 statistics. Where no
> +# real interfaces are configured, lib.sh makes a veth pair instead,
> +# which cannot, and every case then fails on something the kernel
> +# correctly refuses. Check this before sourcing lib.sh: it creates that
> +# pair as it is sourced, so exiting afterwards leaves the devices
> +# behind, and the next test that wants one of those names cannot create
> +# it.
> +
> +: "${NETIF_CREATE:=yes}"
> +: "${NETIF_TYPE:=veth}"
> +if [[ "$NETIF_CREATE" = yes && "$NETIF_TYPE" = veth ]]; then
> + echo "SKIP: needs a real interface, set NETIFS in forwarding.config"
> + exit 4 # ksft_skip, lib.sh is not sourced yet
> +fi
> +
The check does not see forwarding.config. lib.sh sets these defaults
(lib.sh:54-55), then sources net/forwarding/forwarding.config
(lib.sh:126), and only then creates the interfaces (lib.sh:433). Here
lib.sh has not been sourced yet, so the config file has not been read
and the two variables fall back to yes/veth unless they are exported in
the environment.
So a user who does what the SKIP line tells them to, puts real NETIFS
into forwarding.config and sets NETIF_CREATE=no there, still gets the
skip: on real hardware all four tests never run. Only an exported
NETIF_CREATE=no would get past it, and forwarding.config is not
sourced into the environment anywhere.
Read the same file lib.sh reads before deciding:
forwarding_dir=$lib_dir/../../../net/forwarding
[[ -f $forwarding_dir/forwarding.config ]] && \
source "$forwarding_dir/forwarding.config"
: "${NETIF_CREATE:=yes}"
: "${NETIF_TYPE:=veth}"
Since the same block goes into four files, put it into a small helper
next to ethtool_lib.sh and source that before lib.sh, instead of
copying it.
> source "$lib_dir"/../../../net/forwarding/lib.sh
> source "$lib_dir"/../../../net/forwarding/tc_common.sh
>
Two more notes on the set of tests:
ethtool_rmon.sh in the same directory reads rmon histogram counters via
"ethtool -S --groups rmon" and has no skip of its own, so on veth it
fails the same way. If it fails in your runs too, it belongs in this
patch. ethtool_mm.sh and loopback.sh already skip by themselves.
The reference to 0c499a351777 is correct and the "why not upstream"
paragraph is useful, keep it.
--
Konstantin Khorenko <khorenko@virtuozzo.com>
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Devel] [PATCH vz10 1/4] ms/selftests: net: Add python context manager for netns entering
2026-08-31 22:50 [Devel] [PATCH vz10 1/4] ms/selftests: net: Add python context manager for netns entering Eva Kurchatova
` (2 preceding siblings ...)
2026-08-31 22:50 ` [Devel] [PATCH vz10 4/4] selftests: drv-net-hw: skip the tests that need a real interface Eva Kurchatova
@ 2026-09-24 13:27 ` Konstantin Khorenko
3 siblings, 0 replies; 9+ messages in thread
From: Konstantin Khorenko @ 2026-09-24 13:27 UTC (permalink / raw)
To: Eva Kurchatova; +Cc: devel
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
ae029f6f2312
ms/selftests: net: Add python context manager for netns entering
Change netns of current thread and switch back on context exit.
For example:
with NetNSEnter("ns1"):
ip("link add dummy0 type dummy")
The command be executed in netns "ns1".
Signed-off-by: Xiao Liang <shaw.leon@gmail.com>
Link: https://patch.msgid.link/20250219125039.18024-13-shaw.leon@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
(cherry picked from commit 030329416232ff9f2e3e4bb065b29e6c9a7d5050)
https://virtuozzo.atlassian.net/browse/VSTOR-139651
Feature: fix selftests
Signed-off-by: Eva Kurchatova <eva.kurchatova@virtuozzo.com>
Link: http://lore.virtuozzo.com/20260831225137.1642608-1-eva.kurchatova@virtuozzo.com
--
Best regards,
Konstantin Khorenko,
Virtuozzo Linux Kernel Team
On 9/1/26 00:50, Eva Kurchatova wrote:
> From: Xiao Liang <shaw.leon@gmail.com>
>
> Change netns of current thread and switch back on context exit.
> For example:
>
> with NetNSEnter("ns1"):
> ip("link add dummy0 type dummy")
>
> The command be executed in netns "ns1".
>
> Signed-off-by: Xiao Liang <shaw.leon@gmail.com>
> Link: https://patch.msgid.link/20250219125039.18024-13-shaw.leon@gmail.com
> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
> (cherry picked from commit 030329416232ff9f2e3e4bb065b29e6c9a7d5050)
>
> https://virtuozzo.atlassian.net/browse/VSTOR-139651
> Feature: fix selftests
> Signed-off-by: Eva Kurchatova <eva.kurchatova@virtuozzo.com>
> ---
> tools/testing/selftests/net/lib/py/__init__.py | 2 +-
> tools/testing/selftests/net/lib/py/netns.py | 18 ++++++++++++++++++
> 2 files changed, 19 insertions(+), 1 deletion(-)
>
> diff --git a/tools/testing/selftests/net/lib/py/__init__.py b/tools/testing/selftests/net/lib/py/__init__.py
> index bffe01d5ee2d..02be28dcc089 100644
> --- a/tools/testing/selftests/net/lib/py/__init__.py
> +++ b/tools/testing/selftests/net/lib/py/__init__.py
> @@ -2,7 +2,7 @@
>
> from .consts import KSRC
> from .ksft import *
> -from .netns import NetNS
> +from .netns import NetNS, NetNSEnter
> from .nsim import *
> from .utils import *
> from .ynl import NlError, YnlFamily, EthtoolFamily, NetdevFamily, RtnlFamily, RtnlAddrFamily
> diff --git a/tools/testing/selftests/net/lib/py/netns.py b/tools/testing/selftests/net/lib/py/netns.py
> index ecff85f9074f..8e9317044eef 100644
> --- a/tools/testing/selftests/net/lib/py/netns.py
> +++ b/tools/testing/selftests/net/lib/py/netns.py
> @@ -1,9 +1,12 @@
> # SPDX-License-Identifier: GPL-2.0
>
> from .utils import ip
> +import ctypes
> import random
> import string
>
> +libc = ctypes.cdll.LoadLibrary('libc.so.6')
> +
>
> class NetNS:
> def __init__(self, name=None):
> @@ -29,3 +32,18 @@ class NetNS:
>
> def __repr__(self):
> return f"NetNS({self.name})"
> +
> +
> +class NetNSEnter:
> + def __init__(self, ns_name):
> + self.ns_path = f"/run/netns/{ns_name}"
> +
> + def __enter__(self):
> + self.saved = open("/proc/thread-self/ns/net")
> + with open(self.ns_path) as ns_file:
> + libc.setns(ns_file.fileno(), 0)
> + return self
> +
> + def __exit__(self, exc_type, exc_value, traceback):
> + libc.setns(self.saved.fileno(), 0)
> + self.saved.close()
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Devel] [PATCH vz10 2/4] selftests: net: py: add the missing ksft_is() and ksft_not_in() helpers
2026-08-31 22:50 ` [Devel] [PATCH vz10 2/4] selftests: net: py: add the missing ksft_is() and ksft_not_in() helpers Eva Kurchatova
@ 2026-09-24 13:27 ` Konstantin Khorenko
0 siblings, 0 replies; 9+ messages in thread
From: Konstantin Khorenko @ 2026-09-24 13:27 UTC (permalink / raw)
To: Eva Kurchatova; +Cc: devel
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
5cf658d7912e
selftests: net: py: add the missing ksft_is() and ksft_not_in() helpers
rss_api.py and rss_flow_label.py call ksft_is() and ksft_not_in(), and
drivers/net/lib/py/__init__.py and drivers/net/hw/lib/py/__init__.py
import both by name from net.lib.py, but ksft.py never defined them, so
importing the library fails and every test of the group goes down with
it:
ImportError: cannot import name 'ksft_is' from 'net.lib.py'
The tests and the imports came in with the RHEL10 import, commit
9f055df11343 ("rh10: import RHEL10 kernel-6.12.0-211.16.1.el10"), the
helpers did not. Take them from the commits that added them upstream,
commit 31eae6d99587 ("selftests: drv-net: test drivers sleeping in
ndo_get_stats64") for ksft_is() and commit 4fde8398462f ("selftests:
drv-net: improve the use of ksft helpers in XSK queue test") for
ksft_not_in(). The tests those commits add are left out.
https://virtuozzo.atlassian.net/browse/VSTOR-139651
Feature: fix selftests
Signed-off-by: Eva Kurchatova <eva.kurchatova@virtuozzo.com>
Link: http://lore.virtuozzo.com/20260831225137.1642608-2-eva.kurchatova@virtuozzo.com
--
Best regards,
Konstantin Khorenko,
Virtuozzo Linux Kernel Team
On 9/1/26 00:50, Eva Kurchatova wrote:
> rss_api.py and rss_flow_label.py call ksft_is() and ksft_not_in(), and
> net/lib/py/__init__.py exports both, but ksft.py never defined them, so
> importing the library fails and every test of the group goes down with
> it:
>
> ImportError: cannot import name 'ksft_is' from 'net.lib.py'
>
> The tests and the export came in with the RHEL10 import, commit
> 9f055df11343 ("rh10: import RHEL10 kernel-6.12.0-211.16.1.el10"), the
> helpers did not. Take them from the commits that added them upstream,
> commit 31eae6d99587 ("selftests: drv-net: test drivers sleeping in
> ndo_get_stats64") for ksft_is() and commit 4fde8398462f ("selftests:
> drv-net: improve the use of ksft helpers in XSK queue test") for
> ksft_not_in(). The tests those commits add are left out.
>
> https://virtuozzo.atlassian.net/browse/VSTOR-139651
> Feature: fix vz selftests
> Signed-off-by: Eva Kurchatova <eva.kurchatova@virtuozzo.com>
> ---
> tools/testing/selftests/net/lib/py/ksft.py | 10 ++++++++++
> 1 file changed, 10 insertions(+)
>
> diff --git a/tools/testing/selftests/net/lib/py/ksft.py b/tools/testing/selftests/net/lib/py/ksft.py
> index 7b50111340bb..61287c203b6e 100644
> --- a/tools/testing/selftests/net/lib/py/ksft.py
> +++ b/tools/testing/selftests/net/lib/py/ksft.py
> @@ -76,6 +76,16 @@ def ksft_in(a, b, comment=""):
> _fail("Check failed", a, "not in", b, comment)
>
>
> +def ksft_not_in(a, b, comment=""):
> + if a in b:
> + _fail("Check failed", a, "in", b, comment)
> +
> +
> +def ksft_is(a, b, comment=""):
> + if a is not b:
> + _fail("Check failed", a, "is not", b, comment)
> +
> +
> def ksft_ge(a, b, comment=""):
> if a < b:
> _fail("Check failed", a, "<", b, comment)
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Devel] [PATCH vz10 3/4] selftests: net: py: report a refused environment as a skip
2026-08-31 22:50 ` [Devel] [PATCH vz10 3/4] selftests: net: py: report a refused environment as a skip Eva Kurchatova
@ 2026-09-24 13:28 ` Konstantin Khorenko
0 siblings, 0 replies; 9+ messages in thread
From: Konstantin Khorenko @ 2026-09-24 13:28 UTC (permalink / raw)
To: Eva Kurchatova; +Cc: devel
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@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@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
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Devel] [PATCH vz10 4/4] selftests: drv-net-hw: skip the tests that need a real interface
2026-08-31 22:50 ` [Devel] [PATCH vz10 4/4] selftests: drv-net-hw: skip the tests that need a real interface Eva Kurchatova
2026-09-24 13:23 ` Konstantin Khorenko
@ 2026-09-24 13:29 ` Konstantin Khorenko
1 sibling, 0 replies; 9+ messages in thread
From: Konstantin Khorenko @ 2026-09-24 13:29 UTC (permalink / raw)
To: Eva Kurchatova; +Cc: devel
i have NOT applied it, please rework.
--
Best regards,
Konstantin Khorenko,
Virtuozzo Linux Kernel Team
On 9/1/26 00:50, Eva Kurchatova wrote:
> ethtool, ethtool_extended_state, hw_stats_l3 and hw_stats_l3_gre need a
> device that can set link speed and autonegotiation, report an extended
> link state, or offload L3 statistics. Where none is configured, lib.sh
> creates a veth pair instead, which supports none of that, so every case
> fails on something the kernel correctly refuses.
>
> Upstream answers this by keeping such tests in drivers/net/hw and not
> running them on veth at all: commit 0c499a351777 ("selftests:
> forwarding: Ditch skip_on_veth()") removed the equivalent check once the
> directory was split out. This guard is therefore not for upstream, it
> only stops a run that substitutes veth pairs from reporting failures.
>
> Skip before sourcing lib.sh, because lib.sh makes the veth pair as it is
> sourced. Exiting afterwards leaves the devices behind - vrf_cleanup()
> removes them and a test that skips never gets there - and a later test
> that adds a veth by one of those names then cannot. hw_stats_l3_gre
> asks for six interfaces, so one run left veth0 to veth5 in the initial
> namespace and the netfilter suite failed on it.
>
> https://virtuozzo.atlassian.net/browse/VSTOR-139651
> Feature: fix vz selftests
> Signed-off-by: Eva Kurchatova <eva.kurchatova@virtuozzo.com>
> ---
> .../testing/selftests/drivers/net/hw/ethtool.sh | 16 ++++++++++++++++
> .../drivers/net/hw/ethtool_extended_state.sh | 16 ++++++++++++++++
> .../selftests/drivers/net/hw/hw_stats_l3.sh | 16 ++++++++++++++++
> .../selftests/drivers/net/hw/hw_stats_l3_gre.sh | 16 ++++++++++++++++
> 4 files changed, 64 insertions(+)
>
> diff --git a/tools/testing/selftests/drivers/net/hw/ethtool.sh b/tools/testing/selftests/drivers/net/hw/ethtool.sh
> index fa6953de6b6d..b1744758627c 100755
> --- a/tools/testing/selftests/drivers/net/hw/ethtool.sh
> +++ b/tools/testing/selftests/drivers/net/hw/ethtool.sh
> @@ -11,6 +11,22 @@ ALL_TESTS="
> "
> NUM_NETIFS=2
> lib_dir=$(dirname "$0")
> +
> +# The test needs a device capable of setting link speed and
> +# autonegotiation. Where no real interfaces are configured, lib.sh makes
> +# a veth pair instead, which cannot, and every case then fails on
> +# something the kernel correctly refuses. Check this before sourcing
> +# lib.sh: it creates that pair as it is sourced, so exiting afterwards
> +# leaves the devices behind, and the next test that wants one of those
> +# names cannot create it.
> +
> +: "${NETIF_CREATE:=yes}"
> +: "${NETIF_TYPE:=veth}"
> +if [[ "$NETIF_CREATE" = yes && "$NETIF_TYPE" = veth ]]; then
> + echo "SKIP: needs a real interface, set NETIFS in forwarding.config"
> + exit 4 # ksft_skip, lib.sh is not sourced yet
> +fi
> +
> source "$lib_dir"/../../../net/forwarding/lib.sh
> source ethtool_lib.sh
>
> diff --git a/tools/testing/selftests/drivers/net/hw/ethtool_extended_state.sh b/tools/testing/selftests/drivers/net/hw/ethtool_extended_state.sh
> index a7584448416e..c6c96117b1f1 100755
> --- a/tools/testing/selftests/drivers/net/hw/ethtool_extended_state.sh
> +++ b/tools/testing/selftests/drivers/net/hw/ethtool_extended_state.sh
> @@ -9,6 +9,22 @@ ALL_TESTS="
>
> NUM_NETIFS=2
> lib_dir=$(dirname "$0")
> +
> +# The test needs a device capable of reporting an extended link state.
> +# Where no real interfaces are configured, lib.sh makes a veth pair
> +# instead, which cannot, and every case then fails on something the
> +# kernel correctly refuses. Check this before sourcing lib.sh: it
> +# creates that pair as it is sourced, so exiting afterwards leaves the
> +# devices behind, and the next test that wants one of those names cannot
> +# create it.
> +
> +: "${NETIF_CREATE:=yes}"
> +: "${NETIF_TYPE:=veth}"
> +if [[ "$NETIF_CREATE" = yes && "$NETIF_TYPE" = veth ]]; then
> + echo "SKIP: needs a real interface, set NETIFS in forwarding.config"
> + exit 4 # ksft_skip, lib.sh is not sourced yet
> +fi
> +
> source "$lib_dir"/../../../net/forwarding/lib.sh
> source ethtool_lib.sh
>
> diff --git a/tools/testing/selftests/drivers/net/hw/hw_stats_l3.sh b/tools/testing/selftests/drivers/net/hw/hw_stats_l3.sh
> index 67fafefc80be..1776a4954601 100755
> --- a/tools/testing/selftests/drivers/net/hw/hw_stats_l3.sh
> +++ b/tools/testing/selftests/drivers/net/hw/hw_stats_l3.sh
> @@ -49,6 +49,22 @@ ALL_TESTS="
> "
> NUM_NETIFS=4
> lib_dir=$(dirname "$0")
> +
> +# The test needs a device capable of offloading L3 statistics. Where no
> +# real interfaces are configured, lib.sh makes a veth pair instead,
> +# which cannot, and every case then fails on something the kernel
> +# correctly refuses. Check this before sourcing lib.sh: it creates that
> +# pair as it is sourced, so exiting afterwards leaves the devices
> +# behind, and the next test that wants one of those names cannot create
> +# it.
> +
> +: "${NETIF_CREATE:=yes}"
> +: "${NETIF_TYPE:=veth}"
> +if [[ "$NETIF_CREATE" = yes && "$NETIF_TYPE" = veth ]]; then
> + echo "SKIP: needs a real interface, set NETIFS in forwarding.config"
> + exit 4 # ksft_skip, lib.sh is not sourced yet
> +fi
> +
> source "$lib_dir"/../../../net/forwarding/lib.sh
> source "$lib_dir"/../../../net/forwarding/tc_common.sh
>
> diff --git a/tools/testing/selftests/drivers/net/hw/hw_stats_l3_gre.sh b/tools/testing/selftests/drivers/net/hw/hw_stats_l3_gre.sh
> index a94d92e1abce..2cbc2682f7b7 100755
> --- a/tools/testing/selftests/drivers/net/hw/hw_stats_l3_gre.sh
> +++ b/tools/testing/selftests/drivers/net/hw/hw_stats_l3_gre.sh
> @@ -13,6 +13,22 @@ ALL_TESTS="
> "
> NUM_NETIFS=6
> lib_dir=$(dirname "$0")
> +
> +# The test needs a device capable of offloading L3 statistics. Where no
> +# real interfaces are configured, lib.sh makes a veth pair instead,
> +# which cannot, and every case then fails on something the kernel
> +# correctly refuses. Check this before sourcing lib.sh: it creates that
> +# pair as it is sourced, so exiting afterwards leaves the devices
> +# behind, and the next test that wants one of those names cannot create
> +# it.
> +
> +: "${NETIF_CREATE:=yes}"
> +: "${NETIF_TYPE:=veth}"
> +if [[ "$NETIF_CREATE" = yes && "$NETIF_TYPE" = veth ]]; then
> + echo "SKIP: needs a real interface, set NETIFS in forwarding.config"
> + exit 4 # ksft_skip, lib.sh is not sourced yet
> +fi
> +
> source "$lib_dir"/../../../net/forwarding/lib.sh
> source "$lib_dir"/../../../net/forwarding/ipip_lib.sh
> source "$lib_dir"/../../../net/forwarding/tc_common.sh
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2026-09-24 13:30 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-08-31 22:50 [Devel] [PATCH vz10 1/4] ms/selftests: net: Add python context manager for netns entering Eva Kurchatova
2026-08-31 22:50 ` [Devel] [PATCH vz10 2/4] selftests: net: py: add the missing ksft_is() and ksft_not_in() helpers Eva Kurchatova
2026-09-24 13:27 ` Konstantin Khorenko
2026-08-31 22:50 ` [Devel] [PATCH vz10 3/4] selftests: net: py: report a refused environment as a skip Eva Kurchatova
2026-09-24 13:28 ` Konstantin Khorenko
2026-08-31 22:50 ` [Devel] [PATCH vz10 4/4] selftests: drv-net-hw: skip the tests that need a real interface Eva Kurchatova
2026-09-24 13:23 ` Konstantin Khorenko
2026-09-24 13:29 ` Konstantin Khorenko
2026-09-24 13:27 ` [Devel] [PATCH vz10 1/4] ms/selftests: net: Add python context manager for netns entering Konstantin Khorenko
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.