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