perf tests: Move pmu tests into separate object
[deliverable/linux.git] / tools / perf / tests / parse-events.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
3f3a2064
JO
446static int test__checkevent_pmu_events(struct perf_evlist *evlist)
447{
448 struct perf_evsel *evsel;
449
450 evsel = list_entry(evlist->entries.next, struct perf_evsel, node);
451 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
452 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
453 TEST_ASSERT_VAL("wrong exclude_user",
454 !evsel->attr.exclude_user);
455 TEST_ASSERT_VAL("wrong exclude_kernel",
456 evsel->attr.exclude_kernel);
457 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
458 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
459
460 return 0;
461}
462
4429392e
JO
463static int test__checkterms_simple(struct list_head *terms)
464{
465 struct parse_events__term *term;
466
467 /* config=10 */
468 term = list_entry(terms->next, struct parse_events__term, list);
469 TEST_ASSERT_VAL("wrong type term",
470 term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG);
471 TEST_ASSERT_VAL("wrong type val",
472 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
473 TEST_ASSERT_VAL("wrong val", term->val.num == 10);
474 TEST_ASSERT_VAL("wrong config", !term->config);
475
476 /* config1 */
477 term = list_entry(term->list.next, struct parse_events__term, list);
478 TEST_ASSERT_VAL("wrong type term",
479 term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG1);
480 TEST_ASSERT_VAL("wrong type val",
481 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
482 TEST_ASSERT_VAL("wrong val", term->val.num == 1);
483 TEST_ASSERT_VAL("wrong config", !term->config);
484
485 /* config2=3 */
486 term = list_entry(term->list.next, struct parse_events__term, list);
487 TEST_ASSERT_VAL("wrong type term",
488 term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG2);
489 TEST_ASSERT_VAL("wrong type val",
490 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
491 TEST_ASSERT_VAL("wrong val", term->val.num == 3);
492 TEST_ASSERT_VAL("wrong config", !term->config);
493
494 /* umask=1*/
495 term = list_entry(term->list.next, struct parse_events__term, list);
496 TEST_ASSERT_VAL("wrong type term",
497 term->type_term == PARSE_EVENTS__TERM_TYPE_USER);
498 TEST_ASSERT_VAL("wrong type val",
499 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
500 TEST_ASSERT_VAL("wrong val", term->val.num == 1);
501 TEST_ASSERT_VAL("wrong config", !strcmp(term->config, "umask"));
502
503 return 0;
504}
505
905f5ee2
JO
506static int test__group1(struct perf_evlist *evlist)
507{
508 struct perf_evsel *evsel, *leader;
509
510 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
511
512 /* instructions:k */
0c21f736 513 evsel = leader = perf_evlist__first(evlist);
905f5ee2
JO
514 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
515 TEST_ASSERT_VAL("wrong config",
516 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
517 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
518 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
519 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
520 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
521 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
522 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
523 TEST_ASSERT_VAL("wrong leader", evsel->leader == NULL);
524
525 /* cycles:upp */
0c21f736 526 evsel = perf_evsel__next(evsel);
905f5ee2
JO
527 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
528 TEST_ASSERT_VAL("wrong config",
529 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
530 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
531 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
532 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
42be7398
JO
533 /* use of precise requires exclude_guest */
534 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
905f5ee2
JO
535 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
536 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 2);
537 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
538
539 return 0;
540}
541
542static int test__group2(struct perf_evlist *evlist)
543{
544 struct perf_evsel *evsel, *leader;
545
546 TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->nr_entries);
547
548 /* faults + :ku modifier */
0c21f736 549 evsel = leader = perf_evlist__first(evlist);
905f5ee2
JO
550 TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->attr.type);
551 TEST_ASSERT_VAL("wrong config",
552 PERF_COUNT_SW_PAGE_FAULTS == evsel->attr.config);
553 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
554 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
555 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
556 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
557 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
558 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
559 TEST_ASSERT_VAL("wrong leader", evsel->leader == NULL);
560
561 /* cache-references + :u modifier */
0c21f736 562 evsel = perf_evsel__next(evsel);
905f5ee2
JO
563 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
564 TEST_ASSERT_VAL("wrong config",
565 PERF_COUNT_HW_CACHE_REFERENCES == evsel->attr.config);
566 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
567 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
568 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
569 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
570 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
571 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
572 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
573
574 /* cycles:k */
0c21f736 575 evsel = perf_evsel__next(evsel);
905f5ee2
JO
576 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
577 TEST_ASSERT_VAL("wrong config",
578 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
579 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
580 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
581 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
582 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
583 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
584 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
585 TEST_ASSERT_VAL("wrong leader", evsel->leader == NULL);
586
587 return 0;
588}
589
1d037ca1 590static int test__group3(struct perf_evlist *evlist __maybe_unused)
905f5ee2
JO
591{
592 struct perf_evsel *evsel, *leader;
593
594 TEST_ASSERT_VAL("wrong number of entries", 5 == evlist->nr_entries);
595
596 /* group1 syscalls:sys_enter_open:H */
0c21f736 597 evsel = leader = perf_evlist__first(evlist);
905f5ee2
JO
598 TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->attr.type);
599 TEST_ASSERT_VAL("wrong sample_type",
600 PERF_TP_SAMPLE_TYPE == evsel->attr.sample_type);
601 TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->attr.sample_period);
602 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
603 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
604 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
605 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
606 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
607 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
608 TEST_ASSERT_VAL("wrong leader", evsel->leader == NULL);
609 TEST_ASSERT_VAL("wrong group name",
610 !strcmp(leader->group_name, "group1"));
611
612 /* group1 cycles:kppp */
0c21f736 613 evsel = perf_evsel__next(evsel);
905f5ee2
JO
614 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
615 TEST_ASSERT_VAL("wrong config",
616 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
617 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
618 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
619 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
42be7398
JO
620 /* use of precise requires exclude_guest */
621 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
905f5ee2
JO
622 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
623 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 3);
624 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
625 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
626
627 /* group2 cycles + G modifier */
0c21f736 628 evsel = leader = perf_evsel__next(evsel);
905f5ee2
JO
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 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
636 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
637 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
638 TEST_ASSERT_VAL("wrong leader", evsel->leader == NULL);
639 TEST_ASSERT_VAL("wrong group name",
640 !strcmp(leader->group_name, "group2"));
641
642 /* group2 1:3 + G modifier */
0c21f736 643 evsel = perf_evsel__next(evsel);
905f5ee2
JO
644 TEST_ASSERT_VAL("wrong type", 1 == evsel->attr.type);
645 TEST_ASSERT_VAL("wrong config", 3 == evsel->attr.config);
646 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
647 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
648 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
649 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
650 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
651 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
652 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
653
654 /* instructions:u */
0c21f736 655 evsel = perf_evsel__next(evsel);
905f5ee2
JO
656 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
657 TEST_ASSERT_VAL("wrong config",
658 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
659 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
660 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
661 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
662 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
663 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
664 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
665 TEST_ASSERT_VAL("wrong leader", evsel->leader == NULL);
666
667 return 0;
668}
669
1d037ca1 670static int test__group4(struct perf_evlist *evlist __maybe_unused)
905f5ee2
JO
671{
672 struct perf_evsel *evsel, *leader;
673
674 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
675
676 /* cycles:u + p */
0c21f736 677 evsel = leader = perf_evlist__first(evlist);
905f5ee2
JO
678 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
679 TEST_ASSERT_VAL("wrong config",
680 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
681 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
682 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
683 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
42be7398
JO
684 /* use of precise requires exclude_guest */
685 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
905f5ee2
JO
686 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
687 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 1);
688 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
689 TEST_ASSERT_VAL("wrong leader", evsel->leader == NULL);
690
691 /* instructions:kp + p */
0c21f736 692 evsel = perf_evsel__next(evsel);
905f5ee2
JO
693 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
694 TEST_ASSERT_VAL("wrong config",
695 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
696 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
697 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
698 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
42be7398
JO
699 /* use of precise requires exclude_guest */
700 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
905f5ee2
JO
701 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
702 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 2);
703 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
704
705 return 0;
706}
707
1d037ca1 708static int test__group5(struct perf_evlist *evlist __maybe_unused)
905f5ee2
JO
709{
710 struct perf_evsel *evsel, *leader;
711
712 TEST_ASSERT_VAL("wrong number of entries", 5 == evlist->nr_entries);
713
714 /* cycles + G */
0c21f736 715 evsel = leader = perf_evlist__first(evlist);
905f5ee2
JO
716 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
717 TEST_ASSERT_VAL("wrong config",
718 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
719 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
720 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
721 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
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);
725 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
726 TEST_ASSERT_VAL("wrong leader", evsel->leader == NULL);
727
728 /* instructions + G */
0c21f736 729 evsel = perf_evsel__next(evsel);
905f5ee2
JO
730 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
731 TEST_ASSERT_VAL("wrong config",
732 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
733 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
734 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
735 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
736 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
737 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
738 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
739 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
740
741 /* cycles:G */
0c21f736 742 evsel = leader = perf_evsel__next(evsel);
905f5ee2
JO
743 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
744 TEST_ASSERT_VAL("wrong config",
745 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
746 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
747 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
748 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
749 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
750 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
751 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
752 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
753 TEST_ASSERT_VAL("wrong leader", evsel->leader == NULL);
754
755 /* instructions:G */
0c21f736 756 evsel = perf_evsel__next(evsel);
905f5ee2
JO
757 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
758 TEST_ASSERT_VAL("wrong config",
759 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
760 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
761 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
762 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
763 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
764 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
765 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
766 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
767
768 /* cycles */
0c21f736 769 evsel = perf_evsel__next(evsel);
905f5ee2
JO
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 leader", evsel->leader == NULL);
780
781 return 0;
782}
783
f50246e2
JO
784struct test__event_st {
785 const char *name;
786 __u32 type;
787 int (*check)(struct perf_evlist *evlist);
788};
789
790static struct test__event_st test__events[] = {
791 [0] = {
792 .name = "syscalls:sys_enter_open",
793 .check = test__checkevent_tracepoint,
794 },
795 [1] = {
796 .name = "syscalls:*",
797 .check = test__checkevent_tracepoint_multi,
798 },
799 [2] = {
800 .name = "r1a",
801 .check = test__checkevent_raw,
802 },
803 [3] = {
804 .name = "1:1",
805 .check = test__checkevent_numeric,
806 },
807 [4] = {
808 .name = "instructions",
809 .check = test__checkevent_symbolic_name,
810 },
811 [5] = {
812 .name = "cycles/period=100000,config2/",
813 .check = test__checkevent_symbolic_name_config,
814 },
815 [6] = {
816 .name = "faults",
817 .check = test__checkevent_symbolic_alias,
818 },
819 [7] = {
820 .name = "L1-dcache-load-miss",
821 .check = test__checkevent_genhw,
822 },
823 [8] = {
824 .name = "mem:0",
825 .check = test__checkevent_breakpoint,
826 },
827 [9] = {
828 .name = "mem:0:x",
829 .check = test__checkevent_breakpoint_x,
830 },
831 [10] = {
832 .name = "mem:0:r",
833 .check = test__checkevent_breakpoint_r,
834 },
835 [11] = {
836 .name = "mem:0:w",
837 .check = test__checkevent_breakpoint_w,
838 },
839 [12] = {
840 .name = "syscalls:sys_enter_open:k",
841 .check = test__checkevent_tracepoint_modifier,
842 },
843 [13] = {
844 .name = "syscalls:*:u",
845 .check = test__checkevent_tracepoint_multi_modifier,
846 },
847 [14] = {
848 .name = "r1a:kp",
849 .check = test__checkevent_raw_modifier,
850 },
851 [15] = {
852 .name = "1:1:hp",
853 .check = test__checkevent_numeric_modifier,
854 },
855 [16] = {
856 .name = "instructions:h",
857 .check = test__checkevent_symbolic_name_modifier,
858 },
859 [17] = {
860 .name = "faults:u",
861 .check = test__checkevent_symbolic_alias_modifier,
862 },
863 [18] = {
864 .name = "L1-dcache-load-miss:kp",
865 .check = test__checkevent_genhw_modifier,
866 },
867 [19] = {
868 .name = "mem:0:u",
869 .check = test__checkevent_breakpoint_modifier,
870 },
871 [20] = {
872 .name = "mem:0:x:k",
873 .check = test__checkevent_breakpoint_x_modifier,
874 },
875 [21] = {
876 .name = "mem:0:r:hp",
877 .check = test__checkevent_breakpoint_r_modifier,
878 },
879 [22] = {
880 .name = "mem:0:w:up",
881 .check = test__checkevent_breakpoint_w_modifier,
882 },
883 [23] = {
884 .name = "r1,syscalls:sys_enter_open:k,1:1:hp",
885 .check = test__checkevent_list,
886 },
887 [24] = {
888 .name = "instructions:G",
889 .check = test__checkevent_exclude_host_modifier,
890 },
891 [25] = {
892 .name = "instructions:H",
893 .check = test__checkevent_exclude_guest_modifier,
894 },
7582732f
JO
895 [26] = {
896 .name = "mem:0:rw",
897 .check = test__checkevent_breakpoint_rw,
898 },
899 [27] = {
900 .name = "mem:0:rw:kp",
901 .check = test__checkevent_breakpoint_rw_modifier,
902 },
905f5ee2
JO
903 [28] = {
904 .name = "{instructions:k,cycles:upp}",
905 .check = test__group1,
906 },
907 [29] = {
908 .name = "{faults:k,cache-references}:u,cycles:k",
909 .check = test__group2,
910 },
911 [30] = {
912 .name = "group1{syscalls:sys_enter_open:H,cycles:kppp},group2{cycles,1:3}:G,instructions:u",
913 .check = test__group3,
914 },
915 [31] = {
916 .name = "{cycles:u,instructions:kp}:p",
917 .check = test__group4,
918 },
919 [32] = {
920 .name = "{cycles,instructions}:G,{cycles:G,instructions:G},cycles",
921 .check = test__group5,
922 },
f50246e2
JO
923};
924
f50246e2
JO
925static struct test__event_st test__events_pmu[] = {
926 [0] = {
927 .name = "cpu/config=10,config1,config2=3,period=1000/u",
928 .check = test__checkevent_pmu,
929 },
6b5fc39b
JO
930 [1] = {
931 .name = "cpu/config=1,name=krava/u,cpu/config=2/u",
932 .check = test__checkevent_pmu_name,
933 },
f50246e2
JO
934};
935
4429392e
JO
936struct test__term {
937 const char *str;
938 __u32 type;
939 int (*check)(struct list_head *terms);
940};
941
942static struct test__term test__terms[] = {
943 [0] = {
944 .str = "config=10,config1,config2=3,umask=1",
945 .check = test__checkterms_simple,
946 },
947};
948
4429392e 949static int test_event(struct test__event_st *e)
f50246e2
JO
950{
951 struct perf_evlist *evlist;
952 int ret;
953
954 evlist = perf_evlist__new(NULL, NULL);
955 if (evlist == NULL)
956 return -ENOMEM;
957
958 ret = parse_events(evlist, e->name, 0);
959 if (ret) {
960 pr_debug("failed to parse event '%s', err %d\n",
961 e->name, ret);
962 return ret;
963 }
964
965 ret = e->check(evlist);
966 perf_evlist__delete(evlist);
967
968 return ret;
969}
970
971static int test_events(struct test__event_st *events, unsigned cnt)
972{
9bfbbc6d 973 int ret1, ret2 = 0;
f50246e2
JO
974 unsigned i;
975
976 for (i = 0; i < cnt; i++) {
977 struct test__event_st *e = &events[i];
978
979 pr_debug("running test %d '%s'\n", i, e->name);
9bfbbc6d
RR
980 ret1 = test_event(e);
981 if (ret1)
982 ret2 = ret1;
4429392e
JO
983 }
984
9bfbbc6d 985 return ret2;
4429392e
JO
986}
987
988static int test_term(struct test__term *t)
989{
990 struct list_head *terms;
991 int ret;
992
993 terms = malloc(sizeof(*terms));
994 if (!terms)
995 return -ENOMEM;
996
997 INIT_LIST_HEAD(terms);
998
999 ret = parse_events_terms(terms, t->str);
1000 if (ret) {
1001 pr_debug("failed to parse terms '%s', err %d\n",
1002 t->str , ret);
1003 return ret;
1004 }
1005
1006 ret = t->check(terms);
1007 parse_events__free_terms(terms);
1008
1009 return ret;
1010}
1011
1012static int test_terms(struct test__term *terms, unsigned cnt)
1013{
1014 int ret = 0;
1015 unsigned i;
1016
1017 for (i = 0; i < cnt; i++) {
1018 struct test__term *t = &terms[i];
1019
1020 pr_debug("running test %d '%s'\n", i, t->str);
1021 ret = test_term(t);
f50246e2
JO
1022 if (ret)
1023 break;
1024 }
1025
1026 return ret;
1027}
1028
1029static int test_pmu(void)
1030{
1031 struct stat st;
1032 char path[PATH_MAX];
1033 int ret;
1034
1035 snprintf(path, PATH_MAX, "%s/bus/event_source/devices/cpu/format/",
1036 sysfs_find_mountpoint());
1037
1038 ret = stat(path, &st);
1039 if (ret)
3fd44cd4 1040 pr_debug("omitting PMU cpu tests\n");
f50246e2
JO
1041 return !ret;
1042}
1043
3f3a2064
JO
1044static int test_pmu_events(void)
1045{
1046 struct stat st;
1047 char path[PATH_MAX];
1048 struct dirent *ent;
1049 DIR *dir;
1050 int ret;
1051
1052 snprintf(path, PATH_MAX, "%s/bus/event_source/devices/cpu/events/",
1053 sysfs_find_mountpoint());
1054
1055 ret = stat(path, &st);
1056 if (ret) {
1057 pr_debug("ommiting PMU cpu events tests\n");
1058 return 0;
1059 }
1060
1061 dir = opendir(path);
1062 if (!dir) {
1063 pr_debug("can't open pmu event dir");
1064 return -1;
1065 }
1066
1067 while (!ret && (ent = readdir(dir))) {
1068#define MAX_NAME 100
1069 struct test__event_st e;
1070 char name[MAX_NAME];
1071
1072 if (!strcmp(ent->d_name, ".") ||
1073 !strcmp(ent->d_name, ".."))
1074 continue;
1075
1076 snprintf(name, MAX_NAME, "cpu/event=%s/u", ent->d_name);
1077
1078 e.name = name;
1079 e.check = test__checkevent_pmu_events;
1080
1081 ret = test_event(&e);
1082#undef MAX_NAME
1083 }
1084
1085 closedir(dir);
1086 return ret;
1087}
1088
f50246e2
JO
1089int parse_events__test(void)
1090{
9bfbbc6d 1091 int ret1, ret2 = 0;
f50246e2 1092
ebf124ff
JO
1093#define TEST_EVENTS(tests) \
1094do { \
9bfbbc6d
RR
1095 ret1 = test_events(tests, ARRAY_SIZE(tests)); \
1096 if (!ret2) \
1097 ret2 = ret1; \
ebf124ff 1098} while (0)
4429392e 1099
ebf124ff 1100 TEST_EVENTS(test__events);
4429392e 1101
ebf124ff
JO
1102 if (test_pmu())
1103 TEST_EVENTS(test__events_pmu);
f50246e2 1104
3f3a2064
JO
1105 if (test_pmu()) {
1106 int ret = test_pmu_events();
1107 if (ret)
1108 return ret;
1109 }
1110
9bfbbc6d
RR
1111 ret1 = test_terms(test__terms, ARRAY_SIZE(test__terms));
1112 if (!ret2)
1113 ret2 = ret1;
1114
1115 return ret2;
f50246e2 1116}
This page took 0.100966 seconds and 5 git commands to generate.