2 #include "parse-events.h"
7 #include <linux/hw_breakpoint.h>
9 #define TEST_ASSERT_VAL(text, cond) \
12 pr_debug("FAILED %s:%d %s\n", __FILE__, __LINE__, text); \
17 #define PERF_TP_SAMPLE_TYPE (PERF_SAMPLE_RAW | PERF_SAMPLE_TIME | \
18 PERF_SAMPLE_CPU | PERF_SAMPLE_PERIOD)
20 static int test__checkevent_tracepoint(struct perf_evlist *evlist)
22 struct perf_evsel *evsel = perf_evlist__first(evlist);
24 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
25 TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->attr.type);
26 TEST_ASSERT_VAL("wrong sample_type",
27 PERF_TP_SAMPLE_TYPE == evsel->attr.sample_type);
28 TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->attr.sample_period);
32 static int test__checkevent_tracepoint_multi(struct perf_evlist *evlist)
34 struct perf_evsel *evsel;
36 TEST_ASSERT_VAL("wrong number of entries", evlist->nr_entries > 1);
38 list_for_each_entry(evsel, &evlist->entries, node) {
39 TEST_ASSERT_VAL("wrong type",
40 PERF_TYPE_TRACEPOINT == evsel->attr.type);
41 TEST_ASSERT_VAL("wrong sample_type",
42 PERF_TP_SAMPLE_TYPE == evsel->attr.sample_type);
43 TEST_ASSERT_VAL("wrong sample_period",
44 1 == evsel->attr.sample_period);
49 static int test__checkevent_raw(struct perf_evlist *evlist)
51 struct perf_evsel *evsel = perf_evlist__first(evlist);
53 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
54 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
55 TEST_ASSERT_VAL("wrong config", 0x1a == evsel->attr.config);
59 static int test__checkevent_numeric(struct perf_evlist *evlist)
61 struct perf_evsel *evsel = perf_evlist__first(evlist);
63 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
64 TEST_ASSERT_VAL("wrong type", 1 == evsel->attr.type);
65 TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
69 static int test__checkevent_symbolic_name(struct perf_evlist *evlist)
71 struct perf_evsel *evsel = perf_evlist__first(evlist);
73 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
74 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
75 TEST_ASSERT_VAL("wrong config",
76 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
80 static int test__checkevent_symbolic_name_config(struct perf_evlist *evlist)
82 struct perf_evsel *evsel = perf_evlist__first(evlist);
84 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
85 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
86 TEST_ASSERT_VAL("wrong config",
87 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
88 TEST_ASSERT_VAL("wrong period",
89 100000 == evsel->attr.sample_period);
90 TEST_ASSERT_VAL("wrong config1",
91 0 == evsel->attr.config1);
92 TEST_ASSERT_VAL("wrong config2",
93 1 == evsel->attr.config2);
97 static int test__checkevent_symbolic_alias(struct perf_evlist *evlist)
99 struct perf_evsel *evsel = perf_evlist__first(evlist);
101 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
102 TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->attr.type);
103 TEST_ASSERT_VAL("wrong config",
104 PERF_COUNT_SW_PAGE_FAULTS == evsel->attr.config);
108 static int test__checkevent_genhw(struct perf_evlist *evlist)
110 struct perf_evsel *evsel = perf_evlist__first(evlist);
112 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
113 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HW_CACHE == evsel->attr.type);
114 TEST_ASSERT_VAL("wrong config", (1 << 16) == evsel->attr.config);
118 static int test__checkevent_breakpoint(struct perf_evlist *evlist)
120 struct perf_evsel *evsel = perf_evlist__first(evlist);
122 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
123 TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->attr.type);
124 TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
125 TEST_ASSERT_VAL("wrong bp_type", (HW_BREAKPOINT_R | HW_BREAKPOINT_W) ==
126 evsel->attr.bp_type);
127 TEST_ASSERT_VAL("wrong bp_len", HW_BREAKPOINT_LEN_4 ==
132 static int test__checkevent_breakpoint_x(struct perf_evlist *evlist)
134 struct perf_evsel *evsel = perf_evlist__first(evlist);
136 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
137 TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->attr.type);
138 TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
139 TEST_ASSERT_VAL("wrong bp_type",
140 HW_BREAKPOINT_X == evsel->attr.bp_type);
141 TEST_ASSERT_VAL("wrong bp_len", sizeof(long) == evsel->attr.bp_len);
145 static int test__checkevent_breakpoint_r(struct perf_evlist *evlist)
147 struct perf_evsel *evsel = perf_evlist__first(evlist);
149 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
150 TEST_ASSERT_VAL("wrong type",
151 PERF_TYPE_BREAKPOINT == evsel->attr.type);
152 TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
153 TEST_ASSERT_VAL("wrong bp_type",
154 HW_BREAKPOINT_R == evsel->attr.bp_type);
155 TEST_ASSERT_VAL("wrong bp_len",
156 HW_BREAKPOINT_LEN_4 == evsel->attr.bp_len);
160 static int test__checkevent_breakpoint_w(struct perf_evlist *evlist)
162 struct perf_evsel *evsel = perf_evlist__first(evlist);
164 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
165 TEST_ASSERT_VAL("wrong type",
166 PERF_TYPE_BREAKPOINT == evsel->attr.type);
167 TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
168 TEST_ASSERT_VAL("wrong bp_type",
169 HW_BREAKPOINT_W == evsel->attr.bp_type);
170 TEST_ASSERT_VAL("wrong bp_len",
171 HW_BREAKPOINT_LEN_4 == evsel->attr.bp_len);
175 static int test__checkevent_breakpoint_rw(struct perf_evlist *evlist)
177 struct perf_evsel *evsel = perf_evlist__first(evlist);
179 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
180 TEST_ASSERT_VAL("wrong type",
181 PERF_TYPE_BREAKPOINT == evsel->attr.type);
182 TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
183 TEST_ASSERT_VAL("wrong bp_type",
184 (HW_BREAKPOINT_R|HW_BREAKPOINT_W) == evsel->attr.bp_type);
185 TEST_ASSERT_VAL("wrong bp_len",
186 HW_BREAKPOINT_LEN_4 == evsel->attr.bp_len);
190 static int test__checkevent_tracepoint_modifier(struct perf_evlist *evlist)
192 struct perf_evsel *evsel = perf_evlist__first(evlist);
194 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
195 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
196 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
197 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
199 return test__checkevent_tracepoint(evlist);
203 test__checkevent_tracepoint_multi_modifier(struct perf_evlist *evlist)
205 struct perf_evsel *evsel;
207 TEST_ASSERT_VAL("wrong number of entries", evlist->nr_entries > 1);
209 list_for_each_entry(evsel, &evlist->entries, node) {
210 TEST_ASSERT_VAL("wrong exclude_user",
211 !evsel->attr.exclude_user);
212 TEST_ASSERT_VAL("wrong exclude_kernel",
213 evsel->attr.exclude_kernel);
214 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
215 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
218 return test__checkevent_tracepoint_multi(evlist);
221 static int test__checkevent_raw_modifier(struct perf_evlist *evlist)
223 struct perf_evsel *evsel = perf_evlist__first(evlist);
225 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
226 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
227 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
228 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
230 return test__checkevent_raw(evlist);
233 static int test__checkevent_numeric_modifier(struct perf_evlist *evlist)
235 struct perf_evsel *evsel = perf_evlist__first(evlist);
237 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
238 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
239 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
240 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
242 return test__checkevent_numeric(evlist);
245 static int test__checkevent_symbolic_name_modifier(struct perf_evlist *evlist)
247 struct perf_evsel *evsel = perf_evlist__first(evlist);
249 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
250 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
251 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
252 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
254 return test__checkevent_symbolic_name(evlist);
257 static int test__checkevent_exclude_host_modifier(struct perf_evlist *evlist)
259 struct perf_evsel *evsel = perf_evlist__first(evlist);
261 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
262 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
264 return test__checkevent_symbolic_name(evlist);
267 static int test__checkevent_exclude_guest_modifier(struct perf_evlist *evlist)
269 struct perf_evsel *evsel = perf_evlist__first(evlist);
271 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
272 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
274 return test__checkevent_symbolic_name(evlist);
277 static int test__checkevent_symbolic_alias_modifier(struct perf_evlist *evlist)
279 struct perf_evsel *evsel = perf_evlist__first(evlist);
281 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
282 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
283 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
284 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
286 return test__checkevent_symbolic_alias(evlist);
289 static int test__checkevent_genhw_modifier(struct perf_evlist *evlist)
291 struct perf_evsel *evsel = perf_evlist__first(evlist);
293 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
294 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
295 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
296 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
298 return test__checkevent_genhw(evlist);
301 static int test__checkevent_breakpoint_modifier(struct perf_evlist *evlist)
303 struct perf_evsel *evsel = perf_evlist__first(evlist);
306 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
307 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
308 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
309 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
310 TEST_ASSERT_VAL("wrong name",
311 !strcmp(perf_evsel__name(evsel), "mem:0:u"));
313 return test__checkevent_breakpoint(evlist);
316 static int test__checkevent_breakpoint_x_modifier(struct perf_evlist *evlist)
318 struct perf_evsel *evsel = perf_evlist__first(evlist);
320 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
321 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
322 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
323 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
324 TEST_ASSERT_VAL("wrong name",
325 !strcmp(perf_evsel__name(evsel), "mem:0:x:k"));
327 return test__checkevent_breakpoint_x(evlist);
330 static int test__checkevent_breakpoint_r_modifier(struct perf_evlist *evlist)
332 struct perf_evsel *evsel = perf_evlist__first(evlist);
334 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
335 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
336 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
337 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
338 TEST_ASSERT_VAL("wrong name",
339 !strcmp(perf_evsel__name(evsel), "mem:0:r:hp"));
341 return test__checkevent_breakpoint_r(evlist);
344 static int test__checkevent_breakpoint_w_modifier(struct perf_evlist *evlist)
346 struct perf_evsel *evsel = perf_evlist__first(evlist);
348 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
349 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
350 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
351 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
352 TEST_ASSERT_VAL("wrong name",
353 !strcmp(perf_evsel__name(evsel), "mem:0:w:up"));
355 return test__checkevent_breakpoint_w(evlist);
358 static int test__checkevent_breakpoint_rw_modifier(struct perf_evlist *evlist)
360 struct perf_evsel *evsel = perf_evlist__first(evlist);
362 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
363 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
364 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
365 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
366 TEST_ASSERT_VAL("wrong name",
367 !strcmp(perf_evsel__name(evsel), "mem:0:rw:kp"));
369 return test__checkevent_breakpoint_rw(evlist);
372 static int test__checkevent_pmu(struct perf_evlist *evlist)
375 struct perf_evsel *evsel = perf_evlist__first(evlist);
377 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
378 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
379 TEST_ASSERT_VAL("wrong config", 10 == evsel->attr.config);
380 TEST_ASSERT_VAL("wrong config1", 1 == evsel->attr.config1);
381 TEST_ASSERT_VAL("wrong config2", 3 == evsel->attr.config2);
382 TEST_ASSERT_VAL("wrong period", 1000 == evsel->attr.sample_period);
387 static int test__checkevent_list(struct perf_evlist *evlist)
389 struct perf_evsel *evsel = perf_evlist__first(evlist);
391 TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->nr_entries);
394 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
395 TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
396 TEST_ASSERT_VAL("wrong config1", 0 == evsel->attr.config1);
397 TEST_ASSERT_VAL("wrong config2", 0 == evsel->attr.config2);
398 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
399 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
400 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
401 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
403 /* syscalls:sys_enter_open:k */
404 evsel = perf_evsel__next(evsel);
405 TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->attr.type);
406 TEST_ASSERT_VAL("wrong sample_type",
407 PERF_TP_SAMPLE_TYPE == evsel->attr.sample_type);
408 TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->attr.sample_period);
409 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
410 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
411 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
412 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
415 evsel = perf_evsel__next(evsel);
416 TEST_ASSERT_VAL("wrong type", 1 == evsel->attr.type);
417 TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
418 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
419 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
420 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
421 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
426 static int test__checkevent_pmu_name(struct perf_evlist *evlist)
428 struct perf_evsel *evsel = perf_evlist__first(evlist);
430 /* cpu/config=1,name=krava/u */
431 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
432 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
433 TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
434 TEST_ASSERT_VAL("wrong name", !strcmp(perf_evsel__name(evsel), "krava"));
436 /* cpu/config=2/u" */
437 evsel = perf_evsel__next(evsel);
438 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
439 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
440 TEST_ASSERT_VAL("wrong config", 2 == evsel->attr.config);
441 TEST_ASSERT_VAL("wrong name",
442 !strcmp(perf_evsel__name(evsel), "cpu/config=2/u"));
447 static int test__checkevent_pmu_events(struct perf_evlist *evlist)
449 struct perf_evsel *evsel;
451 evsel = list_entry(evlist->entries.next, struct perf_evsel, node);
452 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
453 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
454 TEST_ASSERT_VAL("wrong exclude_user",
455 !evsel->attr.exclude_user);
456 TEST_ASSERT_VAL("wrong exclude_kernel",
457 evsel->attr.exclude_kernel);
458 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
459 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
464 static int test__checkterms_simple(struct list_head *terms)
466 struct parse_events__term *term;
469 term = list_entry(terms->next, struct parse_events__term, list);
470 TEST_ASSERT_VAL("wrong type term",
471 term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG);
472 TEST_ASSERT_VAL("wrong type val",
473 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
474 TEST_ASSERT_VAL("wrong val", term->val.num == 10);
475 TEST_ASSERT_VAL("wrong config", !term->config);
478 term = list_entry(term->list.next, struct parse_events__term, list);
479 TEST_ASSERT_VAL("wrong type term",
480 term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG1);
481 TEST_ASSERT_VAL("wrong type val",
482 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
483 TEST_ASSERT_VAL("wrong val", term->val.num == 1);
484 TEST_ASSERT_VAL("wrong config", !term->config);
487 term = list_entry(term->list.next, struct parse_events__term, list);
488 TEST_ASSERT_VAL("wrong type term",
489 term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG2);
490 TEST_ASSERT_VAL("wrong type val",
491 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
492 TEST_ASSERT_VAL("wrong val", term->val.num == 3);
493 TEST_ASSERT_VAL("wrong config", !term->config);
496 term = list_entry(term->list.next, struct parse_events__term, list);
497 TEST_ASSERT_VAL("wrong type term",
498 term->type_term == PARSE_EVENTS__TERM_TYPE_USER);
499 TEST_ASSERT_VAL("wrong type val",
500 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
501 TEST_ASSERT_VAL("wrong val", term->val.num == 1);
502 TEST_ASSERT_VAL("wrong config", !strcmp(term->config, "umask"));
507 static int test__group1(struct perf_evlist *evlist)
509 struct perf_evsel *evsel, *leader;
511 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
514 evsel = leader = perf_evlist__first(evlist);
515 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
516 TEST_ASSERT_VAL("wrong config",
517 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
518 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
519 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
520 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
521 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
522 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
523 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
524 TEST_ASSERT_VAL("wrong leader", !perf_evsel__is_group_member(evsel));
527 evsel = perf_evsel__next(evsel);
528 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
529 TEST_ASSERT_VAL("wrong config",
530 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
531 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
532 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
533 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
534 /* use of precise requires exclude_guest */
535 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
536 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
537 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 2);
538 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
543 static int test__group2(struct perf_evlist *evlist)
545 struct perf_evsel *evsel, *leader;
547 TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->nr_entries);
549 /* faults + :ku modifier */
550 evsel = leader = perf_evlist__first(evlist);
551 TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->attr.type);
552 TEST_ASSERT_VAL("wrong config",
553 PERF_COUNT_SW_PAGE_FAULTS == evsel->attr.config);
554 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
555 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
556 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
557 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
558 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
559 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
560 TEST_ASSERT_VAL("wrong leader", !perf_evsel__is_group_member(evsel));
562 /* cache-references + :u modifier */
563 evsel = perf_evsel__next(evsel);
564 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
565 TEST_ASSERT_VAL("wrong config",
566 PERF_COUNT_HW_CACHE_REFERENCES == evsel->attr.config);
567 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
568 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
569 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
570 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
571 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
572 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
573 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
576 evsel = perf_evsel__next(evsel);
577 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
578 TEST_ASSERT_VAL("wrong config",
579 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
580 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
581 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
582 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
583 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
584 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
585 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
586 TEST_ASSERT_VAL("wrong leader", !perf_evsel__is_group_member(evsel));
591 static int test__group3(struct perf_evlist *evlist __maybe_unused)
593 struct perf_evsel *evsel, *leader;
595 TEST_ASSERT_VAL("wrong number of entries", 5 == evlist->nr_entries);
597 /* group1 syscalls:sys_enter_open:H */
598 evsel = leader = perf_evlist__first(evlist);
599 TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->attr.type);
600 TEST_ASSERT_VAL("wrong sample_type",
601 PERF_TP_SAMPLE_TYPE == evsel->attr.sample_type);
602 TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->attr.sample_period);
603 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
604 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
605 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
606 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
607 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
608 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
609 TEST_ASSERT_VAL("wrong leader", !perf_evsel__is_group_member(evsel));
610 TEST_ASSERT_VAL("wrong group name",
611 !strcmp(leader->group_name, "group1"));
613 /* group1 cycles:kppp */
614 evsel = perf_evsel__next(evsel);
615 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
616 TEST_ASSERT_VAL("wrong config",
617 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
618 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
619 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
620 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
621 /* use of precise requires exclude_guest */
622 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
623 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
624 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 3);
625 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
626 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
628 /* group2 cycles + G modifier */
629 evsel = leader = perf_evsel__next(evsel);
630 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
631 TEST_ASSERT_VAL("wrong config",
632 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
633 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
634 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
635 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
636 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
637 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
638 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
639 TEST_ASSERT_VAL("wrong leader", !perf_evsel__is_group_member(evsel));
640 TEST_ASSERT_VAL("wrong group name",
641 !strcmp(leader->group_name, "group2"));
643 /* group2 1:3 + G modifier */
644 evsel = perf_evsel__next(evsel);
645 TEST_ASSERT_VAL("wrong type", 1 == evsel->attr.type);
646 TEST_ASSERT_VAL("wrong config", 3 == evsel->attr.config);
647 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
648 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
649 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
650 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
651 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
652 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
653 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
656 evsel = perf_evsel__next(evsel);
657 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
658 TEST_ASSERT_VAL("wrong config",
659 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
660 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
661 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
662 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
663 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
664 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
665 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
666 TEST_ASSERT_VAL("wrong leader", !perf_evsel__is_group_member(evsel));
671 static int test__group4(struct perf_evlist *evlist __maybe_unused)
673 struct perf_evsel *evsel, *leader;
675 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
678 evsel = leader = perf_evlist__first(evlist);
679 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
680 TEST_ASSERT_VAL("wrong config",
681 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
682 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
683 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
684 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
685 /* use of precise requires exclude_guest */
686 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
687 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
688 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 1);
689 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
690 TEST_ASSERT_VAL("wrong leader", !perf_evsel__is_group_member(evsel));
692 /* instructions:kp + p */
693 evsel = perf_evsel__next(evsel);
694 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
695 TEST_ASSERT_VAL("wrong config",
696 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
697 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
698 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
699 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
700 /* use of precise requires exclude_guest */
701 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
702 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
703 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 2);
704 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
709 static int test__group5(struct perf_evlist *evlist __maybe_unused)
711 struct perf_evsel *evsel, *leader;
713 TEST_ASSERT_VAL("wrong number of entries", 5 == evlist->nr_entries);
716 evsel = leader = perf_evlist__first(evlist);
717 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
718 TEST_ASSERT_VAL("wrong config",
719 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
720 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
721 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
722 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
723 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
724 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
725 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
726 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
727 TEST_ASSERT_VAL("wrong leader", !perf_evsel__is_group_member(evsel));
729 /* instructions + G */
730 evsel = perf_evsel__next(evsel);
731 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
732 TEST_ASSERT_VAL("wrong config",
733 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
734 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
735 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
736 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
737 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
738 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
739 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
740 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
743 evsel = leader = perf_evsel__next(evsel);
744 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
745 TEST_ASSERT_VAL("wrong config",
746 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
747 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
748 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
749 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
750 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
751 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
752 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
753 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
754 TEST_ASSERT_VAL("wrong leader", !perf_evsel__is_group_member(evsel));
757 evsel = perf_evsel__next(evsel);
758 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
759 TEST_ASSERT_VAL("wrong config",
760 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
761 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
762 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
763 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
764 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
765 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
766 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
767 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
770 evsel = perf_evsel__next(evsel);
771 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
772 TEST_ASSERT_VAL("wrong config",
773 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
774 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
775 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
776 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
777 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
778 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
779 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
780 TEST_ASSERT_VAL("wrong leader", !perf_evsel__is_group_member(evsel));
785 struct test__event_st {
788 int (*check)(struct perf_evlist *evlist);
791 static struct test__event_st test__events[] = {
793 .name = "syscalls:sys_enter_open",
794 .check = test__checkevent_tracepoint,
797 .name = "syscalls:*",
798 .check = test__checkevent_tracepoint_multi,
802 .check = test__checkevent_raw,
806 .check = test__checkevent_numeric,
809 .name = "instructions",
810 .check = test__checkevent_symbolic_name,
813 .name = "cycles/period=100000,config2/",
814 .check = test__checkevent_symbolic_name_config,
818 .check = test__checkevent_symbolic_alias,
821 .name = "L1-dcache-load-miss",
822 .check = test__checkevent_genhw,
826 .check = test__checkevent_breakpoint,
830 .check = test__checkevent_breakpoint_x,
834 .check = test__checkevent_breakpoint_r,
838 .check = test__checkevent_breakpoint_w,
841 .name = "syscalls:sys_enter_open:k",
842 .check = test__checkevent_tracepoint_modifier,
845 .name = "syscalls:*:u",
846 .check = test__checkevent_tracepoint_multi_modifier,
850 .check = test__checkevent_raw_modifier,
854 .check = test__checkevent_numeric_modifier,
857 .name = "instructions:h",
858 .check = test__checkevent_symbolic_name_modifier,
862 .check = test__checkevent_symbolic_alias_modifier,
865 .name = "L1-dcache-load-miss:kp",
866 .check = test__checkevent_genhw_modifier,
870 .check = test__checkevent_breakpoint_modifier,
874 .check = test__checkevent_breakpoint_x_modifier,
877 .name = "mem:0:r:hp",
878 .check = test__checkevent_breakpoint_r_modifier,
881 .name = "mem:0:w:up",
882 .check = test__checkevent_breakpoint_w_modifier,
885 .name = "r1,syscalls:sys_enter_open:k,1:1:hp",
886 .check = test__checkevent_list,
889 .name = "instructions:G",
890 .check = test__checkevent_exclude_host_modifier,
893 .name = "instructions:H",
894 .check = test__checkevent_exclude_guest_modifier,
898 .check = test__checkevent_breakpoint_rw,
901 .name = "mem:0:rw:kp",
902 .check = test__checkevent_breakpoint_rw_modifier,
905 .name = "{instructions:k,cycles:upp}",
906 .check = test__group1,
909 .name = "{faults:k,cache-references}:u,cycles:k",
910 .check = test__group2,
913 .name = "group1{syscalls:sys_enter_open:H,cycles:kppp},group2{cycles,1:3}:G,instructions:u",
914 .check = test__group3,
917 .name = "{cycles:u,instructions:kp}:p",
918 .check = test__group4,
921 .name = "{cycles,instructions}:G,{cycles:G,instructions:G},cycles",
922 .check = test__group5,
926 static struct test__event_st test__events_pmu[] = {
928 .name = "cpu/config=10,config1,config2=3,period=1000/u",
929 .check = test__checkevent_pmu,
932 .name = "cpu/config=1,name=krava/u,cpu/config=2/u",
933 .check = test__checkevent_pmu_name,
940 int (*check)(struct list_head *terms);
943 static struct test__term test__terms[] = {
945 .str = "config=10,config1,config2=3,umask=1",
946 .check = test__checkterms_simple,
950 static int test_event(struct test__event_st *e)
952 struct perf_evlist *evlist;
955 evlist = perf_evlist__new(NULL, NULL);
959 ret = parse_events(evlist, e->name, 0);
961 pr_debug("failed to parse event '%s', err %d\n",
966 ret = e->check(evlist);
967 perf_evlist__delete(evlist);
972 static int test_events(struct test__event_st *events, unsigned cnt)
977 for (i = 0; i < cnt; i++) {
978 struct test__event_st *e = &events[i];
980 pr_debug("running test %d '%s'\n", i, e->name);
981 ret1 = test_event(e);
989 static int test_term(struct test__term *t)
991 struct list_head *terms;
994 terms = malloc(sizeof(*terms));
998 INIT_LIST_HEAD(terms);
1000 ret = parse_events_terms(terms, t->str);
1002 pr_debug("failed to parse terms '%s', err %d\n",
1007 ret = t->check(terms);
1008 parse_events__free_terms(terms);
1013 static int test_terms(struct test__term *terms, unsigned cnt)
1018 for (i = 0; i < cnt; i++) {
1019 struct test__term *t = &terms[i];
1021 pr_debug("running test %d '%s'\n", i, t->str);
1030 static int test_pmu(void)
1033 char path[PATH_MAX];
1036 snprintf(path, PATH_MAX, "%s/bus/event_source/devices/cpu/format/",
1037 sysfs_find_mountpoint());
1039 ret = stat(path, &st);
1041 pr_debug("omitting PMU cpu tests\n");
1045 static int test_pmu_events(void)
1048 char path[PATH_MAX];
1053 snprintf(path, PATH_MAX, "%s/bus/event_source/devices/cpu/events/",
1054 sysfs_find_mountpoint());
1056 ret = stat(path, &st);
1058 pr_debug("ommiting PMU cpu events tests\n");
1062 dir = opendir(path);
1064 pr_debug("can't open pmu event dir");
1068 while (!ret && (ent = readdir(dir))) {
1069 #define MAX_NAME 100
1070 struct test__event_st e;
1071 char name[MAX_NAME];
1073 if (!strcmp(ent->d_name, ".") ||
1074 !strcmp(ent->d_name, ".."))
1077 snprintf(name, MAX_NAME, "cpu/event=%s/u", ent->d_name);
1080 e.check = test__checkevent_pmu_events;
1082 ret = test_event(&e);
1090 int test__parse_events(void)
1094 #define TEST_EVENTS(tests) \
1096 ret1 = test_events(tests, ARRAY_SIZE(tests)); \
1101 TEST_EVENTS(test__events);
1104 TEST_EVENTS(test__events_pmu);
1107 int ret = test_pmu_events();
1112 ret1 = test_terms(test__terms, ARRAY_SIZE(test__terms));