tools/testing/selftests/bpf/prog_tests/hashmap.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/prog_tests/hashmap.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/prog_tests/hashmap.c- Extension
.c- Size
- 12193 bytes
- Lines
- 460
- 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.hbpf/hashmap.hstddef.h
Detected Declarations
function hash_fnfunction equal_fnfunction next_pow_2function exp_capfunction test_hashmap_genericfunction hashmap__for_each_entry_safefunction str_hash_fnfunction str_equal_fnfunction test_hashmap_ptr_ifacefunction collision_hash_fnfunction test_hashmap_multimapfunction test_hashmap_emptyfunction hashmap__for_each_entryfunction test_hashmap
Annotated Snippet
if (i % 2) {
err = hashmap__add(map, k, v);
} else {
err = hashmap__set(map, k, v, &oldk, &oldv);
if (CHECK(oldk != 0 || oldv != 0, "check_kv",
"unexpected k/v: %ld=%ld\n", oldk, oldv))
goto cleanup;
}
if (CHECK(err, "elem_add", "failed to add k/v %ld = %ld: %d\n", k, v, err))
goto cleanup;
if (CHECK(!hashmap__find(map, k, &oldv), "elem_find",
"failed to find key %ld\n", k))
goto cleanup;
if (CHECK(oldv != v, "elem_val", "found value is wrong: %ld\n", oldv))
goto cleanup;
}
if (CHECK(hashmap__size(map) != ELEM_CNT, "hashmap__size",
"invalid map size: %zu\n", hashmap__size(map)))
goto cleanup;
if (CHECK(hashmap__capacity(map) != exp_cap(hashmap__size(map)),
"hashmap_cap",
"unexpected map capacity: %zu\n", hashmap__capacity(map)))
goto cleanup;
found_msk = 0;
hashmap__for_each_entry(map, entry, bkt) {
long k = entry->key;
long v = entry->value;
found_msk |= 1ULL << k;
if (CHECK(v - k != 1024, "check_kv",
"invalid k/v pair: %ld = %ld\n", k, v))
goto cleanup;
}
if (CHECK(found_msk != (1ULL << ELEM_CNT) - 1, "elem_cnt",
"not all keys iterated: %llx\n", found_msk))
goto cleanup;
for (i = 0; i < ELEM_CNT; i++) {
long oldk, k = i;
long oldv, v = 256 + i;
err = hashmap__add(map, k, v);
if (CHECK(err != -EEXIST, "hashmap__add",
"unexpected add result: %d\n", err))
goto cleanup;
if (i % 2)
err = hashmap__update(map, k, v, &oldk, &oldv);
else
err = hashmap__set(map, k, v, &oldk, &oldv);
if (CHECK(err, "elem_upd",
"failed to update k/v %ld = %ld: %d\n",
k, v, err))
goto cleanup;
if (CHECK(!hashmap__find(map, k, &oldv), "elem_find",
"failed to find key %ld\n", k))
goto cleanup;
if (CHECK(oldv != v, "elem_val",
"found value is wrong: %ld\n", oldv))
goto cleanup;
}
if (CHECK(hashmap__size(map) != ELEM_CNT, "hashmap__size",
"invalid updated map size: %zu\n", hashmap__size(map)))
goto cleanup;
if (CHECK(hashmap__capacity(map) != exp_cap(hashmap__size(map)),
"hashmap__capacity",
"unexpected map capacity: %zu\n", hashmap__capacity(map)))
goto cleanup;
found_msk = 0;
hashmap__for_each_entry_safe(map, entry, tmp, bkt) {
long k = entry->key;
long v = entry->value;
found_msk |= 1ULL << k;
if (CHECK(v - k != 256, "elem_check",
"invalid updated k/v pair: %ld = %ld\n", k, v))
goto cleanup;
}
if (CHECK(found_msk != (1ULL << ELEM_CNT) - 1, "elem_cnt",
"not all keys iterated after update: %llx\n", found_msk))
goto cleanup;
found_cnt = 0;
Annotation
- Immediate include surface: `test_progs.h`, `bpf/hashmap.h`, `stddef.h`.
- Detected declarations: `function hash_fn`, `function equal_fn`, `function next_pow_2`, `function exp_cap`, `function test_hashmap_generic`, `function hashmap__for_each_entry_safe`, `function str_hash_fn`, `function str_equal_fn`, `function test_hashmap_ptr_iface`, `function collision_hash_fn`.
- 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.