Skip to content

Commit 04b0321

Browse files
committed
selftests/bpf: Add tracing multi cookies test
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
1 parent 2c1144c commit 04b0321

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@
77
#include "tracing_multi.skel.h"
88
#include "trace_helpers.h"
99

10+
static __u64 bpf_fentry_test_cookies[] = {
11+
8, /* bpf_fentry_test1 */
12+
6, /* bpf_fentry_test2 */
13+
7, /* bpf_fentry_test3 */
14+
5, /* bpf_fentry_test4 */
15+
4, /* bpf_fentry_test5 */
16+
2, /* bpf_fentry_test6 */
17+
3, /* bpf_fentry_test7 */
18+
1, /* bpf_fentry_test8 */
19+
};
20+
1021
static const char *bpf_fentry_test[] = {
1122
"bpf_fentry_test1",
1223
"bpf_fentry_test2",
@@ -142,7 +153,7 @@ static void test_link_api_pattern(void)
142153
tracing_multi__destroy(skel);
143154
}
144155

145-
static void test_link_api_ids(void)
156+
static void test_link_api_ids(bool test_cookies)
146157
{
147158
LIBBPF_OPTS(bpf_tracing_multi_opts, opts);
148159
size_t cnt = ARRAY_SIZE(bpf_fentry_test);
@@ -153,13 +164,18 @@ static void test_link_api_ids(void)
153164
if (!ASSERT_OK_PTR(skel, "tracing_multi__open_and_load"))
154165
return;
155166

167+
skel->bss->test_cookies = test_cookies;
168+
156169
ids = get_ids(bpf_fentry_test, cnt);
157170
if (!ASSERT_OK_PTR(ids, "get_ids"))
158171
goto cleanup;
159172

160173
opts.ids = ids;
161174
opts.cnt = cnt;
162175

176+
if (test_cookies)
177+
opts.cookies = bpf_fentry_test_cookies;
178+
163179
skel->links.test_fentry = bpf_program__attach_tracing_multi(skel->progs.test_fentry,
164180
NULL, &opts);
165181
if (!ASSERT_OK_PTR(skel->links.test_fentry, "bpf_program__attach_tracing_multi"))
@@ -264,7 +280,9 @@ void test_tracing_multi_test(void)
264280
if (test__start_subtest("link_api_pattern"))
265281
test_link_api_pattern();
266282
if (test__start_subtest("link_api_ids"))
267-
test_link_api_ids();
283+
test_link_api_ids(false);
268284
if (test__start_subtest("intersect"))
269285
test_intersect();
286+
if (test__start_subtest("cookies"))
287+
test_link_api_ids(true);
270288
}

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,18 @@ extern const void bpf_fentry_test6 __ksym;
1515
extern const void bpf_fentry_test7 __ksym;
1616
extern const void bpf_fentry_test8 __ksym;
1717

18+
bool test_cookies = false;
19+
1820
static void arg_check(__u64 *ctx, __u64 *test_result, bool is_return)
1921
{
2022
void *ip = (void *) bpf_get_func_ip(ctx);
21-
__u64 value = 0, ret = 0;
23+
__u64 value = 0, ret = 0, cookie = 0;
2224
long err = 0;
2325

2426
if (is_return)
2527
err |= bpf_get_func_ret(ctx, &ret);
28+
if (test_cookies)
29+
cookie = test_cookies ? bpf_get_attach_cookie(ctx) : 0;
2630

2731
if (ip == &bpf_fentry_test1) {
2832
int a;
@@ -31,6 +35,7 @@ static void arg_check(__u64 *ctx, __u64 *test_result, bool is_return)
3135
a = (int) value;
3236

3337
err |= is_return ? ret != 2 : 0;
38+
err |= test_cookies ? cookie != 8 : 0;
3439

3540
*test_result += err == 0 && a == 1;
3641
} else if (ip == &bpf_fentry_test2) {
@@ -43,6 +48,7 @@ static void arg_check(__u64 *ctx, __u64 *test_result, bool is_return)
4348
b = value;
4449

4550
err |= is_return ? ret != 5 : 0;
51+
err |= test_cookies ? cookie != 6 : 0;
4652

4753
*test_result += err == 0 && a == 2 && b == 3;
4854
} else if (ip == &bpf_fentry_test3) {
@@ -58,6 +64,7 @@ static void arg_check(__u64 *ctx, __u64 *test_result, bool is_return)
5864
c = value;
5965

6066
err |= is_return ? ret != 15 : 0;
67+
err |= test_cookies ? cookie != 7 : 0;
6168

6269
*test_result += err == 0 && a == 4 && b == 5 && c == 6;
6370
} else if (ip == &bpf_fentry_test4) {
@@ -76,6 +83,7 @@ static void arg_check(__u64 *ctx, __u64 *test_result, bool is_return)
7683
d = value;
7784

7885
err |= is_return ? ret != 34 : 0;
86+
err |= test_cookies ? cookie != 5 : 0;
7987

8088
*test_result += err == 0 && a == (void *) 7 && b == 8 && c == 9 && d == 10;
8189
} else if (ip == &bpf_fentry_test5) {
@@ -97,6 +105,7 @@ static void arg_check(__u64 *ctx, __u64 *test_result, bool is_return)
97105
e = value;
98106

99107
err |= is_return ? ret != 65 : 0;
108+
err |= test_cookies ? cookie != 4 : 0;
100109

101110
*test_result += err == 0 && a == 11 && b == (void *) 12 && c == 13 && d == 14 && e == 15;
102111
} else if (ip == &bpf_fentry_test6) {
@@ -121,14 +130,17 @@ static void arg_check(__u64 *ctx, __u64 *test_result, bool is_return)
121130
f = value;;
122131

123132
err |= is_return ? ret != 111 : 0;
133+
err |= test_cookies ? cookie != 2 : 0;
124134

125135
*test_result += err == 0 && a == 16 && b == (void *) 17 && c == 18 && d == 19 && e == (void *) 20 && f == 21;
126136
} else if (ip == &bpf_fentry_test7) {
127137
err |= is_return ? ret != 0 : 0;
138+
err |= test_cookies ? cookie != 3 : 0;
128139

129140
*test_result += err == 0 ? 1 : 0;
130141
} else if (ip == &bpf_fentry_test8) {
131142
err |= is_return ? ret != 0 : 0;
143+
err |= test_cookies ? cookie != 1 : 0;
132144

133145
*test_result += err == 0 ? 1 : 0;
134146
}

0 commit comments

Comments
 (0)