[PATCH v5 3/5] bpf: add a test for BPF ELF load

Marat Khalili marat.khalili at huawei.com
Mon Nov 10 17:38:08 CET 2025


> diff --git a/app/test/bpf/load.c b/app/test/bpf/load.c
> new file mode 100644
> index 0000000000..a4d3d61d7a
> --- /dev/null
> +++ b/app/test/bpf/load.c
> @@ -0,0 +1,51 @@
> +/* SPDX-License-Identifier: BSD-3-Clause
> + *
> + * BPF program for testing rte_bpf_elf_load
> + */
> +
> +typedef unsigned char uint8_t;
> +typedef unsigned short uint16_t;
> +typedef unsigned int uint32_t;
> +typedef unsigned long uint64_t;
> +
> +/* Match the structures from test_bpf.c */
> +struct dummy_offset {
> +	uint64_t u64;
> +	uint32_t u32;
> +	uint16_t u16;
> +	uint8_t  u8;
> +} __attribute__((packed));
> +
> +struct dummy_vect8 {
> +	struct dummy_offset in[8];
> +	struct dummy_offset out[8];
> +};
> +
> +/* External function declaration - provided by test via xsym */
> +extern void dummy_func1(const void *p, uint32_t *v32, uint64_t *v64);
> +
> +/*
> + * Test BPF function that will be loaded from ELF
> + * This function is compiled version of code used in test_call1
> + */

Thank you for this clarification, now it makes more sense why we use these structs.

// snip

> diff --git a/app/test/bpf/meson.build b/app/test/bpf/meson.build
> new file mode 100644
> index 0000000000..b4f54aa976
> --- /dev/null
> +++ b/app/test/bpf/meson.build
> @@ -0,0 +1,52 @@
> +# SPDX-License-Identifier: BSD-3-Clause
> +# Copyright 2025 Stephen Hemminger <stephen at networkplumber.org>
> +
> +bpf_test_hdrs = [ ]
> +
> +# use clang to compile to bpf
> +clang_supports_bpf = false
> +clang = find_program('clang', required: false)
> +if clang.found()
> +    clang_supports_bpf = run_command(clang, '-target', 'bpf', '--print-supported-cpus',
> +                                     check: false).returncode() == 0
> +endif
> +
> +if not clang_supports_bpf
> +    message('app/test_bpf: no BPF load tests missing clang BPF support')
> +    subdir_done()
> +
> +endif
> +
> +xxd = find_program('xxd', required: false)
> +if not xxd.found()
> +    message('app/test_bpf: missing xxd required to convert object to array')
> +    subdir_done()
> +endif
> +
> +# BPF compiler flags
> +bpf_cflags = [ '-O2', '-target', 'bpf', '-g', '-c']
> +
> +# Enable test in test_bpf.c
> +cflags += '-DTEST_BPF_ELF_LOAD'

Sorry for not noticing it earlier, we probably want these tests depend on 
RTE_LIBRTE_BPF_ELF, otherwise they fail when libelf is not installed.

// snip

> +static int
> +test_bpf_elf_load(void)
> +{
> +	static const char test_section[] = "call1";
> +	uint8_t tbuf[sizeof(struct dummy_vect8)];

I still think alignment may become an issue here.



More information about the dev mailing list