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.

Dependency Surface

Detected Declarations

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

Implementation Notes