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>
This commit is contained in:
committed by
Alexei Starovoitov
parent
7cdddb99e4
commit
5b22f4d143
@ -590,6 +590,14 @@ void run_subtest(struct test_loader *tester,
|
|||||||
if (restore_capabilities(&caps))
|
if (restore_capabilities(&caps))
|
||||||
goto tobj_cleanup;
|
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);
|
do_prog_test_run(bpf_program__fd(tprog), &retval);
|
||||||
if (retval != subspec->retval && subspec->retval != POINTER_VALUE) {
|
if (retval != subspec->retval && subspec->retval != POINTER_VALUE) {
|
||||||
PRINT_FAIL("Unexpected retval: %d != %d\n", retval, subspec->retval);
|
PRINT_FAIL("Unexpected retval: %d != %d\n", retval, subspec->retval);
|
||||||
|
@ -424,14 +424,23 @@ int get_bpf_max_tramp_links(void);
|
|||||||
|
|
||||||
#define BPF_TESTMOD_TEST_FILE "/sys/kernel/bpf_testmod"
|
#define BPF_TESTMOD_TEST_FILE "/sys/kernel/bpf_testmod"
|
||||||
|
|
||||||
|
typedef int (*pre_execution_cb)(struct bpf_object *obj);
|
||||||
|
|
||||||
struct test_loader {
|
struct test_loader {
|
||||||
char *log_buf;
|
char *log_buf;
|
||||||
size_t log_buf_sz;
|
size_t log_buf_sz;
|
||||||
size_t next_match_pos;
|
size_t next_match_pos;
|
||||||
|
pre_execution_cb pre_execution_cb;
|
||||||
|
|
||||||
struct bpf_object *obj;
|
struct bpf_object *obj;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static inline void test_loader__set_pre_execution_cb(struct test_loader *tester,
|
||||||
|
pre_execution_cb cb)
|
||||||
|
{
|
||||||
|
tester->pre_execution_cb = cb;
|
||||||
|
}
|
||||||
|
|
||||||
typedef const void *(*skel_elf_bytes_fn)(size_t *sz);
|
typedef const void *(*skel_elf_bytes_fn)(size_t *sz);
|
||||||
|
|
||||||
extern void test_loader__run_subtests(struct test_loader *tester,
|
extern void test_loader__run_subtests(struct test_loader *tester,
|
||||||
|
Reference in New Issue
Block a user