On Tue, Jun 23, 2020 at 5:12 AM Alan Maguire <alan.maguire@xxxxxxxxxx> 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@xxxxxxxxxx> > --- Acked-by: Andrii Nakryiko <andriin@xxxxxx> > .../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 >