Skip to contentSkip to conversation

selftests/bpf: test for bpf_get_file_path() from raw tracepoint

PATCH Superseded Wenbo Zhang 2 participants 3 messages Nov 1, 2019 – Nov 3, 2019

Subsystems (5)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 selftests/bpf: test for bpf_get_file_path() from raw tracepoint

trace fstat events by raw tracepoint sys_enter:newfstat, and handle events only produced by fd2path_loadgen, the fd2path_loadgen call fstat on several different types of files to test bpf_get_file_path's feature.

---
 tools/testing/selftests/bpf/Makefile          |   8 +-
 tools/testing/selftests/bpf/fd2path_loadgen.c |  75 ++++++++++
 .../selftests/bpf/prog_tests/get_file_path.c  | 130 ++++++++++++++++++
 .../selftests/bpf/progs/test_get_file_path.c  |  58 ++++++++
 4 files changed, 269 insertions(+), 2 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/fd2path_loadgen.c
 create mode 100644 tools/testing/selftests/bpf/prog_tests/get_file_path.c
 create mode 100644 tools/testing/selftests/bpf/progs/test_get_file_path.c
tools/testing/selftests/bpf/Makefile +6 -2
index b334a6db15c1..6c7e5cabc4e6 100644
@@ -72,7 +72,7 @@ TEST_GEN_PROGS_EXTENDED = test_sock_addr test_skb_cgroup_id_user \
 	flow_dissector_load test_flow_dissector test_tcp_check_syncookie_user \
 	test_lirc_mode2_user
 
-TEST_CUSTOM_PROGS = urandom_read
+TEST_CUSTOM_PROGS = urandom_read fd2path_loadgen
 
 include ../lib.mk
 
@@ -92,6 +92,9 @@ $(OUTPUT)/urandom_read: urandom_read.c
 $(OUTPUT)/test_stub.o: test_stub.c
 	$(CC) -c $(CFLAGS) -o $@ $<
 
+$(OUTPUT)/fd2path_loadgen: fd2path_loadgen.c
+	$(CC) -o $@ $< -Wl,--build-id
+
 BPFOBJ := $(OUTPUT)/libbpf.a
 
 $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED): $(OUTPUT)/test_stub.o $(BPFOBJ)
@@ -266,7 +269,8 @@ TRUNNER_TESTS_DIR := prog_tests
 TRUNNER_BPF_PROGS_DIR := progs
 TRUNNER_EXTRA_SOURCES := test_progs.c cgroup_helpers.c trace_helpers.c	\
 			 flow_dissector_load.h
-TRUNNER_EXTRA_FILES := $(OUTPUT)/urandom_read				\
+TRUNNER_EXTRA_FILES := $(OUTPUT)/urandom_read 				\
+		       $(OUTPUT)/fd2path_loadgen                        \
 		       $(wildcard progs/btf_dump_test_case_*.c)
 TRUNNER_BPF_BUILD_RULE := CLANG_BPF_BUILD_RULE
 TRUNNER_BPF_CFLAGS := -I. -I$(OUTPUT) $(BPF_CFLAGS) $(CLANG_CFLAGS)
tools/testing/selftests/bpf/fd2path_loadgen.c new file +75 -0

75 lines not on this page · raw message

tools/testing/selftests/bpf/prog_tests/get_file_path.c new file +130 -0

130 lines not on this page · raw message

tools/testing/selftests/bpf/progs/test_get_file_path.c new file +58 -0

58 lines not on this page · raw message

Signature · 1 line
2.17.1
#1 lore raw
Quoted 5 lines · Wenbo Zhang

trace fstat events by raw tracepoint sys_enter:newfstat, and handle events only produced by fd2path_loadgen, the fd2path_loadgen call fstat on several different types of files to test bpf_get_file_path's feature.
---

Unless there is a real reason for all this complexity (in which case, please spell it out in commit or comments), I think this could be so much simpler.

- you don't have to use perf_buffer to pass data back, just use global data;
- you can add a filter for PID to only capture data triggered by test process and avoid the noise;
- why all those set_affinity dances? Is it just because you used existing perf_buffer test which did that to specifically test perf_buffer delivering data across every CPU core? Seems like your test doesn't care about that...
- do we really need a separate binary generating hundreds of syscalls? It's hard to synchronize with test and it seems much simpler to just trigger necessary syscalls synchronously from the test itself, no?

I have a bunch of more minutia nits, but most of them will go away if you simplify your testing approach anyway, so I'll postpone them till then.

Quoted 9 lines
 tools/testing/selftests/bpf/Makefile          |   8 +-
 tools/testing/selftests/bpf/fd2path_loadgen.c |  75 ++++++++++
 .../selftests/bpf/prog_tests/get_file_path.c  | 130 ++++++++++++++++++
 .../selftests/bpf/progs/test_get_file_path.c  |  58 ++++++++
 4 files changed, 269 insertions(+), 2 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/fd2path_loadgen.c
 create mode 100644 tools/testing/selftests/bpf/prog_tests/get_file_path.c
 create mode 100644 tools/testing/selftests/bpf/progs/test_get_file_path.c

[...]

#2 lore raw
Quoted 3 lines

Unless there is a real reason for all this complexity (in which case, please spell it out in commit or comments), I think this could be so much simpler.

Yes, it could be so much simpler than this implement.

Quoted 3 lines

- you don't have to use perf_buffer to pass data back, just use global data;
- you can add a filter for PID to only capture data triggered by test process and avoid the noise;

Yes, I'll use map instead of perf buffer to communicate.

Quoted 4 lines

- why all those set_affinity dances? Is it just because you used existing perf_buffer test which did that to specifically test perf_buffer delivering data across every CPU core? Seems like your test doesn't care about that...

I used fd2path_loadgen to get hundreds of syscalls between multi usleep, which may cause it's sched to different cores, but as you say, this test doesn't care about
that... I'll remove them with perf buffer.

Quoted 3 lines

- do we really need a separate binary generating hundreds of syscalls? It's hard to synchronize with test and it seems much simpler to just trigger necessary syscalls synchronously from the test itself, no?

This is my fault, necessary syscalls synchronously from the test itself is enough.

Quoted 3 lines

I have a bunch of more minutia nits, but most of them will go away if you simplify your testing approach anyway, so I'll postpone them till then.

Thanks a lot. I'll modify a simplified version then recommitted.

Quoted 38 lines · Andrii Nakryiko <[email protected]> 于2019年11月2日周六 下午1:49写道:
Quoted 5 lines · Wenbo Zhang

trace fstat events by raw tracepoint sys_enter:newfstat, and handle events only produced by fd2path_loadgen, the fd2path_loadgen call fstat on several different types of files to test bpf_get_file_path's feature.
---

Unless there is a real reason for all this complexity (in which case, please spell it out in commit or comments), I think this could be so much simpler.

- you don't have to use perf_buffer to pass data back, just use global data;
- you can add a filter for PID to only capture data triggered by test process and avoid the noise;
- why all those set_affinity dances? Is it just because you used existing perf_buffer test which did that to specifically test perf_buffer delivering data across every CPU core? Seems like your test doesn't care about that...
- do we really need a separate binary generating hundreds of syscalls? It's hard to synchronize with test and it seems much simpler to just trigger necessary syscalls synchronously from the test itself, no?

I have a bunch of more minutia nits, but most of them will go away if you simplify your testing approach anyway, so I'll postpone them till then.

Quoted 9 lines
 tools/testing/selftests/bpf/Makefile          |   8 +-
 tools/testing/selftests/bpf/fd2path_loadgen.c |  75 ++++++++++
 .../selftests/bpf/prog_tests/get_file_path.c  | 130 ++++++++++++++++++
 .../selftests/bpf/progs/test_get_file_path.c  |  58 ++++++++
 4 files changed, 269 insertions(+), 2 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/fd2path_loadgen.c
 create mode 100644 tools/testing/selftests/bpf/prog_tests/get_file_path.c
 create mode 100644 tools/testing/selftests/bpf/progs/test_get_file_path.c

[...]