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