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