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.

Reviewed-by: Donald Hunter <donald.hunter@gmail.com>
Tested-by: Donald Hunter <donald.hunter@gmail.com>
Link: https://patch.msgid.link/20260307033630.1396085-2-kuba@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
Jakub Kicinski committed 2026-03-09 17:02:25 -07:00
1 parent 0bcac7b112
commit e0aa0c6175
13 files changed
+45 -45

No files matched your search

+2 -2
View File
@@ -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
-36
View File
@@ -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
@@ -1,8 +1,7 @@
ethtool
devlink
ethtool
netdev
ovs
page-pool
rt-addr
rt-link
rt-route
+42 -5
View File
@@ -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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.