All of lore.kernel.org
 help / color / mirror / Atom feed
From: Song Liu <songliubraving@fb.com>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: Networking <netdev@vger.kernel.org>, bpf <bpf@vger.kernel.org>,
	"Kernel Team" <Kernel-team@fb.com>,
	Alexei Starovoitov <ast@kernel.org>,
	"Daniel Borkmann" <daniel@iogearbox.net>,
	john fastabend <john.fastabend@gmail.com>,
	KP Singh <kpsingh@chromium.org>
Subject: Re: [PATCH v2 bpf-next 3/3] selftests/bpf: add raw_tp_test_run
Date: Wed, 23 Sep 2020 21:30:21 +0000	[thread overview]
Message-ID: <F220CD52-C103-4E90-9B5B-504500984747@fb.com> (raw)
In-Reply-To: <CAEf4Bzb2KdA3m6-hfH96HxwCvPeOyNQ59LRm0rW8OWs+7zyMHQ@mail.gmail.com>



> On Sep 23, 2020, at 12:40 PM, Andrii Nakryiko <andrii.nakryiko@gmail.com> wrote:
> 
> On Wed, Sep 23, 2020 at 9:55 AM Song Liu <songliubraving@fb.com> wrote:
>> 
>> This test runs test_run for raw_tracepoint program. The test covers ctx
>> input, retval output, and proper handling of cpu_plus field.
>> 
>> Signed-off-by: Song Liu <songliubraving@fb.com>
>> ---
>> .../bpf/prog_tests/raw_tp_test_run.c          | 73 +++++++++++++++++++
>> .../bpf/progs/test_raw_tp_test_run.c          | 26 +++++++
>> 2 files changed, 99 insertions(+)
>> create mode 100644 tools/testing/selftests/bpf/prog_tests/raw_tp_test_run.c
>> create mode 100644 tools/testing/selftests/bpf/progs/test_raw_tp_test_run.c
>> 
>> diff --git a/tools/testing/selftests/bpf/prog_tests/raw_tp_test_run.c b/tools/testing/selftests/bpf/prog_tests/raw_tp_test_run.c
>> new file mode 100644
>> index 0000000000000..3c6523b61afc1
>> --- /dev/null
>> +++ b/tools/testing/selftests/bpf/prog_tests/raw_tp_test_run.c
>> @@ -0,0 +1,73 @@
>> +// SPDX-License-Identifier: GPL-2.0-only
>> +/* Copyright (c) 2019 Facebook */
>> +#include <test_progs.h>
>> +#include "bpf/libbpf_internal.h"
>> +#include "test_raw_tp_test_run.skel.h"
>> +
>> +static int duration;
>> +
>> +void test_raw_tp_test_run(void)
>> +{
>> +       struct bpf_prog_test_run_attr test_attr = {};
>> +       __u64 args[2] = {0x1234ULL, 0x5678ULL};
>> +       int comm_fd = -1, err, nr_online, i;
>> +       int expected_retval = 0x1234 + 0x5678;
>> +       struct test_raw_tp_test_run *skel;
>> +       char buf[] = "new_name";
>> +       bool *online = NULL;
>> +
>> +       err = parse_cpu_mask_file("/sys/devices/system/cpu/online", &online,
>> +                                 &nr_online);
>> +       if (CHECK(err, "parse_cpu_mask_file", "err %d\n", err))
>> +               return;
>> +
>> +       skel = test_raw_tp_test_run__open_and_load();
>> +       if (CHECK(!skel, "skel_open", "failed to open skeleton\n"))
>> +               return;
> 
> leaking memory here

Good catch! Fixing it in the next version. 

> 
>> +       err = test_raw_tp_test_run__attach(skel);
>> +       if (CHECK(err, "skel_attach", "skeleton attach failed: %d\n", err))
>> +               goto cleanup;
>> +
>> +       comm_fd = open("/proc/self/comm", O_WRONLY|O_TRUNC);
>> +       if (CHECK(comm_fd < 0, "open /proc/self/comm", "err %d\n", errno))
>> +               goto cleanup;
>> +
> 
> [...]
> 
>> +SEC("raw_tp/task_rename")
>> +int BPF_PROG(rename, struct task_struct *task, char *comm)
>> +{
>> +
>> +       count++;
>> +       if ((unsigned long long) task == 0x1234 &&
>> +           (unsigned long long) comm == 0x5678) {
> 
> you can use shorter __u64?

Sure. 

      reply	other threads:[~2020-09-23 21:30 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-23 16:53 [PATCH v2 bpf-next 0/3] enable BPF_PROG_TEST_RUN for raw_tp Song Liu
2020-09-23 16:53 ` [PATCH v2 bpf-next 1/3] bpf: enable BPF_PROG_TEST_RUN for raw_tracepoint Song Liu
2020-09-23 19:36   ` Andrii Nakryiko
2020-09-23 21:59     ` Song Liu
2020-09-23 16:54 ` [PATCH v2 bpf-next 2/3] libbpf: introduce bpf_prog_test_run_xattr_opts Song Liu
2020-09-23 19:31   ` Andrii Nakryiko
2020-09-23 22:04     ` Song Liu
2020-09-23 23:53     ` Song Liu
2020-09-24  1:11       ` Andrii Nakryiko
2020-09-24  1:20         ` Song Liu
2020-09-23 16:54 ` [PATCH v2 bpf-next 3/3] selftests/bpf: add raw_tp_test_run Song Liu
2020-09-23 19:40   ` Andrii Nakryiko
2020-09-23 21:30     ` Song Liu [this message]

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=F220CD52-C103-4E90-9B5B-504500984747@fb.com \
    --to=songliubraving@fb.com \
    --cc=Kernel-team@fb.com \
    --cc=andrii.nakryiko@gmail.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=john.fastabend@gmail.com \
    --cc=kpsingh@chromium.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.