Skip to content

Commit ccdb726

Browse files
chentao-kernelKernel Patches Daemon
authored andcommitted
selftests/bpf: Add libbpf_probe_bpf_kfunc API selftests
Add selftests for prog_kfunc feature probing. ./test_progs -t libbpf_probe_kfuncs #153 libbpf_probe_kfuncs:OK Summary: 1/0 PASSED, 0 SKIPPED, 0 FAILED Signed-off-by: Tao Chen <[email protected]>
1 parent 5e57d97 commit ccdb726

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

tools/testing/selftests/bpf/prog_tests/libbpf_probes.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,38 @@ void test_libbpf_probe_helpers(void)
126126
ASSERT_EQ(res, d->supported, buf);
127127
}
128128
}
129+
130+
void test_libbpf_probe_kfuncs(void)
131+
{
132+
int ret, kfunc_id;
133+
char *kfunc = "bpf_cpumask_create";
134+
struct btf *btf;
135+
136+
btf = btf__parse("/sys/kernel/btf/vmlinux", NULL);
137+
if (!ASSERT_OK_PTR(btf, "btf_parse"))
138+
return;
139+
140+
kfunc_id = btf__find_by_name_kind(btf, kfunc, BTF_KIND_FUNC);
141+
if (!ASSERT_GT(kfunc_id, 0, kfunc))
142+
goto cleanup;
143+
144+
/* prog BPF_PROG_TYPE_SYSCALL supports kfunc bpf_cpumask_create */
145+
ret = libbpf_probe_bpf_kfunc(BPF_PROG_TYPE_SYSCALL, kfunc_id, 0, NULL);
146+
ASSERT_EQ(ret, 1, kfunc);
147+
148+
/* prog BPF_PROG_TYPE_KPROBE does not support kfunc bpf_cpumask_create */
149+
ret = libbpf_probe_bpf_kfunc(BPF_PROG_TYPE_KPROBE, kfunc_id, 0, NULL);
150+
ASSERT_EQ(ret, 0, kfunc);
151+
152+
/* invalid kfunc id */
153+
ret = libbpf_probe_bpf_kfunc(BPF_PROG_TYPE_KPROBE, -1, 0, NULL);
154+
ASSERT_EQ(ret, 0, "invalid kfunc id:-1");
155+
156+
/* invalid prog type */
157+
ret = libbpf_probe_bpf_kfunc(100000, kfunc_id, 0, NULL);
158+
if (!ASSERT_LE(ret, 0, "invalid prog type:100000"))
159+
goto cleanup;
160+
161+
cleanup:
162+
btf__free(btf);
163+
}

0 commit comments

Comments
 (0)