1 // SPDX-License-Identifier: GPL-2.0
2 #include "parse-events.h"
12 #include <sys/types.h>
15 #include <linux/kernel.h>
16 #include <linux/hw_breakpoint.h>
17 #include <api/fs/tracing_path.h>
19 #define PERF_TP_SAMPLE_TYPE (PERF_SAMPLE_RAW | PERF_SAMPLE_TIME | \
20 PERF_SAMPLE_CPU | PERF_SAMPLE_PERIOD)
22 #if defined(__s390x__)
23 /* Return true if kvm module is available and loaded. Test this
24 * and retun success when trace point kvm_s390_create_vm
25 * exists. Otherwise this test always fails.
27 static bool kvm_s390_create_vm_valid(void)
32 eventfile = get_events_file("kvm-s390");
35 DIR *mydir = opendir(eventfile);
41 put_events_file(eventfile);
48 static int test__checkevent_tracepoint(struct evlist *evlist)
50 struct evsel *evsel = perf_evlist__first(evlist);
52 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
53 TEST_ASSERT_VAL("wrong number of groups", 0 == evlist->nr_groups);
54 TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->core.attr.type);
55 TEST_ASSERT_VAL("wrong sample_type",
56 PERF_TP_SAMPLE_TYPE == evsel->core.attr.sample_type);
57 TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->core.attr.sample_period);
61 static int test__checkevent_tracepoint_multi(struct evlist *evlist)
65 TEST_ASSERT_VAL("wrong number of entries", evlist->core.nr_entries > 1);
66 TEST_ASSERT_VAL("wrong number of groups", 0 == evlist->nr_groups);
68 evlist__for_each_entry(evlist, evsel) {
69 TEST_ASSERT_VAL("wrong type",
70 PERF_TYPE_TRACEPOINT == evsel->core.attr.type);
71 TEST_ASSERT_VAL("wrong sample_type",
72 PERF_TP_SAMPLE_TYPE == evsel->core.attr.sample_type);
73 TEST_ASSERT_VAL("wrong sample_period",
74 1 == evsel->core.attr.sample_period);
79 static int test__checkevent_raw(struct evlist *evlist)
81 struct evsel *evsel = perf_evlist__first(evlist);
83 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
84 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type);
85 TEST_ASSERT_VAL("wrong config", 0x1a == evsel->core.attr.config);
89 static int test__checkevent_numeric(struct evlist *evlist)
91 struct evsel *evsel = perf_evlist__first(evlist);
93 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
94 TEST_ASSERT_VAL("wrong type", 1 == evsel->core.attr.type);
95 TEST_ASSERT_VAL("wrong config", 1 == evsel->core.attr.config);
99 static int test__checkevent_symbolic_name(struct evlist *evlist)
101 struct evsel *evsel = perf_evlist__first(evlist);
103 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
104 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
105 TEST_ASSERT_VAL("wrong config",
106 PERF_COUNT_HW_INSTRUCTIONS == evsel->core.attr.config);
110 static int test__checkevent_symbolic_name_config(struct evlist *evlist)
112 struct evsel *evsel = perf_evlist__first(evlist);
114 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
115 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
116 TEST_ASSERT_VAL("wrong config",
117 PERF_COUNT_HW_CPU_CYCLES == evsel->core.attr.config);
119 * The period value gets configured within perf_evlist__config,
120 * while this test executes only parse events method.
122 TEST_ASSERT_VAL("wrong period",
123 0 == evsel->core.attr.sample_period);
124 TEST_ASSERT_VAL("wrong config1",
125 0 == evsel->core.attr.config1);
126 TEST_ASSERT_VAL("wrong config2",
127 1 == evsel->core.attr.config2);
131 static int test__checkevent_symbolic_alias(struct evlist *evlist)
133 struct evsel *evsel = perf_evlist__first(evlist);
135 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
136 TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->core.attr.type);
137 TEST_ASSERT_VAL("wrong config",
138 PERF_COUNT_SW_PAGE_FAULTS == evsel->core.attr.config);
142 static int test__checkevent_genhw(struct evlist *evlist)
144 struct evsel *evsel = perf_evlist__first(evlist);
146 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
147 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HW_CACHE == evsel->core.attr.type);
148 TEST_ASSERT_VAL("wrong config", (1 << 16) == evsel->core.attr.config);
152 static int test__checkevent_breakpoint(struct evlist *evlist)
154 struct evsel *evsel = perf_evlist__first(evlist);
156 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
157 TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->core.attr.type);
158 TEST_ASSERT_VAL("wrong config", 0 == evsel->core.attr.config);
159 TEST_ASSERT_VAL("wrong bp_type", (HW_BREAKPOINT_R | HW_BREAKPOINT_W) ==
160 evsel->core.attr.bp_type);
161 TEST_ASSERT_VAL("wrong bp_len", HW_BREAKPOINT_LEN_4 ==
162 evsel->core.attr.bp_len);
166 static int test__checkevent_breakpoint_x(struct evlist *evlist)
168 struct evsel *evsel = perf_evlist__first(evlist);
170 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
171 TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->core.attr.type);
172 TEST_ASSERT_VAL("wrong config", 0 == evsel->core.attr.config);
173 TEST_ASSERT_VAL("wrong bp_type",
174 HW_BREAKPOINT_X == evsel->core.attr.bp_type);
175 TEST_ASSERT_VAL("wrong bp_len", sizeof(long) == evsel->core.attr.bp_len);
179 static int test__checkevent_breakpoint_r(struct evlist *evlist)
181 struct evsel *evsel = perf_evlist__first(evlist);
183 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
184 TEST_ASSERT_VAL("wrong type",
185 PERF_TYPE_BREAKPOINT == evsel->core.attr.type);
186 TEST_ASSERT_VAL("wrong config", 0 == evsel->core.attr.config);
187 TEST_ASSERT_VAL("wrong bp_type",
188 HW_BREAKPOINT_R == evsel->core.attr.bp_type);
189 TEST_ASSERT_VAL("wrong bp_len",
190 HW_BREAKPOINT_LEN_4 == evsel->core.attr.bp_len);
194 static int test__checkevent_breakpoint_w(struct evlist *evlist)
196 struct evsel *evsel = perf_evlist__first(evlist);
198 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
199 TEST_ASSERT_VAL("wrong type",
200 PERF_TYPE_BREAKPOINT == evsel->core.attr.type);
201 TEST_ASSERT_VAL("wrong config", 0 == evsel->core.attr.config);
202 TEST_ASSERT_VAL("wrong bp_type",
203 HW_BREAKPOINT_W == evsel->core.attr.bp_type);
204 TEST_ASSERT_VAL("wrong bp_len",
205 HW_BREAKPOINT_LEN_4 == evsel->core.attr.bp_len);
209 static int test__checkevent_breakpoint_rw(struct evlist *evlist)
211 struct evsel *evsel = perf_evlist__first(evlist);
213 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
214 TEST_ASSERT_VAL("wrong type",
215 PERF_TYPE_BREAKPOINT == evsel->core.attr.type);
216 TEST_ASSERT_VAL("wrong config", 0 == evsel->core.attr.config);
217 TEST_ASSERT_VAL("wrong bp_type",
218 (HW_BREAKPOINT_R|HW_BREAKPOINT_W) == evsel->core.attr.bp_type);
219 TEST_ASSERT_VAL("wrong bp_len",
220 HW_BREAKPOINT_LEN_4 == evsel->core.attr.bp_len);
224 static int test__checkevent_tracepoint_modifier(struct evlist *evlist)
226 struct evsel *evsel = perf_evlist__first(evlist);
228 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
229 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
230 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
231 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
233 return test__checkevent_tracepoint(evlist);
237 test__checkevent_tracepoint_multi_modifier(struct evlist *evlist)
241 TEST_ASSERT_VAL("wrong number of entries", evlist->core.nr_entries > 1);
243 evlist__for_each_entry(evlist, evsel) {
244 TEST_ASSERT_VAL("wrong exclude_user",
245 !evsel->core.attr.exclude_user);
246 TEST_ASSERT_VAL("wrong exclude_kernel",
247 evsel->core.attr.exclude_kernel);
248 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
249 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
252 return test__checkevent_tracepoint_multi(evlist);
255 static int test__checkevent_raw_modifier(struct evlist *evlist)
257 struct evsel *evsel = perf_evlist__first(evlist);
259 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
260 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
261 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
262 TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip);
264 return test__checkevent_raw(evlist);
267 static int test__checkevent_numeric_modifier(struct evlist *evlist)
269 struct evsel *evsel = perf_evlist__first(evlist);
271 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
272 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
273 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
274 TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip);
276 return test__checkevent_numeric(evlist);
279 static int test__checkevent_symbolic_name_modifier(struct evlist *evlist)
281 struct evsel *evsel = perf_evlist__first(evlist);
283 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
284 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
285 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
286 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
288 return test__checkevent_symbolic_name(evlist);
291 static int test__checkevent_exclude_host_modifier(struct evlist *evlist)
293 struct evsel *evsel = perf_evlist__first(evlist);
295 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
296 TEST_ASSERT_VAL("wrong exclude host", evsel->core.attr.exclude_host);
298 return test__checkevent_symbolic_name(evlist);
301 static int test__checkevent_exclude_guest_modifier(struct evlist *evlist)
303 struct evsel *evsel = perf_evlist__first(evlist);
305 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
306 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
308 return test__checkevent_symbolic_name(evlist);
311 static int test__checkevent_symbolic_alias_modifier(struct evlist *evlist)
313 struct evsel *evsel = perf_evlist__first(evlist);
315 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
316 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
317 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
318 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
320 return test__checkevent_symbolic_alias(evlist);
323 static int test__checkevent_genhw_modifier(struct evlist *evlist)
325 struct evsel *evsel = perf_evlist__first(evlist);
327 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
328 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
329 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
330 TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip);
332 return test__checkevent_genhw(evlist);
335 static int test__checkevent_exclude_idle_modifier(struct evlist *evlist)
337 struct evsel *evsel = perf_evlist__first(evlist);
339 TEST_ASSERT_VAL("wrong exclude idle", evsel->core.attr.exclude_idle);
340 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
341 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
342 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
343 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
344 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
345 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
347 return test__checkevent_symbolic_name(evlist);
350 static int test__checkevent_exclude_idle_modifier_1(struct evlist *evlist)
352 struct evsel *evsel = perf_evlist__first(evlist);
354 TEST_ASSERT_VAL("wrong exclude idle", evsel->core.attr.exclude_idle);
355 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
356 TEST_ASSERT_VAL("wrong exclude host", evsel->core.attr.exclude_host);
357 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
358 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
359 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
360 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
362 return test__checkevent_symbolic_name(evlist);
365 static int test__checkevent_breakpoint_modifier(struct evlist *evlist)
367 struct evsel *evsel = perf_evlist__first(evlist);
370 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
371 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
372 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
373 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
374 TEST_ASSERT_VAL("wrong name",
375 !strcmp(perf_evsel__name(evsel), "mem:0:u"));
377 return test__checkevent_breakpoint(evlist);
380 static int test__checkevent_breakpoint_x_modifier(struct evlist *evlist)
382 struct evsel *evsel = perf_evlist__first(evlist);
384 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
385 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
386 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
387 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
388 TEST_ASSERT_VAL("wrong name",
389 !strcmp(perf_evsel__name(evsel), "mem:0:x:k"));
391 return test__checkevent_breakpoint_x(evlist);
394 static int test__checkevent_breakpoint_r_modifier(struct evlist *evlist)
396 struct evsel *evsel = perf_evlist__first(evlist);
398 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
399 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
400 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
401 TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip);
402 TEST_ASSERT_VAL("wrong name",
403 !strcmp(perf_evsel__name(evsel), "mem:0:r:hp"));
405 return test__checkevent_breakpoint_r(evlist);
408 static int test__checkevent_breakpoint_w_modifier(struct evlist *evlist)
410 struct evsel *evsel = perf_evlist__first(evlist);
412 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
413 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
414 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
415 TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip);
416 TEST_ASSERT_VAL("wrong name",
417 !strcmp(perf_evsel__name(evsel), "mem:0:w:up"));
419 return test__checkevent_breakpoint_w(evlist);
422 static int test__checkevent_breakpoint_rw_modifier(struct evlist *evlist)
424 struct evsel *evsel = perf_evlist__first(evlist);
426 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
427 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
428 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
429 TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip);
430 TEST_ASSERT_VAL("wrong name",
431 !strcmp(perf_evsel__name(evsel), "mem:0:rw:kp"));
433 return test__checkevent_breakpoint_rw(evlist);
436 static int test__checkevent_pmu(struct evlist *evlist)
439 struct evsel *evsel = perf_evlist__first(evlist);
441 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
442 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type);
443 TEST_ASSERT_VAL("wrong config", 10 == evsel->core.attr.config);
444 TEST_ASSERT_VAL("wrong config1", 1 == evsel->core.attr.config1);
445 TEST_ASSERT_VAL("wrong config2", 3 == evsel->core.attr.config2);
447 * The period value gets configured within perf_evlist__config,
448 * while this test executes only parse events method.
450 TEST_ASSERT_VAL("wrong period", 0 == evsel->core.attr.sample_period);
455 static int test__checkevent_list(struct evlist *evlist)
457 struct evsel *evsel = perf_evlist__first(evlist);
459 TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->core.nr_entries);
462 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type);
463 TEST_ASSERT_VAL("wrong config", 1 == evsel->core.attr.config);
464 TEST_ASSERT_VAL("wrong config1", 0 == evsel->core.attr.config1);
465 TEST_ASSERT_VAL("wrong config2", 0 == evsel->core.attr.config2);
466 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
467 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
468 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
469 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
471 /* syscalls:sys_enter_openat:k */
472 evsel = perf_evsel__next(evsel);
473 TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->core.attr.type);
474 TEST_ASSERT_VAL("wrong sample_type",
475 PERF_TP_SAMPLE_TYPE == evsel->core.attr.sample_type);
476 TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->core.attr.sample_period);
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);
483 evsel = perf_evsel__next(evsel);
484 TEST_ASSERT_VAL("wrong type", 1 == evsel->core.attr.type);
485 TEST_ASSERT_VAL("wrong config", 1 == evsel->core.attr.config);
486 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
487 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
488 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
489 TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip);
494 static int test__checkevent_pmu_name(struct evlist *evlist)
496 struct evsel *evsel = perf_evlist__first(evlist);
498 /* cpu/config=1,name=krava/u */
499 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);
500 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type);
501 TEST_ASSERT_VAL("wrong config", 1 == evsel->core.attr.config);
502 TEST_ASSERT_VAL("wrong name", !strcmp(perf_evsel__name(evsel), "krava"));
504 /* cpu/config=2/u" */
505 evsel = perf_evsel__next(evsel);
506 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);
507 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type);
508 TEST_ASSERT_VAL("wrong config", 2 == evsel->core.attr.config);
509 TEST_ASSERT_VAL("wrong name",
510 !strcmp(perf_evsel__name(evsel), "cpu/config=2/u"));
515 static int test__checkevent_pmu_partial_time_callgraph(struct evlist *evlist)
517 struct evsel *evsel = perf_evlist__first(evlist);
519 /* cpu/config=1,call-graph=fp,time,period=100000/ */
520 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);
521 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type);
522 TEST_ASSERT_VAL("wrong config", 1 == evsel->core.attr.config);
524 * The period, time and callgraph value gets configured
525 * within perf_evlist__config,
526 * while this test executes only parse events method.
528 TEST_ASSERT_VAL("wrong period", 0 == evsel->core.attr.sample_period);
529 TEST_ASSERT_VAL("wrong callgraph", !evsel__has_callchain(evsel));
530 TEST_ASSERT_VAL("wrong time", !(PERF_SAMPLE_TIME & evsel->core.attr.sample_type));
532 /* cpu/config=2,call-graph=no,time=0,period=2000/ */
533 evsel = perf_evsel__next(evsel);
534 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type);
535 TEST_ASSERT_VAL("wrong config", 2 == evsel->core.attr.config);
537 * The period, time and callgraph value gets configured
538 * within perf_evlist__config,
539 * while this test executes only parse events method.
541 TEST_ASSERT_VAL("wrong period", 0 == evsel->core.attr.sample_period);
542 TEST_ASSERT_VAL("wrong callgraph", !evsel__has_callchain(evsel));
543 TEST_ASSERT_VAL("wrong time", !(PERF_SAMPLE_TIME & evsel->core.attr.sample_type));
548 static int test__checkevent_pmu_events(struct evlist *evlist)
550 struct evsel *evsel = perf_evlist__first(evlist);
552 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
553 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type);
554 TEST_ASSERT_VAL("wrong exclude_user",
555 !evsel->core.attr.exclude_user);
556 TEST_ASSERT_VAL("wrong exclude_kernel",
557 evsel->core.attr.exclude_kernel);
558 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
559 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
560 TEST_ASSERT_VAL("wrong pinned", !evsel->core.attr.pinned);
566 static int test__checkevent_pmu_events_mix(struct evlist *evlist)
568 struct evsel *evsel = perf_evlist__first(evlist);
571 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);
572 TEST_ASSERT_VAL("wrong exclude_user",
573 !evsel->core.attr.exclude_user);
574 TEST_ASSERT_VAL("wrong exclude_kernel",
575 evsel->core.attr.exclude_kernel);
576 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
577 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
578 TEST_ASSERT_VAL("wrong pinned", !evsel->core.attr.pinned);
581 evsel = perf_evsel__next(evsel);
582 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);
583 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type);
584 TEST_ASSERT_VAL("wrong exclude_user",
585 !evsel->core.attr.exclude_user);
586 TEST_ASSERT_VAL("wrong exclude_kernel",
587 evsel->core.attr.exclude_kernel);
588 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
589 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
590 TEST_ASSERT_VAL("wrong pinned", !evsel->core.attr.pinned);
595 static int test__checkterms_simple(struct list_head *terms)
597 struct parse_events_term *term;
600 term = list_entry(terms->next, struct parse_events_term, list);
601 TEST_ASSERT_VAL("wrong type term",
602 term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG);
603 TEST_ASSERT_VAL("wrong type val",
604 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
605 TEST_ASSERT_VAL("wrong val", term->val.num == 10);
606 TEST_ASSERT_VAL("wrong config", !term->config);
609 term = list_entry(term->list.next, struct parse_events_term, list);
610 TEST_ASSERT_VAL("wrong type term",
611 term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG1);
612 TEST_ASSERT_VAL("wrong type val",
613 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
614 TEST_ASSERT_VAL("wrong val", term->val.num == 1);
615 TEST_ASSERT_VAL("wrong config", !term->config);
618 term = list_entry(term->list.next, struct parse_events_term, list);
619 TEST_ASSERT_VAL("wrong type term",
620 term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG2);
621 TEST_ASSERT_VAL("wrong type val",
622 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
623 TEST_ASSERT_VAL("wrong val", term->val.num == 3);
624 TEST_ASSERT_VAL("wrong config", !term->config);
627 term = list_entry(term->list.next, struct parse_events_term, list);
628 TEST_ASSERT_VAL("wrong type term",
629 term->type_term == PARSE_EVENTS__TERM_TYPE_USER);
630 TEST_ASSERT_VAL("wrong type val",
631 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
632 TEST_ASSERT_VAL("wrong val", term->val.num == 1);
633 TEST_ASSERT_VAL("wrong config", !strcmp(term->config, "umask"));
638 static int test__group1(struct evlist *evlist)
640 struct evsel *evsel, *leader;
642 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);
643 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
646 evsel = leader = perf_evlist__first(evlist);
647 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
648 TEST_ASSERT_VAL("wrong config",
649 PERF_COUNT_HW_INSTRUCTIONS == evsel->core.attr.config);
650 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
651 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
652 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
653 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
654 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
655 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
656 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
657 TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2);
658 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
659 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
662 evsel = perf_evsel__next(evsel);
663 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
664 TEST_ASSERT_VAL("wrong config",
665 PERF_COUNT_HW_CPU_CYCLES == evsel->core.attr.config);
666 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
667 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
668 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
669 /* use of precise requires exclude_guest */
670 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
671 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
672 TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip == 2);
673 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
674 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
675 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
680 static int test__group2(struct evlist *evlist)
682 struct evsel *evsel, *leader;
684 TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->core.nr_entries);
685 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
687 /* faults + :ku modifier */
688 evsel = leader = perf_evlist__first(evlist);
689 TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->core.attr.type);
690 TEST_ASSERT_VAL("wrong config",
691 PERF_COUNT_SW_PAGE_FAULTS == evsel->core.attr.config);
692 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
693 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
694 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
695 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
696 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
697 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
698 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
699 TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2);
700 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
701 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
703 /* cache-references + :u modifier */
704 evsel = perf_evsel__next(evsel);
705 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
706 TEST_ASSERT_VAL("wrong config",
707 PERF_COUNT_HW_CACHE_REFERENCES == evsel->core.attr.config);
708 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
709 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
710 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
711 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
712 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
713 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
714 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
715 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
716 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
719 evsel = perf_evsel__next(evsel);
720 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
721 TEST_ASSERT_VAL("wrong config",
722 PERF_COUNT_HW_CPU_CYCLES == evsel->core.attr.config);
723 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
724 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
725 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
726 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
727 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
728 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
729 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
730 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
735 static int test__group3(struct evlist *evlist __maybe_unused)
737 struct evsel *evsel, *leader;
739 TEST_ASSERT_VAL("wrong number of entries", 5 == evlist->core.nr_entries);
740 TEST_ASSERT_VAL("wrong number of groups", 2 == evlist->nr_groups);
742 /* group1 syscalls:sys_enter_openat:H */
743 evsel = leader = perf_evlist__first(evlist);
744 TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->core.attr.type);
745 TEST_ASSERT_VAL("wrong sample_type",
746 PERF_TP_SAMPLE_TYPE == evsel->core.attr.sample_type);
747 TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->core.attr.sample_period);
748 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
749 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
750 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
751 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
752 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
753 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
754 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
755 TEST_ASSERT_VAL("wrong group name",
756 !strcmp(leader->group_name, "group1"));
757 TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2);
758 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
759 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
761 /* group1 cycles:kppp */
762 evsel = perf_evsel__next(evsel);
763 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
764 TEST_ASSERT_VAL("wrong config",
765 PERF_COUNT_HW_CPU_CYCLES == evsel->core.attr.config);
766 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
767 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
768 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
769 /* use of precise requires exclude_guest */
770 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
771 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
772 TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip == 3);
773 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
774 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
775 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
776 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
778 /* group2 cycles + G modifier */
779 evsel = leader = perf_evsel__next(evsel);
780 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
781 TEST_ASSERT_VAL("wrong config",
782 PERF_COUNT_HW_CPU_CYCLES == evsel->core.attr.config);
783 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
784 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
785 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
786 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
787 TEST_ASSERT_VAL("wrong exclude host", evsel->core.attr.exclude_host);
788 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
789 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
790 TEST_ASSERT_VAL("wrong group name",
791 !strcmp(leader->group_name, "group2"));
792 TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2);
793 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
794 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
796 /* group2 1:3 + G modifier */
797 evsel = perf_evsel__next(evsel);
798 TEST_ASSERT_VAL("wrong type", 1 == evsel->core.attr.type);
799 TEST_ASSERT_VAL("wrong config", 3 == evsel->core.attr.config);
800 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
801 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
802 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
803 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
804 TEST_ASSERT_VAL("wrong exclude host", evsel->core.attr.exclude_host);
805 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
806 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
807 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
808 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
811 evsel = perf_evsel__next(evsel);
812 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
813 TEST_ASSERT_VAL("wrong config",
814 PERF_COUNT_HW_INSTRUCTIONS == evsel->core.attr.config);
815 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
816 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
817 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
818 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
819 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
820 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
821 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
822 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
827 static int test__group4(struct evlist *evlist __maybe_unused)
829 struct evsel *evsel, *leader;
831 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);
832 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
835 evsel = leader = perf_evlist__first(evlist);
836 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
837 TEST_ASSERT_VAL("wrong config",
838 PERF_COUNT_HW_CPU_CYCLES == evsel->core.attr.config);
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 /* use of precise requires exclude_guest */
843 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
844 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
845 TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip == 1);
846 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
847 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
848 TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2);
849 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
850 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
852 /* instructions:kp + p */
853 evsel = perf_evsel__next(evsel);
854 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
855 TEST_ASSERT_VAL("wrong config",
856 PERF_COUNT_HW_INSTRUCTIONS == evsel->core.attr.config);
857 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
858 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
859 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
860 /* use of precise requires exclude_guest */
861 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
862 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
863 TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip == 2);
864 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
865 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
866 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
871 static int test__group5(struct evlist *evlist __maybe_unused)
873 struct evsel *evsel, *leader;
875 TEST_ASSERT_VAL("wrong number of entries", 5 == evlist->core.nr_entries);
876 TEST_ASSERT_VAL("wrong number of groups", 2 == evlist->nr_groups);
879 evsel = leader = perf_evlist__first(evlist);
880 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
881 TEST_ASSERT_VAL("wrong config",
882 PERF_COUNT_HW_CPU_CYCLES == evsel->core.attr.config);
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 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
887 TEST_ASSERT_VAL("wrong exclude host", evsel->core.attr.exclude_host);
888 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
889 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
890 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
891 TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2);
892 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
893 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
895 /* instructions + G */
896 evsel = perf_evsel__next(evsel);
897 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
898 TEST_ASSERT_VAL("wrong config",
899 PERF_COUNT_HW_INSTRUCTIONS == evsel->core.attr.config);
900 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
901 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
902 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
903 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
904 TEST_ASSERT_VAL("wrong exclude host", evsel->core.attr.exclude_host);
905 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
906 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
907 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
908 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
911 evsel = leader = perf_evsel__next(evsel);
912 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
913 TEST_ASSERT_VAL("wrong config",
914 PERF_COUNT_HW_CPU_CYCLES == evsel->core.attr.config);
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 group name", !evsel->group_name);
922 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
923 TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2);
924 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
925 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
928 evsel = perf_evsel__next(evsel);
929 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
930 TEST_ASSERT_VAL("wrong config",
931 PERF_COUNT_HW_INSTRUCTIONS == evsel->core.attr.config);
932 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
933 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
934 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
935 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
936 TEST_ASSERT_VAL("wrong exclude host", evsel->core.attr.exclude_host);
937 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
938 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
939 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
942 evsel = perf_evsel__next(evsel);
943 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
944 TEST_ASSERT_VAL("wrong config",
945 PERF_COUNT_HW_CPU_CYCLES == evsel->core.attr.config);
946 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
947 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
948 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
949 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
950 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
951 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
952 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
957 static int test__group_gh1(struct evlist *evlist)
959 struct evsel *evsel, *leader;
961 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);
962 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
964 /* cycles + :H group modifier */
965 evsel = leader = perf_evlist__first(evlist);
966 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
967 TEST_ASSERT_VAL("wrong config",
968 PERF_COUNT_HW_CPU_CYCLES == evsel->core.attr.config);
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", perf_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", perf_evsel__group_idx(evsel) == 0);
980 /* cache-misses:G + :H group modifier */
981 evsel = perf_evsel__next(evsel);
982 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
983 TEST_ASSERT_VAL("wrong config",
984 PERF_COUNT_HW_CACHE_MISSES == evsel->core.attr.config);
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->leader == leader);
992 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
997 static int test__group_gh2(struct evlist *evlist)
999 struct evsel *evsel, *leader;
1001 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);
1002 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
1004 /* cycles + :G group modifier */
1005 evsel = leader = perf_evlist__first(evlist);
1006 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1007 TEST_ASSERT_VAL("wrong config",
1008 PERF_COUNT_HW_CPU_CYCLES == evsel->core.attr.config);
1009 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
1010 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
1011 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
1012 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
1013 TEST_ASSERT_VAL("wrong exclude host", evsel->core.attr.exclude_host);
1014 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1015 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1016 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
1017 TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2);
1018 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
1020 /* cache-misses:H + :G group modifier */
1021 evsel = perf_evsel__next(evsel);
1022 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1023 TEST_ASSERT_VAL("wrong config",
1024 PERF_COUNT_HW_CACHE_MISSES == evsel->core.attr.config);
1025 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
1026 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
1027 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
1028 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
1029 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
1030 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1031 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
1032 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
1037 static int test__group_gh3(struct evlist *evlist)
1039 struct evsel *evsel, *leader;
1041 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);
1042 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
1044 /* cycles:G + :u group modifier */
1045 evsel = leader = perf_evlist__first(evlist);
1046 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1047 TEST_ASSERT_VAL("wrong config",
1048 PERF_COUNT_HW_CPU_CYCLES == evsel->core.attr.config);
1049 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
1050 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
1051 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
1052 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
1053 TEST_ASSERT_VAL("wrong exclude host", evsel->core.attr.exclude_host);
1054 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1055 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1056 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
1057 TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2);
1058 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
1060 /* cache-misses:H + :u group modifier */
1061 evsel = perf_evsel__next(evsel);
1062 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1063 TEST_ASSERT_VAL("wrong config",
1064 PERF_COUNT_HW_CACHE_MISSES == evsel->core.attr.config);
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->leader == leader);
1072 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
1077 static int test__group_gh4(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);
1084 /* cycles:G + :uG group modifier */
1085 evsel = leader = perf_evlist__first(evlist);
1086 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1087 TEST_ASSERT_VAL("wrong config",
1088 PERF_COUNT_HW_CPU_CYCLES == evsel->core.attr.config);
1089 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
1090 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
1091 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
1092 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
1093 TEST_ASSERT_VAL("wrong exclude host", evsel->core.attr.exclude_host);
1094 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1095 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1096 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
1097 TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2);
1098 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
1100 /* cache-misses:H + :uG group modifier */
1101 evsel = perf_evsel__next(evsel);
1102 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1103 TEST_ASSERT_VAL("wrong config",
1104 PERF_COUNT_HW_CACHE_MISSES == evsel->core.attr.config);
1105 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
1106 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
1107 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
1108 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
1109 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
1110 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1111 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
1112 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
1117 static int test__leader_sample1(struct evlist *evlist)
1119 struct evsel *evsel, *leader;
1121 TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->core.nr_entries);
1123 /* cycles - sampling group leader */
1124 evsel = leader = perf_evlist__first(evlist);
1125 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1126 TEST_ASSERT_VAL("wrong config",
1127 PERF_COUNT_HW_CPU_CYCLES == evsel->core.attr.config);
1128 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
1129 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
1130 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
1131 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
1132 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
1133 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1134 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1135 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
1136 TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read);
1138 /* cache-misses - not sampling */
1139 evsel = perf_evsel__next(evsel);
1140 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1141 TEST_ASSERT_VAL("wrong config",
1142 PERF_COUNT_HW_CACHE_MISSES == evsel->core.attr.config);
1143 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
1144 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
1145 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
1146 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
1147 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
1148 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1149 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
1150 TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read);
1152 /* branch-misses - not sampling */
1153 evsel = perf_evsel__next(evsel);
1154 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1155 TEST_ASSERT_VAL("wrong config",
1156 PERF_COUNT_HW_BRANCH_MISSES == evsel->core.attr.config);
1157 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
1158 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
1159 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
1160 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
1161 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
1162 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1163 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1164 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
1165 TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read);
1170 static int test__leader_sample2(struct evlist *evlist __maybe_unused)
1172 struct evsel *evsel, *leader;
1174 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);
1176 /* instructions - sampling group leader */
1177 evsel = leader = perf_evlist__first(evlist);
1178 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1179 TEST_ASSERT_VAL("wrong config",
1180 PERF_COUNT_HW_INSTRUCTIONS == evsel->core.attr.config);
1181 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
1182 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
1183 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
1184 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
1185 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
1186 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1187 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1188 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
1189 TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read);
1191 /* branch-misses - not sampling */
1192 evsel = perf_evsel__next(evsel);
1193 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1194 TEST_ASSERT_VAL("wrong config",
1195 PERF_COUNT_HW_BRANCH_MISSES == evsel->core.attr.config);
1196 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
1197 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
1198 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
1199 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
1200 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
1201 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1202 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1203 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
1204 TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read);
1209 static int test__checkevent_pinned_modifier(struct evlist *evlist)
1211 struct evsel *evsel = perf_evlist__first(evlist);
1213 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
1214 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
1215 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
1216 TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip);
1217 TEST_ASSERT_VAL("wrong pinned", evsel->core.attr.pinned);
1219 return test__checkevent_symbolic_name(evlist);
1222 static int test__pinned_group(struct evlist *evlist)
1224 struct evsel *evsel, *leader;
1226 TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->core.nr_entries);
1228 /* cycles - group leader */
1229 evsel = leader = perf_evlist__first(evlist);
1230 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1231 TEST_ASSERT_VAL("wrong config",
1232 PERF_COUNT_HW_CPU_CYCLES == evsel->core.attr.config);
1233 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1234 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
1235 TEST_ASSERT_VAL("wrong pinned", evsel->core.attr.pinned);
1237 /* cache-misses - can not be pinned, but will go on with the leader */
1238 evsel = perf_evsel__next(evsel);
1239 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1240 TEST_ASSERT_VAL("wrong config",
1241 PERF_COUNT_HW_CACHE_MISSES == evsel->core.attr.config);
1242 TEST_ASSERT_VAL("wrong pinned", !evsel->core.attr.pinned);
1244 /* branch-misses - ditto */
1245 evsel = perf_evsel__next(evsel);
1246 TEST_ASSERT_VAL("wrong config",
1247 PERF_COUNT_HW_BRANCH_MISSES == evsel->core.attr.config);
1248 TEST_ASSERT_VAL("wrong pinned", !evsel->core.attr.pinned);
1253 static int test__checkevent_breakpoint_len(struct evlist *evlist)
1255 struct evsel *evsel = perf_evlist__first(evlist);
1257 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
1258 TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->core.attr.type);
1259 TEST_ASSERT_VAL("wrong config", 0 == evsel->core.attr.config);
1260 TEST_ASSERT_VAL("wrong bp_type", (HW_BREAKPOINT_R | HW_BREAKPOINT_W) ==
1261 evsel->core.attr.bp_type);
1262 TEST_ASSERT_VAL("wrong bp_len", HW_BREAKPOINT_LEN_1 ==
1263 evsel->core.attr.bp_len);
1268 static int test__checkevent_breakpoint_len_w(struct evlist *evlist)
1270 struct evsel *evsel = perf_evlist__first(evlist);
1272 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
1273 TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->core.attr.type);
1274 TEST_ASSERT_VAL("wrong config", 0 == evsel->core.attr.config);
1275 TEST_ASSERT_VAL("wrong bp_type", HW_BREAKPOINT_W ==
1276 evsel->core.attr.bp_type);
1277 TEST_ASSERT_VAL("wrong bp_len", HW_BREAKPOINT_LEN_2 ==
1278 evsel->core.attr.bp_len);
1284 test__checkevent_breakpoint_len_rw_modifier(struct evlist *evlist)
1286 struct evsel *evsel = perf_evlist__first(evlist);
1288 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
1289 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
1290 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
1291 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1293 return test__checkevent_breakpoint_rw(evlist);
1296 static int test__checkevent_precise_max_modifier(struct evlist *evlist)
1298 struct evsel *evsel = perf_evlist__first(evlist);
1300 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);
1301 TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->core.attr.type);
1302 TEST_ASSERT_VAL("wrong config",
1303 PERF_COUNT_SW_TASK_CLOCK == evsel->core.attr.config);
1307 static int test__checkevent_config_symbol(struct evlist *evlist)
1309 struct evsel *evsel = perf_evlist__first(evlist);
1311 TEST_ASSERT_VAL("wrong name setting", strcmp(evsel->name, "insn") == 0);
1315 static int test__checkevent_config_raw(struct evlist *evlist)
1317 struct evsel *evsel = perf_evlist__first(evlist);
1319 TEST_ASSERT_VAL("wrong name setting", strcmp(evsel->name, "rawpmu") == 0);
1323 static int test__checkevent_config_num(struct evlist *evlist)
1325 struct evsel *evsel = perf_evlist__first(evlist);
1327 TEST_ASSERT_VAL("wrong name setting", strcmp(evsel->name, "numpmu") == 0);
1331 static int test__checkevent_config_cache(struct evlist *evlist)
1333 struct evsel *evsel = perf_evlist__first(evlist);
1335 TEST_ASSERT_VAL("wrong name setting", strcmp(evsel->name, "cachepmu") == 0);
1339 static bool test__intel_pt_valid(void)
1341 return !!perf_pmu__find("intel_pt");
1344 static int test__intel_pt(struct evlist *evlist)
1346 struct evsel *evsel = perf_evlist__first(evlist);
1348 TEST_ASSERT_VAL("wrong name setting", strcmp(evsel->name, "intel_pt//u") == 0);
1352 static int test__checkevent_complex_name(struct evlist *evlist)
1354 struct evsel *evsel = perf_evlist__first(evlist);
1356 TEST_ASSERT_VAL("wrong complex name parsing", strcmp(evsel->name, "COMPLEX_CYCLES_NAME:orig=cycles,desc=chip-clock-ticks") == 0);
1360 static int test__sym_event_slash(struct evlist *evlist)
1362 struct evsel *evsel = perf_evlist__first(evlist);
1364 TEST_ASSERT_VAL("wrong type", evsel->core.attr.type == PERF_TYPE_HARDWARE);
1365 TEST_ASSERT_VAL("wrong config", evsel->core.attr.config == PERF_COUNT_HW_CPU_CYCLES);
1366 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
1370 static int test__sym_event_dc(struct evlist *evlist)
1372 struct evsel *evsel = perf_evlist__first(evlist);
1374 TEST_ASSERT_VAL("wrong type", evsel->core.attr.type == PERF_TYPE_HARDWARE);
1375 TEST_ASSERT_VAL("wrong config", evsel->core.attr.config == PERF_COUNT_HW_CPU_CYCLES);
1376 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
1380 static int count_tracepoints(void)
1382 struct dirent *events_ent;
1386 events_dir = tracing_events__opendir();
1388 TEST_ASSERT_VAL("Can't open events dir", events_dir);
1390 while ((events_ent = readdir(events_dir))) {
1392 struct dirent *sys_ent;
1395 if (!strcmp(events_ent->d_name, ".")
1396 || !strcmp(events_ent->d_name, "..")
1397 || !strcmp(events_ent->d_name, "enable")
1398 || !strcmp(events_ent->d_name, "header_event")
1399 || !strcmp(events_ent->d_name, "header_page"))
1402 sys_path = get_events_file(events_ent->d_name);
1403 TEST_ASSERT_VAL("Can't get sys path", sys_path);
1405 sys_dir = opendir(sys_path);
1406 TEST_ASSERT_VAL("Can't open sys dir", sys_dir);
1408 while ((sys_ent = readdir(sys_dir))) {
1409 if (!strcmp(sys_ent->d_name, ".")
1410 || !strcmp(sys_ent->d_name, "..")
1411 || !strcmp(sys_ent->d_name, "enable")
1412 || !strcmp(sys_ent->d_name, "filter"))
1419 put_events_file(sys_path);
1422 closedir(events_dir);
1426 static int test__all_tracepoints(struct evlist *evlist)
1428 TEST_ASSERT_VAL("wrong events count",
1429 count_tracepoints() == evlist->core.nr_entries);
1431 return test__checkevent_tracepoint_multi(evlist);
1434 struct evlist_test {
1438 bool (*valid)(void);
1439 int (*check)(struct evlist *evlist);
1442 static struct evlist_test test__events[] = {
1444 .name = "syscalls:sys_enter_openat",
1445 .check = test__checkevent_tracepoint,
1449 .name = "syscalls:*",
1450 .check = test__checkevent_tracepoint_multi,
1455 .check = test__checkevent_raw,
1460 .check = test__checkevent_numeric,
1464 .name = "instructions",
1465 .check = test__checkevent_symbolic_name,
1469 .name = "cycles/period=100000,config2/",
1470 .check = test__checkevent_symbolic_name_config,
1475 .check = test__checkevent_symbolic_alias,
1479 .name = "L1-dcache-load-miss",
1480 .check = test__checkevent_genhw,
1485 .check = test__checkevent_breakpoint,
1490 .check = test__checkevent_breakpoint_x,
1495 .check = test__checkevent_breakpoint_r,
1500 .check = test__checkevent_breakpoint_w,
1504 .name = "syscalls:sys_enter_openat:k",
1505 .check = test__checkevent_tracepoint_modifier,
1509 .name = "syscalls:*:u",
1510 .check = test__checkevent_tracepoint_multi_modifier,
1515 .check = test__checkevent_raw_modifier,
1520 .check = test__checkevent_numeric_modifier,
1524 .name = "instructions:h",
1525 .check = test__checkevent_symbolic_name_modifier,
1530 .check = test__checkevent_symbolic_alias_modifier,
1534 .name = "L1-dcache-load-miss:kp",
1535 .check = test__checkevent_genhw_modifier,
1540 .check = test__checkevent_breakpoint_modifier,
1544 .name = "mem:0:x:k",
1545 .check = test__checkevent_breakpoint_x_modifier,
1549 .name = "mem:0:r:hp",
1550 .check = test__checkevent_breakpoint_r_modifier,
1554 .name = "mem:0:w:up",
1555 .check = test__checkevent_breakpoint_w_modifier,
1559 .name = "r1,syscalls:sys_enter_openat:k,1:1:hp",
1560 .check = test__checkevent_list,
1564 .name = "instructions:G",
1565 .check = test__checkevent_exclude_host_modifier,
1569 .name = "instructions:H",
1570 .check = test__checkevent_exclude_guest_modifier,
1575 .check = test__checkevent_breakpoint_rw,
1579 .name = "mem:0:rw:kp",
1580 .check = test__checkevent_breakpoint_rw_modifier,
1584 .name = "{instructions:k,cycles:upp}",
1585 .check = test__group1,
1589 .name = "{faults:k,cache-references}:u,cycles:k",
1590 .check = test__group2,
1594 .name = "group1{syscalls:sys_enter_openat:H,cycles:kppp},group2{cycles,1:3}:G,instructions:u",
1595 .check = test__group3,
1599 .name = "{cycles:u,instructions:kp}:p",
1600 .check = test__group4,
1604 .name = "{cycles,instructions}:G,{cycles:G,instructions:G},cycles",
1605 .check = test__group5,
1610 .check = test__all_tracepoints,
1614 .name = "{cycles,cache-misses:G}:H",
1615 .check = test__group_gh1,
1619 .name = "{cycles,cache-misses:H}:G",
1620 .check = test__group_gh2,
1624 .name = "{cycles:G,cache-misses:H}:u",
1625 .check = test__group_gh3,
1629 .name = "{cycles:G,cache-misses:H}:uG",
1630 .check = test__group_gh4,
1634 .name = "{cycles,cache-misses,branch-misses}:S",
1635 .check = test__leader_sample1,
1639 .name = "{instructions,branch-misses}:Su",
1640 .check = test__leader_sample2,
1644 .name = "instructions:uDp",
1645 .check = test__checkevent_pinned_modifier,
1649 .name = "{cycles,cache-misses,branch-misses}:D",
1650 .check = test__pinned_group,
1655 .check = test__checkevent_breakpoint_len,
1659 .name = "mem:0/2:w",
1660 .check = test__checkevent_breakpoint_len_w,
1664 .name = "mem:0/4:rw:u",
1665 .check = test__checkevent_breakpoint_len_rw_modifier,
1668 #if defined(__s390x__)
1670 .name = "kvm-s390:kvm_s390_create_vm",
1671 .check = test__checkevent_tracepoint,
1672 .valid = kvm_s390_create_vm_valid,
1677 .name = "instructions:I",
1678 .check = test__checkevent_exclude_idle_modifier,
1682 .name = "instructions:kIG",
1683 .check = test__checkevent_exclude_idle_modifier_1,
1687 .name = "task-clock:P,cycles",
1688 .check = test__checkevent_precise_max_modifier,
1692 .name = "instructions/name=insn/",
1693 .check = test__checkevent_config_symbol,
1697 .name = "r1234/name=rawpmu/",
1698 .check = test__checkevent_config_raw,
1702 .name = "4:0x6530160/name=numpmu/",
1703 .check = test__checkevent_config_num,
1707 .name = "L1-dcache-misses/name=cachepmu/",
1708 .check = test__checkevent_config_cache,
1712 .name = "intel_pt//u",
1713 .valid = test__intel_pt_valid,
1714 .check = test__intel_pt,
1718 .name = "cycles/name='COMPLEX_CYCLES_NAME:orig=cycles,desc=chip-clock-ticks'/Duk",
1719 .check = test__checkevent_complex_name,
1723 .name = "cycles//u",
1724 .check = test__sym_event_slash,
1729 .check = test__sym_event_dc,
1734 static struct evlist_test test__events_pmu[] = {
1736 .name = "cpu/config=10,config1,config2=3,period=1000/u",
1737 .check = test__checkevent_pmu,
1741 .name = "cpu/config=1,name=krava/u,cpu/config=2/u",
1742 .check = test__checkevent_pmu_name,
1746 .name = "cpu/config=1,call-graph=fp,time,period=100000/,cpu/config=2,call-graph=no,time=0,period=2000/",
1747 .check = test__checkevent_pmu_partial_time_callgraph,
1751 .name = "cpu/name='COMPLEX_CYCLES_NAME:orig=cycles,desc=chip-clock-ticks',period=0x1,event=0x2/ukp",
1752 .check = test__checkevent_complex_name,
1760 int (*check)(struct list_head *terms);
1763 static struct terms_test test__terms[] = {
1765 .str = "config=10,config1,config2=3,umask=1",
1766 .check = test__checkterms_simple,
1770 static int test_event(struct evlist_test *e)
1772 struct parse_events_error err = { .idx = 0, };
1773 struct evlist *evlist;
1776 if (e->valid && !e->valid()) {
1777 pr_debug("... SKIP");
1781 evlist = evlist__new();
1785 ret = parse_events(evlist, e->name, &err);
1787 pr_debug("failed to parse event '%s', err %d, str '%s'\n",
1788 e->name, ret, err.str);
1789 parse_events_print_error(&err, e->name);
1791 ret = e->check(evlist);
1794 evlist__delete(evlist);
1799 static int test_events(struct evlist_test *events, unsigned cnt)
1804 for (i = 0; i < cnt; i++) {
1805 struct evlist_test *e = &events[i];
1807 pr_debug("running test %d '%s'", e->id, e->name);
1808 ret1 = test_event(e);
1817 static int test_term(struct terms_test *t)
1819 struct list_head terms;
1822 INIT_LIST_HEAD(&terms);
1824 ret = parse_events_terms(&terms, t->str);
1826 pr_debug("failed to parse terms '%s', err %d\n",
1831 ret = t->check(&terms);
1832 parse_events_terms__purge(&terms);
1837 static int test_terms(struct terms_test *terms, unsigned cnt)
1842 for (i = 0; i < cnt; i++) {
1843 struct terms_test *t = &terms[i];
1845 pr_debug("running test %d '%s'\n", i, t->str);
1854 static int test_pmu(void)
1857 char path[PATH_MAX];
1860 snprintf(path, PATH_MAX, "%s/bus/event_source/devices/cpu/format/",
1861 sysfs__mountpoint());
1863 ret = stat(path, &st);
1865 pr_debug("omitting PMU cpu tests\n");
1869 static int test_pmu_events(void)
1872 char path[PATH_MAX];
1877 snprintf(path, PATH_MAX, "%s/bus/event_source/devices/cpu/events/",
1878 sysfs__mountpoint());
1880 ret = stat(path, &st);
1882 pr_debug("omitting PMU cpu events tests\n");
1886 dir = opendir(path);
1888 pr_debug("can't open pmu event dir");
1892 while (!ret && (ent = readdir(dir))) {
1893 struct evlist_test e = { .id = 0, };
1894 char name[2 * NAME_MAX + 1 + 12 + 3];
1896 /* Names containing . are special and cannot be used directly */
1897 if (strchr(ent->d_name, '.'))
1900 snprintf(name, sizeof(name), "cpu/event=%s/u", ent->d_name);
1903 e.check = test__checkevent_pmu_events;
1905 ret = test_event(&e);
1908 snprintf(name, sizeof(name), "%s:u,cpu/event=%s/u", ent->d_name, ent->d_name);
1910 e.check = test__checkevent_pmu_events_mix;
1911 ret = test_event(&e);
1918 int test__parse_events(struct test *test __maybe_unused, int subtest __maybe_unused)
1922 #define TEST_EVENTS(tests) \
1924 ret1 = test_events(tests, ARRAY_SIZE(tests)); \
1929 TEST_EVENTS(test__events);
1932 TEST_EVENTS(test__events_pmu);
1935 int ret = test_pmu_events();
1940 ret1 = test_terms(test__terms, ARRAY_SIZE(test__terms));