2022-01-22 00:33:21

by Alexei Starovoitov

[permalink] [raw]
Subject: Re: [PATCH bpf-next v6 2/2] selftests: bpf: test BPF_PROG_QUERY for progs attached to sockmap

On Tue, Jan 18, 2022 at 5:40 PM Di Zhu <[email protected]> wrote:
>
> Add test for querying progs attached to sockmap. we use an existing
> libbpf query interface to query prog cnt before and after progs
> attaching to sockmap and check whether the queried prog id is right.
>
> Signed-off-by: Di Zhu <[email protected]>
> Acked-by: Yonghong Song <[email protected]>
> ---
> .../selftests/bpf/prog_tests/sockmap_basic.c | 66 +++++++++++++++++++
> .../bpf/progs/test_sockmap_progs_query.c | 24 +++++++
> 2 files changed, 90 insertions(+)
> create mode 100644 tools/testing/selftests/bpf/progs/test_sockmap_progs_query.c
>
> diff --git a/tools/testing/selftests/bpf/prog_tests/sockmap_basic.c b/tools/testing/selftests/bpf/prog_tests/sockmap_basic.c
> index 85db0f4cdd95..1ab57cdc4ae4 100644
> --- a/tools/testing/selftests/bpf/prog_tests/sockmap_basic.c
> +++ b/tools/testing/selftests/bpf/prog_tests/sockmap_basic.c
> @@ -8,6 +8,7 @@
> #include "test_sockmap_update.skel.h"
> #include "test_sockmap_invalid_update.skel.h"
> #include "test_sockmap_skb_verdict_attach.skel.h"
> +#include "test_sockmap_progs_query.skel.h"
> #include "bpf_iter_sockmap.skel.h"
>
> #define TCP_REPAIR 19 /* TCP sock is under repair right now */
> @@ -315,6 +316,63 @@ static void test_sockmap_skb_verdict_attach(enum bpf_attach_type first,
> test_sockmap_skb_verdict_attach__destroy(skel);
> }
>
> +static __u32 query_prog_id(int prog_fd)
> +{
> + struct bpf_prog_info info = {};
> + __u32 info_len = sizeof(info);
> + int err;
> +
> + err = bpf_obj_get_info_by_fd(prog_fd, &info, &info_len);
> + if (!ASSERT_OK(err, "bpf_obj_get_info_by_fd") ||
> + !ASSERT_EQ(info_len, sizeof(info), "bpf_obj_get_info_by_fd"))
> + return 0;
> +
> + return info.id;
> +}
> +
> +static void test_sockmap_progs_query(enum bpf_attach_type attach_type)
> +{
> + struct test_sockmap_progs_query *skel;
> + int err, map_fd, verdict_fd, duration = 0;

The 'duration' is unused.
You should have seen a warning while compiling the selftests?

Anyway. I've fixed it while applying.