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