2 #include "parse-events.h"
6 #include <lk/debugfs.h>
8 #include <linux/hw_breakpoint.h>
10 #define TEST_ASSERT_VAL(text, cond) \
13 pr_debug("FAILED %s:%d %s\n", __FILE__, __LINE__, text); \
18 #define PERF_TP_SAMPLE_TYPE (PERF_SAMPLE_RAW | PERF_SAMPLE_TIME | \
19 PERF_SAMPLE_CPU | PERF_SAMPLE_PERIOD)
21 static int test__checkevent_tracepoint(struct perf_evlist
*evlist
)
23 struct perf_evsel
*evsel
= perf_evlist__first(evlist
);
25 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist
->nr_entries
);
26 TEST_ASSERT_VAL("wrong number of groups", 0 == evlist
->nr_groups
);
27 TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT
== evsel
->attr
.type
);
28 TEST_ASSERT_VAL("wrong sample_type",
29 PERF_TP_SAMPLE_TYPE
== evsel
->attr
.sample_type
);
30 TEST_ASSERT_VAL("wrong sample_period", 1 == evsel
->attr
.sample_period
);
34 static int test__checkevent_tracepoint_multi(struct perf_evlist
*evlist
)
36 struct perf_evsel
*evsel
;
38 TEST_ASSERT_VAL("wrong number of entries", evlist
->nr_entries
> 1);
39 TEST_ASSERT_VAL("wrong number of groups", 0 == evlist
->nr_groups
);
41 list_for_each_entry(evsel
, &evlist
->entries
, node
) {
42 TEST_ASSERT_VAL("wrong type",
43 PERF_TYPE_TRACEPOINT
== evsel
->attr
.type
);
44 TEST_ASSERT_VAL("wrong sample_type",
45 PERF_TP_SAMPLE_TYPE
== evsel
->attr
.sample_type
);
46 TEST_ASSERT_VAL("wrong sample_period",
47 1 == evsel
->attr
.sample_period
);
52 static int test__checkevent_raw(struct perf_evlist
*evlist
)
54 struct perf_evsel
*evsel
= perf_evlist__first(evlist
);
56 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist
->nr_entries
);
57 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW
== evsel
->attr
.type
);
58 TEST_ASSERT_VAL("wrong config", 0x1a == evsel
->attr
.config
);
62 static int test__checkevent_numeric(struct perf_evlist
*evlist
)
64 struct perf_evsel
*evsel
= perf_evlist__first(evlist
);
66 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist
->nr_entries
);
67 TEST_ASSERT_VAL("wrong type", 1 == evsel
->attr
.type
);
68 TEST_ASSERT_VAL("wrong config", 1 == evsel
->attr
.config
);
72 static int test__checkevent_symbolic_name(struct perf_evlist
*evlist
)
74 struct perf_evsel
*evsel
= perf_evlist__first(evlist
);
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
= perf_evlist__first(evlist
);
87 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist
->nr_entries
);
88 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE
== evsel
->attr
.type
);
89 TEST_ASSERT_VAL("wrong config",
90 PERF_COUNT_HW_CPU_CYCLES
== evsel
->attr
.config
);
91 TEST_ASSERT_VAL("wrong period",
92 100000 == evsel
->attr
.sample_period
);
93 TEST_ASSERT_VAL("wrong config1",
94 0 == evsel
->attr
.config1
);
95 TEST_ASSERT_VAL("wrong config2",
96 1 == evsel
->attr
.config2
);
100 static int test__checkevent_symbolic_alias(struct perf_evlist
*evlist
)
102 struct perf_evsel
*evsel
= perf_evlist__first(evlist
);
104 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist
->nr_entries
);
105 TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE
== evsel
->attr
.type
);
106 TEST_ASSERT_VAL("wrong config",
107 PERF_COUNT_SW_PAGE_FAULTS
== evsel
->attr
.config
);
111 static int test__checkevent_genhw(struct perf_evlist
*evlist
)
113 struct perf_evsel
*evsel
= perf_evlist__first(evlist
);
115 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist
->nr_entries
);
116 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HW_CACHE
== evsel
->attr
.type
);
117 TEST_ASSERT_VAL("wrong config", (1 << 16) == evsel
->attr
.config
);
121 static int test__checkevent_breakpoint(struct perf_evlist
*evlist
)
123 struct perf_evsel
*evsel
= perf_evlist__first(evlist
);
125 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist
->nr_entries
);
126 TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT
== evsel
->attr
.type
);
127 TEST_ASSERT_VAL("wrong config", 0 == evsel
->attr
.config
);
128 TEST_ASSERT_VAL("wrong bp_type", (HW_BREAKPOINT_R
| HW_BREAKPOINT_W
) ==
129 evsel
->attr
.bp_type
);
130 TEST_ASSERT_VAL("wrong bp_len", HW_BREAKPOINT_LEN_4
==
135 static int test__checkevent_breakpoint_x(struct perf_evlist
*evlist
)
137 struct perf_evsel
*evsel
= perf_evlist__first(evlist
);
139 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist
->nr_entries
);
140 TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT
== evsel
->attr
.type
);
141 TEST_ASSERT_VAL("wrong config", 0 == evsel
->attr
.config
);
142 TEST_ASSERT_VAL("wrong bp_type",
143 HW_BREAKPOINT_X
== evsel
->attr
.bp_type
);
144 TEST_ASSERT_VAL("wrong bp_len", sizeof(long) == evsel
->attr
.bp_len
);
148 static int test__checkevent_breakpoint_r(struct perf_evlist
*evlist
)
150 struct perf_evsel
*evsel
= perf_evlist__first(evlist
);
152 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist
->nr_entries
);
153 TEST_ASSERT_VAL("wrong type",
154 PERF_TYPE_BREAKPOINT
== evsel
->attr
.type
);
155 TEST_ASSERT_VAL("wrong config", 0 == evsel
->attr
.config
);
156 TEST_ASSERT_VAL("wrong bp_type",
157 HW_BREAKPOINT_R
== evsel
->attr
.bp_type
);
158 TEST_ASSERT_VAL("wrong bp_len",
159 HW_BREAKPOINT_LEN_4
== evsel
->attr
.bp_len
);
163 static int test__checkevent_breakpoint_w(struct perf_evlist
*evlist
)
165 struct perf_evsel
*evsel
= perf_evlist__first(evlist
);
167 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist
->nr_entries
);
168 TEST_ASSERT_VAL("wrong type",
169 PERF_TYPE_BREAKPOINT
== evsel
->attr
.type
);
170 TEST_ASSERT_VAL("wrong config", 0 == evsel
->attr
.config
);
171 TEST_ASSERT_VAL("wrong bp_type",
172 HW_BREAKPOINT_W
== evsel
->attr
.bp_type
);
173 TEST_ASSERT_VAL("wrong bp_len",
174 HW_BREAKPOINT_LEN_4
== evsel
->attr
.bp_len
);
178 static int test__checkevent_breakpoint_rw(struct perf_evlist
*evlist
)
180 struct perf_evsel
*evsel
= perf_evlist__first(evlist
);
182 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist
->nr_entries
);
183 TEST_ASSERT_VAL("wrong type",
184 PERF_TYPE_BREAKPOINT
== evsel
->attr
.type
);
185 TEST_ASSERT_VAL("wrong config", 0 == evsel
->attr
.config
);
186 TEST_ASSERT_VAL("wrong bp_type",
187 (HW_BREAKPOINT_R
|HW_BREAKPOINT_W
) == evsel
->attr
.bp_type
);
188 TEST_ASSERT_VAL("wrong bp_len",
189 HW_BREAKPOINT_LEN_4
== evsel
->attr
.bp_len
);
193 static int test__checkevent_tracepoint_modifier(struct perf_evlist
*evlist
)
195 struct perf_evsel
*evsel
= perf_evlist__first(evlist
);
197 TEST_ASSERT_VAL("wrong exclude_user", evsel
->attr
.exclude_user
);
198 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel
->attr
.exclude_kernel
);
199 TEST_ASSERT_VAL("wrong exclude_hv", evsel
->attr
.exclude_hv
);
200 TEST_ASSERT_VAL("wrong precise_ip", !evsel
->attr
.precise_ip
);
202 return test__checkevent_tracepoint(evlist
);
206 test__checkevent_tracepoint_multi_modifier(struct perf_evlist
*evlist
)
208 struct perf_evsel
*evsel
;
210 TEST_ASSERT_VAL("wrong number of entries", evlist
->nr_entries
> 1);
212 list_for_each_entry(evsel
, &evlist
->entries
, node
) {
213 TEST_ASSERT_VAL("wrong exclude_user",
214 !evsel
->attr
.exclude_user
);
215 TEST_ASSERT_VAL("wrong exclude_kernel",
216 evsel
->attr
.exclude_kernel
);
217 TEST_ASSERT_VAL("wrong exclude_hv", evsel
->attr
.exclude_hv
);
218 TEST_ASSERT_VAL("wrong precise_ip", !evsel
->attr
.precise_ip
);
221 return test__checkevent_tracepoint_multi(evlist
);
224 static int test__checkevent_raw_modifier(struct perf_evlist
*evlist
)
226 struct perf_evsel
*evsel
= perf_evlist__first(evlist
);
228 TEST_ASSERT_VAL("wrong exclude_user", evsel
->attr
.exclude_user
);
229 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel
->attr
.exclude_kernel
);
230 TEST_ASSERT_VAL("wrong exclude_hv", evsel
->attr
.exclude_hv
);
231 TEST_ASSERT_VAL("wrong precise_ip", evsel
->attr
.precise_ip
);
233 return test__checkevent_raw(evlist
);
236 static int test__checkevent_numeric_modifier(struct perf_evlist
*evlist
)
238 struct perf_evsel
*evsel
= perf_evlist__first(evlist
);
240 TEST_ASSERT_VAL("wrong exclude_user", evsel
->attr
.exclude_user
);
241 TEST_ASSERT_VAL("wrong exclude_kernel", evsel
->attr
.exclude_kernel
);
242 TEST_ASSERT_VAL("wrong exclude_hv", !evsel
->attr
.exclude_hv
);
243 TEST_ASSERT_VAL("wrong precise_ip", evsel
->attr
.precise_ip
);
245 return test__checkevent_numeric(evlist
);
248 static int test__checkevent_symbolic_name_modifier(struct perf_evlist
*evlist
)
250 struct perf_evsel
*evsel
= perf_evlist__first(evlist
);
252 TEST_ASSERT_VAL("wrong exclude_user", evsel
->attr
.exclude_user
);
253 TEST_ASSERT_VAL("wrong exclude_kernel", evsel
->attr
.exclude_kernel
);
254 TEST_ASSERT_VAL("wrong exclude_hv", !evsel
->attr
.exclude_hv
);
255 TEST_ASSERT_VAL("wrong precise_ip", !evsel
->attr
.precise_ip
);
257 return test__checkevent_symbolic_name(evlist
);
260 static int test__checkevent_exclude_host_modifier(struct perf_evlist
*evlist
)
262 struct perf_evsel
*evsel
= perf_evlist__first(evlist
);
264 TEST_ASSERT_VAL("wrong exclude guest", !evsel
->attr
.exclude_guest
);
265 TEST_ASSERT_VAL("wrong exclude host", evsel
->attr
.exclude_host
);
267 return test__checkevent_symbolic_name(evlist
);
270 static int test__checkevent_exclude_guest_modifier(struct perf_evlist
*evlist
)
272 struct perf_evsel
*evsel
= perf_evlist__first(evlist
);
274 TEST_ASSERT_VAL("wrong exclude guest", evsel
->attr
.exclude_guest
);
275 TEST_ASSERT_VAL("wrong exclude host", !evsel
->attr
.exclude_host
);
277 return test__checkevent_symbolic_name(evlist
);
280 static int test__checkevent_symbolic_alias_modifier(struct perf_evlist
*evlist
)
282 struct perf_evsel
*evsel
= perf_evlist__first(evlist
);
284 TEST_ASSERT_VAL("wrong exclude_user", !evsel
->attr
.exclude_user
);
285 TEST_ASSERT_VAL("wrong exclude_kernel", evsel
->attr
.exclude_kernel
);
286 TEST_ASSERT_VAL("wrong exclude_hv", evsel
->attr
.exclude_hv
);
287 TEST_ASSERT_VAL("wrong precise_ip", !evsel
->attr
.precise_ip
);
289 return test__checkevent_symbolic_alias(evlist
);
292 static int test__checkevent_genhw_modifier(struct perf_evlist
*evlist
)
294 struct perf_evsel
*evsel
= perf_evlist__first(evlist
);
296 TEST_ASSERT_VAL("wrong exclude_user", evsel
->attr
.exclude_user
);
297 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel
->attr
.exclude_kernel
);
298 TEST_ASSERT_VAL("wrong exclude_hv", evsel
->attr
.exclude_hv
);
299 TEST_ASSERT_VAL("wrong precise_ip", evsel
->attr
.precise_ip
);
301 return test__checkevent_genhw(evlist
);
304 static int test__checkevent_breakpoint_modifier(struct perf_evlist
*evlist
)
306 struct perf_evsel
*evsel
= perf_evlist__first(evlist
);
309 TEST_ASSERT_VAL("wrong exclude_user", !evsel
->attr
.exclude_user
);
310 TEST_ASSERT_VAL("wrong exclude_kernel", evsel
->attr
.exclude_kernel
);
311 TEST_ASSERT_VAL("wrong exclude_hv", evsel
->attr
.exclude_hv
);
312 TEST_ASSERT_VAL("wrong precise_ip", !evsel
->attr
.precise_ip
);
313 TEST_ASSERT_VAL("wrong name",
314 !strcmp(perf_evsel__name(evsel
), "mem:0:u"));
316 return test__checkevent_breakpoint(evlist
);
319 static int test__checkevent_breakpoint_x_modifier(struct perf_evlist
*evlist
)
321 struct perf_evsel
*evsel
= perf_evlist__first(evlist
);
323 TEST_ASSERT_VAL("wrong exclude_user", evsel
->attr
.exclude_user
);
324 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel
->attr
.exclude_kernel
);
325 TEST_ASSERT_VAL("wrong exclude_hv", evsel
->attr
.exclude_hv
);
326 TEST_ASSERT_VAL("wrong precise_ip", !evsel
->attr
.precise_ip
);
327 TEST_ASSERT_VAL("wrong name",
328 !strcmp(perf_evsel__name(evsel
), "mem:0:x:k"));
330 return test__checkevent_breakpoint_x(evlist
);
333 static int test__checkevent_breakpoint_r_modifier(struct perf_evlist
*evlist
)
335 struct perf_evsel
*evsel
= perf_evlist__first(evlist
);
337 TEST_ASSERT_VAL("wrong exclude_user", evsel
->attr
.exclude_user
);
338 TEST_ASSERT_VAL("wrong exclude_kernel", evsel
->attr
.exclude_kernel
);
339 TEST_ASSERT_VAL("wrong exclude_hv", !evsel
->attr
.exclude_hv
);
340 TEST_ASSERT_VAL("wrong precise_ip", evsel
->attr
.precise_ip
);
341 TEST_ASSERT_VAL("wrong name",
342 !strcmp(perf_evsel__name(evsel
), "mem:0:r:hp"));
344 return test__checkevent_breakpoint_r(evlist
);
347 static int test__checkevent_breakpoint_w_modifier(struct perf_evlist
*evlist
)
349 struct perf_evsel
*evsel
= perf_evlist__first(evlist
);
351 TEST_ASSERT_VAL("wrong exclude_user", !evsel
->attr
.exclude_user
);
352 TEST_ASSERT_VAL("wrong exclude_kernel", evsel
->attr
.exclude_kernel
);
353 TEST_ASSERT_VAL("wrong exclude_hv", evsel
->attr
.exclude_hv
);
354 TEST_ASSERT_VAL("wrong precise_ip", evsel
->attr
.precise_ip
);
355 TEST_ASSERT_VAL("wrong name",
356 !strcmp(perf_evsel__name(evsel
), "mem:0:w:up"));
358 return test__checkevent_breakpoint_w(evlist
);
361 static int test__checkevent_breakpoint_rw_modifier(struct perf_evlist
*evlist
)
363 struct perf_evsel
*evsel
= perf_evlist__first(evlist
);
365 TEST_ASSERT_VAL("wrong exclude_user", evsel
->attr
.exclude_user
);
366 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel
->attr
.exclude_kernel
);
367 TEST_ASSERT_VAL("wrong exclude_hv", evsel
->attr
.exclude_hv
);
368 TEST_ASSERT_VAL("wrong precise_ip", evsel
->attr
.precise_ip
);
369 TEST_ASSERT_VAL("wrong name",
370 !strcmp(perf_evsel__name(evsel
), "mem:0:rw:kp"));
372 return test__checkevent_breakpoint_rw(evlist
);
375 static int test__checkevent_pmu(struct perf_evlist
*evlist
)
378 struct perf_evsel
*evsel
= perf_evlist__first(evlist
);
380 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist
->nr_entries
);
381 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW
== evsel
->attr
.type
);
382 TEST_ASSERT_VAL("wrong config", 10 == evsel
->attr
.config
);
383 TEST_ASSERT_VAL("wrong config1", 1 == evsel
->attr
.config1
);
384 TEST_ASSERT_VAL("wrong config2", 3 == evsel
->attr
.config2
);
385 TEST_ASSERT_VAL("wrong period", 1000 == evsel
->attr
.sample_period
);
390 static int test__checkevent_list(struct perf_evlist
*evlist
)
392 struct perf_evsel
*evsel
= perf_evlist__first(evlist
);
394 TEST_ASSERT_VAL("wrong number of entries", 3 == evlist
->nr_entries
);
397 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW
== evsel
->attr
.type
);
398 TEST_ASSERT_VAL("wrong config", 1 == evsel
->attr
.config
);
399 TEST_ASSERT_VAL("wrong config1", 0 == evsel
->attr
.config1
);
400 TEST_ASSERT_VAL("wrong config2", 0 == evsel
->attr
.config2
);
401 TEST_ASSERT_VAL("wrong exclude_user", !evsel
->attr
.exclude_user
);
402 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel
->attr
.exclude_kernel
);
403 TEST_ASSERT_VAL("wrong exclude_hv", !evsel
->attr
.exclude_hv
);
404 TEST_ASSERT_VAL("wrong precise_ip", !evsel
->attr
.precise_ip
);
406 /* syscalls:sys_enter_open:k */
407 evsel
= perf_evsel__next(evsel
);
408 TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT
== evsel
->attr
.type
);
409 TEST_ASSERT_VAL("wrong sample_type",
410 PERF_TP_SAMPLE_TYPE
== evsel
->attr
.sample_type
);
411 TEST_ASSERT_VAL("wrong sample_period", 1 == evsel
->attr
.sample_period
);
412 TEST_ASSERT_VAL("wrong exclude_user", evsel
->attr
.exclude_user
);
413 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel
->attr
.exclude_kernel
);
414 TEST_ASSERT_VAL("wrong exclude_hv", evsel
->attr
.exclude_hv
);
415 TEST_ASSERT_VAL("wrong precise_ip", !evsel
->attr
.precise_ip
);
418 evsel
= perf_evsel__next(evsel
);
419 TEST_ASSERT_VAL("wrong type", 1 == evsel
->attr
.type
);
420 TEST_ASSERT_VAL("wrong config", 1 == evsel
->attr
.config
);
421 TEST_ASSERT_VAL("wrong exclude_user", evsel
->attr
.exclude_user
);
422 TEST_ASSERT_VAL("wrong exclude_kernel", evsel
->attr
.exclude_kernel
);
423 TEST_ASSERT_VAL("wrong exclude_hv", !evsel
->attr
.exclude_hv
);
424 TEST_ASSERT_VAL("wrong precise_ip", evsel
->attr
.precise_ip
);
429 static int test__checkevent_pmu_name(struct perf_evlist
*evlist
)
431 struct perf_evsel
*evsel
= perf_evlist__first(evlist
);
433 /* cpu/config=1,name=krava/u */
434 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist
->nr_entries
);
435 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW
== evsel
->attr
.type
);
436 TEST_ASSERT_VAL("wrong config", 1 == evsel
->attr
.config
);
437 TEST_ASSERT_VAL("wrong name", !strcmp(perf_evsel__name(evsel
), "krava"));
439 /* cpu/config=2/u" */
440 evsel
= perf_evsel__next(evsel
);
441 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist
->nr_entries
);
442 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW
== evsel
->attr
.type
);
443 TEST_ASSERT_VAL("wrong config", 2 == evsel
->attr
.config
);
444 TEST_ASSERT_VAL("wrong name",
445 !strcmp(perf_evsel__name(evsel
), "cpu/config=2/u"));
450 static int test__checkevent_pmu_events(struct perf_evlist
*evlist
)
452 struct perf_evsel
*evsel
;
454 evsel
= list_entry(evlist
->entries
.next
, struct perf_evsel
, node
);
455 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist
->nr_entries
);
456 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW
== evsel
->attr
.type
);
457 TEST_ASSERT_VAL("wrong exclude_user",
458 !evsel
->attr
.exclude_user
);
459 TEST_ASSERT_VAL("wrong exclude_kernel",
460 evsel
->attr
.exclude_kernel
);
461 TEST_ASSERT_VAL("wrong exclude_hv", evsel
->attr
.exclude_hv
);
462 TEST_ASSERT_VAL("wrong precise_ip", !evsel
->attr
.precise_ip
);
467 static int test__checkterms_simple(struct list_head
*terms
)
469 struct parse_events_term
*term
;
472 term
= list_entry(terms
->next
, struct parse_events_term
, list
);
473 TEST_ASSERT_VAL("wrong type term",
474 term
->type_term
== PARSE_EVENTS__TERM_TYPE_CONFIG
);
475 TEST_ASSERT_VAL("wrong type val",
476 term
->type_val
== PARSE_EVENTS__TERM_TYPE_NUM
);
477 TEST_ASSERT_VAL("wrong val", term
->val
.num
== 10);
478 TEST_ASSERT_VAL("wrong config", !term
->config
);
481 term
= list_entry(term
->list
.next
, struct parse_events_term
, list
);
482 TEST_ASSERT_VAL("wrong type term",
483 term
->type_term
== PARSE_EVENTS__TERM_TYPE_CONFIG1
);
484 TEST_ASSERT_VAL("wrong type val",
485 term
->type_val
== PARSE_EVENTS__TERM_TYPE_NUM
);
486 TEST_ASSERT_VAL("wrong val", term
->val
.num
== 1);
487 TEST_ASSERT_VAL("wrong config", !term
->config
);
490 term
= list_entry(term
->list
.next
, struct parse_events_term
, list
);
491 TEST_ASSERT_VAL("wrong type term",
492 term
->type_term
== PARSE_EVENTS__TERM_TYPE_CONFIG2
);
493 TEST_ASSERT_VAL("wrong type val",
494 term
->type_val
== PARSE_EVENTS__TERM_TYPE_NUM
);
495 TEST_ASSERT_VAL("wrong val", term
->val
.num
== 3);
496 TEST_ASSERT_VAL("wrong config", !term
->config
);
499 term
= list_entry(term
->list
.next
, struct parse_events_term
, list
);
500 TEST_ASSERT_VAL("wrong type term",
501 term
->type_term
== PARSE_EVENTS__TERM_TYPE_USER
);
502 TEST_ASSERT_VAL("wrong type val",
503 term
->type_val
== PARSE_EVENTS__TERM_TYPE_NUM
);
504 TEST_ASSERT_VAL("wrong val", term
->val
.num
== 1);
505 TEST_ASSERT_VAL("wrong config", !strcmp(term
->config
, "umask"));
510 static int test__group1(struct perf_evlist
*evlist
)
512 struct perf_evsel
*evsel
, *leader
;
514 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist
->nr_entries
);
515 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist
->nr_groups
);
518 evsel
= leader
= perf_evlist__first(evlist
);
519 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE
== evsel
->attr
.type
);
520 TEST_ASSERT_VAL("wrong config",
521 PERF_COUNT_HW_INSTRUCTIONS
== evsel
->attr
.config
);
522 TEST_ASSERT_VAL("wrong exclude_user", evsel
->attr
.exclude_user
);
523 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel
->attr
.exclude_kernel
);
524 TEST_ASSERT_VAL("wrong exclude_hv", evsel
->attr
.exclude_hv
);
525 TEST_ASSERT_VAL("wrong exclude guest", !evsel
->attr
.exclude_guest
);
526 TEST_ASSERT_VAL("wrong exclude host", !evsel
->attr
.exclude_host
);
527 TEST_ASSERT_VAL("wrong precise_ip", !evsel
->attr
.precise_ip
);
528 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel
));
529 TEST_ASSERT_VAL("wrong nr_members", evsel
->nr_members
== 2);
530 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel
) == 0);
533 evsel
= perf_evsel__next(evsel
);
534 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE
== evsel
->attr
.type
);
535 TEST_ASSERT_VAL("wrong config",
536 PERF_COUNT_HW_CPU_CYCLES
== evsel
->attr
.config
);
537 TEST_ASSERT_VAL("wrong exclude_user", !evsel
->attr
.exclude_user
);
538 TEST_ASSERT_VAL("wrong exclude_kernel", evsel
->attr
.exclude_kernel
);
539 TEST_ASSERT_VAL("wrong exclude_hv", evsel
->attr
.exclude_hv
);
540 /* use of precise requires exclude_guest */
541 TEST_ASSERT_VAL("wrong exclude guest", evsel
->attr
.exclude_guest
);
542 TEST_ASSERT_VAL("wrong exclude host", !evsel
->attr
.exclude_host
);
543 TEST_ASSERT_VAL("wrong precise_ip", evsel
->attr
.precise_ip
== 2);
544 TEST_ASSERT_VAL("wrong leader", evsel
->leader
== leader
);
545 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel
) == 1);
550 static int test__group2(struct perf_evlist
*evlist
)
552 struct perf_evsel
*evsel
, *leader
;
554 TEST_ASSERT_VAL("wrong number of entries", 3 == evlist
->nr_entries
);
555 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist
->nr_groups
);
557 /* faults + :ku modifier */
558 evsel
= leader
= perf_evlist__first(evlist
);
559 TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE
== evsel
->attr
.type
);
560 TEST_ASSERT_VAL("wrong config",
561 PERF_COUNT_SW_PAGE_FAULTS
== evsel
->attr
.config
);
562 TEST_ASSERT_VAL("wrong exclude_user", !evsel
->attr
.exclude_user
);
563 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel
->attr
.exclude_kernel
);
564 TEST_ASSERT_VAL("wrong exclude_hv", evsel
->attr
.exclude_hv
);
565 TEST_ASSERT_VAL("wrong exclude guest", !evsel
->attr
.exclude_guest
);
566 TEST_ASSERT_VAL("wrong exclude host", !evsel
->attr
.exclude_host
);
567 TEST_ASSERT_VAL("wrong precise_ip", !evsel
->attr
.precise_ip
);
568 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel
));
569 TEST_ASSERT_VAL("wrong nr_members", evsel
->nr_members
== 2);
570 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel
) == 0);
572 /* cache-references + :u modifier */
573 evsel
= perf_evsel__next(evsel
);
574 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE
== evsel
->attr
.type
);
575 TEST_ASSERT_VAL("wrong config",
576 PERF_COUNT_HW_CACHE_REFERENCES
== evsel
->attr
.config
);
577 TEST_ASSERT_VAL("wrong exclude_user", !evsel
->attr
.exclude_user
);
578 TEST_ASSERT_VAL("wrong exclude_kernel", evsel
->attr
.exclude_kernel
);
579 TEST_ASSERT_VAL("wrong exclude_hv", evsel
->attr
.exclude_hv
);
580 TEST_ASSERT_VAL("wrong exclude guest", evsel
->attr
.exclude_guest
);
581 TEST_ASSERT_VAL("wrong exclude host", !evsel
->attr
.exclude_host
);
582 TEST_ASSERT_VAL("wrong precise_ip", !evsel
->attr
.precise_ip
);
583 TEST_ASSERT_VAL("wrong leader", evsel
->leader
== leader
);
584 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel
) == 1);
587 evsel
= perf_evsel__next(evsel
);
588 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE
== evsel
->attr
.type
);
589 TEST_ASSERT_VAL("wrong config",
590 PERF_COUNT_HW_CPU_CYCLES
== evsel
->attr
.config
);
591 TEST_ASSERT_VAL("wrong exclude_user", evsel
->attr
.exclude_user
);
592 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel
->attr
.exclude_kernel
);
593 TEST_ASSERT_VAL("wrong exclude_hv", evsel
->attr
.exclude_hv
);
594 TEST_ASSERT_VAL("wrong exclude guest", !evsel
->attr
.exclude_guest
);
595 TEST_ASSERT_VAL("wrong exclude host", !evsel
->attr
.exclude_host
);
596 TEST_ASSERT_VAL("wrong precise_ip", !evsel
->attr
.precise_ip
);
597 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel
));
602 static int test__group3(struct perf_evlist
*evlist __maybe_unused
)
604 struct perf_evsel
*evsel
, *leader
;
606 TEST_ASSERT_VAL("wrong number of entries", 5 == evlist
->nr_entries
);
607 TEST_ASSERT_VAL("wrong number of groups", 2 == evlist
->nr_groups
);
609 /* group1 syscalls:sys_enter_open:H */
610 evsel
= leader
= perf_evlist__first(evlist
);
611 TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT
== evsel
->attr
.type
);
612 TEST_ASSERT_VAL("wrong sample_type",
613 PERF_TP_SAMPLE_TYPE
== evsel
->attr
.sample_type
);
614 TEST_ASSERT_VAL("wrong sample_period", 1 == evsel
->attr
.sample_period
);
615 TEST_ASSERT_VAL("wrong exclude_user", !evsel
->attr
.exclude_user
);
616 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel
->attr
.exclude_kernel
);
617 TEST_ASSERT_VAL("wrong exclude_hv", !evsel
->attr
.exclude_hv
);
618 TEST_ASSERT_VAL("wrong exclude guest", evsel
->attr
.exclude_guest
);
619 TEST_ASSERT_VAL("wrong exclude host", !evsel
->attr
.exclude_host
);
620 TEST_ASSERT_VAL("wrong precise_ip", !evsel
->attr
.precise_ip
);
621 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel
));
622 TEST_ASSERT_VAL("wrong group name",
623 !strcmp(leader
->group_name
, "group1"));
624 TEST_ASSERT_VAL("wrong nr_members", evsel
->nr_members
== 2);
625 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel
) == 0);
627 /* group1 cycles:kppp */
628 evsel
= perf_evsel__next(evsel
);
629 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE
== evsel
->attr
.type
);
630 TEST_ASSERT_VAL("wrong config",
631 PERF_COUNT_HW_CPU_CYCLES
== evsel
->attr
.config
);
632 TEST_ASSERT_VAL("wrong exclude_user", evsel
->attr
.exclude_user
);
633 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel
->attr
.exclude_kernel
);
634 TEST_ASSERT_VAL("wrong exclude_hv", evsel
->attr
.exclude_hv
);
635 /* use of precise requires exclude_guest */
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
== 3);
639 TEST_ASSERT_VAL("wrong leader", evsel
->leader
== leader
);
640 TEST_ASSERT_VAL("wrong group name", !evsel
->group_name
);
641 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel
) == 1);
643 /* group2 cycles + G modifier */
644 evsel
= leader
= perf_evsel__next(evsel
);
645 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE
== evsel
->attr
.type
);
646 TEST_ASSERT_VAL("wrong config",
647 PERF_COUNT_HW_CPU_CYCLES
== evsel
->attr
.config
);
648 TEST_ASSERT_VAL("wrong exclude_user", !evsel
->attr
.exclude_user
);
649 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel
->attr
.exclude_kernel
);
650 TEST_ASSERT_VAL("wrong exclude_hv", !evsel
->attr
.exclude_hv
);
651 TEST_ASSERT_VAL("wrong exclude guest", !evsel
->attr
.exclude_guest
);
652 TEST_ASSERT_VAL("wrong exclude host", evsel
->attr
.exclude_host
);
653 TEST_ASSERT_VAL("wrong precise_ip", !evsel
->attr
.precise_ip
);
654 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel
));
655 TEST_ASSERT_VAL("wrong group name",
656 !strcmp(leader
->group_name
, "group2"));
657 TEST_ASSERT_VAL("wrong nr_members", evsel
->nr_members
== 2);
658 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel
) == 0);
660 /* group2 1:3 + G modifier */
661 evsel
= perf_evsel__next(evsel
);
662 TEST_ASSERT_VAL("wrong type", 1 == evsel
->attr
.type
);
663 TEST_ASSERT_VAL("wrong config", 3 == evsel
->attr
.config
);
664 TEST_ASSERT_VAL("wrong exclude_user", !evsel
->attr
.exclude_user
);
665 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel
->attr
.exclude_kernel
);
666 TEST_ASSERT_VAL("wrong exclude_hv", !evsel
->attr
.exclude_hv
);
667 TEST_ASSERT_VAL("wrong exclude guest", !evsel
->attr
.exclude_guest
);
668 TEST_ASSERT_VAL("wrong exclude host", evsel
->attr
.exclude_host
);
669 TEST_ASSERT_VAL("wrong precise_ip", !evsel
->attr
.precise_ip
);
670 TEST_ASSERT_VAL("wrong leader", evsel
->leader
== leader
);
671 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel
) == 1);
674 evsel
= perf_evsel__next(evsel
);
675 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE
== evsel
->attr
.type
);
676 TEST_ASSERT_VAL("wrong config",
677 PERF_COUNT_HW_INSTRUCTIONS
== evsel
->attr
.config
);
678 TEST_ASSERT_VAL("wrong exclude_user", !evsel
->attr
.exclude_user
);
679 TEST_ASSERT_VAL("wrong exclude_kernel", evsel
->attr
.exclude_kernel
);
680 TEST_ASSERT_VAL("wrong exclude_hv", evsel
->attr
.exclude_hv
);
681 TEST_ASSERT_VAL("wrong exclude guest", !evsel
->attr
.exclude_guest
);
682 TEST_ASSERT_VAL("wrong exclude host", !evsel
->attr
.exclude_host
);
683 TEST_ASSERT_VAL("wrong precise_ip", !evsel
->attr
.precise_ip
);
684 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel
));
689 static int test__group4(struct perf_evlist
*evlist __maybe_unused
)
691 struct perf_evsel
*evsel
, *leader
;
693 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist
->nr_entries
);
694 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist
->nr_groups
);
697 evsel
= leader
= perf_evlist__first(evlist
);
698 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE
== evsel
->attr
.type
);
699 TEST_ASSERT_VAL("wrong config",
700 PERF_COUNT_HW_CPU_CYCLES
== evsel
->attr
.config
);
701 TEST_ASSERT_VAL("wrong exclude_user", !evsel
->attr
.exclude_user
);
702 TEST_ASSERT_VAL("wrong exclude_kernel", evsel
->attr
.exclude_kernel
);
703 TEST_ASSERT_VAL("wrong exclude_hv", evsel
->attr
.exclude_hv
);
704 /* use of precise requires exclude_guest */
705 TEST_ASSERT_VAL("wrong exclude guest", evsel
->attr
.exclude_guest
);
706 TEST_ASSERT_VAL("wrong exclude host", !evsel
->attr
.exclude_host
);
707 TEST_ASSERT_VAL("wrong precise_ip", evsel
->attr
.precise_ip
== 1);
708 TEST_ASSERT_VAL("wrong group name", !evsel
->group_name
);
709 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel
));
710 TEST_ASSERT_VAL("wrong nr_members", evsel
->nr_members
== 2);
711 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel
) == 0);
713 /* instructions:kp + p */
714 evsel
= perf_evsel__next(evsel
);
715 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE
== evsel
->attr
.type
);
716 TEST_ASSERT_VAL("wrong config",
717 PERF_COUNT_HW_INSTRUCTIONS
== evsel
->attr
.config
);
718 TEST_ASSERT_VAL("wrong exclude_user", evsel
->attr
.exclude_user
);
719 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel
->attr
.exclude_kernel
);
720 TEST_ASSERT_VAL("wrong exclude_hv", evsel
->attr
.exclude_hv
);
721 /* use of precise requires exclude_guest */
722 TEST_ASSERT_VAL("wrong exclude guest", evsel
->attr
.exclude_guest
);
723 TEST_ASSERT_VAL("wrong exclude host", !evsel
->attr
.exclude_host
);
724 TEST_ASSERT_VAL("wrong precise_ip", evsel
->attr
.precise_ip
== 2);
725 TEST_ASSERT_VAL("wrong leader", evsel
->leader
== leader
);
726 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel
) == 1);
731 static int test__group5(struct perf_evlist
*evlist __maybe_unused
)
733 struct perf_evsel
*evsel
, *leader
;
735 TEST_ASSERT_VAL("wrong number of entries", 5 == evlist
->nr_entries
);
736 TEST_ASSERT_VAL("wrong number of groups", 2 == evlist
->nr_groups
);
739 evsel
= leader
= perf_evlist__first(evlist
);
740 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE
== evsel
->attr
.type
);
741 TEST_ASSERT_VAL("wrong config",
742 PERF_COUNT_HW_CPU_CYCLES
== evsel
->attr
.config
);
743 TEST_ASSERT_VAL("wrong exclude_user", !evsel
->attr
.exclude_user
);
744 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel
->attr
.exclude_kernel
);
745 TEST_ASSERT_VAL("wrong exclude_hv", !evsel
->attr
.exclude_hv
);
746 TEST_ASSERT_VAL("wrong exclude guest", !evsel
->attr
.exclude_guest
);
747 TEST_ASSERT_VAL("wrong exclude host", evsel
->attr
.exclude_host
);
748 TEST_ASSERT_VAL("wrong precise_ip", !evsel
->attr
.precise_ip
);
749 TEST_ASSERT_VAL("wrong group name", !evsel
->group_name
);
750 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel
));
751 TEST_ASSERT_VAL("wrong nr_members", evsel
->nr_members
== 2);
752 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel
) == 0);
754 /* instructions + G */
755 evsel
= perf_evsel__next(evsel
);
756 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE
== evsel
->attr
.type
);
757 TEST_ASSERT_VAL("wrong config",
758 PERF_COUNT_HW_INSTRUCTIONS
== evsel
->attr
.config
);
759 TEST_ASSERT_VAL("wrong exclude_user", !evsel
->attr
.exclude_user
);
760 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel
->attr
.exclude_kernel
);
761 TEST_ASSERT_VAL("wrong exclude_hv", !evsel
->attr
.exclude_hv
);
762 TEST_ASSERT_VAL("wrong exclude guest", !evsel
->attr
.exclude_guest
);
763 TEST_ASSERT_VAL("wrong exclude host", evsel
->attr
.exclude_host
);
764 TEST_ASSERT_VAL("wrong precise_ip", !evsel
->attr
.precise_ip
);
765 TEST_ASSERT_VAL("wrong leader", evsel
->leader
== leader
);
766 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel
) == 1);
769 evsel
= leader
= perf_evsel__next(evsel
);
770 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE
== evsel
->attr
.type
);
771 TEST_ASSERT_VAL("wrong config",
772 PERF_COUNT_HW_CPU_CYCLES
== evsel
->attr
.config
);
773 TEST_ASSERT_VAL("wrong exclude_user", !evsel
->attr
.exclude_user
);
774 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel
->attr
.exclude_kernel
);
775 TEST_ASSERT_VAL("wrong exclude_hv", !evsel
->attr
.exclude_hv
);
776 TEST_ASSERT_VAL("wrong exclude guest", !evsel
->attr
.exclude_guest
);
777 TEST_ASSERT_VAL("wrong exclude host", evsel
->attr
.exclude_host
);
778 TEST_ASSERT_VAL("wrong precise_ip", !evsel
->attr
.precise_ip
);
779 TEST_ASSERT_VAL("wrong group name", !evsel
->group_name
);
780 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel
));
781 TEST_ASSERT_VAL("wrong nr_members", evsel
->nr_members
== 2);
782 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel
) == 0);
785 evsel
= perf_evsel__next(evsel
);
786 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE
== evsel
->attr
.type
);
787 TEST_ASSERT_VAL("wrong config",
788 PERF_COUNT_HW_INSTRUCTIONS
== evsel
->attr
.config
);
789 TEST_ASSERT_VAL("wrong exclude_user", !evsel
->attr
.exclude_user
);
790 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel
->attr
.exclude_kernel
);
791 TEST_ASSERT_VAL("wrong exclude_hv", !evsel
->attr
.exclude_hv
);
792 TEST_ASSERT_VAL("wrong exclude guest", !evsel
->attr
.exclude_guest
);
793 TEST_ASSERT_VAL("wrong exclude host", evsel
->attr
.exclude_host
);
794 TEST_ASSERT_VAL("wrong precise_ip", !evsel
->attr
.precise_ip
);
795 TEST_ASSERT_VAL("wrong leader", evsel
->leader
== leader
);
796 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel
) == 1);
799 evsel
= perf_evsel__next(evsel
);
800 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE
== evsel
->attr
.type
);
801 TEST_ASSERT_VAL("wrong config",
802 PERF_COUNT_HW_CPU_CYCLES
== evsel
->attr
.config
);
803 TEST_ASSERT_VAL("wrong exclude_user", !evsel
->attr
.exclude_user
);
804 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel
->attr
.exclude_kernel
);
805 TEST_ASSERT_VAL("wrong exclude_hv", !evsel
->attr
.exclude_hv
);
806 TEST_ASSERT_VAL("wrong exclude guest", evsel
->attr
.exclude_guest
);
807 TEST_ASSERT_VAL("wrong exclude host", !evsel
->attr
.exclude_host
);
808 TEST_ASSERT_VAL("wrong precise_ip", !evsel
->attr
.precise_ip
);
809 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel
));
814 static int test__group_gh1(struct perf_evlist
*evlist
)
816 struct perf_evsel
*evsel
, *leader
;
818 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist
->nr_entries
);
819 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist
->nr_groups
);
821 /* cycles + :H group modifier */
822 evsel
= leader
= perf_evlist__first(evlist
);
823 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE
== evsel
->attr
.type
);
824 TEST_ASSERT_VAL("wrong config",
825 PERF_COUNT_HW_CPU_CYCLES
== evsel
->attr
.config
);
826 TEST_ASSERT_VAL("wrong exclude_user", !evsel
->attr
.exclude_user
);
827 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel
->attr
.exclude_kernel
);
828 TEST_ASSERT_VAL("wrong exclude_hv", !evsel
->attr
.exclude_hv
);
829 TEST_ASSERT_VAL("wrong exclude guest", evsel
->attr
.exclude_guest
);
830 TEST_ASSERT_VAL("wrong exclude host", !evsel
->attr
.exclude_host
);
831 TEST_ASSERT_VAL("wrong precise_ip", !evsel
->attr
.precise_ip
);
832 TEST_ASSERT_VAL("wrong group name", !evsel
->group_name
);
833 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel
));
834 TEST_ASSERT_VAL("wrong nr_members", evsel
->nr_members
== 2);
835 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel
) == 0);
837 /* cache-misses:G + :H group modifier */
838 evsel
= perf_evsel__next(evsel
);
839 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE
== evsel
->attr
.type
);
840 TEST_ASSERT_VAL("wrong config",
841 PERF_COUNT_HW_CACHE_MISSES
== evsel
->attr
.config
);
842 TEST_ASSERT_VAL("wrong exclude_user", !evsel
->attr
.exclude_user
);
843 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel
->attr
.exclude_kernel
);
844 TEST_ASSERT_VAL("wrong exclude_hv", !evsel
->attr
.exclude_hv
);
845 TEST_ASSERT_VAL("wrong exclude guest", !evsel
->attr
.exclude_guest
);
846 TEST_ASSERT_VAL("wrong exclude host", !evsel
->attr
.exclude_host
);
847 TEST_ASSERT_VAL("wrong precise_ip", !evsel
->attr
.precise_ip
);
848 TEST_ASSERT_VAL("wrong leader", evsel
->leader
== leader
);
849 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel
) == 1);
854 static int test__group_gh2(struct perf_evlist
*evlist
)
856 struct perf_evsel
*evsel
, *leader
;
858 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist
->nr_entries
);
859 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist
->nr_groups
);
861 /* cycles + :G group modifier */
862 evsel
= leader
= perf_evlist__first(evlist
);
863 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE
== evsel
->attr
.type
);
864 TEST_ASSERT_VAL("wrong config",
865 PERF_COUNT_HW_CPU_CYCLES
== evsel
->attr
.config
);
866 TEST_ASSERT_VAL("wrong exclude_user", !evsel
->attr
.exclude_user
);
867 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel
->attr
.exclude_kernel
);
868 TEST_ASSERT_VAL("wrong exclude_hv", !evsel
->attr
.exclude_hv
);
869 TEST_ASSERT_VAL("wrong exclude guest", !evsel
->attr
.exclude_guest
);
870 TEST_ASSERT_VAL("wrong exclude host", evsel
->attr
.exclude_host
);
871 TEST_ASSERT_VAL("wrong precise_ip", !evsel
->attr
.precise_ip
);
872 TEST_ASSERT_VAL("wrong group name", !evsel
->group_name
);
873 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel
));
874 TEST_ASSERT_VAL("wrong nr_members", evsel
->nr_members
== 2);
875 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel
) == 0);
877 /* cache-misses:H + :G group modifier */
878 evsel
= perf_evsel__next(evsel
);
879 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE
== evsel
->attr
.type
);
880 TEST_ASSERT_VAL("wrong config",
881 PERF_COUNT_HW_CACHE_MISSES
== evsel
->attr
.config
);
882 TEST_ASSERT_VAL("wrong exclude_user", !evsel
->attr
.exclude_user
);
883 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel
->attr
.exclude_kernel
);
884 TEST_ASSERT_VAL("wrong exclude_hv", !evsel
->attr
.exclude_hv
);
885 TEST_ASSERT_VAL("wrong exclude guest", !evsel
->attr
.exclude_guest
);
886 TEST_ASSERT_VAL("wrong exclude host", !evsel
->attr
.exclude_host
);
887 TEST_ASSERT_VAL("wrong precise_ip", !evsel
->attr
.precise_ip
);
888 TEST_ASSERT_VAL("wrong leader", evsel
->leader
== leader
);
889 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel
) == 1);
894 static int test__group_gh3(struct perf_evlist
*evlist
)
896 struct perf_evsel
*evsel
, *leader
;
898 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist
->nr_entries
);
899 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist
->nr_groups
);
901 /* cycles:G + :u group modifier */
902 evsel
= leader
= perf_evlist__first(evlist
);
903 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE
== evsel
->attr
.type
);
904 TEST_ASSERT_VAL("wrong config",
905 PERF_COUNT_HW_CPU_CYCLES
== evsel
->attr
.config
);
906 TEST_ASSERT_VAL("wrong exclude_user", !evsel
->attr
.exclude_user
);
907 TEST_ASSERT_VAL("wrong exclude_kernel", evsel
->attr
.exclude_kernel
);
908 TEST_ASSERT_VAL("wrong exclude_hv", evsel
->attr
.exclude_hv
);
909 TEST_ASSERT_VAL("wrong exclude guest", !evsel
->attr
.exclude_guest
);
910 TEST_ASSERT_VAL("wrong exclude host", evsel
->attr
.exclude_host
);
911 TEST_ASSERT_VAL("wrong precise_ip", !evsel
->attr
.precise_ip
);
912 TEST_ASSERT_VAL("wrong group name", !evsel
->group_name
);
913 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel
));
914 TEST_ASSERT_VAL("wrong nr_members", evsel
->nr_members
== 2);
915 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel
) == 0);
917 /* cache-misses:H + :u group modifier */
918 evsel
= perf_evsel__next(evsel
);
919 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE
== evsel
->attr
.type
);
920 TEST_ASSERT_VAL("wrong config",
921 PERF_COUNT_HW_CACHE_MISSES
== evsel
->attr
.config
);
922 TEST_ASSERT_VAL("wrong exclude_user", !evsel
->attr
.exclude_user
);
923 TEST_ASSERT_VAL("wrong exclude_kernel", evsel
->attr
.exclude_kernel
);
924 TEST_ASSERT_VAL("wrong exclude_hv", evsel
->attr
.exclude_hv
);
925 TEST_ASSERT_VAL("wrong exclude guest", evsel
->attr
.exclude_guest
);
926 TEST_ASSERT_VAL("wrong exclude host", !evsel
->attr
.exclude_host
);
927 TEST_ASSERT_VAL("wrong precise_ip", !evsel
->attr
.precise_ip
);
928 TEST_ASSERT_VAL("wrong leader", evsel
->leader
== leader
);
929 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel
) == 1);
934 static int test__group_gh4(struct perf_evlist
*evlist
)
936 struct perf_evsel
*evsel
, *leader
;
938 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist
->nr_entries
);
939 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist
->nr_groups
);
941 /* cycles:G + :uG group modifier */
942 evsel
= leader
= perf_evlist__first(evlist
);
943 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE
== evsel
->attr
.type
);
944 TEST_ASSERT_VAL("wrong config",
945 PERF_COUNT_HW_CPU_CYCLES
== evsel
->attr
.config
);
946 TEST_ASSERT_VAL("wrong exclude_user", !evsel
->attr
.exclude_user
);
947 TEST_ASSERT_VAL("wrong exclude_kernel", evsel
->attr
.exclude_kernel
);
948 TEST_ASSERT_VAL("wrong exclude_hv", evsel
->attr
.exclude_hv
);
949 TEST_ASSERT_VAL("wrong exclude guest", !evsel
->attr
.exclude_guest
);
950 TEST_ASSERT_VAL("wrong exclude host", evsel
->attr
.exclude_host
);
951 TEST_ASSERT_VAL("wrong precise_ip", !evsel
->attr
.precise_ip
);
952 TEST_ASSERT_VAL("wrong group name", !evsel
->group_name
);
953 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel
));
954 TEST_ASSERT_VAL("wrong nr_members", evsel
->nr_members
== 2);
955 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel
) == 0);
957 /* cache-misses:H + :uG group modifier */
958 evsel
= perf_evsel__next(evsel
);
959 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE
== evsel
->attr
.type
);
960 TEST_ASSERT_VAL("wrong config",
961 PERF_COUNT_HW_CACHE_MISSES
== evsel
->attr
.config
);
962 TEST_ASSERT_VAL("wrong exclude_user", !evsel
->attr
.exclude_user
);
963 TEST_ASSERT_VAL("wrong exclude_kernel", evsel
->attr
.exclude_kernel
);
964 TEST_ASSERT_VAL("wrong exclude_hv", evsel
->attr
.exclude_hv
);
965 TEST_ASSERT_VAL("wrong exclude guest", !evsel
->attr
.exclude_guest
);
966 TEST_ASSERT_VAL("wrong exclude host", !evsel
->attr
.exclude_host
);
967 TEST_ASSERT_VAL("wrong precise_ip", !evsel
->attr
.precise_ip
);
968 TEST_ASSERT_VAL("wrong leader", evsel
->leader
== leader
);
969 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel
) == 1);
974 static int count_tracepoints(void)
976 char events_path
[PATH_MAX
];
977 struct dirent
*events_ent
;
981 scnprintf(events_path
, PATH_MAX
, "%s/tracing/events",
982 debugfs_find_mountpoint());
984 events_dir
= opendir(events_path
);
986 TEST_ASSERT_VAL("Can't open events dir", events_dir
);
988 while ((events_ent
= readdir(events_dir
))) {
989 char sys_path
[PATH_MAX
];
990 struct dirent
*sys_ent
;
993 if (!strcmp(events_ent
->d_name
, ".")
994 || !strcmp(events_ent
->d_name
, "..")
995 || !strcmp(events_ent
->d_name
, "enable")
996 || !strcmp(events_ent
->d_name
, "header_event")
997 || !strcmp(events_ent
->d_name
, "header_page"))
1000 scnprintf(sys_path
, PATH_MAX
, "%s/%s",
1001 events_path
, events_ent
->d_name
);
1003 sys_dir
= opendir(sys_path
);
1004 TEST_ASSERT_VAL("Can't open sys dir", sys_dir
);
1006 while ((sys_ent
= readdir(sys_dir
))) {
1007 if (!strcmp(sys_ent
->d_name
, ".")
1008 || !strcmp(sys_ent
->d_name
, "..")
1009 || !strcmp(sys_ent
->d_name
, "enable")
1010 || !strcmp(sys_ent
->d_name
, "filter"))
1019 closedir(events_dir
);
1023 static int test__all_tracepoints(struct perf_evlist
*evlist
)
1025 TEST_ASSERT_VAL("wrong events count",
1026 count_tracepoints() == evlist
->nr_entries
);
1028 return test__checkevent_tracepoint_multi(evlist
);
1031 struct evlist_test
{
1034 int (*check
)(struct perf_evlist
*evlist
);
1037 static struct evlist_test test__events
[] = {
1039 .name
= "syscalls:sys_enter_open",
1040 .check
= test__checkevent_tracepoint
,
1043 .name
= "syscalls:*",
1044 .check
= test__checkevent_tracepoint_multi
,
1048 .check
= test__checkevent_raw
,
1052 .check
= test__checkevent_numeric
,
1055 .name
= "instructions",
1056 .check
= test__checkevent_symbolic_name
,
1059 .name
= "cycles/period=100000,config2/",
1060 .check
= test__checkevent_symbolic_name_config
,
1064 .check
= test__checkevent_symbolic_alias
,
1067 .name
= "L1-dcache-load-miss",
1068 .check
= test__checkevent_genhw
,
1072 .check
= test__checkevent_breakpoint
,
1076 .check
= test__checkevent_breakpoint_x
,
1080 .check
= test__checkevent_breakpoint_r
,
1084 .check
= test__checkevent_breakpoint_w
,
1087 .name
= "syscalls:sys_enter_open:k",
1088 .check
= test__checkevent_tracepoint_modifier
,
1091 .name
= "syscalls:*:u",
1092 .check
= test__checkevent_tracepoint_multi_modifier
,
1096 .check
= test__checkevent_raw_modifier
,
1100 .check
= test__checkevent_numeric_modifier
,
1103 .name
= "instructions:h",
1104 .check
= test__checkevent_symbolic_name_modifier
,
1108 .check
= test__checkevent_symbolic_alias_modifier
,
1111 .name
= "L1-dcache-load-miss:kp",
1112 .check
= test__checkevent_genhw_modifier
,
1116 .check
= test__checkevent_breakpoint_modifier
,
1119 .name
= "mem:0:x:k",
1120 .check
= test__checkevent_breakpoint_x_modifier
,
1123 .name
= "mem:0:r:hp",
1124 .check
= test__checkevent_breakpoint_r_modifier
,
1127 .name
= "mem:0:w:up",
1128 .check
= test__checkevent_breakpoint_w_modifier
,
1131 .name
= "r1,syscalls:sys_enter_open:k,1:1:hp",
1132 .check
= test__checkevent_list
,
1135 .name
= "instructions:G",
1136 .check
= test__checkevent_exclude_host_modifier
,
1139 .name
= "instructions:H",
1140 .check
= test__checkevent_exclude_guest_modifier
,
1144 .check
= test__checkevent_breakpoint_rw
,
1147 .name
= "mem:0:rw:kp",
1148 .check
= test__checkevent_breakpoint_rw_modifier
,
1151 .name
= "{instructions:k,cycles:upp}",
1152 .check
= test__group1
,
1155 .name
= "{faults:k,cache-references}:u,cycles:k",
1156 .check
= test__group2
,
1159 .name
= "group1{syscalls:sys_enter_open:H,cycles:kppp},group2{cycles,1:3}:G,instructions:u",
1160 .check
= test__group3
,
1163 .name
= "{cycles:u,instructions:kp}:p",
1164 .check
= test__group4
,
1167 .name
= "{cycles,instructions}:G,{cycles:G,instructions:G},cycles",
1168 .check
= test__group5
,
1172 .check
= test__all_tracepoints
,
1175 .name
= "{cycles,cache-misses:G}:H",
1176 .check
= test__group_gh1
,
1179 .name
= "{cycles,cache-misses:H}:G",
1180 .check
= test__group_gh2
,
1183 .name
= "{cycles:G,cache-misses:H}:u",
1184 .check
= test__group_gh3
,
1187 .name
= "{cycles:G,cache-misses:H}:uG",
1188 .check
= test__group_gh4
,
1192 static struct evlist_test test__events_pmu
[] = {
1194 .name
= "cpu/config=10,config1,config2=3,period=1000/u",
1195 .check
= test__checkevent_pmu
,
1198 .name
= "cpu/config=1,name=krava/u,cpu/config=2/u",
1199 .check
= test__checkevent_pmu_name
,
1206 int (*check
)(struct list_head
*terms
);
1209 static struct terms_test test__terms
[] = {
1211 .str
= "config=10,config1,config2=3,umask=1",
1212 .check
= test__checkterms_simple
,
1216 static int test_event(struct evlist_test
*e
)
1218 struct perf_evlist
*evlist
;
1221 evlist
= perf_evlist__new();
1225 ret
= parse_events(evlist
, e
->name
);
1227 pr_debug("failed to parse event '%s', err %d\n",
1232 ret
= e
->check(evlist
);
1233 perf_evlist__delete(evlist
);
1238 static int test_events(struct evlist_test
*events
, unsigned cnt
)
1243 for (i
= 0; i
< cnt
; i
++) {
1244 struct evlist_test
*e
= &events
[i
];
1246 pr_debug("running test %d '%s'\n", i
, e
->name
);
1247 ret1
= test_event(e
);
1255 static int test_term(struct terms_test
*t
)
1257 struct list_head
*terms
;
1260 terms
= malloc(sizeof(*terms
));
1264 INIT_LIST_HEAD(terms
);
1266 ret
= parse_events_terms(terms
, t
->str
);
1268 pr_debug("failed to parse terms '%s', err %d\n",
1273 ret
= t
->check(terms
);
1274 parse_events__free_terms(terms
);
1279 static int test_terms(struct terms_test
*terms
, unsigned cnt
)
1284 for (i
= 0; i
< cnt
; i
++) {
1285 struct terms_test
*t
= &terms
[i
];
1287 pr_debug("running test %d '%s'\n", i
, t
->str
);
1296 static int test_pmu(void)
1299 char path
[PATH_MAX
];
1302 snprintf(path
, PATH_MAX
, "%s/bus/event_source/devices/cpu/format/",
1303 sysfs_find_mountpoint());
1305 ret
= stat(path
, &st
);
1307 pr_debug("omitting PMU cpu tests\n");
1311 static int test_pmu_events(void)
1314 char path
[PATH_MAX
];
1319 snprintf(path
, PATH_MAX
, "%s/bus/event_source/devices/cpu/events/",
1320 sysfs_find_mountpoint());
1322 ret
= stat(path
, &st
);
1324 pr_debug("omitting PMU cpu events tests\n");
1328 dir
= opendir(path
);
1330 pr_debug("can't open pmu event dir");
1334 while (!ret
&& (ent
= readdir(dir
))) {
1335 #define MAX_NAME 100
1336 struct evlist_test e
;
1337 char name
[MAX_NAME
];
1339 if (!strcmp(ent
->d_name
, ".") ||
1340 !strcmp(ent
->d_name
, ".."))
1343 snprintf(name
, MAX_NAME
, "cpu/event=%s/u", ent
->d_name
);
1346 e
.check
= test__checkevent_pmu_events
;
1348 ret
= test_event(&e
);
1356 int test__parse_events(void)
1360 #define TEST_EVENTS(tests) \
1362 ret1 = test_events(tests, ARRAY_SIZE(tests)); \
1367 TEST_EVENTS(test__events
);
1370 TEST_EVENTS(test__events_pmu
);
1373 int ret
= test_pmu_events();
1378 ret1
= test_terms(test__terms
, ARRAY_SIZE(test__terms
));