diff options
author | Eduard Zingerman <eddyz87@gmail.com> | 2023-04-21 02:23:16 +0300 |
---|---|---|
committer | Alexei Starovoitov <ast@kernel.org> | 2023-04-20 16:49:16 -0700 |
commit | 5b22f4d1436b2693c7176a76be0ba6d30503bf7c (patch) | |
tree | b238b17a89f346931b2fd66f66e43188a8c50329 /tools/testing/selftests/bpf/test_loader.c | |
parent | 7cdddb99e4a69c26881d279472f1487cd67740c4 (diff) |
selftests/bpf: add pre bpf_prog_test_run_opts() callback for test_loader
When a test case is annotated with __retval tag the test_loader engine
would use libbpf's bpf_prog_test_run_opts() to do a test run of the
program and compare retvals.
This commit allows to perform arbitrary actions on bpf object right
before test loader invokes bpf_prog_test_run_opts(). This could be
used to setup some state for program execution, e.g. fill some maps.
Signed-off-by: Eduard Zingerman <eddyz87@gmail.com>
Link: https://lore.kernel.org/r/20230420232317.2181776-4-eddyz87@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Diffstat (limited to 'tools/testing/selftests/bpf/test_loader.c')
-rw-r--r-- | tools/testing/selftests/bpf/test_loader.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/tools/testing/selftests/bpf/test_loader.c b/tools/testing/selftests/bpf/test_loader.c index e2a1bdc5a570..40c9b7d532c4 100644 --- a/tools/testing/selftests/bpf/test_loader.c +++ b/tools/testing/selftests/bpf/test_loader.c @@ -590,6 +590,14 @@ void run_subtest(struct test_loader *tester, if (restore_capabilities(&caps)) goto tobj_cleanup; + if (tester->pre_execution_cb) { + err = tester->pre_execution_cb(tobj); + if (err) { + PRINT_FAIL("pre_execution_cb failed: %d\n", err); + goto tobj_cleanup; + } + } + do_prog_test_run(bpf_program__fd(tprog), &retval); if (retval != subspec->retval && subspec->retval != POINTER_VALUE) { PRINT_FAIL("Unexpected retval: %d != %d\n", retval, subspec->retval); |