[PATCH v6 05/12] perf test: Add extra diagnostics to maps test

From: Ian Rogers
Date: Tue Apr 04 2023 - 17:01:55 EST


Dump the resultant and comparison maps on failure.

Signed-off-by: Ian Rogers <irogers@xxxxxxxxxx>
---
tools/perf/tests/maps.c | 51 +++++++++++++++++++++++++++++------------
1 file changed, 36 insertions(+), 15 deletions(-)

diff --git a/tools/perf/tests/maps.c b/tools/perf/tests/maps.c
index fd0c464fcf95..1c7293476aca 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"
@@ -17,22 +18,42 @@ static int check_maps(struct map_def *merged, unsigned int size, struct maps *ma
{
struct map_rb_node *rb_node;
unsigned int i = 0;
-
- maps__for_each_entry(maps, rb_node) {
- struct map *map = rb_node->map;
-
- if (i > 0)
- TEST_ASSERT_VAL("less maps expected", (map && i < size) || (!map && i == size));
-
- TEST_ASSERT_VAL("wrong map start", map__start(map) == merged[i].start);
- TEST_ASSERT_VAL("wrong map end", map__end(map) == merged[i].end);
- TEST_ASSERT_VAL("wrong map name", !strcmp(map__dso(map)->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) != 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));
+ }
+ }
+ return failed ? TEST_FAIL : TEST_OK;
}

static int test__maps__merge_in(struct test_suite *t __maybe_unused, int subtest __maybe_unused)
--
2.40.0.348.gf938b09366-goog