Skip to content

Commit 23d4389

Browse files
image-dragonKernel Patches Daemon
authored andcommitted
selftests/bpf: add testcase for mixing fsession, fentry and fexit
Test the fsession when it is used together with fentry, fexit. Signed-off-by: Menglong Dong <[email protected]>
1 parent 9b0a614 commit 23d4389

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <test_progs.h>
44
#include "fsession_test.skel.h"
55
#include "fsession_cookie.skel.h"
6+
#include "fsession_mixed.skel.h"
67

78
static int check_result(struct fsession_test *skel)
89
{
@@ -114,6 +115,35 @@ static void test_fsession_cookie(void)
114115
fsession_cookie__destroy(skel);
115116
}
116117

118+
static void test_fsession_mixed(void)
119+
{
120+
LIBBPF_OPTS(bpf_test_run_opts, topts);
121+
struct fsession_mixed *skel = NULL;
122+
int err, prog_fd;
123+
124+
skel = fsession_mixed__open_and_load();
125+
if (!ASSERT_OK_PTR(skel, "fsession_mixed__open_and_load"))
126+
goto cleanup;
127+
128+
err = fsession_mixed__attach(skel);
129+
if (!ASSERT_OK(err, "fsession_mixed_attach"))
130+
goto cleanup;
131+
132+
prog_fd = bpf_program__fd(skel->progs.test1);
133+
err = bpf_prog_test_run_opts(prog_fd, &topts);
134+
if (!ASSERT_OK(err, "test_run_opts err"))
135+
goto cleanup;
136+
if (!ASSERT_OK(topts.retval, "test_run_opts retval"))
137+
goto cleanup;
138+
139+
for (int i = 0; i < sizeof(*skel->bss) / sizeof(__u64); i++) {
140+
if (!ASSERT_EQ(((__u64 *)skel->bss)[i], 1, "test_result"))
141+
goto cleanup;
142+
}
143+
cleanup:
144+
fsession_mixed__destroy(skel);
145+
}
146+
117147
void test_fsession_test(void)
118148
{
119149
#if !defined(__x86_64__)
@@ -126,4 +156,6 @@ void test_fsession_test(void)
126156
test_fsession_reattach();
127157
if (test__start_subtest("fsession_cookie"))
128158
test_fsession_cookie();
159+
if (test__start_subtest("fsession_mixed"))
160+
test_fsession_mixed();
129161
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/* Copyright (c) 2025 ChinaTelecom */
3+
#include <vmlinux.h>
4+
#include <bpf/bpf_helpers.h>
5+
#include <bpf/bpf_tracing.h>
6+
7+
char _license[] SEC("license") = "GPL";
8+
9+
__u64 test1_entry_result = 0;
10+
__u64 test1_exit_result = 0;
11+
12+
SEC("fsession/bpf_fentry_test5")
13+
int BPF_PROG(test1, __u64 a, void *b, short c, int d, __u64 e, int ret)
14+
{
15+
__u64 *cookie = bpf_fsession_cookie(ctx);
16+
17+
if (!bpf_tracing_is_exit(ctx)) {
18+
test1_entry_result = a == 11 && b == (void *)12 && c == 13 && d == 14 &&
19+
e == 15 && ret == 0;
20+
*cookie = 0x123456ULL;
21+
return 0;
22+
}
23+
24+
test1_exit_result = a == 11 && b == (void *)12 && c == 13 && d == 14 &&
25+
e == 15 && ret == 65 && *cookie == 0x123456ULL;
26+
return 0;
27+
}
28+
29+
__u64 test2_result = 0;
30+
SEC("fexit/bpf_fentry_test5")
31+
int BPF_PROG(test2, __u64 a, void *b, short c, int d, __u64 e, int ret)
32+
{
33+
test2_result = a == 11 && b == (void *)12 && c == 13 && d == 14 &&
34+
e == 15 && ret == 65;
35+
return 0;
36+
}
37+
38+
__u64 test3_result = 0;
39+
SEC("fentry/bpf_fentry_test5")
40+
int BPF_PROG(test3, __u64 a, void *b, short c, int d, __u64 e)
41+
{
42+
test3_result = a == 11 && b == (void *)12 && c == 13 && d == 14 &&
43+
e == 15;
44+
return 0;
45+
}

0 commit comments

Comments
 (0)