1 | // SPDX-License-Identifier: GPL-2.0 |
2 | /* Copyright (c) 2023 Meta Platforms, Inc. and affiliates. */ |
3 | |
4 | #include "vmlinux.h" |
5 | #include <bpf/bpf_helpers.h> |
6 | #include "bpf_misc.h" |
7 | |
8 | struct bpf_iter_testmod_seq { |
9 | u64 :64; |
10 | u64 :64; |
11 | }; |
12 | |
13 | extern int bpf_iter_testmod_seq_new(struct bpf_iter_testmod_seq *it, s64 value, int cnt) __ksym; |
14 | extern s64 *bpf_iter_testmod_seq_next(struct bpf_iter_testmod_seq *it) __ksym; |
15 | extern void bpf_iter_testmod_seq_destroy(struct bpf_iter_testmod_seq *it) __ksym; |
16 | |
17 | const volatile __s64 exp_empty = 0 + 1; |
18 | __s64 res_empty; |
19 | |
20 | SEC("raw_tp/sys_enter" ) |
21 | __success __log_level(2) |
22 | __msg("fp-16_w=iter_testmod_seq(ref_id=1,state=active,depth=0)" ) |
23 | __msg("fp-16=iter_testmod_seq(ref_id=1,state=drained,depth=0)" ) |
24 | __msg("call bpf_iter_testmod_seq_destroy" ) |
25 | int testmod_seq_empty(const void *ctx) |
26 | { |
27 | __s64 sum = 0, *i; |
28 | |
29 | bpf_for_each(testmod_seq, i, 1000, 0) sum += *i; |
30 | res_empty = 1 + sum; |
31 | |
32 | return 0; |
33 | } |
34 | |
35 | const volatile __s64 exp_full = 1000000; |
36 | __s64 res_full; |
37 | |
38 | SEC("raw_tp/sys_enter" ) |
39 | __success __log_level(2) |
40 | __msg("fp-16_w=iter_testmod_seq(ref_id=1,state=active,depth=0)" ) |
41 | __msg("fp-16=iter_testmod_seq(ref_id=1,state=drained,depth=0)" ) |
42 | __msg("call bpf_iter_testmod_seq_destroy" ) |
43 | int testmod_seq_full(const void *ctx) |
44 | { |
45 | __s64 sum = 0, *i; |
46 | |
47 | bpf_for_each(testmod_seq, i, 1000, 1000) sum += *i; |
48 | res_full = sum; |
49 | |
50 | return 0; |
51 | } |
52 | |
53 | const volatile __s64 exp_truncated = 10 * 1000000; |
54 | __s64 res_truncated; |
55 | |
56 | static volatile int zero = 0; |
57 | |
58 | SEC("raw_tp/sys_enter" ) |
59 | __success __log_level(2) |
60 | __msg("fp-16_w=iter_testmod_seq(ref_id=1,state=active,depth=0)" ) |
61 | __msg("fp-16=iter_testmod_seq(ref_id=1,state=drained,depth=0)" ) |
62 | __msg("call bpf_iter_testmod_seq_destroy" ) |
63 | int testmod_seq_truncated(const void *ctx) |
64 | { |
65 | __s64 sum = 0, *i; |
66 | int cnt = zero; |
67 | |
68 | bpf_for_each(testmod_seq, i, 10, 2000000) { |
69 | sum += *i; |
70 | cnt++; |
71 | if (cnt >= 1000000) |
72 | break; |
73 | } |
74 | res_truncated = sum; |
75 | |
76 | return 0; |
77 | } |
78 | |
79 | char _license[] SEC("license" ) = "GPL" ; |
80 | |