[Devel] [PATCH vz10 3/7] selftests: net: skip what this kernel and iproute2 do not have

Vladimir Riabchun vladimir.riabchun at virtuozzo.com
Mon Sep 21 17:51:47 MSK 2026


> Five cases report a failure where a feature is simply not there.
> 
> tls asks for every cipher it knows and fails on the ones the kernel does
> not implement, SM4 and ARIA, which answer ENOENT at setsockopt
> time. Skip a cipher the kernel refuses that way; the run then reports
> 632 passed, 264 skipped and none failed.
> 
> rtnetlink.sh sets up an erspan tunnel, which this kernel does not have
> and which fails with "Unknown device type", and checks a netconf dump
> whose exit status iproute2 gets wrong: 6.11 exits 2 on a dump that
> worked, 6.17 exits 0. Probe for both and skip when unusable.
> 
> rtnetlink.py asks for an IPv4 multicast address dump the kernel answers
> with EOPNOTSUPP, and ip_local_port_range asks for protocols it does not
> have. Skip those too.
> 
> https://virtuozzo.atlassian.net/browse/VSTOR-139651
> Feature: fix selftests
> Signed-off-by: Eva Kurchatova <eva.kurchatova at virtuozzo.com>
>
> diff --git a/tools/testing/selftests/net/ip_local_port_range.c b/tools/testing/selftests/net/ip_local_port_range.c
> index 29451d2244b7..2d7b9c852b2b 100644
> --- a/tools/testing/selftests/net/ip_local_port_range.c
> +++ b/tools/testing/selftests/net/ip_local_port_range.c
> @@ -118,10 +118,6 @@ static int get_ip_local_port_range(int fd, __u32 *range)
>  
>  FIXTURE(ip_local_port_range) {};
>  
> -FIXTURE_SETUP(ip_local_port_range)
> -{
> -}
> -
>  FIXTURE_TEARDOWN(ip_local_port_range)
>  {
>  }
> @@ -180,6 +176,19 @@ FIXTURE_VARIANT_ADD(ip_local_port_range, ip6_mptcp) {
>  	.so_protocol	= IPPROTO_MPTCP,
>  };
>  
> +FIXTURE_SETUP(ip_local_port_range)
> +{
> +	int fd;
> +
> +	/* Not every protocol under test is built into every kernel. */
> +	fd = socket(variant->so_domain, variant->so_type, variant->so_protocol);
> +	if (fd < 0 && (errno == EPROTONOSUPPORT || errno == ESOCKTNOSUPPORT ||
> +		       errno == EAFNOSUPPORT))
> +		SKIP(return, "%s", strerror(errno));
> +	ASSERT_GE(fd, 0) TH_LOG("socket failed");
> +	close(fd);
> +}
> +
>  TEST_F(ip_local_port_range, invalid_option_value)
>  {
>  	__u16 val16;
> diff --git a/tools/testing/selftests/net/rtnetlink.py b/tools/testing/selftests/net/rtnetlink.py
> index baa7b33f313e..425fc7a3941b 100755
> --- a/tools/testing/selftests/net/rtnetlink.py
> +++ b/tools/testing/selftests/net/rtnetlink.py
> @@ -1,7 +1,9 @@
>  #! /usr/bin/python3 -sP
>  # SPDX-License-Identifier: GPL-2.0
>  
> -from lib.py import ksft_exit, ksft_run, ksft_ge, RtnlAddrFamily
> +from lib.py import ksft_exit, ksft_run, ksft_ge, KsftSkipEx
> +from lib.py import NlError, RtnlAddrFamily
> +import errno
>  import socket
>  
>  IPV4_ALL_HOSTS_MULTICAST = b'\xe0\x00\x00\x01'
> @@ -12,7 +14,12 @@ def dump_mcaddr_check(rtnl: RtnlAddrFamily) -> None:
>      At least the loopback interface should have this address.
>      """
>  
> -    addresses = rtnl.getmulticast({"ifa-family": socket.AF_INET}, dump=True)
> +    try:
> +        addresses = rtnl.getmulticast({"ifa-family": socket.AF_INET}, dump=True)
> +    except NlError as e:
> +        if e.nl_msg.error == -errno.EOPNOTSUPP:
> +            raise KsftSkipEx("IPv4 multicast address dump is not supported")
> +        raise
>  
>      all_host_multicasts = [
>          addr for addr in addresses if addr['multicast'] == IPV4_ALL_HOSTS_MULTICAST
> diff --git a/tools/testing/selftests/net/rtnetlink.sh b/tools/testing/selftests/net/rtnetlink.sh
> index 5f72b447e940..cc4e94b90002 100755
> --- a/tools/testing/selftests/net/rtnetlink.sh
> +++ b/tools/testing/selftests/net/rtnetlink.sh
> @@ -142,10 +142,30 @@ kci_del_dummy()
>  	run_cmd ip link del dev "$devdummy"
>  }
>  
> +# Some iproute2 versions exit non-zero from a netconf dump that worked,
> +# printing the devconf and then failing anyway.  Nothing about the kernel
> +# can be learned from the exit status of such an ip, so find out once.
> +netconf_exit_status_usable()
> +{
> +	local out
> +
> +	out=$(ip -4 netconf show dev lo 2>/dev/null)
> +	if [ $? -ne 0 ] && [ -n "$out" ]; then
> +		return 1
> +	fi
> +	return 0
> +}
> +
>  kci_test_netconf()
>  {
>  	dev="$1"
>  	r=$ret
> +
> +	if ! netconf_exit_status_usable; then
> +		end_test "SKIP: ip netconf $dev: iproute2 fails a dump that worked"
> +		return $ksft_skip
> +	fi
> +
>  	run_cmd ip netconf show dev "$dev"
>  	for f in 4 6; do
>  		run_cmd ip -$f netconf show dev "$dev"
> @@ -920,6 +940,17 @@ kci_test_erspan()
>  		return $ksft_skip
>  	fi
>  
> +	# the kernel can be built without erspan, rtnetlink then has no ops
> +	# for the type and says so.  A kernel that has it gets past this and
> +	# fails on the attributes the probe leaves out.
> +	if ip -netns "$testns" link add dev "$DEV_NS" type erspan 2>&1 | \
> +	   grep -q "Unknown device type"; then
> +		end_test "SKIP: erspan: not supported by the kernel"
> +		ip netns del "$testns"
> +		return $ksft_skip
> +	fi
> +	ip -netns "$testns" link del dev "$DEV_NS" 2>/dev/null
> +
>  	# test native tunnel erspan v1
>  	run_cmd ip -netns "$testns" link add dev "$DEV_NS" type erspan seq \
>  		key 102 local 172.16.1.100 remote 172.16.1.200 \
> diff --git a/tools/testing/selftests/net/tls.c b/tools/testing/selftests/net/tls.c
> index c9b0b4337e12..07f2b454d755 100644
> --- a/tools/testing/selftests/net/tls.c
> +++ b/tools/testing/selftests/net/tls.c
> @@ -413,6 +413,8 @@ FIXTURE_SETUP(tls)
>  		return;
>  
>  	ret = setsockopt(self->fd, SOL_TLS, TLS_TX, &tls12, tls12.len);
> +	if (ret < 0 && errno == ENOENT)
> +		SKIP(return, "Cipher not built into the kernel");

Just a small question: ENOENT error is not in setsockopt man.
It seems more like ENOPROTOOPT, but if the fix is here, it probably
helped. Could you tell where ENOENT comes from?
Maybe we should test for ENOPROTOOPT as well here?

>  	ASSERT_EQ(ret, 0);
>  
>  	ret = setsockopt(self->cfd, SOL_TLS, TLS_RX, &tls12, tls12.len);

Reviewed-by: Vladimir Riabchun <vladimir.riabchun at virtuozzo.com>

-- 
Vladimir Riabchun <vladimir.riabchun at virtuozzo.com>


More information about the Devel mailing list