perf tools: Use __maybe_used for unused variables
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / tools / perf / util / parse-events-test.c
1
2 #include "parse-events.h"
3 #include "evsel.h"
4 #include "evlist.h"
5 #include "sysfs.h"
6 #include "../../../include/linux/hw_breakpoint.h"
7
8 #define TEST_ASSERT_VAL(text, cond) \
9 do { \
10 if (!(cond)) { \
11 pr_debug("FAILED %s:%d %s\n", __FILE__, __LINE__, text); \
12 return -1; \
13 } \
14 } while (0)
15
16 #define PERF_TP_SAMPLE_TYPE (PERF_SAMPLE_RAW | PERF_SAMPLE_TIME | \
17 PERF_SAMPLE_CPU | PERF_SAMPLE_PERIOD)
18
19 static int test__checkevent_tracepoint(struct perf_evlist *evlist)
20 {
21 struct perf_evsel *evsel = perf_evlist__first(evlist);
22
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);
28 return 0;
29 }
30
31 static int test__checkevent_tracepoint_multi(struct perf_evlist *evlist)
32 {
33 struct perf_evsel *evsel;
34
35 TEST_ASSERT_VAL("wrong number of entries", evlist->nr_entries > 1);
36
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);
44 }
45 return 0;
46 }
47
48 static int test__checkevent_raw(struct perf_evlist *evlist)
49 {
50 struct perf_evsel *evsel = perf_evlist__first(evlist);
51
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);
55 return 0;
56 }
57
58 static int test__checkevent_numeric(struct perf_evlist *evlist)
59 {
60 struct perf_evsel *evsel = perf_evlist__first(evlist);
61
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);
65 return 0;
66 }
67
68 static int test__checkevent_symbolic_name(struct perf_evlist *evlist)
69 {
70 struct perf_evsel *evsel = perf_evlist__first(evlist);
71
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);
76 return 0;
77 }
78
79 static int test__checkevent_symbolic_name_config(struct perf_evlist *evlist)
80 {
81 struct perf_evsel *evsel = perf_evlist__first(evlist);
82
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);
93 return 0;
94 }
95
96 static int test__checkevent_symbolic_alias(struct perf_evlist *evlist)
97 {
98 struct perf_evsel *evsel = perf_evlist__first(evlist);
99
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);
104 return 0;
105 }
106
107 static int test__checkevent_genhw(struct perf_evlist *evlist)
108 {
109 struct perf_evsel *evsel = perf_evlist__first(evlist);
110
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);
114 return 0;
115 }
116
117 static int test__checkevent_breakpoint(struct perf_evlist *evlist)
118 {
119 struct perf_evsel *evsel = perf_evlist__first(evlist);
120
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 ==
127 evsel->attr.bp_len);
128 return 0;
129 }
130
131 static int test__checkevent_breakpoint_x(struct perf_evlist *evlist)
132 {
133 struct perf_evsel *evsel = perf_evlist__first(evlist);
134
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);
141 return 0;
142 }
143
144 static int test__checkevent_breakpoint_r(struct perf_evlist *evlist)
145 {
146 struct perf_evsel *evsel = perf_evlist__first(evlist);
147
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);
156 return 0;
157 }
158
159 static int test__checkevent_breakpoint_w(struct perf_evlist *evlist)
160 {
161 struct perf_evsel *evsel = perf_evlist__first(evlist);
162
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);
171 return 0;
172 }
173
174 static int test__checkevent_breakpoint_rw(struct perf_evlist *evlist)
175 {
176 struct perf_evsel *evsel = perf_evlist__first(evlist);
177
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);
186 return 0;
187 }
188
189 static int test__checkevent_tracepoint_modifier(struct perf_evlist *evlist)
190 {
191 struct perf_evsel *evsel = perf_evlist__first(evlist);
192
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);
197
198 return test__checkevent_tracepoint(evlist);
199 }
200
201 static int
202 test__checkevent_tracepoint_multi_modifier(struct perf_evlist *evlist)
203 {
204 struct perf_evsel *evsel;
205
206 TEST_ASSERT_VAL("wrong number of entries", evlist->nr_entries > 1);
207
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);
215 }
216
217 return test__checkevent_tracepoint_multi(evlist);
218 }
219
220 static int test__checkevent_raw_modifier(struct perf_evlist *evlist)
221 {
222 struct perf_evsel *evsel = perf_evlist__first(evlist);
223
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);
228
229 return test__checkevent_raw(evlist);
230 }
231
232 static int test__checkevent_numeric_modifier(struct perf_evlist *evlist)
233 {
234 struct perf_evsel *evsel = perf_evlist__first(evlist);
235
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);
240
241 return test__checkevent_numeric(evlist);
242 }
243
244 static int test__checkevent_symbolic_name_modifier(struct perf_evlist *evlist)
245 {
246 struct perf_evsel *evsel = perf_evlist__first(evlist);
247
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);
252
253 return test__checkevent_symbolic_name(evlist);
254 }
255
256 static int test__checkevent_exclude_host_modifier(struct perf_evlist *evlist)
257 {
258 struct perf_evsel *evsel = perf_evlist__first(evlist);
259
260 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
261 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
262
263 return test__checkevent_symbolic_name(evlist);
264 }
265
266 static int test__checkevent_exclude_guest_modifier(struct perf_evlist *evlist)
267 {
268 struct perf_evsel *evsel = perf_evlist__first(evlist);
269
270 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
271 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
272
273 return test__checkevent_symbolic_name(evlist);
274 }
275
276 static int test__checkevent_symbolic_alias_modifier(struct perf_evlist *evlist)
277 {
278 struct perf_evsel *evsel = perf_evlist__first(evlist);
279
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);
284
285 return test__checkevent_symbolic_alias(evlist);
286 }
287
288 static int test__checkevent_genhw_modifier(struct perf_evlist *evlist)
289 {
290 struct perf_evsel *evsel = perf_evlist__first(evlist);
291
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);
296
297 return test__checkevent_genhw(evlist);
298 }
299
300 static int test__checkevent_breakpoint_modifier(struct perf_evlist *evlist)
301 {
302 struct perf_evsel *evsel = perf_evlist__first(evlist);
303
304
305 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
306 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
307 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
308 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
309 TEST_ASSERT_VAL("wrong name",
310 !strcmp(perf_evsel__name(evsel), "mem:0:u"));
311
312 return test__checkevent_breakpoint(evlist);
313 }
314
315 static int test__checkevent_breakpoint_x_modifier(struct perf_evlist *evlist)
316 {
317 struct perf_evsel *evsel = perf_evlist__first(evlist);
318
319 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
320 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
321 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
322 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
323 TEST_ASSERT_VAL("wrong name",
324 !strcmp(perf_evsel__name(evsel), "mem:0:x:k"));
325
326 return test__checkevent_breakpoint_x(evlist);
327 }
328
329 static int test__checkevent_breakpoint_r_modifier(struct perf_evlist *evlist)
330 {
331 struct perf_evsel *evsel = perf_evlist__first(evlist);
332
333 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
334 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
335 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
336 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
337 TEST_ASSERT_VAL("wrong name",
338 !strcmp(perf_evsel__name(evsel), "mem:0:r:hp"));
339
340 return test__checkevent_breakpoint_r(evlist);
341 }
342
343 static int test__checkevent_breakpoint_w_modifier(struct perf_evlist *evlist)
344 {
345 struct perf_evsel *evsel = perf_evlist__first(evlist);
346
347 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
348 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
349 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
350 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
351 TEST_ASSERT_VAL("wrong name",
352 !strcmp(perf_evsel__name(evsel), "mem:0:w:up"));
353
354 return test__checkevent_breakpoint_w(evlist);
355 }
356
357 static int test__checkevent_breakpoint_rw_modifier(struct perf_evlist *evlist)
358 {
359 struct perf_evsel *evsel = perf_evlist__first(evlist);
360
361 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
362 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
363 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
364 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
365 TEST_ASSERT_VAL("wrong name",
366 !strcmp(perf_evsel__name(evsel), "mem:0:rw:kp"));
367
368 return test__checkevent_breakpoint_rw(evlist);
369 }
370
371 static int test__checkevent_pmu(struct perf_evlist *evlist)
372 {
373
374 struct perf_evsel *evsel = perf_evlist__first(evlist);
375
376 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
377 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
378 TEST_ASSERT_VAL("wrong config", 10 == evsel->attr.config);
379 TEST_ASSERT_VAL("wrong config1", 1 == evsel->attr.config1);
380 TEST_ASSERT_VAL("wrong config2", 3 == evsel->attr.config2);
381 TEST_ASSERT_VAL("wrong period", 1000 == evsel->attr.sample_period);
382
383 return 0;
384 }
385
386 static int test__checkevent_list(struct perf_evlist *evlist)
387 {
388 struct perf_evsel *evsel = perf_evlist__first(evlist);
389
390 TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->nr_entries);
391
392 /* r1 */
393 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
394 TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
395 TEST_ASSERT_VAL("wrong config1", 0 == evsel->attr.config1);
396 TEST_ASSERT_VAL("wrong config2", 0 == evsel->attr.config2);
397 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
398 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
399 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
400 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
401
402 /* syscalls:sys_enter_open:k */
403 evsel = perf_evsel__next(evsel);
404 TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->attr.type);
405 TEST_ASSERT_VAL("wrong sample_type",
406 PERF_TP_SAMPLE_TYPE == evsel->attr.sample_type);
407 TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->attr.sample_period);
408 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
409 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
410 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
411 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
412
413 /* 1:1:hp */
414 evsel = perf_evsel__next(evsel);
415 TEST_ASSERT_VAL("wrong type", 1 == evsel->attr.type);
416 TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
417 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
418 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
419 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
420 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
421
422 return 0;
423 }
424
425 static int test__checkevent_pmu_name(struct perf_evlist *evlist)
426 {
427 struct perf_evsel *evsel = perf_evlist__first(evlist);
428
429 /* cpu/config=1,name=krava/u */
430 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
431 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
432 TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
433 TEST_ASSERT_VAL("wrong name", !strcmp(perf_evsel__name(evsel), "krava"));
434
435 /* cpu/config=2/u" */
436 evsel = perf_evsel__next(evsel);
437 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
438 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
439 TEST_ASSERT_VAL("wrong config", 2 == evsel->attr.config);
440 TEST_ASSERT_VAL("wrong name",
441 !strcmp(perf_evsel__name(evsel), "cpu/config=2/u"));
442
443 return 0;
444 }
445
446 static int test__checkterms_simple(struct list_head *terms)
447 {
448 struct parse_events__term *term;
449
450 /* config=10 */
451 term = list_entry(terms->next, struct parse_events__term, list);
452 TEST_ASSERT_VAL("wrong type term",
453 term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG);
454 TEST_ASSERT_VAL("wrong type val",
455 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
456 TEST_ASSERT_VAL("wrong val", term->val.num == 10);
457 TEST_ASSERT_VAL("wrong config", !term->config);
458
459 /* config1 */
460 term = list_entry(term->list.next, struct parse_events__term, list);
461 TEST_ASSERT_VAL("wrong type term",
462 term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG1);
463 TEST_ASSERT_VAL("wrong type val",
464 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
465 TEST_ASSERT_VAL("wrong val", term->val.num == 1);
466 TEST_ASSERT_VAL("wrong config", !term->config);
467
468 /* config2=3 */
469 term = list_entry(term->list.next, struct parse_events__term, list);
470 TEST_ASSERT_VAL("wrong type term",
471 term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG2);
472 TEST_ASSERT_VAL("wrong type val",
473 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
474 TEST_ASSERT_VAL("wrong val", term->val.num == 3);
475 TEST_ASSERT_VAL("wrong config", !term->config);
476
477 /* umask=1*/
478 term = list_entry(term->list.next, struct parse_events__term, list);
479 TEST_ASSERT_VAL("wrong type term",
480 term->type_term == PARSE_EVENTS__TERM_TYPE_USER);
481 TEST_ASSERT_VAL("wrong type val",
482 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
483 TEST_ASSERT_VAL("wrong val", term->val.num == 1);
484 TEST_ASSERT_VAL("wrong config", !strcmp(term->config, "umask"));
485
486 return 0;
487 }
488
489 static int test__group1(struct perf_evlist *evlist)
490 {
491 struct perf_evsel *evsel, *leader;
492
493 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
494
495 /* instructions:k */
496 evsel = leader = perf_evlist__first(evlist);
497 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
498 TEST_ASSERT_VAL("wrong config",
499 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
500 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
501 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
502 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
503 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
504 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
505 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
506 TEST_ASSERT_VAL("wrong leader", evsel->leader == NULL);
507
508 /* cycles:upp */
509 evsel = perf_evsel__next(evsel);
510 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
511 TEST_ASSERT_VAL("wrong config",
512 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
513 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
514 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
515 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
516 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
517 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
518 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 2);
519 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
520
521 return 0;
522 }
523
524 static int test__group2(struct perf_evlist *evlist)
525 {
526 struct perf_evsel *evsel, *leader;
527
528 TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->nr_entries);
529
530 /* faults + :ku modifier */
531 evsel = leader = perf_evlist__first(evlist);
532 TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->attr.type);
533 TEST_ASSERT_VAL("wrong config",
534 PERF_COUNT_SW_PAGE_FAULTS == evsel->attr.config);
535 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
536 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
537 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
538 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
539 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
540 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
541 TEST_ASSERT_VAL("wrong leader", evsel->leader == NULL);
542
543 /* cache-references + :u modifier */
544 evsel = perf_evsel__next(evsel);
545 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
546 TEST_ASSERT_VAL("wrong config",
547 PERF_COUNT_HW_CACHE_REFERENCES == evsel->attr.config);
548 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
549 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
550 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
551 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
552 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
553 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
554 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
555
556 /* cycles:k */
557 evsel = perf_evsel__next(evsel);
558 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
559 TEST_ASSERT_VAL("wrong config",
560 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
561 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
562 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
563 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
564 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
565 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
566 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
567 TEST_ASSERT_VAL("wrong leader", evsel->leader == NULL);
568
569 return 0;
570 }
571
572 static int test__group3(struct perf_evlist *evlist __maybe_unused)
573 {
574 struct perf_evsel *evsel, *leader;
575
576 TEST_ASSERT_VAL("wrong number of entries", 5 == evlist->nr_entries);
577
578 /* group1 syscalls:sys_enter_open:H */
579 evsel = leader = perf_evlist__first(evlist);
580 TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->attr.type);
581 TEST_ASSERT_VAL("wrong sample_type",
582 PERF_TP_SAMPLE_TYPE == evsel->attr.sample_type);
583 TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->attr.sample_period);
584 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
585 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
586 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
587 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
588 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
589 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
590 TEST_ASSERT_VAL("wrong leader", evsel->leader == NULL);
591 TEST_ASSERT_VAL("wrong group name",
592 !strcmp(leader->group_name, "group1"));
593
594 /* group1 cycles:kppp */
595 evsel = perf_evsel__next(evsel);
596 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
597 TEST_ASSERT_VAL("wrong config",
598 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
599 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
600 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
601 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
602 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
603 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
604 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 3);
605 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
606 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
607
608 /* group2 cycles + G modifier */
609 evsel = leader = perf_evsel__next(evsel);
610 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
611 TEST_ASSERT_VAL("wrong config",
612 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
613 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
614 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
615 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
616 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
617 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
618 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
619 TEST_ASSERT_VAL("wrong leader", evsel->leader == NULL);
620 TEST_ASSERT_VAL("wrong group name",
621 !strcmp(leader->group_name, "group2"));
622
623 /* group2 1:3 + G modifier */
624 evsel = perf_evsel__next(evsel);
625 TEST_ASSERT_VAL("wrong type", 1 == evsel->attr.type);
626 TEST_ASSERT_VAL("wrong config", 3 == evsel->attr.config);
627 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
628 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
629 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
630 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
631 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
632 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
633 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
634
635 /* instructions:u */
636 evsel = perf_evsel__next(evsel);
637 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
638 TEST_ASSERT_VAL("wrong config",
639 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
640 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
641 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
642 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
643 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
644 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
645 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
646 TEST_ASSERT_VAL("wrong leader", evsel->leader == NULL);
647
648 return 0;
649 }
650
651 static int test__group4(struct perf_evlist *evlist __maybe_unused)
652 {
653 struct perf_evsel *evsel, *leader;
654
655 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
656
657 /* cycles:u + p */
658 evsel = leader = perf_evlist__first(evlist);
659 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
660 TEST_ASSERT_VAL("wrong config",
661 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
662 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
663 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
664 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
665 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
666 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
667 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 1);
668 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
669 TEST_ASSERT_VAL("wrong leader", evsel->leader == NULL);
670
671 /* instructions:kp + p */
672 evsel = perf_evsel__next(evsel);
673 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
674 TEST_ASSERT_VAL("wrong config",
675 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
676 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
677 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
678 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
679 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
680 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
681 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 2);
682 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
683
684 return 0;
685 }
686
687 static int test__group5(struct perf_evlist *evlist __maybe_unused)
688 {
689 struct perf_evsel *evsel, *leader;
690
691 TEST_ASSERT_VAL("wrong number of entries", 5 == evlist->nr_entries);
692
693 /* cycles + G */
694 evsel = leader = perf_evlist__first(evlist);
695 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
696 TEST_ASSERT_VAL("wrong config",
697 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
698 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
699 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
700 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
701 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
702 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
703 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
704 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
705 TEST_ASSERT_VAL("wrong leader", evsel->leader == NULL);
706
707 /* instructions + G */
708 evsel = perf_evsel__next(evsel);
709 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
710 TEST_ASSERT_VAL("wrong config",
711 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
712 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
713 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
714 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
715 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
716 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
717 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
718 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
719
720 /* cycles:G */
721 evsel = leader = perf_evsel__next(evsel);
722 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
723 TEST_ASSERT_VAL("wrong config",
724 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
725 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
726 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
727 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
728 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
729 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
730 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
731 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
732 TEST_ASSERT_VAL("wrong leader", evsel->leader == NULL);
733
734 /* instructions:G */
735 evsel = perf_evsel__next(evsel);
736 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
737 TEST_ASSERT_VAL("wrong config",
738 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
739 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
740 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
741 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
742 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
743 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
744 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
745 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
746
747 /* cycles */
748 evsel = perf_evsel__next(evsel);
749 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
750 TEST_ASSERT_VAL("wrong config",
751 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
752 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
753 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
754 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
755 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
756 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
757 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
758 TEST_ASSERT_VAL("wrong leader", evsel->leader == NULL);
759
760 return 0;
761 }
762
763 struct test__event_st {
764 const char *name;
765 __u32 type;
766 int (*check)(struct perf_evlist *evlist);
767 };
768
769 static struct test__event_st test__events[] = {
770 [0] = {
771 .name = "syscalls:sys_enter_open",
772 .check = test__checkevent_tracepoint,
773 },
774 [1] = {
775 .name = "syscalls:*",
776 .check = test__checkevent_tracepoint_multi,
777 },
778 [2] = {
779 .name = "r1a",
780 .check = test__checkevent_raw,
781 },
782 [3] = {
783 .name = "1:1",
784 .check = test__checkevent_numeric,
785 },
786 [4] = {
787 .name = "instructions",
788 .check = test__checkevent_symbolic_name,
789 },
790 [5] = {
791 .name = "cycles/period=100000,config2/",
792 .check = test__checkevent_symbolic_name_config,
793 },
794 [6] = {
795 .name = "faults",
796 .check = test__checkevent_symbolic_alias,
797 },
798 [7] = {
799 .name = "L1-dcache-load-miss",
800 .check = test__checkevent_genhw,
801 },
802 [8] = {
803 .name = "mem:0",
804 .check = test__checkevent_breakpoint,
805 },
806 [9] = {
807 .name = "mem:0:x",
808 .check = test__checkevent_breakpoint_x,
809 },
810 [10] = {
811 .name = "mem:0:r",
812 .check = test__checkevent_breakpoint_r,
813 },
814 [11] = {
815 .name = "mem:0:w",
816 .check = test__checkevent_breakpoint_w,
817 },
818 [12] = {
819 .name = "syscalls:sys_enter_open:k",
820 .check = test__checkevent_tracepoint_modifier,
821 },
822 [13] = {
823 .name = "syscalls:*:u",
824 .check = test__checkevent_tracepoint_multi_modifier,
825 },
826 [14] = {
827 .name = "r1a:kp",
828 .check = test__checkevent_raw_modifier,
829 },
830 [15] = {
831 .name = "1:1:hp",
832 .check = test__checkevent_numeric_modifier,
833 },
834 [16] = {
835 .name = "instructions:h",
836 .check = test__checkevent_symbolic_name_modifier,
837 },
838 [17] = {
839 .name = "faults:u",
840 .check = test__checkevent_symbolic_alias_modifier,
841 },
842 [18] = {
843 .name = "L1-dcache-load-miss:kp",
844 .check = test__checkevent_genhw_modifier,
845 },
846 [19] = {
847 .name = "mem:0:u",
848 .check = test__checkevent_breakpoint_modifier,
849 },
850 [20] = {
851 .name = "mem:0:x:k",
852 .check = test__checkevent_breakpoint_x_modifier,
853 },
854 [21] = {
855 .name = "mem:0:r:hp",
856 .check = test__checkevent_breakpoint_r_modifier,
857 },
858 [22] = {
859 .name = "mem:0:w:up",
860 .check = test__checkevent_breakpoint_w_modifier,
861 },
862 [23] = {
863 .name = "r1,syscalls:sys_enter_open:k,1:1:hp",
864 .check = test__checkevent_list,
865 },
866 [24] = {
867 .name = "instructions:G",
868 .check = test__checkevent_exclude_host_modifier,
869 },
870 [25] = {
871 .name = "instructions:H",
872 .check = test__checkevent_exclude_guest_modifier,
873 },
874 [26] = {
875 .name = "mem:0:rw",
876 .check = test__checkevent_breakpoint_rw,
877 },
878 [27] = {
879 .name = "mem:0:rw:kp",
880 .check = test__checkevent_breakpoint_rw_modifier,
881 },
882 [28] = {
883 .name = "{instructions:k,cycles:upp}",
884 .check = test__group1,
885 },
886 [29] = {
887 .name = "{faults:k,cache-references}:u,cycles:k",
888 .check = test__group2,
889 },
890 [30] = {
891 .name = "group1{syscalls:sys_enter_open:H,cycles:kppp},group2{cycles,1:3}:G,instructions:u",
892 .check = test__group3,
893 },
894 [31] = {
895 .name = "{cycles:u,instructions:kp}:p",
896 .check = test__group4,
897 },
898 [32] = {
899 .name = "{cycles,instructions}:G,{cycles:G,instructions:G},cycles",
900 .check = test__group5,
901 },
902 };
903
904 static struct test__event_st test__events_pmu[] = {
905 [0] = {
906 .name = "cpu/config=10,config1,config2=3,period=1000/u",
907 .check = test__checkevent_pmu,
908 },
909 [1] = {
910 .name = "cpu/config=1,name=krava/u,cpu/config=2/u",
911 .check = test__checkevent_pmu_name,
912 },
913 };
914
915 struct test__term {
916 const char *str;
917 __u32 type;
918 int (*check)(struct list_head *terms);
919 };
920
921 static struct test__term test__terms[] = {
922 [0] = {
923 .str = "config=10,config1,config2=3,umask=1",
924 .check = test__checkterms_simple,
925 },
926 };
927
928 static int test_event(struct test__event_st *e)
929 {
930 struct perf_evlist *evlist;
931 int ret;
932
933 evlist = perf_evlist__new(NULL, NULL);
934 if (evlist == NULL)
935 return -ENOMEM;
936
937 ret = parse_events(evlist, e->name, 0);
938 if (ret) {
939 pr_debug("failed to parse event '%s', err %d\n",
940 e->name, ret);
941 return ret;
942 }
943
944 ret = e->check(evlist);
945 perf_evlist__delete(evlist);
946
947 return ret;
948 }
949
950 static int test_events(struct test__event_st *events, unsigned cnt)
951 {
952 int ret1, ret2 = 0;
953 unsigned i;
954
955 for (i = 0; i < cnt; i++) {
956 struct test__event_st *e = &events[i];
957
958 pr_debug("running test %d '%s'\n", i, e->name);
959 ret1 = test_event(e);
960 if (ret1)
961 ret2 = ret1;
962 }
963
964 return ret2;
965 }
966
967 static int test_term(struct test__term *t)
968 {
969 struct list_head *terms;
970 int ret;
971
972 terms = malloc(sizeof(*terms));
973 if (!terms)
974 return -ENOMEM;
975
976 INIT_LIST_HEAD(terms);
977
978 ret = parse_events_terms(terms, t->str);
979 if (ret) {
980 pr_debug("failed to parse terms '%s', err %d\n",
981 t->str , ret);
982 return ret;
983 }
984
985 ret = t->check(terms);
986 parse_events__free_terms(terms);
987
988 return ret;
989 }
990
991 static int test_terms(struct test__term *terms, unsigned cnt)
992 {
993 int ret = 0;
994 unsigned i;
995
996 for (i = 0; i < cnt; i++) {
997 struct test__term *t = &terms[i];
998
999 pr_debug("running test %d '%s'\n", i, t->str);
1000 ret = test_term(t);
1001 if (ret)
1002 break;
1003 }
1004
1005 return ret;
1006 }
1007
1008 static int test_pmu(void)
1009 {
1010 struct stat st;
1011 char path[PATH_MAX];
1012 int ret;
1013
1014 snprintf(path, PATH_MAX, "%s/bus/event_source/devices/cpu/format/",
1015 sysfs_find_mountpoint());
1016
1017 ret = stat(path, &st);
1018 if (ret)
1019 pr_debug("ommiting PMU cpu tests\n");
1020 return !ret;
1021 }
1022
1023 int parse_events__test(void)
1024 {
1025 int ret1, ret2 = 0;
1026
1027 #define TEST_EVENTS(tests) \
1028 do { \
1029 ret1 = test_events(tests, ARRAY_SIZE(tests)); \
1030 if (!ret2) \
1031 ret2 = ret1; \
1032 } while (0)
1033
1034 TEST_EVENTS(test__events);
1035
1036 if (test_pmu())
1037 TEST_EVENTS(test__events_pmu);
1038
1039 ret1 = test_terms(test__terms, ARRAY_SIZE(test__terms));
1040 if (!ret2)
1041 ret2 = ret1;
1042
1043 return ret2;
1044 }