perf cpumap: Add checking for reference counter
authorLeo Yan <leo.yan@arm.com>
Thu, 7 Nov 2024 12:53:08 +0000 (12:53 +0000)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 9 Dec 2024 20:52:41 +0000 (17:52 -0300)
For the CPU map merging test, add an extra check for the reference
counter before releasing the last CPU map.

Reviewed-by: Adrian Hunter <adrian.hunter@intel.com>
Signed-off-by: Leo Yan <leo.yan@arm.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: James Clark <james.clark@linaro.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: https://lore.kernel.org/r/20241107125308.41226-4-leo.yan@arm.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/tests/cpumap.c

index f8187a801b8e171e0b892192e34821a05c47055f..5ed7ff072ea342db466a66d09d9c209b05252d2f 100644 (file)
@@ -167,6 +167,15 @@ static int __test__cpu_map_merge(const char *lhs, const char *rhs, int nr, const
        cpu_map__snprint(a, buf, sizeof(buf));
        TEST_ASSERT_VAL("failed to merge map: bad result", !strcmp(buf, expected));
        perf_cpu_map__put(b);
+
+       /*
+        * If 'b' is a superset of 'a', 'a' points to the same map with the
+        * map 'b'. In this case, the owner 'b' has released the resource above
+        * but 'a' still keeps the ownership, the reference counter should be 1.
+        */
+       TEST_ASSERT_VAL("unexpected refcnt: bad result",
+                       refcount_read(perf_cpu_map__refcnt(a)) == 1);
+
        perf_cpu_map__put(a);
        return 0;
 }