perf tools: allow user to specify hardware breakpoint bp_len
[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
ffe59788
KL
460
461static 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
4429392e
JO
490static int test__checkterms_simple(struct list_head *terms)
491{
6cee6cd3 492 struct parse_events_term *term;
4429392e
JO
493
494 /* config=10 */
6cee6cd3 495 term = list_entry(terms->next, struct parse_events_term, list);
4429392e
JO
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 */
6cee6cd3 504 term = list_entry(term->list.next, struct parse_events_term, list);
4429392e
JO
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 */
6cee6cd3 513 term = list_entry(term->list.next, struct parse_events_term, list);
4429392e
JO
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*/
6cee6cd3 522 term = list_entry(term->list.next, struct parse_events_term, list);
4429392e
JO
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
905f5ee2
JO
533static 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);
8d7d8474 538 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
905f5ee2
JO
539
540 /* instructions:k */
0c21f736 541 evsel = leader = perf_evlist__first(evlist);
905f5ee2
JO
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);
823254ed 551 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
8d7d8474
NK
552 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
553 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
a9f93f97 554 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
905f5ee2
JO
555
556 /* cycles:upp */
0c21f736 557 evsel = perf_evsel__next(evsel);
905f5ee2
JO
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);
42be7398
JO
564 /* use of precise requires exclude_guest */
565 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
905f5ee2
JO
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);
8d7d8474 569 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
a9f93f97 570 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
905f5ee2
JO
571
572 return 0;
573}
574
575static 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);
8d7d8474 580 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
905f5ee2
JO
581
582 /* faults + :ku modifier */
0c21f736 583 evsel = leader = perf_evlist__first(evlist);
905f5ee2
JO
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);
823254ed 593 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
8d7d8474
NK
594 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
595 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
a9f93f97 596 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
905f5ee2
JO
597
598 /* cache-references + :u modifier */
0c21f736 599 evsel = perf_evsel__next(evsel);
905f5ee2
JO
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);
5a30a99f 606 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
905f5ee2
JO
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);
8d7d8474 610 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
a9f93f97 611 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
905f5ee2
JO
612
613 /* cycles:k */
0c21f736 614 evsel = perf_evsel__next(evsel);
905f5ee2
JO
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);
823254ed 624 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
a9f93f97 625 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
905f5ee2
JO
626
627 return 0;
628}
629
1d037ca1 630static int test__group3(struct perf_evlist *evlist __maybe_unused)
905f5ee2
JO
631{
632 struct perf_evsel *evsel, *leader;
633
634 TEST_ASSERT_VAL("wrong number of entries", 5 == evlist->nr_entries);
8d7d8474 635 TEST_ASSERT_VAL("wrong number of groups", 2 == evlist->nr_groups);
905f5ee2
JO
636
637 /* group1 syscalls:sys_enter_open:H */
0c21f736 638 evsel = leader = perf_evlist__first(evlist);
905f5ee2
JO
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);
823254ed 649 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
905f5ee2
JO
650 TEST_ASSERT_VAL("wrong group name",
651 !strcmp(leader->group_name, "group1"));
8d7d8474
NK
652 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
653 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
a9f93f97 654 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
905f5ee2
JO
655
656 /* group1 cycles:kppp */
0c21f736 657 evsel = perf_evsel__next(evsel);
905f5ee2
JO
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);
42be7398
JO
664 /* use of precise requires exclude_guest */
665 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
905f5ee2
JO
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);
8d7d8474 670 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
a9f93f97 671 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
905f5ee2
JO
672
673 /* group2 cycles + G modifier */
0c21f736 674 evsel = leader = perf_evsel__next(evsel);
905f5ee2
JO
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);
823254ed 684 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
905f5ee2
JO
685 TEST_ASSERT_VAL("wrong group name",
686 !strcmp(leader->group_name, "group2"));
8d7d8474
NK
687 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
688 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
a9f93f97 689 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
905f5ee2
JO
690
691 /* group2 1:3 + G modifier */
0c21f736 692 evsel = perf_evsel__next(evsel);
905f5ee2
JO
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);
8d7d8474 702 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
a9f93f97 703 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
905f5ee2
JO
704
705 /* instructions:u */
0c21f736 706 evsel = perf_evsel__next(evsel);
905f5ee2
JO
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);
823254ed 716 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
a9f93f97 717 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
905f5ee2
JO
718
719 return 0;
720}
721
1d037ca1 722static int test__group4(struct perf_evlist *evlist __maybe_unused)
905f5ee2
JO
723{
724 struct perf_evsel *evsel, *leader;
725
726 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
8d7d8474 727 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
905f5ee2
JO
728
729 /* cycles:u + p */
0c21f736 730 evsel = leader = perf_evlist__first(evlist);
905f5ee2
JO
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);
42be7398
JO
737 /* use of precise requires exclude_guest */
738 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
905f5ee2
JO
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);
823254ed 742 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
8d7d8474
NK
743 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
744 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
a9f93f97 745 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
905f5ee2
JO
746
747 /* instructions:kp + p */
0c21f736 748 evsel = perf_evsel__next(evsel);
905f5ee2
JO
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);
42be7398
JO
755 /* use of precise requires exclude_guest */
756 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
905f5ee2
JO
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);
8d7d8474 760 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
a9f93f97 761 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
905f5ee2
JO
762
763 return 0;
764}
765
1d037ca1 766static int test__group5(struct perf_evlist *evlist __maybe_unused)
905f5ee2
JO
767{
768 struct perf_evsel *evsel, *leader;
769
770 TEST_ASSERT_VAL("wrong number of entries", 5 == evlist->nr_entries);
8d7d8474 771 TEST_ASSERT_VAL("wrong number of groups", 2 == evlist->nr_groups);
905f5ee2
JO
772
773 /* cycles + G */
0c21f736 774 evsel = leader = perf_evlist__first(evlist);
905f5ee2
JO
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);
823254ed 785 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
8d7d8474
NK
786 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
787 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
a9f93f97 788 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
905f5ee2
JO
789
790 /* instructions + G */
0c21f736 791 evsel = perf_evsel__next(evsel);
905f5ee2
JO
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);
8d7d8474 802 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
a9f93f97 803 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
905f5ee2
JO
804
805 /* cycles:G */
0c21f736 806 evsel = leader = perf_evsel__next(evsel);
905f5ee2
JO
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);
823254ed 817 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
8d7d8474
NK
818 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
819 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
a9f93f97 820 TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read);
905f5ee2
JO
821
822 /* instructions:G */
0c21f736 823 evsel = perf_evsel__next(evsel);
905f5ee2
JO
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);
8d7d8474 834 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
905f5ee2
JO
835
836 /* cycles */
0c21f736 837 evsel = perf_evsel__next(evsel);
905f5ee2
JO
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);
823254ed 847 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
905f5ee2
JO
848
849 return 0;
850}
851
5a30a99f
JO
852static 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
892static 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
932static 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
972static 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
a9f93f97
JO
1012static 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
1065static 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
c9ee780f
ME
1104static 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
1117static 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
82ce75d9
JO
1148static int count_tracepoints(void)
1149{
1150 char events_path[PATH_MAX];
1151 struct dirent *events_ent;
1152 DIR *events_dir;
1153 int cnt = 0;
1154
1155 scnprintf(events_path, PATH_MAX, "%s/tracing/events",
1156 debugfs_find_mountpoint());
1157
1158 events_dir = opendir(events_path);
1159
1160 TEST_ASSERT_VAL("Can't open events dir", events_dir);
1161
1162 while ((events_ent = readdir(events_dir))) {
1163 char sys_path[PATH_MAX];
1164 struct dirent *sys_ent;
1165 DIR *sys_dir;
1166
1167 if (!strcmp(events_ent->d_name, ".")
1168 || !strcmp(events_ent->d_name, "..")
1169 || !strcmp(events_ent->d_name, "enable")
1170 || !strcmp(events_ent->d_name, "header_event")
1171 || !strcmp(events_ent->d_name, "header_page"))
1172 continue;
1173
1174 scnprintf(sys_path, PATH_MAX, "%s/%s",
1175 events_path, events_ent->d_name);
1176
1177 sys_dir = opendir(sys_path);
1178 TEST_ASSERT_VAL("Can't open sys dir", sys_dir);
1179
1180 while ((sys_ent = readdir(sys_dir))) {
1181 if (!strcmp(sys_ent->d_name, ".")
1182 || !strcmp(sys_ent->d_name, "..")
1183 || !strcmp(sys_ent->d_name, "enable")
1184 || !strcmp(sys_ent->d_name, "filter"))
1185 continue;
1186
1187 cnt++;
1188 }
1189
1190 closedir(sys_dir);
1191 }
1192
1193 closedir(events_dir);
1194 return cnt;
1195}
1196
1197static int test__all_tracepoints(struct perf_evlist *evlist)
1198{
1199 TEST_ASSERT_VAL("wrong events count",
1200 count_tracepoints() == evlist->nr_entries);
1201
1202 return test__checkevent_tracepoint_multi(evlist);
1203}
1204
23b6339b 1205struct evlist_test {
f50246e2
JO
1206 const char *name;
1207 __u32 type;
615b8f99 1208 const int id;
f50246e2
JO
1209 int (*check)(struct perf_evlist *evlist);
1210};
1211
23b6339b 1212static struct evlist_test test__events[] = {
615b8f99 1213 {
f50246e2
JO
1214 .name = "syscalls:sys_enter_open",
1215 .check = test__checkevent_tracepoint,
615b8f99 1216 .id = 0,
f50246e2 1217 },
615b8f99 1218 {
f50246e2
JO
1219 .name = "syscalls:*",
1220 .check = test__checkevent_tracepoint_multi,
615b8f99 1221 .id = 1,
f50246e2 1222 },
615b8f99 1223 {
f50246e2
JO
1224 .name = "r1a",
1225 .check = test__checkevent_raw,
615b8f99 1226 .id = 2,
f50246e2 1227 },
615b8f99 1228 {
f50246e2
JO
1229 .name = "1:1",
1230 .check = test__checkevent_numeric,
615b8f99 1231 .id = 3,
f50246e2 1232 },
615b8f99 1233 {
f50246e2
JO
1234 .name = "instructions",
1235 .check = test__checkevent_symbolic_name,
615b8f99 1236 .id = 4,
f50246e2 1237 },
615b8f99 1238 {
f50246e2
JO
1239 .name = "cycles/period=100000,config2/",
1240 .check = test__checkevent_symbolic_name_config,
615b8f99 1241 .id = 5,
f50246e2 1242 },
615b8f99 1243 {
f50246e2
JO
1244 .name = "faults",
1245 .check = test__checkevent_symbolic_alias,
615b8f99 1246 .id = 6,
f50246e2 1247 },
615b8f99 1248 {
f50246e2
JO
1249 .name = "L1-dcache-load-miss",
1250 .check = test__checkevent_genhw,
615b8f99 1251 .id = 7,
f50246e2 1252 },
615b8f99 1253 {
f50246e2
JO
1254 .name = "mem:0",
1255 .check = test__checkevent_breakpoint,
615b8f99 1256 .id = 8,
f50246e2 1257 },
615b8f99 1258 {
f50246e2
JO
1259 .name = "mem:0:x",
1260 .check = test__checkevent_breakpoint_x,
615b8f99 1261 .id = 9,
f50246e2 1262 },
615b8f99 1263 {
f50246e2
JO
1264 .name = "mem:0:r",
1265 .check = test__checkevent_breakpoint_r,
615b8f99 1266 .id = 10,
f50246e2 1267 },
615b8f99 1268 {
f50246e2
JO
1269 .name = "mem:0:w",
1270 .check = test__checkevent_breakpoint_w,
615b8f99 1271 .id = 11,
f50246e2 1272 },
615b8f99 1273 {
f50246e2
JO
1274 .name = "syscalls:sys_enter_open:k",
1275 .check = test__checkevent_tracepoint_modifier,
615b8f99 1276 .id = 12,
f50246e2 1277 },
615b8f99 1278 {
f50246e2
JO
1279 .name = "syscalls:*:u",
1280 .check = test__checkevent_tracepoint_multi_modifier,
615b8f99 1281 .id = 13,
f50246e2 1282 },
615b8f99 1283 {
f50246e2
JO
1284 .name = "r1a:kp",
1285 .check = test__checkevent_raw_modifier,
615b8f99 1286 .id = 14,
f50246e2 1287 },
615b8f99 1288 {
f50246e2
JO
1289 .name = "1:1:hp",
1290 .check = test__checkevent_numeric_modifier,
615b8f99 1291 .id = 15,
f50246e2 1292 },
615b8f99 1293 {
f50246e2
JO
1294 .name = "instructions:h",
1295 .check = test__checkevent_symbolic_name_modifier,
615b8f99 1296 .id = 16,
f50246e2 1297 },
615b8f99 1298 {
f50246e2
JO
1299 .name = "faults:u",
1300 .check = test__checkevent_symbolic_alias_modifier,
615b8f99 1301 .id = 17,
f50246e2 1302 },
615b8f99 1303 {
f50246e2
JO
1304 .name = "L1-dcache-load-miss:kp",
1305 .check = test__checkevent_genhw_modifier,
615b8f99 1306 .id = 18,
f50246e2 1307 },
615b8f99 1308 {
f50246e2
JO
1309 .name = "mem:0:u",
1310 .check = test__checkevent_breakpoint_modifier,
615b8f99 1311 .id = 19,
f50246e2 1312 },
615b8f99 1313 {
f50246e2
JO
1314 .name = "mem:0:x:k",
1315 .check = test__checkevent_breakpoint_x_modifier,
615b8f99 1316 .id = 20,
f50246e2 1317 },
615b8f99 1318 {
f50246e2
JO
1319 .name = "mem:0:r:hp",
1320 .check = test__checkevent_breakpoint_r_modifier,
615b8f99 1321 .id = 21,
f50246e2 1322 },
615b8f99 1323 {
f50246e2
JO
1324 .name = "mem:0:w:up",
1325 .check = test__checkevent_breakpoint_w_modifier,
615b8f99 1326 .id = 22,
f50246e2 1327 },
615b8f99 1328 {
f50246e2
JO
1329 .name = "r1,syscalls:sys_enter_open:k,1:1:hp",
1330 .check = test__checkevent_list,
615b8f99 1331 .id = 23,
f50246e2 1332 },
615b8f99 1333 {
f50246e2
JO
1334 .name = "instructions:G",
1335 .check = test__checkevent_exclude_host_modifier,
615b8f99 1336 .id = 24,
f50246e2 1337 },
615b8f99 1338 {
f50246e2
JO
1339 .name = "instructions:H",
1340 .check = test__checkevent_exclude_guest_modifier,
615b8f99 1341 .id = 25,
f50246e2 1342 },
615b8f99 1343 {
7582732f
JO
1344 .name = "mem:0:rw",
1345 .check = test__checkevent_breakpoint_rw,
615b8f99 1346 .id = 26,
7582732f 1347 },
615b8f99 1348 {
7582732f
JO
1349 .name = "mem:0:rw:kp",
1350 .check = test__checkevent_breakpoint_rw_modifier,
615b8f99 1351 .id = 27,
7582732f 1352 },
615b8f99 1353 {
905f5ee2
JO
1354 .name = "{instructions:k,cycles:upp}",
1355 .check = test__group1,
615b8f99 1356 .id = 28,
905f5ee2 1357 },
615b8f99 1358 {
905f5ee2
JO
1359 .name = "{faults:k,cache-references}:u,cycles:k",
1360 .check = test__group2,
615b8f99 1361 .id = 29,
905f5ee2 1362 },
615b8f99 1363 {
905f5ee2
JO
1364 .name = "group1{syscalls:sys_enter_open:H,cycles:kppp},group2{cycles,1:3}:G,instructions:u",
1365 .check = test__group3,
615b8f99 1366 .id = 30,
905f5ee2 1367 },
615b8f99 1368 {
905f5ee2
JO
1369 .name = "{cycles:u,instructions:kp}:p",
1370 .check = test__group4,
615b8f99 1371 .id = 31,
905f5ee2 1372 },
615b8f99 1373 {
905f5ee2
JO
1374 .name = "{cycles,instructions}:G,{cycles:G,instructions:G},cycles",
1375 .check = test__group5,
615b8f99 1376 .id = 32,
905f5ee2 1377 },
615b8f99 1378 {
82ce75d9
JO
1379 .name = "*:*",
1380 .check = test__all_tracepoints,
615b8f99 1381 .id = 33,
82ce75d9 1382 },
615b8f99 1383 {
5a30a99f
JO
1384 .name = "{cycles,cache-misses:G}:H",
1385 .check = test__group_gh1,
615b8f99 1386 .id = 34,
5a30a99f 1387 },
615b8f99 1388 {
5a30a99f
JO
1389 .name = "{cycles,cache-misses:H}:G",
1390 .check = test__group_gh2,
615b8f99 1391 .id = 35,
5a30a99f 1392 },
615b8f99 1393 {
5a30a99f
JO
1394 .name = "{cycles:G,cache-misses:H}:u",
1395 .check = test__group_gh3,
615b8f99 1396 .id = 36,
5a30a99f 1397 },
615b8f99 1398 {
5a30a99f
JO
1399 .name = "{cycles:G,cache-misses:H}:uG",
1400 .check = test__group_gh4,
615b8f99 1401 .id = 37,
5a30a99f 1402 },
615b8f99 1403 {
a9f93f97
JO
1404 .name = "{cycles,cache-misses,branch-misses}:S",
1405 .check = test__leader_sample1,
615b8f99 1406 .id = 38,
a9f93f97 1407 },
615b8f99 1408 {
a9f93f97
JO
1409 .name = "{instructions,branch-misses}:Su",
1410 .check = test__leader_sample2,
615b8f99 1411 .id = 39,
a9f93f97 1412 },
615b8f99 1413 {
c9ee780f
ME
1414 .name = "instructions:uDp",
1415 .check = test__checkevent_pinned_modifier,
615b8f99 1416 .id = 40,
c9ee780f 1417 },
615b8f99 1418 {
c9ee780f
ME
1419 .name = "{cycles,cache-misses,branch-misses}:D",
1420 .check = test__pinned_group,
615b8f99 1421 .id = 41,
c9ee780f 1422 },
c0bc8c6d
AY
1423#if defined(__s390x__)
1424 {
1425 .name = "kvm-s390:kvm_s390_create_vm",
1426 .check = test__checkevent_tracepoint,
1427 .id = 100,
1428 },
1429#endif
f50246e2
JO
1430};
1431
23b6339b 1432static struct evlist_test test__events_pmu[] = {
615b8f99 1433 {
f50246e2
JO
1434 .name = "cpu/config=10,config1,config2=3,period=1000/u",
1435 .check = test__checkevent_pmu,
615b8f99 1436 .id = 0,
f50246e2 1437 },
615b8f99 1438 {
6b5fc39b
JO
1439 .name = "cpu/config=1,name=krava/u,cpu/config=2/u",
1440 .check = test__checkevent_pmu_name,
615b8f99 1441 .id = 1,
6b5fc39b 1442 },
f50246e2
JO
1443};
1444
23b6339b 1445struct terms_test {
4429392e
JO
1446 const char *str;
1447 __u32 type;
1448 int (*check)(struct list_head *terms);
1449};
1450
23b6339b 1451static struct terms_test test__terms[] = {
4429392e
JO
1452 [0] = {
1453 .str = "config=10,config1,config2=3,umask=1",
1454 .check = test__checkterms_simple,
1455 },
1456};
1457
23b6339b 1458static int test_event(struct evlist_test *e)
f50246e2
JO
1459{
1460 struct perf_evlist *evlist;
1461 int ret;
1462
334fe7a3 1463 evlist = perf_evlist__new();
f50246e2
JO
1464 if (evlist == NULL)
1465 return -ENOMEM;
1466
d8f7bbc9 1467 ret = parse_events(evlist, e->name);
f50246e2
JO
1468 if (ret) {
1469 pr_debug("failed to parse event '%s', err %d\n",
1470 e->name, ret);
2d4352c0
ACM
1471 } else {
1472 ret = e->check(evlist);
f50246e2 1473 }
2d4352c0 1474
f50246e2
JO
1475 perf_evlist__delete(evlist);
1476
1477 return ret;
1478}
1479
23b6339b 1480static int test_events(struct evlist_test *events, unsigned cnt)
f50246e2 1481{
9bfbbc6d 1482 int ret1, ret2 = 0;
f50246e2
JO
1483 unsigned i;
1484
1485 for (i = 0; i < cnt; i++) {
23b6339b 1486 struct evlist_test *e = &events[i];
f50246e2 1487
615b8f99 1488 pr_debug("running test %d '%s'\n", e->id, e->name);
9bfbbc6d
RR
1489 ret1 = test_event(e);
1490 if (ret1)
1491 ret2 = ret1;
4429392e
JO
1492 }
1493
9bfbbc6d 1494 return ret2;
4429392e
JO
1495}
1496
23b6339b 1497static int test_term(struct terms_test *t)
4429392e 1498{
c549aca5 1499 struct list_head terms;
4429392e
JO
1500 int ret;
1501
c549aca5 1502 INIT_LIST_HEAD(&terms);
4429392e 1503
c549aca5 1504 ret = parse_events_terms(&terms, t->str);
4429392e
JO
1505 if (ret) {
1506 pr_debug("failed to parse terms '%s', err %d\n",
1507 t->str , ret);
1508 return ret;
1509 }
1510
c549aca5
DA
1511 ret = t->check(&terms);
1512 parse_events__free_terms(&terms);
4429392e
JO
1513
1514 return ret;
1515}
1516
23b6339b 1517static int test_terms(struct terms_test *terms, unsigned cnt)
4429392e
JO
1518{
1519 int ret = 0;
1520 unsigned i;
1521
1522 for (i = 0; i < cnt; i++) {
23b6339b 1523 struct terms_test *t = &terms[i];
4429392e
JO
1524
1525 pr_debug("running test %d '%s'\n", i, t->str);
1526 ret = test_term(t);
f50246e2
JO
1527 if (ret)
1528 break;
1529 }
1530
1531 return ret;
1532}
1533
1534static int test_pmu(void)
1535{
1536 struct stat st;
1537 char path[PATH_MAX];
1538 int ret;
1539
1540 snprintf(path, PATH_MAX, "%s/bus/event_source/devices/cpu/format/",
cf38fada 1541 sysfs__mountpoint());
f50246e2
JO
1542
1543 ret = stat(path, &st);
1544 if (ret)
3fd44cd4 1545 pr_debug("omitting PMU cpu tests\n");
f50246e2
JO
1546 return !ret;
1547}
1548
3f3a2064
JO
1549static int test_pmu_events(void)
1550{
1551 struct stat st;
1552 char path[PATH_MAX];
1553 struct dirent *ent;
1554 DIR *dir;
1555 int ret;
1556
1557 snprintf(path, PATH_MAX, "%s/bus/event_source/devices/cpu/events/",
cf38fada 1558 sysfs__mountpoint());
3f3a2064
JO
1559
1560 ret = stat(path, &st);
1561 if (ret) {
a895d57d 1562 pr_debug("omitting PMU cpu events tests\n");
3f3a2064
JO
1563 return 0;
1564 }
1565
1566 dir = opendir(path);
1567 if (!dir) {
1568 pr_debug("can't open pmu event dir");
1569 return -1;
1570 }
1571
1572 while (!ret && (ent = readdir(dir))) {
1573#define MAX_NAME 100
23b6339b 1574 struct evlist_test e;
3f3a2064
JO
1575 char name[MAX_NAME];
1576
1577 if (!strcmp(ent->d_name, ".") ||
1578 !strcmp(ent->d_name, ".."))
1579 continue;
1580
1581 snprintf(name, MAX_NAME, "cpu/event=%s/u", ent->d_name);
1582
1583 e.name = name;
1584 e.check = test__checkevent_pmu_events;
1585
1586 ret = test_event(&e);
ffe59788
KL
1587 if (ret)
1588 break;
1589 snprintf(name, MAX_NAME, "%s:u,cpu/event=%s/u", ent->d_name, ent->d_name);
1590 e.name = name;
1591 e.check = test__checkevent_pmu_events_mix;
1592 ret = test_event(&e);
3f3a2064
JO
1593#undef MAX_NAME
1594 }
1595
1596 closedir(dir);
1597 return ret;
1598}
1599
c81251e8 1600int test__parse_events(void)
f50246e2 1601{
9bfbbc6d 1602 int ret1, ret2 = 0;
f50246e2 1603
ebf124ff
JO
1604#define TEST_EVENTS(tests) \
1605do { \
9bfbbc6d
RR
1606 ret1 = test_events(tests, ARRAY_SIZE(tests)); \
1607 if (!ret2) \
1608 ret2 = ret1; \
ebf124ff 1609} while (0)
4429392e 1610
ebf124ff 1611 TEST_EVENTS(test__events);
4429392e 1612
ebf124ff
JO
1613 if (test_pmu())
1614 TEST_EVENTS(test__events_pmu);
f50246e2 1615
3f3a2064
JO
1616 if (test_pmu()) {
1617 int ret = test_pmu_events();
1618 if (ret)
1619 return ret;
1620 }
1621
9bfbbc6d
RR
1622 ret1 = test_terms(test__terms, ARRAY_SIZE(test__terms));
1623 if (!ret2)
1624 ret2 = ret1;
1625
1626 return ret2;
f50246e2 1627}
This page took 0.189809 seconds and 5 git commands to generate.