tools/testing/selftests/bpf/prog_tests/arena_htab.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/prog_tests/arena_htab.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/prog_tests/arena_htab.c- Extension
.c- Size
- 2376 bytes
- Lines
- 91
- 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.harena_htab_asm.skel.harena_htab.skel.hbpf_arena_htab.h
Detected Declarations
function test_arena_htab_commonfunction test_arena_htab_llvmfunction test_arena_htab_asmfunction test_arena_htab
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2024 Meta Platforms, Inc. and affiliates. */
#include <test_progs.h>
#include <sys/mman.h>
#include <network_helpers.h>
#include <sys/user.h>
#ifndef PAGE_SIZE /* on some archs it comes in sys/user.h */
#include <unistd.h>
#define PAGE_SIZE getpagesize()
#endif
#include "arena_htab_asm.skel.h"
#include "arena_htab.skel.h"
#include "bpf_arena_htab.h"
static void test_arena_htab_common(struct htab *htab)
{
int i;
printf("htab %p buckets %p n_buckets %d\n", htab, htab->buckets, htab->n_buckets);
ASSERT_OK_PTR(htab->buckets, "htab->buckets shouldn't be NULL");
for (i = 0; htab->buckets && i < 16; i += 4) {
/*
* Walk htab buckets and link lists since all pointers are correct,
* though they were written by bpf program.
*/
int val = htab_lookup_elem(htab, i);
ASSERT_EQ(i, val, "key == value");
}
}
static void test_arena_htab_llvm(void)
{
LIBBPF_OPTS(bpf_test_run_opts, opts);
struct arena_htab *skel;
struct htab *htab;
size_t arena_sz;
void *area;
int ret;
skel = arena_htab__open_and_load();
if (!ASSERT_OK_PTR(skel, "arena_htab__open_and_load"))
return;
area = bpf_map__initial_value(skel->maps.arena, &arena_sz);
/* fault-in a page with pgoff == 0 as sanity check */
*(volatile int *)area = 0x55aa;
/* bpf prog will allocate more pages */
ret = bpf_prog_test_run_opts(bpf_program__fd(skel->progs.arena_htab_llvm), &opts);
ASSERT_OK(ret, "ret");
ASSERT_OK(opts.retval, "retval");
if (skel->bss->skip) {
printf("%s:SKIP:compiler doesn't support arena_cast\n", __func__);
test__skip();
goto out;
}
htab = skel->bss->htab_for_user;
test_arena_htab_common(htab);
out:
arena_htab__destroy(skel);
}
static void test_arena_htab_asm(void)
{
LIBBPF_OPTS(bpf_test_run_opts, opts);
struct arena_htab_asm *skel;
struct htab *htab;
int ret;
skel = arena_htab_asm__open_and_load();
if (!ASSERT_OK_PTR(skel, "arena_htab_asm__open_and_load"))
return;
ret = bpf_prog_test_run_opts(bpf_program__fd(skel->progs.arena_htab_asm), &opts);
ASSERT_OK(ret, "ret");
ASSERT_OK(opts.retval, "retval");
htab = skel->bss->htab_for_user;
test_arena_htab_common(htab);
arena_htab_asm__destroy(skel);
}
void test_arena_htab(void)
{
if (test__start_subtest("arena_htab_llvm"))
test_arena_htab_llvm();
if (test__start_subtest("arena_htab_asm"))
test_arena_htab_asm();
}
Annotation
- Immediate include surface: `test_progs.h`, `sys/mman.h`, `network_helpers.h`, `sys/user.h`, `unistd.h`, `arena_htab_asm.skel.h`, `arena_htab.skel.h`, `bpf_arena_htab.h`.
- Detected declarations: `function test_arena_htab_common`, `function test_arena_htab_llvm`, `function test_arena_htab_asm`, `function test_arena_htab`.
- 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.