lkml.org 
[lkml]   [2020]   [Jul]   [8]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: [PATCH bpf-next 2/2] selftests/bpf: add selftests verifying bpf_trace_printk() behaviour
On Fri, Jul 3, 2020 at 7:45 AM Alan Maguire <alan.maguire@oracle.com> wrote:
>
> Simple selftest that verifies bpf_trace_printk() returns a sensible
> value and tracing messages appear.
>
> Signed-off-by: Alan Maguire <alan.maguire@oracle.com>
> ---
> .../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
>

\
 
 \ /
  Last update: 2020-07-08 08:03    [W:0.067 / U:2.420 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site