xref: /openbmc/linux/tools/perf/tests/parse-events.c (revision 8c0b9ee8)
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 test__checkevent_breakpoint_len(struct perf_evlist *evlist)
1149 {
1150 	struct perf_evsel *evsel = perf_evlist__first(evlist);
1151 
1152 	TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
1153 	TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->attr.type);
1154 	TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
1155 	TEST_ASSERT_VAL("wrong bp_type", (HW_BREAKPOINT_R | HW_BREAKPOINT_W) ==
1156 					 evsel->attr.bp_type);
1157 	TEST_ASSERT_VAL("wrong bp_len", HW_BREAKPOINT_LEN_1 ==
1158 					evsel->attr.bp_len);
1159 
1160 	return 0;
1161 }
1162 
1163 static int test__checkevent_breakpoint_len_w(struct perf_evlist *evlist)
1164 {
1165 	struct perf_evsel *evsel = perf_evlist__first(evlist);
1166 
1167 	TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
1168 	TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->attr.type);
1169 	TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
1170 	TEST_ASSERT_VAL("wrong bp_type", HW_BREAKPOINT_W ==
1171 					 evsel->attr.bp_type);
1172 	TEST_ASSERT_VAL("wrong bp_len", HW_BREAKPOINT_LEN_2 ==
1173 					evsel->attr.bp_len);
1174 
1175 	return 0;
1176 }
1177 
1178 static int
1179 test__checkevent_breakpoint_len_rw_modifier(struct perf_evlist *evlist)
1180 {
1181 	struct perf_evsel *evsel = perf_evlist__first(evlist);
1182 
1183 	TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
1184 	TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
1185 	TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
1186 	TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
1187 
1188 	return test__checkevent_breakpoint_rw(evlist);
1189 }
1190 
1191 static int count_tracepoints(void)
1192 {
1193 	char events_path[PATH_MAX];
1194 	struct dirent *events_ent;
1195 	DIR *events_dir;
1196 	int cnt = 0;
1197 
1198 	scnprintf(events_path, PATH_MAX, "%s/tracing/events",
1199 		  debugfs_find_mountpoint());
1200 
1201 	events_dir = opendir(events_path);
1202 
1203 	TEST_ASSERT_VAL("Can't open events dir", events_dir);
1204 
1205 	while ((events_ent = readdir(events_dir))) {
1206 		char sys_path[PATH_MAX];
1207 		struct dirent *sys_ent;
1208 		DIR *sys_dir;
1209 
1210 		if (!strcmp(events_ent->d_name, ".")
1211 		    || !strcmp(events_ent->d_name, "..")
1212 		    || !strcmp(events_ent->d_name, "enable")
1213 		    || !strcmp(events_ent->d_name, "header_event")
1214 		    || !strcmp(events_ent->d_name, "header_page"))
1215 			continue;
1216 
1217 		scnprintf(sys_path, PATH_MAX, "%s/%s",
1218 			  events_path, events_ent->d_name);
1219 
1220 		sys_dir = opendir(sys_path);
1221 		TEST_ASSERT_VAL("Can't open sys dir", sys_dir);
1222 
1223 		while ((sys_ent = readdir(sys_dir))) {
1224 			if (!strcmp(sys_ent->d_name, ".")
1225 			    || !strcmp(sys_ent->d_name, "..")
1226 			    || !strcmp(sys_ent->d_name, "enable")
1227 			    || !strcmp(sys_ent->d_name, "filter"))
1228 				continue;
1229 
1230 			cnt++;
1231 		}
1232 
1233 		closedir(sys_dir);
1234 	}
1235 
1236 	closedir(events_dir);
1237 	return cnt;
1238 }
1239 
1240 static int test__all_tracepoints(struct perf_evlist *evlist)
1241 {
1242 	TEST_ASSERT_VAL("wrong events count",
1243 			count_tracepoints() == evlist->nr_entries);
1244 
1245 	return test__checkevent_tracepoint_multi(evlist);
1246 }
1247 
1248 struct evlist_test {
1249 	const char *name;
1250 	__u32 type;
1251 	const int id;
1252 	int (*check)(struct perf_evlist *evlist);
1253 };
1254 
1255 static struct evlist_test test__events[] = {
1256 	{
1257 		.name  = "syscalls:sys_enter_open",
1258 		.check = test__checkevent_tracepoint,
1259 		.id    = 0,
1260 	},
1261 	{
1262 		.name  = "syscalls:*",
1263 		.check = test__checkevent_tracepoint_multi,
1264 		.id    = 1,
1265 	},
1266 	{
1267 		.name  = "r1a",
1268 		.check = test__checkevent_raw,
1269 		.id    = 2,
1270 	},
1271 	{
1272 		.name  = "1:1",
1273 		.check = test__checkevent_numeric,
1274 		.id    = 3,
1275 	},
1276 	{
1277 		.name  = "instructions",
1278 		.check = test__checkevent_symbolic_name,
1279 		.id    = 4,
1280 	},
1281 	{
1282 		.name  = "cycles/period=100000,config2/",
1283 		.check = test__checkevent_symbolic_name_config,
1284 		.id    = 5,
1285 	},
1286 	{
1287 		.name  = "faults",
1288 		.check = test__checkevent_symbolic_alias,
1289 		.id    = 6,
1290 	},
1291 	{
1292 		.name  = "L1-dcache-load-miss",
1293 		.check = test__checkevent_genhw,
1294 		.id    = 7,
1295 	},
1296 	{
1297 		.name  = "mem:0",
1298 		.check = test__checkevent_breakpoint,
1299 		.id    = 8,
1300 	},
1301 	{
1302 		.name  = "mem:0:x",
1303 		.check = test__checkevent_breakpoint_x,
1304 		.id    = 9,
1305 	},
1306 	{
1307 		.name  = "mem:0:r",
1308 		.check = test__checkevent_breakpoint_r,
1309 		.id    = 10,
1310 	},
1311 	{
1312 		.name  = "mem:0:w",
1313 		.check = test__checkevent_breakpoint_w,
1314 		.id    = 11,
1315 	},
1316 	{
1317 		.name  = "syscalls:sys_enter_open:k",
1318 		.check = test__checkevent_tracepoint_modifier,
1319 		.id    = 12,
1320 	},
1321 	{
1322 		.name  = "syscalls:*:u",
1323 		.check = test__checkevent_tracepoint_multi_modifier,
1324 		.id    = 13,
1325 	},
1326 	{
1327 		.name  = "r1a:kp",
1328 		.check = test__checkevent_raw_modifier,
1329 		.id    = 14,
1330 	},
1331 	{
1332 		.name  = "1:1:hp",
1333 		.check = test__checkevent_numeric_modifier,
1334 		.id    = 15,
1335 	},
1336 	{
1337 		.name  = "instructions:h",
1338 		.check = test__checkevent_symbolic_name_modifier,
1339 		.id    = 16,
1340 	},
1341 	{
1342 		.name  = "faults:u",
1343 		.check = test__checkevent_symbolic_alias_modifier,
1344 		.id    = 17,
1345 	},
1346 	{
1347 		.name  = "L1-dcache-load-miss:kp",
1348 		.check = test__checkevent_genhw_modifier,
1349 		.id    = 18,
1350 	},
1351 	{
1352 		.name  = "mem:0:u",
1353 		.check = test__checkevent_breakpoint_modifier,
1354 		.id    = 19,
1355 	},
1356 	{
1357 		.name  = "mem:0:x:k",
1358 		.check = test__checkevent_breakpoint_x_modifier,
1359 		.id    = 20,
1360 	},
1361 	{
1362 		.name  = "mem:0:r:hp",
1363 		.check = test__checkevent_breakpoint_r_modifier,
1364 		.id    = 21,
1365 	},
1366 	{
1367 		.name  = "mem:0:w:up",
1368 		.check = test__checkevent_breakpoint_w_modifier,
1369 		.id    = 22,
1370 	},
1371 	{
1372 		.name  = "r1,syscalls:sys_enter_open:k,1:1:hp",
1373 		.check = test__checkevent_list,
1374 		.id    = 23,
1375 	},
1376 	{
1377 		.name  = "instructions:G",
1378 		.check = test__checkevent_exclude_host_modifier,
1379 		.id    = 24,
1380 	},
1381 	{
1382 		.name  = "instructions:H",
1383 		.check = test__checkevent_exclude_guest_modifier,
1384 		.id    = 25,
1385 	},
1386 	{
1387 		.name  = "mem:0:rw",
1388 		.check = test__checkevent_breakpoint_rw,
1389 		.id    = 26,
1390 	},
1391 	{
1392 		.name  = "mem:0:rw:kp",
1393 		.check = test__checkevent_breakpoint_rw_modifier,
1394 		.id    = 27,
1395 	},
1396 	{
1397 		.name  = "{instructions:k,cycles:upp}",
1398 		.check = test__group1,
1399 		.id    = 28,
1400 	},
1401 	{
1402 		.name  = "{faults:k,cache-references}:u,cycles:k",
1403 		.check = test__group2,
1404 		.id    = 29,
1405 	},
1406 	{
1407 		.name  = "group1{syscalls:sys_enter_open:H,cycles:kppp},group2{cycles,1:3}:G,instructions:u",
1408 		.check = test__group3,
1409 		.id    = 30,
1410 	},
1411 	{
1412 		.name  = "{cycles:u,instructions:kp}:p",
1413 		.check = test__group4,
1414 		.id    = 31,
1415 	},
1416 	{
1417 		.name  = "{cycles,instructions}:G,{cycles:G,instructions:G},cycles",
1418 		.check = test__group5,
1419 		.id    = 32,
1420 	},
1421 	{
1422 		.name  = "*:*",
1423 		.check = test__all_tracepoints,
1424 		.id    = 33,
1425 	},
1426 	{
1427 		.name  = "{cycles,cache-misses:G}:H",
1428 		.check = test__group_gh1,
1429 		.id    = 34,
1430 	},
1431 	{
1432 		.name  = "{cycles,cache-misses:H}:G",
1433 		.check = test__group_gh2,
1434 		.id    = 35,
1435 	},
1436 	{
1437 		.name  = "{cycles:G,cache-misses:H}:u",
1438 		.check = test__group_gh3,
1439 		.id    = 36,
1440 	},
1441 	{
1442 		.name  = "{cycles:G,cache-misses:H}:uG",
1443 		.check = test__group_gh4,
1444 		.id    = 37,
1445 	},
1446 	{
1447 		.name  = "{cycles,cache-misses,branch-misses}:S",
1448 		.check = test__leader_sample1,
1449 		.id    = 38,
1450 	},
1451 	{
1452 		.name  = "{instructions,branch-misses}:Su",
1453 		.check = test__leader_sample2,
1454 		.id    = 39,
1455 	},
1456 	{
1457 		.name  = "instructions:uDp",
1458 		.check = test__checkevent_pinned_modifier,
1459 		.id    = 40,
1460 	},
1461 	{
1462 		.name  = "{cycles,cache-misses,branch-misses}:D",
1463 		.check = test__pinned_group,
1464 		.id    = 41,
1465 	},
1466 	{
1467 		.name  = "mem:0/1",
1468 		.check = test__checkevent_breakpoint_len,
1469 		.id    = 42,
1470 	},
1471 	{
1472 		.name  = "mem:0/2:w",
1473 		.check = test__checkevent_breakpoint_len_w,
1474 		.id    = 43,
1475 	},
1476 	{
1477 		.name  = "mem:0/4:rw:u",
1478 		.check = test__checkevent_breakpoint_len_rw_modifier,
1479 		.id    = 44
1480 	},
1481 #if defined(__s390x__)
1482 	{
1483 		.name  = "kvm-s390:kvm_s390_create_vm",
1484 		.check = test__checkevent_tracepoint,
1485 		.id    = 100,
1486 	},
1487 #endif
1488 };
1489 
1490 static struct evlist_test test__events_pmu[] = {
1491 	{
1492 		.name  = "cpu/config=10,config1,config2=3,period=1000/u",
1493 		.check = test__checkevent_pmu,
1494 		.id    = 0,
1495 	},
1496 	{
1497 		.name  = "cpu/config=1,name=krava/u,cpu/config=2/u",
1498 		.check = test__checkevent_pmu_name,
1499 		.id    = 1,
1500 	},
1501 };
1502 
1503 struct terms_test {
1504 	const char *str;
1505 	__u32 type;
1506 	int (*check)(struct list_head *terms);
1507 };
1508 
1509 static struct terms_test test__terms[] = {
1510 	[0] = {
1511 		.str   = "config=10,config1,config2=3,umask=1",
1512 		.check = test__checkterms_simple,
1513 	},
1514 };
1515 
1516 static int test_event(struct evlist_test *e)
1517 {
1518 	struct perf_evlist *evlist;
1519 	int ret;
1520 
1521 	evlist = perf_evlist__new();
1522 	if (evlist == NULL)
1523 		return -ENOMEM;
1524 
1525 	ret = parse_events(evlist, e->name);
1526 	if (ret) {
1527 		pr_debug("failed to parse event '%s', err %d\n",
1528 			 e->name, ret);
1529 	} else {
1530 		ret = e->check(evlist);
1531 	}
1532 
1533 	perf_evlist__delete(evlist);
1534 
1535 	return ret;
1536 }
1537 
1538 static int test_events(struct evlist_test *events, unsigned cnt)
1539 {
1540 	int ret1, ret2 = 0;
1541 	unsigned i;
1542 
1543 	for (i = 0; i < cnt; i++) {
1544 		struct evlist_test *e = &events[i];
1545 
1546 		pr_debug("running test %d '%s'\n", e->id, e->name);
1547 		ret1 = test_event(e);
1548 		if (ret1)
1549 			ret2 = ret1;
1550 	}
1551 
1552 	return ret2;
1553 }
1554 
1555 static int test_term(struct terms_test *t)
1556 {
1557 	struct list_head terms;
1558 	int ret;
1559 
1560 	INIT_LIST_HEAD(&terms);
1561 
1562 	ret = parse_events_terms(&terms, t->str);
1563 	if (ret) {
1564 		pr_debug("failed to parse terms '%s', err %d\n",
1565 			 t->str , ret);
1566 		return ret;
1567 	}
1568 
1569 	ret = t->check(&terms);
1570 	parse_events__free_terms(&terms);
1571 
1572 	return ret;
1573 }
1574 
1575 static int test_terms(struct terms_test *terms, unsigned cnt)
1576 {
1577 	int ret = 0;
1578 	unsigned i;
1579 
1580 	for (i = 0; i < cnt; i++) {
1581 		struct terms_test *t = &terms[i];
1582 
1583 		pr_debug("running test %d '%s'\n", i, t->str);
1584 		ret = test_term(t);
1585 		if (ret)
1586 			break;
1587 	}
1588 
1589 	return ret;
1590 }
1591 
1592 static int test_pmu(void)
1593 {
1594 	struct stat st;
1595 	char path[PATH_MAX];
1596 	int ret;
1597 
1598 	snprintf(path, PATH_MAX, "%s/bus/event_source/devices/cpu/format/",
1599 		 sysfs__mountpoint());
1600 
1601 	ret = stat(path, &st);
1602 	if (ret)
1603 		pr_debug("omitting PMU cpu tests\n");
1604 	return !ret;
1605 }
1606 
1607 static int test_pmu_events(void)
1608 {
1609 	struct stat st;
1610 	char path[PATH_MAX];
1611 	struct dirent *ent;
1612 	DIR *dir;
1613 	int ret;
1614 
1615 	snprintf(path, PATH_MAX, "%s/bus/event_source/devices/cpu/events/",
1616 		 sysfs__mountpoint());
1617 
1618 	ret = stat(path, &st);
1619 	if (ret) {
1620 		pr_debug("omitting PMU cpu events tests\n");
1621 		return 0;
1622 	}
1623 
1624 	dir = opendir(path);
1625 	if (!dir) {
1626 		pr_debug("can't open pmu event dir");
1627 		return -1;
1628 	}
1629 
1630 	while (!ret && (ent = readdir(dir))) {
1631 #define MAX_NAME 100
1632 		struct evlist_test e;
1633 		char name[MAX_NAME];
1634 
1635 		if (!strcmp(ent->d_name, ".") ||
1636 		    !strcmp(ent->d_name, ".."))
1637 			continue;
1638 
1639 		snprintf(name, MAX_NAME, "cpu/event=%s/u", ent->d_name);
1640 
1641 		e.name  = name;
1642 		e.check = test__checkevent_pmu_events;
1643 
1644 		ret = test_event(&e);
1645 		if (ret)
1646 			break;
1647 		snprintf(name, MAX_NAME, "%s:u,cpu/event=%s/u", ent->d_name, ent->d_name);
1648 		e.name  = name;
1649 		e.check = test__checkevent_pmu_events_mix;
1650 		ret = test_event(&e);
1651 #undef MAX_NAME
1652 	}
1653 
1654 	closedir(dir);
1655 	return ret;
1656 }
1657 
1658 int test__parse_events(void)
1659 {
1660 	int ret1, ret2 = 0;
1661 
1662 #define TEST_EVENTS(tests)				\
1663 do {							\
1664 	ret1 = test_events(tests, ARRAY_SIZE(tests));	\
1665 	if (!ret2)					\
1666 		ret2 = ret1;				\
1667 } while (0)
1668 
1669 	TEST_EVENTS(test__events);
1670 
1671 	if (test_pmu())
1672 		TEST_EVENTS(test__events_pmu);
1673 
1674 	if (test_pmu()) {
1675 		int ret = test_pmu_events();
1676 		if (ret)
1677 			return ret;
1678 	}
1679 
1680 	ret1 = test_terms(test__terms, ARRAY_SIZE(test__terms));
1681 	if (!ret2)
1682 		ret2 = ret1;
1683 
1684 	return ret2;
1685 }
1686