Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

selftests/bpf: Add stacktrace map lookup_and_delete_elem test case

Add tests for stacktrace map lookup and delete:
1. use bpf_map_lookup_and_delete_elem to lookup and delete the target
stack_id,
2. lookup the deleted stack_id again to double check.

Signed-off-by: Tao Chen <chen.dylane@linux.dev>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20250925175030.1615837-3-chen.dylane@linux.dev

authored by

Tao Chen and committed by
Andrii Nakryiko
d43029ff 363b17e2

+12 -1
+10 -1
tools/testing/selftests/bpf/prog_tests/stacktrace_map.c
··· 7 7 struct stacktrace_map *skel; 8 8 int control_map_fd, stackid_hmap_fd, stackmap_fd, stack_amap_fd; 9 9 int err, stack_trace_len; 10 - __u32 key, val, duration = 0; 10 + __u32 key, val, stack_id, duration = 0; 11 + __u64 stack[PERF_MAX_STACK_DEPTH]; 11 12 12 13 skel = stacktrace_map__open_and_load(); 13 14 if (!ASSERT_OK_PTR(skel, "skel_open_and_load")) ··· 49 48 "err %d errno %d\n", err, errno)) 50 49 goto out; 51 50 51 + stack_id = skel->bss->stack_id; 52 + err = bpf_map_lookup_and_delete_elem(stackmap_fd, &stack_id, stack); 53 + if (!ASSERT_OK(err, "lookup and delete target stack_id")) 54 + goto out; 55 + 56 + err = bpf_map_lookup_elem(stackmap_fd, &stack_id, stack); 57 + if (!ASSERT_EQ(err, -ENOENT, "lookup deleted stack_id")) 58 + goto out; 52 59 out: 53 60 stacktrace_map__destroy(skel); 54 61 }
+2
tools/testing/selftests/bpf/progs/stacktrace_map.c
··· 50 50 int next_prio; 51 51 }; 52 52 53 + __u32 stack_id; 53 54 SEC("tracepoint/sched/sched_switch") 54 55 int oncpu(struct sched_switch_args *ctx) 55 56 { ··· 65 64 /* The size of stackmap and stackid_hmap should be the same */ 66 65 key = bpf_get_stackid(ctx, &stackmap, 0); 67 66 if ((int)key >= 0) { 67 + stack_id = key; 68 68 bpf_map_update_elem(&stackid_hmap, &key, &val, 0); 69 69 stack_p = bpf_map_lookup_elem(&stack_amap, &key); 70 70 if (stack_p)