mirror of
https://github.com/torvalds/linux.git
synced 2026-07-28 01:55:51 +02:00
selftests/bpf: Add tracing multi attach fails test
Adding tests for attach fails on tracing multi link. Signed-off-by: Jiri Olsa <jolsa@kernel.org> Link: https://lore.kernel.org/r/20260606123955.345967-27-jolsa@kernel.org Signed-off-by: Alexei Starovoitov <ast@kernel.org>
This commit is contained in:
parent
69f25d4b0c
commit
1fd8328549
|
|
@ -8,6 +8,7 @@
|
|||
#include "tracing_multi_module.skel.h"
|
||||
#include "tracing_multi_intersect.skel.h"
|
||||
#include "tracing_multi_session.skel.h"
|
||||
#include "tracing_multi_fail.skel.h"
|
||||
#include "trace_helpers.h"
|
||||
|
||||
static __u64 bpf_fentry_test_cookies[] = {
|
||||
|
|
@ -498,6 +499,99 @@ static void test_session(void)
|
|||
tracing_multi_session__destroy(skel);
|
||||
}
|
||||
|
||||
static void test_attach_api_fails(void)
|
||||
{
|
||||
LIBBPF_OPTS(bpf_tracing_multi_opts, opts);
|
||||
static const char * const func[] = {
|
||||
"bpf_fentry_test2",
|
||||
};
|
||||
struct tracing_multi_fail *skel = NULL;
|
||||
__u32 ids[2] = {}, *ids2 = NULL;
|
||||
__u64 cookies[2];
|
||||
|
||||
skel = tracing_multi_fail__open_and_load();
|
||||
if (!ASSERT_OK_PTR(skel, "tracing_multi_fail__open_and_load"))
|
||||
return;
|
||||
|
||||
/* fail#1 (libbpf) pattern and opts NULL */
|
||||
skel->links.test_fentry = bpf_program__attach_tracing_multi(skel->progs.test_fentry,
|
||||
NULL, NULL);
|
||||
if (!ASSERT_EQ(libbpf_get_error(skel->links.test_fentry), -EINVAL, "fail_1"))
|
||||
goto cleanup;
|
||||
|
||||
/* fail#2 (libbpf) pattern and ids */
|
||||
LIBBPF_OPTS_RESET(opts,
|
||||
.ids = ids,
|
||||
.cnt = 2,
|
||||
);
|
||||
|
||||
skel->links.test_fentry = bpf_program__attach_tracing_multi(skel->progs.test_fentry,
|
||||
"bpf_fentry_test*", &opts);
|
||||
if (!ASSERT_EQ(libbpf_get_error(skel->links.test_fentry), -EINVAL, "fail_2"))
|
||||
goto cleanup;
|
||||
|
||||
/* fail#3 (libbpf) pattern and cookies */
|
||||
LIBBPF_OPTS_RESET(opts,
|
||||
.ids = NULL,
|
||||
.cnt = 2,
|
||||
.cookies = cookies,
|
||||
);
|
||||
|
||||
skel->links.test_fentry = bpf_program__attach_tracing_multi(skel->progs.test_fentry,
|
||||
"bpf_fentry_test*", &opts);
|
||||
if (!ASSERT_EQ(libbpf_get_error(skel->links.test_fentry), -EINVAL, "fail_3"))
|
||||
goto cleanup;
|
||||
|
||||
/* fail#4 (libbpf) bogus pattern */
|
||||
skel->links.test_fentry = bpf_program__attach_tracing_multi(skel->progs.test_fentry,
|
||||
"bpf_not_really_a_function*", NULL);
|
||||
if (!ASSERT_EQ(libbpf_get_error(skel->links.test_fentry), -EINVAL, "fail_4"))
|
||||
goto cleanup;
|
||||
|
||||
/* fail#5 (kernel) abnormal cnt */
|
||||
LIBBPF_OPTS_RESET(opts,
|
||||
.ids = ids,
|
||||
.cnt = INT_MAX,
|
||||
);
|
||||
|
||||
skel->links.test_fentry = bpf_program__attach_tracing_multi(skel->progs.test_fentry,
|
||||
NULL, &opts);
|
||||
if (!ASSERT_EQ(libbpf_get_error(skel->links.test_fentry), -E2BIG, "fail_5"))
|
||||
goto cleanup;
|
||||
|
||||
/* fail#6 (kernel) attach sleepable program to not-allowed function */
|
||||
ids2 = get_ids(func, 1, NULL);
|
||||
if (!ASSERT_OK_PTR(ids2, "get_ids"))
|
||||
goto cleanup;
|
||||
|
||||
LIBBPF_OPTS_RESET(opts,
|
||||
.ids = ids2,
|
||||
.cnt = 1,
|
||||
);
|
||||
|
||||
skel->links.test_fentry_s = bpf_program__attach_tracing_multi(skel->progs.test_fentry_s,
|
||||
NULL, &opts);
|
||||
if (!ASSERT_EQ(libbpf_get_error(skel->links.test_fentry_s), -EINVAL, "fail_6"))
|
||||
goto cleanup;
|
||||
|
||||
/* fail#7 (kernel) attach with duplicate id */
|
||||
ids[0] = ids2[0];
|
||||
ids[1] = ids2[0];
|
||||
|
||||
LIBBPF_OPTS_RESET(opts,
|
||||
.ids = ids,
|
||||
.cnt = 2,
|
||||
);
|
||||
|
||||
skel->links.test_fentry = bpf_program__attach_tracing_multi(skel->progs.test_fentry,
|
||||
NULL, &opts);
|
||||
ASSERT_EQ(libbpf_get_error(skel->links.test_fentry), -EINVAL, "fail_7");
|
||||
|
||||
cleanup:
|
||||
tracing_multi_fail__destroy(skel);
|
||||
free(ids2);
|
||||
}
|
||||
|
||||
void test_tracing_multi_test(void)
|
||||
{
|
||||
#ifndef __x86_64__
|
||||
|
|
@ -523,4 +617,6 @@ void test_tracing_multi_test(void)
|
|||
test_link_api_ids(true);
|
||||
if (test__start_subtest("session"))
|
||||
test_session();
|
||||
if (test__start_subtest("attach_api_fails"))
|
||||
test_attach_api_fails();
|
||||
}
|
||||
|
|
|
|||
18
tools/testing/selftests/bpf/progs/tracing_multi_fail.c
Normal file
18
tools/testing/selftests/bpf/progs/tracing_multi_fail.c
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
// SPDX-License-Identifier: GPL-2.0
|
||||
#include <vmlinux.h>
|
||||
#include <bpf/bpf_helpers.h>
|
||||
#include <bpf/bpf_tracing.h>
|
||||
|
||||
char _license[] SEC("license") = "GPL";
|
||||
|
||||
SEC("fentry.multi")
|
||||
int BPF_PROG(test_fentry)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
SEC("fentry.multi.s")
|
||||
int BPF_PROG(test_fentry_s)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user