1 // SPDX-License-Identifier: GPL-2.0
2 #include "parse-events.h"
11 #include <sys/types.h>
14 #include <linux/kernel.h>
15 #include <linux/hw_breakpoint.h>
16 #include <api/fs/fs.h>
17 #include <api/fs/tracing_path.h>
19 #define PERF_TP_SAMPLE_TYPE (PERF_SAMPLE_RAW | PERF_SAMPLE_TIME | \
20 PERF_SAMPLE_CPU | PERF_SAMPLE_PERIOD)
22 static int test__checkevent_tracepoint(struct perf_evlist
*evlist
)
24 struct perf_evsel
*evsel
= perf_evlist__first(evlist
);
26 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist
->nr_entries
);
27 TEST_ASSERT_VAL("wrong number of groups", 0 == evlist
->nr_groups
);
28 TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT
== evsel
->attr
.type
);
29 TEST_ASSERT_VAL("wrong sample_type",
30 PERF_TP_SAMPLE_TYPE
== evsel
->attr
.sample_type
);
31 TEST_ASSERT_VAL("wrong sample_period", 1 == evsel
->attr
.sample_period
);
35 static int test__checkevent_tracepoint_multi(struct perf_evlist
*evlist
)
37 struct perf_evsel
*evsel
;
39 TEST_ASSERT_VAL("wrong number of entries", evlist
->nr_entries
> 1);
40 TEST_ASSERT_VAL("wrong number of groups", 0 == evlist
->nr_groups
);
42 evlist__for_each_entry(evlist
, evsel
) {
43 TEST_ASSERT_VAL("wrong type",
44 PERF_TYPE_TRACEPOINT
== evsel
->attr
.type
);
45 TEST_ASSERT_VAL("wrong sample_type",
46 PERF_TP_SAMPLE_TYPE
== evsel
->attr
.sample_type
);
47 TEST_ASSERT_VAL("wrong sample_period",
48 1 == evsel
->attr
.sample_period
);
53 static int test__checkevent_raw(struct perf_evlist
*evlist
)
55 struct perf_evsel
*evsel
= perf_evlist__first(evlist
);
57 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist
->nr_entries
);
58 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW
== evsel
->attr
.type
);
59 TEST_ASSERT_VAL("wrong config", 0x1a == evsel
->attr
.config
);
63 static int test__checkevent_numeric(struct perf_evlist
*evlist
)
65 struct perf_evsel
*evsel
= perf_evlist__first(evlist
);
67 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist
->nr_entries
);
68 TEST_ASSERT_VAL("wrong type", 1 == evsel
->attr
.type
);
69 TEST_ASSERT_VAL("wrong config", 1 == evsel
->attr
.config
);
73 static int test__checkevent_symbolic_name(struct perf_evlist
*evlist
)
75 struct perf_evsel
*evsel
= perf_evlist__first(evlist
);
77 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist
->nr_entries
);
78 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE
== evsel
->attr
.type
);
79 TEST_ASSERT_VAL("wrong config",
80 PERF_COUNT_HW_INSTRUCTIONS
== evsel
->attr
.config
);
84 static int test__checkevent_symbolic_name_config(struct perf_evlist
*evlist
)
86 struct perf_evsel
*evsel
= perf_evlist__first(evlist
);
88 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist
->nr_entries
);
89 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE
== evsel
->attr
.type
);
90 TEST_ASSERT_VAL("wrong config",
91 PERF_COUNT_HW_CPU_CYCLES
== evsel
->attr
.config
);
93 * The period value gets configured within perf_evlist__config,
94 * while this test executes only parse events method.
96 TEST_ASSERT_VAL("wrong period",
97 0 == evsel
->attr
.sample_period
);
98 TEST_ASSERT_VAL("wrong config1",
99 0 == evsel
->attr
.config1
);
100 TEST_ASSERT_VAL("wrong config2",
101 1 == evsel
->attr
.config2
);
105 static int test__checkevent_symbolic_alias(struct perf_evlist
*evlist
)
107 struct perf_evsel
*evsel
= perf_evlist__first(evlist
);
109 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist
->nr_entries
);
110 TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE
== evsel
->attr
.type
);
111 TEST_ASSERT_VAL("wrong config",
112 PERF_COUNT_SW_PAGE_FAULTS
== evsel
->attr
.config
);
116 static int test__checkevent_genhw(struct perf_evlist
*evlist
)
118 struct perf_evsel
*evsel
= perf_evlist__first(evlist
);
120 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist
->nr_entries
);
121 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HW_CACHE
== evsel
->attr
.type
);
122 TEST_ASSERT_VAL("wrong config", (1 << 16) == evsel
->attr
.config
);
126 static int test__checkevent_breakpoint(struct perf_evlist
*evlist
)
128 struct perf_evsel
*evsel
= perf_evlist__first(evlist
);
130 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist
->nr_entries
);
131 TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT
== evsel
->attr
.type
);
132 TEST_ASSERT_VAL("wrong config", 0 == evsel
->attr
.config
);
133 TEST_ASSERT_VAL("wrong bp_type", (HW_BREAKPOINT_R
| HW_BREAKPOINT_W
) ==
134 evsel
->attr
.bp_type
);
135 TEST_ASSERT_VAL("wrong bp_len", HW_BREAKPOINT_LEN_4
==
140 static int test__checkevent_breakpoint_x(struct perf_evlist
*evlist
)
142 struct perf_evsel
*evsel
= perf_evlist__first(evlist
);
144 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist
->nr_entries
);
145 TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT
== evsel
->attr
.type
);
146 TEST_ASSERT_VAL("wrong config", 0 == evsel
->attr
.config
);
147 TEST_ASSERT_VAL("wrong bp_type",
148 HW_BREAKPOINT_X
== evsel
->attr
.bp_type
);
149 TEST_ASSERT_VAL("wrong bp_len", sizeof(long) == evsel
->attr
.bp_len
);
153 static int test__checkevent_breakpoint_r(struct perf_evlist
*evlist
)
155 struct perf_evsel
*evsel
= perf_evlist__first(evlist
);
157 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist
->nr_entries
);
158 TEST_ASSERT_VAL("wrong type",
159 PERF_TYPE_BREAKPOINT
== evsel
->attr
.type
);
160 TEST_ASSERT_VAL("wrong config", 0 == evsel
->attr
.config
);
161 TEST_ASSERT_VAL("wrong bp_type",
162 HW_BREAKPOINT_R
== evsel
->attr
.bp_type
);
163 TEST_ASSERT_VAL("wrong bp_len",
164 HW_BREAKPOINT_LEN_4
== evsel
->attr
.bp_len
);
168 static int test__checkevent_breakpoint_w(struct perf_evlist
*evlist
)
170 struct perf_evsel
*evsel
= perf_evlist__first(evlist
);
172 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist
->nr_entries
);
173 TEST_ASSERT_VAL("wrong type",
174 PERF_TYPE_BREAKPOINT
== evsel
->attr
.type
);
175 TEST_ASSERT_VAL("wrong config", 0 == evsel
->attr
.config
);
176 TEST_ASSERT_VAL("wrong bp_type",
177 HW_BREAKPOINT_W
== evsel
->attr
.bp_type
);
178 TEST_ASSERT_VAL("wrong bp_len",
179 HW_BREAKPOINT_LEN_4
== evsel
->attr
.bp_len
);
183 static int test__checkevent_breakpoint_rw(struct perf_evlist
*evlist
)
185 struct perf_evsel
*evsel
= perf_evlist__first(evlist
);
187 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist
->nr_entries
);
188 TEST_ASSERT_VAL("wrong type",
189 PERF_TYPE_BREAKPOINT
== evsel
->attr
.type
);
190 TEST_ASSERT_VAL("wrong config", 0 == evsel
->attr
.config
);
191 TEST_ASSERT_VAL("wrong bp_type",
192 (HW_BREAKPOINT_R
|HW_BREAKPOINT_W
) == evsel
->attr
.bp_type
);
193 TEST_ASSERT_VAL("wrong bp_len",
194 HW_BREAKPOINT_LEN_4
== evsel
->attr
.bp_len
);
198 static int test__checkevent_tracepoint_modifier(struct perf_evlist
*evlist
)
200 struct perf_evsel
*evsel
= perf_evlist__first(evlist
);
202 TEST_ASSERT_VAL("wrong exclude_user", evsel
->attr
.exclude_user
);
203 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel
->attr
.exclude_kernel
);
204 TEST_ASSERT_VAL("wrong exclude_hv", evsel
->attr
.exclude_hv
);
205 TEST_ASSERT_VAL("wrong precise_ip", !evsel
->attr
.precise_ip
);
207 return test__checkevent_tracepoint(evlist
);
211 test__checkevent_tracepoint_multi_modifier(struct perf_evlist
*evlist
)
213 struct perf_evsel
*evsel
;
215 TEST_ASSERT_VAL("wrong number of entries", evlist
->nr_entries
> 1);
217 evlist__for_each_entry(evlist
, evsel
) {
218 TEST_ASSERT_VAL("wrong exclude_user",
219 !evsel
->attr
.exclude_user
);
220 TEST_ASSERT_VAL("wrong exclude_kernel",
221 evsel
->attr
.exclude_kernel
);
222 TEST_ASSERT_VAL("wrong exclude_hv", evsel
->attr
.exclude_hv
);
223 TEST_ASSERT_VAL("wrong precise_ip", !evsel
->attr
.precise_ip
);
226 return test__checkevent_tracepoint_multi(evlist
);
229 static int test__checkevent_raw_modifier(struct perf_evlist
*evlist
)
231 struct perf_evsel
*evsel
= perf_evlist__first(evlist
);
233 TEST_ASSERT_VAL("wrong exclude_user", evsel
->attr
.exclude_user
);
234 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel
->attr
.exclude_kernel
);
235 TEST_ASSERT_VAL("wrong exclude_hv", evsel
->attr
.exclude_hv
);
236 TEST_ASSERT_VAL("wrong precise_ip", evsel
->attr
.precise_ip
);
238 return test__checkevent_raw(evlist
);
241 static int test__checkevent_numeric_modifier(struct perf_evlist
*evlist
)
243 struct perf_evsel
*evsel
= perf_evlist__first(evlist
);
245 TEST_ASSERT_VAL("wrong exclude_user", evsel
->attr
.exclude_user
);
246 TEST_ASSERT_VAL("wrong exclude_kernel", evsel
->attr
.exclude_kernel
);
247 TEST_ASSERT_VAL("wrong exclude_hv", !evsel
->attr
.exclude_hv
);
248 TEST_ASSERT_VAL("wrong precise_ip", evsel
->attr
.precise_ip
);
250 return test__checkevent_numeric(evlist
);
253 static int test__checkevent_symbolic_name_modifier(struct perf_evlist
*evlist
)
255 struct perf_evsel
*evsel
= perf_evlist__first(evlist
);
257 TEST_ASSERT_VAL("wrong exclude_user", evsel
->attr
.exclude_user
);
258 TEST_ASSERT_VAL("wrong exclude_kernel", evsel
->attr
.exclude_kernel
);
259 TEST_ASSERT_VAL("wrong exclude_hv", !evsel
->attr
.exclude_hv
);
260 TEST_ASSERT_VAL("wrong precise_ip", !evsel
->attr
.precise_ip
);
262 return test__checkevent_symbolic_name(evlist
);
265 static int test__checkevent_exclude_host_modifier(struct perf_evlist
*evlist
)
267 struct perf_evsel
*evsel
= perf_evlist__first(evlist
);
269 TEST_ASSERT_VAL("wrong exclude guest", !evsel
->attr
.exclude_guest
);
270 TEST_ASSERT_VAL("wrong exclude host", evsel
->attr
.exclude_host
);
272 return test__checkevent_symbolic_name(evlist
);
275 static int test__checkevent_exclude_guest_modifier(struct perf_evlist
*evlist
)
277 struct perf_evsel
*evsel
= perf_evlist__first(evlist
);
279 TEST_ASSERT_VAL("wrong exclude guest", evsel
->attr
.exclude_guest
);
280 TEST_ASSERT_VAL("wrong exclude host", !evsel
->attr
.exclude_host
);
282 return test__checkevent_symbolic_name(evlist
);
285 static int test__checkevent_symbolic_alias_modifier(struct perf_evlist
*evlist
)
287 struct perf_evsel
*evsel
= perf_evlist__first(evlist
);
289 TEST_ASSERT_VAL("wrong exclude_user", !evsel
->attr
.exclude_user
);
290 TEST_ASSERT_VAL("wrong exclude_kernel", evsel
->attr
.exclude_kernel
);
291 TEST_ASSERT_VAL("wrong exclude_hv", evsel
->attr
.exclude_hv
);
292 TEST_ASSERT_VAL("wrong precise_ip", !evsel
->attr
.precise_ip
);
294 return test__checkevent_symbolic_alias(evlist
);
297 static int test__checkevent_genhw_modifier(struct perf_evlist
*evlist
)
299 struct perf_evsel
*evsel
= perf_evlist__first(evlist
);
301 TEST_ASSERT_VAL("wrong exclude_user", evsel
->attr
.exclude_user
);
302 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel
->attr
.exclude_kernel
);
303 TEST_ASSERT_VAL("wrong exclude_hv", evsel
->attr
.exclude_hv
);
304 TEST_ASSERT_VAL("wrong precise_ip", evsel
->attr
.precise_ip
);
306 return test__checkevent_genhw(evlist
);
309 static int test__checkevent_exclude_idle_modifier(struct perf_evlist
*evlist
)
311 struct perf_evsel
*evsel
= perf_evlist__first(evlist
);
313 TEST_ASSERT_VAL("wrong exclude idle", evsel
->attr
.exclude_idle
);
314 TEST_ASSERT_VAL("wrong exclude guest", !evsel
->attr
.exclude_guest
);
315 TEST_ASSERT_VAL("wrong exclude host", !evsel
->attr
.exclude_host
);
316 TEST_ASSERT_VAL("wrong exclude_user", !evsel
->attr
.exclude_user
);
317 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel
->attr
.exclude_kernel
);
318 TEST_ASSERT_VAL("wrong exclude_hv", !evsel
->attr
.exclude_hv
);
319 TEST_ASSERT_VAL("wrong precise_ip", !evsel
->attr
.precise_ip
);
321 return test__checkevent_symbolic_name(evlist
);
324 static int test__checkevent_exclude_idle_modifier_1(struct perf_evlist
*evlist
)
326 struct perf_evsel
*evsel
= perf_evlist__first(evlist
);
328 TEST_ASSERT_VAL("wrong exclude idle", evsel
->attr
.exclude_idle
);
329 TEST_ASSERT_VAL("wrong exclude guest", !evsel
->attr
.exclude_guest
);
330 TEST_ASSERT_VAL("wrong exclude host", evsel
->attr
.exclude_host
);
331 TEST_ASSERT_VAL("wrong exclude_user", evsel
->attr
.exclude_user
);
332 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel
->attr
.exclude_kernel
);
333 TEST_ASSERT_VAL("wrong exclude_hv", evsel
->attr
.exclude_hv
);
334 TEST_ASSERT_VAL("wrong precise_ip", !evsel
->attr
.precise_ip
);
336 return test__checkevent_symbolic_name(evlist
);
339 static int test__checkevent_breakpoint_modifier(struct perf_evlist
*evlist
)
341 struct perf_evsel
*evsel
= perf_evlist__first(evlist
);
344 TEST_ASSERT_VAL("wrong exclude_user", !evsel
->attr
.exclude_user
);
345 TEST_ASSERT_VAL("wrong exclude_kernel", evsel
->attr
.exclude_kernel
);
346 TEST_ASSERT_VAL("wrong exclude_hv", evsel
->attr
.exclude_hv
);
347 TEST_ASSERT_VAL("wrong precise_ip", !evsel
->attr
.precise_ip
);
348 TEST_ASSERT_VAL("wrong name",
349 !strcmp(perf_evsel__name(evsel
), "mem:0:u"));
351 return test__checkevent_breakpoint(evlist
);
354 static int test__checkevent_breakpoint_x_modifier(struct perf_evlist
*evlist
)
356 struct perf_evsel
*evsel
= perf_evlist__first(evlist
);
358 TEST_ASSERT_VAL("wrong exclude_user", evsel
->attr
.exclude_user
);
359 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel
->attr
.exclude_kernel
);
360 TEST_ASSERT_VAL("wrong exclude_hv", evsel
->attr
.exclude_hv
);
361 TEST_ASSERT_VAL("wrong precise_ip", !evsel
->attr
.precise_ip
);
362 TEST_ASSERT_VAL("wrong name",
363 !strcmp(perf_evsel__name(evsel
), "mem:0:x:k"));
365 return test__checkevent_breakpoint_x(evlist
);
368 static int test__checkevent_breakpoint_r_modifier(struct perf_evlist
*evlist
)
370 struct perf_evsel
*evsel
= perf_evlist__first(evlist
);
372 TEST_ASSERT_VAL("wrong exclude_user", evsel
->attr
.exclude_user
);
373 TEST_ASSERT_VAL("wrong exclude_kernel", evsel
->attr
.exclude_kernel
);
374 TEST_ASSERT_VAL("wrong exclude_hv", !evsel
->attr
.exclude_hv
);
375 TEST_ASSERT_VAL("wrong precise_ip", evsel
->attr
.precise_ip
);
376 TEST_ASSERT_VAL("wrong name",
377 !strcmp(perf_evsel__name(evsel
), "mem:0:r:hp"));
379 return test__checkevent_breakpoint_r(evlist
);
382 static int test__checkevent_breakpoint_w_modifier(struct perf_evlist
*evlist
)
384 struct perf_evsel
*evsel
= perf_evlist__first(evlist
);
386 TEST_ASSERT_VAL("wrong exclude_user", !evsel
->attr
.exclude_user
);
387 TEST_ASSERT_VAL("wrong exclude_kernel", evsel
->attr
.exclude_kernel
);
388 TEST_ASSERT_VAL("wrong exclude_hv", evsel
->attr
.exclude_hv
);
389 TEST_ASSERT_VAL("wrong precise_ip", evsel
->attr
.precise_ip
);
390 TEST_ASSERT_VAL("wrong name",
391 !strcmp(perf_evsel__name(evsel
), "mem:0:w:up"));
393 return test__checkevent_breakpoint_w(evlist
);
396 static int test__checkevent_breakpoint_rw_modifier(struct perf_evlist
*evlist
)
398 struct perf_evsel
*evsel
= perf_evlist__first(evlist
);
400 TEST_ASSERT_VAL("wrong exclude_user", evsel
->attr
.exclude_user
);
401 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel
->attr
.exclude_kernel
);
402 TEST_ASSERT_VAL("wrong exclude_hv", evsel
->attr
.exclude_hv
);
403 TEST_ASSERT_VAL("wrong precise_ip", evsel
->attr
.precise_ip
);
404 TEST_ASSERT_VAL("wrong name",
405 !strcmp(perf_evsel__name(evsel
), "mem:0:rw:kp"));
407 return test__checkevent_breakpoint_rw(evlist
);
410 static int test__checkevent_pmu(struct perf_evlist
*evlist
)
413 struct perf_evsel
*evsel
= perf_evlist__first(evlist
);
415 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist
->nr_entries
);
416 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW
== evsel
->attr
.type
);
417 TEST_ASSERT_VAL("wrong config", 10 == evsel
->attr
.config
);
418 TEST_ASSERT_VAL("wrong config1", 1 == evsel
->attr
.config1
);
419 TEST_ASSERT_VAL("wrong config2", 3 == evsel
->attr
.config2
);
421 * The period value gets configured within perf_evlist__config,
422 * while this test executes only parse events method.
424 TEST_ASSERT_VAL("wrong period", 0 == evsel
->attr
.sample_period
);
429 static int test__checkevent_list(struct perf_evlist
*evlist
)
431 struct perf_evsel
*evsel
= perf_evlist__first(evlist
);
433 TEST_ASSERT_VAL("wrong number of entries", 3 == evlist
->nr_entries
);
436 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW
== evsel
->attr
.type
);
437 TEST_ASSERT_VAL("wrong config", 1 == evsel
->attr
.config
);
438 TEST_ASSERT_VAL("wrong config1", 0 == evsel
->attr
.config1
);
439 TEST_ASSERT_VAL("wrong config2", 0 == evsel
->attr
.config2
);
440 TEST_ASSERT_VAL("wrong exclude_user", !evsel
->attr
.exclude_user
);
441 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel
->attr
.exclude_kernel
);
442 TEST_ASSERT_VAL("wrong exclude_hv", !evsel
->attr
.exclude_hv
);
443 TEST_ASSERT_VAL("wrong precise_ip", !evsel
->attr
.precise_ip
);
445 /* syscalls:sys_enter_openat:k */
446 evsel
= perf_evsel__next(evsel
);
447 TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT
== evsel
->attr
.type
);
448 TEST_ASSERT_VAL("wrong sample_type",
449 PERF_TP_SAMPLE_TYPE
== evsel
->attr
.sample_type
);
450 TEST_ASSERT_VAL("wrong sample_period", 1 == evsel
->attr
.sample_period
);
451 TEST_ASSERT_VAL("wrong exclude_user", evsel
->attr
.exclude_user
);
452 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel
->attr
.exclude_kernel
);
453 TEST_ASSERT_VAL("wrong exclude_hv", evsel
->attr
.exclude_hv
);
454 TEST_ASSERT_VAL("wrong precise_ip", !evsel
->attr
.precise_ip
);
457 evsel
= perf_evsel__next(evsel
);
458 TEST_ASSERT_VAL("wrong type", 1 == evsel
->attr
.type
);
459 TEST_ASSERT_VAL("wrong config", 1 == evsel
->attr
.config
);
460 TEST_ASSERT_VAL("wrong exclude_user", evsel
->attr
.exclude_user
);
461 TEST_ASSERT_VAL("wrong exclude_kernel", evsel
->attr
.exclude_kernel
);
462 TEST_ASSERT_VAL("wrong exclude_hv", !evsel
->attr
.exclude_hv
);
463 TEST_ASSERT_VAL("wrong precise_ip", evsel
->attr
.precise_ip
);
468 static int test__checkevent_pmu_name(struct perf_evlist
*evlist
)
470 struct perf_evsel
*evsel
= perf_evlist__first(evlist
);
472 /* cpu/config=1,name=krava/u */
473 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist
->nr_entries
);
474 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW
== evsel
->attr
.type
);
475 TEST_ASSERT_VAL("wrong config", 1 == evsel
->attr
.config
);
476 TEST_ASSERT_VAL("wrong name", !strcmp(perf_evsel__name(evsel
), "krava"));
478 /* cpu/config=2/u" */
479 evsel
= perf_evsel__next(evsel
);
480 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist
->nr_entries
);
481 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW
== evsel
->attr
.type
);
482 TEST_ASSERT_VAL("wrong config", 2 == evsel
->attr
.config
);
483 TEST_ASSERT_VAL("wrong name",
484 !strcmp(perf_evsel__name(evsel
), "cpu/config=2/u"));
489 static int test__checkevent_pmu_partial_time_callgraph(struct perf_evlist
*evlist
)
491 struct perf_evsel
*evsel
= perf_evlist__first(evlist
);
493 /* cpu/config=1,call-graph=fp,time,period=100000/ */
494 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist
->nr_entries
);
495 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW
== evsel
->attr
.type
);
496 TEST_ASSERT_VAL("wrong config", 1 == evsel
->attr
.config
);
498 * The period, time and callgraph value gets configured
499 * within perf_evlist__config,
500 * while this test executes only parse events method.
502 TEST_ASSERT_VAL("wrong period", 0 == evsel
->attr
.sample_period
);
503 TEST_ASSERT_VAL("wrong callgraph", !(PERF_SAMPLE_CALLCHAIN
& evsel
->attr
.sample_type
));
504 TEST_ASSERT_VAL("wrong time", !(PERF_SAMPLE_TIME
& evsel
->attr
.sample_type
));
506 /* cpu/config=2,call-graph=no,time=0,period=2000/ */
507 evsel
= perf_evsel__next(evsel
);
508 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW
== evsel
->attr
.type
);
509 TEST_ASSERT_VAL("wrong config", 2 == evsel
->attr
.config
);
511 * The period, time and callgraph value gets configured
512 * within perf_evlist__config,
513 * while this test executes only parse events method.
515 TEST_ASSERT_VAL("wrong period", 0 == evsel
->attr
.sample_period
);
516 TEST_ASSERT_VAL("wrong callgraph", !(PERF_SAMPLE_CALLCHAIN
& evsel
->attr
.sample_type
));
517 TEST_ASSERT_VAL("wrong time", !(PERF_SAMPLE_TIME
& evsel
->attr
.sample_type
));
522 static int test__checkevent_pmu_events(struct perf_evlist
*evlist
)
524 struct perf_evsel
*evsel
= perf_evlist__first(evlist
);
526 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist
->nr_entries
);
527 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW
== evsel
->attr
.type
);
528 TEST_ASSERT_VAL("wrong exclude_user",
529 !evsel
->attr
.exclude_user
);
530 TEST_ASSERT_VAL("wrong exclude_kernel",
531 evsel
->attr
.exclude_kernel
);
532 TEST_ASSERT_VAL("wrong exclude_hv", evsel
->attr
.exclude_hv
);
533 TEST_ASSERT_VAL("wrong precise_ip", !evsel
->attr
.precise_ip
);
534 TEST_ASSERT_VAL("wrong pinned", !evsel
->attr
.pinned
);
540 static int test__checkevent_pmu_events_mix(struct perf_evlist
*evlist
)
542 struct perf_evsel
*evsel
= perf_evlist__first(evlist
);
545 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist
->nr_entries
);
546 TEST_ASSERT_VAL("wrong exclude_user",
547 !evsel
->attr
.exclude_user
);
548 TEST_ASSERT_VAL("wrong exclude_kernel",
549 evsel
->attr
.exclude_kernel
);
550 TEST_ASSERT_VAL("wrong exclude_hv", evsel
->attr
.exclude_hv
);
551 TEST_ASSERT_VAL("wrong precise_ip", !evsel
->attr
.precise_ip
);
552 TEST_ASSERT_VAL("wrong pinned", !evsel
->attr
.pinned
);
555 evsel
= perf_evsel__next(evsel
);
556 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist
->nr_entries
);
557 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW
== evsel
->attr
.type
);
558 TEST_ASSERT_VAL("wrong exclude_user",
559 !evsel
->attr
.exclude_user
);
560 TEST_ASSERT_VAL("wrong exclude_kernel",
561 evsel
->attr
.exclude_kernel
);
562 TEST_ASSERT_VAL("wrong exclude_hv", evsel
->attr
.exclude_hv
);
563 TEST_ASSERT_VAL("wrong precise_ip", !evsel
->attr
.precise_ip
);
564 TEST_ASSERT_VAL("wrong pinned", !evsel
->attr
.pinned
);
569 static int test__checkterms_simple(struct list_head
*terms
)
571 struct parse_events_term
*term
;
574 term
= list_entry(terms
->next
, struct parse_events_term
, list
);
575 TEST_ASSERT_VAL("wrong type term",
576 term
->type_term
== PARSE_EVENTS__TERM_TYPE_CONFIG
);
577 TEST_ASSERT_VAL("wrong type val",
578 term
->type_val
== PARSE_EVENTS__TERM_TYPE_NUM
);
579 TEST_ASSERT_VAL("wrong val", term
->val
.num
== 10);
580 TEST_ASSERT_VAL("wrong config", !term
->config
);
583 term
= list_entry(term
->list
.next
, struct parse_events_term
, list
);
584 TEST_ASSERT_VAL("wrong type term",
585 term
->type_term
== PARSE_EVENTS__TERM_TYPE_CONFIG1
);
586 TEST_ASSERT_VAL("wrong type val",
587 term
->type_val
== PARSE_EVENTS__TERM_TYPE_NUM
);
588 TEST_ASSERT_VAL("wrong val", term
->val
.num
== 1);
589 TEST_ASSERT_VAL("wrong config", !term
->config
);
592 term
= list_entry(term
->list
.next
, struct parse_events_term
, list
);
593 TEST_ASSERT_VAL("wrong type term",
594 term
->type_term
== PARSE_EVENTS__TERM_TYPE_CONFIG2
);
595 TEST_ASSERT_VAL("wrong type val",
596 term
->type_val
== PARSE_EVENTS__TERM_TYPE_NUM
);
597 TEST_ASSERT_VAL("wrong val", term
->val
.num
== 3);
598 TEST_ASSERT_VAL("wrong config", !term
->config
);
601 term
= list_entry(term
->list
.next
, struct parse_events_term
, list
);
602 TEST_ASSERT_VAL("wrong type term",
603 term
->type_term
== PARSE_EVENTS__TERM_TYPE_USER
);
604 TEST_ASSERT_VAL("wrong type val",
605 term
->type_val
== PARSE_EVENTS__TERM_TYPE_NUM
);
606 TEST_ASSERT_VAL("wrong val", term
->val
.num
== 1);
607 TEST_ASSERT_VAL("wrong config", !strcmp(term
->config
, "umask"));
612 static int test__group1(struct perf_evlist
*evlist
)
614 struct perf_evsel
*evsel
, *leader
;
616 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist
->nr_entries
);
617 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist
->nr_groups
);
620 evsel
= leader
= perf_evlist__first(evlist
);
621 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE
== evsel
->attr
.type
);
622 TEST_ASSERT_VAL("wrong config",
623 PERF_COUNT_HW_INSTRUCTIONS
== evsel
->attr
.config
);
624 TEST_ASSERT_VAL("wrong exclude_user", evsel
->attr
.exclude_user
);
625 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel
->attr
.exclude_kernel
);
626 TEST_ASSERT_VAL("wrong exclude_hv", evsel
->attr
.exclude_hv
);
627 TEST_ASSERT_VAL("wrong exclude guest", !evsel
->attr
.exclude_guest
);
628 TEST_ASSERT_VAL("wrong exclude host", !evsel
->attr
.exclude_host
);
629 TEST_ASSERT_VAL("wrong precise_ip", !evsel
->attr
.precise_ip
);
630 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel
));
631 TEST_ASSERT_VAL("wrong nr_members", evsel
->nr_members
== 2);
632 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel
) == 0);
633 TEST_ASSERT_VAL("wrong sample_read", !evsel
->sample_read
);
636 evsel
= perf_evsel__next(evsel
);
637 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE
== evsel
->attr
.type
);
638 TEST_ASSERT_VAL("wrong config",
639 PERF_COUNT_HW_CPU_CYCLES
== evsel
->attr
.config
);
640 TEST_ASSERT_VAL("wrong exclude_user", !evsel
->attr
.exclude_user
);
641 TEST_ASSERT_VAL("wrong exclude_kernel", evsel
->attr
.exclude_kernel
);
642 TEST_ASSERT_VAL("wrong exclude_hv", evsel
->attr
.exclude_hv
);
643 /* use of precise requires exclude_guest */
644 TEST_ASSERT_VAL("wrong exclude guest", evsel
->attr
.exclude_guest
);
645 TEST_ASSERT_VAL("wrong exclude host", !evsel
->attr
.exclude_host
);
646 TEST_ASSERT_VAL("wrong precise_ip", evsel
->attr
.precise_ip
== 2);
647 TEST_ASSERT_VAL("wrong leader", evsel
->leader
== leader
);
648 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel
) == 1);
649 TEST_ASSERT_VAL("wrong sample_read", !evsel
->sample_read
);
654 static int test__group2(struct perf_evlist
*evlist
)
656 struct perf_evsel
*evsel
, *leader
;
658 TEST_ASSERT_VAL("wrong number of entries", 3 == evlist
->nr_entries
);
659 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist
->nr_groups
);
661 /* faults + :ku modifier */
662 evsel
= leader
= perf_evlist__first(evlist
);
663 TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE
== evsel
->attr
.type
);
664 TEST_ASSERT_VAL("wrong config",
665 PERF_COUNT_SW_PAGE_FAULTS
== evsel
->attr
.config
);
666 TEST_ASSERT_VAL("wrong exclude_user", !evsel
->attr
.exclude_user
);
667 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel
->attr
.exclude_kernel
);
668 TEST_ASSERT_VAL("wrong exclude_hv", evsel
->attr
.exclude_hv
);
669 TEST_ASSERT_VAL("wrong exclude guest", !evsel
->attr
.exclude_guest
);
670 TEST_ASSERT_VAL("wrong exclude host", !evsel
->attr
.exclude_host
);
671 TEST_ASSERT_VAL("wrong precise_ip", !evsel
->attr
.precise_ip
);
672 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel
));
673 TEST_ASSERT_VAL("wrong nr_members", evsel
->nr_members
== 2);
674 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel
) == 0);
675 TEST_ASSERT_VAL("wrong sample_read", !evsel
->sample_read
);
677 /* cache-references + :u modifier */
678 evsel
= perf_evsel__next(evsel
);
679 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE
== evsel
->attr
.type
);
680 TEST_ASSERT_VAL("wrong config",
681 PERF_COUNT_HW_CACHE_REFERENCES
== evsel
->attr
.config
);
682 TEST_ASSERT_VAL("wrong exclude_user", !evsel
->attr
.exclude_user
);
683 TEST_ASSERT_VAL("wrong exclude_kernel", evsel
->attr
.exclude_kernel
);
684 TEST_ASSERT_VAL("wrong exclude_hv", evsel
->attr
.exclude_hv
);
685 TEST_ASSERT_VAL("wrong exclude guest", evsel
->attr
.exclude_guest
);
686 TEST_ASSERT_VAL("wrong exclude host", !evsel
->attr
.exclude_host
);
687 TEST_ASSERT_VAL("wrong precise_ip", !evsel
->attr
.precise_ip
);
688 TEST_ASSERT_VAL("wrong leader", evsel
->leader
== leader
);
689 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel
) == 1);
690 TEST_ASSERT_VAL("wrong sample_read", !evsel
->sample_read
);
693 evsel
= perf_evsel__next(evsel
);
694 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE
== evsel
->attr
.type
);
695 TEST_ASSERT_VAL("wrong config",
696 PERF_COUNT_HW_CPU_CYCLES
== evsel
->attr
.config
);
697 TEST_ASSERT_VAL("wrong exclude_user", evsel
->attr
.exclude_user
);
698 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel
->attr
.exclude_kernel
);
699 TEST_ASSERT_VAL("wrong exclude_hv", evsel
->attr
.exclude_hv
);
700 TEST_ASSERT_VAL("wrong exclude guest", !evsel
->attr
.exclude_guest
);
701 TEST_ASSERT_VAL("wrong exclude host", !evsel
->attr
.exclude_host
);
702 TEST_ASSERT_VAL("wrong precise_ip", !evsel
->attr
.precise_ip
);
703 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel
));
704 TEST_ASSERT_VAL("wrong sample_read", !evsel
->sample_read
);
709 static int test__group3(struct perf_evlist
*evlist __maybe_unused
)
711 struct perf_evsel
*evsel
, *leader
;
713 TEST_ASSERT_VAL("wrong number of entries", 5 == evlist
->nr_entries
);
714 TEST_ASSERT_VAL("wrong number of groups", 2 == evlist
->nr_groups
);
716 /* group1 syscalls:sys_enter_openat:H */
717 evsel
= leader
= perf_evlist__first(evlist
);
718 TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT
== evsel
->attr
.type
);
719 TEST_ASSERT_VAL("wrong sample_type",
720 PERF_TP_SAMPLE_TYPE
== evsel
->attr
.sample_type
);
721 TEST_ASSERT_VAL("wrong sample_period", 1 == evsel
->attr
.sample_period
);
722 TEST_ASSERT_VAL("wrong exclude_user", !evsel
->attr
.exclude_user
);
723 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel
->attr
.exclude_kernel
);
724 TEST_ASSERT_VAL("wrong exclude_hv", !evsel
->attr
.exclude_hv
);
725 TEST_ASSERT_VAL("wrong exclude guest", evsel
->attr
.exclude_guest
);
726 TEST_ASSERT_VAL("wrong exclude host", !evsel
->attr
.exclude_host
);
727 TEST_ASSERT_VAL("wrong precise_ip", !evsel
->attr
.precise_ip
);
728 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel
));
729 TEST_ASSERT_VAL("wrong group name",
730 !strcmp(leader
->group_name
, "group1"));
731 TEST_ASSERT_VAL("wrong nr_members", evsel
->nr_members
== 2);
732 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel
) == 0);
733 TEST_ASSERT_VAL("wrong sample_read", !evsel
->sample_read
);
735 /* group1 cycles:kppp */
736 evsel
= perf_evsel__next(evsel
);
737 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE
== evsel
->attr
.type
);
738 TEST_ASSERT_VAL("wrong config",
739 PERF_COUNT_HW_CPU_CYCLES
== evsel
->attr
.config
);
740 TEST_ASSERT_VAL("wrong exclude_user", evsel
->attr
.exclude_user
);
741 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel
->attr
.exclude_kernel
);
742 TEST_ASSERT_VAL("wrong exclude_hv", evsel
->attr
.exclude_hv
);
743 /* use of precise requires exclude_guest */
744 TEST_ASSERT_VAL("wrong exclude guest", evsel
->attr
.exclude_guest
);
745 TEST_ASSERT_VAL("wrong exclude host", !evsel
->attr
.exclude_host
);
746 TEST_ASSERT_VAL("wrong precise_ip", evsel
->attr
.precise_ip
== 3);
747 TEST_ASSERT_VAL("wrong leader", evsel
->leader
== leader
);
748 TEST_ASSERT_VAL("wrong group name", !evsel
->group_name
);
749 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel
) == 1);
750 TEST_ASSERT_VAL("wrong sample_read", !evsel
->sample_read
);
752 /* group2 cycles + G modifier */
753 evsel
= leader
= perf_evsel__next(evsel
);
754 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE
== evsel
->attr
.type
);
755 TEST_ASSERT_VAL("wrong config",
756 PERF_COUNT_HW_CPU_CYCLES
== evsel
->attr
.config
);
757 TEST_ASSERT_VAL("wrong exclude_user", !evsel
->attr
.exclude_user
);
758 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel
->attr
.exclude_kernel
);
759 TEST_ASSERT_VAL("wrong exclude_hv", !evsel
->attr
.exclude_hv
);
760 TEST_ASSERT_VAL("wrong exclude guest", !evsel
->attr
.exclude_guest
);
761 TEST_ASSERT_VAL("wrong exclude host", evsel
->attr
.exclude_host
);
762 TEST_ASSERT_VAL("wrong precise_ip", !evsel
->attr
.precise_ip
);
763 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel
));
764 TEST_ASSERT_VAL("wrong group name",
765 !strcmp(leader
->group_name
, "group2"));
766 TEST_ASSERT_VAL("wrong nr_members", evsel
->nr_members
== 2);
767 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel
) == 0);
768 TEST_ASSERT_VAL("wrong sample_read", !evsel
->sample_read
);
770 /* group2 1:3 + G modifier */
771 evsel
= perf_evsel__next(evsel
);
772 TEST_ASSERT_VAL("wrong type", 1 == evsel
->attr
.type
);
773 TEST_ASSERT_VAL("wrong config", 3 == evsel
->attr
.config
);
774 TEST_ASSERT_VAL("wrong exclude_user", !evsel
->attr
.exclude_user
);
775 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel
->attr
.exclude_kernel
);
776 TEST_ASSERT_VAL("wrong exclude_hv", !evsel
->attr
.exclude_hv
);
777 TEST_ASSERT_VAL("wrong exclude guest", !evsel
->attr
.exclude_guest
);
778 TEST_ASSERT_VAL("wrong exclude host", evsel
->attr
.exclude_host
);
779 TEST_ASSERT_VAL("wrong precise_ip", !evsel
->attr
.precise_ip
);
780 TEST_ASSERT_VAL("wrong leader", evsel
->leader
== leader
);
781 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel
) == 1);
782 TEST_ASSERT_VAL("wrong sample_read", !evsel
->sample_read
);
785 evsel
= perf_evsel__next(evsel
);
786 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE
== evsel
->attr
.type
);
787 TEST_ASSERT_VAL("wrong config",
788 PERF_COUNT_HW_INSTRUCTIONS
== evsel
->attr
.config
);
789 TEST_ASSERT_VAL("wrong exclude_user", !evsel
->attr
.exclude_user
);
790 TEST_ASSERT_VAL("wrong exclude_kernel", evsel
->attr
.exclude_kernel
);
791 TEST_ASSERT_VAL("wrong exclude_hv", evsel
->attr
.exclude_hv
);
792 TEST_ASSERT_VAL("wrong exclude guest", !evsel
->attr
.exclude_guest
);
793 TEST_ASSERT_VAL("wrong exclude host", !evsel
->attr
.exclude_host
);
794 TEST_ASSERT_VAL("wrong precise_ip", !evsel
->attr
.precise_ip
);
795 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel
));
796 TEST_ASSERT_VAL("wrong sample_read", !evsel
->sample_read
);
801 static int test__group4(struct perf_evlist
*evlist __maybe_unused
)
803 struct perf_evsel
*evsel
, *leader
;
805 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist
->nr_entries
);
806 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist
->nr_groups
);
809 evsel
= leader
= perf_evlist__first(evlist
);
810 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE
== evsel
->attr
.type
);
811 TEST_ASSERT_VAL("wrong config",
812 PERF_COUNT_HW_CPU_CYCLES
== evsel
->attr
.config
);
813 TEST_ASSERT_VAL("wrong exclude_user", !evsel
->attr
.exclude_user
);
814 TEST_ASSERT_VAL("wrong exclude_kernel", evsel
->attr
.exclude_kernel
);
815 TEST_ASSERT_VAL("wrong exclude_hv", evsel
->attr
.exclude_hv
);
816 /* use of precise requires exclude_guest */
817 TEST_ASSERT_VAL("wrong exclude guest", evsel
->attr
.exclude_guest
);
818 TEST_ASSERT_VAL("wrong exclude host", !evsel
->attr
.exclude_host
);
819 TEST_ASSERT_VAL("wrong precise_ip", evsel
->attr
.precise_ip
== 1);
820 TEST_ASSERT_VAL("wrong group name", !evsel
->group_name
);
821 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel
));
822 TEST_ASSERT_VAL("wrong nr_members", evsel
->nr_members
== 2);
823 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel
) == 0);
824 TEST_ASSERT_VAL("wrong sample_read", !evsel
->sample_read
);
826 /* instructions:kp + p */
827 evsel
= perf_evsel__next(evsel
);
828 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE
== evsel
->attr
.type
);
829 TEST_ASSERT_VAL("wrong config",
830 PERF_COUNT_HW_INSTRUCTIONS
== evsel
->attr
.config
);
831 TEST_ASSERT_VAL("wrong exclude_user", evsel
->attr
.exclude_user
);
832 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel
->attr
.exclude_kernel
);
833 TEST_ASSERT_VAL("wrong exclude_hv", evsel
->attr
.exclude_hv
);
834 /* use of precise requires exclude_guest */
835 TEST_ASSERT_VAL("wrong exclude guest", evsel
->attr
.exclude_guest
);
836 TEST_ASSERT_VAL("wrong exclude host", !evsel
->attr
.exclude_host
);
837 TEST_ASSERT_VAL("wrong precise_ip", evsel
->attr
.precise_ip
== 2);
838 TEST_ASSERT_VAL("wrong leader", evsel
->leader
== leader
);
839 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel
) == 1);
840 TEST_ASSERT_VAL("wrong sample_read", !evsel
->sample_read
);
845 static int test__group5(struct perf_evlist
*evlist __maybe_unused
)
847 struct perf_evsel
*evsel
, *leader
;
849 TEST_ASSERT_VAL("wrong number of entries", 5 == evlist
->nr_entries
);
850 TEST_ASSERT_VAL("wrong number of groups", 2 == evlist
->nr_groups
);
853 evsel
= leader
= perf_evlist__first(evlist
);
854 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE
== evsel
->attr
.type
);
855 TEST_ASSERT_VAL("wrong config",
856 PERF_COUNT_HW_CPU_CYCLES
== evsel
->attr
.config
);
857 TEST_ASSERT_VAL("wrong exclude_user", !evsel
->attr
.exclude_user
);
858 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel
->attr
.exclude_kernel
);
859 TEST_ASSERT_VAL("wrong exclude_hv", !evsel
->attr
.exclude_hv
);
860 TEST_ASSERT_VAL("wrong exclude guest", !evsel
->attr
.exclude_guest
);
861 TEST_ASSERT_VAL("wrong exclude host", evsel
->attr
.exclude_host
);
862 TEST_ASSERT_VAL("wrong precise_ip", !evsel
->attr
.precise_ip
);
863 TEST_ASSERT_VAL("wrong group name", !evsel
->group_name
);
864 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel
));
865 TEST_ASSERT_VAL("wrong nr_members", evsel
->nr_members
== 2);
866 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel
) == 0);
867 TEST_ASSERT_VAL("wrong sample_read", !evsel
->sample_read
);
869 /* instructions + G */
870 evsel
= perf_evsel__next(evsel
);
871 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE
== evsel
->attr
.type
);
872 TEST_ASSERT_VAL("wrong config",
873 PERF_COUNT_HW_INSTRUCTIONS
== evsel
->attr
.config
);
874 TEST_ASSERT_VAL("wrong exclude_user", !evsel
->attr
.exclude_user
);
875 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel
->attr
.exclude_kernel
);
876 TEST_ASSERT_VAL("wrong exclude_hv", !evsel
->attr
.exclude_hv
);
877 TEST_ASSERT_VAL("wrong exclude guest", !evsel
->attr
.exclude_guest
);
878 TEST_ASSERT_VAL("wrong exclude host", evsel
->attr
.exclude_host
);
879 TEST_ASSERT_VAL("wrong precise_ip", !evsel
->attr
.precise_ip
);
880 TEST_ASSERT_VAL("wrong leader", evsel
->leader
== leader
);
881 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel
) == 1);
882 TEST_ASSERT_VAL("wrong sample_read", !evsel
->sample_read
);
885 evsel
= leader
= perf_evsel__next(evsel
);
886 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE
== evsel
->attr
.type
);
887 TEST_ASSERT_VAL("wrong config",
888 PERF_COUNT_HW_CPU_CYCLES
== evsel
->attr
.config
);
889 TEST_ASSERT_VAL("wrong exclude_user", !evsel
->attr
.exclude_user
);
890 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel
->attr
.exclude_kernel
);
891 TEST_ASSERT_VAL("wrong exclude_hv", !evsel
->attr
.exclude_hv
);
892 TEST_ASSERT_VAL("wrong exclude guest", !evsel
->attr
.exclude_guest
);
893 TEST_ASSERT_VAL("wrong exclude host", evsel
->attr
.exclude_host
);
894 TEST_ASSERT_VAL("wrong precise_ip", !evsel
->attr
.precise_ip
);
895 TEST_ASSERT_VAL("wrong group name", !evsel
->group_name
);
896 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel
));
897 TEST_ASSERT_VAL("wrong nr_members", evsel
->nr_members
== 2);
898 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel
) == 0);
899 TEST_ASSERT_VAL("wrong sample_read", !evsel
->sample_read
);
902 evsel
= perf_evsel__next(evsel
);
903 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE
== evsel
->attr
.type
);
904 TEST_ASSERT_VAL("wrong config",
905 PERF_COUNT_HW_INSTRUCTIONS
== evsel
->attr
.config
);
906 TEST_ASSERT_VAL("wrong exclude_user", !evsel
->attr
.exclude_user
);
907 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel
->attr
.exclude_kernel
);
908 TEST_ASSERT_VAL("wrong exclude_hv", !evsel
->attr
.exclude_hv
);
909 TEST_ASSERT_VAL("wrong exclude guest", !evsel
->attr
.exclude_guest
);
910 TEST_ASSERT_VAL("wrong exclude host", evsel
->attr
.exclude_host
);
911 TEST_ASSERT_VAL("wrong precise_ip", !evsel
->attr
.precise_ip
);
912 TEST_ASSERT_VAL("wrong leader", evsel
->leader
== leader
);
913 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel
) == 1);
916 evsel
= perf_evsel__next(evsel
);
917 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE
== evsel
->attr
.type
);
918 TEST_ASSERT_VAL("wrong config",
919 PERF_COUNT_HW_CPU_CYCLES
== evsel
->attr
.config
);
920 TEST_ASSERT_VAL("wrong exclude_user", !evsel
->attr
.exclude_user
);
921 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel
->attr
.exclude_kernel
);
922 TEST_ASSERT_VAL("wrong exclude_hv", !evsel
->attr
.exclude_hv
);
923 TEST_ASSERT_VAL("wrong exclude guest", evsel
->attr
.exclude_guest
);
924 TEST_ASSERT_VAL("wrong exclude host", !evsel
->attr
.exclude_host
);
925 TEST_ASSERT_VAL("wrong precise_ip", !evsel
->attr
.precise_ip
);
926 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel
));
931 static int test__group_gh1(struct perf_evlist
*evlist
)
933 struct perf_evsel
*evsel
, *leader
;
935 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist
->nr_entries
);
936 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist
->nr_groups
);
938 /* cycles + :H group modifier */
939 evsel
= leader
= perf_evlist__first(evlist
);
940 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE
== evsel
->attr
.type
);
941 TEST_ASSERT_VAL("wrong config",
942 PERF_COUNT_HW_CPU_CYCLES
== evsel
->attr
.config
);
943 TEST_ASSERT_VAL("wrong exclude_user", !evsel
->attr
.exclude_user
);
944 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel
->attr
.exclude_kernel
);
945 TEST_ASSERT_VAL("wrong exclude_hv", !evsel
->attr
.exclude_hv
);
946 TEST_ASSERT_VAL("wrong exclude guest", evsel
->attr
.exclude_guest
);
947 TEST_ASSERT_VAL("wrong exclude host", !evsel
->attr
.exclude_host
);
948 TEST_ASSERT_VAL("wrong precise_ip", !evsel
->attr
.precise_ip
);
949 TEST_ASSERT_VAL("wrong group name", !evsel
->group_name
);
950 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel
));
951 TEST_ASSERT_VAL("wrong nr_members", evsel
->nr_members
== 2);
952 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel
) == 0);
954 /* cache-misses:G + :H group modifier */
955 evsel
= perf_evsel__next(evsel
);
956 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE
== evsel
->attr
.type
);
957 TEST_ASSERT_VAL("wrong config",
958 PERF_COUNT_HW_CACHE_MISSES
== evsel
->attr
.config
);
959 TEST_ASSERT_VAL("wrong exclude_user", !evsel
->attr
.exclude_user
);
960 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel
->attr
.exclude_kernel
);
961 TEST_ASSERT_VAL("wrong exclude_hv", !evsel
->attr
.exclude_hv
);
962 TEST_ASSERT_VAL("wrong exclude guest", !evsel
->attr
.exclude_guest
);
963 TEST_ASSERT_VAL("wrong exclude host", !evsel
->attr
.exclude_host
);
964 TEST_ASSERT_VAL("wrong precise_ip", !evsel
->attr
.precise_ip
);
965 TEST_ASSERT_VAL("wrong leader", evsel
->leader
== leader
);
966 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel
) == 1);
971 static int test__group_gh2(struct perf_evlist
*evlist
)
973 struct perf_evsel
*evsel
, *leader
;
975 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist
->nr_entries
);
976 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist
->nr_groups
);
978 /* cycles + :G group modifier */
979 evsel
= leader
= perf_evlist__first(evlist
);
980 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE
== evsel
->attr
.type
);
981 TEST_ASSERT_VAL("wrong config",
982 PERF_COUNT_HW_CPU_CYCLES
== evsel
->attr
.config
);
983 TEST_ASSERT_VAL("wrong exclude_user", !evsel
->attr
.exclude_user
);
984 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel
->attr
.exclude_kernel
);
985 TEST_ASSERT_VAL("wrong exclude_hv", !evsel
->attr
.exclude_hv
);
986 TEST_ASSERT_VAL("wrong exclude guest", !evsel
->attr
.exclude_guest
);
987 TEST_ASSERT_VAL("wrong exclude host", evsel
->attr
.exclude_host
);
988 TEST_ASSERT_VAL("wrong precise_ip", !evsel
->attr
.precise_ip
);
989 TEST_ASSERT_VAL("wrong group name", !evsel
->group_name
);
990 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel
));
991 TEST_ASSERT_VAL("wrong nr_members", evsel
->nr_members
== 2);
992 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel
) == 0);
994 /* cache-misses:H + :G group modifier */
995 evsel
= perf_evsel__next(evsel
);
996 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE
== evsel
->attr
.type
);
997 TEST_ASSERT_VAL("wrong config",
998 PERF_COUNT_HW_CACHE_MISSES
== evsel
->attr
.config
);
999 TEST_ASSERT_VAL("wrong exclude_user", !evsel
->attr
.exclude_user
);
1000 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel
->attr
.exclude_kernel
);
1001 TEST_ASSERT_VAL("wrong exclude_hv", !evsel
->attr
.exclude_hv
);
1002 TEST_ASSERT_VAL("wrong exclude guest", !evsel
->attr
.exclude_guest
);
1003 TEST_ASSERT_VAL("wrong exclude host", !evsel
->attr
.exclude_host
);
1004 TEST_ASSERT_VAL("wrong precise_ip", !evsel
->attr
.precise_ip
);
1005 TEST_ASSERT_VAL("wrong leader", evsel
->leader
== leader
);
1006 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel
) == 1);
1011 static int test__group_gh3(struct perf_evlist
*evlist
)
1013 struct perf_evsel
*evsel
, *leader
;
1015 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist
->nr_entries
);
1016 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist
->nr_groups
);
1018 /* cycles:G + :u group modifier */
1019 evsel
= leader
= perf_evlist__first(evlist
);
1020 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE
== evsel
->attr
.type
);
1021 TEST_ASSERT_VAL("wrong config",
1022 PERF_COUNT_HW_CPU_CYCLES
== evsel
->attr
.config
);
1023 TEST_ASSERT_VAL("wrong exclude_user", !evsel
->attr
.exclude_user
);
1024 TEST_ASSERT_VAL("wrong exclude_kernel", evsel
->attr
.exclude_kernel
);
1025 TEST_ASSERT_VAL("wrong exclude_hv", evsel
->attr
.exclude_hv
);
1026 TEST_ASSERT_VAL("wrong exclude guest", !evsel
->attr
.exclude_guest
);
1027 TEST_ASSERT_VAL("wrong exclude host", evsel
->attr
.exclude_host
);
1028 TEST_ASSERT_VAL("wrong precise_ip", !evsel
->attr
.precise_ip
);
1029 TEST_ASSERT_VAL("wrong group name", !evsel
->group_name
);
1030 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel
));
1031 TEST_ASSERT_VAL("wrong nr_members", evsel
->nr_members
== 2);
1032 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel
) == 0);
1034 /* cache-misses:H + :u group modifier */
1035 evsel
= perf_evsel__next(evsel
);
1036 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE
== evsel
->attr
.type
);
1037 TEST_ASSERT_VAL("wrong config",
1038 PERF_COUNT_HW_CACHE_MISSES
== evsel
->attr
.config
);
1039 TEST_ASSERT_VAL("wrong exclude_user", !evsel
->attr
.exclude_user
);
1040 TEST_ASSERT_VAL("wrong exclude_kernel", evsel
->attr
.exclude_kernel
);
1041 TEST_ASSERT_VAL("wrong exclude_hv", evsel
->attr
.exclude_hv
);
1042 TEST_ASSERT_VAL("wrong exclude guest", evsel
->attr
.exclude_guest
);
1043 TEST_ASSERT_VAL("wrong exclude host", !evsel
->attr
.exclude_host
);
1044 TEST_ASSERT_VAL("wrong precise_ip", !evsel
->attr
.precise_ip
);
1045 TEST_ASSERT_VAL("wrong leader", evsel
->leader
== leader
);
1046 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel
) == 1);
1051 static int test__group_gh4(struct perf_evlist
*evlist
)
1053 struct perf_evsel
*evsel
, *leader
;
1055 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist
->nr_entries
);
1056 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist
->nr_groups
);
1058 /* cycles:G + :uG group modifier */
1059 evsel
= leader
= perf_evlist__first(evlist
);
1060 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE
== evsel
->attr
.type
);
1061 TEST_ASSERT_VAL("wrong config",
1062 PERF_COUNT_HW_CPU_CYCLES
== evsel
->attr
.config
);
1063 TEST_ASSERT_VAL("wrong exclude_user", !evsel
->attr
.exclude_user
);
1064 TEST_ASSERT_VAL("wrong exclude_kernel", evsel
->attr
.exclude_kernel
);
1065 TEST_ASSERT_VAL("wrong exclude_hv", evsel
->attr
.exclude_hv
);
1066 TEST_ASSERT_VAL("wrong exclude guest", !evsel
->attr
.exclude_guest
);
1067 TEST_ASSERT_VAL("wrong exclude host", evsel
->attr
.exclude_host
);
1068 TEST_ASSERT_VAL("wrong precise_ip", !evsel
->attr
.precise_ip
);
1069 TEST_ASSERT_VAL("wrong group name", !evsel
->group_name
);
1070 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel
));
1071 TEST_ASSERT_VAL("wrong nr_members", evsel
->nr_members
== 2);
1072 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel
) == 0);
1074 /* cache-misses:H + :uG group modifier */
1075 evsel
= perf_evsel__next(evsel
);
1076 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE
== evsel
->attr
.type
);
1077 TEST_ASSERT_VAL("wrong config",
1078 PERF_COUNT_HW_CACHE_MISSES
== evsel
->attr
.config
);
1079 TEST_ASSERT_VAL("wrong exclude_user", !evsel
->attr
.exclude_user
);
1080 TEST_ASSERT_VAL("wrong exclude_kernel", evsel
->attr
.exclude_kernel
);
1081 TEST_ASSERT_VAL("wrong exclude_hv", evsel
->attr
.exclude_hv
);
1082 TEST_ASSERT_VAL("wrong exclude guest", !evsel
->attr
.exclude_guest
);
1083 TEST_ASSERT_VAL("wrong exclude host", !evsel
->attr
.exclude_host
);
1084 TEST_ASSERT_VAL("wrong precise_ip", !evsel
->attr
.precise_ip
);
1085 TEST_ASSERT_VAL("wrong leader", evsel
->leader
== leader
);
1086 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel
) == 1);
1091 static int test__leader_sample1(struct perf_evlist
*evlist
)
1093 struct perf_evsel
*evsel
, *leader
;
1095 TEST_ASSERT_VAL("wrong number of entries", 3 == evlist
->nr_entries
);
1097 /* cycles - sampling group leader */
1098 evsel
= leader
= perf_evlist__first(evlist
);
1099 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE
== evsel
->attr
.type
);
1100 TEST_ASSERT_VAL("wrong config",
1101 PERF_COUNT_HW_CPU_CYCLES
== evsel
->attr
.config
);
1102 TEST_ASSERT_VAL("wrong exclude_user", !evsel
->attr
.exclude_user
);
1103 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel
->attr
.exclude_kernel
);
1104 TEST_ASSERT_VAL("wrong exclude_hv", !evsel
->attr
.exclude_hv
);
1105 TEST_ASSERT_VAL("wrong exclude guest", evsel
->attr
.exclude_guest
);
1106 TEST_ASSERT_VAL("wrong exclude host", !evsel
->attr
.exclude_host
);
1107 TEST_ASSERT_VAL("wrong precise_ip", !evsel
->attr
.precise_ip
);
1108 TEST_ASSERT_VAL("wrong group name", !evsel
->group_name
);
1109 TEST_ASSERT_VAL("wrong leader", evsel
->leader
== leader
);
1110 TEST_ASSERT_VAL("wrong sample_read", evsel
->sample_read
);
1112 /* cache-misses - not sampling */
1113 evsel
= perf_evsel__next(evsel
);
1114 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE
== evsel
->attr
.type
);
1115 TEST_ASSERT_VAL("wrong config",
1116 PERF_COUNT_HW_CACHE_MISSES
== evsel
->attr
.config
);
1117 TEST_ASSERT_VAL("wrong exclude_user", !evsel
->attr
.exclude_user
);
1118 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel
->attr
.exclude_kernel
);
1119 TEST_ASSERT_VAL("wrong exclude_hv", !evsel
->attr
.exclude_hv
);
1120 TEST_ASSERT_VAL("wrong exclude guest", evsel
->attr
.exclude_guest
);
1121 TEST_ASSERT_VAL("wrong exclude host", !evsel
->attr
.exclude_host
);
1122 TEST_ASSERT_VAL("wrong precise_ip", !evsel
->attr
.precise_ip
);
1123 TEST_ASSERT_VAL("wrong leader", evsel
->leader
== leader
);
1124 TEST_ASSERT_VAL("wrong sample_read", evsel
->sample_read
);
1126 /* branch-misses - not sampling */
1127 evsel
= perf_evsel__next(evsel
);
1128 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE
== evsel
->attr
.type
);
1129 TEST_ASSERT_VAL("wrong config",
1130 PERF_COUNT_HW_BRANCH_MISSES
== evsel
->attr
.config
);
1131 TEST_ASSERT_VAL("wrong exclude_user", !evsel
->attr
.exclude_user
);
1132 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel
->attr
.exclude_kernel
);
1133 TEST_ASSERT_VAL("wrong exclude_hv", !evsel
->attr
.exclude_hv
);
1134 TEST_ASSERT_VAL("wrong exclude guest", evsel
->attr
.exclude_guest
);
1135 TEST_ASSERT_VAL("wrong exclude host", !evsel
->attr
.exclude_host
);
1136 TEST_ASSERT_VAL("wrong precise_ip", !evsel
->attr
.precise_ip
);
1137 TEST_ASSERT_VAL("wrong group name", !evsel
->group_name
);
1138 TEST_ASSERT_VAL("wrong leader", evsel
->leader
== leader
);
1139 TEST_ASSERT_VAL("wrong sample_read", evsel
->sample_read
);
1144 static int test__leader_sample2(struct perf_evlist
*evlist __maybe_unused
)
1146 struct perf_evsel
*evsel
, *leader
;
1148 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist
->nr_entries
);
1150 /* instructions - sampling group leader */
1151 evsel
= leader
= perf_evlist__first(evlist
);
1152 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE
== evsel
->attr
.type
);
1153 TEST_ASSERT_VAL("wrong config",
1154 PERF_COUNT_HW_INSTRUCTIONS
== evsel
->attr
.config
);
1155 TEST_ASSERT_VAL("wrong exclude_user", !evsel
->attr
.exclude_user
);
1156 TEST_ASSERT_VAL("wrong exclude_kernel", evsel
->attr
.exclude_kernel
);
1157 TEST_ASSERT_VAL("wrong exclude_hv", evsel
->attr
.exclude_hv
);
1158 TEST_ASSERT_VAL("wrong exclude guest", evsel
->attr
.exclude_guest
);
1159 TEST_ASSERT_VAL("wrong exclude host", !evsel
->attr
.exclude_host
);
1160 TEST_ASSERT_VAL("wrong precise_ip", !evsel
->attr
.precise_ip
);
1161 TEST_ASSERT_VAL("wrong group name", !evsel
->group_name
);
1162 TEST_ASSERT_VAL("wrong leader", evsel
->leader
== leader
);
1163 TEST_ASSERT_VAL("wrong sample_read", evsel
->sample_read
);
1165 /* branch-misses - not sampling */
1166 evsel
= perf_evsel__next(evsel
);
1167 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE
== evsel
->attr
.type
);
1168 TEST_ASSERT_VAL("wrong config",
1169 PERF_COUNT_HW_BRANCH_MISSES
== evsel
->attr
.config
);
1170 TEST_ASSERT_VAL("wrong exclude_user", !evsel
->attr
.exclude_user
);
1171 TEST_ASSERT_VAL("wrong exclude_kernel", evsel
->attr
.exclude_kernel
);
1172 TEST_ASSERT_VAL("wrong exclude_hv", evsel
->attr
.exclude_hv
);
1173 TEST_ASSERT_VAL("wrong exclude guest", evsel
->attr
.exclude_guest
);
1174 TEST_ASSERT_VAL("wrong exclude host", !evsel
->attr
.exclude_host
);
1175 TEST_ASSERT_VAL("wrong precise_ip", !evsel
->attr
.precise_ip
);
1176 TEST_ASSERT_VAL("wrong group name", !evsel
->group_name
);
1177 TEST_ASSERT_VAL("wrong leader", evsel
->leader
== leader
);
1178 TEST_ASSERT_VAL("wrong sample_read", evsel
->sample_read
);
1183 static int test__checkevent_pinned_modifier(struct perf_evlist
*evlist
)
1185 struct perf_evsel
*evsel
= perf_evlist__first(evlist
);
1187 TEST_ASSERT_VAL("wrong exclude_user", !evsel
->attr
.exclude_user
);
1188 TEST_ASSERT_VAL("wrong exclude_kernel", evsel
->attr
.exclude_kernel
);
1189 TEST_ASSERT_VAL("wrong exclude_hv", evsel
->attr
.exclude_hv
);
1190 TEST_ASSERT_VAL("wrong precise_ip", evsel
->attr
.precise_ip
);
1191 TEST_ASSERT_VAL("wrong pinned", evsel
->attr
.pinned
);
1193 return test__checkevent_symbolic_name(evlist
);
1196 static int test__pinned_group(struct perf_evlist
*evlist
)
1198 struct perf_evsel
*evsel
, *leader
;
1200 TEST_ASSERT_VAL("wrong number of entries", 3 == evlist
->nr_entries
);
1202 /* cycles - group leader */
1203 evsel
= leader
= perf_evlist__first(evlist
);
1204 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE
== evsel
->attr
.type
);
1205 TEST_ASSERT_VAL("wrong config",
1206 PERF_COUNT_HW_CPU_CYCLES
== evsel
->attr
.config
);
1207 TEST_ASSERT_VAL("wrong group name", !evsel
->group_name
);
1208 TEST_ASSERT_VAL("wrong leader", evsel
->leader
== leader
);
1209 TEST_ASSERT_VAL("wrong pinned", evsel
->attr
.pinned
);
1211 /* cache-misses - can not be pinned, but will go on with the leader */
1212 evsel
= perf_evsel__next(evsel
);
1213 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE
== evsel
->attr
.type
);
1214 TEST_ASSERT_VAL("wrong config",
1215 PERF_COUNT_HW_CACHE_MISSES
== evsel
->attr
.config
);
1216 TEST_ASSERT_VAL("wrong pinned", !evsel
->attr
.pinned
);
1218 /* branch-misses - ditto */
1219 evsel
= perf_evsel__next(evsel
);
1220 TEST_ASSERT_VAL("wrong config",
1221 PERF_COUNT_HW_BRANCH_MISSES
== evsel
->attr
.config
);
1222 TEST_ASSERT_VAL("wrong pinned", !evsel
->attr
.pinned
);
1227 static int test__checkevent_breakpoint_len(struct perf_evlist
*evlist
)
1229 struct perf_evsel
*evsel
= perf_evlist__first(evlist
);
1231 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist
->nr_entries
);
1232 TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT
== evsel
->attr
.type
);
1233 TEST_ASSERT_VAL("wrong config", 0 == evsel
->attr
.config
);
1234 TEST_ASSERT_VAL("wrong bp_type", (HW_BREAKPOINT_R
| HW_BREAKPOINT_W
) ==
1235 evsel
->attr
.bp_type
);
1236 TEST_ASSERT_VAL("wrong bp_len", HW_BREAKPOINT_LEN_1
==
1237 evsel
->attr
.bp_len
);
1242 static int test__checkevent_breakpoint_len_w(struct perf_evlist
*evlist
)
1244 struct perf_evsel
*evsel
= perf_evlist__first(evlist
);
1246 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist
->nr_entries
);
1247 TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT
== evsel
->attr
.type
);
1248 TEST_ASSERT_VAL("wrong config", 0 == evsel
->attr
.config
);
1249 TEST_ASSERT_VAL("wrong bp_type", HW_BREAKPOINT_W
==
1250 evsel
->attr
.bp_type
);
1251 TEST_ASSERT_VAL("wrong bp_len", HW_BREAKPOINT_LEN_2
==
1252 evsel
->attr
.bp_len
);
1258 test__checkevent_breakpoint_len_rw_modifier(struct perf_evlist
*evlist
)
1260 struct perf_evsel
*evsel
= perf_evlist__first(evlist
);
1262 TEST_ASSERT_VAL("wrong exclude_user", !evsel
->attr
.exclude_user
);
1263 TEST_ASSERT_VAL("wrong exclude_kernel", evsel
->attr
.exclude_kernel
);
1264 TEST_ASSERT_VAL("wrong exclude_hv", evsel
->attr
.exclude_hv
);
1265 TEST_ASSERT_VAL("wrong precise_ip", !evsel
->attr
.precise_ip
);
1267 return test__checkevent_breakpoint_rw(evlist
);
1270 static int test__checkevent_precise_max_modifier(struct perf_evlist
*evlist
)
1272 struct perf_evsel
*evsel
= perf_evlist__first(evlist
);
1274 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist
->nr_entries
);
1275 TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE
== evsel
->attr
.type
);
1276 TEST_ASSERT_VAL("wrong config",
1277 PERF_COUNT_SW_TASK_CLOCK
== evsel
->attr
.config
);
1281 static int test__checkevent_config_symbol(struct perf_evlist
*evlist
)
1283 struct perf_evsel
*evsel
= perf_evlist__first(evlist
);
1285 TEST_ASSERT_VAL("wrong name setting", strcmp(evsel
->name
, "insn") == 0);
1289 static int test__checkevent_config_raw(struct perf_evlist
*evlist
)
1291 struct perf_evsel
*evsel
= perf_evlist__first(evlist
);
1293 TEST_ASSERT_VAL("wrong name setting", strcmp(evsel
->name
, "rawpmu") == 0);
1297 static int test__checkevent_config_num(struct perf_evlist
*evlist
)
1299 struct perf_evsel
*evsel
= perf_evlist__first(evlist
);
1301 TEST_ASSERT_VAL("wrong name setting", strcmp(evsel
->name
, "numpmu") == 0);
1305 static int test__checkevent_config_cache(struct perf_evlist
*evlist
)
1307 struct perf_evsel
*evsel
= perf_evlist__first(evlist
);
1309 TEST_ASSERT_VAL("wrong name setting", strcmp(evsel
->name
, "cachepmu") == 0);
1313 static int count_tracepoints(void)
1315 struct dirent
*events_ent
;
1319 events_dir
= opendir(tracing_events_path
);
1321 TEST_ASSERT_VAL("Can't open events dir", events_dir
);
1323 while ((events_ent
= readdir(events_dir
))) {
1324 char sys_path
[PATH_MAX
];
1325 struct dirent
*sys_ent
;
1328 if (!strcmp(events_ent
->d_name
, ".")
1329 || !strcmp(events_ent
->d_name
, "..")
1330 || !strcmp(events_ent
->d_name
, "enable")
1331 || !strcmp(events_ent
->d_name
, "header_event")
1332 || !strcmp(events_ent
->d_name
, "header_page"))
1335 scnprintf(sys_path
, PATH_MAX
, "%s/%s",
1336 tracing_events_path
, events_ent
->d_name
);
1338 sys_dir
= opendir(sys_path
);
1339 TEST_ASSERT_VAL("Can't open sys dir", sys_dir
);
1341 while ((sys_ent
= readdir(sys_dir
))) {
1342 if (!strcmp(sys_ent
->d_name
, ".")
1343 || !strcmp(sys_ent
->d_name
, "..")
1344 || !strcmp(sys_ent
->d_name
, "enable")
1345 || !strcmp(sys_ent
->d_name
, "filter"))
1354 closedir(events_dir
);
1358 static int test__all_tracepoints(struct perf_evlist
*evlist
)
1360 TEST_ASSERT_VAL("wrong events count",
1361 count_tracepoints() == evlist
->nr_entries
);
1363 return test__checkevent_tracepoint_multi(evlist
);
1366 struct evlist_test
{
1370 int (*check
)(struct perf_evlist
*evlist
);
1373 static struct evlist_test test__events
[] = {
1375 .name
= "syscalls:sys_enter_openat",
1376 .check
= test__checkevent_tracepoint
,
1380 .name
= "syscalls:*",
1381 .check
= test__checkevent_tracepoint_multi
,
1386 .check
= test__checkevent_raw
,
1391 .check
= test__checkevent_numeric
,
1395 .name
= "instructions",
1396 .check
= test__checkevent_symbolic_name
,
1400 .name
= "cycles/period=100000,config2/",
1401 .check
= test__checkevent_symbolic_name_config
,
1406 .check
= test__checkevent_symbolic_alias
,
1410 .name
= "L1-dcache-load-miss",
1411 .check
= test__checkevent_genhw
,
1416 .check
= test__checkevent_breakpoint
,
1421 .check
= test__checkevent_breakpoint_x
,
1426 .check
= test__checkevent_breakpoint_r
,
1431 .check
= test__checkevent_breakpoint_w
,
1435 .name
= "syscalls:sys_enter_openat:k",
1436 .check
= test__checkevent_tracepoint_modifier
,
1440 .name
= "syscalls:*:u",
1441 .check
= test__checkevent_tracepoint_multi_modifier
,
1446 .check
= test__checkevent_raw_modifier
,
1451 .check
= test__checkevent_numeric_modifier
,
1455 .name
= "instructions:h",
1456 .check
= test__checkevent_symbolic_name_modifier
,
1461 .check
= test__checkevent_symbolic_alias_modifier
,
1465 .name
= "L1-dcache-load-miss:kp",
1466 .check
= test__checkevent_genhw_modifier
,
1471 .check
= test__checkevent_breakpoint_modifier
,
1475 .name
= "mem:0:x:k",
1476 .check
= test__checkevent_breakpoint_x_modifier
,
1480 .name
= "mem:0:r:hp",
1481 .check
= test__checkevent_breakpoint_r_modifier
,
1485 .name
= "mem:0:w:up",
1486 .check
= test__checkevent_breakpoint_w_modifier
,
1490 .name
= "r1,syscalls:sys_enter_openat:k,1:1:hp",
1491 .check
= test__checkevent_list
,
1495 .name
= "instructions:G",
1496 .check
= test__checkevent_exclude_host_modifier
,
1500 .name
= "instructions:H",
1501 .check
= test__checkevent_exclude_guest_modifier
,
1506 .check
= test__checkevent_breakpoint_rw
,
1510 .name
= "mem:0:rw:kp",
1511 .check
= test__checkevent_breakpoint_rw_modifier
,
1515 .name
= "{instructions:k,cycles:upp}",
1516 .check
= test__group1
,
1520 .name
= "{faults:k,cache-references}:u,cycles:k",
1521 .check
= test__group2
,
1525 .name
= "group1{syscalls:sys_enter_openat:H,cycles:kppp},group2{cycles,1:3}:G,instructions:u",
1526 .check
= test__group3
,
1530 .name
= "{cycles:u,instructions:kp}:p",
1531 .check
= test__group4
,
1535 .name
= "{cycles,instructions}:G,{cycles:G,instructions:G},cycles",
1536 .check
= test__group5
,
1541 .check
= test__all_tracepoints
,
1545 .name
= "{cycles,cache-misses:G}:H",
1546 .check
= test__group_gh1
,
1550 .name
= "{cycles,cache-misses:H}:G",
1551 .check
= test__group_gh2
,
1555 .name
= "{cycles:G,cache-misses:H}:u",
1556 .check
= test__group_gh3
,
1560 .name
= "{cycles:G,cache-misses:H}:uG",
1561 .check
= test__group_gh4
,
1565 .name
= "{cycles,cache-misses,branch-misses}:S",
1566 .check
= test__leader_sample1
,
1570 .name
= "{instructions,branch-misses}:Su",
1571 .check
= test__leader_sample2
,
1575 .name
= "instructions:uDp",
1576 .check
= test__checkevent_pinned_modifier
,
1580 .name
= "{cycles,cache-misses,branch-misses}:D",
1581 .check
= test__pinned_group
,
1586 .check
= test__checkevent_breakpoint_len
,
1590 .name
= "mem:0/2:w",
1591 .check
= test__checkevent_breakpoint_len_w
,
1595 .name
= "mem:0/4:rw:u",
1596 .check
= test__checkevent_breakpoint_len_rw_modifier
,
1599 #if defined(__s390x__)
1601 .name
= "kvm-s390:kvm_s390_create_vm",
1602 .check
= test__checkevent_tracepoint
,
1607 .name
= "instructions:I",
1608 .check
= test__checkevent_exclude_idle_modifier
,
1612 .name
= "instructions:kIG",
1613 .check
= test__checkevent_exclude_idle_modifier_1
,
1617 .name
= "task-clock:P,cycles",
1618 .check
= test__checkevent_precise_max_modifier
,
1622 .name
= "instructions/name=insn/",
1623 .check
= test__checkevent_config_symbol
,
1627 .name
= "r1234/name=rawpmu/",
1628 .check
= test__checkevent_config_raw
,
1632 .name
= "4:0x6530160/name=numpmu/",
1633 .check
= test__checkevent_config_num
,
1637 .name
= "L1-dcache-misses/name=cachepmu/",
1638 .check
= test__checkevent_config_cache
,
1643 static struct evlist_test test__events_pmu
[] = {
1645 .name
= "cpu/config=10,config1,config2=3,period=1000/u",
1646 .check
= test__checkevent_pmu
,
1650 .name
= "cpu/config=1,name=krava/u,cpu/config=2/u",
1651 .check
= test__checkevent_pmu_name
,
1655 .name
= "cpu/config=1,call-graph=fp,time,period=100000/,cpu/config=2,call-graph=no,time=0,period=2000/",
1656 .check
= test__checkevent_pmu_partial_time_callgraph
,
1664 int (*check
)(struct list_head
*terms
);
1667 static struct terms_test test__terms
[] = {
1669 .str
= "config=10,config1,config2=3,umask=1",
1670 .check
= test__checkterms_simple
,
1674 static int test_event(struct evlist_test
*e
)
1676 struct perf_evlist
*evlist
;
1679 evlist
= perf_evlist__new();
1683 ret
= parse_events(evlist
, e
->name
, NULL
);
1685 pr_debug("failed to parse event '%s', err %d\n",
1688 ret
= e
->check(evlist
);
1691 perf_evlist__delete(evlist
);
1696 static int test_events(struct evlist_test
*events
, unsigned cnt
)
1701 for (i
= 0; i
< cnt
; i
++) {
1702 struct evlist_test
*e
= &events
[i
];
1704 pr_debug("running test %d '%s'\n", e
->id
, e
->name
);
1705 ret1
= test_event(e
);
1713 static int test_term(struct terms_test
*t
)
1715 struct list_head terms
;
1718 INIT_LIST_HEAD(&terms
);
1720 ret
= parse_events_terms(&terms
, t
->str
);
1722 pr_debug("failed to parse terms '%s', err %d\n",
1727 ret
= t
->check(&terms
);
1728 parse_events_terms__purge(&terms
);
1733 static int test_terms(struct terms_test
*terms
, unsigned cnt
)
1738 for (i
= 0; i
< cnt
; i
++) {
1739 struct terms_test
*t
= &terms
[i
];
1741 pr_debug("running test %d '%s'\n", i
, t
->str
);
1750 static int test_pmu(void)
1753 char path
[PATH_MAX
];
1756 snprintf(path
, PATH_MAX
, "%s/bus/event_source/devices/cpu/format/",
1757 sysfs__mountpoint());
1759 ret
= stat(path
, &st
);
1761 pr_debug("omitting PMU cpu tests\n");
1765 static int test_pmu_events(void)
1768 char path
[PATH_MAX
];
1773 snprintf(path
, PATH_MAX
, "%s/bus/event_source/devices/cpu/events/",
1774 sysfs__mountpoint());
1776 ret
= stat(path
, &st
);
1778 pr_debug("omitting PMU cpu events tests\n");
1782 dir
= opendir(path
);
1784 pr_debug("can't open pmu event dir");
1788 while (!ret
&& (ent
= readdir(dir
))) {
1789 struct evlist_test e
;
1790 char name
[2 * NAME_MAX
+ 1 + 12 + 3];
1792 /* Names containing . are special and cannot be used directly */
1793 if (strchr(ent
->d_name
, '.'))
1796 snprintf(name
, sizeof(name
), "cpu/event=%s/u", ent
->d_name
);
1799 e
.check
= test__checkevent_pmu_events
;
1801 ret
= test_event(&e
);
1804 snprintf(name
, sizeof(name
), "%s:u,cpu/event=%s/u", ent
->d_name
, ent
->d_name
);
1806 e
.check
= test__checkevent_pmu_events_mix
;
1807 ret
= test_event(&e
);
1814 int test__parse_events(struct test
*test __maybe_unused
, int subtest __maybe_unused
)
1818 #define TEST_EVENTS(tests) \
1820 ret1 = test_events(tests, ARRAY_SIZE(tests)); \
1825 TEST_EVENTS(test__events
);
1828 TEST_EVENTS(test__events_pmu
);
1831 int ret
= test_pmu_events();
1836 ret1
= test_terms(test__terms
, ARRAY_SIZE(test__terms
));