2 #include "parse-events.h"
6 #include "../../../include/linux/hw_breakpoint.h"
8 #define TEST_ASSERT_VAL(text, cond) \
11 pr_debug("FAILED %s:%d %s\n", __FILE__, __LINE__, text); \
16 #define PERF_TP_SAMPLE_TYPE (PERF_SAMPLE_RAW | PERF_SAMPLE_TIME | \
17 PERF_SAMPLE_CPU | PERF_SAMPLE_PERIOD)
19 static int test__checkevent_tracepoint(struct perf_evlist *evlist)
21 struct perf_evsel *evsel = perf_evlist__first(evlist);
23 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
24 TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->attr.type);
25 TEST_ASSERT_VAL("wrong sample_type",
26 PERF_TP_SAMPLE_TYPE == evsel->attr.sample_type);
27 TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->attr.sample_period);
31 static int test__checkevent_tracepoint_multi(struct perf_evlist *evlist)
33 struct perf_evsel *evsel;
35 TEST_ASSERT_VAL("wrong number of entries", evlist->nr_entries > 1);
37 list_for_each_entry(evsel, &evlist->entries, node) {
38 TEST_ASSERT_VAL("wrong type",
39 PERF_TYPE_TRACEPOINT == evsel->attr.type);
40 TEST_ASSERT_VAL("wrong sample_type",
41 PERF_TP_SAMPLE_TYPE == evsel->attr.sample_type);
42 TEST_ASSERT_VAL("wrong sample_period",
43 1 == evsel->attr.sample_period);
48 static int test__checkevent_raw(struct perf_evlist *evlist)
50 struct perf_evsel *evsel = perf_evlist__first(evlist);
52 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
53 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
54 TEST_ASSERT_VAL("wrong config", 0x1a == evsel->attr.config);
58 static int test__checkevent_numeric(struct perf_evlist *evlist)
60 struct perf_evsel *evsel = perf_evlist__first(evlist);
62 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
63 TEST_ASSERT_VAL("wrong type", 1 == evsel->attr.type);
64 TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
68 static int test__checkevent_symbolic_name(struct perf_evlist *evlist)
70 struct perf_evsel *evsel = perf_evlist__first(evlist);
72 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
73 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
74 TEST_ASSERT_VAL("wrong config",
75 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
79 static int test__checkevent_symbolic_name_config(struct perf_evlist *evlist)
81 struct perf_evsel *evsel = perf_evlist__first(evlist);
83 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
84 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
85 TEST_ASSERT_VAL("wrong config",
86 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
87 TEST_ASSERT_VAL("wrong period",
88 100000 == evsel->attr.sample_period);
89 TEST_ASSERT_VAL("wrong config1",
90 0 == evsel->attr.config1);
91 TEST_ASSERT_VAL("wrong config2",
92 1 == evsel->attr.config2);
96 static int test__checkevent_symbolic_alias(struct perf_evlist *evlist)
98 struct perf_evsel *evsel = perf_evlist__first(evlist);
100 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
101 TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->attr.type);
102 TEST_ASSERT_VAL("wrong config",
103 PERF_COUNT_SW_PAGE_FAULTS == evsel->attr.config);
107 static int test__checkevent_genhw(struct perf_evlist *evlist)
109 struct perf_evsel *evsel = perf_evlist__first(evlist);
111 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
112 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HW_CACHE == evsel->attr.type);
113 TEST_ASSERT_VAL("wrong config", (1 << 16) == evsel->attr.config);
117 static int test__checkevent_breakpoint(struct perf_evlist *evlist)
119 struct perf_evsel *evsel = perf_evlist__first(evlist);
121 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
122 TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->attr.type);
123 TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
124 TEST_ASSERT_VAL("wrong bp_type", (HW_BREAKPOINT_R | HW_BREAKPOINT_W) ==
125 evsel->attr.bp_type);
126 TEST_ASSERT_VAL("wrong bp_len", HW_BREAKPOINT_LEN_4 ==
131 static int test__checkevent_breakpoint_x(struct perf_evlist *evlist)
133 struct perf_evsel *evsel = perf_evlist__first(evlist);
135 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
136 TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->attr.type);
137 TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
138 TEST_ASSERT_VAL("wrong bp_type",
139 HW_BREAKPOINT_X == evsel->attr.bp_type);
140 TEST_ASSERT_VAL("wrong bp_len", sizeof(long) == evsel->attr.bp_len);
144 static int test__checkevent_breakpoint_r(struct perf_evlist *evlist)
146 struct perf_evsel *evsel = perf_evlist__first(evlist);
148 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
149 TEST_ASSERT_VAL("wrong type",
150 PERF_TYPE_BREAKPOINT == evsel->attr.type);
151 TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
152 TEST_ASSERT_VAL("wrong bp_type",
153 HW_BREAKPOINT_R == evsel->attr.bp_type);
154 TEST_ASSERT_VAL("wrong bp_len",
155 HW_BREAKPOINT_LEN_4 == evsel->attr.bp_len);
159 static int test__checkevent_breakpoint_w(struct perf_evlist *evlist)
161 struct perf_evsel *evsel = perf_evlist__first(evlist);
163 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
164 TEST_ASSERT_VAL("wrong type",
165 PERF_TYPE_BREAKPOINT == evsel->attr.type);
166 TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
167 TEST_ASSERT_VAL("wrong bp_type",
168 HW_BREAKPOINT_W == evsel->attr.bp_type);
169 TEST_ASSERT_VAL("wrong bp_len",
170 HW_BREAKPOINT_LEN_4 == evsel->attr.bp_len);
174 static int test__checkevent_breakpoint_rw(struct perf_evlist *evlist)
176 struct perf_evsel *evsel = perf_evlist__first(evlist);
178 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
179 TEST_ASSERT_VAL("wrong type",
180 PERF_TYPE_BREAKPOINT == evsel->attr.type);
181 TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
182 TEST_ASSERT_VAL("wrong bp_type",
183 (HW_BREAKPOINT_R|HW_BREAKPOINT_W) == evsel->attr.bp_type);
184 TEST_ASSERT_VAL("wrong bp_len",
185 HW_BREAKPOINT_LEN_4 == evsel->attr.bp_len);
189 static int test__checkevent_tracepoint_modifier(struct perf_evlist *evlist)
191 struct perf_evsel *evsel = perf_evlist__first(evlist);
193 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
194 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
195 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
196 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
198 return test__checkevent_tracepoint(evlist);
202 test__checkevent_tracepoint_multi_modifier(struct perf_evlist *evlist)
204 struct perf_evsel *evsel;
206 TEST_ASSERT_VAL("wrong number of entries", evlist->nr_entries > 1);
208 list_for_each_entry(evsel, &evlist->entries, node) {
209 TEST_ASSERT_VAL("wrong exclude_user",
210 !evsel->attr.exclude_user);
211 TEST_ASSERT_VAL("wrong exclude_kernel",
212 evsel->attr.exclude_kernel);
213 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
214 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
217 return test__checkevent_tracepoint_multi(evlist);
220 static int test__checkevent_raw_modifier(struct perf_evlist *evlist)
222 struct perf_evsel *evsel = perf_evlist__first(evlist);
224 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
225 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
226 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
227 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
229 return test__checkevent_raw(evlist);
232 static int test__checkevent_numeric_modifier(struct perf_evlist *evlist)
234 struct perf_evsel *evsel = perf_evlist__first(evlist);
236 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
237 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
238 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
239 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
241 return test__checkevent_numeric(evlist);
244 static int test__checkevent_symbolic_name_modifier(struct perf_evlist *evlist)
246 struct perf_evsel *evsel = perf_evlist__first(evlist);
248 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
249 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
250 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
251 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
253 return test__checkevent_symbolic_name(evlist);
256 static int test__checkevent_exclude_host_modifier(struct perf_evlist *evlist)
258 struct perf_evsel *evsel = perf_evlist__first(evlist);
260 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
261 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
263 return test__checkevent_symbolic_name(evlist);
266 static int test__checkevent_exclude_guest_modifier(struct perf_evlist *evlist)
268 struct perf_evsel *evsel = perf_evlist__first(evlist);
270 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
271 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
273 return test__checkevent_symbolic_name(evlist);
276 static int test__checkevent_symbolic_alias_modifier(struct perf_evlist *evlist)
278 struct perf_evsel *evsel = perf_evlist__first(evlist);
280 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
281 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
282 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
283 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
285 return test__checkevent_symbolic_alias(evlist);
288 static int test__checkevent_genhw_modifier(struct perf_evlist *evlist)
290 struct perf_evsel *evsel = perf_evlist__first(evlist);
292 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
293 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
294 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
295 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
297 return test__checkevent_genhw(evlist);
300 static int test__checkevent_breakpoint_modifier(struct perf_evlist *evlist)
302 struct perf_evsel *evsel = perf_evlist__first(evlist);
304 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
305 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
306 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
307 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
308 TEST_ASSERT_VAL("wrong name",
309 !strcmp(perf_evsel__name(evsel), "mem:0x0:rw:u"));
311 return test__checkevent_breakpoint(evlist);
314 static int test__checkevent_breakpoint_x_modifier(struct perf_evlist *evlist)
316 struct perf_evsel *evsel = perf_evlist__first(evlist);
318 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
319 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
320 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
321 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
322 TEST_ASSERT_VAL("wrong name",
323 !strcmp(perf_evsel__name(evsel), "mem:0x0:x:k"));
325 return test__checkevent_breakpoint_x(evlist);
328 static int test__checkevent_breakpoint_r_modifier(struct perf_evlist *evlist)
330 struct perf_evsel *evsel = perf_evlist__first(evlist);
332 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
333 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
334 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
335 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
336 TEST_ASSERT_VAL("wrong name",
337 !strcmp(perf_evsel__name(evsel), "mem:0x0:r:hp"));
339 return test__checkevent_breakpoint_r(evlist);
342 static int test__checkevent_breakpoint_w_modifier(struct perf_evlist *evlist)
344 struct perf_evsel *evsel = perf_evlist__first(evlist);
346 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
347 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
348 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
349 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
350 TEST_ASSERT_VAL("wrong name",
351 !strcmp(perf_evsel__name(evsel), "mem:0x0:w:up"));
353 return test__checkevent_breakpoint_w(evlist);
356 static int test__checkevent_breakpoint_rw_modifier(struct perf_evlist *evlist)
358 struct perf_evsel *evsel = perf_evlist__first(evlist);
360 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
361 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
362 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
363 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
364 TEST_ASSERT_VAL("wrong name",
365 !strcmp(perf_evsel__name(evsel), "mem:0x0:rw:kp"));
367 return test__checkevent_breakpoint_rw(evlist);
370 static int test__checkevent_pmu(struct perf_evlist *evlist)
373 struct perf_evsel *evsel = perf_evlist__first(evlist);
375 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
376 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
377 TEST_ASSERT_VAL("wrong config", 10 == evsel->attr.config);
378 TEST_ASSERT_VAL("wrong config1", 1 == evsel->attr.config1);
379 TEST_ASSERT_VAL("wrong config2", 3 == evsel->attr.config2);
380 TEST_ASSERT_VAL("wrong period", 1000 == evsel->attr.sample_period);
385 static int test__checkevent_list(struct perf_evlist *evlist)
387 struct perf_evsel *evsel = perf_evlist__first(evlist);
389 TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->nr_entries);
392 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
393 TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
394 TEST_ASSERT_VAL("wrong config1", 0 == evsel->attr.config1);
395 TEST_ASSERT_VAL("wrong config2", 0 == evsel->attr.config2);
396 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
397 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
398 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
399 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
401 /* syscalls:sys_enter_open:k */
402 evsel = perf_evsel__next(evsel);
403 TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->attr.type);
404 TEST_ASSERT_VAL("wrong sample_type",
405 PERF_TP_SAMPLE_TYPE == evsel->attr.sample_type);
406 TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->attr.sample_period);
407 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
408 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
409 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
410 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
413 evsel = perf_evsel__next(evsel);
414 TEST_ASSERT_VAL("wrong type", 1 == evsel->attr.type);
415 TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
416 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
417 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
418 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
419 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
424 static int test__checkevent_pmu_name(struct perf_evlist *evlist)
426 struct perf_evsel *evsel = perf_evlist__first(evlist);
428 /* cpu/config=1,name=krava/u */
429 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
430 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
431 TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
432 TEST_ASSERT_VAL("wrong name", !strcmp(perf_evsel__name(evsel), "krava"));
434 /* cpu/config=2/u" */
435 evsel = perf_evsel__next(evsel);
436 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
437 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
438 TEST_ASSERT_VAL("wrong config", 2 == evsel->attr.config);
439 TEST_ASSERT_VAL("wrong name",
440 !strcmp(perf_evsel__name(evsel), "raw 0x2:u"));
445 static int test__checkterms_simple(struct list_head *terms)
447 struct parse_events__term *term;
450 term = list_entry(terms->next, struct parse_events__term, list);
451 TEST_ASSERT_VAL("wrong type term",
452 term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG);
453 TEST_ASSERT_VAL("wrong type val",
454 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
455 TEST_ASSERT_VAL("wrong val", term->val.num == 10);
456 TEST_ASSERT_VAL("wrong config", !term->config);
459 term = list_entry(term->list.next, struct parse_events__term, list);
460 TEST_ASSERT_VAL("wrong type term",
461 term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG1);
462 TEST_ASSERT_VAL("wrong type val",
463 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
464 TEST_ASSERT_VAL("wrong val", term->val.num == 1);
465 TEST_ASSERT_VAL("wrong config", !term->config);
468 term = list_entry(term->list.next, struct parse_events__term, list);
469 TEST_ASSERT_VAL("wrong type term",
470 term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG2);
471 TEST_ASSERT_VAL("wrong type val",
472 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
473 TEST_ASSERT_VAL("wrong val", term->val.num == 3);
474 TEST_ASSERT_VAL("wrong config", !term->config);
477 term = list_entry(term->list.next, struct parse_events__term, list);
478 TEST_ASSERT_VAL("wrong type term",
479 term->type_term == PARSE_EVENTS__TERM_TYPE_USER);
480 TEST_ASSERT_VAL("wrong type val",
481 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
482 TEST_ASSERT_VAL("wrong val", term->val.num == 1);
483 TEST_ASSERT_VAL("wrong config", !strcmp(term->config, "umask"));
488 static int test__group1(struct perf_evlist *evlist)
490 struct perf_evsel *evsel, *leader;
492 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
495 evsel = leader = perf_evlist__first(evlist);
496 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
497 TEST_ASSERT_VAL("wrong config",
498 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
499 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
500 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
501 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
502 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
503 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
504 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
505 TEST_ASSERT_VAL("wrong leader", evsel->leader == NULL);
508 evsel = perf_evsel__next(evsel);
509 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
510 TEST_ASSERT_VAL("wrong config",
511 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
512 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
513 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
514 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
515 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
516 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
517 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 2);
518 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
523 static int test__group2(struct perf_evlist *evlist)
525 struct perf_evsel *evsel, *leader;
527 TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->nr_entries);
529 /* faults + :ku modifier */
530 evsel = leader = perf_evlist__first(evlist);
531 TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->attr.type);
532 TEST_ASSERT_VAL("wrong config",
533 PERF_COUNT_SW_PAGE_FAULTS == evsel->attr.config);
534 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
535 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
536 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
537 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
538 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
539 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
540 TEST_ASSERT_VAL("wrong leader", evsel->leader == NULL);
542 /* cache-references + :u modifier */
543 evsel = perf_evsel__next(evsel);
544 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
545 TEST_ASSERT_VAL("wrong config",
546 PERF_COUNT_HW_CACHE_REFERENCES == evsel->attr.config);
547 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
548 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
549 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
550 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
551 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
552 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
553 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
556 evsel = perf_evsel__next(evsel);
557 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
558 TEST_ASSERT_VAL("wrong config",
559 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
560 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
561 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
562 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
563 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
564 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
565 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
566 TEST_ASSERT_VAL("wrong leader", evsel->leader == NULL);
571 static int test__group3(struct perf_evlist *evlist __used)
573 struct perf_evsel *evsel, *leader;
575 TEST_ASSERT_VAL("wrong number of entries", 5 == evlist->nr_entries);
577 /* group1 syscalls:sys_enter_open:H */
578 evsel = leader = perf_evlist__first(evlist);
579 TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->attr.type);
580 TEST_ASSERT_VAL("wrong sample_type",
581 PERF_TP_SAMPLE_TYPE == evsel->attr.sample_type);
582 TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->attr.sample_period);
583 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
584 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
585 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
586 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
587 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
588 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
589 TEST_ASSERT_VAL("wrong leader", evsel->leader == NULL);
590 TEST_ASSERT_VAL("wrong group name",
591 !strcmp(leader->group_name, "group1"));
593 /* group1 cycles:kppp */
594 evsel = perf_evsel__next(evsel);
595 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
596 TEST_ASSERT_VAL("wrong config",
597 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
598 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
599 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
600 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
601 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
602 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
603 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 3);
604 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
605 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
607 /* group2 cycles + G modifier */
608 evsel = leader = perf_evsel__next(evsel);
609 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
610 TEST_ASSERT_VAL("wrong config",
611 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
612 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
613 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
614 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
615 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
616 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
617 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
618 TEST_ASSERT_VAL("wrong leader", evsel->leader == NULL);
619 TEST_ASSERT_VAL("wrong group name",
620 !strcmp(leader->group_name, "group2"));
622 /* group2 1:3 + G modifier */
623 evsel = perf_evsel__next(evsel);
624 TEST_ASSERT_VAL("wrong type", 1 == evsel->attr.type);
625 TEST_ASSERT_VAL("wrong config", 3 == evsel->attr.config);
626 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
627 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
628 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
629 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
630 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
631 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
632 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
635 evsel = perf_evsel__next(evsel);
636 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
637 TEST_ASSERT_VAL("wrong config",
638 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
639 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
640 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
641 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
642 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
643 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
644 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
645 TEST_ASSERT_VAL("wrong leader", evsel->leader == NULL);
650 static int test__group4(struct perf_evlist *evlist __used)
652 struct perf_evsel *evsel, *leader;
654 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
657 evsel = leader = perf_evlist__first(evlist);
658 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
659 TEST_ASSERT_VAL("wrong config",
660 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
661 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
662 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
663 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
664 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
665 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
666 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 1);
667 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
668 TEST_ASSERT_VAL("wrong leader", evsel->leader == NULL);
670 /* instructions:kp + p */
671 evsel = perf_evsel__next(evsel);
672 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
673 TEST_ASSERT_VAL("wrong config",
674 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
675 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
676 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
677 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
678 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
679 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
680 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 2);
681 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
686 static int test__group5(struct perf_evlist *evlist __used)
688 struct perf_evsel *evsel, *leader;
690 TEST_ASSERT_VAL("wrong number of entries", 5 == evlist->nr_entries);
693 evsel = leader = perf_evlist__first(evlist);
694 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
695 TEST_ASSERT_VAL("wrong config",
696 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
697 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
698 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
699 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
700 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
701 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
702 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
703 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
704 TEST_ASSERT_VAL("wrong leader", evsel->leader == NULL);
706 /* instructions + G */
707 evsel = perf_evsel__next(evsel);
708 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
709 TEST_ASSERT_VAL("wrong config",
710 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
711 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
712 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
713 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
714 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
715 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
716 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
717 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
720 evsel = leader = perf_evsel__next(evsel);
721 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
722 TEST_ASSERT_VAL("wrong config",
723 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
724 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
725 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
726 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
727 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
728 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
729 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
730 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
731 TEST_ASSERT_VAL("wrong leader", evsel->leader == NULL);
734 evsel = perf_evsel__next(evsel);
735 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
736 TEST_ASSERT_VAL("wrong config",
737 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
738 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
739 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
740 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
741 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
742 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
743 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
744 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
747 evsel = perf_evsel__next(evsel);
748 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
749 TEST_ASSERT_VAL("wrong config",
750 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
751 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
752 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
753 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
754 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
755 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
756 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
757 TEST_ASSERT_VAL("wrong leader", evsel->leader == NULL);
762 struct test__event_st {
765 int (*check)(struct perf_evlist *evlist);
768 static struct test__event_st test__events[] = {
770 .name = "syscalls:sys_enter_open",
771 .check = test__checkevent_tracepoint,
774 .name = "syscalls:*",
775 .check = test__checkevent_tracepoint_multi,
779 .check = test__checkevent_raw,
783 .check = test__checkevent_numeric,
786 .name = "instructions",
787 .check = test__checkevent_symbolic_name,
790 .name = "cycles/period=100000,config2/",
791 .check = test__checkevent_symbolic_name_config,
795 .check = test__checkevent_symbolic_alias,
798 .name = "L1-dcache-load-miss",
799 .check = test__checkevent_genhw,
803 .check = test__checkevent_breakpoint,
807 .check = test__checkevent_breakpoint_x,
811 .check = test__checkevent_breakpoint_r,
815 .check = test__checkevent_breakpoint_w,
818 .name = "syscalls:sys_enter_open:k",
819 .check = test__checkevent_tracepoint_modifier,
822 .name = "syscalls:*:u",
823 .check = test__checkevent_tracepoint_multi_modifier,
827 .check = test__checkevent_raw_modifier,
831 .check = test__checkevent_numeric_modifier,
834 .name = "instructions:h",
835 .check = test__checkevent_symbolic_name_modifier,
839 .check = test__checkevent_symbolic_alias_modifier,
842 .name = "L1-dcache-load-miss:kp",
843 .check = test__checkevent_genhw_modifier,
847 .check = test__checkevent_breakpoint_modifier,
851 .check = test__checkevent_breakpoint_x_modifier,
854 .name = "mem:0:r:hp",
855 .check = test__checkevent_breakpoint_r_modifier,
858 .name = "mem:0:w:up",
859 .check = test__checkevent_breakpoint_w_modifier,
862 .name = "r1,syscalls:sys_enter_open:k,1:1:hp",
863 .check = test__checkevent_list,
866 .name = "instructions:G",
867 .check = test__checkevent_exclude_host_modifier,
870 .name = "instructions:H",
871 .check = test__checkevent_exclude_guest_modifier,
875 .check = test__checkevent_breakpoint_rw,
878 .name = "mem:0:rw:kp",
879 .check = test__checkevent_breakpoint_rw_modifier,
882 .name = "{instructions:k,cycles:upp}",
883 .check = test__group1,
886 .name = "{faults:k,cache-references}:u,cycles:k",
887 .check = test__group2,
890 .name = "group1{syscalls:sys_enter_open:H,cycles:kppp},group2{cycles,1:3}:G,instructions:u",
891 .check = test__group3,
894 .name = "{cycles:u,instructions:kp}:p",
895 .check = test__group4,
898 .name = "{cycles,instructions}:G,{cycles:G,instructions:G},cycles",
899 .check = test__group5,
903 static struct test__event_st test__events_pmu[] = {
905 .name = "cpu/config=10,config1,config2=3,period=1000/u",
906 .check = test__checkevent_pmu,
909 .name = "cpu/config=1,name=krava/u,cpu/config=2/u",
910 .check = test__checkevent_pmu_name,
917 int (*check)(struct list_head *terms);
920 static struct test__term test__terms[] = {
922 .str = "config=10,config1,config2=3,umask=1",
923 .check = test__checkterms_simple,
927 static int test_event(struct test__event_st *e)
929 struct perf_evlist *evlist;
932 evlist = perf_evlist__new(NULL, NULL);
936 ret = parse_events(evlist, e->name, 0);
938 pr_debug("failed to parse event '%s', err %d\n",
943 ret = e->check(evlist);
944 perf_evlist__delete(evlist);
949 static int test_events(struct test__event_st *events, unsigned cnt)
954 for (i = 0; i < cnt; i++) {
955 struct test__event_st *e = &events[i];
957 pr_debug("running test %d '%s'\n", i, e->name);
966 static int test_term(struct test__term *t)
968 struct list_head *terms;
971 terms = malloc(sizeof(*terms));
975 INIT_LIST_HEAD(terms);
977 ret = parse_events_terms(terms, t->str);
979 pr_debug("failed to parse terms '%s', err %d\n",
984 ret = t->check(terms);
985 parse_events__free_terms(terms);
990 static int test_terms(struct test__term *terms, unsigned cnt)
995 for (i = 0; i < cnt; i++) {
996 struct test__term *t = &terms[i];
998 pr_debug("running test %d '%s'\n", i, t->str);
1007 static int test_pmu(void)
1010 char path[PATH_MAX];
1013 snprintf(path, PATH_MAX, "%s/bus/event_source/devices/cpu/format/",
1014 sysfs_find_mountpoint());
1016 ret = stat(path, &st);
1018 pr_debug("ommiting PMU cpu tests\n");
1022 int parse_events__test(void)
1026 #define TEST_EVENTS(tests) \
1028 ret = test_events(tests, ARRAY_SIZE(tests)); \
1033 TEST_EVENTS(test__events);
1036 TEST_EVENTS(test__events_pmu);
1038 return test_terms(test__terms, ARRAY_SIZE(test__terms));