Re: [PATCH bpf-next v3 2/2] selftests/bpf: use canonical ftrace path

From: Ross Zwisler
Date: Mon Mar 13 2023 - 16:41:39 EST


On Fri, Mar 10, 2023 at 06:33:52PM -0500, Steven Rostedt wrote:
> On Fri, 10 Mar 2023 10:52:09 -0700
> zwisler@xxxxxxxxxx wrote:
>
> > diff --git a/tools/testing/selftests/bpf/get_cgroup_id_user.c b/tools/testing/selftests/bpf/get_cgroup_id_user.c
> > index 156743cf5870..4fa61ac8a0ee 100644
> > --- a/tools/testing/selftests/bpf/get_cgroup_id_user.c
> > +++ b/tools/testing/selftests/bpf/get_cgroup_id_user.c
> > @@ -86,8 +86,12 @@ int main(int argc, char **argv)
> > pid = getpid();
> > bpf_map_update_elem(pidmap_fd, &key, &pid, 0);
> >
> > - snprintf(buf, sizeof(buf),
> > - "/sys/kernel/debug/tracing/events/%s/id", probe_name);
> > + if (access("/sys/kernel/tracing/trace", F_OK) == 0)
> > + snprintf(buf, sizeof(buf),
> > + "/sys/kernel/tracing/events/%s/id", probe_name);
> > + else
> > + snprintf(buf, sizeof(buf),
> > + "/sys/kernel/debug/tracing/events/%s/id", probe_name);
>
> I don't know how the BPF folks feel, but I do know some kernel developers
> prefer that if you need to break a single command into multiple lines that
> you then need to add brackets around it. As it makes it easier to read.
>
> if (access("/sys/kernel/tracing/trace", F_OK) == 0) {
> snprintf(buf, sizeof(buf),
> "/sys/kernel/tracing/events/%s/id", probe_name);
> } else {
> snprintf(buf, sizeof(buf),
> "/sys/kernel/debug/tracing/events/%s/id", probe_name);
> }
>
>
>
> > efd = open(buf, O_RDONLY, 0);
> > if (CHECK(efd < 0, "open", "err %d errno %d\n", efd, errno))
> > goto close_prog;
> > diff --git a/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c b/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c
> > index 113dba349a57..22be0a9a5a0a 100644
> > --- a/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c
> > +++ b/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c
> > @@ -338,7 +338,12 @@ static int get_syms(char ***symsp, size_t *cntp, bool kernel)
> > * Filtering out duplicates by using hashmap__add, which won't
> > * add existing entry.
> > */
> > - f = fopen("/sys/kernel/debug/tracing/available_filter_functions", "r");
> > +
> > + if (access("/sys/kernel/tracing/trace", F_OK) == 0)
> > + f = fopen("/sys/kernel/tracing/available_filter_functions", "r");
> > + else
> > + f = fopen("/sys/kernel/debug/tracing/available_filter_functions", "r");
> > +
> > if (!f)
> > return -EINVAL;
> >
> > diff --git a/tools/testing/selftests/bpf/prog_tests/task_fd_query_tp.c b/tools/testing/selftests/bpf/prog_tests/task_fd_query_tp.c
> > index c717741bf8b6..60f92fd3c37a 100644
> > --- a/tools/testing/selftests/bpf/prog_tests/task_fd_query_tp.c
> > +++ b/tools/testing/selftests/bpf/prog_tests/task_fd_query_tp.c
> > @@ -17,8 +17,12 @@ static void test_task_fd_query_tp_core(const char *probe_name,
> > if (CHECK(err, "bpf_prog_test_load", "err %d errno %d\n", err, errno))
> > goto close_prog;
> >
> > - snprintf(buf, sizeof(buf),
> > - "/sys/kernel/debug/tracing/events/%s/id", probe_name);
> > + if (access("/sys/kernel/tracing/trace", F_OK) == 0)
> > + snprintf(buf, sizeof(buf),
> > + "/sys/kernel/tracing/events/%s/id", probe_name);
> > + else
> > + snprintf(buf, sizeof(buf),
> > + "/sys/kernel/debug/tracing/events/%s/id", probe_name);
>
> Same here.
>
> > efd = open(buf, O_RDONLY, 0);
> > if (CHECK(efd < 0, "open", "err %d errno %d\n", efd, errno))
> > goto close_prog;
> > diff --git a/tools/testing/selftests/bpf/prog_tests/tp_attach_query.c b/tools/testing/selftests/bpf/prog_tests/tp_attach_query.c
> > index 770fcc3bb1ba..d3e377fa8e9b 100644
> > --- a/tools/testing/selftests/bpf/prog_tests/tp_attach_query.c
> > +++ b/tools/testing/selftests/bpf/prog_tests/tp_attach_query.c
> > @@ -16,8 +16,12 @@ void serial_test_tp_attach_query(void)
> > for (i = 0; i < num_progs; i++)
> > obj[i] = NULL;
> >
> > - snprintf(buf, sizeof(buf),
> > - "/sys/kernel/debug/tracing/events/sched/sched_switch/id");
> > + if (access("/sys/kernel/tracing/trace", F_OK) == 0)
> > + snprintf(buf, sizeof(buf),
> > + "/sys/kernel/tracing/events/sched/sched_switch/id");
> > + else
> > + snprintf(buf, sizeof(buf),
> > + "/sys/kernel/debug/tracing/events/sched/sched_switch/id");
>
> and here.
>
> But perhaps the BPF folks don't care?

Sure, I agree that this is more readable. I'll gather your Reviewed-by for
patch #1, make this change, rebase to the current bpf/bpf-next and send out
v4.