* [PATCHv4 net-next 0/3] Add YNL test framework and library improvements
@ 2025-11-14 3:46 Hangbin Liu
2025-11-14 3:46 ` [PATCHv4 net-next 1/3] tools: ynl: Add MAC address parsing support Hangbin Liu
` (2 more replies)
0 siblings, 3 replies; 9+ messages in thread
From: Hangbin Liu @ 2025-11-14 3:46 UTC (permalink / raw)
To: netdev
Cc: Donald Hunter, Jakub Kicinski, David S. Miller, Eric Dumazet,
Paolo Abeni, Simon Horman, Jan Stancek, Matthieu Baerts (NGI0),
Asbjørn Sloth Tønnesen, Stanislav Fomichev,
Ido Schimmel, Guillaume Nault, Sabrina Dubroca, Petr Machata,
Hangbin Liu
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
v4: Use KTAP helper to report the test result (Matthieu Baerts)
iterate through $(TESTS) instead of being hard coded (Donald Hunter)
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)
Link: https://lore.kernel.org/netdev/20251110100000.3837-1-liuhangbin@gmail.com
v2: move test from selftest to ynl folder (Jakub Kicinski)
Link: https://lore.kernel.org/netdev/20251105082841.165212-1-liuhangbin@gmail.com
v1: Link: https://lore.kernel.org/netdev/20251029082245.128675-1-liuhangbin@gmail.com
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 | 309 ++++++++++++++++++++++
tools/net/ynl/tests/test_ynl_ethtool.sh | 206 +++++++++++++++
14 files changed, 591 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
--
2.50.1
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCHv4 net-next 1/3] tools: ynl: Add MAC address parsing support
2025-11-14 3:46 [PATCHv4 net-next 0/3] Add YNL test framework and library improvements Hangbin Liu
@ 2025-11-14 3:46 ` Hangbin Liu
2025-11-14 3:46 ` [PATCHv4 net-next 2/3] netlink: specs: support ipv4-or-v6 for dual-stack fields Hangbin Liu
2025-11-14 3:46 ` [PATCHv4 net-next 3/3] tools: ynl: add YNL test framework Hangbin Liu
2 siblings, 0 replies; 9+ messages in thread
From: Hangbin Liu @ 2025-11-14 3:46 UTC (permalink / raw)
To: netdev
Cc: Donald Hunter, Jakub Kicinski, David S. Miller, Eric Dumazet,
Paolo Abeni, Simon Horman, Jan Stancek, Matthieu Baerts (NGI0),
Asbjørn Sloth Tønnesen, Stanislav Fomichev,
Ido Schimmel, Guillaume Nault, Sabrina Dubroca, Petr Machata,
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.
Reviewed-by: Donald Hunter <donald.hunter@gmail.com>
Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
---
tools/net/ynl/pyynl/lib/ynl.py | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/tools/net/ynl/pyynl/lib/ynl.py b/tools/net/ynl/pyynl/lib/ynl.py
index 225baad3c8f8..36d36eb7e3b8 100644
--- a/tools/net/ynl/pyynl/lib/ynl.py
+++ b/tools/net/ynl/pyynl/lib/ynl.py
@@ -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']}'")
--
2.50.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCHv4 net-next 2/3] netlink: specs: support ipv4-or-v6 for dual-stack fields
2025-11-14 3:46 [PATCHv4 net-next 0/3] Add YNL test framework and library improvements Hangbin Liu
2025-11-14 3:46 ` [PATCHv4 net-next 1/3] tools: ynl: Add MAC address parsing support Hangbin Liu
@ 2025-11-14 3:46 ` Hangbin Liu
2025-11-14 3:46 ` [PATCHv4 net-next 3/3] tools: ynl: add YNL test framework Hangbin Liu
2 siblings, 0 replies; 9+ messages in thread
From: Hangbin Liu @ 2025-11-14 3:46 UTC (permalink / raw)
To: netdev
Cc: Donald Hunter, Jakub Kicinski, David S. Miller, Eric Dumazet,
Paolo Abeni, Simon Horman, Jan Stancek, Matthieu Baerts (NGI0),
Asbjørn Sloth Tønnesen, Stanislav Fomichev,
Ido Schimmel, Guillaume Nault, Sabrina Dubroca, Petr Machata,
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
Reviewed-by: Asbjørn Sloth Tønnesen <ast@fiberby.net>
Reviewed-by: Donald Hunter <donald.hunter@gmail.com>
Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
---
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(-)
diff --git a/Documentation/netlink/genetlink-c.yaml b/Documentation/netlink/genetlink-c.yaml
index 5a234e9b5fa2..57f59fe23e3f 100644
--- a/Documentation/netlink/genetlink-c.yaml
+++ b/Documentation/netlink/genetlink-c.yaml
@@ -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
diff --git a/Documentation/netlink/genetlink.yaml b/Documentation/netlink/genetlink.yaml
index 7b1ec153e834..b020a537d8ac 100644
--- a/Documentation/netlink/genetlink.yaml
+++ b/Documentation/netlink/genetlink.yaml
@@ -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:
diff --git a/Documentation/netlink/netlink-raw.yaml b/Documentation/netlink/netlink-raw.yaml
index 246fa07bccf6..0166a7e4afbb 100644
--- a/Documentation/netlink/netlink-raw.yaml
+++ b/Documentation/netlink/netlink-raw.yaml
@@ -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
diff --git a/Documentation/netlink/specs/rt-addr.yaml b/Documentation/netlink/specs/rt-addr.yaml
index 3a582eac1629..abcbaa73fa9d 100644
--- a/Documentation/netlink/specs/rt-addr.yaml
+++ b/Documentation/netlink/specs/rt-addr.yaml
@@ -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
diff --git a/Documentation/netlink/specs/rt-link.yaml b/Documentation/netlink/specs/rt-link.yaml
index e07341582771..ca22c68ca691 100644
--- a/Documentation/netlink/specs/rt-link.yaml
+++ b/Documentation/netlink/specs/rt-link.yaml
@@ -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
diff --git a/Documentation/netlink/specs/rt-neigh.yaml b/Documentation/netlink/specs/rt-neigh.yaml
index 2f568a6231c9..0f46ef313590 100644
--- a/Documentation/netlink/specs/rt-neigh.yaml
+++ b/Documentation/netlink/specs/rt-neigh.yaml
@@ -194,7 +194,7 @@ attribute-sets:
-
name: dst
type: binary
- display-hint: ipv4
+ display-hint: ipv4-or-v6
-
name: lladdr
type: binary
diff --git a/Documentation/netlink/specs/rt-route.yaml b/Documentation/netlink/specs/rt-route.yaml
index 1ecb3fadc067..33195db96746 100644
--- a/Documentation/netlink/specs/rt-route.yaml
+++ b/Documentation/netlink/specs/rt-route.yaml
@@ -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
diff --git a/Documentation/netlink/specs/rt-rule.yaml b/Documentation/netlink/specs/rt-rule.yaml
index bebee452a950..7f03a44ab036 100644
--- a/Documentation/netlink/specs/rt-rule.yaml
+++ b/Documentation/netlink/specs/rt-rule.yaml
@@ -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
--
2.50.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCHv4 net-next 3/3] tools: ynl: add YNL test framework
2025-11-14 3:46 [PATCHv4 net-next 0/3] Add YNL test framework and library improvements Hangbin Liu
2025-11-14 3:46 ` [PATCHv4 net-next 1/3] tools: ynl: Add MAC address parsing support Hangbin Liu
2025-11-14 3:46 ` [PATCHv4 net-next 2/3] netlink: specs: support ipv4-or-v6 for dual-stack fields Hangbin Liu
@ 2025-11-14 3:46 ` Hangbin Liu
2025-11-14 11:46 ` Donald Hunter
2025-11-14 18:00 ` Matthieu Baerts
2 siblings, 2 replies; 9+ messages in thread
From: Hangbin Liu @ 2025-11-14 3:46 UTC (permalink / raw)
To: netdev
Cc: Donald Hunter, Jakub Kicinski, David S. Miller, Eric Dumazet,
Paolo Abeni, Simon Horman, Jan Stancek, Matthieu Baerts (NGI0),
Asbjørn Sloth Tønnesen, Stanislav Fomichev,
Ido Schimmel, Guillaume Nault, Sabrina Dubroca, Petr Machata,
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.
Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
---
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 | 309 ++++++++++++++++++++++++
tools/net/ynl/tests/test_ynl_ethtool.sh | 206 ++++++++++++++++
5 files changed, 559 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
diff --git a/tools/net/ynl/Makefile b/tools/net/ynl/Makefile
index 31ed20c0f3f8..a40591e513b7 100644
--- a/tools/net/ynl/Makefile
+++ b/tools/net/ynl/Makefile
@@ -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)
diff --git a/tools/net/ynl/tests/Makefile b/tools/net/ynl/tests/Makefile
new file mode 100644
index 000000000000..38161217e249
--- /dev/null
+++ b/tools/net/ynl/tests/Makefile
@@ -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
diff --git a/tools/net/ynl/tests/config b/tools/net/ynl/tests/config
new file mode 100644
index 000000000000..339f1309c03f
--- /dev/null
+++ b/tools/net/ynl/tests/config
@@ -0,0 +1,6 @@
+CONFIG_DUMMY=m
+CONFIG_INET_DIAG=y
+CONFIG_IPV6=y
+CONFIG_NET_NS=y
+CONFIG_NETDEVSIM=m
+CONFIG_VETH=m
diff --git a/tools/net/ynl/tests/test_ynl_cli.sh b/tools/net/ynl/tests/test_ynl_cli.sh
new file mode 100755
index 000000000000..f40eecbb9701
--- /dev/null
+++ b/tools/net/ynl/tests/test_ynl_cli.sh
@@ -0,0 +1,309 @@
+#!/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 disable=SC1090
+source "$KSELFTEST_KTAP_HELPERS"
+
+# 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
+ ktap_test_pass "YNL CLI list families"
+ else
+ ktap_test_fail "YNL CLI list families"
+ fi
+}
+
+# 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)
+
+ 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
+ ktap_test_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
+ ktap_test_fail "YNL CLI netdev operations (failed to get netdev queue info)"
+ return
+ fi
+
+ ktap_test_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
+ ktap_test_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
+ ktap_test_fail "YNL CLI ethtool operations (ethtool linkinfo-get output missing header)"
+ return
+ fi
+
+ ktap_test_pass "YNL CLI ethtool operations"
+}
+
+# Test rt-route family operations
+cli_rt_route_ops() {
+ local ifindex
+
+ if ! $ynl --list-families 2>/dev/null | grep -q "rt-route"; then
+ ktap_test_skip "YNL CLI rt-route operations (rt-route family not available)"
+ return
+ fi
+
+ ifindex=$(ip netns exec "$testns" cat /sys/class/net/"$NSIM_DEV_NAME"/ifindex 2>/dev/null)
+
+ # Add route: 192.0.2.0/24 dev $dev scope link
+ if ! ip netns exec "$testns" $ynl --family rt-route --do newroute --create \
+ --json "{\"dst\": \"192.0.2.0\", \"oif\": $ifindex, \"rtm-dst-len\": 24, \"rtm-family\": 2, \"rtm-scope\": 253, \"rtm-type\": 1, \"rtm-protocol\": 3, \"rtm-table\": 254}" &>/dev/null; then
+ ktap_test_fail "YNL CLI rt-route operations (failed to add route)"
+ return
+ fi
+
+ local route_output
+ route_output=$(ip netns exec "$testns" $ynl --family rt-route --dump getroute 2>/dev/null)
+ if echo "$route_output" | grep -q "192.0.2.0"; then
+ ktap_test_pass "YNL CLI rt-route operations"
+ else
+ ktap_test_fail "YNL CLI rt-route operations (failed to verify route)"
+ fi
+
+ ip netns exec "$testns" $ynl --family rt-route --do delroute \
+ --json "{\"dst\": \"192.0.2.0\", \"oif\": $ifindex, \"rtm-dst-len\": 24, \"rtm-family\": 2, \"rtm-scope\": 253, \"rtm-type\": 1, \"rtm-protocol\": 3, \"rtm-table\": 254}" &>/dev/null
+}
+
+# Test rt-addr family operations
+cli_rt_addr_ops() {
+ local ifindex
+
+ if ! $ynl --list-families 2>/dev/null | grep -q "rt-addr"; then
+ ktap_test_skip "YNL CLI rt-addr operations (rt-addr family not available)"
+ return
+ fi
+
+ ifindex=$(ip netns exec "$testns" cat /sys/class/net/"$NSIM_DEV_NAME"/ifindex 2>/dev/null)
+
+ if ! ip netns exec "$testns" $ynl --family rt-addr --do newaddr \
+ --json "{\"ifa-index\": $ifindex, \"local\": \"192.0.2.100\", \"ifa-prefixlen\": 24, \"ifa-family\": 2}" &>/dev/null; then
+ ktap_test_fail "YNL CLI rt-addr operations (failed to add address)"
+ return
+ fi
+
+ local addr_output
+ addr_output=$(ip netns exec "$testns" $ynl --family rt-addr --dump getaddr 2>/dev/null)
+ if echo "$addr_output" | grep -q "192.0.2.100"; then
+ ktap_test_pass "YNL CLI rt-addr operations"
+ else
+ ktap_test_fail "YNL CLI rt-addr operations (failed to verify address)"
+ fi
+
+ ip netns exec "$testns" $ynl --family rt-addr --do deladdr \
+ --json "{\"ifa-index\": $ifindex, \"local\": \"192.0.2.100\", \"ifa-prefixlen\": 24, \"ifa-family\": 2}" &>/dev/null
+}
+
+# Test rt-link family operations
+cli_rt_link_ops() {
+ if ! $ynl --list-families 2>/dev/null | grep -q "rt-link"; then
+ ktap_test_skip "YNL CLI rt-link operations (rt-link family not available)"
+ return
+ fi
+
+ if ! ip netns exec "$testns" $ynl --family rt-link --do newlink --create \
+ --json "{\"ifname\": \"dummy0\", \"linkinfo\": {\"kind\": \"dummy\"}}" &>/dev/null; then
+ ktap_test_fail "YNL CLI rt-link operations (failed to add link)"
+ return
+ fi
+
+ local link_output
+ link_output=$(ip netns exec "$testns" $ynl --family rt-link --dump getlink 2>/dev/null)
+ if echo "$link_output" | grep -q "$NSIM_DEV_NAME" && echo "$link_output" | grep -q "dummy0"; then
+ ktap_test_pass "YNL CLI rt-link operations"
+ else
+ ktap_test_fail "YNL CLI rt-link operations (failed to verify link)"
+ fi
+
+ ip netns exec "$testns" $ynl --family rt-link --do dellink \
+ --json "{\"ifname\": \"dummy0\"}" &>/dev/null
+}
+
+# Test rt-neigh family operations
+cli_rt_neigh_ops() {
+ local ifindex
+
+ if ! $ynl --list-families 2>/dev/null | grep -q "rt-neigh"; then
+ ktap_test_skip "YNL CLI rt-neigh operations (rt-neigh family not available)"
+ return
+ fi
+
+ ifindex=$(ip netns exec "$testns" cat /sys/class/net/"$NSIM_DEV_NAME"/ifindex 2>/dev/null)
+
+ # Add neighbor: 192.0.2.1 dev nsim1338 lladdr 11:22:33:44:55:66 PERMANENT
+ if ! ip netns exec "$testns" $ynl --family rt-neigh --do newneigh --create \
+ --json "{\"ndm-ifindex\": $ifindex, \"dst\": \"192.0.2.1\", \"lladdr\": \"11:22:33:44:55:66\", \"ndm-family\": 2, \"ndm-state\": 128}" &>/dev/null; then
+ ktap_test_fail "YNL CLI rt-neigh operations (failed to add neighbor)"
+ fi
+
+ local neigh_output
+ neigh_output=$(ip netns exec "$testns" $ynl --family rt-neigh --dump getneigh 2>/dev/null)
+ if echo "$neigh_output" | grep -q "192.0.2.1"; then
+ ktap_test_pass "YNL CLI rt-neigh operations"
+ else
+ ktap_test_fail "YNL CLI rt-neigh operations (failed to verify neighbor)"
+ fi
+
+ ip netns exec "$testns" $ynl --family rt-neigh --do delneigh \
+ --json "{\"ndm-ifindex\": $ifindex, \"dst\": \"192.0.2.1\", \"lladdr\": \"11:22:33:44:55:66\", \"ndm-family\": 2}" &>/dev/null
+}
+
+# Test rt-rule family operations
+cli_rt_rule_ops() {
+ if ! $ynl --list-families 2>/dev/null | grep -q "rt-rule"; then
+ ktap_test_skip "YNL CLI rt-rule operations (rt-rule family not available)"
+ return
+ fi
+
+ # Add rule: from 192.0.2.0/24 lookup 100 none
+ if ! ip netns exec "$testns" $ynl --family rt-rule --do newrule \
+ --json "{\"family\": 2, \"src-len\": 24, \"src\": \"192.0.2.0\", \"table\": 100}" &>/dev/null; then
+ ktap_test_fail "YNL CLI rt-rule operations (failed to add rule)"
+ return
+ fi
+
+ local rule_output
+ rule_output=$(ip netns exec "$testns" $ynl --family rt-rule --dump getrule 2>/dev/null)
+ if echo "$rule_output" | grep -q "192.0.2.0"; then
+ ktap_test_pass "YNL CLI rt-rule operations"
+ else
+ ktap_test_fail "YNL CLI rt-rule operations (failed to verify rule)"
+ fi
+
+ ip netns exec "$testns" $ynl --family rt-rule --do delrule \
+ --json "{\"family\": 2, \"src-len\": 24, \"src\": \"192.0.2.0\", \"table\": 100}" &>/dev/null
+}
+
+# Test nlctrl family operations
+cli_nlctrl_ops() {
+ local family_output
+
+ if ! family_output=$($ynl --family nlctrl \
+ --do getfamily --json "{\"family-name\": \"netdev\"}" 2>/dev/null); then
+ ktap_test_fail "YNL CLI nlctrl getfamily (failed to get nlctrl family info)"
+ return
+ fi
+
+ if ! echo "$family_output" | grep -q "family-name"; then
+ ktap_test_fail "YNL CLI nlctrl getfamily (nlctrl getfamily output missing family-name)"
+ return
+ fi
+
+ if ! echo "$family_output" | grep -q "family-id"; then
+ ktap_test_fail "YNL CLI nlctrl getfamily (nlctrl getfamily output missing family-id)"
+ return
+ fi
+
+ ktap_test_pass "YNL CLI nlctrl getfamily"
+}
+
+setup() {
+ modprobe netdevsim &> /dev/null
+ if ! [ -f /sys/bus/netdevsim/new_device ]; then
+ ktap_skip_all "netdevsim module not available"
+ exit "$KSFT_SKIP"
+ fi
+
+ if ! ip netns add "$testns" 2>/dev/null; then
+ ktap_skip_all "failed to create test namespace"
+ exit "$KSFT_SKIP"
+ fi
+
+ echo "$NSIM_ID 1" | ip netns exec "$testns" tee /sys/bus/netdevsim/new_device >/dev/null 2>&1 || {
+ ktap_skip_all "failed to create netdevsim device"
+ exit "$KSFT_SKIP"
+ }
+
+ local dev
+ dev=$(ip netns exec "$testns" ls /sys/bus/netdevsim/devices/netdevsim$NSIM_ID/net 2>/dev/null | head -1)
+ if [[ -z "$dev" ]]; then
+ ktap_skip_all "failed to find netdevsim device"
+ exit "$KSFT_SKIP"
+ fi
+
+ ip -netns "$testns" link set dev "$dev" name "$NSIM_DEV_NAME" 2>/dev/null || {
+ ktap_skip_all "failed to rename netdevsim device"
+ exit "$KSFT_SKIP"
+ }
+
+ ip -netns "$testns" link set dev "$NSIM_DEV_NAME" up 2>/dev/null
+
+ if ! ip -n "$testns" link add "$VETH_A" type veth peer name "$VETH_B" 2>/dev/null; then
+ ktap_skip_all "failed to create veth pair"
+ exit "$KSFT_SKIP"
+ fi
+
+ ip -n "$testns" link set "$VETH_A" up 2>/dev/null
+ ip -n "$testns" link set "$VETH_B" up 2>/dev/null
+}
+
+cleanup() {
+ if [[ -n "$testns" ]]; then
+ ip netns exec "$testns" bash -c "echo $NSIM_ID > /sys/bus/netdevsim/del_device" 2>/dev/null || true
+ ip netns del "$testns" 2>/dev/null || true
+ fi
+}
+
+# Check if ynl command is available
+if ! command -v $ynl &>/dev/null && [[ ! -x $ynl ]]; then
+ ktap_skip_all "ynl command not found: $ynl"
+ exit "$KSFT_SKIP"
+fi
+
+trap cleanup EXIT
+
+ktap_print_header
+ktap_set_plan 9
+setup
+
+# Run all tests
+cli_list_families
+cli_netdev_ops
+cli_ethtool_ops
+cli_rt_route_ops
+cli_rt_addr_ops
+cli_rt_link_ops
+cli_rt_neigh_ops
+cli_rt_rule_ops
+cli_nlctrl_ops
+
+ktap_finished
diff --git a/tools/net/ynl/tests/test_ynl_ethtool.sh b/tools/net/ynl/tests/test_ynl_ethtool.sh
new file mode 100755
index 000000000000..01cb9d87f7fa
--- /dev/null
+++ b/tools/net/ynl/tests/test_ynl_ethtool.sh
@@ -0,0 +1,206 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Test YNL ethtool functionality
+
+# Load KTAP test helpers
+KSELFTEST_KTAP_HELPERS="$(dirname "$(realpath "$0")")/../../../testing/selftests/kselftest/ktap_helpers.sh"
+# shellcheck disable=SC1090
+source "$KSELFTEST_KTAP_HELPERS"
+
+# Default ynl-ethtool path for direct execution, can be overridden by make install
+ynl_ethtool="../pyynl/ethtool.py"
+
+readonly NSIM_ID="1337"
+readonly NSIM_DEV_NAME="nsim${NSIM_ID}"
+readonly VETH_A="veth_a"
+readonly VETH_B="veth_b"
+
+testns="ynl-ethtool-$(mktemp -u XXXXXX)"
+
+# Uses veth device as netdevsim doesn't support basic ethtool device info
+ethtool_device_info() {
+ local info_output
+
+ info_output=$(ip netns exec "$testns" $ynl_ethtool "$VETH_A" 2>/dev/null)
+
+ if ! echo "$info_output" | grep -q "Settings for"; then
+ ktap_test_fail "YNL ethtool device info (device info output missing expected content)"
+ return
+ fi
+
+ ktap_test_pass "YNL ethtool device info"
+}
+
+ethtool_statistics() {
+ local stats_output
+
+ stats_output=$(ip netns exec "$testns" $ynl_ethtool --statistics "$NSIM_DEV_NAME" 2>/dev/null)
+
+ if ! echo "$stats_output" | grep -q -E "(NIC statistics|packets|bytes)"; then
+ ktap_test_fail "YNL ethtool statistics (statistics output missing expected content)"
+ return
+ fi
+
+ ktap_test_pass "YNL ethtool statistics"
+}
+
+ethtool_ring_params() {
+ local ring_output
+
+ ring_output=$(ip netns exec "$testns" $ynl_ethtool --show-ring "$NSIM_DEV_NAME" 2>/dev/null)
+
+ if ! echo "$ring_output" | grep -q -E "(Ring parameters|RX|TX)"; then
+ ktap_test_fail "YNL ethtool ring parameters (ring parameters output missing expected content)"
+ return
+ fi
+
+ if ! ip netns exec "$testns" $ynl_ethtool --set-ring "$NSIM_DEV_NAME" rx 64 2>/dev/null; then
+ ktap_test_fail "YNL ethtool ring parameters (set-ring command failed unexpectedly)"
+ return
+ fi
+
+ ktap_test_pass "YNL ethtool ring parameters (show/set)"
+}
+
+ethtool_coalesce_params() {
+ if ! ip netns exec "$testns" $ynl_ethtool --show-coalesce "$NSIM_DEV_NAME" &>/dev/null; then
+ ktap_test_fail "YNL ethtool coalesce parameters (failed to get coalesce parameters)"
+ return
+ fi
+
+ if ! ip netns exec "$testns" $ynl_ethtool --set-coalesce "$NSIM_DEV_NAME" rx-usecs 50 2>/dev/null; then
+ ktap_test_fail "YNL ethtool coalesce parameters (set-coalesce command failed unexpectedly)"
+ return
+ fi
+
+ ktap_test_pass "YNL ethtool coalesce parameters (show/set)"
+}
+
+ethtool_pause_params() {
+ if ! ip netns exec "$testns" $ynl_ethtool --show-pause "$NSIM_DEV_NAME" &>/dev/null; then
+ ktap_test_fail "YNL ethtool pause parameters (failed to get pause parameters)"
+ return
+ fi
+
+ if ! ip netns exec "$testns" $ynl_ethtool --set-pause "$NSIM_DEV_NAME" tx 1 rx 1 2>/dev/null; then
+ ktap_test_fail "YNL ethtool pause parameters (set-pause command failed unexpectedly)"
+ return
+ fi
+
+ ktap_test_pass "YNL ethtool pause parameters (show/set)"
+}
+
+ethtool_features_info() {
+ local features_output
+
+ features_output=$(ip netns exec "$testns" $ynl_ethtool --show-features "$NSIM_DEV_NAME" 2>/dev/null)
+
+ if ! echo "$features_output" | grep -q -E "(Features|offload)"; then
+ ktap_test_fail "YNL ethtool features info (features output missing expected content)"
+ return
+ fi
+
+ ktap_test_pass "YNL ethtool features info (show/set)"
+}
+
+ethtool_channels_info() {
+ local channels_output
+
+ channels_output=$(ip netns exec "$testns" $ynl_ethtool --show-channels "$NSIM_DEV_NAME" 2>/dev/null)
+
+ if ! echo "$channels_output" | grep -q -E "(Channel|Combined|RX|TX)"; then
+ ktap_test_fail "YNL ethtool channels info (channels output missing expected content)"
+ return
+ fi
+
+ if ! ip netns exec "$testns" $ynl_ethtool --set-channels "$NSIM_DEV_NAME" combined-count 1 2>/dev/null; then
+ ktap_test_fail "YNL ethtool channels info (set-channels command failed unexpectedly)"
+ return
+ fi
+
+ ktap_test_pass "YNL ethtool channels info (show/set)"
+}
+
+ethtool_time_stamping() {
+ local ts_output
+
+ ts_output=$(ip netns exec "$testns" $ynl_ethtool --show-time-stamping "$NSIM_DEV_NAME" 2>/dev/null)
+
+ if ! echo "$ts_output" | grep -q -E "(Time stamping|timestamping|SOF_TIMESTAMPING)"; then
+ ktap_test_fail "YNL ethtool time stamping (time stamping output missing expected content)"
+ return
+ fi
+
+ ktap_test_pass "YNL ethtool time stamping"
+}
+
+setup() {
+ modprobe netdevsim &> /dev/null
+ if ! [ -f /sys/bus/netdevsim/new_device ]; then
+ ktap_skip_all "netdevsim module not available"
+ exit "$KSFT_SKIP"
+ fi
+
+ if ! ip netns add "$testns" 2>/dev/null; then
+ ktap_skip_all "failed to create test namespace"
+ exit "$KSFT_SKIP"
+ fi
+
+ echo "$NSIM_ID 1" | ip netns exec "$testns" tee /sys/bus/netdevsim/new_device >/dev/null 2>&1 || {
+ ktap_skip_all "failed to create netdevsim device"
+ exit "$KSFT_SKIP"
+ }
+
+ local dev
+ dev=$(ip netns exec "$testns" ls /sys/bus/netdevsim/devices/netdevsim$NSIM_ID/net 2>/dev/null | head -1)
+ if [[ -z "$dev" ]]; then
+ ktap_skip_all "failed to find netdevsim device"
+ exit "$KSFT_SKIP"
+ fi
+
+ ip -netns "$testns" link set dev "$dev" name "$NSIM_DEV_NAME" 2>/dev/null || {
+ ktap_skip_all "failed to rename netdevsim device"
+ exit "$KSFT_SKIP"
+ }
+
+ ip -netns "$testns" link set dev "$NSIM_DEV_NAME" up 2>/dev/null
+
+ if ! ip -n "$testns" link add "$VETH_A" type veth peer name "$VETH_B" 2>/dev/null; then
+ ktap_skip_all "failed to create veth pair"
+ exit "$KSFT_SKIP"
+ fi
+
+ ip -n "$testns" link set "$VETH_A" up 2>/dev/null
+ ip -n "$testns" link set "$VETH_B" up 2>/dev/null
+}
+
+cleanup() {
+ if [[ -n "$testns" ]]; then
+ ip netns exec "$testns" bash -c "echo $NSIM_ID > /sys/bus/netdevsim/del_device" 2>/dev/null || true
+ ip netns del "$testns" 2>/dev/null || true
+ fi
+}
+
+# Check if ynl-ethtool command is available
+if ! command -v $ynl_ethtool &>/dev/null && [[ ! -x $ynl_ethtool ]]; then
+ ktap_skip_all "ynl-ethtool command not found: $ynl_ethtool"
+ exit "$KSFT_SKIP"
+fi
+
+trap cleanup EXIT
+
+ktap_print_header
+ktap_set_plan 8
+setup
+
+# Run all tests
+ethtool_device_info
+ethtool_statistics
+ethtool_ring_params
+ethtool_coalesce_params
+ethtool_pause_params
+ethtool_features_info
+ethtool_channels_info
+ethtool_time_stamping
+
+ktap_finished
--
2.50.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCHv4 net-next 3/3] tools: ynl: add YNL test framework
2025-11-14 3:46 ` [PATCHv4 net-next 3/3] tools: ynl: add YNL test framework Hangbin Liu
@ 2025-11-14 11:46 ` Donald Hunter
2025-11-14 18:04 ` Matthieu Baerts
2025-11-14 18:00 ` Matthieu Baerts
1 sibling, 1 reply; 9+ messages in thread
From: Donald Hunter @ 2025-11-14 11:46 UTC (permalink / raw)
To: Hangbin Liu
Cc: netdev, Jakub Kicinski, David S. Miller, Eric Dumazet,
Paolo Abeni, Simon Horman, Jan Stancek, Matthieu Baerts (NGI0),
Asbjørn Sloth Tønnesen, Stanislav Fomichev,
Ido Schimmel, Guillaume Nault, Sabrina Dubroca, Petr Machata
Hangbin Liu <liuhangbin@gmail.com> writes:
>
> +cleanup() {
> + if [[ -n "$testns" ]]; then
> + ip netns exec "$testns" bash -c "echo $NSIM_ID > /sys/bus/netdevsim/del_device" 2>/dev/null || true
> + ip netns del "$testns" 2>/dev/null || true
> + fi
> +}
> +
> +# Check if ynl command is available
> +if ! command -v $ynl &>/dev/null && [[ ! -x $ynl ]]; then
> + ktap_skip_all "ynl command not found: $ynl"
> + exit "$KSFT_SKIP"
> +fi
> +
> +trap cleanup EXIT
> +
> +ktap_print_header
> +ktap_set_plan 9
> +setup
> +
> +# Run all tests
> +cli_list_families
> +cli_netdev_ops
> +cli_ethtool_ops
> +cli_rt_route_ops
> +cli_rt_addr_ops
> +cli_rt_link_ops
> +cli_rt_neigh_ops
> +cli_rt_rule_ops
> +cli_nlctrl_ops
> +
> +ktap_finished
minor nit: ktap_finished should probably be in the 'cleanup' trap handler
> +cleanup() {
> + if [[ -n "$testns" ]]; then
> + ip netns exec "$testns" bash -c "echo $NSIM_ID > /sys/bus/netdevsim/del_device" 2>/dev/null || true
> + ip netns del "$testns" 2>/dev/null || true
> + fi
> +}
> +
> +# Check if ynl-ethtool command is available
> +if ! command -v $ynl_ethtool &>/dev/null && [[ ! -x $ynl_ethtool ]]; then
> + ktap_skip_all "ynl-ethtool command not found: $ynl_ethtool"
> + exit "$KSFT_SKIP"
> +fi
> +
> +trap cleanup EXIT
> +
> +ktap_print_header
> +ktap_set_plan 8
> +setup
> +
> +# Run all tests
> +ethtool_device_info
> +ethtool_statistics
> +ethtool_ring_params
> +ethtool_coalesce_params
> +ethtool_pause_params
> +ethtool_features_info
> +ethtool_channels_info
> +ethtool_time_stamping
> +
> +ktap_finished
And here.
Otherwise LGTM.
Reviewed-by: Donald Hunter <donald.hunter@gmail.com>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCHv4 net-next 3/3] tools: ynl: add YNL test framework
2025-11-14 3:46 ` [PATCHv4 net-next 3/3] tools: ynl: add YNL test framework Hangbin Liu
2025-11-14 11:46 ` Donald Hunter
@ 2025-11-14 18:00 ` Matthieu Baerts
1 sibling, 0 replies; 9+ messages in thread
From: Matthieu Baerts @ 2025-11-14 18:00 UTC (permalink / raw)
To: Hangbin Liu, netdev
Cc: Donald Hunter, Jakub Kicinski, David S. Miller, Eric Dumazet,
Paolo Abeni, Simon Horman, Jan Stancek,
Asbjørn Sloth Tønnesen, Stanislav Fomichev,
Ido Schimmel, Guillaume Nault, Sabrina Dubroca, Petr Machata
Hi Hangbin,
On 14/11/2025 04:46, 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.
Thank you for the new version!
I have two minor comments, up to you to fix that or not.
(...)
> diff --git a/tools/net/ynl/tests/test_ynl_cli.sh b/tools/net/ynl/tests/test_ynl_cli.sh
> new file mode 100755
> index 000000000000..f40eecbb9701
> --- /dev/null
> +++ b/tools/net/ynl/tests/test_ynl_cli.sh
> @@ -0,0 +1,309 @@
> +#!/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 disable=SC1090
nit: maybe you can use this instead?
# shellcheck source=../../../testing/selftests/kselftest/ktap_helpers.sh
(If not, it might be good to always document why something is disabled
by adding a comment on the same line or before.)
(Same for the other test.)
(...)
> +ktap_print_header
> +ktap_set_plan 9
I think you should print the plan after the setup, to avoid this in case
of errors during the setup:
TAP version 13
1..9
1..0 # SKIP (...)
<exit 4>
Note that it might be interesting to add a dedicated variable for the
tests counter that you increment after having declared each test, just
not to forget modifying the plan when a new test is added, e.g.
TESTS_NO=0
(...)
cli_list_families() {
(...)
}
TESTS_NO=$((TESTS_NO + 1))
(...)
# Run all tests
ktap_set_plan "${TESTS_NO}"
cli_list_families
(...)
(Same for the other test.)
Cheers,
Matt
--
Sponsored by the NGI0 Core fund.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCHv4 net-next 3/3] tools: ynl: add YNL test framework
2025-11-14 11:46 ` Donald Hunter
@ 2025-11-14 18:04 ` Matthieu Baerts
2025-11-16 10:38 ` Donald Hunter
0 siblings, 1 reply; 9+ messages in thread
From: Matthieu Baerts @ 2025-11-14 18:04 UTC (permalink / raw)
To: Donald Hunter, Hangbin Liu
Cc: netdev, Jakub Kicinski, David S. Miller, Eric Dumazet,
Paolo Abeni, Simon Horman, Jan Stancek,
Asbjørn Sloth Tønnesen, Stanislav Fomichev,
Ido Schimmel, Guillaume Nault, Sabrina Dubroca, Petr Machata
Hi Donald,
On 14/11/2025 12:46, Donald Hunter wrote:
> Hangbin Liu <liuhangbin@gmail.com> writes:
>>
>> +cleanup() {
>> + if [[ -n "$testns" ]]; then
>> + ip netns exec "$testns" bash -c "echo $NSIM_ID > /sys/bus/netdevsim/del_device" 2>/dev/null || true
>> + ip netns del "$testns" 2>/dev/null || true
>> + fi
>> +}
>> +
>> +# Check if ynl command is available
>> +if ! command -v $ynl &>/dev/null && [[ ! -x $ynl ]]; then
>> + ktap_skip_all "ynl command not found: $ynl"
>> + exit "$KSFT_SKIP"
>> +fi
>> +
>> +trap cleanup EXIT
>> +
>> +ktap_print_header
>> +ktap_set_plan 9>> +setup
>> +
>> +# Run all tests
>> +cli_list_families
>> +cli_netdev_ops
>> +cli_ethtool_ops
>> +cli_rt_route_ops
>> +cli_rt_addr_ops
>> +cli_rt_link_ops
>> +cli_rt_neigh_ops
>> +cli_rt_rule_ops
>> +cli_nlctrl_ops
>> +
>> +ktap_finished
>
> minor nit: ktap_finished should probably be in the 'cleanup' trap handler
@Donald: I don't think 'ktap_finished' should be called there: in case
of errors with an early exit during the setup phase, the two scripts
will call 'ktap_skip_all', then 'exit "$KSFT_SKIP"'. If 'ktap_finished'
is called in the 'cleanup' trap, it will print a total with everything
set to 0 and call 'exit' again with other values (and no effects). So I
think it is not supposed to be called from the exit trap.
Cheers,
Matt
--
Sponsored by the NGI0 Core fund.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCHv4 net-next 3/3] tools: ynl: add YNL test framework
2025-11-14 18:04 ` Matthieu Baerts
@ 2025-11-16 10:38 ` Donald Hunter
2025-11-17 1:30 ` Hangbin Liu
0 siblings, 1 reply; 9+ messages in thread
From: Donald Hunter @ 2025-11-16 10:38 UTC (permalink / raw)
To: Matthieu Baerts
Cc: Hangbin Liu, netdev, Jakub Kicinski, David S. Miller,
Eric Dumazet, Paolo Abeni, Simon Horman, Jan Stancek,
Asbjørn Sloth Tønnesen, Stanislav Fomichev,
Ido Schimmel, Guillaume Nault, Sabrina Dubroca, Petr Machata
Matthieu Baerts <matttbe@kernel.org> writes:
> Hi Donald,
>
> On 14/11/2025 12:46, Donald Hunter wrote:
>> Hangbin Liu <liuhangbin@gmail.com> writes:
>>>
>>> +cleanup() {
>>> + if [[ -n "$testns" ]]; then
>>> + ip netns exec "$testns" bash -c "echo $NSIM_ID > /sys/bus/netdevsim/del_device" 2>/dev/null || true
>>> + ip netns del "$testns" 2>/dev/null || true
>>> + fi
>>> +}
>>> +
>>> +# Check if ynl command is available
>>> +if ! command -v $ynl &>/dev/null && [[ ! -x $ynl ]]; then
>>> + ktap_skip_all "ynl command not found: $ynl"
>>> + exit "$KSFT_SKIP"
>>> +fi
>>> +
>>> +trap cleanup EXIT
>>> +
>>> +ktap_print_header
>>> +ktap_set_plan 9>> +setup
>>> +
>>> +# Run all tests
>>> +cli_list_families
>>> +cli_netdev_ops
>>> +cli_ethtool_ops
>>> +cli_rt_route_ops
>>> +cli_rt_addr_ops
>>> +cli_rt_link_ops
>>> +cli_rt_neigh_ops
>>> +cli_rt_rule_ops
>>> +cli_nlctrl_ops
>>> +
>>> +ktap_finished
>>
>> minor nit: ktap_finished should probably be in the 'cleanup' trap handler
>
> @Donald: I don't think 'ktap_finished' should be called there: in case
> of errors with an early exit during the setup phase, the two scripts
> will call 'ktap_skip_all', then 'exit "$KSFT_SKIP"'. If 'ktap_finished'
> is called in the 'cleanup' trap, it will print a total with everything
> set to 0 and call 'exit' again with other values (and no effects). So I
> think it is not supposed to be called from the exit trap.
Okay, fair. I thought the goal was to always output totals. Looking at
ktap_helpers.sh I see that it can't output a meaningful skip count for
the skip_call case.
>
> Cheers,
> Matt
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCHv4 net-next 3/3] tools: ynl: add YNL test framework
2025-11-16 10:38 ` Donald Hunter
@ 2025-11-17 1:30 ` Hangbin Liu
0 siblings, 0 replies; 9+ messages in thread
From: Hangbin Liu @ 2025-11-17 1:30 UTC (permalink / raw)
To: Donald Hunter
Cc: Matthieu Baerts, netdev, Jakub Kicinski, David S. Miller,
Eric Dumazet, Paolo Abeni, Simon Horman, Jan Stancek,
Asbjørn Sloth Tønnesen, Stanislav Fomichev,
Ido Schimmel, Guillaume Nault, Sabrina Dubroca, Petr Machata
On Sun, Nov 16, 2025 at 10:38:30AM +0000, Donald Hunter wrote:
> Matthieu Baerts <matttbe@kernel.org> writes:
>
> > Hi Donald,
> >
> > On 14/11/2025 12:46, Donald Hunter wrote:
> >> Hangbin Liu <liuhangbin@gmail.com> writes:
> >>>
> >>> +cleanup() {
> >>> + if [[ -n "$testns" ]]; then
> >>> + ip netns exec "$testns" bash -c "echo $NSIM_ID > /sys/bus/netdevsim/del_device" 2>/dev/null || true
> >>> + ip netns del "$testns" 2>/dev/null || true
> >>> + fi
> >>> +}
> >>> +
> >>> +# Check if ynl command is available
> >>> +if ! command -v $ynl &>/dev/null && [[ ! -x $ynl ]]; then
> >>> + ktap_skip_all "ynl command not found: $ynl"
> >>> + exit "$KSFT_SKIP"
> >>> +fi
> >>> +
> >>> +trap cleanup EXIT
> >>> +
> >>> +ktap_print_header
> >>> +ktap_set_plan 9>> +setup
> >>> +
> >>> +# Run all tests
> >>> +cli_list_families
> >>> +cli_netdev_ops
> >>> +cli_ethtool_ops
> >>> +cli_rt_route_ops
> >>> +cli_rt_addr_ops
> >>> +cli_rt_link_ops
> >>> +cli_rt_neigh_ops
> >>> +cli_rt_rule_ops
> >>> +cli_nlctrl_ops
> >>> +
> >>> +ktap_finished
> >>
> >> minor nit: ktap_finished should probably be in the 'cleanup' trap handler
> >
> > @Donald: I don't think 'ktap_finished' should be called there: in case
> > of errors with an early exit during the setup phase, the two scripts
> > will call 'ktap_skip_all', then 'exit "$KSFT_SKIP"'. If 'ktap_finished'
> > is called in the 'cleanup' trap, it will print a total with everything
> > set to 0 and call 'exit' again with other values (and no effects). So I
> > think it is not supposed to be called from the exit trap.
>
> Okay, fair. I thought the goal was to always output totals. Looking at
> ktap_helpers.sh I see that it can't output a meaningful skip count for
> the skip_call case.
Definitely, I will add this to my todo list and see if I could fix the helper.
Thanks
Hangbin
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2025-11-17 1:30 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-14 3:46 [PATCHv4 net-next 0/3] Add YNL test framework and library improvements Hangbin Liu
2025-11-14 3:46 ` [PATCHv4 net-next 1/3] tools: ynl: Add MAC address parsing support Hangbin Liu
2025-11-14 3:46 ` [PATCHv4 net-next 2/3] netlink: specs: support ipv4-or-v6 for dual-stack fields Hangbin Liu
2025-11-14 3:46 ` [PATCHv4 net-next 3/3] tools: ynl: add YNL test framework Hangbin Liu
2025-11-14 11:46 ` Donald Hunter
2025-11-14 18:04 ` Matthieu Baerts
2025-11-16 10:38 ` Donald Hunter
2025-11-17 1:30 ` Hangbin Liu
2025-11-14 18:00 ` Matthieu Baerts
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).