From: Leo Yan Date: Thu, 7 Nov 2024 12:53:08 +0000 (+0000) Subject: perf cpumap: Add checking for reference counter X-Git-Tag: v6.14-rc1~29^2~175 X-Git-Url: https://git.kernel.dk/?a=commitdiff_plain;h=9eef3ec920f558aabcf7bd0acd55d7d037b9e56b;p=linux-block.git perf cpumap: Add checking for reference counter For the CPU map merging test, add an extra check for the reference counter before releasing the last CPU map. Reviewed-by: Adrian Hunter Signed-off-by: Leo Yan Tested-by: Arnaldo Carvalho de Melo Cc: Alexander Shishkin Cc: Ian Rogers Cc: James Clark Cc: Jiri Olsa Cc: Kan Liang Cc: Mark Rutland Cc: Namhyung Kim Link: https://lore.kernel.org/r/20241107125308.41226-4-leo.yan@arm.com Signed-off-by: Arnaldo Carvalho de Melo --- diff --git a/tools/perf/tests/cpumap.c b/tools/perf/tests/cpumap.c index f8187a801b8e..5ed7ff072ea3 100644 --- a/tools/perf/tests/cpumap.c +++ b/tools/perf/tests/cpumap.c @@ -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; }