1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2023 Meta Platforms, Inc. and affiliates. */
5 #include <bpf/bpf_helpers.h>
8 struct bpf_iter_testmod_seq {
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 s64 bpf_iter_testmod_seq_value(int blah, struct bpf_iter_testmod_seq *it) __ksym;
16 extern void bpf_iter_testmod_seq_destroy(struct bpf_iter_testmod_seq *it) __ksym;
18 const volatile __s64 exp_empty = 0 + 1;
21 SEC("raw_tp/sys_enter")
22 __success __log_level(2)
23 __msg("fp-16_w=iter_testmod_seq(ref_id=1,state=active,depth=0)")
24 __msg("fp-16=iter_testmod_seq(ref_id=1,state=drained,depth=0)")
25 __msg("call bpf_iter_testmod_seq_destroy")
26 int testmod_seq_empty(const void *ctx)
30 bpf_for_each(testmod_seq, i, 1000, 0) sum += *i;
36 const volatile __s64 exp_full = 1000000;
39 SEC("raw_tp/sys_enter")
40 __success __log_level(2)
41 __msg("fp-16_w=iter_testmod_seq(ref_id=1,state=active,depth=0)")
42 __msg("fp-16=iter_testmod_seq(ref_id=1,state=drained,depth=0)")
43 __msg("call bpf_iter_testmod_seq_destroy")
44 int testmod_seq_full(const void *ctx)
48 bpf_for_each(testmod_seq, i, 1000, 1000) sum += *i;
54 const volatile __s64 exp_truncated = 10 * 1000000;
57 static volatile int zero = 0;
59 SEC("raw_tp/sys_enter")
60 __success __log_level(2)
61 __msg("fp-16_w=iter_testmod_seq(ref_id=1,state=active,depth=0)")
62 __msg("fp-16=iter_testmod_seq(ref_id=1,state=drained,depth=0)")
63 __msg("call bpf_iter_testmod_seq_destroy")
64 int testmod_seq_truncated(const void *ctx)
69 bpf_for_each(testmod_seq, i, 10, 2000000) {
82 __msg("expected an initialized iter_testmod_seq as arg #1")
83 int testmod_seq_getter_before_bad(const void *ctx)
85 struct bpf_iter_testmod_seq it;
87 return bpf_iter_testmod_seq_value(0, &it);
92 __msg("expected an initialized iter_testmod_seq as arg #1")
93 int testmod_seq_getter_after_bad(const void *ctx)
95 struct bpf_iter_testmod_seq it;
98 bpf_iter_testmod_seq_new(&it, 100, 100);
100 while ((v = bpf_iter_testmod_seq_next(&it))) {
104 bpf_iter_testmod_seq_destroy(&it);
106 return sum + bpf_iter_testmod_seq_value(0, &it);
110 __success __retval(1000000)
111 int testmod_seq_getter_good(const void *ctx)
113 struct bpf_iter_testmod_seq it;
116 bpf_iter_testmod_seq_new(&it, 100, 100);
118 while ((v = bpf_iter_testmod_seq_next(&it))) {
122 sum *= bpf_iter_testmod_seq_value(0, &it);
124 bpf_iter_testmod_seq_destroy(&it);
129 char _license[] SEC("license") = "GPL";