Skip to content

Commit 882e3d8

Browse files
anakryikoAlexei Starovoitov
authored andcommitted
selftests/bpf: add iter test requiring range x range logic
Add a simple verifier test that requires deriving reg bounds for one register from another register that's not a constant. This is a realistic example of iterating elements of an array with fixed maximum number of elements, but smaller actual number of elements. This small example was an original motivation for doing this whole patch set in the first place, yes. Signed-off-by: Andrii Nakryiko <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent a5c57f8 commit 882e3d8

File tree

1 file changed

+22
-0
lines changed
  • tools/testing/selftests/bpf/progs

1 file changed

+22
-0
lines changed

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1411,4 +1411,26 @@ __naked int checkpoint_states_deletion(void)
14111411
);
14121412
}
14131413

1414+
struct {
1415+
int data[32];
1416+
int n;
1417+
} loop_data;
1418+
1419+
SEC("raw_tp")
1420+
__success
1421+
int iter_arr_with_actual_elem_count(const void *ctx)
1422+
{
1423+
int i, n = loop_data.n, sum = 0;
1424+
1425+
if (n > ARRAY_SIZE(loop_data.data))
1426+
return 0;
1427+
1428+
bpf_for(i, 0, n) {
1429+
/* no rechecking of i against ARRAY_SIZE(loop_data.n) */
1430+
sum += loop_data.data[i];
1431+
}
1432+
1433+
return sum;
1434+
}
1435+
14141436
char _license[] SEC("license") = "GPL";

0 commit comments

Comments
 (0)