Subject: [PATCH net-next 01/10] tools: ynl: move samples to tests

From: Jakub Kicinski <[email-masked]>
Date: Thu, 5 Mar 2026 18:08:52 -0800

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.

Signed-off-by: Jakub Kicinski <[email-masked]>
---
 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%)

diff --git a/tools/net/ynl/Makefile b/tools/net/ynl/Makefile
index 9b692f368be7..d514a48dae27 100644
--- a/tools/net/ynl/Makefile
+++ b/tools/net/ynl/Makefile
@@ -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
diff --git a/tools/net/ynl/samples/Makefile b/tools/net/ynl/samples/Makefile
deleted file mode 100644
index d76cbd41cbb1..000000000000
--- a/tools/net/ynl/samples/Makefile
+++ /dev/null
@@ -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_$@) $@.c -o $@.o
-	@$(LINK.c) $@.o -o $@  $(LDLIBS)
-
-clean:
-	rm -f *.o *.d *~
-
-distclean: clean
-	rm -f $(BINS)
-
-.PHONY: all clean distclean
-.DEFAULT_GOAL=all
diff --git a/tools/net/ynl/tests/Makefile b/tools/net/ynl/tests/Makefile
index eb166c9550db..5fa36c877235 100644
--- a/tools/net/ynl/tests/Makefile
+++ b/tools/net/ynl/tests/Makefile
@@ -1,21 +1,51 @@
 # SPDX-License-Identifier: GPL-2.0
 # Makefile for YNL tests
 
+include ../Makefile.deps
+
+CC=gcc
+CFLAGS += -std=gnu11 -O2 -W -Wall -Wextra -Wno-unused-parameter -Wshadow \
+	-I../lib/ -I../generated/ -I../../../testing/selftests/ \
+	-idirafter $(UAPI_PATH)
+ifneq ("$(NDEBUG)","1")
+  CFLAGS += -g -fsanitize=address -fsanitize=leak -static-libasan
+endif
+
+LDLIBS=../lib/ynl.a ../generated/protos.a
+
 TEST_PROGS := \
 	test_ynl_cli.sh \
 	test_ynl_ethtool.sh \
 # end of TEST_PROGS
 
+SRCS=$(wildcard *.c)
+BINS=$(patsubst %.c,%,${SRCS})
+
+CFLAGS_tc-filter-add:=$(CFLAGS_tc)
+
+include $(wildcard *.d)
+
 INSTALL_PATH ?= $(DESTDIR)/usr/share/kselftest
 
-all: $(TEST_PROGS)
+all: $(BINS) $(TEST_PROGS)
+
+../lib/ynl.a:
+	@$(MAKE) -C ../lib
+
+ ../generated/protos.a:
+	@$(MAKE) -C ../generated
+
+$(BINS): ../lib/ynl.a ../generated/protos.a
+	@echo -e '\tCC test $@'
+	@$(COMPILE.c) $(CFLAGS_$@) $@.c -o $@.o
+	@$(LINK.c) $@.o -o $@  $(LDLIBS)
 
 run_tests:
 	@for test in $(TEST_PROGS); do \
 		./$$test; \
 	done
 
-install: $(TEST_PROGS)
+install: $(TEST_PROGS) $(BINS)
 	@mkdir -p $(INSTALL_PATH)/ynl
 	@cp ../../../testing/selftests/kselftest/ktap_helpers.sh $(INSTALL_PATH)/
 	@for test in $(TEST_PROGS); do \
@@ -26,11 +56,18 @@ install: $(TEST_PROGS)
 		    $$test > $(INSTALL_PATH)/ynl/$$name; \
 		chmod +x $(INSTALL_PATH)/ynl/$$name; \
 	done
+	@for bin in $(BINS); do \
+		cp $$bin $(INSTALL_PATH)/ynl/$$bin; \
+	done
 	@for test in $(TEST_PROGS); do \
 		echo "ynl:$$test"; \
 	done > $(INSTALL_PATH)/kselftest-list.txt
 
-clean distclean:
-	@# Nothing to clean
+clean:
+	rm -f *.o *.d *~
 
-.PHONY: all install clean run_tests
+distclean: clean
+	rm -f $(BINS)
+
+.PHONY: all install clean distclean run_tests
+.DEFAULT_GOAL=all
diff --git a/tools/net/ynl/samples/devlink.c b/tools/net/ynl/tests/devlink.c
similarity index 100%
rename from tools/net/ynl/samples/devlink.c
rename to tools/net/ynl/tests/devlink.c
diff --git a/tools/net/ynl/samples/ethtool.c b/tools/net/ynl/tests/ethtool.c
similarity index 100%
rename from tools/net/ynl/samples/ethtool.c
rename to tools/net/ynl/tests/ethtool.c
diff --git a/tools/net/ynl/samples/netdev.c b/tools/net/ynl/tests/netdev.c
similarity index 100%
rename from tools/net/ynl/samples/netdev.c
rename to tools/net/ynl/tests/netdev.c
diff --git a/tools/net/ynl/samples/ovs.c b/tools/net/ynl/tests/ovs.c
similarity index 100%
rename from tools/net/ynl/samples/ovs.c
rename to tools/net/ynl/tests/ovs.c
diff --git a/tools/net/ynl/samples/rt-addr.c b/tools/net/ynl/tests/rt-addr.c
similarity index 100%
rename from tools/net/ynl/samples/rt-addr.c
rename to tools/net/ynl/tests/rt-addr.c
diff --git a/tools/net/ynl/samples/rt-link.c b/tools/net/ynl/tests/rt-link.c
similarity index 100%
rename from tools/net/ynl/samples/rt-link.c
rename to tools/net/ynl/tests/rt-link.c
diff --git a/tools/net/ynl/samples/rt-route.c b/tools/net/ynl/tests/rt-route.c
similarity index 100%
rename from tools/net/ynl/samples/rt-route.c
rename to tools/net/ynl/tests/rt-route.c
diff --git a/tools/net/ynl/samples/tc-filter-add.c b/tools/net/ynl/tests/tc-filter-add.c
similarity index 100%
rename from tools/net/ynl/samples/tc-filter-add.c
rename to tools/net/ynl/tests/tc-filter-add.c
diff --git a/tools/net/ynl/samples/tc.c b/tools/net/ynl/tests/tc.c
similarity index 100%
rename from tools/net/ynl/samples/tc.c
rename to tools/net/ynl/tests/tc.c
diff --git a/tools/net/ynl/samples/.gitignore b/tools/net/ynl/tests/.gitignore
similarity index 87%
rename from tools/net/ynl/samples/.gitignore
rename to tools/net/ynl/tests/.gitignore
index 05087ee323ba..045385df42a4 100644
--- a/tools/net/ynl/samples/.gitignore
+++ b/tools/net/ynl/tests/.gitignore
@@ -1,8 +1,7 @@
-ethtool
 devlink
+ethtool
 netdev
 ovs
-page-pool
 rt-addr
 rt-link
 rt-route
-- 
2.53.0