Skip to contentSkip to conversation

selftests/bpf: Remove xxd util dependency

PATCH Applied Mykyta Yatsenko 2 participants 2 messages Jan 28

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 selftests/bpf: Remove xxd util dependency

From: Mykyta Yatsenko <[email protected]>

The verification signature header generation requires converting a binary certificate to a C array. Previously this only worked with xxd (part of vim-common package).
As xxd may not be available on some systems building selftests, it makes sense to substitute it with more common utils: hexdump, wc, sed to generate equivalent C array output.

Tested by generating header with both xxd and hexdump and comparing them.

---
 tools/testing/selftests/bpf/.gitignore |  1 -
 tools/testing/selftests/bpf/Makefile   | 10 ++++++----
 2 files changed, 6 insertions(+), 5 deletions(-)
tools/testing/selftests/bpf/.gitignore +0 -1
index b8bf51b7a0b0..a3ea98211ea6 100644
@@ -23,7 +23,6 @@ test_tcpnotify_user
 test_libbpf
 xdping
 test_cpp
-test_progs_verification_cert
 *.d
 *.subskel.h
 *.skel.h
tools/testing/selftests/bpf/Makefile +6 -4
index 2c2f68a171ed..c6bf4dfb1495 100644
@@ -720,9 +720,12 @@ $(VERIFICATION_CERT) $(PRIVATE_KEY): $(VERIFY_SIG_SETUP)
 	$(Q)mkdir -p $(BUILD_DIR)
 	$(Q)$(VERIFY_SIG_SETUP) genkey $(BUILD_DIR)
 
+# Generates a header with C array declaration, containing test_progs_verification_cert bytes
 $(VERIFY_SIG_HDR): $(VERIFICATION_CERT)
-	$(Q)ln -fs $< test_progs_verification_cert && \
-	xxd -i test_progs_verification_cert > $@
+	$(Q)(echo "unsigned char test_progs_verification_cert[] = {"; \
+	 hexdump -v -e '12/1 "  0x%02x," "\n"' $< | sed 's/0x  ,//g; $$s/,$$//'; \
+	 echo "};"; \
+	 echo "unsigned int test_progs_verification_cert_len = $$(wc -c < $<);") > $@
 
 # Define test_progs test runner.
 TRUNNER_TESTS_DIR := prog_tests
@@ -898,8 +901,7 @@ EXTRA_CLEAN := $(SCRATCH_DIR) $(HOST_SCRATCH_DIR)			\
 			       *.BTF *.BTF_ids *.BTF.base		\
 			       no_alu32 cpuv4 bpf_gcc			\
 			       liburandom_read.so)			\
-	$(OUTPUT)/FEATURE-DUMP.selftests				\
-	test_progs_verification_cert
+	$(OUTPUT)/FEATURE-DUMP.selftests
 
 .PHONY: docs docs-clean
 
Signature · 1 line
2.52.0
#1 lore raw
This patch was applied to bpf/bpf-next.git (master) by Andrii Nakryiko <[email protected]>:

Hello:

This patch was applied to bpf/bpf-next.git (master) by Andrii Nakryiko <[email protected]>:

Quoted 10 lines · On Wed, 28 Jan 2026 19:05:51 +0000 you wrote:

From: Mykyta Yatsenko <[email protected]>

The verification signature header generation requires converting a binary certificate to a C array. Previously this only worked with xxd (part of vim-common package).
As xxd may not be available on some systems building selftests, it makes sense to substitute it with more common utils: hexdump, wc, sed to generate equivalent C array output.

[...]

Here is the summary with links:
- [bpf-next,v3] selftests/bpf: Remove xxd util dependency

    https://git.kernel.org/bpf/bpf-next/c/b640d556a2b3

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html