Re: [RFC PATCH v3 2/3] bpf: Add selftests
From: Hou Tao <hidden>
Date: 2021-11-04 06:32:48
Also in:
bpf, lkml
Hi, On 11/2/2021 10:14 AM, Joe Burton wrote:
From: Joe Burton <redacted> Add selftests verifying that each supported map type is traced. Signed-off-by: Joe Burton <redacted> --- .../selftests/bpf/prog_tests/map_trace.c | 166 ++++++++++++++++++ .../selftests/bpf/progs/bpf_map_trace.c | 95 ++++++++++ .../bpf/progs/bpf_map_trace_common.h | 12 ++ 3 files changed, 273 insertions(+) create mode 100644 tools/testing/selftests/bpf/prog_tests/map_trace.c create mode 100644 tools/testing/selftests/bpf/progs/bpf_map_trace.c create mode 100644 tools/testing/selftests/bpf/progs/bpf_map_trace_common.h
snip
+ /*
+ * Invoke core BPF program.
+ */
+ write_fd = open("/tmp/map_trace_test_file", O_CREAT | O_WRONLY);
+ if (!ASSERT_GE(rc, 0, "open tmp file for writing"))
+ goto out;
+
+ bytes_written = write(write_fd, &write_buf, sizeof(write_buf));
+ if (!ASSERT_EQ(bytes_written, sizeof(write_buf), "write to tmp file"))
+ return;In fentry__x64_sys_write(), you just do trigger updates to maps, so for the portability of the test (e.g. run-able for arm64) and minimal dependency (e.g. don't depends on /tmp), why do you using nanosleep() and replacing fentry_x64_sys_write by tp/syscalls/sys_enter_nanosleep instead. Also it will be better if you can filter out other processes by pid. Thanks, Tao