perf tools: Add support to specify hw event as PMU event term
[deliverable/linux.git] / tools / perf / util / parse-events-test.c
CommitLineData
f50246e2
JO
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) \
9do { \
10 if (!(cond)) { \
11 pr_debug("FAILED %s:%d %s\n", __FILE__, __LINE__, text); \
12 return -1; \
13 } \
14} while (0)
15
30f31c0a
JO
16#define PERF_TP_SAMPLE_TYPE (PERF_SAMPLE_RAW | PERF_SAMPLE_TIME | \
17 PERF_SAMPLE_CPU | PERF_SAMPLE_PERIOD)
18
f50246e2
JO
19static int test__checkevent_tracepoint(struct perf_evlist *evlist)
20{
0c21f736 21 struct perf_evsel *evsel = perf_evlist__first(evlist);
f50246e2
JO
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",
30f31c0a 26 PERF_TP_SAMPLE_TYPE == evsel->attr.sample_type);
f50246e2
JO
27 TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->attr.sample_period);
28 return 0;
29}
30
31static 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",
30f31c0a 41 PERF_TP_SAMPLE_TYPE == evsel->attr.sample_type);
f50246e2
JO
42 TEST_ASSERT_VAL("wrong sample_period",
43 1 == evsel->attr.sample_period);
44 }
45 return 0;
46}
47
48static int test__checkevent_raw(struct perf_evlist *evlist)
49{
0c21f736 50 struct perf_evsel *evsel = perf_evlist__first(evlist);
f50246e2
JO
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
58static int test__checkevent_numeric(struct perf_evlist *evlist)
59{
0c21f736 60 struct perf_evsel *evsel = perf_evlist__first(evlist);
f50246e2
JO
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
68static int test__checkevent_symbolic_name(struct perf_evlist *evlist)
69{
0c21f736 70 struct perf_evsel *evsel = perf_evlist__first(evlist);
f50246e2
JO
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
79static int test__checkevent_symbolic_name_config(struct perf_evlist *evlist)
80{
0c21f736 81 struct perf_evsel *evsel = perf_evlist__first(evlist);
f50246e2
JO
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
96static int test__checkevent_symbolic_alias(struct perf_evlist *evlist)
97{
0c21f736 98 struct perf_evsel *evsel = perf_evlist__first(evlist);
f50246e2
JO
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
107static int test__checkevent_genhw(struct perf_evlist *evlist)
108{
0c21f736 109 struct perf_evsel *evsel = perf_evlist__first(evlist);
f50246e2
JO
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
117static int test__checkevent_breakpoint(struct perf_evlist *evlist)
118{
0c21f736 119 struct perf_evsel *evsel = perf_evlist__first(evlist);
f50246e2
JO
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
131static int test__checkevent_breakpoint_x(struct perf_evlist *evlist)
132{
0c21f736 133 struct perf_evsel *evsel = perf_evlist__first(evlist);
f50246e2
JO
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
144static int test__checkevent_breakpoint_r(struct perf_evlist *evlist)
145{
0c21f736 146 struct perf_evsel *evsel = perf_evlist__first(evlist);
f50246e2
JO
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
159static int test__checkevent_breakpoint_w(struct perf_evlist *evlist)
160{
0c21f736 161 struct perf_evsel *evsel = perf_evlist__first(evlist);
f50246e2
JO
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
7582732f
JO
174static int test__checkevent_breakpoint_rw(struct perf_evlist *evlist)
175{
0c21f736 176 struct perf_evsel *evsel = perf_evlist__first(evlist);
7582732f
JO
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
f50246e2
JO
189static int test__checkevent_tracepoint_modifier(struct perf_evlist *evlist)
190{
0c21f736 191 struct perf_evsel *evsel = perf_evlist__first(evlist);
f50246e2
JO
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
201static int
202test__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
220static int test__checkevent_raw_modifier(struct perf_evlist *evlist)
221{
0c21f736 222 struct perf_evsel *evsel = perf_evlist__first(evlist);
f50246e2
JO
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
232static int test__checkevent_numeric_modifier(struct perf_evlist *evlist)
233{
0c21f736 234 struct perf_evsel *evsel = perf_evlist__first(evlist);
f50246e2
JO
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
244static int test__checkevent_symbolic_name_modifier(struct perf_evlist *evlist)
245{
0c21f736 246 struct perf_evsel *evsel = perf_evlist__first(evlist);
f50246e2
JO
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
256static int test__checkevent_exclude_host_modifier(struct perf_evlist *evlist)
257{
0c21f736 258 struct perf_evsel *evsel = perf_evlist__first(evlist);
f50246e2
JO
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
266static int test__checkevent_exclude_guest_modifier(struct perf_evlist *evlist)
267{
0c21f736 268 struct perf_evsel *evsel = perf_evlist__first(evlist);
f50246e2
JO
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
276static int test__checkevent_symbolic_alias_modifier(struct perf_evlist *evlist)
277{
0c21f736 278 struct perf_evsel *evsel = perf_evlist__first(evlist);
f50246e2
JO
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
288static int test__checkevent_genhw_modifier(struct perf_evlist *evlist)
289{
0c21f736 290 struct perf_evsel *evsel = perf_evlist__first(evlist);
f50246e2
JO
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
300static int test__checkevent_breakpoint_modifier(struct perf_evlist *evlist)
301{
0c21f736 302 struct perf_evsel *evsel = perf_evlist__first(evlist);
f50246e2 303
f50246e2
JO
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);
287e74aa 309 TEST_ASSERT_VAL("wrong name",
ac2ba9f3 310 !strcmp(perf_evsel__name(evsel), "mem:0:u"));
f50246e2
JO
311
312 return test__checkevent_breakpoint(evlist);
313}
314
315static int test__checkevent_breakpoint_x_modifier(struct perf_evlist *evlist)
316{
0c21f736 317 struct perf_evsel *evsel = perf_evlist__first(evlist);
f50246e2
JO
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);
287e74aa 323 TEST_ASSERT_VAL("wrong name",
ac2ba9f3 324 !strcmp(perf_evsel__name(evsel), "mem:0:x:k"));
f50246e2
JO
325
326 return test__checkevent_breakpoint_x(evlist);
327}
328
329static int test__checkevent_breakpoint_r_modifier(struct perf_evlist *evlist)
330{
0c21f736 331 struct perf_evsel *evsel = perf_evlist__first(evlist);
f50246e2
JO
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);
287e74aa 337 TEST_ASSERT_VAL("wrong name",
ac2ba9f3 338 !strcmp(perf_evsel__name(evsel), "mem:0:r:hp"));
f50246e2
JO
339
340 return test__checkevent_breakpoint_r(evlist);
341}
342
343static int test__checkevent_breakpoint_w_modifier(struct perf_evlist *evlist)
344{
0c21f736 345 struct perf_evsel *evsel = perf_evlist__first(evlist);
f50246e2
JO
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);
287e74aa 351 TEST_ASSERT_VAL("wrong name",
ac2ba9f3 352 !strcmp(perf_evsel__name(evsel), "mem:0:w:up"));
f50246e2
JO
353
354 return test__checkevent_breakpoint_w(evlist);
355}
356
7582732f
JO
357static int test__checkevent_breakpoint_rw_modifier(struct perf_evlist *evlist)
358{
0c21f736 359 struct perf_evsel *evsel = perf_evlist__first(evlist);
7582732f
JO
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);
287e74aa 365 TEST_ASSERT_VAL("wrong name",
ac2ba9f3 366 !strcmp(perf_evsel__name(evsel), "mem:0:rw:kp"));
7582732f
JO
367
368 return test__checkevent_breakpoint_rw(evlist);
369}
370
f50246e2
JO
371static int test__checkevent_pmu(struct perf_evlist *evlist)
372{
373
0c21f736 374 struct perf_evsel *evsel = perf_evlist__first(evlist);
f50246e2
JO
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
386static int test__checkevent_list(struct perf_evlist *evlist)
387{
0c21f736 388 struct perf_evsel *evsel = perf_evlist__first(evlist);
f50246e2
JO
389
390 TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->nr_entries);
391
392 /* r1 */
f50246e2
JO
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 */
0c21f736 403 evsel = perf_evsel__next(evsel);
f50246e2
JO
404 TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->attr.type);
405 TEST_ASSERT_VAL("wrong sample_type",
30f31c0a 406 PERF_TP_SAMPLE_TYPE == evsel->attr.sample_type);
f50246e2
JO
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 */
0c21f736 414 evsel = perf_evsel__next(evsel);
f50246e2
JO
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
6b5fc39b
JO
425static int test__checkevent_pmu_name(struct perf_evlist *evlist)
426{
0c21f736 427 struct perf_evsel *evsel = perf_evlist__first(evlist);
6b5fc39b 428
7a25b2d3 429 /* cpu/config=1,name=krava/u */
6b5fc39b
JO
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);
22c8b843 433 TEST_ASSERT_VAL("wrong name", !strcmp(perf_evsel__name(evsel), "krava"));
6b5fc39b 434
7a25b2d3 435 /* cpu/config=2/u" */
0c21f736 436 evsel = perf_evsel__next(evsel);
6b5fc39b
JO
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);
7a25b2d3 440 TEST_ASSERT_VAL("wrong name",
ac2ba9f3 441 !strcmp(perf_evsel__name(evsel), "cpu/config=2/u"));
6b5fc39b
JO
442
443 return 0;
444}
445
4429392e
JO
446static 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
905f5ee2
JO
489static 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 */
0c21f736 496 evsel = leader = perf_evlist__first(evlist);
905f5ee2
JO
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 */
0c21f736 509 evsel = perf_evsel__next(evsel);
905f5ee2
JO
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);
42be7398
JO
516 /* use of precise requires exclude_guest */
517 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
905f5ee2
JO
518 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
519 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 2);
520 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
521
522 return 0;
523}
524
525static int test__group2(struct perf_evlist *evlist)
526{
527 struct perf_evsel *evsel, *leader;
528
529 TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->nr_entries);
530
531 /* faults + :ku modifier */
0c21f736 532 evsel = leader = perf_evlist__first(evlist);
905f5ee2
JO
533 TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->attr.type);
534 TEST_ASSERT_VAL("wrong config",
535 PERF_COUNT_SW_PAGE_FAULTS == evsel->attr.config);
536 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
537 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
538 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
539 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
540 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
541 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
542 TEST_ASSERT_VAL("wrong leader", evsel->leader == NULL);
543
544 /* cache-references + :u modifier */
0c21f736 545 evsel = perf_evsel__next(evsel);
905f5ee2
JO
546 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
547 TEST_ASSERT_VAL("wrong config",
548 PERF_COUNT_HW_CACHE_REFERENCES == evsel->attr.config);
549 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
550 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
551 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
552 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
553 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
554 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
555 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
556
557 /* cycles:k */
0c21f736 558 evsel = perf_evsel__next(evsel);
905f5ee2
JO
559 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
560 TEST_ASSERT_VAL("wrong config",
561 PERF_COUNT_HW_CPU_CYCLES == 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", evsel->leader == NULL);
569
570 return 0;
571}
572
1d037ca1 573static int test__group3(struct perf_evlist *evlist __maybe_unused)
905f5ee2
JO
574{
575 struct perf_evsel *evsel, *leader;
576
577 TEST_ASSERT_VAL("wrong number of entries", 5 == evlist->nr_entries);
578
579 /* group1 syscalls:sys_enter_open:H */
0c21f736 580 evsel = leader = perf_evlist__first(evlist);
905f5ee2
JO
581 TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->attr.type);
582 TEST_ASSERT_VAL("wrong sample_type",
583 PERF_TP_SAMPLE_TYPE == evsel->attr.sample_type);
584 TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->attr.sample_period);
585 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
586 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
587 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
588 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
589 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
590 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
591 TEST_ASSERT_VAL("wrong leader", evsel->leader == NULL);
592 TEST_ASSERT_VAL("wrong group name",
593 !strcmp(leader->group_name, "group1"));
594
595 /* group1 cycles:kppp */
0c21f736 596 evsel = perf_evsel__next(evsel);
905f5ee2
JO
597 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
598 TEST_ASSERT_VAL("wrong config",
599 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
600 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
601 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
602 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
42be7398
JO
603 /* use of precise requires exclude_guest */
604 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
905f5ee2
JO
605 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
606 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 3);
607 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
608 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
609
610 /* group2 cycles + G modifier */
0c21f736 611 evsel = leader = perf_evsel__next(evsel);
905f5ee2
JO
612 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
613 TEST_ASSERT_VAL("wrong config",
614 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
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", evsel->leader == NULL);
622 TEST_ASSERT_VAL("wrong group name",
623 !strcmp(leader->group_name, "group2"));
624
625 /* group2 1:3 + G modifier */
0c21f736 626 evsel = perf_evsel__next(evsel);
905f5ee2
JO
627 TEST_ASSERT_VAL("wrong type", 1 == evsel->attr.type);
628 TEST_ASSERT_VAL("wrong config", 3 == evsel->attr.config);
629 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
630 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
631 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
632 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
633 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
634 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
635 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
636
637 /* instructions:u */
0c21f736 638 evsel = perf_evsel__next(evsel);
905f5ee2
JO
639 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
640 TEST_ASSERT_VAL("wrong config",
641 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
642 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
643 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
644 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
645 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
646 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
647 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
648 TEST_ASSERT_VAL("wrong leader", evsel->leader == NULL);
649
650 return 0;
651}
652
1d037ca1 653static int test__group4(struct perf_evlist *evlist __maybe_unused)
905f5ee2
JO
654{
655 struct perf_evsel *evsel, *leader;
656
657 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
658
659 /* cycles:u + p */
0c21f736 660 evsel = leader = perf_evlist__first(evlist);
905f5ee2
JO
661 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
662 TEST_ASSERT_VAL("wrong config",
663 PERF_COUNT_HW_CPU_CYCLES == 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);
42be7398
JO
667 /* use of precise requires exclude_guest */
668 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
905f5ee2
JO
669 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
670 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 1);
671 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
672 TEST_ASSERT_VAL("wrong leader", evsel->leader == NULL);
673
674 /* instructions:kp + p */
0c21f736 675 evsel = perf_evsel__next(evsel);
905f5ee2
JO
676 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
677 TEST_ASSERT_VAL("wrong config",
678 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
679 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
680 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
681 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
42be7398
JO
682 /* use of precise requires exclude_guest */
683 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
905f5ee2
JO
684 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
685 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 2);
686 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
687
688 return 0;
689}
690
1d037ca1 691static int test__group5(struct perf_evlist *evlist __maybe_unused)
905f5ee2
JO
692{
693 struct perf_evsel *evsel, *leader;
694
695 TEST_ASSERT_VAL("wrong number of entries", 5 == evlist->nr_entries);
696
697 /* cycles + G */
0c21f736 698 evsel = leader = perf_evlist__first(evlist);
905f5ee2
JO
699 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
700 TEST_ASSERT_VAL("wrong config",
701 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
702 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
703 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
704 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
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);
708 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
709 TEST_ASSERT_VAL("wrong leader", evsel->leader == NULL);
710
711 /* instructions + G */
0c21f736 712 evsel = perf_evsel__next(evsel);
905f5ee2
JO
713 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
714 TEST_ASSERT_VAL("wrong config",
715 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
716 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
717 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
718 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
719 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
720 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
721 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
722 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
723
724 /* cycles:G */
0c21f736 725 evsel = leader = perf_evsel__next(evsel);
905f5ee2
JO
726 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
727 TEST_ASSERT_VAL("wrong config",
728 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
729 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
730 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
731 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
732 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
733 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
734 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
735 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
736 TEST_ASSERT_VAL("wrong leader", evsel->leader == NULL);
737
738 /* instructions:G */
0c21f736 739 evsel = perf_evsel__next(evsel);
905f5ee2
JO
740 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
741 TEST_ASSERT_VAL("wrong config",
742 PERF_COUNT_HW_INSTRUCTIONS == 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 leader", evsel->leader == leader);
750
751 /* cycles */
0c21f736 752 evsel = perf_evsel__next(evsel);
905f5ee2
JO
753 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
754 TEST_ASSERT_VAL("wrong config",
755 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
756 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
757 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
758 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
759 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
760 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
761 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
762 TEST_ASSERT_VAL("wrong leader", evsel->leader == NULL);
763
764 return 0;
765}
766
f50246e2
JO
767struct test__event_st {
768 const char *name;
769 __u32 type;
770 int (*check)(struct perf_evlist *evlist);
771};
772
773static struct test__event_st test__events[] = {
774 [0] = {
775 .name = "syscalls:sys_enter_open",
776 .check = test__checkevent_tracepoint,
777 },
778 [1] = {
779 .name = "syscalls:*",
780 .check = test__checkevent_tracepoint_multi,
781 },
782 [2] = {
783 .name = "r1a",
784 .check = test__checkevent_raw,
785 },
786 [3] = {
787 .name = "1:1",
788 .check = test__checkevent_numeric,
789 },
790 [4] = {
791 .name = "instructions",
792 .check = test__checkevent_symbolic_name,
793 },
794 [5] = {
795 .name = "cycles/period=100000,config2/",
796 .check = test__checkevent_symbolic_name_config,
797 },
798 [6] = {
799 .name = "faults",
800 .check = test__checkevent_symbolic_alias,
801 },
802 [7] = {
803 .name = "L1-dcache-load-miss",
804 .check = test__checkevent_genhw,
805 },
806 [8] = {
807 .name = "mem:0",
808 .check = test__checkevent_breakpoint,
809 },
810 [9] = {
811 .name = "mem:0:x",
812 .check = test__checkevent_breakpoint_x,
813 },
814 [10] = {
815 .name = "mem:0:r",
816 .check = test__checkevent_breakpoint_r,
817 },
818 [11] = {
819 .name = "mem:0:w",
820 .check = test__checkevent_breakpoint_w,
821 },
822 [12] = {
823 .name = "syscalls:sys_enter_open:k",
824 .check = test__checkevent_tracepoint_modifier,
825 },
826 [13] = {
827 .name = "syscalls:*:u",
828 .check = test__checkevent_tracepoint_multi_modifier,
829 },
830 [14] = {
831 .name = "r1a:kp",
832 .check = test__checkevent_raw_modifier,
833 },
834 [15] = {
835 .name = "1:1:hp",
836 .check = test__checkevent_numeric_modifier,
837 },
838 [16] = {
839 .name = "instructions:h",
840 .check = test__checkevent_symbolic_name_modifier,
841 },
842 [17] = {
843 .name = "faults:u",
844 .check = test__checkevent_symbolic_alias_modifier,
845 },
846 [18] = {
847 .name = "L1-dcache-load-miss:kp",
848 .check = test__checkevent_genhw_modifier,
849 },
850 [19] = {
851 .name = "mem:0:u",
852 .check = test__checkevent_breakpoint_modifier,
853 },
854 [20] = {
855 .name = "mem:0:x:k",
856 .check = test__checkevent_breakpoint_x_modifier,
857 },
858 [21] = {
859 .name = "mem:0:r:hp",
860 .check = test__checkevent_breakpoint_r_modifier,
861 },
862 [22] = {
863 .name = "mem:0:w:up",
864 .check = test__checkevent_breakpoint_w_modifier,
865 },
866 [23] = {
867 .name = "r1,syscalls:sys_enter_open:k,1:1:hp",
868 .check = test__checkevent_list,
869 },
870 [24] = {
871 .name = "instructions:G",
872 .check = test__checkevent_exclude_host_modifier,
873 },
874 [25] = {
875 .name = "instructions:H",
876 .check = test__checkevent_exclude_guest_modifier,
877 },
7582732f
JO
878 [26] = {
879 .name = "mem:0:rw",
880 .check = test__checkevent_breakpoint_rw,
881 },
882 [27] = {
883 .name = "mem:0:rw:kp",
884 .check = test__checkevent_breakpoint_rw_modifier,
885 },
905f5ee2
JO
886 [28] = {
887 .name = "{instructions:k,cycles:upp}",
888 .check = test__group1,
889 },
890 [29] = {
891 .name = "{faults:k,cache-references}:u,cycles:k",
892 .check = test__group2,
893 },
894 [30] = {
895 .name = "group1{syscalls:sys_enter_open:H,cycles:kppp},group2{cycles,1:3}:G,instructions:u",
896 .check = test__group3,
897 },
898 [31] = {
899 .name = "{cycles:u,instructions:kp}:p",
900 .check = test__group4,
901 },
902 [32] = {
903 .name = "{cycles,instructions}:G,{cycles:G,instructions:G},cycles",
904 .check = test__group5,
905 },
f50246e2
JO
906};
907
f50246e2
JO
908static struct test__event_st test__events_pmu[] = {
909 [0] = {
910 .name = "cpu/config=10,config1,config2=3,period=1000/u",
911 .check = test__checkevent_pmu,
912 },
6b5fc39b
JO
913 [1] = {
914 .name = "cpu/config=1,name=krava/u,cpu/config=2/u",
915 .check = test__checkevent_pmu_name,
916 },
f50246e2
JO
917};
918
4429392e
JO
919struct test__term {
920 const char *str;
921 __u32 type;
922 int (*check)(struct list_head *terms);
923};
924
925static struct test__term test__terms[] = {
926 [0] = {
927 .str = "config=10,config1,config2=3,umask=1",
928 .check = test__checkterms_simple,
929 },
930};
931
4429392e 932static int test_event(struct test__event_st *e)
f50246e2
JO
933{
934 struct perf_evlist *evlist;
935 int ret;
936
937 evlist = perf_evlist__new(NULL, NULL);
938 if (evlist == NULL)
939 return -ENOMEM;
940
941 ret = parse_events(evlist, e->name, 0);
942 if (ret) {
943 pr_debug("failed to parse event '%s', err %d\n",
944 e->name, ret);
945 return ret;
946 }
947
948 ret = e->check(evlist);
949 perf_evlist__delete(evlist);
950
951 return ret;
952}
953
954static int test_events(struct test__event_st *events, unsigned cnt)
955{
9bfbbc6d 956 int ret1, ret2 = 0;
f50246e2
JO
957 unsigned i;
958
959 for (i = 0; i < cnt; i++) {
960 struct test__event_st *e = &events[i];
961
962 pr_debug("running test %d '%s'\n", i, e->name);
9bfbbc6d
RR
963 ret1 = test_event(e);
964 if (ret1)
965 ret2 = ret1;
4429392e
JO
966 }
967
9bfbbc6d 968 return ret2;
4429392e
JO
969}
970
971static int test_term(struct test__term *t)
972{
973 struct list_head *terms;
974 int ret;
975
976 terms = malloc(sizeof(*terms));
977 if (!terms)
978 return -ENOMEM;
979
980 INIT_LIST_HEAD(terms);
981
982 ret = parse_events_terms(terms, t->str);
983 if (ret) {
984 pr_debug("failed to parse terms '%s', err %d\n",
985 t->str , ret);
986 return ret;
987 }
988
989 ret = t->check(terms);
990 parse_events__free_terms(terms);
991
992 return ret;
993}
994
995static int test_terms(struct test__term *terms, unsigned cnt)
996{
997 int ret = 0;
998 unsigned i;
999
1000 for (i = 0; i < cnt; i++) {
1001 struct test__term *t = &terms[i];
1002
1003 pr_debug("running test %d '%s'\n", i, t->str);
1004 ret = test_term(t);
f50246e2
JO
1005 if (ret)
1006 break;
1007 }
1008
1009 return ret;
1010}
1011
1012static int test_pmu(void)
1013{
1014 struct stat st;
1015 char path[PATH_MAX];
1016 int ret;
1017
1018 snprintf(path, PATH_MAX, "%s/bus/event_source/devices/cpu/format/",
1019 sysfs_find_mountpoint());
1020
1021 ret = stat(path, &st);
1022 if (ret)
3fd44cd4 1023 pr_debug("omitting PMU cpu tests\n");
f50246e2
JO
1024 return !ret;
1025}
1026
1027int parse_events__test(void)
1028{
9bfbbc6d 1029 int ret1, ret2 = 0;
f50246e2 1030
ebf124ff
JO
1031#define TEST_EVENTS(tests) \
1032do { \
9bfbbc6d
RR
1033 ret1 = test_events(tests, ARRAY_SIZE(tests)); \
1034 if (!ret2) \
1035 ret2 = ret1; \
ebf124ff 1036} while (0)
4429392e 1037
ebf124ff 1038 TEST_EVENTS(test__events);
4429392e 1039
ebf124ff
JO
1040 if (test_pmu())
1041 TEST_EVENTS(test__events_pmu);
f50246e2 1042
9bfbbc6d
RR
1043 ret1 = test_terms(test__terms, ARRAY_SIZE(test__terms));
1044 if (!ret2)
1045 ret2 = ret1;
1046
1047 return ret2;
f50246e2 1048}
This page took 0.107666 seconds and 5 git commands to generate.