1 // SPDX-License-Identifier: GPL-2.0
2 #include "parse-events.h"
13 #include <sys/types.h>
16 #include <linux/kernel.h>
17 #include <linux/hw_breakpoint.h>
18 #include <api/fs/tracing_path.h>
20 #define PERF_TP_SAMPLE_TYPE (PERF_SAMPLE_RAW | PERF_SAMPLE_TIME | \
21 PERF_SAMPLE_CPU | PERF_SAMPLE_PERIOD)
23 static bool test_config(const struct evsel *evsel, __u64 expected_config)
25 __u32 type = evsel->core.attr.type;
26 __u64 config = evsel->core.attr.config;
28 if (type == PERF_TYPE_HARDWARE || type == PERF_TYPE_HW_CACHE) {
30 * HARDWARE and HW_CACHE events encode the PMU's extended type
31 * in the top 32-bits. Mask in order to ignore.
33 config &= PERF_HW_EVENT_MASK;
35 return config == expected_config;
38 static bool test_perf_config(const struct perf_evsel *evsel, __u64 expected_config)
40 return (evsel->attr.config & PERF_HW_EVENT_MASK) == expected_config;
43 #ifdef HAVE_LIBTRACEEVENT
45 #if defined(__s390x__)
46 /* Return true if kvm module is available and loaded. Test this
47 * and return success when trace point kvm_s390_create_vm
48 * exists. Otherwise this test always fails.
50 static bool kvm_s390_create_vm_valid(void)
55 eventfile = get_events_file("kvm-s390");
58 DIR *mydir = opendir(eventfile);
64 put_events_file(eventfile);
71 static int test__checkevent_tracepoint(struct evlist *evlist)
73 struct evsel *evsel = evlist__first(evlist);
75 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
76 TEST_ASSERT_VAL("wrong number of groups", 0 == evlist__nr_groups(evlist));
77 TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->core.attr.type);
78 TEST_ASSERT_VAL("wrong sample_type",
79 PERF_TP_SAMPLE_TYPE == evsel->core.attr.sample_type);
80 TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->core.attr.sample_period);
84 static int test__checkevent_tracepoint_multi(struct evlist *evlist)
88 TEST_ASSERT_VAL("wrong number of entries", evlist->core.nr_entries > 1);
89 TEST_ASSERT_VAL("wrong number of groups", 0 == evlist__nr_groups(evlist));
91 evlist__for_each_entry(evlist, evsel) {
92 TEST_ASSERT_VAL("wrong type",
93 PERF_TYPE_TRACEPOINT == evsel->core.attr.type);
94 TEST_ASSERT_VAL("wrong sample_type",
95 PERF_TP_SAMPLE_TYPE == evsel->core.attr.sample_type);
96 TEST_ASSERT_VAL("wrong sample_period",
97 1 == evsel->core.attr.sample_period);
101 #endif /* HAVE_LIBTRACEEVENT */
103 static int test__checkevent_raw(struct evlist *evlist)
105 struct perf_evsel *evsel;
106 bool raw_type_match = false;
108 TEST_ASSERT_VAL("wrong number of entries", 0 != evlist->core.nr_entries);
110 perf_evlist__for_each_evsel(&evlist->core, evsel) {
111 struct perf_pmu *pmu;
112 bool type_matched = false;
114 TEST_ASSERT_VAL("wrong config", test_perf_config(evsel, 0x1a));
115 perf_pmus__for_each_pmu(pmu) {
116 if (pmu->type == evsel->attr.type) {
117 TEST_ASSERT_VAL("PMU type expected once", !type_matched);
119 if (pmu->type == PERF_TYPE_RAW)
120 raw_type_match = true;
123 TEST_ASSERT_VAL("No PMU found for type", type_matched);
125 TEST_ASSERT_VAL("Raw PMU not matched", raw_type_match);
129 static int test__checkevent_numeric(struct evlist *evlist)
131 struct evsel *evsel = evlist__first(evlist);
133 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
134 TEST_ASSERT_VAL("wrong type", 1 == evsel->core.attr.type);
135 TEST_ASSERT_VAL("wrong config", test_config(evsel, 1));
139 static int test__checkevent_symbolic_name(struct evlist *evlist)
141 struct perf_evsel *evsel;
143 TEST_ASSERT_VAL("wrong number of entries", 0 != evlist->core.nr_entries);
145 perf_evlist__for_each_evsel(&evlist->core, evsel) {
146 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
147 TEST_ASSERT_VAL("wrong config",
148 test_perf_config(evsel, PERF_COUNT_HW_INSTRUCTIONS));
153 static int test__checkevent_symbolic_name_config(struct evlist *evlist)
155 struct perf_evsel *evsel;
157 TEST_ASSERT_VAL("wrong number of entries", 0 != evlist->core.nr_entries);
159 perf_evlist__for_each_evsel(&evlist->core, evsel) {
160 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
161 TEST_ASSERT_VAL("wrong config", test_perf_config(evsel, PERF_COUNT_HW_CPU_CYCLES));
163 * The period value gets configured within evlist__config,
164 * while this test executes only parse events method.
166 TEST_ASSERT_VAL("wrong period", 0 == evsel->attr.sample_period);
167 TEST_ASSERT_VAL("wrong config1", 0 == evsel->attr.config1);
168 TEST_ASSERT_VAL("wrong config2", 1 == evsel->attr.config2);
173 static int test__checkevent_symbolic_alias(struct evlist *evlist)
175 struct evsel *evsel = evlist__first(evlist);
177 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
178 TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->core.attr.type);
179 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_SW_PAGE_FAULTS));
183 static int test__checkevent_genhw(struct evlist *evlist)
185 struct perf_evsel *evsel;
187 TEST_ASSERT_VAL("wrong number of entries", 0 != evlist->core.nr_entries);
189 perf_evlist__for_each_entry(&evlist->core, evsel) {
190 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HW_CACHE == evsel->attr.type);
191 TEST_ASSERT_VAL("wrong config", test_perf_config(evsel, 1 << 16));
196 static int test__checkevent_breakpoint(struct evlist *evlist)
198 struct evsel *evsel = evlist__first(evlist);
200 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
201 TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->core.attr.type);
202 TEST_ASSERT_VAL("wrong config", test_config(evsel, 0));
203 TEST_ASSERT_VAL("wrong bp_type", (HW_BREAKPOINT_R | HW_BREAKPOINT_W) ==
204 evsel->core.attr.bp_type);
205 TEST_ASSERT_VAL("wrong bp_len", HW_BREAKPOINT_LEN_4 ==
206 evsel->core.attr.bp_len);
210 static int test__checkevent_breakpoint_x(struct evlist *evlist)
212 struct evsel *evsel = evlist__first(evlist);
214 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
215 TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->core.attr.type);
216 TEST_ASSERT_VAL("wrong config", test_config(evsel, 0));
217 TEST_ASSERT_VAL("wrong bp_type",
218 HW_BREAKPOINT_X == evsel->core.attr.bp_type);
219 TEST_ASSERT_VAL("wrong bp_len", sizeof(long) == evsel->core.attr.bp_len);
223 static int test__checkevent_breakpoint_r(struct evlist *evlist)
225 struct evsel *evsel = evlist__first(evlist);
227 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
228 TEST_ASSERT_VAL("wrong type",
229 PERF_TYPE_BREAKPOINT == evsel->core.attr.type);
230 TEST_ASSERT_VAL("wrong config", test_config(evsel, 0));
231 TEST_ASSERT_VAL("wrong bp_type",
232 HW_BREAKPOINT_R == evsel->core.attr.bp_type);
233 TEST_ASSERT_VAL("wrong bp_len",
234 HW_BREAKPOINT_LEN_4 == evsel->core.attr.bp_len);
238 static int test__checkevent_breakpoint_w(struct evlist *evlist)
240 struct evsel *evsel = evlist__first(evlist);
242 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
243 TEST_ASSERT_VAL("wrong type",
244 PERF_TYPE_BREAKPOINT == evsel->core.attr.type);
245 TEST_ASSERT_VAL("wrong config", test_config(evsel, 0));
246 TEST_ASSERT_VAL("wrong bp_type",
247 HW_BREAKPOINT_W == evsel->core.attr.bp_type);
248 TEST_ASSERT_VAL("wrong bp_len",
249 HW_BREAKPOINT_LEN_4 == evsel->core.attr.bp_len);
253 static int test__checkevent_breakpoint_rw(struct evlist *evlist)
255 struct evsel *evsel = evlist__first(evlist);
257 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
258 TEST_ASSERT_VAL("wrong type",
259 PERF_TYPE_BREAKPOINT == evsel->core.attr.type);
260 TEST_ASSERT_VAL("wrong config", test_config(evsel, 0));
261 TEST_ASSERT_VAL("wrong bp_type",
262 (HW_BREAKPOINT_R|HW_BREAKPOINT_W) == evsel->core.attr.bp_type);
263 TEST_ASSERT_VAL("wrong bp_len",
264 HW_BREAKPOINT_LEN_4 == evsel->core.attr.bp_len);
268 #ifdef HAVE_LIBTRACEEVENT
269 static int test__checkevent_tracepoint_modifier(struct evlist *evlist)
271 struct evsel *evsel = evlist__first(evlist);
273 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
274 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
275 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
276 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
278 return test__checkevent_tracepoint(evlist);
282 test__checkevent_tracepoint_multi_modifier(struct evlist *evlist)
284 struct perf_evsel *evsel;
286 TEST_ASSERT_VAL("wrong number of entries", evlist->core.nr_entries > 1);
288 perf_evlist__for_each_entry(&evlist->core, evsel) {
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);
295 return test__checkevent_tracepoint_multi(evlist);
297 #endif /* HAVE_LIBTRACEEVENT */
299 static int test__checkevent_raw_modifier(struct evlist *evlist)
301 struct perf_evsel *evsel;
303 perf_evlist__for_each_entry(&evlist->core, evsel) {
304 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
305 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
306 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
307 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
309 return test__checkevent_raw(evlist);
312 static int test__checkevent_numeric_modifier(struct evlist *evlist)
314 struct perf_evsel *evsel;
316 perf_evlist__for_each_entry(&evlist->core, evsel) {
317 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
318 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
319 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
320 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
322 return test__checkevent_numeric(evlist);
325 static int test__checkevent_symbolic_name_modifier(struct evlist *evlist)
327 struct evsel *evsel = evlist__first(evlist);
329 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
330 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
331 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
332 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
334 return test__checkevent_symbolic_name(evlist);
337 static int test__checkevent_exclude_host_modifier(struct evlist *evlist)
339 struct perf_evsel *evsel;
341 perf_evlist__for_each_entry(&evlist->core, evsel) {
342 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
343 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
345 return test__checkevent_symbolic_name(evlist);
348 static int test__checkevent_exclude_guest_modifier(struct evlist *evlist)
350 struct perf_evsel *evsel;
352 perf_evlist__for_each_entry(&evlist->core, evsel) {
353 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
354 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
356 return test__checkevent_symbolic_name(evlist);
359 static int test__checkevent_symbolic_alias_modifier(struct evlist *evlist)
361 struct evsel *evsel = evlist__first(evlist);
363 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
364 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
365 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
366 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
368 return test__checkevent_symbolic_alias(evlist);
371 static int test__checkevent_genhw_modifier(struct evlist *evlist)
373 struct perf_evsel *evsel;
375 perf_evlist__for_each_entry(&evlist->core, evsel) {
376 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
377 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
378 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
379 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
381 return test__checkevent_genhw(evlist);
384 static int test__checkevent_exclude_idle_modifier(struct evlist *evlist)
386 struct evsel *evsel = evlist__first(evlist);
388 TEST_ASSERT_VAL("wrong exclude idle", evsel->core.attr.exclude_idle);
389 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
390 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
391 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
392 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
393 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
394 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
396 return test__checkevent_symbolic_name(evlist);
399 static int test__checkevent_exclude_idle_modifier_1(struct evlist *evlist)
401 struct evsel *evsel = evlist__first(evlist);
403 TEST_ASSERT_VAL("wrong exclude idle", evsel->core.attr.exclude_idle);
404 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
405 TEST_ASSERT_VAL("wrong exclude host", evsel->core.attr.exclude_host);
406 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
407 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
408 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
409 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
411 return test__checkevent_symbolic_name(evlist);
414 static int test__checkevent_breakpoint_modifier(struct evlist *evlist)
416 struct evsel *evsel = evlist__first(evlist);
419 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
420 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
421 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
422 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
423 TEST_ASSERT_VAL("wrong name",
424 !strcmp(evsel__name(evsel), "mem:0:u"));
426 return test__checkevent_breakpoint(evlist);
429 static int test__checkevent_breakpoint_x_modifier(struct evlist *evlist)
431 struct evsel *evsel = evlist__first(evlist);
433 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
434 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
435 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
436 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
437 TEST_ASSERT_VAL("wrong name",
438 !strcmp(evsel__name(evsel), "mem:0:x:k"));
440 return test__checkevent_breakpoint_x(evlist);
443 static int test__checkevent_breakpoint_r_modifier(struct evlist *evlist)
445 struct evsel *evsel = evlist__first(evlist);
447 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
448 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
449 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
450 TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip);
451 TEST_ASSERT_VAL("wrong name",
452 !strcmp(evsel__name(evsel), "mem:0:r:hp"));
454 return test__checkevent_breakpoint_r(evlist);
457 static int test__checkevent_breakpoint_w_modifier(struct evlist *evlist)
459 struct evsel *evsel = evlist__first(evlist);
461 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
462 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
463 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
464 TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip);
465 TEST_ASSERT_VAL("wrong name",
466 !strcmp(evsel__name(evsel), "mem:0:w:up"));
468 return test__checkevent_breakpoint_w(evlist);
471 static int test__checkevent_breakpoint_rw_modifier(struct evlist *evlist)
473 struct evsel *evsel = evlist__first(evlist);
475 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
476 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
477 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
478 TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip);
479 TEST_ASSERT_VAL("wrong name",
480 !strcmp(evsel__name(evsel), "mem:0:rw:kp"));
482 return test__checkevent_breakpoint_rw(evlist);
485 static int test__checkevent_pmu(struct evlist *evlist)
488 struct evsel *evsel = evlist__first(evlist);
490 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
491 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type);
492 TEST_ASSERT_VAL("wrong config", test_config(evsel, 10));
493 TEST_ASSERT_VAL("wrong config1", 1 == evsel->core.attr.config1);
494 TEST_ASSERT_VAL("wrong config2", 3 == evsel->core.attr.config2);
495 TEST_ASSERT_VAL("wrong config3", 0 == evsel->core.attr.config3);
497 * The period value gets configured within evlist__config,
498 * while this test executes only parse events method.
500 TEST_ASSERT_VAL("wrong period", 0 == evsel->core.attr.sample_period);
505 #ifdef HAVE_LIBTRACEEVENT
506 static int test__checkevent_list(struct evlist *evlist)
508 struct evsel *evsel = evlist__first(evlist);
510 TEST_ASSERT_VAL("wrong number of entries", 3 <= evlist->core.nr_entries);
513 TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT != evsel->core.attr.type);
514 while (evsel->core.attr.type != PERF_TYPE_TRACEPOINT) {
515 TEST_ASSERT_VAL("wrong config", test_config(evsel, 1));
516 TEST_ASSERT_VAL("wrong config1", 0 == evsel->core.attr.config1);
517 TEST_ASSERT_VAL("wrong config2", 0 == evsel->core.attr.config2);
518 TEST_ASSERT_VAL("wrong config3", 0 == evsel->core.attr.config3);
519 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
520 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
521 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
522 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
523 evsel = evsel__next(evsel);
526 /* syscalls:sys_enter_openat:k */
527 TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->core.attr.type);
528 TEST_ASSERT_VAL("wrong sample_type",
529 PERF_TP_SAMPLE_TYPE == evsel->core.attr.sample_type);
530 TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->core.attr.sample_period);
531 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
532 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
533 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
534 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
537 evsel = evsel__next(evsel);
538 TEST_ASSERT_VAL("wrong type", 1 == evsel->core.attr.type);
539 TEST_ASSERT_VAL("wrong config", test_config(evsel, 1));
540 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
541 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
542 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
543 TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip);
549 static int test__checkevent_pmu_name(struct evlist *evlist)
551 struct evsel *evsel = evlist__first(evlist);
553 /* cpu/config=1,name=krava/u */
554 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);
555 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type);
556 TEST_ASSERT_VAL("wrong config", test_config(evsel, 1));
557 TEST_ASSERT_VAL("wrong name", !strcmp(evsel__name(evsel), "krava"));
559 /* cpu/config=2/u" */
560 evsel = evsel__next(evsel);
561 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);
562 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type);
563 TEST_ASSERT_VAL("wrong config", test_config(evsel, 2));
564 TEST_ASSERT_VAL("wrong name",
565 !strcmp(evsel__name(evsel), "cpu/config=2/u"));
570 static int test__checkevent_pmu_partial_time_callgraph(struct evlist *evlist)
572 struct evsel *evsel = evlist__first(evlist);
574 /* cpu/config=1,call-graph=fp,time,period=100000/ */
575 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);
576 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type);
577 TEST_ASSERT_VAL("wrong config", test_config(evsel, 1));
579 * The period, time and callgraph value gets configured within evlist__config,
580 * while this test executes only parse events method.
582 TEST_ASSERT_VAL("wrong period", 0 == evsel->core.attr.sample_period);
583 TEST_ASSERT_VAL("wrong callgraph", !evsel__has_callchain(evsel));
584 TEST_ASSERT_VAL("wrong time", !(PERF_SAMPLE_TIME & evsel->core.attr.sample_type));
586 /* cpu/config=2,call-graph=no,time=0,period=2000/ */
587 evsel = evsel__next(evsel);
588 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type);
589 TEST_ASSERT_VAL("wrong config", test_config(evsel, 2));
591 * The period, time and callgraph value gets configured within evlist__config,
592 * while this test executes only parse events method.
594 TEST_ASSERT_VAL("wrong period", 0 == evsel->core.attr.sample_period);
595 TEST_ASSERT_VAL("wrong callgraph", !evsel__has_callchain(evsel));
596 TEST_ASSERT_VAL("wrong time", !(PERF_SAMPLE_TIME & evsel->core.attr.sample_type));
601 static int test__checkevent_pmu_events(struct evlist *evlist)
603 struct evsel *evsel = evlist__first(evlist);
605 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
606 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type ||
607 strcmp(evsel->pmu_name, "cpu"));
608 TEST_ASSERT_VAL("wrong exclude_user",
609 !evsel->core.attr.exclude_user);
610 TEST_ASSERT_VAL("wrong exclude_kernel",
611 evsel->core.attr.exclude_kernel);
612 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
613 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
614 TEST_ASSERT_VAL("wrong pinned", !evsel->core.attr.pinned);
615 TEST_ASSERT_VAL("wrong exclusive", !evsel->core.attr.exclusive);
621 static int test__checkevent_pmu_events_mix(struct evlist *evlist)
623 struct evsel *evsel = evlist__first(evlist);
626 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);
627 TEST_ASSERT_VAL("wrong exclude_user",
628 !evsel->core.attr.exclude_user);
629 TEST_ASSERT_VAL("wrong exclude_kernel",
630 evsel->core.attr.exclude_kernel);
631 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
632 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
633 TEST_ASSERT_VAL("wrong pinned", !evsel->core.attr.pinned);
634 TEST_ASSERT_VAL("wrong exclusive", !evsel->core.attr.exclusive);
637 evsel = evsel__next(evsel);
638 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);
639 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type ||
640 strcmp(evsel->pmu_name, "cpu"));
641 TEST_ASSERT_VAL("wrong exclude_user",
642 !evsel->core.attr.exclude_user);
643 TEST_ASSERT_VAL("wrong exclude_kernel",
644 evsel->core.attr.exclude_kernel);
645 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
646 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
647 TEST_ASSERT_VAL("wrong pinned", !evsel->core.attr.pinned);
648 TEST_ASSERT_VAL("wrong exclusive", !evsel->core.attr.pinned);
653 static int test__checkterms_simple(struct list_head *terms)
655 struct parse_events_term *term;
658 term = list_entry(terms->next, struct parse_events_term, list);
659 TEST_ASSERT_VAL("wrong type term",
660 term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG);
661 TEST_ASSERT_VAL("wrong type val",
662 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
663 TEST_ASSERT_VAL("wrong val", term->val.num == 10);
664 TEST_ASSERT_VAL("wrong config", !strcmp(term->config, "config"));
667 term = list_entry(term->list.next, struct parse_events_term, list);
668 TEST_ASSERT_VAL("wrong type term",
669 term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG1);
670 TEST_ASSERT_VAL("wrong type val",
671 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
672 TEST_ASSERT_VAL("wrong val", term->val.num == 1);
673 TEST_ASSERT_VAL("wrong config", !strcmp(term->config, "config1"));
676 term = list_entry(term->list.next, struct parse_events_term, list);
677 TEST_ASSERT_VAL("wrong type term",
678 term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG2);
679 TEST_ASSERT_VAL("wrong type val",
680 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
681 TEST_ASSERT_VAL("wrong val", term->val.num == 3);
682 TEST_ASSERT_VAL("wrong config", !strcmp(term->config, "config2"));
685 term = list_entry(term->list.next, struct parse_events_term, list);
686 TEST_ASSERT_VAL("wrong type term",
687 term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG3);
688 TEST_ASSERT_VAL("wrong type val",
689 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
690 TEST_ASSERT_VAL("wrong val", term->val.num == 4);
691 TEST_ASSERT_VAL("wrong config", !strcmp(term->config, "config3"));
694 term = list_entry(term->list.next, struct parse_events_term, list);
695 TEST_ASSERT_VAL("wrong type term",
696 term->type_term == PARSE_EVENTS__TERM_TYPE_USER);
697 TEST_ASSERT_VAL("wrong type val",
698 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
699 TEST_ASSERT_VAL("wrong val", term->val.num == 1);
700 TEST_ASSERT_VAL("wrong config", !strcmp(term->config, "umask"));
705 * The perf_pmu__test_parse_init injects 'read' term into
706 * perf_pmu_events_list, so 'read' is evaluated as read term
707 * and not as raw event with 'ead' hex value.
709 term = list_entry(term->list.next, struct parse_events_term, list);
710 TEST_ASSERT_VAL("wrong type term",
711 term->type_term == PARSE_EVENTS__TERM_TYPE_RAW);
712 TEST_ASSERT_VAL("wrong type val",
713 term->type_val == PARSE_EVENTS__TERM_TYPE_STR);
714 TEST_ASSERT_VAL("wrong val", !strcmp(term->val.str, "read"));
715 TEST_ASSERT_VAL("wrong config", !strcmp(term->config, "raw"));
720 * To be still able to pass 'ead' value with 'r' syntax,
721 * we added support to parse 'r0xHEX' event.
723 term = list_entry(term->list.next, struct parse_events_term, list);
724 TEST_ASSERT_VAL("wrong type term",
725 term->type_term == PARSE_EVENTS__TERM_TYPE_RAW);
726 TEST_ASSERT_VAL("wrong type val",
727 term->type_val == PARSE_EVENTS__TERM_TYPE_STR);
728 TEST_ASSERT_VAL("wrong val", !strcmp(term->val.str, "r0xead"));
729 TEST_ASSERT_VAL("wrong config", !strcmp(term->config, "raw"));
733 static int test__group1(struct evlist *evlist)
735 struct evsel *evsel, *leader;
737 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);
738 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist__nr_groups(evlist));
741 evsel = leader = evlist__first(evlist);
742 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
743 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_INSTRUCTIONS));
744 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
745 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
746 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
747 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
748 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
749 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
750 TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));
751 TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2);
752 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 0);
753 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
756 evsel = evsel__next(evsel);
757 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
758 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CPU_CYCLES));
759 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
760 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
761 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
762 /* use of precise requires exclude_guest */
763 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
764 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
765 TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip == 2);
766 TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));
767 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 1);
768 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
773 static int test__group2(struct evlist *evlist)
775 struct evsel *evsel, *leader;
777 TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->core.nr_entries);
778 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist__nr_groups(evlist));
780 /* faults + :ku modifier */
781 evsel = leader = evlist__first(evlist);
782 TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->core.attr.type);
783 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_SW_PAGE_FAULTS));
784 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
785 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
786 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
787 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
788 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
789 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
790 TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));
791 TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2);
792 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 0);
793 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
795 /* cache-references + :u modifier */
796 evsel = evsel__next(evsel);
797 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
798 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CACHE_REFERENCES));
799 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
800 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
801 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
802 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
803 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
804 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
805 TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));
806 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 1);
807 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
810 evsel = evsel__next(evsel);
811 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
812 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CPU_CYCLES));
813 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
814 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
815 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
816 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
817 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
818 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
819 TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));
820 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
825 #ifdef HAVE_LIBTRACEEVENT
826 static int test__group3(struct evlist *evlist __maybe_unused)
828 struct evsel *evsel, *leader;
830 TEST_ASSERT_VAL("wrong number of entries", 5 == evlist->core.nr_entries);
831 TEST_ASSERT_VAL("wrong number of groups", 2 == evlist__nr_groups(evlist));
833 /* group1 syscalls:sys_enter_openat:H */
834 evsel = leader = evlist__first(evlist);
835 TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->core.attr.type);
836 TEST_ASSERT_VAL("wrong sample_type",
837 PERF_TP_SAMPLE_TYPE == evsel->core.attr.sample_type);
838 TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->core.attr.sample_period);
839 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
840 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
841 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
842 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
843 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
844 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
845 TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));
846 TEST_ASSERT_VAL("wrong group name",
847 !strcmp(leader->group_name, "group1"));
848 TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2);
849 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 0);
850 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
852 /* group1 cycles:kppp */
853 evsel = evsel__next(evsel);
854 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
855 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CPU_CYCLES));
856 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
857 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
858 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
859 /* use of precise requires exclude_guest */
860 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
861 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
862 TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip == 3);
863 TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));
864 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
865 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 1);
866 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
868 /* group2 cycles + G modifier */
869 evsel = leader = evsel__next(evsel);
870 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
871 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CPU_CYCLES));
872 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
873 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
874 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
875 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
876 TEST_ASSERT_VAL("wrong exclude host", evsel->core.attr.exclude_host);
877 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
878 TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));
879 TEST_ASSERT_VAL("wrong group name",
880 !strcmp(leader->group_name, "group2"));
881 TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2);
882 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 0);
883 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
885 /* group2 1:3 + G modifier */
886 evsel = evsel__next(evsel);
887 TEST_ASSERT_VAL("wrong type", 1 == evsel->core.attr.type);
888 TEST_ASSERT_VAL("wrong config", test_config(evsel, 3));
889 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
890 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
891 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
892 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
893 TEST_ASSERT_VAL("wrong exclude host", evsel->core.attr.exclude_host);
894 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
895 TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));
896 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 1);
897 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
900 evsel = evsel__next(evsel);
901 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
902 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_INSTRUCTIONS));
903 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
904 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
905 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
906 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
907 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
908 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
909 TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));
910 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
916 static int test__group4(struct evlist *evlist __maybe_unused)
918 struct evsel *evsel, *leader;
920 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);
921 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist__nr_groups(evlist));
924 evsel = leader = evlist__first(evlist);
925 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
926 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CPU_CYCLES));
927 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
928 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
929 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
930 /* use of precise requires exclude_guest */
931 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
932 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
933 TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip == 1);
934 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
935 TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));
936 TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2);
937 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 0);
938 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
940 /* instructions:kp + p */
941 evsel = evsel__next(evsel);
942 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
943 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_INSTRUCTIONS));
944 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
945 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
946 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
947 /* use of precise requires exclude_guest */
948 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
949 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
950 TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip == 2);
951 TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));
952 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 1);
953 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
958 static int test__group5(struct evlist *evlist __maybe_unused)
960 struct evsel *evsel, *leader;
962 TEST_ASSERT_VAL("wrong number of entries", 5 == evlist->core.nr_entries);
963 TEST_ASSERT_VAL("wrong number of groups", 2 == evlist__nr_groups(evlist));
966 evsel = leader = evlist__first(evlist);
967 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
968 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CPU_CYCLES));
969 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
970 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
971 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
972 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
973 TEST_ASSERT_VAL("wrong exclude host", evsel->core.attr.exclude_host);
974 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
975 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
976 TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));
977 TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2);
978 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 0);
979 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
981 /* instructions + G */
982 evsel = evsel__next(evsel);
983 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
984 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_INSTRUCTIONS));
985 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
986 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
987 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
988 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
989 TEST_ASSERT_VAL("wrong exclude host", evsel->core.attr.exclude_host);
990 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
991 TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));
992 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 1);
993 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
996 evsel = leader = evsel__next(evsel);
997 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
998 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CPU_CYCLES));
999 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
1000 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
1001 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
1002 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
1003 TEST_ASSERT_VAL("wrong exclude host", evsel->core.attr.exclude_host);
1004 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1005 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1006 TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));
1007 TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2);
1008 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 0);
1009 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
1011 /* instructions:G */
1012 evsel = evsel__next(evsel);
1013 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1014 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_INSTRUCTIONS));
1015 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
1016 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
1017 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
1018 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
1019 TEST_ASSERT_VAL("wrong exclude host", evsel->core.attr.exclude_host);
1020 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1021 TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));
1022 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 1);
1025 evsel = evsel__next(evsel);
1026 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1027 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CPU_CYCLES));
1028 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
1029 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
1030 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
1031 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
1032 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
1033 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1034 TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));
1039 static int test__group_gh1(struct evlist *evlist)
1041 struct evsel *evsel, *leader;
1043 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);
1044 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist__nr_groups(evlist));
1046 /* cycles + :H group modifier */
1047 evsel = leader = evlist__first(evlist);
1048 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1049 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CPU_CYCLES));
1050 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
1051 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
1052 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
1053 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
1054 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
1055 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1056 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1057 TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));
1058 TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2);
1059 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 0);
1061 /* cache-misses:G + :H group modifier */
1062 evsel = evsel__next(evsel);
1063 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1064 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CACHE_MISSES));
1065 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
1066 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
1067 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
1068 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
1069 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
1070 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1071 TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));
1072 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 1);
1077 static int test__group_gh2(struct evlist *evlist)
1079 struct evsel *evsel, *leader;
1081 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);
1082 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist__nr_groups(evlist));
1084 /* cycles + :G group modifier */
1085 evsel = leader = evlist__first(evlist);
1086 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1087 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CPU_CYCLES));
1088 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
1089 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
1090 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
1091 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
1092 TEST_ASSERT_VAL("wrong exclude host", evsel->core.attr.exclude_host);
1093 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1094 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1095 TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));
1096 TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2);
1097 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 0);
1099 /* cache-misses:H + :G group modifier */
1100 evsel = evsel__next(evsel);
1101 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1102 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CACHE_MISSES));
1103 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
1104 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
1105 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
1106 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
1107 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
1108 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1109 TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));
1110 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 1);
1115 static int test__group_gh3(struct evlist *evlist)
1117 struct evsel *evsel, *leader;
1119 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);
1120 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist__nr_groups(evlist));
1122 /* cycles:G + :u group modifier */
1123 evsel = leader = evlist__first(evlist);
1124 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1125 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CPU_CYCLES));
1126 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
1127 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
1128 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
1129 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
1130 TEST_ASSERT_VAL("wrong exclude host", evsel->core.attr.exclude_host);
1131 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1132 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1133 TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));
1134 TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2);
1135 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 0);
1137 /* cache-misses:H + :u group modifier */
1138 evsel = evsel__next(evsel);
1139 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1140 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CACHE_MISSES));
1141 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
1142 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
1143 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
1144 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
1145 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
1146 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1147 TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));
1148 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 1);
1153 static int test__group_gh4(struct evlist *evlist)
1155 struct evsel *evsel, *leader;
1157 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);
1158 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist__nr_groups(evlist));
1160 /* cycles:G + :uG group modifier */
1161 evsel = leader = evlist__first(evlist);
1162 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1163 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CPU_CYCLES));
1164 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
1165 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
1166 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
1167 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
1168 TEST_ASSERT_VAL("wrong exclude host", evsel->core.attr.exclude_host);
1169 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1170 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1171 TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));
1172 TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2);
1173 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 0);
1175 /* cache-misses:H + :uG group modifier */
1176 evsel = evsel__next(evsel);
1177 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1178 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CACHE_MISSES));
1179 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
1180 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
1181 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
1182 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
1183 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
1184 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1185 TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));
1186 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 1);
1191 static int test__leader_sample1(struct evlist *evlist)
1193 struct evsel *evsel, *leader;
1195 TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->core.nr_entries);
1197 /* cycles - sampling group leader */
1198 evsel = leader = evlist__first(evlist);
1199 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1200 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CPU_CYCLES));
1201 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
1202 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
1203 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
1204 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
1205 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
1206 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1207 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1208 TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));
1209 TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read);
1211 /* cache-misses - not sampling */
1212 evsel = evsel__next(evsel);
1213 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1214 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CACHE_MISSES));
1215 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
1216 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
1217 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
1218 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
1219 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
1220 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1221 TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));
1222 TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read);
1224 /* branch-misses - not sampling */
1225 evsel = evsel__next(evsel);
1226 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1227 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_BRANCH_MISSES));
1228 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
1229 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
1230 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
1231 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
1232 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
1233 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1234 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1235 TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));
1236 TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read);
1241 static int test__leader_sample2(struct evlist *evlist __maybe_unused)
1243 struct evsel *evsel, *leader;
1245 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);
1247 /* instructions - sampling group leader */
1248 evsel = leader = evlist__first(evlist);
1249 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1250 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_INSTRUCTIONS));
1251 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
1252 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
1253 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
1254 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
1255 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
1256 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1257 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1258 TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));
1259 TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read);
1261 /* branch-misses - not sampling */
1262 evsel = evsel__next(evsel);
1263 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1264 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_BRANCH_MISSES));
1265 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
1266 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
1267 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
1268 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
1269 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
1270 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1271 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1272 TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));
1273 TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read);
1278 static int test__checkevent_pinned_modifier(struct evlist *evlist)
1280 struct evsel *evsel = evlist__first(evlist);
1282 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
1283 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
1284 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
1285 TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip);
1286 TEST_ASSERT_VAL("wrong pinned", evsel->core.attr.pinned);
1288 return test__checkevent_symbolic_name(evlist);
1291 static int test__pinned_group(struct evlist *evlist)
1293 struct evsel *evsel, *leader;
1295 TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->core.nr_entries);
1297 /* cycles - group leader */
1298 evsel = leader = evlist__first(evlist);
1299 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1300 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CPU_CYCLES));
1301 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1302 TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));
1303 TEST_ASSERT_VAL("wrong pinned", evsel->core.attr.pinned);
1305 /* cache-misses - can not be pinned, but will go on with the leader */
1306 evsel = evsel__next(evsel);
1307 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1308 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CACHE_MISSES));
1309 TEST_ASSERT_VAL("wrong pinned", !evsel->core.attr.pinned);
1311 /* branch-misses - ditto */
1312 evsel = evsel__next(evsel);
1313 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_BRANCH_MISSES));
1314 TEST_ASSERT_VAL("wrong pinned", !evsel->core.attr.pinned);
1319 static int test__checkevent_exclusive_modifier(struct evlist *evlist)
1321 struct evsel *evsel = evlist__first(evlist);
1323 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
1324 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
1325 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
1326 TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip);
1327 TEST_ASSERT_VAL("wrong exclusive", evsel->core.attr.exclusive);
1329 return test__checkevent_symbolic_name(evlist);
1332 static int test__exclusive_group(struct evlist *evlist)
1334 struct evsel *evsel, *leader;
1336 TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->core.nr_entries);
1338 /* cycles - group leader */
1339 evsel = leader = evlist__first(evlist);
1340 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1341 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CPU_CYCLES));
1342 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1343 TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));
1344 TEST_ASSERT_VAL("wrong exclusive", evsel->core.attr.exclusive);
1346 /* cache-misses - can not be pinned, but will go on with the leader */
1347 evsel = evsel__next(evsel);
1348 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1349 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CACHE_MISSES));
1350 TEST_ASSERT_VAL("wrong exclusive", !evsel->core.attr.exclusive);
1352 /* branch-misses - ditto */
1353 evsel = evsel__next(evsel);
1354 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_BRANCH_MISSES));
1355 TEST_ASSERT_VAL("wrong exclusive", !evsel->core.attr.exclusive);
1359 static int test__checkevent_breakpoint_len(struct evlist *evlist)
1361 struct evsel *evsel = evlist__first(evlist);
1363 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
1364 TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->core.attr.type);
1365 TEST_ASSERT_VAL("wrong config", test_config(evsel, 0));
1366 TEST_ASSERT_VAL("wrong bp_type", (HW_BREAKPOINT_R | HW_BREAKPOINT_W) ==
1367 evsel->core.attr.bp_type);
1368 TEST_ASSERT_VAL("wrong bp_len", HW_BREAKPOINT_LEN_1 ==
1369 evsel->core.attr.bp_len);
1374 static int test__checkevent_breakpoint_len_w(struct evlist *evlist)
1376 struct evsel *evsel = evlist__first(evlist);
1378 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
1379 TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->core.attr.type);
1380 TEST_ASSERT_VAL("wrong config", test_config(evsel, 0));
1381 TEST_ASSERT_VAL("wrong bp_type", HW_BREAKPOINT_W ==
1382 evsel->core.attr.bp_type);
1383 TEST_ASSERT_VAL("wrong bp_len", HW_BREAKPOINT_LEN_2 ==
1384 evsel->core.attr.bp_len);
1390 test__checkevent_breakpoint_len_rw_modifier(struct evlist *evlist)
1392 struct evsel *evsel = evlist__first(evlist);
1394 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
1395 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
1396 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
1397 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1399 return test__checkevent_breakpoint_rw(evlist);
1402 static int test__checkevent_precise_max_modifier(struct evlist *evlist)
1404 struct evsel *evsel = evlist__first(evlist);
1406 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);
1407 TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->core.attr.type);
1408 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_SW_TASK_CLOCK));
1412 static int test__checkevent_config_symbol(struct evlist *evlist)
1414 struct evsel *evsel = evlist__first(evlist);
1416 TEST_ASSERT_VAL("wrong name setting", evsel__name_is(evsel, "insn"));
1420 static int test__checkevent_config_raw(struct evlist *evlist)
1422 struct evsel *evsel = evlist__first(evlist);
1424 TEST_ASSERT_VAL("wrong name setting", evsel__name_is(evsel, "rawpmu"));
1428 static int test__checkevent_config_num(struct evlist *evlist)
1430 struct evsel *evsel = evlist__first(evlist);
1432 TEST_ASSERT_VAL("wrong name setting", evsel__name_is(evsel, "numpmu"));
1436 static int test__checkevent_config_cache(struct evlist *evlist)
1438 struct evsel *evsel = evlist__first(evlist);
1440 TEST_ASSERT_VAL("wrong name setting", evsel__name_is(evsel, "cachepmu"));
1441 return test__checkevent_genhw(evlist);
1444 static bool test__pmu_cpu_valid(void)
1446 return !!perf_pmu__find("cpu");
1449 static bool test__intel_pt_valid(void)
1451 return !!perf_pmu__find("intel_pt");
1454 static int test__intel_pt(struct evlist *evlist)
1456 struct evsel *evsel = evlist__first(evlist);
1458 TEST_ASSERT_VAL("wrong name setting", evsel__name_is(evsel, "intel_pt//u"));
1462 static int test__checkevent_complex_name(struct evlist *evlist)
1464 struct evsel *evsel = evlist__first(evlist);
1466 TEST_ASSERT_VAL("wrong complex name parsing",
1467 evsel__name_is(evsel,
1468 "COMPLEX_CYCLES_NAME:orig=cycles,desc=chip-clock-ticks"));
1472 static int test__checkevent_raw_pmu(struct evlist *evlist)
1474 struct evsel *evsel = evlist__first(evlist);
1476 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
1477 TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->core.attr.type);
1478 TEST_ASSERT_VAL("wrong config", test_config(evsel, 0x1a));
1482 static int test__sym_event_slash(struct evlist *evlist)
1484 struct evsel *evsel = evlist__first(evlist);
1486 TEST_ASSERT_VAL("wrong type", evsel->core.attr.type == PERF_TYPE_HARDWARE);
1487 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CPU_CYCLES));
1488 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
1492 static int test__sym_event_dc(struct evlist *evlist)
1494 struct evsel *evsel = evlist__first(evlist);
1496 TEST_ASSERT_VAL("wrong type", evsel->core.attr.type == PERF_TYPE_HARDWARE);
1497 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CPU_CYCLES));
1498 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
1502 #ifdef HAVE_LIBTRACEEVENT
1503 static int count_tracepoints(void)
1505 struct dirent *events_ent;
1509 events_dir = tracing_events__opendir();
1511 TEST_ASSERT_VAL("Can't open events dir", events_dir);
1513 while ((events_ent = readdir(events_dir))) {
1515 struct dirent *sys_ent;
1518 if (!strcmp(events_ent->d_name, ".")
1519 || !strcmp(events_ent->d_name, "..")
1520 || !strcmp(events_ent->d_name, "enable")
1521 || !strcmp(events_ent->d_name, "header_event")
1522 || !strcmp(events_ent->d_name, "header_page"))
1525 sys_path = get_events_file(events_ent->d_name);
1526 TEST_ASSERT_VAL("Can't get sys path", sys_path);
1528 sys_dir = opendir(sys_path);
1529 TEST_ASSERT_VAL("Can't open sys dir", sys_dir);
1531 while ((sys_ent = readdir(sys_dir))) {
1532 if (!strcmp(sys_ent->d_name, ".")
1533 || !strcmp(sys_ent->d_name, "..")
1534 || !strcmp(sys_ent->d_name, "enable")
1535 || !strcmp(sys_ent->d_name, "filter"))
1542 put_events_file(sys_path);
1545 closedir(events_dir);
1549 static int test__all_tracepoints(struct evlist *evlist)
1551 TEST_ASSERT_VAL("wrong events count",
1552 count_tracepoints() == evlist->core.nr_entries);
1554 return test__checkevent_tracepoint_multi(evlist);
1556 #endif /* HAVE_LIBTRACEVENT */
1558 struct evlist_test {
1560 bool (*valid)(void);
1561 int (*check)(struct evlist *evlist);
1564 static const struct evlist_test test__events[] = {
1565 #ifdef HAVE_LIBTRACEEVENT
1567 .name = "syscalls:sys_enter_openat",
1568 .check = test__checkevent_tracepoint,
1572 .name = "syscalls:*",
1573 .check = test__checkevent_tracepoint_multi,
1579 .check = test__checkevent_raw,
1584 .check = test__checkevent_numeric,
1588 .name = "instructions",
1589 .check = test__checkevent_symbolic_name,
1593 .name = "cycles/period=100000,config2/",
1594 .check = test__checkevent_symbolic_name_config,
1599 .check = test__checkevent_symbolic_alias,
1603 .name = "L1-dcache-load-miss",
1604 .check = test__checkevent_genhw,
1609 .check = test__checkevent_breakpoint,
1614 .check = test__checkevent_breakpoint_x,
1619 .check = test__checkevent_breakpoint_r,
1624 .check = test__checkevent_breakpoint_w,
1627 #ifdef HAVE_LIBTRACEEVENT
1629 .name = "syscalls:sys_enter_openat:k",
1630 .check = test__checkevent_tracepoint_modifier,
1634 .name = "syscalls:*:u",
1635 .check = test__checkevent_tracepoint_multi_modifier,
1641 .check = test__checkevent_raw_modifier,
1646 .check = test__checkevent_numeric_modifier,
1650 .name = "instructions:h",
1651 .check = test__checkevent_symbolic_name_modifier,
1656 .check = test__checkevent_symbolic_alias_modifier,
1660 .name = "L1-dcache-load-miss:kp",
1661 .check = test__checkevent_genhw_modifier,
1666 .check = test__checkevent_breakpoint_modifier,
1670 .name = "mem:0:x:k",
1671 .check = test__checkevent_breakpoint_x_modifier,
1675 .name = "mem:0:r:hp",
1676 .check = test__checkevent_breakpoint_r_modifier,
1680 .name = "mem:0:w:up",
1681 .check = test__checkevent_breakpoint_w_modifier,
1684 #ifdef HAVE_LIBTRACEEVENT
1686 .name = "r1,syscalls:sys_enter_openat:k,1:1:hp",
1687 .check = test__checkevent_list,
1692 .name = "instructions:G",
1693 .check = test__checkevent_exclude_host_modifier,
1697 .name = "instructions:H",
1698 .check = test__checkevent_exclude_guest_modifier,
1703 .check = test__checkevent_breakpoint_rw,
1707 .name = "mem:0:rw:kp",
1708 .check = test__checkevent_breakpoint_rw_modifier,
1712 .name = "{instructions:k,cycles:upp}",
1713 .check = test__group1,
1717 .name = "{faults:k,cache-references}:u,cycles:k",
1718 .check = test__group2,
1721 #ifdef HAVE_LIBTRACEEVENT
1723 .name = "group1{syscalls:sys_enter_openat:H,cycles:kppp},group2{cycles,1:3}:G,instructions:u",
1724 .check = test__group3,
1729 .name = "{cycles:u,instructions:kp}:p",
1730 .check = test__group4,
1734 .name = "{cycles,instructions}:G,{cycles:G,instructions:G},cycles",
1735 .check = test__group5,
1738 #ifdef HAVE_LIBTRACEEVENT
1741 .check = test__all_tracepoints,
1746 .name = "{cycles,cache-misses:G}:H",
1747 .check = test__group_gh1,
1751 .name = "{cycles,cache-misses:H}:G",
1752 .check = test__group_gh2,
1756 .name = "{cycles:G,cache-misses:H}:u",
1757 .check = test__group_gh3,
1761 .name = "{cycles:G,cache-misses:H}:uG",
1762 .check = test__group_gh4,
1766 .name = "{cycles,cache-misses,branch-misses}:S",
1767 .check = test__leader_sample1,
1771 .name = "{instructions,branch-misses}:Su",
1772 .check = test__leader_sample2,
1776 .name = "instructions:uDp",
1777 .check = test__checkevent_pinned_modifier,
1781 .name = "{cycles,cache-misses,branch-misses}:D",
1782 .check = test__pinned_group,
1787 .check = test__checkevent_breakpoint_len,
1791 .name = "mem:0/2:w",
1792 .check = test__checkevent_breakpoint_len_w,
1796 .name = "mem:0/4:rw:u",
1797 .check = test__checkevent_breakpoint_len_rw_modifier,
1800 #if defined(__s390x__) && defined(HAVE_LIBTRACEEVENT)
1802 .name = "kvm-s390:kvm_s390_create_vm",
1803 .check = test__checkevent_tracepoint,
1804 .valid = kvm_s390_create_vm_valid,
1809 .name = "instructions:I",
1810 .check = test__checkevent_exclude_idle_modifier,
1814 .name = "instructions:kIG",
1815 .check = test__checkevent_exclude_idle_modifier_1,
1819 .name = "task-clock:P,cycles",
1820 .check = test__checkevent_precise_max_modifier,
1824 .name = "instructions/name=insn/",
1825 .check = test__checkevent_config_symbol,
1829 .name = "r1234/name=rawpmu/",
1830 .check = test__checkevent_config_raw,
1834 .name = "4:0x6530160/name=numpmu/",
1835 .check = test__checkevent_config_num,
1839 .name = "L1-dcache-misses/name=cachepmu/",
1840 .check = test__checkevent_config_cache,
1844 .name = "intel_pt//u",
1845 .valid = test__intel_pt_valid,
1846 .check = test__intel_pt,
1850 .name = "cycles/name='COMPLEX_CYCLES_NAME:orig=cycles,desc=chip-clock-ticks'/Duk",
1851 .check = test__checkevent_complex_name,
1855 .name = "cycles//u",
1856 .check = test__sym_event_slash,
1861 .check = test__sym_event_dc,
1865 .name = "instructions:uep",
1866 .check = test__checkevent_exclusive_modifier,
1870 .name = "{cycles,cache-misses,branch-misses}:e",
1871 .check = test__exclusive_group,
1876 static const struct evlist_test test__events_pmu[] = {
1878 .name = "cpu/config=10,config1,config2=3,period=1000/u",
1879 .valid = test__pmu_cpu_valid,
1880 .check = test__checkevent_pmu,
1884 .name = "cpu/config=1,name=krava/u,cpu/config=2/u",
1885 .valid = test__pmu_cpu_valid,
1886 .check = test__checkevent_pmu_name,
1890 .name = "cpu/config=1,call-graph=fp,time,period=100000/,cpu/config=2,call-graph=no,time=0,period=2000/",
1891 .valid = test__pmu_cpu_valid,
1892 .check = test__checkevent_pmu_partial_time_callgraph,
1896 .name = "cpu/name='COMPLEX_CYCLES_NAME:orig=cycles,desc=chip-clock-ticks',period=0x1,event=0x2/ukp",
1897 .valid = test__pmu_cpu_valid,
1898 .check = test__checkevent_complex_name,
1902 .name = "software/r1a/",
1903 .check = test__checkevent_raw_pmu,
1907 .name = "software/r0x1a/",
1908 .check = test__checkevent_raw_pmu,
1912 .name = "cpu/L1-dcache-load-miss/",
1913 .valid = test__pmu_cpu_valid,
1914 .check = test__checkevent_genhw,
1918 .name = "cpu/L1-dcache-load-miss/kp",
1919 .valid = test__pmu_cpu_valid,
1920 .check = test__checkevent_genhw_modifier,
1924 .name = "cpu/L1-dcache-misses,name=cachepmu/",
1925 .valid = test__pmu_cpu_valid,
1926 .check = test__checkevent_config_cache,
1933 int (*check)(struct list_head *terms);
1936 static const struct terms_test test__terms[] = {
1938 .str = "config=10,config1,config2=3,config3=4,umask=1,read,r0xead",
1939 .check = test__checkterms_simple,
1943 static int test_event(const struct evlist_test *e)
1945 struct parse_events_error err;
1946 struct evlist *evlist;
1949 if (e->valid && !e->valid()) {
1950 pr_debug("... SKIP\n");
1954 evlist = evlist__new();
1955 if (evlist == NULL) {
1956 pr_err("Failed allocation");
1959 parse_events_error__init(&err);
1960 ret = parse_events(evlist, e->name, &err);
1962 pr_debug("failed to parse event '%s', err %d, str '%s'\n",
1963 e->name, ret, err.str);
1964 parse_events_error__print(&err, e->name);
1966 if (err.str && strstr(err.str, "can't access trace events"))
1969 ret = e->check(evlist);
1971 parse_events_error__exit(&err);
1972 evlist__delete(evlist);
1977 static int test_event_fake_pmu(const char *str)
1979 struct parse_events_error err;
1980 struct evlist *evlist;
1983 evlist = evlist__new();
1987 parse_events_error__init(&err);
1988 ret = __parse_events(evlist, str, /*pmu_filter=*/NULL, &err,
1989 &perf_pmu__fake, /*warn_if_reordered=*/true);
1991 pr_debug("failed to parse event '%s', err %d, str '%s'\n",
1993 parse_events_error__print(&err, str);
1996 parse_events_error__exit(&err);
1997 evlist__delete(evlist);
2002 static int combine_test_results(int existing, int latest)
2004 if (existing == TEST_FAIL)
2006 if (existing == TEST_SKIP)
2007 return latest == TEST_OK ? TEST_SKIP : latest;
2011 static int test_events(const struct evlist_test *events, int cnt)
2015 for (int i = 0; i < cnt; i++) {
2016 const struct evlist_test *e = &events[i];
2019 pr_debug("running test %d '%s'\n", i, e->name);
2020 test_ret = test_event(e);
2021 if (test_ret != TEST_OK) {
2022 pr_debug("Event test failure: test %d '%s'", i, e->name);
2023 ret = combine_test_results(ret, test_ret);
2030 static int test__events2(struct test_suite *test __maybe_unused, int subtest __maybe_unused)
2032 return test_events(test__events, ARRAY_SIZE(test__events));
2035 static int test_term(const struct terms_test *t)
2037 struct list_head terms;
2040 INIT_LIST_HEAD(&terms);
2042 ret = parse_events_terms(&terms, t->str);
2044 pr_debug("failed to parse terms '%s', err %d\n",
2049 ret = t->check(&terms);
2050 parse_events_terms__purge(&terms);
2055 static int test_terms(const struct terms_test *terms, int cnt)
2059 for (int i = 0; i < cnt; i++) {
2060 const struct terms_test *t = &terms[i];
2062 pr_debug("running test %d '%s'\n", i, t->str);
2071 static int test__terms2(struct test_suite *test __maybe_unused, int subtest __maybe_unused)
2073 return test_terms(test__terms, ARRAY_SIZE(test__terms));
2076 static int test__pmu_events(struct test_suite *test __maybe_unused, int subtest __maybe_unused)
2078 struct perf_pmu *pmu;
2081 if (list_empty(&pmus))
2082 perf_pmu__scan(NULL);
2084 perf_pmus__for_each_pmu(pmu) {
2086 char path[PATH_MAX];
2091 snprintf(path, PATH_MAX, "%s/bus/event_source/devices/%s/events/",
2092 sysfs__mountpoint(), pmu->name);
2094 err = stat(path, &st);
2096 pr_debug("skipping PMU %s events tests: %s\n", pmu->name, path);
2100 dir = opendir(path);
2102 pr_debug("can't open pmu event dir: %s\n", path);
2103 ret = combine_test_results(ret, TEST_SKIP);
2107 while ((ent = readdir(dir))) {
2108 struct evlist_test e = { .name = NULL, };
2109 char name[2 * NAME_MAX + 1 + 12 + 3];
2112 /* Names containing . are special and cannot be used directly */
2113 if (strchr(ent->d_name, '.'))
2116 snprintf(name, sizeof(name), "%s/event=%s/u", pmu->name, ent->d_name);
2119 e.check = test__checkevent_pmu_events;
2121 test_ret = test_event(&e);
2122 if (test_ret != TEST_OK) {
2123 pr_debug("Test PMU event failed for '%s'", name);
2124 ret = combine_test_results(ret, test_ret);
2127 if (!is_pmu_core(pmu->name))
2131 * Names containing '-' are recognized as prefixes and suffixes
2132 * due to '-' being a legacy PMU separator. This fails when the
2133 * prefix or suffix collides with an existing legacy token. For
2134 * example, branch-brs has a prefix (branch) that collides with
2135 * a PE_NAME_CACHE_TYPE token causing a parse error as a suffix
2136 * isn't expected after this. As event names in the config
2137 * slashes are allowed a '-' in the name we check this works
2140 if (strchr(ent->d_name, '-'))
2143 snprintf(name, sizeof(name), "%s:u,%s/event=%s/u",
2144 ent->d_name, pmu->name, ent->d_name);
2146 e.check = test__checkevent_pmu_events_mix;
2147 test_ret = test_event(&e);
2148 if (test_ret != TEST_OK) {
2149 pr_debug("Test PMU event failed for '%s'", name);
2150 ret = combine_test_results(ret, test_ret);
2159 static int test__pmu_events2(struct test_suite *test __maybe_unused, int subtest __maybe_unused)
2161 return test_events(test__events_pmu, ARRAY_SIZE(test__events_pmu));
2164 static bool test_alias(char **event, char **alias)
2166 char path[PATH_MAX];
2168 struct dirent *dent;
2169 const char *sysfs = sysfs__mountpoint();
2176 snprintf(path, PATH_MAX, "%s/bus/event_source/devices/", sysfs);
2177 dir = opendir(path);
2181 while ((dent = readdir(dir))) {
2182 if (!strcmp(dent->d_name, ".") ||
2183 !strcmp(dent->d_name, ".."))
2186 snprintf(path, PATH_MAX, "%s/bus/event_source/devices/%s/alias",
2187 sysfs, dent->d_name);
2189 if (!file_available(path))
2192 file = fopen(path, "r");
2196 if (!fgets(buf, sizeof(buf), file)) {
2201 /* Remove the last '\n' */
2202 buf[strlen(buf) - 1] = 0;
2205 *event = strdup(dent->d_name);
2206 *alias = strdup(buf);
2209 if (*event == NULL || *alias == NULL) {
2222 static int test__checkevent_pmu_events_alias(struct evlist *evlist)
2224 struct evsel *evsel1 = evlist__first(evlist);
2225 struct evsel *evsel2 = evlist__last(evlist);
2227 TEST_ASSERT_VAL("wrong type", evsel1->core.attr.type == evsel2->core.attr.type);
2228 TEST_ASSERT_VAL("wrong config", evsel1->core.attr.config == evsel2->core.attr.config);
2232 static int test__pmu_events_alias(char *event, char *alias)
2234 struct evlist_test e = { .name = NULL, };
2235 char name[2 * NAME_MAX + 20];
2237 snprintf(name, sizeof(name), "%s/event=1/,%s/event=1/",
2241 e.check = test__checkevent_pmu_events_alias;
2242 return test_event(&e);
2245 static int test__alias(struct test_suite *test __maybe_unused, int subtest __maybe_unused)
2247 char *event, *alias;
2250 if (!test_alias(&event, &alias))
2253 ret = test__pmu_events_alias(event, alias);
2260 static int test__pmu_events_alias2(struct test_suite *test __maybe_unused,
2261 int subtest __maybe_unused)
2263 static const char events[][30] = {
2269 for (unsigned int i = 0; i < ARRAY_SIZE(events); i++) {
2270 int test_ret = test_event_fake_pmu(&events[i][0]);
2272 if (test_ret != TEST_OK) {
2273 pr_debug("check_parse_fake %s failed\n", &events[i][0]);
2274 ret = combine_test_results(ret, test_ret);
2281 static struct test_case tests__parse_events[] = {
2282 TEST_CASE_REASON("Test event parsing",
2285 TEST_CASE_REASON("Parsing of all PMU events from sysfs",
2288 TEST_CASE_REASON("Parsing of given PMU events from sysfs",
2291 TEST_CASE_REASON("Parsing of aliased events from sysfs", alias,
2292 "no aliases in sysfs"),
2293 TEST_CASE("Parsing of aliased events", pmu_events_alias2),
2294 TEST_CASE("Parsing of terms (event modifiers)", terms2),
2298 struct test_suite suite__parse_events = {
2299 .desc = "Parse event definition strings",
2300 .test_cases = tests__parse_events,