selftests/bpf: Add read_trace_pipe_iter function
authorJiri Olsa <jolsa@kernel.org>
Wed, 10 Apr 2024 14:09:52 +0000 (16:09 +0200)
committerDaniel Borkmann <daniel@iogearbox.net>
Fri, 12 Apr 2024 16:25:21 +0000 (18:25 +0200)
commit4d4992ff587604455e8843a0e76dce0b99175319
treeb6bc29b0220753ef4eaa63910d935df69e0373cd
parent23cc4fe44f1df5ccce088a7c9398f96794047c2a
selftests/bpf: Add read_trace_pipe_iter function

We have two printk tests reading trace_pipe in non blocking way,
with the very same code. Moving that in new read_trace_pipe_iter
function.

Current read_trace_pipe is used from samples/bpf and needs to
do blocking read and printf of the trace_pipe data, using new
read_trace_pipe_iter to implement that.

Both printk tests do early checks for the number of found messages
and can bail earlier, but I did not find any speed difference w/o
that condition, so I did not complicate the change more for that.

Some of the samples/bpf programs use read_trace_pipe function,
so I kept that interface untouched. I did not see any issues with
affected samples/bpf programs other than there's slight change in
read_trace_pipe output. The current code uses puts that adds new
line after the printed string, so we would occasionally see extra
new line. With this patch we read output per lines, so there's no
need to use puts and we can use just printf instead without extra
new line.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Yonghong Song <yonghong.song@linux.dev>
Link: https://lore.kernel.org/bpf/20240410140952.292261-1-jolsa@kernel.org
tools/testing/selftests/bpf/prog_tests/trace_printk.c
tools/testing/selftests/bpf/prog_tests/trace_vprintk.c
tools/testing/selftests/bpf/trace_helpers.c
tools/testing/selftests/bpf/trace_helpers.h