diff options
author | Alexei Starovoitov <ast@kernel.org> | 2024-06-12 18:38:15 -0700 |
---|---|---|
committer | Daniel Borkmann <daniel@iogearbox.net> | 2024-06-14 21:52:40 +0200 |
commit | dedf56d775c0bebbc3003bfb988dddaf0a583c28 (patch) | |
tree | 9b5db9431d4b9630956715796a7e1d7f9bfb255c /tools/testing/selftests/bpf/progs/arena_htab.c | |
parent | 6870bdb3f4f2991193449f9de57109b3e263f55c (diff) |
selftests/bpf: Add tests for add_const
Improve arena based tests and add several C and asm tests
with specific pattern.
These tests would have failed without add_const verifier support.
Also add several loop_inside_iter*() tests that are not related to add_const,
but nice to have.
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20240613013815.953-5-alexei.starovoitov@gmail.com
Diffstat (limited to 'tools/testing/selftests/bpf/progs/arena_htab.c')
-rw-r--r-- | tools/testing/selftests/bpf/progs/arena_htab.c | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/tools/testing/selftests/bpf/progs/arena_htab.c b/tools/testing/selftests/bpf/progs/arena_htab.c index cf938cf8c11e..81eaa94afeb0 100644 --- a/tools/testing/selftests/bpf/progs/arena_htab.c +++ b/tools/testing/selftests/bpf/progs/arena_htab.c @@ -19,25 +19,35 @@ void __arena *htab_for_user; bool skip = false; int zero = 0; +char __arena arr1[100000]; +char arr2[1000]; SEC("syscall") int arena_htab_llvm(void *ctx) { #if defined(__BPF_FEATURE_ADDR_SPACE_CAST) || defined(BPF_ARENA_FORCE_ASM) struct htab __arena *htab; + char __arena *arr = arr1; __u64 i; htab = bpf_alloc(sizeof(*htab)); cast_kern(htab); htab_init(htab); + cast_kern(arr); + /* first run. No old elems in the table */ - for (i = zero; i < 1000; i++) + for (i = zero; i < 100000 && can_loop; i++) { htab_update_elem(htab, i, i); + arr[i] = i; + } - /* should replace all elems with new ones */ - for (i = zero; i < 1000; i++) + /* should replace some elems with new ones */ + for (i = zero; i < 1000 && can_loop; i++) { htab_update_elem(htab, i, i); + /* Access mem to make the verifier use bounded loop logic */ + arr2[i] = i; + } cast_user(htab); htab_for_user = htab; #else |