Add YNL test framework and library improvements
Subsystems (4)
v5 cover Add YNL test framework and library improvements
This series enhances YNL tools with some functionalities and adds YNL test framework.
Changes include:
- Add MAC address parsing support in YNL library
- Support ipv4-or-v6 display hint for dual-stack fields
- Add tests covering CLI and ethtool functionality
The tests provide usage examples and regression testing for YNL tools.
# make run_tests TAP version 13 1..9 ok 1 YNL CLI list families ok 2 YNL CLI netdev operations ok 3 YNL CLI ethtool operations ok 4 YNL CLI rt-route operations ok 5 YNL CLI rt-addr operations ok 6 YNL CLI rt-link operations ok 7 YNL CLI rt-neigh operations ok 8 YNL CLI rt-rule operations ok 9 YNL CLI nlctrl getfamily # Totals: pass:9 fail:0 xfail:0 xpass:0 skip:0 error:0 TAP version 13 1..8 ok 1 YNL ethtool device info ok 2 YNL ethtool statistics ok 3 YNL ethtool ring parameters (show/set) ok 4 YNL ethtool coalesce parameters (show/set) ok 5 YNL ethtool pause parameters (show/set) ok 6 YNL ethtool features info (show/set) ok 7 YNL ethtool channels info (show/set) ok 8 YNL ethtool time stamping # Totals: pass:8 fail:0 xfail:0 xpass:0 skip:0 error:0
v5: add a comment about why disable shellcheck (Matthieu Baerts)
move ktap_set_plan after setup (Matthieu Baerts) Use TESTS_NO to track the test number (Matthieu Baerts)
v4: Use KTAP helper to report the test result (Matthieu Baerts)
iterate through $(TESTS) instead of being hard coded (Donald Hunter)
Link: https://lore.kernel.org/netdev/[email protected]v3: add make run_tests to run all the tests at a time (Jakub Kicinski)
use ipv4-or-v6 display hint for dual-stack fields (Jakub Kicinski) check sysfs in case of netdevsim buildin (Sabrina Dubroca)
v2: move test from selftest to ynl folder (Jakub Kicinski)
Link: https://lore.kernel.org/netdev/[email protected]
v1: Link: https://lore.kernel.org/netdev/[email protected]
Hangbin Liu (3):
tools: ynl: Add MAC address parsing support
netlink: specs: support ipv4-or-v6 for dual-stack fields
tools: ynl: add YNL test framework
Documentation/netlink/genetlink-c.yaml | 2 +- Documentation/netlink/genetlink.yaml | 2 +- Documentation/netlink/netlink-raw.yaml | 2 +- Documentation/netlink/specs/rt-addr.yaml | 6 +- Documentation/netlink/specs/rt-link.yaml | 16 +- Documentation/netlink/specs/rt-neigh.yaml | 2 +- Documentation/netlink/specs/rt-route.yaml | 8 +- Documentation/netlink/specs/rt-rule.yaml | 6 +- tools/net/ynl/Makefile | 8 +- tools/net/ynl/pyynl/lib/ynl.py | 9 + tools/net/ynl/tests/Makefile | 32 +++ tools/net/ynl/tests/config | 6 + tools/net/ynl/tests/test_ynl_cli.sh | 327 ++++++++++++++++++++++ tools/net/ynl/tests/test_ynl_ethtool.sh | 222 +++++++++++++++ 14 files changed, 625 insertions(+), 23 deletions(-) create mode 100644 tools/net/ynl/tests/Makefile create mode 100644 tools/net/ynl/tests/config create mode 100755 tools/net/ynl/tests/test_ynl_cli.sh create mode 100755 tools/net/ynl/tests/test_ynl_ethtool.sh
Signature · 1 line
2.50.1
PATCH v5 1/3 tools: ynl: Add MAC address parsing support
Add missing support for parsing MAC addresses when display_hint is 'mac' in the YNL library. This enables YNL CLI to accept MAC address strings for attributes like lladdr in rt-neigh operations.
--- tools/net/ynl/pyynl/lib/ynl.py | 9 +++++++++ 1 file changed, 9 insertions(+)
tools/net/ynl/pyynl/lib/ynl.py +9 -0
@@ -985,6 +985,15 @@ class YnlFamily(SpecFamily): raw = bytes.fromhex(string) else: raw = int(string, 16) + elif attr_spec.display_hint == 'mac': + # Parse MAC address in format "00:11:22:33:44:55" or "001122334455" + if ':' in string: + mac_bytes = [int(x, 16) for x in string.split(':')] + else: + if len(string) % 2 != 0: + raise Exception(f"Invalid MAC address format: {string}") + mac_bytes = [int(string[i:i+2], 16) for i in range(0, len(string), 2)] + raw = bytes(mac_bytes) else: raise Exception(f"Display hint '{attr_spec.display_hint}' not implemented" f" when parsing '{attr_spec['name']}'")
Signature · 1 line
2.50.1
PATCH v5 2/3 netlink: specs: support ipv4-or-v6 for dual-stack fields
In reply to Hangbin LiuSince commit 1b255e1beabf ("tools: ynl: add ipv4-or-v6 display hint"), we can display either IPv4 or IPv6 addresses for a single field based on the address family. However, most dual-stack fields still use the ipv4 display hint. This update changes them to use the new ipv4-or-v6 display hint and converts IPv4-only fields to use the u32 type.
Field changes:
- v4-or-v6
- IFA_ADDRESS, IFA_LOCAL
- IFLA_GRE_LOCAL, IFLA_GRE_REMOTE
- IFLA_VTI_LOCAL, IFLA_VTI_REMOTE
- IFLA_IPTUN_LOCAL, IFLA_IPTUN_REMOTE
- NDA_DST
- RTA_DST, RTA_SRC, RTA_GATEWAY, RTA_PREFSRC
- FRA_SRC, FRA_DST
- ipv4
- IFA_BROADCAST
- IFLA_GENEVE_REMOTE
- IFLA_IPTUN_6RD_RELAY_PREFIX
--- Documentation/netlink/genetlink-c.yaml | 2 +- Documentation/netlink/genetlink.yaml | 2 +- Documentation/netlink/netlink-raw.yaml | 2 +- Documentation/netlink/specs/rt-addr.yaml | 6 +++--- Documentation/netlink/specs/rt-link.yaml | 16 ++++++++-------- Documentation/netlink/specs/rt-neigh.yaml | 2 +- Documentation/netlink/specs/rt-route.yaml | 8 ++++---- Documentation/netlink/specs/rt-rule.yaml | 6 ++++-- 8 files changed, 23 insertions(+), 21 deletions(-)
Documentation/netlink/genetlink-c.yaml +1 -1
@@ -227,7 +227,7 @@ properties: Optional format indicator that is intended only for choosing the right formatting mechanism when displaying values of this type. - enum: [ hex, mac, fddi, ipv4, ipv6, uuid ] + enum: [ hex, mac, fddi, ipv4, ipv6, ipv4-or-v6, uuid ] # Start genetlink-c name-prefix: type: string
Documentation/netlink/genetlink.yaml +1 -1
@@ -185,7 +185,7 @@ properties: Optional format indicator that is intended only for choosing the right formatting mechanism when displaying values of this type. - enum: [ hex, mac, fddi, ipv4, ipv6, uuid ] + enum: [ hex, mac, fddi, ipv4, ipv6, ipv4-or-v6, uuid ] # Make sure name-prefix does not appear in subsets (subsets inherit naming) dependencies:
Documentation/netlink/netlink-raw.yaml +1 -1
@@ -157,7 +157,7 @@ properties: Optional format indicator that is intended only for choosing the right formatting mechanism when displaying values of this type. - enum: [ hex, mac, fddi, ipv4, ipv6, uuid ] + enum: [ hex, mac, fddi, ipv4, ipv6, ipv4-or-v6, uuid ] struct: description: Name of the nested struct type. type: string
Documentation/netlink/specs/rt-addr.yaml +3 -3
@@ -86,17 +86,17 @@ attribute-sets: - name: address type: binary - display-hint: ipv4 + display-hint: ipv4-or-v6 - name: local type: binary - display-hint: ipv4 + display-hint: ipv4-or-v6 - name: label type: string - name: broadcast - type: binary + type: u32 display-hint: ipv4 - name: anycast
Documentation/netlink/specs/rt-link.yaml +8 -8
@@ -1707,11 +1707,11 @@ attribute-sets: - name: local type: binary - display-hint: ipv4 + display-hint: ipv4-or-v6 - name: remote type: binary - display-hint: ipv4 + display-hint: ipv4-or-v6 - name: ttl type: u8
@@ -1833,11 +1833,11 @@ attribute-sets: - name: local type: binary - display-hint: ipv4 + display-hint: ipv4-or-v6 - name: remote type: binary - display-hint: ipv4 + display-hint: ipv4-or-v6 - name: fwmark type: u32
@@ -1868,7 +1868,7 @@ attribute-sets: type: u32 - name: remote - type: binary + type: u32 display-hint: ipv4 - name: ttl
@@ -1952,11 +1952,11 @@ attribute-sets: - name: local type: binary - display-hint: ipv4 + display-hint: ipv4-or-v6 - name: remote type: binary - display-hint: ipv4 + display-hint: ipv4-or-v6 - name: ttl type: u8
@@ -1986,7 +1986,7 @@ attribute-sets: display-hint: ipv6 - name: 6rd-relay-prefix - type: binary + type: u32 display-hint: ipv4 - name: 6rd-prefixlen
Documentation/netlink/specs/rt-neigh.yaml +1 -1
@@ -194,7 +194,7 @@ attribute-sets: - name: dst type: binary - display-hint: ipv4 + display-hint: ipv4-or-v6 - name: lladdr type: binary
Documentation/netlink/specs/rt-route.yaml +4 -4
@@ -87,11 +87,11 @@ attribute-sets: - name: dst type: binary - display-hint: ipv4 + display-hint: ipv4-or-v6 - name: src type: binary - display-hint: ipv4 + display-hint: ipv4-or-v6 - name: iif type: u32
@@ -101,14 +101,14 @@ attribute-sets: - name: gateway type: binary - display-hint: ipv4 + display-hint: ipv4-or-v6 - name: priority type: u32 - name: prefsrc type: binary - display-hint: ipv4 + display-hint: ipv4-or-v6 - name: metrics type: nest
Documentation/netlink/specs/rt-rule.yaml +4 -2
@@ -96,10 +96,12 @@ attribute-sets: attributes: - name: dst - type: u32 + type: binary + display-hint: ipv4-or-v6 - name: src - type: u32 + type: binary + display-hint: ipv4-or-v6 - name: iifname type: string
Signature · 1 line
2.50.1
PATCH v5 3/3 tools: ynl: add YNL test framework
In reply to Hangbin LiuAdd a test framework for YAML Netlink (YNL) tools, covering both CLI and ethtool functionality. The framework includes:
1) cli: family listing, netdev, ethtool, rt-* families, and nlctrl operations
2) ethtool: device info, statistics, ring/coalesce/pause parameters, and feature gettings
The current YNL syntax is a bit obscure, and end users may not always know how to use it. This test framework provides usage examples and also serves as a regression test to catch potential breakages caused by future changes.
--- tools/net/ynl/Makefile | 8 +- tools/net/ynl/tests/Makefile | 32 +++ tools/net/ynl/tests/config | 6 + tools/net/ynl/tests/test_ynl_cli.sh | 327 ++++++++++++++++++++++++ tools/net/ynl/tests/test_ynl_ethtool.sh | 222 ++++++++++++++++ 5 files changed, 593 insertions(+), 2 deletions(-) create mode 100644 tools/net/ynl/tests/Makefile create mode 100644 tools/net/ynl/tests/config create mode 100755 tools/net/ynl/tests/test_ynl_cli.sh create mode 100755 tools/net/ynl/tests/test_ynl_ethtool.sh
tools/net/ynl/Makefile +6 -2
@@ -12,7 +12,7 @@ endif libdir ?= $(prefix)/$(libdir_relative) includedir ?= $(prefix)/include -SUBDIRS = lib generated samples ynltool +SUBDIRS = lib generated samples ynltool tests all: $(SUBDIRS) libynl.a
@@ -49,5 +49,9 @@ install: libynl.a lib/*.h @echo -e "\tINSTALL pyynl" @pip install --prefix=$(DESTDIR)$(prefix) . @make -C generated install + @make -C tests install -.PHONY: all clean distclean install $(SUBDIRS) +run_tests: + @$(MAKE) -C tests run_tests + +.PHONY: all clean distclean install run_tests $(SUBDIRS)
tools/net/ynl/tests/Makefile new file +32 -0
@@ -0,0 +1,32 @@ +# SPDX-License-Identifier: GPL-2.0 +# Makefile for YNL tests + +TESTS := \ + test_ynl_cli.sh \ + test_ynl_ethtool.sh \ +# end of TESTS + +all: $(TESTS) + +run_tests: + @for test in $(TESTS); do \ + ./$$test; \ + done + +install: $(TESTS) + @mkdir -p $(DESTDIR)/usr/bin + @mkdir -p $(DESTDIR)/usr/share/kselftest + @cp ../../../testing/selftests/kselftest/ktap_helpers.sh $(DESTDIR)/usr/share/kselftest/ + @for test in $(TESTS); do \ + name=$$(basename $$test .sh); \ + sed -e 's|^ynl=.*|ynl="ynl"|' \ + -e 's|^ynl_ethtool=.*|ynl_ethtool="ynl-ethtool"|' \ + -e 's|KSELFTEST_KTAP_HELPERS=.*|KSELFTEST_KTAP_HELPERS="/usr/share/kselftest/ktap_helpers.sh"|' \ + $$test > $(DESTDIR)/usr/bin/$$name; \ + chmod +x $(DESTDIR)/usr/bin/$$name; \ + done + +clean: + @# Nothing to clean + +.PHONY: all install clean run_tests
tools/net/ynl/tests/config new file +6 -0
@@ -0,0 +1,6 @@ +CONFIG_DUMMY=m +CONFIG_INET_DIAG=y +CONFIG_IPV6=y +CONFIG_NET_NS=y +CONFIG_NETDEVSIM=m +CONFIG_VETH=m
tools/net/ynl/tests/test_ynl_cli.sh new file +327 -0
327 lines not on this page · raw message
tools/net/ynl/tests/test_ynl_ethtool.sh new file +222 -0
222 lines not on this page · raw message
Signature · 1 line
2.50.1
Re: [PATCHv5 net-next 3/3] tools: ynl: add YNL test framework
Hi Hangbin,
Quoted 11 lines · Hangbin Liu
Add a test framework for YAML Netlink (YNL) tools, covering both CLI and ethtool functionality. The framework includes:
1) cli: family listing, netdev, ethtool, rt-* families, and nlctrl operations
2) ethtool: device info, statistics, ring/coalesce/pause parameters, and feature gettingsThe current YNL syntax is a bit obscure, and end users may not always know how to use it. This test framework provides usage examples and also serves as a regression test to catch potential breakages caused by future changes.
Thank you for the v5!
The new version looks good to me:
I just have one question below, but that's not blocking.
(...)
tools/net/ynl/tests/test_ynl_cli.sh line 7
Quoted 13 lines
tools/net/ynl/tests/test_ynl_cli.sh new file +7
-0@@ -0,0 +1,327 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Test YNL CLI functionality + +# Load KTAP test helpers +KSELFTEST_KTAP_HELPERS="$(dirname "$(realpath "$0")")/../../../testing/selftests/kselftest/ktap_helpers.sh" +# shellcheck source=/dev/null
Out of curiosity, why did you put source=/dev/null? It is equivalent to "disable=SC1090" and there is no comment explaining why: was it not OK to use this?
shellcheck source=../../../testing/selftests/kselftest/ktap_helpers.sh
Quoted 1 line
tools/net/ynl/tests/test_ynl_cli.sh new file +1
-0+source "$KSELFTEST_KTAP_HELPERS"
(...)
Quoted 1 line
+cleanup()
Note that with shellcheck 0.11, you will need to disable SC2329 here. But NIPA is not using this version yet, so no need to change now.
https://www.shellcheck.net/wiki/SC2329
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
Re: [PATCHv5 net-next 3/3] tools: ynl: add YNL test framework
In reply to Hangbin LiuQuoted 8 lines · Hangbin Liu
Add a test framework for YAML Netlink (YNL) tools, covering both CLI and ethtool functionality. The framework includes:
1) cli: family listing, netdev, ethtool, rt-* families, and nlctrl operations
2) ethtool: device info, statistics, ring/coalesce/pause parameters, and feature gettings
Quoted 5 lines
The current YNL syntax is a bit obscure, and end users may not always know how to use it. This test framework provides usage examples and also serves as a regression test to catch potential breakages caused by future changes.
Signed-off-by Hangbin Liu <[email protected]>
Re: [PATCHv5 net-next 3/3] tools: ynl: add YNL test framework
In reply to Matthieu BaertsQuoted 22 lines · Matthieu Baerts
I just have one question below, but that's not blocking.
(...)
tools/net/ynl/tests/test_ynl_cli.sh line 7
Quoted 13 lines
tools/net/ynl/tests/test_ynl_cli.sh new file +7
-0@@ -0,0 +1,327 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Test YNL CLI functionality + +# Load KTAP test helpers +KSELFTEST_KTAP_HELPERS="$(dirname "$(realpath "$0")")/../../../testing/selftests/kselftest/ktap_helpers.sh" +# shellcheck source=/dev/nullOut of curiosity, why did you put source=/dev/null? It is equivalent to "disable=SC1090" and there is no comment explaining why: was it not OK to use this?
Quoted 2 lines
shellcheck source=../../../testing/selftests/kselftest/ktap_helpers.sh
I got the following warning with it
In test_ynl_cli.sh line 8:
source "$KSELFTEST_KTAP_HELPERS"
^-----------------------^ SC1091 (info): Not following: ../../../testing/selftests/kselftest/ktap_helpers.sh was not specified as input (see shellcheck -x).
It looks the KSELFTEST_KTAP_HELPERS cannot be statically analyzed after variable expansion.
Thanks
Hangbin
Quoted 16 lines
Quoted 1 line
tools/net/ynl/tests/test_ynl_cli.sh new file +1
-0+source "$KSELFTEST_KTAP_HELPERS"(...)
Quoted 1 line
+cleanup()
Note that with shellcheck 0.11, you will need to disable SC2329 here. But NIPA is not using this version yet, so no need to change now.
https://www.shellcheck.net/wiki/SC2329
Cheers,
MattSignature · 1 line
Sponsored by the NGI0 Core fund.
Re: [PATCHv5 net-next 3/3] tools: ynl: add YNL test framework
18 Nov 2025 02:15:08 Hangbin Liu <[email protected]>:
Quoted 23 lines · Matthieu Baerts
Quoted 22 lines
I just have one question below, but that's not blocking.
(...)
tools/net/ynl/tests/test_ynl_cli.sh line 7
Quoted 13 lines
tools/net/ynl/tests/test_ynl_cli.sh new file +7
-0@@ -0,0 +1,327 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Test YNL CLI functionality + +# Load KTAP test helpers +KSELFTEST_KTAP_HELPERS="$(dirname "$(realpath "$0")")/../../../testing/selftests/kselftest/ktap_helpers.sh" +# shellcheck source=/dev/nullOut of curiosity, why did you put source=/dev/null? It is equivalent to "disable=SC1090" and there is no comment explaining why: was it not OK to use this?
Quoted 8 lines
Quoted 2 lines
shellcheck source=../../../testing/selftests/kselftest/ktap_helpers.sh
I got the following warning with it
In
test_ynl_cli.shline 8:
source "$KSELFTEST_KTAP_HELPERS"
^-----------------------^ SC1091 (info): Not following:../../../testing/selftests/kselftest/ktap_helpers.shwas not specified as input (see shellcheck -x).
How did you execute shellcheck?
If I'm not mistaken, you are supposed to execute it from the same directory, and with -x:
cd "$(dirname "${script}")"
shellcheck -x "$(basename "${script}")"
Cheers,
Matt
Re: [PATCHv5 net-next 3/3] tools: ynl: add YNL test framework
Quoted 34 lines · Matthieu Baerts
18 Nov 2025 02:15:08 Hangbin Liu <[email protected]>:
Quoted 23 lines · Matthieu Baerts
Quoted 22 lines
I just have one question below, but that's not blocking.
(...)
tools/net/ynl/tests/test_ynl_cli.sh line 7
Quoted 13 lines
tools/net/ynl/tests/test_ynl_cli.sh new file +7
-0@@ -0,0 +1,327 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Test YNL CLI functionality + +# Load KTAP test helpers +KSELFTEST_KTAP_HELPERS="$(dirname "$(realpath "$0")")/../../../testing/selftests/kselftest/ktap_helpers.sh" +# shellcheck source=/dev/nullOut of curiosity, why did you put source=/dev/null? It is equivalent to "disable=SC1090" and there is no comment explaining why: was it not OK to use this?
Quoted 8 lines
Quoted 2 lines
shellcheck source=../../../testing/selftests/kselftest/ktap_helpers.sh
I got the following warning with it
In
test_ynl_cli.shline 8:
source "$KSELFTEST_KTAP_HELPERS"
^-----------------------^ SC1091 (info): Not following:../../../testing/selftests/kselftest/ktap_helpers.shwas not specified as input (see shellcheck -x).
Quoted 6 lines
How did you execute shellcheck?
If I'm not mistaken, you are supposed to execute it from the same directory, and with -x:
cd "$(dirname "${script}")"
shellcheck -x "$(basename "${script}")"
Ah, I forgot to add the "-x" option... I will fix the comment in future test case update.
Thanks
Hangbin
Jakub Kicinski
maintainerRe: [PATCHv5 net-next 3/3] tools: ynl: add YNL test framework
Quoted 9 lines · On Tue, 18 Nov 2025 02:43:59 +0000 Hangbin Liu wrote:
Quoted 6 lines
How did you execute shellcheck?
If I'm not mistaken, you are supposed to execute it from the same directory, and with -x:
cd "$(dirname "${script}")"
shellcheck -x "$(basename "${script}")"Ah, I forgot to add the "-x" option... I will fix the comment in future test case update.
I applied the first two patches of the series, please respin this one. TBH I'd like to check if this all works in NIPA but probably won't have time to set up a new worker until the weekend. I suspect I'll need to touch up the vng wrappers since this is not true ksft TARGET.
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 9 lines · On Mon, 17 Nov 2025 02:44:54 +0000 you wrote:
This series enhances YNL tools with some functionalities and adds YNL test framework.
Changes include:
- Add MAC address parsing support in YNL library
- Support ipv4-or-v6 display hint for dual-stack fields
- Add tests covering CLI and ethtool functionality[...]
Here is the summary with links:
- [PATCHv5,net-next,1/3] tools: ynl: Add MAC address parsing support
https://git.kernel.org/netdev/net-next/c/4abe51dba69f - [PATCHv5,net-next,2/3] netlink: specs: support ipv4-or-v6 for dual-stack fields https://git.kernel.org/netdev/net-next/c/1064d521d177
- [PATCHv5,net-next,3/3] tools: ynl: add YNL test framework (no matching commit)
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html