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