perf tools: Use fallback for sample_addr_correlates_sym() cases
[linux/fpc-iii.git] / tools / perf / tests / mem2node.c
blob9e9e4d37cc771868c183e22fbba4eaa6c095ba1b
1 #include <linux/compiler.h>
2 #include <linux/bitmap.h>
3 #include "cpumap.h"
4 #include "mem2node.h"
5 #include "tests.h"
7 static struct node {
8 int node;
9 const char *map;
10 } test_nodes[] = {
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;
22 int i;
24 bm = bitmap_alloc(nbits);
26 if (map && bm) {
27 for (i = 0; i < map->nr; i++) {
28 set_bit(map->map[i], bm);
32 if (map)
33 cpu_map__put(map);
34 else
35 free(bm);
37 return bm && map ? bm : NULL;
40 int test__mem2node(struct test *t __maybe_unused, int subtest __maybe_unused)
42 struct mem2node map;
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,
49 unsigned int i;
51 for (i = 0; i < ARRAY_SIZE(nodes); i++) {
52 nodes[i].node = test_nodes[i].node;
53 nodes[i].size = 10;
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++)
69 free(nodes[i].set);
71 mem2node__exit(&map);
72 return 0;