tools/testing/selftests/bpf/prog_tests/arena_list.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/prog_tests/arena_list.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/prog_tests/arena_list.c- Extension
.c- Size
- 2302 bytes
- Lines
- 82
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
test_progs.hsys/mman.hnetwork_helpers.hsys/user.hunistd.hbpf_arena_list.harena_list.skel.h
Detected Declarations
struct elemfunction list_sumfunction test_arena_list_add_delfunction test_arena_list
Annotated Snippet
struct elem {
struct arena_list_node node;
__u64 value;
};
static int list_sum(struct arena_list_head *head)
{
struct elem __arena *n;
int sum = 0;
list_for_each_entry(n, head, node)
sum += n->value;
return sum;
}
static void test_arena_list_add_del(int cnt, bool nonsleepable)
{
LIBBPF_OPTS(bpf_test_run_opts, opts);
struct arena_list *skel;
int expected_sum = (u64)cnt * (cnt - 1) / 2;
int ret, sum;
skel = arena_list__open();
if (!ASSERT_OK_PTR(skel, "arena_list__open"))
return;
skel->rodata->nonsleepable = nonsleepable;
ret = arena_list__load(skel);
if (!ASSERT_OK(ret, "arena_list__load"))
goto out;
skel->bss->cnt = cnt;
ret = bpf_prog_test_run_opts(bpf_program__fd(skel->progs.arena_list_add), &opts);
ASSERT_OK(ret, "ret_add");
ASSERT_OK(opts.retval, "retval");
if (skel->bss->skip) {
printf("%s:SKIP:compiler doesn't support arena_cast\n", __func__);
test__skip();
goto out;
}
sum = list_sum(skel->bss->list_head);
ASSERT_EQ(sum, expected_sum, "sum of elems");
ASSERT_EQ(skel->arena->arena_sum, expected_sum, "__arena sum of elems");
ASSERT_EQ(skel->arena->test_val, cnt + 1, "num of elems");
ret = bpf_prog_test_run_opts(bpf_program__fd(skel->progs.arena_list_del), &opts);
ASSERT_OK(ret, "ret_del");
sum = list_sum(skel->bss->list_head);
ASSERT_EQ(sum, 0, "sum of list elems after del");
ASSERT_EQ(skel->bss->list_sum, expected_sum, "sum of list elems computed by prog");
ASSERT_EQ(skel->arena->arena_sum, expected_sum, "__arena sum of elems");
out:
arena_list__destroy(skel);
}
void test_arena_list(void)
{
if (test__start_subtest("arena_list_1"))
test_arena_list_add_del(1, false);
if (test__start_subtest("arena_list_1000"))
test_arena_list_add_del(1000, false);
if (test__start_subtest("arena_list_1_nonsleepable"))
test_arena_list_add_del(1, true);
if (test__start_subtest("arena_list_1000_nonsleepable"))
test_arena_list_add_del(1000, true);
}
Annotation
- Immediate include surface: `test_progs.h`, `sys/mman.h`, `network_helpers.h`, `sys/user.h`, `unistd.h`, `bpf_arena_list.h`, `arena_list.skel.h`.
- Detected declarations: `struct elem`, `function list_sum`, `function test_arena_list_add_del`, `function test_arena_list`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.