perf tools: Don't free list head in parse_events__free_terms
[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"
5#include "sysfs.h"
85c66be1 6#include <lk/debugfs.h>
c81251e8 7#include "tests.h"
d2709c7c 8#include <linux/hw_breakpoint.h>
f50246e2 9
30f31c0a
JO
10#define PERF_TP_SAMPLE_TYPE (PERF_SAMPLE_RAW | PERF_SAMPLE_TIME | \
11 PERF_SAMPLE_CPU | PERF_SAMPLE_PERIOD)
12
f50246e2
JO
13static int test__checkevent_tracepoint(struct perf_evlist *evlist)
14{
0c21f736 15 struct perf_evsel *evsel = perf_evlist__first(evlist);
f50246e2
JO
16
17 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
8d7d8474 18 TEST_ASSERT_VAL("wrong number of groups", 0 == evlist->nr_groups);
f50246e2
JO
19 TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->attr.type);
20 TEST_ASSERT_VAL("wrong sample_type",
30f31c0a 21 PERF_TP_SAMPLE_TYPE == evsel->attr.sample_type);
f50246e2
JO
22 TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->attr.sample_period);
23 return 0;
24}
25
26static int test__checkevent_tracepoint_multi(struct perf_evlist *evlist)
27{
28 struct perf_evsel *evsel;
29
30 TEST_ASSERT_VAL("wrong number of entries", evlist->nr_entries > 1);
8d7d8474 31 TEST_ASSERT_VAL("wrong number of groups", 0 == evlist->nr_groups);
f50246e2
JO
32
33 list_for_each_entry(evsel, &evlist->entries, node) {
34 TEST_ASSERT_VAL("wrong type",
35 PERF_TYPE_TRACEPOINT == evsel->attr.type);
36 TEST_ASSERT_VAL("wrong sample_type",
30f31c0a 37 PERF_TP_SAMPLE_TYPE == evsel->attr.sample_type);
f50246e2
JO
38 TEST_ASSERT_VAL("wrong sample_period",
39 1 == evsel->attr.sample_period);
40 }
41 return 0;
42}
43
44static int test__checkevent_raw(struct perf_evlist *evlist)
45{
0c21f736 46 struct perf_evsel *evsel = perf_evlist__first(evlist);
f50246e2
JO
47
48 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
49 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
50 TEST_ASSERT_VAL("wrong config", 0x1a == evsel->attr.config);
51 return 0;
52}
53
54static int test__checkevent_numeric(struct perf_evlist *evlist)
55{
0c21f736 56 struct perf_evsel *evsel = perf_evlist__first(evlist);
f50246e2
JO
57
58 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
59 TEST_ASSERT_VAL("wrong type", 1 == evsel->attr.type);
60 TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
61 return 0;
62}
63
64static int test__checkevent_symbolic_name(struct perf_evlist *evlist)
65{
0c21f736 66 struct perf_evsel *evsel = perf_evlist__first(evlist);
f50246e2
JO
67
68 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
69 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
70 TEST_ASSERT_VAL("wrong config",
71 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
72 return 0;
73}
74
75static int test__checkevent_symbolic_name_config(struct perf_evlist *evlist)
76{
0c21f736 77 struct perf_evsel *evsel = perf_evlist__first(evlist);
f50246e2
JO
78
79 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
80 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
81 TEST_ASSERT_VAL("wrong config",
82 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
83 TEST_ASSERT_VAL("wrong period",
84 100000 == evsel->attr.sample_period);
85 TEST_ASSERT_VAL("wrong config1",
86 0 == evsel->attr.config1);
87 TEST_ASSERT_VAL("wrong config2",
88 1 == evsel->attr.config2);
89 return 0;
90}
91
92static int test__checkevent_symbolic_alias(struct perf_evlist *evlist)
93{
0c21f736 94 struct perf_evsel *evsel = perf_evlist__first(evlist);
f50246e2
JO
95
96 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
97 TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->attr.type);
98 TEST_ASSERT_VAL("wrong config",
99 PERF_COUNT_SW_PAGE_FAULTS == evsel->attr.config);
100 return 0;
101}
102
103static int test__checkevent_genhw(struct perf_evlist *evlist)
104{
0c21f736 105 struct perf_evsel *evsel = perf_evlist__first(evlist);
f50246e2
JO
106
107 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
108 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HW_CACHE == evsel->attr.type);
109 TEST_ASSERT_VAL("wrong config", (1 << 16) == evsel->attr.config);
110 return 0;
111}
112
113static int test__checkevent_breakpoint(struct perf_evlist *evlist)
114{
0c21f736 115 struct perf_evsel *evsel = perf_evlist__first(evlist);
f50246e2
JO
116
117 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
118 TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->attr.type);
119 TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
120 TEST_ASSERT_VAL("wrong bp_type", (HW_BREAKPOINT_R | HW_BREAKPOINT_W) ==
121 evsel->attr.bp_type);
122 TEST_ASSERT_VAL("wrong bp_len", HW_BREAKPOINT_LEN_4 ==
123 evsel->attr.bp_len);
124 return 0;
125}
126
127static int test__checkevent_breakpoint_x(struct perf_evlist *evlist)
128{
0c21f736 129 struct perf_evsel *evsel = perf_evlist__first(evlist);
f50246e2
JO
130
131 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
132 TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->attr.type);
133 TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
134 TEST_ASSERT_VAL("wrong bp_type",
135 HW_BREAKPOINT_X == evsel->attr.bp_type);
136 TEST_ASSERT_VAL("wrong bp_len", sizeof(long) == evsel->attr.bp_len);
137 return 0;
138}
139
140static int test__checkevent_breakpoint_r(struct perf_evlist *evlist)
141{
0c21f736 142 struct perf_evsel *evsel = perf_evlist__first(evlist);
f50246e2
JO
143
144 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
145 TEST_ASSERT_VAL("wrong type",
146 PERF_TYPE_BREAKPOINT == evsel->attr.type);
147 TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
148 TEST_ASSERT_VAL("wrong bp_type",
149 HW_BREAKPOINT_R == evsel->attr.bp_type);
150 TEST_ASSERT_VAL("wrong bp_len",
151 HW_BREAKPOINT_LEN_4 == evsel->attr.bp_len);
152 return 0;
153}
154
155static int test__checkevent_breakpoint_w(struct perf_evlist *evlist)
156{
0c21f736 157 struct perf_evsel *evsel = perf_evlist__first(evlist);
f50246e2
JO
158
159 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
160 TEST_ASSERT_VAL("wrong type",
161 PERF_TYPE_BREAKPOINT == evsel->attr.type);
162 TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
163 TEST_ASSERT_VAL("wrong bp_type",
164 HW_BREAKPOINT_W == evsel->attr.bp_type);
165 TEST_ASSERT_VAL("wrong bp_len",
166 HW_BREAKPOINT_LEN_4 == evsel->attr.bp_len);
167 return 0;
168}
169
7582732f
JO
170static int test__checkevent_breakpoint_rw(struct perf_evlist *evlist)
171{
0c21f736 172 struct perf_evsel *evsel = perf_evlist__first(evlist);
7582732f
JO
173
174 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
175 TEST_ASSERT_VAL("wrong type",
176 PERF_TYPE_BREAKPOINT == evsel->attr.type);
177 TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
178 TEST_ASSERT_VAL("wrong bp_type",
179 (HW_BREAKPOINT_R|HW_BREAKPOINT_W) == evsel->attr.bp_type);
180 TEST_ASSERT_VAL("wrong bp_len",
181 HW_BREAKPOINT_LEN_4 == evsel->attr.bp_len);
182 return 0;
183}
184
f50246e2
JO
185static int test__checkevent_tracepoint_modifier(struct perf_evlist *evlist)
186{
0c21f736 187 struct perf_evsel *evsel = perf_evlist__first(evlist);
f50246e2
JO
188
189 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
190 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
191 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
192 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
193
194 return test__checkevent_tracepoint(evlist);
195}
196
197static int
198test__checkevent_tracepoint_multi_modifier(struct perf_evlist *evlist)
199{
200 struct perf_evsel *evsel;
201
202 TEST_ASSERT_VAL("wrong number of entries", evlist->nr_entries > 1);
203
204 list_for_each_entry(evsel, &evlist->entries, node) {
205 TEST_ASSERT_VAL("wrong exclude_user",
206 !evsel->attr.exclude_user);
207 TEST_ASSERT_VAL("wrong exclude_kernel",
208 evsel->attr.exclude_kernel);
209 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
210 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
211 }
212
213 return test__checkevent_tracepoint_multi(evlist);
214}
215
216static int test__checkevent_raw_modifier(struct perf_evlist *evlist)
217{
0c21f736 218 struct perf_evsel *evsel = perf_evlist__first(evlist);
f50246e2
JO
219
220 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
221 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
222 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
223 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
224
225 return test__checkevent_raw(evlist);
226}
227
228static int test__checkevent_numeric_modifier(struct perf_evlist *evlist)
229{
0c21f736 230 struct perf_evsel *evsel = perf_evlist__first(evlist);
f50246e2
JO
231
232 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
233 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
234 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
235 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
236
237 return test__checkevent_numeric(evlist);
238}
239
240static int test__checkevent_symbolic_name_modifier(struct perf_evlist *evlist)
241{
0c21f736 242 struct perf_evsel *evsel = perf_evlist__first(evlist);
f50246e2
JO
243
244 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
245 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
246 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
247 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
248
249 return test__checkevent_symbolic_name(evlist);
250}
251
252static int test__checkevent_exclude_host_modifier(struct perf_evlist *evlist)
253{
0c21f736 254 struct perf_evsel *evsel = perf_evlist__first(evlist);
f50246e2
JO
255
256 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
257 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
258
259 return test__checkevent_symbolic_name(evlist);
260}
261
262static int test__checkevent_exclude_guest_modifier(struct perf_evlist *evlist)
263{
0c21f736 264 struct perf_evsel *evsel = perf_evlist__first(evlist);
f50246e2
JO
265
266 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
267 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
268
269 return test__checkevent_symbolic_name(evlist);
270}
271
272static int test__checkevent_symbolic_alias_modifier(struct perf_evlist *evlist)
273{
0c21f736 274 struct perf_evsel *evsel = perf_evlist__first(evlist);
f50246e2
JO
275
276 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
277 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
278 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
279 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
280
281 return test__checkevent_symbolic_alias(evlist);
282}
283
284static int test__checkevent_genhw_modifier(struct perf_evlist *evlist)
285{
0c21f736 286 struct perf_evsel *evsel = perf_evlist__first(evlist);
f50246e2
JO
287
288 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
289 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
290 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
291 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
292
293 return test__checkevent_genhw(evlist);
294}
295
296static int test__checkevent_breakpoint_modifier(struct perf_evlist *evlist)
297{
0c21f736 298 struct perf_evsel *evsel = perf_evlist__first(evlist);
f50246e2 299
f50246e2
JO
300
301 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
302 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
303 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
304 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
287e74aa 305 TEST_ASSERT_VAL("wrong name",
ac2ba9f3 306 !strcmp(perf_evsel__name(evsel), "mem:0:u"));
f50246e2
JO
307
308 return test__checkevent_breakpoint(evlist);
309}
310
311static int test__checkevent_breakpoint_x_modifier(struct perf_evlist *evlist)
312{
0c21f736 313 struct perf_evsel *evsel = perf_evlist__first(evlist);
f50246e2
JO
314
315 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
316 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
317 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
318 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
287e74aa 319 TEST_ASSERT_VAL("wrong name",
ac2ba9f3 320 !strcmp(perf_evsel__name(evsel), "mem:0:x:k"));
f50246e2
JO
321
322 return test__checkevent_breakpoint_x(evlist);
323}
324
325static int test__checkevent_breakpoint_r_modifier(struct perf_evlist *evlist)
326{
0c21f736 327 struct perf_evsel *evsel = perf_evlist__first(evlist);
f50246e2
JO
328
329 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
330 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
331 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
332 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
287e74aa 333 TEST_ASSERT_VAL("wrong name",
ac2ba9f3 334 !strcmp(perf_evsel__name(evsel), "mem:0:r:hp"));
f50246e2
JO
335
336 return test__checkevent_breakpoint_r(evlist);
337}
338
339static int test__checkevent_breakpoint_w_modifier(struct perf_evlist *evlist)
340{
0c21f736 341 struct perf_evsel *evsel = perf_evlist__first(evlist);
f50246e2
JO
342
343 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
344 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
345 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
346 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
287e74aa 347 TEST_ASSERT_VAL("wrong name",
ac2ba9f3 348 !strcmp(perf_evsel__name(evsel), "mem:0:w:up"));
f50246e2
JO
349
350 return test__checkevent_breakpoint_w(evlist);
351}
352
7582732f
JO
353static int test__checkevent_breakpoint_rw_modifier(struct perf_evlist *evlist)
354{
0c21f736 355 struct perf_evsel *evsel = perf_evlist__first(evlist);
7582732f
JO
356
357 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
358 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
359 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
360 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
287e74aa 361 TEST_ASSERT_VAL("wrong name",
ac2ba9f3 362 !strcmp(perf_evsel__name(evsel), "mem:0:rw:kp"));
7582732f
JO
363
364 return test__checkevent_breakpoint_rw(evlist);
365}
366
f50246e2
JO
367static int test__checkevent_pmu(struct perf_evlist *evlist)
368{
369
0c21f736 370 struct perf_evsel *evsel = perf_evlist__first(evlist);
f50246e2
JO
371
372 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
373 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
374 TEST_ASSERT_VAL("wrong config", 10 == evsel->attr.config);
375 TEST_ASSERT_VAL("wrong config1", 1 == evsel->attr.config1);
376 TEST_ASSERT_VAL("wrong config2", 3 == evsel->attr.config2);
377 TEST_ASSERT_VAL("wrong period", 1000 == evsel->attr.sample_period);
378
379 return 0;
380}
381
382static int test__checkevent_list(struct perf_evlist *evlist)
383{
0c21f736 384 struct perf_evsel *evsel = perf_evlist__first(evlist);
f50246e2
JO
385
386 TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->nr_entries);
387
388 /* r1 */
f50246e2
JO
389 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
390 TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
391 TEST_ASSERT_VAL("wrong config1", 0 == evsel->attr.config1);
392 TEST_ASSERT_VAL("wrong config2", 0 == evsel->attr.config2);
393 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
394 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
395 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
396 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
397
398 /* syscalls:sys_enter_open:k */
0c21f736 399 evsel = perf_evsel__next(evsel);
f50246e2
JO
400 TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->attr.type);
401 TEST_ASSERT_VAL("wrong sample_type",
30f31c0a 402 PERF_TP_SAMPLE_TYPE == evsel->attr.sample_type);
f50246e2
JO
403 TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->attr.sample_period);
404 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
405 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
406 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
407 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
408
409 /* 1:1:hp */
0c21f736 410 evsel = perf_evsel__next(evsel);
f50246e2
JO
411 TEST_ASSERT_VAL("wrong type", 1 == evsel->attr.type);
412 TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
413 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
414 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
415 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
416 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip);
417
418 return 0;
419}
420
6b5fc39b
JO
421static int test__checkevent_pmu_name(struct perf_evlist *evlist)
422{
0c21f736 423 struct perf_evsel *evsel = perf_evlist__first(evlist);
6b5fc39b 424
7a25b2d3 425 /* cpu/config=1,name=krava/u */
6b5fc39b
JO
426 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
427 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
428 TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
22c8b843 429 TEST_ASSERT_VAL("wrong name", !strcmp(perf_evsel__name(evsel), "krava"));
6b5fc39b 430
7a25b2d3 431 /* cpu/config=2/u" */
0c21f736 432 evsel = perf_evsel__next(evsel);
6b5fc39b
JO
433 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
434 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
435 TEST_ASSERT_VAL("wrong config", 2 == evsel->attr.config);
7a25b2d3 436 TEST_ASSERT_VAL("wrong name",
ac2ba9f3 437 !strcmp(perf_evsel__name(evsel), "cpu/config=2/u"));
6b5fc39b
JO
438
439 return 0;
440}
441
3f3a2064
JO
442static int test__checkevent_pmu_events(struct perf_evlist *evlist)
443{
444 struct perf_evsel *evsel;
445
446 evsel = list_entry(evlist->entries.next, struct perf_evsel, node);
447 TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
448 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
449 TEST_ASSERT_VAL("wrong exclude_user",
450 !evsel->attr.exclude_user);
451 TEST_ASSERT_VAL("wrong exclude_kernel",
452 evsel->attr.exclude_kernel);
453 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
454 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
455
456 return 0;
457}
458
4429392e
JO
459static int test__checkterms_simple(struct list_head *terms)
460{
6cee6cd3 461 struct parse_events_term *term;
4429392e
JO
462
463 /* config=10 */
6cee6cd3 464 term = list_entry(terms->next, struct parse_events_term, list);
4429392e
JO
465 TEST_ASSERT_VAL("wrong type term",
466 term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG);
467 TEST_ASSERT_VAL("wrong type val",
468 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
469 TEST_ASSERT_VAL("wrong val", term->val.num == 10);
470 TEST_ASSERT_VAL("wrong config", !term->config);
471
472 /* config1 */
6cee6cd3 473 term = list_entry(term->list.next, struct parse_events_term, list);
4429392e
JO
474 TEST_ASSERT_VAL("wrong type term",
475 term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG1);
476 TEST_ASSERT_VAL("wrong type val",
477 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
478 TEST_ASSERT_VAL("wrong val", term->val.num == 1);
479 TEST_ASSERT_VAL("wrong config", !term->config);
480
481 /* config2=3 */
6cee6cd3 482 term = list_entry(term->list.next, struct parse_events_term, list);
4429392e
JO
483 TEST_ASSERT_VAL("wrong type term",
484 term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG2);
485 TEST_ASSERT_VAL("wrong type val",
486 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
487 TEST_ASSERT_VAL("wrong val", term->val.num == 3);
488 TEST_ASSERT_VAL("wrong config", !term->config);
489
490 /* umask=1*/
6cee6cd3 491 term = list_entry(term->list.next, struct parse_events_term, list);
4429392e
JO
492 TEST_ASSERT_VAL("wrong type term",
493 term->type_term == PARSE_EVENTS__TERM_TYPE_USER);
494 TEST_ASSERT_VAL("wrong type val",
495 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
496 TEST_ASSERT_VAL("wrong val", term->val.num == 1);
497 TEST_ASSERT_VAL("wrong config", !strcmp(term->config, "umask"));
498
499 return 0;
500}
501
905f5ee2
JO
502static int test__group1(struct perf_evlist *evlist)
503{
504 struct perf_evsel *evsel, *leader;
505
506 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
8d7d8474 507 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
905f5ee2
JO
508
509 /* instructions:k */
0c21f736 510 evsel = leader = perf_evlist__first(evlist);
905f5ee2
JO
511 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
512 TEST_ASSERT_VAL("wrong config",
513 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
514 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
515 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
516 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
517 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
518 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
519 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
823254ed 520 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
8d7d8474
NK
521 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
522 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
905f5ee2
JO
523
524 /* cycles:upp */
0c21f736 525 evsel = perf_evsel__next(evsel);
905f5ee2
JO
526 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
527 TEST_ASSERT_VAL("wrong config",
528 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
529 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
530 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
531 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
42be7398
JO
532 /* use of precise requires exclude_guest */
533 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
905f5ee2
JO
534 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
535 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 2);
536 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
8d7d8474 537 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
905f5ee2
JO
538
539 return 0;
540}
541
542static int test__group2(struct perf_evlist *evlist)
543{
544 struct perf_evsel *evsel, *leader;
545
546 TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->nr_entries);
8d7d8474 547 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
905f5ee2
JO
548
549 /* faults + :ku modifier */
0c21f736 550 evsel = leader = perf_evlist__first(evlist);
905f5ee2
JO
551 TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->attr.type);
552 TEST_ASSERT_VAL("wrong config",
553 PERF_COUNT_SW_PAGE_FAULTS == evsel->attr.config);
554 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
555 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
556 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
557 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
558 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
559 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
823254ed 560 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
8d7d8474
NK
561 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
562 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
905f5ee2
JO
563
564 /* cache-references + :u modifier */
0c21f736 565 evsel = perf_evsel__next(evsel);
905f5ee2
JO
566 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
567 TEST_ASSERT_VAL("wrong config",
568 PERF_COUNT_HW_CACHE_REFERENCES == evsel->attr.config);
569 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
570 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
571 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
5a30a99f 572 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
905f5ee2
JO
573 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
574 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
575 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
8d7d8474 576 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
905f5ee2
JO
577
578 /* cycles:k */
0c21f736 579 evsel = perf_evsel__next(evsel);
905f5ee2
JO
580 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
581 TEST_ASSERT_VAL("wrong config",
582 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
583 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
584 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
585 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
586 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
587 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
588 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
823254ed 589 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
905f5ee2
JO
590
591 return 0;
592}
593
1d037ca1 594static int test__group3(struct perf_evlist *evlist __maybe_unused)
905f5ee2
JO
595{
596 struct perf_evsel *evsel, *leader;
597
598 TEST_ASSERT_VAL("wrong number of entries", 5 == evlist->nr_entries);
8d7d8474 599 TEST_ASSERT_VAL("wrong number of groups", 2 == evlist->nr_groups);
905f5ee2
JO
600
601 /* group1 syscalls:sys_enter_open:H */
0c21f736 602 evsel = leader = perf_evlist__first(evlist);
905f5ee2
JO
603 TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->attr.type);
604 TEST_ASSERT_VAL("wrong sample_type",
605 PERF_TP_SAMPLE_TYPE == evsel->attr.sample_type);
606 TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->attr.sample_period);
607 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
608 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
609 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
610 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
611 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
612 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
823254ed 613 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
905f5ee2
JO
614 TEST_ASSERT_VAL("wrong group name",
615 !strcmp(leader->group_name, "group1"));
8d7d8474
NK
616 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
617 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
905f5ee2
JO
618
619 /* group1 cycles:kppp */
0c21f736 620 evsel = perf_evsel__next(evsel);
905f5ee2
JO
621 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
622 TEST_ASSERT_VAL("wrong config",
623 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
624 TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user);
625 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
626 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
42be7398
JO
627 /* use of precise requires exclude_guest */
628 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
905f5ee2
JO
629 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
630 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 3);
631 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
632 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
8d7d8474 633 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
905f5ee2
JO
634
635 /* group2 cycles + G modifier */
0c21f736 636 evsel = leader = perf_evsel__next(evsel);
905f5ee2
JO
637 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
638 TEST_ASSERT_VAL("wrong config",
639 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
640 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
641 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
642 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
643 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
644 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
645 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
823254ed 646 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
905f5ee2
JO
647 TEST_ASSERT_VAL("wrong group name",
648 !strcmp(leader->group_name, "group2"));
8d7d8474
NK
649 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
650 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
905f5ee2
JO
651
652 /* group2 1:3 + G modifier */
0c21f736 653 evsel = perf_evsel__next(evsel);
905f5ee2
JO
654 TEST_ASSERT_VAL("wrong type", 1 == evsel->attr.type);
655 TEST_ASSERT_VAL("wrong config", 3 == evsel->attr.config);
656 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
657 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
658 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
659 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
660 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
661 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
662 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
8d7d8474 663 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
905f5ee2
JO
664
665 /* instructions:u */
0c21f736 666 evsel = perf_evsel__next(evsel);
905f5ee2
JO
667 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
668 TEST_ASSERT_VAL("wrong config",
669 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
670 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
671 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
672 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
673 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
674 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
675 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
823254ed 676 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
905f5ee2
JO
677
678 return 0;
679}
680
1d037ca1 681static int test__group4(struct perf_evlist *evlist __maybe_unused)
905f5ee2
JO
682{
683 struct perf_evsel *evsel, *leader;
684
685 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
8d7d8474 686 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
905f5ee2
JO
687
688 /* cycles:u + p */
0c21f736 689 evsel = leader = perf_evlist__first(evlist);
905f5ee2
JO
690 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
691 TEST_ASSERT_VAL("wrong config",
692 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
693 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
694 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
695 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
42be7398
JO
696 /* use of precise requires exclude_guest */
697 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
905f5ee2
JO
698 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
699 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 1);
700 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
823254ed 701 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
8d7d8474
NK
702 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
703 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
905f5ee2
JO
704
705 /* instructions:kp + p */
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);
42be7398
JO
713 /* use of precise requires exclude_guest */
714 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
905f5ee2
JO
715 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
716 TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip == 2);
717 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
8d7d8474 718 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
905f5ee2
JO
719
720 return 0;
721}
722
1d037ca1 723static int test__group5(struct perf_evlist *evlist __maybe_unused)
905f5ee2
JO
724{
725 struct perf_evsel *evsel, *leader;
726
727 TEST_ASSERT_VAL("wrong number of entries", 5 == evlist->nr_entries);
8d7d8474 728 TEST_ASSERT_VAL("wrong number of groups", 2 == evlist->nr_groups);
905f5ee2
JO
729
730 /* cycles + G */
0c21f736 731 evsel = leader = perf_evlist__first(evlist);
905f5ee2
JO
732 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
733 TEST_ASSERT_VAL("wrong config",
734 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
735 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
736 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
737 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
738 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
739 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
740 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
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);
905f5ee2
JO
745
746 /* instructions + G */
0c21f736 747 evsel = perf_evsel__next(evsel);
905f5ee2
JO
748 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
749 TEST_ASSERT_VAL("wrong config",
750 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
751 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
752 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
753 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
754 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
755 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
756 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
757 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
8d7d8474 758 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
905f5ee2
JO
759
760 /* cycles:G */
0c21f736 761 evsel = leader = 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_CPU_CYCLES == 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 group name", !evsel->group_name);
823254ed 772 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
8d7d8474
NK
773 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
774 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
905f5ee2
JO
775
776 /* instructions:G */
0c21f736 777 evsel = perf_evsel__next(evsel);
905f5ee2
JO
778 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
779 TEST_ASSERT_VAL("wrong config",
780 PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
781 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
782 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
783 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
784 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
785 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
786 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
787 TEST_ASSERT_VAL("wrong leader", evsel->leader == leader);
8d7d8474 788 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
905f5ee2
JO
789
790 /* cycles */
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_CPU_CYCLES == 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);
823254ed 801 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
905f5ee2
JO
802
803 return 0;
804}
805
5a30a99f
JO
806static int test__group_gh1(struct perf_evlist *evlist)
807{
808 struct perf_evsel *evsel, *leader;
809
810 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
811 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
812
813 /* cycles + :H group modifier */
814 evsel = leader = perf_evlist__first(evlist);
815 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
816 TEST_ASSERT_VAL("wrong config",
817 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
818 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
819 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
820 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
821 TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest);
822 TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host);
823 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
824 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
825 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
826 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
827 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
828
829 /* cache-misses:G + :H group modifier */
830 evsel = perf_evsel__next(evsel);
831 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
832 TEST_ASSERT_VAL("wrong config",
833 PERF_COUNT_HW_CACHE_MISSES == 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 leader", evsel->leader == leader);
841 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
842
843 return 0;
844}
845
846static int test__group_gh2(struct perf_evlist *evlist)
847{
848 struct perf_evsel *evsel, *leader;
849
850 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
851 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
852
853 /* cycles + :G group modifier */
854 evsel = leader = perf_evlist__first(evlist);
855 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
856 TEST_ASSERT_VAL("wrong config",
857 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
858 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
859 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel);
860 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
861 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
862 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
863 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
864 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
865 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
866 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
867 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
868
869 /* cache-misses:H + :G group modifier */
870 evsel = perf_evsel__next(evsel);
871 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
872 TEST_ASSERT_VAL("wrong config",
873 PERF_COUNT_HW_CACHE_MISSES == 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 leader", evsel->leader == leader);
881 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
882
883 return 0;
884}
885
886static int test__group_gh3(struct perf_evlist *evlist)
887{
888 struct perf_evsel *evsel, *leader;
889
890 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
891 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
892
893 /* cycles:G + :u group modifier */
894 evsel = leader = perf_evlist__first(evlist);
895 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
896 TEST_ASSERT_VAL("wrong config",
897 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
898 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
899 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
900 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
901 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
902 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
903 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
904 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
905 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
906 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
907 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
908
909 /* cache-misses:H + :u group modifier */
910 evsel = perf_evsel__next(evsel);
911 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
912 TEST_ASSERT_VAL("wrong config",
913 PERF_COUNT_HW_CACHE_MISSES == 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 leader", evsel->leader == leader);
921 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
922
923 return 0;
924}
925
926static int test__group_gh4(struct perf_evlist *evlist)
927{
928 struct perf_evsel *evsel, *leader;
929
930 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
931 TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
932
933 /* cycles:G + :uG group modifier */
934 evsel = leader = perf_evlist__first(evlist);
935 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
936 TEST_ASSERT_VAL("wrong config",
937 PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
938 TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user);
939 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel);
940 TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
941 TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest);
942 TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host);
943 TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
944 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
945 TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
946 TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
947 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);
948
949 /* cache-misses:H + :uG group modifier */
950 evsel = perf_evsel__next(evsel);
951 TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
952 TEST_ASSERT_VAL("wrong config",
953 PERF_COUNT_HW_CACHE_MISSES == 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 leader", evsel->leader == leader);
961 TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 1);
962
963 return 0;
964}
965
82ce75d9
JO
966static int count_tracepoints(void)
967{
968 char events_path[PATH_MAX];
969 struct dirent *events_ent;
970 DIR *events_dir;
971 int cnt = 0;
972
973 scnprintf(events_path, PATH_MAX, "%s/tracing/events",
974 debugfs_find_mountpoint());
975
976 events_dir = opendir(events_path);
977
978 TEST_ASSERT_VAL("Can't open events dir", events_dir);
979
980 while ((events_ent = readdir(events_dir))) {
981 char sys_path[PATH_MAX];
982 struct dirent *sys_ent;
983 DIR *sys_dir;
984
985 if (!strcmp(events_ent->d_name, ".")
986 || !strcmp(events_ent->d_name, "..")
987 || !strcmp(events_ent->d_name, "enable")
988 || !strcmp(events_ent->d_name, "header_event")
989 || !strcmp(events_ent->d_name, "header_page"))
990 continue;
991
992 scnprintf(sys_path, PATH_MAX, "%s/%s",
993 events_path, events_ent->d_name);
994
995 sys_dir = opendir(sys_path);
996 TEST_ASSERT_VAL("Can't open sys dir", sys_dir);
997
998 while ((sys_ent = readdir(sys_dir))) {
999 if (!strcmp(sys_ent->d_name, ".")
1000 || !strcmp(sys_ent->d_name, "..")
1001 || !strcmp(sys_ent->d_name, "enable")
1002 || !strcmp(sys_ent->d_name, "filter"))
1003 continue;
1004
1005 cnt++;
1006 }
1007
1008 closedir(sys_dir);
1009 }
1010
1011 closedir(events_dir);
1012 return cnt;
1013}
1014
1015static int test__all_tracepoints(struct perf_evlist *evlist)
1016{
1017 TEST_ASSERT_VAL("wrong events count",
1018 count_tracepoints() == evlist->nr_entries);
1019
1020 return test__checkevent_tracepoint_multi(evlist);
1021}
1022
23b6339b 1023struct evlist_test {
f50246e2
JO
1024 const char *name;
1025 __u32 type;
1026 int (*check)(struct perf_evlist *evlist);
1027};
1028
23b6339b 1029static struct evlist_test test__events[] = {
f50246e2
JO
1030 [0] = {
1031 .name = "syscalls:sys_enter_open",
1032 .check = test__checkevent_tracepoint,
1033 },
1034 [1] = {
1035 .name = "syscalls:*",
1036 .check = test__checkevent_tracepoint_multi,
1037 },
1038 [2] = {
1039 .name = "r1a",
1040 .check = test__checkevent_raw,
1041 },
1042 [3] = {
1043 .name = "1:1",
1044 .check = test__checkevent_numeric,
1045 },
1046 [4] = {
1047 .name = "instructions",
1048 .check = test__checkevent_symbolic_name,
1049 },
1050 [5] = {
1051 .name = "cycles/period=100000,config2/",
1052 .check = test__checkevent_symbolic_name_config,
1053 },
1054 [6] = {
1055 .name = "faults",
1056 .check = test__checkevent_symbolic_alias,
1057 },
1058 [7] = {
1059 .name = "L1-dcache-load-miss",
1060 .check = test__checkevent_genhw,
1061 },
1062 [8] = {
1063 .name = "mem:0",
1064 .check = test__checkevent_breakpoint,
1065 },
1066 [9] = {
1067 .name = "mem:0:x",
1068 .check = test__checkevent_breakpoint_x,
1069 },
1070 [10] = {
1071 .name = "mem:0:r",
1072 .check = test__checkevent_breakpoint_r,
1073 },
1074 [11] = {
1075 .name = "mem:0:w",
1076 .check = test__checkevent_breakpoint_w,
1077 },
1078 [12] = {
1079 .name = "syscalls:sys_enter_open:k",
1080 .check = test__checkevent_tracepoint_modifier,
1081 },
1082 [13] = {
1083 .name = "syscalls:*:u",
1084 .check = test__checkevent_tracepoint_multi_modifier,
1085 },
1086 [14] = {
1087 .name = "r1a:kp",
1088 .check = test__checkevent_raw_modifier,
1089 },
1090 [15] = {
1091 .name = "1:1:hp",
1092 .check = test__checkevent_numeric_modifier,
1093 },
1094 [16] = {
1095 .name = "instructions:h",
1096 .check = test__checkevent_symbolic_name_modifier,
1097 },
1098 [17] = {
1099 .name = "faults:u",
1100 .check = test__checkevent_symbolic_alias_modifier,
1101 },
1102 [18] = {
1103 .name = "L1-dcache-load-miss:kp",
1104 .check = test__checkevent_genhw_modifier,
1105 },
1106 [19] = {
1107 .name = "mem:0:u",
1108 .check = test__checkevent_breakpoint_modifier,
1109 },
1110 [20] = {
1111 .name = "mem:0:x:k",
1112 .check = test__checkevent_breakpoint_x_modifier,
1113 },
1114 [21] = {
1115 .name = "mem:0:r:hp",
1116 .check = test__checkevent_breakpoint_r_modifier,
1117 },
1118 [22] = {
1119 .name = "mem:0:w:up",
1120 .check = test__checkevent_breakpoint_w_modifier,
1121 },
1122 [23] = {
1123 .name = "r1,syscalls:sys_enter_open:k,1:1:hp",
1124 .check = test__checkevent_list,
1125 },
1126 [24] = {
1127 .name = "instructions:G",
1128 .check = test__checkevent_exclude_host_modifier,
1129 },
1130 [25] = {
1131 .name = "instructions:H",
1132 .check = test__checkevent_exclude_guest_modifier,
1133 },
7582732f
JO
1134 [26] = {
1135 .name = "mem:0:rw",
1136 .check = test__checkevent_breakpoint_rw,
1137 },
1138 [27] = {
1139 .name = "mem:0:rw:kp",
1140 .check = test__checkevent_breakpoint_rw_modifier,
1141 },
905f5ee2
JO
1142 [28] = {
1143 .name = "{instructions:k,cycles:upp}",
1144 .check = test__group1,
1145 },
1146 [29] = {
1147 .name = "{faults:k,cache-references}:u,cycles:k",
1148 .check = test__group2,
1149 },
1150 [30] = {
1151 .name = "group1{syscalls:sys_enter_open:H,cycles:kppp},group2{cycles,1:3}:G,instructions:u",
1152 .check = test__group3,
1153 },
1154 [31] = {
1155 .name = "{cycles:u,instructions:kp}:p",
1156 .check = test__group4,
1157 },
1158 [32] = {
1159 .name = "{cycles,instructions}:G,{cycles:G,instructions:G},cycles",
1160 .check = test__group5,
1161 },
82ce75d9
JO
1162 [33] = {
1163 .name = "*:*",
1164 .check = test__all_tracepoints,
1165 },
5a30a99f
JO
1166 [34] = {
1167 .name = "{cycles,cache-misses:G}:H",
1168 .check = test__group_gh1,
1169 },
1170 [35] = {
1171 .name = "{cycles,cache-misses:H}:G",
1172 .check = test__group_gh2,
1173 },
1174 [36] = {
1175 .name = "{cycles:G,cache-misses:H}:u",
1176 .check = test__group_gh3,
1177 },
1178 [37] = {
1179 .name = "{cycles:G,cache-misses:H}:uG",
1180 .check = test__group_gh4,
1181 },
f50246e2
JO
1182};
1183
23b6339b 1184static struct evlist_test test__events_pmu[] = {
f50246e2
JO
1185 [0] = {
1186 .name = "cpu/config=10,config1,config2=3,period=1000/u",
1187 .check = test__checkevent_pmu,
1188 },
6b5fc39b
JO
1189 [1] = {
1190 .name = "cpu/config=1,name=krava/u,cpu/config=2/u",
1191 .check = test__checkevent_pmu_name,
1192 },
f50246e2
JO
1193};
1194
23b6339b 1195struct terms_test {
4429392e
JO
1196 const char *str;
1197 __u32 type;
1198 int (*check)(struct list_head *terms);
1199};
1200
23b6339b 1201static struct terms_test test__terms[] = {
4429392e
JO
1202 [0] = {
1203 .str = "config=10,config1,config2=3,umask=1",
1204 .check = test__checkterms_simple,
1205 },
1206};
1207
23b6339b 1208static int test_event(struct evlist_test *e)
f50246e2
JO
1209{
1210 struct perf_evlist *evlist;
1211 int ret;
1212
334fe7a3 1213 evlist = perf_evlist__new();
f50246e2
JO
1214 if (evlist == NULL)
1215 return -ENOMEM;
1216
d8f7bbc9 1217 ret = parse_events(evlist, e->name);
f50246e2
JO
1218 if (ret) {
1219 pr_debug("failed to parse event '%s', err %d\n",
1220 e->name, ret);
1221 return ret;
1222 }
1223
1224 ret = e->check(evlist);
1225 perf_evlist__delete(evlist);
1226
1227 return ret;
1228}
1229
23b6339b 1230static int test_events(struct evlist_test *events, unsigned cnt)
f50246e2 1231{
9bfbbc6d 1232 int ret1, ret2 = 0;
f50246e2
JO
1233 unsigned i;
1234
1235 for (i = 0; i < cnt; i++) {
23b6339b 1236 struct evlist_test *e = &events[i];
f50246e2
JO
1237
1238 pr_debug("running test %d '%s'\n", i, e->name);
9bfbbc6d
RR
1239 ret1 = test_event(e);
1240 if (ret1)
1241 ret2 = ret1;
4429392e
JO
1242 }
1243
9bfbbc6d 1244 return ret2;
4429392e
JO
1245}
1246
23b6339b 1247static int test_term(struct terms_test *t)
4429392e
JO
1248{
1249 struct list_head *terms;
1250 int ret;
1251
1252 terms = malloc(sizeof(*terms));
1253 if (!terms)
1254 return -ENOMEM;
1255
1256 INIT_LIST_HEAD(terms);
1257
1258 ret = parse_events_terms(terms, t->str);
1259 if (ret) {
1260 pr_debug("failed to parse terms '%s', err %d\n",
1261 t->str , ret);
1262 return ret;
1263 }
1264
1265 ret = t->check(terms);
1266 parse_events__free_terms(terms);
1267
1268 return ret;
1269}
1270
23b6339b 1271static int test_terms(struct terms_test *terms, unsigned cnt)
4429392e
JO
1272{
1273 int ret = 0;
1274 unsigned i;
1275
1276 for (i = 0; i < cnt; i++) {
23b6339b 1277 struct terms_test *t = &terms[i];
4429392e
JO
1278
1279 pr_debug("running test %d '%s'\n", i, t->str);
1280 ret = test_term(t);
f50246e2
JO
1281 if (ret)
1282 break;
1283 }
1284
1285 return ret;
1286}
1287
1288static int test_pmu(void)
1289{
1290 struct stat st;
1291 char path[PATH_MAX];
1292 int ret;
1293
1294 snprintf(path, PATH_MAX, "%s/bus/event_source/devices/cpu/format/",
1295 sysfs_find_mountpoint());
1296
1297 ret = stat(path, &st);
1298 if (ret)
3fd44cd4 1299 pr_debug("omitting PMU cpu tests\n");
f50246e2
JO
1300 return !ret;
1301}
1302
3f3a2064
JO
1303static int test_pmu_events(void)
1304{
1305 struct stat st;
1306 char path[PATH_MAX];
1307 struct dirent *ent;
1308 DIR *dir;
1309 int ret;
1310
1311 snprintf(path, PATH_MAX, "%s/bus/event_source/devices/cpu/events/",
1312 sysfs_find_mountpoint());
1313
1314 ret = stat(path, &st);
1315 if (ret) {
a895d57d 1316 pr_debug("omitting PMU cpu events tests\n");
3f3a2064
JO
1317 return 0;
1318 }
1319
1320 dir = opendir(path);
1321 if (!dir) {
1322 pr_debug("can't open pmu event dir");
1323 return -1;
1324 }
1325
1326 while (!ret && (ent = readdir(dir))) {
1327#define MAX_NAME 100
23b6339b 1328 struct evlist_test e;
3f3a2064
JO
1329 char name[MAX_NAME];
1330
1331 if (!strcmp(ent->d_name, ".") ||
1332 !strcmp(ent->d_name, ".."))
1333 continue;
1334
1335 snprintf(name, MAX_NAME, "cpu/event=%s/u", ent->d_name);
1336
1337 e.name = name;
1338 e.check = test__checkevent_pmu_events;
1339
1340 ret = test_event(&e);
1341#undef MAX_NAME
1342 }
1343
1344 closedir(dir);
1345 return ret;
1346}
1347
c81251e8 1348int test__parse_events(void)
f50246e2 1349{
9bfbbc6d 1350 int ret1, ret2 = 0;
f50246e2 1351
ebf124ff
JO
1352#define TEST_EVENTS(tests) \
1353do { \
9bfbbc6d
RR
1354 ret1 = test_events(tests, ARRAY_SIZE(tests)); \
1355 if (!ret2) \
1356 ret2 = ret1; \
ebf124ff 1357} while (0)
4429392e 1358
ebf124ff 1359 TEST_EVENTS(test__events);
4429392e 1360
ebf124ff
JO
1361 if (test_pmu())
1362 TEST_EVENTS(test__events_pmu);
f50246e2 1363
3f3a2064
JO
1364 if (test_pmu()) {
1365 int ret = test_pmu_events();
1366 if (ret)
1367 return ret;
1368 }
1369
9bfbbc6d
RR
1370 ret1 = test_terms(test__terms, ARRAY_SIZE(test__terms));
1371 if (!ret2)
1372 ret2 = ret1;
1373
1374 return ret2;
f50246e2 1375}
This page took 0.131312 seconds and 5 git commands to generate.