Re: [PATCH bpf-next v2 2/2] selftests/bpf: Excercise bpf_obj_get_info_by_fd for bpf2bpf

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Aug 03, 2022 at 10:10:33AM -0700, Stanislav Fomichev wrote:
> On Wed, Aug 3, 2022 at 9:51 AM Martin KaFai Lau <kafai@xxxxxx> wrote:
> >
> > On Wed, Aug 03, 2022 at 09:32:23AM -0700, Stanislav Fomichev wrote:
> > > +static void test_fentry_to_cgroup_bpf(void)
> > > +{
> > > +     struct bind4_prog *skel = NULL;
> > > +     struct bpf_prog_info info = {};
> > > +     __u32 info_len = sizeof(info);
> > > +     int cgroup_fd = -1;
> > > +     int fentry_fd = -1;
> > > +     int btf_id;
> > > +
> > > +     cgroup_fd = test__join_cgroup("/fentry_to_cgroup_bpf");
> > > +     if (!ASSERT_GE(cgroup_fd, 0, "cgroup_fd"))
> > > +             return;
> > > +
> > > +     skel = bind4_prog__open_and_load();
> > > +     if (!ASSERT_OK_PTR(skel, "skel"))
> > > +             goto cleanup;
> > > +
> > > +     skel->links.bind_v4_prog = bpf_program__attach_cgroup(skel->progs.bind_v4_prog, cgroup_fd);
> > > +     if (!ASSERT_OK_PTR(skel->links.bind_v4_prog, "bpf_program__attach_cgroup"))
> > > +             goto cleanup;
> > > +
> > > +     btf_id = find_prog_btf_id("bind_v4_prog", bpf_program__fd(skel->progs.bind_v4_prog));
> > > +     if (!ASSERT_GE(btf_id, 0, "find_prog_btf_id"))
> > > +             goto cleanup;
> > > +
> > > +     fentry_fd = load_fentry(bpf_program__fd(skel->progs.bind_v4_prog), btf_id);
> > > +     if (!ASSERT_GE(fentry_fd, 0, "load_fentry"))
> > > +             goto cleanup;
> > > +
> > > +     /* Make sure bpf_obj_get_info_by_fd works correctly when attaching
> > > +      * to another BPF program.
> > > +      */
> > > +
> > > +     ASSERT_OK(bpf_obj_get_info_by_fd(fentry_fd, &info, &info_len),
> > > +               "bpf_obj_get_info_by_fd");
> > > +
> > > +     ASSERT_EQ(info.btf_id, 0, "info.btf_id");
> > > +     ASSERT_GT(info.attach_btf_id, 0, "info.attach_btf_id");
> > > +     ASSERT_GT(info.attach_btf_obj_id, 0, "info.attach_btf_obj_id");
> > nit. This can check against btf_id.
> 
> As in ASSERT_NEQ(info.attach_btf_obj_id, info.btf_id,
> "info.attach_btf_obj_id") ?
Ah, my bad on one line off.  I meant the previous line.

ASSERT_NEQ(info.attach_btf_id, btf_id, "info.attach_btf_id");

The bind_v4_prog's btf_obj_id is lost.  Otherwise, it could also do
ASSERT_NEQ(info.attach_btf_obj_id, bind_v4_prog_btf_id, "info.attach_btf_obj_id");



[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux