tools/testing/selftests/bpf/prog_tests/bpftool_maps_access.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/prog_tests/bpftool_maps_access.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/prog_tests/bpftool_maps_access.c- Extension
.c- Size
- 8911 bytes
- Lines
- 372
- 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
stdlib.hunistd.hfcntl.hstdint.hsys/stat.hstdbool.hlinux/bpf.hbpf/libbpf.hbpftool_helpers.htest_progs.hbpf/bpf.hsecurity_bpf_map.skel.h
Detected Declarations
struct test_descenum map_protectionfunction general_cleanupfunction update_test_descfunction test_setupfunction test_cleanupfunction lookup_map_valuefunction read_map_btf_datafunction write_map_valuefunction delete_map_valuefunction iterate_on_map_valuesfunction create_inner_mapfunction create_outer_mapfunction delete_pinned_mapfunction add_outer_map_entryfunction test_basic_accessfunction test_create_nested_mapsfunction test_btf_listfunction test_bpftool_maps_access
Annotated Snippet
struct test_desc {
char *name;
enum map_protection protection;
struct bpf_map *map;
char *map_name;
bool pinned;
char pin_path[PATH_MAX_LEN];
bool write_must_fail;
};
static struct security_bpf_map *general_setup(void)
{
struct security_bpf_map *skel;
uint32_t key, value;
int ret, i;
skel = security_bpf_map__open_and_load();
if (!ASSERT_OK_PTR(skel, "open and load skeleton"))
goto end;
struct bpf_map *maps[] = {skel->maps.prot_map, skel->maps.not_prot_map};
ret = security_bpf_map__attach(skel);
if (!ASSERT_OK(ret, "attach maps security programs"))
goto end_destroy;
for (i = 0; i < sizeof(maps)/sizeof(struct bpf_map *); i++) {
for (key = 0; key < 2; key++) {
int ret = bpf_map__update_elem(maps[i], &key,
sizeof(key), &key, sizeof(key),
0);
if (!ASSERT_OK(ret, "set initial map value"))
goto end_destroy;
}
}
key = 0;
value = 1;
ret = bpf_map__update_elem(skel->maps.prot_status_map, &key,
sizeof(key), &value, sizeof(value), 0);
if (!ASSERT_OK(ret, "configure map protection"))
goto end_destroy;
if (!ASSERT_OK(mkdir(BPFFS_PIN_DIR, S_IFDIR), "create bpffs pin dir"))
goto end_destroy;
return skel;
end_destroy:
security_bpf_map__destroy(skel);
end:
return NULL;
}
static void general_cleanup(struct security_bpf_map *skel)
{
rmdir(BPFFS_PIN_DIR);
security_bpf_map__destroy(skel);
}
static void update_test_desc(struct security_bpf_map *skel,
struct test_desc *test)
{
/* Now that the skeleton is loaded, update all missing fields to
* have the subtest properly configured
*/
if (test->protection == PROTECTED) {
test->map = skel->maps.prot_map;
test->map_name = PROTECTED_MAP_NAME;
} else {
test->map = skel->maps.not_prot_map;
test->map_name = UNPROTECTED_MAP_NAME;
}
}
static int test_setup(struct security_bpf_map *skel, struct test_desc *desc)
{
int ret;
update_test_desc(skel, desc);
if (desc->pinned) {
ret = snprintf(desc->pin_path, PATH_MAX_LEN, "%s/%s", BPFFS_PIN_DIR,
desc->name);
if (!ASSERT_GT(ret, 0, "format pin path"))
return 1;
ret = bpf_map__pin(desc->map, desc->pin_path);
if (!ASSERT_OK(ret, "pin map"))
return 1;
}
Annotation
- Immediate include surface: `stdlib.h`, `unistd.h`, `fcntl.h`, `stdint.h`, `sys/stat.h`, `stdbool.h`, `linux/bpf.h`, `bpf/libbpf.h`.
- Detected declarations: `struct test_desc`, `enum map_protection`, `function general_cleanup`, `function update_test_desc`, `function test_setup`, `function test_cleanup`, `function lookup_map_value`, `function read_map_btf_data`, `function write_map_value`, `function delete_map_value`.
- 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.