Skip to content

Commit a26c3c7

Browse files
committed
selftests/bpf: Add tracing multi session test
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
1 parent f348393 commit a26c3c7

File tree

3 files changed

+59
-1
lines changed

3 files changed

+59
-1
lines changed

tools/testing/selftests/bpf/Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,8 @@ LINKED_SKELS := test_static_linked.skel.h linked_funcs.skel.h \
482482
linked_vars.skel.h linked_maps.skel.h \
483483
test_subskeleton.skel.h test_subskeleton_lib.skel.h \
484484
test_usdt.skel.h tracing_multi.skel.h \
485-
tracing_multi_intersect.skel.h
485+
tracing_multi_intersect.skel.h \
486+
tracing_multi_session.skel.h
486487

487488
LSKELS := fexit_sleep.c trace_printk.c trace_vprintk.c map_ptr_kern.c \
488489
core_kern.c core_kern_overflow.c test_ringbuf.c \
@@ -510,6 +511,7 @@ xdp_hw_metadata.skel.h-deps := xdp_hw_metadata.bpf.o
510511
xdp_features.skel.h-deps := xdp_features.bpf.o
511512
tracing_multi.skel.h-deps := tracing_multi_attach.bpf.o tracing_multi_check.bpf.o
512513
tracing_multi_intersect.skel.h-deps := tracing_multi_intersect_attach.bpf.o tracing_multi_check.bpf.o
514+
tracing_multi_session.skel.h-deps := tracing_multi_session_attach.bpf.o tracing_multi_check.bpf.o
513515

514516
LINKED_BPF_OBJS := $(foreach skel,$(LINKED_SKELS),$($(skel)-deps))
515517
LINKED_BPF_SRCS := $(patsubst %.bpf.o,%.c,$(LINKED_BPF_OBJS))

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "bpf/libbpf_internal.h"
77
#include "tracing_multi.skel.h"
88
#include "tracing_multi_intersect.skel.h"
9+
#include "tracing_multi_session.skel.h"
910
#include "trace_helpers.h"
1011

1112
static __u64 bpf_fentry_test_cookies[] = {
@@ -288,6 +289,32 @@ static void test_intersect(void)
288289
tracing_multi_intersect__destroy(skel);
289290
}
290291

292+
static void test_session(void)
293+
{
294+
LIBBPF_OPTS(bpf_test_run_opts, topts);
295+
struct tracing_multi_session *skel;
296+
int err, prog_fd;
297+
298+
skel = tracing_multi_session__open_and_load();
299+
if (!ASSERT_OK_PTR(skel, "tracing_multi_session__open_and_load"))
300+
return;
301+
302+
err = tracing_multi_session__attach(skel);
303+
if (!ASSERT_OK(err, "tracing_multi_session__attach"))
304+
goto cleanup;
305+
306+
prog_fd = bpf_program__fd(skel->progs.test_session);
307+
err = bpf_prog_test_run_opts(prog_fd, &topts);
308+
ASSERT_OK(err, "test_run");
309+
310+
ASSERT_EQ(skel->bss->test_result_fentry, 10, "test_result_fentry");
311+
/* extra count for test_result_fexit cookie */
312+
ASSERT_EQ(skel->bss->test_result_fexit, 20, "test_result_fexit");
313+
314+
cleanup:
315+
tracing_multi_session__destroy(skel);
316+
}
317+
291318
void test_tracing_multi_test(void)
292319
{
293320
#ifndef __x86_64__
@@ -305,4 +332,6 @@ void test_tracing_multi_test(void)
305332
test_intersect();
306333
if (test__start_subtest("cookies"))
307334
test_link_api_ids(true);
335+
if (test__start_subtest("session"))
336+
test_session();
308337
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
#include <vmlinux.h>
3+
#include <bpf/bpf_helpers.h>
4+
#include <bpf/bpf_tracing.h>
5+
6+
char _license[] SEC("license") = "GPL";
7+
8+
__hidden extern int tracing_multi_arg_check(__u64 *ctx, __u64 *test_result, bool is_return);
9+
10+
__u64 test_result_fentry = 0;
11+
__u64 test_result_fexit = 0;
12+
13+
SEC("fsession.multi/bpf_fentry_test*")
14+
int BPF_PROG(test_session)
15+
{
16+
volatile __u64 *cookie = bpf_session_cookie(ctx);
17+
18+
if (bpf_session_is_return(ctx)) {
19+
tracing_multi_arg_check(ctx, &test_result_fexit, true);
20+
/* extra count for test_result_fexit cookie */
21+
test_result_fexit += *cookie == 0xbeafbeafbeafbeaf;
22+
} else {
23+
tracing_multi_arg_check(ctx, &test_result_fentry, false);
24+
*cookie = 0xbeafbeafbeafbeaf;
25+
}
26+
return 0;
27+
}

0 commit comments

Comments
 (0)