As part of the cleanup of outdated test cases in sample/bpf, this commit migrates test for tracepoint overhead to selftest prog_tests. The test_overhead in selftest/bpf focus on the 'raw_tracepoint' only, and do not cover tracepoint-specific tests. To support this, this commit utilize 'vmlinux.h', and additional test program for tracepoint has been added. Signed-off-by: Daniel T. Lee <danieltimlee@xxxxxxxxx> --- .../selftests/bpf/prog_tests/test_overhead.c | 14 +++++++++++++- tools/testing/selftests/bpf/progs/test_overhead.c | 11 +++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/test_overhead.c b/tools/testing/selftests/bpf/prog_tests/test_overhead.c index f27013e38d03..06153602a859 100644 --- a/tools/testing/selftests/bpf/prog_tests/test_overhead.c +++ b/tools/testing/selftests/bpf/prog_tests/test_overhead.c @@ -61,9 +61,10 @@ void test_test_overhead(void) const char *raw_tp_name = "prog3"; const char *fentry_name = "prog4"; const char *fexit_name = "prog5"; + const char *tp_name = "prog6"; const char *kprobe_func = "__set_task_comm"; struct bpf_program *kprobe_prog, *kretprobe_prog, *raw_tp_prog; - struct bpf_program *fentry_prog, *fexit_prog; + struct bpf_program *fentry_prog, *fexit_prog, *tp_prog; struct bpf_object *obj; struct bpf_link *link; int err, duration = 0; @@ -96,6 +97,10 @@ void test_test_overhead(void) if (CHECK(!fexit_prog, "find_probe", "prog '%s' not found\n", fexit_name)) goto cleanup; + tp_prog = bpf_object__find_program_by_name(obj, tp_name); + if (CHECK(!tp_prog, "find_probe", + "prog '%s' not found\n", tp_name)) + goto cleanup; err = bpf_object__load(obj); if (CHECK(err, "obj_load", "err %d\n", err)) goto cleanup; @@ -142,6 +147,13 @@ void test_test_overhead(void) test_run("fexit"); bpf_link__destroy(link); + /* attach tp */ + link = bpf_program__attach_tracepoint(tp_prog, "task", "task_rename"); + if (!ASSERT_OK_PTR(link, "attach_tp")) + goto cleanup; + test_run("tp"); + bpf_link__destroy(link); + cleanup: prctl(PR_SET_NAME, comm, 0L, 0L, 0L); bpf_object__close(obj); diff --git a/tools/testing/selftests/bpf/progs/test_overhead.c b/tools/testing/selftests/bpf/progs/test_overhead.c index abb7344b531f..6dc1f68180e0 100644 --- a/tools/testing/selftests/bpf/progs/test_overhead.c +++ b/tools/testing/selftests/bpf/progs/test_overhead.c @@ -1,9 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 /* Copyright (c) 2019 Facebook */ -#include <stdbool.h> -#include <stddef.h> -#include <linux/bpf.h> -#include <linux/ptrace.h> +#include "vmlinux.h" #include <bpf/bpf_helpers.h> #include <bpf/bpf_tracing.h> @@ -39,4 +36,10 @@ int BPF_PROG(prog5, struct task_struct *tsk, const char *buf, bool exec) return 0; } +SEC("tracepoint/task/task_rename") +int prog6(struct trace_event_raw_task_rename *ctx) +{ + return 0; +} + char _license[] SEC("license") = "GPL"; -- 2.43.0