6 #include <linux/bitops.h>
11 static int process_event_mask(struct perf_tool
*tool __maybe_unused
,
12 union perf_event
*event
,
13 struct perf_sample
*sample __maybe_unused
,
14 struct machine
*machine __maybe_unused
)
16 struct cpu_map_event
*map_event
= &event
->cpu_map
;
17 struct cpu_map_mask
*mask
;
18 struct cpu_map_data
*data
;
22 data
= &map_event
->data
;
24 TEST_ASSERT_VAL("wrong type", data
->type
== PERF_CPU_MAP__MASK
);
26 mask
= (struct cpu_map_mask
*)data
->data
;
28 TEST_ASSERT_VAL("wrong nr", mask
->nr
== 1);
30 for (i
= 0; i
< 20; i
++) {
31 TEST_ASSERT_VAL("wrong cpu", test_bit(i
, mask
->mask
));
34 map
= cpu_map__new_data(data
);
35 TEST_ASSERT_VAL("wrong nr", map
->nr
== 20);
37 for (i
= 0; i
< 20; i
++) {
38 TEST_ASSERT_VAL("wrong cpu", map
->map
[i
] == i
);
45 static int process_event_cpus(struct perf_tool
*tool __maybe_unused
,
46 union perf_event
*event
,
47 struct perf_sample
*sample __maybe_unused
,
48 struct machine
*machine __maybe_unused
)
50 struct cpu_map_event
*map_event
= &event
->cpu_map
;
51 struct cpu_map_entries
*cpus
;
52 struct cpu_map_data
*data
;
55 data
= &map_event
->data
;
57 TEST_ASSERT_VAL("wrong type", data
->type
== PERF_CPU_MAP__CPUS
);
59 cpus
= (struct cpu_map_entries
*)data
->data
;
61 TEST_ASSERT_VAL("wrong nr", cpus
->nr
== 2);
62 TEST_ASSERT_VAL("wrong cpu", cpus
->cpu
[0] == 1);
63 TEST_ASSERT_VAL("wrong cpu", cpus
->cpu
[1] == 256);
65 map
= cpu_map__new_data(data
);
66 TEST_ASSERT_VAL("wrong nr", map
->nr
== 2);
67 TEST_ASSERT_VAL("wrong cpu", map
->map
[0] == 1);
68 TEST_ASSERT_VAL("wrong cpu", map
->map
[1] == 256);
69 TEST_ASSERT_VAL("wrong refcnt", atomic_read(&map
->refcnt
) == 1);
75 int test__cpu_map_synthesize(int subtest __maybe_unused
)
79 /* This one is better stores in mask. */
80 cpus
= cpu_map__new("0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19");
82 TEST_ASSERT_VAL("failed to synthesize map",
83 !perf_event__synthesize_cpu_map(NULL
, cpus
, process_event_mask
, NULL
));
87 /* This one is better stores in cpu values. */
88 cpus
= cpu_map__new("1,256");
90 TEST_ASSERT_VAL("failed to synthesize map",
91 !perf_event__synthesize_cpu_map(NULL
, cpus
, process_event_cpus
, NULL
));
97 static int cpu_map_print(const char *str
)
99 struct cpu_map
*map
= cpu_map__new(str
);
105 cpu_map__snprint(map
, buf
, sizeof(buf
));
106 return !strcmp(buf
, str
);
109 int test__cpu_map_print(int subtest __maybe_unused
)
111 TEST_ASSERT_VAL("failed to convert map", cpu_map_print("1"));
112 TEST_ASSERT_VAL("failed to convert map", cpu_map_print("1,5"));
113 TEST_ASSERT_VAL("failed to convert map", cpu_map_print("1,3,5,7,9,11,13,15,17,19,21-40"));
114 TEST_ASSERT_VAL("failed to convert map", cpu_map_print("2-5"));
115 TEST_ASSERT_VAL("failed to convert map", cpu_map_print("1,3-6,8-10,24,35-37"));
116 TEST_ASSERT_VAL("failed to convert map", cpu_map_print("1,3-6,8-10,24,35-37"));
117 TEST_ASSERT_VAL("failed to convert map", cpu_map_print("1-10,12-20,22-30,32-40"));