Skip to contentSkip to conversation

BPF elf examples

DISCUSSION Stephen Hemminger 3 participants 4 messages Oct 20, 2025 – Oct 21, 2025

lore
Share & tools
lore
#0 lore raw

While looking in more detail at BPF use of VLA, went down a rabbit hole because there are no tests and no examples of loading a BPF program using the elf_load API's in BPF.

Tried using AI to generate tests, and as usual it sort of worked but the example code generated won't load or work. Is there anywhere to find working DPDK examples of using BPF load?

#1 lore raw
Quoted 8 lines

While looking in more detail at BPF use of VLA, went down a rabbit hole because there are no tests and no examples of loading a BPF program using the elf_load API's in BPF.

Tried using AI to generate tests, and as usual it sort of worked but the example code generated won't load or work. Is there anywhere to find working DPDK examples of using BPF load?

app/test-pmd/bpf_cmd.c calls rte_bpf_eth_rx_elf_load/ rte_bpf_eth_tx_elf_load, which in turn calls rte_bpf_elf_load().
Though it is a good point, will think can we add a UT for it too.

#2 lore raw
In reply to Stephen Hemminger
Quoted 4 lines

-----Original Message-----
Tried using AI to generate tests, and as usual it sort of worked but the example code generated won't load or work. Is there anywhere to find working DPDK examples of using BPF load?

Hello! I'm sitting on some patches adding a framework for generating BPF ELF files using libelf and some basic unit tests based on it. Hopefully I'll be able to upstream it within the next couple of months.

Generating ELF files is probably beyond the reach of current AI, but once the framework is there perhaps it could be used to add test cases, would be interesting to try...

#3 lore raw
Quoted 5 lines · On Tue, 21 Oct 2025 11:42:25 +0000 Marat Khalili <[email protected]>…
Quoted 4 lines

-----Original Message-----
Tried using AI to generate tests, and as usual it sort of worked but the example code generated won't load or work. Is there anywhere to find working DPDK examples of using BPF load?

Quoted 7 lines

Hello! I'm sitting on some patches adding a framework for generating BPF ELF files using libelf and some basic unit tests based on it. Hopefully I'll be able to upstream it within the next couple of months.

Generating ELF files is probably beyond the reach of current AI, but once the framework is there perhaps it could be used to add test cases, would be interesting to try...

I have sample programs now (thanks AI). But building them in meson is messy. And integrating standalone files in UT is brittle.
Perhaps using bpftool like tap driver does to generate a header file (.h) and then have UT write a /tmp file to load.