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 = list_entry(evlist->entries.next,
22 struct perf_evsel, node);
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 = list_entry(evlist->entries.next,
52 struct perf_evsel, node);
54 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
55 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
56 TEST_ASSERT_VAL("wrong config", 0x1a == evsel->attr.config);
60 static int test__checkevent_numeric(struct perf_evlist *evlist)
62 struct perf_evsel *evsel = list_entry(evlist->entries.next,
63 struct perf_evsel, node);
65 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
66 TEST_ASSERT_VAL("wrong type", 1 == evsel->attr.type);
67 TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
71 static int test__checkevent_symbolic_name(struct perf_evlist *evlist)
73 struct perf_evsel *evsel = list_entry(evlist->entries.next,
74 struct perf_evsel, node);
76 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
77 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
78 TEST_ASSERT_VAL("wrong config",
79 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
83 static int test__checkevent_symbolic_name_config(struct perf_evlist *evlist)
85 struct perf_evsel *evsel = list_entry(evlist->entries.next,
86 struct perf_evsel, node);
88 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
89 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
90 TEST_ASSERT_VAL("wrong config",
91 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
92 TEST_ASSERT_VAL("wrong period",
93 100000 == evsel->attr.sample_period);
94 TEST_ASSERT_VAL("wrong config1",
95 0 == evsel->attr.config1);
96 TEST_ASSERT_VAL("wrong config2",
97 1 == evsel->attr.config2);
101 static int test__checkevent_symbolic_alias(struct perf_evlist *evlist)
103 struct perf_evsel *evsel = list_entry(evlist->entries.next,
104 struct perf_evsel, node);
106 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
107 TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->attr.type);
108 TEST_ASSERT_VAL("wrong config",
109 PERF_COUNT_SW_PAGE_FAULTS == evsel->attr.config);
113 static int test__checkevent_genhw(struct perf_evlist *evlist)
115 struct perf_evsel *evsel = list_entry(evlist->entries.next,
116 struct perf_evsel, node);
118 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
119 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HW_CACHE == evsel->attr.type);
120 TEST_ASSERT_VAL("wrong config", (1 << 16) == evsel->attr.config);
124 static int test__checkevent_breakpoint(struct perf_evlist *evlist)
126 struct perf_evsel *evsel = list_entry(evlist->entries.next,
127 struct perf_evsel, node);
129 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
130 TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->attr.type);
131 TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
132 TEST_ASSERT_VAL("wrong bp_type", (HW_BREAKPOINT_R | HW_BREAKPOINT_W) ==
133 evsel->attr.bp_type);
134 TEST_ASSERT_VAL("wrong bp_len", HW_BREAKPOINT_LEN_4 ==
139 static int test__checkevent_breakpoint_x(struct perf_evlist *evlist)
141 struct perf_evsel *evsel = list_entry(evlist->entries.next,
142 struct perf_evsel, node);
144 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
145 TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->attr.type);
146 TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
147 TEST_ASSERT_VAL("wrong bp_type",
148 HW_BREAKPOINT_X == evsel->attr.bp_type);
149 TEST_ASSERT_VAL("wrong bp_len", sizeof(long) == evsel->attr.bp_len);
153 static int test__checkevent_breakpoint_r(struct perf_evlist *evlist)
155 struct perf_evsel *evsel = list_entry(evlist->entries.next,
156 struct perf_evsel, node);
158 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
159 TEST_ASSERT_VAL("wrong type",
160 PERF_TYPE_BREAKPOINT == evsel->attr.type);
161 TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
162 TEST_ASSERT_VAL("wrong bp_type",
163 HW_BREAKPOINT_R == evsel->attr.bp_type);
164 TEST_ASSERT_VAL("wrong bp_len",
165 HW_BREAKPOINT_LEN_4 == evsel->attr.bp_len);
169 static int test__checkevent_breakpoint_w(struct perf_evlist *evlist)
171 struct perf_evsel *evsel = list_entry(evlist->entries.next,
172 struct perf_evsel, node);
174 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
175 TEST_ASSERT_VAL("wrong type",
176 PERF_TYPE_BREAKPOINT == evsel->attr.type);
177 TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
178 TEST_ASSERT_VAL("wrong bp_type",
179 HW_BREAKPOINT_W == evsel->attr.bp_type);
180 TEST_ASSERT_VAL("wrong bp_len",
181 HW_BREAKPOINT_LEN_4 == evsel->attr.bp_len);
185 static int test__checkevent_breakpoint_rw(struct perf_evlist *evlist)
187 struct perf_evsel *evsel = list_entry(evlist->entries.next,
188 struct perf_evsel, node);
190 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
191 TEST_ASSERT_VAL("wrong type",
192 PERF_TYPE_BREAKPOINT == evsel->attr.type);
193 TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
194 TEST_ASSERT_VAL("wrong bp_type",
195 (HW_BREAKPOINT_R|HW_BREAKPOINT_W) == evsel->attr.bp_type);
196 TEST_ASSERT_VAL("wrong bp_len",
197 HW_BREAKPOINT_LEN_4 == evsel->attr.bp_len);
201 static int test__checkevent_tracepoint_modifier(struct perf_evlist *evlist)
203 struct perf_evsel *evsel = list_entry(evlist->entries.next,
204 struct perf_evsel, node);
206 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
207 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
208 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
209 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
211 return test__checkevent_tracepoint(evlist);
215 test__checkevent_tracepoint_multi_modifier(struct perf_evlist *evlist)
217 struct perf_evsel *evsel;
219 TEST_ASSERT_VAL("wrong number of entries", evlist->nr_entries > 1);
221 list_for_each_entry(evsel, &evlist->entries, node) {
222 TEST_ASSERT_VAL("wrong exclude_user",
223 !evsel->attr.exclude_user);
224 TEST_ASSERT_VAL("wrong exclude_kernel",
225 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);
230 return test__checkevent_tracepoint_multi(evlist);
233 static int test__checkevent_raw_modifier(struct perf_evlist *evlist)
235 struct perf_evsel *evsel = list_entry(evlist->entries.next,
236 struct perf_evsel, node);
238 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
239 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
240 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
241 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
243 return test__checkevent_raw(evlist);
246 static int test__checkevent_numeric_modifier(struct perf_evlist *evlist)
248 struct perf_evsel *evsel = list_entry(evlist->entries.next,
249 struct perf_evsel, node);
251 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
252 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
253 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
254 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
256 return test__checkevent_numeric(evlist);
259 static int test__checkevent_symbolic_name_modifier(struct perf_evlist *evlist)
261 struct perf_evsel *evsel = list_entry(evlist->entries.next,
262 struct perf_evsel, node);
264 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
265 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
266 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
267 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
269 return test__checkevent_symbolic_name(evlist);
272 static int test__checkevent_exclude_host_modifier(struct perf_evlist *evlist)
274 struct perf_evsel *evsel = list_entry(evlist->entries.next,
275 struct perf_evsel, node);
277 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
278 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
280 return test__checkevent_symbolic_name(evlist);
283 static int test__checkevent_exclude_guest_modifier(struct perf_evlist *evlist)
285 struct perf_evsel *evsel = list_entry(evlist->entries.next,
286 struct perf_evsel, node);
288 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
289 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
291 return test__checkevent_symbolic_name(evlist);
294 static int test__checkevent_symbolic_alias_modifier(struct perf_evlist *evlist)
296 struct perf_evsel *evsel = list_entry(evlist->entries.next,
297 struct perf_evsel, node);
299 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
300 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
301 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
302 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
304 return test__checkevent_symbolic_alias(evlist);
307 static int test__checkevent_genhw_modifier(struct perf_evlist *evlist)
309 struct perf_evsel *evsel = list_entry(evlist->entries.next,
310 struct perf_evsel, node);
312 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
313 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
314 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
315 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
317 return test__checkevent_genhw(evlist);
320 static int test__checkevent_breakpoint_modifier(struct perf_evlist *evlist)
322 struct perf_evsel *evsel = list_entry(evlist->entries.next,
323 struct perf_evsel, node);
325 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
326 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
327 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
328 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
329 TEST_ASSERT_VAL("wrong name",
330 !strcmp(perf_evsel__name(evsel), "mem:0x0:rw:u"));
332 return test__checkevent_breakpoint(evlist);
335 static int test__checkevent_breakpoint_x_modifier(struct perf_evlist *evlist)
337 struct perf_evsel *evsel = list_entry(evlist->entries.next,
338 struct perf_evsel, node);
340 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
341 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
342 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
343 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
344 TEST_ASSERT_VAL("wrong name",
345 !strcmp(perf_evsel__name(evsel), "mem:0x0:x:k"));
347 return test__checkevent_breakpoint_x(evlist);
350 static int test__checkevent_breakpoint_r_modifier(struct perf_evlist *evlist)
352 struct perf_evsel *evsel = list_entry(evlist->entries.next,
353 struct perf_evsel, node);
355 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
356 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
357 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
358 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
359 TEST_ASSERT_VAL("wrong name",
360 !strcmp(perf_evsel__name(evsel), "mem:0x0:r:hp"));
362 return test__checkevent_breakpoint_r(evlist);
365 static int test__checkevent_breakpoint_w_modifier(struct perf_evlist *evlist)
367 struct perf_evsel *evsel = list_entry(evlist->entries.next,
368 struct perf_evsel, node);
370 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
371 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
372 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
373 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
374 TEST_ASSERT_VAL("wrong name",
375 !strcmp(perf_evsel__name(evsel), "mem:0x0:w:up"));
377 return test__checkevent_breakpoint_w(evlist);
380 static int test__checkevent_breakpoint_rw_modifier(struct perf_evlist *evlist)
382 struct perf_evsel *evsel = list_entry(evlist->entries.next,
383 struct perf_evsel, node);
385 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
386 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
387 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
388 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
389 TEST_ASSERT_VAL("wrong name",
390 !strcmp(perf_evsel__name(evsel), "mem:0x0:rw:kp"));
392 return test__checkevent_breakpoint_rw(evlist);
395 static int test__checkevent_pmu(struct perf_evlist *evlist)
398 struct perf_evsel *evsel = list_entry(evlist->entries.next,
399 struct perf_evsel, node);
401 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
402 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
403 TEST_ASSERT_VAL("wrong config", 10 == evsel->attr.config);
404 TEST_ASSERT_VAL("wrong config1", 1 == evsel->attr.config1);
405 TEST_ASSERT_VAL("wrong config2", 3 == evsel->attr.config2);
406 TEST_ASSERT_VAL("wrong period", 1000 == evsel->attr.sample_period);
411 static int test__checkevent_list(struct perf_evlist *evlist)
413 struct perf_evsel *evsel;
415 TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->nr_entries);
418 evsel = list_entry(evlist->entries.next, struct perf_evsel, node);
419 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
420 TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
421 TEST_ASSERT_VAL("wrong config1", 0 == evsel->attr.config1);
422 TEST_ASSERT_VAL("wrong config2", 0 == evsel->attr.config2);
423 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
424 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
425 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
426 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
428 /* syscalls:sys_enter_open:k */
429 evsel = list_entry(evsel->node.next, struct perf_evsel, node);
430 TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->attr.type);
431 TEST_ASSERT_VAL("wrong sample_type",
432 PERF_TP_SAMPLE_TYPE == evsel->attr.sample_type);
433 TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->attr.sample_period);
434 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
435 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
436 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
437 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
440 evsel = list_entry(evsel->node.next, struct perf_evsel, node);
441 TEST_ASSERT_VAL("wrong type", 1 == evsel->attr.type);
442 TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
443 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
444 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
445 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
446 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
451 static int test__checkevent_pmu_name(struct perf_evlist *evlist)
453 struct perf_evsel *evsel;
455 /* cpu/config=1,name=krava/u */
456 evsel = list_entry(evlist->entries.next, struct perf_evsel, node);
457 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
458 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
459 TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
460 TEST_ASSERT_VAL("wrong name", !strcmp(perf_evsel__name(evsel), "krava"));
462 /* cpu/config=2/u" */
463 evsel = list_entry(evsel->node.next, struct perf_evsel, node);
464 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
465 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
466 TEST_ASSERT_VAL("wrong config", 2 == evsel->attr.config);
467 TEST_ASSERT_VAL("wrong name",
468 !strcmp(perf_evsel__name(evsel), "raw 0x2:u"));
473 static int test__checkterms_simple(struct list_head *terms)
475 struct parse_events__term *term;
478 term = list_entry(terms->next, struct parse_events__term, list);
479 TEST_ASSERT_VAL("wrong type term",
480 term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG);
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 == 10);
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_CONFIG1);
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 == 1);
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_CONFIG2);
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 == 3);
502 TEST_ASSERT_VAL("wrong config", !term->config);
505 term = list_entry(term->list.next, struct parse_events__term, list);
506 TEST_ASSERT_VAL("wrong type term",
507 term->type_term == PARSE_EVENTS__TERM_TYPE_USER);
508 TEST_ASSERT_VAL("wrong type val",
509 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
510 TEST_ASSERT_VAL("wrong val", term->val.num == 1);
511 TEST_ASSERT_VAL("wrong config", !strcmp(term->config, "umask"));
516 struct test__event_st {
519 int (*check)(struct perf_evlist *evlist);
522 static struct test__event_st test__events[] = {
524 .name = "syscalls:sys_enter_open",
525 .check = test__checkevent_tracepoint,
528 .name = "syscalls:*",
529 .check = test__checkevent_tracepoint_multi,
533 .check = test__checkevent_raw,
537 .check = test__checkevent_numeric,
540 .name = "instructions",
541 .check = test__checkevent_symbolic_name,
544 .name = "cycles/period=100000,config2/",
545 .check = test__checkevent_symbolic_name_config,
549 .check = test__checkevent_symbolic_alias,
552 .name = "L1-dcache-load-miss",
553 .check = test__checkevent_genhw,
557 .check = test__checkevent_breakpoint,
561 .check = test__checkevent_breakpoint_x,
565 .check = test__checkevent_breakpoint_r,
569 .check = test__checkevent_breakpoint_w,
572 .name = "syscalls:sys_enter_open:k",
573 .check = test__checkevent_tracepoint_modifier,
576 .name = "syscalls:*:u",
577 .check = test__checkevent_tracepoint_multi_modifier,
581 .check = test__checkevent_raw_modifier,
585 .check = test__checkevent_numeric_modifier,
588 .name = "instructions:h",
589 .check = test__checkevent_symbolic_name_modifier,
593 .check = test__checkevent_symbolic_alias_modifier,
596 .name = "L1-dcache-load-miss:kp",
597 .check = test__checkevent_genhw_modifier,
601 .check = test__checkevent_breakpoint_modifier,
605 .check = test__checkevent_breakpoint_x_modifier,
608 .name = "mem:0:r:hp",
609 .check = test__checkevent_breakpoint_r_modifier,
612 .name = "mem:0:w:up",
613 .check = test__checkevent_breakpoint_w_modifier,
616 .name = "r1,syscalls:sys_enter_open:k,1:1:hp",
617 .check = test__checkevent_list,
620 .name = "instructions:G",
621 .check = test__checkevent_exclude_host_modifier,
624 .name = "instructions:H",
625 .check = test__checkevent_exclude_guest_modifier,
629 .check = test__checkevent_breakpoint_rw,
632 .name = "mem:0:rw:kp",
633 .check = test__checkevent_breakpoint_rw_modifier,
637 static struct test__event_st test__events_pmu[] = {
639 .name = "cpu/config=10,config1,config2=3,period=1000/u",
640 .check = test__checkevent_pmu,
643 .name = "cpu/config=1,name=krava/u,cpu/config=2/u",
644 .check = test__checkevent_pmu_name,
651 int (*check)(struct list_head *terms);
654 static struct test__term test__terms[] = {
656 .str = "config=10,config1,config2=3,umask=1",
657 .check = test__checkterms_simple,
661 #define TEST__TERMS_CNT (sizeof(test__terms) / \
662 sizeof(struct test__term))
664 static int test_event(struct test__event_st *e)
666 struct perf_evlist *evlist;
669 evlist = perf_evlist__new(NULL, NULL);
673 ret = parse_events(evlist, e->name, 0);
675 pr_debug("failed to parse event '%s', err %d\n",
680 ret = e->check(evlist);
681 perf_evlist__delete(evlist);
686 static int test_events(struct test__event_st *events, unsigned cnt)
691 for (i = 0; i < cnt; i++) {
692 struct test__event_st *e = &events[i];
694 pr_debug("running test %d '%s'\n", i, e->name);
703 static int test_term(struct test__term *t)
705 struct list_head *terms;
708 terms = malloc(sizeof(*terms));
712 INIT_LIST_HEAD(terms);
714 ret = parse_events_terms(terms, t->str);
716 pr_debug("failed to parse terms '%s', err %d\n",
721 ret = t->check(terms);
722 parse_events__free_terms(terms);
727 static int test_terms(struct test__term *terms, unsigned cnt)
732 for (i = 0; i < cnt; i++) {
733 struct test__term *t = &terms[i];
735 pr_debug("running test %d '%s'\n", i, t->str);
744 static int test_pmu(void)
750 snprintf(path, PATH_MAX, "%s/bus/event_source/devices/cpu/format/",
751 sysfs_find_mountpoint());
753 ret = stat(path, &st);
755 pr_debug("ommiting PMU cpu tests\n");
759 int parse_events__test(void)
763 #define TEST_EVENTS(tests) \
765 ret = test_events(tests, ARRAY_SIZE(tests)); \
770 TEST_EVENTS(test__events);
773 TEST_EVENTS(test__events_pmu);
775 return test_terms(test__terms, ARRAY_SIZE(test__terms));