1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/compiler.h>
3 #include <linux/bitmap.h>
4 #include <linux/kernel.h>
5 #include <linux/zalloc.h>
6 #include <perf/cpumap.h>
7 #include <internal/cpumap.h>
17 { .node
= 0, .map
= "0" },
18 { .node
= 1, .map
= "1-2" },
19 { .node
= 3, .map
= "5-7,9" },
22 #define T TEST_ASSERT_VAL
24 static unsigned long *get_bitmap(const char *str
, int nbits
)
26 struct perf_cpu_map
*map
= perf_cpu_map__new(str
);
27 unsigned long *bm
= NULL
;
30 bm
= bitmap_alloc(nbits
);
33 for (i
= 0; i
< map
->nr
; i
++) {
34 set_bit(map
->map
[i
], bm
);
39 perf_cpu_map__put(map
);
43 return bm
&& map
? bm
: NULL
;
46 int test__mem2node(struct test
*t __maybe_unused
, int subtest __maybe_unused
)
49 struct memory_node nodes
[3];
50 struct perf_env env
= {
51 .memory_nodes
= (struct memory_node
*) &nodes
[0],
52 .nr_memory_nodes
= ARRAY_SIZE(nodes
),
53 .memory_bsize
= 0x100,
57 for (i
= 0; i
< ARRAY_SIZE(nodes
); i
++) {
58 nodes
[i
].node
= test_nodes
[i
].node
;
61 T("failed: alloc bitmap",
62 (nodes
[i
].set
= get_bitmap(test_nodes
[i
].map
, 10)));
65 T("failed: mem2node__init", !mem2node__init(&map
, &env
));
66 T("failed: mem2node__node", 0 == mem2node__node(&map
, 0x50));
67 T("failed: mem2node__node", 1 == mem2node__node(&map
, 0x100));
68 T("failed: mem2node__node", 1 == mem2node__node(&map
, 0x250));
69 T("failed: mem2node__node", 3 == mem2node__node(&map
, 0x500));
70 T("failed: mem2node__node", 3 == mem2node__node(&map
, 0x650));
71 T("failed: mem2node__node", -1 == mem2node__node(&map
, 0x450));
72 T("failed: mem2node__node", -1 == mem2node__node(&map
, 0x1050));
74 for (i
= 0; i
< ARRAY_SIZE(nodes
); i
++)