Skip to contentSkip to conversation

Add YNL test framework and library improvements

PATCH Superseded Hangbin Liu 4 participants 15 messages Nov 10, 2025 – Nov 13, 2025

Subsystems (4)

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v3 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
  make[1]: Entering directory '/home/net/tools/net/ynl/tests'
  Running YNL tests...
  Running test_ynl_cli.sh...
  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
  Running test_ynl_ethtool.sh...
  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
  All tests passed!
  make[1]: Leaving directory '/home/net/tools/net/ynl/tests'

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              |  38 +++
 tools/net/ynl/tests/config                |   6 +
 tools/net/ynl/tests/test_ynl_cli.sh       | 291 ++++++++++++++++++++++
 tools/net/ynl/tests/test_ynl_ethtool.sh   | 196 +++++++++++++++
 14 files changed, 569 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
#1 lore raw

PATCH v3 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
maintainer Reviewed-by on v3 1/3
#2 lore raw

Re: [PATCHv3 net-next 1/3] tools: ynl: Add MAC address parsing support

Quoted 5 lines · Hangbin Liu

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.

#3 lore raw

PATCH v3 2/3 netlink: specs: support ipv4-or-v6 for dual-stack fields

In reply to Hangbin Liu

Since 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
index 5a234e9b5fa2..57f59fe23e3f 100644
@@ -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
index 7b1ec153e834..b020a537d8ac 100644
@@ -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
index 246fa07bccf6..0166a7e4afbb 100644
@@ -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
index 3a582eac1629..abcbaa73fa9d 100644
@@ -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
index 2a23e9699c0b..5bfdcb5afa86 100644
@@ -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
@@ -1923,11 +1923,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
@@ -1957,7 +1957,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
index 2f568a6231c9..0f46ef313590 100644
@@ -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
index 1ecb3fadc067..33195db96746 100644
@@ -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
index bebee452a950..7f03a44ab036 100644
@@ -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
Reviewed-by on v3 2/3
#4 lore raw

Re: [PATCHv3 net-next 2/3] netlink: specs: support ipv4-or-v6 for dual-stack fields

Quoted 20 lines · Hangbin Liu

Since 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

Quoted 1 line

Thanks for finding these! I can't remember how I did my previous check, and why I didn't find these earlier.

maintainer Reviewed-by on v3 2/3
#5 lore raw

Re: [PATCHv3 net-next 2/3] netlink: specs: support ipv4-or-v6 for dual-stack fields

In reply to Hangbin Liu
Quoted 20 lines · Hangbin Liu

Since 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

Quoted 1 line

Thanks for all the fixes!

#6 lore raw

PATCH v3 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                  |   8 +-
 tools/net/ynl/tests/Makefile            |  38 ++++
 tools/net/ynl/tests/config              |   6 +
 tools/net/ynl/tests/test_ynl_cli.sh     | 291 ++++++++++++++++++++++++
 tools/net/ynl/tests/test_ynl_ethtool.sh | 196 ++++++++++++++++
 5 files changed, 537 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
index 211df5a93ad9..8a328972564a 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,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 +38 -0
new file mode 100644
index 000000000000..4d527f9c3de9
@@ -0,0 +1,38 @@
+# 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:
+	@echo "Running YNL tests..."
+	@failed=0; \
+	echo "Running test_ynl_cli.sh..."; \
+	./test_ynl_cli.sh || failed=$$(($$failed + 1)); \
+	echo "Running test_ynl_ethtool.sh..."; \
+	./test_ynl_ethtool.sh || failed=$$(($$failed + 1)); \
+	if [ $$failed -eq 0 ]; then \
+		echo "All tests passed!"; \
+	else \
+		echo "$$failed test(s) failed!"; \
+		exit 1; \
+	fi
+
+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 run_tests
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 +291 -0

291 lines not on this page · raw message

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

196 lines not on this page · raw message

Signature · 1 line
2.50.1
maintainer
#7 lore raw

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

Quoted 62 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

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            |  38 ++++
 tools/net/ynl/tests/config              |   6 +
 tools/net/ynl/tests/test_ynl_cli.sh     | 291 ++++++++++++++++++++++++
 tools/net/ynl/tests/test_ynl_ethtool.sh | 196 ++++++++++++++++
 5 files changed, 537 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
index 211df5a93ad9..8a328972564a 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,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 +7 -0
new file mode 100644
index 000000000000..4d527f9c3de9
@@ -0,0 +1,38 @@
+# SPDX-License-Identifier: GPL-2.0
+# Makefile for YNL tests
+
+TESTS := \
+	test_ynl_cli.sh \
+	test_ynl_ethtool.sh \
+# end of TESTS

tools/net/ynl/tests/Makefile line 17

Quoted 10 lines
tools/net/ynl/tests/Makefile new file +10 -0
+
+all: $(TESTS)
+
+run_tests:
+	@echo "Running YNL tests..."
+	@failed=0; \
+	echo "Running test_ynl_cli.sh..."; \
+	./test_ynl_cli.sh || failed=$$(($$failed + 1)); \
+	echo "Running test_ynl_ethtool.sh..."; \
+	./test_ynl_ethtool.sh || failed=$$(($$failed + 1)); \

This could iterate through $(TESTS) instead of being hard coded.

tools/net/ynl/tests/Makefile line 21

Quoted 4 lines
tools/net/ynl/tests/Makefile new file +4 -0
+	if [ $$failed -eq 0 ]; then \
+		echo "All tests passed!"; \
+	else \
+		echo "$$failed test(s) failed!"; \

AFAICS this will never be reported since the scripts only ever exit 0. The message is also a bit misleading since it would be the count of scripts that failed, not individual tests.

It would be great if the scripts exited with the number of test failures so the make file could report a total.

Quoted 56 lines
tools/net/ynl/tests/Makefile new file +17 -0
+		exit 1; \
+	fi
+
+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 run_tests
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 +21 -0
new file mode 100755
index 000000000000..5cc0624ffaad
@@ -0,0 +1,291 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Test YNL CLI functionality
+
+# Default ynl path for direct execution, can be overridden by make install
+ynl="../pyynl/cli.py"
+
+readonly NSIM_ID="1338"
+readonly NSIM_DEV_NAME="nsim${NSIM_ID}"
+readonly VETH_A="veth_a"
+readonly VETH_B="veth_b"
+
+testns="ynl-$(mktemp -u XXXXXX)"
+
+# Test listing available families
+cli_list_families() {
+	if $ynl --list-families &>/dev/null; then
+		echo "PASS: YNL CLI list families"
+	else
+		echo "FAIL: YNL CLI list families"
+	fi

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

Quoted 10 lines
tools/net/ynl/tests/test_ynl_cli.sh new file +10 -0
+}
+
+# Test netdev family operations (dev-get, queue-get)
+cli_netdev_ops() {
+	local dev_output
+	local ifindex
+
+	ifindex=$(ip netns exec "$testns" cat /sys/class/net/"$NSIM_DEV_NAME"/ifindex 2>/dev/null)
+	if [[ -z "$ifindex" ]]; then
+		echo "FAIL: YNL CLI netdev operations (failed to get ifindex)"

This is a bit misleading, there's no ynl command here so I don't think it should be a FAIL. Can we just report SKIP when it is an infra issue?

Quoted 46 lines
tools/net/ynl/tests/test_ynl_cli.sh new file +46 -0
+		return
+	fi
+
+	dev_output=$(ip netns exec "$testns" $ynl --family netdev \
+		--do dev-get --json "{\"ifindex\": $ifindex}" 2>/dev/null)
+
+	if ! echo "$dev_output" | grep -q "ifindex"; then
+		echo "FAIL: YNL CLI netdev operations (netdev dev-get output missing ifindex)"
+		return
+	fi
+
+	if ! ip netns exec "$testns" $ynl --family netdev \
+		--dump queue-get --json "{\"ifindex\": $ifindex}" &>/dev/null; then
+		echo "FAIL: YNL CLI netdev operations (failed to get netdev queue info)"
+		return
+	fi
+
+	echo "PASS: YNL CLI netdev operations"
+}
+
+# Test ethtool family operations (rings-get, linkinfo-get)
+cli_ethtool_ops() {
+	local rings_output
+	local linkinfo_output
+
+	rings_output=$(ip netns exec "$testns" $ynl --family ethtool \
+		--do rings-get --json "{\"header\": {\"dev-name\": \"$NSIM_DEV_NAME\"}}" 2>/dev/null)
+
+	if ! echo "$rings_output" | grep -q "header"; then
+		echo "FAIL: YNL CLI ethtool operations (ethtool rings-get output missing header)"
+		return
+	fi
+
+	linkinfo_output=$(ip netns exec "$testns" $ynl --family ethtool \
+		--do linkinfo-get --json "{\"header\": {\"dev-name\": \"$VETH_A\"}}" 2>/dev/null)
+
+	if ! echo "$linkinfo_output" | grep -q "header"; then
+		echo "FAIL: YNL CLI ethtool operations (ethtool linkinfo-get output missing header)"
+		return
+	fi
+
+	echo "PASS: YNL CLI ethtool operations"
+}
+
+# Test rt-* family operations (route, addr, link, neigh, rule)
+cli_rt_ops() {

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

Quoted 10 lines
tools/net/ynl/tests/test_ynl_cli.sh new file +10 -0
+	local ifindex
+
+	if ! $ynl --list-families 2>/dev/null | grep -q "rt-"; then
+		echo "SKIP: YNL CLI rt-* operations (no rt-* families available)"
+		return
+	fi
+
+	ifindex=$(ip netns exec "$testns" cat /sys/class/net/"$NSIM_DEV_NAME"/ifindex 2>/dev/null)
+	if [[ -z "$ifindex" ]]; then
+		echo "FAIL: YNL CLI rt-* operations (failed to get ifindex)"

Also FAIL -> SKIP ?

Quoted 2 lines
tools/net/ynl/tests/test_ynl_cli.sh new file +2 -0
+		return
+	fi
#8 lore raw

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

Quoted 35 lines · Donald Hunter
Quoted 13 lines
tools/net/ynl/tests/Makefile new file +7 -0
new file mode 100644
index 000000000000..4d527f9c3de9
@@ -0,0 +1,38 @@
+# SPDX-License-Identifier: GPL-2.0
+# Makefile for YNL tests
+
+TESTS := \
+	test_ynl_cli.sh \
+	test_ynl_ethtool.sh \
+# end of TESTS

tools/net/ynl/tests/Makefile line 17

Quoted 10 lines
tools/net/ynl/tests/Makefile new file +10 -0
+
+all: $(TESTS)
+
+run_tests:
+	@echo "Running YNL tests..."
+	@failed=0; \
+	echo "Running test_ynl_cli.sh..."; \
+	./test_ynl_cli.sh || failed=$$(($$failed + 1)); \
+	echo "Running test_ynl_ethtool.sh..."; \
+	./test_ynl_ethtool.sh || failed=$$(($$failed + 1)); \

This could iterate through $(TESTS) instead of being hard coded.

tools/net/ynl/tests/Makefile line 21

Quoted 4 lines
tools/net/ynl/tests/Makefile new file +4 -0
+	if [ $$failed -eq 0 ]; then \
+		echo "All tests passed!"; \
+	else \
+		echo "$$failed test(s) failed!"; \

AFAICS this will never be reported since the scripts only ever exit 0. The message is also a bit misleading since it would be the count of scripts that failed, not individual tests.

Quoted 2 lines

It would be great if the scripts exited with the number of test failures so the make file could report a total.

Yes, indeed, I will fix it. Thanks!

Quoted 11 lines

tools/net/ynl/tests/Makefile line 29

Quoted 8 lines
tools/net/ynl/tests/Makefile new file +8 -0
+# Test netdev family operations (dev-get, queue-get)
+cli_netdev_ops() {
+	local dev_output
+	local ifindex
+
+	ifindex=$(ip netns exec "$testns" cat /sys/class/net/"$NSIM_DEV_NAME"/ifindex 2>/dev/null)
+	if [[ -z "$ifindex" ]]; then
+		echo "FAIL: YNL CLI netdev operations (failed to get ifindex)"

This is a bit misleading, there's no ynl command here so I don't think it should be a FAIL. Can we just report SKIP when it is an infra issue?

The test reported SKIP for infra issue in setup() function. Here the netdevsim device has already setup. The ifindex should be there. Maybe I should use ip cmd to get the ifindex number and skip this checking.

Quoted 7 lines
Quoted 7 lines
tools/net/ynl/tests/Makefile new file +7 -0
+
+# Test rt-* family operations (route, addr, link, neigh, rule)
+cli_rt_ops() {
+	local ifindex
+
+	if ! $ynl --list-families 2>/dev/null | grep -q "rt-"; then
+		echo "SKIP: YNL CLI rt-* operations (no rt-* families available)"
Quoted 8 lines

tools/net/ynl/tests/Makefile

Quoted 6 lines
tools/net/ynl/tests/Makefile new file +6 -0
+		return
+	fi
+
+	ifindex=$(ip netns exec "$testns" cat /sys/class/net/"$NSIM_DEV_NAME"/ifindex 2>/dev/null)
+	if [[ -z "$ifindex" ]]; then
+		echo "FAIL: YNL CLI rt-* operations (failed to get ifindex)"

Also FAIL -> SKIP ?

Same here, the dev has created, I will remove this checking.

Thanks
Hangbin

#9 lore raw

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

In reply to Donald Hunter
Quoted 35 lines · Donald Hunter
Quoted 13 lines
tools/net/ynl/tests/Makefile new file +7 -0
new file mode 100644
index 000000000000..4d527f9c3de9
@@ -0,0 +1,38 @@
+# SPDX-License-Identifier: GPL-2.0
+# Makefile for YNL tests
+
+TESTS := \
+	test_ynl_cli.sh \
+	test_ynl_ethtool.sh \
+# end of TESTS

tools/net/ynl/tests/Makefile line 17

Quoted 10 lines
tools/net/ynl/tests/Makefile new file +10 -0
+
+all: $(TESTS)
+
+run_tests:
+	@echo "Running YNL tests..."
+	@failed=0; \
+	echo "Running test_ynl_cli.sh..."; \
+	./test_ynl_cli.sh || failed=$$(($$failed + 1)); \
+	echo "Running test_ynl_ethtool.sh..."; \
+	./test_ynl_ethtool.sh || failed=$$(($$failed + 1)); \

This could iterate through $(TESTS) instead of being hard coded.

tools/net/ynl/tests/Makefile line 21

Quoted 4 lines
tools/net/ynl/tests/Makefile new file +4 -0
+	if [ $$failed -eq 0 ]; then \
+		echo "All tests passed!"; \
+	else \
+		echo "$$failed test(s) failed!"; \

AFAICS this will never be reported since the scripts only ever exit 0. The message is also a bit misleading since it would be the count of scripts that failed, not individual tests.

Quoted 2 lines

It would be great if the scripts exited with the number of test failures so the make file could report a total.

Oh, BTW, do you think if we should exit with the failed test number or just report failed number in test and exit 1. i.e.

Option 1:

test 1 (pass)
test 2 (fail)
test 3 (fail)
exit 2

Option 2:

test 1 (pass)
test 2 (fail)
test 3 (fail)
echo "2 test failed"
exit 1

With Option 1, we will summary all the failure number in the Makefile. With Option 2, we will report failure number in each test, and report failed *test script* number in Makefile.

Thanks
Hangbin

#10 lore raw

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

Hi Hangbin,

Quoted 36 lines · Hangbin Liu
Quoted 35 lines · Donald Hunter
Quoted 13 lines
tools/net/ynl/tests/Makefile new file +7 -0
new file mode 100644
index 000000000000..4d527f9c3de9
@@ -0,0 +1,38 @@
+# SPDX-License-Identifier: GPL-2.0
+# Makefile for YNL tests
+
+TESTS := \
+	test_ynl_cli.sh \
+	test_ynl_ethtool.sh \
+# end of TESTS

tools/net/ynl/tests/Makefile line 17

Quoted 10 lines
tools/net/ynl/tests/Makefile new file +10 -0
+
+all: $(TESTS)
+
+run_tests:
+	@echo "Running YNL tests..."
+	@failed=0; \
+	echo "Running test_ynl_cli.sh..."; \
+	./test_ynl_cli.sh || failed=$$(($$failed + 1)); \
+	echo "Running test_ynl_ethtool.sh..."; \
+	./test_ynl_ethtool.sh || failed=$$(($$failed + 1)); \

This could iterate through $(TESTS) instead of being hard coded.

tools/net/ynl/tests/Makefile line 21

Quoted 4 lines
tools/net/ynl/tests/Makefile new file +4 -0
+	if [ $$failed -eq 0 ]; then \
+		echo "All tests passed!"; \
+	else \
+		echo "$$failed test(s) failed!"; \

AFAICS this will never be reported since the scripts only ever exit 0. The message is also a bit misleading since it would be the count of scripts that failed, not individual tests.

Quoted 4 lines
Quoted 2 lines

It would be great if the scripts exited with the number of test failures so the make file could report a total.

Oh, BTW, do you think if we should exit with the failed test number or just

I know these new tests are not in the selftests, but maybe "safer" to keep the same exit code to avoid being misinterpreted?

KSFT_PASS=0
KSFT_FAIL=1
KSFT_XFAIL=2
KSFT_XPASS=3
KSFT_SKIP=4

If there is a need to know which tests have failed, why not using (K)TAP format for the output?

Cheers,
Matt

Signature · 1 line
Sponsored by the NGI0 Core fund.
#11 lore raw

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

Quoted 14 lines · Matthieu Baerts
Quoted 9 lines
Quoted 9 lines

tools/net/ynl/tests/Makefile line 21

Quoted 4 lines
tools/net/ynl/tests/Makefile new file +4 -0
+	if [ $$failed -eq 0 ]; then \
+		echo "All tests passed!"; \
+	else \
+		echo "$$failed test(s) failed!"; \

AFAICS this will never be reported since the scripts only ever exit 0. The message is also a bit misleading since it would be the count of scripts that failed, not individual tests.

Quoted 4 lines
Quoted 2 lines

It would be great if the scripts exited with the number of test failures so the make file could report a total.

Oh, BTW, do you think if we should exit with the failed test number or just

Quoted 8 lines

I know these new tests are not in the selftests, but maybe "safer" to keep the same exit code to avoid being misinterpreted?

KSFT_PASS=0
KSFT_FAIL=1
KSFT_XFAIL=2
KSFT_XPASS=3
KSFT_SKIP=4

Yes, that's why I ask about the return code. I also prefer use the same exit code with selftest.

Quoted 3 lines

If there is a need to know which tests have failed, why not using (K)TAP format for the output?

I feel it's too heavy to copy the (K)TAP format here. I would just using the exit code unless Jakub ask to using the specific output format

Thanks
Hangbin

#12 lore raw

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

Quoted 18 lines · Hangbin Liu
Quoted 17 lines · Matthieu Baerts
Quoted 9 lines
Quoted 9 lines

tools/net/ynl/tests/Makefile line 21

Quoted 4 lines
tools/net/ynl/tests/Makefile new file +4 -0
+	if [ $$failed -eq 0 ]; then \
+		echo "All tests passed!"; \
+	else \
+		echo "$$failed test(s) failed!"; \

AFAICS this will never be reported since the scripts only ever exit 0. The message is also a bit misleading since it would be the count of scripts that failed, not individual tests.

Quoted 4 lines
Quoted 2 lines

It would be great if the scripts exited with the number of test failures so the make file could report a total.

Oh, BTW, do you think if we should exit with the failed test number or just

I know these new tests are not in the selftests, but maybe "safer" to keep the same exit code to avoid being misinterpreted?

Quoted 8 lines
Quoted 5 lines

KSFT_PASS=0
KSFT_FAIL=1
KSFT_XFAIL=2
KSFT_XPASS=3
KSFT_SKIP=4

Yes, that's why I ask about the return code. I also prefer use the same exit code with selftest.

Should you then exit with rc=4 instead of 0 in case of SKIP?

Quoted 5 lines
Quoted 2 lines

If there is a need to know which tests have failed, why not using (K)TAP format for the output?

I feel it's too heavy to copy the (K)TAP format here. I would just using the exit code unless Jakub ask to using the specific output format

OK, I thought it was just a question of changing your 'echo' from "PASS" and "FAIL" to "(not )ok ${COUNTER} (...)" + print the header and the number of tests. But sure, if this format is not needed, no need to bother.

Cheers,
Matt

Signature · 1 line
Sponsored by the NGI0 Core fund.
#13 lore raw

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

Quoted 9 lines · Matthieu Baerts
Quoted 9 lines
Quoted 8 lines

I know these new tests are not in the selftests, but maybe "safer" to keep the same exit code to avoid being misinterpreted?

KSFT_PASS=0
KSFT_FAIL=1
KSFT_XFAIL=2
KSFT_XPASS=3
KSFT_SKIP=4

Quoted 4 lines
Quoted 2 lines

Yes, that's why I ask about the return code. I also prefer use the same exit code with selftest.

Should you then exit with rc=4 instead of 0 in case of SKIP?

Sure

Quoted 10 lines
Quoted 6 lines
Quoted 3 lines

If there is a need to know which tests have failed, why not using (K)TAP format for the output?

I feel it's too heavy to copy the (K)TAP format here. I would just using the exit code unless Jakub ask to using the specific output format

OK, I thought it was just a question of changing your 'echo' from "PASS" and "FAIL" to "(not )ok ${COUNTER} (...)" + print the header and the number of tests. But sure, if this format is not needed, no need to bother.

Oh, this looks reasonable. I will try add a helper for the output.

Thanks
Hangbin

#14 lore raw

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

Quoted 1 line · Hangbin Liu

On Thu, Nov 13, 2025 at 10:59:49AM +0100, Matthieu Baerts wrote:

(...)

Quoted 11 lines
Quoted 9 lines
Quoted 5 lines
Quoted 2 lines

If there is a need to know which tests have failed, why not using (K)TAP format for the output?

I feel it's too heavy to copy the (K)TAP format here. I would just using the exit code unless Jakub ask to using the specific output format

OK, I thought it was just a question of changing your 'echo' from "PASS" and "FAIL" to "(not )ok ${COUNTER} (...)" + print the header and the number of tests. But sure, if this format is not needed, no need to bother.

Oh, this looks reasonable. I will try add a helper for the output.

I don't know if it is a good idea for these tests, but maybe you can use existing ones from tools/testing/selftests/kselftest/ktap_helpers.sh?

Cheers,
Matt

Signature · 1 line
Sponsored by the NGI0 Core fund.