Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/bpf: Add a test for kprobe multi with unique_match

Add a kprobe multi subtest to test kprobe multi unique_match option.

Signed-off-by: Yonghong Song <yonghong.song@linux.dev>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20250109174028.3368967-1-yonghong.song@linux.dev

authored by

Yonghong Song and committed by
Andrii Nakryiko
a43796b5 e2b0bda6

+27
+27
tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c
··· 397 397 kprobe_multi_session_cookie__destroy(skel); 398 398 } 399 399 400 + static void test_unique_match(void) 401 + { 402 + LIBBPF_OPTS(bpf_kprobe_multi_opts, opts); 403 + struct kprobe_multi *skel = NULL; 404 + struct bpf_link *link = NULL; 405 + 406 + skel = kprobe_multi__open_and_load(); 407 + if (!ASSERT_OK_PTR(skel, "kprobe_multi__open_and_load")) 408 + return; 409 + 410 + opts.unique_match = true; 411 + skel->bss->pid = getpid(); 412 + link = bpf_program__attach_kprobe_multi_opts(skel->progs.test_kprobe_manual, 413 + "bpf_fentry_test*", &opts); 414 + if (!ASSERT_ERR_PTR(link, "bpf_program__attach_kprobe_multi_opts")) 415 + bpf_link__destroy(link); 416 + 417 + link = bpf_program__attach_kprobe_multi_opts(skel->progs.test_kprobe_manual, 418 + "bpf_fentry_test8*", &opts); 419 + if (ASSERT_OK_PTR(link, "bpf_program__attach_kprobe_multi_opts")) 420 + bpf_link__destroy(link); 421 + 422 + kprobe_multi__destroy(skel); 423 + } 424 + 400 425 static size_t symbol_hash(long key, void *ctx __maybe_unused) 401 426 { 402 427 return str_hash((const char *) key); ··· 790 765 test_session_skel_api(); 791 766 if (test__start_subtest("session_cookie")) 792 767 test_session_cookie_skel_api(); 768 + if (test__start_subtest("unique_match")) 769 + test_unique_match(); 793 770 RUN_TESTS(kprobe_multi_verifier); 794 771 }