]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/blob - tools/perf/tests/parse-events.c
Merge remote-tracking branches 'asoc/topic/ac97', 'asoc/topic/ac97-mfd', 'asoc/topic...
[mirror_ubuntu-focal-kernel.git] / tools / perf / tests / parse-events.c
1 // SPDX-License-Identifier: GPL-2.0
2 #include "parse-events.h"
3 #include "evsel.h"
4 #include "evlist.h"
5 #include <api/fs/fs.h>
6 #include "tests.h"
7 #include "debug.h"
8 #include "util.h"
9 #include <dirent.h>
10 #include <errno.h>
11 #include <sys/types.h>
12 #include <sys/stat.h>
13 #include <unistd.h>
14 #include <linux/kernel.h>
15 #include <linux/hw_breakpoint.h>
16 #include <api/fs/fs.h>
17 #include <api/fs/tracing_path.h>
18
19 #define PERF_TP_SAMPLE_TYPE (PERF_SAMPLE_RAW | PERF_SAMPLE_TIME | \
20 PERF_SAMPLE_CPU | PERF_SAMPLE_PERIOD)
21
22 static int test__checkevent_tracepoint(struct perf_evlist *evlist)
23 {
24 struct perf_evsel *evsel = perf_evlist__first(evlist);
25
26 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
27 TEST_ASSERT_VAL("wrong number of groups", 0 == evlist->nr_groups);
28 TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->attr.type);
29 TEST_ASSERT_VAL("wrong sample_type",
30 PERF_TP_SAMPLE_TYPE == evsel->attr.sample_type);
31 TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->attr.sample_period);
32 return 0;
33 }
34
35 static int test__checkevent_tracepoint_multi(struct perf_evlist *evlist)
36 {
37 struct perf_evsel *evsel;
38
39 TEST_ASSERT_VAL("wrong number of entries", evlist->nr_entries > 1);
40 TEST_ASSERT_VAL("wrong number of groups", 0 == evlist->nr_groups);
41
42 evlist__for_each_entry(evlist, evsel) {
43 TEST_ASSERT_VAL("wrong type",
44 PERF_TYPE_TRACEPOINT == evsel->attr.type);
45 TEST_ASSERT_VAL("wrong sample_type",
46 PERF_TP_SAMPLE_TYPE == evsel->attr.sample_type);
47 TEST_ASSERT_VAL("wrong sample_period",
48 1 == evsel->attr.sample_period);
49 }
50 return 0;
51 }
52
53 static int test__checkevent_raw(struct perf_evlist *evlist)
54 {
55 struct perf_evsel *evsel = perf_evlist__first(evlist);
56
57 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
58 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
59 TEST_ASSERT_VAL("wrong config", 0x1a == evsel->attr.config);
60 return 0;
61 }
62
63 static int test__checkevent_numeric(struct perf_evlist *evlist)
64 {
65 struct perf_evsel *evsel = perf_evlist__first(evlist);
66
67 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
68 TEST_ASSERT_VAL("wrong type", 1 == evsel->attr.type);
69 TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
70 return 0;
71 }
72
73 static int test__checkevent_symbolic_name(struct perf_evlist *evlist)
74 {
75 struct perf_evsel *evsel = perf_evlist__first(evlist);
76
77 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
78 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
79 TEST_ASSERT_VAL("wrong config",
80 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
81 return 0;
82 }
83
84 static int test__checkevent_symbolic_name_config(struct perf_evlist *evlist)
85 {
86 struct perf_evsel *evsel = perf_evlist__first(evlist);
87
88 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
89 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
90 TEST_ASSERT_VAL("wrong config",
91 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
92 /*
93 * The period value gets configured within perf_evlist__config,
94 * while this test executes only parse events method.
95 */
96 TEST_ASSERT_VAL("wrong period",
97 0 == evsel->attr.sample_period);
98 TEST_ASSERT_VAL("wrong config1",
99 0 == evsel->attr.config1);
100 TEST_ASSERT_VAL("wrong config2",
101 1 == evsel->attr.config2);
102 return 0;
103 }
104
105 static int test__checkevent_symbolic_alias(struct perf_evlist *evlist)
106 {
107 struct perf_evsel *evsel = perf_evlist__first(evlist);
108
109 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
110 TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->attr.type);
111 TEST_ASSERT_VAL("wrong config",
112 PERF_COUNT_SW_PAGE_FAULTS == evsel->attr.config);
113 return 0;
114 }
115
116 static int test__checkevent_genhw(struct perf_evlist *evlist)
117 {
118 struct perf_evsel *evsel = perf_evlist__first(evlist);
119
120 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
121 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HW_CACHE == evsel->attr.type);
122 TEST_ASSERT_VAL("wrong config", (1 << 16) == evsel->attr.config);
123 return 0;
124 }
125
126 static int test__checkevent_breakpoint(struct perf_evlist *evlist)
127 {
128 struct perf_evsel *evsel = perf_evlist__first(evlist);
129
130 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
131 TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->attr.type);
132 TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
133 TEST_ASSERT_VAL("wrong bp_type", (HW_BREAKPOINT_R | HW_BREAKPOINT_W) ==
134 evsel->attr.bp_type);
135 TEST_ASSERT_VAL("wrong bp_len", HW_BREAKPOINT_LEN_4 ==
136 evsel->attr.bp_len);
137 return 0;
138 }
139
140 static int test__checkevent_breakpoint_x(struct perf_evlist *evlist)
141 {
142 struct perf_evsel *evsel = perf_evlist__first(evlist);
143
144 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
145 TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->attr.type);
146 TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
147 TEST_ASSERT_VAL("wrong bp_type",
148 HW_BREAKPOINT_X == evsel->attr.bp_type);
149 TEST_ASSERT_VAL("wrong bp_len", sizeof(long) == evsel->attr.bp_len);
150 return 0;
151 }
152
153 static int test__checkevent_breakpoint_r(struct perf_evlist *evlist)
154 {
155 struct perf_evsel *evsel = perf_evlist__first(evlist);
156
157 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
158 TEST_ASSERT_VAL("wrong type",
159 PERF_TYPE_BREAKPOINT == evsel->attr.type);
160 TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
161 TEST_ASSERT_VAL("wrong bp_type",
162 HW_BREAKPOINT_R == evsel->attr.bp_type);
163 TEST_ASSERT_VAL("wrong bp_len",
164 HW_BREAKPOINT_LEN_4 == evsel->attr.bp_len);
165 return 0;
166 }
167
168 static int test__checkevent_breakpoint_w(struct perf_evlist *evlist)
169 {
170 struct perf_evsel *evsel = perf_evlist__first(evlist);
171
172 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
173 TEST_ASSERT_VAL("wrong type",
174 PERF_TYPE_BREAKPOINT == evsel->attr.type);
175 TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
176 TEST_ASSERT_VAL("wrong bp_type",
177 HW_BREAKPOINT_W == evsel->attr.bp_type);
178 TEST_ASSERT_VAL("wrong bp_len",
179 HW_BREAKPOINT_LEN_4 == evsel->attr.bp_len);
180 return 0;
181 }
182
183 static int test__checkevent_breakpoint_rw(struct perf_evlist *evlist)
184 {
185 struct perf_evsel *evsel = perf_evlist__first(evlist);
186
187 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
188 TEST_ASSERT_VAL("wrong type",
189 PERF_TYPE_BREAKPOINT == evsel->attr.type);
190 TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
191 TEST_ASSERT_VAL("wrong bp_type",
192 (HW_BREAKPOINT_R|HW_BREAKPOINT_W) == evsel->attr.bp_type);
193 TEST_ASSERT_VAL("wrong bp_len",
194 HW_BREAKPOINT_LEN_4 == evsel->attr.bp_len);
195 return 0;
196 }
197
198 static int test__checkevent_tracepoint_modifier(struct perf_evlist *evlist)
199 {
200 struct perf_evsel *evsel = perf_evlist__first(evlist);
201
202 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
203 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
204 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
205 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
206
207 return test__checkevent_tracepoint(evlist);
208 }
209
210 static int
211 test__checkevent_tracepoint_multi_modifier(struct perf_evlist *evlist)
212 {
213 struct perf_evsel *evsel;
214
215 TEST_ASSERT_VAL("wrong number of entries", evlist->nr_entries > 1);
216
217 evlist__for_each_entry(evlist, evsel) {
218 TEST_ASSERT_VAL("wrong exclude_user",
219 !evsel->attr.exclude_user);
220 TEST_ASSERT_VAL("wrong exclude_kernel",
221 evsel->attr.exclude_kernel);
222 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
223 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
224 }
225
226 return test__checkevent_tracepoint_multi(evlist);
227 }
228
229 static int test__checkevent_raw_modifier(struct perf_evlist *evlist)
230 {
231 struct perf_evsel *evsel = perf_evlist__first(evlist);
232
233 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
234 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
235 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
236 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
237
238 return test__checkevent_raw(evlist);
239 }
240
241 static int test__checkevent_numeric_modifier(struct perf_evlist *evlist)
242 {
243 struct perf_evsel *evsel = perf_evlist__first(evlist);
244
245 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
246 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
247 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
248 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
249
250 return test__checkevent_numeric(evlist);
251 }
252
253 static int test__checkevent_symbolic_name_modifier(struct perf_evlist *evlist)
254 {
255 struct perf_evsel *evsel = perf_evlist__first(evlist);
256
257 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
258 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
259 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
260 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
261
262 return test__checkevent_symbolic_name(evlist);
263 }
264
265 static int test__checkevent_exclude_host_modifier(struct perf_evlist *evlist)
266 {
267 struct perf_evsel *evsel = perf_evlist__first(evlist);
268
269 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
270 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
271
272 return test__checkevent_symbolic_name(evlist);
273 }
274
275 static int test__checkevent_exclude_guest_modifier(struct perf_evlist *evlist)
276 {
277 struct perf_evsel *evsel = perf_evlist__first(evlist);
278
279 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
280 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
281
282 return test__checkevent_symbolic_name(evlist);
283 }
284
285 static int test__checkevent_symbolic_alias_modifier(struct perf_evlist *evlist)
286 {
287 struct perf_evsel *evsel = perf_evlist__first(evlist);
288
289 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
290 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
291 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
292 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
293
294 return test__checkevent_symbolic_alias(evlist);
295 }
296
297 static int test__checkevent_genhw_modifier(struct perf_evlist *evlist)
298 {
299 struct perf_evsel *evsel = perf_evlist__first(evlist);
300
301 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
302 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
303 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
304 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
305
306 return test__checkevent_genhw(evlist);
307 }
308
309 static int test__checkevent_exclude_idle_modifier(struct perf_evlist *evlist)
310 {
311 struct perf_evsel *evsel = perf_evlist__first(evlist);
312
313 TEST_ASSERT_VAL("wrong exclude idle", evsel->attr.exclude_idle);
314 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
315 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
316 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
317 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
318 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
319 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
320
321 return test__checkevent_symbolic_name(evlist);
322 }
323
324 static int test__checkevent_exclude_idle_modifier_1(struct perf_evlist *evlist)
325 {
326 struct perf_evsel *evsel = perf_evlist__first(evlist);
327
328 TEST_ASSERT_VAL("wrong exclude idle", evsel->attr.exclude_idle);
329 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
330 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
331 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
332 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
333 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
334 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
335
336 return test__checkevent_symbolic_name(evlist);
337 }
338
339 static int test__checkevent_breakpoint_modifier(struct perf_evlist *evlist)
340 {
341 struct perf_evsel *evsel = perf_evlist__first(evlist);
342
343
344 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
345 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
346 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
347 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
348 TEST_ASSERT_VAL("wrong name",
349 !strcmp(perf_evsel__name(evsel), "mem:0:u"));
350
351 return test__checkevent_breakpoint(evlist);
352 }
353
354 static int test__checkevent_breakpoint_x_modifier(struct perf_evlist *evlist)
355 {
356 struct perf_evsel *evsel = perf_evlist__first(evlist);
357
358 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
359 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
360 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
361 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
362 TEST_ASSERT_VAL("wrong name",
363 !strcmp(perf_evsel__name(evsel), "mem:0:x:k"));
364
365 return test__checkevent_breakpoint_x(evlist);
366 }
367
368 static int test__checkevent_breakpoint_r_modifier(struct perf_evlist *evlist)
369 {
370 struct perf_evsel *evsel = perf_evlist__first(evlist);
371
372 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
373 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
374 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
375 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
376 TEST_ASSERT_VAL("wrong name",
377 !strcmp(perf_evsel__name(evsel), "mem:0:r:hp"));
378
379 return test__checkevent_breakpoint_r(evlist);
380 }
381
382 static int test__checkevent_breakpoint_w_modifier(struct perf_evlist *evlist)
383 {
384 struct perf_evsel *evsel = perf_evlist__first(evlist);
385
386 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
387 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
388 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
389 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
390 TEST_ASSERT_VAL("wrong name",
391 !strcmp(perf_evsel__name(evsel), "mem:0:w:up"));
392
393 return test__checkevent_breakpoint_w(evlist);
394 }
395
396 static int test__checkevent_breakpoint_rw_modifier(struct perf_evlist *evlist)
397 {
398 struct perf_evsel *evsel = perf_evlist__first(evlist);
399
400 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
401 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
402 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
403 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
404 TEST_ASSERT_VAL("wrong name",
405 !strcmp(perf_evsel__name(evsel), "mem:0:rw:kp"));
406
407 return test__checkevent_breakpoint_rw(evlist);
408 }
409
410 static int test__checkevent_pmu(struct perf_evlist *evlist)
411 {
412
413 struct perf_evsel *evsel = perf_evlist__first(evlist);
414
415 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
416 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
417 TEST_ASSERT_VAL("wrong config", 10 == evsel->attr.config);
418 TEST_ASSERT_VAL("wrong config1", 1 == evsel->attr.config1);
419 TEST_ASSERT_VAL("wrong config2", 3 == evsel->attr.config2);
420 /*
421 * The period value gets configured within perf_evlist__config,
422 * while this test executes only parse events method.
423 */
424 TEST_ASSERT_VAL("wrong period", 0 == evsel->attr.sample_period);
425
426 return 0;
427 }
428
429 static int test__checkevent_list(struct perf_evlist *evlist)
430 {
431 struct perf_evsel *evsel = perf_evlist__first(evlist);
432
433 TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->nr_entries);
434
435 /* r1 */
436 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
437 TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
438 TEST_ASSERT_VAL("wrong config1", 0 == evsel->attr.config1);
439 TEST_ASSERT_VAL("wrong config2", 0 == evsel->attr.config2);
440 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
441 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
442 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
443 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
444
445 /* syscalls:sys_enter_openat:k */
446 evsel = perf_evsel__next(evsel);
447 TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->attr.type);
448 TEST_ASSERT_VAL("wrong sample_type",
449 PERF_TP_SAMPLE_TYPE == evsel->attr.sample_type);
450 TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->attr.sample_period);
451 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
452 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
453 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
454 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
455
456 /* 1:1:hp */
457 evsel = perf_evsel__next(evsel);
458 TEST_ASSERT_VAL("wrong type", 1 == evsel->attr.type);
459 TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
460 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
461 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
462 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
463 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
464
465 return 0;
466 }
467
468 static int test__checkevent_pmu_name(struct perf_evlist *evlist)
469 {
470 struct perf_evsel *evsel = perf_evlist__first(evlist);
471
472 /* cpu/config=1,name=krava/u */
473 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
474 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
475 TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
476 TEST_ASSERT_VAL("wrong name", !strcmp(perf_evsel__name(evsel), "krava"));
477
478 /* cpu/config=2/u" */
479 evsel = perf_evsel__next(evsel);
480 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
481 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
482 TEST_ASSERT_VAL("wrong config", 2 == evsel->attr.config);
483 TEST_ASSERT_VAL("wrong name",
484 !strcmp(perf_evsel__name(evsel), "cpu/config=2/u"));
485
486 return 0;
487 }
488
489 static int test__checkevent_pmu_partial_time_callgraph(struct perf_evlist *evlist)
490 {
491 struct perf_evsel *evsel = perf_evlist__first(evlist);
492
493 /* cpu/config=1,call-graph=fp,time,period=100000/ */
494 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
495 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
496 TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
497 /*
498 * The period, time and callgraph value gets configured
499 * within perf_evlist__config,
500 * while this test executes only parse events method.
501 */
502 TEST_ASSERT_VAL("wrong period", 0 == evsel->attr.sample_period);
503 TEST_ASSERT_VAL("wrong callgraph", !(PERF_SAMPLE_CALLCHAIN & evsel->attr.sample_type));
504 TEST_ASSERT_VAL("wrong time", !(PERF_SAMPLE_TIME & evsel->attr.sample_type));
505
506 /* cpu/config=2,call-graph=no,time=0,period=2000/ */
507 evsel = perf_evsel__next(evsel);
508 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
509 TEST_ASSERT_VAL("wrong config", 2 == evsel->attr.config);
510 /*
511 * The period, time and callgraph value gets configured
512 * within perf_evlist__config,
513 * while this test executes only parse events method.
514 */
515 TEST_ASSERT_VAL("wrong period", 0 == evsel->attr.sample_period);
516 TEST_ASSERT_VAL("wrong callgraph", !(PERF_SAMPLE_CALLCHAIN & evsel->attr.sample_type));
517 TEST_ASSERT_VAL("wrong time", !(PERF_SAMPLE_TIME & evsel->attr.sample_type));
518
519 return 0;
520 }
521
522 static int test__checkevent_pmu_events(struct perf_evlist *evlist)
523 {
524 struct perf_evsel *evsel = perf_evlist__first(evlist);
525
526 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
527 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
528 TEST_ASSERT_VAL("wrong exclude_user",
529 !evsel->attr.exclude_user);
530 TEST_ASSERT_VAL("wrong exclude_kernel",
531 evsel->attr.exclude_kernel);
532 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
533 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
534 TEST_ASSERT_VAL("wrong pinned", !evsel->attr.pinned);
535
536 return 0;
537 }
538
539
540 static int test__checkevent_pmu_events_mix(struct perf_evlist *evlist)
541 {
542 struct perf_evsel *evsel = perf_evlist__first(evlist);
543
544 /* pmu-event:u */
545 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
546 TEST_ASSERT_VAL("wrong exclude_user",
547 !evsel->attr.exclude_user);
548 TEST_ASSERT_VAL("wrong exclude_kernel",
549 evsel->attr.exclude_kernel);
550 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
551 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
552 TEST_ASSERT_VAL("wrong pinned", !evsel->attr.pinned);
553
554 /* cpu/pmu-event/u*/
555 evsel = perf_evsel__next(evsel);
556 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
557 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
558 TEST_ASSERT_VAL("wrong exclude_user",
559 !evsel->attr.exclude_user);
560 TEST_ASSERT_VAL("wrong exclude_kernel",
561 evsel->attr.exclude_kernel);
562 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
563 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
564 TEST_ASSERT_VAL("wrong pinned", !evsel->attr.pinned);
565
566 return 0;
567 }
568
569 static int test__checkterms_simple(struct list_head *terms)
570 {
571 struct parse_events_term *term;
572
573 /* config=10 */
574 term = list_entry(terms->next, struct parse_events_term, list);
575 TEST_ASSERT_VAL("wrong type term",
576 term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG);
577 TEST_ASSERT_VAL("wrong type val",
578 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
579 TEST_ASSERT_VAL("wrong val", term->val.num == 10);
580 TEST_ASSERT_VAL("wrong config", !term->config);
581
582 /* config1 */
583 term = list_entry(term->list.next, struct parse_events_term, list);
584 TEST_ASSERT_VAL("wrong type term",
585 term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG1);
586 TEST_ASSERT_VAL("wrong type val",
587 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
588 TEST_ASSERT_VAL("wrong val", term->val.num == 1);
589 TEST_ASSERT_VAL("wrong config", !term->config);
590
591 /* config2=3 */
592 term = list_entry(term->list.next, struct parse_events_term, list);
593 TEST_ASSERT_VAL("wrong type term",
594 term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG2);
595 TEST_ASSERT_VAL("wrong type val",
596 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
597 TEST_ASSERT_VAL("wrong val", term->val.num == 3);
598 TEST_ASSERT_VAL("wrong config", !term->config);
599
600 /* umask=1*/
601 term = list_entry(term->list.next, struct parse_events_term, list);
602 TEST_ASSERT_VAL("wrong type term",
603 term->type_term == PARSE_EVENTS__TERM_TYPE_USER);
604 TEST_ASSERT_VAL("wrong type val",
605 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
606 TEST_ASSERT_VAL("wrong val", term->val.num == 1);
607 TEST_ASSERT_VAL("wrong config", !strcmp(term->config, "umask"));
608
609 return 0;
610 }
611
612 static int test__group1(struct perf_evlist *evlist)
613 {
614 struct perf_evsel *evsel, *leader;
615
616 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
617 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
618
619 /* instructions:k */
620 evsel = leader = perf_evlist__first(evlist);
621 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
622 TEST_ASSERT_VAL("wrong config",
623 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
624 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
625 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
626 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
627 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
628 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
629 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
630 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
631 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
632 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
633 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
634
635 /* cycles:upp */
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_CPU_CYCLES == 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 /* use of precise requires exclude_guest */
644 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
645 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
646 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 2);
647 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
648 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
649 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
650
651 return 0;
652 }
653
654 static int test__group2(struct perf_evlist *evlist)
655 {
656 struct perf_evsel *evsel, *leader;
657
658 TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->nr_entries);
659 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
660
661 /* faults + :ku modifier */
662 evsel = leader = perf_evlist__first(evlist);
663 TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->attr.type);
664 TEST_ASSERT_VAL("wrong config",
665 PERF_COUNT_SW_PAGE_FAULTS == evsel->attr.config);
666 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
667 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
668 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
669 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
670 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
671 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
672 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
673 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
674 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
675 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
676
677 /* cache-references + :u modifier */
678 evsel = perf_evsel__next(evsel);
679 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
680 TEST_ASSERT_VAL("wrong config",
681 PERF_COUNT_HW_CACHE_REFERENCES == evsel->attr.config);
682 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
683 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
684 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
685 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
686 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
687 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
688 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
689 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
690 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
691
692 /* cycles:k */
693 evsel = perf_evsel__next(evsel);
694 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
695 TEST_ASSERT_VAL("wrong config",
696 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
697 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
698 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
699 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
700 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
701 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
702 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
703 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
704 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
705
706 return 0;
707 }
708
709 static int test__group3(struct perf_evlist *evlist __maybe_unused)
710 {
711 struct perf_evsel *evsel, *leader;
712
713 TEST_ASSERT_VAL("wrong number of entries", 5 == evlist->nr_entries);
714 TEST_ASSERT_VAL("wrong number of groups", 2 == evlist->nr_groups);
715
716 /* group1 syscalls:sys_enter_openat:H */
717 evsel = leader = perf_evlist__first(evlist);
718 TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->attr.type);
719 TEST_ASSERT_VAL("wrong sample_type",
720 PERF_TP_SAMPLE_TYPE == evsel->attr.sample_type);
721 TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->attr.sample_period);
722 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
723 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
724 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
725 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
726 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
727 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
728 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
729 TEST_ASSERT_VAL("wrong group name",
730 !strcmp(leader->group_name, "group1"));
731 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
732 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
733 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
734
735 /* group1 cycles:kppp */
736 evsel = perf_evsel__next(evsel);
737 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
738 TEST_ASSERT_VAL("wrong config",
739 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
740 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
741 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
742 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
743 /* use of precise requires exclude_guest */
744 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
745 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
746 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 3);
747 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
748 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
749 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
750 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
751
752 /* group2 cycles + G modifier */
753 evsel = leader = perf_evsel__next(evsel);
754 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
755 TEST_ASSERT_VAL("wrong config",
756 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
757 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
758 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
759 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
760 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
761 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
762 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
763 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
764 TEST_ASSERT_VAL("wrong group name",
765 !strcmp(leader->group_name, "group2"));
766 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
767 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
768 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
769
770 /* group2 1:3 + G modifier */
771 evsel = perf_evsel__next(evsel);
772 TEST_ASSERT_VAL("wrong type", 1 == evsel->attr.type);
773 TEST_ASSERT_VAL("wrong config", 3 == evsel->attr.config);
774 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
775 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
776 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
777 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
778 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
779 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
780 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
781 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
782 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
783
784 /* instructions:u */
785 evsel = perf_evsel__next(evsel);
786 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
787 TEST_ASSERT_VAL("wrong config",
788 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
789 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
790 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
791 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
792 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
793 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
794 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
795 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
796 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
797
798 return 0;
799 }
800
801 static int test__group4(struct perf_evlist *evlist __maybe_unused)
802 {
803 struct perf_evsel *evsel, *leader;
804
805 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
806 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
807
808 /* cycles:u + p */
809 evsel = leader = perf_evlist__first(evlist);
810 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
811 TEST_ASSERT_VAL("wrong config",
812 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
813 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
814 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
815 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
816 /* use of precise requires exclude_guest */
817 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
818 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
819 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 1);
820 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
821 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
822 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
823 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
824 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
825
826 /* instructions:kp + p */
827 evsel = perf_evsel__next(evsel);
828 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
829 TEST_ASSERT_VAL("wrong config",
830 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
831 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
832 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
833 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
834 /* use of precise requires exclude_guest */
835 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
836 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
837 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 2);
838 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
839 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
840 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
841
842 return 0;
843 }
844
845 static int test__group5(struct perf_evlist *evlist __maybe_unused)
846 {
847 struct perf_evsel *evsel, *leader;
848
849 TEST_ASSERT_VAL("wrong number of entries", 5 == evlist->nr_entries);
850 TEST_ASSERT_VAL("wrong number of groups", 2 == evlist->nr_groups);
851
852 /* cycles + G */
853 evsel = leader = perf_evlist__first(evlist);
854 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
855 TEST_ASSERT_VAL("wrong config",
856 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
857 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
858 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
859 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
860 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
861 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
862 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
863 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
864 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
865 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
866 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
867 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
868
869 /* instructions + G */
870 evsel = perf_evsel__next(evsel);
871 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
872 TEST_ASSERT_VAL("wrong config",
873 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
874 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
875 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
876 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
877 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
878 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
879 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
880 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
881 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
882 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
883
884 /* cycles:G */
885 evsel = leader = perf_evsel__next(evsel);
886 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
887 TEST_ASSERT_VAL("wrong config",
888 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
889 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
890 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
891 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
892 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
893 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
894 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
895 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
896 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
897 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
898 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
899 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
900
901 /* instructions:G */
902 evsel = perf_evsel__next(evsel);
903 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
904 TEST_ASSERT_VAL("wrong config",
905 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
906 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
907 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
908 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
909 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
910 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
911 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
912 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
913 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
914
915 /* cycles */
916 evsel = perf_evsel__next(evsel);
917 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
918 TEST_ASSERT_VAL("wrong config",
919 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
920 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
921 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
922 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
923 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
924 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
925 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
926 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
927
928 return 0;
929 }
930
931 static int test__group_gh1(struct perf_evlist *evlist)
932 {
933 struct perf_evsel *evsel, *leader;
934
935 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
936 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
937
938 /* cycles + :H group modifier */
939 evsel = leader = perf_evlist__first(evlist);
940 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
941 TEST_ASSERT_VAL("wrong config",
942 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
943 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
944 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
945 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
946 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
947 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
948 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
949 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
950 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
951 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
952 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
953
954 /* cache-misses:G + :H group modifier */
955 evsel = perf_evsel__next(evsel);
956 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
957 TEST_ASSERT_VAL("wrong config",
958 PERF_COUNT_HW_CACHE_MISSES == evsel->attr.config);
959 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
960 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
961 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
962 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
963 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
964 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
965 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
966 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
967
968 return 0;
969 }
970
971 static int test__group_gh2(struct perf_evlist *evlist)
972 {
973 struct perf_evsel *evsel, *leader;
974
975 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
976 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
977
978 /* cycles + :G group modifier */
979 evsel = leader = perf_evlist__first(evlist);
980 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
981 TEST_ASSERT_VAL("wrong config",
982 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
983 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
984 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
985 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
986 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
987 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
988 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
989 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
990 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
991 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
992 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
993
994 /* cache-misses:H + :G group modifier */
995 evsel = perf_evsel__next(evsel);
996 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
997 TEST_ASSERT_VAL("wrong config",
998 PERF_COUNT_HW_CACHE_MISSES == evsel->attr.config);
999 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
1000 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
1001 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
1002 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
1003 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
1004 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
1005 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
1006 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
1007
1008 return 0;
1009 }
1010
1011 static int test__group_gh3(struct perf_evlist *evlist)
1012 {
1013 struct perf_evsel *evsel, *leader;
1014
1015 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
1016 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
1017
1018 /* cycles:G + :u group modifier */
1019 evsel = leader = perf_evlist__first(evlist);
1020 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
1021 TEST_ASSERT_VAL("wrong config",
1022 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
1023 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
1024 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
1025 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
1026 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
1027 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
1028 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
1029 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1030 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
1031 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
1032 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
1033
1034 /* cache-misses:H + :u group modifier */
1035 evsel = perf_evsel__next(evsel);
1036 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
1037 TEST_ASSERT_VAL("wrong config",
1038 PERF_COUNT_HW_CACHE_MISSES == evsel->attr.config);
1039 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
1040 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
1041 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
1042 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
1043 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
1044 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
1045 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
1046 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
1047
1048 return 0;
1049 }
1050
1051 static int test__group_gh4(struct perf_evlist *evlist)
1052 {
1053 struct perf_evsel *evsel, *leader;
1054
1055 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
1056 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
1057
1058 /* cycles:G + :uG group modifier */
1059 evsel = leader = perf_evlist__first(evlist);
1060 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
1061 TEST_ASSERT_VAL("wrong config",
1062 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
1063 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
1064 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
1065 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
1066 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
1067 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
1068 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
1069 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1070 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
1071 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
1072 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
1073
1074 /* cache-misses:H + :uG group modifier */
1075 evsel = perf_evsel__next(evsel);
1076 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
1077 TEST_ASSERT_VAL("wrong config",
1078 PERF_COUNT_HW_CACHE_MISSES == evsel->attr.config);
1079 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
1080 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
1081 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
1082 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
1083 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
1084 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
1085 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
1086 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
1087
1088 return 0;
1089 }
1090
1091 static int test__leader_sample1(struct perf_evlist *evlist)
1092 {
1093 struct perf_evsel *evsel, *leader;
1094
1095 TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->nr_entries);
1096
1097 /* cycles - sampling group leader */
1098 evsel = leader = perf_evlist__first(evlist);
1099 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
1100 TEST_ASSERT_VAL("wrong config",
1101 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
1102 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
1103 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
1104 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
1105 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
1106 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
1107 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
1108 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1109 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
1110 TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read);
1111
1112 /* cache-misses - not sampling */
1113 evsel = perf_evsel__next(evsel);
1114 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
1115 TEST_ASSERT_VAL("wrong config",
1116 PERF_COUNT_HW_CACHE_MISSES == evsel->attr.config);
1117 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
1118 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
1119 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
1120 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
1121 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
1122 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
1123 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
1124 TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read);
1125
1126 /* branch-misses - not sampling */
1127 evsel = perf_evsel__next(evsel);
1128 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
1129 TEST_ASSERT_VAL("wrong config",
1130 PERF_COUNT_HW_BRANCH_MISSES == evsel->attr.config);
1131 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
1132 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
1133 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
1134 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
1135 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
1136 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
1137 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1138 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
1139 TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read);
1140
1141 return 0;
1142 }
1143
1144 static int test__leader_sample2(struct perf_evlist *evlist __maybe_unused)
1145 {
1146 struct perf_evsel *evsel, *leader;
1147
1148 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
1149
1150 /* instructions - sampling group leader */
1151 evsel = leader = perf_evlist__first(evlist);
1152 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
1153 TEST_ASSERT_VAL("wrong config",
1154 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
1155 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
1156 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
1157 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
1158 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
1159 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
1160 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
1161 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1162 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
1163 TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read);
1164
1165 /* branch-misses - not sampling */
1166 evsel = perf_evsel__next(evsel);
1167 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
1168 TEST_ASSERT_VAL("wrong config",
1169 PERF_COUNT_HW_BRANCH_MISSES == evsel->attr.config);
1170 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
1171 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
1172 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
1173 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
1174 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
1175 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
1176 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1177 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
1178 TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read);
1179
1180 return 0;
1181 }
1182
1183 static int test__checkevent_pinned_modifier(struct perf_evlist *evlist)
1184 {
1185 struct perf_evsel *evsel = perf_evlist__first(evlist);
1186
1187 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
1188 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
1189 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
1190 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
1191 TEST_ASSERT_VAL("wrong pinned", evsel->attr.pinned);
1192
1193 return test__checkevent_symbolic_name(evlist);
1194 }
1195
1196 static int test__pinned_group(struct perf_evlist *evlist)
1197 {
1198 struct perf_evsel *evsel, *leader;
1199
1200 TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->nr_entries);
1201
1202 /* cycles - group leader */
1203 evsel = leader = perf_evlist__first(evlist);
1204 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
1205 TEST_ASSERT_VAL("wrong config",
1206 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
1207 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1208 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
1209 TEST_ASSERT_VAL("wrong pinned", evsel->attr.pinned);
1210
1211 /* cache-misses - can not be pinned, but will go on with the leader */
1212 evsel = perf_evsel__next(evsel);
1213 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
1214 TEST_ASSERT_VAL("wrong config",
1215 PERF_COUNT_HW_CACHE_MISSES == evsel->attr.config);
1216 TEST_ASSERT_VAL("wrong pinned", !evsel->attr.pinned);
1217
1218 /* branch-misses - ditto */
1219 evsel = perf_evsel__next(evsel);
1220 TEST_ASSERT_VAL("wrong config",
1221 PERF_COUNT_HW_BRANCH_MISSES == evsel->attr.config);
1222 TEST_ASSERT_VAL("wrong pinned", !evsel->attr.pinned);
1223
1224 return 0;
1225 }
1226
1227 static int test__checkevent_breakpoint_len(struct perf_evlist *evlist)
1228 {
1229 struct perf_evsel *evsel = perf_evlist__first(evlist);
1230
1231 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
1232 TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->attr.type);
1233 TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
1234 TEST_ASSERT_VAL("wrong bp_type", (HW_BREAKPOINT_R | HW_BREAKPOINT_W) ==
1235 evsel->attr.bp_type);
1236 TEST_ASSERT_VAL("wrong bp_len", HW_BREAKPOINT_LEN_1 ==
1237 evsel->attr.bp_len);
1238
1239 return 0;
1240 }
1241
1242 static int test__checkevent_breakpoint_len_w(struct perf_evlist *evlist)
1243 {
1244 struct perf_evsel *evsel = perf_evlist__first(evlist);
1245
1246 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
1247 TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->attr.type);
1248 TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
1249 TEST_ASSERT_VAL("wrong bp_type", HW_BREAKPOINT_W ==
1250 evsel->attr.bp_type);
1251 TEST_ASSERT_VAL("wrong bp_len", HW_BREAKPOINT_LEN_2 ==
1252 evsel->attr.bp_len);
1253
1254 return 0;
1255 }
1256
1257 static int
1258 test__checkevent_breakpoint_len_rw_modifier(struct perf_evlist *evlist)
1259 {
1260 struct perf_evsel *evsel = perf_evlist__first(evlist);
1261
1262 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
1263 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
1264 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
1265 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
1266
1267 return test__checkevent_breakpoint_rw(evlist);
1268 }
1269
1270 static int test__checkevent_precise_max_modifier(struct perf_evlist *evlist)
1271 {
1272 struct perf_evsel *evsel = perf_evlist__first(evlist);
1273
1274 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
1275 TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->attr.type);
1276 TEST_ASSERT_VAL("wrong config",
1277 PERF_COUNT_SW_TASK_CLOCK == evsel->attr.config);
1278 return 0;
1279 }
1280
1281 static int test__checkevent_config_symbol(struct perf_evlist *evlist)
1282 {
1283 struct perf_evsel *evsel = perf_evlist__first(evlist);
1284
1285 TEST_ASSERT_VAL("wrong name setting", strcmp(evsel->name, "insn") == 0);
1286 return 0;
1287 }
1288
1289 static int test__checkevent_config_raw(struct perf_evlist *evlist)
1290 {
1291 struct perf_evsel *evsel = perf_evlist__first(evlist);
1292
1293 TEST_ASSERT_VAL("wrong name setting", strcmp(evsel->name, "rawpmu") == 0);
1294 return 0;
1295 }
1296
1297 static int test__checkevent_config_num(struct perf_evlist *evlist)
1298 {
1299 struct perf_evsel *evsel = perf_evlist__first(evlist);
1300
1301 TEST_ASSERT_VAL("wrong name setting", strcmp(evsel->name, "numpmu") == 0);
1302 return 0;
1303 }
1304
1305 static int test__checkevent_config_cache(struct perf_evlist *evlist)
1306 {
1307 struct perf_evsel *evsel = perf_evlist__first(evlist);
1308
1309 TEST_ASSERT_VAL("wrong name setting", strcmp(evsel->name, "cachepmu") == 0);
1310 return 0;
1311 }
1312
1313 static int count_tracepoints(void)
1314 {
1315 struct dirent *events_ent;
1316 DIR *events_dir;
1317 int cnt = 0;
1318
1319 events_dir = opendir(tracing_events_path);
1320
1321 TEST_ASSERT_VAL("Can't open events dir", events_dir);
1322
1323 while ((events_ent = readdir(events_dir))) {
1324 char sys_path[PATH_MAX];
1325 struct dirent *sys_ent;
1326 DIR *sys_dir;
1327
1328 if (!strcmp(events_ent->d_name, ".")
1329 || !strcmp(events_ent->d_name, "..")
1330 || !strcmp(events_ent->d_name, "enable")
1331 || !strcmp(events_ent->d_name, "header_event")
1332 || !strcmp(events_ent->d_name, "header_page"))
1333 continue;
1334
1335 scnprintf(sys_path, PATH_MAX, "%s/%s",
1336 tracing_events_path, events_ent->d_name);
1337
1338 sys_dir = opendir(sys_path);
1339 TEST_ASSERT_VAL("Can't open sys dir", sys_dir);
1340
1341 while ((sys_ent = readdir(sys_dir))) {
1342 if (!strcmp(sys_ent->d_name, ".")
1343 || !strcmp(sys_ent->d_name, "..")
1344 || !strcmp(sys_ent->d_name, "enable")
1345 || !strcmp(sys_ent->d_name, "filter"))
1346 continue;
1347
1348 cnt++;
1349 }
1350
1351 closedir(sys_dir);
1352 }
1353
1354 closedir(events_dir);
1355 return cnt;
1356 }
1357
1358 static int test__all_tracepoints(struct perf_evlist *evlist)
1359 {
1360 TEST_ASSERT_VAL("wrong events count",
1361 count_tracepoints() == evlist->nr_entries);
1362
1363 return test__checkevent_tracepoint_multi(evlist);
1364 }
1365
1366 struct evlist_test {
1367 const char *name;
1368 __u32 type;
1369 const int id;
1370 int (*check)(struct perf_evlist *evlist);
1371 };
1372
1373 static struct evlist_test test__events[] = {
1374 {
1375 .name = "syscalls:sys_enter_openat",
1376 .check = test__checkevent_tracepoint,
1377 .id = 0,
1378 },
1379 {
1380 .name = "syscalls:*",
1381 .check = test__checkevent_tracepoint_multi,
1382 .id = 1,
1383 },
1384 {
1385 .name = "r1a",
1386 .check = test__checkevent_raw,
1387 .id = 2,
1388 },
1389 {
1390 .name = "1:1",
1391 .check = test__checkevent_numeric,
1392 .id = 3,
1393 },
1394 {
1395 .name = "instructions",
1396 .check = test__checkevent_symbolic_name,
1397 .id = 4,
1398 },
1399 {
1400 .name = "cycles/period=100000,config2/",
1401 .check = test__checkevent_symbolic_name_config,
1402 .id = 5,
1403 },
1404 {
1405 .name = "faults",
1406 .check = test__checkevent_symbolic_alias,
1407 .id = 6,
1408 },
1409 {
1410 .name = "L1-dcache-load-miss",
1411 .check = test__checkevent_genhw,
1412 .id = 7,
1413 },
1414 {
1415 .name = "mem:0",
1416 .check = test__checkevent_breakpoint,
1417 .id = 8,
1418 },
1419 {
1420 .name = "mem:0:x",
1421 .check = test__checkevent_breakpoint_x,
1422 .id = 9,
1423 },
1424 {
1425 .name = "mem:0:r",
1426 .check = test__checkevent_breakpoint_r,
1427 .id = 10,
1428 },
1429 {
1430 .name = "mem:0:w",
1431 .check = test__checkevent_breakpoint_w,
1432 .id = 11,
1433 },
1434 {
1435 .name = "syscalls:sys_enter_openat:k",
1436 .check = test__checkevent_tracepoint_modifier,
1437 .id = 12,
1438 },
1439 {
1440 .name = "syscalls:*:u",
1441 .check = test__checkevent_tracepoint_multi_modifier,
1442 .id = 13,
1443 },
1444 {
1445 .name = "r1a:kp",
1446 .check = test__checkevent_raw_modifier,
1447 .id = 14,
1448 },
1449 {
1450 .name = "1:1:hp",
1451 .check = test__checkevent_numeric_modifier,
1452 .id = 15,
1453 },
1454 {
1455 .name = "instructions:h",
1456 .check = test__checkevent_symbolic_name_modifier,
1457 .id = 16,
1458 },
1459 {
1460 .name = "faults:u",
1461 .check = test__checkevent_symbolic_alias_modifier,
1462 .id = 17,
1463 },
1464 {
1465 .name = "L1-dcache-load-miss:kp",
1466 .check = test__checkevent_genhw_modifier,
1467 .id = 18,
1468 },
1469 {
1470 .name = "mem:0:u",
1471 .check = test__checkevent_breakpoint_modifier,
1472 .id = 19,
1473 },
1474 {
1475 .name = "mem:0:x:k",
1476 .check = test__checkevent_breakpoint_x_modifier,
1477 .id = 20,
1478 },
1479 {
1480 .name = "mem:0:r:hp",
1481 .check = test__checkevent_breakpoint_r_modifier,
1482 .id = 21,
1483 },
1484 {
1485 .name = "mem:0:w:up",
1486 .check = test__checkevent_breakpoint_w_modifier,
1487 .id = 22,
1488 },
1489 {
1490 .name = "r1,syscalls:sys_enter_openat:k,1:1:hp",
1491 .check = test__checkevent_list,
1492 .id = 23,
1493 },
1494 {
1495 .name = "instructions:G",
1496 .check = test__checkevent_exclude_host_modifier,
1497 .id = 24,
1498 },
1499 {
1500 .name = "instructions:H",
1501 .check = test__checkevent_exclude_guest_modifier,
1502 .id = 25,
1503 },
1504 {
1505 .name = "mem:0:rw",
1506 .check = test__checkevent_breakpoint_rw,
1507 .id = 26,
1508 },
1509 {
1510 .name = "mem:0:rw:kp",
1511 .check = test__checkevent_breakpoint_rw_modifier,
1512 .id = 27,
1513 },
1514 {
1515 .name = "{instructions:k,cycles:upp}",
1516 .check = test__group1,
1517 .id = 28,
1518 },
1519 {
1520 .name = "{faults:k,cache-references}:u,cycles:k",
1521 .check = test__group2,
1522 .id = 29,
1523 },
1524 {
1525 .name = "group1{syscalls:sys_enter_openat:H,cycles:kppp},group2{cycles,1:3}:G,instructions:u",
1526 .check = test__group3,
1527 .id = 30,
1528 },
1529 {
1530 .name = "{cycles:u,instructions:kp}:p",
1531 .check = test__group4,
1532 .id = 31,
1533 },
1534 {
1535 .name = "{cycles,instructions}:G,{cycles:G,instructions:G},cycles",
1536 .check = test__group5,
1537 .id = 32,
1538 },
1539 {
1540 .name = "*:*",
1541 .check = test__all_tracepoints,
1542 .id = 33,
1543 },
1544 {
1545 .name = "{cycles,cache-misses:G}:H",
1546 .check = test__group_gh1,
1547 .id = 34,
1548 },
1549 {
1550 .name = "{cycles,cache-misses:H}:G",
1551 .check = test__group_gh2,
1552 .id = 35,
1553 },
1554 {
1555 .name = "{cycles:G,cache-misses:H}:u",
1556 .check = test__group_gh3,
1557 .id = 36,
1558 },
1559 {
1560 .name = "{cycles:G,cache-misses:H}:uG",
1561 .check = test__group_gh4,
1562 .id = 37,
1563 },
1564 {
1565 .name = "{cycles,cache-misses,branch-misses}:S",
1566 .check = test__leader_sample1,
1567 .id = 38,
1568 },
1569 {
1570 .name = "{instructions,branch-misses}:Su",
1571 .check = test__leader_sample2,
1572 .id = 39,
1573 },
1574 {
1575 .name = "instructions:uDp",
1576 .check = test__checkevent_pinned_modifier,
1577 .id = 40,
1578 },
1579 {
1580 .name = "{cycles,cache-misses,branch-misses}:D",
1581 .check = test__pinned_group,
1582 .id = 41,
1583 },
1584 {
1585 .name = "mem:0/1",
1586 .check = test__checkevent_breakpoint_len,
1587 .id = 42,
1588 },
1589 {
1590 .name = "mem:0/2:w",
1591 .check = test__checkevent_breakpoint_len_w,
1592 .id = 43,
1593 },
1594 {
1595 .name = "mem:0/4:rw:u",
1596 .check = test__checkevent_breakpoint_len_rw_modifier,
1597 .id = 44
1598 },
1599 #if defined(__s390x__)
1600 {
1601 .name = "kvm-s390:kvm_s390_create_vm",
1602 .check = test__checkevent_tracepoint,
1603 .id = 100,
1604 },
1605 #endif
1606 {
1607 .name = "instructions:I",
1608 .check = test__checkevent_exclude_idle_modifier,
1609 .id = 45,
1610 },
1611 {
1612 .name = "instructions:kIG",
1613 .check = test__checkevent_exclude_idle_modifier_1,
1614 .id = 46,
1615 },
1616 {
1617 .name = "task-clock:P,cycles",
1618 .check = test__checkevent_precise_max_modifier,
1619 .id = 47,
1620 },
1621 {
1622 .name = "instructions/name=insn/",
1623 .check = test__checkevent_config_symbol,
1624 .id = 48,
1625 },
1626 {
1627 .name = "r1234/name=rawpmu/",
1628 .check = test__checkevent_config_raw,
1629 .id = 49,
1630 },
1631 {
1632 .name = "4:0x6530160/name=numpmu/",
1633 .check = test__checkevent_config_num,
1634 .id = 50,
1635 },
1636 {
1637 .name = "L1-dcache-misses/name=cachepmu/",
1638 .check = test__checkevent_config_cache,
1639 .id = 51,
1640 },
1641 };
1642
1643 static struct evlist_test test__events_pmu[] = {
1644 {
1645 .name = "cpu/config=10,config1,config2=3,period=1000/u",
1646 .check = test__checkevent_pmu,
1647 .id = 0,
1648 },
1649 {
1650 .name = "cpu/config=1,name=krava/u,cpu/config=2/u",
1651 .check = test__checkevent_pmu_name,
1652 .id = 1,
1653 },
1654 {
1655 .name = "cpu/config=1,call-graph=fp,time,period=100000/,cpu/config=2,call-graph=no,time=0,period=2000/",
1656 .check = test__checkevent_pmu_partial_time_callgraph,
1657 .id = 2,
1658 },
1659 };
1660
1661 struct terms_test {
1662 const char *str;
1663 __u32 type;
1664 int (*check)(struct list_head *terms);
1665 };
1666
1667 static struct terms_test test__terms[] = {
1668 [0] = {
1669 .str = "config=10,config1,config2=3,umask=1",
1670 .check = test__checkterms_simple,
1671 },
1672 };
1673
1674 static int test_event(struct evlist_test *e)
1675 {
1676 struct perf_evlist *evlist;
1677 int ret;
1678
1679 evlist = perf_evlist__new();
1680 if (evlist == NULL)
1681 return -ENOMEM;
1682
1683 ret = parse_events(evlist, e->name, NULL);
1684 if (ret) {
1685 pr_debug("failed to parse event '%s', err %d\n",
1686 e->name, ret);
1687 } else {
1688 ret = e->check(evlist);
1689 }
1690
1691 perf_evlist__delete(evlist);
1692
1693 return ret;
1694 }
1695
1696 static int test_events(struct evlist_test *events, unsigned cnt)
1697 {
1698 int ret1, ret2 = 0;
1699 unsigned i;
1700
1701 for (i = 0; i < cnt; i++) {
1702 struct evlist_test *e = &events[i];
1703
1704 pr_debug("running test %d '%s'\n", e->id, e->name);
1705 ret1 = test_event(e);
1706 if (ret1)
1707 ret2 = ret1;
1708 }
1709
1710 return ret2;
1711 }
1712
1713 static int test_term(struct terms_test *t)
1714 {
1715 struct list_head terms;
1716 int ret;
1717
1718 INIT_LIST_HEAD(&terms);
1719
1720 ret = parse_events_terms(&terms, t->str);
1721 if (ret) {
1722 pr_debug("failed to parse terms '%s', err %d\n",
1723 t->str , ret);
1724 return ret;
1725 }
1726
1727 ret = t->check(&terms);
1728 parse_events_terms__purge(&terms);
1729
1730 return ret;
1731 }
1732
1733 static int test_terms(struct terms_test *terms, unsigned cnt)
1734 {
1735 int ret = 0;
1736 unsigned i;
1737
1738 for (i = 0; i < cnt; i++) {
1739 struct terms_test *t = &terms[i];
1740
1741 pr_debug("running test %d '%s'\n", i, t->str);
1742 ret = test_term(t);
1743 if (ret)
1744 break;
1745 }
1746
1747 return ret;
1748 }
1749
1750 static int test_pmu(void)
1751 {
1752 struct stat st;
1753 char path[PATH_MAX];
1754 int ret;
1755
1756 snprintf(path, PATH_MAX, "%s/bus/event_source/devices/cpu/format/",
1757 sysfs__mountpoint());
1758
1759 ret = stat(path, &st);
1760 if (ret)
1761 pr_debug("omitting PMU cpu tests\n");
1762 return !ret;
1763 }
1764
1765 static int test_pmu_events(void)
1766 {
1767 struct stat st;
1768 char path[PATH_MAX];
1769 struct dirent *ent;
1770 DIR *dir;
1771 int ret;
1772
1773 snprintf(path, PATH_MAX, "%s/bus/event_source/devices/cpu/events/",
1774 sysfs__mountpoint());
1775
1776 ret = stat(path, &st);
1777 if (ret) {
1778 pr_debug("omitting PMU cpu events tests\n");
1779 return 0;
1780 }
1781
1782 dir = opendir(path);
1783 if (!dir) {
1784 pr_debug("can't open pmu event dir");
1785 return -1;
1786 }
1787
1788 while (!ret && (ent = readdir(dir))) {
1789 struct evlist_test e;
1790 char name[2 * NAME_MAX + 1 + 12 + 3];
1791
1792 /* Names containing . are special and cannot be used directly */
1793 if (strchr(ent->d_name, '.'))
1794 continue;
1795
1796 snprintf(name, sizeof(name), "cpu/event=%s/u", ent->d_name);
1797
1798 e.name = name;
1799 e.check = test__checkevent_pmu_events;
1800
1801 ret = test_event(&e);
1802 if (ret)
1803 break;
1804 snprintf(name, sizeof(name), "%s:u,cpu/event=%s/u", ent->d_name, ent->d_name);
1805 e.name = name;
1806 e.check = test__checkevent_pmu_events_mix;
1807 ret = test_event(&e);
1808 }
1809
1810 closedir(dir);
1811 return ret;
1812 }
1813
1814 int test__parse_events(struct test *test __maybe_unused, int subtest __maybe_unused)
1815 {
1816 int ret1, ret2 = 0;
1817
1818 #define TEST_EVENTS(tests) \
1819 do { \
1820 ret1 = test_events(tests, ARRAY_SIZE(tests)); \
1821 if (!ret2) \
1822 ret2 = ret1; \
1823 } while (0)
1824
1825 TEST_EVENTS(test__events);
1826
1827 if (test_pmu())
1828 TEST_EVENTS(test__events_pmu);
1829
1830 if (test_pmu()) {
1831 int ret = test_pmu_events();
1832 if (ret)
1833 return ret;
1834 }
1835
1836 ret1 = test_terms(test__terms, ARRAY_SIZE(test__terms));
1837 if (!ret2)
1838 ret2 = ret1;
1839
1840 return ret2;
1841 }