Netdev List
 help / color / mirror / Atom feed
From: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
To: netdev@vger.kernel.org
Cc: magnus.karlsson@intel.com, stfomichev@gmail.com, kuba@kernel.org,
	pabeni@redhat.com, tushar.vyavahare@intel.com,
	kerneljasonxing@gmail.com, bjorn@kernel.org,
	Maciej Fijalkowski <maciej.fijalkowski@intel.com>
Subject: [PATCH net-next 2/4] selftests: net: add a generic rule for BPF skeletons
Date: Thu,  5 Nov 2026 14:41:15 +0100	[thread overview]
Message-ID: <20261105134117.977655-3-maciej.fijalkowski@intel.com> (raw)
In-Reply-To: <20261105134117.977655-1-maciej.fijalkowski@intel.com>

Tests that load their BPF program through a bpftool skeleton have to
bring their own rule for the header. Add a pattern rule to bpf.mk that
generates $(OUTPUT)/<name>.skel.h from $(OUTPUT)/<name>.bpf.o with
$(BPFTOOL), the bpftool in PATH by default, and removes the partial
header if bpftool fails.

Also build the programs in the subdirectories listed in BPF_PROG_DIRS,
and have make clean remove all program objects and their skeletons.

xskxceiver, which moves to net/lib/xsk in the next patch, is the first
user of both.

Signed-off-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
---
 tools/testing/selftests/net/bpf.mk | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/net/bpf.mk b/tools/testing/selftests/net/bpf.mk
index a4f6755dd894..e0e10cf44af3 100644
--- a/tools/testing/selftests/net/bpf.mk
+++ b/tools/testing/selftests/net/bpf.mk
@@ -1,6 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0
 # Rules to generate bpf objs
 CLANG ?= clang
+BPFTOOL ?= bpftool
 SCRATCH_DIR := $(OUTPUT)/tools
 BUILD_DIR := $(SCRATCH_DIR)/build
 BPFDIR := $(top_srcdir)/tools/lib/bpf
@@ -35,13 +36,21 @@ endif
 
 CLANG_SYS_INCLUDES = $(call get_sys_includes,$(CLANG),$(CLANG_TARGET_ARCH))
 
-BPF_PROG_OBJS := $(patsubst %.c,$(OUTPUT)/%.o,$(wildcard *.bpf.c))
+# Programs come from *.bpf.c here and in the subdirectories in BPF_PROG_DIRS.
+BPF_PROG_SRCS := $(wildcard *.bpf.c $(addsuffix /*.bpf.c,$(BPF_PROG_DIRS)))
+BPF_PROG_OBJS := $(patsubst %.c,$(OUTPUT)/%.o,$(notdir $(BPF_PROG_SRCS)))
+vpath %.bpf.c $(BPF_PROG_DIRS)
 
 $(BPF_PROG_OBJS): $(OUTPUT)/%.o : %.c $(BPFOBJ) | $(MAKE_DIRS)
 	$(call msg,BPF_PROG,,$@)
 	$(Q)$(CLANG) -O2 -g --target=bpf $(CCINCLUDE) $(CLANG_SYS_INCLUDES) \
 	-c $< -o $@
 
+$(OUTPUT)/%.skel.h: $(OUTPUT)/%.bpf.o
+	$(call msg,GEN-SKEL,,$@)
+	$(Q)$(BPFTOOL) gen skeleton $< name $(notdir $*) > $@ || \
+		{ rm -f $@; exit 1; }
+
 $(BPFOBJ): $(wildcard $(BPFDIR)/*.[ch] $(BPFDIR)/Makefile)		       \
 	   $(APIDIR)/linux/bpf.h					       \
 	   | $(BUILD_DIR)/libbpf
@@ -50,4 +59,4 @@ $(BPFOBJ): $(wildcard $(BPFDIR)/*.[ch] $(BPFDIR)/Makefile)		       \
 		    EXTRA_CFLAGS='-g -O0'				       \
 		    DESTDIR=$(SCRATCH_DIR) prefix= all install_headers
 
-EXTRA_CLEAN += $(SCRATCH_DIR)
+EXTRA_CLEAN += $(SCRATCH_DIR) $(BPF_PROG_OBJS) $(BPF_PROG_OBJS:.bpf.o=.skel.h)
-- 
2.43.0


  parent reply	other threads:[~2026-11-05 13:44 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-05 13:41 [PATCH net-next 0/4] selftests: move the AF_XDP test suite from bpf to net Maciej Fijalkowski
2026-11-05 13:41 ` [PATCH net-next 1/4] selftests/bpf: drop the test_progs AF_XDP wrapper Maciej Fijalkowski
2026-11-05 13:41 ` Maciej Fijalkowski [this message]
2026-11-05 13:41 ` [PATCH net-next 3/4] selftests: xsk: move the AF_XDP test suite to selftests/net Maciej Fijalkowski
2026-11-05 13:41 ` [PATCH net-next 4/4] selftests: net: move xdp_hw_metadata from selftests/bpf Maciej Fijalkowski
2026-11-05 20:43 ` [PATCH net-next 0/4] selftests: move the AF_XDP test suite from bpf to net Stanislav Fomichev
2026-11-09 12:44   ` Maciej Fijalkowski
2026-11-09 16:52     ` Stanislav Fomichev
2026-11-09 19:12       ` Maciej Fijalkowski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261105134117.977655-3-maciej.fijalkowski@intel.com \
    --to=maciej.fijalkowski@intel.com \
    --cc=bjorn@kernel.org \
    --cc=kerneljasonxing@gmail.com \
    --cc=kuba@kernel.org \
    --cc=magnus.karlsson@intel.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=stfomichev@gmail.com \
    --cc=tushar.vyavahare@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox