Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp280349ybt; Tue, 7 Jul 2020 23:09:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxdiBLzNLnCQgzh5/7SvRumyMdfjJQ/41c4ApQD99oHhyVnk0kG2eJ+uT+NzQgtq9q5Qu8P X-Received: by 2002:a17:906:a459:: with SMTP id cb25mr49886279ejb.234.1594188553164; Tue, 07 Jul 2020 23:09:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594188553; cv=none; d=google.com; s=arc-20160816; b=wHsJF4nuiTnXCW82lVOtfCe1pvP1ys5O0hPCpnGdZkkbJ4H2wiF7RSmhT8AyvOpH/d bLl9ASQ0vi7HaDhOc4Q4axosvBV91O2IuDc1JyMMmwCywARNFzWQMlc/P5jCFDbIzztw 2HQV2DEweCvzOIANB49VTLvxSzI6l5aOXwnlzohxKu5C+DLcVyJKVt6KCrOOd83KWxKS e3qRje8qLODMIiT6suQ3K0cc2CT1xN5lB3ywZqCjXCb8FlR5vTVDsDdZejA/BPw/y8IJ Z4fdpOIpcG+z99ztb9Tdc5WByU1M5U7CWYQNr5kJO4vG6AhHWmr+3tNVfDjN51UCbf3D DCNA== 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=h46sytC3dVmHv8xrOAubvrrK7HsHhfWItZlwDU6JO/I=; b=LeyNQWJKEa3fMjOaZXP4fIfVi0xL7PQUSI2/frrjUcezaqbWA0B6jscPXRYt1gsckV Eyd93m3OH4qEZ4Yp6ld79zDYaMx4d+QVFQvZo4Ea6/qeG52rCb3BWHqYM+/eTQJcebRS j7zLnvri+qd2acp6oVOReDWuDgMMZTjYtAZ2z90prr3Zdr1HZd03KtnsxtbEKqnJSLTk gbgAPU1NPn3FCn9jm+jHoZzAFZYsPJH0OVqS9yJnwcjLbV+tpSPYrYLnxdsqN27OHwVP WRFqXVMtjp8mAxSueLVa7KPKDLyVXpjHN2b6GN34G2Ay/YEYCgtxQP1fTOZkeJShhMfv irqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Q3aLc47q; 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 u10si15793775ejh.592.2020.07.07.23.08.46; Tue, 07 Jul 2020 23:09:13 -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=Q3aLc47q; 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 S1729015AbgGHGBp (ORCPT + 99 others); Wed, 8 Jul 2020 02:01:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55618 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726278AbgGHGBp (ORCPT ); Wed, 8 Jul 2020 02:01:45 -0400 Received: from mail-qk1-x741.google.com (mail-qk1-x741.google.com [IPv6:2607:f8b0:4864:20::741]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 11E07C061755; Tue, 7 Jul 2020 23:01:45 -0700 (PDT) Received: by mail-qk1-x741.google.com with SMTP id e13so40480471qkg.5; Tue, 07 Jul 2020 23:01:44 -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=h46sytC3dVmHv8xrOAubvrrK7HsHhfWItZlwDU6JO/I=; b=Q3aLc47qKjpaan/9JjMLz2pepmzfJao0bSK4t/G2ejkYNlnIs7cQtCPXktZSm2tzni uUNS2x4gu+TMDPBjV1+5ffhBo+YjHBxSzYjnip9cHC0niX/T4k7yJJCLGvazoss8IIiO NWGBNqhfWCo/M71etTwhUHGfEA+pU9HQDRc79sdpcOp298WgQZOUpR15UHJJLpVmmPsM hE53n80Z1+vi2z4C4jDCO/0kn+SQZUCnSru8dLTbI4WLAwefz2kexYKxEAi2vJZ9/6Bc PMnY63y6Ud85Oa+QA7aLFq1lq6t1Zp28pch91Bk2TwIURiyOK9dtdnL73wIYpIudiwW4 Lsuw== 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=h46sytC3dVmHv8xrOAubvrrK7HsHhfWItZlwDU6JO/I=; b=LeWts6nNMtFnFh5AfOdkC/QKaV2l71sTXBQP/qta9HP97Rr0UMGzbIfQqE/+0FclI9 Ol2THCfG5TBwg/gVnE6IEfTJw496MJhwHdB2dR0fjaD3nD4TSE77cAcAxPuFH4sIwMRp BxkQgiheU0Aujz8tuMgBlQa0mTAxcH36AoiUZNunt6Hjn+yHfS9TCMidfEwKWwA/thec 7KXxEDH35NRTXifIQ5XDUd6OHs74cwS8l0vR1PESv/EBd1VdntVN6uVaxiGTmv5hjpm6 VO0AB4M4XfsDaStYHBKpxEB+1bjPr0Fvanc6gCgKo4eSSLibHoLaTN7oRO188dEOHrMY D/XA== X-Gm-Message-State: AOAM5331byKz1hWPDlcWZQ2pxFp15iiOuOgXGmUNkiodTflEib40oEc0 2bJdAFbyOtGlHBfsPf3XNiYwaZKpLGeInidqw/U= X-Received: by 2002:a05:620a:2409:: with SMTP id d9mr57777749qkn.36.1594188104172; Tue, 07 Jul 2020 23:01:44 -0700 (PDT) MIME-Version: 1.0 References: <1593787468-29931-1-git-send-email-alan.maguire@oracle.com> <1593787468-29931-3-git-send-email-alan.maguire@oracle.com> In-Reply-To: <1593787468-29931-3-git-send-email-alan.maguire@oracle.com> From: Andrii Nakryiko Date: Tue, 7 Jul 2020 23:01:33 -0700 Message-ID: Subject: Re: [PATCH bpf-next 2/2] selftests/bpf: add selftests verifying bpf_trace_printk() behaviour To: Alan Maguire Cc: Steven Rostedt , Ingo Molnar , Alexei Starovoitov , Daniel Borkmann , Martin Lau , Song Liu , Yonghong Song , Andrii Nakryiko , john fastabend , KP Singh , open list , Networking , bpf 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 Fri, Jul 3, 2020 at 7:45 AM Alan Maguire wrote: > > Simple selftest that verifies bpf_trace_printk() returns a sensible > value and tracing messages appear. > > Signed-off-by: Alan Maguire > --- > .../selftests/bpf/prog_tests/trace_printk.c | 71 ++++++++++++++++++++++ > tools/testing/selftests/bpf/progs/trace_printk.c | 21 +++++++ > 2 files changed, 92 insertions(+) > create mode 100644 tools/testing/selftests/bpf/prog_tests/trace_printk.c > create mode 100644 tools/testing/selftests/bpf/progs/trace_printk.c > [...] > + fd = open(TRACEBUF, O_RDONLY); > + if (CHECK(fd < 0, "could not open trace buffer", > + "error %d opening %s", errno, TRACEBUF)) > + goto cleanup; > + > + /* We do not want to wait forever if this test fails... */ > + fcntl(fd, F_SETFL, O_NONBLOCK); > + > + /* wait for tracepoint to trigger */ > + sleep(1); that's a long sleep, it's better to use tp/raw_syscalls/sys_enter tracepoint to trigger BPF program and then just usleep(1) > + trace_printk__detach(skel); > + > + if (CHECK(bss->trace_printk_ran == 0, > + "bpf_trace_printk never ran", > + "ran == %d", bss->trace_printk_ran)) > + goto cleanup; > + [...] > + > +int trace_printk_ret = 0; > +int trace_printk_ran = 0; > + > +SEC("tracepoint/sched/sched_switch") see above, probably better to stick to something like tp/raw_syscalls/sys_enter or raw_tp/sys_enter. Also, to not overwhelm trace_pipe output, might want to filter by PID and emit messages for test_prog's PID only. > +int sched_switch(void *ctx) > +{ > + static const char fmt[] = "testing,testing %d\n"; > + > + trace_printk_ret = bpf_trace_printk(fmt, sizeof(fmt), > + ++trace_printk_ran); > + return 0; > +} > -- > 1.8.3.1 >