tools: ynl: convert samples into selftests
Subsystems (3)
Jakub Kicinski
maintainercover tools: ynl: convert samples into selftests
The "samples" were always poor man's tests, used to manually confirm that C YNL works as expected. Since a proper tests/ directory now exists move the samples and use the kselftest harness to turn them into selftests outputting KTAP.
Jakub Kicinski (10):
tools: ynl: move samples to tests
tools: ynl: convert netdev sample to selftest
tools: ynl: convert ovs sample to selftest
tools: ynl: convert rt-link sample to selftest
tools: ynl: convert tc and tc-filter-add samples to selftest
tools: ynl: add netdevsim wrapper library for YNL tests
tools: ynl: convert devlink sample to selftest
tools: ynl: convert ethtool sample to selftest
tools: ynl: convert rt-addr sample to selftest
tools: ynl: convert rt-route sample to selftest
tools/net/ynl/Makefile | 4 +-
tools/net/ynl/samples/Makefile | 36 --
tools/net/ynl/tests/Makefile | 70 +++-
tools/net/ynl/samples/devlink.c | 61 ---
tools/net/ynl/samples/ethtool.c | 65 ----
tools/net/ynl/samples/netdev.c | 128 ------
tools/net/ynl/samples/ovs.c | 60 ---
tools/net/ynl/samples/rt-addr.c | 80 ----
tools/net/ynl/samples/rt-link.c | 184 ---------
tools/net/ynl/samples/rt-route.c | 80 ----
tools/net/ynl/samples/tc-filter-add.c | 335 ----------------
tools/net/ynl/samples/tc.c | 80 ----
tools/net/ynl/tests/devlink.c | 100 +++++
tools/net/ynl/tests/ethtool.c | 92 +++++
tools/net/ynl/tests/netdev.c | 231 +++++++++++
tools/net/ynl/tests/ovs.c | 104 +++++
tools/net/ynl/tests/rt-addr.c | 111 ++++++
tools/net/ynl/tests/rt-link.c | 204 ++++++++++
tools/net/ynl/tests/rt-route.c | 113 ++++++
tools/net/ynl/tests/tc.c | 407 ++++++++++++++++++++
tools/net/ynl/{samples => tests}/.gitignore | 3 +-
tools/net/ynl/tests/config | 8 +
tools/net/ynl/tests/devlink.sh | 5 +
tools/net/ynl/tests/ethtool.sh | 5 +
tools/net/ynl/tests/rt-addr.sh | 5 +
tools/net/ynl/tests/rt-route.sh | 5 +
tools/net/ynl/tests/ynl_nsim_lib.sh | 35 ++
27 files changed, 1492 insertions(+), 1119 deletions(-)
delete mode 100644 tools/net/ynl/samples/Makefile
delete mode 100644 tools/net/ynl/samples/devlink.c
delete mode 100644 tools/net/ynl/samples/ethtool.c
delete mode 100644 tools/net/ynl/samples/netdev.c
delete mode 100644 tools/net/ynl/samples/ovs.c
delete mode 100644 tools/net/ynl/samples/rt-addr.c
delete mode 100644 tools/net/ynl/samples/rt-link.c
delete mode 100644 tools/net/ynl/samples/rt-route.c
delete mode 100644 tools/net/ynl/samples/tc-filter-add.c
delete mode 100644 tools/net/ynl/samples/tc.c
create mode 100644 tools/net/ynl/tests/devlink.c
create mode 100644 tools/net/ynl/tests/ethtool.c
create mode 100644 tools/net/ynl/tests/netdev.c
create mode 100644 tools/net/ynl/tests/ovs.c
create mode 100644 tools/net/ynl/tests/rt-addr.c
create mode 100644 tools/net/ynl/tests/rt-link.c
create mode 100644 tools/net/ynl/tests/rt-route.c
create mode 100644 tools/net/ynl/tests/tc.c
rename tools/net/ynl/{samples => tests}/.gitignore (87%)
create mode 100755 tools/net/ynl/tests/devlink.sh
create mode 100755 tools/net/ynl/tests/ethtool.sh
create mode 100755 tools/net/ynl/tests/rt-addr.sh
create mode 100755 tools/net/ynl/tests/rt-route.sh
create mode 100644 tools/net/ynl/tests/ynl_nsim_lib.shSignature · 1 line
2.53.0
Jakub Kicinski
maintainerPATCH 1/10 tools: ynl: move samples to tests
The "samples" were always poor man's tests (used to manually confirm that C YNL works).
Move all C sample programs from tools/net/ynl/samples/ to tools/net/ynl/tests/, "merge" the Makefiles. The subsequent changes will convert each sample into a proper KTAP selftests.
Since these are now tests rather than samples - default to enabling asan. After all we're testing user space code here.
Sort the gitignore while at it, the page-pool entry was a leftover so delete it.
---
tools/net/ynl/Makefile | 4 +-
tools/net/ynl/samples/Makefile | 36 --------------
tools/net/ynl/tests/Makefile | 47 +++++++++++++++++--
tools/net/ynl/{samples => tests}/devlink.c | 0
tools/net/ynl/{samples => tests}/ethtool.c | 0
tools/net/ynl/{samples => tests}/netdev.c | 0
tools/net/ynl/{samples => tests}/ovs.c | 0
tools/net/ynl/{samples => tests}/rt-addr.c | 0
tools/net/ynl/{samples => tests}/rt-link.c | 0
tools/net/ynl/{samples => tests}/rt-route.c | 0
.../ynl/{samples => tests}/tc-filter-add.c | 0
tools/net/ynl/{samples => tests}/tc.c | 0
tools/net/ynl/{samples => tests}/.gitignore | 3 +-
13 files changed, 45 insertions(+), 45 deletions(-)
delete mode 100644 tools/net/ynl/samples/Makefile
rename tools/net/ynl/{samples => tests}/devlink.c (100%)
rename tools/net/ynl/{samples => tests}/ethtool.c (100%)
rename tools/net/ynl/{samples => tests}/netdev.c (100%)
rename tools/net/ynl/{samples => tests}/ovs.c (100%)
rename tools/net/ynl/{samples => tests}/rt-addr.c (100%)
rename tools/net/ynl/{samples => tests}/rt-link.c (100%)
rename tools/net/ynl/{samples => tests}/rt-route.c (100%)
rename tools/net/ynl/{samples => tests}/tc-filter-add.c (100%)
rename tools/net/ynl/{samples => tests}/tc.c (100%)
rename tools/net/ynl/{samples => tests}/.gitignore (87%)tools/net/ynl/Makefile +2 -2
@@ -14,12 +14,12 @@ includedir ?= $(prefix)/include SPECDIR=../../../Documentation/netlink/specs -SUBDIRS = lib generated samples ynltool tests +SUBDIRS = lib generated ynltool tests all: $(SUBDIRS) libynl.a +tests: | lib generated libynl.a ynltool: | lib generated libynl.a -samples: | lib generated libynl.a: | lib generated @echo -e "\tAR $@" @ar rcs $@ lib/ynl.o generated/*-user.o
tools/net/ynl/samples/Makefile deleted +0 -36
@@ -1,36 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 - -include ../Makefile.deps - -CC=gcc -CFLAGS += -std=gnu11 -O2 -W -Wall -Wextra -Wno-unused-parameter -Wshadow \ - -I../lib/ -I../generated/ -idirafter $(UAPI_PATH) -ifeq ("$(DEBUG)","1") - CFLAGS += -g -fsanitize=address -fsanitize=leak -static-libasan -endif - -LDLIBS=../lib/ynl.a ../generated/protos.a - -SRCS=$(wildcard *.c) -BINS=$(patsubst %.c,%,${SRCS}) - -include $(wildcard *.d) - -all: $(BINS) - -CFLAGS_page-pool=$(CFLAGS_netdev) -CFLAGS_tc-filter-add:=$(CFLAGS_tc) - -$(BINS): ../lib/ynl.a ../generated/protos.a $(SRCS) - @echo -e '\tCC sample $@' - @$(COMPILE.c) $(CFLAGS_$@) [email protected] -o [email protected] - @$(LINK.c) [email protected] -o $@ $(LDLIBS) - -clean: - rm -f *.o *.d *~ - -distclean: clean - rm -f $(BINS) - -.PHONY: all clean distclean -.DEFAULT_GOAL=all
tools/net/ynl/tests/Makefile +42 -5
74 lines not on this page · raw message
tools/net/ynl/tests/devlink.c renamed from tools/net/ynl/samples/devlink.c +0 -0
tools/net/ynl/tests/ethtool.c renamed from tools/net/ynl/samples/ethtool.c +0 -0
tools/net/ynl/tests/netdev.c renamed from tools/net/ynl/samples/netdev.c +0 -0
tools/net/ynl/tests/ovs.c renamed from tools/net/ynl/samples/ovs.c +0 -0
tools/net/ynl/tests/rt-addr.c renamed from tools/net/ynl/samples/rt-addr.c +0 -0
tools/net/ynl/tests/rt-link.c renamed from tools/net/ynl/samples/rt-link.c +0 -0
tools/net/ynl/tests/rt-route.c renamed from tools/net/ynl/samples/rt-route.c +0 -0
tools/net/ynl/tests/tc-filter-add.c renamed from tools/net/ynl/samples/tc-filter-add.c +0 -0
tools/net/ynl/tests/tc.c renamed from tools/net/ynl/samples/tc.c +0 -0
tools/net/ynl/tests/.gitignore renamed from tools/net/ynl/samples/.gitignore +1 -2
@@ -1,8 +1,7 @@ -ethtool devlink +ethtool netdev ovs -page-pool rt-addr rt-link rt-route
Signature · 1 line
2.53.0
Jakub Kicinski
maintainerPATCH 2/10 tools: ynl: convert netdev sample to selftest
In reply to Jakub KicinskiConvert netdev.c to produce KTAP output with 3 tests:
- dev_dump: dump all netdev devices, skip if empty
- dev_get: query first device from dump by ifindex
- ntf_check: subscribe to "mgmt", create a veth via rt-link, verify netdev notification is received, then delete the veth
Remove stdin/scanf-based UI. Add rt-link dependency for the veth notification test.
TAP version 13
1..3
# Starting 3 tests from 1 test cases.
# RUN netdev.dump ...
# lo[1] xdp-features (0): xdp-rx-metadata-features (0): xsk-fea...
# sit0[2] xdp-features (0): xdp-rx-metadata-features (0): xsk-fea...
# OK netdev.dump
ok 1 netdev.dump
# RUN netdev.get ...
# lo[1] xdp-features (0): xdp-rx-metadata-features (0): xsk-fea...
# OK netdev.get
ok 2 netdev.get
# RUN netdev.ntf_check ...
# veth0[7] xdp-features (0): xdp-rx-metadata-features (7): timesta...
# OK netdev.ntf_check
ok 3 netdev.ntf_check
# PASSED: 3 / 3 tests passed.
# Totals: pass:3 fail:0 xfail:0 xpass:0 skip:0 error:0
--- tools/net/ynl/tests/Makefile | 29 +++-- tools/net/ynl/tests/netdev.c | 229 +++++++++++++++++++++++++---------- 2 files changed, 187 insertions(+), 71 deletions(-)
tools/net/ynl/tests/Makefile +21 -8
@@ -18,16 +18,29 @@ TEST_PROGS := \ test_ynl_ethtool.sh \ # end of TEST_PROGS -SRCS=$(wildcard *.c) -BINS=$(patsubst %.c,%,${SRCS}) +TEST_GEN_PROGS := \ + netdev \ +# end of TEST_GEN_PROGS +BINS := \ + devlink \ + ethtool \ + ovs \ + rt-addr \ + rt-link \ + rt-route \ + tc \ + tc-filter-add \ +# end of BINS + +CFLAGS_netdev:=$(CFLAGS_netdev) $(CFLAGS_rt-link) CFLAGS_tc-filter-add:=$(CFLAGS_tc) include $(wildcard *.d) INSTALL_PATH ?= $(DESTDIR)/usr/share/kselftest -all: $(BINS) $(TEST_PROGS) +all: $(TEST_GEN_PROGS) $(BINS) ../lib/ynl.a: @$(MAKE) -C ../lib
@@ -35,7 +48,7 @@ all: $(BINS) $(TEST_PROGS) ../generated/protos.a: @$(MAKE) -C ../generated -$(BINS): ../lib/ynl.a ../generated/protos.a +$(TEST_GEN_PROGS) $(BINS): %: %.c ../lib/ynl.a ../generated/protos.a @echo -e '\tCC test $@' @$(COMPILE.c) $(CFLAGS_$@) [email protected] -o [email protected] @$(LINK.c) [email protected] -o $@ $(LDLIBS)
@@ -45,7 +58,7 @@ $(BINS): ../lib/ynl.a ../generated/protos.a ./$$test; \ done -install: $(TEST_PROGS) $(BINS) +install: $(TEST_GEN_PROGS) $(BINS) @mkdir -p $(INSTALL_PATH)/ynl @cp ../../../testing/selftests/kselftest/ktap_helpers.sh $(INSTALL_PATH)/ @for test in $(TEST_PROGS); do \
@@ -56,10 +69,10 @@ install: $(TEST_PROGS) $(BINS) $$test > $(INSTALL_PATH)/ynl/$$name; \ chmod +x $(INSTALL_PATH)/ynl/$$name; \ done - @for bin in $(BINS); do \ + @for bin in $(TEST_GEN_PROGS) $(BINS); do \ cp $$bin $(INSTALL_PATH)/ynl/$$bin; \ done - @for test in $(TEST_PROGS); do \ + @for test in $(TEST_PROGS) $(TEST_GEN_PROGS); do \ echo "ynl:$$test"; \ done > $(INSTALL_PATH)/kselftest-list.txt
@@ -67,7 +80,7 @@ install: $(TEST_PROGS) $(BINS) rm -f *.o *.d *~ distclean: clean - rm -f $(BINS) + rm -f $(TEST_GEN_PROGS) $(BINS) .PHONY: all install clean distclean run_tests .DEFAULT_GOAL=all
tools/net/ynl/tests/netdev.c +166 -63
276 lines not on this page · raw message
Signature · 1 line
2.53.0
Jakub Kicinski
maintainerPATCH 3/10 tools: ynl: convert ovs sample to selftest
In reply to Jakub KicinskiConvert ovs.c to produce KTAP output with kselftest_harness. The single "crud" test creates a new OVS datapath, fetches it back by name, then dumps all datapaths verifying the new one appears.
IIRC I added this test because ovs is a genetlink family but has a family-specific fixed header.
TAP version 13
1..1
# Starting 1 tests from 1 test cases.
# RUN ovs.crud ...
# get:
# ynl-test(3): pid:0 cache:256
# dump:
# ynl-test(3): pid:0 cache:256
# OK ovs.crud
ok 1 ovs.crud
# PASSED: 1 / 1 tests passed.
# Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
--- tools/net/ynl/tests/Makefile | 3 +- tools/net/ynl/tests/ovs.c | 124 ++++++++++++++++++++++++----------- tools/net/ynl/tests/config | 1 + 3 files changed, 87 insertions(+), 41 deletions(-)
tools/net/ynl/tests/Makefile +2 -1
@@ -20,12 +20,12 @@ TEST_PROGS := \ TEST_GEN_PROGS := \ netdev \ + ovs \ # end of TEST_GEN_PROGS BINS := \ devlink \ ethtool \ - ovs \ rt-addr \ rt-link \ rt-route \
@@ -34,6 +34,7 @@ BINS := \ # end of BINS CFLAGS_netdev:=$(CFLAGS_netdev) $(CFLAGS_rt-link) +CFLAGS_ovs:=$(CFLAGS_ovs_datapath) CFLAGS_tc-filter-add:=$(CFLAGS_tc) include $(wildcard *.d)
tools/net/ynl/tests/ovs.c +84 -40
141 lines not on this page · raw message
tools/net/ynl/tests/config +1 -0
@@ -3,4 +3,5 @@ CONFIG_INET_DIAG=y CONFIG_IPV6=y CONFIG_NET_NS=y CONFIG_NETDEVSIM=m +CONFIG_OPENVSWITCH=m CONFIG_VETH=m
Signature · 1 line
2.53.0
Jakub Kicinski
maintainerPATCH 4/10 tools: ynl: convert rt-link sample to selftest
In reply to Jakub KicinskiConvert rt-link.c to use kselftest_harness.h with FIXTURE/TEST_F. Move rt-link from BINS to TEST_GEN_PROGS.
Output:
TAP version 13
1..3
# Starting 3 tests from 1 test cases.
# RUN rt_link.dump ...
# 1: lo: mtu 65536 # 2: sit0: mtu 1480 kind sit
# OK rt_link.dump
ok 1 rt_link.dump
# RUN rt_link.netkit ...
# 4: nk1: mtu 1500 kind netkit primary 1 policy blackhole
# OK rt_link.netkit
ok 2 rt_link.netkit
# RUN rt_link.netkit_err_msg ...
# OK rt_link.netkit_err_msg
ok 3 rt_link.netkit_err_msg
# PASSED: 3 / 3 tests passed.
# Totals: pass:3 fail:0 xfail:0 xpass:0 skip:0 error:0
--- tools/net/ynl/tests/Makefile | 2 +- tools/net/ynl/tests/rt-link.c | 192 +++++++++++++++++++--------------- tools/net/ynl/tests/config | 1 + 3 files changed, 108 insertions(+), 87 deletions(-)
tools/net/ynl/tests/Makefile +1 -1
@@ -21,13 +21,13 @@ TEST_PROGS := \ TEST_GEN_PROGS := \ netdev \ ovs \ + rt-link \ # end of TEST_GEN_PROGS BINS := \ devlink \ ethtool \ rt-addr \ - rt-link \ rt-route \ tc \ tc-filter-add \
tools/net/ynl/tests/rt-link.c +106 -86
253 lines not on this page · raw message
tools/net/ynl/tests/config +1 -0
@@ -3,5 +3,6 @@ CONFIG_INET_DIAG=y CONFIG_IPV6=y CONFIG_NET_NS=y CONFIG_NETDEVSIM=m +CONFIG_NETKIT=y CONFIG_OPENVSWITCH=m CONFIG_VETH=m
Signature · 1 line
2.53.0
Jakub Kicinski
maintainerPATCH 5/10 tools: ynl: convert tc and tc-filter-add samples to selftest
In reply to Jakub KicinskiConvert tc.c and tc-filter-add.c to produce KTAP output with kselftest_harness. Merge the two tests together. They both test TC one is testing qdisc and the other classifiers but they can easily live in a single selftest.
Make the test spawn a new netns, and run the operations on lo to avoid onerous setup and cleanup.
TAP version 13
1..2
# Starting 2 tests from 1 test cases.
# RUN tc.qdisc ...
# lo: fq_codel limit: 10240p target: 5ms new_flow_cnt: 0
# OK tc.qdisc
ok 1 tc.qdisc
# RUN tc.flower ...
# flower pref 1 proto: 0x8100 # flower: # vlan_id: 100 # vlan_prio: 5 # num_of_vlans: 3 # action order: 1 vlan push id 200 protocol 0x8100 priority 0 # action order: 2 vlan push id 300 protocol 0x8100 priority 0 # OK tc.flower ok 2 tc.flower # PASSED: 2 / 2 tests passed. # Totals: pass:2 fail:0 xfail:0 xpass:0 skip:0 error:0
--- tools/net/ynl/tests/Makefile | 4 +- tools/net/ynl/tests/tc-filter-add.c | 335 ----------------------- tools/net/ynl/tests/tc.c | 403 +++++++++++++++++++++++++--- tools/net/ynl/tests/config | 6 + 4 files changed, 372 insertions(+), 376 deletions(-) delete mode 100644 tools/net/ynl/tests/tc-filter-add.c
tools/net/ynl/tests/Makefile +1 -3
@@ -22,6 +22,7 @@ TEST_GEN_PROGS := \ netdev \ ovs \ rt-link \ + tc \ # end of TEST_GEN_PROGS BINS := \
@@ -29,13 +30,10 @@ BINS := \ ethtool \ rt-addr \ rt-route \ - tc \ - tc-filter-add \ # end of BINS CFLAGS_netdev:=$(CFLAGS_netdev) $(CFLAGS_rt-link) CFLAGS_ovs:=$(CFLAGS_ovs_datapath) -CFLAGS_tc-filter-add:=$(CFLAGS_tc) include $(wildcard *.d)
tools/net/ynl/tests/tc-filter-add.c deleted +0 -335
335 lines not on this page · raw message
tools/net/ynl/tests/tc.c +365 -38
438 lines not on this page · raw message
tools/net/ynl/tests/config +6 -0
@@ -1,7 +1,13 @@ CONFIG_DUMMY=m CONFIG_INET_DIAG=y CONFIG_IPV6=y +CONFIG_NET_ACT_VLAN=m +CONFIG_NET_CLS_ACT=y +CONFIG_NET_CLS_FLOWER=m +CONFIG_NET_SCH_FQ_CODEL=m +CONFIG_NET_SCH_INGRESS=m CONFIG_NET_NS=y +CONFIG_NET_SCHED=y CONFIG_NETDEVSIM=m CONFIG_NETKIT=y CONFIG_OPENVSWITCH=m
Signature · 1 line
2.53.0
Jakub Kicinski
maintainerPATCH 6/10 tools: ynl: add netdevsim wrapper library for YNL tests
In reply to Jakub KicinskiSome tests need netdevsim setup which is painful to do from C.
Add ynl_nsim_lib.sh, a shared library providing nsim_setup and nsim_cleanup functions for tests that need a netdevsim device.
--- tools/net/ynl/tests/Makefile | 5 +++++ tools/net/ynl/tests/ynl_nsim_lib.sh | 35 +++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 tools/net/ynl/tests/ynl_nsim_lib.sh
tools/net/ynl/tests/Makefile +5 -0
@@ -32,6 +32,8 @@ BINS := \ rt-route \ # end of BINS +TEST_FILES := ynl_nsim_lib.sh + CFLAGS_netdev:=$(CFLAGS_netdev) $(CFLAGS_rt-link) CFLAGS_ovs:=$(CFLAGS_ovs_datapath)
@@ -68,6 +70,9 @@ install: $(TEST_GEN_PROGS) $(BINS) $$test > $(INSTALL_PATH)/ynl/$$name; \ chmod +x $(INSTALL_PATH)/ynl/$$name; \ done + @for file in $(TEST_FILES); do \ + cp $$file $(INSTALL_PATH)/ynl/$$file; \ + done @for bin in $(TEST_GEN_PROGS) $(BINS); do \ cp $$bin $(INSTALL_PATH)/ynl/$$bin; \ done
tools/net/ynl/tests/ynl_nsim_lib.sh new file +35 -0
@@ -0,0 +1,35 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Shared netdevsim setup/cleanup for YNL C test wrappers + +NSIM_ID="1337" +NSIM_DEV="" +KSFT_SKIP=4 + +nsim_cleanup() { + echo "$NSIM_ID" > /sys/bus/netdevsim/del_device 2>/dev/null || true +} + +nsim_setup() { + modprobe netdevsim 2>/dev/null + if ! [ -f /sys/bus/netdevsim/new_device ]; then + echo "netdevsim module not available, skipping" >&2 + exit "$KSFT_SKIP" + fi + + trap nsim_cleanup EXIT + + echo "$NSIM_ID 1" > /sys/bus/netdevsim/new_device + udevadm settle + + NSIM_DEV=$(ls /sys/bus/netdevsim/devices/netdevsim${NSIM_ID}/net 2>/dev/null | head -1) + if [ -z "$NSIM_DEV" ]; then + echo "failed to find netdevsim device" >&2 + exit 1 + fi + + ip link set dev "$NSIM_DEV" name nsim0 + ip link set dev nsim0 up + ip addr add 192.168.1.1/24 dev nsim0 + ip addr add 2001:db8::1/64 dev nsim0 nodad +}
Signature · 1 line
2.53.0
Jakub Kicinski
maintainerPATCH 7/10 tools: ynl: convert devlink sample to selftest
In reply to Jakub KicinskiConvert devlink.c to use kselftest_harness.h with FIXTURE/TEST_F. Move devlink from BINS to TEST_GEN_FILES in the Makefile since it's invoked via the devlink.sh wrapper which sets up netdevsim.
Output:
TAP version 13
1..2
# Starting 2 tests from 1 test cases.
# RUN devlink.dump ...
# netdevsim/netdevsim1337 # OK devlink.dump ok 1 devlink.dump # RUN devlink.info ... # netdevsim/netdevsim1337: # driver: netdevsim # running fw: # fw.mgmt: 10.20.30 # OK devlink.info ok 2 devlink.info # PASSED: 2 / 2 tests passed. # Totals: pass:2 fail:0 xfail:0 xpass:0 skip:0 error:0
--- tools/net/ynl/tests/Makefile | 16 +++--- tools/net/ynl/tests/devlink.c | 99 +++++++++++++++++++++++----------- tools/net/ynl/tests/devlink.sh | 5 ++ 3 files changed, 84 insertions(+), 36 deletions(-) create mode 100755 tools/net/ynl/tests/devlink.sh
tools/net/ynl/tests/Makefile +10 -6
@@ -14,6 +14,7 @@ endif LDLIBS=../lib/ynl.a ../generated/protos.a TEST_PROGS := \ + devlink.sh \ test_ynl_cli.sh \ test_ynl_ethtool.sh \ # end of TEST_PROGS
@@ -25,8 +26,11 @@ TEST_GEN_PROGS := \ tc \ # end of TEST_GEN_PROGS -BINS := \ +TEST_GEN_FILES := \ devlink \ +# end of TEST_GEN_FILES + +BINS := \ ethtool \ rt-addr \ rt-route \
@@ -41,7 +45,7 @@ include $(wildcard *.d) INSTALL_PATH ?= $(DESTDIR)/usr/share/kselftest -all: $(TEST_GEN_PROGS) $(BINS) +all: $(TEST_GEN_PROGS) $(TEST_GEN_FILES) $(BINS) ../lib/ynl.a: @$(MAKE) -C ../lib
@@ -49,7 +53,7 @@ all: $(TEST_GEN_PROGS) $(BINS) ../generated/protos.a: @$(MAKE) -C ../generated -$(TEST_GEN_PROGS) $(BINS): %: %.c ../lib/ynl.a ../generated/protos.a +$(TEST_GEN_PROGS) $(TEST_GEN_FILES) $(BINS): %: %.c ../lib/ynl.a ../generated/protos.a @echo -e '\tCC test $@' @$(COMPILE.c) $(CFLAGS_$@) [email protected] -o [email protected] @$(LINK.c) [email protected] -o $@ $(LDLIBS)
@@ -59,7 +63,7 @@ $(TEST_GEN_PROGS) $(BINS): %: %.c ../lib/ynl.a ../generated/protos.a ./$$test; \ done -install: $(TEST_GEN_PROGS) $(BINS) +install: $(TEST_GEN_PROGS) $(TEST_GEN_FILES) $(BINS) @mkdir -p $(INSTALL_PATH)/ynl @cp ../../../testing/selftests/kselftest/ktap_helpers.sh $(INSTALL_PATH)/ @for test in $(TEST_PROGS); do \
@@ -73,7 +77,7 @@ install: $(TEST_GEN_PROGS) $(BINS) @for file in $(TEST_FILES); do \ cp $$file $(INSTALL_PATH)/ynl/$$file; \ done - @for bin in $(TEST_GEN_PROGS) $(BINS); do \ + @for bin in $(TEST_GEN_PROGS) $(TEST_GEN_FILES) $(BINS); do \ cp $$bin $(INSTALL_PATH)/ynl/$$bin; \ done @for test in $(TEST_PROGS) $(TEST_GEN_PROGS); do \
@@ -84,7 +88,7 @@ install: $(TEST_GEN_PROGS) $(BINS) rm -f *.o *.d *~ distclean: clean - rm -f $(TEST_GEN_PROGS) $(BINS) + rm -f $(TEST_GEN_PROGS) $(TEST_GEN_FILES) $(BINS) .PHONY: all install clean distclean run_tests .DEFAULT_GOAL=all
tools/net/ynl/tests/devlink.c +69 -30
127 lines not on this page · raw message
tools/net/ynl/tests/devlink.sh new file +5 -0
@@ -0,0 +1,5 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 +source "$(dirname "$(realpath "$0")")/ynl_nsim_lib.sh" +nsim_setup +exec "$(dirname "$(realpath "$0")")/devlink"
Signature · 1 line
2.53.0
Jakub Kicinski
maintainerPATCH 8/10 tools: ynl: convert ethtool sample to selftest
In reply to Jakub KicinskiConvert ethtool.c to use kselftest_harness.h with FIXTURE/TEST_F. Move ethtool from BINS to TEST_GEN_FILES and add ethtool.sh wrapper which sets up a netdevsim device before running the test binary.
Output:
TAP version 13
1..2
# Starting 2 tests from 1 test cases.
# RUN ethtool.channels ...
# nsim0: combined 1
# OK ethtool.channels
ok 1 ethtool.channels
# RUN ethtool.rings ...
# nsim0: rx 512 tx 512
# OK ethtool.rings
ok 2 ethtool.rings
# PASSED: 2 / 2 tests passed.
# Totals: pass:2 fail:0 xfail:0 xpass:0 skip:0 error:0
--- tools/net/ynl/tests/Makefile | 3 +- tools/net/ynl/tests/ethtool.c | 83 ++++++++++++++++++++++------------ tools/net/ynl/tests/ethtool.sh | 5 ++ 3 files changed, 62 insertions(+), 29 deletions(-) create mode 100755 tools/net/ynl/tests/ethtool.sh
tools/net/ynl/tests/Makefile +2 -1
@@ -15,6 +15,7 @@ LDLIBS=../lib/ynl.a ../generated/protos.a TEST_PROGS := \ devlink.sh \ + ethtool.sh \ test_ynl_cli.sh \ test_ynl_ethtool.sh \ # end of TEST_PROGS
@@ -28,10 +29,10 @@ TEST_GEN_PROGS := \ TEST_GEN_FILES := \ devlink \ + ethtool \ # end of TEST_GEN_FILES BINS := \ - ethtool \ rt-addr \ rt-route \ # end of BINS
tools/net/ynl/tests/ethtool.c +55 -28
111 lines not on this page · raw message
tools/net/ynl/tests/ethtool.sh new file +5 -0
@@ -0,0 +1,5 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 +source "$(dirname "$(realpath "$0")")/ynl_nsim_lib.sh" +nsim_setup +exec "$(dirname "$(realpath "$0")")/ethtool"
Signature · 1 line
2.53.0
Jakub Kicinski
maintainerPATCH 9/10 tools: ynl: convert rt-addr sample to selftest
In reply to Jakub KicinskiConvert rt-addr.c to use kselftest_harness.h with FIXTURE/TEST_F.
Validate that the addresses configured by the wrapper (192.168.1.1 and 2001:db8::1) appear in the dump.
Output:
TAP version 13
1..1
# Starting 1 tests from 1 test cases.
# RUN rt_addr.dump ...
# lo: 127.0.0.1
# nsim0: 192.168.1.1
# lo: ::1
# nsim0: 2001:db8::1 # nsim0: fe80::7c66:c9ff:fe5f:bf01 # OK rt_addr.dump
ok 1 rt_addr.dump
# PASSED: 1 / 1 tests passed.
# Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
--- tools/net/ynl/tests/Makefile | 3 +- tools/net/ynl/tests/rt-addr.c | 85 +++++++++++++++++++++++----------- tools/net/ynl/tests/rt-addr.sh | 5 ++ 3 files changed, 65 insertions(+), 28 deletions(-) create mode 100755 tools/net/ynl/tests/rt-addr.sh
tools/net/ynl/tests/Makefile +2 -1
@@ -16,6 +16,7 @@ LDLIBS=../lib/ynl.a ../generated/protos.a TEST_PROGS := \ devlink.sh \ ethtool.sh \ + rt-addr.sh \ test_ynl_cli.sh \ test_ynl_ethtool.sh \ # end of TEST_PROGS
@@ -30,10 +31,10 @@ TEST_GEN_PROGS := \ TEST_GEN_FILES := \ devlink \ ethtool \ + rt-addr \ # end of TEST_GEN_FILES BINS := \ - rt-addr \ rt-route \ # end of BINS
tools/net/ynl/tests/rt-addr.c +58 -27
116 lines not on this page · raw message
tools/net/ynl/tests/rt-addr.sh new file +5 -0
@@ -0,0 +1,5 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 +source "$(dirname "$(realpath "$0")")/ynl_nsim_lib.sh" +nsim_setup +exec "$(dirname "$(realpath "$0")")/rt-addr"
Signature · 1 line
2.53.0
Jakub Kicinski
maintainerPATCH 10/10 tools: ynl: convert rt-route sample to selftest
In reply to Jakub KicinskiConvert rt-route.c to use kselftest_harness.h with FIXTURE/TEST_F. This is the last test to convert so clean up the Makefile.
Validate that the connected routes for 192.168.1.0/24 and 2001:db8::/64 appear in the dump.
Output:
TAP version 13
1..1
# Starting 1 tests from 1 test cases.
# RUN rt_route.dump ...
# oif: nsim0 dst: 192.168.1.0/24 # oif: lo dst: ::1/128 # oif: nsim0 dst: 2001:db8::1/128 # oif: nsim0 dst: 2001:db8::/64 # oif: nsim0 dst: fe80::/64 # oif: nsim0 dst: ff00::/8
# OK rt_route.dump
ok 1 rt_route.dump
# PASSED: 1 / 1 tests passed.
# Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
--- tools/net/ynl/tests/Makefile | 16 +++--- tools/net/ynl/tests/rt-route.c | 87 +++++++++++++++++++++++---------- tools/net/ynl/tests/rt-route.sh | 5 ++ 3 files changed, 72 insertions(+), 36 deletions(-) create mode 100755 tools/net/ynl/tests/rt-route.sh
tools/net/ynl/tests/Makefile +7 -9
@@ -17,6 +17,7 @@ TEST_PROGS := \ devlink.sh \ ethtool.sh \ rt-addr.sh \ + rt-route.sh \ test_ynl_cli.sh \ test_ynl_ethtool.sh \ # end of TEST_PROGS
@@ -32,11 +33,8 @@ TEST_GEN_FILES := \ devlink \ ethtool \ rt-addr \ -# end of TEST_GEN_FILES - -BINS := \ rt-route \ -# end of BINS +# end of TEST_GEN_FILES TEST_FILES := ynl_nsim_lib.sh
@@ -47,7 +45,7 @@ include $(wildcard *.d) INSTALL_PATH ?= $(DESTDIR)/usr/share/kselftest -all: $(TEST_GEN_PROGS) $(TEST_GEN_FILES) $(BINS) +all: $(TEST_GEN_PROGS) $(TEST_GEN_FILES) ../lib/ynl.a: @$(MAKE) -C ../lib
@@ -55,7 +53,7 @@ all: $(TEST_GEN_PROGS) $(TEST_GEN_FILES) $(BINS) ../generated/protos.a: @$(MAKE) -C ../generated -$(TEST_GEN_PROGS) $(TEST_GEN_FILES) $(BINS): %: %.c ../lib/ynl.a ../generated/protos.a +$(TEST_GEN_PROGS) $(TEST_GEN_FILES): %: %.c ../lib/ynl.a ../generated/protos.a @echo -e '\tCC test $@' @$(COMPILE.c) $(CFLAGS_$@) [email protected] -o [email protected] @$(LINK.c) [email protected] -o $@ $(LDLIBS)
@@ -65,7 +63,7 @@ $(TEST_GEN_PROGS) $(TEST_GEN_FILES) $(BINS): %: %.c ../lib/ynl.a ../generated/pr ./$$test; \ done -install: $(TEST_GEN_PROGS) $(TEST_GEN_FILES) $(BINS) +install: $(TEST_GEN_PROGS) $(TEST_GEN_FILES) @mkdir -p $(INSTALL_PATH)/ynl @cp ../../../testing/selftests/kselftest/ktap_helpers.sh $(INSTALL_PATH)/ @for test in $(TEST_PROGS); do \
@@ -79,7 +77,7 @@ install: $(TEST_GEN_PROGS) $(TEST_GEN_FILES) $(BINS) @for file in $(TEST_FILES); do \ cp $$file $(INSTALL_PATH)/ynl/$$file; \ done - @for bin in $(TEST_GEN_PROGS) $(TEST_GEN_FILES) $(BINS); do \ + @for bin in $(TEST_GEN_PROGS) $(TEST_GEN_FILES); do \ cp $$bin $(INSTALL_PATH)/ynl/$$bin; \ done @for test in $(TEST_PROGS) $(TEST_GEN_PROGS); do \
@@ -90,7 +88,7 @@ install: $(TEST_GEN_PROGS) $(TEST_GEN_FILES) $(BINS) rm -f *.o *.d *~ distclean: clean - rm -f $(TEST_GEN_PROGS) $(TEST_GEN_FILES) $(BINS) + rm -f $(TEST_GEN_PROGS) $(TEST_GEN_FILES) .PHONY: all install clean distclean run_tests .DEFAULT_GOAL=all
tools/net/ynl/tests/rt-route.c +60 -27
117 lines not on this page · raw message
tools/net/ynl/tests/rt-route.sh new file +5 -0
@@ -0,0 +1,5 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 +source "$(dirname "$(realpath "$0")")/ynl_nsim_lib.sh" +nsim_setup +exec "$(dirname "$(realpath "$0")")/rt-route"
Signature · 1 line
2.53.0
Donald Hunter
maintainerRe: [PATCH net-next 07/10] tools: ynl: convert devlink sample to selftest
In reply to Jakub Kicinskitools/net/ynl/tests/devlink.sh line 5
Quoted 11 lines · Jakub Kicinski
tools/net/ynl/tests/devlink.sh new file +5
-0@@ -0,0 +1,5 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 +source "$(dirname "$(realpath "$0")")/ynl_nsim_lib.sh" +nsim_setup +exec "$(dirname "$(realpath "$0")")/devlink"
exec is defeating the netdevsim cleanup in the exit handler.
.../ynl_nsim_lib.sh: line 22: echo: write error: No space left on device
Error: ipv4: Address already assigned.
Error: ipv6: address already assigned.
Same for ethtool.sh, rt-addr.sh and rt-route.sh
Re: [PATCH net-next 01/10] tools: ynl: move samples to tests
In reply to Jakub KicinskiQuoted 7 lines · Jakub Kicinski
The "samples" were always poor man's tests (used to manually confirm that C YNL works).
Move all C sample programs from
tools/net/ynl/samples/totools/net/ynl/tests/, "merge" the Makefiles. The subsequent changes will convert each sample into a proper KTAP selftests.
Quoted 7 lines
Since these are now tests rather than samples - default to enabling asan. After all we're testing user space code here.
Sort the gitignore while at it, the page-pool entry was a leftover so delete it.
Signed-off-by Jakub Kicinski <[email protected]>
Re: [PATCH net-next 06/10] tools: ynl: add netdevsim wrapper library for YNL tests
In reply to Jakub KicinskiQuoted 6 lines · Jakub Kicinski
Some tests need netdevsim setup which is painful to do from C.
Add
ynl_nsim_lib.sh, a shared library providingnsim_setupandnsim_cleanupfunctions for tests that need a netdevsim device.Signed-off-by Jakub Kicinski <[email protected]>
Re: [PATCH net-next 02/10] tools: ynl: convert netdev sample to selftest
In reply to Jakub KicinskiQuoted 28 lines · Jakub Kicinski
Convert
netdev.cto produce KTAP output with 3 tests:
-dev_dump: dump all netdev devices, skip if empty
-dev_get: query first device from dump by ifindex
-ntf_check: subscribe to "mgmt", create a veth via rt-link, verify netdev notification is received, then delete the vethRemove stdin/scanf-based UI. Add rt-link dependency for the veth notification test.
TAP version 13
1..3
# Starting 3 tests from 1 test cases.
# RUN netdev.dump ...
# lo[1] xdp-features (0): xdp-rx-metadata-features (0): xsk-fea...
# sit0[2] xdp-features (0): xdp-rx-metadata-features (0): xsk-fea...
# OK netdev.dump
ok 1 netdev.dump
# RUN netdev.get ...
# lo[1] xdp-features (0): xdp-rx-metadata-features (0): xsk-fea...
# OK netdev.get
ok 2 netdev.get
# RUN netdev.ntf_check ...
# veth0[7] xdp-features (0): xdp-rx-metadata-features (7): timesta...
# OK netdev.ntf_check
ok 3 netdev.ntf_check
# PASSED: 3 / 3 tests passed.
# Totals: pass:3 fail:0 xfail:0 xpass:0 skip:0 error:0
Quoted 1 line
Signed-off-by Jakub Kicinski <[email protected]>
Donald Hunter
maintainerRe: [PATCH net-next 04/10] tools: ynl: convert rt-link sample to selftest
In reply to Jakub KicinskiQuoted 255 lines · Jakub Kicinski
Convert
rt-link.cto usekselftest_harness.hwith FIXTURE/TEST_F. Move rt-link from BINS toTEST_GEN_PROGS.Output:
TAP version 13
1..3
# Starting 3 tests from 1 test cases.
# RUN rt_link.dump ...# 1: lo: mtu 65536 # 2: sit0: mtu 1480 kind sit# OK rt_link.dump
ok 1 rt_link.dump
# RUN rt_link.netkit ...
# 4: nk1: mtu 1500 kind netkit primary 1 policy blackhole
# OK rt_link.netkit
ok 2 rt_link.netkit
# RUN rt_link.netkit_err_msg ...
# OK rt_link.netkit_err_msg
ok 3 rt_link.netkit_err_msg
# PASSED: 3 / 3 tests passed.
# Totals: pass:3 fail:0 xfail:0 xpass:0 skip:0 error:0Signed-off-by Jakub Kicinski <[email protected]>--- tools/net/ynl/tests/Makefile | 2 +- tools/net/ynl/tests/rt-link.c | 192 +++++++++++++++++++--------------- tools/net/ynl/tests/config | 1 + 3 files changed, 108 insertions(+), 87 deletions(-)tools/net/ynl/tests/Makefile +1
-1@@ -21,13 +21,13 @@ TEST_PROGS := \ TEST_GEN_PROGS := \ netdev \ ovs \ + rt-link \ # end of TEST_GEN_PROGS BINS := \ devlink \ ethtool \ rt-addr \ - rt-link \ rt-route \ tc \ tc-filter-add \tools/net/ynl/tests/rt-link.c +51
-86@@ -7,16 +7,21 @@#include <arpa/inet.h> #include <net/if.h> +#include <kselftest_harness.h> +#include "rt-link-user.h" -static void rt_link_print (struct rt_link_getlink_rsp *r) +static void rt_link_print (struct __test_metadata *_metadata, +struct rt_link_getlink_rsp *r) {unsigned int i; -printf ("%3d: " , r->_hdr.ifi_index); +EXPECT_TRUE ((bool )r->_hdr.ifi_index); +ksft_print_msg ("%3d: " , r->_hdr.ifi_index); +EXPECT_TRUE ((bool )r->_len.ifname);if (r->_len.ifname) -printf ("%16s: " , r->ifname); +printf ("%6s: " , r->ifname);if (r->_present.mtu)printf ("mtu %5d " , r->mtu);@@ -50,7 +55,7 @@ static void rt_link_print(struct rt_link_getlink_rsp *r)printf ("\n" ); } -static int rt_link_create_netkit (struct ynl_sock *ys) +static int netkit_create (struct ynl_sock *ys) {struct rt_link_getlink_ntf *ntf_gl;struct rt_link_newlink_req *req;@@ -58,49 +63,24 @@ static int rt_link_create_netkit(struct ynl_sock *ys)int ret; req =rt_link_newlink_req_alloc (); -if (!req) { -fprintf (stderr,"Can't alloc req\n" ); +if (!req)return -1 ; - } -/* rtnetlink doesn't provide info about the created object. -* It expects us to set the ECHO flag and the dig the info out -* of the notifications... -*/ rt_link_newlink_req_set_nlflags (req,NLM_F_CREATE |NLM_F_ECHO ); -rt_link_newlink_req_set_linkinfo_kind (req,"netkit" ); - -/* Test error messages */ -rt_link_newlink_req_set_linkinfo_data_netkit_policy (req,10 ); - ret =rt_link_newlink (ys, req); -if (ret) { -printf ("Testing error message for policy being bad:\n\t%s\n" , ys->err.msg); - }else { -fprintf (stderr,"Warning: unexpected success creating netkit with bad attrs\n" ); - goto created; - } -rt_link_newlink_req_set_linkinfo_data_netkit_policy (req,NETKIT_DROP ); ret =rt_link_newlink (ys, req); -created:rt_link_newlink_req_free (req); -if (ret) { -fprintf (stderr,"YNL: %s\n" , ys->err.msg); +if (ret)return -1 ; - } -if (!ynl_has_ntf (ys)) { -fprintf (stderr, -"Warning: interface created but received no notification, won't delete the interface\n" ); +if (!ynl_has_ntf (ys))return 0 ; - } ntf =ynl_ntf_dequeue (ys); -if (ntf->cmd !=RTM_NEWLINK ) { -fprintf (stderr, -"Warning: unexpected notification type, won't delete the interface\n" ); +if (!ntf || ntf->cmd !=RTM_NEWLINK ) { +ynl_ntf_free (ntf);return 0 ; } ntf_gl = (void *)ntf;@@ -110,75 +90,115 @@ static int rt_link_create_netkit(struct ynl_sock *ys)return ret; } -static void rt_link_del (struct ynl_sock *ys,int ifindex) +static void netkit_delete (struct __test_metadata *_metadata, +struct ynl_sock *ys,int ifindex) {struct rt_link_dellink_req *req; req =rt_link_dellink_req_alloc (); -if (!req) { -fprintf (stderr,"Can't alloc req\n" ); +if (!req)return ; - } req->_hdr.ifi_index = ifindex; -if (rt_link_dellink (ys, req)) -fprintf (stderr,"YNL: %s\n" , ys->err.msg); -else -fprintf (stderr, -"Trying to delete a Netkit interface (ifindex %d)\n" , - ifindex); - +EXPECT_EQ (0 ,rt_link_dellink (ys, req));rt_link_dellink_req_free (req); } -int main (int argc,char **argv) +FIXTURE (rt_link) +{ +struct ynl_sock *ys; +}; + +FIXTURE_SETUP (rt_link) +{ +struct ynl_error yerr; + + self->ys =ynl_sock_create (&ynl_rt_link_family, &yerr); + ASSERT_NE(NULL, self->ys) { +TH_LOG ("failed to create rt-link socket: %s" , yerr.msg); + } +} + +FIXTURE_TEARDOWN (rt_link) +{ +ynl_sock_destroy (self->ys); +} + +TEST_F(rt_link, dump) {struct rt_link_getlink_req_dump *req;struct rt_link_getlink_list *rsp; -struct ynl_error yerr; -struct ynl_sock *ys; -int created =0 ; - - ys =ynl_sock_create (&ynl_rt_link_family, &yerr); -if (!ys) { -fprintf (stderr,"YNL: %s\n" , yerr.msg); -return 1 ; - } - -if (argc >1 ) { -fprintf (stderr,"Trying to create a Netkit interface\n" ); - created =rt_link_create_netkit (ys); -if (created <0 ) - goto err_destroy; - } req =rt_link_getlink_req_dump_alloc (); -if (!req) - goto err_del_ifc; - - rsp =rt_link_getlink_dump (ys, req); + rsp =rt_link_getlink_dump (self->ys, req);rt_link_getlink_req_dump_free (req); -if (!rsp) - goto err_close; + ASSERT_NE(NULL, rsp) { +TH_LOG ("dump failed: %s" , self->ys->err.msg); + } +ASSERT_FALSE (ynl_dump_empty (rsp)); -if (ynl_dump_empty (rsp)) -fprintf (stderr,"Error: no links reported\n" ); ynl_dump_foreach(rsp, link) -rt_link_print (link); +rt_link_print (_metadata, link); +rt_link_getlink_list_free (rsp); - -if (created) -rt_link_del (ys, created); - -ynl_sock_destroy (ys); -return 0 ; - -err_close: -fprintf (stderr,"YNL: %s\n" , ys->err.msg); -err_del_ifc: -if (created) -rt_link_del (ys, created); -err_destroy: -ynl_sock_destroy (ys); -return 2 ; } + +TEST_F(rt_link, netkit) +{ +struct rt_link_getlink_req_dump *dreq; +struct rt_link_getlink_list *rsp;
tools/net/ynl/tests/rt-link.c static int rt_link_create_netkit(struct ynl_sock *ys) · line 159
Quoted 10 lines
tools/net/ynl/tests/rt-link.c +10
-0+bool found = false; +int netkit_ifindex; + +/* Create netkit with valid policy */ + netkit_ifindex =netkit_create (self->ys); + ASSERT_GT(netkit_ifindex, 0) +TH_LOG ("failed to create netkit: %s" , self->ys->err.msg); + +/* Verify it appears in a dump */ + dreq =rt_link_getlink_req_dump_alloc ();
I see there's error handling for *_alloc() in helper functions but not in tests. Is that intentional?
Quoted 56 lines
tools/net/ynl/tests/rt-link.c +45
-0+ rsp =rt_link_getlink_dump (self->ys, dreq); +rt_link_getlink_req_dump_free (dreq); + ASSERT_NE(NULL, rsp) { +TH_LOG ("dump failed: %s" , self->ys->err.msg); + } + + ynl_dump_foreach(rsp, link) { +if (link->_hdr.ifi_index == netkit_ifindex) { +rt_link_print (_metadata, link); + found = true; + } + } +rt_link_getlink_list_free (rsp); +EXPECT_TRUE (found); + +netkit_delete (_metadata, self->ys, netkit_ifindex); +} + +TEST_F(rt_link, netkit_err_msg) +{ +struct rt_link_newlink_req *req; +int ret; + +/* Test creating netkit with bad policy - should fail */ + req =rt_link_newlink_req_alloc (); +rt_link_newlink_req_set_nlflags (req,NLM_F_CREATE ); +rt_link_newlink_req_set_linkinfo_kind (req,"netkit" ); +rt_link_newlink_req_set_linkinfo_data_netkit_policy (req,10 ); + + ret =rt_link_newlink (self->ys, req); +rt_link_newlink_req_free (req); + EXPECT_NE(0, ret) { +TH_LOG ("creating netkit with bad policy should fail" ); + } + +/* Expect: +* Kernel error: 'Provided default xmit policy not supported' (bad attribute: .linkinfo.data(netkit).policy) +*/ + EXPECT_NE(NULL, strstr(self->ys->err.msg, "bad attribute: .linkinfo.data(netkit).policy")) { +TH_LOG ("expected extack msg not found: %s" , + self->ys->err.msg); + } +} + +TEST_HARNESS_MAIN tools/net/ynl/tests/config +1
-0@@ -3,5 +3,6 @@ CONFIG_INET_DIAG=y CONFIG_IPV6=y CONFIG_NET_NS=y CONFIG_NETDEVSIM=m +CONFIG_NETKIT=y CONFIG_OPENVSWITCH=m CONFIG_VETH=m
Jakub Kicinski
maintainerRe: [PATCH net-next 04/10] tools: ynl: convert rt-link sample to selftest
Quoted 5 lines · On Fri, 06 Mar 2026 14:29:09 +0000 Donald Hunter wrote:
tools/net/ynl/tests/rt-link.c static int rt_link_create_netkit(struct ynl_sock *ys) · line 159
Quoted 2 lines
tools/net/ynl/tests/rt-link.c +2
-0+/* Verify it appears in a dump */ + dreq =rt_link_getlink_req_dump_alloc ();I see there's error handling for
*_alloc()in helper functions but not in tests. Is that intentional?
I think the tedium of the conversions just got to me by patch 4 ;) Let me add ASSERT_NE(NULL, *) in the relevant spots.
Jakub Kicinski
maintainerRe: [PATCH net-next 07/10] tools: ynl: convert devlink sample to selftest
In reply to Donald HunterQuoted 7 lines · On Fri, 06 Mar 2026 11:53:11 +0000 Donald Hunter wrote:
tools/net/ynl/tests/devlink.sh line 5
Quoted 4 lines
tools/net/ynl/tests/devlink.sh new file +4
-0+# SPDX-License-Identifier: GPL-2.0 +source "$(dirname "$(realpath "$0")")/ynl_nsim_lib.sh" +nsim_setup +exec "$(dirname "$(realpath "$0")")/devlink"exec is defeating the netdevsim cleanup in the exit handler.
Quoted 5 lines
.../ynl_nsim_lib.sh: line 22: echo: write error: No space left on device
Error: ipv4: Address already assigned.
Error: ipv6: address already assigned.Same for
ethtool.sh,rt-addr.shandrt-route.sh
Ah thanks! I've been testing these with:
vng --user root -r -- ./tools/net/ynl/tests/devlink.sh
didn't actually check if the cleanup works..