* [PATCH] test/bpf: use unit test suite
@ 2026-08-30 19:13 Stephen Hemminger
2026-08-31 8:34 ` Marat Khalili
0 siblings, 1 reply; 4+ messages in thread
From: Stephen Hemminger @ 2026-08-30 19:13 UTC (permalink / raw)
To: dev; +Cc: Stephen Hemminger, Konstantin Ananyev, Marat Khalili
The BPF tests registered 23 separate autotests. Collapse them into a
single bpf_autotest suite run by unit_test_suite_runner().
Rename the old table-driven test_bpf() to test_bpf_progs() so that
test_bpf() can be the suite entry point.
Move the #endif of the RTE_LIB_BPF guard to the end of the file. It
closed mid-file, leaving the stack, ELF, convert and atomic tests
outside the guard even though they all call rte_bpf functions.
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
app/test/test_bpf.c | 86 +++++++++++++++++++++++++++++----------------
1 file changed, 56 insertions(+), 30 deletions(-)
diff --git a/app/test/test_bpf.c b/app/test/test_bpf.c
index d85e64e7fb..7f235720e7 100644
--- a/app/test/test_bpf.c
+++ b/app/test/test_bpf.c
@@ -27,6 +27,8 @@ test_bpf(void)
return TEST_SKIPPED;
}
+REGISTER_FAST_TEST(bpf_autotest, NOHUGE_OK, ASAN_OK, test_bpf);
+
#else
#include <rte_bpf.h>
@@ -92,7 +94,6 @@ test_no_instructions(void)
return bpf_load_test(RTE_DIM(ins), ins, EINVAL);
}
-REGISTER_FAST_TEST(bpf_no_instructions_autotest, NOHUGE_OK, ASAN_OK, test_no_instructions);
/*
* Try and load a BPF program comprising single EXIT instruction.
@@ -109,7 +110,6 @@ test_exit_only(void)
return bpf_load_test(RTE_DIM(ins), ins, EINVAL);
}
-REGISTER_FAST_TEST(bpf_exit_only_autotest, NOHUGE_OK, ASAN_OK, test_exit_only);
/*
* Try and load a BPF program with no EXIT instruction.
@@ -129,7 +129,6 @@ test_no_exit(void)
return bpf_load_test(RTE_DIM(ins), ins, EINVAL);
}
-REGISTER_FAST_TEST(bpf_no_exit_autotest, NOHUGE_OK, ASAN_OK, test_no_exit);
/*
* Try and load smallest possible valid BPF program.
@@ -151,7 +150,6 @@ test_minimal_working(void)
return bpf_load_test(RTE_DIM(ins), ins, 0);
}
-REGISTER_FAST_TEST(bpf_minimal_working_autotest, NOHUGE_OK, ASAN_OK, test_minimal_working);
/*
* Try and load valid BPF program adding one to the argument.
@@ -179,7 +177,6 @@ test_add_one(void)
return bpf_load_test(RTE_DIM(ins), ins, 0);
}
-REGISTER_FAST_TEST(bpf_add_one_autotest, NOHUGE_OK, ASAN_OK, test_add_one);
/*
* Try and load valid BPF program subtracting one from the argument.
@@ -207,7 +204,6 @@ test_subtract_one(void)
return bpf_load_test(RTE_DIM(ins), ins, 0);
}
-REGISTER_FAST_TEST(bpf_subtract_one_autotest, NOHUGE_OK, ASAN_OK, test_subtract_one);
/*
* Conditionally jump over invalid operation as first instruction.
@@ -243,8 +239,6 @@ test_jump_over_invalid_first(void)
return bpf_load_test(RTE_DIM(ins), ins, EINVAL);
}
-REGISTER_FAST_TEST(bpf_jump_over_invalid_first_autotest, NOHUGE_OK, ASAN_OK,
- test_jump_over_invalid_first);
/*
* Conditionally jump over invalid operation as non-first instruction.
@@ -286,8 +280,6 @@ test_jump_over_invalid_non_first(void)
return bpf_load_test(RTE_DIM(ins), ins, EINVAL);
}
-REGISTER_FAST_TEST(bpf_jump_over_invalid_non_first_autotest, NOHUGE_OK, ASAN_OK,
- test_jump_over_invalid_non_first);
/*
* Basic functional tests for librte_bpf.
@@ -3796,7 +3788,6 @@ test_bpf_load_null(void)
return 0;
}
-REGISTER_FAST_TEST(bpf_load_null_autotest, NOHUGE_OK, ASAN_OK, test_bpf_load_null);
/* Test calling wrong API for execution of a multi-argument eBPF program. */
static int
@@ -3837,8 +3828,6 @@ test_bpf_exec_wrong_nb_prog_arg(void)
return 0;
}
-REGISTER_FAST_TEST(bpf_exec_wrong_nb_prog_arg_autotest, NOHUGE_OK, ASAN_OK,
- test_bpf_exec_wrong_nb_prog_arg);
/* Test passing unsupported flags when executing an eBPF program. */
static int
@@ -3876,10 +3865,9 @@ test_bpf_exec_wrong_flags(void)
return 0;
}
-REGISTER_FAST_TEST(bpf_exec_wrong_flags_autotest, NOHUGE_OK, ASAN_OK, test_bpf_exec_wrong_flags);
static int
-test_bpf(void)
+test_bpf_progs(void)
{
int32_t rc, rv;
uint32_t i;
@@ -3894,10 +3882,6 @@ test_bpf(void)
return rc;
}
-#endif /* !RTE_LIB_BPF */
-
-REGISTER_FAST_TEST(bpf_autotest, NOHUGE_OK, ASAN_OK, test_bpf);
-
/* Tests of BPF JIT stack alignment when calling external functions (xfuncs). */
/* Function called from the BPF program in a test. */
@@ -4010,7 +3994,6 @@ test_stack_alignment(void)
return TEST_SUCCESS;
}
-REGISTER_FAST_TEST(bpf_stack_alignment_autotest, NOHUGE_OK, ASAN_OK, test_stack_alignment);
/*
* Test copying `__uint128_t`.
@@ -4066,7 +4049,6 @@ test_stack_copy_uint128(void)
#endif
-REGISTER_FAST_TEST(bpf_stack_copy_uint128_autotest, NOHUGE_OK, ASAN_OK, test_stack_copy_uint128);
/*
* Test SSE2 load and store intrinsics.
@@ -4152,7 +4134,6 @@ test_stack_sse2(void)
#endif
-REGISTER_FAST_TEST(bpf_stack_sse2_autotest, NOHUGE_OK, ASAN_OK, test_stack_sse2);
/*
* Run memcpy and rte_memcpy with various data sizes and offsets (unaligned and aligned).
@@ -4285,7 +4266,6 @@ test_stack_memcpy(void)
return TEST_SUCCESS;
}
-REGISTER_FAST_TEST(bpf_stack_memcpy_autotest, NOHUGE_OK, ASAN_OK, test_stack_memcpy);
/*
* The BPF elf load test needs the BPF programs to be successfully
@@ -4801,7 +4781,6 @@ test_bpf_elf(void)
#endif /* !(TEST_BPF_ELF_LOAD && RTE_NULL) */
-REGISTER_FAST_TEST(bpf_elf_autotest, NOHUGE_OK, ASAN_OK, test_bpf_elf);
#ifndef RTE_HAS_LIBPCAP
@@ -5087,7 +5066,6 @@ test_bpf_convert(void)
#endif /* RTE_HAS_LIBPCAP */
-REGISTER_FAST_TEST(bpf_convert_autotest, NOHUGE_OK, ASAN_OK, test_bpf_convert);
/*
* Tests of BPF atomic instructions.
@@ -5244,7 +5222,6 @@ test_xadd32(void)
return run_xchg_test(RTE_DIM(ins), ins, expected);
}
-REGISTER_FAST_TEST(bpf_xadd32_autotest, NOHUGE_OK, ASAN_OK, test_xadd32);
/*
* Test 64-bit XADD.
@@ -5313,7 +5290,6 @@ test_xadd64(void)
return run_xchg_test(RTE_DIM(ins), ins, expected);
}
-REGISTER_FAST_TEST(bpf_xadd64_autotest, NOHUGE_OK, ASAN_OK, test_xadd64);
/*
* Test 32-bit XCHG.
@@ -5408,7 +5384,6 @@ test_xchg32(void)
return run_xchg_test(RTE_DIM(ins), ins, expected);
}
-REGISTER_FAST_TEST(bpf_xchg32_autotest, NOHUGE_OK, ASAN_OK, test_xchg32);
/*
* Test 64-bit XCHG.
@@ -5473,7 +5448,6 @@ test_xchg64(void)
return run_xchg_test(RTE_DIM(ins), ins, expected);
}
-REGISTER_FAST_TEST(bpf_xchg64_autotest, NOHUGE_OK, ASAN_OK, test_xchg64);
/*
* Test invalid and unsupported atomic imm values (also valid ones for control).
@@ -5546,4 +5520,56 @@ test_atomic_imms(void)
return TEST_SUCCESS;
}
-REGISTER_FAST_TEST(bpf_atomic_imms_autotest, NOHUGE_OK, ASAN_OK, test_atomic_imms);
+static struct unit_test_suite test_bpf_suite = {
+ .suite_name = "BPF Unit Test Suite",
+ .unit_test_cases = {
+ /* Loading of the most simple programs. */
+ TEST_CASE(test_no_instructions),
+ TEST_CASE(test_exit_only),
+ TEST_CASE(test_no_exit),
+ TEST_CASE(test_minimal_working),
+ TEST_CASE(test_add_one),
+ TEST_CASE(test_subtract_one),
+ TEST_CASE(test_jump_over_invalid_first),
+ TEST_CASE(test_jump_over_invalid_non_first),
+
+ /* API misuse. */
+ TEST_CASE(test_bpf_load_null),
+ TEST_CASE(test_bpf_exec_wrong_nb_prog_arg),
+ TEST_CASE(test_bpf_exec_wrong_flags),
+
+ /* Execution of the programs in the tests[] table. */
+ TEST_CASE(test_bpf_progs),
+
+ /* JIT stack alignment when calling external functions. */
+ TEST_CASE(test_stack_alignment),
+ TEST_CASE(test_stack_copy_uint128),
+ TEST_CASE(test_stack_sse2),
+ TEST_CASE(test_stack_memcpy),
+
+ /* Loading of programs from ELF objects. */
+ TEST_CASE(test_bpf_elf),
+
+ /* Conversion of cBPF programs. */
+ TEST_CASE(test_bpf_convert),
+
+ /* Atomic instructions. */
+ TEST_CASE(test_xadd32),
+ TEST_CASE(test_xadd64),
+ TEST_CASE(test_xchg32),
+ TEST_CASE(test_xchg64),
+ TEST_CASE(test_atomic_imms),
+
+ TEST_CASES_END()
+ }
+};
+
+static int
+test_bpf(void)
+{
+ return unit_test_suite_runner(&test_bpf_suite);
+}
+
+REGISTER_FAST_TEST(bpf_autotest, NOHUGE_OK, ASAN_OK, test_bpf);
+
+#endif /* !RTE_LIB_BPF */
--
2.53.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* RE: [PATCH] test/bpf: use unit test suite
2026-08-30 19:13 [PATCH] test/bpf: use unit test suite Stephen Hemminger
@ 2026-08-31 8:34 ` Marat Khalili
2026-08-31 15:12 ` Stephen Hemminger
0 siblings, 1 reply; 4+ messages in thread
From: Marat Khalili @ 2026-08-31 8:34 UTC (permalink / raw)
To: Stephen Hemminger; +Cc: Konstantin Ananyev, dev@dpdk.org
Hi!
> The BPF tests registered 23 separate autotests. Collapse them into a
> single bpf_autotest suite run by unit_test_suite_runner().
Some of these tests still don't pass with sanitizer enabled. With them
registered individually there was an option to ignore these failures or only
run the tests that are known to not contain UB. After lumping them in one suite
running BPF tests under sanitizer is going to become much more difficult.
There are other reasons why more granular tests are good, like ease of tracking
or debugging failures. What are the benefits from collapsing them? What is the
actual problem we are trying to solve?
If DPDK CI is running out of tmpfs again, there is a proper fix for that.
> Rename the old table-driven test_bpf() to test_bpf_progs() so that
> test_bpf() can be the suite entry point.
While having only one of the BPF tests called test_bpf was confusing, I'm not
sure new name is more clear.
> Move the #endif of the RTE_LIB_BPF guard to the end of the file. It
> closed mid-file, leaving the stack, ELF, convert and atomic tests
> outside the guard even though they all call rte_bpf functions.
This guard is unnecessary and I already sent a patch to delete it.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] test/bpf: use unit test suite
2026-08-31 8:34 ` Marat Khalili
@ 2026-08-31 15:12 ` Stephen Hemminger
2026-08-31 15:47 ` Marat Khalili
0 siblings, 1 reply; 4+ messages in thread
From: Stephen Hemminger @ 2026-08-31 15:12 UTC (permalink / raw)
To: Marat Khalili; +Cc: Konstantin Ananyev, dev@dpdk.org
On Mon, 31 Aug 2026 08:34:58 +0000
Marat Khalili <marat.khalili@huawei.com> wrote:
> Hi!
>
> > The BPF tests registered 23 separate autotests. Collapse them into a
> > single bpf_autotest suite run by unit_test_suite_runner().
>
> Some of these tests still don't pass with sanitizer enabled. With them
> registered individually there was an option to ignore these failures or only
> run the tests that are known to not contain UB. After lumping them in one suite
> running BPF tests under sanitizer is going to become much more difficult.
>
> There are other reasons why more granular tests are good, like ease of tracking
> or debugging failures. What are the benefits from collapsing them? What is the
> actual problem we are trying to solve?
The only technical difference is that meson runs individual tests in
parallel and have seen some failures on my machine.
But for me it is more about decluttering the output.
^ permalink raw reply [flat|nested] 4+ messages in thread
* RE: [PATCH] test/bpf: use unit test suite
2026-08-31 15:12 ` Stephen Hemminger
@ 2026-08-31 15:47 ` Marat Khalili
0 siblings, 0 replies; 4+ messages in thread
From: Marat Khalili @ 2026-08-31 15:47 UTC (permalink / raw)
To: Stephen Hemminger; +Cc: Konstantin Ananyev, dev@dpdk.org
> The only technical difference is that meson runs individual tests in
> parallel and have seen some failures on my machine.
To the best of my knowledge none of the BPF tests are timing-dependent. If they
fail to run in parallel it may very well be an issue that needs to be
investigated. If it happens again, can you save the logs and open a bug?
> But for me it is more about decluttering the output.
Hard for me to argue with this one, since it is highly subjective. But note
that for the price of 23 separate lines in the meson test output when one of
the tests actually fails the output is significantly less cluttered, only
showing the output of the relevant test.
Do you think 20+ independent tests is too much for a single library? If we set
some hard limit like this then I suppose we have to collapse them. Then I would
elevate bpf_test elements to the level of test suite cases, three levels of
containers is too much and going to be real pain to walk through in gdb.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-08-31 15:47 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-30 19:13 [PATCH] test/bpf: use unit test suite Stephen Hemminger
2026-08-31 8:34 ` Marat Khalili
2026-08-31 15:12 ` Stephen Hemminger
2026-08-31 15:47 ` Marat Khalili
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox