Skip to contentSkip to conversation

Add YNL test framework and library improvements

PATCH Superseded Hangbin Liu 3 participants 10 messages Nov 5, 2025 – Nov 10, 2025

Subsystems (4)

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v2 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
- Fix rt-rule spec consistency with other rt-* families
- Add tests covering CLI and ethtool functionality

The tests provide usage examples and regression testing for YNL tools. Test result:

  # test_ynl_cli
  PASS: YNL CLI list families
  PASS: YNL CLI netdev operations
  PASS: YNL CLI ethtool operations
  PASS: YNL CLI rt-route operations
  PASS: YNL CLI rt-addr operations
  PASS: YNL CLI rt-link operations
  PASS: YNL CLI rt-neigh operations
  PASS: YNL CLI rt-rule operations
  PASS: YNL CLI nlctrl getfamily
  # test_ynl_ethtool
  PASS: YNL ethtool device info
  PASS: YNL ethtool statistics
  PASS: YNL ethtool ring parameters (show/set)
  PASS: YNL ethtool coalesce parameters (show/set)
  PASS: YNL ethtool pause parameters (show/set)
  PASS: YNL ethtool features info (show/set)
  PASS: YNL ethtool channels info (show/set)
  PASS: YNL ethtool time stamping

v2: move test from selftest to ynl folder (Jakub Kicinski)
v1: https://lore.kernel.org/netdev/[email protected]

Hangbin Liu (3):
tools: ynl: Add MAC address parsing support
netlink: specs: update rt-rule src/dst attribute types to support IPv4
addresses
tools: ynl: add YNL test framework

 Documentation/netlink/specs/rt-rule.yaml |   6 +-
 tools/net/ynl/Makefile                   |   3 +-
 tools/net/ynl/pyynl/lib/ynl.py           |   9 +
 tools/net/ynl/tests/Makefile             |  24 ++
 tools/net/ynl/tests/config               |   6 +
 tools/net/ynl/tests/test_ynl_cli.sh      | 290 +++++++++++++++++++++++
 tools/net/ynl/tests/test_ynl_ethtool.sh  | 195 +++++++++++++++
 7 files changed, 530 insertions(+), 3 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
#1 lore raw

PATCH v2 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
index 225baad3c8f8..36d36eb7e3b8 100644
@@ -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
#2 lore raw

PATCH v2 2/3 netlink: specs: update rt-rule src/dst attribute types to support IPv4 addresses

In reply to Hangbin Liu

Similar with other rt-* family specs (rt-route, rt-addr, rt-neigh), change src and dst attributes in rt-rule.yaml from type u32 to type binary with display-hint ipv4 to properly support IPv4/IPv6 address operations.

---
 Documentation/netlink/specs/rt-rule.yaml | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
Documentation/netlink/specs/rt-rule.yaml +4 -2
index bebee452a950..7ebd95312ee4 100644
@@ -96,10 +96,12 @@ attribute-sets:
     attributes:
       -
         name: dst
-        type: u32
+        type: binary
+        display-hint: ipv4
       -
         name: src
-        type: u32
+        type: binary
+        display-hint: ipv4
       -
         name: iifname
         type: string
Signature · 1 line
2.50.1
#3 lore raw

PATCH v2 3/3 tools: ynl: add YNL test framework

In reply to 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

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                  |   3 +-
 tools/net/ynl/tests/Makefile            |  24 ++
 tools/net/ynl/tests/config              |   6 +
 tools/net/ynl/tests/test_ynl_cli.sh     | 290 ++++++++++++++++++++++++
 tools/net/ynl/tests/test_ynl_ethtool.sh | 195 ++++++++++++++++
 5 files changed, 517 insertions(+), 1 deletion(-)
 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 +2 -1
index 211df5a93ad9..89a9cd0a1306 100644
@@ -12,7 +12,7 @@ endif
 libdir  ?= $(prefix)/$(libdir_relative)
 includedir ?= $(prefix)/include
 
-SUBDIRS = lib generated samples
+SUBDIRS = lib generated samples tests
 
 all: $(SUBDIRS) libynl.a
 
@@ -48,5 +48,6 @@ 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)
tools/net/ynl/tests/Makefile new file +24 -0
new file mode 100644
index 000000000000..10bca7fe54c5
@@ -0,0 +1,24 @@
+# SPDX-License-Identifier: GPL-2.0
+# Makefile for YNL tests
+
+TESTS := \
+	test_ynl_cli.sh \
+	test_ynl_ethtool.sh \
+# end of TESTS
+
+all: $(TESTS)
+
+install: $(TESTS)
+	@mkdir -p $(DESTDIR)/usr/bin
+	@for test in $(TESTS); do \
+		name=$$(basename $$test .sh); \
+		sed -e 's|^ynl=.*|ynl="ynl"|' \
+		    -e 's|^ynl_ethtool=.*|ynl_ethtool="ynl-ethtool"|' \
+		    $$test > $(DESTDIR)/usr/bin/$$name; \
+		chmod +x $(DESTDIR)/usr/bin/$$name; \
+	done
+
+clean:
+	@# Nothing to clean
+
+.PHONY: all install clean
tools/net/ynl/tests/config new file +6 -0
new file mode 100644
index 000000000000..339f1309c03f
@@ -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 +290 -0

290 lines not on this page · raw message

tools/net/ynl/tests/test_ynl_ethtool.sh new file +195 -0

195 lines not on this page · raw message

Signature · 1 line
2.50.1
#4 lore raw

Re: [PATCHv2 net-next 3/3] tools: ynl: add YNL test framework

tools/net/ynl/tests/test_ynl_cli.sh line 232

Quoted 3 lines · Hangbin Liu
tools/net/ynl/tests/test_ynl_cli.sh new file +3 -0
+setup() {
+	if ! modprobe netdevsim &>/dev/null; then
+		echo "SKIP: all YNL CLI tests (netdevsim module not available)"

Can we maybe find a way to try to load the module and still run the test if modprobe fails but netdevsim is built-in? I usually do my testing in VMs with kernels where everything I need is built in, so I don't do "make modules_install" and "modprobe netdevsim" fails even if netdevsim is actually available (because it's built in).

For some modules it may be difficult, for netdevsim we could just run modprobe (but ignore its return value) and check if /sys/bus/netdevsim/new_device exists to decide if we need to skip the tests?

Or do we only expect selftests/those new tests to run with the standard net selftests config, and not with custom configs that also provide all the required features?

Signature · 1 line
Sabrina
#5 lore raw

Re: [PATCHv2 net-next 3/3] tools: ynl: add YNL test framework

Quoted 11 lines · Sabrina Dubroca

tools/net/ynl/tests/test_ynl_cli.sh line 232

Quoted 3 lines · Hangbin Liu
tools/net/ynl/tests/test_ynl_cli.sh new file +3 -0
+setup() {
+	if ! modprobe netdevsim &>/dev/null; then
+		echo "SKIP: all YNL CLI tests (netdevsim module not available)"

Can we maybe find a way to try to load the module and still run the test if modprobe fails but netdevsim is built-in? I usually do my testing in VMs with kernels where everything I need is built in, so I don't do "make modules_install" and "modprobe netdevsim" fails even if netdevsim is actually available (because it's built in).

Quoted 4 lines

For some modules it may be difficult, for netdevsim we could just run modprobe (but ignore its return value) and check if /sys/bus/netdevsim/new_device exists to decide if we need to skip the tests?

Yes, could be.

Quoted 5 lines

Or do we only expect selftests/those new tests to run with the standard net selftests config, and not with custom configs that also provide all the required features?

I do not have a preference. I added a config file to the test folder. However, this config file is just for reference.

Thanks
Hangbin

maintainer
#6 lore raw

Re: [PATCHv2 net-next 3/3] tools: ynl: add YNL test framework

In reply to Hangbin Liu
Quoted 11 lines · On Wed, 5 Nov 2025 08:28:41 +0000 Hangbin Liu wrote:

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

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.

And how would we run all the tests in the new directory?

Since we have two test files we need some way to run all.

#7 lore raw

Re: [PATCHv2 net-next 3/3] tools: ynl: add YNL test framework

Quoted 9 lines · Jakub Kicinski
Quoted 8 lines · On Wed, 5 Nov 2025 08:28:41 +0000 Hangbin Liu wrote:

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 7 lines
Quoted 3 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.

And how would we run all the tests in the new directory?

Since we have two test files we need some way to run all.

I didn't get your requirement. We can run them one by one in the test folder.

 # ./test_ynl_cli.sh
 # ./test_ynl_ethtool.sh

Do you want to use a wrapper to run the 2 tests? e.g.

 # ./run_all_ynl_tests.sh

Thanks
Hangbin

maintainer
#8 lore raw

Re: [PATCHv2 net-next 3/3] tools: ynl: add YNL test framework

Quoted 18 lines · On Thu, 6 Nov 2025 02:40:25 +0000 Hangbin Liu wrote:
Quoted 9 lines · Jakub Kicinski
Quoted 8 lines · On Wed, 5 Nov 2025 08:28:41 +0000 Hangbin Liu wrote:

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 7 lines
Quoted 3 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.

And how would we run all the tests in the new directory?

Since we have two test files we need some way to run all.

Quoted 7 lines

I didn't get your requirement. We can run them one by one in the test folder.

 # ./test_ynl_cli.sh
 # ./test_ynl_ethtool.sh

Do you want to use a wrapper to run the 2 tests? e.g.

 # ./run_all_ynl_tests.sh

Or make run_tests, like ksft

#9 lore raw

Re: [PATCHv2 net-next 3/3] tools: ynl: add YNL test framework

Quoted 6 lines · Jakub Kicinski
Quoted 6 lines
Quoted 3 lines

And how would we run all the tests in the new directory?

Since we have two test files we need some way to run all.

I didn't get your requirement. We can run them one by one in the test folder.

Quoted 7 lines
Quoted 5 lines
 # ./test_ynl_cli.sh
 # ./test_ynl_ethtool.sh

Do you want to use a wrapper to run the 2 tests? e.g.

 # ./run_all_ynl_tests.sh

Or make run_tests, like ksft

OK, makes sense to me.

Hangbin