1 // SPDX-License-Identifier: GPL-2.0
7 #include <linux/bitops.h>
12 static int process_event_mask(struct perf_tool
*tool __maybe_unused
,
13 union perf_event
*event
,
14 struct perf_sample
*sample __maybe_unused
,
15 struct machine
*machine __maybe_unused
)
17 struct cpu_map_event
*map_event
= &event
->cpu_map
;
18 struct cpu_map_mask
*mask
;
19 struct cpu_map_data
*data
;
23 data
= &map_event
->data
;
25 TEST_ASSERT_VAL("wrong type", data
->type
== PERF_CPU_MAP__MASK
);
27 mask
= (struct cpu_map_mask
*)data
->data
;
29 TEST_ASSERT_VAL("wrong nr", mask
->nr
== 1);
31 for (i
= 0; i
< 20; i
++) {
32 TEST_ASSERT_VAL("wrong cpu", test_bit(i
, mask
->mask
));
35 map
= cpu_map__new_data(data
);
36 TEST_ASSERT_VAL("wrong nr", map
->nr
== 20);
38 for (i
= 0; i
< 20; i
++) {
39 TEST_ASSERT_VAL("wrong cpu", map
->map
[i
] == i
);
46 static int process_event_cpus(struct perf_tool
*tool __maybe_unused
,
47 union perf_event
*event
,
48 struct perf_sample
*sample __maybe_unused
,
49 struct machine
*machine __maybe_unused
)
51 struct cpu_map_event
*map_event
= &event
->cpu_map
;
52 struct cpu_map_entries
*cpus
;
53 struct cpu_map_data
*data
;
56 data
= &map_event
->data
;
58 TEST_ASSERT_VAL("wrong type", data
->type
== PERF_CPU_MAP__CPUS
);
60 cpus
= (struct cpu_map_entries
*)data
->data
;
62 TEST_ASSERT_VAL("wrong nr", cpus
->nr
== 2);
63 TEST_ASSERT_VAL("wrong cpu", cpus
->cpu
[0] == 1);
64 TEST_ASSERT_VAL("wrong cpu", cpus
->cpu
[1] == 256);
66 map
= cpu_map__new_data(data
);
67 TEST_ASSERT_VAL("wrong nr", map
->nr
== 2);
68 TEST_ASSERT_VAL("wrong cpu", map
->map
[0] == 1);
69 TEST_ASSERT_VAL("wrong cpu", map
->map
[1] == 256);
70 TEST_ASSERT_VAL("wrong refcnt", refcount_read(&map
->refcnt
) == 1);
76 int test__cpu_map_synthesize(struct test
*test __maybe_unused
, int subtest __maybe_unused
)
80 /* This one is better stores in mask. */
81 cpus
= cpu_map__new("0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19");
83 TEST_ASSERT_VAL("failed to synthesize map",
84 !perf_event__synthesize_cpu_map(NULL
, cpus
, process_event_mask
, NULL
));
88 /* This one is better stores in cpu values. */
89 cpus
= cpu_map__new("1,256");
91 TEST_ASSERT_VAL("failed to synthesize map",
92 !perf_event__synthesize_cpu_map(NULL
, cpus
, process_event_cpus
, NULL
));
98 static int cpu_map_print(const char *str
)
100 struct cpu_map
*map
= cpu_map__new(str
);
106 cpu_map__snprint(map
, buf
, sizeof(buf
));
107 return !strcmp(buf
, str
);
110 int test__cpu_map_print(struct test
*test __maybe_unused
, int subtest __maybe_unused
)
112 TEST_ASSERT_VAL("failed to convert map", cpu_map_print("1"));
113 TEST_ASSERT_VAL("failed to convert map", cpu_map_print("1,5"));
114 TEST_ASSERT_VAL("failed to convert map", cpu_map_print("1,3,5,7,9,11,13,15,17,19,21-40"));
115 TEST_ASSERT_VAL("failed to convert map", cpu_map_print("2-5"));
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,3-6,8-10,24,35-37"));
118 TEST_ASSERT_VAL("failed to convert map", cpu_map_print("1-10,12-20,22-30,32-40"));