netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Song Liu <liu.song.a23@gmail.com>
To: Andrii Nakryiko <andriin@fb.com>
Cc: Andrii Nakryiko <andrii.nakryiko@gmail.com>,
	bpf <bpf@vger.kernel.org>, Networking <netdev@vger.kernel.org>,
	Alexei Starovoitov <ast@fb.com>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Kernel Team <kernel-team@fb.com>
Subject: Re: [PATCH bpf-next 7/8] selftests/bpf: add test for BTF-defined maps
Date: Sat, 15 Jun 2019 15:05:14 -0700	[thread overview]
Message-ID: <CAPhsuW5MNx4NvXJGNo9uPkQBHFgojHCbdy4eyVE31e6bENx8Mg@mail.gmail.com> (raw)
In-Reply-To: <20190611044747.44839-8-andriin@fb.com>

On Mon, Jun 10, 2019 at 9:49 PM Andrii Nakryiko <andriin@fb.com> wrote:
>
> Add file test for BTF-defined map definition.
>
> Signed-off-by: Andrii Nakryiko <andriin@fb.com>

Acked-by: Song Liu <songliubraving@fb.com>

> ---
>  .../selftests/bpf/progs/test_btf_newkv.c      | 73 +++++++++++++++++++
>  tools/testing/selftests/bpf/test_btf.c        | 10 +--
>  2 files changed, 76 insertions(+), 7 deletions(-)
>  create mode 100644 tools/testing/selftests/bpf/progs/test_btf_newkv.c
>
> diff --git a/tools/testing/selftests/bpf/progs/test_btf_newkv.c b/tools/testing/selftests/bpf/progs/test_btf_newkv.c
> new file mode 100644
> index 000000000000..28c16bb583b6
> --- /dev/null
> +++ b/tools/testing/selftests/bpf/progs/test_btf_newkv.c
> @@ -0,0 +1,73 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +/* Copyright (c) 2018 Facebook */
> +#include <linux/bpf.h>
> +#include "bpf_helpers.h"
> +
> +int _version SEC("version") = 1;
> +
> +struct ipv_counts {
> +       unsigned int v4;
> +       unsigned int v6;
> +};
> +
> +/* just to validate we can handle maps in multiple sections */
> +struct bpf_map_def SEC("maps") btf_map_legacy = {
> +       .type = BPF_MAP_TYPE_ARRAY,
> +       .key_size = sizeof(int),
> +       .value_size = sizeof(long long),
> +       .max_entries = 4,
> +};
> +
> +BPF_ANNOTATE_KV_PAIR(btf_map_legacy, int, struct ipv_counts);
> +
> +struct {
> +       int *key;
> +       struct ipv_counts *value;
> +       unsigned int type;
> +       unsigned int max_entries;
> +} btf_map SEC(".maps") = {
> +       .type = BPF_MAP_TYPE_ARRAY,
> +       .max_entries = 4,
> +};
> +
> +struct dummy_tracepoint_args {
> +       unsigned long long pad;
> +       struct sock *sock;
> +};
> +
> +__attribute__((noinline))
> +static int test_long_fname_2(struct dummy_tracepoint_args *arg)
> +{
> +       struct ipv_counts *counts;
> +       int key = 0;
> +
> +       if (!arg->sock)
> +               return 0;
> +
> +       counts = bpf_map_lookup_elem(&btf_map, &key);
> +       if (!counts)
> +               return 0;
> +
> +       counts->v6++;
> +
> +       /* just verify we can reference both maps */
> +       counts = bpf_map_lookup_elem(&btf_map_legacy, &key);
> +       if (!counts)
> +               return 0;
> +
> +       return 0;
> +}
> +
> +__attribute__((noinline))
> +static int test_long_fname_1(struct dummy_tracepoint_args *arg)
> +{
> +       return test_long_fname_2(arg);
> +}
> +
> +SEC("dummy_tracepoint")
> +int _dummy_tracepoint(struct dummy_tracepoint_args *arg)
> +{
> +       return test_long_fname_1(arg);
> +}
> +
> +char _license[] SEC("license") = "GPL";
> diff --git a/tools/testing/selftests/bpf/test_btf.c b/tools/testing/selftests/bpf/test_btf.c
> index 289daf54dec4..8351cb5f4a20 100644
> --- a/tools/testing/selftests/bpf/test_btf.c
> +++ b/tools/testing/selftests/bpf/test_btf.c
> @@ -4016,13 +4016,9 @@ struct btf_file_test {
>  };
>
>  static struct btf_file_test file_tests[] = {
> -{
> -       .file = "test_btf_haskv.o",
> -},
> -{
> -       .file = "test_btf_nokv.o",
> -       .btf_kv_notfound = true,
> -},
> +       { .file = "test_btf_haskv.o", },
> +       { .file = "test_btf_newkv.o", },
> +       { .file = "test_btf_nokv.o", .btf_kv_notfound = true, },
>  };
>
>  static int do_test_file(unsigned int test_num)
> --
> 2.17.1
>

  reply	other threads:[~2019-06-15 22:05 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-11  4:47 [PATCH bpf-next 0/8] BTF-defined BPF map definitions Andrii Nakryiko
2019-06-11  4:47 ` [PATCH bpf-next 1/8] libbpf: add common min/max macro to libbpf_internal.h Andrii Nakryiko
2019-06-15 20:26   ` Song Liu
2019-06-11  4:47 ` [PATCH bpf-next 2/8] libbpf: extract BTF loading and simplify ELF parsing logic Andrii Nakryiko
2019-06-15 20:25   ` Song Liu
2019-06-15 20:28     ` Song Liu
2019-06-17 17:46       ` Andrii Nakryiko
2019-06-17 17:24     ` Andrii Nakryiko
2019-06-17 18:07       ` Song Liu
2019-06-17 18:35         ` Andrii Nakryiko
2019-06-11  4:47 ` [PATCH bpf-next 3/8] libbpf: refactor map initialization Andrii Nakryiko
2019-06-11  4:47 ` [PATCH bpf-next 4/8] libbpf: identify maps by section index in addition to offset Andrii Nakryiko
2019-06-11  4:47 ` [PATCH bpf-next 5/8] libbpf: split initialization and loading of BTF Andrii Nakryiko
2019-06-15 21:21   ` Song Liu
2019-06-11  4:47 ` [PATCH bpf-next 6/8] libbpf: allow specifying map definitions using BTF Andrii Nakryiko
2019-06-15 22:00   ` Song Liu
2019-06-17 18:33     ` Andrii Nakryiko
2019-06-11  4:47 ` [PATCH bpf-next 7/8] selftests/bpf: add test for BTF-defined maps Andrii Nakryiko
2019-06-15 22:05   ` Song Liu [this message]
2019-06-11  4:47 ` [PATCH bpf-next 8/8] selftests/bpf: switch tests to BTF-defined map definitions Andrii Nakryiko
2019-06-14 23:23   ` Stanislav Fomichev
2019-06-14 23:43     ` Andrii Nakryiko
2019-06-15  0:01       ` Stanislav Fomichev
2019-06-17 19:30         ` Andrii Nakryiko
2019-06-17 21:07           ` Stanislav Fomichev
2019-06-11  5:21 ` [PATCH bpf-next 0/8] BTF-defined BPF " Andrii Nakryiko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAPhsuW5MNx4NvXJGNo9uPkQBHFgojHCbdy4eyVE31e6bENx8Mg@mail.gmail.com \
    --to=liu.song.a23@gmail.com \
    --cc=andrii.nakryiko@gmail.com \
    --cc=andriin@fb.com \
    --cc=ast@fb.com \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=kernel-team@fb.com \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).