[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAEf4BzZmNFUBdSzCLiiQ-anQRmnzd-E1qa0wVdXHu0pYV_-=Nw@mail.gmail.com>
Date: Thu, 18 Jun 2020 21:44:23 -0700
From: Andrii Nakryiko <andrii.nakryiko@...il.com>
To: Jiri Olsa <jolsa@...nel.org>
Cc: Alexei Starovoitov <ast@...nel.org>,
Daniel Borkmann <daniel@...earbox.net>,
Wenbo Zhang <ethercflow@...il.com>,
Networking <netdev@...r.kernel.org>, bpf <bpf@...r.kernel.org>,
Song Liu <songliubraving@...com>, Yonghong Song <yhs@...com>,
Martin KaFai Lau <kafai@...com>,
David Miller <davem@...hat.com>,
John Fastabend <john.fastabend@...il.com>,
KP Singh <kpsingh@...omium.org>,
Andrii Nakryiko <andriin@...com>,
Brendan Gregg <bgregg@...flix.com>,
Florent Revest <revest@...omium.org>,
Al Viro <viro@...iv.linux.org.uk>
Subject: Re: [PATCH 11/11] selftests/bpf: Add test for d_path helper
On Tue, Jun 16, 2020 at 3:07 AM Jiri Olsa <jolsa@...nel.org> wrote:
>
> Adding test for d_path helper which is pretty much
> copied from Wenbo Zhang's test for bpf_get_fd_path,
> which never made it in.
>
> I've failed so far to compile the test with <linux/fs.h>
> kernel header, so for now adding 'struct file' with f_path
> member that has same offset as kernel's file object.
>
> Original-patch-by: Wenbo Zhang <ethercflow@...il.com>
> Signed-off-by: Jiri Olsa <jolsa@...nel.org>
> ---
> .../testing/selftests/bpf/prog_tests/d_path.c | 153 ++++++++++++++++++
> .../testing/selftests/bpf/progs/test_d_path.c | 55 +++++++
> 2 files changed, 208 insertions(+)
> create mode 100644 tools/testing/selftests/bpf/prog_tests/d_path.c
> create mode 100644 tools/testing/selftests/bpf/progs/test_d_path.c
>
> diff --git a/tools/testing/selftests/bpf/prog_tests/d_path.c b/tools/testing/selftests/bpf/prog_tests/d_path.c
> new file mode 100644
> index 000000000000..e2b7dfeb506f
> --- /dev/null
> +++ b/tools/testing/selftests/bpf/prog_tests/d_path.c
> @@ -0,0 +1,153 @@
> +// SPDX-License-Identifier: GPL-2.0
> +#define _GNU_SOURCE
> +#include <test_progs.h>
> +#include <sys/stat.h>
> +#include <linux/sched.h>
> +#include <sys/syscall.h>
> +
> +#define MAX_PATH_LEN 128
> +#define MAX_FILES 7
> +#define MAX_EVENT_NUM 16
> +
> +struct d_path_test_data {
> + pid_t pid;
> + __u32 cnt_stat;
> + __u32 cnt_close;
> + char paths_stat[MAX_EVENT_NUM][MAX_PATH_LEN];
> + char paths_close[MAX_EVENT_NUM][MAX_PATH_LEN];
> +};
with skeleton there is no point in defining this container struct, and
especially duplicating it between BPF code and user-space code. Just
declare all those fields as global variables and access them from
skeleton directly.
[...]
> diff --git a/tools/testing/selftests/bpf/progs/test_d_path.c b/tools/testing/selftests/bpf/progs/test_d_path.c
> new file mode 100644
> index 000000000000..1b478c00ee7a
> --- /dev/null
> +++ b/tools/testing/selftests/bpf/progs/test_d_path.c
> @@ -0,0 +1,55 @@
> +// SPDX-License-Identifier: GPL-2.0
> +
> +#include "vmlinux.h"
> +#include <bpf/bpf_helpers.h>
> +#include <bpf/bpf_tracing.h>
> +
> +#define MAX_PATH_LEN 128
> +#define MAX_EVENT_NUM 16
> +
> +static struct d_path_test_data {
> + pid_t pid;
> + __u32 cnt_stat;
> + __u32 cnt_close;
> + char paths_stat[MAX_EVENT_NUM][MAX_PATH_LEN];
> + char paths_close[MAX_EVENT_NUM][MAX_PATH_LEN];
> +} data;
> +
> +struct path;
> +struct kstat;
both structs are in vmlinux.h, you shouldn't need this.
[...]
>
Powered by blists - more mailing lists