Commit 3490d299 authored by Jiri Olsa's avatar Jiri Olsa Committed by Alexei Starovoitov
Browse files

selftests/bpf: Add stacktrace ips test for raw_tp



Adding test that verifies we get expected initial 2 entries from
stacktrace for rawtp probe via ORC unwind.

Signed-off-by: default avatarJiri Olsa <jolsa@kernel.org>
Link: https://lore.kernel.org/r/20251104215405.168643-5-jolsa@kernel.org


Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
Acked-by: default avatarSteven Rostedt (Google) <rostedt@goodmis.org>
parent c9e208fa
Loading
Loading
Loading
Loading
+46 −0
Original line number Diff line number Diff line
@@ -84,12 +84,58 @@ static void test_stacktrace_ips_kprobe_multi(bool retprobe)
	stacktrace_ips__destroy(skel);
}

static void test_stacktrace_ips_raw_tp(void)
{
	__u32 info_len = sizeof(struct bpf_prog_info);
	LIBBPF_OPTS(bpf_test_run_opts, topts);
	struct bpf_prog_info info = {};
	struct stacktrace_ips *skel;
	__u64 bpf_prog_ksym = 0;
	int err;

	skel = stacktrace_ips__open_and_load();
	if (!ASSERT_OK_PTR(skel, "stacktrace_ips__open_and_load"))
		return;

	if (!skel->kconfig->CONFIG_UNWINDER_ORC) {
		test__skip();
		goto cleanup;
	}

	skel->links.rawtp_test = bpf_program__attach_raw_tracepoint(
							skel->progs.rawtp_test,
							"bpf_testmod_test_read");
	if (!ASSERT_OK_PTR(skel->links.rawtp_test, "bpf_program__attach_raw_tracepoint"))
		goto cleanup;

	/* get bpf program address */
	info.jited_ksyms = ptr_to_u64(&bpf_prog_ksym);
	info.nr_jited_ksyms = 1;
	err = bpf_prog_get_info_by_fd(bpf_program__fd(skel->progs.rawtp_test),
				      &info, &info_len);
	if (!ASSERT_OK(err, "bpf_prog_get_info_by_fd"))
		goto cleanup;

	trigger_module_test_read(1);

	load_kallsyms();

	check_stacktrace_ips(bpf_map__fd(skel->maps.stackmap), skel->bss->stack_key, 2,
			     bpf_prog_ksym,
			     ksym_get_addr("bpf_trace_run2"));

cleanup:
	stacktrace_ips__destroy(skel);
}

static void __test_stacktrace_ips(void)
{
	if (test__start_subtest("kprobe_multi"))
		test_stacktrace_ips_kprobe_multi(false);
	if (test__start_subtest("kretprobe_multi"))
		test_stacktrace_ips_kprobe_multi(true);
	if (test__start_subtest("raw_tp"))
		test_stacktrace_ips_raw_tp();
}
#else
static void __test_stacktrace_ips(void)
+8 −0
Original line number Diff line number Diff line
@@ -38,4 +38,12 @@ int kprobe_multi_test(struct pt_regs *ctx)
	return 0;
}

SEC("raw_tp/bpf_testmod_test_read")
int rawtp_test(void *ctx)
{
	/* Skip ebpf program entry in the stack. */
	stack_key = bpf_get_stackid(ctx, &stackmap, 0);
	return 0;
}

char _license[] SEC("license") = "GPL";