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