Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp3812458ybt; Tue, 23 Jun 2020 11:17:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx/nIVoBV0hM/ZW52Rcf4Z/u6mm+l76SavOrJv2zUMx9MEu1OtFimjfiphT4gpo6ZlSLcUm X-Received: by 2002:a05:6402:13ca:: with SMTP id a10mr23440370edx.224.1592936256878; Tue, 23 Jun 2020 11:17:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592936256; cv=none; d=google.com; s=arc-20160816; b=DZokRue4VuYcaNT0+o8wvvH1T/ShWbToTpXcSGoekKP6MdAy89dUBLc4UW9j91Ctwc KX5KSBrbp12UYi3BpBu1Y5aEV5KoTeOyLLzN3cEo2VlTDwaYsU8EJTkFBw0IoeukKsuX zOrpK/N7wmzDC4yyaSt01eq4jgWolzSLGYDkaJUbTsk1XoM9DmkVmTvZBtb5jnFPMUq7 UJ2aS6enirb9dX4/ac4+pDTuUMG50sbXbR4oZaS5ltXp20tqvl1sR3BZUoS5ycDN00sk db1JtfUbZyVJON+6r6r9iz9n50NwOstuBkuB35Ynj+VAhrMat7zG9k0jBxKZdstHRb1o wdQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=mldfnWKkii9NqHOu/tXDKOQ3f+s/hvhqqjnpq5hhPWY=; b=wcF0q/WlTE+RVUsdT0P7+YZl5V4MtClgBETTwU0+a7C+HwG1gdTBB9ZZxgCdVoofQW yBeVoY0iHzBfAaCLi2DA1tSDLoPFxrAwHC8/HuG030B/A4c7CUXm2WCvMNzwC6wGIFYF 64gq1eN3Cuq7Y34wH8sd+DVv4rPquh61ZVpyNu1RbaliT1DOqHC4FIqLwyM6brcI5vQh h4DBtVYFowMz5Xr4ZeBzBqehu79riLiXwu6o3xV98fE5sn/qkzA5wEjx39jNJA6HVKPy QbWt5ETdfpQ0uVlvL7pnv5eCETa6tPfU6YeqcLzFbVM3VaO0vEZKmG6TB6tzvG3wLZOb cPkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=dodDBLcl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y27si4957178eje.284.2020.06.23.11.17.13; Tue, 23 Jun 2020 11:17:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=dodDBLcl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733149AbgFWSQ4 (ORCPT + 99 others); Tue, 23 Jun 2020 14:16:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33238 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728916AbgFWSQz (ORCPT ); Tue, 23 Jun 2020 14:16:55 -0400 Received: from mail-qk1-x743.google.com (mail-qk1-x743.google.com [IPv6:2607:f8b0:4864:20::743]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A3FCC061573; Tue, 23 Jun 2020 11:16:55 -0700 (PDT) Received: by mail-qk1-x743.google.com with SMTP id q198so11881385qka.2; Tue, 23 Jun 2020 11:16:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=mldfnWKkii9NqHOu/tXDKOQ3f+s/hvhqqjnpq5hhPWY=; b=dodDBLcldmPsxJt8X89WGwJOvoTtN0MpO3DcU1SWAop3JWBYfEMfQXH8Q8v5FQI21y M3tssQMT05tLDv9R6ymn0+i+m6N+QuzwN5Y1qdZ7B2/KDYUC+Itt2Vm4F2QXgwgvZjNz mlaaaiiHmj7FsvhyXxCgyHHA40Zcq0kzHC3visY014WNtJ6l5BO/j/i6CQIkwfBEBwjv HC3BFqGOvFA1pg1s2Z1gj3WyPbjUC+BkSwUvzeBfkz3ioODYf/cWvuwnlGnDf59yfTzz iBTXm5nq4tQtXWf8f1LYCbt+oq81CmnvCVBA07qKm2CLXoYpx1zzOi7AFSP02d2m7WgV eQlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=mldfnWKkii9NqHOu/tXDKOQ3f+s/hvhqqjnpq5hhPWY=; b=jPIW7q/drsEbtxivgUQeAsG2s1wjZJDya7nYpMfYpMeAQn0v0I9fiB6ZOok/lpTBKO Lwh8ht6Uh3EoqmNEdo4k0g66WfPS/sTGNkR9SUNEc4bEXH5wpICW2oqg+HsoY664HTg5 lg1yD6Z2wTzJLjZG1uB9uVSNqSXpTaMOeP1F67owQnOXXBBb6i0b6NzeB1TeyrkkmFuY MYz2VlHMX5mWXD/ocM/oDkMUWiD/bNMlm5OTbPDZVJB+PatxypXkffy9WPZhqQ599FBK AgvZziNBedwdgOSJbLG5NvqD2oNRPSRhSDmGkjqLoy4b3rQFi7YOBu1djgK+FTWNZXIn UQ4A== X-Gm-Message-State: AOAM533ppAyMwwmImd2aHVlpFbjeyGqUJSMYKkbaCJFBaD4r1HN3AEol rgS+tU3IMNiilNSr0Ek0AMi/We9B8FXaSKvUc0c= X-Received: by 2002:a05:620a:12d2:: with SMTP id e18mr22426657qkl.437.1592936214457; Tue, 23 Jun 2020 11:16:54 -0700 (PDT) MIME-Version: 1.0 References: <1592914031-31049-1-git-send-email-alan.maguire@oracle.com> <1592914031-31049-9-git-send-email-alan.maguire@oracle.com> In-Reply-To: <1592914031-31049-9-git-send-email-alan.maguire@oracle.com> From: Andrii Nakryiko Date: Tue, 23 Jun 2020 11:16:43 -0700 Message-ID: Subject: Re: [PATCH v3 bpf-next 8/8] bpf/selftests: add tests for %pT format specifier To: Alan Maguire Cc: Alexei Starovoitov , Daniel Borkmann , Yonghong Song , Andrii Nakryiko , Arnaldo Carvalho de Melo , Martin Lau , Song Liu , john fastabend , KP Singh , Rasmus Villemoes , Joe Perches , Petr Mladek , Steven Rostedt , Sergey Senozhatsky , andriy.shevchenko@linux.intel.com, corbet@lwn.net, bpf , Networking , open list , linux-doc@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jun 23, 2020 at 5:12 AM Alan Maguire 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 > --- Acked-by: Andrii Nakryiko > .../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 > +#include > + > +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 >