migrate from bpf_prog_test_run{,_xattr}
Subsystems (6)
v2 cover migrate from bpf_prog_test_run{,_xattr}
Fairly straight-forward mechanical transformation from bpf_prog_test_run and bpf_prog_test_run_xattr to the bpf_prog_test_run_opts goodness. Most of the changes are in tests, though bpftool and libbpf (xsk.c) have one call site each as well.
The only aspect that's still a bit RFC is that prog_run_xattr is testing behavior specific to bpf_prog_test_run_xattr, which does not exist in prog_run_opts. Namely, -EINVAL return on data_out == NULL && data_size_out > 0. Adding this behavior to prog_test_run_opts is one option, keeping the test as-is and cloning it to use bpf_prog_test_run_opts is another possibility. The current version just suppresses the deprecation warning.
As an aside, checkpatch really doesn't like that LIBBPF_OPTS looks like a function call but is formatted like a struct declaration. If anyone cares about formatting, now would be a good time to mention it.
v1 -> v2:
Split selftests/bpf changes into two commits to appease the mailing list.
Delyan Kratunov (4):
selftests: bpf: migrate from bpf_prog_test_run
selftests: bpf: migrate from bpf_prog_test_run_xattr
bpftool: migrate from bpf_prog_test_run_xattr
libbpf: Deprecate bpf_prog_test_run_xattr and bpf_prog_test_run
tools/bpf/bpftool/prog.c | 55 ++-- tools/lib/bpf/bpf.h | 8 +- tools/lib/bpf/xsk.c | 11 +- .../selftests/bpf/prog_tests/atomics.c | 86 +++--- .../testing/selftests/bpf/prog_tests/bpf_nf.c | 10 +- .../selftests/bpf/prog_tests/check_mtu.c | 47 ++-- .../selftests/bpf/prog_tests/cls_redirect.c | 30 +-- .../selftests/bpf/prog_tests/dummy_st_ops.c | 31 +-- .../selftests/bpf/prog_tests/fentry_fexit.c | 33 ++- .../selftests/bpf/prog_tests/fentry_test.c | 9 +- .../selftests/bpf/prog_tests/fexit_bpf2bpf.c | 33 ++- .../selftests/bpf/prog_tests/fexit_stress.c | 26 +- .../selftests/bpf/prog_tests/fexit_test.c | 9 +- .../selftests/bpf/prog_tests/flow_dissector.c | 75 +++--- .../prog_tests/flow_dissector_load_bytes.c | 27 +- .../selftests/bpf/prog_tests/for_each.c | 32 ++- .../bpf/prog_tests/get_func_args_test.c | 14 +- .../bpf/prog_tests/get_func_ip_test.c | 12 +- .../selftests/bpf/prog_tests/global_data.c | 25 +- .../bpf/prog_tests/global_func_args.c | 13 +- .../selftests/bpf/prog_tests/kfree_skb.c | 16 +- .../selftests/bpf/prog_tests/kfunc_call.c | 46 ++-- .../selftests/bpf/prog_tests/ksyms_module.c | 23 +- .../selftests/bpf/prog_tests/l4lb_all.c | 35 ++- .../selftests/bpf/prog_tests/map_lock.c | 15 +- .../selftests/bpf/prog_tests/map_ptr.c | 18 +- .../selftests/bpf/prog_tests/modify_return.c | 38 +-- .../selftests/bpf/prog_tests/pkt_access.c | 27 +- .../selftests/bpf/prog_tests/pkt_md_access.c | 15 +- .../selftests/bpf/prog_tests/prog_run_xattr.c | 5 + .../bpf/prog_tests/queue_stack_map.c | 43 +-- .../bpf/prog_tests/raw_tp_test_run.c | 85 +++--- .../bpf/prog_tests/raw_tp_writable_test_run.c | 16 +- .../selftests/bpf/prog_tests/signal_pending.c | 24 +- .../selftests/bpf/prog_tests/skb_ctx.c | 93 +++---- .../selftests/bpf/prog_tests/skb_helpers.c | 16 +- .../selftests/bpf/prog_tests/sockmap_basic.c | 19 +- .../selftests/bpf/prog_tests/spinlock.c | 15 +- .../selftests/bpf/prog_tests/syscall.c | 12 +- .../selftests/bpf/prog_tests/tailcalls.c | 245 ++++++++++-------- .../selftests/bpf/prog_tests/test_profiler.c | 16 +- .../bpf/prog_tests/test_skb_pkt_end.c | 15 +- .../testing/selftests/bpf/prog_tests/timer.c | 9 +- .../selftests/bpf/prog_tests/timer_mim.c | 9 +- .../selftests/bpf/prog_tests/trace_ext.c | 28 +- tools/testing/selftests/bpf/prog_tests/xdp.c | 35 ++- .../bpf/prog_tests/xdp_adjust_frags.c | 34 ++- .../bpf/prog_tests/xdp_adjust_tail.c | 148 ++++++----- .../selftests/bpf/prog_tests/xdp_bpf2bpf.c | 16 +- .../selftests/bpf/prog_tests/xdp_noinline.c | 45 ++-- .../selftests/bpf/prog_tests/xdp_perf.c | 19 +- tools/testing/selftests/bpf/test_lru_map.c | 11 +- tools/testing/selftests/bpf/test_progs.h | 2 + tools/testing/selftests/bpf/test_verifier.c | 16 +- 54 files changed, 993 insertions(+), 802 deletions(-)
--
2.30.2
PATCH v2 1/4 selftests: bpf: migrate from bpf_prog_test_run
--- .../selftests/bpf/prog_tests/atomics.c | 86 +++--- .../testing/selftests/bpf/prog_tests/bpf_nf.c | 10 +- .../selftests/bpf/prog_tests/fentry_fexit.c | 33 ++- .../selftests/bpf/prog_tests/fentry_test.c | 9 +- .../selftests/bpf/prog_tests/fexit_bpf2bpf.c | 33 ++- .../selftests/bpf/prog_tests/fexit_stress.c | 26 +- .../selftests/bpf/prog_tests/fexit_test.c | 9 +- .../prog_tests/flow_dissector_load_bytes.c | 27 +- .../selftests/bpf/prog_tests/for_each.c | 32 ++- .../bpf/prog_tests/get_func_args_test.c | 14 +- .../bpf/prog_tests/get_func_ip_test.c | 12 +- .../selftests/bpf/prog_tests/global_data.c | 25 +- .../bpf/prog_tests/global_func_args.c | 13 +- .../selftests/bpf/prog_tests/kfunc_call.c | 46 ++-- .../selftests/bpf/prog_tests/ksyms_module.c | 23 +- .../selftests/bpf/prog_tests/l4lb_all.c | 35 ++- .../selftests/bpf/prog_tests/map_lock.c | 15 +- .../selftests/bpf/prog_tests/map_ptr.c | 18 +- .../selftests/bpf/prog_tests/modify_return.c | 38 +-- .../selftests/bpf/prog_tests/pkt_access.c | 27 +- .../selftests/bpf/prog_tests/pkt_md_access.c | 15 +- .../bpf/prog_tests/queue_stack_map.c | 43 +-- .../bpf/prog_tests/raw_tp_writable_test_run.c | 16 +- .../selftests/bpf/prog_tests/signal_pending.c | 24 +- .../selftests/bpf/prog_tests/spinlock.c | 15 +- .../selftests/bpf/prog_tests/tailcalls.c | 245 ++++++++++-------- .../bpf/prog_tests/test_skb_pkt_end.c | 15 +- .../testing/selftests/bpf/prog_tests/timer.c | 9 +- .../selftests/bpf/prog_tests/timer_mim.c | 9 +- .../selftests/bpf/prog_tests/trace_ext.c | 28 +- tools/testing/selftests/bpf/prog_tests/xdp.c | 35 ++- .../bpf/prog_tests/xdp_adjust_frags.c | 34 ++- .../bpf/prog_tests/xdp_adjust_tail.c | 114 +++++--- .../selftests/bpf/prog_tests/xdp_bpf2bpf.c | 16 +- .../selftests/bpf/prog_tests/xdp_noinline.c | 45 ++-- .../selftests/bpf/prog_tests/xdp_perf.c | 19 +- tools/testing/selftests/bpf/test_lru_map.c | 11 +- tools/testing/selftests/bpf/test_progs.h | 2 + tools/testing/selftests/bpf/test_verifier.c | 16 +- 39 files changed, 727 insertions(+), 515 deletions(-)
tools/testing/selftests/bpf/prog_tests/atomics.c +49 -37
@@ -7,18 +7,20 @@static void test_add (struct atomics_lskel *skel) {int err, prog_fd; -__u32 duration =0 , retval;int link_fd; +LIBBPF_OPTS (bpf_test_run_opts, topts, + .repeat = 1, + ); link_fd =atomics_lskel__add__attach (skel);if (!ASSERT_GT (link_fd,0 ,"attach(add)" ))return ; prog_fd = skel->progs.add.prog_fd; - err =bpf_prog_test_run (prog_fd,1 ,NULL ,0 , -NULL ,NULL , &retval, &duration); -if (CHECK (err || retval,"test_run add" , -"err %d errno %d retval %d duration %d\n" , err, errno, retval, duration)) + err =bpf_prog_test_run_opts (prog_fd, &topts); +if (CHECK_OPTS (err || topts.retval,"test_run add" , +"err %d errno %d retval %d duration %d\n" , err, errno, + topts.retval, topts.duration)) goto cleanup;ASSERT_EQ (skel->data->add64_value,3 ,"add64_value" );
@@ -39,19 +41,20 @@ static void test_add(struct atomics_lskel *skel)static void test_sub (struct atomics_lskel *skel) {int err, prog_fd; -__u32 duration =0 , retval;int link_fd; +LIBBPF_OPTS (bpf_test_run_opts, topts, + .repeat = 1, + ); link_fd =atomics_lskel__sub__attach (skel);if (!ASSERT_GT (link_fd,0 ,"attach(sub)" ))return ; prog_fd = skel->progs.sub.prog_fd; - err =bpf_prog_test_run (prog_fd,1 ,NULL ,0 , -NULL ,NULL , &retval, &duration); -if (CHECK (err || retval,"test_run sub" , -"err %d errno %d retval %d duration %d\n" , - err, errno, retval, duration)) + err =bpf_prog_test_run_opts (prog_fd, &topts); +if (CHECK_OPTS (err || topts.retval,"test_run sub" , +"err %d errno %d retval %d duration %d\n" , err, errno, + topts.retval, topts.duration)) goto cleanup;ASSERT_EQ (skel->data->sub64_value,-1 ,"sub64_value" );
@@ -72,18 +75,20 @@ static void test_sub(struct atomics_lskel *skel)static void test_and (struct atomics_lskel *skel) {int err, prog_fd; -__u32 duration =0 , retval;int link_fd; +LIBBPF_OPTS (bpf_test_run_opts, topts, + .repeat = 1, + ); link_fd =atomics_lskel__and__attach (skel);if (!ASSERT_GT (link_fd,0 ,"attach(and)" ))return ; prog_fd = skel->progs.and.prog_fd; - err =bpf_prog_test_run (prog_fd,1 ,NULL ,0 , -NULL ,NULL , &retval, &duration); -if (CHECK (err || retval,"test_run and" , -"err %d errno %d retval %d duration %d\n" , err, errno, retval, duration)) + err =bpf_prog_test_run_opts (prog_fd, &topts); +if (CHECK_OPTS (err || topts.retval,"test_run and" , +"err %d errno %d retval %d duration %d\n" , err, errno, + topts.retval, topts.duration)) goto cleanup;ASSERT_EQ (skel->data->and64_value,0x010ull <<32 ,"and64_value" );
@@ -100,19 +105,20 @@ static void test_and(struct atomics_lskel *skel)static void test_or (struct atomics_lskel *skel) {int err, prog_fd; -__u32 duration =0 , retval;int link_fd; +LIBBPF_OPTS (bpf_test_run_opts, topts, + .repeat = 1, + ); link_fd =atomics_lskel__or__attach (skel);if (!ASSERT_GT (link_fd,0 ,"attach(or)" ))return ; prog_fd = skel->progs.or.prog_fd; - err =bpf_prog_test_run (prog_fd,1 ,NULL ,0 , -NULL ,NULL , &retval, &duration); -if (CHECK (err || retval,"test_run or" , -"err %d errno %d retval %d duration %d\n" , - err, errno, retval, duration)) + err =bpf_prog_test_run_opts (prog_fd, &topts); +if (CHECK_OPTS (err || topts.retval,"test_run or" , +"err %d errno %d retval %d duration %d\n" , err, errno, + topts.retval, topts.duration)) goto cleanup;ASSERT_EQ (skel->data->or64_value,0x111ull <<32 ,"or64_value" );
@@ -129,18 +135,20 @@ static void test_or(struct atomics_lskel *skel)static void test_xor (struct atomics_lskel *skel) {int err, prog_fd; -__u32 duration =0 , retval;int link_fd; +LIBBPF_OPTS (bpf_test_run_opts, topts, + .repeat = 1, + ); link_fd =atomics_lskel__xor__attach (skel);if (!ASSERT_GT (link_fd,0 ,"attach(xor)" ))return ; prog_fd = skel->progs.xor.prog_fd; - err =bpf_prog_test_run (prog_fd,1 ,NULL ,0 , -NULL ,NULL , &retval, &duration); -if (CHECK (err || retval,"test_run xor" , -"err %d errno %d retval %d duration %d\n" , err, errno, retval, duration)) + err =bpf_prog_test_run_opts (prog_fd, &topts); +if (CHECK_OPTS (err || topts.retval,"test_run xor" , +"err %d errno %d retval %d duration %d\n" , err, errno, + topts.retval, topts.duration)) goto cleanup;ASSERT_EQ (skel->data->xor64_value,0x101ull <<32 ,"xor64_value" );
@@ -157,18 +165,20 @@ static void test_xor(struct atomics_lskel *skel)static void test_cmpxchg (struct atomics_lskel *skel) {int err, prog_fd; -__u32 duration =0 , retval;int link_fd; +LIBBPF_OPTS (bpf_test_run_opts, topts, + .repeat = 1, + ); link_fd =atomics_lskel__cmpxchg__attach (skel);if (!ASSERT_GT (link_fd,0 ,"attach(cmpxchg)" ))return ; prog_fd = skel->progs.cmpxchg.prog_fd; - err =bpf_prog_test_run (prog_fd,1 ,NULL ,0 , -NULL ,NULL , &retval, &duration); -if (CHECK (err || retval,"test_run cmpxchg" , -"err %d errno %d retval %d duration %d\n" , err, errno, retval, duration)) + err =bpf_prog_test_run_opts (prog_fd, &topts); +if (CHECK_OPTS (err || topts.retval,"test_run cmpxchg" , +"err %d errno %d retval %d duration %d\n" , err, errno, + topts.retval, topts.duration)) goto cleanup;ASSERT_EQ (skel->data->cmpxchg64_value,2 ,"cmpxchg64_value" );
@@ -186,18 +196,20 @@ static void test_cmpxchg(struct atomics_lskel *skel)static void test_xchg (struct atomics_lskel *skel) {int err, prog_fd; -__u32 duration =0 , retval;int link_fd; +LIBBPF_OPTS (bpf_test_run_opts, topts, + .repeat = 1, + ); link_fd =atomics_lskel__xchg__attach (skel);if (!ASSERT_GT (link_fd,0 ,"attach(xchg)" ))return ; prog_fd = skel->progs.xchg.prog_fd; - err =bpf_prog_test_run (prog_fd,1 ,NULL ,0 , -NULL ,NULL , &retval, &duration); -if (CHECK (err || retval,"test_run xchg" , -"err %d errno %d retval %d duration %d\n" , err, errno, retval, duration)) + err =bpf_prog_test_run_opts (prog_fd, &topts); +if (CHECK_OPTS (err || topts.retval,"test_run xchg" , +"err %d errno %d retval %d duration %d\n" , err, errno, + topts.retval, topts.duration)) goto cleanup;ASSERT_EQ (skel->data->xchg64_value,2 ,"xchg64_value" );
tools/testing/selftests/bpf/prog_tests/bpf_nf.c +7 -3
@@ -11,7 +11,12 @@ enum {void test_bpf_nf_ct (int mode) {struct test_bpf_nf *skel; -int prog_fd, err, retval; +int prog_fd, err; +LIBBPF_OPTS (bpf_test_run_opts, topts, + .data_in = &pkt_v4, + .data_size_in = sizeof(pkt_v4), + .repeat = 1, + ); skel =test_bpf_nf__open_and_load ();if (!ASSERT_OK_PTR (skel,"test_bpf_nf__open_and_load" ))
@@ -22,8 +27,7 @@ void test_bpf_nf_ct(int mode)else prog_fd =bpf_program__fd (skel->progs.nf_skb_ct_test); - err =bpf_prog_test_run (prog_fd,1 , &pkt_v4,sizeof (pkt_v4),NULL ,NULL , - (__u32 *)&retval,NULL ); + err =bpf_prog_test_run_opts (prog_fd, &topts);if (!ASSERT_OK (err,"bpf_prog_test_run" )) goto end;
tools/testing/selftests/bpf/prog_tests/fentry_fexit.c +19 -14
@@ -9,38 +9,43 @@ void test_fentry_fexit(void)struct fentry_test_lskel *fentry_skel =NULL ;struct fexit_test_lskel *fexit_skel =NULL ;__u64 *fentry_res, *fexit_res; -__u32 duration =0 , retval;int err, prog_fd, i; +LIBBPF_OPTS (bpf_test_run_opts, topts, + .repeat = 1, + ); fentry_skel =fentry_test_lskel__open_and_load (); -if (CHECK (!fentry_skel,"fentry_skel_load" ,"fentry skeleton failed\n" )) +if (CHECK_OPTS (!fentry_skel,"fentry_skel_load" , +"fentry skeleton failed\n" )) goto close_prog; fexit_skel =fexit_test_lskel__open_and_load (); -if (CHECK (!fexit_skel,"fexit_skel_load" ,"fexit skeleton failed\n" )) +if (CHECK_OPTS (!fexit_skel,"fexit_skel_load" , +"fexit skeleton failed\n" )) goto close_prog; err =fentry_test_lskel__attach (fentry_skel); -if (CHECK (err,"fentry_attach" ,"fentry attach failed: %d\n" , err)) +if (CHECK_OPTS (err,"fentry_attach" ,"fentry attach failed: %d\n" , err)) goto close_prog; err =fexit_test_lskel__attach (fexit_skel); -if (CHECK (err,"fexit_attach" ,"fexit attach failed: %d\n" , err)) +if (CHECK_OPTS (err,"fexit_attach" ,"fexit attach failed: %d\n" , err)) goto close_prog; prog_fd = fexit_skel->progs.test1.prog_fd; - err =bpf_prog_test_run (prog_fd,1 ,NULL ,0 , -NULL ,NULL , &retval, &duration); -CHECK (err || retval,"ipv6" , -"err %d errno %d retval %d duration %d\n" , - err, errno, retval, duration); + err =bpf_prog_test_run_opts (prog_fd, &topts); +CHECK_OPTS (err || topts.retval,"ipv6" , +"err %d errno %d retval %d duration %d\n" , err, errno, + topts.retval, topts.duration); fentry_res = (__u64 *)fentry_skel->bss; fexit_res = (__u64 *)fexit_skel->bss;printf ("%lld\n" , fentry_skel->bss->test1_result);for (i =0 ; i <8 ; i++) { -CHECK (fentry_res[i] !=1 ,"result" , -"fentry_test%d failed err %lld\n" , i +1 , fentry_res[i]); -CHECK (fexit_res[i] !=1 ,"result" , -"fexit_test%d failed err %lld\n" , i +1 , fexit_res[i]); +CHECK_OPTS (fentry_res[i] !=1 ,"result" , +"fentry_test%d failed err %lld\n" , i +1 , + fentry_res[i]); +CHECK_OPTS (fexit_res[i] !=1 ,"result" , +"fexit_test%d failed err %lld\n" , i +1 , + fexit_res[i]); } close_prog:
tools/testing/selftests/bpf/prog_tests/fentry_test.c +5 -4
@@ -6,9 +6,11 @@static int fentry_test (struct fentry_test_lskel *fentry_skel) {int err, prog_fd, i; -__u32 duration =0 , retval;int link_fd;__u64 *result; +LIBBPF_OPTS (bpf_test_run_opts, topts, + .repeat = 1, + ); err =fentry_test_lskel__attach (fentry_skel);if (!ASSERT_OK (err,"fentry_attach" ))
@@ -20,10 +22,9 @@ static int fentry_test(struct fentry_test_lskel *fentry_skel)return -1 ; prog_fd = fentry_skel->progs.test1.prog_fd; - err =bpf_prog_test_run (prog_fd,1 ,NULL ,0 , -NULL ,NULL , &retval, &duration); + err =bpf_prog_test_run_opts (prog_fd, &topts);ASSERT_OK (err,"test_run" ); -ASSERT_EQ (retval,0 ,"test_run" ); +ASSERT_EQ (topts.retval,0 ,"test_run" ); result = (__u64 *)fentry_skel->bss;for (i =0 ; i <sizeof (*fentry_skel->bss) /sizeof (__u64); i++) {
tools/testing/selftests/bpf/prog_tests/fexit_bpf2bpf.c +20 -13
@@ -58,12 +58,17 @@ static void test_fexit_bpf2bpf_common(const char *obj_file, test_cb cb) {struct bpf_object *obj =NULL , *tgt_obj; -__u32 retval, tgt_prog_id, info_len; +__u32 tgt_prog_id, info_len;struct bpf_prog_info prog_info = {};struct bpf_program **prog =NULL , *p;struct bpf_link **link =NULL ;int err, tgt_fd, i;struct btf *btf; +LIBBPF_OPTS (bpf_test_run_opts, topts, + .data_in = &pkt_v6, + .data_size_in = sizeof(pkt_v6), + .repeat = 1, + ); err =bpf_prog_test_load (target_obj_file,BPF_PROG_TYPE_UNSPEC , &tgt_obj, &tgt_fd);
@@ -147,10 +152,9 @@ static void test_fexit_bpf2bpf_common(const char *obj_file,if (!run_prog) goto close_prog; - err =bpf_prog_test_run (tgt_fd,1 , &pkt_v6,sizeof (pkt_v6), -NULL ,NULL , &retval,NULL ); + err =bpf_prog_test_run_opts (tgt_fd, &topts);ASSERT_OK (err,"prog_run" ); -ASSERT_EQ (retval,0 ,"prog_run_ret" ); +ASSERT_EQ (topts.retval,0 ,"prog_run_ret" );if (check_data_map (obj, prog_cnt, false)) goto close_prog;
@@ -225,29 +229,32 @@ static int test_second_attach(struct bpf_object *obj)const char *tgt_obj_file ="./test_pkt_access.o" ;struct bpf_program *prog =NULL ;struct bpf_object *tgt_obj; -__u32 duration =0 , retval;struct bpf_link *link;int err =0 , tgt_fd; +LIBBPF_OPTS (bpf_test_run_opts, topts, + .data_in = &pkt_v6, + .data_size_in = sizeof(pkt_v6), + .repeat = 1, + ); prog =bpf_object__find_program_by_name (obj, prog_name); -if (CHECK (!prog,"find_prog" ,"prog %s not found\n" , prog_name)) +if (CHECK_OPTS (!prog,"find_prog" ,"prog %s not found\n" , prog_name))return -ENOENT ; err =bpf_prog_test_load (tgt_obj_file,BPF_PROG_TYPE_UNSPEC , &tgt_obj, &tgt_fd); -if (CHECK (err,"second_prog_load" ,"file %s err %d errno %d\n" , - tgt_obj_file, err, errno)) +if (CHECK_OPTS (err,"second_prog_load" ,"file %s err %d errno %d\n" , + tgt_obj_file, err, errno))return err; link =bpf_program__attach_freplace (prog, tgt_fd, tgt_name);if (!ASSERT_OK_PTR (link,"second_link" )) goto out; - err =bpf_prog_test_run (tgt_fd,1 , &pkt_v6,sizeof (pkt_v6), -NULL ,NULL , &retval, &duration); -if (CHECK (err || retval,"ipv6" , -"err %d errno %d retval %d duration %d\n" , - err, errno, retval, duration)) + err =bpf_prog_test_run_opts (tgt_fd, &topts); +if (CHECK_OPTS (err || topts.retval,"ipv6" , +"err %d errno %d retval %d duration %d\n" , err, errno, + topts.retval, topts.duration)) goto out; err =check_data_map (obj,1 , true);
tools/testing/selftests/bpf/prog_tests/fexit_stress.c +15 -11
@@ -10,9 +10,7 @@ void test_fexit_stress(void)char test_skb[128 ] = {};int fexit_fd[CNT ] = {};int link_fd[CNT ] = {}; -__u32 duration =0 ;char error[4096 ]; -__u32 prog_ret;int err, i, filter_fd;const struct bpf_insn trace_program[] = {
@@ -36,9 +34,15 @@ void test_fexit_stress(void) .log_size = sizeof(error), ); +LIBBPF_OPTS (bpf_test_run_opts, topts, + .data_in = test_skb, + .data_size_in = sizeof(test_skb), + .repeat = 1, + ); + err =libbpf_find_vmlinux_btf_id ("bpf_fentry_test1" , trace_opts.expected_attach_type); -if (CHECK (err <=0 ,"find_vmlinux_btf_id" ,"failed: %d\n" , err)) +if (CHECK_OPTS (err <=0 ,"find_vmlinux_btf_id" ,"failed: %d\n" , err)) goto out; trace_opts.attach_btf_id = err;
@@ -47,24 +51,24 @@ void test_fexit_stress(void) trace_program,sizeof (trace_program) /sizeof (struct bpf_insn ), &trace_opts); -if (CHECK (fexit_fd[i] <0 ,"fexit loaded" , -"failed: %d errno %d\n" , fexit_fd[i], errno)) +if (CHECK_OPTS (fexit_fd[i] <0 ,"fexit loaded" , +"failed: %d errno %d\n" , fexit_fd[i], errno)) goto out; link_fd[i] =bpf_raw_tracepoint_open (NULL , fexit_fd[i]); -if (CHECK (link_fd[i] <0 ,"fexit attach failed" , -"prog %d failed: %d err %d\n" , i, link_fd[i], errno)) +if (CHECK_OPTS (link_fd[i] <0 ,"fexit attach failed" , +"prog %d failed: %d err %d\n" , i, link_fd[i], + errno)) goto out; } filter_fd =bpf_prog_load (BPF_PROG_TYPE_SOCKET_FILTER ,NULL ,"GPL" , skb_program,sizeof (skb_program) /sizeof (struct bpf_insn ), &skb_opts); -if (CHECK (filter_fd <0 ,"test_program_loaded" ,"failed: %d errno %d\n" , - filter_fd, errno)) +if (CHECK_OPTS (filter_fd <0 ,"test_program_loaded" , +"failed: %d errno %d\n" , filter_fd, errno)) goto out; - err =bpf_prog_test_run (filter_fd,1 , test_skb,sizeof (test_skb),0 , -0 , &prog_ret,0 ); + err =bpf_prog_test_run_opts (filter_fd, &topts);close (filter_fd);CHECK_FAIL (err); out:
tools/testing/selftests/bpf/prog_tests/fexit_test.c +5 -4
@@ -6,9 +6,11 @@static int fexit_test (struct fexit_test_lskel *fexit_skel) {int err, prog_fd, i; -__u32 duration =0 , retval;int link_fd;__u64 *result; +LIBBPF_OPTS (bpf_test_run_opts, topts, + .repeat = 1, + ); err =fexit_test_lskel__attach (fexit_skel);if (!ASSERT_OK (err,"fexit_attach" ))
@@ -20,10 +22,9 @@ static int fexit_test(struct fexit_test_lskel *fexit_skel)return -1 ; prog_fd = fexit_skel->progs.test1.prog_fd; - err =bpf_prog_test_run (prog_fd,1 ,NULL ,0 , -NULL ,NULL , &retval, &duration); + err =bpf_prog_test_run_opts (prog_fd, &topts);ASSERT_OK (err,"test_run" ); -ASSERT_EQ (retval,0 ,"test_run" ); +ASSERT_EQ (topts.retval,0 ,"test_run" ); result = (__u64 *)fexit_skel->bss;for (i =0 ; i <sizeof (*fexit_skel->bss) /sizeof (__u64); i++) {
tools/testing/selftests/bpf/prog_tests/flow_dissector_load_bytes.c +16 -11
@@ -5,7 +5,6 @@void serial_test_flow_dissector_load_bytes (void ) {struct bpf_flow_keys flow_keys; -__u32 duration =0 , retval, size;struct bpf_insn prog[] = {// BPF_REG_1 - 1st argument: context // BPF_REG_2 - 2nd argument: offset, start at first byte
@@ -27,22 +26,28 @@ void serial_test_flow_dissector_load_bytes(void) BPF_EXIT_INSN(), };int fd, err; +LIBBPF_OPTS (bpf_test_run_opts, topts, + .data_in = &pkt_v4, + .data_size_in = sizeof(pkt_v4), + .data_out = &flow_keys, + .data_size_out = sizeof(flow_keys), + .repeat = 1, + );/* make sure bpf_skb_load_bytes is not allowed from skb-less context */ fd =bpf_test_load_program (BPF_PROG_TYPE_FLOW_DISSECTOR , prog,ARRAY_SIZE (prog),"GPL" ,0 ,NULL ,0 ); -CHECK (fd <0 , -"flow_dissector-bpf_skb_load_bytes-load" , -"fd %d errno %d\n" , - fd, errno); +CHECK_OPTS (fd <0 ,"flow_dissector-bpf_skb_load_bytes-load" , +"fd %d errno %d\n" , fd, errno); - err =bpf_prog_test_run (fd,1 , &pkt_v4,sizeof (pkt_v4), - &flow_keys, &size, &retval, &duration); -CHECK (size !=sizeof (flow_keys) || err || retval !=1 , -"flow_dissector-bpf_skb_load_bytes" , -"err %d errno %d retval %d duration %d size %u/%zu\n" , - err, errno, retval, duration, size,sizeof (flow_keys)); + err =bpf_prog_test_run_opts (fd, &topts); +CHECK_OPTS (topts.data_size_out !=sizeof (flow_keys) || err || + topts.retval !=1 , +"flow_dissector-bpf_skb_load_bytes" , +"err %d errno %d retval %d duration %d size %u/%zu\n" , err, + errno, topts.retval, topts.duration, topts.data_size_out, +sizeof (flow_keys));if (fd >=-1 )close (fd);
tools/testing/selftests/bpf/prog_tests/for_each.c +20 -12
@@ -12,8 +12,13 @@ static void test_hash_map(void)int i, err, hashmap_fd, max_entries, percpu_map_fd;struct for_each_hash_map_elem *skel;__u64 *percpu_valbuf =NULL ; -__u32 key, num_cpus, retval; +__u32 key, num_cpus;__u64 val; +LIBBPF_OPTS (bpf_test_run_opts, topts, + .data_in = &pkt_v4, + .data_size_in = sizeof(pkt_v4), + .repeat = 1, + ); skel =for_each_hash_map_elem__open_and_load ();if (!ASSERT_OK_PTR (skel,"for_each_hash_map_elem__open_and_load" ))
@@ -42,11 +47,10 @@ static void test_hash_map(void)if (!ASSERT_OK (err,"percpu_map_update" )) goto out; - err =bpf_prog_test_run (bpf_program__fd (skel->progs.test_pkt_access), -1 , &pkt_v4,sizeof (pkt_v4),NULL ,NULL , - &retval, &duration); -if (CHECK (err || retval,"ipv4" ,"err %d errno %d retval %d\n" , - err, errno, retval)) + err =bpf_prog_test_run_opts (bpf_program__fd (skel->progs.test_pkt_access), &topts); + duration = topts.duration; +if (CHECK (err || topts.retval,"ipv4" ,"err %d errno %d retval %d\n" , + err, errno, topts.retval)) goto out;ASSERT_EQ (skel->bss->hashmap_output,4 ,"hashmap_output" );
@@ -69,11 +73,16 @@ static void test_hash_map(void)static void test_array_map (void ) { -__u32 key, num_cpus, max_entries, retval; +__u32 key, num_cpus, max_entries;int i, arraymap_fd, percpu_map_fd, err;struct for_each_array_map_elem *skel;__u64 *percpu_valbuf =NULL ;__u64 val, expected_total; +LIBBPF_OPTS (bpf_test_run_opts, topts, + .data_in = &pkt_v4, + .data_size_in = sizeof(pkt_v4), + .repeat = 1, + ); skel =for_each_array_map_elem__open_and_load ();if (!ASSERT_OK_PTR (skel,"for_each_array_map_elem__open_and_load" ))
@@ -106,11 +115,10 @@ static void test_array_map(void)if (!ASSERT_OK (err,"percpu_map_update" )) goto out; - err =bpf_prog_test_run (bpf_program__fd (skel->progs.test_pkt_access), -1 , &pkt_v4,sizeof (pkt_v4),NULL ,NULL , - &retval, &duration); -if (CHECK (err || retval,"ipv4" ,"err %d errno %d retval %d\n" , - err, errno, retval)) + err =bpf_prog_test_run_opts (bpf_program__fd (skel->progs.test_pkt_access), &topts); + duration = topts.duration; +if (CHECK (err || topts.retval,"ipv4" ,"err %d errno %d retval %d\n" , + err, errno, topts.retval)) goto out;ASSERT_EQ (skel->bss->arraymap_output, expected_total,"array_output" );
tools/testing/selftests/bpf/prog_tests/get_func_args_test.c +7 -7
@@ -5,8 +5,10 @@void test_get_func_args_test (void ) {struct get_func_args_test *skel =NULL ; -__u32 duration =0 , retval;int err, prog_fd; +LIBBPF_OPTS (bpf_test_run_opts, topts, + .repeat = 1, + ); skel =get_func_args_test__open_and_load ();if (!ASSERT_OK_PTR (skel,"get_func_args_test__open_and_load" ))
@@ -20,19 +22,17 @@ void test_get_func_args_test(void)* fentry/fexit programs. */ prog_fd =bpf_program__fd (skel->progs.test1); - err =bpf_prog_test_run (prog_fd,1 ,NULL ,0 , -NULL ,NULL , &retval, &duration); + err =bpf_prog_test_run_opts (prog_fd, &topts);ASSERT_OK (err,"test_run" ); -ASSERT_EQ (retval,0 ,"test_run" ); +ASSERT_EQ (topts.retval,0 ,"test_run" );/* This runs bpf_modify_return_test function and triggers * fmod_ret_test and fexit_test programs. */ prog_fd =bpf_program__fd (skel->progs.fmod_ret_test); - err =bpf_prog_test_run (prog_fd,1 ,NULL ,0 , -NULL ,NULL , &retval, &duration); + err =bpf_prog_test_run_opts (prog_fd, &topts);ASSERT_OK (err,"test_run" ); -ASSERT_EQ (retval,1234 ,"test_run" ); +ASSERT_EQ (topts.retval,1234 ,"test_run" );ASSERT_EQ (skel->bss->test1_result,1 ,"test1_result" );ASSERT_EQ (skel->bss->test2_result,1 ,"test2_result" );
tools/testing/selftests/bpf/prog_tests/get_func_ip_test.c +6 -6
@@ -5,8 +5,10 @@void test_get_func_ip_test (void ) {struct get_func_ip_test *skel =NULL ; -__u32 duration =0 , retval;int err, prog_fd; +LIBBPF_OPTS (bpf_test_run_opts, topts, + .repeat = 1, + ); skel =get_func_ip_test__open ();if (!ASSERT_OK_PTR (skel,"get_func_ip_test__open" ))
@@ -29,14 +31,12 @@ void test_get_func_ip_test(void) goto cleanup; prog_fd =bpf_program__fd (skel->progs.test1); - err =bpf_prog_test_run (prog_fd,1 ,NULL ,0 , -NULL ,NULL , &retval, &duration); + err =bpf_prog_test_run_opts (prog_fd, &topts);ASSERT_OK (err,"test_run" ); -ASSERT_EQ (retval,0 ,"test_run" ); +ASSERT_EQ (topts.retval,0 ,"test_run" ); prog_fd =bpf_program__fd (skel->progs.test5); - err =bpf_prog_test_run (prog_fd,1 ,NULL ,0 , -NULL ,NULL , &retval, &duration); + err =bpf_prog_test_run_opts (prog_fd, &topts);ASSERT_OK (err,"test_run" );
tools/testing/selftests/bpf/prog_tests/global_data.c +14 -11
@@ -132,24 +132,27 @@ static void test_global_data_rdonly(struct bpf_object *obj, __u32 duration)void test_global_data (void ) {const char *file ="./test_global_data.o" ; -__u32 duration =0 , retval;struct bpf_object *obj;int err, prog_fd; +LIBBPF_OPTS (bpf_test_run_opts, topts, + .data_in = &pkt_v4, + .data_size_in = sizeof(pkt_v4), + .repeat = 1, + ); err =bpf_prog_test_load (file,BPF_PROG_TYPE_SCHED_CLS , &obj, &prog_fd); -if (CHECK (err,"load program" ,"error %d loading %s\n" , err, file)) +if (CHECK_OPTS (err,"load program" ,"error %d loading %s\n" , err, file))return ; - err =bpf_prog_test_run (prog_fd,1 , &pkt_v4,sizeof (pkt_v4), -NULL ,NULL , &retval, &duration); -CHECK (err || retval,"pass global data run" , -"err %d errno %d retval %d duration %d\n" , - err, errno, retval, duration); + err =bpf_prog_test_run_opts (prog_fd, &topts); +CHECK_OPTS (err || topts.retval,"pass global data run" , +"err %d errno %d retval %d duration %d\n" , err, errno, + topts.retval, topts.duration); -test_global_data_number (obj, duration); -test_global_data_string (obj, duration); -test_global_data_struct (obj, duration); -test_global_data_rdonly (obj, duration); +test_global_data_number (obj, topts.duration); +test_global_data_string (obj, topts.duration); +test_global_data_struct (obj, topts.duration); +test_global_data_rdonly (obj, topts.duration);bpf_object__close (obj); }
tools/testing/selftests/bpf/prog_tests/global_func_args.c +8 -5
@@ -40,19 +40,22 @@ static void test_global_func_args0(struct bpf_object *obj)void test_global_func_args (void ) {const char *file ="./test_global_func_args.o" ; -__u32 retval;struct bpf_object *obj;int err, prog_fd; +LIBBPF_OPTS (bpf_test_run_opts, topts, + .data_in = &pkt_v4, + .data_size_in = sizeof(pkt_v4), + .repeat = 1, + ); err =bpf_prog_test_load (file,BPF_PROG_TYPE_CGROUP_SKB , &obj, &prog_fd);if (CHECK (err,"load program" ,"error %d loading %s\n" , err, file))return ; - err =bpf_prog_test_run (prog_fd,1 , &pkt_v4,sizeof (pkt_v4), -NULL ,NULL , &retval, &duration); -CHECK (err || retval,"pass global func args run" , + err =bpf_prog_test_run_opts (prog_fd, &topts); +CHECK (err || topts.retval,"pass global func args run" ,"err %d errno %d retval %d duration %d\n" , - err, errno, retval, duration); + err, errno, topts.retval, topts.duration);test_global_func_args0 (obj);
tools/testing/selftests/bpf/prog_tests/kfunc_call.c +28 -18
91 lines not on this page · raw message
tools/testing/selftests/bpf/prog_tests/ksyms_module.c +15 -8
@@ -9,8 +9,12 @@void test_ksyms_module_lskel (void ) {struct test_ksyms_module_lskel *skel; -int retval;int err; +LIBBPF_OPTS (bpf_test_run_opts, topts, + .data_in = &pkt_v4, + .data_size_in = sizeof(pkt_v4), + .repeat = 1, + );if (!env.has_testmod) {test__skip ();
@@ -20,11 +24,10 @@ void test_ksyms_module_lskel(void) skel =test_ksyms_module_lskel__open_and_load ();if (!ASSERT_OK_PTR (skel,"test_ksyms_module_lskel__open_and_load" ))return ; - err =bpf_prog_test_run (skel->progs.load.prog_fd,1 , &pkt_v4,sizeof (pkt_v4), -NULL ,NULL , (__u32 *)&retval,NULL ); + err =bpf_prog_test_run_opts (skel->progs.load.prog_fd, &topts);if (!ASSERT_OK (err,"bpf_prog_test_run" )) goto cleanup; -ASSERT_EQ (retval,0 ,"retval" ); +ASSERT_EQ (topts.retval,0 ,"retval" );ASSERT_EQ (skel->bss->out_bpf_testmod_ksym,42 ,"bpf_testmod_ksym" ); cleanup:test_ksyms_module_lskel__destroy (skel);
@@ -33,7 +36,12 @@ void test_ksyms_module_lskel(void)void test_ksyms_module_libbpf (void ) {struct test_ksyms_module *skel; -int retval, err; +int err; +LIBBPF_OPTS (bpf_test_run_opts, topts, + .data_in = &pkt_v4, + .data_size_in = sizeof(pkt_v4), + .repeat = 1, + );if (!env.has_testmod) {test__skip ();
@@ -43,11 +51,10 @@ void test_ksyms_module_libbpf(void) skel =test_ksyms_module__open_and_load ();if (!ASSERT_OK_PTR (skel,"test_ksyms_module__open" ))return ; - err =bpf_prog_test_run (bpf_program__fd (skel->progs.load),1 , &pkt_v4, -sizeof (pkt_v4),NULL ,NULL , (__u32 *)&retval,NULL ); + err =bpf_prog_test_run_opts (bpf_program__fd (skel->progs.load), &topts);if (!ASSERT_OK (err,"bpf_prog_test_run" )) goto cleanup; -ASSERT_EQ (retval,0 ,"retval" ); +ASSERT_EQ (topts.retval,0 ,"retval" );ASSERT_EQ (skel->bss->out_bpf_testmod_ksym,42 ,"bpf_testmod_ksym" ); cleanup:test_ksyms_module__destroy (skel);
tools/testing/selftests/bpf/prog_tests/l4lb_all.c +22 -13
@@ -23,12 +23,16 @@ static void test_l4lb(const char *file)__u8 flags; } real_def = {.dst = MAGIC_VAL};__u32 ch_key =11 , real_num =3 ; -__u32 duration, retval, size;int err, i, prog_fd, map_fd;__u64 bytes =0 , pkts =0 ;struct bpf_object *obj;char buf[128 ];u32 *magic = (u32 *)buf; +LIBBPF_OPTS (bpf_test_run_opts, topts, + .data_out = buf, + .data_size_out = sizeof(buf), + .repeat = NUM_ITER, + ); err =bpf_prog_test_load (file,BPF_PROG_TYPE_SCHED_CLS , &obj, &prog_fd);if (CHECK_FAIL (err))
@@ -49,19 +53,24 @@ static void test_l4lb(const char *file) goto out;bpf_map_update_elem (map_fd, &real_num, &real_def,0 ); - err =bpf_prog_test_run (prog_fd,NUM_ITER , &pkt_v4,sizeof (pkt_v4), - buf, &size, &retval, &duration); -CHECK (err || retval !=7 /*TC_ACT_REDIRECT*/ || size !=54 || - *magic !=MAGIC_VAL ,"ipv4" , -"err %d errno %d retval %d size %d magic %x\n" , - err, errno, retval, size, *magic); + topts.data_in = &pkt_v4; + topts.data_size_in =sizeof (pkt_v4); - err =bpf_prog_test_run (prog_fd,NUM_ITER , &pkt_v6,sizeof (pkt_v6), - buf, &size, &retval, &duration); -CHECK (err || retval !=7 /*TC_ACT_REDIRECT*/ || size !=74 || - *magic !=MAGIC_VAL ,"ipv6" , -"err %d errno %d retval %d size %d magic %x\n" , - err, errno, retval, size, *magic); + err =bpf_prog_test_run_opts (prog_fd, &topts); +CHECK_OPTS (err || topts.retval !=7 /*TC_ACT_REDIRECT*/ || + topts.data_size_out !=54 || *magic !=MAGIC_VAL , +"ipv4" ,"err %d errno %d retval %d size %d magic %x\n" , err, + errno, topts.retval, topts.data_size_out, *magic); + + topts.data_in = &pkt_v6; + topts.data_size_in =sizeof (pkt_v6); + topts.data_size_out =sizeof (buf);/* reset out size */ + + err =bpf_prog_test_run_opts (prog_fd, &topts); +CHECK_OPTS (err || topts.retval !=7 /*TC_ACT_REDIRECT*/ || + topts.data_size_out !=74 || *magic !=MAGIC_VAL , +"ipv6" ,"err %d errno %d retval %d size %d magic %x\n" , err, + errno, topts.retval, topts.data_size_out, *magic); map_fd =bpf_find_map (__func__, obj,"stats" );if (map_fd <0 )
tools/testing/selftests/bpf/prog_tests/map_lock.c +9 -6
@@ -4,14 +4,17 @@static void *spin_lock_thread (void *arg) { -__u32 duration, retval;int err, prog_fd = *(u32 *) arg; +LIBBPF_OPTS (bpf_test_run_opts, topts, + .data_in = &pkt_v4, + .data_size_in = sizeof(pkt_v4), + .repeat = 10000, + ); - err =bpf_prog_test_run (prog_fd,10000 , &pkt_v4,sizeof (pkt_v4), -NULL ,NULL , &retval, &duration); -CHECK (err || retval,"" , -"err %d errno %d retval %d duration %d\n" , - err, errno, retval, duration); + err =bpf_prog_test_run_opts (prog_fd, &topts); +CHECK_OPTS (err || topts.retval,"" , +"err %d errno %d retval %d duration %d\n" , err, errno, + topts.retval, topts.duration);pthread_exit (arg); }
tools/testing/selftests/bpf/prog_tests/map_ptr.c +12 -6
@@ -9,10 +9,16 @@void test_map_ptr (void ) {struct map_ptr_kern_lskel *skel; -__u32 duration =0 , retval;char buf[128 ];int err;int page_size =getpagesize (); +LIBBPF_OPTS (bpf_test_run_opts, topts, + .data_in = &pkt_v4, + .data_size_in = sizeof(pkt_v4), + .data_out = buf, + .data_size_out = sizeof(buf), + .repeat = 1, + ); skel =map_ptr_kern_lskel__open ();if (!ASSERT_OK_PTR (skel,"skel_open" ))
@@ -26,14 +32,14 @@ void test_map_ptr(void) skel->bss->page_size = page_size; - err =bpf_prog_test_run (skel->progs.cg_skb.prog_fd,1 , &pkt_v4, -sizeof (pkt_v4), buf,NULL , &retval,NULL ); + err =bpf_prog_test_run_opts (skel->progs.cg_skb.prog_fd, &topts); -if (CHECK (err,"test_run" ,"err=%d errno=%d\n" , err, errno)) +if (CHECK_OPTS (err,"test_run" ,"err=%d errno=%d\n" , err, errno)) goto cleanup; -if (CHECK (!retval,"retval" ,"retval=%d map_type=%u line=%u\n" , retval, - skel->bss->g_map_type, skel->bss->g_line)) +if (CHECK_OPTS (!topts.retval,"retval" , +"retval=%d map_type=%u line=%u\n" , topts.retval, + skel->bss->g_map_type, skel->bss->g_line)) goto cleanup; cleanup:
tools/testing/selftests/bpf/prog_tests/modify_return.c +19 -19
@@ -15,39 +15,40 @@ static void run_test(__u32 input_retval, __u16 want_side_effect, __s16 want_ret) {struct modify_return *skel =NULL ;int err, prog_fd; -__u32 duration =0 , retval;__u16 side_effect;__s16 ret; +LIBBPF_OPTS (bpf_test_run_opts, topts, + .repeat = 1, + ); skel =modify_return__open_and_load (); -if (CHECK (!skel,"skel_load" ,"modify_return skeleton failed\n" )) +if (CHECK_OPTS (!skel,"skel_load" ,"modify_return skeleton failed\n" )) goto cleanup; err =modify_return__attach (skel); -if (CHECK (err,"modify_return" ,"attach failed: %d\n" , err)) +if (CHECK_OPTS (err,"modify_return" ,"attach failed: %d\n" , err)) goto cleanup; skel->bss->input_retval = input_retval; prog_fd =bpf_program__fd (skel->progs.fmod_ret_test); - err =bpf_prog_test_run (prog_fd,1 ,NULL ,0 ,NULL ,0 , - &retval, &duration); + err =bpf_prog_test_run_opts (prog_fd, &topts); -CHECK (err,"test_run" ,"err %d errno %d\n" , err, errno); +CHECK_OPTS (err,"test_run" ,"err %d errno %d\n" , err, errno); - side_effect =UPPER (retval); - ret =LOWER (retval); + side_effect =UPPER (topts.retval); + ret =LOWER (topts.retval); -CHECK (ret != want_ret,"test_run" , -"unexpected ret: %d, expected: %d\n" , ret, want_ret); -CHECK (side_effect != want_side_effect,"modify_return" , -"unexpected side_effect: %d\n" , side_effect); +CHECK_OPTS (ret != want_ret,"test_run" , +"unexpected ret: %d, expected: %d\n" , ret, want_ret); +CHECK_OPTS (side_effect != want_side_effect,"modify_return" , +"unexpected side_effect: %d\n" , side_effect); -CHECK (skel->bss->fentry_result !=1 ,"modify_return" , -"fentry failed\n" ); -CHECK (skel->bss->fexit_result !=1 ,"modify_return" , -"fexit failed\n" ); -CHECK (skel->bss->fmod_ret_result !=1 ,"modify_return" , -"fmod_ret failed\n" ); +CHECK_OPTS (skel->bss->fentry_result !=1 ,"modify_return" , +"fentry failed\n" ); +CHECK_OPTS (skel->bss->fexit_result !=1 ,"modify_return" , +"fexit failed\n" ); +CHECK_OPTS (skel->bss->fmod_ret_result !=1 ,"modify_return" , +"fmod_ret failed\n" ); cleanup:modify_return__destroy (skel);
@@ -63,4 +64,3 @@ void serial_test_modify_return(void)0 /* want_side_effect */ , -EINVAL /* want_ret */); } -
tools/testing/selftests/bpf/prog_tests/pkt_access.c +16 -11
@@ -6,23 +6,28 @@ void test_pkt_access(void) {const char *file ="./test_pkt_access.o" ;struct bpf_object *obj; -__u32 duration, retval;int err, prog_fd; +LIBBPF_OPTS (bpf_test_run_opts, topts, + .data_in = &pkt_v4, + .data_size_in = sizeof(pkt_v4), + .repeat = 100000, + ); err =bpf_prog_test_load (file,BPF_PROG_TYPE_SCHED_CLS , &obj, &prog_fd);if (CHECK_FAIL (err))return ; - err =bpf_prog_test_run (prog_fd,100000 , &pkt_v4,sizeof (pkt_v4), -NULL ,NULL , &retval, &duration); -CHECK (err || retval,"ipv4" , -"err %d errno %d retval %d duration %d\n" , - err, errno, retval, duration); + err =bpf_prog_test_run_opts (prog_fd, &topts); +CHECK_OPTS (err || topts.retval,"ipv4" , +"err %d errno %d retval %d duration %d\n" , err, errno, + topts.retval, topts.duration); - err =bpf_prog_test_run (prog_fd,100000 , &pkt_v6,sizeof (pkt_v6), -NULL ,NULL , &retval, &duration); -CHECK (err || retval,"ipv6" , -"err %d errno %d retval %d duration %d\n" , - err, errno, retval, duration); + topts.data_in = &pkt_v6; + topts.data_size_in =sizeof (pkt_v6); + topts.data_size_out =0 ;/* reset from last call */ + err =bpf_prog_test_run_opts (prog_fd, &topts); +CHECK_OPTS (err || topts.retval,"ipv6" , +"err %d errno %d retval %d duration %d\n" , err, errno, + topts.retval, topts.duration);bpf_object__close (obj); }
tools/testing/selftests/bpf/prog_tests/pkt_md_access.c +9 -6
@@ -6,18 +6,21 @@ void test_pkt_md_access(void) {const char *file ="./test_pkt_md_access.o" ;struct bpf_object *obj; -__u32 duration, retval;int err, prog_fd; +LIBBPF_OPTS (bpf_test_run_opts, topts, + .data_in = &pkt_v4, + .data_size_in = sizeof(pkt_v4), + .repeat = 10, + ); err =bpf_prog_test_load (file,BPF_PROG_TYPE_SCHED_CLS , &obj, &prog_fd);if (CHECK_FAIL (err))return ; - err =bpf_prog_test_run (prog_fd,10 , &pkt_v4,sizeof (pkt_v4), -NULL ,NULL , &retval, &duration); -CHECK (err || retval,"" , -"err %d errno %d retval %d duration %d\n" , - err, errno, retval, duration); + err =bpf_prog_test_run_opts (prog_fd, &topts); +CHECK_OPTS (err || topts.retval,"" , +"err %d errno %d retval %d duration %d\n" , err, errno, + topts.retval, topts.duration);bpf_object__close (obj); }
tools/testing/selftests/bpf/prog_tests/queue_stack_map.c +27 -16
73 lines not on this page · raw message
tools/testing/selftests/bpf/prog_tests/raw_tp_writable_test_run.c +9 -7
@@ -56,21 +56,23 @@ void serial_test_raw_tp_writable_test_run(void) 0, }; -__u32 prog_ret; -int err =bpf_prog_test_run (filter_fd,1 , test_skb,sizeof (test_skb),0 , -0 , &prog_ret,0 ); +LIBBPF_OPTS (bpf_test_run_opts, topts, + .data_in = test_skb, + .data_size_in = sizeof(test_skb), + .repeat = 1, + ); +int err =bpf_prog_test_run_opts (filter_fd, &topts);CHECK (err !=42 ,"test_run" ,"tracepoint did not modify return value\n" ); -CHECK (prog_ret !=0 ,"test_run_ret" , +CHECK (topts.retval !=0 ,"test_run_ret" ,"socket_filter did not return 0\n" );close (tp_fd); - err =bpf_prog_test_run (filter_fd,1 , test_skb,sizeof (test_skb),0 ,0 , - &prog_ret,0 ); + err =bpf_prog_test_run_opts (filter_fd, &topts);CHECK (err !=0 ,"test_run_notrace" ,"test_run failed with %d errno %d\n" , err, errno); -CHECK (prog_ret !=0 ,"test_run_ret_notrace" , +CHECK (topts.retval !=0 ,"test_run_ret_notrace" ,"socket_filter did not return 0\n" ); out_filterfd:
tools/testing/selftests/bpf/prog_tests/signal_pending.c +13 -11
@@ -13,10 +13,14 @@ static void test_signal_pending_by_type(enum bpf_prog_type prog_type)struct itimerval timeo = { .it_value.tv_usec =100000 ,/* 100ms */ }; -__u32 duration =0 , retval;int prog_fd;int err;int i; +LIBBPF_OPTS (bpf_test_run_opts, topts, + .data_in = &pkt_v4, + .data_size_in = sizeof(pkt_v4), + .repeat = 0xffffffff, + );for (i =0 ; i <ARRAY_SIZE (prog); i++) prog[i] =BPF_ALU64_IMM (BPF_MOV ,BPF_REG_0 ,0 );
@@ -24,20 +28,18 @@ static void test_signal_pending_by_type(enum bpf_prog_type prog_type) prog_fd =bpf_test_load_program (prog_type, prog,ARRAY_SIZE (prog),"GPL" ,0 ,NULL ,0 ); -CHECK (prog_fd <0 ,"test-run" ,"errno %d\n" , errno); +CHECK_OPTS (prog_fd <0 ,"test-run" ,"errno %d\n" , errno); err =sigaction (SIGALRM , &sigalrm_action,NULL ); -CHECK (err,"test-run-signal-sigaction" ,"errno %d\n" , errno); +CHECK_OPTS (err,"test-run-signal-sigaction" ,"errno %d\n" , errno); err =setitimer (ITIMER_REAL , &timeo,NULL ); -CHECK (err,"test-run-signal-timer" ,"errno %d\n" , errno); - - err =bpf_prog_test_run (prog_fd,0xffffffff , &pkt_v4,sizeof (pkt_v4), -NULL ,NULL , &retval, &duration); -CHECK (duration >500000000 ,/* 500ms */ -"test-run-signal-duration" , -"duration %dns > 500ms\n" , - duration); +CHECK_OPTS (err,"test-run-signal-timer" ,"errno %d\n" , errno); + + err =bpf_prog_test_run_opts (prog_fd, &topts); +CHECK_OPTS (topts.duration >500000000 ,/* 500ms */ +"test-run-signal-duration" ,"duration %dns > 500ms\n" , + topts.duration);signal (SIGALRM ,SIG_DFL ); }
tools/testing/selftests/bpf/prog_tests/spinlock.c +9 -6
@@ -4,14 +4,17 @@static void *spin_lock_thread (void *arg) { -__u32 duration, retval;int err, prog_fd = *(u32 *) arg; +LIBBPF_OPTS (bpf_test_run_opts, topts, + .data_in = &pkt_v4, + .data_size_in = sizeof(pkt_v4), + .repeat = 10000, + ); - err =bpf_prog_test_run (prog_fd,10000 , &pkt_v4,sizeof (pkt_v4), -NULL ,NULL , &retval, &duration); -CHECK (err || retval,"" , -"err %d errno %d retval %d duration %d\n" , - err, errno, retval, duration); + err =bpf_prog_test_run_opts (prog_fd, &topts); +CHECK_OPTS (err || topts.retval,"" , +"err %d errno %d retval %d duration %d\n" , err, errno, + topts.retval, topts.duration);pthread_exit (arg); }
tools/testing/selftests/bpf/prog_tests/tailcalls.c +130 -115
473 lines not on this page · raw message
tools/testing/selftests/bpf/prog_tests/test_skb_pkt_end.c +9 -6
@@ -6,15 +6,18 @@static int sanity_run (struct bpf_program *prog) { -__u32 duration, retval;int err, prog_fd; +LIBBPF_OPTS (bpf_test_run_opts, topts, + .data_in = &pkt_v4, + .data_size_in = sizeof(pkt_v4), + .repeat = 1, + ); prog_fd =bpf_program__fd (prog); - err =bpf_prog_test_run (prog_fd,1 , &pkt_v4,sizeof (pkt_v4), -NULL ,NULL , &retval, &duration); -if (CHECK (err || retval !=123 ,"test_run" , -"err %d errno %d retval %d duration %d\n" , - err, errno, retval, duration)) + err =bpf_prog_test_run_opts (prog_fd, &topts); +if (CHECK_OPTS (err || topts.retval !=123 ,"test_run" , +"err %d errno %d retval %d duration %d\n" , err, errno, + topts.retval, topts.duration))return -1 ;return 0 ; }
tools/testing/selftests/bpf/prog_tests/timer.c +5 -4
@@ -6,7 +6,9 @@static int timer (struct timer *timer_skel) {int err, prog_fd; -__u32 duration =0 , retval; +LIBBPF_OPTS (bpf_test_run_opts, topts, + .repeat = 1, + ); err =timer__attach (timer_skel);if (!ASSERT_OK (err,"timer_attach" ))
@@ -16,10 +18,9 @@ static int timer(struct timer *timer_skel)ASSERT_EQ (timer_skel->data->callback2_check,52 ,"callback2_check1" ); prog_fd =bpf_program__fd (timer_skel->progs.test1); - err =bpf_prog_test_run (prog_fd,1 ,NULL ,0 , -NULL ,NULL , &retval, &duration); + err =bpf_prog_test_run_opts (prog_fd, &topts);ASSERT_OK (err,"test_run" ); -ASSERT_EQ (retval,0 ,"test_run" ); +ASSERT_EQ (topts.retval,0 ,"test_run" );timer__detach (timer_skel);usleep (50 );/* 10 usecs should be enough, but give it extra */
tools/testing/selftests/bpf/prog_tests/timer_mim.c +5 -4
@@ -6,19 +6,20 @@static int timer_mim (struct timer_mim *timer_skel) { -__u32 duration =0 , retval;__u64 cnt1, cnt2;int err, prog_fd, key1 =1 ; +LIBBPF_OPTS (bpf_test_run_opts, topts, + .repeat = 1, + ); err =timer_mim__attach (timer_skel);if (!ASSERT_OK (err,"timer_attach" ))return err; prog_fd =bpf_program__fd (timer_skel->progs.test1); - err =bpf_prog_test_run (prog_fd,1 ,NULL ,0 , -NULL ,NULL , &retval, &duration); + err =bpf_prog_test_run_opts (prog_fd, &topts);ASSERT_OK (err,"test_run" ); -ASSERT_EQ (retval,0 ,"test_run" ); +ASSERT_EQ (topts.retval,0 ,"test_run" );timer_mim__detach (timer_skel);/* check that timer_cb[12] are incrementing 'cnt' */
tools/testing/selftests/bpf/prog_tests/trace_ext.c +16 -12
@@ -23,8 +23,12 @@ void test_trace_ext(void)int err, pkt_fd, ext_fd;struct bpf_program *prog;char buf[100 ]; -__u32 retval;__u64 len; +LIBBPF_OPTS (bpf_test_run_opts, topts, + .data_in = &pkt_v4, + .data_size_in = sizeof(pkt_v4), + .repeat = 1, + );/* open/load/attach test_pkt_md_access */ skel_pkt =test_pkt_md_access__open_and_load ();
@@ -77,32 +81,32 @@ void test_trace_ext(void)/* load/attach tracing */ err =test_trace_ext_tracing__load (skel_trace); -if (CHECK (err,"setup" ,"tracing/test_pkt_md_access_new load failed\n" )) { +if (CHECK_OPTS (err,"setup" ,"tracing/test_pkt_md_access_new load failed\n" )) {libbpf_strerror (err, buf,sizeof (buf));fprintf (stderr,"%s\n" , buf); goto cleanup; } err =test_trace_ext_tracing__attach (skel_trace); -if (CHECK (err,"setup" ,"tracing/test_pkt_md_access_new attach failed: %d\n" , err)) +if (CHECK_OPTS (err,"setup" ,"tracing/test_pkt_md_access_new attach failed: %d\n" , err)) goto cleanup;/* trigger the test */ - err =bpf_prog_test_run (pkt_fd,1 , &pkt_v4,sizeof (pkt_v4), -NULL ,NULL , &retval, &duration); -CHECK (err || retval,"run" ,"err %d errno %d retval %d\n" , err, errno, retval); + err =bpf_prog_test_run_opts (pkt_fd, &topts); +CHECK_OPTS (err || topts.retval,"run" ,"err %d errno %d retval %d\n" , + err, errno, topts.retval); bss_ext = skel_ext->bss; bss_trace = skel_trace->bss; len = bss_ext->ext_called; -CHECK (bss_ext->ext_called ==0 , -"check" ,"failed to trigger freplace/test_pkt_md_access\n" ); -CHECK (bss_trace->fentry_called != len, -"check" ,"failed to trigger fentry/test_pkt_md_access_new\n" ); -CHECK (bss_trace->fexit_called != len, -"check" ,"failed to trigger fexit/test_pkt_md_access_new\n" ); +CHECK_OPTS (bss_ext->ext_called ==0 ,"check" , +"failed to trigger freplace/test_pkt_md_access\n" ); +CHECK_OPTS (bss_trace->fentry_called != len,"check" , +"failed to trigger fentry/test_pkt_md_access_new\n" ); +CHECK_OPTS (bss_trace->fexit_called != len,"check" , +"failed to trigger fexit/test_pkt_md_access_new\n" ); cleanup:test_trace_ext_tracing__destroy (skel_trace);
tools/testing/selftests/bpf/prog_tests/xdp.c +22 -13
@@ -13,8 +13,14 @@ void test_xdp(void)char buf[128 ];struct ipv6hdr iph6;struct iphdr iph; -__u32 duration, retval, size;int err, prog_fd, map_fd; +LIBBPF_OPTS (bpf_test_run_opts, topts, + .data_in = &pkt_v4, + .data_size_in = sizeof(pkt_v4), + .data_out = buf, + .data_size_out = sizeof(buf), + .repeat = 1, + ); err =bpf_prog_test_load (file,BPF_PROG_TYPE_XDP , &obj, &prog_fd);if (CHECK_FAIL (err))
@@ -26,21 +32,24 @@ void test_xdp(void)bpf_map_update_elem (map_fd, &key4, &value4,0 );bpf_map_update_elem (map_fd, &key6, &value6,0 ); - err =bpf_prog_test_run (prog_fd,1 , &pkt_v4,sizeof (pkt_v4), - buf, &size, &retval, &duration); + err =bpf_prog_test_run_opts (prog_fd, &topts);memcpy (&iph, buf +sizeof (struct ethhdr ),sizeof (iph)); -CHECK (err || retval !=XDP_TX || size !=74 || - iph.protocol !=IPPROTO_IPIP ,"ipv4" , -"err %d errno %d retval %d size %d\n" , - err, errno, retval, size); +CHECK_OPTS (err || topts.retval !=XDP_TX || topts.data_size_out !=74 || + iph.protocol !=IPPROTO_IPIP , +"ipv4" ,"err %d errno %d retval %d size %d\n" , err, errno, + topts.retval, topts.data_size_out); - err =bpf_prog_test_run (prog_fd,1 , &pkt_v6,sizeof (pkt_v6), - buf, &size, &retval, &duration); + topts.data_in = &pkt_v6; + topts.data_size_in =sizeof (pkt_v6); + topts.data_size_out =sizeof (buf); + + err =bpf_prog_test_run_opts (prog_fd, &topts);memcpy (&iph6, buf +sizeof (struct ethhdr ),sizeof (iph6)); -CHECK (err || retval !=XDP_TX || size !=114 || - iph6.nexthdr !=IPPROTO_IPV6 ,"ipv6" , -"err %d errno %d retval %d size %d\n" , - err, errno, retval, size); +CHECK_OPTS (err || topts.retval !=XDP_TX || + topts.data_size_out !=114 || + iph6.nexthdr !=IPPROTO_IPV6 , +"ipv6" ,"err %d errno %d retval %d size %d\n" , err, errno, + topts.retval, topts.data_size_out); out:bpf_object__close (obj); }
tools/testing/selftests/bpf/prog_tests/xdp_adjust_frags.c +21 -13
@@ -5,12 +5,14 @@void test_xdp_update_frags (void ) {const char *file ="./test_xdp_update_frags.o" ; -__u32 duration, retval, size;struct bpf_program *prog;struct bpf_object *obj;int err, prog_fd;__u32 *offset;__u8 *buf; +LIBBPF_OPTS (bpf_test_run_opts, topts, + .repeat = 1, + ); obj =bpf_object__open (file);if (libbpf_get_error (obj))
@@ -32,12 +34,16 @@ void test_xdp_update_frags(void) buf[*offset] =0xaa ;/* marker at offset 16 (head) */ buf[*offset +15 ] =0xaa ;/* marker at offset 31 (head) */ - err =bpf_prog_test_run (prog_fd,1 , buf,128 , - buf, &size, &retval, &duration); + topts.data_in = buf; + topts.data_out = buf; + topts.data_size_in =128 ; + topts.data_size_out =128 ; + + err =bpf_prog_test_run_opts (prog_fd, &topts);/* test_xdp_update_frags: buf[16,31]: 0xaa -> 0xbb */ ASSERT_OK (err,"xdp_update_frag" ); -ASSERT_EQ (retval,XDP_PASS ,"xdp_update_frag retval" ); +ASSERT_EQ (topts.retval,XDP_PASS ,"xdp_update_frag retval" );ASSERT_EQ (buf[16 ],0xbb ,"xdp_update_frag buf[16]" );ASSERT_EQ (buf[31 ],0xbb ,"xdp_update_frag buf[31]" );
@@ -53,12 +59,16 @@ void test_xdp_update_frags(void) buf[*offset] =0xaa ;/* marker at offset 5000 (frag0) */ buf[*offset +15 ] =0xaa ;/* marker at offset 5015 (frag0) */ - err =bpf_prog_test_run (prog_fd,1 , buf,9000 , - buf, &size, &retval, &duration); + topts.data_in = buf; + topts.data_out = buf; + topts.data_size_in =9000 ; + topts.data_size_out =9000 ; + + err =bpf_prog_test_run_opts (prog_fd, &topts);/* test_xdp_update_frags: buf[5000,5015]: 0xaa -> 0xbb */ ASSERT_OK (err,"xdp_update_frag" ); -ASSERT_EQ (retval,XDP_PASS ,"xdp_update_frag retval" ); +ASSERT_EQ (topts.retval,XDP_PASS ,"xdp_update_frag retval" );ASSERT_EQ (buf[5000 ],0xbb ,"xdp_update_frag buf[5000]" );ASSERT_EQ (buf[5015 ],0xbb ,"xdp_update_frag buf[5015]" );
@@ -68,12 +78,11 @@ void test_xdp_update_frags(void) buf[*offset] =0xaa ;/* marker at offset 3510 (head) */ buf[*offset +15 ] =0xaa ;/* marker at offset 3525 (frag0) */ - err =bpf_prog_test_run (prog_fd,1 , buf,9000 , - buf, &size, &retval, &duration); + err =bpf_prog_test_run_opts (prog_fd, &topts);/* test_xdp_update_frags: buf[3510,3525]: 0xaa -> 0xbb */ ASSERT_OK (err,"xdp_update_frag" ); -ASSERT_EQ (retval,XDP_PASS ,"xdp_update_frag retval" ); +ASSERT_EQ (topts.retval,XDP_PASS ,"xdp_update_frag retval" );ASSERT_EQ (buf[3510 ],0xbb ,"xdp_update_frag buf[3510]" );ASSERT_EQ (buf[3525 ],0xbb ,"xdp_update_frag buf[3525]" );
@@ -83,12 +92,11 @@ void test_xdp_update_frags(void) buf[*offset] =0xaa ;/* marker at offset 7606 (frag0) */ buf[*offset +15 ] =0xaa ;/* marker at offset 7621 (frag1) */ - err =bpf_prog_test_run (prog_fd,1 , buf,9000 , - buf, &size, &retval, &duration); + err =bpf_prog_test_run_opts (prog_fd, &topts);/* test_xdp_update_frags: buf[7606,7621]: 0xaa -> 0xbb */ ASSERT_OK (err,"xdp_update_frag" ); -ASSERT_EQ (retval,XDP_PASS ,"xdp_update_frag retval" ); +ASSERT_EQ (topts.retval,XDP_PASS ,"xdp_update_frag retval" );ASSERT_EQ (buf[7606 ],0xbb ,"xdp_update_frag buf[7606]" );ASSERT_EQ (buf[7621 ],0xbb ,"xdp_update_frag buf[7621]" );
tools/testing/selftests/bpf/prog_tests/xdp_adjust_tail.c +72 -42
204 lines not on this page · raw message
tools/testing/selftests/bpf/prog_tests/xdp_bpf2bpf.c +11 -5
@@ -45,9 +45,11 @@ static void run_xdp_bpf2bpf_pkt_size(int pkt_fd, struct perf_buffer *pb, struct test_xdp_bpf2bpf *ftrace_skel, int pkt_size) { -__u32 duration =0 , retval, size;__u8 *buf, *buf_in;int err; +LIBBPF_OPTS (bpf_test_run_opts, topts, + .repeat = 1, + );if (!ASSERT_LE (pkt_size,BUF_SZ ,"pkt_size" ) || !ASSERT_GE (pkt_size,sizeof (pkt_v4),"pkt_size" ))
@@ -73,12 +75,16 @@ static void run_xdp_bpf2bpf_pkt_size(int pkt_fd, struct perf_buffer *pb, }/* Run test program */ - err =bpf_prog_test_run (pkt_fd,1 , buf_in, pkt_size, - buf, &size, &retval, &duration); + topts.data_in = buf_in; + topts.data_size_in = pkt_size; + topts.data_out = buf; + topts.data_size_out =BUF_SZ ; + + err =bpf_prog_test_run_opts (pkt_fd, &topts);ASSERT_OK (err,"ipv4" ); -ASSERT_EQ (retval,XDP_PASS ,"ipv4 retval" ); -ASSERT_EQ (size, pkt_size,"ipv4 size" ); +ASSERT_EQ (topts.retval,XDP_PASS ,"ipv4 retval" ); +ASSERT_EQ (topts.data_size_out, pkt_size,"ipv4 size" );/* Make sure bpf_xdp_output() was triggered and it sent the expected * data to the perf ring buffer.
tools/testing/selftests/bpf/prog_tests/xdp_noinline.c +26 -19
69 lines not on this page · raw message
tools/testing/selftests/bpf/prog_tests/xdp_perf.c +12 -7
@@ -4,22 +4,27 @@void test_xdp_perf (void ) {const char *file ="./xdp_dummy.o" ; -__u32 duration, retval, size;struct bpf_object *obj;char in[128 ], out[128 ];int err, prog_fd; +LIBBPF_OPTS (bpf_test_run_opts, topts, + .data_in = in, + .data_size_in = sizeof(in), + .data_out = out, + .data_size_out = sizeof(out), + .repeat = 1000000, + ); err =bpf_prog_test_load (file,BPF_PROG_TYPE_XDP , &obj, &prog_fd);if (CHECK_FAIL (err))return ; - err =bpf_prog_test_run (prog_fd,1000000 , &in[0 ],128 , - out, &size, &retval, &duration); + err =bpf_prog_test_run_opts (prog_fd, &topts); -CHECK (err || retval !=XDP_PASS || size !=128 , -"xdp-perf" , -"err %d errno %d retval %d size %d\n" , - err, errno, retval, size); +CHECK_OPTS (err || topts.retval !=XDP_PASS || + topts.data_size_out !=128 , +"xdp-perf" ,"err %d errno %d retval %d size %d\n" , err, + errno, topts.retval, topts.data_size_out);bpf_object__close (obj); }
tools/testing/selftests/bpf/test_lru_map.c +7 -4
@@ -61,7 +61,11 @@ static int bpf_map_lookup_elem_with_ref_bit(int fd, unsigned long long key, };__u8 data[64 ] = {};int mfd, pfd, ret, zero =0 ; -__u32 retval =0 ; +LIBBPF_OPTS (bpf_test_run_opts, topts, + .data_in = data, + .data_size_in = sizeof(data), + .repeat = 1, + ); mfd =bpf_map_create (BPF_MAP_TYPE_ARRAY ,NULL ,sizeof (int ),sizeof (__u64),1 ,NULL );if (mfd <0 )
@@ -75,9 +79,8 @@ static int bpf_map_lookup_elem_with_ref_bit(int fd, unsigned long long key,return -1 ; } - ret =bpf_prog_test_run (pfd,1 , data,sizeof (data), -NULL ,NULL , &retval,NULL ); -if (ret <0 || retval !=42 ) { + ret =bpf_prog_test_run_opts (pfd, &topts); +if (ret <0 || topts.retval !=42 ) { ret =-1 ; }else {assert (!bpf_map_lookup_elem (mfd, &zero, value));
tools/testing/selftests/bpf/test_progs.h +2 -0
@@ -163,6 +163,8 @@ extern int test__join_cgroup(const char *path); _CHECK(condition, tag, duration, format) #define CHECK_ATTR(condition, tag, format...) \ _CHECK(condition, tag, tattr.duration, format) +#define CHECK_OPTS(condition, tag, format...) \ + _CHECK(condition, tag, topts.duration, format)#define ASSERT_TRUE (actual, name) ({ \ static int duration = 0; \
tools/testing/selftests/bpf/test_verifier.c +10 -6
@@ -1021,13 +1021,18 @@ static int do_prog_test_run(int fd_prog, bool unpriv, uint32_t expected_val, {__u8 tmp[TEST_DATA_LEN <<2 ];__u32 size_tmp =sizeof (tmp); -uint32_t retval;int err, saved_errno; +LIBBPF_OPTS (bpf_test_run_opts, topts, + .data_in = data, + .data_size_in = size_data, + .data_out = tmp, + .data_size_out = size_tmp, + .repeat = 1, + );if (unpriv)set_admin (true); - err =bpf_prog_test_run (fd_prog,1 , data, size_data, - tmp, &size_tmp, &retval,NULL ); + err =bpf_prog_test_run_opts (fd_prog, &topts); saved_errno = errno;if (unpriv)
@@ -1051,9 +1056,8 @@ static int do_prog_test_run(int fd_prog, bool unpriv, uint32_t expected_val, } } -if (retval != expected_val && - expected_val !=POINTER_VALUE ) { -printf ("FAIL retval %d != %d " , retval, expected_val); +if (topts.retval != expected_val && expected_val !=POINTER_VALUE ) { +printf ("FAIL retval %d != %d " , topts.retval, expected_val);return 1 ; }
--
2.30.2
Re: [PATCH bpf-next v2 1/4] selftests: bpf: migrate from bpf_prog_test_run
Quoted 49 lines · Delyan Kratunov
Signed-off-by Delyan Kratunov <[email protected]>--- .../selftests/bpf/prog_tests/atomics.c | 86 +++--- .../testing/selftests/bpf/prog_tests/bpf_nf.c | 10 +- .../selftests/bpf/prog_tests/fentry_fexit.c | 33 ++- .../selftests/bpf/prog_tests/fentry_test.c | 9 +- .../selftests/bpf/prog_tests/fexit_bpf2bpf.c | 33 ++- .../selftests/bpf/prog_tests/fexit_stress.c | 26 +- .../selftests/bpf/prog_tests/fexit_test.c | 9 +- .../prog_tests/flow_dissector_load_bytes.c | 27 +- .../selftests/bpf/prog_tests/for_each.c | 32 ++- .../bpf/prog_tests/get_func_args_test.c | 14 +- .../bpf/prog_tests/get_func_ip_test.c | 12 +- .../selftests/bpf/prog_tests/global_data.c | 25 +- .../bpf/prog_tests/global_func_args.c | 13 +- .../selftests/bpf/prog_tests/kfunc_call.c | 46 ++-- .../selftests/bpf/prog_tests/ksyms_module.c | 23 +- .../selftests/bpf/prog_tests/l4lb_all.c | 35 ++- .../selftests/bpf/prog_tests/map_lock.c | 15 +- .../selftests/bpf/prog_tests/map_ptr.c | 18 +- .../selftests/bpf/prog_tests/modify_return.c | 38 +-- .../selftests/bpf/prog_tests/pkt_access.c | 27 +- .../selftests/bpf/prog_tests/pkt_md_access.c | 15 +- .../bpf/prog_tests/queue_stack_map.c | 43 +-- .../bpf/prog_tests/raw_tp_writable_test_run.c | 16 +- .../selftests/bpf/prog_tests/signal_pending.c | 24 +- .../selftests/bpf/prog_tests/spinlock.c | 15 +- .../selftests/bpf/prog_tests/tailcalls.c | 245 ++++++++++-------- .../bpf/prog_tests/test_skb_pkt_end.c | 15 +- .../testing/selftests/bpf/prog_tests/timer.c | 9 +- .../selftests/bpf/prog_tests/timer_mim.c | 9 +- .../selftests/bpf/prog_tests/trace_ext.c | 28 +- tools/testing/selftests/bpf/prog_tests/xdp.c | 35 ++- .../bpf/prog_tests/xdp_adjust_frags.c | 34 ++- .../bpf/prog_tests/xdp_adjust_tail.c | 114 +++++--- .../selftests/bpf/prog_tests/xdp_bpf2bpf.c | 16 +- .../selftests/bpf/prog_tests/xdp_noinline.c | 45 ++-- .../selftests/bpf/prog_tests/xdp_perf.c | 19 +- tools/testing/selftests/bpf/test_lru_map.c | 11 +- tools/testing/selftests/bpf/test_progs.h | 2 + tools/testing/selftests/bpf/test_verifier.c | 16 +- 39 files changed, 727 insertions(+), 515 deletions(-)tools/testing/selftests/bpf/prog_tests/atomics.c +0
-0
tools/testing/selftests/bpf/prog_tests/atomics.c line 13
Quoted 8 lines
tools/testing/selftests/bpf/prog_tests/atomics.c +3
-1@@ -7,18 +7,20 @@static void test_add (struct atomics_lskel *skel) {int err, prog_fd; -__u32 duration =0 , retval;int link_fd; +LIBBPF_OPTS (bpf_test_run_opts, topts, + .repeat = 1, + );
for simple case like this you can just keep it single line:
LIBBPF_OPTS(bpf_test_run_opts, topts, .repeat = 1)
But, it seems like the kernel does if (!repeat) repeat = 1; logic for program types that support repeat feature, so I'd suggest just drop .repeat = 1 and keep it simple.
tools/testing/selftests/bpf/prog_tests/atomics.c line 21
Quoted 12 lines
tools/testing/selftests/bpf/prog_tests/atomics.c +2
-4link_fd =atomics_lskel__add__attach (skel);if (!ASSERT_GT (link_fd,0 ,"attach(add)" ))return ; prog_fd = skel->progs.add.prog_fd; - err =bpf_prog_test_run (prog_fd,1 ,NULL ,0 , -NULL ,NULL , &retval, &duration); -if (CHECK (err || retval,"test_run add" , -"err %d errno %d retval %d duration %d\n" , err, errno, retval, duration)) + err =bpf_prog_test_run_opts (prog_fd, &topts); + if (CHECK_OPTS(err || topts.retval, "test_run add",
let's not add new CHECK*() variants, CHECK() and its derivative are deprecated, we are using ASSERT_xxx() macros for all new code.
In this case, I think it's best to replace CHECK() with just:
ASSERT_OK(err, "run_err");ASSERT_OK(topts.retval, "run_ret_val");
I don't think logging duration is useful for most, if not all, tests, so I wouldn't bother.
Quoted 5 lines
tools/testing/selftests/bpf/prog_tests/atomics.c +2
-0+ "err %d errno %d retval %d duration %d\n", err, errno, + topts.retval, topts.duration)) goto cleanup;ASSERT_EQ (skel->data->add64_value,3 ,"add64_value" );
[...]
Quoted 8 lines
tools/testing/selftests/bpf/prog_tests/fentry_fexit.c +0
-0@@ -9,38 +9,43 @@ void test_fentry_fexit(void)struct fentry_test_lskel *fentry_skel =NULL ;struct fexit_test_lskel *fexit_skel =NULL ;__u64 *fentry_res, *fexit_res;
tools/testing/selftests/bpf/prog_tests/fentry_fexit.c void test_fentry_fexit(void) · line 19
Quoted 10 lines
tools/testing/selftests/bpf/prog_tests/fentry_fexit.c +5
-2-__u32 duration =0 , retval;int err, prog_fd, i; +LIBBPF_OPTS (bpf_test_run_opts, topts, + .repeat = 1, + ); fentry_skel =fentry_test_lskel__open_and_load (); -if (CHECK (!fentry_skel,"fentry_skel_load" ,"fentry skeleton failed\n" )) +if (CHECK_OPTS (!fentry_skel,"fentry_skel_load" , +"fentry skeleton failed\n" ))
You didn't have to touch this code, you could have just kept duration = 0 (which CHECK() internally assumes, unfortunately).
Alternatively, just switch to ASSERT_OK_PTR(fentry_skel, "fentry_skel_load"); and be done with it. As I mentioned, we are in a gradual process of removing CHECK()s, I was actually surprised how far we've progressed already:
$ rg CHECK | wc -l 2024 $ rg ASSERT_ | wc -l 1782
At some point we'll do the final push and remove CHECK() altogether, but it doesn't have to be part of this patch set (unless you are interested in doing some more mechanical conversions, of course, it's greatly appreciated, but I didn't yet have heart to ask anyone to do those 2000 conversions...).
Quoted 7 lines
tools/testing/selftests/bpf/prog_tests/fentry_fexit.c +2
-1goto close_prog; fexit_skel =fexit_test_lskel__open_and_load (); -if (CHECK (!fexit_skel,"fexit_skel_load" ,"fexit skeleton failed\n" )) +if (CHECK_OPTS (!fexit_skel,"fexit_skel_load" , +"fexit skeleton failed\n" )) goto close_prog;
[...]
Re: [PATCH bpf-next v2 1/4] selftests: bpf: migrate from bpf_prog_test_run
Quoted 7 lines · Andrii Nakryiko
for simple case like this you can just keep it single line:
LIBBPF_OPTS(bpf_test_run_opts, topts, .repeat = 1)But, it seems like the kernel does
if (!repeat) repeat = 1;logic for program types that support repeat feature, so I'd suggest just drop .repeat = 1 and keep it simple.
Sure.
Quoted 11 lines
let's not add new CHECK*() variants,
CHECK()and its derivative are deprecated, we are usingASSERT_xxx()macros for all new code.In this case, I think it's best to replace
CHECK()with just:
ASSERT_OK(err, "run_err");ASSERT_OK(topts.retval, "run_ret_val");I don't think logging duration is useful for most, if not all, tests, so I wouldn't bother.
Ah, this makes a lot of sense, I was wondering what was going on with these quite unreadable CHECK{,_ATTR} macros. I'll rewrite the ones I'm changing in this series to use ASSERT_* if you're okay with that amount of churn?
Quoted 2 lines
You didn't have to touch this code, you could have just kept duration = 0 (which
CHECK()internally assumes, unfortunately).
I didn't *have* to but leaving the variable around to satisfy a macro feels super awkward. Happy to minimize these changes, if they're going overboard but I'd rather clean up the CHECK usage where I can.
Quoted 10 lines
Alternatively, just switch to
ASSERT_OK_PTR(fentry_skel, "fentry_skel_load"); and be done with it. As I mentioned, we are in a gradual process of removing CHECK()s,
[...]
At some point we'll do the final push and removeCHECK()altogether, but it doesn't have to be part of this patch set (unless you are interested in doing some more mechanical conversions, of course, it's greatly appreciated, but I didn't yet have heart to ask anyone to do those 2000 conversions...).
I don't think I have it in me to volunteer for the whole refactor but I'll do my bit in the usages this series touches.
Re: [PATCH bpf-next v2 1/4] selftests: bpf: migrate from bpf_prog_test_run
Quoted 21 lines · Delyan Kratunov
Quoted 7 lines · Andrii Nakryiko
for simple case like this you can just keep it single line:
LIBBPF_OPTS(bpf_test_run_opts, topts, .repeat = 1)But, it seems like the kernel does
if (!repeat) repeat = 1;logic for program types that support repeat feature, so I'd suggest just drop .repeat = 1 and keep it simple.Sure.
Quoted 9 lines
let's not add new CHECK*() variants,
CHECK()and its derivative are deprecated, we are usingASSERT_xxx()macros for all new code.In this case, I think it's best to replace
CHECK()with just:
ASSERT_OK(err, "run_err");ASSERT_OK(topts.retval, "run_ret_val");
Quoted 6 lines
Quoted 2 lines
I don't think logging duration is useful for most, if not all, tests, so I wouldn't bother.
Ah, this makes a lot of sense, I was wondering what was going on with these quite unreadable CHECK{,_ATTR} macros. I'll rewrite the ones I'm changing in this series to use ASSERT_* if you're okay with that amount of churn?
No, it's fine with me. As I said, I'd like all CHECK()s to be gone, so the sooner and closer we get to that the better. We have BPF CI setup to make sure that we don't accidentally screw up checks in a major way, so it's pretty safe to do.
Quoted 7 lines
Quoted 3 lines
You didn't have to touch this code, you could have just kept duration = 0 (which
CHECK()internally assumes, unfortunately).I didn't *have* to but leaving the variable around to satisfy a macro feels super awkward. Happy to minimize these changes, if they're going overboard but I'd rather clean up the CHECK usage where I can.
Heh, we do have some selftests doing static int duration; in a file to satisfy CHECK() :) But I don't mind more selftest code churn to convert to ASSERT_xxx() macros.
Quoted 12 lines
Quoted 11 lines
Alternatively, just switch to
ASSERT_OK_PTR(fentry_skel, "fentry_skel_load"); and be done with it. As I mentioned, we are in a gradual process of removing CHECK()s,
[...]
At some point we'll do the final push and removeCHECK()altogether, but it doesn't have to be part of this patch set (unless you are interested in doing some more mechanical conversions, of course, it's greatly appreciated, but I didn't yet have heart to ask anyone to do those 2000 conversions...).
Quoted 2 lines
I don't think I have it in me to volunteer for the whole refactor but I'll do my bit in the usages this series touches.
No worries and thanks!
PATCH v2 2/4 selftests: bpf: migrate from bpf_prog_test_run_xattr
In reply to Delyan Kratunov--- .../selftests/bpf/prog_tests/check_mtu.c | 47 +++++----- .../selftests/bpf/prog_tests/cls_redirect.c | 30 +++--- .../selftests/bpf/prog_tests/dummy_st_ops.c | 31 +++---- .../selftests/bpf/prog_tests/flow_dissector.c | 75 ++++++++------- .../selftests/bpf/prog_tests/kfree_skb.c | 16 ++-- .../selftests/bpf/prog_tests/prog_run_xattr.c | 5 + .../bpf/prog_tests/raw_tp_test_run.c | 85 ++++++++--------- .../selftests/bpf/prog_tests/skb_ctx.c | 93 ++++++++----------- .../selftests/bpf/prog_tests/skb_helpers.c | 16 ++-- .../selftests/bpf/prog_tests/sockmap_basic.c | 19 ++-- .../selftests/bpf/prog_tests/syscall.c | 12 +-- .../selftests/bpf/prog_tests/test_profiler.c | 16 ++-- .../bpf/prog_tests/xdp_adjust_tail.c | 34 +++---- 13 files changed, 227 insertions(+), 252 deletions(-)
tools/testing/selftests/bpf/prog_tests/check_mtu.c +22 -25
@@ -83,24 +83,22 @@ static void test_check_mtu_run_xdp(struct test_check_mtu *skel,int retval_expect =XDP_PASS ;__u32 mtu_result =0 ;char buf[256 ] = {}; -int err; -struct bpf_prog_test_run_attr tattr = { - .repeat =1 , - .data_in = &pkt_v4, +int err, prog_fd =bpf_program__fd (prog); +LIBBPF_OPTS (bpf_test_run_opts, topts, + .repeat = 1, .data_in = &pkt_v4, .data_size_in = sizeof(pkt_v4), .data_out = buf, .data_size_out = sizeof(buf), - .prog_fd =bpf_program__fd (prog), - }; + ); - err =bpf_prog_test_run_xattr (&tattr); -CHECK_ATTR (err !=0 ,"bpf_prog_test_run" , -"prog_name:%s (err %d errno %d retval %d)\n" , - prog_name, err, errno, tattr.retval); + err =bpf_prog_test_run_opts (prog_fd, &topts); +CHECK_OPTS (err !=0 ,"bpf_prog_test_run" , +"prog_name:%s (err %d errno %d retval %d)\n" , prog_name, err, + errno, topts.retval); -CHECK (tattr.retval != retval_expect,"retval" , -"progname:%s unexpected retval=%d expected=%d\n" , - prog_name, tattr.retval, retval_expect); +CHECK (topts.retval != retval_expect,"retval" , +"progname:%s unexpected retval=%d expected=%d\n" , prog_name, + topts.retval, retval_expect);/* Extract MTU that BPF-prog got */ mtu_result = skel->bss->global_bpf_mtu_xdp;
@@ -143,24 +141,23 @@ static void test_check_mtu_run_tc(struct test_check_mtu *skel,int retval_expect =BPF_OK ;__u32 mtu_result =0 ;char buf[256 ] = {}; -int err; -struct bpf_prog_test_run_attr tattr = { - .repeat =1 , +int err, prog_fd =bpf_program__fd (prog); +LIBBPF_OPTS (bpf_test_run_opts, topts, .data_in = &pkt_v4, .data_size_in = sizeof(pkt_v4), .data_out = buf, .data_size_out = sizeof(buf), - .prog_fd =bpf_program__fd (prog), - }; + .repeat = 1, + ); - err =bpf_prog_test_run_xattr (&tattr); -CHECK_ATTR (err !=0 ,"bpf_prog_test_run" , -"prog_name:%s (err %d errno %d retval %d)\n" , - prog_name, err, errno, tattr.retval); + err =bpf_prog_test_run_opts (prog_fd, &topts); +CHECK_OPTS (err !=0 ,"bpf_prog_test_run" , +"prog_name:%s (err %d errno %d retval %d)\n" , prog_name, err, + errno, topts.retval); -CHECK (tattr.retval != retval_expect,"retval" , -"progname:%s unexpected retval=%d expected=%d\n" , - prog_name, tattr.retval, retval_expect); +CHECK (topts.retval != retval_expect,"retval" , +"progname:%s unexpected retval=%d expected=%d\n" , prog_name, + topts.retval, retval_expect);/* Extract MTU that BPF-prog got */ mtu_result = skel->bss->global_bpf_mtu_tc;
tools/testing/selftests/bpf/prog_tests/cls_redirect.c +15 -15
@@ -161,9 +161,9 @@ static socklen_t prepare_addr(struct sockaddr_storage *addr, int family) } } -static bool was_decapsulated (struct bpf_prog_test_run_attr *tattr) +static bool was_decapsulated (struct bpf_test_run_opts *topts) { -return tattr->data_size_out < tattr->data_size_in; +return topts->data_size_out < topts->data_size_in; }enum type {
@@ -367,12 +367,12 @@ static void close_fds(int *fds, int n)static void test_cls_redirect_common (struct bpf_program *prog) { -struct bpf_prog_test_run_attr tattr = {}; +LIBBPF_OPTS (bpf_test_run_opts, topts);int families[] = {AF_INET ,AF_INET6 };struct sockaddr_storage ss;struct sockaddr *addr;socklen_t slen; -int i, j, err; +int i, j, err, prog_fd;int servers[__NR_KIND][ARRAY_SIZE (families)] = {};int conns[__NR_KIND][ARRAY_SIZE (families)] = {};struct tuple tuples[__NR_KIND][ARRAY_SIZE (families)];
@@ -394,7 +394,7 @@ static void test_cls_redirect_common(struct bpf_program *prog) goto cleanup; } - tattr.prog_fd =bpf_program__fd (prog); + prog_fd =bpf_program__fd (prog);for (i =0 ; i <ARRAY_SIZE (tests); i++) {struct test_cfg *test = &tests[i];
@@ -407,31 +407,31 @@ static void test_cls_redirect_common(struct bpf_program *prog)if (!test__start_subtest (tmp))continue ; - tattr.data_out = tmp; - tattr.data_size_out =sizeof (tmp); + topts.data_out = tmp; + topts.data_size_out =sizeof (tmp); - tattr.data_in = input; - tattr.data_size_in =build_input (test, input, tuple); -if (CHECK_FAIL (!tattr.data_size_in)) + topts.data_in = input; + topts.data_size_in =build_input (test, input, tuple); +if (CHECK_FAIL (!topts.data_size_in))continue ; - err =bpf_prog_test_run_xattr (&tattr); + err =bpf_prog_test_run_opts (prog_fd, &topts);if (CHECK_FAIL (err))continue ; -if (tattr.retval !=TC_ACT_REDIRECT ) { +if (topts.retval !=TC_ACT_REDIRECT ) {PRINT_FAIL ("expected TC_ACT_REDIRECT, got %d\n" , - tattr.retval); + topts.retval);continue ; }switch (test->result) {case ACCEPT : -if (CHECK_FAIL (!was_decapsulated (&tattr))) +if (CHECK_FAIL (!was_decapsulated (&topts)))continue ;break ;case FORWARD : -if (CHECK_FAIL (was_decapsulated (&tattr))) +if (CHECK_FAIL (was_decapsulated (&topts)))continue ;break ;default :
tools/testing/selftests/bpf/prog_tests/dummy_st_ops.c +14 -17
@@ -26,10 +26,10 @@ static void test_dummy_st_ops_attach(void)static void test_dummy_init_ret_value (void ) {__u64 args[1 ] = {0 }; -struct bpf_prog_test_run_attr attr = { - .ctx_size_in =sizeof (args), +LIBBPF_OPTS (bpf_test_run_opts, topts, .ctx_in = args, - }; + .ctx_size_in = sizeof(args), + );struct dummy_st_ops *skel;int fd, err;
@@ -38,10 +38,9 @@ static void test_dummy_init_ret_value(void)return ; fd =bpf_program__fd (skel->progs.test_1); - attr.prog_fd = fd; - err =bpf_prog_test_run_xattr (&attr); + err =bpf_prog_test_run_opts (fd, &topts);ASSERT_OK (err,"test_run" ); -ASSERT_EQ (attr.retval,0xf2f3f4f5 ,"test_ret" ); +ASSERT_EQ (topts.retval,0xf2f3f4f5 ,"test_ret" );dummy_st_ops__destroy (skel); }
@@ -53,10 +52,10 @@ static void test_dummy_init_ptr_arg(void) .val = exp_retval, };__u64 args[1 ] = {(unsigned long )&in_state}; -struct bpf_prog_test_run_attr attr = { - .ctx_size_in =sizeof (args), +LIBBPF_OPTS (bpf_test_run_opts, topts, .ctx_in = args, - }; + .ctx_size_in = sizeof(args), + );struct dummy_st_ops *skel;int fd, err;
@@ -65,11 +64,10 @@ static void test_dummy_init_ptr_arg(void)return ; fd =bpf_program__fd (skel->progs.test_1); - attr.prog_fd = fd; - err =bpf_prog_test_run_xattr (&attr); + err =bpf_prog_test_run_opts (fd, &topts);ASSERT_OK (err,"test_run" );ASSERT_EQ (in_state.val,0x5a ,"test_ptr_ret" ); -ASSERT_EQ (attr.retval, exp_retval,"test_ret" ); +ASSERT_EQ (topts.retval, exp_retval,"test_ret" );dummy_st_ops__destroy (skel); }
@@ -77,10 +75,10 @@ static void test_dummy_init_ptr_arg(void)static void test_dummy_multiple_args (void ) {__u64 args[5 ] = {0 ,-100 ,0x8a5f ,'c' ,0x1234567887654321ULL }; -struct bpf_prog_test_run_attr attr = { - .ctx_size_in =sizeof (args), +LIBBPF_OPTS (bpf_test_run_opts, topts, .ctx_in = args, - }; + .ctx_size_in = sizeof(args), + );struct dummy_st_ops *skel;int fd, err;size_t i;
@@ -91,8 +89,7 @@ static void test_dummy_multiple_args(void)return ; fd =bpf_program__fd (skel->progs.test_2); - attr.prog_fd = fd; - err =bpf_prog_test_run_xattr (&attr); + err =bpf_prog_test_run_opts (fd, &topts);ASSERT_OK (err,"test_run" );for (i =0 ; i <ARRAY_SIZE (args); i++) {snprintf (name,sizeof (name),"arg %zu" , i);
tools/testing/selftests/bpf/prog_tests/flow_dissector.c +37 -38
114 lines not on this page · raw message
tools/testing/selftests/bpf/prog_tests/kfree_skb.c +8 -8
@@ -53,24 +53,24 @@ static void on_sample(void *ctx, int cpu, void *data, __u32 size)void serial_test_kfree_skb (void ) {struct __sk_buff skb = {}; -struct bpf_prog_test_run_attr tattr = { +LIBBPF_OPTS (bpf_test_run_opts, topts, .data_in = &pkt_v6, .data_size_in = sizeof(pkt_v6), .ctx_in = &skb, .ctx_size_in = sizeof(skb), - }; + );struct kfree_skb *skel =NULL ;struct bpf_link *link;struct bpf_object *obj;struct perf_buffer *pb =NULL ; -int err; +int err, prog_fd;bool passed = false;__u32 duration =0 ;const int zero =0 ;bool test_ok[2 ]; err =bpf_prog_test_load ("./test_pkt_access.o" ,BPF_PROG_TYPE_SCHED_CLS , - &obj, &tattr.prog_fd); + &obj, &prog_fd);if (CHECK (err,"prog_load sched cls" ,"err %d errno %d\n" , err, errno))return ;
@@ -100,11 +100,11 @@ void serial_test_kfree_skb(void) goto close_prog;memcpy (skb.cb, &cb,sizeof (cb)); - err =bpf_prog_test_run_xattr (&tattr); - duration = tattr.duration; -CHECK (err || tattr.retval,"ipv6" , + err =bpf_prog_test_run_opts (prog_fd, &topts); + duration = topts.duration; +CHECK (err || topts.retval,"ipv6" ,"err %d errno %d retval %d duration %d\n" , - err, errno, tattr.retval, duration); + err, errno, topts.retval, duration);/* read perf buffer */ err =perf_buffer__poll (pb,100 );
tools/testing/selftests/bpf/prog_tests/prog_run_xattr.c +5 -0
@@ -20,6 +20,9 @@ static void check_run_cnt(int prog_fd, __u64 run_cnt) "incorrect number of repetitions, want %llu have %llu\n", run_cnt, info.run_cnt); } +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" +void test_prog_run_xattr (void ) {struct test_pkt_access *skel;
@@ -81,3 +84,5 @@ void test_prog_run_xattr(void)if (stats_fd >=0 )close (stats_fd); } + +#pragma GCC diagnostic pop
tools/testing/selftests/bpf/prog_tests/raw_tp_test_run.c +40 -45
129 lines not on this page · raw message
tools/testing/selftests/bpf/prog_tests/skb_ctx.c +39 -54
136 lines not on this page · raw message
tools/testing/selftests/bpf/prog_tests/skb_helpers.c +8 -8
@@ -9,22 +9,22 @@ void test_skb_helpers(void) .gso_segs = 8, .gso_size = 10, }; -struct bpf_prog_test_run_attr tattr = { +LIBBPF_OPTS (bpf_test_run_opts, topts, .data_in = &pkt_v4, .data_size_in = sizeof(pkt_v4), .ctx_in = &skb, .ctx_size_in = sizeof(skb), .ctx_out = &skb, .ctx_size_out = sizeof(skb), - }; + );struct bpf_object *obj; -int err; +int err, prog_fd; - err =bpf_prog_test_load ("./test_skb_helpers.o" ,BPF_PROG_TYPE_SCHED_CLS , &obj, - &tattr.prog_fd); -if (CHECK_ATTR (err,"load" ,"err %d errno %d\n" , err, errno)) + err =bpf_prog_test_load ("./test_skb_helpers.o" , +BPF_PROG_TYPE_SCHED_CLS , &obj, &prog_fd); +if (CHECK_OPTS (err,"load" ,"err %d errno %d\n" , err, errno))return ; - err =bpf_prog_test_run_xattr (&tattr); -CHECK_ATTR (err,"len" ,"err %d errno %d\n" , err, errno); + err =bpf_prog_test_run_opts (prog_fd, &topts); +CHECK_OPTS (err,"len" ,"err %d errno %d\n" , err, errno);bpf_object__close (obj); }
tools/testing/selftests/bpf/prog_tests/sockmap_basic.c +8 -11
@@ -140,12 +140,16 @@ static void test_skmsg_helpers(enum bpf_map_type map_type)static void test_sockmap_update (enum bpf_map_type map_type) { -struct bpf_prog_test_run_attr tattr;int err, prog, src, duration =0 ;struct test_sockmap_update *skel;struct bpf_map *dst_map;const __u32 zero =0 ;char dummy[14 ] = {0 }; +LIBBPF_OPTS (bpf_test_run_opts, topts, + .data_in = dummy, + .data_size_in = sizeof(dummy), + .repeat = 1, + );__s64 sk; sk =connected_socket_v4 ();
@@ -167,16 +171,9 @@ static void test_sockmap_update(enum bpf_map_type map_type)if (CHECK (err,"update_elem(src)" ,"errno=%u\n" , errno)) goto out; - tattr = (struct bpf_prog_test_run_attr ){ - .prog_fd = prog, - .repeat =1 , - .data_in = dummy, - .data_size_in =sizeof (dummy), - }; - - err =bpf_prog_test_run_xattr (&tattr); -if (CHECK_ATTR (err || !tattr.retval,"bpf_prog_test_run" , -"errno=%u retval=%u\n" , errno, tattr.retval)) + err =bpf_prog_test_run_opts (prog, &topts); +if (CHECK_OPTS (err || !topts.retval,"bpf_prog_test_run" , +"errno=%u retval=%u\n" , errno, topts.retval)) goto out;compare_cookies (skel->maps.src, dst_map);
tools/testing/selftests/bpf/prog_tests/syscall.c +6 -6
@@ -20,22 +20,22 @@ void test_syscall(void) .log_buf = (uintptr_t) verifier_log, .log_size = sizeof(verifier_log), }; -struct bpf_prog_test_run_attr tattr = { +LIBBPF_OPTS (bpf_test_run_opts, topts, .ctx_in = &ctx, .ctx_size_in = sizeof(ctx), - }; + );struct syscall *skel =NULL ;__u64 key =12 , value =0 ; -int err; +int err, prog_fd; skel =syscall__open_and_load ();if (!ASSERT_OK_PTR (skel,"skel_load" )) goto cleanup; - tattr.prog_fd =bpf_program__fd (skel->progs.bpf_prog); - err =bpf_prog_test_run_xattr (&tattr); + prog_fd =bpf_program__fd (skel->progs.bpf_prog); + err =bpf_prog_test_run_opts (prog_fd, &topts);ASSERT_EQ (err,0 ,"err" ); -ASSERT_EQ (tattr.retval,1 ,"retval" ); +ASSERT_EQ (topts.retval,1 ,"retval" );ASSERT_GT (ctx.map_fd,0 ,"ctx.map_fd" );ASSERT_GT (ctx.prog_fd,0 ,"ctx.prog_fd" ); ASSERT_OK(memcmp(verifier_log, "processed", sizeof("processed") - 1),
tools/testing/selftests/bpf/prog_tests/test_profiler.c +8 -8
@@ -8,19 +8,19 @@static int sanity_run (struct bpf_program *prog) { -struct bpf_prog_test_run_attr test_attr = {};__u64 args[] = {1 ,2 ,3 }; +LIBBPF_OPTS (bpf_test_run_opts, topts, + .ctx_in = args, + .ctx_size_in = sizeof(args), + );__u32 duration =0 ;int err, prog_fd; prog_fd =bpf_program__fd (prog); - test_attr.prog_fd = prog_fd; - test_attr.ctx_in = args; - test_attr.ctx_size_in =sizeof (args); - err =bpf_prog_test_run_xattr (&test_attr); -if (CHECK (err || test_attr.retval,"test_run" , -"err %d errno %d retval %d duration %d\n" , - err, errno, test_attr.retval, duration)) + err =bpf_prog_test_run_opts (prog_fd, &topts); +if (CHECK (err || topts.retval,"test_run" , +"err %d errno %d retval %d duration %d\n" , err, errno, + topts.retval, duration))return -1 ;return 0 ; }
tools/testing/selftests/bpf/prog_tests/xdp_adjust_tail.c +17 -17
@@ -78,30 +78,30 @@ static void test_xdp_adjust_tail_grow2(void)int tailroom =320 ;/* SKB_DATA_ALIGN(sizeof(struct skb_shared_info))*/ ;struct bpf_object *obj;int err, cnt, i; -int max_grow; +int max_grow, prog_fd; -struct bpf_prog_test_run_attr tattr = { - .repeat =1 , +LIBBPF_OPTS (bpf_test_run_opts, topts, .data_in = &buf, .data_out = &buf, .data_size_in = 0, /* Per test */ .data_size_out = 0, /* Per test */ - }; + .repeat = 1, + ); - err =bpf_prog_test_load (file,BPF_PROG_TYPE_XDP , &obj, &tattr.prog_fd); + err =bpf_prog_test_load (file,BPF_PROG_TYPE_XDP , &obj, &prog_fd);if (ASSERT_OK (err,"test_xdp_adjust_tail_grow" ))return ;/* Test case-64 */ memset (buf,1 ,sizeof (buf)); - tattr.data_size_in =64 ;/* Determine test case via pkt size */ - tattr.data_size_out =128 ;/* Limit copy_size */ + topts.data_size_in =64 ;/* Determine test case via pkt size */ + topts.data_size_out =128 ;/* Limit copy_size */ /* Kernel side alloc packet memory area that is zero init */ - err =bpf_prog_test_run_xattr (&tattr); + err =bpf_prog_test_run_opts (prog_fd, &topts);ASSERT_EQ (errno,ENOSPC ,"case-64 errno" );/* Due limit copy_size in bpf_test_finish */ -ASSERT_EQ (tattr.retval,XDP_TX ,"case-64 retval" ); -ASSERT_EQ (tattr.data_size_out,192 ,"case-64 data_size_out" );/* Expected grow size */ +ASSERT_EQ (topts.retval,XDP_TX ,"case-64 retval" ); +ASSERT_EQ (topts.data_size_out,192 ,"case-64 data_size_out" );/* Expected grow size */ /* Extra checks for data contents */ ASSERT_EQ (buf[0 ],1 ,"case-64-data buf[0]" );/* 0-63 memset to 1 */
@@ -113,22 +113,22 @@ static void test_xdp_adjust_tail_grow2(void)/* Test case-128 */ memset (buf,2 ,sizeof (buf)); - tattr.data_size_in =128 ;/* Determine test case via pkt size */ - tattr.data_size_out =sizeof (buf);/* Copy everything */ - err =bpf_prog_test_run_xattr (&tattr); + topts.data_size_in =128 ;/* Determine test case via pkt size */ + topts.data_size_out =sizeof (buf);/* Copy everything */ + err =bpf_prog_test_run_opts (prog_fd, &topts); max_grow =4096 -XDP_PACKET_HEADROOM - tailroom;/* 3520 */ ASSERT_OK (err,"case-128" ); -ASSERT_EQ (tattr.retval,XDP_TX ,"case-128 retval" ); -ASSERT_EQ (tattr.data_size_out, max_grow,"case-128 data_size_out" );/* Expect max grow */ +ASSERT_EQ (topts.retval,XDP_TX ,"case-128 retval" ); +ASSERT_EQ (topts.data_size_out, max_grow,"case-128 data_size_out" );/* Expect max grow */ /* Extra checks for data content: Count grow size, will contain zeros */ for (i =0 , cnt =0 ; i <sizeof (buf); i++) {if (buf[i] ==0 ) cnt++; } -ASSERT_EQ (cnt, max_grow - tattr.data_size_in,"case-128-data cnt" );/* Grow increase */ -ASSERT_EQ (tattr.data_size_out, max_grow,"case-128-data data_size_out" );/* Total grow */ +ASSERT_EQ (cnt, max_grow - topts.data_size_in,"case-128-data cnt" );/* Grow increase */ +ASSERT_EQ (topts.data_size_out, max_grow,"case-128-data data_size_out" );/* Total grow */ bpf_object__close (obj); }
--
2.30.2
Re: [PATCH bpf-next v2 2/4] selftests: bpf: migrate from bpf_prog_test_run_xattr
Quoted 3 lines · Delyan Kratunov
Signed-off-by Delyan Kratunov <[email protected]>---
You can avoid a bunch of code churn if you name the new opts variable as tattr, let's do that in this patch?
CHECK_FLOW_KEYS() is probably justified, so feel free to stick to using CHECK() internally for extra formatting capabilities (we might extend ASSERT_xxx() macros eventually to support vararg format args).
Also, forgot to mention in the previous patch reply, please use "selftests/bpf: " subject prefix. We are never perfectly consistent, but stats still favor selftests/bpf heavily:
$ git log --oneline -- . | rg 'selftests: bpf: ' | wc -l 102 $ git log --oneline -- . | rg 'selftests/bpf: ' | wc -l 1090
Quoted 15 lines
.../selftests/bpf/prog_tests/check_mtu.c | 47 +++++----- .../selftests/bpf/prog_tests/cls_redirect.c | 30 +++--- .../selftests/bpf/prog_tests/dummy_st_ops.c | 31 +++---- .../selftests/bpf/prog_tests/flow_dissector.c | 75 ++++++++------- .../selftests/bpf/prog_tests/kfree_skb.c | 16 ++-- .../selftests/bpf/prog_tests/prog_run_xattr.c | 5 + .../bpf/prog_tests/raw_tp_test_run.c | 85 ++++++++--------- .../selftests/bpf/prog_tests/skb_ctx.c | 93 ++++++++----------- .../selftests/bpf/prog_tests/skb_helpers.c | 16 ++-- .../selftests/bpf/prog_tests/sockmap_basic.c | 19 ++-- .../selftests/bpf/prog_tests/syscall.c | 12 +-- .../selftests/bpf/prog_tests/test_profiler.c | 16 ++-- .../bpf/prog_tests/xdp_adjust_tail.c | 34 +++---- 13 files changed, 227 insertions(+), 252 deletions(-)
[...]
PATCH v2 3/4 bpftool: migrate from bpf_prog_test_run_xattr
In reply to Delyan Kratunovbpf_prog_test_run_xattr is being deprecated in favor of bpf_prog_test_run_opts.
--- tools/bpf/bpftool/prog.c | 55 ++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 28 deletions(-)
tools/bpf/bpftool/prog.c +27 -28
@@ -1272,12 +1272,12 @@ static int do_run(int argc, char **argv) {char *data_fname_in =NULL , *data_fname_out =NULL ;char *ctx_fname_in =NULL , *ctx_fname_out =NULL ; -struct bpf_prog_test_run_attr test_attr = {0 };const unsigned int default_size =SZ_32K ;void *data_in =NULL , *data_out =NULL ;void *ctx_in =NULL , *ctx_out =NULL ;unsigned int repeat =1 ;int fd, err; +LIBBPF_OPTS (bpf_test_run_opts, topts);if (!REQ_ARGS (4 ))return -1 ;
@@ -1315,7 +1315,7 @@ static int do_run(int argc, char **argv)if (!REQ_ARGS (1 ))return -1 ; - test_attr.data_size_out =strtoul (*argv, &endptr,0 ); + topts.data_size_out =strtoul (*argv, &endptr,0 );if (*endptr) {p_err ("can't parse %s as output data size" , *argv);
@@ -1343,7 +1343,7 @@ static int do_run(int argc, char **argv)if (!REQ_ARGS (1 ))return -1 ; - test_attr.ctx_size_out =strtoul (*argv, &endptr,0 ); + topts.ctx_size_out =strtoul (*argv, &endptr,0 );if (*endptr) {p_err ("can't parse %s as output context size" , *argv);
@@ -1371,38 +1371,37 @@ static int do_run(int argc, char **argv) } } - err =get_run_data (data_fname_in, &data_in, &test_attr.data_size_in); + err =get_run_data (data_fname_in, &data_in, &topts.data_size_in);if (err)return -1 ;if (data_in) { -if (!test_attr.data_size_out) - test_attr.data_size_out = default_size; - err =alloc_run_data (&data_out, test_attr.data_size_out); +if (!topts.data_size_out) + topts.data_size_out = default_size; + err =alloc_run_data (&data_out, topts.data_size_out);if (err) goto free_data_in; } - err =get_run_data (ctx_fname_in, &ctx_in, &test_attr.ctx_size_in); + err =get_run_data (ctx_fname_in, &ctx_in, &topts.ctx_size_in);if (err) goto free_data_out;if (ctx_in) { -if (!test_attr.ctx_size_out) - test_attr.ctx_size_out = default_size; - err =alloc_run_data (&ctx_out, test_attr.ctx_size_out); +if (!topts.ctx_size_out) + topts.ctx_size_out = default_size; + err =alloc_run_data (&ctx_out, topts.ctx_size_out);if (err) goto free_ctx_in; } - test_attr.prog_fd = fd; - test_attr.repeat = repeat; - test_attr.data_in = data_in; - test_attr.data_out = data_out; - test_attr.ctx_in = ctx_in; - test_attr.ctx_out = ctx_out; + topts.repeat = repeat; + topts.data_in = data_in; + topts.data_out = data_out; + topts.ctx_in = ctx_in; + topts.ctx_out = ctx_out; - err =bpf_prog_test_run_xattr (&test_attr); + err =bpf_prog_test_run_opts (fd, &topts);if (err) {p_err ("failed to run program: %s" ,strerror (errno)); goto free_ctx_out;
@@ -1416,23 +1415,23 @@ static int do_run(int argc, char **argv)/* Do not exit on errors occurring when printing output data/context, * we still want to print return value and duration for program run. */ -if (test_attr.data_size_out) - err +=print_run_output (test_attr.data_out, - test_attr.data_size_out, +if (topts.data_size_out) + err +=print_run_output (topts.data_out, + topts.data_size_out, data_fname_out,"data_out" ); -if (test_attr.ctx_size_out) - err +=print_run_output (test_attr.ctx_out, - test_attr.ctx_size_out, +if (topts.ctx_size_out) + err +=print_run_output (topts.ctx_out, + topts.ctx_size_out, ctx_fname_out,"ctx_out" );if (json_output) { -jsonw_uint_field (json_wtr,"retval" , test_attr.retval); -jsonw_uint_field (json_wtr,"duration" , test_attr.duration); +jsonw_uint_field (json_wtr,"retval" , topts.retval); +jsonw_uint_field (json_wtr,"duration" , topts.duration);jsonw_end_object (json_wtr);/* root */ }else {fprintf (stdout,"Return value: %u, duration%s: %uns\n" , - test_attr.retval, - repeat >1 ?" (average)" :"" , test_attr.duration); + topts.retval, + repeat >1 ?" (average)" :"" , topts.duration); } free_ctx_out:
Signature · 1 line
2.30.2
Re: [PATCH bpf-next v2 3/4] bpftool: migrate from bpf_prog_test_run_xattr
Quoted 13 lines · Delyan Kratunov
bpf_prog_test_run_xattris being deprecated in favor ofbpf_prog_test_run_opts.Signed-off-by Delyan Kratunov <[email protected]>--- tools/bpf/bpftool/prog.c | 55 ++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 28 deletions(-)tools/bpf/bpftool/prog.c +0
-0
tools/bpf/bpftool/prog.c static int do_run(int argc, char **argv) · line 1280
Quoted 10 lines
tools/bpf/bpftool/prog.c +1
-1@@ -1272,12 +1272,12 @@ static int do_run(int argc, char **argv) {char *data_fname_in =NULL , *data_fname_out =NULL ;char *ctx_fname_in =NULL , *ctx_fname_out =NULL ; -struct bpf_prog_test_run_attr test_attr = {0 };const unsigned int default_size =SZ_32K ;void *data_in =NULL , *data_out =NULL ;void *ctx_in =NULL , *ctx_out =NULL ;unsigned int repeat =1 ;int fd, err; +LIBBPF_OPTS (bpf_test_run_opts, topts);
let's name it "test_attr" and avoid most of the code churn?
Otherwise it looks good, thanks!
Quoted 3 lines
tools/bpf/bpftool/prog.c +0
-0if (!REQ_ARGS (4 ))return -1 ;
[...]
PATCH v2 4/4 libbpf: Deprecate bpf_prog_test_run_xattr and bpf_prog_test_run
In reply to Delyan Kratunov--- tools/lib/bpf/bpf.h | 8 +++++--- tools/lib/bpf/xsk.c | 11 +++++++---- 2 files changed, 12 insertions(+), 7 deletions(-)
tools/lib/bpf/bpf.h +5 -3
@@ -453,13 +453,15 @@ struct bpf_prog_test_run_attr {* out: length of cxt_out */ }; -LIBBPF_API int bpf_prog_test_run_xattr(struct bpf_prog_test_run_attr *test_attr); +LIBBPF_DEPRECATED_SINCE(0, 7, "use bpf_prog_test_run_opts() instead") +int bpf_prog_test_run_xattr (struct bpf_prog_test_run_attr *test_attr);/* * bpf_prog_test_run does not check that data_out is large enough. Consider -* using bpf_prog_test_run_xattr instead. +* using bpf_prog_test_run_opts instead. */ -LIBBPF_API int bpf_prog_test_run(int prog_fd, int repeat, void *data, +LIBBPF_DEPRECATED_SINCE(0, 7, "use bpf_prog_test_run_opts() instead") +int bpf_prog_test_run (int prog_fd,int repeat,void *data,__u32 size,void *data_out,__u32 *size_out,__u32 *retval,__u32 *duration); LIBBPF_API int bpf_prog_get_next_id(__u32 start_id, __u32 *next_id);
tools/lib/bpf/xsk.c +7 -4
@@ -369,8 +369,7 @@ int xsk_umem__create_v0_0_2(struct xsk_umem **umem_ptr, void *umem_area,static enum xsk_prog get_xsk_prog (void ) {enum xsk_prog detected =XSK_PROG_FALLBACK ; -__u32 size_out, retval, duration; -char data_in =0 , data_out; +char data_in =0 ;struct bpf_insn insns[] = {BPF_LD_MAP_FD (BPF_REG_1 ,0 ),BPF_MOV64_IMM (BPF_REG_2 ,0 ),
@@ -378,6 +377,10 @@ static enum xsk_prog get_xsk_prog(void)BPF_EMIT_CALL (BPF_FUNC_redirect_map),BPF_EXIT_INSN (), }; +LIBBPF_OPTS (bpf_test_run_opts, test_opts, + .data_in = &data_in, + .data_size_in = 1, + );int prog_fd, map_fd, ret, insn_cnt =ARRAY_SIZE (insns); map_fd =bpf_map_create (BPF_MAP_TYPE_XSKMAP ,NULL ,sizeof (int ),sizeof (int ),1 ,NULL );
@@ -392,8 +395,8 @@ static enum xsk_prog get_xsk_prog(void)return detected; } - ret =bpf_prog_test_run (prog_fd,0 , &data_in,1 , &data_out, &size_out, &retval, &duration); -if (!ret && retval ==XDP_PASS ) + ret =bpf_prog_test_run_opts (prog_fd, &test_opts); +if (!ret && test_opts.retval ==XDP_PASS ) detected =XSK_PROG_REDIRECT_FLAGS ;close (prog_fd);close (map_fd);
Signature · 1 line
2.30.2
Re: [PATCH bpf-next v2 4/4] libbpf: Deprecate bpf_prog_test_run_xattr and bpf_prog_test_run
Quoted 2 lines · Delyan Kratunov
As Daniel mentioned, please add non-empty commit message. As for the "Closes: ", it's not one of "supported" tags in Linux repo, so we've been using a "reference" syntax to introduce it. So something like this commit message would do the trick:
Deprecate non-extendable bpf_prog_test_run_xattr() in favor of OPTS-based bpf_prog_test_run_opts() ([0]).
[0] Closes: https://github.com/libbpf/libbpf/issues/286
Quoted 11 lines
Signed-off-by Delyan Kratunov <[email protected]>--- tools/lib/bpf/bpf.h | 8 +++++--- tools/lib/bpf/xsk.c | 11 +++++++---- 2 files changed, 12 insertions(+), 7 deletions(-)tools/lib/bpf/bpf.h +0
-0
tools/lib/bpf/bpf.h struct bpf_prog_test_run_attr { · line 456
Quoted 5 lines
tools/lib/bpf/bpf.h +1
-1@@ -453,13 +453,15 @@ struct bpf_prog_test_run_attr {* out: length of cxt_out */ }; -LIBBPF_API int bpf_prog_test_run_xattr(struct bpf_prog_test_run_attr *test_attr); +LIBBPF_DEPRECATED_SINCE (0 ,7 ,"use bpf_prog_test_run_opts() instead" )
please don't remove LIBBPF_API, it still has to be marked with LIBBPF_API for proper shared library visibility
tools/lib/bpf/xsk.c
Quoted 17 lines
tools/lib/bpf/bpf.h +4
-2+int bpf_prog_test_run_xattr (struct bpf_prog_test_run_attr *test_attr);/* * bpf_prog_test_run does not check that data_out is large enough. Consider -* using bpf_prog_test_run_xattr instead. +* using bpf_prog_test_run_opts instead. */ -LIBBPF_API int bpf_prog_test_run(int prog_fd, int repeat, void *data, +LIBBPF_DEPRECATED_SINCE(0, 7, "use bpf_prog_test_run_opts() instead") +int bpf_prog_test_run (int prog_fd,int repeat,void *data,__u32 size,void *data_out,__u32 *size_out,__u32 *retval,__u32 *duration); LIBBPF_API int bpf_prog_get_next_id(__u32 start_id, __u32 *next_id);tools/lib/bpf/xsk.c +0
-0
don't bother with xsk.c, entire file is marked as deprecated and will be removed in libbpf v1.0. It already has deprecation suppressing pragma, so you shouldn't see any compilation warning.
Quoted 35 lines
tools/lib/bpf/xsk.c +7
-5@@ -369,8 +369,7 @@ int xsk_umem__create_v0_0_2(struct xsk_umem **umem_ptr, void *umem_area,static enum xsk_prog get_xsk_prog (void ) {enum xsk_prog detected =XSK_PROG_FALLBACK ; -__u32 size_out, retval, duration; -char data_in =0 , data_out; +char data_in =0 ;struct bpf_insn insns[] = {BPF_LD_MAP_FD (BPF_REG_1 ,0 ),BPF_MOV64_IMM (BPF_REG_2 ,0 ),@@ -378,6 +377,10 @@ static enum xsk_prog get_xsk_prog(void)BPF_EMIT_CALL (BPF_FUNC_redirect_map),BPF_EXIT_INSN (), }; +LIBBPF_OPTS (bpf_test_run_opts, test_opts, + .data_in = &data_in, + .data_size_in = 1, + );int prog_fd, map_fd, ret, insn_cnt =ARRAY_SIZE (insns); map_fd =bpf_map_create (BPF_MAP_TYPE_XSKMAP ,NULL ,sizeof (int ),sizeof (int ),1 ,NULL );@@ -392,8 +395,8 @@ static enum xsk_prog get_xsk_prog(void)return detected; } - ret =bpf_prog_test_run (prog_fd,0 , &data_in,1 , &data_out, &size_out, &retval, &duration); -if (!ret && retval ==XDP_PASS ) + ret =bpf_prog_test_run_opts (prog_fd, &test_opts); +if (!ret && test_opts.retval ==XDP_PASS ) detected =XSK_PROG_REDIRECT_FLAGS ;close (prog_fd);close (map_fd); --2.30.2
Daniel Borkmann
maintainerQuoted 10 lines · Delyan Kratunov
Fairly straight-forward mechanical transformation from
bpf_prog_test_runandbpf_prog_test_run_xattrto thebpf_prog_test_run_optsgoodness. Most of the changes are in tests, though bpftool and libbpf (xsk.c) have one call site each as well.The only aspect that's still a bit RFC is that
prog_run_xattris testing behavior specific tobpf_prog_test_run_xattr, which does not exist inprog_run_opts. Namely,-EINVALreturn ondata_out== NULL &&data_size_out> 0. Adding this behavior toprog_test_run_optsis one option, keeping the test as-is and cloning it to usebpf_prog_test_run_optsis another possibility.
I would suggest to do the former rather than duplicating, if there's nothing particularly blocking us from adding this to prog_test_run_opts.
Quoted 5 lines
The current version just suppresses the deprecation warning.
As an aside, checkpatch really doesn't like that
LIBBPF_OPTSlooks like a function call but is formatted like a struct declaration. If anyone cares about formatting, now would be a good time to mention it.
As you have it looks good to me. One small nit, please also add a non-empty commit message with rationale to each of the patches rather than just SoB alone.
Thanks a lot!
Quoted 9 lines
v1 -> v2:
Split selftests/bpf changes into two commits to appease the mailing list.Delyan Kratunov (4):
selftests: bpf: migrate frombpf_prog_test_run
selftests: bpf: migrate frombpf_prog_test_run_xattr
bpftool: migrate frombpf_prog_test_run_xattr
libbpf: Deprecatebpf_prog_test_run_xattrandbpf_prog_test_run
Thanks for taking a look, Daniel!
Quoted 6 lines · Daniel Borkmann
Quoted 2 lines · Delyan Kratunov
Adding this behavior to
prog_test_run_optsis one option, keeping the test as-is and cloning it to usebpf_prog_test_run_optsis another possibility.I would suggest to do the former rather than duplicating, if there's nothing particularly blocking us from adding this to
prog_test_run_opts.
I looked into this a bit more. Unfortunately, bpf_test_finish unconditionally copies data_size_out back into the uattr, even if data_out is NULL. (net/bpf/test_run.c:180)
This makes the ergonomics of reusing the same topts struct for multiple bpf_prog_test_run calls pretty horrendous - you'd need to clear data_size_out before every call, even if you don't care about it otherwise (and you don't, you didn't set data_out!).
In practicality, adding the logic from _xattr to _opts results in a significant number of test failures. I'm a bit worried it might break libbpf users if they use similar opts reuse patterns.
Quoted 2 lines
As you have it looks good to me. One small nit, please also add a non-empty commit message with rationale to each of the patches rather than just SoB alone.
Will do!
Quoted 15 lines · Delyan Kratunov
Thanks for taking a look, Daniel!
Quoted 6 lines · Daniel Borkmann
Quoted 2 lines · Delyan Kratunov
Adding this behavior to
prog_test_run_optsis one option, keeping the test as-is and cloning it to usebpf_prog_test_run_optsis another possibility.I would suggest to do the former rather than duplicating, if there's nothing particularly blocking us from adding this to
prog_test_run_opts.I looked into this a bit more. Unfortunately,
bpf_test_finishunconditionally copiesdata_size_outback into the uattr, even ifdata_outis NULL. (net/bpf/test_run.c:180)
Quoted 9 lines
This makes the ergonomics of reusing the same topts struct for multiple
bpf_prog_test_runcalls pretty horrendous - you'd need to cleardata_size_outbefore every call, even if you don't care about it otherwise (and you don't, you didn't setdata_out!).In practicality, adding the logic from
_xattrto_optsresults in a significant number of test failures. I'm a bit worried it might break libbpf users if they use similar opts reuse patterns.
Seems like kernel doesn't enforce that data_size_out == 0 if data_out is NULL, so I'd say let's just keep bpf_test_run_opts() as is and defer to kernel for error checking (e.g., for raw_tp data_out isn't allowed to be NULL, but libbpf doesn't check that, right, it just lets kernel do all the nuanced error checking).
So I'd say let's keep _opts() as is and let's remove parts of prog_run_xattr.c selftest that check this specific error check?
Quoted 5 lines
Quoted 2 lines
As you have it looks good to me. One small nit, please also add a non-empty commit message with rationale to each of the patches rather than just SoB alone.
Will do!