tools/perf/tests/maps.c
Source file repositories/reference/linux-study-clean/tools/perf/tests/maps.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/tests/maps.c- Extension
.c- Size
- 6849 bytes
- Lines
- 246
- 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
inttypes.hlinux/compiler.hlinux/kernel.htests.hmap.hmaps.hdso.hdebug.h
Detected Declarations
struct map_defstruct check_maps_cb_argsfunction check_maps_cbfunction failed_cbfunction check_mapsfunction test__maps__merge_infunction test__maps__fixup_overlap_and_insert
Annotated Snippet
struct map_def {
const char *name;
u64 start;
u64 end;
};
struct check_maps_cb_args {
struct map_def *merged;
unsigned int i;
};
static int check_maps_cb(struct map *map, void *data)
{
struct check_maps_cb_args *args = data;
struct map_def *merged = &args->merged[args->i];
if (map__start(map) != merged->start ||
map__end(map) != merged->end ||
strcmp(dso__name(map__dso(map)), merged->name) ||
refcount_read(map__refcnt(map)) != 1) {
return 1;
}
args->i++;
return 0;
}
static int failed_cb(struct map *map, void *data __maybe_unused)
{
pr_debug("\tstart: %" PRIu64 " end: %" PRIu64 " name: '%s' refcnt: %d\n",
map__start(map),
map__end(map),
dso__name(map__dso(map)),
refcount_read(map__refcnt(map)));
return 0;
}
static int check_maps(struct map_def *merged, unsigned int size, struct maps *maps)
{
bool failed = false;
if (maps__nr_maps(maps) != size) {
pr_debug("Expected %d maps, got %d", size, maps__nr_maps(maps));
failed = true;
} else {
struct check_maps_cb_args args = {
.merged = merged,
.i = 0,
};
failed = maps__for_each_map(maps, check_maps_cb, &args);
}
if (failed) {
pr_debug("Expected:\n");
for (unsigned int i = 0; i < size; i++) {
pr_debug("\tstart: %" PRIu64 " end: %" PRIu64 " name: '%s' refcnt: 1\n",
merged[i].start, merged[i].end, merged[i].name);
}
pr_debug("Got:\n");
maps__for_each_map(maps, failed_cb, NULL);
}
return failed ? TEST_FAIL : TEST_OK;
}
static int test__maps__merge_in(struct test_suite *t __maybe_unused, int subtest __maybe_unused)
{
unsigned int i;
struct map_def bpf_progs[] = {
{ "bpf_prog_1", 200, 300 },
{ "bpf_prog_2", 500, 600 },
{ "bpf_prog_3", 800, 900 },
};
struct map_def merged12[] = {
{ "kcore1", 100, 200 },
{ "bpf_prog_1", 200, 300 },
{ "kcore1", 300, 500 },
{ "bpf_prog_2", 500, 600 },
{ "kcore1", 600, 800 },
{ "bpf_prog_3", 800, 900 },
{ "kcore1", 900, 1000 },
};
struct map_def merged3[] = {
{ "kcore1", 100, 200 },
{ "bpf_prog_1", 200, 300 },
{ "kcore1", 300, 500 },
{ "bpf_prog_2", 500, 600 },
{ "kcore1", 600, 800 },
{ "bpf_prog_3", 800, 900 },
{ "kcore1", 900, 1000 },
{ "kcore3", 1000, 1100 },
};
Annotation
- Immediate include surface: `inttypes.h`, `linux/compiler.h`, `linux/kernel.h`, `tests.h`, `map.h`, `maps.h`, `dso.h`, `debug.h`.
- Detected declarations: `struct map_def`, `struct check_maps_cb_args`, `function check_maps_cb`, `function failed_cb`, `function check_maps`, `function test__maps__merge_in`, `function test__maps__fixup_overlap_and_insert`.
- 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.