Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
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 "pmu.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/tracing_path.h>
17
18#define PERF_TP_SAMPLE_TYPE (PERF_SAMPLE_RAW | PERF_SAMPLE_TIME | \
19 PERF_SAMPLE_CPU | PERF_SAMPLE_PERIOD)
20
21#if defined(__s390x__)
22/* Return true if kvm module is available and loaded. Test this
23 * and return success when trace point kvm_s390_create_vm
24 * exists. Otherwise this test always fails.
25 */
26static bool kvm_s390_create_vm_valid(void)
27{
28 char *eventfile;
29 bool rc = false;
30
31 eventfile = get_events_file("kvm-s390");
32
33 if (eventfile) {
34 DIR *mydir = opendir(eventfile);
35
36 if (mydir) {
37 rc = true;
38 closedir(mydir);
39 }
40 put_events_file(eventfile);
41 }
42
43 return rc;
44}
45#endif
46
47static int test__checkevent_tracepoint(struct evlist *evlist)
48{
49 struct evsel *evsel = evlist__first(evlist);
50
51 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
52 TEST_ASSERT_VAL("wrong number of groups", 0 == evlist->nr_groups);
53 TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->core.attr.type);
54 TEST_ASSERT_VAL("wrong sample_type",
55 PERF_TP_SAMPLE_TYPE == evsel->core.attr.sample_type);
56 TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->core.attr.sample_period);
57 return 0;
58}
59
60static int test__checkevent_tracepoint_multi(struct evlist *evlist)
61{
62 struct evsel *evsel;
63
64 TEST_ASSERT_VAL("wrong number of entries", evlist->core.nr_entries > 1);
65 TEST_ASSERT_VAL("wrong number of groups", 0 == evlist->nr_groups);
66
67 evlist__for_each_entry(evlist, evsel) {
68 TEST_ASSERT_VAL("wrong type",
69 PERF_TYPE_TRACEPOINT == evsel->core.attr.type);
70 TEST_ASSERT_VAL("wrong sample_type",
71 PERF_TP_SAMPLE_TYPE == evsel->core.attr.sample_type);
72 TEST_ASSERT_VAL("wrong sample_period",
73 1 == evsel->core.attr.sample_period);
74 }
75 return 0;
76}
77
78static int test__checkevent_raw(struct evlist *evlist)
79{
80 struct evsel *evsel = evlist__first(evlist);
81
82 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
83 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type);
84 TEST_ASSERT_VAL("wrong config", 0x1a == evsel->core.attr.config);
85 return 0;
86}
87
88static int test__checkevent_numeric(struct evlist *evlist)
89{
90 struct evsel *evsel = evlist__first(evlist);
91
92 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
93 TEST_ASSERT_VAL("wrong type", 1 == evsel->core.attr.type);
94 TEST_ASSERT_VAL("wrong config", 1 == evsel->core.attr.config);
95 return 0;
96}
97
98static int test__checkevent_symbolic_name(struct evlist *evlist)
99{
100 struct evsel *evsel = evlist__first(evlist);
101
102 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
103 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
104 TEST_ASSERT_VAL("wrong config",
105 PERF_COUNT_HW_INSTRUCTIONS == evsel->core.attr.config);
106 return 0;
107}
108
109static int test__checkevent_symbolic_name_config(struct evlist *evlist)
110{
111 struct evsel *evsel = evlist__first(evlist);
112
113 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
114 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
115 TEST_ASSERT_VAL("wrong config",
116 PERF_COUNT_HW_CPU_CYCLES == evsel->core.attr.config);
117 /*
118 * The period value gets configured within evlist__config,
119 * while this test executes only parse events method.
120 */
121 TEST_ASSERT_VAL("wrong period",
122 0 == evsel->core.attr.sample_period);
123 TEST_ASSERT_VAL("wrong config1",
124 0 == evsel->core.attr.config1);
125 TEST_ASSERT_VAL("wrong config2",
126 1 == evsel->core.attr.config2);
127 return 0;
128}
129
130static int test__checkevent_symbolic_alias(struct evlist *evlist)
131{
132 struct evsel *evsel = evlist__first(evlist);
133
134 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
135 TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->core.attr.type);
136 TEST_ASSERT_VAL("wrong config",
137 PERF_COUNT_SW_PAGE_FAULTS == evsel->core.attr.config);
138 return 0;
139}
140
141static int test__checkevent_genhw(struct evlist *evlist)
142{
143 struct evsel *evsel = evlist__first(evlist);
144
145 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
146 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HW_CACHE == evsel->core.attr.type);
147 TEST_ASSERT_VAL("wrong config", (1 << 16) == evsel->core.attr.config);
148 return 0;
149}
150
151static int test__checkevent_breakpoint(struct evlist *evlist)
152{
153 struct evsel *evsel = evlist__first(evlist);
154
155 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
156 TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->core.attr.type);
157 TEST_ASSERT_VAL("wrong config", 0 == evsel->core.attr.config);
158 TEST_ASSERT_VAL("wrong bp_type", (HW_BREAKPOINT_R | HW_BREAKPOINT_W) ==
159 evsel->core.attr.bp_type);
160 TEST_ASSERT_VAL("wrong bp_len", HW_BREAKPOINT_LEN_4 ==
161 evsel->core.attr.bp_len);
162 return 0;
163}
164
165static int test__checkevent_breakpoint_x(struct evlist *evlist)
166{
167 struct evsel *evsel = evlist__first(evlist);
168
169 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
170 TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->core.attr.type);
171 TEST_ASSERT_VAL("wrong config", 0 == evsel->core.attr.config);
172 TEST_ASSERT_VAL("wrong bp_type",
173 HW_BREAKPOINT_X == evsel->core.attr.bp_type);
174 TEST_ASSERT_VAL("wrong bp_len", sizeof(long) == evsel->core.attr.bp_len);
175 return 0;
176}
177
178static int test__checkevent_breakpoint_r(struct evlist *evlist)
179{
180 struct evsel *evsel = evlist__first(evlist);
181
182 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
183 TEST_ASSERT_VAL("wrong type",
184 PERF_TYPE_BREAKPOINT == evsel->core.attr.type);
185 TEST_ASSERT_VAL("wrong config", 0 == evsel->core.attr.config);
186 TEST_ASSERT_VAL("wrong bp_type",
187 HW_BREAKPOINT_R == evsel->core.attr.bp_type);
188 TEST_ASSERT_VAL("wrong bp_len",
189 HW_BREAKPOINT_LEN_4 == evsel->core.attr.bp_len);
190 return 0;
191}
192
193static int test__checkevent_breakpoint_w(struct evlist *evlist)
194{
195 struct evsel *evsel = evlist__first(evlist);
196
197 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
198 TEST_ASSERT_VAL("wrong type",
199 PERF_TYPE_BREAKPOINT == evsel->core.attr.type);
200 TEST_ASSERT_VAL("wrong config", 0 == evsel->core.attr.config);
201 TEST_ASSERT_VAL("wrong bp_type",
202 HW_BREAKPOINT_W == evsel->core.attr.bp_type);
203 TEST_ASSERT_VAL("wrong bp_len",
204 HW_BREAKPOINT_LEN_4 == evsel->core.attr.bp_len);
205 return 0;
206}
207
208static int test__checkevent_breakpoint_rw(struct evlist *evlist)
209{
210 struct evsel *evsel = evlist__first(evlist);
211
212 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
213 TEST_ASSERT_VAL("wrong type",
214 PERF_TYPE_BREAKPOINT == evsel->core.attr.type);
215 TEST_ASSERT_VAL("wrong config", 0 == evsel->core.attr.config);
216 TEST_ASSERT_VAL("wrong bp_type",
217 (HW_BREAKPOINT_R|HW_BREAKPOINT_W) == evsel->core.attr.bp_type);
218 TEST_ASSERT_VAL("wrong bp_len",
219 HW_BREAKPOINT_LEN_4 == evsel->core.attr.bp_len);
220 return 0;
221}
222
223static int test__checkevent_tracepoint_modifier(struct evlist *evlist)
224{
225 struct evsel *evsel = evlist__first(evlist);
226
227 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
228 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
229 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
230 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
231
232 return test__checkevent_tracepoint(evlist);
233}
234
235static int
236test__checkevent_tracepoint_multi_modifier(struct evlist *evlist)
237{
238 struct evsel *evsel;
239
240 TEST_ASSERT_VAL("wrong number of entries", evlist->core.nr_entries > 1);
241
242 evlist__for_each_entry(evlist, evsel) {
243 TEST_ASSERT_VAL("wrong exclude_user",
244 !evsel->core.attr.exclude_user);
245 TEST_ASSERT_VAL("wrong exclude_kernel",
246 evsel->core.attr.exclude_kernel);
247 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
248 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
249 }
250
251 return test__checkevent_tracepoint_multi(evlist);
252}
253
254static int test__checkevent_raw_modifier(struct evlist *evlist)
255{
256 struct evsel *evsel = evlist__first(evlist);
257
258 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
259 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
260 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
261 TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip);
262
263 return test__checkevent_raw(evlist);
264}
265
266static int test__checkevent_numeric_modifier(struct evlist *evlist)
267{
268 struct evsel *evsel = evlist__first(evlist);
269
270 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
271 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
272 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
273 TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip);
274
275 return test__checkevent_numeric(evlist);
276}
277
278static int test__checkevent_symbolic_name_modifier(struct evlist *evlist)
279{
280 struct evsel *evsel = evlist__first(evlist);
281
282 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
283 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
284 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
285 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
286
287 return test__checkevent_symbolic_name(evlist);
288}
289
290static int test__checkevent_exclude_host_modifier(struct evlist *evlist)
291{
292 struct evsel *evsel = evlist__first(evlist);
293
294 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
295 TEST_ASSERT_VAL("wrong exclude host", evsel->core.attr.exclude_host);
296
297 return test__checkevent_symbolic_name(evlist);
298}
299
300static int test__checkevent_exclude_guest_modifier(struct evlist *evlist)
301{
302 struct evsel *evsel = evlist__first(evlist);
303
304 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
305 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
306
307 return test__checkevent_symbolic_name(evlist);
308}
309
310static int test__checkevent_symbolic_alias_modifier(struct evlist *evlist)
311{
312 struct evsel *evsel = evlist__first(evlist);
313
314 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
315 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
316 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
317 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
318
319 return test__checkevent_symbolic_alias(evlist);
320}
321
322static int test__checkevent_genhw_modifier(struct evlist *evlist)
323{
324 struct evsel *evsel = evlist__first(evlist);
325
326 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
327 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
328 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
329 TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip);
330
331 return test__checkevent_genhw(evlist);
332}
333
334static int test__checkevent_exclude_idle_modifier(struct evlist *evlist)
335{
336 struct evsel *evsel = evlist__first(evlist);
337
338 TEST_ASSERT_VAL("wrong exclude idle", evsel->core.attr.exclude_idle);
339 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
340 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
341 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
342 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
343 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
344 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
345
346 return test__checkevent_symbolic_name(evlist);
347}
348
349static int test__checkevent_exclude_idle_modifier_1(struct evlist *evlist)
350{
351 struct evsel *evsel = evlist__first(evlist);
352
353 TEST_ASSERT_VAL("wrong exclude idle", evsel->core.attr.exclude_idle);
354 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
355 TEST_ASSERT_VAL("wrong exclude host", evsel->core.attr.exclude_host);
356 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
357 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
358 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
359 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
360
361 return test__checkevent_symbolic_name(evlist);
362}
363
364static int test__checkevent_breakpoint_modifier(struct evlist *evlist)
365{
366 struct evsel *evsel = evlist__first(evlist);
367
368
369 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
370 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
371 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
372 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
373 TEST_ASSERT_VAL("wrong name",
374 !strcmp(evsel__name(evsel), "mem:0:u"));
375
376 return test__checkevent_breakpoint(evlist);
377}
378
379static int test__checkevent_breakpoint_x_modifier(struct evlist *evlist)
380{
381 struct evsel *evsel = evlist__first(evlist);
382
383 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
384 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
385 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
386 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
387 TEST_ASSERT_VAL("wrong name",
388 !strcmp(evsel__name(evsel), "mem:0:x:k"));
389
390 return test__checkevent_breakpoint_x(evlist);
391}
392
393static int test__checkevent_breakpoint_r_modifier(struct evlist *evlist)
394{
395 struct evsel *evsel = evlist__first(evlist);
396
397 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
398 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
399 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
400 TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip);
401 TEST_ASSERT_VAL("wrong name",
402 !strcmp(evsel__name(evsel), "mem:0:r:hp"));
403
404 return test__checkevent_breakpoint_r(evlist);
405}
406
407static int test__checkevent_breakpoint_w_modifier(struct evlist *evlist)
408{
409 struct evsel *evsel = evlist__first(evlist);
410
411 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
412 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
413 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
414 TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip);
415 TEST_ASSERT_VAL("wrong name",
416 !strcmp(evsel__name(evsel), "mem:0:w:up"));
417
418 return test__checkevent_breakpoint_w(evlist);
419}
420
421static int test__checkevent_breakpoint_rw_modifier(struct evlist *evlist)
422{
423 struct evsel *evsel = evlist__first(evlist);
424
425 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
426 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
427 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
428 TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip);
429 TEST_ASSERT_VAL("wrong name",
430 !strcmp(evsel__name(evsel), "mem:0:rw:kp"));
431
432 return test__checkevent_breakpoint_rw(evlist);
433}
434
435static int test__checkevent_pmu(struct evlist *evlist)
436{
437
438 struct evsel *evsel = evlist__first(evlist);
439
440 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
441 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type);
442 TEST_ASSERT_VAL("wrong config", 10 == evsel->core.attr.config);
443 TEST_ASSERT_VAL("wrong config1", 1 == evsel->core.attr.config1);
444 TEST_ASSERT_VAL("wrong config2", 3 == evsel->core.attr.config2);
445 /*
446 * The period value gets configured within evlist__config,
447 * while this test executes only parse events method.
448 */
449 TEST_ASSERT_VAL("wrong period", 0 == evsel->core.attr.sample_period);
450
451 return 0;
452}
453
454static int test__checkevent_list(struct evlist *evlist)
455{
456 struct evsel *evsel = evlist__first(evlist);
457
458 TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->core.nr_entries);
459
460 /* r1 */
461 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type);
462 TEST_ASSERT_VAL("wrong config", 1 == evsel->core.attr.config);
463 TEST_ASSERT_VAL("wrong config1", 0 == evsel->core.attr.config1);
464 TEST_ASSERT_VAL("wrong config2", 0 == evsel->core.attr.config2);
465 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
466 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
467 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
468 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
469
470 /* syscalls:sys_enter_openat:k */
471 evsel = evsel__next(evsel);
472 TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->core.attr.type);
473 TEST_ASSERT_VAL("wrong sample_type",
474 PERF_TP_SAMPLE_TYPE == evsel->core.attr.sample_type);
475 TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->core.attr.sample_period);
476 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
477 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
478 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
479 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
480
481 /* 1:1:hp */
482 evsel = evsel__next(evsel);
483 TEST_ASSERT_VAL("wrong type", 1 == evsel->core.attr.type);
484 TEST_ASSERT_VAL("wrong config", 1 == evsel->core.attr.config);
485 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
486 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
487 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
488 TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip);
489
490 return 0;
491}
492
493static int test__checkevent_pmu_name(struct evlist *evlist)
494{
495 struct evsel *evsel = evlist__first(evlist);
496
497 /* cpu/config=1,name=krava/u */
498 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);
499 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type);
500 TEST_ASSERT_VAL("wrong config", 1 == evsel->core.attr.config);
501 TEST_ASSERT_VAL("wrong name", !strcmp(evsel__name(evsel), "krava"));
502
503 /* cpu/config=2/u" */
504 evsel = evsel__next(evsel);
505 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);
506 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type);
507 TEST_ASSERT_VAL("wrong config", 2 == evsel->core.attr.config);
508 TEST_ASSERT_VAL("wrong name",
509 !strcmp(evsel__name(evsel), "cpu/config=2/u"));
510
511 return 0;
512}
513
514static int test__checkevent_pmu_partial_time_callgraph(struct evlist *evlist)
515{
516 struct evsel *evsel = evlist__first(evlist);
517
518 /* cpu/config=1,call-graph=fp,time,period=100000/ */
519 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);
520 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type);
521 TEST_ASSERT_VAL("wrong config", 1 == evsel->core.attr.config);
522 /*
523 * The period, time and callgraph value gets configured within evlist__config,
524 * while this test executes only parse events method.
525 */
526 TEST_ASSERT_VAL("wrong period", 0 == evsel->core.attr.sample_period);
527 TEST_ASSERT_VAL("wrong callgraph", !evsel__has_callchain(evsel));
528 TEST_ASSERT_VAL("wrong time", !(PERF_SAMPLE_TIME & evsel->core.attr.sample_type));
529
530 /* cpu/config=2,call-graph=no,time=0,period=2000/ */
531 evsel = evsel__next(evsel);
532 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type);
533 TEST_ASSERT_VAL("wrong config", 2 == evsel->core.attr.config);
534 /*
535 * The period, time and callgraph value gets configured within evlist__config,
536 * while this test executes only parse events method.
537 */
538 TEST_ASSERT_VAL("wrong period", 0 == evsel->core.attr.sample_period);
539 TEST_ASSERT_VAL("wrong callgraph", !evsel__has_callchain(evsel));
540 TEST_ASSERT_VAL("wrong time", !(PERF_SAMPLE_TIME & evsel->core.attr.sample_type));
541
542 return 0;
543}
544
545static int test__checkevent_pmu_events(struct evlist *evlist)
546{
547 struct evsel *evsel = evlist__first(evlist);
548
549 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
550 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type);
551 TEST_ASSERT_VAL("wrong exclude_user",
552 !evsel->core.attr.exclude_user);
553 TEST_ASSERT_VAL("wrong exclude_kernel",
554 evsel->core.attr.exclude_kernel);
555 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
556 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
557 TEST_ASSERT_VAL("wrong pinned", !evsel->core.attr.pinned);
558 TEST_ASSERT_VAL("wrong exclusive", !evsel->core.attr.exclusive);
559
560 return 0;
561}
562
563
564static int test__checkevent_pmu_events_mix(struct evlist *evlist)
565{
566 struct evsel *evsel = evlist__first(evlist);
567
568 /* pmu-event:u */
569 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);
570 TEST_ASSERT_VAL("wrong exclude_user",
571 !evsel->core.attr.exclude_user);
572 TEST_ASSERT_VAL("wrong exclude_kernel",
573 evsel->core.attr.exclude_kernel);
574 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
575 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
576 TEST_ASSERT_VAL("wrong pinned", !evsel->core.attr.pinned);
577 TEST_ASSERT_VAL("wrong exclusive", !evsel->core.attr.exclusive);
578
579 /* cpu/pmu-event/u*/
580 evsel = evsel__next(evsel);
581 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);
582 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type);
583 TEST_ASSERT_VAL("wrong exclude_user",
584 !evsel->core.attr.exclude_user);
585 TEST_ASSERT_VAL("wrong exclude_kernel",
586 evsel->core.attr.exclude_kernel);
587 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
588 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
589 TEST_ASSERT_VAL("wrong pinned", !evsel->core.attr.pinned);
590 TEST_ASSERT_VAL("wrong exclusive", !evsel->core.attr.pinned);
591
592 return 0;
593}
594
595static int test__checkterms_simple(struct list_head *terms)
596{
597 struct parse_events_term *term;
598
599 /* config=10 */
600 term = list_entry(terms->next, struct parse_events_term, list);
601 TEST_ASSERT_VAL("wrong type term",
602 term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG);
603 TEST_ASSERT_VAL("wrong type val",
604 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
605 TEST_ASSERT_VAL("wrong val", term->val.num == 10);
606 TEST_ASSERT_VAL("wrong config", !term->config);
607
608 /* config1 */
609 term = list_entry(term->list.next, struct parse_events_term, list);
610 TEST_ASSERT_VAL("wrong type term",
611 term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG1);
612 TEST_ASSERT_VAL("wrong type val",
613 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
614 TEST_ASSERT_VAL("wrong val", term->val.num == 1);
615 TEST_ASSERT_VAL("wrong config", !term->config);
616
617 /* config2=3 */
618 term = list_entry(term->list.next, struct parse_events_term, list);
619 TEST_ASSERT_VAL("wrong type term",
620 term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG2);
621 TEST_ASSERT_VAL("wrong type val",
622 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
623 TEST_ASSERT_VAL("wrong val", term->val.num == 3);
624 TEST_ASSERT_VAL("wrong config", !term->config);
625
626 /* umask=1*/
627 term = list_entry(term->list.next, struct parse_events_term, list);
628 TEST_ASSERT_VAL("wrong type term",
629 term->type_term == PARSE_EVENTS__TERM_TYPE_USER);
630 TEST_ASSERT_VAL("wrong type val",
631 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
632 TEST_ASSERT_VAL("wrong val", term->val.num == 1);
633 TEST_ASSERT_VAL("wrong config", !strcmp(term->config, "umask"));
634
635 /*
636 * read
637 *
638 * The perf_pmu__test_parse_init injects 'read' term into
639 * perf_pmu_events_list, so 'read' is evaluated as read term
640 * and not as raw event with 'ead' hex value.
641 */
642 term = list_entry(term->list.next, struct parse_events_term, list);
643 TEST_ASSERT_VAL("wrong type term",
644 term->type_term == PARSE_EVENTS__TERM_TYPE_USER);
645 TEST_ASSERT_VAL("wrong type val",
646 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
647 TEST_ASSERT_VAL("wrong val", term->val.num == 1);
648 TEST_ASSERT_VAL("wrong config", !strcmp(term->config, "read"));
649
650 /*
651 * r0xead
652 *
653 * To be still able to pass 'ead' value with 'r' syntax,
654 * we added support to parse 'r0xHEX' event.
655 */
656 term = list_entry(term->list.next, struct parse_events_term, list);
657 TEST_ASSERT_VAL("wrong type term",
658 term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG);
659 TEST_ASSERT_VAL("wrong type val",
660 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
661 TEST_ASSERT_VAL("wrong val", term->val.num == 0xead);
662 TEST_ASSERT_VAL("wrong config", !term->config);
663 return 0;
664}
665
666static int test__group1(struct evlist *evlist)
667{
668 struct evsel *evsel, *leader;
669
670 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);
671 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
672
673 /* instructions:k */
674 evsel = leader = evlist__first(evlist);
675 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
676 TEST_ASSERT_VAL("wrong config",
677 PERF_COUNT_HW_INSTRUCTIONS == evsel->core.attr.config);
678 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
679 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
680 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
681 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
682 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
683 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
684 TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));
685 TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2);
686 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 0);
687 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
688
689 /* cycles:upp */
690 evsel = evsel__next(evsel);
691 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
692 TEST_ASSERT_VAL("wrong config",
693 PERF_COUNT_HW_CPU_CYCLES == evsel->core.attr.config);
694 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
695 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
696 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
697 /* use of precise requires exclude_guest */
698 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
699 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
700 TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip == 2);
701 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
702 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 1);
703 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
704
705 return 0;
706}
707
708static int test__group2(struct evlist *evlist)
709{
710 struct evsel *evsel, *leader;
711
712 TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->core.nr_entries);
713 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
714
715 /* faults + :ku modifier */
716 evsel = leader = evlist__first(evlist);
717 TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->core.attr.type);
718 TEST_ASSERT_VAL("wrong config",
719 PERF_COUNT_SW_PAGE_FAULTS == evsel->core.attr.config);
720 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
721 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
722 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
723 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
724 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
725 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
726 TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));
727 TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2);
728 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 0);
729 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
730
731 /* cache-references + :u modifier */
732 evsel = evsel__next(evsel);
733 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
734 TEST_ASSERT_VAL("wrong config",
735 PERF_COUNT_HW_CACHE_REFERENCES == evsel->core.attr.config);
736 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
737 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
738 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
739 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
740 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
741 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
742 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
743 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 1);
744 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
745
746 /* cycles:k */
747 evsel = evsel__next(evsel);
748 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
749 TEST_ASSERT_VAL("wrong config",
750 PERF_COUNT_HW_CPU_CYCLES == evsel->core.attr.config);
751 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
752 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
753 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
754 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
755 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
756 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
757 TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));
758 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
759
760 return 0;
761}
762
763static int test__group3(struct evlist *evlist __maybe_unused)
764{
765 struct evsel *evsel, *leader;
766
767 TEST_ASSERT_VAL("wrong number of entries", 5 == evlist->core.nr_entries);
768 TEST_ASSERT_VAL("wrong number of groups", 2 == evlist->nr_groups);
769
770 /* group1 syscalls:sys_enter_openat:H */
771 evsel = leader = evlist__first(evlist);
772 TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->core.attr.type);
773 TEST_ASSERT_VAL("wrong sample_type",
774 PERF_TP_SAMPLE_TYPE == evsel->core.attr.sample_type);
775 TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->core.attr.sample_period);
776 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
777 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
778 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
779 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
780 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
781 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
782 TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));
783 TEST_ASSERT_VAL("wrong group name",
784 !strcmp(leader->group_name, "group1"));
785 TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2);
786 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 0);
787 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
788
789 /* group1 cycles:kppp */
790 evsel = evsel__next(evsel);
791 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
792 TEST_ASSERT_VAL("wrong config",
793 PERF_COUNT_HW_CPU_CYCLES == evsel->core.attr.config);
794 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
795 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
796 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
797 /* use of precise requires exclude_guest */
798 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
799 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
800 TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip == 3);
801 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
802 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
803 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 1);
804 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
805
806 /* group2 cycles + G modifier */
807 evsel = leader = evsel__next(evsel);
808 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
809 TEST_ASSERT_VAL("wrong config",
810 PERF_COUNT_HW_CPU_CYCLES == evsel->core.attr.config);
811 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
812 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
813 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
814 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
815 TEST_ASSERT_VAL("wrong exclude host", evsel->core.attr.exclude_host);
816 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
817 TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));
818 TEST_ASSERT_VAL("wrong group name",
819 !strcmp(leader->group_name, "group2"));
820 TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2);
821 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 0);
822 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
823
824 /* group2 1:3 + G modifier */
825 evsel = evsel__next(evsel);
826 TEST_ASSERT_VAL("wrong type", 1 == evsel->core.attr.type);
827 TEST_ASSERT_VAL("wrong config", 3 == evsel->core.attr.config);
828 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
829 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
830 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
831 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
832 TEST_ASSERT_VAL("wrong exclude host", evsel->core.attr.exclude_host);
833 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
834 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
835 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 1);
836 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
837
838 /* instructions:u */
839 evsel = evsel__next(evsel);
840 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
841 TEST_ASSERT_VAL("wrong config",
842 PERF_COUNT_HW_INSTRUCTIONS == evsel->core.attr.config);
843 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
844 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
845 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
846 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
847 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
848 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
849 TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));
850 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
851
852 return 0;
853}
854
855static int test__group4(struct evlist *evlist __maybe_unused)
856{
857 struct evsel *evsel, *leader;
858
859 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);
860 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
861
862 /* cycles:u + p */
863 evsel = leader = evlist__first(evlist);
864 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
865 TEST_ASSERT_VAL("wrong config",
866 PERF_COUNT_HW_CPU_CYCLES == evsel->core.attr.config);
867 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
868 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
869 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
870 /* use of precise requires exclude_guest */
871 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
872 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
873 TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip == 1);
874 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
875 TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));
876 TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2);
877 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 0);
878 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
879
880 /* instructions:kp + p */
881 evsel = evsel__next(evsel);
882 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
883 TEST_ASSERT_VAL("wrong config",
884 PERF_COUNT_HW_INSTRUCTIONS == evsel->core.attr.config);
885 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
886 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
887 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
888 /* use of precise requires exclude_guest */
889 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
890 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
891 TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip == 2);
892 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
893 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 1);
894 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
895
896 return 0;
897}
898
899static int test__group5(struct evlist *evlist __maybe_unused)
900{
901 struct evsel *evsel, *leader;
902
903 TEST_ASSERT_VAL("wrong number of entries", 5 == evlist->core.nr_entries);
904 TEST_ASSERT_VAL("wrong number of groups", 2 == evlist->nr_groups);
905
906 /* cycles + G */
907 evsel = leader = evlist__first(evlist);
908 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
909 TEST_ASSERT_VAL("wrong config",
910 PERF_COUNT_HW_CPU_CYCLES == evsel->core.attr.config);
911 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
912 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
913 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
914 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
915 TEST_ASSERT_VAL("wrong exclude host", evsel->core.attr.exclude_host);
916 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
917 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
918 TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));
919 TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2);
920 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 0);
921 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
922
923 /* instructions + G */
924 evsel = evsel__next(evsel);
925 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
926 TEST_ASSERT_VAL("wrong config",
927 PERF_COUNT_HW_INSTRUCTIONS == evsel->core.attr.config);
928 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
929 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
930 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
931 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
932 TEST_ASSERT_VAL("wrong exclude host", evsel->core.attr.exclude_host);
933 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
934 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
935 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 1);
936 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
937
938 /* cycles:G */
939 evsel = leader = evsel__next(evsel);
940 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
941 TEST_ASSERT_VAL("wrong config",
942 PERF_COUNT_HW_CPU_CYCLES == evsel->core.attr.config);
943 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
944 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
945 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
946 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
947 TEST_ASSERT_VAL("wrong exclude host", evsel->core.attr.exclude_host);
948 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
949 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
950 TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));
951 TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2);
952 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 0);
953 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
954
955 /* instructions:G */
956 evsel = evsel__next(evsel);
957 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
958 TEST_ASSERT_VAL("wrong config",
959 PERF_COUNT_HW_INSTRUCTIONS == evsel->core.attr.config);
960 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
961 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
962 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
963 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
964 TEST_ASSERT_VAL("wrong exclude host", evsel->core.attr.exclude_host);
965 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
966 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
967 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 1);
968
969 /* cycles */
970 evsel = evsel__next(evsel);
971 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
972 TEST_ASSERT_VAL("wrong config",
973 PERF_COUNT_HW_CPU_CYCLES == evsel->core.attr.config);
974 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
975 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
976 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
977 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
978 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
979 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
980 TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));
981
982 return 0;
983}
984
985static int test__group_gh1(struct evlist *evlist)
986{
987 struct evsel *evsel, *leader;
988
989 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);
990 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
991
992 /* cycles + :H group modifier */
993 evsel = leader = evlist__first(evlist);
994 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
995 TEST_ASSERT_VAL("wrong config",
996 PERF_COUNT_HW_CPU_CYCLES == evsel->core.attr.config);
997 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
998 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
999 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
1000 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
1001 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
1002 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1003 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1004 TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));
1005 TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2);
1006 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 0);
1007
1008 /* cache-misses:G + :H group modifier */
1009 evsel = evsel__next(evsel);
1010 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1011 TEST_ASSERT_VAL("wrong config",
1012 PERF_COUNT_HW_CACHE_MISSES == evsel->core.attr.config);
1013 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
1014 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
1015 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
1016 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
1017 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
1018 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1019 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
1020 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 1);
1021
1022 return 0;
1023}
1024
1025static int test__group_gh2(struct evlist *evlist)
1026{
1027 struct evsel *evsel, *leader;
1028
1029 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);
1030 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
1031
1032 /* cycles + :G group modifier */
1033 evsel = leader = evlist__first(evlist);
1034 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1035 TEST_ASSERT_VAL("wrong config",
1036 PERF_COUNT_HW_CPU_CYCLES == evsel->core.attr.config);
1037 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
1038 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
1039 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
1040 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
1041 TEST_ASSERT_VAL("wrong exclude host", evsel->core.attr.exclude_host);
1042 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1043 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1044 TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));
1045 TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2);
1046 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 0);
1047
1048 /* cache-misses:H + :G group modifier */
1049 evsel = evsel__next(evsel);
1050 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1051 TEST_ASSERT_VAL("wrong config",
1052 PERF_COUNT_HW_CACHE_MISSES == evsel->core.attr.config);
1053 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
1054 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
1055 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
1056 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
1057 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
1058 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1059 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
1060 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 1);
1061
1062 return 0;
1063}
1064
1065static int test__group_gh3(struct evlist *evlist)
1066{
1067 struct evsel *evsel, *leader;
1068
1069 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);
1070 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
1071
1072 /* cycles:G + :u group modifier */
1073 evsel = leader = evlist__first(evlist);
1074 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1075 TEST_ASSERT_VAL("wrong config",
1076 PERF_COUNT_HW_CPU_CYCLES == evsel->core.attr.config);
1077 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
1078 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
1079 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
1080 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
1081 TEST_ASSERT_VAL("wrong exclude host", evsel->core.attr.exclude_host);
1082 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1083 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1084 TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));
1085 TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2);
1086 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 0);
1087
1088 /* cache-misses:H + :u group modifier */
1089 evsel = evsel__next(evsel);
1090 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1091 TEST_ASSERT_VAL("wrong config",
1092 PERF_COUNT_HW_CACHE_MISSES == evsel->core.attr.config);
1093 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
1094 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
1095 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
1096 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
1097 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
1098 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1099 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
1100 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 1);
1101
1102 return 0;
1103}
1104
1105static int test__group_gh4(struct evlist *evlist)
1106{
1107 struct evsel *evsel, *leader;
1108
1109 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);
1110 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
1111
1112 /* cycles:G + :uG group modifier */
1113 evsel = leader = evlist__first(evlist);
1114 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1115 TEST_ASSERT_VAL("wrong config",
1116 PERF_COUNT_HW_CPU_CYCLES == evsel->core.attr.config);
1117 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
1118 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
1119 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
1120 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
1121 TEST_ASSERT_VAL("wrong exclude host", evsel->core.attr.exclude_host);
1122 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1123 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1124 TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));
1125 TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2);
1126 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 0);
1127
1128 /* cache-misses:H + :uG group modifier */
1129 evsel = evsel__next(evsel);
1130 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1131 TEST_ASSERT_VAL("wrong config",
1132 PERF_COUNT_HW_CACHE_MISSES == evsel->core.attr.config);
1133 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
1134 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
1135 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
1136 TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
1137 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
1138 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1139 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
1140 TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 1);
1141
1142 return 0;
1143}
1144
1145static int test__leader_sample1(struct evlist *evlist)
1146{
1147 struct evsel *evsel, *leader;
1148
1149 TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->core.nr_entries);
1150
1151 /* cycles - sampling group leader */
1152 evsel = leader = evlist__first(evlist);
1153 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1154 TEST_ASSERT_VAL("wrong config",
1155 PERF_COUNT_HW_CPU_CYCLES == evsel->core.attr.config);
1156 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
1157 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
1158 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
1159 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
1160 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
1161 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1162 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1163 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
1164 TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read);
1165
1166 /* cache-misses - not sampling */
1167 evsel = evsel__next(evsel);
1168 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1169 TEST_ASSERT_VAL("wrong config",
1170 PERF_COUNT_HW_CACHE_MISSES == evsel->core.attr.config);
1171 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
1172 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
1173 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
1174 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
1175 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
1176 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1177 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
1178 TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read);
1179
1180 /* branch-misses - not sampling */
1181 evsel = evsel__next(evsel);
1182 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1183 TEST_ASSERT_VAL("wrong config",
1184 PERF_COUNT_HW_BRANCH_MISSES == evsel->core.attr.config);
1185 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
1186 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
1187 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv);
1188 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
1189 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
1190 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1191 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1192 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
1193 TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read);
1194
1195 return 0;
1196}
1197
1198static int test__leader_sample2(struct evlist *evlist __maybe_unused)
1199{
1200 struct evsel *evsel, *leader;
1201
1202 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);
1203
1204 /* instructions - sampling group leader */
1205 evsel = leader = evlist__first(evlist);
1206 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1207 TEST_ASSERT_VAL("wrong config",
1208 PERF_COUNT_HW_INSTRUCTIONS == evsel->core.attr.config);
1209 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
1210 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
1211 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
1212 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
1213 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
1214 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1215 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1216 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
1217 TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read);
1218
1219 /* branch-misses - not sampling */
1220 evsel = evsel__next(evsel);
1221 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1222 TEST_ASSERT_VAL("wrong config",
1223 PERF_COUNT_HW_BRANCH_MISSES == evsel->core.attr.config);
1224 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
1225 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
1226 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
1227 TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
1228 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
1229 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1230 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1231 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
1232 TEST_ASSERT_VAL("wrong sample_read", evsel->sample_read);
1233
1234 return 0;
1235}
1236
1237static int test__checkevent_pinned_modifier(struct evlist *evlist)
1238{
1239 struct evsel *evsel = evlist__first(evlist);
1240
1241 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
1242 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
1243 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
1244 TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip);
1245 TEST_ASSERT_VAL("wrong pinned", evsel->core.attr.pinned);
1246
1247 return test__checkevent_symbolic_name(evlist);
1248}
1249
1250static int test__pinned_group(struct evlist *evlist)
1251{
1252 struct evsel *evsel, *leader;
1253
1254 TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->core.nr_entries);
1255
1256 /* cycles - group leader */
1257 evsel = leader = evlist__first(evlist);
1258 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1259 TEST_ASSERT_VAL("wrong config",
1260 PERF_COUNT_HW_CPU_CYCLES == evsel->core.attr.config);
1261 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1262 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
1263 TEST_ASSERT_VAL("wrong pinned", evsel->core.attr.pinned);
1264
1265 /* cache-misses - can not be pinned, but will go on with the leader */
1266 evsel = evsel__next(evsel);
1267 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1268 TEST_ASSERT_VAL("wrong config",
1269 PERF_COUNT_HW_CACHE_MISSES == evsel->core.attr.config);
1270 TEST_ASSERT_VAL("wrong pinned", !evsel->core.attr.pinned);
1271
1272 /* branch-misses - ditto */
1273 evsel = evsel__next(evsel);
1274 TEST_ASSERT_VAL("wrong config",
1275 PERF_COUNT_HW_BRANCH_MISSES == evsel->core.attr.config);
1276 TEST_ASSERT_VAL("wrong pinned", !evsel->core.attr.pinned);
1277
1278 return 0;
1279}
1280
1281static int test__checkevent_exclusive_modifier(struct evlist *evlist)
1282{
1283 struct evsel *evsel = evlist__first(evlist);
1284
1285 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
1286 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
1287 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
1288 TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip);
1289 TEST_ASSERT_VAL("wrong exclusive", evsel->core.attr.exclusive);
1290
1291 return test__checkevent_symbolic_name(evlist);
1292}
1293
1294static int test__exclusive_group(struct evlist *evlist)
1295{
1296 struct evsel *evsel, *leader;
1297
1298 TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->core.nr_entries);
1299
1300 /* cycles - group leader */
1301 evsel = leader = evlist__first(evlist);
1302 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1303 TEST_ASSERT_VAL("wrong config",
1304 PERF_COUNT_HW_CPU_CYCLES == evsel->core.attr.config);
1305 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
1306 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
1307 TEST_ASSERT_VAL("wrong exclusive", evsel->core.attr.exclusive);
1308
1309 /* cache-misses - can not be pinned, but will go on with the leader */
1310 evsel = evsel__next(evsel);
1311 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
1312 TEST_ASSERT_VAL("wrong config",
1313 PERF_COUNT_HW_CACHE_MISSES == evsel->core.attr.config);
1314 TEST_ASSERT_VAL("wrong exclusive", !evsel->core.attr.exclusive);
1315
1316 /* branch-misses - ditto */
1317 evsel = evsel__next(evsel);
1318 TEST_ASSERT_VAL("wrong config",
1319 PERF_COUNT_HW_BRANCH_MISSES == evsel->core.attr.config);
1320 TEST_ASSERT_VAL("wrong exclusive", !evsel->core.attr.exclusive);
1321
1322 return 0;
1323}
1324static int test__checkevent_breakpoint_len(struct evlist *evlist)
1325{
1326 struct evsel *evsel = evlist__first(evlist);
1327
1328 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
1329 TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->core.attr.type);
1330 TEST_ASSERT_VAL("wrong config", 0 == evsel->core.attr.config);
1331 TEST_ASSERT_VAL("wrong bp_type", (HW_BREAKPOINT_R | HW_BREAKPOINT_W) ==
1332 evsel->core.attr.bp_type);
1333 TEST_ASSERT_VAL("wrong bp_len", HW_BREAKPOINT_LEN_1 ==
1334 evsel->core.attr.bp_len);
1335
1336 return 0;
1337}
1338
1339static int test__checkevent_breakpoint_len_w(struct evlist *evlist)
1340{
1341 struct evsel *evsel = evlist__first(evlist);
1342
1343 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
1344 TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->core.attr.type);
1345 TEST_ASSERT_VAL("wrong config", 0 == evsel->core.attr.config);
1346 TEST_ASSERT_VAL("wrong bp_type", HW_BREAKPOINT_W ==
1347 evsel->core.attr.bp_type);
1348 TEST_ASSERT_VAL("wrong bp_len", HW_BREAKPOINT_LEN_2 ==
1349 evsel->core.attr.bp_len);
1350
1351 return 0;
1352}
1353
1354static int
1355test__checkevent_breakpoint_len_rw_modifier(struct evlist *evlist)
1356{
1357 struct evsel *evsel = evlist__first(evlist);
1358
1359 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
1360 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
1361 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
1362 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
1363
1364 return test__checkevent_breakpoint_rw(evlist);
1365}
1366
1367static int test__checkevent_precise_max_modifier(struct evlist *evlist)
1368{
1369 struct evsel *evsel = evlist__first(evlist);
1370
1371 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);
1372 TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->core.attr.type);
1373 TEST_ASSERT_VAL("wrong config",
1374 PERF_COUNT_SW_TASK_CLOCK == evsel->core.attr.config);
1375 return 0;
1376}
1377
1378static int test__checkevent_config_symbol(struct evlist *evlist)
1379{
1380 struct evsel *evsel = evlist__first(evlist);
1381
1382 TEST_ASSERT_VAL("wrong name setting", strcmp(evsel->name, "insn") == 0);
1383 return 0;
1384}
1385
1386static int test__checkevent_config_raw(struct evlist *evlist)
1387{
1388 struct evsel *evsel = evlist__first(evlist);
1389
1390 TEST_ASSERT_VAL("wrong name setting", strcmp(evsel->name, "rawpmu") == 0);
1391 return 0;
1392}
1393
1394static int test__checkevent_config_num(struct evlist *evlist)
1395{
1396 struct evsel *evsel = evlist__first(evlist);
1397
1398 TEST_ASSERT_VAL("wrong name setting", strcmp(evsel->name, "numpmu") == 0);
1399 return 0;
1400}
1401
1402static int test__checkevent_config_cache(struct evlist *evlist)
1403{
1404 struct evsel *evsel = evlist__first(evlist);
1405
1406 TEST_ASSERT_VAL("wrong name setting", strcmp(evsel->name, "cachepmu") == 0);
1407 return 0;
1408}
1409
1410static bool test__intel_pt_valid(void)
1411{
1412 return !!perf_pmu__find("intel_pt");
1413}
1414
1415static int test__intel_pt(struct evlist *evlist)
1416{
1417 struct evsel *evsel = evlist__first(evlist);
1418
1419 TEST_ASSERT_VAL("wrong name setting", strcmp(evsel->name, "intel_pt//u") == 0);
1420 return 0;
1421}
1422
1423static int test__checkevent_complex_name(struct evlist *evlist)
1424{
1425 struct evsel *evsel = evlist__first(evlist);
1426
1427 TEST_ASSERT_VAL("wrong complex name parsing", strcmp(evsel->name, "COMPLEX_CYCLES_NAME:orig=cycles,desc=chip-clock-ticks") == 0);
1428 return 0;
1429}
1430
1431static int test__checkevent_raw_pmu(struct evlist *evlist)
1432{
1433 struct evsel *evsel = evlist__first(evlist);
1434
1435 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
1436 TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->core.attr.type);
1437 TEST_ASSERT_VAL("wrong config", 0x1a == evsel->core.attr.config);
1438 return 0;
1439}
1440
1441static int test__sym_event_slash(struct evlist *evlist)
1442{
1443 struct evsel *evsel = evlist__first(evlist);
1444
1445 TEST_ASSERT_VAL("wrong type", evsel->core.attr.type == PERF_TYPE_HARDWARE);
1446 TEST_ASSERT_VAL("wrong config", evsel->core.attr.config == PERF_COUNT_HW_CPU_CYCLES);
1447 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
1448 return 0;
1449}
1450
1451static int test__sym_event_dc(struct evlist *evlist)
1452{
1453 struct evsel *evsel = evlist__first(evlist);
1454
1455 TEST_ASSERT_VAL("wrong type", evsel->core.attr.type == PERF_TYPE_HARDWARE);
1456 TEST_ASSERT_VAL("wrong config", evsel->core.attr.config == PERF_COUNT_HW_CPU_CYCLES);
1457 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
1458 return 0;
1459}
1460
1461static int count_tracepoints(void)
1462{
1463 struct dirent *events_ent;
1464 DIR *events_dir;
1465 int cnt = 0;
1466
1467 events_dir = tracing_events__opendir();
1468
1469 TEST_ASSERT_VAL("Can't open events dir", events_dir);
1470
1471 while ((events_ent = readdir(events_dir))) {
1472 char *sys_path;
1473 struct dirent *sys_ent;
1474 DIR *sys_dir;
1475
1476 if (!strcmp(events_ent->d_name, ".")
1477 || !strcmp(events_ent->d_name, "..")
1478 || !strcmp(events_ent->d_name, "enable")
1479 || !strcmp(events_ent->d_name, "header_event")
1480 || !strcmp(events_ent->d_name, "header_page"))
1481 continue;
1482
1483 sys_path = get_events_file(events_ent->d_name);
1484 TEST_ASSERT_VAL("Can't get sys path", sys_path);
1485
1486 sys_dir = opendir(sys_path);
1487 TEST_ASSERT_VAL("Can't open sys dir", sys_dir);
1488
1489 while ((sys_ent = readdir(sys_dir))) {
1490 if (!strcmp(sys_ent->d_name, ".")
1491 || !strcmp(sys_ent->d_name, "..")
1492 || !strcmp(sys_ent->d_name, "enable")
1493 || !strcmp(sys_ent->d_name, "filter"))
1494 continue;
1495
1496 cnt++;
1497 }
1498
1499 closedir(sys_dir);
1500 put_events_file(sys_path);
1501 }
1502
1503 closedir(events_dir);
1504 return cnt;
1505}
1506
1507static int test__all_tracepoints(struct evlist *evlist)
1508{
1509 TEST_ASSERT_VAL("wrong events count",
1510 count_tracepoints() == evlist->core.nr_entries);
1511
1512 return test__checkevent_tracepoint_multi(evlist);
1513}
1514
1515static int test__hybrid_hw_event_with_pmu(struct evlist *evlist)
1516{
1517 struct evsel *evsel = evlist__first(evlist);
1518
1519 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
1520 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type);
1521 TEST_ASSERT_VAL("wrong config", 0x3c == evsel->core.attr.config);
1522 return 0;
1523}
1524
1525static int test__hybrid_hw_group_event(struct evlist *evlist)
1526{
1527 struct evsel *evsel, *leader;
1528
1529 evsel = leader = evlist__first(evlist);
1530 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);
1531 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type);
1532 TEST_ASSERT_VAL("wrong config", 0x3c == evsel->core.attr.config);
1533 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
1534
1535 evsel = evsel__next(evsel);
1536 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type);
1537 TEST_ASSERT_VAL("wrong config", 0xc0 == evsel->core.attr.config);
1538 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
1539 return 0;
1540}
1541
1542static int test__hybrid_sw_hw_group_event(struct evlist *evlist)
1543{
1544 struct evsel *evsel, *leader;
1545
1546 evsel = leader = evlist__first(evlist);
1547 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);
1548 TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->core.attr.type);
1549 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
1550
1551 evsel = evsel__next(evsel);
1552 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type);
1553 TEST_ASSERT_VAL("wrong config", 0x3c == evsel->core.attr.config);
1554 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
1555 return 0;
1556}
1557
1558static int test__hybrid_hw_sw_group_event(struct evlist *evlist)
1559{
1560 struct evsel *evsel, *leader;
1561
1562 evsel = leader = evlist__first(evlist);
1563 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);
1564 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type);
1565 TEST_ASSERT_VAL("wrong config", 0x3c == evsel->core.attr.config);
1566 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
1567
1568 evsel = evsel__next(evsel);
1569 TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->core.attr.type);
1570 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
1571 return 0;
1572}
1573
1574static int test__hybrid_group_modifier1(struct evlist *evlist)
1575{
1576 struct evsel *evsel, *leader;
1577
1578 evsel = leader = evlist__first(evlist);
1579 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);
1580 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type);
1581 TEST_ASSERT_VAL("wrong config", 0x3c == evsel->core.attr.config);
1582 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
1583 TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
1584 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
1585
1586 evsel = evsel__next(evsel);
1587 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type);
1588 TEST_ASSERT_VAL("wrong config", 0xc0 == evsel->core.attr.config);
1589 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
1590 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
1591 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
1592 return 0;
1593}
1594
1595static int test__hybrid_raw1(struct evlist *evlist)
1596{
1597 struct evsel *evsel = evlist__first(evlist);
1598
1599 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);
1600 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type);
1601 TEST_ASSERT_VAL("wrong config", 0x1a == evsel->core.attr.config);
1602
1603 /* The type of second event is randome value */
1604 evsel = evsel__next(evsel);
1605 TEST_ASSERT_VAL("wrong config", 0x1a == evsel->core.attr.config);
1606 return 0;
1607}
1608
1609static int test__hybrid_raw2(struct evlist *evlist)
1610{
1611 struct evsel *evsel = evlist__first(evlist);
1612
1613 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
1614 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type);
1615 TEST_ASSERT_VAL("wrong config", 0x1a == evsel->core.attr.config);
1616 return 0;
1617}
1618
1619static int test__hybrid_cache_event(struct evlist *evlist)
1620{
1621 struct evsel *evsel = evlist__first(evlist);
1622
1623 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);
1624 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HW_CACHE == evsel->core.attr.type);
1625 TEST_ASSERT_VAL("wrong config", 0x2 == (evsel->core.attr.config & 0xffffffff));
1626
1627 evsel = evsel__next(evsel);
1628 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HW_CACHE == evsel->core.attr.type);
1629 TEST_ASSERT_VAL("wrong config", 0x10002 == (evsel->core.attr.config & 0xffffffff));
1630 return 0;
1631}
1632
1633struct evlist_test {
1634 const char *name;
1635 __u32 type;
1636 const int id;
1637 bool (*valid)(void);
1638 int (*check)(struct evlist *evlist);
1639};
1640
1641static struct evlist_test test__events[] = {
1642 {
1643 .name = "syscalls:sys_enter_openat",
1644 .check = test__checkevent_tracepoint,
1645 .id = 0,
1646 },
1647 {
1648 .name = "syscalls:*",
1649 .check = test__checkevent_tracepoint_multi,
1650 .id = 1,
1651 },
1652 {
1653 .name = "r1a",
1654 .check = test__checkevent_raw,
1655 .id = 2,
1656 },
1657 {
1658 .name = "1:1",
1659 .check = test__checkevent_numeric,
1660 .id = 3,
1661 },
1662 {
1663 .name = "instructions",
1664 .check = test__checkevent_symbolic_name,
1665 .id = 4,
1666 },
1667 {
1668 .name = "cycles/period=100000,config2/",
1669 .check = test__checkevent_symbolic_name_config,
1670 .id = 5,
1671 },
1672 {
1673 .name = "faults",
1674 .check = test__checkevent_symbolic_alias,
1675 .id = 6,
1676 },
1677 {
1678 .name = "L1-dcache-load-miss",
1679 .check = test__checkevent_genhw,
1680 .id = 7,
1681 },
1682 {
1683 .name = "mem:0",
1684 .check = test__checkevent_breakpoint,
1685 .id = 8,
1686 },
1687 {
1688 .name = "mem:0:x",
1689 .check = test__checkevent_breakpoint_x,
1690 .id = 9,
1691 },
1692 {
1693 .name = "mem:0:r",
1694 .check = test__checkevent_breakpoint_r,
1695 .id = 10,
1696 },
1697 {
1698 .name = "mem:0:w",
1699 .check = test__checkevent_breakpoint_w,
1700 .id = 11,
1701 },
1702 {
1703 .name = "syscalls:sys_enter_openat:k",
1704 .check = test__checkevent_tracepoint_modifier,
1705 .id = 12,
1706 },
1707 {
1708 .name = "syscalls:*:u",
1709 .check = test__checkevent_tracepoint_multi_modifier,
1710 .id = 13,
1711 },
1712 {
1713 .name = "r1a:kp",
1714 .check = test__checkevent_raw_modifier,
1715 .id = 14,
1716 },
1717 {
1718 .name = "1:1:hp",
1719 .check = test__checkevent_numeric_modifier,
1720 .id = 15,
1721 },
1722 {
1723 .name = "instructions:h",
1724 .check = test__checkevent_symbolic_name_modifier,
1725 .id = 16,
1726 },
1727 {
1728 .name = "faults:u",
1729 .check = test__checkevent_symbolic_alias_modifier,
1730 .id = 17,
1731 },
1732 {
1733 .name = "L1-dcache-load-miss:kp",
1734 .check = test__checkevent_genhw_modifier,
1735 .id = 18,
1736 },
1737 {
1738 .name = "mem:0:u",
1739 .check = test__checkevent_breakpoint_modifier,
1740 .id = 19,
1741 },
1742 {
1743 .name = "mem:0:x:k",
1744 .check = test__checkevent_breakpoint_x_modifier,
1745 .id = 20,
1746 },
1747 {
1748 .name = "mem:0:r:hp",
1749 .check = test__checkevent_breakpoint_r_modifier,
1750 .id = 21,
1751 },
1752 {
1753 .name = "mem:0:w:up",
1754 .check = test__checkevent_breakpoint_w_modifier,
1755 .id = 22,
1756 },
1757 {
1758 .name = "r1,syscalls:sys_enter_openat:k,1:1:hp",
1759 .check = test__checkevent_list,
1760 .id = 23,
1761 },
1762 {
1763 .name = "instructions:G",
1764 .check = test__checkevent_exclude_host_modifier,
1765 .id = 24,
1766 },
1767 {
1768 .name = "instructions:H",
1769 .check = test__checkevent_exclude_guest_modifier,
1770 .id = 25,
1771 },
1772 {
1773 .name = "mem:0:rw",
1774 .check = test__checkevent_breakpoint_rw,
1775 .id = 26,
1776 },
1777 {
1778 .name = "mem:0:rw:kp",
1779 .check = test__checkevent_breakpoint_rw_modifier,
1780 .id = 27,
1781 },
1782 {
1783 .name = "{instructions:k,cycles:upp}",
1784 .check = test__group1,
1785 .id = 28,
1786 },
1787 {
1788 .name = "{faults:k,cache-references}:u,cycles:k",
1789 .check = test__group2,
1790 .id = 29,
1791 },
1792 {
1793 .name = "group1{syscalls:sys_enter_openat:H,cycles:kppp},group2{cycles,1:3}:G,instructions:u",
1794 .check = test__group3,
1795 .id = 30,
1796 },
1797 {
1798 .name = "{cycles:u,instructions:kp}:p",
1799 .check = test__group4,
1800 .id = 31,
1801 },
1802 {
1803 .name = "{cycles,instructions}:G,{cycles:G,instructions:G},cycles",
1804 .check = test__group5,
1805 .id = 32,
1806 },
1807 {
1808 .name = "*:*",
1809 .check = test__all_tracepoints,
1810 .id = 33,
1811 },
1812 {
1813 .name = "{cycles,cache-misses:G}:H",
1814 .check = test__group_gh1,
1815 .id = 34,
1816 },
1817 {
1818 .name = "{cycles,cache-misses:H}:G",
1819 .check = test__group_gh2,
1820 .id = 35,
1821 },
1822 {
1823 .name = "{cycles:G,cache-misses:H}:u",
1824 .check = test__group_gh3,
1825 .id = 36,
1826 },
1827 {
1828 .name = "{cycles:G,cache-misses:H}:uG",
1829 .check = test__group_gh4,
1830 .id = 37,
1831 },
1832 {
1833 .name = "{cycles,cache-misses,branch-misses}:S",
1834 .check = test__leader_sample1,
1835 .id = 38,
1836 },
1837 {
1838 .name = "{instructions,branch-misses}:Su",
1839 .check = test__leader_sample2,
1840 .id = 39,
1841 },
1842 {
1843 .name = "instructions:uDp",
1844 .check = test__checkevent_pinned_modifier,
1845 .id = 40,
1846 },
1847 {
1848 .name = "{cycles,cache-misses,branch-misses}:D",
1849 .check = test__pinned_group,
1850 .id = 41,
1851 },
1852 {
1853 .name = "mem:0/1",
1854 .check = test__checkevent_breakpoint_len,
1855 .id = 42,
1856 },
1857 {
1858 .name = "mem:0/2:w",
1859 .check = test__checkevent_breakpoint_len_w,
1860 .id = 43,
1861 },
1862 {
1863 .name = "mem:0/4:rw:u",
1864 .check = test__checkevent_breakpoint_len_rw_modifier,
1865 .id = 44
1866 },
1867#if defined(__s390x__)
1868 {
1869 .name = "kvm-s390:kvm_s390_create_vm",
1870 .check = test__checkevent_tracepoint,
1871 .valid = kvm_s390_create_vm_valid,
1872 .id = 100,
1873 },
1874#endif
1875 {
1876 .name = "instructions:I",
1877 .check = test__checkevent_exclude_idle_modifier,
1878 .id = 45,
1879 },
1880 {
1881 .name = "instructions:kIG",
1882 .check = test__checkevent_exclude_idle_modifier_1,
1883 .id = 46,
1884 },
1885 {
1886 .name = "task-clock:P,cycles",
1887 .check = test__checkevent_precise_max_modifier,
1888 .id = 47,
1889 },
1890 {
1891 .name = "instructions/name=insn/",
1892 .check = test__checkevent_config_symbol,
1893 .id = 48,
1894 },
1895 {
1896 .name = "r1234/name=rawpmu/",
1897 .check = test__checkevent_config_raw,
1898 .id = 49,
1899 },
1900 {
1901 .name = "4:0x6530160/name=numpmu/",
1902 .check = test__checkevent_config_num,
1903 .id = 50,
1904 },
1905 {
1906 .name = "L1-dcache-misses/name=cachepmu/",
1907 .check = test__checkevent_config_cache,
1908 .id = 51,
1909 },
1910 {
1911 .name = "intel_pt//u",
1912 .valid = test__intel_pt_valid,
1913 .check = test__intel_pt,
1914 .id = 52,
1915 },
1916 {
1917 .name = "cycles/name='COMPLEX_CYCLES_NAME:orig=cycles,desc=chip-clock-ticks'/Duk",
1918 .check = test__checkevent_complex_name,
1919 .id = 53
1920 },
1921 {
1922 .name = "cycles//u",
1923 .check = test__sym_event_slash,
1924 .id = 54,
1925 },
1926 {
1927 .name = "cycles:k",
1928 .check = test__sym_event_dc,
1929 .id = 55,
1930 },
1931 {
1932 .name = "instructions:uep",
1933 .check = test__checkevent_exclusive_modifier,
1934 .id = 56,
1935 },
1936 {
1937 .name = "{cycles,cache-misses,branch-misses}:e",
1938 .check = test__exclusive_group,
1939 .id = 57,
1940 },
1941};
1942
1943static struct evlist_test test__events_pmu[] = {
1944 {
1945 .name = "cpu/config=10,config1,config2=3,period=1000/u",
1946 .check = test__checkevent_pmu,
1947 .id = 0,
1948 },
1949 {
1950 .name = "cpu/config=1,name=krava/u,cpu/config=2/u",
1951 .check = test__checkevent_pmu_name,
1952 .id = 1,
1953 },
1954 {
1955 .name = "cpu/config=1,call-graph=fp,time,period=100000/,cpu/config=2,call-graph=no,time=0,period=2000/",
1956 .check = test__checkevent_pmu_partial_time_callgraph,
1957 .id = 2,
1958 },
1959 {
1960 .name = "cpu/name='COMPLEX_CYCLES_NAME:orig=cycles,desc=chip-clock-ticks',period=0x1,event=0x2/ukp",
1961 .check = test__checkevent_complex_name,
1962 .id = 3,
1963 },
1964 {
1965 .name = "software/r1a/",
1966 .check = test__checkevent_raw_pmu,
1967 .id = 4,
1968 },
1969 {
1970 .name = "software/r0x1a/",
1971 .check = test__checkevent_raw_pmu,
1972 .id = 4,
1973 },
1974};
1975
1976struct terms_test {
1977 const char *str;
1978 __u32 type;
1979 int (*check)(struct list_head *terms);
1980};
1981
1982static struct terms_test test__terms[] = {
1983 [0] = {
1984 .str = "config=10,config1,config2=3,umask=1,read,r0xead",
1985 .check = test__checkterms_simple,
1986 },
1987};
1988
1989static struct evlist_test test__hybrid_events[] = {
1990 {
1991 .name = "cpu_core/cpu-cycles/",
1992 .check = test__hybrid_hw_event_with_pmu,
1993 .id = 0,
1994 },
1995 {
1996 .name = "{cpu_core/cpu-cycles/,cpu_core/instructions/}",
1997 .check = test__hybrid_hw_group_event,
1998 .id = 1,
1999 },
2000 {
2001 .name = "{cpu-clock,cpu_core/cpu-cycles/}",
2002 .check = test__hybrid_sw_hw_group_event,
2003 .id = 2,
2004 },
2005 {
2006 .name = "{cpu_core/cpu-cycles/,cpu-clock}",
2007 .check = test__hybrid_hw_sw_group_event,
2008 .id = 3,
2009 },
2010 {
2011 .name = "{cpu_core/cpu-cycles/k,cpu_core/instructions/u}",
2012 .check = test__hybrid_group_modifier1,
2013 .id = 4,
2014 },
2015 {
2016 .name = "r1a",
2017 .check = test__hybrid_raw1,
2018 .id = 5,
2019 },
2020 {
2021 .name = "cpu_core/r1a/",
2022 .check = test__hybrid_raw2,
2023 .id = 6,
2024 },
2025 {
2026 .name = "cpu_core/config=10,config1,config2=3,period=1000/u",
2027 .check = test__checkevent_pmu,
2028 .id = 7,
2029 },
2030 {
2031 .name = "cpu_core/LLC-loads/,cpu_atom/LLC-load-misses/",
2032 .check = test__hybrid_cache_event,
2033 .id = 8,
2034 },
2035};
2036
2037static int test_event(struct evlist_test *e)
2038{
2039 struct parse_events_error err;
2040 struct evlist *evlist;
2041 int ret;
2042
2043 bzero(&err, sizeof(err));
2044 if (e->valid && !e->valid()) {
2045 pr_debug("... SKIP");
2046 return 0;
2047 }
2048
2049 evlist = evlist__new();
2050 if (evlist == NULL)
2051 return -ENOMEM;
2052
2053 ret = parse_events(evlist, e->name, &err);
2054 if (ret) {
2055 pr_debug("failed to parse event '%s', err %d, str '%s'\n",
2056 e->name, ret, err.str);
2057 parse_events_print_error(&err, e->name);
2058 } else {
2059 ret = e->check(evlist);
2060 }
2061
2062 evlist__delete(evlist);
2063
2064 return ret;
2065}
2066
2067static int test_events(struct evlist_test *events, unsigned cnt)
2068{
2069 int ret1, ret2 = 0;
2070 unsigned i;
2071
2072 for (i = 0; i < cnt; i++) {
2073 struct evlist_test *e = &events[i];
2074
2075 pr_debug("running test %d '%s'", e->id, e->name);
2076 ret1 = test_event(e);
2077 if (ret1)
2078 ret2 = ret1;
2079 pr_debug("\n");
2080 }
2081
2082 return ret2;
2083}
2084
2085static int test_term(struct terms_test *t)
2086{
2087 struct list_head terms;
2088 int ret;
2089
2090 INIT_LIST_HEAD(&terms);
2091
2092 /*
2093 * The perf_pmu__test_parse_init prepares perf_pmu_events_list
2094 * which gets freed in parse_events_terms.
2095 */
2096 if (perf_pmu__test_parse_init())
2097 return -1;
2098
2099 ret = parse_events_terms(&terms, t->str);
2100 if (ret) {
2101 pr_debug("failed to parse terms '%s', err %d\n",
2102 t->str , ret);
2103 return ret;
2104 }
2105
2106 ret = t->check(&terms);
2107 parse_events_terms__purge(&terms);
2108
2109 return ret;
2110}
2111
2112static int test_terms(struct terms_test *terms, unsigned cnt)
2113{
2114 int ret = 0;
2115 unsigned i;
2116
2117 for (i = 0; i < cnt; i++) {
2118 struct terms_test *t = &terms[i];
2119
2120 pr_debug("running test %d '%s'\n", i, t->str);
2121 ret = test_term(t);
2122 if (ret)
2123 break;
2124 }
2125
2126 return ret;
2127}
2128
2129static int test_pmu(void)
2130{
2131 struct stat st;
2132 char path[PATH_MAX];
2133 int ret;
2134
2135 snprintf(path, PATH_MAX, "%s/bus/event_source/devices/cpu/format/",
2136 sysfs__mountpoint());
2137
2138 ret = stat(path, &st);
2139 if (ret)
2140 pr_debug("omitting PMU cpu tests\n");
2141 return !ret;
2142}
2143
2144static int test_pmu_events(void)
2145{
2146 struct stat st;
2147 char path[PATH_MAX];
2148 struct dirent *ent;
2149 DIR *dir;
2150 int ret;
2151
2152 snprintf(path, PATH_MAX, "%s/bus/event_source/devices/cpu/events/",
2153 sysfs__mountpoint());
2154
2155 ret = stat(path, &st);
2156 if (ret) {
2157 pr_debug("omitting PMU cpu events tests\n");
2158 return 0;
2159 }
2160
2161 dir = opendir(path);
2162 if (!dir) {
2163 pr_debug("can't open pmu event dir");
2164 return -1;
2165 }
2166
2167 while (!ret && (ent = readdir(dir))) {
2168 struct evlist_test e = { .id = 0, };
2169 char name[2 * NAME_MAX + 1 + 12 + 3];
2170
2171 /* Names containing . are special and cannot be used directly */
2172 if (strchr(ent->d_name, '.'))
2173 continue;
2174
2175 snprintf(name, sizeof(name), "cpu/event=%s/u", ent->d_name);
2176
2177 e.name = name;
2178 e.check = test__checkevent_pmu_events;
2179
2180 ret = test_event(&e);
2181 if (ret)
2182 break;
2183 snprintf(name, sizeof(name), "%s:u,cpu/event=%s/u", ent->d_name, ent->d_name);
2184 e.name = name;
2185 e.check = test__checkevent_pmu_events_mix;
2186 ret = test_event(&e);
2187 }
2188
2189 closedir(dir);
2190 return ret;
2191}
2192
2193int test__parse_events(struct test *test __maybe_unused, int subtest __maybe_unused)
2194{
2195 int ret1, ret2 = 0;
2196
2197#define TEST_EVENTS(tests) \
2198do { \
2199 ret1 = test_events(tests, ARRAY_SIZE(tests)); \
2200 if (!ret2) \
2201 ret2 = ret1; \
2202} while (0)
2203
2204 if (perf_pmu__has_hybrid()) {
2205 TEST_EVENTS(test__hybrid_events);
2206 return ret2;
2207 }
2208
2209 TEST_EVENTS(test__events);
2210
2211 if (test_pmu())
2212 TEST_EVENTS(test__events_pmu);
2213
2214 if (test_pmu()) {
2215 int ret = test_pmu_events();
2216 if (ret)
2217 return ret;
2218 }
2219
2220 ret1 = test_terms(test__terms, ARRAY_SIZE(test__terms));
2221 if (!ret2)
2222 ret2 = ret1;
2223
2224 return ret2;
2225}