[PATCH v3 16/22] perf test: Add extra diagnostics to maps test

Ian Rogers
2022-02-11T10:35:44Z

Dump the resultant and comparison maps on failure.

Signed-off-by: Ian Rogers <irogers@google.com>
---
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 a58274598587..38c1ec0074d1 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 == 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) != 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.35.1.265.g69c8d7142f-goog