1 #include <linux/compiler.h>
2 #include <linux/bitmap.h>
11 { .node
= 0, .map
= "0" },
12 { .node
= 1, .map
= "1-2" },
13 { .node
= 3, .map
= "5-7,9" },
16 #define T TEST_ASSERT_VAL
18 static unsigned long *get_bitmap(const char *str
, int nbits
)
20 struct cpu_map
*map
= cpu_map__new(str
);
21 unsigned long *bm
= NULL
;
24 bm
= bitmap_alloc(nbits
);
27 for (i
= 0; i
< map
->nr
; i
++) {
28 set_bit(map
->map
[i
], bm
);
37 return bm
&& map
? bm
: NULL
;
40 int test__mem2node(struct test
*t __maybe_unused
, int subtest __maybe_unused
)
43 struct memory_node nodes
[3];
44 struct perf_env env
= {
45 .memory_nodes
= (struct memory_node
*) &nodes
[0],
46 .nr_memory_nodes
= ARRAY_SIZE(nodes
),
47 .memory_bsize
= 0x100,
51 for (i
= 0; i
< ARRAY_SIZE(nodes
); i
++) {
52 nodes
[i
].node
= test_nodes
[i
].node
;
55 T("failed: alloc bitmap",
56 (nodes
[i
].set
= get_bitmap(test_nodes
[i
].map
, 10)));
59 T("failed: mem2node__init", !mem2node__init(&map
, &env
));
60 T("failed: mem2node__node", 0 == mem2node__node(&map
, 0x50));
61 T("failed: mem2node__node", 1 == mem2node__node(&map
, 0x100));
62 T("failed: mem2node__node", 1 == mem2node__node(&map
, 0x250));
63 T("failed: mem2node__node", 3 == mem2node__node(&map
, 0x500));
64 T("failed: mem2node__node", 3 == mem2node__node(&map
, 0x650));
65 T("failed: mem2node__node", -1 == mem2node__node(&map
, 0x450));
66 T("failed: mem2node__node", -1 == mem2node__node(&map
, 0x1050));
68 for (i
= 0; i
< ARRAY_SIZE(nodes
); i
++)