summaryrefslogtreecommitdiff
path: root/tools/perf/tests/maps.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/perf/tests/maps.c')
-rw-r--r--tools/perf/tests/maps.c69
1 files changed, 46 insertions, 23 deletions
diff --git a/tools/perf/tests/maps.c b/tools/perf/tests/maps.c
index a69988a89d26..8c0eb5cf8bb5 100644
--- a/tools/perf/tests/maps.c
+++ b/tools/perf/tests/maps.c
@@ -1,4 +1,5 @@
// SPDX-License-Identifier: GPL-2.0
+#include <inttypes.h>
#include <linux/compiler.h>
#include <linux/kernel.h>
#include "tests.h"
@@ -15,22 +16,44 @@ struct map_def {
static int check_maps(struct map_def *merged, unsigned int size, struct maps *maps)
{
- struct map *map;
+ struct map_rb_node *rb_node;
unsigned int i = 0;
-
- maps__for_each_entry(maps, map) {
- if (i > 0)
- TEST_ASSERT_VAL("less maps expected", (map && i < size) || (!map && i == size));
-
- TEST_ASSERT_VAL("wrong map start", map->start == merged[i].start);
- TEST_ASSERT_VAL("wrong map end", map->end == merged[i].end);
- TEST_ASSERT_VAL("wrong map name", !strcmp(map->dso->name, merged[i].name));
- TEST_ASSERT_VAL("wrong map refcnt", refcount_read(&map->refcnt) == 1);
-
- i++;
+ bool failed = false;
+
+ if (maps__nr_maps(maps) != size) {
+ pr_debug("Expected %d maps, got %d", size, maps__nr_maps(maps));
+ failed = true;
+ } else {
+ maps__for_each_entry(maps, rb_node) {
+ struct map *map = rb_node->map;
+
+ if (map__start(map) != merged[i].start ||
+ map__end(map) != merged[i].end ||
+ strcmp(map__dso(map)->name, merged[i].name) ||
+ refcount_read(map__refcnt(map)) != 1) {
+ failed = true;
+ }
+ i++;
+ }
}
-
- return TEST_OK;
+ if (failed) {
+ pr_debug("Expected:\n");
+ for (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_entry(maps, rb_node) {
+ struct map *map = rb_node->map;
+
+ pr_debug("\tstart: %" PRIu64 " end: %" PRIu64 " name: '%s' refcnt: %d\n",
+ map__start(map),
+ map__end(map),
+ map__dso(map)->name,
+ refcount_read(map__refcnt(map)));
+ }
+ }
+ return failed ? TEST_FAIL : TEST_OK;
}
static int test__maps__merge_in(struct test_suite *t __maybe_unused, int subtest __maybe_unused)
@@ -72,9 +95,9 @@ static int test__maps__merge_in(struct test_suite *t __maybe_unused, int subtest
map = dso__new_map(bpf_progs[i].name);
TEST_ASSERT_VAL("failed to create map", map);
- map->start = bpf_progs[i].start;
- map->end = bpf_progs[i].end;
- maps__insert(maps, map);
+ map__set_start(map, bpf_progs[i].start);
+ map__set_end(map, bpf_progs[i].end);
+ TEST_ASSERT_VAL("failed to insert map", maps__insert(maps, map) == 0);
map__put(map);
}
@@ -88,16 +111,16 @@ static int test__maps__merge_in(struct test_suite *t __maybe_unused, int subtest
TEST_ASSERT_VAL("failed to create map", map_kcore3);
/* kcore1 map overlaps over all bpf maps */
- map_kcore1->start = 100;
- map_kcore1->end = 1000;
+ map__set_start(map_kcore1, 100);
+ map__set_end(map_kcore1, 1000);
/* kcore2 map hides behind bpf_prog_2 */
- map_kcore2->start = 550;
- map_kcore2->end = 570;
+ map__set_start(map_kcore2, 550);
+ map__set_end(map_kcore2, 570);
/* kcore3 map hides behind bpf_prog_3, kcore1 and adds new map */
- map_kcore3->start = 880;
- map_kcore3->end = 1100;
+ map__set_start(map_kcore3, 880);
+ map__set_end(map_kcore3, 1100);
ret = maps__merge_in(maps, map_kcore1);
TEST_ASSERT_VAL("failed to merge map", !ret);