[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAEf4BzZ8cbMBVNhxXRXapyZCm_b70y-85Xb5SpB0MWBixJ9h_w@mail.gmail.com>
Date: Tue, 23 Jun 2020 11:16:43 -0700
From: Andrii Nakryiko <andrii.nakryiko@...il.com>
To: Alan Maguire <alan.maguire@...cle.com>
Cc: Alexei Starovoitov <ast@...nel.org>,
Daniel Borkmann <daniel@...earbox.net>,
Yonghong Song <yhs@...com>, Andrii Nakryiko <andriin@...com>,
Arnaldo Carvalho de Melo <arnaldo.melo@...il.com>,
Martin Lau <kafai@...com>, Song Liu <songliubraving@...com>,
john fastabend <john.fastabend@...il.com>,
KP Singh <kpsingh@...omium.org>,
Rasmus Villemoes <linux@...musvillemoes.dk>,
Joe Perches <joe@...ches.com>, Petr Mladek <pmladek@...e.com>,
Steven Rostedt <rostedt@...dmis.org>,
Sergey Senozhatsky <sergey.senozhatsky@...il.com>,
andriy.shevchenko@...ux.intel.com, corbet@....net,
bpf <bpf@...r.kernel.org>, Networking <netdev@...r.kernel.org>,
open list <linux-kernel@...r.kernel.org>,
linux-doc@...r.kernel.org
Subject: Re: [PATCH v3 bpf-next 8/8] bpf/selftests: add tests for %pT format specifier
On Tue, Jun 23, 2020 at 5:12 AM Alan Maguire <alan.maguire@...cle.com> wrote:
>
> tests verify we get 0 return value from bpf_trace_print()
> using %pT format specifier with various modifiers/pointer
> values.
>
> Signed-off-by: Alan Maguire <alan.maguire@...cle.com>
> ---
Acked-by: Andrii Nakryiko <andriin@...com>
> .../selftests/bpf/prog_tests/trace_printk_btf.c | 45 +++++++++++++++++++++
> .../selftests/bpf/progs/netif_receive_skb.c | 47 ++++++++++++++++++++++
> 2 files changed, 92 insertions(+)
> create mode 100644 tools/testing/selftests/bpf/prog_tests/trace_printk_btf.c
> create mode 100644 tools/testing/selftests/bpf/progs/netif_receive_skb.c
>
[...]
> diff --git a/tools/testing/selftests/bpf/progs/netif_receive_skb.c b/tools/testing/selftests/bpf/progs/netif_receive_skb.c
> new file mode 100644
> index 0000000..03ca1d8
> --- /dev/null
> +++ b/tools/testing/selftests/bpf/progs/netif_receive_skb.c
> @@ -0,0 +1,47 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/* Copyright (c) 2020, Oracle and/or its affiliates. */
> +#include "vmlinux.h"
> +#include <bpf/bpf_helpers.h>
> +#include <bpf/bpf_tracing.h>
> +
> +char _license[] SEC("license") = "GPL";
> +
> +int ret;
> +int num_subtests;
> +int ran_subtests;
oh, interesting, so Clang doesn't put these into the COM section
anymore? We used to need to explicitly zero-initialize these global
vars because of that.
> +
> +#define CHECK_PRINTK(_fmt, _p, res) \
> + do { \
> + char fmt[] = _fmt; \
pro tip: you can use `static const char fmt[] = _fmt` and it will just work.
> + ++num_subtests; \
> + if (ret >= 0) { \
> + ++ran_subtests; \
> + ret = bpf_trace_printk(fmt, sizeof(fmt), (_p)); \
> + } \
> + } while (0)
> +
> +/* TRACE_EVENT(netif_receive_skb,
> + * TP_PROTO(struct sk_buff *skb),
> + */
> +SEC("tp_btf/netif_receive_skb")
> +int BPF_PROG(trace_netif_receive_skb, struct sk_buff *skb)
> +{
> + char skb_type[] = "struct sk_buff";
same, `static const char` will generate more optimal code (good to
have good examples in selftests for people to follow). But don't
bother re-spinning just for this.
> + struct btf_ptr nullp = { .ptr = 0, .type = skb_type };
> + struct btf_ptr p = { .ptr = skb, .type = skb_type };
> +
> + CHECK_PRINTK("%pT\n", &p, &res);
> + CHECK_PRINTK("%pTc\n", &p, &res);
> + CHECK_PRINTK("%pTN\n", &p, &res);
> + CHECK_PRINTK("%pTx\n", &p, &res);
> + CHECK_PRINTK("%pT0\n", &p, &res);
> + CHECK_PRINTK("%pTcNx0\n", &p, &res);
> + CHECK_PRINTK("%pT\n", &nullp, &res);
> + CHECK_PRINTK("%pTc\n", &nullp, &res);
> + CHECK_PRINTK("%pTN\n", &nullp, &res);
> + CHECK_PRINTK("%pTx\n", &nullp, &res);
> + CHECK_PRINTK("%pT0\n", &nullp, &res);
> + CHECK_PRINTK("%pTcNx0\n", &nullp, &res);
> +
> + return 0;
> +}
> --
> 1.8.3.1
>
Powered by blists - more mailing lists