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 int num_core_entries(void)
26 * If the kernel supports extended type, expect events to be
27 * opened once for each core PMU type. Otherwise fall back to the legacy
28 * behavior of opening only one event even though there are multiple
31 if (perf_pmus__supports_extended_type())
32 return perf_pmus__num_core_pmus();
37 static bool test_config(const struct evsel *evsel, __u64 expected_config)
39 __u32 type = evsel->core.attr.type;
40 __u64 config = evsel->core.attr.config;
42 if (type == PERF_TYPE_HARDWARE || type == PERF_TYPE_HW_CACHE) {
44 * HARDWARE and HW_CACHE events encode the PMU's extended type
45 * in the top 32-bits. Mask in order to ignore.
47 config &= PERF_HW_EVENT_MASK;
49 return config == expected_config;
52 static bool test_perf_config(const struct perf_evsel *evsel, __u64 expected_config)
54 return (evsel->attr.config & PERF_HW_EVENT_MASK) == expected_config;
57 #ifdef HAVE_LIBTRACEEVENT
59 #if defined(__s390x__)
60 /* Return true if kvm module is available and loaded. Test this
61 * and return success when trace point kvm_s390_create_vm
62 * exists. Otherwise this test always fails.
64 static bool kvm_s390_create_vm_valid(void)
69 eventfile = get_events_file("kvm-s390");
72 DIR *mydir = opendir(eventfile);
78 put_events_file(eventfile);
85 static int test__checkevent_tracepoint(struct evlist *evlist)
87 struct evsel *evsel = evlist__first(evlist);
89 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
90 TEST_ASSERT_VAL("wrong number of groups", 0 == evlist__nr_groups(evlist));
91 TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->core.attr.type);
92 TEST_ASSERT_VAL("wrong sample_type",
93 PERF_TP_SAMPLE_TYPE == evsel->core.attr.sample_type);
94 TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->core.attr.sample_period);
98 static int test__checkevent_tracepoint_multi(struct evlist *evlist)
102 TEST_ASSERT_VAL("wrong number of entries", evlist->core.nr_entries > 1);
103 TEST_ASSERT_VAL("wrong number of groups", 0 == evlist__nr_groups(evlist));
105 evlist__for_each_entry(evlist, evsel) {
106 TEST_ASSERT_VAL("wrong type",
107 PERF_TYPE_TRACEPOINT == evsel->core.attr.type);
108 TEST_ASSERT_VAL("wrong sample_type",
109 PERF_TP_SAMPLE_TYPE == evsel->core.attr.sample_type);
110 TEST_ASSERT_VAL("wrong sample_period",
111 1 == evsel->core.attr.sample_period);
115 #endif /* HAVE_LIBTRACEEVENT */
117 static int test__checkevent_raw(struct evlist *evlist)
119 struct perf_evsel *evsel;
120 bool raw_type_match = false;
122 TEST_ASSERT_VAL("wrong number of entries", 0 != evlist->core.nr_entries);
124 perf_evlist__for_each_evsel(&evlist->core, evsel) {
125 struct perf_pmu *pmu __maybe_unused = NULL;
126 bool type_matched = false;
128 TEST_ASSERT_VAL("wrong config", test_perf_config(evsel, 0x1a));
129 TEST_ASSERT_VAL("event not parsed as raw type",
130 evsel->attr.type == PERF_TYPE_RAW);
131 #if defined(__aarch64__)
133 * Arm doesn't have a real raw type PMU in sysfs, so raw events
134 * would never match any PMU. However, RAW events on Arm will
135 * always successfully open on the first available core PMU
136 * so no need to test for a matching type here.
138 type_matched = raw_type_match = true;
140 while ((pmu = perf_pmus__scan(pmu)) != NULL) {
141 if (pmu->type == evsel->attr.type) {
142 TEST_ASSERT_VAL("PMU type expected once", !type_matched);
144 if (pmu->type == PERF_TYPE_RAW)
145 raw_type_match = true;
149 TEST_ASSERT_VAL("No PMU found for type", type_matched);
151 TEST_ASSERT_VAL("Raw PMU not matched", raw_type_match);
155 static int test__checkevent_numeric(struct evlist *evlist)
157 struct evsel *evsel = evlist__first(evlist);
159 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
160 TEST_ASSERT_VAL("wrong type", 1 == evsel->core.attr.type);
161 TEST_ASSERT_VAL("wrong config", test_config(evsel, 1));
165 static int test__checkevent_symbolic_name(struct evlist *evlist)
167 struct perf_evsel *evsel;
169 TEST_ASSERT_VAL("wrong number of entries", 0 != evlist->core.nr_entries);
171 perf_evlist__for_each_evsel(&evlist->core, evsel) {
172 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
173 TEST_ASSERT_VAL("wrong config",
174 test_perf_config(evsel, PERF_COUNT_HW_INSTRUCTIONS));
179 static int test__checkevent_symbolic_name_config(struct evlist *evlist)
181 struct perf_evsel *evsel;
183 TEST_ASSERT_VAL("wrong number of entries", 0 != evlist->core.nr_entries);
185 perf_evlist__for_each_evsel(&evlist->core, evsel) {
186 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
187 TEST_ASSERT_VAL("wrong config", test_perf_config(evsel, PERF_COUNT_HW_CPU_CYCLES));
189 * The period value gets configured within evlist__config,
190 * while this test executes only parse events method.
192 TEST_ASSERT_VAL("wrong period", 0 == evsel->attr.sample_period);
193 TEST_ASSERT_VAL("wrong config1", 0 == evsel->attr.config1);
194 TEST_ASSERT_VAL("wrong config2", 1 == evsel->attr.config2);
199 static int test__checkevent_symbolic_alias(struct evlist *evlist)
201 struct evsel *evsel = evlist__first(evlist);
203 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
204 TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->core.attr.type);
205 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_SW_PAGE_FAULTS));
209 static int test__checkevent_genhw(struct evlist *evlist)
211 struct perf_evsel *evsel;
213 TEST_ASSERT_VAL("wrong number of entries", 0 != evlist->core.nr_entries);
215 perf_evlist__for_each_entry(&evlist->core, evsel) {
216 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HW_CACHE == evsel->attr.type);
217 TEST_ASSERT_VAL("wrong config", test_perf_config(evsel, 1 << 16));
222 static int test__checkevent_breakpoint(struct evlist *evlist)
224 struct evsel *evsel = evlist__first(evlist);
226 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
227 TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->core.attr.type);
228 TEST_ASSERT_VAL("wrong config", test_config(evsel, 0));
229 TEST_ASSERT_VAL("wrong bp_type", (HW_BREAKPOINT_R | HW_BREAKPOINT_W) ==
230 evsel->core.attr.bp_type);
231 TEST_ASSERT_VAL("wrong bp_len", HW_BREAKPOINT_LEN_4 ==
232 evsel->core.attr.bp_len);
236 static int test__checkevent_breakpoint_x(struct evlist *evlist)
238 struct evsel *evsel = evlist__first(evlist);
240 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
241 TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->core.attr.type);
242 TEST_ASSERT_VAL("wrong config", test_config(evsel, 0));
243 TEST_ASSERT_VAL("wrong bp_type",
244 HW_BREAKPOINT_X == evsel->core.attr.bp_type);
245 TEST_ASSERT_VAL("wrong bp_len", sizeof(long) == evsel->core.attr.bp_len);
249 static int test__checkevent_breakpoint_r(struct evlist *evlist)
251 struct evsel *evsel = evlist__first(evlist);
253 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
254 TEST_ASSERT_VAL("wrong type",
255 PERF_TYPE_BREAKPOINT == evsel->core.attr.type);
256 TEST_ASSERT_VAL("wrong config", test_config(evsel, 0));
257 TEST_ASSERT_VAL("wrong bp_type",
258 HW_BREAKPOINT_R == evsel->core.attr.bp_type);
259 TEST_ASSERT_VAL("wrong bp_len",
260 HW_BREAKPOINT_LEN_4 == evsel->core.attr.bp_len);
264 static int test__checkevent_breakpoint_w(struct evlist *evlist)
266 struct evsel *evsel = evlist__first(evlist);
268 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
269 TEST_ASSERT_VAL("wrong type",
270 PERF_TYPE_BREAKPOINT == evsel->core.attr.type);
271 TEST_ASSERT_VAL("wrong config", test_config(evsel, 0));
272 TEST_ASSERT_VAL("wrong bp_type",
273 HW_BREAKPOINT_W == evsel->core.attr.bp_type);
274 TEST_ASSERT_VAL("wrong bp_len",
275 HW_BREAKPOINT_LEN_4 == evsel->core.attr.bp_len);
279 static int test__checkevent_breakpoint_rw(struct evlist *evlist)
281 struct evsel *evsel = evlist__first(evlist);
283 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
284 TEST_ASSERT_VAL("wrong type",
285 PERF_TYPE_BREAKPOINT == evsel->core.attr.type);
286 TEST_ASSERT_VAL("wrong config", test_config(evsel, 0));
287 TEST_ASSERT_VAL("wrong bp_type",
288 (HW_BREAKPOINT_R|HW_BREAKPOINT_W) == evsel->core.attr.bp_type);
289 TEST_ASSERT_VAL("wrong bp_len",
290 HW_BREAKPOINT_LEN_4 == evsel->core.attr.bp_len);
294 #ifdef HAVE_LIBTRACEEVENT
295 static int test__checkevent_tracepoint_modifier(struct evlist *evlist)
297 struct evsel *evsel = evlist__first(evlist);
299 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
300 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
301 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
302 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
304 return test__checkevent_tracepoint(evlist);
308 test__checkevent_tracepoint_multi_modifier(struct evlist *evlist)
310 struct perf_evsel *evsel;
312 TEST_ASSERT_VAL("wrong number of entries", evlist->core.nr_entries > 1);
314 perf_evlist__for_each_entry(&evlist->core, evsel) {
315 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
316 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
317 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
318 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
321 return test__checkevent_tracepoint_multi(evlist);
323 #endif /* HAVE_LIBTRACEEVENT */
325 static int test__checkevent_raw_modifier(struct evlist *evlist)
327 struct perf_evsel *evsel;
329 perf_evlist__for_each_entry(&evlist->core, evsel) {
330 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
331 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
332 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
333 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
335 return test__checkevent_raw(evlist);
338 static int test__checkevent_numeric_modifier(struct evlist *evlist)
340 struct perf_evsel *evsel;
342 perf_evlist__for_each_entry(&evlist->core, evsel) {
343 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
344 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
345 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
346 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
348 return test__checkevent_numeric(evlist);
351 static int test__checkevent_symbolic_name_modifier(struct evlist *evlist)
353 struct perf_evsel *evsel;
355 TEST_ASSERT_VAL("wrong number of entries",
356 evlist->core.nr_entries == num_core_entries());
358 perf_evlist__for_each_entry(&evlist->core, evsel) {
359 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
360 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
361 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
362 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
364 return test__checkevent_symbolic_name(evlist);
367 static int test__checkevent_exclude_host_modifier(struct evlist *evlist)
369 struct perf_evsel *evsel;
371 perf_evlist__for_each_entry(&evlist->core, evsel) {
372 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
373 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
375 return test__checkevent_symbolic_name(evlist);
378 static int test__checkevent_exclude_guest_modifier(struct evlist *evlist)
380 struct perf_evsel *evsel;
382 perf_evlist__for_each_entry(&evlist->core, evsel) {
383 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
384 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
386 return test__checkevent_symbolic_name(evlist);
389 static int test__checkevent_symbolic_alias_modifier(struct evlist *evlist)
391 struct evsel *evsel = evlist__first(evlist);
393 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
394 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
395 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
396 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
398 return test__checkevent_symbolic_alias(evlist);
401 static int test__checkevent_genhw_modifier(struct evlist *evlist)
403 struct perf_evsel *evsel;
405 perf_evlist__for_each_entry(&evlist->core, evsel) {
406 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
407 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
408 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
409 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
411 return test__checkevent_genhw(evlist);
414 static int test__checkevent_exclude_idle_modifier(struct evlist *evlist)
416 struct evsel *evsel = evlist__first(evlist);
418 TEST_ASSERT_VAL("wrong exclude idle", evsel->core.attr.exclude_idle);
419 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
420 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
421 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
422 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
423 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
424 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
426 return test__checkevent_symbolic_name(evlist);
429 static int test__checkevent_exclude_idle_modifier_1(struct evlist *evlist)
431 struct evsel *evsel = evlist__first(evlist);
433 TEST_ASSERT_VAL("wrong exclude idle", evsel->core.attr.exclude_idle);
434 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
435 TEST_ASSERT_VAL("wrong exclude host", evsel->core.attr.exclude_host);
436 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
437 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
438 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
439 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
441 return test__checkevent_symbolic_name(evlist);
444 static int test__checkevent_breakpoint_modifier(struct evlist *evlist)
446 struct evsel *evsel = evlist__first(evlist);
449 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
450 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
451 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
452 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
453 TEST_ASSERT_VAL("wrong name",
454 !strcmp(evsel__name(evsel), "mem:0:u"));
456 return test__checkevent_breakpoint(evlist);
459 static int test__checkevent_breakpoint_x_modifier(struct evlist *evlist)
461 struct evsel *evsel = evlist__first(evlist);
463 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
464 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
465 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
466 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
467 TEST_ASSERT_VAL("wrong name",
468 !strcmp(evsel__name(evsel), "mem:0:x:k"));
470 return test__checkevent_breakpoint_x(evlist);
473 static int test__checkevent_breakpoint_r_modifier(struct evlist *evlist)
475 struct evsel *evsel = evlist__first(evlist);
477 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
478 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
479 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
480 TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip);
481 TEST_ASSERT_VAL("wrong name",
482 !strcmp(evsel__name(evsel), "mem:0:r:hp"));
484 return test__checkevent_breakpoint_r(evlist);
487 static int test__checkevent_breakpoint_w_modifier(struct evlist *evlist)
489 struct evsel *evsel = evlist__first(evlist);
491 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
492 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
493 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
494 TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip);
495 TEST_ASSERT_VAL("wrong name",
496 !strcmp(evsel__name(evsel), "mem:0:w:up"));
498 return test__checkevent_breakpoint_w(evlist);
501 static int test__checkevent_breakpoint_rw_modifier(struct evlist *evlist)
503 struct evsel *evsel = evlist__first(evlist);
505 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
506 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
507 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
508 TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip);
509 TEST_ASSERT_VAL("wrong name",
510 !strcmp(evsel__name(evsel), "mem:0:rw:kp"));
512 return test__checkevent_breakpoint_rw(evlist);
515 static int test__checkevent_breakpoint_modifier_name(struct evlist *evlist)
517 struct evsel *evsel = evlist__first(evlist);
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 TEST_ASSERT_VAL("wrong name",
524 !strcmp(evsel__name(evsel), "breakpoint"));
526 return test__checkevent_breakpoint(evlist);
529 static int test__checkevent_breakpoint_x_modifier_name(struct evlist *evlist)
531 struct evsel *evsel = evlist__first(evlist);
533 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
534 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
535 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
536 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
537 TEST_ASSERT_VAL("wrong name",
538 !strcmp(evsel__name(evsel), "breakpoint"));
540 return test__checkevent_breakpoint_x(evlist);
543 static int test__checkevent_breakpoint_r_modifier_name(struct evlist *evlist)
545 struct evsel *evsel = evlist__first(evlist);
547 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
548 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
549 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
550 TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip);
551 TEST_ASSERT_VAL("wrong name",
552 !strcmp(evsel__name(evsel), "breakpoint"));
554 return test__checkevent_breakpoint_r(evlist);
557 static int test__checkevent_breakpoint_w_modifier_name(struct evlist *evlist)
559 struct evsel *evsel = evlist__first(evlist);
561 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
562 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
563 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
564 TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip);
565 TEST_ASSERT_VAL("wrong name",
566 !strcmp(evsel__name(evsel), "breakpoint"));
568 return test__checkevent_breakpoint_w(evlist);
571 static int test__checkevent_breakpoint_rw_modifier_name(struct evlist *evlist)
573 struct evsel *evsel = evlist__first(evlist);
575 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
576 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
577 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
578 TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip);
579 TEST_ASSERT_VAL("wrong name",
580 !strcmp(evsel__name(evsel), "breakpoint"));
582 return test__checkevent_breakpoint_rw(evlist);
585 static int test__checkevent_breakpoint_2_events(struct evlist *evlist)
587 struct evsel *evsel = evlist__first(evlist);
589 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);
591 TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->core.attr.type);
592 TEST_ASSERT_VAL("wrong name", !strcmp(evsel__name(evsel), "breakpoint1"));
594 evsel = evsel__next(evsel);
596 TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->core.attr.type);
597 TEST_ASSERT_VAL("wrong name", !strcmp(evsel__name(evsel), "breakpoint2"));
602 static int test__checkevent_pmu(struct evlist *evlist)
605 struct evsel *evsel = evlist__first(evlist);
607 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
608 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type);
609 TEST_ASSERT_VAL("wrong config", test_config(evsel, 10));
610 TEST_ASSERT_VAL("wrong config1", 1 == evsel->core.attr.config1);
611 TEST_ASSERT_VAL("wrong config2", 3 == evsel->core.attr.config2);
612 TEST_ASSERT_VAL("wrong config3", 0 == evsel->core.attr.config3);
614 * The period value gets configured within evlist__config,
615 * while this test executes only parse events method.
617 TEST_ASSERT_VAL("wrong period", 0 == evsel->core.attr.sample_period);
622 #ifdef HAVE_LIBTRACEEVENT
623 static int test__checkevent_list(struct evlist *evlist)
625 struct evsel *evsel = evlist__first(evlist);
627 TEST_ASSERT_VAL("wrong number of entries", 3 <= evlist->core.nr_entries);
630 TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT != evsel->core.attr.type);
631 while (evsel->core.attr.type != PERF_TYPE_TRACEPOINT) {
632 TEST_ASSERT_VAL("wrong config", test_config(evsel, 1));
633 TEST_ASSERT_VAL("wrong config1", 0 == evsel->core.attr.config1);
634 TEST_ASSERT_VAL("wrong config2", 0 == evsel->core.attr.config2);
635 TEST_ASSERT_VAL("wrong config3", 0 == evsel->core.attr.config3);
636 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
637 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
638 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
639 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
640 evsel = evsel__next(evsel);
643 /* syscalls:sys_enter_openat:k */
644 TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->core.attr.type);
645 TEST_ASSERT_VAL("wrong sample_type",
646 PERF_TP_SAMPLE_TYPE == evsel->core.attr.sample_type);
647 TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->core.attr.sample_period);
648 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
649 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
650 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
651 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
654 evsel = evsel__next(evsel);
655 TEST_ASSERT_VAL("wrong type", 1 == evsel->core.attr.type);
656 TEST_ASSERT_VAL("wrong config", test_config(evsel, 1));
657 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
658 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
659 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
660 TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip);
666 static int test__checkevent_pmu_name(struct evlist *evlist)
668 struct evsel *evsel = evlist__first(evlist);
670 /* cpu/config=1,name=krava/u */
671 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);
672 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type);
673 TEST_ASSERT_VAL("wrong config", test_config(evsel, 1));
674 TEST_ASSERT_VAL("wrong name", !strcmp(evsel__name(evsel), "krava"));
676 /* cpu/config=2/u" */
677 evsel = evsel__next(evsel);
678 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);
679 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type);
680 TEST_ASSERT_VAL("wrong config", test_config(evsel, 2));
681 TEST_ASSERT_VAL("wrong name",
682 !strcmp(evsel__name(evsel), "cpu/config=2/u"));
687 static int test__checkevent_pmu_partial_time_callgraph(struct evlist *evlist)
689 struct evsel *evsel = evlist__first(evlist);
691 /* cpu/config=1,call-graph=fp,time,period=100000/ */
692 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);
693 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type);
694 TEST_ASSERT_VAL("wrong config", test_config(evsel, 1));
696 * The period, time and callgraph value gets configured within evlist__config,
697 * while this test executes only parse events method.
699 TEST_ASSERT_VAL("wrong period", 0 == evsel->core.attr.sample_period);
700 TEST_ASSERT_VAL("wrong callgraph", !evsel__has_callchain(evsel));
701 TEST_ASSERT_VAL("wrong time", !(PERF_SAMPLE_TIME & evsel->core.attr.sample_type));
703 /* cpu/config=2,call-graph=no,time=0,period=2000/ */
704 evsel = evsel__next(evsel);
705 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type);
706 TEST_ASSERT_VAL("wrong config", test_config(evsel, 2));
708 * The period, time and callgraph value gets configured within evlist__config,
709 * while this test executes only parse events method.
711 TEST_ASSERT_VAL("wrong period", 0 == evsel->core.attr.sample_period);
712 TEST_ASSERT_VAL("wrong callgraph", !evsel__has_callchain(evsel));
713 TEST_ASSERT_VAL("wrong time", !(PERF_SAMPLE_TIME & evsel->core.attr.sample_type));
718 static int test__checkevent_pmu_events(struct evlist *evlist)
720 struct evsel *evsel = evlist__first(evlist);
722 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
723 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type ||
724 strcmp(evsel->pmu_name, "cpu"));
725 TEST_ASSERT_VAL("wrong exclude_user",
726 !evsel->core.attr.exclude_user);
727 TEST_ASSERT_VAL("wrong exclude_kernel",
728 evsel->core.attr.exclude_kernel);
729 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
730 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
731 TEST_ASSERT_VAL("wrong pinned", !evsel->core.attr.pinned);
732 TEST_ASSERT_VAL("wrong exclusive", !evsel->core.attr.exclusive);
738 static int test__checkevent_pmu_events_mix(struct evlist *evlist)
740 struct evsel *evsel = NULL;
743 * The wild card event will be opened at least once, but it may be
744 * opened on each core PMU.
746 TEST_ASSERT_VAL("wrong number of entries", evlist->core.nr_entries >= 2);
747 for (int i = 0; i < evlist->core.nr_entries - 1; i++) {
748 evsel = (i == 0 ? evlist__first(evlist) : evsel__next(evsel));
750 TEST_ASSERT_VAL("wrong exclude_user",
751 !evsel->core.attr.exclude_user);
752 TEST_ASSERT_VAL("wrong exclude_kernel",
753 evsel->core.attr.exclude_kernel);
754 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
755 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
756 TEST_ASSERT_VAL("wrong pinned", !evsel->core.attr.pinned);
757 TEST_ASSERT_VAL("wrong exclusive", !evsel->core.attr.exclusive);
760 evsel = evsel__next(evsel);
761 TEST_ASSERT_VAL("wrong type", evsel__find_pmu(evsel)->is_core);
762 TEST_ASSERT_VAL("wrong exclude_user",
763 !evsel->core.attr.exclude_user);
764 TEST_ASSERT_VAL("wrong exclude_kernel",
765 evsel->core.attr.exclude_kernel);
766 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
767 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
768 TEST_ASSERT_VAL("wrong pinned", !evsel->core.attr.pinned);
769 TEST_ASSERT_VAL("wrong exclusive", !evsel->core.attr.pinned);
774 static int test__checkterms_simple(struct list_head *terms)
776 struct parse_events_term *term;
779 term = list_entry(terms->next, struct parse_events_term, list);
780 TEST_ASSERT_VAL("wrong type term",
781 term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG);
782 TEST_ASSERT_VAL("wrong type val",
783 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
784 TEST_ASSERT_VAL("wrong val", term->val.num == 10);
785 TEST_ASSERT_VAL("wrong config", !strcmp(term->config, "config"));
788 term = list_entry(term->list.next, struct parse_events_term, list);
789 TEST_ASSERT_VAL("wrong type term",
790 term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG1);
791 TEST_ASSERT_VAL("wrong type val",
792 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
793 TEST_ASSERT_VAL("wrong val", term->val.num == 1);
794 TEST_ASSERT_VAL("wrong config", !strcmp(term->config, "config1"));
797 term = list_entry(term->list.next, struct parse_events_term, list);
798 TEST_ASSERT_VAL("wrong type term",
799 term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG2);
800 TEST_ASSERT_VAL("wrong type val",
801 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
802 TEST_ASSERT_VAL("wrong val", term->val.num == 3);
803 TEST_ASSERT_VAL("wrong config", !strcmp(term->config, "config2"));
806 term = list_entry(term->list.next, struct parse_events_term, list);
807 TEST_ASSERT_VAL("wrong type term",
808 term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG3);
809 TEST_ASSERT_VAL("wrong type val",
810 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
811 TEST_ASSERT_VAL("wrong val", term->val.num == 4);
812 TEST_ASSERT_VAL("wrong config", !strcmp(term->config, "config3"));
815 term = list_entry(term->list.next, struct parse_events_term, list);
816 TEST_ASSERT_VAL("wrong type term",
817 term->type_term == PARSE_EVENTS__TERM_TYPE_USER);
818 TEST_ASSERT_VAL("wrong type val",
819 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
820 TEST_ASSERT_VAL("wrong val", term->val.num == 1);
821 TEST_ASSERT_VAL("wrong config", !strcmp(term->config, "umask"));
826 * The perf_pmu__test_parse_init injects 'read' term into
827 * perf_pmu_events_list, so 'read' is evaluated as read term
828 * and not as raw event with 'ead' hex value.
830 term = list_entry(term->list.next, struct parse_events_term, list);
831 TEST_ASSERT_VAL("wrong type term",
832 term->type_term == PARSE_EVENTS__TERM_TYPE_RAW);
833 TEST_ASSERT_VAL("wrong type val",
834 term->type_val == PARSE_EVENTS__TERM_TYPE_STR);
835 TEST_ASSERT_VAL("wrong val", !strcmp(term->val.str, "read"));
836 TEST_ASSERT_VAL("wrong config", !strcmp(term->config, "raw"));
841 * To be still able to pass 'ead' value with 'r' syntax,
842 * we added support to parse 'r0xHEX' event.
844 term = list_entry(term->list.next, struct parse_events_term, list);
845 TEST_ASSERT_VAL("wrong type term",
846 term->type_term == PARSE_EVENTS__TERM_TYPE_RAW);
847 TEST_ASSERT_VAL("wrong type val",
848 term->type_val == PARSE_EVENTS__TERM_TYPE_STR);
849 TEST_ASSERT_VAL("wrong val", !strcmp(term->val.str, "r0xead"));
850 TEST_ASSERT_VAL("wrong config", !strcmp(term->config, "raw"));
854 static int test__group1(struct evlist *evlist)
856 struct evsel *evsel, *leader;
858 TEST_ASSERT_VAL("wrong number of entries",
859 evlist->core.nr_entries == (num_core_entries() * 2));
860 TEST_ASSERT_VAL("wrong number of groups",
861 evlist__nr_groups(evlist) == num_core_entries());
863 for (int i = 0; i < num_core_entries(); i++) {
865 evsel = leader = (i == 0 ? evlist__first(evlist) : evsel__next(evsel));
866 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
867 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_INSTRUCTIONS));
868 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
869 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
870 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
871 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
872 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
873 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
874 TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));
875 TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2);
876 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 0);
877 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
880 evsel = evsel__next(evsel);
881 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
882 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CPU_CYCLES));
883 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
884 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
885 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
886 /* use of precise requires exclude_guest */
887 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
888 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
889 TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip == 2);
890 TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));
891 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 1);
892 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
897 static int test__group2(struct evlist *evlist)
899 struct evsel *evsel, *leader = NULL;
901 TEST_ASSERT_VAL("wrong number of entries",
902 evlist->core.nr_entries == (2 * num_core_entries() + 1));
904 * TODO: Currently the software event won't be grouped with the hardware
905 * event except for 1 PMU.
907 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist__nr_groups(evlist));
909 evlist__for_each_entry(evlist, evsel) {
910 if (evsel->core.attr.type == PERF_TYPE_SOFTWARE) {
911 /* faults + :ku modifier */
913 TEST_ASSERT_VAL("wrong config",
914 test_config(evsel, PERF_COUNT_SW_PAGE_FAULTS));
915 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
916 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
917 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
918 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
919 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
920 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
921 TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));
922 TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2);
923 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 0);
924 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
927 if (evsel->core.attr.type == PERF_TYPE_HARDWARE &&
928 test_config(evsel, PERF_COUNT_HW_CACHE_REFERENCES)) {
929 /* cache-references + :u modifier */
930 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
931 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
932 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
933 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
934 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
935 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
936 if (evsel__has_leader(evsel, leader))
937 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 1);
938 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
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_CPU_CYCLES));
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 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
948 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
949 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
950 TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));
951 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
956 #ifdef HAVE_LIBTRACEEVENT
957 static int test__group3(struct evlist *evlist __maybe_unused)
959 struct evsel *evsel, *group1_leader = NULL, *group2_leader = NULL;
961 TEST_ASSERT_VAL("wrong number of entries",
962 evlist->core.nr_entries == (3 * perf_pmus__num_core_pmus() + 2));
964 * Currently the software event won't be grouped with the hardware event
965 * except for 1 PMU. This means there are always just 2 groups
966 * regardless of the number of core PMUs.
968 TEST_ASSERT_VAL("wrong number of groups", 2 == evlist__nr_groups(evlist));
970 evlist__for_each_entry(evlist, evsel) {
971 if (evsel->core.attr.type == PERF_TYPE_TRACEPOINT) {
972 /* group1 syscalls:sys_enter_openat:H */
973 group1_leader = evsel;
974 TEST_ASSERT_VAL("wrong sample_type",
975 evsel->core.attr.sample_type == PERF_TP_SAMPLE_TYPE);
976 TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->core.attr.sample_period);
977 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
978 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
979 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
980 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
981 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
982 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
983 TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));
984 TEST_ASSERT_VAL("wrong group name", !strcmp(evsel->group_name, "group1"));
985 TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2);
986 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 0);
987 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
990 if (evsel->core.attr.type == PERF_TYPE_HARDWARE &&
991 test_config(evsel, PERF_COUNT_HW_CPU_CYCLES)) {
992 if (evsel->core.attr.exclude_user) {
993 /* group1 cycles:kppp */
994 TEST_ASSERT_VAL("wrong exclude_user",
995 evsel->core.attr.exclude_user);
996 TEST_ASSERT_VAL("wrong exclude_kernel",
997 !evsel->core.attr.exclude_kernel);
998 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
999 /* use of precise requires exclude_guest */
1000 TEST_ASSERT_VAL("wrong exclude guest",
1001 evsel->core.attr.exclude_guest);
1002 TEST_ASSERT_VAL("wrong exclude host",
1003 !evsel->core.attr.exclude_host);
1004 TEST_ASSERT_VAL("wrong precise_ip",
1005 evsel->core.attr.precise_ip == 3);
1006 if (evsel__has_leader(evsel, group1_leader)) {
1007 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1008 TEST_ASSERT_VAL("wrong group_idx",
1009 evsel__group_idx(evsel) == 1);
1011 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
1013 /* group2 cycles + G modifier */
1014 group2_leader = evsel;
1015 TEST_ASSERT_VAL("wrong exclude_kernel",
1016 !evsel->core.attr.exclude_kernel);
1017 TEST_ASSERT_VAL("wrong exclude_hv",
1018 !evsel->core.attr.exclude_hv);
1019 TEST_ASSERT_VAL("wrong exclude guest",
1020 !evsel->core.attr.exclude_guest);
1021 TEST_ASSERT_VAL("wrong exclude host",
1022 evsel->core.attr.exclude_host);
1023 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1024 TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));
1025 if (evsel->core.nr_members == 2) {
1026 TEST_ASSERT_VAL("wrong group_idx",
1027 evsel__group_idx(evsel) == 0);
1029 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
1033 if (evsel->core.attr.type == 1) {
1034 /* group2 1:3 + G modifier */
1035 TEST_ASSERT_VAL("wrong config", test_config(evsel, 3));
1036 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
1037 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
1038 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
1039 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
1040 TEST_ASSERT_VAL("wrong exclude host", evsel->core.attr.exclude_host);
1041 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1042 if (evsel__has_leader(evsel, group2_leader))
1043 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 1);
1044 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
1047 /* instructions:u */
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_INSTRUCTIONS));
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 leader", evsel__is_group_leader(evsel));
1057 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
1063 static int test__group4(struct evlist *evlist __maybe_unused)
1065 struct evsel *evsel, *leader;
1067 TEST_ASSERT_VAL("wrong number of entries",
1068 evlist->core.nr_entries == (num_core_entries() * 2));
1069 TEST_ASSERT_VAL("wrong number of groups",
1070 num_core_entries() == evlist__nr_groups(evlist));
1072 for (int i = 0; i < num_core_entries(); i++) {
1074 evsel = leader = (i == 0 ? evlist__first(evlist) : evsel__next(evsel));
1075 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1076 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CPU_CYCLES));
1077 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
1078 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
1079 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
1080 /* use of precise requires exclude_guest */
1081 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
1082 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
1083 TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip == 1);
1084 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1085 TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));
1086 TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2);
1087 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 0);
1088 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
1090 /* instructions:kp + p */
1091 evsel = evsel__next(evsel);
1092 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1093 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_INSTRUCTIONS));
1094 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
1095 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
1096 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
1097 /* use of precise requires exclude_guest */
1098 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
1099 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
1100 TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip == 2);
1101 TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));
1102 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 1);
1103 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
1108 static int test__group5(struct evlist *evlist __maybe_unused)
1110 struct evsel *evsel = NULL, *leader;
1112 TEST_ASSERT_VAL("wrong number of entries",
1113 evlist->core.nr_entries == (5 * num_core_entries()));
1114 TEST_ASSERT_VAL("wrong number of groups",
1115 evlist__nr_groups(evlist) == (2 * num_core_entries()));
1117 for (int i = 0; i < num_core_entries(); i++) {
1119 evsel = leader = (i == 0 ? evlist__first(evlist) : evsel__next(evsel));
1120 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1121 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CPU_CYCLES));
1122 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
1123 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
1124 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
1125 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
1126 TEST_ASSERT_VAL("wrong exclude host", evsel->core.attr.exclude_host);
1127 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1128 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1129 TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));
1130 TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2);
1131 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 0);
1132 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
1134 /* instructions + G */
1135 evsel = evsel__next(evsel);
1136 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1137 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_INSTRUCTIONS));
1138 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
1139 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
1140 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
1141 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
1142 TEST_ASSERT_VAL("wrong exclude host", evsel->core.attr.exclude_host);
1143 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1144 TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));
1145 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 1);
1146 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
1148 for (int i = 0; i < num_core_entries(); i++) {
1150 evsel = leader = evsel__next(evsel);
1151 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1152 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CPU_CYCLES));
1153 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
1154 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
1155 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
1156 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
1157 TEST_ASSERT_VAL("wrong exclude host", evsel->core.attr.exclude_host);
1158 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1159 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1160 TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));
1161 TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2);
1162 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 0);
1163 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
1165 /* instructions:G */
1166 evsel = evsel__next(evsel);
1167 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1168 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_INSTRUCTIONS));
1169 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
1170 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
1171 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
1172 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
1173 TEST_ASSERT_VAL("wrong exclude host", evsel->core.attr.exclude_host);
1174 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1175 TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));
1176 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 1);
1178 for (int i = 0; i < num_core_entries(); i++) {
1180 evsel = evsel__next(evsel);
1181 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1182 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CPU_CYCLES));
1183 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
1184 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
1185 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
1186 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
1187 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
1188 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1189 TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));
1194 static int test__group_gh1(struct evlist *evlist)
1196 struct evsel *evsel = NULL, *leader;
1198 TEST_ASSERT_VAL("wrong number of entries",
1199 evlist->core.nr_entries == (2 * num_core_entries()));
1200 TEST_ASSERT_VAL("wrong number of groups",
1201 evlist__nr_groups(evlist) == num_core_entries());
1203 for (int i = 0; i < num_core_entries(); i++) {
1204 /* cycles + :H group modifier */
1205 evsel = leader = (i == 0 ? evlist__first(evlist) : evsel__next(evsel));
1206 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1207 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CPU_CYCLES));
1208 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
1209 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
1210 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
1211 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
1212 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
1213 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1214 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1215 TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));
1216 TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2);
1217 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 0);
1219 /* cache-misses:G + :H group modifier */
1220 evsel = evsel__next(evsel);
1221 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1222 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CACHE_MISSES));
1223 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
1224 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
1225 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
1226 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
1227 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
1228 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1229 TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));
1230 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 1);
1235 static int test__group_gh2(struct evlist *evlist)
1237 struct evsel *evsel = NULL, *leader;
1239 TEST_ASSERT_VAL("wrong number of entries",
1240 evlist->core.nr_entries == (2 * num_core_entries()));
1241 TEST_ASSERT_VAL("wrong number of groups",
1242 evlist__nr_groups(evlist) == num_core_entries());
1244 for (int i = 0; i < num_core_entries(); i++) {
1245 /* cycles + :G group modifier */
1246 evsel = leader = (i == 0 ? evlist__first(evlist) : evsel__next(evsel));
1247 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1248 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CPU_CYCLES));
1249 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
1250 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
1251 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
1252 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
1253 TEST_ASSERT_VAL("wrong exclude host", evsel->core.attr.exclude_host);
1254 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1255 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1256 TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));
1257 TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2);
1258 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 0);
1260 /* cache-misses:H + :G group modifier */
1261 evsel = evsel__next(evsel);
1262 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1263 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CACHE_MISSES));
1264 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
1265 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
1266 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
1267 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
1268 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
1269 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1270 TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));
1271 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 1);
1276 static int test__group_gh3(struct evlist *evlist)
1278 struct evsel *evsel = NULL, *leader;
1280 TEST_ASSERT_VAL("wrong number of entries",
1281 evlist->core.nr_entries == (2 * num_core_entries()));
1282 TEST_ASSERT_VAL("wrong number of groups",
1283 evlist__nr_groups(evlist) == num_core_entries());
1285 for (int i = 0; i < num_core_entries(); i++) {
1286 /* cycles:G + :u group modifier */
1287 evsel = leader = (i == 0 ? evlist__first(evlist) : evsel__next(evsel));
1288 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1289 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CPU_CYCLES));
1290 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
1291 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
1292 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
1293 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
1294 TEST_ASSERT_VAL("wrong exclude host", evsel->core.attr.exclude_host);
1295 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1296 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1297 TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));
1298 TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2);
1299 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 0);
1301 /* cache-misses:H + :u group modifier */
1302 evsel = evsel__next(evsel);
1303 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1304 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CACHE_MISSES));
1305 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
1306 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
1307 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
1308 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
1309 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
1310 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1311 TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));
1312 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 1);
1317 static int test__group_gh4(struct evlist *evlist)
1319 struct evsel *evsel = NULL, *leader;
1321 TEST_ASSERT_VAL("wrong number of entries",
1322 evlist->core.nr_entries == (2 * num_core_entries()));
1323 TEST_ASSERT_VAL("wrong number of groups",
1324 evlist__nr_groups(evlist) == num_core_entries());
1326 for (int i = 0; i < num_core_entries(); i++) {
1327 /* cycles:G + :uG group modifier */
1328 evsel = leader = (i == 0 ? evlist__first(evlist) : evsel__next(evsel));
1329 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1330 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CPU_CYCLES));
1331 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
1332 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
1333 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
1334 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
1335 TEST_ASSERT_VAL("wrong exclude host", evsel->core.attr.exclude_host);
1336 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1337 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1338 TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));
1339 TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2);
1340 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 0);
1342 /* cache-misses:H + :uG group modifier */
1343 evsel = evsel__next(evsel);
1344 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1345 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CACHE_MISSES));
1346 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
1347 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
1348 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
1349 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
1350 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
1351 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1352 TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));
1353 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 1);
1358 static int test__leader_sample1(struct evlist *evlist)
1360 struct evsel *evsel = NULL, *leader;
1362 TEST_ASSERT_VAL("wrong number of entries",
1363 evlist->core.nr_entries == (3 * num_core_entries()));
1365 for (int i = 0; i < num_core_entries(); i++) {
1366 /* cycles - sampling group leader */
1367 evsel = leader = (i == 0 ? evlist__first(evlist) : evsel__next(evsel));
1368 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1369 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CPU_CYCLES));
1370 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
1371 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
1372 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
1373 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
1374 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
1375 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1376 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1377 TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));
1378 TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read);
1380 /* cache-misses - not sampling */
1381 evsel = evsel__next(evsel);
1382 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1383 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CACHE_MISSES));
1384 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
1385 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
1386 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
1387 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
1388 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
1389 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1390 TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));
1391 TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read);
1393 /* branch-misses - not sampling */
1394 evsel = evsel__next(evsel);
1395 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1396 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_BRANCH_MISSES));
1397 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
1398 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
1399 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
1400 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
1401 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
1402 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1403 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1404 TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));
1405 TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read);
1410 static int test__leader_sample2(struct evlist *evlist __maybe_unused)
1412 struct evsel *evsel = NULL, *leader;
1414 TEST_ASSERT_VAL("wrong number of entries",
1415 evlist->core.nr_entries == (2 * num_core_entries()));
1417 for (int i = 0; i < num_core_entries(); i++) {
1418 /* instructions - sampling group leader */
1419 evsel = leader = (i == 0 ? evlist__first(evlist) : evsel__next(evsel));
1420 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1421 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_INSTRUCTIONS));
1422 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
1423 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
1424 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
1425 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
1426 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
1427 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1428 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1429 TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));
1430 TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read);
1432 /* branch-misses - not sampling */
1433 evsel = evsel__next(evsel);
1434 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1435 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_BRANCH_MISSES));
1436 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
1437 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
1438 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
1439 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
1440 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
1441 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1442 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1443 TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));
1444 TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read);
1449 static int test__checkevent_pinned_modifier(struct evlist *evlist)
1451 struct evsel *evsel = NULL;
1453 TEST_ASSERT_VAL("wrong number of entries",
1454 evlist->core.nr_entries == num_core_entries());
1456 for (int i = 0; i < num_core_entries(); i++) {
1457 evsel = (i == 0 ? evlist__first(evlist) : evsel__next(evsel));
1458 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
1459 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
1460 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
1461 TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip);
1462 TEST_ASSERT_VAL("wrong pinned", evsel->core.attr.pinned);
1464 return test__checkevent_symbolic_name(evlist);
1467 static int test__pinned_group(struct evlist *evlist)
1469 struct evsel *evsel = NULL, *leader;
1471 TEST_ASSERT_VAL("wrong number of entries",
1472 evlist->core.nr_entries == (3 * num_core_entries()));
1474 for (int i = 0; i < num_core_entries(); i++) {
1475 /* cycles - group leader */
1476 evsel = leader = (i == 0 ? evlist__first(evlist) : evsel__next(evsel));
1477 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1478 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CPU_CYCLES));
1479 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1480 TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));
1481 /* TODO: The group modifier is not copied to the split group leader. */
1482 if (perf_pmus__num_core_pmus() == 1)
1483 TEST_ASSERT_VAL("wrong pinned", evsel->core.attr.pinned);
1485 /* cache-misses - can not be pinned, but will go on with the leader */
1486 evsel = evsel__next(evsel);
1487 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1488 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CACHE_MISSES));
1489 TEST_ASSERT_VAL("wrong pinned", !evsel->core.attr.pinned);
1491 /* branch-misses - ditto */
1492 evsel = evsel__next(evsel);
1493 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_BRANCH_MISSES));
1494 TEST_ASSERT_VAL("wrong pinned", !evsel->core.attr.pinned);
1499 static int test__checkevent_exclusive_modifier(struct evlist *evlist)
1501 struct evsel *evsel = evlist__first(evlist);
1503 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
1504 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
1505 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
1506 TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip);
1507 TEST_ASSERT_VAL("wrong exclusive", evsel->core.attr.exclusive);
1509 return test__checkevent_symbolic_name(evlist);
1512 static int test__exclusive_group(struct evlist *evlist)
1514 struct evsel *evsel = NULL, *leader;
1516 TEST_ASSERT_VAL("wrong number of entries",
1517 evlist->core.nr_entries == 3 * num_core_entries());
1519 for (int i = 0; i < num_core_entries(); i++) {
1520 /* cycles - group leader */
1521 evsel = leader = (i == 0 ? evlist__first(evlist) : evsel__next(evsel));
1522 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1523 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CPU_CYCLES));
1524 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1525 TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));
1526 /* TODO: The group modifier is not copied to the split group leader. */
1527 if (perf_pmus__num_core_pmus() == 1)
1528 TEST_ASSERT_VAL("wrong exclusive", evsel->core.attr.exclusive);
1530 /* cache-misses - can not be pinned, but will go on with the leader */
1531 evsel = evsel__next(evsel);
1532 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1533 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CACHE_MISSES));
1534 TEST_ASSERT_VAL("wrong exclusive", !evsel->core.attr.exclusive);
1536 /* branch-misses - ditto */
1537 evsel = evsel__next(evsel);
1538 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_BRANCH_MISSES));
1539 TEST_ASSERT_VAL("wrong exclusive", !evsel->core.attr.exclusive);
1543 static int test__checkevent_breakpoint_len(struct evlist *evlist)
1545 struct evsel *evsel = evlist__first(evlist);
1547 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
1548 TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->core.attr.type);
1549 TEST_ASSERT_VAL("wrong config", test_config(evsel, 0));
1550 TEST_ASSERT_VAL("wrong bp_type", (HW_BREAKPOINT_R | HW_BREAKPOINT_W) ==
1551 evsel->core.attr.bp_type);
1552 TEST_ASSERT_VAL("wrong bp_len", HW_BREAKPOINT_LEN_1 ==
1553 evsel->core.attr.bp_len);
1558 static int test__checkevent_breakpoint_len_w(struct evlist *evlist)
1560 struct evsel *evsel = evlist__first(evlist);
1562 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
1563 TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->core.attr.type);
1564 TEST_ASSERT_VAL("wrong config", test_config(evsel, 0));
1565 TEST_ASSERT_VAL("wrong bp_type", HW_BREAKPOINT_W ==
1566 evsel->core.attr.bp_type);
1567 TEST_ASSERT_VAL("wrong bp_len", HW_BREAKPOINT_LEN_2 ==
1568 evsel->core.attr.bp_len);
1574 test__checkevent_breakpoint_len_rw_modifier(struct evlist *evlist)
1576 struct evsel *evsel = evlist__first(evlist);
1578 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
1579 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
1580 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
1581 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1583 return test__checkevent_breakpoint_rw(evlist);
1586 static int test__checkevent_precise_max_modifier(struct evlist *evlist)
1588 struct evsel *evsel = evlist__first(evlist);
1590 TEST_ASSERT_VAL("wrong number of entries",
1591 evlist->core.nr_entries == 1 + num_core_entries());
1592 TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->core.attr.type);
1593 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_SW_TASK_CLOCK));
1597 static int test__checkevent_config_symbol(struct evlist *evlist)
1599 struct evsel *evsel = evlist__first(evlist);
1601 TEST_ASSERT_VAL("wrong name setting", evsel__name_is(evsel, "insn"));
1605 static int test__checkevent_config_raw(struct evlist *evlist)
1607 struct evsel *evsel = evlist__first(evlist);
1609 TEST_ASSERT_VAL("wrong name setting", evsel__name_is(evsel, "rawpmu"));
1613 static int test__checkevent_config_num(struct evlist *evlist)
1615 struct evsel *evsel = evlist__first(evlist);
1617 TEST_ASSERT_VAL("wrong name setting", evsel__name_is(evsel, "numpmu"));
1621 static int test__checkevent_config_cache(struct evlist *evlist)
1623 struct evsel *evsel = evlist__first(evlist);
1625 TEST_ASSERT_VAL("wrong name setting", evsel__name_is(evsel, "cachepmu"));
1626 return test__checkevent_genhw(evlist);
1629 static bool test__pmu_cpu_valid(void)
1631 return !!perf_pmus__find("cpu");
1634 static bool test__pmu_cpu_event_valid(void)
1636 struct perf_pmu *pmu = perf_pmus__find("cpu");
1641 return perf_pmu__has_format(pmu, "event");
1644 static bool test__intel_pt_valid(void)
1646 return !!perf_pmus__find("intel_pt");
1649 static int test__intel_pt(struct evlist *evlist)
1651 struct evsel *evsel = evlist__first(evlist);
1653 TEST_ASSERT_VAL("wrong name setting", evsel__name_is(evsel, "intel_pt//u"));
1657 static int test__checkevent_complex_name(struct evlist *evlist)
1659 struct evsel *evsel = evlist__first(evlist);
1661 TEST_ASSERT_VAL("wrong complex name parsing",
1662 evsel__name_is(evsel,
1663 "COMPLEX_CYCLES_NAME:orig=cycles,desc=chip-clock-ticks"));
1667 static int test__checkevent_raw_pmu(struct evlist *evlist)
1669 struct evsel *evsel = evlist__first(evlist);
1671 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
1672 TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->core.attr.type);
1673 TEST_ASSERT_VAL("wrong config", test_config(evsel, 0x1a));
1677 static int test__sym_event_slash(struct evlist *evlist)
1679 struct evsel *evsel = evlist__first(evlist);
1681 TEST_ASSERT_VAL("wrong type", evsel->core.attr.type == PERF_TYPE_HARDWARE);
1682 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CPU_CYCLES));
1683 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
1687 static int test__sym_event_dc(struct evlist *evlist)
1689 struct evsel *evsel = evlist__first(evlist);
1691 TEST_ASSERT_VAL("wrong type", evsel->core.attr.type == PERF_TYPE_HARDWARE);
1692 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CPU_CYCLES));
1693 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
1697 static int test__term_equal_term(struct evlist *evlist)
1699 struct evsel *evsel = evlist__first(evlist);
1701 TEST_ASSERT_VAL("wrong type", evsel->core.attr.type == PERF_TYPE_HARDWARE);
1702 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CPU_CYCLES));
1703 TEST_ASSERT_VAL("wrong name setting", strcmp(evsel->name, "name") == 0);
1707 static int test__term_equal_legacy(struct evlist *evlist)
1709 struct evsel *evsel = evlist__first(evlist);
1711 TEST_ASSERT_VAL("wrong type", evsel->core.attr.type == PERF_TYPE_HARDWARE);
1712 TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CPU_CYCLES));
1713 TEST_ASSERT_VAL("wrong name setting", strcmp(evsel->name, "l1d") == 0);
1717 #ifdef HAVE_LIBTRACEEVENT
1718 static int count_tracepoints(void)
1720 struct dirent *events_ent;
1724 events_dir = tracing_events__opendir();
1726 TEST_ASSERT_VAL("Can't open events dir", events_dir);
1728 while ((events_ent = readdir(events_dir))) {
1730 struct dirent *sys_ent;
1733 if (!strcmp(events_ent->d_name, ".")
1734 || !strcmp(events_ent->d_name, "..")
1735 || !strcmp(events_ent->d_name, "enable")
1736 || !strcmp(events_ent->d_name, "header_event")
1737 || !strcmp(events_ent->d_name, "header_page"))
1740 sys_path = get_events_file(events_ent->d_name);
1741 TEST_ASSERT_VAL("Can't get sys path", sys_path);
1743 sys_dir = opendir(sys_path);
1744 TEST_ASSERT_VAL("Can't open sys dir", sys_dir);
1746 while ((sys_ent = readdir(sys_dir))) {
1747 if (!strcmp(sys_ent->d_name, ".")
1748 || !strcmp(sys_ent->d_name, "..")
1749 || !strcmp(sys_ent->d_name, "enable")
1750 || !strcmp(sys_ent->d_name, "filter"))
1757 put_events_file(sys_path);
1760 closedir(events_dir);
1764 static int test__all_tracepoints(struct evlist *evlist)
1766 TEST_ASSERT_VAL("wrong events count",
1767 count_tracepoints() == evlist->core.nr_entries);
1769 return test__checkevent_tracepoint_multi(evlist);
1771 #endif /* HAVE_LIBTRACEVENT */
1773 struct evlist_test {
1775 bool (*valid)(void);
1776 int (*check)(struct evlist *evlist);
1779 static const struct evlist_test test__events[] = {
1780 #ifdef HAVE_LIBTRACEEVENT
1782 .name = "syscalls:sys_enter_openat",
1783 .check = test__checkevent_tracepoint,
1787 .name = "syscalls:*",
1788 .check = test__checkevent_tracepoint_multi,
1794 .check = test__checkevent_raw,
1799 .check = test__checkevent_numeric,
1803 .name = "instructions",
1804 .check = test__checkevent_symbolic_name,
1808 .name = "cycles/period=100000,config2/",
1809 .check = test__checkevent_symbolic_name_config,
1814 .check = test__checkevent_symbolic_alias,
1818 .name = "L1-dcache-load-miss",
1819 .check = test__checkevent_genhw,
1824 .check = test__checkevent_breakpoint,
1829 .check = test__checkevent_breakpoint_x,
1834 .check = test__checkevent_breakpoint_r,
1839 .check = test__checkevent_breakpoint_w,
1842 #ifdef HAVE_LIBTRACEEVENT
1844 .name = "syscalls:sys_enter_openat:k",
1845 .check = test__checkevent_tracepoint_modifier,
1849 .name = "syscalls:*:u",
1850 .check = test__checkevent_tracepoint_multi_modifier,
1856 .check = test__checkevent_raw_modifier,
1861 .check = test__checkevent_numeric_modifier,
1865 .name = "instructions:h",
1866 .check = test__checkevent_symbolic_name_modifier,
1871 .check = test__checkevent_symbolic_alias_modifier,
1875 .name = "L1-dcache-load-miss:kp",
1876 .check = test__checkevent_genhw_modifier,
1881 .check = test__checkevent_breakpoint_modifier,
1885 .name = "mem:0:x:k",
1886 .check = test__checkevent_breakpoint_x_modifier,
1890 .name = "mem:0:r:hp",
1891 .check = test__checkevent_breakpoint_r_modifier,
1895 .name = "mem:0:w:up",
1896 .check = test__checkevent_breakpoint_w_modifier,
1899 #ifdef HAVE_LIBTRACEEVENT
1901 .name = "r1,syscalls:sys_enter_openat:k,1:1:hp",
1902 .check = test__checkevent_list,
1907 .name = "instructions:G",
1908 .check = test__checkevent_exclude_host_modifier,
1912 .name = "instructions:H",
1913 .check = test__checkevent_exclude_guest_modifier,
1918 .check = test__checkevent_breakpoint_rw,
1922 .name = "mem:0:rw:kp",
1923 .check = test__checkevent_breakpoint_rw_modifier,
1927 .name = "{instructions:k,cycles:upp}",
1928 .check = test__group1,
1932 .name = "{faults:k,cache-references}:u,cycles:k",
1933 .check = test__group2,
1936 #ifdef HAVE_LIBTRACEEVENT
1938 .name = "group1{syscalls:sys_enter_openat:H,cycles:kppp},group2{cycles,1:3}:G,instructions:u",
1939 .check = test__group3,
1944 .name = "{cycles:u,instructions:kp}:p",
1945 .check = test__group4,
1949 .name = "{cycles,instructions}:G,{cycles:G,instructions:G},cycles",
1950 .check = test__group5,
1953 #ifdef HAVE_LIBTRACEEVENT
1956 .check = test__all_tracepoints,
1961 .name = "{cycles,cache-misses:G}:H",
1962 .check = test__group_gh1,
1966 .name = "{cycles,cache-misses:H}:G",
1967 .check = test__group_gh2,
1971 .name = "{cycles:G,cache-misses:H}:u",
1972 .check = test__group_gh3,
1976 .name = "{cycles:G,cache-misses:H}:uG",
1977 .check = test__group_gh4,
1981 .name = "{cycles,cache-misses,branch-misses}:S",
1982 .check = test__leader_sample1,
1986 .name = "{instructions,branch-misses}:Su",
1987 .check = test__leader_sample2,
1991 .name = "instructions:uDp",
1992 .check = test__checkevent_pinned_modifier,
1996 .name = "{cycles,cache-misses,branch-misses}:D",
1997 .check = test__pinned_group,
2002 .check = test__checkevent_breakpoint_len,
2006 .name = "mem:0/2:w",
2007 .check = test__checkevent_breakpoint_len_w,
2011 .name = "mem:0/4:rw:u",
2012 .check = test__checkevent_breakpoint_len_rw_modifier,
2015 #if defined(__s390x__) && defined(HAVE_LIBTRACEEVENT)
2017 .name = "kvm-s390:kvm_s390_create_vm",
2018 .check = test__checkevent_tracepoint,
2019 .valid = kvm_s390_create_vm_valid,
2024 .name = "instructions:I",
2025 .check = test__checkevent_exclude_idle_modifier,
2029 .name = "instructions:kIG",
2030 .check = test__checkevent_exclude_idle_modifier_1,
2034 .name = "task-clock:P,cycles",
2035 .check = test__checkevent_precise_max_modifier,
2039 .name = "instructions/name=insn/",
2040 .check = test__checkevent_config_symbol,
2044 .name = "r1234/name=rawpmu/",
2045 .check = test__checkevent_config_raw,
2049 .name = "4:0x6530160/name=numpmu/",
2050 .check = test__checkevent_config_num,
2054 .name = "L1-dcache-misses/name=cachepmu/",
2055 .check = test__checkevent_config_cache,
2059 .name = "intel_pt//u",
2060 .valid = test__intel_pt_valid,
2061 .check = test__intel_pt,
2065 .name = "cycles/name='COMPLEX_CYCLES_NAME:orig=cycles,desc=chip-clock-ticks'/Duk",
2066 .check = test__checkevent_complex_name,
2070 .name = "cycles//u",
2071 .check = test__sym_event_slash,
2076 .check = test__sym_event_dc,
2080 .name = "instructions:uep",
2081 .check = test__checkevent_exclusive_modifier,
2085 .name = "{cycles,cache-misses,branch-misses}:e",
2086 .check = test__exclusive_group,
2090 .name = "cycles/name=name/",
2091 .check = test__term_equal_term,
2095 .name = "cycles/name=l1d/",
2096 .check = test__term_equal_legacy,
2100 .name = "mem:0/name=breakpoint/",
2101 .check = test__checkevent_breakpoint,
2105 .name = "mem:0:x/name=breakpoint/",
2106 .check = test__checkevent_breakpoint_x,
2110 .name = "mem:0:r/name=breakpoint/",
2111 .check = test__checkevent_breakpoint_r,
2115 .name = "mem:0:w/name=breakpoint/",
2116 .check = test__checkevent_breakpoint_w,
2120 .name = "mem:0/name=breakpoint/u",
2121 .check = test__checkevent_breakpoint_modifier_name,
2125 .name = "mem:0:x/name=breakpoint/k",
2126 .check = test__checkevent_breakpoint_x_modifier_name,
2130 .name = "mem:0:r/name=breakpoint/hp",
2131 .check = test__checkevent_breakpoint_r_modifier_name,
2135 .name = "mem:0:w/name=breakpoint/up",
2136 .check = test__checkevent_breakpoint_w_modifier_name,
2140 .name = "mem:0:rw/name=breakpoint/",
2141 .check = test__checkevent_breakpoint_rw,
2145 .name = "mem:0:rw/name=breakpoint/kp",
2146 .check = test__checkevent_breakpoint_rw_modifier_name,
2150 .name = "mem:0/1/name=breakpoint/",
2151 .check = test__checkevent_breakpoint_len,
2155 .name = "mem:0/2:w/name=breakpoint/",
2156 .check = test__checkevent_breakpoint_len_w,
2160 .name = "mem:0/4:rw/name=breakpoint/u",
2161 .check = test__checkevent_breakpoint_len_rw_modifier,
2165 .name = "mem:0/1/name=breakpoint1/,mem:0/4:rw/name=breakpoint2/",
2166 .check = test__checkevent_breakpoint_2_events,
2171 static const struct evlist_test test__events_pmu[] = {
2173 .name = "cpu/config=10,config1,config2=3,period=1000/u",
2174 .valid = test__pmu_cpu_valid,
2175 .check = test__checkevent_pmu,
2179 .name = "cpu/config=1,name=krava/u,cpu/config=2/u",
2180 .valid = test__pmu_cpu_valid,
2181 .check = test__checkevent_pmu_name,
2185 .name = "cpu/config=1,call-graph=fp,time,period=100000/,cpu/config=2,call-graph=no,time=0,period=2000/",
2186 .valid = test__pmu_cpu_valid,
2187 .check = test__checkevent_pmu_partial_time_callgraph,
2191 .name = "cpu/name='COMPLEX_CYCLES_NAME:orig=cycles,desc=chip-clock-ticks',period=0x1,event=0x2/ukp",
2192 .valid = test__pmu_cpu_event_valid,
2193 .check = test__checkevent_complex_name,
2197 .name = "software/r1a/",
2198 .check = test__checkevent_raw_pmu,
2202 .name = "software/r0x1a/",
2203 .check = test__checkevent_raw_pmu,
2207 .name = "cpu/L1-dcache-load-miss/",
2208 .valid = test__pmu_cpu_valid,
2209 .check = test__checkevent_genhw,
2213 .name = "cpu/L1-dcache-load-miss/kp",
2214 .valid = test__pmu_cpu_valid,
2215 .check = test__checkevent_genhw_modifier,
2219 .name = "cpu/L1-dcache-misses,name=cachepmu/",
2220 .valid = test__pmu_cpu_valid,
2221 .check = test__checkevent_config_cache,
2225 .name = "cpu/instructions/",
2226 .valid = test__pmu_cpu_valid,
2227 .check = test__checkevent_symbolic_name,
2231 .name = "cpu/cycles,period=100000,config2/",
2232 .valid = test__pmu_cpu_valid,
2233 .check = test__checkevent_symbolic_name_config,
2237 .name = "cpu/instructions/h",
2238 .valid = test__pmu_cpu_valid,
2239 .check = test__checkevent_symbolic_name_modifier,
2243 .name = "cpu/instructions/G",
2244 .valid = test__pmu_cpu_valid,
2245 .check = test__checkevent_exclude_host_modifier,
2249 .name = "cpu/instructions/H",
2250 .valid = test__pmu_cpu_valid,
2251 .check = test__checkevent_exclude_guest_modifier,
2255 .name = "{cpu/instructions/k,cpu/cycles/upp}",
2256 .valid = test__pmu_cpu_valid,
2257 .check = test__group1,
2261 .name = "{cpu/cycles/u,cpu/instructions/kp}:p",
2262 .valid = test__pmu_cpu_valid,
2263 .check = test__group4,
2267 .name = "{cpu/cycles/,cpu/cache-misses/G}:H",
2268 .valid = test__pmu_cpu_valid,
2269 .check = test__group_gh1,
2273 .name = "{cpu/cycles/,cpu/cache-misses/H}:G",
2274 .valid = test__pmu_cpu_valid,
2275 .check = test__group_gh2,
2279 .name = "{cpu/cycles/G,cpu/cache-misses/H}:u",
2280 .valid = test__pmu_cpu_valid,
2281 .check = test__group_gh3,
2285 .name = "{cpu/cycles/G,cpu/cache-misses/H}:uG",
2286 .valid = test__pmu_cpu_valid,
2287 .check = test__group_gh4,
2291 .name = "{cpu/cycles/,cpu/cache-misses/,cpu/branch-misses/}:S",
2292 .valid = test__pmu_cpu_valid,
2293 .check = test__leader_sample1,
2297 .name = "{cpu/instructions/,cpu/branch-misses/}:Su",
2298 .valid = test__pmu_cpu_valid,
2299 .check = test__leader_sample2,
2303 .name = "cpu/instructions/uDp",
2304 .valid = test__pmu_cpu_valid,
2305 .check = test__checkevent_pinned_modifier,
2309 .name = "{cpu/cycles/,cpu/cache-misses/,cpu/branch-misses/}:D",
2310 .valid = test__pmu_cpu_valid,
2311 .check = test__pinned_group,
2315 .name = "cpu/instructions/I",
2316 .valid = test__pmu_cpu_valid,
2317 .check = test__checkevent_exclude_idle_modifier,
2321 .name = "cpu/instructions/kIG",
2322 .valid = test__pmu_cpu_valid,
2323 .check = test__checkevent_exclude_idle_modifier_1,
2327 .name = "cpu/cycles/u",
2328 .valid = test__pmu_cpu_valid,
2329 .check = test__sym_event_slash,
2333 .name = "cpu/cycles/k",
2334 .valid = test__pmu_cpu_valid,
2335 .check = test__sym_event_dc,
2339 .name = "cpu/instructions/uep",
2340 .valid = test__pmu_cpu_valid,
2341 .check = test__checkevent_exclusive_modifier,
2345 .name = "{cpu/cycles/,cpu/cache-misses/,cpu/branch-misses/}:e",
2346 .valid = test__pmu_cpu_valid,
2347 .check = test__exclusive_group,
2351 .name = "cpu/cycles,name=name/",
2352 .valid = test__pmu_cpu_valid,
2353 .check = test__term_equal_term,
2357 .name = "cpu/cycles,name=l1d/",
2358 .valid = test__pmu_cpu_valid,
2359 .check = test__term_equal_legacy,
2366 int (*check)(struct list_head *terms);
2369 static const struct terms_test test__terms[] = {
2371 .str = "config=10,config1,config2=3,config3=4,umask=1,read,r0xead",
2372 .check = test__checkterms_simple,
2376 static int test_event(const struct evlist_test *e)
2378 struct parse_events_error err;
2379 struct evlist *evlist;
2382 if (e->valid && !e->valid()) {
2383 pr_debug("... SKIP\n");
2387 evlist = evlist__new();
2388 if (evlist == NULL) {
2389 pr_err("Failed allocation");
2392 parse_events_error__init(&err);
2393 ret = parse_events(evlist, e->name, &err);
2395 pr_debug("failed to parse event '%s', err %d, str '%s'\n",
2396 e->name, ret, err.str);
2397 parse_events_error__print(&err, e->name);
2399 if (err.str && strstr(err.str, "can't access trace events"))
2402 ret = e->check(evlist);
2404 parse_events_error__exit(&err);
2405 evlist__delete(evlist);
2410 static int test_event_fake_pmu(const char *str)
2412 struct parse_events_error err;
2413 struct evlist *evlist;
2416 evlist = evlist__new();
2420 parse_events_error__init(&err);
2421 ret = __parse_events(evlist, str, /*pmu_filter=*/NULL, &err,
2422 &perf_pmu__fake, /*warn_if_reordered=*/true);
2424 pr_debug("failed to parse event '%s', err %d, str '%s'\n",
2426 parse_events_error__print(&err, str);
2429 parse_events_error__exit(&err);
2430 evlist__delete(evlist);
2435 static int combine_test_results(int existing, int latest)
2437 if (existing == TEST_FAIL)
2439 if (existing == TEST_SKIP)
2440 return latest == TEST_OK ? TEST_SKIP : latest;
2444 static int test_events(const struct evlist_test *events, int cnt)
2448 for (int i = 0; i < cnt; i++) {
2449 const struct evlist_test *e = &events[i];
2452 pr_debug("running test %d '%s'\n", i, e->name);
2453 test_ret = test_event(e);
2454 if (test_ret != TEST_OK) {
2455 pr_debug("Event test failure: test %d '%s'", i, e->name);
2456 ret = combine_test_results(ret, test_ret);
2463 static int test__events2(struct test_suite *test __maybe_unused, int subtest __maybe_unused)
2465 return test_events(test__events, ARRAY_SIZE(test__events));
2468 static int test_term(const struct terms_test *t)
2470 struct list_head terms;
2473 INIT_LIST_HEAD(&terms);
2475 ret = parse_events_terms(&terms, t->str);
2477 pr_debug("failed to parse terms '%s', err %d\n",
2482 ret = t->check(&terms);
2483 parse_events_terms__purge(&terms);
2488 static int test_terms(const struct terms_test *terms, int cnt)
2492 for (int i = 0; i < cnt; i++) {
2493 const struct terms_test *t = &terms[i];
2495 pr_debug("running test %d '%s'\n", i, t->str);
2504 static int test__terms2(struct test_suite *test __maybe_unused, int subtest __maybe_unused)
2506 return test_terms(test__terms, ARRAY_SIZE(test__terms));
2509 static int test__pmu_events(struct test_suite *test __maybe_unused, int subtest __maybe_unused)
2511 struct perf_pmu *pmu = NULL;
2514 while ((pmu = perf_pmus__scan(pmu)) != NULL) {
2516 char path[PATH_MAX];
2521 snprintf(path, PATH_MAX, "%s/bus/event_source/devices/%s/events/",
2522 sysfs__mountpoint(), pmu->name);
2524 err = stat(path, &st);
2526 pr_debug("skipping PMU %s events tests: %s\n", pmu->name, path);
2530 dir = opendir(path);
2532 pr_debug("can't open pmu event dir: %s\n", path);
2533 ret = combine_test_results(ret, TEST_SKIP);
2537 while ((ent = readdir(dir))) {
2538 struct evlist_test e = { .name = NULL, };
2539 char name[2 * NAME_MAX + 1 + 12 + 3];
2542 /* Names containing . are special and cannot be used directly */
2543 if (strchr(ent->d_name, '.'))
2546 snprintf(name, sizeof(name), "%s/event=%s/u", pmu->name, ent->d_name);
2549 e.check = test__checkevent_pmu_events;
2551 test_ret = test_event(&e);
2552 if (test_ret != TEST_OK) {
2553 pr_debug("Test PMU event failed for '%s'", name);
2554 ret = combine_test_results(ret, test_ret);
2557 if (!is_pmu_core(pmu->name))
2561 * Names containing '-' are recognized as prefixes and suffixes
2562 * due to '-' being a legacy PMU separator. This fails when the
2563 * prefix or suffix collides with an existing legacy token. For
2564 * example, branch-brs has a prefix (branch) that collides with
2565 * a PE_NAME_CACHE_TYPE token causing a parse error as a suffix
2566 * isn't expected after this. As event names in the config
2567 * slashes are allowed a '-' in the name we check this works
2570 if (strchr(ent->d_name, '-'))
2573 snprintf(name, sizeof(name), "%s:u,%s/event=%s/u",
2574 ent->d_name, pmu->name, ent->d_name);
2576 e.check = test__checkevent_pmu_events_mix;
2577 test_ret = test_event(&e);
2578 if (test_ret != TEST_OK) {
2579 pr_debug("Test PMU event failed for '%s'", name);
2580 ret = combine_test_results(ret, test_ret);
2589 static int test__pmu_events2(struct test_suite *test __maybe_unused, int subtest __maybe_unused)
2591 return test_events(test__events_pmu, ARRAY_SIZE(test__events_pmu));
2594 static bool test_alias(char **event, char **alias)
2596 char path[PATH_MAX];
2598 struct dirent *dent;
2599 const char *sysfs = sysfs__mountpoint();
2606 snprintf(path, PATH_MAX, "%s/bus/event_source/devices/", sysfs);
2607 dir = opendir(path);
2611 while ((dent = readdir(dir))) {
2612 if (!strcmp(dent->d_name, ".") ||
2613 !strcmp(dent->d_name, ".."))
2616 snprintf(path, PATH_MAX, "%s/bus/event_source/devices/%s/alias",
2617 sysfs, dent->d_name);
2619 if (!file_available(path))
2622 file = fopen(path, "r");
2626 if (!fgets(buf, sizeof(buf), file)) {
2631 /* Remove the last '\n' */
2632 buf[strlen(buf) - 1] = 0;
2635 *event = strdup(dent->d_name);
2636 *alias = strdup(buf);
2639 if (*event == NULL || *alias == NULL) {
2652 static int test__checkevent_pmu_events_alias(struct evlist *evlist)
2654 struct evsel *evsel1 = evlist__first(evlist);
2655 struct evsel *evsel2 = evlist__last(evlist);
2657 TEST_ASSERT_VAL("wrong type", evsel1->core.attr.type == evsel2->core.attr.type);
2658 TEST_ASSERT_VAL("wrong config", evsel1->core.attr.config == evsel2->core.attr.config);
2662 static int test__pmu_events_alias(char *event, char *alias)
2664 struct evlist_test e = { .name = NULL, };
2665 char name[2 * NAME_MAX + 20];
2667 snprintf(name, sizeof(name), "%s/event=1/,%s/event=1/",
2671 e.check = test__checkevent_pmu_events_alias;
2672 return test_event(&e);
2675 static int test__alias(struct test_suite *test __maybe_unused, int subtest __maybe_unused)
2677 char *event, *alias;
2680 if (!test_alias(&event, &alias))
2683 ret = test__pmu_events_alias(event, alias);
2690 static int test__pmu_events_alias2(struct test_suite *test __maybe_unused,
2691 int subtest __maybe_unused)
2693 static const char events[][30] = {
2699 for (unsigned int i = 0; i < ARRAY_SIZE(events); i++) {
2700 int test_ret = test_event_fake_pmu(&events[i][0]);
2702 if (test_ret != TEST_OK) {
2703 pr_debug("check_parse_fake %s failed\n", &events[i][0]);
2704 ret = combine_test_results(ret, test_ret);
2711 static struct test_case tests__parse_events[] = {
2712 TEST_CASE_REASON("Test event parsing",
2715 TEST_CASE_REASON("Parsing of all PMU events from sysfs",
2718 TEST_CASE_REASON("Parsing of given PMU events from sysfs",
2721 TEST_CASE_REASON("Parsing of aliased events from sysfs", alias,
2722 "no aliases in sysfs"),
2723 TEST_CASE("Parsing of aliased events", pmu_events_alias2),
2724 TEST_CASE("Parsing of terms (event modifiers)", terms2),
2728 struct test_suite suite__parse_events = {
2729 .desc = "Parse event definition strings",
2730 .test_cases = tests__parse_events,