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